1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt3D module 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 | |
29 | |
30 | #include <QtTest/QTest> |
31 | #include <Qt3DAnimation/qclock.h> |
32 | #include <Qt3DAnimation/private/qclock_p.h> |
33 | #include <Qt3DCore/qnodecreatedchange.h> |
34 | #include <Qt3DCore/private/qnodecreatedchangegenerator_p.h> |
35 | #include <QObject> |
36 | #include <QSignalSpy> |
37 | #include <testpostmanarbiter.h> |
38 | |
39 | class tst_QClock : public QObject |
40 | { |
41 | Q_OBJECT |
42 | |
43 | private Q_SLOTS: |
44 | void initTestCase() |
45 | { |
46 | qRegisterMetaType<Qt3DAnimation::QClock*>(); |
47 | } |
48 | |
49 | void checkDefaultConstruction() |
50 | { |
51 | // GIVEN |
52 | Qt3DAnimation::QClock clock; |
53 | |
54 | // THEN |
55 | QCOMPARE(clock.playbackRate(), 1.0); |
56 | } |
57 | |
58 | void checkPropertyChanges() |
59 | { |
60 | // GIVEN |
61 | Qt3DAnimation::QClock clock; |
62 | |
63 | // WHEN |
64 | QSignalSpy spy(&clock, SIGNAL(playbackRateChanged(double))); |
65 | const double newValue = 5.5; |
66 | clock.setPlaybackRate(newValue); |
67 | |
68 | // THEN |
69 | QVERIFY(spy.isValid()); |
70 | QCOMPARE(clock.playbackRate(), newValue); |
71 | QCOMPARE(spy.count(), 1); |
72 | |
73 | // WHEN |
74 | spy.clear(); |
75 | clock.setPlaybackRate(newValue); |
76 | |
77 | // THEN |
78 | QCOMPARE(clock.playbackRate(), newValue); |
79 | QCOMPARE(spy.count(), 0); |
80 | } |
81 | |
82 | void checkCreationData() |
83 | { |
84 | // GIVEN |
85 | Qt3DAnimation::QClock clock; |
86 | clock.setPlaybackRate(10.f); |
87 | |
88 | // WHEN |
89 | QVector<Qt3DCore::QNodeCreatedChangeBasePtr> creationChanges; |
90 | { |
91 | Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&clock); |
92 | creationChanges = creationChangeGenerator.creationChanges(); |
93 | } |
94 | |
95 | // THEN |
96 | { |
97 | QCOMPARE(creationChanges.size(), 1); |
98 | |
99 | const auto creationChangeData = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<Qt3DAnimation::QClockData>>(src: creationChanges.first()); |
100 | const Qt3DAnimation::QClockData data = creationChangeData->data; |
101 | |
102 | QCOMPARE(clock.id(), creationChangeData->subjectId()); |
103 | QCOMPARE(clock.isEnabled(), true); |
104 | QCOMPARE(clock.isEnabled(), creationChangeData->isNodeEnabled()); |
105 | QCOMPARE(clock.metaObject(), creationChangeData->metaObject()); |
106 | QCOMPARE(clock.playbackRate(), data.playbackRate); |
107 | } |
108 | |
109 | // WHEN |
110 | clock.setEnabled(false); |
111 | { |
112 | Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&clock); |
113 | creationChanges = creationChangeGenerator.creationChanges(); |
114 | } |
115 | |
116 | // THEN |
117 | { |
118 | QCOMPARE(creationChanges.size(), 1); |
119 | |
120 | const auto creationChangeData = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<Qt3DAnimation::QClockData>>(src: creationChanges.first()); |
121 | |
122 | QCOMPARE(clock.id(), creationChangeData->subjectId()); |
123 | QCOMPARE(clock.isEnabled(), false); |
124 | QCOMPARE(clock.isEnabled(), creationChangeData->isNodeEnabled()); |
125 | QCOMPARE(clock.metaObject(), creationChangeData->metaObject()); |
126 | } |
127 | } |
128 | |
129 | void checkPropertyUpdate() |
130 | { |
131 | // GIVEN |
132 | TestArbiter arbiter; |
133 | Qt3DAnimation::QClock clock; |
134 | arbiter.setArbiterOnNode(&clock); |
135 | |
136 | { |
137 | // WHEN |
138 | clock.setPlaybackRate(10.5f); |
139 | |
140 | // THEN |
141 | QCOMPARE(arbiter.dirtyNodes.size(), 1); |
142 | QCOMPARE(arbiter.dirtyNodes.front(), &clock); |
143 | |
144 | arbiter.dirtyNodes.clear(); |
145 | } |
146 | |
147 | { |
148 | // WHEN |
149 | clock.setPlaybackRate(10.5f); |
150 | |
151 | // THEN |
152 | QCOMPARE(arbiter.dirtyNodes.size(), 0); |
153 | } |
154 | } |
155 | }; |
156 | |
157 | QTEST_MAIN(tst_QClock) |
158 | |
159 | #include "tst_qclock.moc" |
160 | |