예제 #1
0
void tst_QMimeDatabase::initTestCase()
{
    QVERIFY2(m_temporaryDir.isValid(), qPrintable(m_temporaryDir.errorString()));
    QStandardPaths::setTestModeEnabled(true);
    m_localMimeDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/mime";
    if (QDir(m_localMimeDir).exists()) {
        QVERIFY2(QDir(m_localMimeDir).removeRecursively(), qPrintable(m_localMimeDir + ": " + qt_error_string()));
    }
    QString errorMessage;

#ifdef USE_XDG_DATA_DIRS
    // Create a temporary "global" XDG data dir for later use
    // It will initially contain a copy of freedesktop.org.xml
    QVERIFY2(m_temporaryDir.isValid(),
             ("Could not create temporary subdir: " + m_temporaryDir.errorString()).toUtf8());
    const QDir here = QDir(m_temporaryDir.path());
    m_globalXdgDir = m_temporaryDir.path() + QStringLiteral("/global");
    const QString globalPackageDir = m_globalXdgDir + QStringLiteral("/mime/packages");
    QVERIFY(here.mkpath(globalPackageDir));

    qputenv("XDG_DATA_DIRS", QFile::encodeName(m_globalXdgDir));
    qDebug() << "\nGlobal XDG_DATA_DIRS: " << m_globalXdgDir;

    const QString freeDesktopXml = QStringLiteral("freedesktop.org.xml");
    const QString xmlFileName = QLatin1String(RESOURCE_PREFIX) + freeDesktopXml;
    const QString xmlTargetFileName = globalPackageDir + QLatin1Char('/') + freeDesktopXml;
    QVERIFY2(copyResourceFile(xmlFileName, xmlTargetFileName, &errorMessage), qPrintable(errorMessage));
#endif

    m_testSuite = QFINDTESTDATA("testfiles");
    if (m_testSuite.isEmpty())
        qWarning("%s", qPrintable(testSuiteWarning()));

    errorMessage = QString::fromLatin1("Cannot find '%1'");
    for (uint i = 0; i < sizeof additionalMimeFiles / sizeof additionalMimeFiles[0] - 1; i++) {
        const QString resourceFilePath = QString::fromLatin1(RESOURCE_PREFIX) + QLatin1String(additionalMimeFiles[i]);
        QVERIFY2(QFile::exists(resourceFilePath), qPrintable(errorMessage.arg(resourceFilePath)));
        m_additionalMimeFileNames.append(QLatin1String(additionalMimeFiles[i]));
        m_additionalMimeFilePaths.append(resourceFilePath);
    }

    initTestCaseInternal();
    m_isUsingCacheProvider = !qEnvironmentVariableIsSet("QT_NO_MIME_CACHE");
}
예제 #2
0
void tst_QMimeDatabase::initTestCase()
{
    QVERIFY(m_temporaryDir.isValid());

    // Create a "global" and a "local" XDG data dir, right here.
    // The local dir will be empty initially, while the global dir will contain a copy of freedesktop.org.xml

    const QDir here = QDir(m_temporaryDir.path());

    m_globalXdgDir = m_temporaryDir.path() + QStringLiteral("/global");
    m_localXdgDir = m_temporaryDir.path() + QStringLiteral("/local");

    const QString globalPackageDir = m_globalXdgDir + QStringLiteral("/mime/packages");
    QVERIFY(here.mkpath(globalPackageDir) && here.mkpath(m_localXdgDir));

    qputenv("XDG_DATA_DIRS", QFile::encodeName(m_globalXdgDir));
    qputenv("XDG_DATA_HOME", QFile::encodeName(m_localXdgDir));
    qDebug() << "\nLocal XDG_DATA_HOME: " << m_localXdgDir
             << "\nGlobal XDG_DATA_DIRS: " << m_globalXdgDir;

    const QString freeDesktopXml = QStringLiteral("freedesktop.org.xml");
    const QString xmlFileName = QLatin1String(CORE_SOURCES)
                          + QStringLiteral("/mimetypes/mime/packages/")
                          + freeDesktopXml;
    QVERIFY2(QFileInfo(xmlFileName).exists(), qPrintable(xmlFileName + QStringLiteral(" does not exist")));
    QFile xml(xmlFileName);
    QVERIFY(xml.copy(globalPackageDir + '/' + freeDesktopXml));

    m_testSuite = QFINDTESTDATA("testfiles");
    if (m_testSuite.isEmpty())
        qWarning("%s", qPrintable(testSuiteWarning()));

    m_yastMimeTypes = QFINDTESTDATA(yastFileName);
    QVERIFY2(!m_yastMimeTypes.isEmpty(),
             qPrintable(QString::fromLatin1("Cannot find '%1' starting from '%2'").
                        arg(yastFileName, QDir::currentPath())));
    m_qmlAgainFileName = QFINDTESTDATA(qmlAgainFileName);
    QVERIFY2(!m_qmlAgainFileName.isEmpty(),
             qPrintable(QString::fromLatin1("Cannot find '%1' starting from '%2'").
                        arg(qmlAgainFileName, QDir::currentPath())));

    init();
}