author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 22 Apr 2010 16:15:11 +0300 | |
branch | RCL_3 |
changeset 14 | 8c4229025c0b |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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 |
#include <QtTest/QtTest> |
|
43 |
||
44 |
#include <QtCore/qanimationgroup.h> |
|
45 |
#include <QtCore/qsequentialanimationgroup.h> |
|
46 |
#include <QtCore/qparallelanimationgroup.h> |
|
47 |
||
48 |
//TESTED_CLASS=QAnimationGroup |
|
49 |
//TESTED_FILES= |
|
50 |
||
51 |
Q_DECLARE_METATYPE(QAbstractAnimation::State) |
|
52 |
||
53 |
class tst_QAnimationGroup : public QObject |
|
54 |
{ |
|
55 |
Q_OBJECT |
|
56 |
public: |
|
57 |
tst_QAnimationGroup(); |
|
58 |
virtual ~tst_QAnimationGroup(); |
|
59 |
||
60 |
public Q_SLOTS: |
|
61 |
void init(); |
|
62 |
void cleanup(); |
|
63 |
||
64 |
private slots: |
|
65 |
void construction(); |
|
66 |
void emptyGroup(); |
|
67 |
void setCurrentTime(); |
|
68 |
void statesAndSignals(); |
|
69 |
void setParentAutoAdd(); |
|
70 |
void beginNestedGroup(); |
|
71 |
void addChildTwice(); |
|
72 |
void loopWithoutStartValue(); |
|
73 |
}; |
|
74 |
||
75 |
tst_QAnimationGroup::tst_QAnimationGroup() |
|
76 |
{ |
|
77 |
} |
|
78 |
||
79 |
tst_QAnimationGroup::~tst_QAnimationGroup() |
|
80 |
{ |
|
81 |
} |
|
82 |
||
83 |
void tst_QAnimationGroup::init() |
|
84 |
{ |
|
85 |
qRegisterMetaType<QAbstractAnimation::State>("QAbstractAnimation::State"); |
|
86 |
} |
|
87 |
||
88 |
void tst_QAnimationGroup::cleanup() |
|
89 |
{ |
|
90 |
} |
|
91 |
||
92 |
void tst_QAnimationGroup::construction() |
|
93 |
{ |
|
94 |
QSequentialAnimationGroup animationgroup; |
|
95 |
} |
|
96 |
||
97 |
class AnimationObject : public QObject |
|
98 |
{ |
|
99 |
Q_OBJECT |
|
100 |
Q_PROPERTY(int value READ value WRITE setValue) |
|
101 |
public: |
|
102 |
AnimationObject(int startValue = 0) |
|
103 |
: v(startValue) |
|
104 |
{ } |
|
105 |
||
106 |
int value() const { return v; } |
|
107 |
void setValue(int value) { v = value; } |
|
108 |
||
109 |
int v; |
|
110 |
}; |
|
111 |
||
112 |
class TestAnimation : public QVariantAnimation |
|
113 |
{ |
|
114 |
Q_OBJECT |
|
115 |
public: |
|
116 |
virtual void updateCurrentValue(const QVariant &value) { Q_UNUSED(value)}; |
|
117 |
virtual void updateState(QAbstractAnimation::State oldState, |
|
118 |
QAbstractAnimation::State newState) |
|
119 |
{ |
|
120 |
Q_UNUSED(oldState) |
|
121 |
Q_UNUSED(newState) |
|
122 |
}; |
|
123 |
}; |
|
124 |
||
125 |
class UncontrolledAnimation : public QPropertyAnimation |
|
126 |
{ |
|
127 |
Q_OBJECT |
|
128 |
public: |
|
129 |
UncontrolledAnimation(QObject *target, const QByteArray &propertyName, QObject *parent = 0) |
|
130 |
: QPropertyAnimation(target, propertyName, parent), id(0) |
|
131 |
{ |
|
132 |
setDuration(250); |
|
133 |
} |
|
134 |
||
135 |
int duration() const { return -1; /* not time driven */ } |
|
136 |
||
137 |
protected: |
|
138 |
void timerEvent(QTimerEvent *event) |
|
139 |
{ |
|
140 |
if (event->timerId() == id) |
|
141 |
stop(); |
|
142 |
} |
|
143 |
||
144 |
void updateRunning(bool running) |
|
145 |
{ |
|
146 |
if (running) { |
|
147 |
id = startTimer(500); |
|
148 |
} else { |
|
149 |
killTimer(id); |
|
150 |
id = 0; |
|
151 |
} |
|
152 |
} |
|
153 |
||
154 |
private: |
|
155 |
int id; |
|
156 |
}; |
|
157 |
||
158 |
void tst_QAnimationGroup::emptyGroup() |
|
159 |
{ |
|
160 |
QSequentialAnimationGroup group; |
|
161 |
QSignalSpy groupStateChangedSpy(&group, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State))); |
|
162 |
||
163 |
QCOMPARE(group.state(), QAnimationGroup::Stopped); |
|
164 |
group.start(); |
|
165 |
||
166 |
QCOMPARE(groupStateChangedSpy.count(), 2); |
|
167 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
168 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(groupStateChangedSpy.at(0).first()), |
0 | 169 |
QAnimationGroup::Running); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
170 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(groupStateChangedSpy.at(1).first()), |
0 | 171 |
QAnimationGroup::Stopped); |
172 |
||
173 |
QCOMPARE(group.state(), QAnimationGroup::Stopped); |
|
174 |
||
175 |
QTest::ignoreMessage(QtWarningMsg, "QAbstractAnimation::pause: Cannot pause a stopped animation"); |
|
176 |
group.pause(); |
|
177 |
||
178 |
QCOMPARE(groupStateChangedSpy.count(), 2); |
|
179 |
QCOMPARE(group.state(), QAnimationGroup::Stopped); |
|
180 |
||
181 |
group.start(); |
|
182 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
183 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(groupStateChangedSpy.at(2).first()), |
0 | 184 |
QAnimationGroup::Running); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
185 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(groupStateChangedSpy.at(3).first()), |
0 | 186 |
QAnimationGroup::Stopped); |
187 |
||
188 |
QCOMPARE(group.state(), QAnimationGroup::Stopped); |
|
189 |
||
190 |
group.stop(); |
|
191 |
||
192 |
QCOMPARE(groupStateChangedSpy.count(), 4); |
|
193 |
QCOMPARE(group.state(), QAnimationGroup::Stopped); |
|
194 |
} |
|
195 |
||
196 |
void tst_QAnimationGroup::setCurrentTime() |
|
197 |
{ |
|
198 |
AnimationObject s_o1; |
|
199 |
AnimationObject s_o2; |
|
200 |
AnimationObject s_o3; |
|
201 |
AnimationObject p_o1; |
|
202 |
AnimationObject p_o2; |
|
203 |
AnimationObject p_o3; |
|
204 |
AnimationObject t_o1; |
|
205 |
AnimationObject t_o2; |
|
206 |
||
207 |
// sequence operating on same object/property |
|
208 |
QSequentialAnimationGroup *sequence = new QSequentialAnimationGroup(); |
|
209 |
QAbstractAnimation *a1_s_o1 = new QPropertyAnimation(&s_o1, "value"); |
|
210 |
QAbstractAnimation *a2_s_o1 = new QPropertyAnimation(&s_o1, "value"); |
|
211 |
QAbstractAnimation *a3_s_o1 = new QPropertyAnimation(&s_o1, "value"); |
|
212 |
a2_s_o1->setLoopCount(3); |
|
213 |
sequence->addAnimation(a1_s_o1); |
|
214 |
sequence->addAnimation(a2_s_o1); |
|
215 |
sequence->addAnimation(a3_s_o1); |
|
216 |
||
217 |
// sequence operating on different object/properties |
|
218 |
QAnimationGroup *sequence2 = new QSequentialAnimationGroup(); |
|
219 |
QAbstractAnimation *a1_s_o2 = new QPropertyAnimation(&s_o2, "value"); |
|
220 |
QAbstractAnimation *a1_s_o3 = new QPropertyAnimation(&s_o3, "value"); |
|
221 |
sequence2->addAnimation(a1_s_o2); |
|
222 |
sequence2->addAnimation(a1_s_o3); |
|
223 |
||
224 |
// parallel operating on different object/properties |
|
225 |
QAnimationGroup *parallel = new QParallelAnimationGroup(); |
|
226 |
QAbstractAnimation *a1_p_o1 = new QPropertyAnimation(&p_o1, "value"); |
|
227 |
QAbstractAnimation *a1_p_o2 = new QPropertyAnimation(&p_o2, "value"); |
|
228 |
QAbstractAnimation *a1_p_o3 = new QPropertyAnimation(&p_o3, "value"); |
|
229 |
a1_p_o2->setLoopCount(3); |
|
230 |
parallel->addAnimation(a1_p_o1); |
|
231 |
parallel->addAnimation(a1_p_o2); |
|
232 |
parallel->addAnimation(a1_p_o3); |
|
233 |
||
234 |
QAbstractAnimation *notTimeDriven = new UncontrolledAnimation(&t_o1, "value"); |
|
235 |
QCOMPARE(notTimeDriven->totalDuration(), -1); |
|
236 |
||
237 |
QAbstractAnimation *loopsForever = new QPropertyAnimation(&t_o2, "value"); |
|
238 |
loopsForever->setLoopCount(-1); |
|
239 |
QCOMPARE(loopsForever->totalDuration(), -1); |
|
240 |
||
241 |
QParallelAnimationGroup group; |
|
242 |
group.addAnimation(sequence); |
|
243 |
group.addAnimation(sequence2); |
|
244 |
group.addAnimation(parallel); |
|
245 |
group.addAnimation(notTimeDriven); |
|
246 |
group.addAnimation(loopsForever); |
|
247 |
||
248 |
// Current time = 1 |
|
249 |
group.setCurrentTime(1); |
|
250 |
QCOMPARE(group.state(), QAnimationGroup::Stopped); |
|
251 |
QCOMPARE(sequence->state(), QAnimationGroup::Stopped); |
|
252 |
QCOMPARE(a1_s_o1->state(), QAnimationGroup::Stopped); |
|
253 |
QCOMPARE(sequence2->state(), QAnimationGroup::Stopped); |
|
254 |
QCOMPARE(a1_s_o2->state(), QAnimationGroup::Stopped); |
|
255 |
QCOMPARE(parallel->state(), QAnimationGroup::Stopped); |
|
256 |
QCOMPARE(a1_p_o1->state(), QAnimationGroup::Stopped); |
|
257 |
QCOMPARE(a1_p_o2->state(), QAnimationGroup::Stopped); |
|
258 |
QCOMPARE(a1_p_o3->state(), QAnimationGroup::Stopped); |
|
259 |
QCOMPARE(notTimeDriven->state(), QAnimationGroup::Stopped); |
|
260 |
QCOMPARE(loopsForever->state(), QAnimationGroup::Stopped); |
|
261 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
262 |
QCOMPARE(group.currentLoopTime(), 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
263 |
QCOMPARE(sequence->currentLoopTime(), 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
264 |
QCOMPARE(a1_s_o1->currentLoopTime(), 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
265 |
QCOMPARE(a2_s_o1->currentLoopTime(), 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
266 |
QCOMPARE(a3_s_o1->currentLoopTime(), 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
267 |
QCOMPARE(a1_s_o2->currentLoopTime(), 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
268 |
QCOMPARE(a1_s_o3->currentLoopTime(), 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
269 |
QCOMPARE(a1_p_o1->currentLoopTime(), 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
270 |
QCOMPARE(a1_p_o2->currentLoopTime(), 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
271 |
QCOMPARE(a1_p_o3->currentLoopTime(), 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
272 |
QCOMPARE(notTimeDriven->currentLoopTime(), 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
273 |
QCOMPARE(loopsForever->currentLoopTime(), 1); |
0 | 274 |
|
275 |
// Current time = 250 |
|
276 |
group.setCurrentTime(250); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
277 |
QCOMPARE(group.currentLoopTime(), 250); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
278 |
QCOMPARE(sequence->currentLoopTime(), 250); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
279 |
QCOMPARE(a1_s_o1->currentLoopTime(), 250); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
280 |
QCOMPARE(a2_s_o1->currentLoopTime(), 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
281 |
QCOMPARE(a3_s_o1->currentLoopTime(), 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
282 |
QCOMPARE(a1_s_o2->currentLoopTime(), 250); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
283 |
QCOMPARE(a1_s_o3->currentLoopTime(), 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
284 |
QCOMPARE(a1_p_o1->currentLoopTime(), 250); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
285 |
QCOMPARE(a1_p_o2->currentLoopTime(), 0); |
0 | 286 |
QCOMPARE(a1_p_o2->currentLoop(), 1); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
287 |
QCOMPARE(a1_p_o3->currentLoopTime(), 250); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
288 |
QCOMPARE(notTimeDriven->currentLoopTime(), 250); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
289 |
QCOMPARE(loopsForever->currentLoopTime(), 0); |
0 | 290 |
QCOMPARE(loopsForever->currentLoop(), 1); |
291 |
QCOMPARE(sequence->currentAnimation(), a2_s_o1); |
|
292 |
||
293 |
// Current time = 251 |
|
294 |
group.setCurrentTime(251); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
295 |
QCOMPARE(group.currentLoopTime(), 251); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
296 |
QCOMPARE(sequence->currentLoopTime(), 251); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
297 |
QCOMPARE(a1_s_o1->currentLoopTime(), 250); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
298 |
QCOMPARE(a2_s_o1->currentLoopTime(), 1); |
0 | 299 |
QCOMPARE(a2_s_o1->currentLoop(), 0); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
300 |
QCOMPARE(a3_s_o1->currentLoopTime(), 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
301 |
QCOMPARE(sequence2->currentLoopTime(), 251); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
302 |
QCOMPARE(a1_s_o2->currentLoopTime(), 250); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
303 |
QCOMPARE(a1_s_o3->currentLoopTime(), 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
304 |
QCOMPARE(a1_p_o1->currentLoopTime(), 250); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
305 |
QCOMPARE(a1_p_o2->currentLoopTime(), 1); |
0 | 306 |
QCOMPARE(a1_p_o2->currentLoop(), 1); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
307 |
QCOMPARE(a1_p_o3->currentLoopTime(), 250); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
308 |
QCOMPARE(notTimeDriven->currentLoopTime(), 251); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
309 |
QCOMPARE(loopsForever->currentLoopTime(), 1); |
0 | 310 |
QCOMPARE(sequence->currentAnimation(), a2_s_o1); |
311 |
} |
|
312 |
||
313 |
void tst_QAnimationGroup::statesAndSignals() |
|
314 |
{ |
|
315 |
} |
|
316 |
||
317 |
void tst_QAnimationGroup::setParentAutoAdd() |
|
318 |
{ |
|
319 |
QParallelAnimationGroup group; |
|
320 |
QVariantAnimation *animation = new QPropertyAnimation(&group); |
|
321 |
QCOMPARE(animation->group(), static_cast<QAnimationGroup*>(&group)); |
|
322 |
} |
|
323 |
||
324 |
void tst_QAnimationGroup::beginNestedGroup() |
|
325 |
{ |
|
326 |
QAnimationGroup *subGroup; |
|
327 |
QAnimationGroup *parent = new QParallelAnimationGroup(); |
|
328 |
||
329 |
for (int i = 0; i < 10; ++i) { |
|
330 |
if (i & 1) |
|
331 |
subGroup = new QParallelAnimationGroup(parent); |
|
332 |
else |
|
333 |
subGroup = new QSequentialAnimationGroup(parent); |
|
334 |
||
335 |
QCOMPARE(parent->animationCount(), 1); |
|
336 |
QAnimationGroup *child = static_cast<QAnimationGroup *>(parent->animationAt(0)); |
|
337 |
||
338 |
QCOMPARE(child->parent(), static_cast<QObject *>(parent)); |
|
339 |
if (i & 1) |
|
340 |
QVERIFY(qobject_cast<QParallelAnimationGroup *> (child)); |
|
341 |
else |
|
342 |
QVERIFY(qobject_cast<QSequentialAnimationGroup *> (child)); |
|
343 |
||
344 |
parent = child; |
|
345 |
} |
|
346 |
} |
|
347 |
||
348 |
void tst_QAnimationGroup::addChildTwice() |
|
349 |
{ |
|
350 |
QAbstractAnimation *subGroup; |
|
351 |
QAbstractAnimation *subGroup2; |
|
352 |
QAnimationGroup *parent = new QSequentialAnimationGroup(); |
|
353 |
||
354 |
subGroup = new QPropertyAnimation(); |
|
355 |
subGroup->setParent(parent); |
|
356 |
parent->addAnimation(subGroup); |
|
357 |
QCOMPARE(parent->animationCount(), 1); |
|
358 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
359 |
parent->clear(); |
0 | 360 |
|
361 |
QCOMPARE(parent->animationCount(), 0); |
|
362 |
||
363 |
// adding the same item twice to a group will remove the item from its current position |
|
364 |
// and append it to the end |
|
365 |
subGroup = new QPropertyAnimation(parent); |
|
366 |
subGroup2 = new QPropertyAnimation(parent); |
|
367 |
||
368 |
QCOMPARE(parent->animationCount(), 2); |
|
369 |
QCOMPARE(parent->animationAt(0), subGroup); |
|
370 |
QCOMPARE(parent->animationAt(1), subGroup2); |
|
371 |
||
372 |
parent->addAnimation(subGroup); |
|
373 |
||
374 |
QCOMPARE(parent->animationCount(), 2); |
|
375 |
QCOMPARE(parent->animationAt(0), subGroup2); |
|
376 |
QCOMPARE(parent->animationAt(1), subGroup); |
|
377 |
||
378 |
delete parent; |
|
379 |
} |
|
380 |
||
381 |
void tst_QAnimationGroup::loopWithoutStartValue() |
|
382 |
{ |
|
383 |
QAnimationGroup *parent = new QSequentialAnimationGroup(); |
|
384 |
QObject o; |
|
385 |
o.setProperty("ole", 0); |
|
386 |
QCOMPARE(o.property("ole").toInt(), 0); |
|
387 |
||
388 |
QPropertyAnimation anim1(&o, "ole"); |
|
389 |
anim1.setEndValue(-50); |
|
390 |
anim1.setDuration(100); |
|
391 |
||
392 |
QPropertyAnimation anim2(&o, "ole"); |
|
393 |
anim2.setEndValue(50); |
|
394 |
anim2.setDuration(100); |
|
395 |
||
396 |
parent->addAnimation(&anim1); |
|
397 |
parent->addAnimation(&anim2); |
|
398 |
||
399 |
parent->setLoopCount(-1); |
|
400 |
parent->start(); |
|
401 |
||
402 |
QVERIFY(anim1.startValue().isNull()); |
|
403 |
QCOMPARE(anim1.currentValue().toInt(), 0); |
|
404 |
QCOMPARE(parent->currentLoop(), 0); |
|
405 |
||
406 |
parent->setCurrentTime(200); |
|
407 |
QCOMPARE(parent->currentLoop(), 1); |
|
408 |
QCOMPARE(anim1.currentValue().toInt(), 50); |
|
409 |
parent->stop(); |
|
410 |
} |
|
411 |
||
412 |
QTEST_MAIN(tst_QAnimationGroup) |
|
413 |
#include "tst_qanimationgroup.moc" |