QLibraryInfo: add tests
Change-Id: I0a5cf4d5724b1e1c02634374b27a868f72a38243 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>bb10
parent
bcadcb029e
commit
1d9cd866f8
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
[Paths]
|
||||
QmlImports = "/path/to/myqml"
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
// 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 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);
|
||||
|
||||
}
|
||||
|
||||
QTEST_GUILESS_MAIN(tst_QLibraryInfo)
|
||||
|
||||
#include "tst_qlibraryinfo.moc"
|
||||
Loading…
Reference in New Issue