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/qclock.h>
31#include <Qt3DAnimation/private/clock_p.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
38class tst_Clock: public Qt3DCore::QBackendNodeTester
39{
40 Q_OBJECT
41
42private Q_SLOTS:
43 void checkPeerPropertyMirroring()
44 {
45 // GIVEN
46 Qt3DAnimation::Animation::Clock backendClock;
47 Qt3DAnimation::QClock clock;
48
49 clock.setPlaybackRate(10.5);
50
51 // WHEN
52 simulateInitializationSync(frontend: &clock, backend: &backendClock);
53
54 // THEN
55 QCOMPARE(backendClock.playbackRate(), clock.playbackRate());
56 }
57
58 void checkInitialAndCleanedUpState()
59 {
60 // GIVEN
61 Qt3DAnimation::Animation::Clock backendClock;
62
63 // THEN
64 QCOMPARE(backendClock.playbackRate(), 1.0);
65
66 // GIVEN
67 Qt3DAnimation::QClock clock;
68 clock.setPlaybackRate(10.5);
69
70 // WHEN
71 simulateInitializationSync(frontend: &clock, backend: &backendClock);
72 backendClock.cleanup();
73
74 // THEN
75 QCOMPARE(backendClock.playbackRate(), 1.0);
76 }
77
78 void checkSceneChangeEvents()
79 {
80 // GIVEN
81 Qt3DAnimation::QClock clock;
82 Qt3DAnimation::Animation::Clock backendClock;
83 simulateInitializationSync(frontend: &clock, backend: &backendClock);
84
85 {
86 // WHEN
87 const bool newValue = false;
88 clock.setEnabled(newValue);
89 backendClock.syncFromFrontEnd(frontEnd: &clock, firstTime: false);
90
91 // THEN
92 QCOMPARE(backendClock.isEnabled(), newValue);
93 }
94 {
95 // WHEN
96 const double newPlaybackRateValue = 2.0;
97 clock.setPlaybackRate(newPlaybackRateValue);
98 backendClock.syncFromFrontEnd(frontEnd: &clock, firstTime: false);
99
100 // THEN
101 QCOMPARE(backendClock.playbackRate(), newPlaybackRateValue);
102 }
103 }
104};
105
106QTEST_APPLESS_MAIN(tst_Clock)
107
108#include "tst_clock.moc"
109

source code of qt3d/tests/auto/animation/clock/tst_clock.cpp