1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the test suite of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
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 https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28#include <qtest.h>
29#include <QtQml/qqmlengine.h>
30#include <QtQml/qqmlcomponent.h>
31#include <QtQuick/qquickview.h>
32#include <private/qquickflipable_p.h>
33#include <private/qqmlvaluetype_p.h>
34#include <QFontMetrics>
35#include <QtQuick/private/qquickrectangle_p.h>
36#include <math.h>
37#include "../../shared/util.h"
38
39class tst_qquickflipable : public QQmlDataTest
40{
41 Q_OBJECT
42public:
43
44private slots:
45 void create();
46 void checkFrontAndBack();
47 void setFrontAndBack();
48 void flipFlipable();
49
50 // below here task issues
51 void QTBUG_9161_crash();
52 void QTBUG_8474_qgv_abort();
53
54private:
55 QQmlEngine engine;
56};
57
58void tst_qquickflipable::create()
59{
60 QQmlEngine engine;
61 QQmlComponent c(&engine, testFileUrl(fileName: "test-flipable.qml"));
62 QQuickFlipable *obj = qobject_cast<QQuickFlipable*>(object: c.create());
63
64 QVERIFY(obj != nullptr);
65 delete obj;
66}
67
68void tst_qquickflipable::checkFrontAndBack()
69{
70 QQmlEngine engine;
71 QQmlComponent c(&engine, testFileUrl(fileName: "test-flipable.qml"));
72 QQuickFlipable *obj = qobject_cast<QQuickFlipable*>(object: c.create());
73
74 QVERIFY(obj != nullptr);
75 QVERIFY(obj->front() != nullptr);
76 QVERIFY(obj->back() != nullptr);
77 delete obj;
78}
79
80void tst_qquickflipable::setFrontAndBack()
81{
82 QQmlEngine engine;
83 QQmlComponent c(&engine, testFileUrl(fileName: "test-flipable.qml"));
84 QQuickFlipable *obj = qobject_cast<QQuickFlipable*>(object: c.create());
85
86 QVERIFY(obj != nullptr);
87 QVERIFY(obj->front() != nullptr);
88 QVERIFY(obj->back() != nullptr);
89
90 QString message = c.url().toString() + ":3:1: QML Flipable: front is a write-once property";
91 QTest::ignoreMessage(type: QtWarningMsg, qPrintable(message));
92 obj->setFront(new QQuickRectangle());
93
94 message = c.url().toString() + ":3:1: QML Flipable: back is a write-once property";
95 QTest::ignoreMessage(type: QtWarningMsg, qPrintable(message));
96 obj->setBack(new QQuickRectangle());
97 delete obj;
98}
99
100void tst_qquickflipable::flipFlipable()
101{
102 QQmlEngine engine;
103 QQmlComponent c(&engine, testFileUrl(fileName: "flip-flipable.qml"));
104 QQuickFlipable *obj = qobject_cast<QQuickFlipable*>(object: c.create());
105 QVERIFY(obj != nullptr);
106 QCOMPARE(obj->side(), QQuickFlipable::Front);
107 obj->setProperty(name: "flipped", value: QVariant(true));
108 QTRY_COMPARE(obj->side(), QQuickFlipable::Back);
109 QTRY_COMPARE(obj->side(), QQuickFlipable::Front);
110 QTRY_COMPARE(obj->side(), QQuickFlipable::Back);
111 delete obj;
112}
113
114void tst_qquickflipable::QTBUG_9161_crash()
115{
116 QQuickView *window = new QQuickView;
117 window->setSource(testFileUrl(fileName: "crash.qml"));
118 QQuickItem *root = window->rootObject();
119 QVERIFY(root != nullptr);
120 window->show();
121 delete window;
122}
123
124void tst_qquickflipable::QTBUG_8474_qgv_abort()
125{
126 QQuickView *window = new QQuickView;
127 window->setSource(testFileUrl(fileName: "flipable-abort.qml"));
128 QQuickItem *root = window->rootObject();
129 QVERIFY(root != nullptr);
130 window->show();
131 delete window;
132}
133
134QTEST_MAIN(tst_qquickflipable)
135
136#include "tst_qquickflipable.moc"
137

source code of qtdeclarative/tests/auto/quick/qquickflipable/tst_qquickflipable.cpp