summaryrefslogtreecommitdiffstats
path: root/tests/auto/unit/qmediaplayer/tst_qmediaplayer.cpp
diff options
context:
space:
mode:
authorYoann Lopes <yoann.lopes@theqtcompany.com>2015-02-18 16:58:02 +0100
committerFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2015-04-07 17:21:47 +0000
commit63cff37741dca71f3db45ee06bc5bb06488c51f4 (patch)
tree4feeb36d8f95a24b5dc5dc12c99f471f824de38b /tests/auto/unit/qmediaplayer/tst_qmediaplayer.cpp
parent4d17db19f895ddaa778120c346d8a6a33a710194 (diff)
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/auto/unit/qmediaplayer/tst_qmediaplayer.cpp')
-rw-r--r--tests/auto/unit/qmediaplayer/tst_qmediaplayer.cpp90
1 files changed, 88 insertions, 2 deletions
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"