diff options
Diffstat (limited to 'tests/auto/qml/qqmlfileselector')
18 files changed, 144 insertions, 46 deletions
diff --git a/tests/auto/qml/qqmlfileselector/CMakeLists.txt b/tests/auto/qml/qqmlfileselector/CMakeLists.txt index 61707f79c7..b3dec0ff3d 100644 --- a/tests/auto/qml/qqmlfileselector/CMakeLists.txt +++ b/tests/auto/qml/qqmlfileselector/CMakeLists.txt @@ -1,9 +1,18 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + # Generated from qqmlfileselector.pro. ##################################################################### ## tst_qqmlfileselector Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qqmlfileselector LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + # Collect test data file(GLOB_RECURSE test_data_glob RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} @@ -12,27 +21,29 @@ list(APPEND test_data ${test_data_glob}) qt_internal_add_test(tst_qqmlfileselector SOURCES - ../../shared/util.cpp ../../shared/util.h tst_qqmlfileselector.cpp - INCLUDE_DIRECTORIES - ../../shared - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate Qt::QmlPrivate + Qt::QuickTestUtilsPrivate TESTDATA ${test_data} ) +if(QT_BUILD_STANDALONE_TESTS) + qt_import_qml_plugins(tst_qqmlfileselector) +endif() + ## Scopes: ##################################################################### qt_internal_extend_target(tst_qqmlfileselector CONDITION ANDROID OR IOS DEFINES - QT_QMLTEST_DATADIR=\\\":/data\\\" + QT_QMLTEST_DATADIR=":/data" ) qt_internal_extend_target(tst_qqmlfileselector CONDITION NOT ANDROID AND NOT IOS DEFINES - QT_QMLTEST_DATADIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}/data\\\" + QT_QMLTEST_DATADIR="${CMAKE_CURRENT_SOURCE_DIR}/data" ) diff --git a/tests/auto/qml/qqmlfileselector/data/qmldirtest/main.qml b/tests/auto/qml/qqmlfileselector/data/qmldirtest/main.qml new file mode 100644 index 0000000000..4e09798a84 --- /dev/null +++ b/tests/auto/qml/qqmlfileselector/data/qmldirtest/main.qml @@ -0,0 +1,11 @@ +import QtQuick +import qmldirtest + +Item { + objectName: Name.name + property color color: mybutton.color + + MyButton { + id: mybutton + } +} diff --git a/tests/auto/qml/qqmlfileselector/data/qmldirtest/qml/+linux/MyButton.qml b/tests/auto/qml/qqmlfileselector/data/qmldirtest/qml/+linux/MyButton.qml new file mode 100644 index 0000000000..cc6eb967da --- /dev/null +++ b/tests/auto/qml/qqmlfileselector/data/qmldirtest/qml/+linux/MyButton.qml @@ -0,0 +1,7 @@ +import QtQuick + +Rectangle { + width: 300 + height: 50 + color: "blue" +} diff --git a/tests/auto/qml/qqmlfileselector/data/qmldirtest/qml/+linux/Name.js b/tests/auto/qml/qqmlfileselector/data/qmldirtest/qml/+linux/Name.js new file mode 100644 index 0000000000..91ca4f129d --- /dev/null +++ b/tests/auto/qml/qqmlfileselector/data/qmldirtest/qml/+linux/Name.js @@ -0,0 +1 @@ +var name = "linux" diff --git a/tests/auto/qml/qqmlfileselector/data/qmldirtest/qml/+macos/MyButton.qml b/tests/auto/qml/qqmlfileselector/data/qmldirtest/qml/+macos/MyButton.qml new file mode 100644 index 0000000000..5bf632c48d --- /dev/null +++ b/tests/auto/qml/qqmlfileselector/data/qmldirtest/qml/+macos/MyButton.qml @@ -0,0 +1,7 @@ +import QtQuick + +Rectangle { + width: 300 + height: 50 + color: "yellow" +} diff --git a/tests/auto/qml/qqmlfileselector/data/qmldirtest/qml/+macos/Name.js b/tests/auto/qml/qqmlfileselector/data/qmldirtest/qml/+macos/Name.js new file mode 100644 index 0000000000..12e5058285 --- /dev/null +++ b/tests/auto/qml/qqmlfileselector/data/qmldirtest/qml/+macos/Name.js @@ -0,0 +1 @@ +var name = "macos" diff --git a/tests/auto/qml/qqmlfileselector/data/qmldirtest/qml/MyButton.qml b/tests/auto/qml/qqmlfileselector/data/qmldirtest/qml/MyButton.qml new file mode 100644 index 0000000000..32db428c4f --- /dev/null +++ b/tests/auto/qml/qqmlfileselector/data/qmldirtest/qml/MyButton.qml @@ -0,0 +1,7 @@ +import QtQuick + +Rectangle { + width: 300 + height: 50 + color: "green" +} diff --git a/tests/auto/qml/qqmlfileselector/data/qmldirtest/qml/Name.js b/tests/auto/qml/qqmlfileselector/data/qmldirtest/qml/Name.js new file mode 100644 index 0000000000..916a232eb4 --- /dev/null +++ b/tests/auto/qml/qqmlfileselector/data/qmldirtest/qml/Name.js @@ -0,0 +1 @@ +var name = "base" diff --git a/tests/auto/qml/qqmlfileselector/data/qmldirtest/qmldir b/tests/auto/qml/qqmlfileselector/data/qmldirtest/qmldir new file mode 100644 index 0000000000..a2efdbf27d --- /dev/null +++ b/tests/auto/qml/qqmlfileselector/data/qmldirtest/qmldir @@ -0,0 +1,8 @@ +module qmldirtest +MyButton 1.0 qml/MyButton.qml +MyButton 1.0 qml/+linux/MyButton.qml +MyButton 1.0 qml/+macos/MyButton.qml +Name 1.0 qml/Name.js +Name 1.0 qml/+linux/Name.js +Name 1.0 qml/+macos/Name.js + diff --git a/tests/auto/qml/qqmlfileselector/data/qmldirtest2/+bar/MyButton.qml b/tests/auto/qml/qqmlfileselector/data/qmldirtest2/+bar/MyButton.qml new file mode 100644 index 0000000000..5bf632c48d --- /dev/null +++ b/tests/auto/qml/qqmlfileselector/data/qmldirtest2/+bar/MyButton.qml @@ -0,0 +1,7 @@ +import QtQuick + +Rectangle { + width: 300 + height: 50 + color: "yellow" +} diff --git a/tests/auto/qml/qqmlfileselector/data/qmldirtest2/+bar/Name.js b/tests/auto/qml/qqmlfileselector/data/qmldirtest2/+bar/Name.js new file mode 100644 index 0000000000..8591795d37 --- /dev/null +++ b/tests/auto/qml/qqmlfileselector/data/qmldirtest2/+bar/Name.js @@ -0,0 +1 @@ +var name = "bar" diff --git a/tests/auto/qml/qqmlfileselector/data/qmldirtest2/+foo/MyButton.qml b/tests/auto/qml/qqmlfileselector/data/qmldirtest2/+foo/MyButton.qml new file mode 100644 index 0000000000..cc6eb967da --- /dev/null +++ b/tests/auto/qml/qqmlfileselector/data/qmldirtest2/+foo/MyButton.qml @@ -0,0 +1,7 @@ +import QtQuick + +Rectangle { + width: 300 + height: 50 + color: "blue" +} diff --git a/tests/auto/qml/qqmlfileselector/data/qmldirtest2/+foo/Name.js b/tests/auto/qml/qqmlfileselector/data/qmldirtest2/+foo/Name.js new file mode 100644 index 0000000000..b224ed15ec --- /dev/null +++ b/tests/auto/qml/qqmlfileselector/data/qmldirtest2/+foo/Name.js @@ -0,0 +1 @@ +var name = "foo" diff --git a/tests/auto/qml/qqmlfileselector/data/qmldirtest2/MyButton.qml b/tests/auto/qml/qqmlfileselector/data/qmldirtest2/MyButton.qml new file mode 100644 index 0000000000..32db428c4f --- /dev/null +++ b/tests/auto/qml/qqmlfileselector/data/qmldirtest2/MyButton.qml @@ -0,0 +1,7 @@ +import QtQuick + +Rectangle { + width: 300 + height: 50 + color: "green" +} diff --git a/tests/auto/qml/qqmlfileselector/data/qmldirtest2/Name.js b/tests/auto/qml/qqmlfileselector/data/qmldirtest2/Name.js new file mode 100644 index 0000000000..916a232eb4 --- /dev/null +++ b/tests/auto/qml/qqmlfileselector/data/qmldirtest2/Name.js @@ -0,0 +1 @@ +var name = "base" diff --git a/tests/auto/qml/qqmlfileselector/data/qmldirtest2/main.qml b/tests/auto/qml/qqmlfileselector/data/qmldirtest2/main.qml new file mode 100644 index 0000000000..5fb8afc660 --- /dev/null +++ b/tests/auto/qml/qqmlfileselector/data/qmldirtest2/main.qml @@ -0,0 +1,9 @@ +import QtQuick + +Item { + objectName: Name.name + property color color: mybutton.color + MyButton { + id: mybutton + } +} diff --git a/tests/auto/qml/qqmlfileselector/data/qmldirtest2/qmldir b/tests/auto/qml/qqmlfileselector/data/qmldirtest2/qmldir new file mode 100644 index 0000000000..92fefb9806 --- /dev/null +++ b/tests/auto/qml/qqmlfileselector/data/qmldirtest2/qmldir @@ -0,0 +1,5 @@ +module qmldirtest2 +MyButton 1.0 +foo/MyButton.qml +MyButton 1.0 MyButton.qml +MyButton 1.0 +bar/MyButton.qml +Name 1.0 Name.js diff --git a/tests/auto/qml/qqmlfileselector/tst_qqmlfileselector.cpp b/tests/auto/qml/qqmlfileselector/tst_qqmlfileselector.cpp index 2d618170d4..98774ffe64 100644 --- a/tests/auto/qml/qqmlfileselector/tst_qqmlfileselector.cpp +++ b/tests/auto/qml/qqmlfileselector/tst_qqmlfileselector.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 BlackBerry Limited. All rights reserved. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 BlackBerry Limited. All rights reserved. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <qtest.h> #include <QQmlEngine> @@ -35,19 +10,19 @@ #include <QQmlContext> #include <QLoggingCategory> #include <qqmlinfo.h> -#include "../../shared/util.h" +#include <QtQuickTestUtils/private/qmlutils_p.h> class tst_qqmlfileselector : public QQmlDataTest { Q_OBJECT public: - tst_qqmlfileselector() {} + tst_qqmlfileselector() : QQmlDataTest(QT_QMLTEST_DATADIR) {} private slots: void basicTest(); void basicTestCached(); void applicationEngineTest(); - + void qmldirCompatibility(); }; void tst_qqmlfileselector::basicTest() @@ -57,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) @@ -86,16 +59,49 @@ void tst_qqmlfileselector::basicTestCached() void tst_qqmlfileselector::applicationEngineTest() { QQmlApplicationEngine engine; - QQmlFileSelector* selector = QQmlFileSelector::get(&engine); - QVERIFY(selector != nullptr); - selector->setExtraSelectors(QStringList() << "basic"); + engine.setExtraFileSelectors(QStringList() << "basic"); + engine.load(testFileUrl("basicTest.qml")); - QQmlComponent component(&engine, testFileUrl("basicTest.qml")); - QObject *object = component.create(); + QVERIFY(!engine.rootObjects().isEmpty()); + QObject *object = engine.rootObjects().at(0); QVERIFY(object != nullptr); QCOMPARE(object->property("value").toString(), QString("selected")); +} - delete object; +void tst_qqmlfileselector::qmldirCompatibility() +{ + { + // 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(object->objectName(), "linux"); + QCOMPARE(color, QColorConstants::Svg::blue); +#elif defined(Q_OS_DARWIN) + QCOMPARE(object->objectName(), "macos"); + QCOMPARE(color, QColorConstants::Svg::yellow); +#else + 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) |