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/qanimationcliploader.h> |
32 | #include <Qt3DAnimation/private/qanimationcliploader_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_QAnimationClipLoader : public Qt3DAnimation::QAnimationClipLoader |
40 | { |
41 | Q_OBJECT |
42 | |
43 | private Q_SLOTS: |
44 | void checkDefaultConstruction() |
45 | { |
46 | // GIVEN |
47 | Qt3DAnimation::QAnimationClipLoader clip; |
48 | |
49 | // THEN |
50 | QCOMPARE(clip.source(), QUrl()); |
51 | QCOMPARE(clip.duration(), 0.0f); |
52 | QCOMPARE(clip.status(), Qt3DAnimation::QAnimationClipLoader::NotReady); |
53 | } |
54 | |
55 | void checkPropertyChanges() |
56 | { |
57 | // GIVEN |
58 | Qt3DAnimation::QAnimationClipLoader clip; |
59 | |
60 | { |
61 | // WHEN |
62 | QSignalSpy spy(&clip, SIGNAL(sourceChanged(QUrl))); |
63 | const QUrl newValue(QStringLiteral("qrc:/walk.qlip" )); |
64 | clip.setSource(newValue); |
65 | |
66 | // THEN |
67 | QVERIFY(spy.isValid()); |
68 | QCOMPARE(clip.source(), newValue); |
69 | QCOMPARE(spy.count(), 1); |
70 | |
71 | // WHEN |
72 | spy.clear(); |
73 | clip.setSource(newValue); |
74 | |
75 | // THEN |
76 | QCOMPARE(clip.source(), newValue); |
77 | QCOMPARE(spy.count(), 0); |
78 | } |
79 | } |
80 | |
81 | void checkCreationData() |
82 | { |
83 | // GIVEN |
84 | Qt3DAnimation::QAnimationClipLoader clip; |
85 | |
86 | clip.setSource(QUrl(QStringLiteral("http://someRemoteURL.com" ))); |
87 | |
88 | // WHEN |
89 | QVector<Qt3DCore::QNodeCreatedChangeBasePtr> creationChanges; |
90 | |
91 | { |
92 | Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&clip); |
93 | creationChanges = creationChangeGenerator.creationChanges(); |
94 | } |
95 | |
96 | // THEN |
97 | { |
98 | QCOMPARE(creationChanges.size(), 1); |
99 | |
100 | const auto creationChangeData = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<Qt3DAnimation::QAnimationClipLoaderData>>(src: creationChanges.first()); |
101 | const Qt3DAnimation::QAnimationClipLoaderData data = creationChangeData->data; |
102 | |
103 | QCOMPARE(clip.id(), creationChangeData->subjectId()); |
104 | QCOMPARE(clip.isEnabled(), true); |
105 | QCOMPARE(clip.isEnabled(), creationChangeData->isNodeEnabled()); |
106 | QCOMPARE(clip.metaObject(), creationChangeData->metaObject()); |
107 | QCOMPARE(clip.source(), data.source); |
108 | } |
109 | |
110 | // WHEN |
111 | clip.setEnabled(false); |
112 | |
113 | { |
114 | Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&clip); |
115 | creationChanges = creationChangeGenerator.creationChanges(); |
116 | } |
117 | |
118 | // THEN |
119 | { |
120 | QCOMPARE(creationChanges.size(), 1); |
121 | |
122 | const auto creationChangeData = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<Qt3DAnimation::QAnimationClipLoaderData>>(src: creationChanges.first()); |
123 | |
124 | QCOMPARE(clip.id(), creationChangeData->subjectId()); |
125 | QCOMPARE(clip.isEnabled(), false); |
126 | QCOMPARE(clip.isEnabled(), creationChangeData->isNodeEnabled()); |
127 | QCOMPARE(clip.metaObject(), creationChangeData->metaObject()); |
128 | } |
129 | } |
130 | |
131 | void checkSourceUpdate() |
132 | { |
133 | // GIVEN |
134 | TestArbiter arbiter; |
135 | Qt3DAnimation::QAnimationClipLoader clip; |
136 | arbiter.setArbiterOnNode(&clip); |
137 | |
138 | { |
139 | // WHEN |
140 | clip.setSource(QUrl(QStringLiteral("qrc:/toyplane.qlip" ))); |
141 | |
142 | // THEN |
143 | QCOMPARE(arbiter.events.size(), 0); |
144 | QCOMPARE(arbiter.dirtyNodes.size(), 1); |
145 | QCOMPARE(arbiter.dirtyNodes.front(), &clip); |
146 | |
147 | arbiter.dirtyNodes.clear(); |
148 | } |
149 | |
150 | { |
151 | // WHEN |
152 | clip.setSource(QStringLiteral("qrc:/toyplane.qlip" )); |
153 | |
154 | // THEN |
155 | QCOMPARE(arbiter.events.size(), 0); |
156 | QCOMPARE(arbiter.dirtyNodes.size(), 0); |
157 | } |
158 | |
159 | } |
160 | }; |
161 | |
162 | QTEST_MAIN(tst_QAnimationClipLoader) |
163 | |
164 | #include "tst_qanimationcliploader.moc" |
165 | |