diff --git a/tests/auto/corelib/global/CMakeLists.txt b/tests/auto/corelib/global/CMakeLists.txt index 7970116672..6072a18e81 100644 --- a/tests/auto/corelib/global/CMakeLists.txt +++ b/tests/auto/corelib/global/CMakeLists.txt @@ -16,6 +16,7 @@ if(NOT INTEGRITY) add_subdirectory(qnativeinterface) endif() add_subdirectory(qrandomgenerator) +add_subdirectory(qlibraryinfo) add_subdirectory(qlogging) add_subdirectory(qtendian) add_subdirectory(qglobalstatic) diff --git a/tests/auto/corelib/global/qlibraryinfo/CMakeLists.txt b/tests/auto/corelib/global/qlibraryinfo/CMakeLists.txt new file mode 100644 index 0000000000..18642c6838 --- /dev/null +++ b/tests/auto/corelib/global/qlibraryinfo/CMakeLists.txt @@ -0,0 +1,17 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qlibraryinfo LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + + +qt_internal_add_test(tst_qlibraryinfo SOURCES tst_qlibraryinfo.cpp + LIBRARIES + Qt::CorePrivate + +) + +qt_add_resources(tst_qlibraryinfo "qtconffiles" PREFIX "/" FILES empty.qt.conf partial.qt.conf) diff --git a/tests/auto/corelib/global/qlibraryinfo/empty.qt.conf b/tests/auto/corelib/global/qlibraryinfo/empty.qt.conf new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/auto/corelib/global/qlibraryinfo/partial.qt.conf b/tests/auto/corelib/global/qlibraryinfo/partial.qt.conf new file mode 100644 index 0000000000..bba214c2a6 --- /dev/null +++ b/tests/auto/corelib/global/qlibraryinfo/partial.qt.conf @@ -0,0 +1,2 @@ +[Paths] +QmlImports = "/path/to/myqml" diff --git a/tests/auto/corelib/global/qlibraryinfo/tst_qlibraryinfo.cpp b/tests/auto/corelib/global/qlibraryinfo/tst_qlibraryinfo.cpp new file mode 100644 index 0000000000..1224652bf1 --- /dev/null +++ b/tests/auto/corelib/global/qlibraryinfo/tst_qlibraryinfo.cpp @@ -0,0 +1,66 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include +#include +#include +#include + + +class tst_QLibraryInfo : public QObject +{ + Q_OBJECT +private slots: + void initTestCase(); + void cleanup(); + void path_data(); + void path(); +}; + +void tst_QLibraryInfo::initTestCase() +{ +#if !QT_CONFIG(settings) + QSKIP("QSettings support is required for the test to run."); +#endif +} + +void tst_QLibraryInfo::cleanup() +{ + QLibraryInfoPrivate::setQtconfManualPath(nullptr); + QLibraryInfoPrivate::reload(); +} + +void tst_QLibraryInfo::path_data() +{ + QTest::addColumn("qtConfPath"); + QTest::addColumn("path"); + QTest::addColumn("expected"); + + // TODO: deal with bundle on macOs? + QString baseDir = QCoreApplication::applicationDirPath(); + + // empty means we fall-back to default entries + QTest::addRow("empty_qmlimports") << ":/empty.qt.conf" << QLibraryInfo::QmlImportsPath << (baseDir + "/qml"); + QTest::addRow("empty_Data") << ":/empty.qt.conf" << QLibraryInfo::DataPath << baseDir; + + // partial override; use given entry if provided, otherwise default + QTest::addRow("partial_qmlimports") << ":/partial.qt.conf" << QLibraryInfo::QmlImportsPath << "/path/to/myqml"; + QTest::addRow("partial_Data") << ":/partial.qt.conf" << QLibraryInfo::DataPath << baseDir; +} + +void tst_QLibraryInfo::path() +{ + QFETCH(QString, qtConfPath); + QFETCH(QLibraryInfo::LibraryPath, path); + QFETCH(QString, expected); + + QLibraryInfoPrivate::setQtconfManualPath(&qtConfPath); + QLibraryInfoPrivate::reload(); + QString value = QLibraryInfo::path(path); + QCOMPARE(value, expected); + +} + +QTEST_GUILESS_MAIN(tst_QLibraryInfo) + +#include "tst_qlibraryinfo.moc"