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