158 |
159 |
159 QUrl m_url; |
160 QUrl m_url; |
160 Phonon::MediaObject *m_media; |
161 Phonon::MediaObject *m_media; |
161 QSignalSpy *m_stateChangedSignalSpy; |
162 QSignalSpy *m_stateChangedSignalSpy; |
162 QString m_tmpFileName; |
163 QString m_tmpFileName; |
|
164 |
|
165 static void copyMediaFile(const QString &original, |
|
166 const QString &name, |
|
167 QString &resultFilePath, |
|
168 QUrl *const asURL = 0); |
163 #endif //QT_NO_PHONON |
169 #endif //QT_NO_PHONON |
164 bool m_success; |
170 bool m_success; |
165 }; |
171 }; |
166 |
172 |
167 #ifndef QT_NO_PHONON |
173 #ifndef QT_NO_PHONON |
350 QCOMPARE(s, Phonon::PausedState); |
356 QCOMPARE(s, Phonon::PausedState); |
351 QCOMPARE(m_media->state(), Phonon::PausedState); |
357 QCOMPARE(m_media->state(), Phonon::PausedState); |
352 m_success = true; |
358 m_success = true; |
353 } |
359 } |
354 |
360 |
|
361 /*! |
|
362 Copies the file \a name to the testing area. The resulting file name path is |
|
363 returned in resultFilePath, and also set as a URL in \a asURL. |
|
364 */ |
|
365 void tst_MediaObject::copyMediaFile(const QString &original, |
|
366 const QString &name, |
|
367 QString &resultFilePath, |
|
368 QUrl *const asURL) |
|
369 { |
|
370 resultFilePath = QDir::toNativeSeparators(QDir::tempPath() + name); |
|
371 if (asURL) |
|
372 *asURL = QUrl::fromLocalFile(resultFilePath); |
|
373 |
|
374 QFile::remove(resultFilePath); |
|
375 QVERIFY(QFile::copy(original, resultFilePath)); |
|
376 QFile::setPermissions(resultFilePath, QFile::permissions(resultFilePath) | QFile::WriteOther); |
|
377 } |
|
378 |
355 void tst_MediaObject::initTestCase() |
379 void tst_MediaObject::initTestCase() |
356 { |
380 { |
357 QCoreApplication::setApplicationName("tst_MediaObject"); |
381 QCoreApplication::setApplicationName("tst_MediaObject"); |
358 m_stateChangedSignalSpy = 0; |
382 m_stateChangedSignalSpy = 0; |
359 m_media = 0; |
383 m_media = 0; |
373 connect(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State)), SLOT(stateChanged(Phonon::State, Phonon::State))); |
397 connect(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State)), SLOT(stateChanged(Phonon::State, Phonon::State))); |
374 m_stateChangedSignalSpy = new QSignalSpy(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State))); |
398 m_stateChangedSignalSpy = new QSignalSpy(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State))); |
375 QVERIFY(m_stateChangedSignalSpy->isValid()); |
399 QVERIFY(m_stateChangedSignalSpy->isValid()); |
376 m_stateChangedSignalSpy->clear(); |
400 m_stateChangedSignalSpy->clear(); |
377 |
401 |
378 if (m_url.isEmpty()) { |
402 if (m_url.isEmpty()) |
379 m_tmpFileName = QDir::toNativeSeparators(QDir::tempPath() + MEDIA_FILE); |
403 copyMediaFile(MEDIA_FILEPATH, MEDIA_FILE, m_tmpFileName, &m_url); |
380 QFile::remove(m_tmpFileName); |
|
381 QVERIFY(QFile::copy(MEDIA_FILEPATH, m_tmpFileName)); |
|
382 QFile::Permissions p = QFile::permissions(m_tmpFileName); |
|
383 QFile::setPermissions(m_tmpFileName, p | QFile::WriteOther); |
|
384 m_url = QUrl::fromLocalFile(m_tmpFileName); |
|
385 } |
|
386 |
404 |
387 qDebug() << "Using url:" << m_url.toString(); |
405 qDebug() << "Using url:" << m_url.toString(); |
388 |
406 |
389 // AudioOutput is needed else the backend might have no time source |
407 // AudioOutput is needed else the backend might have no time source |
390 AudioOutput *audioOutput = new AudioOutput(Phonon::MusicCategory, this); |
408 AudioOutput *audioOutput = new AudioOutput(Phonon::MusicCategory, this); |
529 void tst_MediaObject::pauseToStop() |
547 void tst_MediaObject::pauseToStop() |
530 { |
548 { |
531 startPlayback(); |
549 startPlayback(); |
532 pausePlayback(); |
550 pausePlayback(); |
533 stopPlayback(Phonon::PausedState); |
551 stopPlayback(Phonon::PausedState); |
|
552 } |
|
553 |
|
554 /*! |
|
555 |
|
556 We attempt to play a SDP file. An SDP file essentially describes different |
|
557 media streams and is hence a layer in front of the actual media(s). |
|
558 Sometimes the backend handles the SDP file, in other cases not. |
|
559 |
|
560 Some Phonon backends doesn't support SDP at all, ifdef appropriately. Real |
|
561 Player and Helix, the two backends for Symbian, are known to support SDP. |
|
562 */ |
|
563 void tst_MediaObject::playSDP() |
|
564 { |
|
565 #ifdef Q_OS_SYMBIAN |
|
566 QString sdpFile; |
|
567 copyMediaFile(QLatin1String(":/media/test.sdp"), QLatin1String("test.sdp"), sdpFile); |
|
568 |
|
569 // Let's verify our test setup. |
|
570 QVERIFY(QFileInfo(sdpFile).isReadable()); |
|
571 |
|
572 // We need a window in order to setup the video. |
|
573 QWidget widget; |
|
574 widget.show(); |
|
575 |
|
576 const MediaSource oldSource(m_media->currentSource()); |
|
577 const MediaSource sdpSource(sdpFile); |
|
578 m_media->setCurrentSource(sdpSource); |
|
579 if (m_media->state() != Phonon::StoppedState) |
|
580 QTest::waitForSignal(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State)), 10000); |
|
581 |
|
582 // At this point we're in error state due to absent media, but it has now loaded the SDP: |
|
583 QCOMPARE(m_media->errorString(), QString::fromLatin1("Buffering clip failed: Unknown error (-39)")); |
|
584 |
|
585 // We cannot play the SDP, we can neither attempt to play it, because we |
|
586 // won't get a state change from ErrorState to ErrorState, and hence block |
|
587 // on a never occuring signal. |
|
588 m_media->setCurrentSource(oldSource); |
|
589 |
|
590 #else |
|
591 QSKIP("Unsupported on this platform.", SkipAll); |
|
592 #endif |
534 } |
593 } |
535 |
594 |
536 void tst_MediaObject::testPrefinishMark() |
595 void tst_MediaObject::testPrefinishMark() |
537 { |
596 { |
538 const qint32 requestedPrefinishMarkTime = 2000; |
597 const qint32 requestedPrefinishMarkTime = 2000; |