summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Mira <samuel.mira@qt.io>2021-10-21 14:00:49 +0300
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-11-01 17:48:14 +0000
commit90727f89b3a5f6696e5fef21d38db19d29388e5a (patch)
tree4c65d741fdd5246f34f3b7bcaefe93447555e22d
parente8d25ce6d89aad07314a21babbd6cbab14230ad8 (diff)
downloadqtmultimedia-90727f89b3a5f6696e5fef21d38db19d29388e5a.tar.gz
Add test for multiple source
Two tests added to verify for QTBUG-96456 issue. One on unit and other on integration (tests against emu). Also fixed tst_QMediaPlayerBackend to work on android. Before it did not worked, because the test files were not copied to apk file. Change-Id: Ie6c3c1ca16092ab377ca96e122a24131dfdc2335 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> (cherry picked from commit 83502faf856ecf2cde0d79cfac80a03088732d2d) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--tests/auto/integration/qmediaplayerbackend/CMakeLists.txt11
-rw-r--r--tests/auto/integration/qmediaplayerbackend/testdata/BigBuckBunny.mp4bin0 -> 45969 bytes
-rw-r--r--tests/auto/integration/qmediaplayerbackend/testdata/busMpeg4.mp4bin0 -> 25954 bytes
-rw-r--r--tests/auto/integration/qmediaplayerbackend/tst_qmediaplayerbackend.cpp67
-rw-r--r--tests/auto/integration/shared/mediafileselector.h6
-rw-r--r--tests/auto/unit/multimedia/qmediaplayer/tst_qmediaplayer.cpp34
6 files changed, 104 insertions, 14 deletions
diff --git a/tests/auto/integration/qmediaplayerbackend/CMakeLists.txt b/tests/auto/integration/qmediaplayerbackend/CMakeLists.txt
index 0f9888b91..3848c6099 100644
--- a/tests/auto/integration/qmediaplayerbackend/CMakeLists.txt
+++ b/tests/auto/integration/qmediaplayerbackend/CMakeLists.txt
@@ -8,7 +8,7 @@
file(GLOB_RECURSE test_data_glob
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
testdata/*)
-list(APPEND test_data ${test_data_glob})
+list(APPEND testdata_resource_files ${test_data_glob})
qt_internal_add_test(tst_qmediaplayerbackend
SOURCES
@@ -17,7 +17,14 @@ qt_internal_add_test(tst_qmediaplayerbackend
PUBLIC_LIBRARIES
Qt::Gui
Qt::MultimediaPrivate
- TESTDATA ${test_data}
+ TESTDATA ${testdata_resource_files}
+)
+
+qt_internal_add_resource(tst_qmediaplayerbackend "testdata"
+ PREFIX
+ "/"
+ FILES
+ ${testdata_resource_files}
)
## Scopes:
diff --git a/tests/auto/integration/qmediaplayerbackend/testdata/BigBuckBunny.mp4 b/tests/auto/integration/qmediaplayerbackend/testdata/BigBuckBunny.mp4
new file mode 100644
index 000000000..8aa192503
--- /dev/null
+++ b/tests/auto/integration/qmediaplayerbackend/testdata/BigBuckBunny.mp4
Binary files differ
diff --git a/tests/auto/integration/qmediaplayerbackend/testdata/busMpeg4.mp4 b/tests/auto/integration/qmediaplayerbackend/testdata/busMpeg4.mp4
new file mode 100644
index 000000000..8824fe8c9
--- /dev/null
+++ b/tests/auto/integration/qmediaplayerbackend/testdata/busMpeg4.mp4
Binary files differ
diff --git a/tests/auto/integration/qmediaplayerbackend/tst_qmediaplayerbackend.cpp b/tests/auto/integration/qmediaplayerbackend/tst_qmediaplayerbackend.cpp
index 6e284afaa..28470cb1c 100644
--- a/tests/auto/integration/qmediaplayerbackend/tst_qmediaplayerbackend.cpp
+++ b/tests/auto/integration/qmediaplayerbackend/tst_qmediaplayerbackend.cpp
@@ -82,6 +82,7 @@ private slots:
void positionAfterSeek();
void videoDimensions();
void position();
+ void multipleMediaPlayback();
private:
QUrl selectVideoFile(const QStringList& mediaCandidates);
@@ -91,6 +92,7 @@ private:
QUrl localWavFile;
QUrl localWavFile2;
QUrl localVideoFile;
+ QUrl localVideoFile2;
QUrl localCompressedSoundFile;
QUrl localFileWithMetadata;
@@ -171,20 +173,26 @@ void tst_QMediaPlayerBackend::initTestCase()
if (!player.isAvailable())
QSKIP("Media player service is not available");
- localWavFile = MediaFileSelector::selectMediaFile(QStringList() << QFINDTESTDATA("testdata/test.wav"));
- localWavFile2 = MediaFileSelector::selectMediaFile(QStringList() << QFINDTESTDATA("testdata/_test.wav"));;
+ localWavFile = MediaFileSelector::selectMediaFile(QStringList() << "qrc:/testdata/test.wav");
+ localWavFile2 = MediaFileSelector::selectMediaFile(QStringList() << "qrc:/testdata/_test.wav");
QStringList mediaCandidates;
- mediaCandidates << QFINDTESTDATA("testdata/colors.mp4");
- mediaCandidates << QFINDTESTDATA("testdata/colors.ogv");
+ mediaCandidates << "qrc:/testdata/colors.mp4";
+ mediaCandidates << "qrc:/testdata/colors.ogv";
localVideoFile = MediaFileSelector::selectMediaFile(mediaCandidates);
mediaCandidates.clear();
- mediaCandidates << QFINDTESTDATA("testdata/nokia-tune.mp3");
- mediaCandidates << QFINDTESTDATA("testdata/nokia-tune.mkv");
+ mediaCandidates << "qrc:/testdata/BigBuckBunny.mp4";
+ mediaCandidates << "qrc:/testdata/busMpeg4.mp4";
+ localVideoFile2 = MediaFileSelector::selectMediaFile(mediaCandidates);
+
+ mediaCandidates.clear();
+ mediaCandidates << "qrc:/testdata/nokia-tune.mp3";
+ mediaCandidates << "qrc:/testdata/nokia-tune.mkv";
localCompressedSoundFile = MediaFileSelector::selectMediaFile(mediaCandidates);
- localFileWithMetadata = MediaFileSelector::selectMediaFile(QStringList() << QFINDTESTDATA("testdata/nokia-tune.mp3"));
+ localFileWithMetadata =
+ MediaFileSelector::selectMediaFile(QStringList() << "qrc:/testdata/nokia-tune.mp3");
qgetenv("QT_TEST_CI").toInt(&m_inCISystem,10);
}
@@ -987,6 +995,51 @@ void tst_QMediaPlayerBackend::subsequentPlayback()
QVERIFY(player.position() > 1000);
}
+void tst_QMediaPlayerBackend::multipleMediaPlayback()
+{
+ if (localVideoFile.isEmpty() || localVideoFile2.isEmpty())
+ QSKIP("Video format is not supported");
+
+ TestVideoSink surface(false);
+ QMediaPlayer player;
+ QAudioOutput output;
+
+ player.setVideoOutput(&surface);
+ player.setAudioOutput(&output);
+ player.setSource(localVideoFile);
+
+ QCOMPARE(player.source(), localVideoFile);
+ QTRY_COMPARE(player.mediaStatus(), QMediaPlayer::LoadedMedia);
+
+ player.setPosition(0);
+ player.play();
+
+ QCOMPARE(player.error(), QMediaPlayer::NoError);
+ QCOMPARE(player.playbackState(), QMediaPlayer::PlayingState);
+ QTRY_VERIFY(player.position() > 0);
+ QCOMPARE(player.source(), localVideoFile);
+
+ player.stop();
+
+ player.setSource(localVideoFile2);
+
+ QCOMPARE(player.source(), localVideoFile2);
+ QTRY_COMPARE(player.mediaStatus(), QMediaPlayer::LoadedMedia);
+ QTRY_VERIFY(player.isSeekable());
+
+ player.setPosition(0);
+ player.play();
+
+ QCOMPARE(player.error(), QMediaPlayer::NoError);
+ QCOMPARE(player.playbackState(), QMediaPlayer::PlayingState);
+ QTRY_VERIFY(player.position() > 0);
+ QCOMPARE(player.source(), localVideoFile2);
+
+ player.stop();
+
+ QTRY_COMPARE(player.playbackState(), QMediaPlayer::StoppedState);
+}
+
void tst_QMediaPlayerBackend::surfaceTest()
{
// 25 fps video file
diff --git a/tests/auto/integration/shared/mediafileselector.h b/tests/auto/integration/shared/mediafileselector.h
index 19eded56a..8a9c3e86a 100644
--- a/tests/auto/integration/shared/mediafileselector.h
+++ b/tests/auto/integration/shared/mediafileselector.h
@@ -50,11 +50,7 @@ static QUrl selectMediaFile(const QStringList& mediaCandidates)
QSignalSpy errorSpy(&player, SIGNAL(errorOccurred(QMediaPlayer::Error, const QString&)));
- for (const QString &s : mediaCandidates) {
- QFileInfo mediaFile(s);
- if (!mediaFile.exists())
- continue;
- QUrl media = QUrl::fromLocalFile(mediaFile.absoluteFilePath());
+ for (const QString &media : mediaCandidates) {
player.setSource(media);
player.play();
diff --git a/tests/auto/unit/multimedia/qmediaplayer/tst_qmediaplayer.cpp b/tests/auto/unit/multimedia/qmediaplayer/tst_qmediaplayer.cpp
index 807f95a05..bf48b7f9a 100644
--- a/tests/auto/unit/multimedia/qmediaplayer/tst_qmediaplayer.cpp
+++ b/tests/auto/unit/multimedia/qmediaplayer/tst_qmediaplayer.cpp
@@ -81,6 +81,8 @@ private slots:
void testValid();
void testMedia_data();
void testMedia();
+ void testMultipleMedia_data();
+ void testMultipleMedia();
void testDuration_data();
void testDuration();
void testPosition_data();
@@ -254,6 +256,38 @@ void tst_QMediaPlayer::testMedia()
QCOMPARE(player->sourceDevice(), &stream);
}
+void tst_QMediaPlayer::testMultipleMedia_data()
+{
+ QTest::addColumn<QUrl>("mediaContent");
+ QTest::addColumn<QUrl>("anotherMediaContent");
+
+ QTest::newRow("multipleSources")
+ << QUrl(QUrl("file:///some.mp3")) << QUrl(QUrl("file:///someother.mp3"));
+}
+
+void tst_QMediaPlayer::testMultipleMedia()
+{
+ QFETCH(QUrl, mediaContent);
+
+ player->setSource(mediaContent);
+ QCOMPARE(player->source(), mediaContent);
+
+ QBuffer stream;
+ player->setSourceDevice(&stream, mediaContent);
+ QCOMPARE(player->source(), mediaContent);
+ QCOMPARE(player->sourceDevice(), &stream);
+
+ QFETCH(QUrl, anotherMediaContent);
+
+ player->setSource(anotherMediaContent);
+ QCOMPARE(player->source(), anotherMediaContent);
+
+ QBuffer anotherStream;
+ player->setSourceDevice(&anotherStream, anotherMediaContent);
+ QCOMPARE(player->source(), anotherMediaContent);
+ QCOMPARE(player->sourceDevice(), &anotherStream);
+}
+
void tst_QMediaPlayer::testDuration_data()
{
setupCommonTestData();