Debian Codegraph @

tests/auto/core/qjoint/tst_qjoint.cpp

raw symbols SCIP
1 // Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4 #include <QtTest/QTest>
5 #include <Qt3DCore/qjoint.h>
6 #include <Qt3DCore/private/qjoint_p.h>
7 #include <QObject>
8 #include <QSignalSpy>
9 #include <testarbiter.h>
10
11 #include <QtGui/qquaternion.h>
12
13 using namespace Qt3DCore;
14
15 class tst_QJoint : public QObject
16 {
17 Q_OBJECT
18
19 private Q_SLOTS:
20 void checkDefaultConstruction()
21 {
22 // GIVEN
23 QJoint joint;
24
25 // THEN
26 QCOMPARE(joint.scale(), QVector3D(1.0f, 1.0f, 1.0f));
27 QCOMPARE(joint.rotation(), QQuaternion());
28 QCOMPARE(joint.translation(), QVector3D(0.0f, 0.0f, 0.0f));
29 QCOMPARE(joint.inverseBindMatrix(), QMatrix4x4());
30 QCOMPARE(joint.rotationX(), 0.0f);
31 QCOMPARE(joint.rotationY(), 0.0f);
32 QCOMPARE(joint.rotationZ(), 0.0f);
33 }
34
35 void checkPropertyChanges()
36 {
37 // GIVEN
38 QJoint joint;
39
40 {
41 // WHEN
42 joint.setToIdentity();
43 QSignalSpy spy(&joint, SIGNAL(scaleChanged(QVector3D)));
44 const QVector3D newValue(2.5f, 2.0f, 1.3f);
45 joint.setScale(newValue);
46
47 // THEN
48 QVERIFY(spy.isValid());
49 QCOMPARE(joint.scale(), newValue);
50 QCOMPARE(spy.size(), 1);
51
52 // WHEN
53 spy.clear();
54 joint.setScale(newValue);
55
56 // THEN
57 QCOMPARE(joint.scale(), newValue);
58 QCOMPARE(spy.size(), 0);
59 }
60
61 {
62 // WHEN
63 joint.setToIdentity();
64 QSignalSpy spy(&joint, SIGNAL(rotationChanged(QQuaternion)));
65 const auto newValue = QQuaternion::fromAxisAndAngle(0.0f, 1.0f, 0.0f, 45.0f);
66 joint.setRotation(newValue);
67
68 // THEN
69 QVERIFY(spy.isValid());
70 QCOMPARE(joint.rotation(), newValue);
71 QCOMPARE(spy.size(), 1);
72
73 // WHEN
74 spy.clear();
75 joint.setRotation(newValue);
76
77 // THEN
78 QCOMPARE(joint.rotation(), newValue);
79 QCOMPARE(spy.size(), 0);
80 }
81
82 {
83 // WHEN
84 joint.setToIdentity();
85 QSignalSpy spy(&joint, SIGNAL(translationChanged(QVector3D)));
86 const QVector3D newValue(1.0f, 2.0f, 3.0f);
87 joint.setTranslation(newValue);
88
89 // THEN
90 QVERIFY(spy.isValid());
91 QCOMPARE(joint.translation(), newValue);
92 QCOMPARE(spy.size(), 1);
93
94 // WHEN
95 spy.clear();
96 joint.setTranslation(newValue);
97
98 // THEN
99 QCOMPARE(joint.translation(), newValue);
100 QCOMPARE(spy.size(), 0);
101 }
102
103 {
104 // WHEN
105 joint.setToIdentity();
106 QSignalSpy spy(&joint, SIGNAL(inverseBindMatrixChanged(QMatrix4x4)));
107 QMatrix4x4 newValue;
108 newValue.scale(3.5f);
109 joint.setInverseBindMatrix(newValue);
110
111 // THEN
112 QVERIFY(spy.isValid());
113 QCOMPARE(joint.inverseBindMatrix(), newValue);
114 QCOMPARE(spy.size(), 1);
115
116 // WHEN
117 spy.clear();
118 joint.setInverseBindMatrix(newValue);
119
120 // THEN
121 QCOMPARE(joint.inverseBindMatrix(), newValue);
122 QCOMPARE(spy.size(), 0);
123 }
124
125 {
126 // WHEN
127 joint.setToIdentity();
128 QSignalSpy spy(&joint, SIGNAL(rotationChanged(QQuaternion)));
129 QSignalSpy spyEuler(&joint, SIGNAL(rotationXChanged(float)));
130 const auto newValue = 45.0f;
131 const auto newValueAsQuaternion = QQuaternion::fromEulerAngles(newValue, 0.0f, 0.0f);
132 joint.setRotationX(newValue);
133
134 // THEN
135 QVERIFY(spy.isValid());
136 QVERIFY(spyEuler.isValid());
137 QCOMPARE(joint.rotationX(), newValue);
138 QCOMPARE(joint.rotation(), newValueAsQuaternion);
139 QCOMPARE(spy.size(), 1);
140 QCOMPARE(spyEuler.size(), 1);
141
142 // WHEN
143 spy.clear();
144 spyEuler.clear();
145 joint.setRotationX(newValue);
146
147 // THEN
148 QCOMPARE(joint.rotationX(), newValue);
149 QCOMPARE(joint.rotation(), newValueAsQuaternion);
150 QCOMPARE(spy.size(), 0);
151 QCOMPARE(spyEuler.size(), 0);
152
153 joint.setRotationX(0.0f);
154 }
155
156 {
157 // WHEN
158 joint.setToIdentity();
159 QSignalSpy spy(&joint, SIGNAL(rotationChanged(QQuaternion)));
160 QSignalSpy spyEuler(&joint, SIGNAL(rotationYChanged(float)));
161 const auto newValue = 45.0f;
162 const auto newValueAsQuaternion = QQuaternion::fromEulerAngles(0.0f, newValue, 0.0f);
163 joint.setRotationY(newValue);
164
165 // THEN
166 QVERIFY(spy.isValid());
167 QVERIFY(spyEuler.isValid());
168 QCOMPARE(joint.rotationY(), newValue);
169 QCOMPARE(joint.rotation(), newValueAsQuaternion);
170 QCOMPARE(spy.size(), 1);
171 QCOMPARE(spyEuler.size(), 1);
172
173 // WHEN
174 spy.clear();
175 spyEuler.clear();
176 joint.setRotationY(newValue);
177
178 // THEN
179 QCOMPARE(joint.rotationY(), newValue);
180 QCOMPARE(joint.rotation(), newValueAsQuaternion);
181 QCOMPARE(spy.size(), 0);
182 QCOMPARE(spyEuler.size(), 0);
183
184 joint.setRotationY(0.0f);
185 }
186
187 {
188 // WHEN
189 joint.setToIdentity();
190 QSignalSpy spy(&joint, SIGNAL(rotationChanged(QQuaternion)));
191 QSignalSpy spyEuler(&joint, SIGNAL(rotationZChanged(float)));
192 const auto newValue = 45.0f;
193 const auto newValueAsQuaternion = QQuaternion::fromEulerAngles(0.0f, 0.0f, newValue);
194 joint.setRotationZ(newValue);
195
196 // THEN
197 QVERIFY(spy.isValid());
198 QVERIFY(spyEuler.isValid());
199 QCOMPARE(joint.rotationZ(), newValue);
200 QCOMPARE(joint.rotation(), newValueAsQuaternion);
201 QCOMPARE(spy.size(), 1);
202 QCOMPARE(spyEuler.size(), 1);
203
204 // WHEN
205 spy.clear();
206 spyEuler.clear();
207 joint.setRotationZ(newValue);
208
209 // THEN
210 QCOMPARE(joint.rotationZ(), newValue);
211 QCOMPARE(joint.rotation(), newValueAsQuaternion);
212 QCOMPARE(spy.size(), 0);
213 QCOMPARE(spyEuler.size(), 0);
214
215 joint.setRotationZ(0.0f);
216 }
217 }
218
219 void checkPropertyUpdateChanges()
220 {
221 // GIVEN
222 TestArbiter arbiter;
223 QJoint joint;
224 arbiter.setArbiterOnNode(&joint);
225
226 {
227 // WHEN
228 joint.setScale(QVector3D(2.0f, 1.0f, 3.0f));
229
230 // THEN
231 QCOMPARE(arbiter.dirtyNodes().size(), 1);
232 QCOMPARE(arbiter.dirtyNodes().front(), &joint);
233
234 arbiter.clear();
235
236 // WHEN
237 joint.setScale(QVector3D(2.0f, 1.0f, 3.0f));
238
239 // THEN
240 QCOMPARE(arbiter.dirtyNodes().size(), 0);
241 }
242
243 {
244 // WHEN
245 const auto newValue = QQuaternion::fromAxisAndAngle(1.0f, 1.0f, 1.0f, 45.0f);
246 joint.setRotation(newValue);
247
248 // THEN
249 QCOMPARE(arbiter.dirtyNodes().size(), 1);
250 QCOMPARE(arbiter.dirtyNodes().front(), &joint);
251
252 arbiter.clear();
253
254 // WHEN
255 joint.setRotation(newValue);
256
257 // THEN
258 QCOMPARE(arbiter.dirtyNodes().size(), 0);
259 }
260
261 {
262 // WHEN
263 const QVector3D newValue(1.0f, 2.0f, 3.0f);
264 joint.setTranslation(newValue);
265
266 // THEN
267 QCOMPARE(arbiter.dirtyNodes().size(), 1);
268 QCOMPARE(arbiter.dirtyNodes().front(), &joint);
269
270 arbiter.clear();
271
272 // WHEN
273 joint.setTranslation(newValue);
274
275 // THEN
276 QCOMPARE(arbiter.dirtyNodes().size(), 0);
277 }
278
279 {
280 // WHEN
281 QMatrix4x4 newValue;
282 newValue.rotate(90.0f, 1.0f, 0.0f, 0.0f);
283 joint.setInverseBindMatrix(newValue);
284
285 // THEN
286 QCOMPARE(arbiter.dirtyNodes().size(), 1);
287 QCOMPARE(arbiter.dirtyNodes().front(), &joint);
288
289 arbiter.clear();
290
291 // WHEN
292 joint.setInverseBindMatrix(newValue);
293
294 // THEN
295 QCOMPARE(arbiter.dirtyNodes().size(), 0);
296 }
297 }
298 };
299
300 QTEST_MAIN(tst_QJoint)
301
302 #include "tst_qjoint.moc"