1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
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.h>
30#include <Qt3DAnimation/qabstractanimation.h>
31#include <Qt3DCore/qnode.h>
32#include <qobject.h>
33#include <qsignalspy.h>
34
35#include <private/qabstractanimation_p.h>
36
37class TestAnimation : public Qt3DAnimation::QAbstractAnimation
38{
39public:
40 explicit TestAnimation(Qt3DCore::QNode *parent = nullptr)
41 : Qt3DAnimation::QAbstractAnimation(
42 *new Qt3DAnimation::QAbstractAnimationPrivate(
43 Qt3DAnimation::QAbstractAnimation::KeyframeAnimation), parent)
44 {
45
46 }
47};
48
49class tst_QAbstractAnimation : public QObject
50{
51 Q_OBJECT
52
53private Q_SLOTS:
54
55 void checkDefaultConstruction()
56 {
57 // GIVEN
58 TestAnimation abstractAnimation;
59
60 // THEN
61 QCOMPARE(abstractAnimation.animationName(), QString());
62 QCOMPARE(abstractAnimation.animationType(),
63 Qt3DAnimation::QAbstractAnimation::KeyframeAnimation);
64 QCOMPARE(abstractAnimation.position(), 0.0f);
65 QCOMPARE(abstractAnimation.duration(), 0.0f);
66 }
67
68 void checkPropertyChanges()
69 {
70 // GIVEN
71 TestAnimation abstractAnimation;
72
73 {
74 // WHEN
75 QSignalSpy spy(&abstractAnimation, SIGNAL(animationNameChanged(QString)));
76 const QString newValue = QString("test");
77 abstractAnimation.setAnimationName(newValue);
78
79 // THEN
80 QCOMPARE(abstractAnimation.animationName(), newValue);
81 QCOMPARE(spy.count(), 1);
82
83 // WHEN
84 spy.clear();
85 abstractAnimation.setAnimationName(newValue);
86
87 // THEN
88 QCOMPARE(abstractAnimation.animationName(), newValue);
89 QCOMPARE(spy.count(), 0);
90
91 }
92 {
93 // WHEN
94 QSignalSpy spy(&abstractAnimation, SIGNAL(positionChanged(float)));
95 const float newValue = 1.0f;
96 abstractAnimation.setPosition(newValue);
97
98 // THEN
99 QCOMPARE(abstractAnimation.position(), newValue);
100 QCOMPARE(spy.count(), 1);
101
102 // WHEN
103 spy.clear();
104 abstractAnimation.setPosition(newValue);
105
106 // THEN
107 QCOMPARE(abstractAnimation.position(), newValue);
108 QCOMPARE(spy.count(), 0);
109
110 }
111 }
112
113};
114
115QTEST_APPLESS_MAIN(tst_QAbstractAnimation)
116
117#include "tst_qabstractanimation.moc"
118

source code of qt3d/tests/auto/animation/qabstractanimation/tst_qabstractanimation.cpp