Debian Codegraph @

tests/auto/animation/qclipblendvalue/tst_qclipblendvalue.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
5 #include <QtTest/QTest>
6 #include <Qt3DAnimation/qclipblendvalue.h>
7 #include <Qt3DAnimation/qanimationcliploader.h>
8 #include <Qt3DAnimation/private/qclipblendvalue_p.h>
9 #include <QObject>
10 #include <QSignalSpy>
11 #include <testarbiter.h>
12
13 class tst_QClipBlendValue : public QObject
14 {
15 Q_OBJECT
16
17 private Q_SLOTS:
18 void initTestCase()
19 {
20 qRegisterMetaType<Qt3DAnimation::QAbstractAnimationClip*>();
21 }
22
23 void checkDefaultConstruction()
24 {
25 // GIVEN
26 Qt3DAnimation::QClipBlendValue clipBlendNode;
27
28 // THEN;
29 QCOMPARE(clipBlendNode.clip(), static_cast<Qt3DAnimation::QAbstractAnimationClip *>(nullptr));
30 }
31
32 void checkPropertyChanges()
33 {
34 // GIVEN
35 Qt3DAnimation::QClipBlendValue clipBlendNode;
36
37 {
38 // WHEN
39 QSignalSpy spy(&clipBlendNode, SIGNAL(clipChanged(Qt3DAnimation::QAbstractAnimationClip*)));
40 auto newValue = new Qt3DAnimation::QAnimationClipLoader();
41 clipBlendNode.setClip(newValue);
42
43 // THEN
44 QVERIFY(spy.isValid());
45 QCOMPARE(clipBlendNode.clip(), newValue);
46 QCOMPARE(spy.size(), 1);
47
48 // WHEN
49 spy.clear();
50 clipBlendNode.setClip(newValue);
51
52 // THEN
53 QCOMPARE(clipBlendNode.clip(), newValue);
54 QCOMPARE(spy.size(), 0);
55 }
56 }
57
58 void checkClipUpdate()
59 {
60 // GIVEN
61 TestArbiter arbiter;
62 Qt3DAnimation::QClipBlendValue clipBlendNode;
63 arbiter.setArbiterOnNode(&clipBlendNode);
64 auto clip = new Qt3DAnimation::QAnimationClipLoader();
65
66 {
67 // WHEN
68 clipBlendNode.setClip(clip);
69
70 // THEN
71 QCOMPARE(arbiter.dirtyNodes().size(), 1);
72 QCOMPARE(arbiter.dirtyNodes().front(), &clipBlendNode);
73
74 arbiter.clear();
75 }
76
77 {
78 // WHEN
79 clipBlendNode.setClip(clip);
80
81 // THEN
82 QCOMPARE(arbiter.dirtyNodes().size(), 0);
83 }
84 }
85
86 void checkStartClipBookkeeping()
87 {
88 // GIVEN
89 QScopedPointer<Qt3DAnimation::QClipBlendValue> clipBlendNode(new Qt3DAnimation::QClipBlendValue);
90 {
91 // WHEN
92 Qt3DAnimation::QAnimationClipLoader clip;
93 clipBlendNode->setClip(&clip);
94
95 // THEN
96 QCOMPARE(clip.parent(), clipBlendNode.data());
97 QCOMPARE(clipBlendNode->clip(), &clip);
98 }
99 // THEN (Should not crash and clip be unset)
100 QVERIFY(clipBlendNode->clip() == nullptr);
101
102 {
103 // WHEN
104 Qt3DAnimation::QClipBlendValue someOtherNode;
105 QScopedPointer<Qt3DAnimation::QAnimationClipLoader> clip(new Qt3DAnimation::QAnimationClipLoader(&someOtherNode));
106 clipBlendNode->setClip(clip.data());
107
108 // THEN
109 QCOMPARE(clip->parent(), &someOtherNode);
110 QCOMPARE(clipBlendNode->clip(), clip.data());
111
112 // WHEN
113 clipBlendNode.reset();
114 clip.reset();
115
116 // THEN Should not crash when the effect is destroyed (tests for failed removal of destruction helper)
117 }
118 }
119 };
120
121 QTEST_MAIN(tst_QClipBlendValue)
122
123 #include "tst_qclipblendvalue.moc"