diff options
Diffstat (limited to 'tests/auto/corelib/global')
9 files changed, 141 insertions, 0 deletions
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/q20/CMakeLists.txt b/tests/auto/corelib/global/q20/CMakeLists.txt index bd28f8b999..141f94d9f7 100644 --- a/tests/auto/corelib/global/q20/CMakeLists.txt +++ b/tests/auto/corelib/global/q20/CMakeLists.txt @@ -1 +1,3 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause add_subdirectory(memory) diff --git a/tests/auto/corelib/global/qlibraryinfo/CMakeLists.txt b/tests/auto/corelib/global/qlibraryinfo/CMakeLists.txt new file mode 100644 index 0000000000..d72e871967 --- /dev/null +++ b/tests/auto/corelib/global/qlibraryinfo/CMakeLists.txt @@ -0,0 +1,24 @@ +# 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 + list.qt.conf + merge.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 --- /dev/null +++ b/tests/auto/corelib/global/qlibraryinfo/empty.qt.conf diff --git a/tests/auto/corelib/global/qlibraryinfo/list.qt.conf b/tests/auto/corelib/global/qlibraryinfo/list.qt.conf new file mode 100644 index 0000000000..9271b414ca --- /dev/null +++ b/tests/auto/corelib/global/qlibraryinfo/list.qt.conf @@ -0,0 +1,2 @@ +[Paths] +Documentation = "/path/to/mydoc","/path/to/anotherdoc","relativePath" diff --git a/tests/auto/corelib/global/qlibraryinfo/merge.qt.conf b/tests/auto/corelib/global/qlibraryinfo/merge.qt.conf new file mode 100644 index 0000000000..a687dc4d71 --- /dev/null +++ b/tests/auto/corelib/global/qlibraryinfo/merge.qt.conf @@ -0,0 +1,5 @@ +[Paths] +QmlImports = "/path/to/myqml" + +[Config] +MergeQtConf=true 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..b7d79c05f5 --- /dev/null +++ b/tests/auto/corelib/global/qlibraryinfo/tst_qlibraryinfo.cpp @@ -0,0 +1,103 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QTest> +#include <QtCore/qlibraryinfo.h> +#include <QtCore/qscopeguard.h> +#include <QtCore/private/qlibraryinfo_p.h> + + +class tst_QLibraryInfo : public QObject +{ + Q_OBJECT +private slots: + void initTestCase(); + void cleanup(); + void path_data(); + void path(); + void paths(); + void merge(); +}; + +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<QString>("qtConfPath"); + QTest::addColumn<QLibraryInfo::LibraryPath>("path"); + QTest::addColumn<QString>("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); + + // check consistency with paths + auto values = QLibraryInfo::paths(path); + QVERIFY(!values.isEmpty()); + QCOMPARE(values.first(), expected); +} + +void tst_QLibraryInfo::paths() +{ + QString qtConfPath(u":/list.qt.conf"); + QLibraryInfoPrivate::setQtconfManualPath(&qtConfPath); + QLibraryInfoPrivate::reload(); + + QList<QString> values = QLibraryInfo::paths(QLibraryInfo::DocumentationPath); + QCOMPARE(values.length(), 3); + QCOMPARE(values[0], "/path/to/mydoc"); + QCOMPARE(values[1], "/path/to/anotherdoc"); + QString baseDir = QCoreApplication::applicationDirPath(); + QCOMPARE(values[2], baseDir + "/relativePath"); +} + +void tst_QLibraryInfo::merge() +{ + QString qtConfPath(u":/merge.qt.conf"); + QLibraryInfoPrivate::setQtconfManualPath(&qtConfPath); + QLibraryInfoPrivate::reload(); + + QString baseDir = QCoreApplication::applicationDirPath(); + QString docPath = QLibraryInfo::path(QLibraryInfo::DocumentationPath); + // we can't know where exactly the doc path points, but it should not point to ${baseDir}/doc, + // which would be the behavior without merge_qt_conf + QCOMPARE_NE(docPath, baseDir + "/doc"); + + QList<QString> values = QLibraryInfo::paths(QLibraryInfo::QmlImportsPath); + QCOMPARE(values.size(), 2); // custom entry + Qt default entry + QCOMPARE(values[0], "/path/to/myqml"); +} + +QTEST_GUILESS_MAIN(tst_QLibraryInfo) + +#include "tst_qlibraryinfo.moc" diff --git a/tests/auto/corelib/global/qxp/CMakeLists.txt b/tests/auto/corelib/global/qxp/CMakeLists.txt index 2178f446db..8292462d17 100644 --- a/tests/auto/corelib/global/qxp/CMakeLists.txt +++ b/tests/auto/corelib/global/qxp/CMakeLists.txt @@ -1,2 +1,4 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause add_subdirectory(function_ref) add_subdirectory(is_virtual_base_of) |