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 <Qt3DCore/qskeletonloader.h>
32#include <Qt3DCore/qjoint.h>
33#include <Qt3DCore/private/qskeletonloader_p.h>
34#include <Qt3DCore/qpropertyupdatedchange.h>
35#include <Qt3DCore/qnodecreatedchange.h>
36#include <Qt3DCore/private/qnodecreatedchangegenerator_p.h>
37#include <QObject>
38#include <QSignalSpy>
39#include <testpostmanarbiter.h>
40
41using namespace Qt3DCore;
42
43class tst_QSkeletonLoader : public QSkeletonLoader
44{
45 Q_OBJECT
46
47private Q_SLOTS:
48 void checkDefaultConstruction()
49 {
50 // GIVEN
51 QSkeletonLoader skeleton;
52
53 // THEN
54 QCOMPARE(skeleton.source(), QUrl());
55 QCOMPARE(skeleton.status(), QSkeletonLoader::NotReady);
56 QCOMPARE(skeleton.isCreateJointsEnabled(), false);
57 }
58
59 void checkPropertyChanges()
60 {
61 // GIVEN
62 QSkeletonLoader skeleton;
63
64 {
65 // WHEN
66 QSignalSpy spy(&skeleton, SIGNAL(sourceChanged(QUrl)));
67 const QUrl newValue(QStringLiteral("qrc:/zergling.skel"));
68 skeleton.setSource(newValue);
69
70 // THEN
71 QVERIFY(spy.isValid());
72 QCOMPARE(skeleton.source(), newValue);
73 QCOMPARE(spy.count(), 1);
74
75 // WHEN
76 spy.clear();
77 skeleton.setSource(newValue);
78
79 // THEN
80 QCOMPARE(skeleton.source(), newValue);
81 QCOMPARE(spy.count(), 0);
82 }
83
84 {
85 // WHEN
86 QSignalSpy spy(&skeleton, SIGNAL(createJointsEnabledChanged(bool)));
87 const bool newValue(true);
88 skeleton.setCreateJointsEnabled(newValue);
89
90 // THEN
91 QVERIFY(spy.isValid());
92 QCOMPARE(skeleton.isCreateJointsEnabled(), newValue);
93 QCOMPARE(spy.count(), 1);
94
95 // WHEN
96 spy.clear();
97 skeleton.setCreateJointsEnabled(newValue);
98
99 // THEN
100 QCOMPARE(skeleton.isCreateJointsEnabled(), newValue);
101 QCOMPARE(spy.count(), 0);
102 }
103 }
104
105 void checkCreationData()
106 {
107 // GIVEN
108 QSkeletonLoader skeleton;
109
110 skeleton.setSource(QUrl(QStringLiteral("http://someRemoteURL.com/dem-bones.skel")));
111
112 // WHEN
113 QVector<Qt3DCore::QNodeCreatedChangeBasePtr> creationChanges;
114
115 {
116 QNodeCreatedChangeGenerator creationChangeGenerator(&skeleton);
117 creationChanges = creationChangeGenerator.creationChanges();
118 }
119
120 // THEN
121 {
122 QCOMPARE(creationChanges.size(), 1);
123
124 const auto creationChangeData = qSharedPointerCast<QNodeCreatedChange<QSkeletonLoaderData>>(src: creationChanges.first());
125 const QSkeletonLoaderData data = creationChangeData->data;
126
127 QCOMPARE(skeleton.id(), creationChangeData->subjectId());
128 QCOMPARE(skeleton.isEnabled(), true);
129 QCOMPARE(skeleton.isEnabled(), creationChangeData->isNodeEnabled());
130 QCOMPARE(skeleton.metaObject(), creationChangeData->metaObject());
131 QCOMPARE(skeleton.source(), data.source);
132 QCOMPARE(skeleton.isCreateJointsEnabled(), data.createJoints);
133 }
134
135 // WHEN
136 skeleton.setEnabled(false);
137
138 {
139 QNodeCreatedChangeGenerator creationChangeGenerator(&skeleton);
140 creationChanges = creationChangeGenerator.creationChanges();
141 }
142
143 // THEN
144 {
145 QCOMPARE(creationChanges.size(), 1);
146
147 const auto creationChangeData = qSharedPointerCast<QNodeCreatedChange<QSkeletonLoaderData>>(src: creationChanges.first());
148 const QSkeletonLoaderData data = creationChangeData->data;
149
150 QCOMPARE(skeleton.id(), creationChangeData->subjectId());
151 QCOMPARE(skeleton.isEnabled(), false);
152 QCOMPARE(skeleton.isEnabled(), creationChangeData->isNodeEnabled());
153 QCOMPARE(skeleton.metaObject(), creationChangeData->metaObject());
154 QCOMPARE(skeleton.source(), data.source);
155 QCOMPARE(skeleton.isCreateJointsEnabled(), data.createJoints);
156 }
157 }
158
159 void checkPropertyUpdates()
160 {
161 // GIVEN
162 TestArbiter arbiter;
163 QSkeletonLoader skeleton;
164 arbiter.setArbiterOnNode(&skeleton);
165
166 {
167 // WHEN
168 skeleton.setSource(QUrl(QStringLiteral("qrc:/hydralisk.skel")));
169 QCoreApplication::processEvents();
170
171 // THEN
172 QCOMPARE(arbiter.events.size(), 0);
173 QCOMPARE(arbiter.dirtyNodes.size(), 1);
174 QCOMPARE(arbiter.dirtyNodes[0], &skeleton);
175
176 arbiter.dirtyNodes.clear();
177 }
178
179 {
180 // WHEN
181 skeleton.setSource(QStringLiteral("qrc:/hydralisk.skel"));
182 QCoreApplication::processEvents();
183
184 // THEN
185 QCOMPARE(arbiter.events.size(), 0);
186 QCOMPARE(arbiter.dirtyNodes.size(), 0);
187 }
188
189 {
190 // WHEN
191 skeleton.setCreateJointsEnabled(true);
192 QCoreApplication::processEvents();
193
194 // THEN
195 QCOMPARE(arbiter.events.size(), 0);
196 QCOMPARE(arbiter.dirtyNodes.size(), 1);
197 QCOMPARE(arbiter.dirtyNodes[0], &skeleton);
198
199 arbiter.dirtyNodes.clear();
200 }
201
202 {
203 // WHEN
204 skeleton.setCreateJointsEnabled(true);
205 QCoreApplication::processEvents();
206
207 // THEN
208 QCOMPARE(arbiter.events.size(), 0);
209 QCOMPARE(arbiter.events.size(), 0);
210 }
211 }
212};
213
214QTEST_MAIN(tst_QSkeletonLoader)
215
216#include "tst_qskeletonloader.moc"
217

source code of qt3d/tests/auto/core/qskeletonloader/tst_qskeletonloader.cpp