0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the test suite of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
|
|
43 |
#include <QtTest/QtTest>
|
|
44 |
|
|
45 |
#include <qgraphicsitemanimation.h>
|
|
46 |
#include <QtCore/qtimeline.h>
|
|
47 |
#include <QtGui/qmatrix.h>
|
|
48 |
|
|
49 |
//TESTED_CLASS=
|
|
50 |
//TESTED_FILES=
|
|
51 |
|
|
52 |
class tst_QGraphicsItemAnimation : public QObject
|
|
53 |
{
|
|
54 |
Q_OBJECT
|
|
55 |
|
|
56 |
private slots:
|
|
57 |
void construction();
|
|
58 |
void linearMove();
|
|
59 |
void linearRotation();
|
|
60 |
void checkReturnedLists();
|
|
61 |
void overwriteValueForStep();
|
|
62 |
void setTimeLine();
|
|
63 |
};
|
|
64 |
|
|
65 |
void tst_QGraphicsItemAnimation::construction()
|
|
66 |
{
|
|
67 |
QGraphicsItemAnimation animation;
|
|
68 |
QVERIFY(!animation.item());
|
|
69 |
QVERIFY(!animation.timeLine());
|
|
70 |
QCOMPARE(animation.posAt(0), QPointF());
|
|
71 |
QCOMPARE(animation.posAt(0.5), QPointF());
|
|
72 |
QCOMPARE(animation.posAt(1), QPointF());
|
|
73 |
QCOMPARE(animation.matrixAt(0), QMatrix());
|
|
74 |
QCOMPARE(animation.matrixAt(0.5), QMatrix());
|
|
75 |
QCOMPARE(animation.matrixAt(1), QMatrix());
|
|
76 |
QCOMPARE(animation.rotationAt(0), qreal(0.0));
|
|
77 |
QCOMPARE(animation.rotationAt(0.5), qreal(0.0));
|
|
78 |
QCOMPARE(animation.rotationAt(1), qreal(0.0));
|
|
79 |
QCOMPARE(animation.xTranslationAt(0), qreal(0.0));
|
|
80 |
QCOMPARE(animation.xTranslationAt(0.5), qreal(0.0));
|
|
81 |
QCOMPARE(animation.xTranslationAt(1), qreal(0.0));
|
|
82 |
QCOMPARE(animation.yTranslationAt(0), qreal(0.0));
|
|
83 |
QCOMPARE(animation.yTranslationAt(0.5), qreal(0.0));
|
|
84 |
QCOMPARE(animation.yTranslationAt(1), qreal(0.0));
|
|
85 |
QCOMPARE(animation.verticalScaleAt(0), qreal(1.0));
|
|
86 |
QCOMPARE(animation.horizontalScaleAt(0), qreal(1.0));
|
|
87 |
QCOMPARE(animation.verticalShearAt(0), qreal(0.0));
|
|
88 |
QCOMPARE(animation.horizontalShearAt(0), qreal(0.0));
|
|
89 |
animation.clear(); // don't crash
|
|
90 |
}
|
|
91 |
|
|
92 |
void tst_QGraphicsItemAnimation::linearMove()
|
|
93 |
{
|
|
94 |
QGraphicsItemAnimation animation;
|
|
95 |
|
|
96 |
for (int i = 0; i <= 10; ++i) {
|
|
97 |
QCOMPARE(animation.posAt(i / 10.0).x(), qreal(0));
|
|
98 |
QCOMPARE(animation.posAt(i / 10.0).y(), qreal(0));
|
|
99 |
}
|
|
100 |
|
|
101 |
animation.setPosAt(1, QPointF(10, -10));
|
|
102 |
|
|
103 |
for (int i = 0; i <= 10; ++i) {
|
|
104 |
QCOMPARE(animation.posAt(i / 10.0).x(), qreal(i));
|
|
105 |
QCOMPARE(animation.posAt(i / 10.0).y(), qreal(-i));
|
|
106 |
}
|
|
107 |
|
|
108 |
animation.setPosAt(2, QPointF(10, -10));
|
|
109 |
|
|
110 |
QCOMPARE(animation.posAt(11).x(), qreal(10));
|
|
111 |
}
|
|
112 |
|
|
113 |
void tst_QGraphicsItemAnimation::linearRotation()
|
|
114 |
{
|
|
115 |
QGraphicsItemAnimation animation;
|
|
116 |
animation.setRotationAt(1, 1);
|
|
117 |
|
|
118 |
for (int i = 0; i <= 10; ++i)
|
|
119 |
QCOMPARE(animation.rotationAt(i / 10.0), qreal(i / 10.0));
|
|
120 |
}
|
|
121 |
|
|
122 |
void tst_QGraphicsItemAnimation::checkReturnedLists()
|
|
123 |
{
|
|
124 |
QGraphicsItemAnimation animation;
|
|
125 |
|
|
126 |
animation.setPosAt(1.0, QPointF(10, -10));
|
|
127 |
animation.setPosAt(0.5, QPointF(5, -5));
|
|
128 |
|
|
129 |
animation.setRotationAt(0.3, 2.3);
|
|
130 |
animation.setTranslationAt(0.3, 15, 15);
|
|
131 |
animation.setScaleAt(0.3, 2.5, 1.8);
|
|
132 |
animation.setShearAt(0.3, 5, 5);
|
|
133 |
|
|
134 |
QCOMPARE(animation.posList().at(0), (QPair<qreal, QPointF>(0.5, QPointF(5, -5))));
|
|
135 |
QCOMPARE(animation.posList().at(1), (QPair<qreal, QPointF>(1.0, QPointF(10, -10))));
|
|
136 |
QCOMPARE(animation.rotationList().at(0), (QPair<qreal, qreal>(0.3, 2.3)));
|
|
137 |
QCOMPARE(animation.translationList().at(0), (QPair<qreal, QPointF>(0.3, QPointF(15, 15))));
|
|
138 |
QCOMPARE(animation.scaleList().at(0), (QPair<qreal, QPointF>(0.3, QPointF(2.5, 1.8))));
|
|
139 |
QCOMPARE(animation.shearList().at(0), (QPair<qreal, QPointF>(0.3, QPointF(5, 5))));
|
|
140 |
|
|
141 |
QCOMPARE(animation.posList().size(), 2);
|
|
142 |
QCOMPARE(animation.rotationList().size(), 1);
|
|
143 |
QCOMPARE(animation.translationList().size(), 1);
|
|
144 |
QCOMPARE(animation.scaleList().size(), 1);
|
|
145 |
QCOMPARE(animation.shearList().size(), 1);
|
|
146 |
}
|
|
147 |
|
|
148 |
void tst_QGraphicsItemAnimation::overwriteValueForStep()
|
|
149 |
{
|
|
150 |
QGraphicsItemAnimation animation;
|
|
151 |
|
|
152 |
for (int i=0; i<3; i++){
|
|
153 |
animation.setPosAt(0.3, QPointF(3, -3.1));
|
|
154 |
animation.setRotationAt(0.3, 2.3);
|
|
155 |
animation.setTranslationAt(0.3, 15, 15);
|
|
156 |
animation.setScaleAt(0.3, 2.5, 1.8);
|
|
157 |
animation.setShearAt(0.3, 5, 5);
|
|
158 |
|
|
159 |
QCOMPARE(animation.posList().size(), 1);
|
|
160 |
QCOMPARE(animation.rotationList().size(), 1);
|
|
161 |
QCOMPARE(animation.translationList().size(), 1);
|
|
162 |
QCOMPARE(animation.scaleList().size(), 1);
|
|
163 |
QCOMPARE(animation.shearList().size(), 1);
|
|
164 |
}
|
|
165 |
}
|
|
166 |
|
|
167 |
void tst_QGraphicsItemAnimation::setTimeLine()
|
|
168 |
{
|
|
169 |
QGraphicsItemAnimation animation;
|
|
170 |
QCOMPARE(animation.timeLine(), (QTimeLine *)0);
|
|
171 |
|
|
172 |
QPointer<QTimeLine> line1 = new QTimeLine;
|
|
173 |
animation.setTimeLine(line1);
|
|
174 |
QCOMPARE(animation.timeLine(), (QTimeLine *)line1);
|
|
175 |
animation.setTimeLine(line1);
|
|
176 |
QVERIFY(line1);
|
|
177 |
QCOMPARE(animation.timeLine(), (QTimeLine *)line1);
|
|
178 |
|
|
179 |
animation.setTimeLine(0);
|
|
180 |
QCOMPARE(animation.timeLine(), (QTimeLine *)0);
|
|
181 |
QVERIFY(!line1);
|
|
182 |
|
|
183 |
QTimeLine *line2 = new QTimeLine;
|
|
184 |
animation.setTimeLine(line2);
|
|
185 |
QCOMPARE(animation.timeLine(), (QTimeLine *)line2);
|
|
186 |
|
|
187 |
delete line2;
|
|
188 |
QCOMPARE(animation.timeLine(), (QTimeLine *)0);
|
|
189 |
}
|
|
190 |
|
|
191 |
QTEST_MAIN(tst_QGraphicsItemAnimation)
|
|
192 |
#include "tst_qgraphicsitemanimation.moc"
|