コード例 #1
0
ファイル: kinotifytest.cpp プロジェクト: stream009/baloo
void KInotifyTest::testMoveRootFolder()
{
    // create some test folders
    QTemporaryDir dir;
    const QString src(QStringLiteral("%1/randomJunk1").arg(dir.path()));
    const QString dest(QStringLiteral("%1/randomJunk2").arg(dir.path()));
    mkdir(src);

    // start watching the new subfolder only
    KInotify kn(nullptr /*no config*/);
    kn.addWatch(src, KInotify::EventAll);

    // listen for the moved signal
    QSignalSpy spy(&kn, SIGNAL(moved(QString,QString)));

    // actually move the file
    QFile::rename(src, dest);

    // check the desired signal
    QEXPECT_FAIL("", "KInotify cannot handle moving of top-level folders.", Abort);
    QVERIFY(spy.wait(500));
    QCOMPARE(spy.count(), 1);
    QList<QVariant> args = spy.takeFirst();
    QCOMPARE(args.at(0).toString(), src);
    QCOMPARE(args.at(1).toString(), dest);

    // check the path cache
    QVERIFY(!kn.watchingPath(src));
    QVERIFY(kn.watchingPath(dest));
}
コード例 #2
0
ファイル: kinotifytest.cpp プロジェクト: stream009/baloo
void KInotifyTest::testRenameFolder()
{
    // create some test files
    QTemporaryDir dir;
    const QString f1(QStringLiteral("%1/randomJunk1").arg(dir.path()));
    mkdir(f1);

    // start the inotify watcher
    KInotify kn(nullptr /*no config*/);
    kn.addWatch(dir.path(), KInotify::EventAll);

    // listen to the desired signal
    QSignalSpy spy(&kn, SIGNAL(moved(QString,QString)));

    // actually move the file
    const QString f2(QStringLiteral("%1/randomJunk2").arg(dir.path()));
    QFile::rename(f1, f2);

    // check the desired signal
    QVERIFY(spy.wait());
    QCOMPARE(spy.count(), 1);
    QList<QVariant> args = spy.takeFirst();
    QCOMPARE(args.at(0).toString(), f1);
    QCOMPARE(args.at(1).toString(), f2);

    // check the path cache
    QVERIFY(!kn.watchingPath(f1));
    QVERIFY(kn.watchingPath(f2));

    // test a subsequent rename
    const QString f3(QStringLiteral("%1/randomJunk3").arg(dir.path()));
    QFile::rename(f2, f3);

    // check the desired signal
    QVERIFY(spy.wait());
    QCOMPARE(spy.count(), 1);
    args = spy.takeFirst();
    QCOMPARE(args.at(0).toString(), f2);
    QCOMPARE(args.at(1).toString(), f3);

    // check the path cache
    QVERIFY(!kn.watchingPath(f1));
    QVERIFY(!kn.watchingPath(f2));
    QVERIFY(kn.watchingPath(f3));


    // KInotify claims it has updated its data structures, lets see if that is true
    // by creating a file in the new folder
    // listen to the desired signal
    const QString f4(QStringLiteral("%1/somefile").arg(f3));

    QSignalSpy createdSpy(&kn, SIGNAL(created(QString,bool)));

    // test creating a file
    touchFile(f4);

    QVERIFY(createdSpy.wait());
    QCOMPARE(createdSpy.count(), 1);
    QCOMPARE(createdSpy.takeFirst().at(0).toString(), f4);
}
コード例 #3
0
ファイル: puppetcreator.cpp プロジェクト: colede/qtcreator
bool PuppetCreator::build(const QString &qmlPuppetProjectFilePath) const
{
    PuppetBuildProgressDialog progressDialog;

    m_compileLog.clear();

    QTemporaryDir buildDirectory;

    bool buildSucceeded = false;

    if (qtIsSupported()) {
        if (buildDirectory.isValid()) {
            QStringList qmakeArguments;
            qmakeArguments.append(QStringLiteral("-r"));
            qmakeArguments.append(QStringLiteral("-after"));
            qmakeArguments.append(QStringLiteral("DESTDIR=") + qmlpuppetDirectory(UserSpacePuppet));
#ifndef QT_DEBUG
            qmakeArguments.append(QStringLiteral("CONFIG+=release"));
#endif
            qmakeArguments.append(qmlPuppetProjectFilePath);
            buildSucceeded = startBuildProcess(buildDirectory.path(), qmakeCommand(), qmakeArguments);
            if (buildSucceeded) {
                progressDialog.show();
                buildSucceeded = startBuildProcess(buildDirectory.path(), buildCommand(), QStringList(), &progressDialog);
                progressDialog.hide();
            }
        } else {
            buildSucceeded = true;
        }
    }

    m_useOnlyFallbackPuppet = !buildSucceeded;  // fall back to creator puppet and don't compile again

    return buildSucceeded;
}
コード例 #4
0
ファイル: PartUtils.cpp プロジェクト: AlpyDemirok/calamares
FstabEntryList
lookForFstabEntries( const QString& partitionPath )
{
    FstabEntryList fstabEntries;
    QTemporaryDir mountsDir;

    int exit = QProcess::execute( "mount", { partitionPath, mountsDir.path() } );
    if ( !exit ) // if all is well
    {
        QFile fstabFile( mountsDir.path() + "/etc/fstab" );
        if ( fstabFile.open( QIODevice::ReadOnly | QIODevice::Text ) )
        {
            QStringList fstabLines = QString::fromLocal8Bit( fstabFile.readAll() )
                                     .split( '\n' );

            foreach ( const QString& rawLine, fstabLines )
            {
                QString line = rawLine.simplified();
                if ( line.startsWith( '#' ) )
                    continue;

                QStringList splitLine = line.split( ' ' );
                if ( splitLine.length() != 6 )
                    continue;

                fstabEntries.append( { splitLine.at( 0 ), // path, or UUID, or LABEL, etc.
                                       splitLine.at( 1 ), // mount point
                                       splitLine.at( 2 ), // fs type
                                       splitLine.at( 3 ), // options
                                       splitLine.at( 4 ).toInt(), //dump
                                       splitLine.at( 5 ).toInt()  //pass
                                     } );
            }
コード例 #5
0
ファイル: kinotifytest.cpp プロジェクト: stream009/baloo
void KInotifyTest::testCreateFolder()
{
    QTemporaryDir dir;

    // start the inotify watcher
    KInotify kn(nullptr /*no config*/);
    kn.addWatch(dir.path(), KInotify::EventAll);

    // listen to the desired signal
    QSignalSpy createdSpy(&kn, SIGNAL(created(QString,bool)));

    // create the subdir
    const QString d1(QStringLiteral("%1/randomJunk1").arg(dir.path()));
    mkdir(d1);
    QVERIFY(createdSpy.wait());
    QCOMPARE(createdSpy.count(), 1);
    QCOMPARE(createdSpy.takeFirst().at(0).toString(), d1);
    QVERIFY(kn.watchingPath(d1));

    // lets go one level deeper
    const QString d2 = QStringLiteral("%1/subdir1").arg(d1);
    mkdir(d2);
    QVERIFY(createdSpy.wait());
    QCOMPARE(createdSpy.count(), 1);
    QCOMPARE(createdSpy.takeFirst().at(0).toString(), d2);
    QVERIFY(kn.watchingPath(d2));

    // although we are in the folder test lets try creating a file
    const QString f1 = QStringLiteral("%1/somefile1").arg(d2);
    touchFile(f1);
    QVERIFY(createdSpy.wait());
    QCOMPARE(createdSpy.count(), 1);
    QCOMPARE(createdSpy.takeFirst().at(0).toString(), f1);
}
コード例 #6
0
ファイル: import_argo.cpp プロジェクト: Nephos/umbrello
bool Import_Argo::loadFromXMIFile(const KZip &zipFile, const QString &fileName)
{
    const KArchiveFile *file = static_cast<const KArchiveFile*>(zipFile.directory()->entry(fileName));
    if (!file)
        return false;

#if QT_VERSION >= 0x050000
    QTemporaryDir tmpDir;
#else
    KTempDir tmpDir;
#endif
    tmpDir.setAutoRemove(true);

#if QT_VERSION >= 0x050000
    file->copyTo(tmpDir.path());
    QFile xmiFile(tmpDir.path() + QLatin1Char('/') + file->name());
#else
    file->copyTo(tmpDir.name());
    QFile xmiFile(tmpDir.name() + file->name());
#endif
    if(!xmiFile.open(QIODevice::ReadOnly)) {
        return false;
    }
    return UMLApp::app()->document()->loadFromXMI(xmiFile, 0);
}
コード例 #7
0
ファイル: tests.cpp プロジェクト: hsorby/opencor
void Tests::basicTests()
{
    // Create a simple COMBINE archive that contains various files

    QString fileName = OpenCOR::Core::temporaryFileName();
    OpenCOR::COMBINESupport::CombineArchive combineArchive(fileName);
    int counter = 0;

    for (int i = 1; i <= 3; ++i) {
        for (int j = 1; j <= 3; ++j, ++counter) {
            combineArchive.addFile(QDir::currentPath()+QDir::separator()+OpenCOR::fileName("src/plugins/support/COMBINESupport/tests/data/dir0%1/file0%2.txt").arg(QString::number(i), QString::number(j)),
                                   QString("dir0%1/file0%2.txt").arg(QString::number(i), QString::number(j)),
                                   OpenCOR::COMBINESupport::CombineArchiveFile::Format(1+counter%4),
                                   !(counter%2));
        }
    }

    combineArchive.save();

    QVERIFY(QFile::exists(fileName));

    // Unzip our COMBINE archive

    OpenCOR::ZIPSupport::QZipReader zipReader(fileName);
    QTemporaryDir temporaryDir;

    QVERIFY(zipReader.extractAll(temporaryDir.path()));

    zipReader.close();

    // Make sure that our COMBINE archive's manifest is correct

    QCOMPARE(OpenCOR::fileContents(temporaryDir.path()+QDir::separator()+"manifest.xml"),
             OpenCOR::fileContents(OpenCOR::fileName("src/plugins/support/COMBINESupport/tests/data/manifest.xml")));
}
コード例 #8
0
ファイル: test_buddies.cpp プロジェクト: KDE/kdevelop
void TestBuddies::testMultipleFolders()
{
/*  4. Multiple folders:
       Activate buddy option
       Open f/a.cpp f/xyz.cpp g/a.h
       Verify g/a.h is activated
       Verify order (f/a.cpp f/xyz.cpp g/a.h)*/
    enableBuddies();
    enableOpenAfterCurrent();

    QTemporaryDir tempDirA;
    QDir dirA(tempDirA.path());
    createFile(dirA, "a.cpp");
    createFile(dirA, "x.cpp");
    QTemporaryDir tempDirB;
    QDir dirB(tempDirB.path());
    createFile(dirB, "a.h");  // different folder => not dirA/a.cpp's buddy!

    m_documentController->openDocument(QUrl::fromLocalFile(dirA.filePath("a.cpp")));
    m_documentController->openDocument(QUrl::fromLocalFile(dirA.filePath("x.cpp")));
    m_documentController->openDocument(QUrl::fromLocalFile(dirB.filePath("a.h")));

    Sublime::Area *area = m_uiController->activeArea();
    Sublime::AreaIndex* areaIndex = area->indexOf(toSublimeWindow(m_uiController->activeMainWindow())->activeView());

    verifyFilename(areaIndex->views().value(0), "a.cpp");
    verifyFilename(areaIndex->views().value(1), "x.cpp");
    verifyFilename(areaIndex->views().value(2), "a.h");
    verifyFilename(toSublimeWindow(m_uiController->activeMainWindow())->activeView(), "a.h");
}
コード例 #9
0
ファイル: tests.cpp プロジェクト: fethio/opencor
void Tests::doBasicTests(const QString &pFileName)
{
    // Save the given COMBINE archive to the given file

    QString fileName = pFileName.isEmpty()?mCombineArchive->fileName():pFileName;

    mCombineArchive->save(fileName);

    QVERIFY(QFile::exists(fileName));

    // Unzip our COMBINE archive and make sure that its manifest is correct and
    // that the various files are present

    OpenCOR::ZIPSupport::QZipReader zipReader(fileName);
    QTemporaryDir temporaryDir;

    QVERIFY(zipReader.extractAll(temporaryDir.path()));

    QCOMPARE(OpenCOR::fileContents(temporaryDir.path()+QDir::separator()+"manifest.xml"),
             OpenCOR::fileContents(OpenCOR::fileName("src/plugins/support/COMBINESupport/tests/data/manifest.xml")));

    for (int i = 1; i <= 3; ++i) {
        for (int j = 1; j <= 3; ++j)
            QVERIFY(QFile::exists(temporaryDir.path()+QDir::separator()+QString("dir0%1/file0%2.txt").arg(QString::number(i), QString::number(j))));
    }
}
コード例 #10
0
terrama2::core::DataSetSeries terrama2::core::DataAccessorDcpToa5::getSeries(const std::string& uri,
        const terrama2::core::Filter& filter,
        terrama2::core::DataSetPtr dataSet) const

{
    std::string mask = getMask(dataSet);
    std::string folder = getFolder(dataSet);

    QTemporaryDir tempBaseDir;
    if(!tempBaseDir.isValid())
    {
        QString errMsg = QObject::tr("Can't create temporary folder.");
        TERRAMA2_LOG_ERROR() << errMsg;
        throw DataAccessException() << ErrorDescription(errMsg);
    }

    QDir tempDir(tempBaseDir.path());
    tempDir.mkdir(QString::fromStdString(folder));
    tempDir.cd(QString::fromStdString(folder));

    QUrl url((uri+"/"+folder+"/"+mask).c_str());
    QFileInfo originalInfo(url.path());

    QFile file(url.path());
    QFile tempFile(tempDir.path()+"/"+originalInfo.fileName());
    if(!file.open(QIODevice::ReadOnly))
    {
        QString errMsg = QObject::tr("Can't open file: dataset %1.").arg(dataSet->id);
        TERRAMA2_LOG_ERROR() << errMsg;
        throw DataAccessException() << ErrorDescription(errMsg);
    }

    if(!tempFile.open(QIODevice::ReadWrite))
    {
        QString errMsg = QObject::tr("Can't open temporary file: dataset %1.").arg(dataSet->id);
        TERRAMA2_LOG_ERROR() << errMsg;
        throw DataAccessException() << ErrorDescription(errMsg);
    }

    file.readLine();//ignore first line
    tempFile.write(file.readLine()); //headers line

    //ignore third and fourth lines
    file.readLine();
    file.readLine();

    //read all file
    tempFile.write(file.readAll()); //headers line

    //update file path
    std::string tempUri = "file://"+tempBaseDir.path().toStdString();

    file.close();
    tempFile.close();

    auto dataSeries = terrama2::core::DataAccessorFile::getSeries(tempUri, filter, dataSet);

    return dataSeries;
}
コード例 #11
0
ファイル: generatepage.cpp プロジェクト: KDE/kapptemplate
bool GeneratePage::unpackArchive(const KArchiveDirectory *dir, const QString &dest)
{
    qCDebug(KAPPTEMPLATE) << "unpacking dir:" << dir->name() << "to" << dest;
    QStringList entries = dir->entries();
    qCDebug(KAPPTEMPLATE) << "entries:" << entries.join(",");

    QTemporaryDir tdir;

    bool ret = true;

    //create path were we want copy files to
    if (!QDir::root().mkpath(dest)) {
        displayError(i18n("%1 cannot be created.", dest));
        return false;
    }

    int progress = 0;

    bool failed = false;
    foreach (const QString &entry, entries) {
        progress++;
        ui_generate.progressBar->setValue((progress / entries.size()) * 100);

        if (entry.endsWith(".kdevtemplate"))
            continue;

        if (entry == templateName + ".png")
            continue;

        if (dir->entry(entry)->isDirectory()) {
            const KArchiveDirectory *file = dynamic_cast<const KArchiveDirectory *>(dir->entry(entry));
            QString newdest = dest + "/" + file->name();
            if (!QFileInfo(newdest).exists()) {
                if (!QDir::root().mkdir(newdest)) {
                    displayError(i18n("Path %1 could not be created.", newdest));
                    return false;
                }
            }
            ret |= unpackArchive(file, newdest);
        }
        else if (dir->entry(entry)->isFile()) {
            const KArchiveFile *file = dynamic_cast<const KArchiveFile *>(dir->entry(entry));
            file->copyTo(tdir.path());
            QString destName = KMacroExpander::expandMacros(dest + '/' + file->name(), m_variables);
            if (QFile(QDir::cleanPath(tdir.path() + '/' + file->name())).copy(destName)) {
                if (!extractFileMacros(destName)) {
                    displayError(i18n("Failed to integrate your project information into "
                                      "the file %1. The project has not been generated and "
                                      "all temporary files will be removed.", destName));
                    failed = true;
                    break;
                }
            } else {
                displayError(i18n("Could not copy template file to %1.", destName));
                failed = true;
                break;
            }
        }
    }
コード例 #12
0
void tst_qmldiskcache::cppRegisteredSingletonDependency()
{
    qmlClearTypeRegistrations();
    QScopedPointer<QQmlEngine> engine(new QQmlEngine);

    QTemporaryDir tempDir;
    QVERIFY(tempDir.isValid());

    const auto writeTempFile = [&tempDir](const QString &fileName, const char *contents) {
        QFile f(tempDir.path() + '/' + fileName);
        const bool ok = f.open(QIODevice::WriteOnly | QIODevice::Truncate);
        Q_ASSERT(ok);
        f.write(contents);
        return f.fileName();
    };

    writeTempFile("MySingleton.qml", "import QtQml 2.0\npragma Singleton\nQtObject { property int value: 42 }");

    qmlRegisterSingletonType(QUrl::fromLocalFile(tempDir.path() + QLatin1String("/MySingleton.qml")), "CppRegisteredSingletonDependency", 1, 0, "Singly");

    const QString testFilePath = writeTempFile("main.qml", "import QtQml 2.0\nimport CppRegisteredSingletonDependency 1.0\nQtObject {\n"
                                                           "    function getValue() { return Singly.value; }\n"
                                                           "}");

    {
        CleanlyLoadingComponent component(engine.data(), QUrl::fromLocalFile(testFilePath));
        QScopedPointer<QObject> obj(component.create());
        QVERIFY(!obj.isNull());
        QVariant value;
        QVERIFY(QMetaObject::invokeMethod(obj.data(), "getValue", Q_RETURN_ARG(QVariant, value)));
        QCOMPARE(value.toInt(), 42);
    }

    const QString testFileCachePath = testFilePath + QLatin1Char('c');
    QVERIFY(QFile::exists(testFileCachePath));
    QDateTime initialCacheTimeStamp = QFileInfo(testFileCachePath).lastModified();

    engine.reset(new QQmlEngine);
    waitForFileSystem();

    writeTempFile("MySingleton.qml", "import QtQml 2.0\npragma Singleton\nQtObject { property int value: 100 }");
    waitForFileSystem();

    {
        CleanlyLoadingComponent component(engine.data(), QUrl::fromLocalFile(testFilePath));
        QScopedPointer<QObject> obj(component.create());
        QVERIFY(!obj.isNull());

        {
            QVERIFY(QFile::exists(testFileCachePath));
            QDateTime newCacheTimeStamp = QFileInfo(testFileCachePath).lastModified();
            QVERIFY2(newCacheTimeStamp > initialCacheTimeStamp, qPrintable(newCacheTimeStamp.toString()));
        }

        QVariant value;
        QVERIFY(QMetaObject::invokeMethod(obj.data(), "getValue", Q_RETURN_ARG(QVariant, value)));
        QCOMPARE(value.toInt(), 100);
    }
}
コード例 #13
0
void tst_QTemporaryDir::construction()
{
    QTemporaryDir dir;
    QString tmp = QDir::tempPath();
    QCOMPARE(dir.path().left(tmp.size()), tmp);
    QVERIFY(dir.path().contains("tst_qtemporarydir"));
    QVERIFY(QFileInfo(dir.path()).isDir());
}
コード例 #14
0
ファイル: tests.cpp プロジェクト: fethio/opencor
void Tests::basicTests()
{
    // Some basic tests to save our COMBINE archive either directly or to a
    // different file and checking that its contents is sound

    QString otherFileName = OpenCOR::Core::temporaryFileName();

    doBasicTests();
    doBasicTests(otherFileName);

    // Check that we can load our other COMBINE archive and save it in yet
    // another file

    OpenCOR::COMBINESupport::CombineArchive otherCombineArchive(otherFileName);

    QString yetAnotherFileName = OpenCOR::Core::temporaryFileName();

    QVERIFY(otherCombineArchive.load());
    QVERIFY(otherCombineArchive.isValid());
    QVERIFY(otherCombineArchive.save(yetAnotherFileName));

    // Unzip our two COMBINE archives and make sure that their contents is the
    // same
    // Note: the original plan was to check that the SHA-1 value of the two
    //       files was the same, but the fact is that the ZIP file format
    //       contains various date and time information, so the SHA-1 value of
    //       two files may be different...

    QTemporaryDir temporaryDir;
    QString otherDir = temporaryDir.path()+"/otherDir";
    QString yetAnotherDir = temporaryDir.path()+"/yetAnotherDir";
    OpenCOR::ZIPSupport::QZipReader otherZipReader(otherFileName);
    OpenCOR::ZIPSupport::QZipReader yetAnotherZipReader(yetAnotherFileName);

    QVERIFY(otherZipReader.extractAll(otherDir));
    QVERIFY(yetAnotherZipReader.extractAll(yetAnotherDir));

    QDirIterator dirIterator(otherDir, QStringList() << "*",
                             QDir::Files, QDirIterator::Subdirectories);

    while (dirIterator.hasNext()) {
        QString otherFileName = dirIterator.next();
        QString yetAnotherFileName = otherFileName.replace(otherDir, yetAnotherDir);
        QByteArray otherFileContents;
        QByteArray yetAnotherFileContents;

        QVERIFY(OpenCOR::Core::readFileContentsFromFile(otherFileName, otherFileContents));
        QVERIFY(OpenCOR::Core::readFileContentsFromFile(yetAnotherFileName, yetAnotherFileContents));

        QCOMPARE(OpenCOR::Core::sha1(otherFileContents),
                 OpenCOR::Core::sha1(yetAnotherFileContents));
    }

    // Clean up after ourselves

    QFile::remove(otherFileName);
    QFile::remove(yetAnotherFileName);
}
コード例 #15
0
ファイル: test_buddies.cpp プロジェクト: KDE/kdevelop
void TestBuddies::testDUChainBuddyVote()
{
    /*
     * Test that the DUChain buddy system finds the buddy file with the most
     * common declarations/definitions
     */

    enableBuddies();
    enableOpenAfterCurrent();

    QTemporaryDir dirA;

    TestFile header("void func1();\nvoid func2();\nvoid func3();\n", "h", nullptr, dirA.path());
    TestFile source1(
        QString("#include \"%1\"\nvoid func1() {}\n").arg(header.url().toUrl().fileName()),
        "cpp", nullptr, dirA.path()
    );
    TestFile source2(
        QString("#include \"%1\"\nvoid func2() {}\nvoid func3() {}\n").arg(header.url().toUrl().fileName()),
        "cpp", nullptr, dirA.path()
    );

    // -> buddy(header) should resolve to source2

    header.parseAndWait();
    source1.parseAndWait();
    source2.parseAndWait();

    // Test IBuddyDocumentFinder::getPotentialBuddies()
    QMimeDatabase db;
    IBuddyDocumentFinder* sourceBuddyFinder = IBuddyDocumentFinder::finderForMimeType(db.mimeTypeForUrl(source1.url().toUrl()).name());
    QVector< QUrl > sourceBuddies = sourceBuddyFinder->getPotentialBuddies(source1.url().toUrl());
    if (!sourceBuddies.contains(header.url().toUrl())) {
        qDebug() << "got source buddies: " << sourceBuddies;
        qDebug() << "expected: " << header.url().toUrl();
        QFAIL("Failed to find buddy for source file");
    }

    IBuddyDocumentFinder* source2BuddyFinder = IBuddyDocumentFinder::finderForMimeType(db.mimeTypeForUrl(source2.url().toUrl()).name());
    QVector< QUrl > source2Buddies = source2BuddyFinder->getPotentialBuddies(source2.url().toUrl());
    if (!source2Buddies.contains(header.url().toUrl())) {
        qDebug() << "got source2 buddies: " << source2Buddies;
        qDebug() << "expected: " << header.url().toUrl();
        QFAIL("Failed to find buddy for source2 file");
    }

    IBuddyDocumentFinder* headerBuddyFinder = IBuddyDocumentFinder::finderForMimeType(db.mimeTypeForUrl(header.url().toUrl()).name());
    QVector< QUrl > headerBuddies = headerBuddyFinder->getPotentialBuddies(header.url().toUrl());
    if (!headerBuddies.contains(source2.url().toUrl())) {
        qDebug() << "got header buddies: " << headerBuddies;
        qDebug() << "expected: " << source2.url().toUrl();
        QFAIL("Failed to find buddy for header file");
    }
    QVERIFY2(!headerBuddies.contains(source1.url().toUrl()), "header buddy list contains weaker file");
}
コード例 #16
0
void tst_qmldiskcache::fileSelectors()
{
    QQmlEngine engine;

    QTemporaryDir tempDir;
    QVERIFY(tempDir.isValid());

    const QString testFilePath = tempDir.path() + "/test.qml";
    {
        QFile f(testFilePath);
        QVERIFY2(f.open(QIODevice::WriteOnly), qPrintable(f.errorString()));
        f.write(QByteArrayLiteral("import QtQml 2.0\nQtObject { property int value: 42 }"));
    }

    const QString selector = QStringLiteral("testSelector");
    const QString selectorPath = tempDir.path() + "/+" + selector;
    const QString selectedTestFilePath = selectorPath + "/test.qml";
    {
        QVERIFY(QDir::root().mkpath(selectorPath));
        QFile f(selectorPath + "/test.qml");
        QVERIFY2(f.open(QIODevice::WriteOnly), qPrintable(f.errorString()));
        f.write(QByteArrayLiteral("import QtQml 2.0\nQtObject { property int value: 100 }"));
    }

    {
        QQmlComponent component(&engine, testFilePath);
        QScopedPointer<QObject> obj(component.create());
        QVERIFY(!obj.isNull());
        QCOMPARE(obj->property("value").toInt(), 42);

        QFile cacheFile(testFilePath + "c");
        QVERIFY2(cacheFile.exists(), qPrintable(cacheFile.fileName()));
    }

    QQmlFileSelector qmlSelector(&engine);
    qmlSelector.setExtraSelectors(QStringList() << selector);

    engine.clearComponentCache();

    {
        QQmlComponent component(&engine, testFilePath);
        QScopedPointer<QObject> obj(component.create());
        QVERIFY(!obj.isNull());
        QCOMPARE(obj->property("value").toInt(), 100);

        QFile cacheFile(selectedTestFilePath + "c");
        QVERIFY2(cacheFile.exists(), qPrintable(cacheFile.fileName()));
    }
}
コード例 #17
0
ファイル: kinotifytest.cpp プロジェクト: stream009/baloo
void KInotifyTest::testFileClosedAfterWrite()
{
    QTemporaryDir dir;
    touchFile(dir.path() + QLatin1String("/file"));

    KInotify kn(nullptr /*no config*/);
    kn.addWatch(dir.path(), KInotify::EventAll);

    QSignalSpy spy(&kn, SIGNAL(closedWrite(QString)));
    touchFile(dir.path() + QLatin1String("/file"));

    QVERIFY(spy.wait());
    QCOMPARE(spy.count(), 1);
    QCOMPARE(spy.at(0).first().toString(), QString(dir.path() + QLatin1String("/file")));
}
コード例 #18
0
ファイル: TestShpFilter.cpp プロジェクト: asmaloney/trunk
void TestShpFilter::testWritePolygonZFile() const
{
	CCVector3d bbMin(1422671.7232666016, 4188903.4295959473, 71.99445343017578);
	CCVector3d shift = ccGlobalShiftManager::BestShift(bbMin);
	bool shiftEnabled = true;

	ccHObject container;
	FileIOFilter::LoadParameters params;
	params.alwaysDisplayLoadDialog = false;
	params.shiftHandlingMode = ccGlobalShiftManager::Mode::NO_DIALOG;
	params.coordinatesShiftEnabled = &shiftEnabled;
	params.coordinatesShift = &shift;
	params.preserveShiftOnSave = true;
	ShpFilter filter;

	CC_FILE_ERROR error = filter.loadFile(POLYGONZ_FILE, container, params);
	QVERIFY(error == CC_FERR_NO_ERROR);

	QTemporaryDir tmpDir;
	QString tmpMultipatch = tmpDir.path() + "polygon_z.shp";
	FileIOFilter::SaveParameters saveParams;
	saveParams.alwaysDisplaySaveDialog = false;

	filter.save3DPolyAs2D(false);
	filter.treatClosedPolylinesAsPolygons(true);
	error = filter.saveToFile(&container, tmpMultipatch, saveParams);
	QVERIFY(error == CC_FERR_NO_ERROR);
	readPolygonZFile(tmpMultipatch);
}
コード例 #19
0
ファイル: test_buddies.cpp プロジェクト: KDE/kdevelop
void TestBuddies::testMultiDotFilenames()
{
    enableBuddies();
    enableOpenAfterCurrent();

    QTemporaryDir tempDirA;
    QDir dirA(tempDirA.path());
    createFile(dirA, "a.cpp");
    createFile(dirA, "lots.of.dots.cpp");
    createFile(dirA, "b.cpp");
    createFile(dirA, "lots.of.dots.h");

    m_documentController->openDocument(QUrl::fromLocalFile(dirA.filePath("a.cpp")));
    m_documentController->openDocument(QUrl::fromLocalFile(dirA.filePath("lots.of.dots.cpp")));
    m_documentController->openDocument(QUrl::fromLocalFile(dirA.filePath("b.cpp")));
    m_documentController->openDocument(QUrl::fromLocalFile(dirA.filePath("lots.of.dots.h")));

    Sublime::Area *area = m_uiController->activeArea();
    Sublime::AreaIndex* areaIndex = area->indexOf(toSublimeWindow(m_uiController->activeMainWindow())->activeView());
    QCOMPARE(m_documentController->openDocuments().count(), 4);
    //QCOMPARE(m_sublimeController->documents().count(), 4);
    QCOMPARE(areaIndex->viewCount(), 4);

    verifyFilename(areaIndex->views().value(0), "a.cpp");
    verifyFilename(areaIndex->views().value(1), "lots.of.dots.h");
    verifyFilename(areaIndex->views().value(2), "lots.of.dots.cpp");
    verifyFilename(areaIndex->views().value(3), "b.cpp");
}
コード例 #20
0
ファイル: test_buddies.cpp プロジェクト: KDE/kdevelop
void TestBuddies::testDisableAll()
{
/*  6. Disable buddy option, Disable open next to active tab
       Open       foo.cpp bar.h foo.h
       Activate   bar.h
       Open       bar.cpp
       Verify order (foo.cpp bar.h foo.h bar.cpp)
       Verify that bar.cpp is activated*/
    enableBuddies(false);
    enableOpenAfterCurrent(false);

    QTemporaryDir tempDirA;
    QDir dirA(tempDirA.path());
    createFile(dirA, "foo.h");
    createFile(dirA, "foo.cpp");
    createFile(dirA, "bar.h");
    createFile(dirA, "bar.cpp");

    m_documentController->openDocument(QUrl::fromLocalFile(dirA.filePath("foo.cpp")));
    m_documentController->openDocument(QUrl::fromLocalFile(dirA.filePath("bar.h")));
    m_documentController->openDocument(QUrl::fromLocalFile(dirA.filePath("foo.h")));
    Sublime::Area *area = m_uiController->activeArea();
    Sublime::AreaIndex* areaIndex = area->indexOf(toSublimeWindow(m_uiController->activeMainWindow())->activeView());

    //activate bar.h
    toSublimeWindow(m_uiController->activeMainWindow())->activateView(areaIndex->views().value(1));

    m_documentController->openDocument(QUrl::fromLocalFile(dirA.filePath("bar.cpp")));

    verifyFilename(areaIndex->views().value(0), "foo.cpp");
    verifyFilename(areaIndex->views().value(1), "bar.h");
    verifyFilename(areaIndex->views().value(2), "foo.h");
    verifyFilename(areaIndex->views().value(3), "bar.cpp");
    verifyFilename(toSublimeWindow(m_uiController->activeMainWindow())->activeView(), "bar.cpp");
}
コード例 #21
0
void KArchiveTest::testZipAddLocalDirectory()
{
    // Prepare local dir
    QTemporaryDir tmpDir;
    const QString dirName = tmpDir.path() + '/';

    const QByteArray file1Data = "Hello Shantanu";
    const QString file1 = QStringLiteral("file1");
    QVERIFY(writeFile(dirName, file1, file1Data));

    {
        KZip zip(s_zipFileName);

        QVERIFY(zip.open(QIODevice::WriteOnly));
        QVERIFY(zip.addLocalDirectory(dirName, "."));
        QVERIFY(zip.close());
    }
    {
        KZip zip(s_zipFileName);

        QVERIFY(zip.open(QIODevice::ReadOnly));

        const KArchiveDirectory *dir = zip.directory();
        QVERIFY(dir != nullptr);

        const KArchiveEntry *e = dir->entry(file1);
        QVERIFY(e && e->isFile());
        const KArchiveFile *f = (KArchiveFile *)e;
        QCOMPARE(f->data(), file1Data);
    }
}
コード例 #22
0
ファイル: movetest.cpp プロジェクト: KDE/ark
void MoveTest::testMoving()
{
    QTemporaryDir temporaryDir;

    QFETCH(QString, archiveName);
    const QString archivePath = temporaryDir.path() + QLatin1Char('/') + archiveName;
    QVERIFY(QFile::copy(QFINDTESTDATA(QStringLiteral("data/") + archiveName), archivePath));

    QFETCH(Plugin*, plugin);
    QVERIFY(plugin);

    auto loadJob = Archive::load(archivePath, plugin);
    QVERIFY(loadJob);
    loadJob->setAutoDelete(false);

    TestHelper::startAndWaitForResult(loadJob);
    auto archive = loadJob->archive();
    QVERIFY(archive);

    if (!archive->isValid()) {
        QSKIP("Could not find a plugin to handle the archive. Skipping test.", SkipSingle);
    }

    QFETCH(QVector<Archive::Entry*>, targetEntries);
    QFETCH(Archive::Entry*, destination);
    QFETCH(QStringList, expectedNewPaths);

    // Retrieve current paths in the archive.
    QStringList oldPaths = getEntryPaths(archive);

    // Check that the entries to be moved are in the archive.
    foreach (const auto entry, targetEntries) {
        QVERIFY(oldPaths.contains(entry->fullPath()));
    }
コード例 #23
0
void CreateFileTest::createFileTest()
{
  QTemporaryDir dir;
  QVERIFY(dir.isValid());
  const auto filePath = QDir::cleanPath(dir.path() + "/subA/subB/file.txt");
  QVERIFY(!QFile::exists(filePath));
  QVERIFY(createFile(filePath));
  QVERIFY(QFile::exists(filePath));
}
コード例 #24
0
ファイル: test_shellbuddy.cpp プロジェクト: KDE/kdevplatform
void TestShellBuddy::testDisableOpenAfterCurrent()
{
/*  5. Enable buddy option, Disable open next to active tab
       Open foo.l.txt bar.cpp foo.cpp
       Verify order (foo.l.txt foo.cpp bar.cpp)
       Verify that foo.cpp is activated
       Open x.cpp => tab must be placed at the end
       Verify order (foo.l.txt foo.cpp bar.cpp x.cpp)
       Verify that x.cpp is activated*/
    QCOMPARE(m_documentController->openDocuments().count(), 0);
    enableBuddies();
    enableOpenAfterCurrent(false);

    QTemporaryDir dirA;
    createFile(dirA, QStringLiteral("foo.l.txt"));
    createFile(dirA, QStringLiteral("bar.r.txt"));
    createFile(dirA, QStringLiteral("foo.r.txt"));
    createFile(dirA, QStringLiteral("x.r.txt"));

    m_documentController->openDocument(QUrl::fromLocalFile(dirA.path() + "foo.l.txt"));
    m_documentController->openDocument(QUrl::fromLocalFile(dirA.path() + "bar.r.txt"));
    m_documentController->openDocument(QUrl::fromLocalFile(dirA.path() + "foo.r.txt"));

    Sublime::Area *area = m_uiController->activeArea();
    Sublime::AreaIndex* areaIndex = area->indexOf(m_uiController->activeSublimeWindow()->activeView());

    verifyFilename(areaIndex->views().value(0), "foo.l.txt");
    verifyFilename(areaIndex->views().value(1), "foo.r.txt");
    verifyFilename(areaIndex->views().value(2), "bar.r.txt");
    verifyFilename(m_uiController->activeSublimeWindow()->activeView(), "foo.r.txt");

    m_documentController->openDocument(QUrl::fromLocalFile(dirA.path() + "x.r.txt"));
    verifyFilename(areaIndex->views().value(0), "foo.l.txt");
    verifyFilename(areaIndex->views().value(1), "foo.r.txt");
    verifyFilename(areaIndex->views().value(2), "bar.r.txt");
    verifyFilename(areaIndex->views().value(3), "x.r.txt");
    verifyFilename(m_uiController->activeSublimeWindow()->activeView(), "x.r.txt");

    QCOMPARE(m_documentController->openDocuments().count(), 4);
    for(int i = 0; i < 4; i++)
        m_documentController->openDocuments().at(0)->close(IDocument::Discard);
    QCOMPARE(m_documentController->openDocuments().count(), 0);
}
コード例 #25
0
ファイル: test_shellbuddy.cpp プロジェクト: KDE/kdevplatform
void TestShellBuddy::testDisableBuddies()
{
/*  3. Deactivate buddy option, Activate open next to active tab
       Open a.cpp a.l.txt
       Verify order (a.cpp a.l.txt)
       Verify that a.l.txt is activated
       Activate a.cpp
       Open b.cpp
       Verify order (a.cpp b.cpp a.l.txt) */
    QCOMPARE(m_documentController->openDocuments().count(), 0);
    enableBuddies(false);
    enableOpenAfterCurrent();

    QTemporaryDir dirA;
    createFile(dirA, QStringLiteral("a.l.txt"));
    createFile(dirA, QStringLiteral("a.r.txt"));
    createFile(dirA, QStringLiteral("b.r.txt"));

    m_documentController->openDocument(QUrl::fromLocalFile(dirA.path() + "a.r.txt"));
    m_documentController->openDocument(QUrl::fromLocalFile(dirA.path() + "a.l.txt"));

    Sublime::Area *area = m_uiController->activeArea();
    Sublime::AreaIndex* areaIndex = area->indexOf(m_uiController->activeSublimeWindow()->activeView());

    // Buddies disabled => order of tabs should be the order of file opening
    verifyFilename(areaIndex->views().value(0), "a.r.txt");
    verifyFilename(areaIndex->views().value(1), "a.l.txt");
    verifyFilename(m_uiController->activeSublimeWindow()->activeView(), "a.l.txt");

    //activate a.cpp => new doc should be opened right next to it
    m_uiController->activeSublimeWindow()->activateView(areaIndex->views().value(0));

    m_documentController->openDocument(QUrl::fromLocalFile(dirA.path() + "b.r.txt"));
    verifyFilename(areaIndex->views().value(0), "a.r.txt");
    verifyFilename(areaIndex->views().value(1), "b.r.txt");
    verifyFilename(areaIndex->views().value(2), "a.l.txt");
    verifyFilename(m_uiController->activeSublimeWindow()->activeView(), "b.r.txt");

    QCOMPARE(m_documentController->openDocuments().count(), 3);
    for(int i = 0; i < 3; i++)
        m_documentController->openDocuments().at(0)->close(IDocument::Discard);
    QCOMPARE(m_documentController->openDocuments().count(), 0);
}
コード例 #26
0
ファイル: testdatatest.cpp プロジェクト: KDE/kdepim-runtime
void TestDataTest::testInstall()
{
    QTemporaryDir dir;
    QDir installDir(dir.path());
    QDir curDir;

    const QString indexFilePattern = QStringLiteral(".%1.index");

    QVERIFY(TestDataUtil::installFolder(QLatin1String("mbox"), dir.path(), QStringLiteral("mbox1")));
    QVERIFY(installDir.exists(QLatin1String("mbox1")));
    QVERIFY(installDir.exists(indexFilePattern.arg(QLatin1String("mbox1"))));

    QVERIFY(TestDataUtil::installFolder(QLatin1String("mbox-tagged"), dir.path(), QStringLiteral("mbox2")));
    QVERIFY(installDir.exists(QLatin1String("mbox2")));
    QVERIFY(installDir.exists(indexFilePattern.arg(QLatin1String("mbox2"))));

    QVERIFY(TestDataUtil::installFolder(QLatin1String("maildir"), dir.path(), QStringLiteral("md1")));
    QVERIFY(installDir.exists(QLatin1String("md1")));
    QVERIFY(installDir.exists(QLatin1String("md1/new")));
    QVERIFY(installDir.exists(QLatin1String("md1/cur")));
    QVERIFY(installDir.exists(QLatin1String("md1/tmp")));
    QVERIFY(installDir.exists(indexFilePattern.arg(QLatin1String("md1"))));

    curDir = installDir;
    curDir.cd(QStringLiteral("md1"));
    curDir.cd(QStringLiteral("cur"));
    curDir.setFilter(QDir::Files);
    QCOMPARE((int)curDir.count(), 4);

    QVERIFY(TestDataUtil::installFolder(QLatin1String("maildir-tagged"), dir.path(), QStringLiteral("md2")));
    QVERIFY(installDir.exists(QLatin1String("md2")));
    QVERIFY(installDir.exists(QLatin1String("md2/new")));
    QVERIFY(installDir.exists(QLatin1String("md2/cur")));
    QVERIFY(installDir.exists(QLatin1String("md2/tmp")));
    QVERIFY(installDir.exists(indexFilePattern.arg(QLatin1String("md2"))));

    curDir = installDir;
    curDir.cd(QStringLiteral("md2"));
    curDir.cd(QStringLiteral("cur"));
    curDir.setFilter(QDir::Files);
    QCOMPARE((int)curDir.count(), 4);
}
コード例 #27
0
static QUrl createFile(const QString& fileContents)
{
    static QTemporaryDir dirA;
    static int i = 0;
    ++i;
    QFile file(dirA.path() + '/' + QString::number(i) + ".cpp");
    file.open(QIODevice::WriteOnly | QIODevice::Text);
    file.write(fileContents.toUtf8());
    file.close();
    return QUrl::fromLocalFile(file.fileName());
}
コード例 #28
0
void CreateFileTest::createFileInDirectoryTest()
{
  QTemporaryDir dir;
  QVERIFY(dir.isValid());
  QString fileName = "file.txt";
  const auto dirPath = QDir::cleanPath( dir.path() + "/subC" );
  const auto filePath = QDir::cleanPath( dirPath + "/" + fileName );
  QVERIFY(!QFile::exists(filePath));
  QVERIFY(createFileInDirectory(dirPath, fileName));
  QVERIFY(QFile::exists(filePath));
}
コード例 #29
0
ファイル: kinotifytest.cpp プロジェクト: stream009/baloo
void KInotifyTest::testDeleteFile()
{
    // create some test files
    QTemporaryDir dir;
    const QString f1(QStringLiteral("%1/randomJunk1").arg(dir.path()));
    touchFile(f1);

    // start the inotify watcher
    KInotify kn(nullptr /*no config*/);
    kn.addWatch(dir.path(), KInotify::EventAll);

    // listen to the desired signal
    QSignalSpy spy(&kn, SIGNAL(deleted(QString,bool)));

    // test removing a file
    QFile::remove(f1);
    QVERIFY(spy.wait());
    QCOMPARE(spy.count(), 1);
    QCOMPARE(spy.takeFirst().at(0).toString(), f1);
}
コード例 #30
0
ファイル: basicindexingtest.cpp プロジェクト: stream009/baloo
int main(int argc, char** argv)
{
    QCoreApplication app(argc, argv);

    QTemporaryDir tempDir;
    qDebug() << tempDir.path();

    Database db(tempDir.path());
    db.open(Baloo::Database::CreateDatabase);

    Transaction tr(db, Transaction::ReadWrite);

    QMimeDatabase mimeDb;
    {
        QTime timer;
        timer.start();

        QDirIterator it(QDir::homePath(), QDirIterator::Subdirectories);
        uint num = 0;
        while (it.hasNext()) {
            const QString& path = it.next();
            const QString& mimetype = mimeDb.mimeTypeForFile(path, QMimeDatabase::MatchExtension).name();

            BasicIndexingJob job(path, mimetype);
            job.index();

            tr.addDocument(job.document());
            num++;

            if ((num % 10000) == 0) {
                qDebug() << num;
            }
        }
        tr.commit();

        qDebug() << "Done" << timer.elapsed() << "msecs";
        app.exec();
    }

    return 0;
}