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/qquickspringanimation_p.h> |
33 | #include <private/qqmlvaluetype_p.h> |
34 | #include "../../shared/util.h" |
35 | |
36 | class tst_qquickspringanimation : public QQmlDataTest |
37 | { |
38 | Q_OBJECT |
39 | public: |
40 | tst_qquickspringanimation(); |
41 | |
42 | private slots: |
43 | void defaultValues(); |
44 | void values(); |
45 | void disabled(); |
46 | void inTransition(); |
47 | |
48 | private: |
49 | QQmlEngine engine; |
50 | }; |
51 | |
52 | tst_qquickspringanimation::tst_qquickspringanimation() |
53 | { |
54 | } |
55 | |
56 | void tst_qquickspringanimation::defaultValues() |
57 | { |
58 | QQmlEngine engine; |
59 | QQmlComponent c(&engine, testFileUrl(fileName: "springanimation1.qml" )); |
60 | QQuickSpringAnimation *obj = qobject_cast<QQuickSpringAnimation*>(object: c.create()); |
61 | |
62 | QVERIFY(obj != nullptr); |
63 | |
64 | QCOMPARE(obj->to(), 0.); |
65 | QCOMPARE(obj->velocity(), 0.); |
66 | QCOMPARE(obj->spring(), 0.); |
67 | QCOMPARE(obj->damping(), 0.); |
68 | QCOMPARE(obj->epsilon(), 0.01); |
69 | QCOMPARE(obj->modulus(), 0.); |
70 | QCOMPARE(obj->mass(), 1.); |
71 | QCOMPARE(obj->isRunning(), false); |
72 | |
73 | delete obj; |
74 | } |
75 | |
76 | void tst_qquickspringanimation::values() |
77 | { |
78 | QQmlEngine engine; |
79 | QQmlComponent c(&engine, testFileUrl(fileName: "springanimation2.qml" )); |
80 | QObject *root = c.create(); |
81 | |
82 | QQuickSpringAnimation *obj = root->findChild<QQuickSpringAnimation*>(); |
83 | |
84 | QVERIFY(obj != nullptr); |
85 | |
86 | QCOMPARE(obj->to(), 1.44); |
87 | QCOMPARE(obj->velocity(), 0.9); |
88 | QCOMPARE(obj->spring(), 1.0); |
89 | QCOMPARE(obj->damping(), 0.5); |
90 | QCOMPARE(obj->epsilon(), 0.25); |
91 | QCOMPARE(obj->modulus(), 360.0); |
92 | QCOMPARE(obj->mass(), 2.0); |
93 | QCOMPARE(obj->isRunning(), true); |
94 | |
95 | QTRY_COMPARE(obj->isRunning(), false); |
96 | |
97 | delete obj; |
98 | } |
99 | |
100 | void tst_qquickspringanimation::disabled() |
101 | { |
102 | QQmlEngine engine; |
103 | QQmlComponent c(&engine, testFileUrl(fileName: "springanimation3.qml" )); |
104 | QQuickSpringAnimation *obj = qobject_cast<QQuickSpringAnimation*>(object: c.create()); |
105 | |
106 | QVERIFY(obj != nullptr); |
107 | |
108 | QCOMPARE(obj->to(), 1.44); |
109 | QCOMPARE(obj->velocity(), 0.9); |
110 | QCOMPARE(obj->spring(), 1.0); |
111 | QCOMPARE(obj->damping(), 0.5); |
112 | QCOMPARE(obj->epsilon(), 0.25); |
113 | QCOMPARE(obj->modulus(), 360.0); |
114 | QCOMPARE(obj->mass(), 2.0); |
115 | QCOMPARE(obj->isRunning(), false); |
116 | |
117 | delete obj; |
118 | } |
119 | |
120 | void tst_qquickspringanimation::inTransition() |
121 | { |
122 | QQuickView view(testFileUrl(fileName: "inTransition.qml" )); |
123 | view.show(); |
124 | // this used to crash after ~1 sec, once the spring animation was done |
125 | QTest::qWait(ms: 2000); |
126 | } |
127 | |
128 | QTEST_MAIN(tst_qquickspringanimation) |
129 | |
130 | #include "tst_qquickspringanimation.moc" |
131 | |