tst_qmimedatabase: separate xml files for Global and Local tests
For historic reasons, the test had a single list of override xml files to copy first into the global dir, and then into the local dir. But glob-deleteall only makes sense in the local dir (as per the MIME spec). Having two definitions for the same mimetype in the same dir is undefined behavior, so the test was working by chance only, and my upcoming refactoring/fixes caught that. Change-Id: I4717683b4b3f9ba69f1fd815669460789700e877 (cherry picked from commit 251ab925fe8e3dfbc8a8e5f9ed999777d3f6af99) Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
c88e1caf3b
commit
6bc35430f9
@ -14,6 +14,7 @@ qt_internal_add_test(tst_qmimedatabase-cache
|
|||||||
../tst_qmimedatabase.h
|
../tst_qmimedatabase.h
|
||||||
tst_qmimedatabase-cache.cpp
|
tst_qmimedatabase-cache.cpp
|
||||||
LIBRARIES
|
LIBRARIES
|
||||||
|
Qt::CorePrivate
|
||||||
Qt::Concurrent
|
Qt::Concurrent
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ qt_internal_add_test(tst_qmimedatabase-xml
|
|||||||
tst_qmimedatabase-xml.cpp
|
tst_qmimedatabase-xml.cpp
|
||||||
LIBRARIES
|
LIBRARIES
|
||||||
Qt::Concurrent
|
Qt::Concurrent
|
||||||
|
Qt::CorePrivate
|
||||||
)
|
)
|
||||||
|
|
||||||
# Resources:
|
# Resources:
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include <QtCore/QTemporaryDir>
|
#include <QtCore/QTemporaryDir>
|
||||||
#include <QtCore/QTextStream>
|
#include <QtCore/QTextStream>
|
||||||
#include <QtConcurrent/QtConcurrentRun>
|
#include <QtConcurrent/QtConcurrentRun>
|
||||||
|
#include <private/qspan_p.h>
|
||||||
|
|
||||||
#include <QTest>
|
#include <QTest>
|
||||||
#include <QBuffer>
|
#include <QBuffer>
|
||||||
@ -30,16 +31,23 @@
|
|||||||
|
|
||||||
using namespace Qt::StringLiterals;
|
using namespace Qt::StringLiterals;
|
||||||
|
|
||||||
static const char *const additionalMimeFiles[] = { "yast2-metapackage-handler-mimetypes.xml",
|
static const std::array additionalGlobalMimeFiles = {
|
||||||
"qml-again.xml",
|
"yast2-metapackage-handler-mimetypes.xml",
|
||||||
"text-x-objcsrc.xml",
|
"qml-again.xml",
|
||||||
"text-plain-subclass.xml",
|
"magic-and-hierarchy.xml",
|
||||||
"invalid-magic1.xml",
|
};
|
||||||
"invalid-magic2.xml",
|
|
||||||
"invalid-magic3.xml",
|
static const std::array additionalLocalMimeFiles = {
|
||||||
"magic-and-hierarchy.xml",
|
"yast2-metapackage-handler-mimetypes.xml",
|
||||||
"circular-inheritance.xml",
|
"qml-again.xml",
|
||||||
0 };
|
"text-x-objcsrc.xml",
|
||||||
|
"text-plain-subclass.xml",
|
||||||
|
"invalid-magic1.xml",
|
||||||
|
"invalid-magic2.xml",
|
||||||
|
"invalid-magic3.xml",
|
||||||
|
"magic-and-hierarchy.xml",
|
||||||
|
"circular-inheritance.xml",
|
||||||
|
};
|
||||||
|
|
||||||
static const auto s_resourcePrefix = ":/qt-project.org/qmime/"_L1;
|
static const auto s_resourcePrefix = ":/qt-project.org/qmime/"_L1;
|
||||||
static const auto s_inodeMimetype = "inode/directory"_L1;
|
static const auto s_inodeMimetype = "inode/directory"_L1;
|
||||||
@ -119,7 +127,6 @@ void tst_QMimeDatabase::initTestCase()
|
|||||||
if (QDir(m_localMimeDir).exists()) {
|
if (QDir(m_localMimeDir).exists()) {
|
||||||
QVERIFY2(QDir(m_localMimeDir).removeRecursively(), qPrintable(m_localMimeDir + ": " + qt_error_string()));
|
QVERIFY2(QDir(m_localMimeDir).removeRecursively(), qPrintable(m_localMimeDir + ": " + qt_error_string()));
|
||||||
}
|
}
|
||||||
QString errorMessage;
|
|
||||||
|
|
||||||
#ifdef USE_XDG_DATA_DIRS
|
#ifdef USE_XDG_DATA_DIRS
|
||||||
// Create a temporary "global" XDG data dir for later use
|
// Create a temporary "global" XDG data dir for later use
|
||||||
@ -139,6 +146,7 @@ void tst_QMimeDatabase::initTestCase()
|
|||||||
const QString freeDesktopXml = QStringLiteral("freedesktop.org.xml");
|
const QString freeDesktopXml = QStringLiteral("freedesktop.org.xml");
|
||||||
const QString xmlFileName = s_resourcePrefix + "packages/"_L1 + freeDesktopXml;
|
const QString xmlFileName = s_resourcePrefix + "packages/"_L1 + freeDesktopXml;
|
||||||
const QString xmlTargetFileName = globalPackageDir + QLatin1Char('/') + freeDesktopXml;
|
const QString xmlTargetFileName = globalPackageDir + QLatin1Char('/') + freeDesktopXml;
|
||||||
|
QString errorMessage;
|
||||||
QVERIFY2(copyResourceFile(xmlFileName, xmlTargetFileName, &errorMessage), qPrintable(errorMessage));
|
QVERIFY2(copyResourceFile(xmlFileName, xmlTargetFileName, &errorMessage), qPrintable(errorMessage));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -146,14 +154,6 @@ void tst_QMimeDatabase::initTestCase()
|
|||||||
if (m_testSuite.isEmpty())
|
if (m_testSuite.isEmpty())
|
||||||
qWarning("%s", qPrintable(testSuiteWarning()));
|
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 = s_resourcePrefix + QLatin1String(additionalMimeFiles[i]);
|
|
||||||
QVERIFY2(QFile::exists(resourceFilePath), qPrintable(errorMessage.arg(resourceFilePath)));
|
|
||||||
m_additionalMimeFileNames.append(QLatin1String(additionalMimeFiles[i]));
|
|
||||||
m_additionalMimeFilePaths.append(resourceFilePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
initTestCaseInternal();
|
initTestCaseInternal();
|
||||||
m_isUsingCacheProvider = !qEnvironmentVariableIsSet("QT_NO_MIME_CACHE");
|
m_isUsingCacheProvider = !qEnvironmentVariableIsSet("QT_NO_MIME_CACHE");
|
||||||
}
|
}
|
||||||
@ -1074,6 +1074,30 @@ QT_BEGIN_NAMESPACE
|
|||||||
extern Q_CORE_EXPORT int qmime_secondsBetweenChecks; // see qmimeprovider.cpp
|
extern Q_CORE_EXPORT int qmime_secondsBetweenChecks; // see qmimeprovider.cpp
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
void copyFiles(const QSpan<const char *const> &additionalMimeFiles, const QString &destDir)
|
||||||
|
{
|
||||||
|
const QString notFoundErrorMessage = QString::fromLatin1("Cannot find '%1'");
|
||||||
|
for (const char *mimeFile : additionalMimeFiles) {
|
||||||
|
const QString resourceFilePath = s_resourcePrefix + QLatin1String(mimeFile);
|
||||||
|
QVERIFY2(QFile::exists(resourceFilePath),
|
||||||
|
qPrintable(notFoundErrorMessage.arg(resourceFilePath)));
|
||||||
|
|
||||||
|
const QString destFile = destDir + QLatin1String(mimeFile);
|
||||||
|
QFile::remove(destFile);
|
||||||
|
QString errorMessage;
|
||||||
|
QVERIFY2(copyResourceFile(resourceFilePath, destFile, &errorMessage),
|
||||||
|
qPrintable(errorMessage));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void deleteFiles(const QSpan<const char *const> &additionalMimeFiles, const QString &destDir)
|
||||||
|
{
|
||||||
|
for (const char *mimeFile : additionalMimeFiles) {
|
||||||
|
const QString destFile = destDir + QLatin1String(mimeFile);
|
||||||
|
QFile::remove(destFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void tst_QMimeDatabase::installNewGlobalMimeType()
|
void tst_QMimeDatabase::installNewGlobalMimeType()
|
||||||
{
|
{
|
||||||
#if !defined(USE_XDG_DATA_DIRS)
|
#if !defined(USE_XDG_DATA_DIRS)
|
||||||
@ -1093,18 +1117,11 @@ void tst_QMimeDatabase::installNewGlobalMimeType()
|
|||||||
if (!QFileInfo(destDir).isDir())
|
if (!QFileInfo(destDir).isDir())
|
||||||
QVERIFY(QDir(m_globalXdgDir).mkpath(destDir));
|
QVERIFY(QDir(m_globalXdgDir).mkpath(destDir));
|
||||||
|
|
||||||
QString errorMessage;
|
copyFiles(additionalGlobalMimeFiles, destDir);
|
||||||
for (int i = 0; i < m_additionalMimeFileNames.size(); ++i) {
|
QVERIFY(!QTest::currentTestFailed());
|
||||||
const QString destFile = destDir + m_additionalMimeFileNames.at(i);
|
|
||||||
QFile::remove(destFile);
|
|
||||||
QVERIFY2(copyResourceFile(m_additionalMimeFilePaths.at(i), destFile, &errorMessage), qPrintable(errorMessage));
|
|
||||||
}
|
|
||||||
if (m_isUsingCacheProvider && !waitAndRunUpdateMimeDatabase(mimeDir))
|
if (m_isUsingCacheProvider && !waitAndRunUpdateMimeDatabase(mimeDir))
|
||||||
QSKIP("shared-mime-info not found, skipping mime.cache test");
|
QSKIP("shared-mime-info not found, skipping mime.cache test");
|
||||||
|
|
||||||
if (!m_isUsingCacheProvider)
|
|
||||||
ignoreInvalidMimetypeWarnings(mimeDir);
|
|
||||||
|
|
||||||
QCOMPARE(db.mimeTypeForFile(QLatin1String("foo.ymu"), QMimeDatabase::MatchExtension).name(),
|
QCOMPARE(db.mimeTypeForFile(QLatin1String("foo.ymu"), QMimeDatabase::MatchExtension).name(),
|
||||||
QString::fromLatin1("text/x-SuSE-ymu"));
|
QString::fromLatin1("text/x-SuSE-ymu"));
|
||||||
QVERIFY(db.mimeTypeForName(QLatin1String("text/x-suse-ymp")).isValid());
|
QVERIFY(db.mimeTypeForName(QLatin1String("text/x-suse-ymp")).isValid());
|
||||||
@ -1118,12 +1135,6 @@ void tst_QMimeDatabase::installNewGlobalMimeType()
|
|||||||
QCOMPARE(db.mimeTypeForFile(qmlTestFile).name(),
|
QCOMPARE(db.mimeTypeForFile(qmlTestFile).name(),
|
||||||
QString::fromLatin1("text/x-qml"));
|
QString::fromLatin1("text/x-qml"));
|
||||||
|
|
||||||
{
|
|
||||||
QMimeType objcsrc = db.mimeTypeForName(QStringLiteral("text/x-objcsrc"));
|
|
||||||
QVERIFY(objcsrc.isValid());
|
|
||||||
QCOMPARE(objcsrc.globPatterns(), QStringList());
|
|
||||||
}
|
|
||||||
|
|
||||||
const QString fooTestFile = s_resourcePrefix + "magic-and-hierarchy.foo"_L1;
|
const QString fooTestFile = s_resourcePrefix + "magic-and-hierarchy.foo"_L1;
|
||||||
QCOMPARE(db.mimeTypeForFile(fooTestFile).name(), QString::fromLatin1("application/foo"));
|
QCOMPARE(db.mimeTypeForFile(fooTestFile).name(), QString::fromLatin1("application/foo"));
|
||||||
|
|
||||||
@ -1145,8 +1156,7 @@ void tst_QMimeDatabase::installNewGlobalMimeType()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now test removing the mimetype definitions again
|
// Now test removing the mimetype definitions again
|
||||||
for (int i = 0; i < m_additionalMimeFileNames.size(); ++i)
|
deleteFiles(additionalGlobalMimeFiles, destDir);
|
||||||
QFile::remove(destDir + m_additionalMimeFileNames.at(i));
|
|
||||||
if (m_isUsingCacheProvider && !waitAndRunUpdateMimeDatabase(mimeDir))
|
if (m_isUsingCacheProvider && !waitAndRunUpdateMimeDatabase(mimeDir))
|
||||||
QSKIP("shared-mime-info not found, skipping mime.cache test");
|
QSKIP("shared-mime-info not found, skipping mime.cache test");
|
||||||
QCOMPARE(db.mimeTypeForFile(QLatin1String("foo.ymu"), QMimeDatabase::MatchExtension).name(),
|
QCOMPARE(db.mimeTypeForFile(QLatin1String("foo.ymu"), QMimeDatabase::MatchExtension).name(),
|
||||||
@ -1170,12 +1180,9 @@ void tst_QMimeDatabase::installNewLocalMimeType()
|
|||||||
|
|
||||||
const QString destDir = m_localMimeDir + QLatin1String("/packages/");
|
const QString destDir = m_localMimeDir + QLatin1String("/packages/");
|
||||||
QVERIFY(QDir().mkpath(destDir));
|
QVERIFY(QDir().mkpath(destDir));
|
||||||
QString errorMessage;
|
|
||||||
for (int i = 0; i < m_additionalMimeFileNames.size(); ++i) {
|
copyFiles(additionalLocalMimeFiles, destDir);
|
||||||
const QString destFile = destDir + m_additionalMimeFileNames.at(i);
|
QVERIFY(!QTest::currentTestFailed());
|
||||||
QFile::remove(destFile);
|
|
||||||
QVERIFY2(copyResourceFile(m_additionalMimeFilePaths.at(i), destFile, &errorMessage), qPrintable(errorMessage));
|
|
||||||
}
|
|
||||||
if (m_isUsingCacheProvider && !waitAndRunUpdateMimeDatabase(m_localMimeDir)) {
|
if (m_isUsingCacheProvider && !waitAndRunUpdateMimeDatabase(m_localMimeDir)) {
|
||||||
const QString skipWarning = QStringLiteral("shared-mime-info not found, skipping mime.cache test (")
|
const QString skipWarning = QStringLiteral("shared-mime-info not found, skipping mime.cache test (")
|
||||||
+ QDir::toNativeSeparators(m_localMimeDir) + QLatin1Char(')');
|
+ QDir::toNativeSeparators(m_localMimeDir) + QLatin1Char(')');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user