1/****************************************************************************
2**
3** Copyright (C) 2017 Paul Lemire <paul.lemire350@gmail.com>
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 <QObject>
32#include <QSignalSpy>
33#include <Qt3DAnimation/private/managers_p.h>
34#include <Qt3DAnimation/private/clipblendnode_p.h>
35
36namespace {
37
38int deadCount = 0;
39
40class TestClipBlendNode : public Qt3DAnimation::Animation::ClipBlendNode
41{
42public:
43 TestClipBlendNode()
44 : Qt3DAnimation::Animation::ClipBlendNode(Qt3DAnimation::Animation::ClipBlendNode::NoneBlendType)
45 {}
46
47 ~TestClipBlendNode()
48 {
49 deadCount += 1;
50 }
51
52 inline QVector<Qt3DCore::QNodeId> allDependencyIds() const override
53 {
54 return currentDependencyIds();
55 }
56
57 QVector<Qt3DCore::QNodeId> currentDependencyIds() const final
58 {
59 return QVector<Qt3DCore::QNodeId>();
60 }
61
62 double duration() const final { return 0.0f; }
63
64protected:
65 Qt3DAnimation::Animation::ClipResults doBlend(const QVector<Qt3DAnimation::Animation::ClipResults> &) const final
66 {
67 return Qt3DAnimation::Animation::ClipResults();
68 }
69};
70
71} // anonymous
72
73class tst_ClipBlendNodeManager : public QObject
74{
75 Q_OBJECT
76
77private Q_SLOTS:
78
79 void checkCointainsNode()
80 {
81 // GIVEN
82 Qt3DAnimation::Animation::ClipBlendNodeManager manager;
83 const Qt3DCore::QNodeId nodeId = Qt3DCore::QNodeId::createId();
84
85 // THEN
86 QVERIFY(manager.containsNode(nodeId) == false);
87
88 // WHEN
89 TestClipBlendNode *node = new TestClipBlendNode();
90 manager.appendNode(nodeId, node);
91
92 // THEN
93 QVERIFY(manager.containsNode(nodeId));
94 }
95
96 void checkAppendNode()
97 {
98 // GIVEN
99 Qt3DAnimation::Animation::ClipBlendNodeManager manager;
100 const Qt3DCore::QNodeId nodeId = Qt3DCore::QNodeId::createId();
101 const Qt3DCore::QNodeId nodeId2 = Qt3DCore::QNodeId::createId();
102 TestClipBlendNode *node = new TestClipBlendNode();
103 TestClipBlendNode *node2 = new TestClipBlendNode();
104
105 // WHEN
106 manager.appendNode(nodeId, node);
107 manager.appendNode(nodeId2, node2);
108
109 // THEN
110 QVERIFY(manager.containsNode(nodeId));
111 QVERIFY(manager.containsNode(nodeId2));
112 }
113
114 void checkLookupNode()
115 {
116 // GIVEN
117 Qt3DAnimation::Animation::ClipBlendNodeManager manager;
118 const Qt3DCore::QNodeId nodeId = Qt3DCore::QNodeId::createId();
119 const Qt3DCore::QNodeId nodeId2 = Qt3DCore::QNodeId::createId();
120 TestClipBlendNode *node = new TestClipBlendNode();
121 TestClipBlendNode *node2 = new TestClipBlendNode();
122
123 // WHEN
124 manager.appendNode(nodeId, node);
125 manager.appendNode(nodeId2, node2);
126 Qt3DAnimation::Animation::ClipBlendNode *lookedUpNode = manager.lookupNode(nodeId);
127
128 // THEN
129 QCOMPARE(lookedUpNode, node);
130
131 // WHEN
132 lookedUpNode = manager.lookupNode(nodeId2);
133
134 // THEN
135 QCOMPARE(lookedUpNode, node2);
136
137 // WHEN
138 lookedUpNode = manager.lookupNode(Qt3DCore::QNodeId::createId());
139
140 // THEN
141 QVERIFY(lookedUpNode == nullptr);
142 }
143
144 void checkReleaseNode()
145 {
146 // GIVEN
147 Qt3DAnimation::Animation::ClipBlendNodeManager manager;
148 const Qt3DCore::QNodeId nodeId = Qt3DCore::QNodeId::createId();
149 TestClipBlendNode *node = new TestClipBlendNode();
150 deadCount = 0;
151
152 // WHEN
153 manager.appendNode(nodeId, node);
154
155 // THEN
156 QCOMPARE(deadCount, 0);
157
158 // WHEN
159 manager.releaseNode(nodeId);
160
161 // THEN
162 QCOMPARE(deadCount, 1);
163 }
164
165 void checkDestruction()
166 {
167 // GIVEN
168 const Qt3DCore::QNodeId nodeId = Qt3DCore::QNodeId::createId();
169 const Qt3DCore::QNodeId nodeId2 = Qt3DCore::QNodeId::createId();
170 TestClipBlendNode *node = new TestClipBlendNode();
171 TestClipBlendNode *node2 = new TestClipBlendNode();
172
173 // WHEN
174 {
175 Qt3DAnimation::Animation::ClipBlendNodeManager manager;
176 deadCount = 0;
177
178 // WHEN
179 manager.appendNode(nodeId, node);
180 manager.appendNode(nodeId2, node2);
181
182 // THEN
183 QCOMPARE(deadCount, 0);
184 }
185
186 // THEN
187 QCOMPARE(deadCount, 2);
188 }
189};
190
191QTEST_MAIN(tst_ClipBlendNodeManager)
192
193#include "tst_clipblendnodemanager.moc"
194