Debian Codegraph @

tests/auto/animation/clipblendnodevisitor/tst_clipblendnodevisitor.cpp

raw symbols SCIP
1 // Copyright (C) 2017 Paul Lemire <[email protected]>
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4 #include <QtTest/QTest>
5 #include <QObject>
6 #include <QSignalSpy>
7 #include <Qt3DAnimation/private/managers_p.h>
8 #include <Qt3DAnimation/private/clipblendnodevisitor_p.h>
9 #include <Qt3DAnimation/private/lerpclipblend_p.h>
10 #include <Qt3DAnimation/qlerpclipblend.h>
11 #include "qbackendnodetester.h"
12
13 class tst_ClipBlendNodeVisitor : public Qt3DCore::QBackendNodeTester
14 {
15 Q_OBJECT
16
17 private Q_SLOTS:
18 void checkVisitAllNodes()
19 {
20 // GIVEN
21 Qt3DAnimation::QLerpClipBlend rootBlendNode;
22 Qt3DAnimation::QLerpClipBlend childBlendNode1(&rootBlendNode);
23 Qt3DAnimation::QLerpClipBlend childBlendNode2(&rootBlendNode);
24 rootBlendNode.setStartClip(&childBlendNode1);
25 rootBlendNode.setEndClip(&childBlendNode2);
26 Qt3DAnimation::QLerpClipBlend childBlendNode11(&childBlendNode1);
27 Qt3DAnimation::QLerpClipBlend childBlendNode12(&childBlendNode1);
28 childBlendNode1.setStartClip(&childBlendNode11);
29 childBlendNode1.setEndClip(&childBlendNode12);
30
31 Qt3DAnimation::Animation::LerpClipBlend *backendRootBlendNode = new Qt3DAnimation::Animation::LerpClipBlend();
32 Qt3DAnimation::Animation::LerpClipBlend *backendChildBlendNode1 = new Qt3DAnimation::Animation::LerpClipBlend();
33 Qt3DAnimation::Animation::LerpClipBlend *backendChildBlendNode2 = new Qt3DAnimation::Animation::LerpClipBlend();
34 Qt3DAnimation::Animation::LerpClipBlend *backendChildBlendNode11 = new Qt3DAnimation::Animation::LerpClipBlend();
35 Qt3DAnimation::Animation::LerpClipBlend *backendChildBlendNode12 = new Qt3DAnimation::Animation::LerpClipBlend();
36
37 Qt3DAnimation::Animation::ClipBlendNodeManager manager;
38 backendRootBlendNode->setClipBlendNodeManager(&manager);
39 backendChildBlendNode1->setClipBlendNodeManager(&manager);
40 backendChildBlendNode2->setClipBlendNodeManager(&manager);
41 backendChildBlendNode11->setClipBlendNodeManager(&manager);
42 backendChildBlendNode12->setClipBlendNodeManager(&manager);
43
44 manager.appendNode(rootBlendNode.id(), backendRootBlendNode);
45 manager.appendNode(childBlendNode1.id(), backendChildBlendNode1);
46 manager.appendNode(childBlendNode2.id(), backendChildBlendNode2);
47 manager.appendNode(childBlendNode11.id(), backendChildBlendNode11);
48 manager.appendNode(childBlendNode12.id(), backendChildBlendNode12);
49
50 // WHEN
51 simulateInitializationSync(&rootBlendNode, backendRootBlendNode);
52 simulateInitializationSync(&childBlendNode1, backendChildBlendNode1);
53 simulateInitializationSync(&childBlendNode2, backendChildBlendNode2);
54 simulateInitializationSync(&childBlendNode11, backendChildBlendNode11);
55 simulateInitializationSync(&childBlendNode12, backendChildBlendNode12);
56
57 // THEN
58 QCOMPARE(backendRootBlendNode->allDependencyIds().size(), 2);
59 QCOMPARE(backendChildBlendNode1->allDependencyIds().size(), 2);
60 QCOMPARE(backendChildBlendNode2->allDependencyIds().size(), 2);
61 QCOMPARE(backendChildBlendNode11->allDependencyIds().size(), 2);
62 QCOMPARE(backendChildBlendNode12->allDependencyIds().size(), 2);
63
64 // WHEN
65 int i = 0;
66 // Note: post-order traversal
67 auto childCounter = [&] (Qt3DAnimation::Animation::ClipBlendNode *node) {
68 if (i == 0)
69 QCOMPARE(node, backendChildBlendNode11);
70 else if (i == 1)
71 QCOMPARE(node, backendChildBlendNode12);
72 else if (i == 2)
73 QCOMPARE(node, backendChildBlendNode1);
74 else if (i == 3)
75 QCOMPARE(node, backendChildBlendNode2);
76 else if (i == 4)
77 QCOMPARE(node, backendRootBlendNode);
78 ++i;
79 };
80
81 // THEN -> no comparison failure
82 Qt3DAnimation::Animation::ClipBlendNodeVisitor visitor(&manager);
83 visitor.traverse(rootBlendNode.id(), childCounter);
84 }
85
86 void checkDoesntCrashIfRootNodeIsNotFound()
87 {
88 // GIVEN
89 Qt3DAnimation::QLerpClipBlend rootBlendNode;
90
91 Qt3DAnimation::Animation::LerpClipBlend *backendRootBlendNode = new Qt3DAnimation::Animation::LerpClipBlend();
92
93 Qt3DAnimation::Animation::ClipBlendNodeManager manager;
94 backendRootBlendNode->setClipBlendNodeManager(&manager);
95
96 // We purposely forgot the to do: manager.appendNode(rootBlendNode.id(), backendRootBlendNode);
97
98 // WHEN
99 simulateInitializationSync(&rootBlendNode, backendRootBlendNode);
100
101 // THEN
102 QCOMPARE(backendRootBlendNode->allDependencyIds().size(), 2);
103
104 // WHEN
105 auto childCounter = [] (Qt3DAnimation::Animation::ClipBlendNode *) {};
106
107 // THEN -> shouldn't crash
108 Qt3DAnimation::Animation::ClipBlendNodeVisitor visitor(&manager);
109 visitor.traverse(rootBlendNode.id(), childCounter);
110 }
111
112 void checkDoesntCrashIfChildNodeIsNotFound()
113 {
114 // GIVEN
115 Qt3DAnimation::QLerpClipBlend rootBlendNode;
116 Qt3DAnimation::QLerpClipBlend childBlendNode1(&rootBlendNode);
117 Qt3DAnimation::QLerpClipBlend childBlendNode2(&rootBlendNode);
118 rootBlendNode.setStartClip(&childBlendNode1);
119 rootBlendNode.setEndClip(&childBlendNode2);
120
121 Qt3DAnimation::Animation::LerpClipBlend *backendRootBlendNode = new Qt3DAnimation::Animation::LerpClipBlend();
122 Qt3DAnimation::Animation::LerpClipBlend *backendChildBlendNode1 = new Qt3DAnimation::Animation::LerpClipBlend();
123 Qt3DAnimation::Animation::LerpClipBlend *backendChildBlendNode2 = new Qt3DAnimation::Animation::LerpClipBlend();
124
125 Qt3DAnimation::Animation::ClipBlendNodeManager manager;
126 backendRootBlendNode->setClipBlendNodeManager(&manager);
127 backendChildBlendNode1->setClipBlendNodeManager(&manager);
128 backendChildBlendNode2->setClipBlendNodeManager(&manager);
129
130 manager.appendNode(rootBlendNode.id(), backendRootBlendNode);
131 // We purposely forgot the to do:
132 // manager.appendNode(childBlendNode1.id(), backendChildBlendNode1);
133 // manager.appendNode(childBlendNode2.id(), backendChildBlendNode2);
134
135
136 // WHEN
137 simulateInitializationSync(&rootBlendNode, backendRootBlendNode);
138 simulateInitializationSync(&childBlendNode1, backendChildBlendNode1);
139 simulateInitializationSync(&childBlendNode2, backendChildBlendNode2);
140
141 // THEN
142 QCOMPARE(backendRootBlendNode->allDependencyIds().size(), 2);
143 QCOMPARE(backendChildBlendNode1->allDependencyIds().size(), 2);
144 QCOMPARE(backendChildBlendNode2->allDependencyIds().size(), 2);
145
146 // WHEN
147 int i = 0;
148 auto childCounter = [&] (Qt3DAnimation::Animation::ClipBlendNode *) {
149 ++i;
150 };
151
152 // THEN -> shouldn't crash
153 Qt3DAnimation::Animation::ClipBlendNodeVisitor visitor(&manager);
154 visitor.traverse(rootBlendNode.id(), childCounter);
155 QCOMPARE(i, 1);
156 }
157
158 };
159
160 QTEST_MAIN(tst_ClipBlendNodeVisitor)
161
162 #include "tst_clipblendnodevisitor.moc"