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 | #include <QtTest/QTest> |
30 | #include <Qt3DAnimation/private/blendedclipanimator_p.h> |
31 | #include <Qt3DAnimation/qanimationcliploader.h> |
32 | #include <Qt3DAnimation/qadditiveclipblend.h> |
33 | #include <Qt3DAnimation/qblendedclipanimator.h> |
34 | #include <Qt3DCore/private/qnode_p.h> |
35 | #include <Qt3DCore/private/qscene_p.h> |
36 | #include <Qt3DCore/private/qbackendnode_p.h> |
37 | #include <qbackendnodetester.h> |
38 | #include <testpostmanarbiter.h> |
39 | |
40 | #include <QtTest/QTest> |
41 | #include <Qt3DAnimation/qblendedclipanimator.h> |
42 | #include <Qt3DAnimation/qlerpclipblend.h> |
43 | #include <Qt3DAnimation/qchannelmapper.h> |
44 | #include <Qt3DAnimation/private/qblendedclipanimator_p.h> |
45 | #include <Qt3DAnimation/private/blendedclipanimator_p.h> |
46 | #include "qbackendnodetester.h" |
47 | |
48 | class tst_BlendedClipAnimator : public Qt3DCore::QBackendNodeTester |
49 | { |
50 | Q_OBJECT |
51 | |
52 | private Q_SLOTS: |
53 | |
54 | void checkInitialState() |
55 | { |
56 | // GIVEN |
57 | Qt3DAnimation::Animation::BlendedClipAnimator backendBlendedClipAnimator; |
58 | |
59 | // THEN |
60 | QCOMPARE(backendBlendedClipAnimator.isEnabled(), false); |
61 | QVERIFY(backendBlendedClipAnimator.peerId().isNull()); |
62 | QCOMPARE(backendBlendedClipAnimator.blendTreeRootId(), Qt3DCore::QNodeId()); |
63 | QCOMPARE(backendBlendedClipAnimator.mapperId(), Qt3DCore::QNodeId()); |
64 | QCOMPARE(backendBlendedClipAnimator.isRunning(), false); |
65 | QCOMPARE(backendBlendedClipAnimator.lastLocalTime(), 0.0); |
66 | QCOMPARE(backendBlendedClipAnimator.nsSincePreviousFrame(0), 0); |
67 | QCOMPARE(backendBlendedClipAnimator.currentLoop(), 0); |
68 | QCOMPARE(backendBlendedClipAnimator.loops(), 1); |
69 | |
70 | } |
71 | |
72 | void checkCleanupState() |
73 | { |
74 | // GIVEN |
75 | Qt3DAnimation::Animation::BlendedClipAnimator backendBlendedClipAnimator; |
76 | Qt3DAnimation::Animation::Handler handler; |
77 | backendBlendedClipAnimator.setHandler(&handler); |
78 | |
79 | // WHEN |
80 | backendBlendedClipAnimator.setEnabled(true); |
81 | backendBlendedClipAnimator.setBlendTreeRootId(Qt3DCore::QNodeId::createId()); |
82 | backendBlendedClipAnimator.setMapperId(Qt3DCore::QNodeId::createId()); |
83 | backendBlendedClipAnimator.setRunning(true); |
84 | backendBlendedClipAnimator.setStartTime(28); |
85 | backendBlendedClipAnimator.setLastLocalTime(0.28); |
86 | backendBlendedClipAnimator.cleanup(); |
87 | |
88 | // THEN |
89 | QCOMPARE(backendBlendedClipAnimator.isEnabled(), false); |
90 | QCOMPARE(backendBlendedClipAnimator.blendTreeRootId(), Qt3DCore::QNodeId()); |
91 | QCOMPARE(backendBlendedClipAnimator.mapperId(), Qt3DCore::QNodeId()); |
92 | QCOMPARE(backendBlendedClipAnimator.isRunning(), false); |
93 | QCOMPARE(backendBlendedClipAnimator.lastLocalTime(), 0.0); |
94 | QCOMPARE(backendBlendedClipAnimator.nsSincePreviousFrame(0), 0); |
95 | QCOMPARE(backendBlendedClipAnimator.currentLoop(), 0); |
96 | QCOMPARE(backendBlendedClipAnimator.loops(), 1); |
97 | } |
98 | |
99 | void checkInitializeFromPeer() |
100 | { |
101 | // GIVEN |
102 | Qt3DAnimation::QBlendedClipAnimator blendedClipAnimator; |
103 | Qt3DAnimation::QChannelMapper mapper; |
104 | Qt3DAnimation::QLerpClipBlend blendTree; |
105 | blendedClipAnimator.setRunning(true); |
106 | blendedClipAnimator.setBlendTree(&blendTree); |
107 | blendedClipAnimator.setChannelMapper(&mapper); |
108 | blendedClipAnimator.setLoopCount(10); |
109 | |
110 | { |
111 | // WHEN |
112 | Qt3DAnimation::Animation::BlendedClipAnimator backendBlendedClipAnimator; |
113 | Qt3DAnimation::Animation::Handler handler; |
114 | backendBlendedClipAnimator.setHandler(&handler); |
115 | |
116 | simulateInitializationSync(frontend: &blendedClipAnimator, backend: &backendBlendedClipAnimator); |
117 | |
118 | // THEN |
119 | QCOMPARE(backendBlendedClipAnimator.isEnabled(), true); |
120 | QCOMPARE(backendBlendedClipAnimator.peerId(), blendedClipAnimator.id()); |
121 | QCOMPARE(backendBlendedClipAnimator.blendTreeRootId(), blendTree.id()); |
122 | QCOMPARE(backendBlendedClipAnimator.mapperId(), mapper.id()); |
123 | QCOMPARE(backendBlendedClipAnimator.isRunning(), true); |
124 | QCOMPARE(backendBlendedClipAnimator.loops(), 10); |
125 | } |
126 | { |
127 | // WHEN |
128 | Qt3DAnimation::Animation::BlendedClipAnimator backendBlendedClipAnimator; |
129 | Qt3DAnimation::Animation::Handler handler; |
130 | backendBlendedClipAnimator.setHandler(&handler); |
131 | |
132 | blendedClipAnimator.setEnabled(false); |
133 | simulateInitializationSync(frontend: &blendedClipAnimator, backend: &backendBlendedClipAnimator); |
134 | |
135 | // THEN |
136 | QCOMPARE(backendBlendedClipAnimator.peerId(), blendedClipAnimator.id()); |
137 | QCOMPARE(backendBlendedClipAnimator.isEnabled(), false); |
138 | } |
139 | } |
140 | |
141 | void checkSceneChangeEvents() |
142 | { |
143 | // GIVEN |
144 | Qt3DAnimation::QBlendedClipAnimator blendedClipAnimator; |
145 | Qt3DAnimation::Animation::BlendedClipAnimator backendBlendedClipAnimator; |
146 | Qt3DAnimation::Animation::Handler handler; |
147 | backendBlendedClipAnimator.setHandler(&handler); |
148 | simulateInitializationSync(frontend: &blendedClipAnimator, backend: &backendBlendedClipAnimator); |
149 | |
150 | { |
151 | // WHEN |
152 | const bool newValue = false; |
153 | blendedClipAnimator.setEnabled(newValue); |
154 | backendBlendedClipAnimator.syncFromFrontEnd(frontEnd: &blendedClipAnimator, firstTime: false); |
155 | |
156 | // THEN |
157 | QCOMPARE(backendBlendedClipAnimator.isEnabled(), newValue); |
158 | } |
159 | { |
160 | // WHEN |
161 | auto blendTree = new Qt3DAnimation::QAdditiveClipBlend(); |
162 | blendedClipAnimator.setBlendTree(blendTree); |
163 | backendBlendedClipAnimator.syncFromFrontEnd(frontEnd: &blendedClipAnimator, firstTime: false); |
164 | |
165 | // THEN |
166 | QCOMPARE(backendBlendedClipAnimator.blendTreeRootId(), blendTree->id()); |
167 | } |
168 | { |
169 | // WHEN |
170 | auto channelMapper = new Qt3DAnimation::QChannelMapper(); |
171 | blendedClipAnimator.setChannelMapper(channelMapper); |
172 | backendBlendedClipAnimator.syncFromFrontEnd(frontEnd: &blendedClipAnimator, firstTime: false); |
173 | |
174 | // THEN |
175 | QCOMPARE(backendBlendedClipAnimator.mapperId(), channelMapper->id()); |
176 | } |
177 | { |
178 | // WHEN |
179 | const bool newValue = true; |
180 | blendedClipAnimator.setRunning(newValue); |
181 | backendBlendedClipAnimator.syncFromFrontEnd(frontEnd: &blendedClipAnimator, firstTime: false); |
182 | |
183 | // THEN |
184 | QCOMPARE(backendBlendedClipAnimator.isRunning(), newValue); |
185 | } |
186 | { |
187 | // WHEN |
188 | const int newValue = 883; |
189 | blendedClipAnimator.setLoopCount(newValue); |
190 | backendBlendedClipAnimator.syncFromFrontEnd(frontEnd: &blendedClipAnimator, firstTime: false); |
191 | |
192 | // THEN |
193 | QCOMPARE(backendBlendedClipAnimator.loops(), newValue); |
194 | } |
195 | } |
196 | |
197 | }; |
198 | |
199 | QTEST_APPLESS_MAIN(tst_BlendedClipAnimator) |
200 | |
201 | #include "tst_blendedclipanimator.moc" |
202 | |