diff options
Diffstat (limited to 'tests/auto/qml/qqmlfileselector/tst_qqmlfileselector.cpp')
-rw-r--r-- | tests/auto/qml/qqmlfileselector/tst_qqmlfileselector.cpp | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/tests/auto/qml/qqmlfileselector/tst_qqmlfileselector.cpp b/tests/auto/qml/qqmlfileselector/tst_qqmlfileselector.cpp index 46df20378c..98774ffe64 100644 --- a/tests/auto/qml/qqmlfileselector/tst_qqmlfileselector.cpp +++ b/tests/auto/qml/qqmlfileselector/tst_qqmlfileselector.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 BlackBerry Limited. All rights reserved. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <qtest.h> #include <QQmlEngine> @@ -32,11 +32,9 @@ void tst_qqmlfileselector::basicTest() selector.setExtraSelectors(QStringList() << "basic"); QQmlComponent component(&engine, testFileUrl("basicTest.qml")); - QObject *object = component.create(); - QVERIFY(object != nullptr); + std::unique_ptr<QObject> object { component.create() }; + QVERIFY(object.get() != nullptr); QCOMPARE(object->property("value").toString(), QString("selected")); - - delete object; } void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &message) @@ -72,19 +70,38 @@ void tst_qqmlfileselector::applicationEngineTest() void tst_qqmlfileselector::qmldirCompatibility() { - QQmlApplicationEngine engine; - engine.addImportPath(dataDirectory()); - engine.load(testFileUrl("qmldirtest/main.qml")); - QVERIFY(!engine.rootObjects().isEmpty()); - QObject *object = engine.rootObjects().at(0); - auto color = object->property("color").value<QColor>(); + { + // No error for multiple files with different selectors, and the matching one is chosen + // for +macos and +linux selectors. + QQmlApplicationEngine engine; + engine.addImportPath(dataDirectory()); + engine.load(testFileUrl("qmldirtest/main.qml")); + QVERIFY(!engine.rootObjects().isEmpty()); + QObject *object = engine.rootObjects().at(0); + auto color = object->property("color").value<QColor>(); #if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) - QCOMPARE(color, QColorConstants::Svg::blue); + QCOMPARE(object->objectName(), "linux"); + QCOMPARE(color, QColorConstants::Svg::blue); #elif defined(Q_OS_DARWIN) - QCOMPARE(color, QColorConstants::Svg::yellow); + QCOMPARE(object->objectName(), "macos"); + QCOMPARE(color, QColorConstants::Svg::yellow); #else - QCOMPARE(color, QColorConstants::Svg::green); + QCOMPARE(object->objectName(), "base"); + QCOMPARE(color, QColorConstants::Svg::green); #endif + } + + { + // If nothing matches, the _base_ file is chosen, not the first or the last one. + // This also holds when using the implicit import. + QQmlApplicationEngine engine; + engine.addImportPath(dataDirectory()); + engine.load(testFileUrl("qmldirtest2/main.qml")); + QVERIFY(!engine.rootObjects().isEmpty()); + QObject *object = engine.rootObjects().at(0); + QCOMPARE(object->property("color").value<QColor>(), QColorConstants::Svg::green); + QCOMPARE(object->objectName(), "base"); + } } QTEST_MAIN(tst_qqmlfileselector) |