diff options
author | Yoann Lopes <yoann.lopes@theqtcompany.com> | 2015-02-18 16:58:02 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> | 2015-04-07 17:21:47 +0000 |
commit | 63cff37741dca71f3db45ee06bc5bb06488c51f4 (patch) | |
tree | 4feeb36d8f95a24b5dc5dc12c99f471f824de38b /tests | |
parent | 4d17db19f895ddaa778120c346d8a6a33a710194 (diff) | |
download | qtmultimedia-63cff37741dca71f3db45ee06bc5bb06488c51f4.tar.gz |
QMediaPlayer: handle resource files in a cross-platform way.
It was the backend's responsibility to handle resource files in an
appropriate way. In practice, it was either not handled at all,
or implemented in an almost identical manner in every backend
that does handle it.
This is now dealt with in QMediaPlayer, always passing to the
backend something it will be able to play. If the backend has the
StreamPlayback capability, we pass a QFile from which it streams
the data. If it doesn't, we copy the resource to a temporary
file and pass its path to the backend.
Task-number: QTBUG-36175
Task-number: QTBUG-42263
Task-number: QTBUG-43839
Change-Id: I57b355c72692d02661baeaf74e66581ca0a0bd1d
Reviewed-by: Andrew Knight <qt@panimo.net>
Reviewed-by: Peng Wu <peng.wu@intopalo.com>
Reviewed-by: Christian Stromme <christian.stromme@theqtcompany.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/unit/qmediaplayer/qmediaplayer.pro | 1 | ||||
-rw-r--r-- | tests/auto/unit/qmediaplayer/testdata.qrc | 5 | ||||
-rw-r--r-- | tests/auto/unit/qmediaplayer/testdata/nokia-tune.mp3 | bin | 0 -> 62715 bytes | |||
-rw-r--r-- | tests/auto/unit/qmediaplayer/tst_qmediaplayer.cpp | 90 | ||||
-rw-r--r-- | tests/auto/unit/qmultimedia_common/mockmediaplayercontrol.h | 7 | ||||
-rw-r--r-- | tests/auto/unit/qmultimedia_common/mockmediaserviceprovider.h | 11 |
6 files changed, 108 insertions, 6 deletions
diff --git a/tests/auto/unit/qmediaplayer/qmediaplayer.pro b/tests/auto/unit/qmediaplayer/qmediaplayer.pro index 52568c071..cbdbf71f4 100644 --- a/tests/auto/unit/qmediaplayer/qmediaplayer.pro +++ b/tests/auto/unit/qmediaplayer/qmediaplayer.pro @@ -2,6 +2,7 @@ CONFIG += testcase no_private_qt_headers_warning TARGET = tst_qmediaplayer QT += network multimedia-private testlib SOURCES += tst_qmediaplayer.cpp +RESOURCES += testdata.qrc include (../qmultimedia_common/mock.pri) include (../qmultimedia_common/mockplayer.pri) diff --git a/tests/auto/unit/qmediaplayer/testdata.qrc b/tests/auto/unit/qmediaplayer/testdata.qrc new file mode 100644 index 000000000..1afc630dd --- /dev/null +++ b/tests/auto/unit/qmediaplayer/testdata.qrc @@ -0,0 +1,5 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource prefix="/"> + <file>testdata/nokia-tune.mp3</file> +</qresource> +</RCC> diff --git a/tests/auto/unit/qmediaplayer/testdata/nokia-tune.mp3 b/tests/auto/unit/qmediaplayer/testdata/nokia-tune.mp3 Binary files differnew file mode 100644 index 000000000..2435f65b8 --- /dev/null +++ b/tests/auto/unit/qmediaplayer/testdata/nokia-tune.mp3 diff --git a/tests/auto/unit/qmediaplayer/tst_qmediaplayer.cpp b/tests/auto/unit/qmediaplayer/tst_qmediaplayer.cpp index 2082fe14a..0271f1a8f 100644 --- a/tests/auto/unit/qmediaplayer/tst_qmediaplayer.cpp +++ b/tests/auto/unit/qmediaplayer/tst_qmediaplayer.cpp @@ -133,6 +133,8 @@ private slots: void testPlayerFlags(); void testDestructor(); void testSupportedMimeTypes(); + void testQrc_data(); + void testQrc(); private: void setupCommonTestData(); @@ -976,12 +978,17 @@ void tst_QMediaPlayer::testPlaylist() player->setPlaylist(playlist); player->play(); QCOMPARE(ss.count(), 1); + QCOMPARE(ms.count(), 1); + QCOMPARE(qvariant_cast<QMediaPlayer::MediaStatus>(ms.last().value(0)), QMediaPlayer::LoadingMedia); + ms.clear(); mockService->setState(QMediaPlayer::StoppedState, QMediaPlayer::InvalidMedia); QCOMPARE(player->state(), QMediaPlayer::PlayingState); - QCOMPARE(player->mediaStatus(), QMediaPlayer::InvalidMedia); + QCOMPARE(player->mediaStatus(), QMediaPlayer::LoadingMedia); QCOMPARE(ss.count(), 1); - QCOMPARE(ms.count(), 1); + QCOMPARE(ms.count(), 2); + QCOMPARE(qvariant_cast<QMediaPlayer::MediaStatus>(ms.at(0).value(0)), QMediaPlayer::InvalidMedia); + QCOMPARE(qvariant_cast<QMediaPlayer::MediaStatus>(ms.at(1).value(0)), QMediaPlayer::LoadingMedia); // NOTE: status should begin transitioning through to BufferedMedia. QCOMPARE(player->currentMedia(), content1); @@ -1210,5 +1217,84 @@ void tst_QMediaPlayer::testSupportedMimeTypes() // This is empty on some platforms, and not on others, so can't test something here at the moment. } +void tst_QMediaPlayer::testQrc_data() +{ + QTest::addColumn<QMediaContent>("mediaContent"); + QTest::addColumn<QMediaPlayer::MediaStatus>("status"); + QTest::addColumn<QMediaPlayer::Error>("error"); + QTest::addColumn<int>("errorCount"); + QTest::addColumn<bool>("hasStreamFeature"); + QTest::addColumn<QString>("backendMediaContentScheme"); + QTest::addColumn<bool>("backendHasStream"); + + QTest::newRow("invalid") << QMediaContent(QUrl(QLatin1String("qrc:/invalid.mp3"))) + << QMediaPlayer::InvalidMedia + << QMediaPlayer::ResourceError + << 1 // error count + << false // No StreamPlayback support + << QString() // backend should not have got any media (empty URL scheme) + << false; // backend should not have got any stream + + QTest::newRow("valid+nostream") << QMediaContent(QUrl(QLatin1String("qrc:/testdata/nokia-tune.mp3"))) + << QMediaPlayer::LoadingMedia + << QMediaPlayer::NoError + << 0 // error count + << false // No StreamPlayback support + << QStringLiteral("file") // backend should have a got a temporary file + << false; // backend should not have got any stream + + QTest::newRow("valid+stream") << QMediaContent(QUrl(QLatin1String("qrc:/testdata/nokia-tune.mp3"))) + << QMediaPlayer::LoadingMedia + << QMediaPlayer::NoError + << 0 // error count + << true // StreamPlayback support + << QStringLiteral("qrc") + << true; // backend should have got a stream (QFile opened from the resource) +} + +void tst_QMediaPlayer::testQrc() +{ + QFETCH(QMediaContent, mediaContent); + QFETCH(QMediaPlayer::MediaStatus, status); + QFETCH(QMediaPlayer::Error, error); + QFETCH(int, errorCount); + QFETCH(bool, hasStreamFeature); + QFETCH(QString, backendMediaContentScheme); + QFETCH(bool, backendHasStream); + + if (hasStreamFeature) + mockProvider->setSupportedFeatures(QMediaServiceProviderHint::StreamPlayback); + + QMediaPlayer player; + + mockService->setState(QMediaPlayer::PlayingState, QMediaPlayer::NoMedia); + + QSignalSpy mediaSpy(&player, SIGNAL(currentMediaChanged(QMediaContent))); + QSignalSpy statusSpy(&player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus))); + QSignalSpy errorSpy(&player, SIGNAL(error(QMediaPlayer::Error))); + + player.setMedia(mediaContent); + + QTRY_COMPARE(player.mediaStatus(), status); + QCOMPARE(statusSpy.count(), 1); + QCOMPARE(qvariant_cast<QMediaPlayer::MediaStatus>(statusSpy.last().value(0)), status); + + QCOMPARE(player.media(), mediaContent); + QCOMPARE(player.currentMedia(), mediaContent); + QCOMPARE(mediaSpy.count(), 1); + QCOMPARE(qvariant_cast<QMediaContent>(mediaSpy.last().value(0)), mediaContent); + + QCOMPARE(player.error(), error); + QCOMPARE(errorSpy.count(), errorCount); + if (errorCount > 0) { + QCOMPARE(qvariant_cast<QMediaPlayer::Error>(errorSpy.last().value(0)), error); + QVERIFY(!player.errorString().isEmpty()); + } + + // Check the media actually passed to the backend + QCOMPARE(mockService->mockControl->media().canonicalUrl().scheme(), backendMediaContentScheme); + QCOMPARE(bool(mockService->mockControl->mediaStream()), backendHasStream); +} + QTEST_GUILESS_MAIN(tst_QMediaPlayer) #include "tst_qmediaplayer.moc" diff --git a/tests/auto/unit/qmultimedia_common/mockmediaplayercontrol.h b/tests/auto/unit/qmultimedia_common/mockmediaplayercontrol.h index 5b313fb95..5127498bc 100644 --- a/tests/auto/unit/qmultimedia_common/mockmediaplayercontrol.h +++ b/tests/auto/unit/qmultimedia_common/mockmediaplayercontrol.h @@ -91,11 +91,10 @@ public: { _stream = stream; _media = content; - if (_state != QMediaPlayer::StoppedState) { - _mediaStatus = _media.isNull() ? QMediaPlayer::NoMedia : QMediaPlayer::LoadingMedia; + _mediaStatus = _media.isNull() ? QMediaPlayer::NoMedia : QMediaPlayer::LoadingMedia; + if (_state != QMediaPlayer::StoppedState) emit stateChanged(_state = QMediaPlayer::StoppedState); - emit mediaStatusChanged(_mediaStatus); - } + emit mediaStatusChanged(_mediaStatus); emit mediaChanged(_media = content); } QIODevice *mediaStream() const { return _stream; } diff --git a/tests/auto/unit/qmultimedia_common/mockmediaserviceprovider.h b/tests/auto/unit/qmultimedia_common/mockmediaserviceprovider.h index 60ea672c9..89820c557 100644 --- a/tests/auto/unit/qmultimedia_common/mockmediaserviceprovider.h +++ b/tests/auto/unit/qmultimedia_common/mockmediaserviceprovider.h @@ -61,6 +61,16 @@ public: } } + QMediaServiceProviderHint::Features supportedFeatures(const QMediaService *) const + { + return features; + } + + void setSupportedFeatures(QMediaServiceProviderHint::Features f) + { + features = f; + } + QByteArray defaultDevice(const QByteArray &serviceType) const { if (serviceType == Q_MEDIASERVICE_CAMERA) @@ -97,6 +107,7 @@ public: QMediaService *service; bool deleteServiceOnRelease; + QMediaServiceProviderHint::Features features; }; #endif // MOCKMEDIASERVICEPROVIDER_H |