1/****************************************************************************
2**
3** Copyright (C) 2017 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the test suite of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL3$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPLv3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or later as published by the Free
28** Software Foundation and appearing in the file LICENSE.GPL included in
29** the packaging of this file. Please review the following information to
30** ensure the GNU General Public License version 2.0 requirements will be
31** met: http://www.gnu.org/licenses/gpl-2.0.html.
32**
33** $QT_END_LICENSE$
34**
35****************************************************************************/
36
37#include <QtTest/qtest.h>
38#include <QtQuickControls2/qquickstyle.h>
39#include <QtQuickControls2/private/qquickstyle_p.h>
40#include <QtQuickControls2/private/qquickstyleselector_p.h>
41#include "../shared/util.h"
42
43class tst_QQuickStyleSelector : public QQmlDataTest
44{
45 Q_OBJECT
46
47private slots:
48 void initTestCase();
49
50 void select_data();
51 void select();
52
53 void platformSelectors();
54};
55
56void tst_QQuickStyleSelector::initTestCase()
57{
58 QQmlDataTest::initTestCase();
59 QQuickStylePrivate::init(baseUrl: dataDirectoryUrl());
60}
61
62void tst_QQuickStyleSelector::select_data()
63{
64 QTest::addColumn<QString>(name: "file");
65 QTest::addColumn<QString>(name: "style");
66 QTest::addColumn<QString>(name: "path");
67 QTest::addColumn<QString>(name: "fallback");
68 QTest::addColumn<QString>(name: "expected");
69
70 // Control.qml exists only in the default style
71 QTest::newRow(dataTag: "control") << "Control.qml" << "" << "data" << "" << testFileUrl(fileName: "Control.qml").toString();
72 QTest::newRow(dataTag: "/control") << "Control.qml" << "" << dataDirectory() << "" << testFileUrl(fileName: "Control.qml").toString();
73 QTest::newRow(dataTag: "fs/control") << "Control.qml" << "FileSystemStyle" << "data" << "" << testFileUrl(fileName: "Control.qml").toString();
74 QTest::newRow(dataTag: "/fs/control") << "Control.qml" << "FileSystemStyle" << dataDirectory() << "" << testFileUrl(fileName: "Control.qml").toString();
75 QTest::newRow(dataTag: ":/control") << "Control.qml" << "ResourceStyle" << ":/" << "" << testFileUrl(fileName: "Control.qml").toString();
76 QTest::newRow(dataTag: "qrc:/control") << "Control.qml" << "ResourceStyle" << "qrc:/" << "" << testFileUrl(fileName: "Control.qml").toString();
77 QTest::newRow(dataTag: "nosuch/control") << "Control.qml" << "NoSuchStyle" << "data" << "" << testFileUrl(fileName: "Control.qml").toString();
78 QTest::newRow(dataTag: "/nosuch/control") << "Control.qml" << "NoSuchStyle" << dataDirectory() << "" << testFileUrl(fileName: "Control.qml").toString();
79
80 QTest::newRow(dataTag: "control->base") << "Control.qml" << "" << "data" << "FallbackStyle" << testFileUrl(fileName: "Control.qml").toString();
81 QTest::newRow(dataTag: "/control->base") << "Control.qml" << "" << dataDirectory() << "FallbackStyle" << testFileUrl(fileName: "Control.qml").toString();
82 QTest::newRow(dataTag: "fs/control->base") << "Control.qml" << "FileSystemStyle" << "data" << "FallbackStyle" << testFileUrl(fileName: "Control.qml").toString();
83 QTest::newRow(dataTag: "/fs/control->base") << "Control.qml" << "FileSystemStyle" << dataDirectory() << "FallbackStyle" << testFileUrl(fileName: "Control.qml").toString();
84 QTest::newRow(dataTag: ":/control->base") << "Control.qml" << "ResourceStyle" << ":/" << "FallbackStyle" << testFileUrl(fileName: "Control.qml").toString();
85 QTest::newRow(dataTag: "qrc:/control->base") << "Control.qml" << "ResourceStyle" << "qrc:/" << "FallbackStyle" << testFileUrl(fileName: "Control.qml").toString();
86 QTest::newRow(dataTag: "nosuch/control->base") << "Control.qml" << "NoSuchStyle" << "data" << "FallbackStyle" << testFileUrl(fileName: "Control.qml").toString();
87 QTest::newRow(dataTag: "/nosuch/control->base") << "Control.qml" << "NoSuchStyle" << dataDirectory() << "FallbackStyle" << testFileUrl(fileName: "Control.qml").toString();
88
89 // Label.qml exists in the default and fallback styles
90 QTest::newRow(dataTag: "label") << "Label.qml" << "" << "data" << "" << testFileUrl(fileName: "Label.qml").toString();
91 QTest::newRow(dataTag: "/label") << "Label.qml" << "" << dataDirectory() << "" << testFileUrl(fileName: "Label.qml").toString();
92 QTest::newRow(dataTag: "fs/label") << "Label.qml" << "FileSystemStyle" << "data" << "" << testFileUrl(fileName: "Label.qml").toString();
93 QTest::newRow(dataTag: "/fs/label") << "Label.qml" << "FileSystemStyle" << dataDirectory() << "" << testFileUrl(fileName: "Label.qml").toString();
94 QTest::newRow(dataTag: ":/label") << "Label.qml" << "ResourceStyle" << ":/" << "" << testFileUrl(fileName: "Label.qml").toString();
95 QTest::newRow(dataTag: "qrc:/label") << "Label.qml" << "ResourceStyle" << "qrc:/" << "" << testFileUrl(fileName: "Label.qml").toString();
96 QTest::newRow(dataTag: "nosuch/label") << "Label.qml" << "NoSuchStyle" << "data" << "" << testFileUrl(fileName: "Label.qml").toString();
97 QTest::newRow(dataTag: "/nosuch/label") << "Label.qml" << "NoSuchStyle" << dataDirectory() << "" << testFileUrl(fileName: "Label.qml").toString();
98
99 QTest::newRow(dataTag: "label->base") << "Label.qml" << "" << "data" << "FallbackStyle" << testFileUrl(fileName: "Label.qml").toString();
100 QTest::newRow(dataTag: "/label->base") << "Label.qml" << "" << dataDirectory() << "FallbackStyle" << testFileUrl(fileName: "Label.qml").toString();
101 QTest::newRow(dataTag: "fs/label->base") << "Label.qml" << "FileSystemStyle" << "data" << "FallbackStyle" << testFileUrl(fileName: "FallbackStyle/Label.qml").toString();
102 QTest::newRow(dataTag: "/fs/label->base") << "Label.qml" << "FileSystemStyle" << dataDirectory() << "FallbackStyle" << testFileUrl(fileName: "FallbackStyle/Label.qml").toString();
103 QTest::newRow(dataTag: ":/label->base") << "Label.qml" << "ResourceStyle" << ":/" << "FallbackStyle" << testFileUrl(fileName: "FallbackStyle/Label.qml").toString();
104 QTest::newRow(dataTag: "qrc:/label->base") << "Label.qml" << "ResourceStyle" << "qrc:/" << "FallbackStyle" << testFileUrl(fileName: "FallbackStyle/Label.qml").toString();
105 QTest::newRow(dataTag: "nosuch/label->base") << "Label.qml" << "NoSuchStyle" << "data" << "FallbackStyle" << testFileUrl(fileName: "FallbackStyle/Label.qml").toString();
106 QTest::newRow(dataTag: "/nosuch/label->base") << "Label.qml" << "NoSuchStyle" << dataDirectory() << "FallbackStyle" << testFileUrl(fileName: "FallbackStyle/Label.qml").toString();
107
108 // Button.qml exists in all styles including the fs and qrc styles
109 QTest::newRow(dataTag: "button") << "Button.qml" << "" << "data" << "" << testFileUrl(fileName: "Button.qml").toString();
110 QTest::newRow(dataTag: "/button") << "Button.qml" << "" << dataDirectory() << "" << testFileUrl(fileName: "Button.qml").toString();
111 QTest::newRow(dataTag: "fs/button") << "Button.qml" << "FileSystemStyle" << "data" << "" << testFileUrl(fileName: "FileSystemStyle/Button.qml").toString();
112 QTest::newRow(dataTag: "/fs/button") << "Button.qml" << "FileSystemStyle" << dataDirectory() << "" << testFileUrl(fileName: "FileSystemStyle/Button.qml").toString();
113 QTest::newRow(dataTag: ":/button") << "Button.qml" << "ResourceStyle" << ":/" << "" << "qrc:/ResourceStyle/Button.qml";
114 QTest::newRow(dataTag: "qrc:/button") << "Button.qml" << "ResourceStyle" << "qrc:/" << "" << "qrc:/ResourceStyle/Button.qml";
115 QTest::newRow(dataTag: "nosuch/button") << "Button.qml" << "NoSuchStyle" << "data" << "" << testFileUrl(fileName: "Button.qml").toString();
116 QTest::newRow(dataTag: "/nosuch/button") << "Button.qml" << "NoSuchStyle" << dataDirectory() << "" << testFileUrl(fileName: "Button.qml").toString();
117
118 QTest::newRow(dataTag: "button->base") << "Button.qml" << "" << "data" << "FallbackStyle" << testFileUrl(fileName: "Button.qml").toString();
119 QTest::newRow(dataTag: "/button->base") << "Button.qml" << "" << dataDirectory() << "FallbackStyle" << testFileUrl(fileName: "Button.qml").toString();
120 QTest::newRow(dataTag: "fs/button->base") << "Button.qml" << "FileSystemStyle" << "data" << "FallbackStyle" << testFileUrl(fileName: "FileSystemStyle/Button.qml").toString();
121 QTest::newRow(dataTag: "/fs/button->base") << "Button.qml" << "FileSystemStyle" << dataDirectory() << "FallbackStyle" << testFileUrl(fileName: "FileSystemStyle/Button.qml").toString();
122 QTest::newRow(dataTag: ":/button->base") << "Button.qml" << "ResourceStyle" << ":/" << "FallbackStyle" << "qrc:/ResourceStyle/Button.qml";
123 QTest::newRow(dataTag: "qrc:/button->base") << "Button.qml" << "ResourceStyle" << "qrc:/" << "FallbackStyle" << "qrc:/ResourceStyle/Button.qml";
124 QTest::newRow(dataTag: "nosuch/button->base") << "Button.qml" << "NoSuchStyle" << "data" << "FallbackStyle" << testFileUrl(fileName: "FallbackStyle/Button.qml").toString();
125 QTest::newRow(dataTag: "/nosuch/button->base") << "Button.qml" << "NoSuchStyle" << dataDirectory() << "FallbackStyle" << testFileUrl(fileName: "FallbackStyle/Button.qml").toString();
126}
127
128void tst_QQuickStyleSelector::select()
129{
130 QFETCH(QString, file);
131 QFETCH(QString, style);
132 QFETCH(QString, path);
133 QFETCH(QString, fallback);
134 QFETCH(QString, expected);
135
136 QQuickStyle::setStyle(QDir(path).filePath(fileName: style));
137 QQuickStyle::setFallbackStyle(fallback);
138
139 QQuickStyleSelector selector;
140 selector.addSelector(selector: style);
141 selector.addSelector(selector: fallback);
142 selector.setPaths(QStringList() << dataDirectory() << ":/");
143 QCOMPARE(selector.select(file), expected);
144}
145
146void tst_QQuickStyleSelector::platformSelectors()
147{
148 QQuickStyle::setStyle(QDir(dataDirectory()).filePath(fileName: "PlatformStyle"));
149
150 QQuickStyleSelector selector;
151 selector.addSelector(selector: "PlatformStyle");
152 selector.setPaths(QStringList() << dataDirectory());
153
154#if defined(Q_OS_LINUX)
155 QCOMPARE(selector.select("Button.qml"), testFileUrl("PlatformStyle/+linux/Button.qml").toString());
156#elif defined(Q_OS_MACOS)
157 QCOMPARE(selector.select("Button.qml"), testFileUrl("PlatformStyle/+macos/Button.qml").toString());
158#elif defined(Q_OS_WIN)
159 QCOMPARE(selector.select("Button.qml"), testFileUrl("PlatformStyle/+windows/Button.qml").toString());
160#else
161 QCOMPARE(selector.select("Button.qml"), testFileUrl("PlatformStyle/Button.qml").toString());
162#endif
163}
164
165QTEST_MAIN(tst_QQuickStyleSelector)
166
167#include "tst_qquickstyleselector.moc"
168

source code of qtquickcontrols2/tests/auto/qquickstyleselector/tst_qquickstyleselector.cpp