aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quickcontrols/designer/tst_designer.cpp
blob: 760f739a022a9410e6998e81cc8e22c0f97e839b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#include <QtTest>
#include <QtQuick>

#include <QtQuickControls2>
#include <QQmlComponent>
#include <QDir>

#include <private/qquickdesignersupportitems_p.h>

class tst_Designer : public QObject
{
    Q_OBJECT

private slots:
    void initTestCase();

    void test_controls();
    void test_controls_data();
};


void tst_Designer::initTestCase()
{
    QQuickStyle::setStyle("Basic");
}

void doComponentCompleteRecursive(QObject *object)
{
    if (object) {
        QQuickItem *item = qobject_cast<QQuickItem*>(object);

        if (item && DesignerSupport::isComponentComplete(item))
            return;

        DesignerSupport::emitComponentCompleteSignalForAttachedProperty(qobject_cast<QQuickItem*>(object));

        QList<QObject*> childList = object->children();

        if (item) {
            for (QQuickItem *childItem : item->childItems()) {
                if (!childList.contains(childItem))
                    childList.append(childItem);
            }
        }

        for (QObject *child : childList)
                doComponentCompleteRecursive(child);

        if (item) {
            static_cast<QQmlParserStatus*>(item)->componentComplete();
        } else {
            QQmlParserStatus *qmlParserStatus = dynamic_cast< QQmlParserStatus*>(object);
            if (qmlParserStatus)
                qmlParserStatus->componentComplete();
        }
    }
}


void tst_Designer::test_controls()
{
    QFETCH(QString, type);

    const QByteArray before("import QtQuick\n"
                   "import QtQuick.Controls\n"
                   "Item {\n");

    QByteArray source = before;
    source.append(type.toUtf8());

    const QByteArray after(" {"
                        "}\n"
                        "}\n");

    source.append(after);

    QQmlEngine engine;
    QQmlComponent component(&engine);

    {
        ComponentCompleteDisabler disableComponentComplete;
        component.setData(source, QUrl::fromLocalFile(QDir::current().absolutePath()));
    }

    QObject *root = component.create();
    QVERIFY(root);
    doComponentCompleteRecursive(root);
}

void tst_Designer::test_controls_data()
{
    QTest::addColumn<QString>("type");

    QTest::newRow("Button") << "Button";
    QTest::newRow("CheckBox") << "CheckBox";
    QTest::newRow("ComboBox") << "ComboBox";
    QTest::newRow("DelayButton") << "DelayButton";
    QTest::newRow("Dial") << "Dial";
    QTest::newRow("Frame") << "Frame";
    QTest::newRow("GroupBox") << "GroupBox";
    QTest::newRow("Label") << "Label";
    QTest::newRow("Page") << "Page";
    QTest::newRow("Pane") << "Pane";
    QTest::newRow("ProgressBar") << "ProgressBar";
    QTest::newRow("RadioButton") << "RadioButton";
    QTest::newRow("RangeSlider") << "RangeSlider";
    QTest::newRow("RoundButton") << "RoundButton";
    QTest::newRow("ScrollView") << "ScrollView";
    QTest::newRow("Slider") << "Slider";
    QTest::newRow("SpinBox") << "SpinBox";
    QTest::newRow("StackView") << "StackView";
    QTest::newRow("SwipeView") << "SwipeView";
    QTest::newRow("Switch") << "Switch";
    QTest::newRow("Switch") << "Switch";
    QTest::newRow("TabBar") << "TabBar";
    QTest::newRow("TabButton") << "TabButton";
    QTest::newRow("TextArea") << "TextArea";
    QTest::newRow("TextField") << "TextField";
    QTest::newRow("ToolBar") << "ToolBar";
    QTest::newRow("ToolButton") << "ToolButton";
    QTest::newRow("Tumbler") << "Tumbler";
}

QTEST_MAIN(tst_Designer)

#include "tst_designer.moc"