115 |
114 |
116 tst_QPauseAnimation::~tst_QPauseAnimation() |
115 tst_QPauseAnimation::~tst_QPauseAnimation() |
117 { |
116 { |
118 } |
117 } |
119 |
118 |
120 void tst_QPauseAnimation::init() |
119 void tst_QPauseAnimation::initTestCase() |
121 { |
120 { |
122 qRegisterMetaType<QAbstractAnimation::State>("QAbstractAnimation::State"); |
121 qRegisterMetaType<QAbstractAnimation::State>("QAbstractAnimation::State"); |
123 qRegisterMetaType<QAbstractAnimation::DeletionPolicy>("QAbstractAnimation::DeletionPolicy"); |
122 qRegisterMetaType<QAbstractAnimation::DeletionPolicy>("QAbstractAnimation::DeletionPolicy"); |
124 } |
123 } |
125 |
124 |
126 void tst_QPauseAnimation::cleanup() |
|
127 { |
|
128 } |
|
129 |
|
130 void tst_QPauseAnimation::changeDirectionWhileRunning() |
125 void tst_QPauseAnimation::changeDirectionWhileRunning() |
131 { |
126 { |
132 QUnifiedTimer *timer = QUnifiedTimer::instance(); |
127 EnableConsistentTiming enabled; |
133 timer->setConsistentTiming(true); |
|
134 |
128 |
135 TestablePauseAnimation animation; |
129 TestablePauseAnimation animation; |
136 animation.setDuration(400); |
130 animation.setDuration(400); |
137 animation.start(); |
131 animation.start(); |
138 QTest::qWait(100); |
132 QTest::qWait(100); |
139 QVERIFY(animation.state() == QAbstractAnimation::Running); |
133 QVERIFY(animation.state() == QAbstractAnimation::Running); |
140 animation.setDirection(QAbstractAnimation::Backward); |
134 animation.setDirection(QAbstractAnimation::Backward); |
141 QTest::qWait(animation.totalDuration() + 50); |
135 QTest::qWait(animation.totalDuration() + 50); |
142 QVERIFY(animation.state() == QAbstractAnimation::Stopped); |
136 QVERIFY(animation.state() == QAbstractAnimation::Stopped); |
143 |
|
144 timer->setConsistentTiming(false); |
|
145 } |
137 } |
146 |
138 |
147 void tst_QPauseAnimation::noTimerUpdates_data() |
139 void tst_QPauseAnimation::noTimerUpdates_data() |
148 { |
140 { |
149 QTest::addColumn<int>("duration"); |
141 QTest::addColumn<int>("duration"); |
155 QTest::newRow("3") << 200 << 3; |
147 QTest::newRow("3") << 200 << 3; |
156 } |
148 } |
157 |
149 |
158 void tst_QPauseAnimation::noTimerUpdates() |
150 void tst_QPauseAnimation::noTimerUpdates() |
159 { |
151 { |
160 QUnifiedTimer *timer = QUnifiedTimer::instance(); |
152 EnableConsistentTiming enabled; |
161 timer->setConsistentTiming(true); |
|
162 |
153 |
163 QFETCH(int, duration); |
154 QFETCH(int, duration); |
164 QFETCH(int, loopCount); |
155 QFETCH(int, loopCount); |
165 |
156 |
166 TestablePauseAnimation animation; |
157 TestablePauseAnimation animation; |
167 animation.setDuration(duration); |
158 animation.setDuration(duration); |
168 animation.setLoopCount(loopCount); |
159 animation.setLoopCount(loopCount); |
169 animation.start(); |
160 animation.start(); |
170 QTest::qWait(animation.totalDuration() + 100); |
|
171 QVERIFY(animation.state() == QAbstractAnimation::Stopped); |
|
172 QCOMPARE(animation.m_updateCurrentTimeCount, 1 + loopCount); |
|
173 |
|
174 timer->setConsistentTiming(false); |
|
175 } |
|
176 |
|
177 void tst_QPauseAnimation::mulitplePauseAnimations() |
|
178 { |
|
179 QUnifiedTimer *timer = QUnifiedTimer::instance(); |
|
180 timer->setConsistentTiming(true); |
|
181 |
|
182 TestablePauseAnimation animation; |
|
183 animation.setDuration(200); |
|
184 |
|
185 TestablePauseAnimation animation2; |
|
186 animation2.setDuration(800); |
|
187 |
|
188 animation.start(); |
|
189 animation2.start(); |
|
190 QTest::qWait(animation.totalDuration() + 100); |
|
191 QVERIFY(animation.state() == QAbstractAnimation::Stopped); |
|
192 QVERIFY(animation2.state() == QAbstractAnimation::Running); |
|
193 QCOMPARE(animation.m_updateCurrentTimeCount, 2); |
|
194 QCOMPARE(animation2.m_updateCurrentTimeCount, 2); |
|
195 |
|
196 QTest::qWait(550); |
|
197 QVERIFY(animation2.state() == QAbstractAnimation::Stopped); |
|
198 QCOMPARE(animation2.m_updateCurrentTimeCount, 3); |
|
199 |
|
200 timer->setConsistentTiming(false); |
|
201 } |
|
202 |
|
203 void tst_QPauseAnimation::pauseAndPropertyAnimations() |
|
204 { |
|
205 EnableConsistentTiming enabled; |
|
206 |
|
207 TestablePauseAnimation pause; |
|
208 pause.setDuration(200); |
|
209 |
|
210 QObject o; |
|
211 o.setProperty("ole", 42); |
|
212 |
|
213 QPropertyAnimation animation(&o, "ole"); |
|
214 animation.setEndValue(43); |
|
215 |
|
216 pause.start(); |
|
217 |
|
218 QTest::qWait(100); |
|
219 animation.start(); |
|
220 |
|
221 QVERIFY(animation.state() == QAbstractAnimation::Running); |
|
222 QVERIFY(pause.state() == QAbstractAnimation::Running); |
|
223 QCOMPARE(pause.m_updateCurrentTimeCount, 2); |
|
224 |
|
225 QTest::qWait(animation.totalDuration() + 100); |
161 QTest::qWait(animation.totalDuration() + 100); |
226 |
162 |
227 #ifdef Q_OS_WIN |
163 #ifdef Q_OS_WIN |
228 if (animation.state() != QAbstractAnimation::Stopped) |
164 if (animation.state() != QAbstractAnimation::Stopped) |
229 QEXPECT_FAIL("", "On windows, consistent timing is not working properly due to bad timer resolution", Abort); |
165 QEXPECT_FAIL("", "On windows, consistent timing is not working properly due to bad timer resolution", Abort); |
230 #endif |
166 #endif |
|
167 |
|
168 QVERIFY(animation.state() == QAbstractAnimation::Stopped); |
|
169 QCOMPARE(animation.m_updateCurrentTimeCount, 1 + loopCount); |
|
170 } |
|
171 |
|
172 void tst_QPauseAnimation::mulitplePauseAnimations() |
|
173 { |
|
174 EnableConsistentTiming enabled; |
|
175 |
|
176 TestablePauseAnimation animation; |
|
177 animation.setDuration(200); |
|
178 |
|
179 TestablePauseAnimation animation2; |
|
180 animation2.setDuration(800); |
|
181 |
|
182 animation.start(); |
|
183 animation2.start(); |
|
184 QTest::qWait(animation.totalDuration() + 100); |
|
185 |
|
186 #ifdef Q_OS_WIN |
|
187 if (animation.state() != QAbstractAnimation::Stopped) |
|
188 QEXPECT_FAIL("", "On windows, consistent timing is not working properly due to bad timer resolution", Abort); |
|
189 #endif |
|
190 |
|
191 QVERIFY(animation.state() == QAbstractAnimation::Stopped); |
|
192 QVERIFY(animation2.state() == QAbstractAnimation::Running); |
|
193 QCOMPARE(animation.m_updateCurrentTimeCount, 2); |
|
194 QCOMPARE(animation2.m_updateCurrentTimeCount, 2); |
|
195 |
|
196 QTest::qWait(550); |
|
197 |
|
198 #ifdef Q_OS_WIN |
|
199 if (animation2.state() != QAbstractAnimation::Stopped) |
|
200 QEXPECT_FAIL("", "On windows, consistent timing is not working properly due to bad timer resolution", Abort); |
|
201 #endif |
|
202 |
|
203 QVERIFY(animation2.state() == QAbstractAnimation::Stopped); |
|
204 QCOMPARE(animation2.m_updateCurrentTimeCount, 3); |
|
205 } |
|
206 |
|
207 void tst_QPauseAnimation::pauseAndPropertyAnimations() |
|
208 { |
|
209 EnableConsistentTiming enabled; |
|
210 |
|
211 TestablePauseAnimation pause; |
|
212 pause.setDuration(200); |
|
213 |
|
214 QObject o; |
|
215 o.setProperty("ole", 42); |
|
216 |
|
217 QPropertyAnimation animation(&o, "ole"); |
|
218 animation.setEndValue(43); |
|
219 |
|
220 pause.start(); |
|
221 |
|
222 QTest::qWait(100); |
|
223 animation.start(); |
|
224 |
|
225 QVERIFY(animation.state() == QAbstractAnimation::Running); |
|
226 QVERIFY(pause.state() == QAbstractAnimation::Running); |
|
227 QCOMPARE(pause.m_updateCurrentTimeCount, 2); |
|
228 |
|
229 QTest::qWait(animation.totalDuration() + 100); |
|
230 |
|
231 #ifdef Q_OS_WIN |
|
232 if (animation.state() != QAbstractAnimation::Stopped) |
|
233 QEXPECT_FAIL("", "On windows, consistent timing is not working properly due to bad timer resolution", Abort); |
|
234 #endif |
231 QVERIFY(animation.state() == QAbstractAnimation::Stopped); |
235 QVERIFY(animation.state() == QAbstractAnimation::Stopped); |
232 QVERIFY(pause.state() == QAbstractAnimation::Stopped); |
236 QVERIFY(pause.state() == QAbstractAnimation::Stopped); |
233 QVERIFY(pause.m_updateCurrentTimeCount > 3); |
237 QVERIFY(pause.m_updateCurrentTimeCount > 3); |
234 } |
238 } |
235 |
239 |
258 animation2.setDuration(200); |
262 animation2.setDuration(200); |
259 TestablePauseAnimation animation3(&group); |
263 TestablePauseAnimation animation3(&group); |
260 animation3.setDuration(200); |
264 animation3.setDuration(200); |
261 |
265 |
262 group.start(); |
266 group.start(); |
|
267 QCOMPARE(animation1.m_updateCurrentTimeCount, 1); |
|
268 QCOMPARE(animation2.m_updateCurrentTimeCount, 0); |
|
269 QCOMPARE(animation3.m_updateCurrentTimeCount, 0); |
263 |
270 |
264 QVERIFY(group.state() == QAbstractAnimation::Running); |
271 QVERIFY(group.state() == QAbstractAnimation::Running); |
265 QVERIFY(animation1.state() == QAbstractAnimation::Running); |
272 QVERIFY(animation1.state() == QAbstractAnimation::Running); |
266 QVERIFY(animation2.state() == QAbstractAnimation::Stopped); |
273 QVERIFY(animation2.state() == QAbstractAnimation::Stopped); |
267 QVERIFY(animation3.state() == QAbstractAnimation::Stopped); |
274 QVERIFY(animation3.state() == QAbstractAnimation::Stopped); |
268 |
275 |
269 group.setCurrentTime(250); |
276 group.setCurrentTime(250); |
|
277 QCOMPARE(animation1.m_updateCurrentTimeCount, 2); |
|
278 QCOMPARE(animation2.m_updateCurrentTimeCount, 1); |
|
279 QCOMPARE(animation3.m_updateCurrentTimeCount, 0); |
270 |
280 |
271 QVERIFY(group.state() == QAbstractAnimation::Running); |
281 QVERIFY(group.state() == QAbstractAnimation::Running); |
272 QVERIFY(animation1.state() == QAbstractAnimation::Stopped); |
282 QVERIFY(animation1.state() == QAbstractAnimation::Stopped); |
273 QCOMPARE(&animation2, group.currentAnimation()); |
283 QCOMPARE(&animation2, group.currentAnimation()); |
274 QVERIFY(animation2.state() == QAbstractAnimation::Running); |
284 QVERIFY(animation2.state() == QAbstractAnimation::Running); |
275 QVERIFY(animation3.state() == QAbstractAnimation::Stopped); |
285 QVERIFY(animation3.state() == QAbstractAnimation::Stopped); |
276 |
286 |
277 group.setCurrentTime(500); |
287 group.setCurrentTime(500); |
|
288 QCOMPARE(animation1.m_updateCurrentTimeCount, 2); |
|
289 QCOMPARE(animation2.m_updateCurrentTimeCount, 2); |
|
290 QCOMPARE(animation3.m_updateCurrentTimeCount, 1); |
278 |
291 |
279 QVERIFY(group.state() == QAbstractAnimation::Running); |
292 QVERIFY(group.state() == QAbstractAnimation::Running); |
280 QVERIFY(animation1.state() == QAbstractAnimation::Stopped); |
293 QVERIFY(animation1.state() == QAbstractAnimation::Stopped); |
281 QVERIFY(animation2.state() == QAbstractAnimation::Stopped); |
294 QVERIFY(animation2.state() == QAbstractAnimation::Stopped); |
282 QCOMPARE(&animation3, group.currentAnimation()); |
295 QCOMPARE(&animation3, group.currentAnimation()); |