1/****************************************************************************
2**
3** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
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#include <QtTest/QTest>
30#include <Qt3DAnimation/private/animationclip_p.h>
31#include <Qt3DAnimation/qanimationcliploader.h>
32#include <Qt3DCore/private/qnode_p.h>
33#include <Qt3DCore/private/qscene_p.h>
34#include <Qt3DCore/private/qbackendnode_p.h>
35#include <qbackendnodetester.h>
36#include <testpostmanarbiter.h>
37
38using namespace Qt3DAnimation::Animation;
39
40class tst_AnimationClip : public Qt3DCore::QBackendNodeTester
41{
42 Q_OBJECT
43
44private Q_SLOTS:
45 void checkPeerPropertyMirroring()
46 {
47 // GIVEN
48 AnimationClip backendClip;
49 Handler handler;
50 backendClip.setHandler(&handler);
51 Qt3DAnimation::QAnimationClipLoader clip;
52
53 clip.setSource(QUrl::fromLocalFile(localfile: "walk.qlip"));
54
55 // WHEN
56 simulateInitializationSync(frontend: &clip, backend: &backendClip);
57
58 // THEN
59 QCOMPARE(backendClip.peerId(), clip.id());
60 QCOMPARE(backendClip.isEnabled(), clip.isEnabled());
61 QCOMPARE(backendClip.source(), clip.source());
62 }
63
64 void checkInitialAndCleanedUpState()
65 {
66 // GIVEN
67 AnimationClip backendClip;
68 Handler handler;
69 backendClip.setHandler(&handler);
70
71 // THEN
72 QVERIFY(backendClip.peerId().isNull());
73 QCOMPARE(backendClip.isEnabled(), false);
74 QCOMPARE(backendClip.source(), QUrl());
75 QCOMPARE(backendClip.duration(), 0.0f);
76 QCOMPARE(backendClip.status(), Qt3DAnimation::QAnimationClipLoader::NotReady);
77
78 // GIVEN
79 Qt3DAnimation::QAnimationClipLoader clip;
80 clip.setSource(QUrl::fromLocalFile(localfile: "walk.qlip"));
81
82 // WHEN
83 simulateInitializationSync(frontend: &clip, backend: &backendClip);
84 backendClip.setSource(QUrl::fromLocalFile(localfile: "run.qlip"));
85 backendClip.cleanup();
86
87 // THEN
88 QCOMPARE(backendClip.source(), QUrl());
89 QCOMPARE(backendClip.isEnabled(), false);
90 QCOMPARE(backendClip.duration(), 0.0f);
91 QCOMPARE(backendClip.status(), Qt3DAnimation::QAnimationClipLoader::NotReady);
92 }
93
94 void checkPropertyChanges()
95 {
96 // GIVEN
97 Qt3DAnimation::QAnimationClipLoader clip;
98 AnimationClip backendClip;
99 Handler handler;
100 backendClip.setHandler(&handler);
101 simulateInitializationSync(frontend: &clip, backend: &backendClip);
102
103 // WHEN
104 clip.setEnabled(false);
105 backendClip.syncFromFrontEnd(frontEnd: &clip, firstTime: false);
106
107 // THEN
108 QCOMPARE(backendClip.isEnabled(), false);
109
110 // WHEN
111 const QUrl newSource = QUrl::fromLocalFile(localfile: "fallover.qlip");
112 clip.setSource(newSource);
113 backendClip.syncFromFrontEnd(frontEnd: &clip, firstTime: false);
114
115 // THEN
116 QCOMPARE(backendClip.source(), newSource);
117 }
118};
119
120QTEST_APPLESS_MAIN(tst_AnimationClip)
121
122#include "tst_animationclip.moc"
123

source code of qt3d/tests/auto/animation/animationclip/tst_animationclip.cpp