diff options
author | Frederik Gladhorn <frederik.gladhorn@theqtcompany.com> | 2015-08-06 10:45:40 +0200 |
---|---|---|
committer | Frederik Gladhorn <frederik.gladhorn@theqtcompany.com> | 2015-08-06 10:54:01 +0200 |
commit | 77da617dc8e378a631ee8c15b1b414f16b87f147 (patch) | |
tree | 563f4f8e64e416774ea2b1599b896b589385168c /tests/auto/corelib/mimetypes | |
parent | c17134e2db4d364855aa78a0d3c47cb9ef964dd9 (diff) | |
parent | 01f3530650f9f6f4c08520263a3c62281d81e3fc (diff) |
Merge remote-tracking branch 'origin/5.5' into dev
Conflicts:
doc/global/qt-cpp-defines.qdocconf
src/3rdparty/forkfd/forkfd.c
src/corelib/codecs/qtextcodec.cpp
src/corelib/kernel/qmetatype.cpp
src/corelib/tools/qset.qdoc
src/gui/accessible/qaccessible.cpp
src/gui/image/qpixmapcache.cpp
src/opengl/qgl.cpp
src/tools/qdoc/generator.cpp
src/widgets/kernel/qwidget.cpp
tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
Change-Id: I4fbe1fa756a54c6843aa75f4ef70a1069ba7b085
Diffstat (limited to 'tests/auto/corelib/mimetypes')
-rw-r--r-- | tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp | 53 |
1 files changed, 45 insertions, 8 deletions
diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp index 7c32f2cc12..12abaf47c5 100644 --- a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp +++ b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp @@ -73,10 +73,45 @@ static inline QString testSuiteWarning() return result; } +static bool copyResourceFile(const QString &sourceFileName, const QString &targetFileName, + QString *errorMessage) +{ + + QFile sourceFile(sourceFileName); + if (!sourceFile.exists()) { + *errorMessage = QDir::toNativeSeparators(sourceFileName) + QLatin1String(" does not exist."); + return false; + } + if (!sourceFile.copy(targetFileName)) { + *errorMessage = QLatin1String("Cannot copy ") + + QDir::toNativeSeparators(sourceFileName) + QLatin1String(" to ") + + QDir::toNativeSeparators(targetFileName) + QLatin1String(": ") + + sourceFile.errorString(); + return false; + } + // QFile::copy() sets the permissions of the source file which are read-only for + // resource files. Set write permission to enable deletion of the temporary directory. + QFile targetFile(targetFileName); + if (!targetFile.setPermissions(targetFile.permissions() | QFileDevice::WriteUser)) { + *errorMessage = QLatin1String("Cannot set write permission on ") + + QDir::toNativeSeparators(targetFileName) + QLatin1String(": ") + + targetFile.errorString(); + return false; + } + return true; +} + // Set LANG before QCoreApplication is created Q_CONSTRUCTOR_FUNCTION(initializeLang) +static QString seedAndTemplate() +{ + qsrand(QDateTime::currentDateTimeUtc().toTime_t()); + return QDir::tempPath() + "/tst_qmimedatabase-XXXXXX"; +} + tst_QMimeDatabase::tst_QMimeDatabase() + : m_temporaryDir(seedAndTemplate()) { } @@ -103,15 +138,15 @@ void tst_QMimeDatabase::initTestCase() const QString freeDesktopXml = QStringLiteral("freedesktop.org.xml"); const QString xmlFileName = QLatin1String(RESOURCE_PREFIX) + freeDesktopXml; - QVERIFY2(QFileInfo(xmlFileName).exists(), qPrintable(xmlFileName + QStringLiteral(" does not exist"))); - QFile xml(xmlFileName); - QVERIFY(xml.copy(globalPackageDir + '/' + freeDesktopXml)); + const QString xmlTargetFileName = globalPackageDir + QLatin1Char('/') + freeDesktopXml; + QString errorMessage; + QVERIFY2(copyResourceFile(xmlFileName, xmlTargetFileName, &errorMessage), qPrintable(errorMessage)); m_testSuite = QFINDTESTDATA("testfiles"); if (m_testSuite.isEmpty()) qWarning("%s", qPrintable(testSuiteWarning())); - const QString errorMessage = QString::fromLatin1("Cannot find '%1'"); + errorMessage = QString::fromLatin1("Cannot find '%1'"); m_yastMimeTypes = QLatin1String(RESOURCE_PREFIX) + yastFileName; QVERIFY2(QFile::exists(m_yastMimeTypes), qPrintable(errorMessage.arg(yastFileName))); m_qmlAgainFileName = QLatin1String(RESOURCE_PREFIX) + qmlAgainFileName; @@ -836,8 +871,9 @@ void tst_QMimeDatabase::installNewGlobalMimeType() if (!QFileInfo(destDir).isDir()) QVERIFY(QDir(m_globalXdgDir).mkpath(destDir)); - QVERIFY(QFile::copy(m_yastMimeTypes, destFile)); - QVERIFY(QFile::copy(m_qmlAgainFileName, destQmlFile)); + QString errorMessage; + QVERIFY2(copyResourceFile(m_yastMimeTypes, destFile, &errorMessage), qPrintable(errorMessage)); + QVERIFY2(copyResourceFile(m_qmlAgainFileName, destQmlFile, &errorMessage), qPrintable(errorMessage)); if (!waitAndRunUpdateMimeDatabase(mimeDir)) QSKIP("shared-mime-info not found, skipping mime.cache test"); @@ -882,8 +918,9 @@ void tst_QMimeDatabase::installNewLocalMimeType() QFile::remove(destFile); const QString destQmlFile = destDir + QLatin1String(qmlAgainFileName); QFile::remove(destQmlFile); - QVERIFY(QFile::copy(m_yastMimeTypes, destFile)); - QVERIFY(QFile::copy(m_qmlAgainFileName, destQmlFile)); + QString errorMessage; + QVERIFY2(copyResourceFile(m_yastMimeTypes, destFile, &errorMessage), qPrintable(errorMessage)); + QVERIFY2(copyResourceFile(m_qmlAgainFileName, destQmlFile, &errorMessage), qPrintable(errorMessage)); if (!runUpdateMimeDatabase(mimeDir)) { const QString skipWarning = QStringLiteral("shared-mime-info not found, skipping mime.cache test (") + QDir::toNativeSeparators(mimeDir) + QLatin1Char(')'); |