|
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 Qt Mobility Components. |
|
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 #include <QtCore/qdebug.h> |
|
44 #include <QtCore/qbuffer.h> |
|
45 |
|
46 #include <QMediaPlayer> |
|
47 #include <QMediaPlayerControl> |
|
48 #include <QMediaPlaylist> |
|
49 #include <QMediaService> |
|
50 #include <QMediaStreamsControl> |
|
51 |
|
52 QTM_USE_NAMESPACE |
|
53 class AutoConnection |
|
54 { |
|
55 public: |
|
56 AutoConnection(QObject *sender, const char *signal, QObject *receiver, const char *method) |
|
57 : sender(sender), signal(signal), receiver(receiver), method(method) |
|
58 { |
|
59 QObject::connect(sender, signal, receiver, method); |
|
60 } |
|
61 |
|
62 ~AutoConnection() |
|
63 { |
|
64 QObject::disconnect(sender, signal, receiver, method); |
|
65 } |
|
66 |
|
67 private: |
|
68 QObject *sender; |
|
69 const char *signal; |
|
70 QObject *receiver; |
|
71 const char *method; |
|
72 }; |
|
73 |
|
74 class tst_QMediaPlayer: public QObject |
|
75 { |
|
76 Q_OBJECT |
|
77 |
|
78 public slots: |
|
79 void initTestCase_data(); |
|
80 void initTestCase(); |
|
81 void cleanupTestCase(); |
|
82 void init(); |
|
83 void cleanup(); |
|
84 |
|
85 private slots: |
|
86 void testMedia(); |
|
87 void testDuration(); |
|
88 void testPosition(); |
|
89 void testVolume(); |
|
90 void testMuted(); |
|
91 void testVideoAvailable(); |
|
92 // //void testBufferStatus(); |
|
93 void testSeekable(); |
|
94 // //void testPlaybackRate(); |
|
95 // //void testError(); |
|
96 // //void testErrorString(); |
|
97 // //void testService(); |
|
98 |
|
99 void testPlay(); |
|
100 void testPause(); |
|
101 void testStop(); |
|
102 // //void testMediaStatus(); |
|
103 void testPlaylist(); |
|
104 }; |
|
105 |
|
106 void tst_QMediaPlayer::initTestCase_data() |
|
107 { |
|
108 QTest::addColumn<bool>("valid"); |
|
109 //QTest::addColumn<QMediaPlayer::State>("state"); |
|
110 //QTest::addColumn<QMediaPlayer::MediaStatus>("status"); |
|
111 QTest::addColumn<QMediaContent>("mediaContent"); |
|
112 QTest::addColumn<qint64>("duration"); |
|
113 QTest::addColumn<qint64>("position"); |
|
114 QTest::addColumn<bool>("seekable"); |
|
115 QTest::addColumn<int>("volume"); |
|
116 QTest::addColumn<bool>("muted"); // Is this needed ??? |
|
117 QTest::addColumn<bool>("videoAvailable"); // Is this needed ??? |
|
118 //QTest::addColumn<int>("bufferStatus"); |
|
119 //QTest::addColumn<qreal>("playbackRate"); |
|
120 //QTest::addColumn<QMediaPlayer::Error>("error"); |
|
121 //QTest::addColumn<QString>("errorString"); |
|
122 |
|
123 QTest::newRow("TestDataNull") |
|
124 << false // valid |
|
125 //<< QMediaPlayer::StoppedState // state |
|
126 //<< QMediaPlayer::UnknownMediaStatus // status |
|
127 << QMediaContent() // mediaContent |
|
128 << qint64(-1) // duration |
|
129 << qint64(0) // position |
|
130 << false // seekable |
|
131 << 0 // volume |
|
132 << false // muted |
|
133 << false; // videoAvailable |
|
134 //<< 0 // bufferStatus |
|
135 //<< qreal(0) // playbackRate |
|
136 //<< QMediaPlayer::NoError // error |
|
137 //<< QString(); // errorString |
|
138 |
|
139 /* |
|
140 QTest::newRow("test_3gp.3gp") |
|
141 << true // valid |
|
142 //<< QMediaPlayer::StoppedState // state |
|
143 //<< QMediaPlayer::UnknownMediaStatus // status |
|
144 << QMediaContent(QUrl("file:///C:/data/testfiles/test_3gp.3gp")) // mediaContent |
|
145 << qint64(-1) // duration |
|
146 << qint64(0) // position |
|
147 << false // seekable |
|
148 << 0 // volume |
|
149 << false // muted |
|
150 << false; // videoAvailable |
|
151 //<< 0 // bufferStatus |
|
152 //<< qreal(0) // playbackRate |
|
153 //<< QMediaPlayer::NoError // error |
|
154 //<< QString(); // errorString |
|
155 */ |
|
156 |
|
157 QTest::newRow("test_amr.amr") |
|
158 << true // valid |
|
159 //<< QMediaPlayer::StoppedState // state |
|
160 //<< QMediaPlayer::UnknownMediaStatus // status |
|
161 << QMediaContent(QUrl("file:///C:/data/testfiles/test_amr.amr")) // mediaContent |
|
162 << qint64(14400) // duration |
|
163 << qint64(200) // position |
|
164 << true // seekable |
|
165 << 0 // volume |
|
166 << false // muted |
|
167 << false; // videoAvailable |
|
168 //<< 0 // bufferStatus |
|
169 //<< qreal(0) // playbackRate |
|
170 //<< QMediaPlayer::NoError // error |
|
171 //<< QString(); // errorString |
|
172 |
|
173 /* |
|
174 QTest::newRow("test_flash_video.flv") |
|
175 << true // valid |
|
176 //<< QMediaPlayer::StoppedState // state |
|
177 //<< QMediaPlayer::UnknownMediaStatus // status |
|
178 << QMediaContent(QUrl("file:///C:/data/testfiles/test_flash_video.flv")) // mediaContent |
|
179 << qint64(-1) // duration |
|
180 << qint64(0) // position |
|
181 << true // seekable |
|
182 << 0 // volume |
|
183 << false // muted |
|
184 << false; // videoAvailable |
|
185 //<< 0 // bufferStatus |
|
186 //<< qreal(0) // playbackRate |
|
187 //<< QMediaPlayer::NoError // error |
|
188 //<< QString(); // errorString |
|
189 */ |
|
190 |
|
191 QTest::newRow("test_invalid_extension_mp4.xyz") |
|
192 << true // valid |
|
193 //<< QMediaPlayer::StoppedState // state |
|
194 //<< QMediaPlayer::UnknownMediaStatus // status |
|
195 << QMediaContent(QUrl("file:///C:/data/testfiles/test_invalid_extension_mp4.xyz")) // mediaContent |
|
196 << qint64(2701) // duration //TODO: FIXME: In this case duration could not be read |
|
197 << qint64(0) // position |
|
198 << false // seekable |
|
199 << 0 // volume |
|
200 << false // muted |
|
201 << false; // videoAvailable |
|
202 //<< 0 // bufferStatus |
|
203 //<< qreal(0) // playbackRate |
|
204 //<< QMediaPlayer::NoError // error |
|
205 //<< QString(); // errorString |
|
206 |
|
207 QTest::newRow("test_invalid_extension_wav.xyz") |
|
208 << true // valid |
|
209 //<< QMediaPlayer::StoppedState // state |
|
210 //<< QMediaPlayer::UnknownMediaStatus // status |
|
211 << QMediaContent(QUrl("file:///C:/data/testfiles/test_invalid_extension_wav.xyz")) // mediaContent |
|
212 << qint64(12400) // duration |
|
213 << qint64(400) // position |
|
214 << true // seekable |
|
215 << 0 // volume |
|
216 << false // muted |
|
217 << false; // videoAvailable |
|
218 //<< 0 // bufferStatus |
|
219 //<< qreal(0) // playbackRate |
|
220 //<< QMediaPlayer::NoError // error |
|
221 //<< QString(); // errorString |
|
222 |
|
223 QTest::newRow("test_mp3.mp3") |
|
224 << true // valid |
|
225 //<< QMediaPlayer::StoppedState // state |
|
226 //<< QMediaPlayer::UnknownMediaStatus // status |
|
227 << QMediaContent(QUrl("file:///C:/data/testfiles/test_mp3.mp3")) // mediaContent |
|
228 << qint64(102044) // duration |
|
229 << qint64(0) // position |
|
230 << false // seekable |
|
231 << 0 // volume |
|
232 << false // muted |
|
233 << false; // videoAvailable |
|
234 //<< 0 // bufferStatus |
|
235 //<< qreal(0) // playbackRate |
|
236 //<< QMediaPlayer::NoError // error |
|
237 //<< QString(); // errorString |
|
238 |
|
239 QTest::newRow("test_mp4.mp4") |
|
240 << true // valid |
|
241 //<< QMediaPlayer::StoppedState // state |
|
242 //<< QMediaPlayer::UnknownMediaStatus // status |
|
243 << QMediaContent(QUrl("file:///C:/data/testfiles/test_mp4.mp4")) // mediaContent |
|
244 << qint64(2701) // duration //TODO: FIXME: In this case duration could not be read |
|
245 << qint64(0) // position |
|
246 << false // seekable |
|
247 << 0 // volume |
|
248 << false // muted |
|
249 << false; // videoAvailable |
|
250 //<< 0 // bufferStatus |
|
251 //<< qreal(0) // playbackRate |
|
252 //<< QMediaPlayer::NoError // error |
|
253 //<< QString(); // errorString |
|
254 |
|
255 QTest::newRow("test_wav.wav") |
|
256 << true // valid |
|
257 //<< QMediaPlayer::StoppedState // state |
|
258 //<< QMediaPlayer::UnknownMediaStatus // status |
|
259 << QMediaContent(QUrl("file:///C:/data/testfiles/test_wav.wav")) // mediaContent |
|
260 << qint64(12400) // duration |
|
261 << qint64(321) // position |
|
262 << true // seekable |
|
263 << 0 // volume |
|
264 << false // muted |
|
265 << false; // videoAvailable |
|
266 //<< 0 // bufferStatus |
|
267 //<< qreal(0) // playbackRate |
|
268 //<< QMediaPlayer::NoError // error |
|
269 //<< QString(); // errorString |
|
270 |
|
271 QTest::newRow("test_wmv9.wmv") |
|
272 << true // valid |
|
273 //<< QMediaPlayer::StoppedState // state |
|
274 //<< QMediaPlayer::UnknownMediaStatus // status |
|
275 << QMediaContent(QUrl("file:///C:/data/testfiles/test_wmv9.wmv")) // mediaContent |
|
276 << qint64(169389) // duration |
|
277 << qint64(789) // position |
|
278 << true // seekable |
|
279 << 0 // volume |
|
280 << false // muted |
|
281 << false; // videoAvailable |
|
282 //<< 0 // bufferStatus |
|
283 //<< qreal(0) // playbackRate |
|
284 //<< QMediaPlayer::NoError // error |
|
285 //<< QString(); // errorString |
|
286 |
|
287 QTest::newRow("test youtube stream") |
|
288 << true // valid |
|
289 //<< QMediaPlayer::StoppedState // state |
|
290 //<< QMediaPlayer::UnknownMediaStatus // status |
|
291 << QMediaContent(QUrl("rtsp://v3.cache4.c.youtube.com/CkgLENy73wIaPwlU2rm7yu8PFhMYESARFEIJbXYtZ29vZ2xlSARSB3JlbGF0ZWRaDkNsaWNrVGh1bWJuYWlsYPi6_IXT2rvpSgw=/0/0/0/video.3gp")) // mediaContent |
|
292 << qint64(0) // duration |
|
293 << qint64(0) // position |
|
294 << true // seekable |
|
295 << 0 // volume |
|
296 << false // muted |
|
297 << false; // videoAvailable |
|
298 //<< 0 // bufferStatus |
|
299 //<< qreal(0) // playbackRate |
|
300 //<< QMediaPlayer::NoError // error |
|
301 //<< QString(); // errorString |
|
302 |
|
303 /* |
|
304 QTest::newRow("invalid") << false << QMediaPlayer::StoppedState << QMediaPlayer::UnknownMediaStatus << |
|
305 QMediaContent() << qint64(-1) << qint64(0) << false << 0 << false << false << 0 << |
|
306 qreal(0) << QMediaPlayer::NoError << QString(); |
|
307 QTest::newRow("valid+null") << true << QMediaPlayer::StoppedState << QMediaPlayer::UnknownMediaStatus << |
|
308 QMediaContent() << qint64(0) << qint64(0) << false << 0 << false << false << 50 << |
|
309 qreal(0) << QMediaPlayer::NoError << QString(); |
|
310 QTest::newRow("valid+content+stopped") << true << QMediaPlayer::StoppedState << QMediaPlayer::UnknownMediaStatus << |
|
311 QMediaContent(QUrl("file:///some.mp3")) << qint64(0) << qint64(0) << false << 50 << false << false << 0 << |
|
312 qreal(1) << QMediaPlayer::NoError << QString(); |
|
313 QTest::newRow("valid+content+playing") << true << QMediaPlayer::PlayingState << QMediaPlayer::LoadedMedia << |
|
314 QMediaContent(QUrl("file:///some.mp3")) << qint64(10000) << qint64(10) << true << 50 << true << false << 0 << |
|
315 qreal(1) << QMediaPlayer::NoError << QString(); |
|
316 QTest::newRow("valid+content+paused") << true << QMediaPlayer::PausedState << QMediaPlayer::LoadedMedia << |
|
317 QMediaContent(QUrl("file:///some.mp3")) << qint64(10000) << qint64(10) << true << 50 << true << false << 0 << |
|
318 qreal(1) << QMediaPlayer::NoError << QString(); |
|
319 QTest::newRow("valud+streaming") << true << QMediaPlayer::PlayingState << QMediaPlayer::LoadedMedia << |
|
320 QMediaContent(QUrl("http://example.com/stream")) << qint64(10000) << qint64(10000) << false << 50 << false << true << 0 << |
|
321 qreal(1) << QMediaPlayer::NoError << QString(); |
|
322 QTest::newRow("valid+error") << true << QMediaPlayer::StoppedState << QMediaPlayer::UnknownMediaStatus << |
|
323 QMediaContent(QUrl("http://example.com/stream")) << qint64(0) << qint64(0) << false << 50 << false << false << 0 << |
|
324 qreal(0) << QMediaPlayer::ResourceError << QString("Resource unavailable"); |
|
325 */ |
|
326 } |
|
327 |
|
328 void tst_QMediaPlayer::initTestCase() |
|
329 { |
|
330 } |
|
331 |
|
332 void tst_QMediaPlayer::cleanupTestCase() |
|
333 { |
|
334 } |
|
335 |
|
336 void tst_QMediaPlayer::init() |
|
337 { |
|
338 qRegisterMetaType<QMediaPlayer::State>("QMediaPlayer::State"); |
|
339 qRegisterMetaType<QMediaPlayer::Error>("QMediaPlayer::Error"); |
|
340 qRegisterMetaType<QMediaPlayer::MediaStatus>("QMediaPlayer::MediaStatus"); |
|
341 qRegisterMetaType<QMediaContent>("QMediaContent"); |
|
342 } |
|
343 |
|
344 void tst_QMediaPlayer::cleanup() |
|
345 { |
|
346 } |
|
347 |
|
348 void tst_QMediaPlayer::testMedia() |
|
349 { |
|
350 QFETCH_GLOBAL(QMediaContent, mediaContent); |
|
351 |
|
352 QMediaPlayer player; |
|
353 |
|
354 player.setMedia(mediaContent); |
|
355 QTest::qWait(500); |
|
356 QCOMPARE(player.media(), mediaContent); |
|
357 |
|
358 // QBuffer stream; |
|
359 // player.setMedia(mediaContent, &stream); |
|
360 // QCOMPARE(player.media(), mediaContent); |
|
361 // QCOMPARE((QBuffer*)player.mediaStream(), &stream); |
|
362 } |
|
363 |
|
364 void tst_QMediaPlayer::testDuration() |
|
365 { |
|
366 QFETCH_GLOBAL(QMediaContent, mediaContent); |
|
367 QFETCH_GLOBAL(qint64, duration); |
|
368 |
|
369 QMediaPlayer player; |
|
370 player.setMedia(mediaContent); |
|
371 QTest::qWait(500); |
|
372 |
|
373 |
|
374 QEXPECT_FAIL("", "player.duration() failed: ", Continue); |
|
375 QVERIFY(player.duration() == duration); |
|
376 } |
|
377 |
|
378 |
|
379 void tst_QMediaPlayer::testPosition() |
|
380 { |
|
381 QFETCH_GLOBAL(QMediaContent, mediaContent); |
|
382 QFETCH_GLOBAL(qint64, duration); |
|
383 QFETCH_GLOBAL(qint64, position); |
|
384 QFETCH_GLOBAL(bool, seekable); |
|
385 |
|
386 QMediaPlayer player; |
|
387 |
|
388 player.setMedia(mediaContent); |
|
389 QTest::qWait(500); |
|
390 player.setPosition(position); |
|
391 |
|
392 qDebug() << "Mediafile" << player.media().canonicalUrl().toString(); |
|
393 QEXPECT_FAIL("", "player.isSeekable() failed: ", Continue); |
|
394 QVERIFY(player.isSeekable() == seekable); |
|
395 QEXPECT_FAIL("", "player.position() failed: ", Continue); |
|
396 QVERIFY(player.position() == position); |
|
397 QEXPECT_FAIL("", "player.duration() failed: ", Continue); |
|
398 QVERIFY(player.duration() == duration); |
|
399 |
|
400 if (seekable) { |
|
401 { QSignalSpy spy(&player, SIGNAL(positionChanged(qint64))); |
|
402 player.setPosition(position); |
|
403 qDebug() << player.position(); |
|
404 QCOMPARE(player.position(), position); |
|
405 QCOMPARE(spy.count(), 0); } |
|
406 |
|
407 player.setPosition(position); |
|
408 { QSignalSpy spy(&player, SIGNAL(positionChanged(qint64))); |
|
409 player.setPosition(0); |
|
410 QCOMPARE(player.position(), qint64(0)); |
|
411 QCOMPARE(spy.count(), position == 0 ? 0 : 1); } |
|
412 |
|
413 player.setPosition(position); |
|
414 { QSignalSpy spy(&player, SIGNAL(positionChanged(qint64))); |
|
415 player.setPosition(duration); |
|
416 QEXPECT_FAIL("", "player.duration() failed: ", Continue); |
|
417 QCOMPARE(player.position(), duration); |
|
418 QCOMPARE(spy.count(), position == duration ? 0 : 1); } |
|
419 |
|
420 player.setPosition(position); |
|
421 { QSignalSpy spy(&player, SIGNAL(positionChanged(qint64))); |
|
422 player.setPosition(-1); |
|
423 QCOMPARE(player.position(), qint64(0)); |
|
424 QCOMPARE(spy.count(), position == 0 ? 0 : 1); } |
|
425 |
|
426 player.setPosition(position); |
|
427 { QSignalSpy spy(&player, SIGNAL(positionChanged(qint64))); |
|
428 player.setPosition(duration + 1); |
|
429 QCOMPARE(player.position(), duration); |
|
430 QCOMPARE(spy.count(), position == duration ? 0 : 1); } |
|
431 } |
|
432 else { |
|
433 QSignalSpy spy(&player, SIGNAL(positionChanged(qint64))); |
|
434 player.setPosition(position); |
|
435 |
|
436 QCOMPARE(player.position(), position); |
|
437 QCOMPARE(spy.count(), 0); |
|
438 } |
|
439 } |
|
440 |
|
441 void tst_QMediaPlayer::testVolume() |
|
442 { |
|
443 QFETCH_GLOBAL(QMediaContent, mediaContent); |
|
444 QFETCH_GLOBAL(bool, valid); |
|
445 QFETCH_GLOBAL(int, volume); |
|
446 |
|
447 QMediaPlayer player; |
|
448 |
|
449 player.setMedia(mediaContent); |
|
450 QTest::qWait(500); |
|
451 |
|
452 player.setVolume(volume); |
|
453 QVERIFY(player.volume() == volume); |
|
454 |
|
455 //TODO: Remove this IF |
|
456 if (valid) { |
|
457 { QSignalSpy spy(&player, SIGNAL(volumeChanged(int))); |
|
458 player.setVolume(10); |
|
459 QCOMPARE(player.volume(), 10); |
|
460 QCOMPARE(spy.count(), 1); } |
|
461 |
|
462 { QSignalSpy spy(&player, SIGNAL(volumeChanged(int))); |
|
463 player.setVolume(-1000); |
|
464 QCOMPARE(player.volume(), 0); |
|
465 QCOMPARE(spy.count(), 1); } |
|
466 |
|
467 { QSignalSpy spy(&player, SIGNAL(volumeChanged(int))); |
|
468 player.setVolume(100); |
|
469 QCOMPARE(player.volume(), 100); |
|
470 QCOMPARE(spy.count(), 1); } |
|
471 |
|
472 { QSignalSpy spy(&player, SIGNAL(volumeChanged(int))); |
|
473 player.setVolume(1000); |
|
474 QCOMPARE(player.volume(), 100); |
|
475 QCOMPARE(spy.count(), 0); } |
|
476 } |
|
477 } |
|
478 |
|
479 void tst_QMediaPlayer::testMuted() |
|
480 { |
|
481 QFETCH_GLOBAL(bool, valid); |
|
482 QFETCH_GLOBAL(int, volume); |
|
483 QFETCH_GLOBAL(bool, muted); |
|
484 |
|
485 // TODO Use valid |
|
486 |
|
487 QMediaPlayer player; |
|
488 |
|
489 if (valid) { |
|
490 player.setMuted(muted); |
|
491 player.setVolume(volume); |
|
492 QVERIFY(player.isMuted() == muted); |
|
493 |
|
494 QSignalSpy spy(&player, SIGNAL(mutedChanged(bool))); |
|
495 player.setMuted(!muted); |
|
496 QCOMPARE(player.isMuted(), !muted); |
|
497 QCOMPARE(player.volume(), volume); |
|
498 QCOMPARE(spy.count(), 1); |
|
499 } |
|
500 } |
|
501 |
|
502 void tst_QMediaPlayer::testVideoAvailable() |
|
503 { |
|
504 QFETCH_GLOBAL(bool, videoAvailable); |
|
505 QFETCH_GLOBAL(QMediaContent, mediaContent); |
|
506 |
|
507 QMediaPlayer player; |
|
508 |
|
509 player.setMedia(mediaContent); |
|
510 QTest::qWait(500); |
|
511 QVERIFY(player.isVideoAvailable() == videoAvailable); |
|
512 } |
|
513 |
|
514 /* |
|
515 void tst_QMediaPlayer::testBufferStatus() |
|
516 { |
|
517 QFETCH_GLOBAL(int, bufferStatus); |
|
518 |
|
519 QMediaPlayer player; |
|
520 |
|
521 mockService->setBufferStatus(bufferStatus); |
|
522 QVERIFY(player.bufferStatus() == bufferStatus); |
|
523 } |
|
524 */ |
|
525 |
|
526 void tst_QMediaPlayer::testSeekable() |
|
527 { |
|
528 QFETCH_GLOBAL(QMediaContent, mediaContent); |
|
529 QFETCH_GLOBAL(bool, seekable); |
|
530 |
|
531 QMediaPlayer player; |
|
532 |
|
533 player.setMedia(mediaContent); |
|
534 QTest::qWait(500); |
|
535 QVERIFY(player.isSeekable() == seekable); |
|
536 } |
|
537 |
|
538 /* |
|
539 void tst_QMediaPlayer::testPlaybackRate() |
|
540 { |
|
541 QFETCH_GLOBAL(bool, valid); |
|
542 QFETCH_GLOBAL(qreal, playbackRate); |
|
543 |
|
544 QMediaPlayer player; |
|
545 |
|
546 if (valid) { |
|
547 player.setPlaybackRate(playbackRate); |
|
548 QVERIFY(player.playbackRate() == playbackRate); |
|
549 |
|
550 QSignalSpy spy(&player, SIGNAL(playbackRateChanged(qreal))); |
|
551 player.setPlaybackRate(playbackRate + 0.5f); |
|
552 QCOMPARE(player.playbackRate(), playbackRate + 0.5f); |
|
553 QCOMPARE(spy.count(), 1); |
|
554 } |
|
555 } |
|
556 */ |
|
557 |
|
558 /* |
|
559 void tst_QMediaPlayer::testError() |
|
560 { |
|
561 QFETCH_GLOBAL(QMediaPlayer::Error, error); |
|
562 |
|
563 |
|
564 QMediaPlayer player; |
|
565 |
|
566 //mockService->setError(error); |
|
567 //QVERIFY(player.error() == error); |
|
568 } |
|
569 */ |
|
570 |
|
571 /* |
|
572 void tst_QMediaPlayer::testErrorString() |
|
573 { |
|
574 QFETCH_GLOBAL(QString, errorString); |
|
575 |
|
576 QMediaPlayer player; |
|
577 |
|
578 //mockService->setErrorString(errorString); |
|
579 //QVERIFY(player.errorString() == errorString); |
|
580 } |
|
581 */ |
|
582 |
|
583 /* |
|
584 void tst_QMediaPlayer::testService() |
|
585 { |
|
586 QFETCH_GLOBAL(bool, valid); |
|
587 |
|
588 QMediaPlayer player; |
|
589 |
|
590 mockService->setIsValid(valid); |
|
591 |
|
592 if (valid) |
|
593 QVERIFY(player.service() != 0); |
|
594 else |
|
595 QVERIFY(player.service() == 0); |
|
596 } |
|
597 */ |
|
598 |
|
599 void tst_QMediaPlayer::testPlay() |
|
600 { |
|
601 QFETCH_GLOBAL(bool, valid); |
|
602 QFETCH_GLOBAL(QMediaContent, mediaContent); |
|
603 |
|
604 QMediaPlayer player; |
|
605 |
|
606 player.setMedia(mediaContent); |
|
607 QTest::qWait(500); |
|
608 QVERIFY(player.state() == QMediaPlayer::StoppedState); |
|
609 QVERIFY(player.media() == mediaContent); |
|
610 |
|
611 { |
|
612 QSignalSpy spy(&player, SIGNAL(stateChanged(QMediaPlayer::State))); |
|
613 |
|
614 player.play(); |
|
615 QTest::qWait(500); |
|
616 |
|
617 if (!valid || mediaContent.isNull()) { |
|
618 QCOMPARE(player.state(), QMediaPlayer::StoppedState); |
|
619 QCOMPARE(spy.count(), 0); |
|
620 } |
|
621 else { |
|
622 QCOMPARE(player.state(), QMediaPlayer::PlayingState); |
|
623 QCOMPARE(spy.count(), 1); |
|
624 } |
|
625 } |
|
626 |
|
627 { |
|
628 QSignalSpy spy(&player, SIGNAL(stateChanged(QMediaPlayer::State))); |
|
629 |
|
630 player.play(); |
|
631 QTest::qWait(500); |
|
632 |
|
633 if (!valid || mediaContent.isNull()) { |
|
634 QCOMPARE(player.state(), QMediaPlayer::StoppedState); |
|
635 QCOMPARE(spy.count(), 0); |
|
636 } |
|
637 else { |
|
638 QCOMPARE(player.state(), QMediaPlayer::PlayingState); |
|
639 QCOMPARE(spy.count(), 0); |
|
640 } |
|
641 } |
|
642 } |
|
643 |
|
644 void tst_QMediaPlayer::testPause() |
|
645 { |
|
646 QFETCH_GLOBAL(bool, valid); |
|
647 QFETCH_GLOBAL(QMediaContent, mediaContent); |
|
648 |
|
649 QMediaPlayer player; |
|
650 |
|
651 player.setMedia(mediaContent); |
|
652 QTest::qWait(500); |
|
653 QCOMPARE(player.state(), QMediaPlayer::StoppedState); |
|
654 QVERIFY(player.media() == mediaContent); |
|
655 |
|
656 player.play(); |
|
657 QTest::qWait(500); |
|
658 |
|
659 { |
|
660 QSignalSpy spy(&player, SIGNAL(stateChanged(QMediaPlayer::State))); |
|
661 |
|
662 player.pause(); |
|
663 |
|
664 if (!valid || mediaContent.isNull()) { |
|
665 QCOMPARE(player.state(), QMediaPlayer::StoppedState); |
|
666 QCOMPARE(spy.count(), 0); |
|
667 } |
|
668 else { |
|
669 QCOMPARE(player.state(), QMediaPlayer::PausedState); |
|
670 QCOMPARE(spy.count(), 1); |
|
671 } |
|
672 } |
|
673 |
|
674 { |
|
675 QSignalSpy spy(&player, SIGNAL(stateChanged(QMediaPlayer::State))); |
|
676 |
|
677 player.pause(); |
|
678 QTest::qWait(500); |
|
679 |
|
680 if (!valid || mediaContent.isNull()) { |
|
681 QCOMPARE(player.state(), QMediaPlayer::StoppedState); |
|
682 QCOMPARE(spy.count(), 0); |
|
683 } |
|
684 else { |
|
685 QCOMPARE(player.state(), QMediaPlayer::PausedState); |
|
686 QCOMPARE(spy.count(), 0); |
|
687 } |
|
688 } |
|
689 } |
|
690 |
|
691 void tst_QMediaPlayer::testStop() |
|
692 { |
|
693 QFETCH_GLOBAL(QMediaContent, mediaContent); |
|
694 |
|
695 QMediaPlayer player; |
|
696 |
|
697 player.setMedia(mediaContent); |
|
698 QTest::qWait(500); |
|
699 QVERIFY(player.state() == QMediaPlayer::StoppedState); |
|
700 QVERIFY(player.media() == mediaContent); |
|
701 |
|
702 player.play(); |
|
703 QTest::qWait(500); |
|
704 |
|
705 { |
|
706 QSignalSpy spy(&player, SIGNAL(stateChanged(QMediaPlayer::State))); |
|
707 |
|
708 player.stop(); |
|
709 QTest::qWait(500); |
|
710 |
|
711 if (mediaContent.isNull()) { |
|
712 QCOMPARE(player.state(), QMediaPlayer::StoppedState); |
|
713 QCOMPARE(spy.count(), 0); |
|
714 } |
|
715 else { |
|
716 QCOMPARE(player.state(), QMediaPlayer::StoppedState); |
|
717 QCOMPARE(spy.count(), 1); |
|
718 } |
|
719 } |
|
720 |
|
721 { |
|
722 QSignalSpy spy(&player, SIGNAL(stateChanged(QMediaPlayer::State))); |
|
723 |
|
724 if (mediaContent.isNull() || player.state() == QMediaPlayer::StoppedState) { |
|
725 QCOMPARE(player.state(), QMediaPlayer::StoppedState); |
|
726 QCOMPARE(spy.count(), 0); |
|
727 } |
|
728 } |
|
729 } |
|
730 |
|
731 /* |
|
732 void tst_QMediaPlayer::testMediaStatus() |
|
733 { |
|
734 QFETCH_GLOBAL(int, bufferStatus); |
|
735 |
|
736 QMediaPlayer player; |
|
737 |
|
738 int bufferSignals = 0; |
|
739 |
|
740 player.setNotifyInterval(10); |
|
741 |
|
742 //mockService->setMediaStatus(QMediaPlayer::NoMedia); |
|
743 //mockService->setBufferStatus(bufferStatus); |
|
744 |
|
745 AutoConnection connection( |
|
746 &player, SIGNAL(bufferStatusChanged(int)), |
|
747 &QTestEventLoop::instance(), SLOT(exitLoop())); |
|
748 |
|
749 QSignalSpy statusSpy(&player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus))); |
|
750 QSignalSpy bufferSpy(&player, SIGNAL(bufferStatusChanged(int))); |
|
751 |
|
752 QCOMPARE(player.mediaStatus(), QMediaPlayer::NoMedia); |
|
753 |
|
754 //mockService->setMediaStatus(QMediaPlayer::LoadingMedia); |
|
755 QCOMPARE(player.mediaStatus(), QMediaPlayer::LoadingMedia); |
|
756 QCOMPARE(statusSpy.count(), 1); |
|
757 QCOMPARE(qvariant_cast<QMediaPlayer::MediaStatus>(statusSpy.last().value(0)), |
|
758 QMediaPlayer::LoadingMedia); |
|
759 |
|
760 //mockService->setMediaStatus(QMediaPlayer::LoadedMedia); |
|
761 QCOMPARE(player.mediaStatus(), QMediaPlayer::LoadedMedia); |
|
762 QCOMPARE(statusSpy.count(), 2); |
|
763 QCOMPARE(qvariant_cast<QMediaPlayer::MediaStatus>(statusSpy.last().value(0)), |
|
764 QMediaPlayer::LoadedMedia); |
|
765 |
|
766 // Verify the bufferStatusChanged() signal isn't being emitted. |
|
767 QTestEventLoop::instance().enterLoop(1); |
|
768 QCOMPARE(bufferSpy.count(), 0); |
|
769 |
|
770 //mockService->setMediaStatus(QMediaPlayer::StalledMedia); |
|
771 QCOMPARE(player.mediaStatus(), QMediaPlayer::StalledMedia); |
|
772 QCOMPARE(statusSpy.count(), 3); |
|
773 QCOMPARE(qvariant_cast<QMediaPlayer::MediaStatus>(statusSpy.last().value(0)), |
|
774 QMediaPlayer::StalledMedia); |
|
775 |
|
776 // Verify the bufferStatusChanged() signal is being emitted. |
|
777 QTestEventLoop::instance().enterLoop(1); |
|
778 QVERIFY(bufferSpy.count() > bufferSignals); |
|
779 QCOMPARE(bufferSpy.last().value(0).toInt(), bufferStatus); |
|
780 bufferSignals = bufferSpy.count(); |
|
781 |
|
782 /-* |
|
783 mockService->setMediaStatus(QMediaPlayer::BufferingMedia); |
|
784 QCOMPARE(player.mediaStatus(), QMediaPlayer::BufferingMedia); |
|
785 QCOMPARE(statusSpy.count(), 4); |
|
786 QCOMPARE(qvariant_cast<QMediaPlayer::MediaStatus>(statusSpy.last().value(0)), |
|
787 QMediaPlayer::BufferingMedia); |
|
788 *-/ |
|
789 |
|
790 // Verify the bufferStatusChanged() signal is being emitted. |
|
791 QTestEventLoop::instance().enterLoop(1); |
|
792 QVERIFY(bufferSpy.count() > bufferSignals); |
|
793 QCOMPARE(bufferSpy.last().value(0).toInt(), bufferStatus); |
|
794 bufferSignals = bufferSpy.count(); |
|
795 |
|
796 //mockService->setMediaStatus(QMediaPlayer::BufferedMedia); |
|
797 QCOMPARE(player.mediaStatus(), QMediaPlayer::BufferedMedia); |
|
798 QCOMPARE(statusSpy.count(), 5); |
|
799 QCOMPARE(qvariant_cast<QMediaPlayer::MediaStatus>(statusSpy.last().value(0)), |
|
800 QMediaPlayer::BufferedMedia); |
|
801 |
|
802 // Verify the bufferStatusChanged() signal isn't being emitted. |
|
803 QTestEventLoop::instance().enterLoop(1); |
|
804 QCOMPARE(bufferSpy.count(), bufferSignals); |
|
805 |
|
806 //mockService->setMediaStatus(QMediaPlayer::EndOfMedia); |
|
807 QCOMPARE(player.mediaStatus(), QMediaPlayer::EndOfMedia); |
|
808 QCOMPARE(statusSpy.count(), 6); |
|
809 QCOMPARE(qvariant_cast<QMediaPlayer::MediaStatus>(statusSpy.last().value(0)), |
|
810 QMediaPlayer::EndOfMedia); |
|
811 } |
|
812 */ |
|
813 |
|
814 void tst_QMediaPlayer::testPlaylist() |
|
815 { |
|
816 QMediaContent content0(QUrl(QLatin1String("file:///c:/data/test.mp3"))); //audio |
|
817 QMediaContent content1(QUrl(QLatin1String("file:///c:/data/test.mp3"))); //audio |
|
818 QMediaContent content2(QUrl(QLatin1String("file:///c:/data/test.mp4"))); //video |
|
819 QMediaContent content3(QUrl(QLatin1String("file:///c:/data/test.mp4"))); //video |
|
820 QMediaContent content4(QUrl(QLatin1String("file:///c:/data/test.mp3"))); //image |
|
821 |
|
822 QMediaPlayer player; |
|
823 |
|
824 QMediaPlaylist *playlist = new QMediaPlaylist(&player); |
|
825 |
|
826 QSignalSpy stateSpy(&player, SIGNAL(stateChanged(QMediaPlayer::State))); |
|
827 QSignalSpy mediaSpy(&player, SIGNAL(mediaChanged(QMediaContent))); |
|
828 |
|
829 // Test the player does nothing with an empty playlist attached. |
|
830 player.play(); |
|
831 QCOMPARE(player.state(), QMediaPlayer::StoppedState); |
|
832 QCOMPARE(player.media(), QMediaContent()); |
|
833 QCOMPARE(stateSpy.count(), 0); |
|
834 QCOMPARE(mediaSpy.count(), 0); |
|
835 |
|
836 playlist->addMedia(content0); |
|
837 playlist->addMedia(content1); |
|
838 playlist->addMedia(content2); |
|
839 playlist->addMedia(content3); |
|
840 |
|
841 // Test changing the playlist position, changes the current media, but not the playing state. |
|
842 playlist->setCurrentIndex(1); |
|
843 QCOMPARE(player.media(), content1); |
|
844 QCOMPARE(player.state(), QMediaPlayer::StoppedState); |
|
845 QCOMPARE(stateSpy.count(), 0); |
|
846 QCOMPARE(mediaSpy.count(), 1); |
|
847 |
|
848 // Test playing starts with the current media. |
|
849 player.play(); |
|
850 QCOMPARE(player.media(), content1); |
|
851 QCOMPARE(player.state(), QMediaPlayer::PlayingState); |
|
852 QCOMPARE(stateSpy.count(), 1); |
|
853 QCOMPARE(mediaSpy.count(), 1); |
|
854 |
|
855 // Test pausing doesn't change the current media. |
|
856 player.pause(); |
|
857 QCOMPARE(player.media(), content1); |
|
858 QCOMPARE(player.state(), QMediaPlayer::PausedState); |
|
859 QCOMPARE(stateSpy.count(), 2); |
|
860 QCOMPARE(mediaSpy.count(), 1); |
|
861 |
|
862 // Test stopping doesn't change the current media. |
|
863 player.stop(); |
|
864 QCOMPARE(player.media(), content1); |
|
865 QCOMPARE(player.state(), QMediaPlayer::StoppedState); |
|
866 QCOMPARE(stateSpy.count(), 3); |
|
867 QCOMPARE(mediaSpy.count(), 1); |
|
868 |
|
869 // Test when the player service reaches the end of the current media, the player moves onto |
|
870 // the next item without stopping. |
|
871 player.play(); |
|
872 QCOMPARE(player.media(), content1); |
|
873 QCOMPARE(player.state(), QMediaPlayer::PlayingState); |
|
874 QCOMPARE(stateSpy.count(), 4); |
|
875 QCOMPARE(mediaSpy.count(), 1); |
|
876 |
|
877 /* |
|
878 // TODO FIXME: This test case needs to be refactored after duration and setposition works |
|
879 //mockService->setState(QMediaPlayer::StoppedState, QMediaPlayer::EndOfMedia); |
|
880 QCOMPARE(player.media(), content2); |
|
881 QCOMPARE(player.state(), QMediaPlayer::PlayingState); |
|
882 QCOMPARE(stateSpy.count(), 4); |
|
883 QCOMPARE(mediaSpy.count(), 2); |
|
884 |
|
885 // Test skipping the current media doesn't change the state. |
|
886 playlist->next(); |
|
887 QCOMPARE(player.media(), content3); |
|
888 QCOMPARE(player.state(), QMediaPlayer::PlayingState); |
|
889 QCOMPARE(stateSpy.count(), 4); |
|
890 QCOMPARE(mediaSpy.count(), 3); |
|
891 |
|
892 // Test changing the current media while paused doesn't change the state. |
|
893 player.pause(); |
|
894 //mockService->setMediaStatus(QMediaPlayer::BufferedMedia); |
|
895 QCOMPARE(player.media(), content3); |
|
896 QCOMPARE(player.state(), QMediaPlayer::PausedState); |
|
897 QCOMPARE(stateSpy.count(), 5); |
|
898 QCOMPARE(mediaSpy.count(), 3); |
|
899 |
|
900 playlist->previous(); |
|
901 QCOMPARE(player.media(), content2); |
|
902 QCOMPARE(player.state(), QMediaPlayer::PausedState); |
|
903 QCOMPARE(stateSpy.count(), 5); |
|
904 QCOMPARE(mediaSpy.count(), 4); |
|
905 |
|
906 // Test changing the current media while stopped doesn't change the state. |
|
907 player.stop(); |
|
908 //mockService->setMediaStatus(QMediaPlayer::LoadedMedia); |
|
909 QCOMPARE(player.media(), content2); |
|
910 QCOMPARE(player.state(), QMediaPlayer::StoppedState); |
|
911 QCOMPARE(stateSpy.count(), 6); |
|
912 QCOMPARE(mediaSpy.count(), 4); |
|
913 |
|
914 playlist->next(); |
|
915 QCOMPARE(player.media(), content3); |
|
916 QCOMPARE(player.state(), QMediaPlayer::StoppedState); |
|
917 QCOMPARE(stateSpy.count(), 6); |
|
918 QCOMPARE(mediaSpy.count(), 5); |
|
919 |
|
920 // Test the player is stopped and the current media cleared when it reaches the end of the last |
|
921 // item in the playlist. |
|
922 player.play(); |
|
923 QCOMPARE(player.media(), content3); |
|
924 QCOMPARE(player.state(), QMediaPlayer::PlayingState); |
|
925 QCOMPARE(stateSpy.count(), 7); |
|
926 QCOMPARE(mediaSpy.count(), 5); |
|
927 |
|
928 // Double up the signals to ensure some noise doesn't destabalize things. |
|
929 //mockService->setState(QMediaPlayer::StoppedState, QMediaPlayer::EndOfMedia); |
|
930 //mockService->setState(QMediaPlayer::StoppedState, QMediaPlayer::EndOfMedia); |
|
931 QCOMPARE(player.media(), QMediaContent()); |
|
932 QCOMPARE(player.state(), QMediaPlayer::StoppedState); |
|
933 QCOMPARE(stateSpy.count(), 8); |
|
934 QCOMPARE(mediaSpy.count(), 6); |
|
935 |
|
936 // Test starts playing from the start of the playlist if there is no current media selected. |
|
937 player.play(); |
|
938 QCOMPARE(player.media(), content0); |
|
939 QCOMPARE(player.state(), QMediaPlayer::PlayingState); |
|
940 QCOMPARE(stateSpy.count(), 9); |
|
941 QCOMPARE(mediaSpy.count(), 7); |
|
942 */ |
|
943 |
|
944 // TODO FIXME: This part of needs to be used after using refactored test cases before |
|
945 // Here are original signal spy values. |
|
946 /* |
|
947 // Test deleting the playlist stops the player and clears the media it set. |
|
948 delete playlist; |
|
949 QCOMPARE(player.media(), QMediaContent()); |
|
950 QCOMPARE(player.state(), QMediaPlayer::StoppedState); |
|
951 QCOMPARE(stateSpy.count(), 10); |
|
952 QCOMPARE(mediaSpy.count(), 8); |
|
953 |
|
954 // Test the player works as normal with the playlist removed. |
|
955 player.play(); |
|
956 QCOMPARE(player.media(), QMediaContent()); |
|
957 QCOMPARE(player.state(), QMediaPlayer::StoppedState); |
|
958 QCOMPARE(stateSpy.count(), 10); |
|
959 QCOMPARE(mediaSpy.count(), 8); |
|
960 |
|
961 player.setMedia(content1); |
|
962 player.play(); |
|
963 |
|
964 QCOMPARE(player.media(), content1); |
|
965 QCOMPARE(player.state(), QMediaPlayer::PlayingState); |
|
966 QCOMPARE(stateSpy.count(), 11); |
|
967 QCOMPARE(mediaSpy.count(), 9); |
|
968 */ |
|
969 |
|
970 // Test deleting the playlist stops the player and clears the media it set. |
|
971 delete playlist; |
|
972 QCOMPARE(player.media(), QMediaContent()); |
|
973 QCOMPARE(player.state(), QMediaPlayer::StoppedState); |
|
974 QCOMPARE(stateSpy.count(), 4); |
|
975 QCOMPARE(mediaSpy.count(), 1); |
|
976 |
|
977 // Test the player works as normal with the playlist removed. |
|
978 player.play(); |
|
979 QCOMPARE(player.media(), QMediaContent()); |
|
980 QCOMPARE(player.state(), QMediaPlayer::StoppedState); |
|
981 QCOMPARE(stateSpy.count(), 4); |
|
982 QCOMPARE(mediaSpy.count(), 1); |
|
983 |
|
984 player.setMedia(content1); |
|
985 player.play(); |
|
986 |
|
987 QCOMPARE(player.media(), content1); |
|
988 QCOMPARE(player.state(), QMediaPlayer::PlayingState); |
|
989 QCOMPARE(stateSpy.count(), 4); |
|
990 QCOMPARE(mediaSpy.count(), 2); |
|
991 } |
|
992 |
|
993 QTEST_MAIN(tst_QMediaPlayer) |
|
994 |
|
995 #include "tst_qmediaplayer.moc" |