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#include <QtTest/QtTest>
29#include <QtQml/QQmlEngine>
30#include <QtQml/QQmlProperty>
31#include <QtQuick/QQuickView>
32#include <QtQuick/QQuickItem>
33#include <QtCore/QPropertyAnimation>
34#include <QtCore/QPoint>
35#include <QtCore/QSize>
36#include <QtCore/QRect>
37#include <QtGui/QColor>
38
39#include "../../shared/util.h"
40
41class tst_qquickdynamicpropertyanimation : public QQmlDataTest
42{
43 Q_OBJECT
44public:
45 tst_qquickdynamicpropertyanimation() {}
46
47private:
48 template<class T>
49 void dynamicPropertyAnimation(const QByteArray & propertyName, T toValue)
50 {
51 QQuickView view(testFileUrl(fileName: "MyItem.qml"));
52 QQuickItem * item = qobject_cast<QQuickItem *>(object: view.rootObject());
53 QVERIFY(item);
54 QQmlProperty testProp(item, propertyName);
55 QPropertyAnimation animation(item, propertyName, this);
56 animation.setEndValue(toValue);
57 QCOMPARE(animation.targetObject(), item);
58 QCOMPARE(animation.propertyName(), propertyName);
59 QCOMPARE(animation.endValue().value<T>(), toValue);
60 animation.start();
61 QCOMPARE(animation.state(), QAbstractAnimation::Running);
62 QTest::qWait(ms: animation.duration());
63 QTRY_COMPARE(testProp.read().value<T>(), toValue);
64 }
65
66private slots:
67 void initTestCase()
68 {
69 QQmlEngine engine; // ensure types are registered
70 QQmlDataTest::initTestCase();
71 }
72
73 void dynamicIntPropertyAnimation();
74 void dynamicDoublePropertyAnimation();
75 void dynamicRealPropertyAnimation();
76 void dynamicPointPropertyAnimation();
77 void dynamicSizePropertyAnimation();
78 void dynamicRectPropertyAnimation();
79 void dynamicColorPropertyAnimation();
80 void dynamicVarPropertyAnimation();
81};
82
83void tst_qquickdynamicpropertyanimation::dynamicIntPropertyAnimation()
84{
85 dynamicPropertyAnimation(propertyName: "testInt", toValue: 1);
86}
87
88void tst_qquickdynamicpropertyanimation::dynamicDoublePropertyAnimation()
89{
90 dynamicPropertyAnimation(propertyName: "testDouble", toValue: 1.0);
91}
92
93void tst_qquickdynamicpropertyanimation::dynamicRealPropertyAnimation()
94{
95 dynamicPropertyAnimation(propertyName: "testReal", toValue: qreal(1.0));
96}
97
98void tst_qquickdynamicpropertyanimation::dynamicPointPropertyAnimation()
99{
100 dynamicPropertyAnimation(propertyName: "testPoint", toValue: QPoint(1, 1));
101}
102
103void tst_qquickdynamicpropertyanimation::dynamicSizePropertyAnimation()
104{
105 dynamicPropertyAnimation(propertyName: "testSize", toValue: QSize(1,1));
106}
107
108void tst_qquickdynamicpropertyanimation::dynamicRectPropertyAnimation()
109{
110 dynamicPropertyAnimation(propertyName: "testRect", toValue: QRect(1, 1, 1, 1));
111}
112
113void tst_qquickdynamicpropertyanimation::dynamicColorPropertyAnimation()
114{
115 dynamicPropertyAnimation(propertyName: "testColor", toValue: QColor::fromRgbF(r: 1.0, g: 1.0, b: 1.0, a: 1.0));
116}
117
118void tst_qquickdynamicpropertyanimation::dynamicVarPropertyAnimation()
119{
120 dynamicPropertyAnimation(propertyName: "testVar", toValue: QVariant::fromValue(value: 1));
121}
122
123QTEST_MAIN(tst_qquickdynamicpropertyanimation)
124
125#include "tst_qquickdynamicpropertyanimation.moc"
126

source code of qtdeclarative/tests/auto/quick/qquickdynamicpropertyanimation/tst_qquickdynamicpropertyanimation.cpp