diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-06-10 12:36:31 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-06-10 17:48:01 +0200 |
commit | d52a10eccd6fd7fae7481330e816975ba2b64f91 (patch) | |
tree | ede89aedbec213671f45b9563efb4992dda37546 /tests/auto/qml/qqmlimport | |
parent | 31ee1bc904e4fc565f7198b47fcf7305e4f4d5d7 (diff) |
QQmlImport: Parse resource paths from QML2_IMPORT_PATH
We can interpret double colons as start of resource paths.
Task-number: QTBUG-69435
Change-Id: If2b4412c28c7c59f160ddfcfe04ec293af437660
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlimport')
-rw-r--r-- | tests/auto/qml/qqmlimport/tst_qqmlimport.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp b/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp index 0fdec44cdf..316c4cb168 100644 --- a/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp +++ b/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp @@ -26,6 +26,7 @@ ** ****************************************************************************/ +#include <QtCore/qscopeguard.h> #include <QtTest/QtTest> #include <QQmlApplicationEngine> #include <QQmlAbstractUrlInterceptor> @@ -52,6 +53,7 @@ private slots: void partialImportVersions(); void registerModuleImport(); void cleanup(); + void envResourceImportPath(); }; void tst_QQmlImport::cleanup() @@ -59,6 +61,33 @@ void tst_QQmlImport::cleanup() QQmlImports::setDesignerSupportRequired(false); } +void tst_QQmlImport::envResourceImportPath() +{ + const bool hadEnv = qEnvironmentVariableIsSet("QML2_IMPORT_PATH"); + const QByteArray oldEnv = hadEnv ? qgetenv("QML2_IMPORT_PATH") : QByteArray(); + auto guard = qScopeGuard([&] { + if (hadEnv) + qputenv("QML2_IMPORT_PATH", oldEnv); + else + qunsetenv("QML2_IMPORT_PATH"); + }); + + const QStringList envPaths({ + QLatin1String(":/some/resource"), + dataDirectory(), + QLatin1String(":/some/other/resource"), + directory() + }); + + qputenv("QML2_IMPORT_PATH", envPaths.join(QDir::listSeparator()).toUtf8()); + + QQmlImportDatabase importDb(nullptr); + const QStringList importPaths = importDb.importPathList(); + + for (const QString &path : envPaths) + QVERIFY((importPaths.contains(path.startsWith(u':') ? QLatin1String("qrc") + path : path))); +} + void tst_QQmlImport::testDesignerSupported() { QQuickView *window = new QQuickView(); |