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 test suite 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
30#include <QtCore/qvariantanimation.h>
31#include <QtTest>
32
33class tst_QVariantAnimation : public QObject
34{
35 Q_OBJECT
36private slots:
37 void construction();
38 void destruction();
39 void currentValue();
40 void easingCurve();
41 void startValue();
42 void endValue();
43 void keyValueAt();
44 void keyValues();
45 void duration();
46 void interpolation();
47};
48
49class TestableQVariantAnimation : public QVariantAnimation
50{
51 Q_OBJECT
52public:
53 void updateCurrentValue(const QVariant&) {}
54};
55
56void tst_QVariantAnimation::construction()
57{
58 TestableQVariantAnimation anim;
59}
60
61void tst_QVariantAnimation::destruction()
62{
63 TestableQVariantAnimation *anim = new TestableQVariantAnimation;
64 delete anim;
65}
66
67void tst_QVariantAnimation::currentValue()
68{
69 TestableQVariantAnimation anim;
70 QVERIFY(!anim.currentValue().isValid());
71}
72
73void tst_QVariantAnimation::easingCurve()
74{
75 TestableQVariantAnimation anim;
76 QCOMPARE(anim.easingCurve().type(), QEasingCurve::Linear);
77 anim.setEasingCurve(QEasingCurve::InQuad);
78 QCOMPARE(anim.easingCurve().type(), QEasingCurve::InQuad);
79}
80
81void tst_QVariantAnimation::endValue()
82{
83 TestableQVariantAnimation anim;
84 anim.setEndValue(QVariant(1));
85 QCOMPARE(anim.endValue().toInt(), 1);
86}
87
88void tst_QVariantAnimation::startValue()
89{
90 TestableQVariantAnimation anim;
91 anim.setStartValue(QVariant(1));
92 QCOMPARE(anim.startValue().toInt(), 1);
93 anim.setStartValue(QVariant(-1));
94 QCOMPARE(anim.startValue().toInt(), -1);
95}
96
97void tst_QVariantAnimation::keyValueAt()
98{
99 TestableQVariantAnimation anim;
100
101 int i=0;
102 for (qreal r=0.0; r<1.0; r+=0.1) {
103 anim.setKeyValueAt(step: 0.1, value: ++i);
104 QCOMPARE(anim.keyValueAt(0.1).toInt(), i);
105 }
106}
107
108void tst_QVariantAnimation::keyValues()
109{
110 TestableQVariantAnimation anim;
111
112 QVariantAnimation::KeyValues values;
113 int i=0;
114 for (qreal r=0.0; r<1.0; r+=0.1) {
115 values.append(t: QVariantAnimation::KeyValue(r, i));
116 }
117
118 anim.setKeyValues(values);
119 QCOMPARE(anim.keyValues(), values);
120}
121
122void tst_QVariantAnimation::duration()
123{
124 TestableQVariantAnimation anim;
125 QCOMPARE(anim.duration(), 250);
126 anim.setDuration(500);
127 QCOMPARE(anim.duration(), 500);
128 QTest::ignoreMessage(type: QtWarningMsg, message: "QVariantAnimation::setDuration: cannot set a negative duration");
129 anim.setDuration(-1);
130 QCOMPARE(anim.duration(), 500);
131}
132
133void tst_QVariantAnimation::interpolation()
134{
135 QVariantAnimation unsignedAnim;
136 unsignedAnim.setStartValue(100u);
137 unsignedAnim.setEndValue(0u);
138 unsignedAnim.setDuration(100);
139 unsignedAnim.setCurrentTime(50);
140 QCOMPARE(unsignedAnim.currentValue().toUInt(), 50u);
141
142 QVariantAnimation signedAnim;
143 signedAnim.setStartValue(100);
144 signedAnim.setEndValue(0);
145 signedAnim.setDuration(100);
146 signedAnim.setCurrentTime(50);
147 QCOMPARE(signedAnim.currentValue().toInt(), 50);
148
149 QVariantAnimation pointAnim;
150 pointAnim.setStartValue(QPoint(100, 100));
151 pointAnim.setEndValue(QPoint(0, 0));
152 pointAnim.setDuration(100);
153 pointAnim.setCurrentTime(50);
154 QCOMPARE(pointAnim.currentValue().toPoint(), QPoint(50, 50));
155}
156
157QTEST_MAIN(tst_QVariantAnimation)
158
159#include "tst_qvariantanimation.moc"
160

source code of qtbase/tests/auto/corelib/animation/qvariantanimation/tst_qvariantanimation.cpp