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> |
38 | #include <QtQuick> |
39 | |
40 | #include <QtQuickControls2> |
41 | #include <QQmlComponent> |
42 | #include <QDir> |
43 | |
44 | #include <private/qquickdesignersupportitems_p.h> |
45 | |
46 | class tst_Designer : public QObject |
47 | { |
48 | Q_OBJECT |
49 | |
50 | private slots: |
51 | void initTestCase(); |
52 | |
53 | void test_controls(); |
54 | void test_controls_data(); |
55 | }; |
56 | |
57 | |
58 | void tst_Designer::initTestCase() |
59 | { |
60 | } |
61 | |
62 | void doComponentCompleteRecursive(QObject *object) |
63 | { |
64 | if (object) { |
65 | QQuickItem *item = qobject_cast<QQuickItem*>(object); |
66 | |
67 | if (item && DesignerSupport::isComponentComplete(item)) |
68 | return; |
69 | |
70 | DesignerSupport::emitComponentCompleteSignalForAttachedProperty(item: qobject_cast<QQuickItem*>(object)); |
71 | |
72 | QList<QObject*> childList = object->children(); |
73 | |
74 | if (item) { |
75 | for (QQuickItem *childItem : item->childItems()) { |
76 | if (!childList.contains(t: childItem)) |
77 | childList.append(t: childItem); |
78 | } |
79 | } |
80 | |
81 | for (QObject *child : childList) |
82 | doComponentCompleteRecursive(object: child); |
83 | |
84 | if (item) { |
85 | static_cast<QQmlParserStatus*>(item)->componentComplete(); |
86 | } else { |
87 | QQmlParserStatus *qmlParserStatus = dynamic_cast< QQmlParserStatus*>(object); |
88 | if (qmlParserStatus) |
89 | qmlParserStatus->componentComplete(); |
90 | } |
91 | } |
92 | } |
93 | |
94 | |
95 | void tst_Designer::test_controls() |
96 | { |
97 | QFETCH(QString, type); |
98 | |
99 | const QByteArray before("import QtQuick 2.10\n" |
100 | "import QtQuick.Controls 2.3\n" |
101 | "Item {\n"); |
102 | |
103 | QByteArray source = before; |
104 | source.append(s: type); |
105 | |
106 | const QByteArray after(" {" |
107 | "}\n" |
108 | "}\n"); |
109 | |
110 | source.append(a: after); |
111 | |
112 | QQmlEngine engine; |
113 | QQmlComponent component(&engine); |
114 | |
115 | { |
116 | ComponentCompleteDisabler disableComponentComplete; |
117 | component.setData(source, baseUrl: QUrl::fromLocalFile(localfile: QDir::current().absolutePath())); |
118 | } |
119 | |
120 | QObject *root = component.create(); |
121 | QVERIFY(root); |
122 | doComponentCompleteRecursive(object: root); |
123 | } |
124 | |
125 | void tst_Designer::test_controls_data() |
126 | { |
127 | QTest::addColumn<QString>(name: "type"); |
128 | |
129 | QTest::newRow(dataTag: "type") << "SpinBox"; |
130 | QTest::newRow(dataTag: "type") << "Switch"; |
131 | QTest::newRow(dataTag: "type") << "ComboBox"; |
132 | QTest::newRow(dataTag: "type") << "CheckBox"; |
133 | QTest::newRow(dataTag: "type") << "Button"; |
134 | QTest::newRow(dataTag: "type") << "DelayButton"; |
135 | QTest::newRow(dataTag: "type") << "Dial"; |
136 | QTest::newRow(dataTag: "type") << "Frame"; |
137 | QTest::newRow(dataTag: "type") << "GroupBox"; |
138 | QTest::newRow(dataTag: "type") << "Label"; |
139 | QTest::newRow(dataTag: "type") << "Page"; |
140 | QTest::newRow(dataTag: "type") << "Pane"; |
141 | QTest::newRow(dataTag: "type") << "ProgressBar"; |
142 | QTest::newRow(dataTag: "type") << "RadioButton"; |
143 | QTest::newRow(dataTag: "type") << "RangeSlider"; |
144 | QTest::newRow(dataTag: "type") << "RoundButton"; |
145 | QTest::newRow(dataTag: "type") << "ScrollView"; |
146 | QTest::newRow(dataTag: "type") << "Slider"; |
147 | QTest::newRow(dataTag: "type") << "StackView"; |
148 | QTest::newRow(dataTag: "type") << "SwipeView"; |
149 | QTest::newRow(dataTag: "type") << "Switch"; |
150 | QTest::newRow(dataTag: "type") << "TabBar"; |
151 | QTest::newRow(dataTag: "type") << "TabButton"; |
152 | QTest::newRow(dataTag: "type") << "TextArea"; |
153 | QTest::newRow(dataTag: "type") << "TextField"; |
154 | QTest::newRow(dataTag: "type") << "ToolBar"; |
155 | QTest::newRow(dataTag: "type") << "ToolButton"; |
156 | QTest::newRow(dataTag: "type") << "Tumbler"; |
157 | } |
158 | |
159 | QTEST_MAIN(tst_Designer) |
160 | |
161 | #include "tst_designer.moc" |
162 |