summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoris Verria <doris.verria@qt.io>2021-06-13 17:01:05 +0200
committerDoris Verria <doris.verria@qt.io>2021-06-14 12:54:32 +0200
commitc4e782df9dc88ab531dad47a44bc48058e7e628c (patch)
tree161f9daf3005b0a45ca2b5c03b7265610556931c
parente56807775e48c69feba3c71cd2631da8e26e5fa2 (diff)
Add test case for invalid source file/device to audiodecoder test
Check that the appropriate errors are set on the decoder when media sources can not be resolved. Change-Id: Ie9bcc1298bf561a4ee4a90e4d6d74869541a1c6e Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r--tests/auto/integration/qaudiodecoderbackend/tst_qaudiodecoderbackend.cpp94
1 files changed, 94 insertions, 0 deletions
diff --git a/tests/auto/integration/qaudiodecoderbackend/tst_qaudiodecoderbackend.cpp b/tests/auto/integration/qaudiodecoderbackend/tst_qaudiodecoderbackend.cpp
index b3ccb0a10..885aa34e0 100644
--- a/tests/auto/integration/qaudiodecoderbackend/tst_qaudiodecoderbackend.cpp
+++ b/tests/auto/integration/qaudiodecoderbackend/tst_qaudiodecoderbackend.cpp
@@ -35,6 +35,7 @@
#define TEST_FILE_NAME "testdata/test.wav"
#define TEST_UNSUPPORTED_FILE_NAME "testdata/test-unsupported.avi"
#define TEST_CORRUPTED_FILE_NAME "testdata/test-corrupted.wav"
+#define TEST_INVALID_SOURCE "invalid"
QT_USE_NAMESPACE
@@ -57,6 +58,7 @@ private slots:
void fileTest();
void unsupportedFileTest();
void corruptedFileTest();
+ void invalidSource();
void deviceTest();
private:
@@ -425,6 +427,98 @@ void tst_QAudioDecoderBackend::corruptedFileTest()
QVERIFY(!d.bufferAvailable());
}
+void tst_QAudioDecoderBackend::invalidSource()
+{
+ QAudioDecoder d;
+ if (d.error() == QAudioDecoder::NotSupportedError)
+ QSKIP("There is no audio decoding support on this platform.");
+ QAudioBuffer buffer;
+
+ QVERIFY(d.state() == QAudioDecoder::StoppedState);
+ QVERIFY(d.bufferAvailable() == false);
+ QCOMPARE(d.source(), QUrl());
+ QVERIFY(d.audioFormat() == QAudioFormat());
+
+ // Test invalid file source
+ QFileInfo fileInfo(TEST_INVALID_SOURCE);
+ QUrl url = QUrl::fromLocalFile(fileInfo.absoluteFilePath());
+ d.setSource(url);
+ QVERIFY(d.state() == QAudioDecoder::StoppedState);
+ QVERIFY(!d.bufferAvailable());
+ QCOMPARE(d.source(), url);
+
+ QSignalSpy readySpy(&d, SIGNAL(bufferReady()));
+ QSignalSpy bufferChangedSpy(&d, SIGNAL(bufferAvailableChanged(bool)));
+ QSignalSpy errorSpy(&d, SIGNAL(error(QAudioDecoder::Error)));
+ QSignalSpy stateSpy(&d, SIGNAL(stateChanged(QAudioDecoder::State)));
+ QSignalSpy durationSpy(&d, SIGNAL(durationChanged(qint64)));
+ QSignalSpy finishedSpy(&d, SIGNAL(finished()));
+ QSignalSpy positionSpy(&d, SIGNAL(positionChanged(qint64)));
+
+ d.start();
+ QTRY_VERIFY(d.state() == QAudioDecoder::StoppedState);
+ QVERIFY(!d.bufferAvailable());
+ QCOMPARE(d.audioFormat(), QAudioFormat());
+ QCOMPARE(d.duration(), qint64(-1));
+ QCOMPARE(d.position(), qint64(-1));
+
+ // Check the error code.
+ QTRY_VERIFY(!errorSpy.isEmpty());
+
+ // Have to use qvariant_cast, toInt will return 0 because unrecognized type;
+ QAudioDecoder::Error errorCode = qvariant_cast<QAudioDecoder::Error>(errorSpy.takeLast().at(0));
+ QCOMPARE(errorCode, QAudioDecoder::ResourceError);
+ QCOMPARE(d.error(), QAudioDecoder::ResourceError);
+
+ // Check all other spies.
+ QVERIFY(readySpy.isEmpty());
+ QVERIFY(bufferChangedSpy.isEmpty());
+ QVERIFY(stateSpy.isEmpty());
+ QVERIFY(finishedSpy.isEmpty());
+ QVERIFY(positionSpy.isEmpty());
+ QVERIFY(durationSpy.isEmpty());
+
+ errorSpy.clear();
+
+ d.stop();
+ QTRY_COMPARE(d.state(), QAudioDecoder::StoppedState);
+ QCOMPARE(d.duration(), qint64(-1));
+ QVERIFY(!d.bufferAvailable());
+
+ QFile file;
+ file.setFileName(TEST_INVALID_SOURCE);
+ file.open(QIODevice::ReadOnly);
+ d.setSourceDevice(&file);
+
+ d.start();
+ QTRY_VERIFY(d.state() == QAudioDecoder::StoppedState);
+ QVERIFY(!d.bufferAvailable());
+ QCOMPARE(d.audioFormat(), QAudioFormat());
+ QCOMPARE(d.duration(), qint64(-1));
+ QCOMPARE(d.position(), qint64(-1));
+
+ // Check the error code.
+ QTRY_VERIFY(!errorSpy.isEmpty());
+ errorCode = qvariant_cast<QAudioDecoder::Error>(errorSpy.takeLast().at(0));
+ QCOMPARE(errorCode, QAudioDecoder::AccessDeniedError);
+ QCOMPARE(d.error(), QAudioDecoder::AccessDeniedError);
+
+ // Check all other spies.
+ QVERIFY(readySpy.isEmpty());
+ QVERIFY(bufferChangedSpy.isEmpty());
+ QVERIFY(stateSpy.isEmpty());
+ QVERIFY(finishedSpy.isEmpty());
+ QVERIFY(positionSpy.isEmpty());
+ QVERIFY(durationSpy.isEmpty());
+
+ errorSpy.clear();
+
+ d.stop();
+ QTRY_COMPARE(d.state(), QAudioDecoder::StoppedState);
+ QCOMPARE(d.duration(), qint64(-1));
+ QVERIFY(!d.bufferAvailable());
+}
+
void tst_QAudioDecoderBackend::deviceTest()
{
if (!isWavSupported())