diff options
Diffstat (limited to 'tests/auto/styleimports')
17 files changed, 406 insertions, 0 deletions
diff --git a/tests/auto/styleimports/CMakeLists.txt b/tests/auto/styleimports/CMakeLists.txt new file mode 100644 index 00000000..b5910e92 --- /dev/null +++ b/tests/auto/styleimports/CMakeLists.txt @@ -0,0 +1,62 @@ +# Generated from styleimports.pro. + +##################################################################### +## tst_styleimports Test: +##################################################################### + +# Collect test data +file(GLOB_RECURSE test_data_glob + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + data/*) +list(APPEND test_data ${test_data_glob}) + +qt_add_test(tst_styleimports + SOURCES + ../shared/qtest_quickcontrols.h + ../shared/util.cpp ../shared/util.h + ../shared/visualtestutil.cpp ../shared/visualtestutil.h + tst_styleimports.cpp + DEFINES + QQC2_IMPORT_PATH=\\\"${CMAKE_CURRENT_SOURCE_DIR}/../../../src/imports\\\" + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate + Qt::QmlPrivate + Qt::QuickControls2 + Qt::QuickControls2Private + Qt::QuickPrivate + Qt::QuickTemplates2Private + Qt::TestPrivate + TESTDATA ${test_data} +) + +# Resources: +set(qmake_resourcestyle_resource_files + "ResourceStyle/Button.qml" + "ResourceStyle/qmldir" +) + +qt_add_resource(tst_styleimports "qmake_resourcestyle" + PREFIX + "/" + FILES + ${qmake_resourcestyle_resource_files} +) + + +#### Keys ignored in scope 1:.:.:styleimports.pro:<TRUE>: +# OTHER_FILES = "data/*.qml" "data/qmldir" "data/FileSystemStyle/*.qml" "data/FileSystemStyle/qmldir" "data/PlatformStyle/*.qml" "data/PlatformStyle/+linux/*.qml" "data/PlatformStyle/+macos/*.qml" "data/PlatformStyle/+windows/*.qml" "data/PlatformStyle/qmldir" + +## Scopes: +##################################################################### + +qt_extend_target(tst_styleimports CONDITION ANDROID OR IOS + DEFINES + QT_QMLTEST_DATADIR=\\\":/data\\\" +) + +qt_extend_target(tst_styleimports CONDITION NOT ANDROID AND NOT IOS + DEFINES + QT_QMLTEST_DATADIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}/data\\\" +) diff --git a/tests/auto/styleimports/ResourceStyle/Button.qml b/tests/auto/styleimports/ResourceStyle/Button.qml new file mode 100644 index 00000000..2b9e5bb7 --- /dev/null +++ b/tests/auto/styleimports/ResourceStyle/Button.qml @@ -0,0 +1,4 @@ +import QtQuick.Templates 2.15 as T +T.Button { + objectName: "ResourceStyle" +} diff --git a/tests/auto/styleimports/ResourceStyle/qmldir b/tests/auto/styleimports/ResourceStyle/qmldir new file mode 100644 index 00000000..4cb1a835 --- /dev/null +++ b/tests/auto/styleimports/ResourceStyle/qmldir @@ -0,0 +1,2 @@ +module ResourceStyle +Button 2.15 Button.qml diff --git a/tests/auto/styleimports/data/Action.qml b/tests/auto/styleimports/data/Action.qml new file mode 100644 index 00000000..62501292 --- /dev/null +++ b/tests/auto/styleimports/data/Action.qml @@ -0,0 +1,4 @@ +import QtQuick.Templates 2.15 as T +T.Action { + objectName: "data" +} diff --git a/tests/auto/styleimports/data/Button.qml b/tests/auto/styleimports/data/Button.qml new file mode 100644 index 00000000..f67719e3 --- /dev/null +++ b/tests/auto/styleimports/data/Button.qml @@ -0,0 +1,4 @@ +import QtQuick.Templates 2.15 as T +T.Button { + objectName: "data" +} diff --git a/tests/auto/styleimports/data/FileSystemStyle/Button.qml b/tests/auto/styleimports/data/FileSystemStyle/Button.qml new file mode 100644 index 00000000..a5719dd8 --- /dev/null +++ b/tests/auto/styleimports/data/FileSystemStyle/Button.qml @@ -0,0 +1,4 @@ +import QtQuick.Templates 2.15 as T +T.Button { + objectName: "FileSystemStyle" +} diff --git a/tests/auto/styleimports/data/FileSystemStyle/qmldir b/tests/auto/styleimports/data/FileSystemStyle/qmldir new file mode 100644 index 00000000..3c401588 --- /dev/null +++ b/tests/auto/styleimports/data/FileSystemStyle/qmldir @@ -0,0 +1,2 @@ +module FileSystemStyle +Button 2.15 Button.qml diff --git a/tests/auto/styleimports/data/Label.qml b/tests/auto/styleimports/data/Label.qml new file mode 100644 index 00000000..b6d434ad --- /dev/null +++ b/tests/auto/styleimports/data/Label.qml @@ -0,0 +1,4 @@ +import QtQuick.Templates 2.15 as T +T.Label { + objectName: "data" +} diff --git a/tests/auto/styleimports/data/PlatformStyle/+linux/Button.qml b/tests/auto/styleimports/data/PlatformStyle/+linux/Button.qml new file mode 100644 index 00000000..74e2a6f4 --- /dev/null +++ b/tests/auto/styleimports/data/PlatformStyle/+linux/Button.qml @@ -0,0 +1,4 @@ +import QtQuick.Templates 2.15 as T +T.Button { + objectName: "PlatformStyle/+linux" +} diff --git a/tests/auto/styleimports/data/PlatformStyle/+macos/Button.qml b/tests/auto/styleimports/data/PlatformStyle/+macos/Button.qml new file mode 100644 index 00000000..47fd788b --- /dev/null +++ b/tests/auto/styleimports/data/PlatformStyle/+macos/Button.qml @@ -0,0 +1,4 @@ +import QtQuick.Templates 2.15 as T +T.Button { + objectName: "PlatformStyle/+macos" +} diff --git a/tests/auto/styleimports/data/PlatformStyle/+windows/Button.qml b/tests/auto/styleimports/data/PlatformStyle/+windows/Button.qml new file mode 100644 index 00000000..e5b56653 --- /dev/null +++ b/tests/auto/styleimports/data/PlatformStyle/+windows/Button.qml @@ -0,0 +1,4 @@ +import QtQuick.Templates 2.15 as T +T.Button { + objectName: "PlatformStyle/+windows" +} diff --git a/tests/auto/styleimports/data/PlatformStyle/Button.qml b/tests/auto/styleimports/data/PlatformStyle/Button.qml new file mode 100644 index 00000000..fd1dc83d --- /dev/null +++ b/tests/auto/styleimports/data/PlatformStyle/Button.qml @@ -0,0 +1,4 @@ +import QtQuick.Templates 2.15 as T +T.Button { + objectName: "PlatformStyle/Button.qml" +} diff --git a/tests/auto/styleimports/data/PlatformStyle/qmldir b/tests/auto/styleimports/data/PlatformStyle/qmldir new file mode 100644 index 00000000..ce254517 --- /dev/null +++ b/tests/auto/styleimports/data/PlatformStyle/qmldir @@ -0,0 +1,2 @@ +module PlatformStyle +Button 2.15 Button.qml diff --git a/tests/auto/styleimports/data/platformSelectors.qml b/tests/auto/styleimports/data/platformSelectors.qml new file mode 100644 index 00000000..ba6af22c --- /dev/null +++ b/tests/auto/styleimports/data/platformSelectors.qml @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** 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. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick +import QtQuick.Controls + +ApplicationWindow { + title: "Test Application Window" + width: 400 + height: 400 + + property alias button: button + + Button { + id: button + } +} diff --git a/tests/auto/styleimports/data/qmldir b/tests/auto/styleimports/data/qmldir new file mode 100644 index 00000000..9e9df940 --- /dev/null +++ b/tests/auto/styleimports/data/qmldir @@ -0,0 +1,4 @@ +module data +Action 2.15 Action.qml +Button 2.15 Button.qml +Label 2.15 Label.qml diff --git a/tests/auto/styleimports/styleimports.pro b/tests/auto/styleimports/styleimports.pro new file mode 100644 index 00000000..774d93e9 --- /dev/null +++ b/tests/auto/styleimports/styleimports.pro @@ -0,0 +1,29 @@ +CONFIG += testcase +TARGET = tst_styleimports +SOURCES += tst_styleimports.cpp + +macos:CONFIG -= app_bundle + +QT += core-private gui-private qml-private quick-private quickcontrols2-private testlib + +include (../shared/util.pri) + +resourcestyle.prefix = / +resourcestyle.files += \ + $$PWD/ResourceStyle/Button.qml \ + $$PWD/ResourceStyle/qmldir +RESOURCES += resourcestyle + +TESTDATA = data/* + +OTHER_FILES += \ + data/*.qml \ + data/qmldir \ + data/FileSystemStyle/*.qml \ + data/FileSystemStyle/qmldir \ + data/PlatformStyle/*.qml \ + data/PlatformStyle/+linux/*.qml \ + data/PlatformStyle/+macos/*.qml \ + data/PlatformStyle/+windows/*.qml \ + data/PlatformStyle/qmldir + diff --git a/tests/auto/styleimports/tst_styleimports.cpp b/tests/auto/styleimports/tst_styleimports.cpp new file mode 100644 index 00000000..04acbb21 --- /dev/null +++ b/tests/auto/styleimports/tst_styleimports.cpp @@ -0,0 +1,205 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtCore/qregularexpression.h> +#include <QtTest/qtest.h> +#include <QtQml/qqmlcomponent.h> +#include <QtQml/qqmlcontext.h> +#include <QtQml/qqmlapplicationengine.h> +#include <QtQml/qqmlengine.h> +#include <QtQuick/qquickwindow.h> +#include <QtQuickControls2/qquickstyle.h> +#include <QtQuickControls2/private/qquickstyle_p.h> + +#include "../shared/util.h" + +class tst_StyleImports : public QQmlDataTest +{ + Q_OBJECT + +private slots: + void initTestCase(); + + void cleanup(); + + void select_data(); + void select(); + + void platformSelectors(); +}; + +void tst_StyleImports::initTestCase() +{ + QQmlDataTest::initTestCase(); +} + +void tst_StyleImports::cleanup() +{ + qmlClearTypeRegistrations(); +} + +void tst_StyleImports::select_data() +{ + QTest::addColumn<QString>("file"); + QTest::addColumn<QString>("style"); + QTest::addColumn<QString>("fallback"); + QTest::addColumn<QString>("expected"); + + // Action.qml exists in the "data" style and the Default style. + QTest::newRow("control=Action,style=empty,fallback=empty") << "Action.qml" << "" << "" << "Default"; + QTest::newRow("control=Action,style=fs,fallback=empty") << "Action.qml" << "FileSystemStyle" << "" << "Default"; + QTest::newRow("control=Action,style=qrc,fallback=empty") << "Action.qml" << "ResourceStyle" << "" << "Default"; + QTest::newRow("control=Action,style=nosuch,fallback=empty") << "Action.qml" << "NoSuchStyle" << "" << "Default"; + QTest::newRow("control=Action,style=data,fallback=empty") << "Action.qml" << "data" << "" << "data"; + + QTest::newRow("control=Action,style=empty,fallback=mat") << "Action.qml" << "" << "Material" << ""; + QTest::newRow("control=Action,style=fs,fallback=mat") << "Action.qml" << "FileSystemStyle" << "Material" << "Default"; + QTest::newRow("control=Action,style=qrc,fallback=mat") << "Action.qml" << "ResourceStyle" << "Material" << "Default"; + QTest::newRow("control=Action,style=nosuch,fallback=mat") << "Action.qml" << "NoSuchStyle" << "Material" << "Default"; + QTest::newRow("control=Action,style=data,fallback=mat") << "Action.qml" << "data" << "Material" << "data"; + + // ScrollView.qml only exists in the Default style. + QTest::newRow("control=ScrollView,style=empty,fallback=empty") << "ScrollView.qml" << "" << "" << "Default"; + QTest::newRow("control=ScrollView,style=fs,fallback=empty") << "ScrollView.qml" << "FileSystemStyle" << "" << "Default"; + QTest::newRow("control=ScrollView,style=qrc,fallback=empty") << "ScrollView.qml" << "ResourceStyle" << "" << "Default"; + QTest::newRow("control=ScrollView,style=nosuch,fallback=empty") << "ScrollView.qml" << "NoSuchStyle" << "" << "Default"; + QTest::newRow("control=ScrollView,style=data,fallback=empty") << "ScrollView.qml" << "data" << "" << "Default"; + + QTest::newRow("control=ScrollView,style=empty,fallback=mat") << "ScrollView.qml" << "" << "Material" << "Default"; + QTest::newRow("control=ScrollView,style=fs,fallback=mat") << "ScrollView.qml" << "FileSystemStyle" << "Material" << "Default"; + QTest::newRow("control=ScrollView,style=qrc,fallback=mat") << "ScrollView.qml" << "ResourceStyle" << "Material" << "Default"; + QTest::newRow("control=ScrollView,style=nosuch,fallback=mat") << "ScrollView.qml" << "NoSuchStyle" << "Material" << "Default"; + QTest::newRow("control=ScrollView,style=data,fallback=mat") << "ScrollView.qml" << "data" << "Material" << "Default"; + + // Label.qml exists in the "data", Default and Material styles. + QTest::newRow("control=Label,style=none,fallback=none") << "Label.qml" << "" << "" << "Default"; + QTest::newRow("control=Label,style=fs,fallback=none") << "Label.qml" << "FileSystemStyle" << "" << "Default"; + QTest::newRow("control=Label,style=qrc,fallback=none") << "Label.qml" << "ResourceStyle" << "" << "Default"; + QTest::newRow("control=Label,style=nosuch,fallback=none") << "Label.qml" << "NoSuchStyle" << "" << "Default"; + QTest::newRow("control=Label,style=data,fallback=none") << "Label.qml" << "data" << "" << "data"; + + QTest::newRow("control=Label,style=none,fallback=mat") << "Label.qml" << "" << "Material" << "Default"; + QTest::newRow("control=Label,style=fs,fallback=mat") << "Label.qml" << "FileSystemStyle" << "Material" << "Default"; + QTest::newRow("control=Label,style=qrc,fallback=mat") << "Label.qml" << "ResourceStyle" << "Material" << "Default"; + QTest::newRow("control=Label,style=nosuch,fallback=mat") << "Label.qml" << "NoSuchStyle" << "Material" << "Default"; + QTest::newRow("control=Label,style=data,fallback=mat") << "Label.qml" << "data" << "Material" << "data"; + + // Button.qml exists in all styles including the fs and qrc styles + QTest::newRow("control=Button,style=none,fallback=none") << "Button.qml" << "" << "" << "Default"; + QTest::newRow("control=Button,style=fs,fallback=none") << "Button.qml" << "FileSystemStyle" << "" << "FileSystemStyle"; + QTest::newRow("control=Button,style=qrc,fallback=none") << "Button.qml" << "ResourceStyle" << "" << "ResourceStyle"; + QTest::newRow("control=Button,style=nosuch,fallback=none") << "Button.qml" << "NoSuchStyle" << "" << "Default"; + QTest::newRow("control=Button,style=data,fallback=none") << "Button.qml" << "data" << "" << "data"; + + QTest::newRow("control=Button,style=none,fallback=mat") << "Button.qml" << "" << "Material" << "Default"; + QTest::newRow("control=Button,style=fs,fallback=mat") << "Button.qml" << "FileSystemStyle" << "Material" << "FileSystemStyle"; + QTest::newRow("control=Button,style=qrc,fallback=mat") << "Button.qml" << "ResourceStyle" << "Material" << "ResourceStyle"; + QTest::newRow("control=Button,style=nosuch,fallback=mat") << "Button.qml" << "NoSuchStyle" << "Material" << "Default"; + QTest::newRow("control=Button,style=data,fallback=mat") << "Button.qml" << "data" << "Material" << "data"; +} + +void tst_StyleImports::select() +{ + QFETCH(QString, file); + QFETCH(QString, style); + QFETCH(QString, fallback); + QFETCH(QString, expected); + + // In Qt 5, there were several accepted forms for style names. + // In Qt 6, the only accepted form is the base name of the style directory. + const bool invalidStyleName = style.contains(QLatin1Char('/')); + if (invalidStyleName) + QTest::ignoreMessage(QtWarningMsg, + "Style names must not contain paths; see the \"Definition of a Style\" documentation for more information"); + QQuickStyle::setStyle(style); + QQuickStyle::setFallbackStyle(fallback); + + QQmlEngine engine; + engine.addImportPath(directory()); + engine.addImportPath(dataDirectory()); + QQmlComponent component(&engine); + const QString controlName = file.mid(0, file.indexOf(QLatin1Char('.'))); + component.setData(QString::fromLatin1("import QtQuick 2.15; import QtQuick.Controls 2.15; %1 { }").arg(controlName).toUtf8(), QUrl()); + + const bool nonExistentStyle = style == QLatin1String("NoSuchStyle"); + if (nonExistentStyle) + QTest::ignoreMessage(QtWarningMsg, "QQmlComponent: Component is not ready"); + QScopedPointer<QObject> object(component.create()); + if (nonExistentStyle) { + QVERIFY(object.isNull()); + return; + } + + QVERIFY2(!object.isNull(), qPrintable(component.errorString())); + + // TODO: test built-in styles below too + // We can't check for the attached style object since that API is in a plugin, + // and it's not possible to use e.g. the baseUrl of the QQmlContext + // nor the metaObject to test it either. + + if (!QQuickStylePrivate::builtInStyles().contains(expected)) { + // We're expecting a custom style. + QCOMPARE(object->objectName(), expected); + } +} + +void tst_StyleImports::platformSelectors() +{ + QQuickStyle::setStyle(QLatin1String("PlatformStyle")); + + QQmlApplicationEngine engine; + engine.addImportPath(dataDirectory()); + engine.load(testFileUrl("platformSelectors.qml")); + QQuickWindow *window = qobject_cast<QQuickWindow*>(engine.rootObjects().first()); + QVERIFY(window); + + QObject *button = window->property("button").value<QObject*>(); + QVERIFY(button); + +#if defined(Q_OS_LINUX) + QCOMPARE(button->objectName(), "PlatformStyle/+linux"); +#elif defined(Q_OS_MACOS) + QCOMPARE(button->objectName(), "PlatformStyle/+macos"); +#elif defined(Q_OS_WIN) + QCOMPARE(button->objectName(), "PlatformStyle/+windows"); +#else + QCOMPARE(button->objectName(), "PlatformStyle/Button.qml"); +#endif +} + +QTEST_MAIN(tst_StyleImports) + +#include "tst_styleimports.moc" |