diff options
Diffstat (limited to 'tests/auto/corelib/io/qresourceengine')
5 files changed, 129 insertions, 41 deletions
diff --git a/tests/auto/corelib/io/qresourceengine/CMakeLists.txt b/tests/auto/corelib/io/qresourceengine/CMakeLists.txt new file mode 100644 index 0000000000..a86cc8e76a --- /dev/null +++ b/tests/auto/corelib/io/qresourceengine/CMakeLists.txt @@ -0,0 +1,58 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +##################################################################### +## tst_qresourceengine Test: +##################################################################### + +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qresourceengine LANGUAGES C CXX ASM) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +# Collect test data +set(test_data "parentdir.txt") +file(GLOB_RECURSE test_data_glob + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + testqrc/*) +list(APPEND test_data ${test_data_glob}) +file(GLOB_RECURSE test_data_glob + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + *.rcc) +list(APPEND test_data ${test_data_glob}) + +qt_internal_add_test(tst_qresourceengine + SOURCES + tst_qresourceengine.cpp + LIBRARIES + Qt::CorePrivate + moctestplugin + TESTDATA ${test_data} +) + +set_source_files_properties("world.txt" + PROPERTIES QT_DISCARD_FILE_CONTENTS TRUE +) + +qt_internal_add_resource(tst_qresourceengine "qt_resource_empty" + PREFIX + "/empty" + FILES + "world.txt" +) + +qt_add_resources(additional_sources testqrc/test.qrc) +target_sources(tst_qresourceengine PRIVATE ${additional_sources}) + +if(ANDROID) + qt_add_resources(additional_sources android_testdata.qrc) + target_sources(tst_qresourceengine PRIVATE ${additional_sources}) +endif() + +qt_add_binary_resources(tst_qresourceengine_runtime_resource "testqrc/test.qrc" + DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/runtime_resource.rcc" + OPTIONS -root "/runtime_resource/" -binary) +add_dependencies(tst_qresourceengine tst_qresourceengine_runtime_resource) + +add_subdirectory(staticplugin) diff --git a/tests/auto/corelib/io/qresourceengine/staticplugin/.gitignore b/tests/auto/corelib/io/qresourceengine/staticplugin/.gitignore deleted file mode 100644 index c397dde6a5..0000000000 --- a/tests/auto/corelib/io/qresourceengine/staticplugin/.gitignore +++ /dev/null @@ -1 +0,0 @@ -moctestplugin_plugin_resources.cpp diff --git a/tests/auto/corelib/io/qresourceengine/staticplugin/CMakeLists.txt b/tests/auto/corelib/io/qresourceengine/staticplugin/CMakeLists.txt new file mode 100644 index 0000000000..1012fcaa62 --- /dev/null +++ b/tests/auto/corelib/io/qresourceengine/staticplugin/CMakeLists.txt @@ -0,0 +1,25 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +##################################################################### +## moctestplugin Generic Library: +##################################################################### + +qt_internal_add_cmake_library(moctestplugin + STATIC + SOURCES + main.cpp + LIBRARIES + Qt::Core + DEFINES + QT_STATICPLUGIN +) + +qt_internal_add_resource(moctestplugin "qmake_plugin_resource" + PREFIX + "/staticplugin" + FILES + "main.cpp" +) + +qt_autogen_tools_initial_setup(moctestplugin) diff --git a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp index b2f7aedab0..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,17 +50,16 @@ 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)); QDirIterator it(sourcePath, QDirIterator::Subdirectories); while (it.hasNext()) { - it.next(); - - QFileInfo fileInfo = it.fileInfo(); + 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())); @@ -188,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") @@ -307,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() @@ -403,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() @@ -490,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"); @@ -564,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); @@ -580,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 @@ -625,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" diff --git a/tests/auto/corelib/io/qresourceengine/world.txt b/tests/auto/corelib/io/qresourceengine/world.txt new file mode 100644 index 0000000000..ce01362503 --- /dev/null +++ b/tests/auto/corelib/io/qresourceengine/world.txt @@ -0,0 +1 @@ +hello |