summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp')
-rw-r--r--tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp81
1 files changed, 44 insertions, 37 deletions
diff --git a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp
index 317a57a44c..fc9b9ee201 100644
--- a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp
+++ b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp
@@ -1,31 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Copyright (C) 2019 Intel Corporation.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// Copyright (C) 2019 Intel Corporation.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QResource>
@@ -40,8 +15,10 @@ class tst_QResourceEngine: public QObject
public:
tst_QResourceEngine()
-#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED)
- : m_runtimeResourceRcc(QFileInfo(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + QStringLiteral("/runtime_resource.rcc")).absoluteFilePath())
+#ifdef Q_OS_ANDROID
+ : m_runtimeResourceRcc(
+ QFileInfo(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)
+ + QStringLiteral("/runtime_resource.rcc")).absoluteFilePath())
#else
: m_runtimeResourceRcc(QFINDTESTDATA("runtime_resource.rcc"))
#endif
@@ -60,9 +37,11 @@ private slots:
void searchPath_data();
void searchPath();
void doubleSlashInRoot();
+ void setLocale_data();
void setLocale();
void lastModified();
void resourcesInStaticPlugins();
+ void qtResourceEmpty();
private:
const QString m_runtimeResourceRcc;
@@ -71,7 +50,7 @@ private:
void tst_QResourceEngine::initTestCase()
{
-#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED)
+#ifdef Q_OS_ANDROID
QString sourcePath(QStringLiteral(":/android_testdata/"));
QString dataPath(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
@@ -79,7 +58,8 @@ void tst_QResourceEngine::initTestCase()
while (it.hasNext()) {
QFileInfo fileInfo = it.nextFileInfo();
if (!fileInfo.isDir()) {
- QString destination(dataPath + QLatin1Char('/') + fileInfo.filePath().mid(sourcePath.length()));
+ QString destination(dataPath + QLatin1Char('/')
+ + fileInfo.filePath().mid(sourcePath.length()));
QFileInfo destinationFileInfo(destination);
if (!destinationFileInfo.exists()) {
QVERIFY(QDir().mkpath(destinationFileInfo.path()));
@@ -186,9 +166,10 @@ void tst_QResourceEngine::checkStructure_data()
QStringList rootContents;
rootContents << QLatin1String("aliasdir")
-#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED)
+#ifdef Q_OS_ANDROID
<< QLatin1String("android_testdata")
#endif
+ << QLatin1String("empty")
<< QLatin1String("otherdir")
<< QLatin1String("runtime_resource")
<< QLatin1String("searchpath1")
@@ -305,7 +286,7 @@ void tst_QResourceEngine::checkStructure_data()
info = QFileInfo(QFINDTESTDATA("testqrc/test/test/test2.txt"));
- QTest::addRow("%s test1 text", qPrintable(root)) << QString(root + "test/test/test2.txt")
+ QTest::addRow("%s test2 text", qPrintable(root)) << QString(root + "test/test/test2.txt")
<< QByteArray("def\n")
<< QStringList()
<< QStringList()
@@ -401,7 +382,7 @@ void tst_QResourceEngine::checkStructure_data()
<< qlonglong(info.size());
QFile file(QFINDTESTDATA("testqrc/aliasdir/compressme.txt"));
- file.open(QFile::ReadOnly);
+ QVERIFY(file.open(QFile::ReadOnly));
info = QFileInfo(QFINDTESTDATA("testqrc/aliasdir/compressme.txt"));
QTest::addRow("%s compressed text", qPrintable(root)) << QString(root + "aliasdir/aliasdir.txt")
<< file.readAll()
@@ -488,7 +469,7 @@ void tst_QResourceEngine::checkStructure()
void tst_QResourceEngine::searchPath_data()
{
- auto searchPath = QFileInfo(QFINDTESTDATA("testqrc")).canonicalFilePath();
+ auto searchPath = QFileInfo(QFINDTESTDATA("testqrc/test.qrc")).canonicalPath();
QTest::addColumn<QString>("searchPathPrefix");
QTest::addColumn<QString>("searchPath");
@@ -562,6 +543,15 @@ void tst_QResourceEngine::checkUnregisterResource()
QVERIFY(QFile::exists(file_check));
QVERIFY(QResource::unregisterResource(rcc_file, root));
QVERIFY(!QFile::exists(file_check));
+ {
+ // QTBUG-86088
+ QVERIFY(QResource::registerResource(rcc_file, root));
+ QFile file(file_check);
+ QVERIFY(file.open(QFile::ReadOnly));
+ QVERIFY(!QResource::unregisterResource(rcc_file, root));
+ file.close();
+ QVERIFY(!QFile::exists(file_check));
+ }
QVERIFY(QResource::registerResource(rcc_file, root));
QVERIFY(QFile::exists(file_check));
QFileInfo fileInfo(file_check);
@@ -578,13 +568,22 @@ void tst_QResourceEngine::doubleSlashInRoot()
QVERIFY(QFile::exists("://secondary_root/runtime_resource/search_file.txt"));
}
+void tst_QResourceEngine::setLocale_data()
+{
+ QTest::addColumn<QString>("prefix");
+ QTest::newRow("built-in") << QString();
+ QTest::newRow("runtime") << "/runtime_resource/";
+}
+
void tst_QResourceEngine::setLocale()
{
+ QFETCH(QString, prefix);
QLocale::setDefault(QLocale::c());
// default constructed QResource gets the default locale
QResource resource;
- resource.setFileName("aliasdir/aliasdir.txt");
+ resource.setFileName(prefix + "aliasdir/aliasdir.txt");
+ QVERIFY(resource.isValid());
QCOMPARE(resource.compressionAlgorithm(), QResource::NoCompression);
// change the default locale and make sure it doesn't affect the resource
@@ -623,6 +622,14 @@ void tst_QResourceEngine::resourcesInStaticPlugins()
QVERIFY(QFile::exists(":/staticplugin/main.cpp"));
}
+void tst_QResourceEngine::qtResourceEmpty()
+{
+ QFile f(":/empty/world.txt");
+ QVERIFY(f.exists());
+ QVERIFY(f.open(QIODevice::ReadOnly));
+ QVERIFY(f.readAll().isEmpty());
+}
+
QTEST_MAIN(tst_QResourceEngine)
#include "tst_qresourceengine.moc"