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 <QtTest/QtTest> |
29 | #include "../../shared/util.h" |
30 | #include <QtQuick/qquickview.h> |
31 | #include <private/qquickspritesequence_p.h> |
32 | |
33 | class tst_qquickspritesequence : public QQmlDataTest |
34 | { |
35 | Q_OBJECT |
36 | public: |
37 | tst_qquickspritesequence(){} |
38 | |
39 | private slots: |
40 | void test_properties(); |
41 | void test_framerateAdvance();//Separate codepath for QQuickSpriteEngine |
42 | void test_huge();//Separate codepath for QQuickSpriteEngine |
43 | void test_jumpToCrash(); |
44 | void test_spriteBeforeGoal(); |
45 | void test_spriteAfterGoal(); |
46 | }; |
47 | |
48 | void tst_qquickspritesequence::test_properties() |
49 | { |
50 | QQuickView *window = new QQuickView(nullptr); |
51 | |
52 | window->setSource(testFileUrl(fileName: "basic.qml")); |
53 | window->show(); |
54 | QVERIFY(QTest::qWaitForWindowExposed(window)); |
55 | |
56 | QVERIFY(window->rootObject()); |
57 | QQuickSpriteSequence* sprite = window->rootObject()->findChild<QQuickSpriteSequence*>(aName: "sprite"); |
58 | QVERIFY(sprite); |
59 | |
60 | QVERIFY(sprite->running()); |
61 | QVERIFY(sprite->interpolate()); |
62 | |
63 | sprite->setRunning(false); |
64 | QVERIFY(!sprite->running()); |
65 | sprite->setInterpolate(false); |
66 | QVERIFY(!sprite->interpolate()); |
67 | |
68 | delete window; |
69 | } |
70 | |
71 | void tst_qquickspritesequence::test_huge() |
72 | { |
73 | /* Merely tests that it doesn't crash, as waiting for it to complete |
74 | (or even having something to watch) would bloat CI. |
75 | The large allocations of memory involved and separate codepath does make |
76 | a doesn't crash test worthwhile. |
77 | */ |
78 | QQuickView *window = new QQuickView(nullptr); |
79 | |
80 | window->setSource(testFileUrl(fileName: "huge.qml")); |
81 | window->show(); |
82 | QVERIFY(QTest::qWaitForWindowExposed(window)); |
83 | |
84 | QVERIFY(window->rootObject()); |
85 | QQuickSpriteSequence* sprite = window->rootObject()->findChild<QQuickSpriteSequence*>(aName: "sprite"); |
86 | QVERIFY(sprite); |
87 | |
88 | delete window; |
89 | } |
90 | |
91 | void tst_qquickspritesequence::test_framerateAdvance() |
92 | { |
93 | QQuickView *window = new QQuickView(nullptr); |
94 | |
95 | window->setSource(testFileUrl(fileName: "advance.qml")); |
96 | window->show(); |
97 | QVERIFY(QTest::qWaitForWindowExposed(window)); |
98 | |
99 | QVERIFY(window->rootObject()); |
100 | QQuickSpriteSequence* sprite = window->rootObject()->findChild<QQuickSpriteSequence*>(aName: "sprite"); |
101 | QVERIFY(sprite); |
102 | |
103 | QTRY_COMPARE(sprite->currentSprite(), QLatin1String("secondState")); |
104 | delete window; |
105 | } |
106 | |
107 | void tst_qquickspritesequence::test_jumpToCrash() |
108 | { |
109 | QQuickView *window = new QQuickView(nullptr); |
110 | |
111 | window->setSource(testFileUrl(fileName: "crashonstart.qml")); |
112 | window->show(); |
113 | QVERIFY(QTest::qWaitForWindowExposed(window)); |
114 | //verify: Don't crash |
115 | |
116 | delete window; |
117 | } |
118 | |
119 | void tst_qquickspritesequence::test_spriteBeforeGoal() |
120 | { |
121 | QQuickView *window = new QQuickView(nullptr); |
122 | |
123 | window->setSource(testFileUrl(fileName: "spritebeforegoal.qml")); |
124 | window->show(); |
125 | QVERIFY(QTest::qWaitForWindowExposed(window)); |
126 | //verify: Don't crash |
127 | |
128 | delete window; |
129 | } |
130 | |
131 | void tst_qquickspritesequence::test_spriteAfterGoal() |
132 | { |
133 | QQuickView *window = new QQuickView(nullptr); |
134 | |
135 | window->setSource(testFileUrl(fileName: "spriteaftergoal.qml")); |
136 | window->show(); |
137 | QVERIFY(QTest::qWaitForWindowExposed(window)); |
138 | //verify: Don't crash |
139 | |
140 | delete window; |
141 | } |
142 | |
143 | QTEST_MAIN(tst_qquickspritesequence) |
144 | |
145 | #include "tst_qquickspritesequence.moc" |
146 |