diff options
Diffstat (limited to 'tests/auto/corelib/io')
17 files changed, 333 insertions, 54 deletions
diff --git a/tests/auto/corelib/io/qdir/tst_qdir.cpp b/tests/auto/corelib/io/qdir/tst_qdir.cpp index 52e7ebadb1..1162fb31e4 100644 --- a/tests/auto/corelib/io/qdir/tst_qdir.cpp +++ b/tests/auto/corelib/io/qdir/tst_qdir.cpp @@ -528,7 +528,7 @@ void tst_QDir::removeRecursivelyFailure() #ifdef Q_OS_UNIX QFile dirAsFile(path); // yay, I have to use QFile to change a dir's permissions... - QVERIFY(dirAsFile.setPermissions(QFile::Permissions(0))); // no permissions + QVERIFY(dirAsFile.setPermissions({})); // no permissions QVERIFY(!QDir().rmdir(path)); QDir dir(path); @@ -1786,9 +1786,9 @@ void tst_QDir::searchPaths() { QFETCH(QString, filename); QFETCH(QString, searchPathPrefixes); - QStringList searchPathPrefixList = searchPathPrefixes.split(";", QString::SkipEmptyParts); + QStringList searchPathPrefixList = searchPathPrefixes.split(";", Qt::SkipEmptyParts); QFETCH(QString, searchPaths); - QStringList searchPathsList = searchPaths.split(";", QString::SkipEmptyParts); + QStringList searchPathsList = searchPaths.split(";", Qt::SkipEmptyParts); QFETCH(QString, expectedAbsolutePath); bool exists = !expectedAbsolutePath.isEmpty(); diff --git a/tests/auto/corelib/io/qdiriterator/tst_qdiriterator.cpp b/tests/auto/corelib/io/qdiriterator/tst_qdiriterator.cpp index 0b125925bb..00e1c74d07 100644 --- a/tests/auto/corelib/io/qdiriterator/tst_qdiriterator.cpp +++ b/tests/auto/corelib/io/qdiriterator/tst_qdiriterator.cpp @@ -236,7 +236,7 @@ void tst_QDirIterator::iterateRelativeDirectory_data() QTest::addColumn<QStringList>("entries"); QTest::newRow("no flags") - << QString("entrylist") << QDirIterator::IteratorFlags(0) + << QString("entrylist") << QDirIterator::IteratorFlags{} << QDir::Filters(QDir::NoFilter) << QStringList("*") << QString( "entrylist/.," @@ -252,7 +252,7 @@ void tst_QDirIterator::iterateRelativeDirectory_data() "entrylist/writable").split(','); QTest::newRow("NoDot") - << QString("entrylist") << QDirIterator::IteratorFlags(0) + << QString("entrylist") << QDirIterator::IteratorFlags{} << QDir::Filters(QDir::AllEntries | QDir::NoDot) << QStringList("*") << QString( "entrylist/..," @@ -267,7 +267,7 @@ void tst_QDirIterator::iterateRelativeDirectory_data() "entrylist/writable").split(','); QTest::newRow("NoDotDot") - << QString("entrylist") << QDirIterator::IteratorFlags(0) + << QString("entrylist") << QDirIterator::IteratorFlags{} << QDir::Filters(QDir::AllEntries | QDir::NoDotDot) << QStringList("*") << QString( "entrylist/.," @@ -282,7 +282,7 @@ void tst_QDirIterator::iterateRelativeDirectory_data() "entrylist/writable").split(','); QTest::newRow("NoDotAndDotDot") - << QString("entrylist") << QDirIterator::IteratorFlags(0) + << QString("entrylist") << QDirIterator::IteratorFlags{} << QDir::Filters(QDir::AllEntries | QDir::NoDotAndDotDot) << QStringList("*") << QString( "entrylist/file," @@ -335,12 +335,12 @@ void tst_QDirIterator::iterateRelativeDirectory_data() "entrylist/writable").split(','); QTest::newRow("empty, default") - << QString("empty") << QDirIterator::IteratorFlags(0) + << QString("empty") << QDirIterator::IteratorFlags{} << QDir::Filters(QDir::NoFilter) << QStringList("*") << QString("empty/.,empty/..").split(','); QTest::newRow("empty, QDir::NoDotAndDotDot") - << QString("empty") << QDirIterator::IteratorFlags(0) + << QString("empty") << QDirIterator::IteratorFlags{} << QDir::Filters(QDir::NoDotAndDotDot) << QStringList("*") << QStringList(); } @@ -399,13 +399,13 @@ void tst_QDirIterator::iterateResource_data() QTest::addColumn<QStringList>("nameFilters"); QTest::addColumn<QStringList>("entries"); - QTest::newRow("invalid") << QString::fromLatin1(":/testdata/burpaburpa") << QDirIterator::IteratorFlags(0) + QTest::newRow("invalid") << QString::fromLatin1(":/testdata/burpaburpa") << QDirIterator::IteratorFlags{} << QDir::Filters(QDir::NoFilter) << QStringList(QLatin1String("*")) << QStringList(); - QTest::newRow(":/testdata") << QString::fromLatin1(":/testdata/") << QDirIterator::IteratorFlags(0) + QTest::newRow(":/testdata") << QString::fromLatin1(":/testdata/") << QDirIterator::IteratorFlags{} << QDir::Filters(QDir::NoFilter) << QStringList(QLatin1String("*")) << QString::fromLatin1(":/testdata/entrylist").split(QLatin1String(",")); - QTest::newRow(":/testdata/entrylist") << QString::fromLatin1(":/testdata/entrylist") << QDirIterator::IteratorFlags(0) + QTest::newRow(":/testdata/entrylist") << QString::fromLatin1(":/testdata/entrylist") << QDirIterator::IteratorFlags{} << QDir::Filters(QDir::NoFilter) << QStringList(QLatin1String("*")) << QString::fromLatin1(":/testdata/entrylist/directory,:/testdata/entrylist/file").split(QLatin1String(",")); QTest::newRow(":/testdata recursive") << QString::fromLatin1(":/testdata") << QDirIterator::IteratorFlags(QDirIterator::Subdirectories) diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp index b8ae95dd93..350bff0652 100644 --- a/tests/auto/corelib/io/qfile/tst_qfile.cpp +++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp @@ -279,6 +279,9 @@ private slots: void reuseQFile(); + void moveToTrash_data(); + void moveToTrash(); + private: #ifdef BUILTIN_TESTDATA QSharedPointer<QTemporaryDir> m_dataDir; @@ -499,7 +502,7 @@ void tst_QFile::initTestCase() file.write("b", 1); file.close(); #ifndef Q_OS_WIN // Not supported on Windows. - QVERIFY2(file.setPermissions(0), qPrintable(file.errorString())); + QVERIFY2(file.setPermissions({ }), qPrintable(file.errorString())); #else QVERIFY2(file.open(QFile::WriteOnly), msgOpenFailed(file).constData()); #endif @@ -2211,7 +2214,7 @@ public: QStringList entryList(QDir::Filters, const QStringList &) const { return QStringList(); } bool caseSensitive() const { return false; } bool isRelativePath() const { return false; } - FileFlags fileFlags(FileFlags) const { return 0; } + FileFlags fileFlags(FileFlags) const { return { }; } bool chmod(uint) { return false; } QString fileName(FileName) const { return name; } uint ownerId(FileOwner) const { return 0; } @@ -3672,5 +3675,142 @@ void tst_QFile::reuseQFile() } } +void tst_QFile::moveToTrash_data() +{ + QTest::addColumn<QString>("source"); + QTest::addColumn<bool>("create"); + QTest::addColumn<bool>("result"); + + // success cases + { + QTemporaryFile temp; + QVERIFY(temp.open()); + QTest::newRow("temporary file") << temp.fileName() << true << true; + } + { + QTemporaryDir tempDir; + tempDir.setAutoRemove(false); + QTest::newRow("temporary dir") + << tempDir.path() + QLatin1Char('/') + << true << true; + } + { + QTemporaryDir homeDir(QDir::homePath() + QLatin1String("/XXXXXX")); + homeDir.setAutoRemove(false); + QTemporaryFile homeFile(homeDir.path() + + QLatin1String("/tst_qfile-XXXXXX")); + homeFile.open(); + QTest::newRow("home file") + << homeFile.fileName() + << true << true; + + QTest::newRow("home dir") + << homeDir.path() + QLatin1Char('/') + << true << true; + } + QTest::newRow("relative") << QStringLiteral("tst_qfile_moveToTrash.tmp") << true << true; + + // failure cases + QTest::newRow("root") << QDir::rootPath() << false << false; + QTest::newRow("no-such-file") << QString::fromLatin1("no/such/file") << false << false; +} + +void tst_QFile::moveToTrash() +{ + QFETCH(QString, source); + QFETCH(bool, create); + QFETCH(bool, result); + + /* This test makes assumptions about the file system layout + which might be wrong - moveToTrash may fail if the file lives + on a file system that is different from the home file system, and + has no .Trash directory. + */ + const bool mayFail = QStorageInfo(source) != QStorageInfo(QDir::home()); + +#if defined(Q_OS_WINRT) + QSKIP("WinRT does not have a trash", SkipAll); +#endif + + auto ensureFile = [](const QString &source, bool create) { + if (QFileInfo::exists(source) || !create) + return; + if (source.endsWith(QLatin1Char('/'))) { + QDir::root().mkdir(source); + QFile file(source + QLatin1String("test")); + if (!file.open(QIODevice::WriteOnly)) + QSKIP("Couldn't create directory with file"); + } else { + QFile sourceFile(source); + QVERIFY2(sourceFile.open(QFile::WriteOnly | QFile::Text), qPrintable(sourceFile.errorString())); + sourceFile.close(); + } + }; + auto cleanupFile = [source, create]() { + if (!QFileInfo::exists(source) || !create) + return; + if (source.endsWith(QLatin1Char('/'))) { + QDir(source).removeRecursively(); + } else { + QFile sourceFile(source); + sourceFile.remove(); + } + }; + // non-static version + { + ensureFile(source, create); + QFile sourceFile(source); + const bool success = sourceFile.moveToTrash(); + + // tolerate moveToTrash failing + if (result && !success && mayFail) + result = false; + + if (result) { + // if any of the test fails, we still want to remove the file + auto onFailure = qScopeGuard(cleanupFile); + QVERIFY2(success, qPrintable(sourceFile.errorString())); + QCOMPARE(sourceFile.error(), QFile::NoError); + QVERIFY(source != sourceFile.fileName()); + if (!sourceFile.fileName().isEmpty()) { + QVERIFY2(sourceFile.exists(), qPrintable(sourceFile.fileName())); + // remove file/dir in trash as well, don't fill disk + if (source.endsWith(QLatin1Char('/'))) + QDir(sourceFile.fileName()).removeRecursively(); + else + sourceFile.remove(); + } + } else { + QVERIFY(!success); + QVERIFY(!sourceFile.errorString().isEmpty()); + QCOMPARE(source, sourceFile.fileName()); + } + } + + // don't retry + if (mayFail) + return; + + // static version + { + ensureFile(source, create); + QString pathInTrash; + const bool success = QFile::moveToTrash(source, &pathInTrash); + QCOMPARE(success, result); + if (result) { + auto onFailure = qScopeGuard(cleanupFile); + QVERIFY(source != pathInTrash); + if (!pathInTrash.isEmpty()) { + // remove file/dir in trash as well, don't fill disk + QVERIFY2(QFile::exists(pathInTrash), qPrintable(pathInTrash)); + if (source.endsWith(QLatin1Char('/'))) + QDir(pathInTrash).removeRecursively(); + else + QFile::remove(pathInTrash); + } + } + } +} + QTEST_MAIN(tst_QFile) #include "tst_qfile.moc" diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp index 0597a7d521..09ef0ea44f 100644 --- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp @@ -1813,19 +1813,22 @@ void tst_QFileInfo::ntfsJunctionPointsAndSymlinks() QVERIFY2(creationResult == ERROR_SUCCESS, qPrintable(errorMessage)); QFileInfo fi(path); - const bool actualIsSymLink = fi.isSymbolicLink(); + auto guard = qScopeGuard([&fi, this]() { + // Ensure that junctions, mountpoints are removed. If this fails, do not remove + // temporary directory to prevent it from trashing the system. + if (fi.isDir()) { + if (!QDir().rmdir(fi.filePath())) { + qWarning("Unable to remove NTFS junction '%ls', keeping '%ls'.", + qUtf16Printable(fi.fileName()), + qUtf16Printable(QDir::toNativeSeparators(m_dir.path()))); + m_dir.setAutoRemove(false); + } + } + }); const QString actualSymLinkTarget = isSymLink ? fi.symLinkTarget() : QString(); const QString actualCanonicalFilePath = isSymLink ? fi.canonicalFilePath() : QString(); - // Ensure that junctions, mountpoints are removed. If this fails, do not remove - // temporary directory to prevent it from trashing the system. - if (fi.isDir()) { - if (!QDir().rmdir(fi.filePath())) { - qWarning("Unable to remove NTFS junction '%s'', keeping '%s'.", - qPrintable(fi.fileName()), qPrintable(QDir::toNativeSeparators(m_dir.path()))); - m_dir.setAutoRemove(false); - } - } - QCOMPARE(actualIsSymLink, isSymLink); + QCOMPARE(fi.isJunction(), resource.type == NtfsTestResource::Junction); + QCOMPARE(fi.isSymbolicLink(), isSymLink); if (isSymLink) { QCOMPARE(actualSymLinkTarget, linkTarget); QCOMPARE(actualCanonicalFilePath, canonicalFilePath); diff --git a/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp b/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp index 8703b15dda..4969e417f4 100644 --- a/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp +++ b/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp @@ -444,7 +444,7 @@ void tst_QLockFile::noPermissions() const QString fileName = dir.path() + "/staleLock"; QFile dirAsFile(dir.path()); // I have to use QFile to change a dir's permissions... - QVERIFY2(dirAsFile.setPermissions(QFile::Permissions(0)), qPrintable(dir.path())); // no permissions + QVERIFY2(dirAsFile.setPermissions(QFile::Permissions{}), qPrintable(dir.path())); // no permissions PermissionRestorer permissionRestorer(dir.path()); QLockFile lockFile(fileName); diff --git a/tests/auto/corelib/io/qloggingregistry/tst_qloggingregistry.cpp b/tests/auto/corelib/io/qloggingregistry/tst_qloggingregistry.cpp index a10e706ed7..4c269822d6 100644 --- a/tests/auto/corelib/io/qloggingregistry/tst_qloggingregistry.cpp +++ b/tests/auto/corelib/io/qloggingregistry/tst_qloggingregistry.cpp @@ -158,10 +158,13 @@ private slots: QFETCH(QtMsgType, msgType); QFETCH(LoggingRuleState, result); - QLoggingRule rule(QStringRef(&pattern), true); + const auto categoryL1 = category.toLatin1(); + const auto categoryL1S = QLatin1String(categoryL1); + + QLoggingRule rule(pattern, true); LoggingRuleState state = Invalid; if (rule.flags != 0) { - switch (rule.pass(category, msgType)) { + switch (rule.pass(categoryL1S, msgType)) { case -1: QFAIL("Shoudn't happen, we set pattern to true"); break; case 0: state = NoMatch; break; case 1: state = Match; break; diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp index e799369c8a..9495631c23 100644 --- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp +++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. -** Copyright (C) 2016 Intel Corporation. +** Copyright (C) 2020 The Qt Company Ltd. +** Copyright (C) 2020 Intel Corporation. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -40,6 +40,12 @@ #include <QtCore/QDebug> #include <QtCore/QMetaType> #include <QtNetwork/QHostInfo> + +#include <qplatformdefs.h> +#ifdef Q_OS_UNIX +# include <private/qcore_unix_p.h> +#endif + #include <stdlib.h> typedef void (QProcess::*QProcessFinishedSignal1)(int); @@ -59,6 +65,7 @@ private slots: void getSetCheck(); void constructing(); void simpleStart(); + void setupChildProcess(); void startWithOpen(); void startWithOldOpen(); void execute(); @@ -277,6 +284,51 @@ void tst_QProcess::simpleStart() QCOMPARE(qvariant_cast<QProcess::ProcessState>(spy.at(2).at(0)), QProcess::NotRunning); } +void tst_QProcess::setupChildProcess() +{ + /* This test exists because in Qt 5.15, the Unix version of QProcess has + * some code that depends on whether it's an actual QProcess or a + * derived class */ + static const char setupChildMessage[] = "Called from setupChildProcess()"; + class DerivedProcessClass : public QProcess { + public: + int fd; + DerivedProcessClass(int fd) : fd(fd) + { + } + + protected: + void setupChildProcess() override + { + QT_WRITE(fd, setupChildMessage, sizeof(setupChildMessage) - 1); + QT_CLOSE(fd); + } + }; + + int pipes[2] = { -1 , -1 }; +#ifdef Q_OS_UNIX + QVERIFY(qt_safe_pipe(pipes) == 0); +#endif + + DerivedProcessClass process(pipes[1]); + process.start("testProcessNormal/testProcessNormal"); + if (process.state() != QProcess::Starting) + QCOMPARE(process.state(), QProcess::Running); + QVERIFY2(process.waitForStarted(5000), qPrintable(process.errorString())); + +#ifdef Q_OS_UNIX + char buf[sizeof setupChildMessage] = {}; + qt_safe_close(pipes[1]); + QCOMPARE(qt_safe_read(pipes[0], buf, sizeof(buf)), qint64(sizeof(setupChildMessage) - 1)); + QCOMPARE(buf, setupChildMessage); + qt_safe_close(pipes[0]); +#endif + + QVERIFY2(process.waitForFinished(5000), qPrintable(process.errorString())); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + QCOMPARE(process.exitCode(), 0); +} + void tst_QProcess::startWithOpen() { QProcess p; @@ -2439,7 +2491,7 @@ void tst_QProcess::finishProcessBeforeReadingDone() QVERIFY(process.waitForStarted()); loop.exec(); QStringList lines = QString::fromLocal8Bit(process.readAllStandardOutput()).split( - QRegExp(QStringLiteral("[\r\n]")), QString::SkipEmptyParts); + QRegExp(QStringLiteral("[\r\n]")), Qt::SkipEmptyParts); QVERIFY(!lines.isEmpty()); QCOMPARE(lines.last(), QStringLiteral("10239 -this is a number")); QCOMPARE(process.exitStatus(), QProcess::NormalExit); @@ -2671,7 +2723,7 @@ void tst_QProcess::finishProcessBeforeReadingDone_deprecated() QVERIFY(process.waitForStarted()); loop.exec(); QStringList lines = QString::fromLocal8Bit(process.readAllStandardOutput()).split( - QRegExp(QStringLiteral("[\r\n]")), QString::SkipEmptyParts); + QRegExp(QStringLiteral("[\r\n]")), Qt::SkipEmptyParts); QVERIFY(!lines.isEmpty()); QCOMPARE(lines.last(), QStringLiteral("10239 -this is a number")); QCOMPARE(process.exitStatus(), QProcess::NormalExit); diff --git a/tests/auto/corelib/io/qresourceengine/compressed.qrc b/tests/auto/corelib/io/qresourceengine/compressed.qrc new file mode 100644 index 0000000000..f7c7cbc20f --- /dev/null +++ b/tests/auto/corelib/io/qresourceengine/compressed.qrc @@ -0,0 +1,5 @@ +<RCC version="1.0"> + <qresource> + <file>zero.txt</file> + </qresource> +</RCC> diff --git a/tests/auto/corelib/io/qresourceengine/generateResources.sh b/tests/auto/corelib/io/qresourceengine/generateResources.sh new file mode 100755 index 0000000000..9894f6bfb7 --- /dev/null +++ b/tests/auto/corelib/io/qresourceengine/generateResources.sh @@ -0,0 +1,7 @@ +#!/bin/sh +count=`awk '/ZERO_FILE_LEN/ { print $3 }' tst_qresourceengine.cpp` +dd if=/dev/zero of=zero.txt bs=1 count=$count +rcc --binary -o uncompressed.rcc --no-compress compressed.qrc +rcc --binary -o zlib.rcc --compress-algo zlib --compress 9 compressed.qrc +rcc --binary -o zstd.rcc --compress-algo zstd --compress 19 compressed.qrc +rm zero.txt diff --git a/tests/auto/corelib/io/qresourceengine/qresourceengine_test.pro b/tests/auto/corelib/io/qresourceengine/qresourceengine_test.pro index f523116cc9..345e3d13b9 100644 --- a/tests/auto/corelib/io/qresourceengine/qresourceengine_test.pro +++ b/tests/auto/corelib/io/qresourceengine/qresourceengine_test.pro @@ -1,7 +1,7 @@ CONFIG += testcase TARGET = tst_qresourceengine -QT = core testlib +QT = core-private testlib SOURCES = tst_qresourceengine.cpp RESOURCES += testqrc/test.qrc @@ -15,7 +15,8 @@ QMAKE_DISTCLEAN += $${runtime_resource.target} TESTDATA += \ parentdir.txt \ - testqrc/* + testqrc/* \ + *.rcc GENERATED_TESTDATA = $${runtime_resource.target} android:!android-embedded { diff --git a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp index 44c8c4b681..902e6db12a 100644 --- a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp +++ b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp @@ -27,10 +27,10 @@ ** ****************************************************************************/ - #include <QtTest/QtTest> #include <QtCore/QCoreApplication> -#include <QtCore/QMimeDatabase> +#include <QtCore/QScopeGuard> +#include <QtCore/private/qglobal_p.h> class tst_QResourceEngine: public QObject { @@ -51,6 +51,8 @@ private slots: void checkUnregisterResource_data(); void checkUnregisterResource(); + void compressedResource_data(); + void compressedResource(); void checkStructure_data(); void checkStructure(); void searchPath_data(); @@ -106,6 +108,75 @@ void tst_QResourceEngine::cleanupTestCase() QVERIFY(QResource::unregisterResource(m_runtimeResourceRcc, "/secondary_root/")); } +void tst_QResourceEngine::compressedResource_data() +{ + QTest::addColumn<QString>("fileName"); + QTest::addColumn<int>("compressionAlgo"); + QTest::addColumn<bool>("supported"); + + QTest::newRow("uncompressed") + << QFINDTESTDATA("uncompressed.rcc") << int(QResource::NoCompression) << true; + QTest::newRow("zlib") + << QFINDTESTDATA("zlib.rcc") << int(QResource::ZlibCompression) << true; + QTest::newRow("zstd") + << QFINDTESTDATA("zstd.rcc") << int(QResource::ZstdCompression) << QT_CONFIG(zstd); +} + +// Note: generateResource.sh parses this line. Make sure it's a simple number. +#define ZERO_FILE_LEN 16384 +// End note +void tst_QResourceEngine::compressedResource() +{ + QFETCH(QString, fileName); + QFETCH(int, compressionAlgo); + QFETCH(bool, supported); + const QByteArray expectedData(ZERO_FILE_LEN, '\0'); + + QVERIFY(!QResource("zero.txt").isValid()); + QCOMPARE(QResource::registerResource(fileName), supported); + if (!supported) + return; + + auto unregister = qScopeGuard([=] { QResource::unregisterResource(fileName); }); + + QResource resource("zero.txt"); + QVERIFY(resource.isValid()); + QVERIFY(resource.size() > 0); + QVERIFY(resource.data()); + QCOMPARE(resource.compressionAlgorithm(), QResource::Compression(compressionAlgo)); + + if (compressionAlgo == QResource::NoCompression) { + QCOMPARE(resource.size(), ZERO_FILE_LEN); + QCOMPARE(memcmp(resource.data(), expectedData.data(), ZERO_FILE_LEN), 0); + + // API guarantees it will be QByteArray::fromRawData: + QCOMPARE(static_cast<const void *>(resource.uncompressedData().constData()), + static_cast<const void *>(resource.data())); + } else { + // reasonable expectation: + QVERIFY(resource.size() < ZERO_FILE_LEN); + } + + // using the engine + QFile f(":/zero.txt"); + QVERIFY(f.exists()); + QVERIFY(f.open(QIODevice::ReadOnly)); + + // verify that we can decompress correctly + QCOMPARE(resource.uncompressedSize(), ZERO_FILE_LEN); + QCOMPARE(f.size(), ZERO_FILE_LEN); + + QByteArray data = resource.uncompressedData(); + QCOMPARE(data.size(), expectedData.size()); + QCOMPARE(data, expectedData); + + // decompression through the engine + data = f.readAll(); + QCOMPARE(data.size(), expectedData.size()); + QCOMPARE(data, expectedData); +} + + void tst_QResourceEngine::checkStructure_data() { QTest::addColumn<QString>("pathName"); @@ -119,24 +190,20 @@ void tst_QResourceEngine::checkStructure_data() QStringList rootContents; rootContents << QLatin1String("aliasdir") +#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED) + << QLatin1String("android_testdata") +#endif << QLatin1String("otherdir") - << QLatin1String("qt-project.org") << QLatin1String("runtime_resource") << QLatin1String("searchpath1") << QLatin1String("searchpath2") << QLatin1String("secondary_root") << QLatin1String("staticplugin") << QLatin1String("test") - << QLatin1String("withoutslashes"); - -#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED) - rootContents.insert(1, QLatin1String("android_testdata")); -#endif - #if defined(BUILTIN_TESTDATA) - rootContents.insert(9, QLatin1String("testqrc")); + << QLatin1String("testqrc") #endif - + << QLatin1String("withoutslashes"); QTest::newRow("root dir") << QString(":/") << QByteArray() @@ -145,7 +212,13 @@ void tst_QResourceEngine::checkStructure_data() << "parentdir.txt" << "runtime_resource.rcc" #endif - << "search_file.txt") + << "search_file.txt" +#if defined(BUILTIN_TESTDATA) + << "uncompressed.rcc" + << "zlib.rcc" + << "zstd.rcc" +#endif + ) << rootContents << QLocale::c() << qlonglong(0); @@ -352,11 +425,6 @@ void tst_QResourceEngine::checkStructure() QFETCH(QLocale, locale); QFETCH(qlonglong, contentsSize); - // We rely on the existence of the root "qt-project.org" in resources. For - // static builds on MSVC these resources are only added if they are used. - QMimeDatabase db; - Q_UNUSED(db); - bool directory = (containedDirs.size() + containedFiles.size() > 0); QLocale::setDefault(locale); diff --git a/tests/auto/corelib/io/qresourceengine/uncompressed.rcc b/tests/auto/corelib/io/qresourceengine/uncompressed.rcc Binary files differnew file mode 100644 index 0000000000..4b009f73d5 --- /dev/null +++ b/tests/auto/corelib/io/qresourceengine/uncompressed.rcc diff --git a/tests/auto/corelib/io/qresourceengine/zlib.rcc b/tests/auto/corelib/io/qresourceengine/zlib.rcc Binary files differnew file mode 100644 index 0000000000..66f79fa630 --- /dev/null +++ b/tests/auto/corelib/io/qresourceengine/zlib.rcc diff --git a/tests/auto/corelib/io/qresourceengine/zstd.rcc b/tests/auto/corelib/io/qresourceengine/zstd.rcc Binary files differnew file mode 100644 index 0000000000..672fa05d14 --- /dev/null +++ b/tests/auto/corelib/io/qresourceengine/zstd.rcc diff --git a/tests/auto/corelib/io/qsavefile/tst_qsavefile.cpp b/tests/auto/corelib/io/qsavefile/tst_qsavefile.cpp index f1327933c4..8e500d7c8e 100644 --- a/tests/auto/corelib/io/qsavefile/tst_qsavefile.cpp +++ b/tests/auto/corelib/io/qsavefile/tst_qsavefile.cpp @@ -356,7 +356,7 @@ void tst_QSaveFile::transactionalWriteErrorRenaming() #ifdef Q_OS_UNIX // Make rename() fail for lack of permissions in the directory QFile dirAsFile(dir.path()); // yay, I have to use QFile to change a dir's permissions... - QVERIFY(dirAsFile.setPermissions(QFile::Permissions(0))); // no permissions + QVERIFY(dirAsFile.setPermissions(QFile::Permissions{})); // no permissions PermissionRestorer permissionRestorer(dir.path()); #else // Windows: Make rename() fail for lack of permissions on an existing target file diff --git a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp index dae4e66106..d0fbdb7a2a 100644 --- a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp +++ b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp @@ -360,7 +360,7 @@ static inline QFileInfo findSh() QLatin1String sh("/sh"); QByteArray pEnv = qgetenv("PATH"); const QLatin1Char pathSep(':'); - const QStringList rawPaths = QString::fromLocal8Bit(pEnv.constData()).split(pathSep, QString::SkipEmptyParts); + const QStringList rawPaths = QString::fromLocal8Bit(pEnv.constData()).split(pathSep, Qt::SkipEmptyParts); foreach (const QString &path, rawPaths) { if (QFile::exists(path + sh)) return path + sh; diff --git a/tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp b/tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp index bcf6d6c32b..5c6e633749 100644 --- a/tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp +++ b/tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp @@ -848,7 +848,7 @@ void tst_QUrlInternal::correctEncodedMistakes() QString dataTag = QTest::currentDataTag(); QString output = dataTag; - if (!qt_urlRecode(output, input.constData(), input.constData() + input.length(), 0)) + if (!qt_urlRecode(output, input.constData(), input.constData() + input.length(), { })) output += input; QCOMPARE(output, dataTag + expected); |