summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/io')
-rw-r--r--tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp28
-rw-r--r--tests/auto/corelib/io/qnodebug/tst_qnodebug.cpp4
-rw-r--r--tests/auto/corelib/io/qresourceengine/compressed.qrc5
-rwxr-xr-xtests/auto/corelib/io/qresourceengine/generateResources.sh7
-rw-r--r--tests/auto/corelib/io/qresourceengine/qresourceengine_test.pro5
-rw-r--r--tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp102
-rw-r--r--tests/auto/corelib/io/qresourceengine/uncompressed.rccbin0 -> 16478 bytes
-rw-r--r--tests/auto/corelib/io/qresourceengine/zlib.rccbin0 -> 137 bytes
-rw-r--r--tests/auto/corelib/io/qresourceengine/zstd.rccbin0 -> 112 bytes
9 files changed, 130 insertions, 21 deletions
diff --git a/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp b/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp
index cdd1f6361e..7d88601e54 100644
--- a/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp
+++ b/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp
@@ -34,6 +34,9 @@
#include <QElapsedTimer>
#include <QTextStream>
#include <QDir>
+#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
+#include <windows.h>
+#endif
/* All tests need to run in temporary directories not used
* by the application to avoid non-deterministic failures on Windows
@@ -79,6 +82,9 @@ private slots:
void signalsEmittedAfterFileMoved();
void watchUnicodeCharacters();
+#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
+ void watchDirectoryAttributeChanges();
+#endif
private:
QString m_tempDirPattern;
@@ -813,5 +819,27 @@ void tst_QFileSystemWatcher::watchUnicodeCharacters()
QTRY_COMPARE(changedSpy.count(), 1);
}
+#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
+void tst_QFileSystemWatcher::watchDirectoryAttributeChanges()
+{
+ QTemporaryDir temporaryDirectory(m_tempDirPattern);
+ QVERIFY2(temporaryDirectory.isValid(), qPrintable(temporaryDirectory.errorString()));
+
+ QDir testDir(temporaryDirectory.path());
+ const QString subDir(QString::fromLatin1("attrib_test"));
+ QVERIFY(testDir.mkdir(subDir));
+ testDir = QDir(temporaryDirectory.path() + QDir::separator() + subDir);
+
+ QFileSystemWatcher watcher;
+ QVERIFY(watcher.addPath(temporaryDirectory.path()));
+ FileSystemWatcherSpy changedSpy(&watcher, FileSystemWatcherSpy::SpyOnDirectoryChanged);
+ QCOMPARE(changedSpy.count(), 0);
+ QVERIFY(SetFileAttributes(reinterpret_cast<LPCWSTR>(testDir.absolutePath().utf16()), FILE_ATTRIBUTE_HIDDEN) != 0);
+ QTRY_COMPARE(changedSpy.count(), 1);
+ QVERIFY(SetFileAttributes(reinterpret_cast<LPCWSTR>(testDir.absolutePath().utf16()), FILE_ATTRIBUTE_NORMAL) != 0);
+ QTRY_COMPARE(changedSpy.count(), 2);
+}
+#endif
+
QTEST_MAIN(tst_QFileSystemWatcher)
#include "tst_qfilesystemwatcher.moc"
diff --git a/tests/auto/corelib/io/qnodebug/tst_qnodebug.cpp b/tests/auto/corelib/io/qnodebug/tst_qnodebug.cpp
index b05c89a8bb..cf2079a407 100644
--- a/tests/auto/corelib/io/qnodebug/tst_qnodebug.cpp
+++ b/tests/auto/corelib/io/qnodebug/tst_qnodebug.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
@@ -65,7 +65,7 @@ void tst_QNoDebug::noDebugOutput() const
void tst_QNoDebug::streaming() const
{
QDateTime dt(QDate(1,2,3),QTime(4,5,6));
- const QByteArray debugString = dt.toString(u"yyyy-MM-dd HH:mm:ss.zzz t").toLatin1();
+ const QByteArray debugString = dt.toString(u"yyyy-MM-dd HH:mm:ss.zzz t").toLocal8Bit();
const QByteArray message = "QDateTime(" + debugString + " Qt::LocalTime)";
QTest::ignoreMessage(QtWarningMsg, message.constData());
qWarning() << dt;
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
new file mode 100644
index 0000000000..4b009f73d5
--- /dev/null
+++ b/tests/auto/corelib/io/qresourceengine/uncompressed.rcc
Binary files differ
diff --git a/tests/auto/corelib/io/qresourceengine/zlib.rcc b/tests/auto/corelib/io/qresourceengine/zlib.rcc
new file mode 100644
index 0000000000..66f79fa630
--- /dev/null
+++ b/tests/auto/corelib/io/qresourceengine/zlib.rcc
Binary files differ
diff --git a/tests/auto/corelib/io/qresourceengine/zstd.rcc b/tests/auto/corelib/io/qresourceengine/zstd.rcc
new file mode 100644
index 0000000000..672fa05d14
--- /dev/null
+++ b/tests/auto/corelib/io/qresourceengine/zstd.rcc
Binary files differ