Debian Codegraph @

tests/auto/animation/clipanimator/tst_clipanimator.cpp

raw symbols SCIP
1 // Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4 #include <QtTest/QTest>
5 #include <Qt3DAnimation/private/clipanimator_p.h>
6 #include <Qt3DAnimation/qanimationcliploader.h>
7 #include <Qt3DAnimation/qchannelmapper.h>
8 #include <Qt3DAnimation/qclipanimator.h>
9 #include <Qt3DAnimation/qclock.h>
10 #include <Qt3DCore/private/qnode_p.h>
11 #include <Qt3DCore/private/qscene_p.h>
12 #include <Qt3DCore/private/qbackendnode_p.h>
13 #include <qbackendnodetester.h>
14 #include <testarbiter.h>
15
16 class tst_ClipAnimator: public Qt3DCore::QBackendNodeTester
17 {
18 Q_OBJECT
19
20 private Q_SLOTS:
21 void checkPeerPropertyMirroring()
22 {
23 // GIVEN
24 Qt3DAnimation::Animation::Handler handler;
25 Qt3DAnimation::Animation::ClipAnimator backendAnimator;
26 backendAnimator.setHandler(&handler);
27 Qt3DAnimation::QClipAnimator animator;
28 auto clip = new Qt3DAnimation::QAnimationClipLoader();
29 auto clock = new Qt3DAnimation::QClock();
30
31 animator.setClip(clip);
32 animator.setClock(clock);
33 animator.setLoopCount(10);
34 animator.setNormalizedTime(0.5f);
35
36 // WHEN
37 simulateInitializationSync(&animator, &backendAnimator);
38
39 // THEN
40 QCOMPARE(backendAnimator.peerId(), animator.id());
41 QCOMPARE(backendAnimator.isEnabled(), animator.isEnabled());
42 QCOMPARE(backendAnimator.clipId(), clip->id());
43 QCOMPARE(backendAnimator.clockId(), clock->id());
44 QCOMPARE(backendAnimator.isRunning(), animator.isRunning());
45 QCOMPARE(backendAnimator.loops(), animator.loopCount());
46 QCOMPARE(backendAnimator.normalizedLocalTime(), animator.normalizedTime());
47 }
48
49 void checkInitialAndCleanedUpState()
50 {
51 // GIVEN
52 Qt3DAnimation::Animation::Handler handler;
53 Qt3DAnimation::Animation::ClipAnimator backendAnimator;
54 backendAnimator.setHandler(&handler);
55
56 // THEN
57 QVERIFY(backendAnimator.peerId().isNull());
58 QCOMPARE(backendAnimator.isEnabled(), false);
59 QCOMPARE(backendAnimator.clipId(), Qt3DCore::QNodeId());
60 QCOMPARE(backendAnimator.clockId(), Qt3DCore::QNodeId());
61 QCOMPARE(backendAnimator.isRunning(), false);
62 QCOMPARE(backendAnimator.loops(), 1);
63 QCOMPARE(backendAnimator.normalizedLocalTime(), -1.0);
64
65 // GIVEN
66 Qt3DAnimation::QClipAnimator animator;
67 auto clip = new Qt3DAnimation::QAnimationClipLoader();
68 auto clock = new Qt3DAnimation::QClock();
69 animator.setClip(clip);
70 animator.setClock(clock);
71 animator.setRunning(true);
72 animator.setLoopCount(25);
73 animator.setNormalizedTime(1.0f);
74
75 // WHEN
76 simulateInitializationSync(&animator, &backendAnimator);
77 backendAnimator.setClipId(Qt3DCore::QNodeId::createId());
78 backendAnimator.setClockId(Qt3DCore::QNodeId::createId());
79 backendAnimator.cleanup();
80
81 // THEN
82 QCOMPARE(backendAnimator.clipId(), Qt3DCore::QNodeId());
83 QCOMPARE(backendAnimator.clockId(), Qt3DCore::QNodeId());
84 QCOMPARE(backendAnimator.isEnabled(), false);
85 QCOMPARE(backendAnimator.isRunning(), false);
86 QCOMPARE(backendAnimator.loops(), 1);
87 QCOMPARE(backendAnimator.normalizedLocalTime(), -1.0f);
88 }
89
90 void checkPropertyChanges()
91 {
92 // GIVEN
93 Qt3DAnimation::QClipAnimator animator;
94 Qt3DAnimation::Animation::Handler handler;
95 Qt3DAnimation::Animation::ClipAnimator backendAnimator;
96 backendAnimator.setHandler(&handler);
97 simulateInitializationSync(&animator, &backendAnimator);
98
99 // WHEN
100 animator.setEnabled(false);
101 backendAnimator.syncFromFrontEnd(&animator, false);
102
103 // THEN
104 QCOMPARE(backendAnimator.isEnabled(), false);
105
106 // WHEN
107 auto newClip = new Qt3DAnimation::QAnimationClipLoader();
108 animator.setClip(newClip);
109 backendAnimator.syncFromFrontEnd(&animator, false);
110
111 // THEN
112 QCOMPARE(backendAnimator.clipId(), newClip->id());
113
114 // WHEN
115 auto newMapper = new Qt3DAnimation::QChannelMapper();
116 animator.setChannelMapper(newMapper);
117 backendAnimator.syncFromFrontEnd(&animator, false);
118
119 // THEN
120 QCOMPARE(backendAnimator.mapperId(), newMapper->id());
121
122 // WHEN
123 auto clock = new Qt3DAnimation::QClock();
124 animator.setClock(clock);
125 backendAnimator.syncFromFrontEnd(&animator, false);
126
127 // THEN
128 QCOMPARE(backendAnimator.clockId(), clock->id());
129
130 // WHEN
131 animator.setRunning(true);
132 backendAnimator.syncFromFrontEnd(&animator, false);
133
134 // THEN
135 QCOMPARE(backendAnimator.isRunning(), true);
136
137 // WHEN
138 animator.setLoopCount(64);
139 backendAnimator.syncFromFrontEnd(&animator, false);
140
141 // THEN
142 QCOMPARE(backendAnimator.loops(), 64);
143
144 // WHEN
145 animator.setNormalizedTime(0.5f);
146 backendAnimator.syncFromFrontEnd(&animator, false);
147
148 // THEN
149 QVERIFY(qFuzzyCompare(backendAnimator.normalizedLocalTime(), 0.5f));
150 }
151 };
152
153 QTEST_APPLESS_MAIN(tst_ClipAnimator)
154
155 #include "tst_clipanimator.moc"