summaryrefslogtreecommitdiffstats
path: root/tests/auto/integration/qaudiodecoderbackend/tst_qaudiodecoderbackend.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/integration/qaudiodecoderbackend/tst_qaudiodecoderbackend.cpp')
-rw-r--r--tests/auto/integration/qaudiodecoderbackend/tst_qaudiodecoderbackend.cpp221
1 files changed, 39 insertions, 182 deletions
diff --git a/tests/auto/integration/qaudiodecoderbackend/tst_qaudiodecoderbackend.cpp b/tests/auto/integration/qaudiodecoderbackend/tst_qaudiodecoderbackend.cpp
index 8a948e905..5e32efa16 100644
--- a/tests/auto/integration/qaudiodecoderbackend/tst_qaudiodecoderbackend.cpp
+++ b/tests/auto/integration/qaudiodecoderbackend/tst_qaudiodecoderbackend.cpp
@@ -72,7 +72,7 @@ void tst_QAudioDecoderBackend::init()
void tst_QAudioDecoderBackend::initTestCase()
{
QAudioDecoder d;
- if (!d.isAvailable())
+ if (!d.isSupported())
QSKIP("Audio decoder service is not available");
}
@@ -102,30 +102,29 @@ void tst_QAudioDecoderBackend::fileTest()
int byteCount = 0;
int sampleCount = 0;
- QVERIFY(d.state() == QAudioDecoder::StoppedState);
+ QVERIFY(!d.isDecoding());
QVERIFY(d.bufferAvailable() == false);
QCOMPARE(d.source(), QString(""));
- QVERIFY(d.audioFormat() == QAudioFormat());
// Test local file
QFileInfo fileInfo(QFINDTESTDATA(TEST_FILE_NAME));
QUrl url = QUrl::fromLocalFile(fileInfo.absoluteFilePath());
d.setSource(url);
- QVERIFY(d.state() == QAudioDecoder::StoppedState);
+ QVERIFY(!d.isDecoding());
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 isDecodingSpy(&d, SIGNAL(isDecodingChanged(bool)));
QSignalSpy durationSpy(&d, SIGNAL(durationChanged(qint64)));
QSignalSpy finishedSpy(&d, SIGNAL(finished()));
QSignalSpy positionSpy(&d, SIGNAL(positionChanged(qint64)));
d.start();
- QTRY_VERIFY(d.state() == QAudioDecoder::DecodingState);
- QTRY_VERIFY(!stateSpy.isEmpty());
+ QTRY_VERIFY(d.isDecoding());
+ QTRY_VERIFY(!isDecodingSpy.isEmpty());
QTRY_VERIFY(!readySpy.isEmpty());
QTRY_VERIFY(!bufferChangedSpy.isEmpty());
QVERIFY(d.bufferAvailable());
@@ -141,11 +140,6 @@ void tst_QAudioDecoderBackend::fileTest()
QCOMPARE(buffer.format().sampleFormat(), QAudioFormat::Int16);
QCOMPARE(buffer.byteCount(), buffer.sampleCount() * 2); // 16bit mono
- // This does not make a lot of sense
- // The decoder's audioFormat() should report the actual buffer format?
- // // The decoder should still have no format set
- // QVERIFY(d.audioFormat() == QAudioFormat());
-
QVERIFY(errorSpy.isEmpty());
duration += buffer.duration();
@@ -179,94 +173,10 @@ void tst_QAudioDecoderBackend::fileTest()
QVERIFY(qAbs((d.position() + (buffer.duration() / 1000)) - 1000) < 20);
QTRY_COMPARE(finishedSpy.count(), 1);
QVERIFY(!d.bufferAvailable());
- QTRY_COMPARE(d.state(), QAudioDecoder::StoppedState);
-
- d.stop();
- QTRY_COMPARE(d.state(), QAudioDecoder::StoppedState);
- QTRY_COMPARE(durationSpy.count(), 2);
- QCOMPARE(d.duration(), qint64(-1));
- QVERIFY(!d.bufferAvailable());
- readySpy.clear();
- bufferChangedSpy.clear();
- stateSpy.clear();
- durationSpy.clear();
- finishedSpy.clear();
- positionSpy.clear();
-
- // change output audio format
- QAudioFormat format;
- format.setChannelCount(2);
- format.setSampleRate(11050);
- format.setSampleFormat(QAudioFormat::UInt8);
-
- d.setAudioFormat(format);
-
- // We expect 1 second still, at 11050 * 2 samples == 22k samples.
- // (at 1 byte/sample -> 22kb)
-
- // Make sure it stuck
- QVERIFY(d.audioFormat() == format);
-
- duration = 0;
- sampleCount = 0;
- byteCount = 0;
-
- d.start();
- QTRY_VERIFY(d.state() == QAudioDecoder::DecodingState);
- QTRY_VERIFY(!stateSpy.isEmpty());
- QTRY_VERIFY(!readySpy.isEmpty());
- QTRY_VERIFY(!bufferChangedSpy.isEmpty());
- QVERIFY(d.bufferAvailable());
- QTRY_VERIFY(!durationSpy.isEmpty());
- QVERIFY(qAbs(d.duration() - 1000) < 20);
-
- buffer = d.read();
- QVERIFY(buffer.isValid());
- // See if we got the right format
- QVERIFY(buffer.format() == format);
-
- // The decoder should still have the same format
- QVERIFY(d.audioFormat() == format);
-
- QVERIFY(errorSpy.isEmpty());
-
- duration += buffer.duration();
- sampleCount += buffer.sampleCount();
- byteCount += buffer.byteCount();
-
- // Now drain the decoder
- if (duration < 998000) {
- QTRY_COMPARE(d.bufferAvailable(), true);
- }
-
- while (d.bufferAvailable()) {
- buffer = d.read();
- QVERIFY(buffer.isValid());
- QTRY_VERIFY(!positionSpy.isEmpty());
- QVERIFY(positionSpy.takeLast().at(0).toLongLong() == qint64(duration / 1000));
- QVERIFY(d.position() - (duration / 1000) < 20);
-
- duration += buffer.duration();
- sampleCount += buffer.sampleCount();
- byteCount += buffer.byteCount();
-
- if (duration < 998000) {
- QTRY_COMPARE(d.bufferAvailable(), true);
- }
- }
-
- // Resampling might end up with fewer or more samples
- // so be a bit sloppy
- QVERIFY(qAbs(sampleCount - 22047) < 100);
- QVERIFY(qAbs(byteCount - 22047) < 100);
- QVERIFY(qAbs(qint64(duration) - 1000000) < 20000);
- QVERIFY(qAbs((d.position() + (buffer.duration() / 1000)) - 1000) < 20);
- QTRY_COMPARE(finishedSpy.count(), 1);
- QVERIFY(!d.bufferAvailable());
- QTRY_COMPARE(d.state(), QAudioDecoder::StoppedState);
+ QTRY_VERIFY(!d.isDecoding());
d.stop();
- QTRY_COMPARE(d.state(), QAudioDecoder::StoppedState);
+ QTRY_VERIFY(!d.isDecoding());
QTRY_COMPARE(durationSpy.count(), 2);
QCOMPARE(d.duration(), qint64(-1));
QVERIFY(!d.bufferAvailable());
@@ -282,31 +192,29 @@ void tst_QAudioDecoderBackend::unsupportedFileTest()
QSKIP("There is no audio decoding support on this platform.");
QAudioBuffer buffer;
- QVERIFY(d.state() == QAudioDecoder::StoppedState);
+ QVERIFY(!d.isDecoding());
QVERIFY(d.bufferAvailable() == false);
QCOMPARE(d.source(), QString(""));
- QVERIFY(d.audioFormat() == QAudioFormat());
// Test local file
QFileInfo fileInfo(QFINDTESTDATA(TEST_UNSUPPORTED_FILE_NAME));
QUrl url = QUrl::fromLocalFile(fileInfo.absoluteFilePath());
d.setSource(url);
- QVERIFY(d.state() == QAudioDecoder::StoppedState);
+ QVERIFY(!d.isDecoding());
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 isDecodingSpy(&d, SIGNAL(isDecodingChanged(bool)));
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);
+ QTRY_VERIFY(!d.isDecoding());
QVERIFY(!d.bufferAvailable());
- QCOMPARE(d.audioFormat(), QAudioFormat());
QCOMPARE(d.duration(), qint64(-1));
QCOMPARE(d.position(), qint64(-1));
@@ -321,7 +229,7 @@ void tst_QAudioDecoderBackend::unsupportedFileTest()
// Check all other spies.
QVERIFY(readySpy.isEmpty());
QVERIFY(bufferChangedSpy.isEmpty());
- QVERIFY(stateSpy.isEmpty());
+ QVERIFY(isDecodingSpy.isEmpty());
QVERIFY(finishedSpy.isEmpty());
QVERIFY(positionSpy.isEmpty());
QVERIFY(durationSpy.isEmpty());
@@ -330,7 +238,7 @@ void tst_QAudioDecoderBackend::unsupportedFileTest()
// Try read even if the file is not supported to test robustness.
buffer = d.read();
- QTRY_VERIFY(d.state() == QAudioDecoder::StoppedState);
+ QTRY_VERIFY(!d.isDecoding());
QVERIFY(!buffer.isValid());
QVERIFY(!d.bufferAvailable());
QCOMPARE(d.position(), qint64(-1));
@@ -338,14 +246,14 @@ void tst_QAudioDecoderBackend::unsupportedFileTest()
QVERIFY(errorSpy.isEmpty());
QVERIFY(readySpy.isEmpty());
QVERIFY(bufferChangedSpy.isEmpty());
- QVERIFY(stateSpy.isEmpty());
+ QVERIFY(isDecodingSpy.isEmpty());
QVERIFY(finishedSpy.isEmpty());
QVERIFY(positionSpy.isEmpty());
QVERIFY(durationSpy.isEmpty());
d.stop();
- QTRY_COMPARE(d.state(), QAudioDecoder::StoppedState);
+ QTRY_VERIFY(!d.isDecoding());
QCOMPARE(d.duration(), qint64(-1));
QVERIFY(!d.bufferAvailable());
}
@@ -361,31 +269,29 @@ void tst_QAudioDecoderBackend::corruptedFileTest()
QSKIP("There is no audio decoding support on this platform.");
QAudioBuffer buffer;
- QVERIFY(d.state() == QAudioDecoder::StoppedState);
+ QVERIFY(!d.isDecoding());
QVERIFY(d.bufferAvailable() == false);
QCOMPARE(d.source(), QUrl());
- QVERIFY(d.audioFormat() == QAudioFormat());
// Test local file
QFileInfo fileInfo(QFINDTESTDATA(TEST_CORRUPTED_FILE_NAME));
QUrl url = QUrl::fromLocalFile(fileInfo.absoluteFilePath());
d.setSource(url);
- QVERIFY(d.state() == QAudioDecoder::StoppedState);
+ QVERIFY(!d.isDecoding());
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 isDecodingSpy(&d, SIGNAL(isDecodingChanged(bool)));
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);
+ QTRY_VERIFY(!d.isDecoding());
QVERIFY(!d.bufferAvailable());
- QCOMPARE(d.audioFormat(), QAudioFormat());
QCOMPARE(d.duration(), qint64(-1));
QCOMPARE(d.position(), qint64(-1));
@@ -400,7 +306,7 @@ void tst_QAudioDecoderBackend::corruptedFileTest()
// Check all other spies.
QVERIFY(readySpy.isEmpty());
QVERIFY(bufferChangedSpy.isEmpty());
- QVERIFY(stateSpy.isEmpty());
+ QVERIFY(isDecodingSpy.isEmpty());
QVERIFY(finishedSpy.isEmpty());
QVERIFY(positionSpy.isEmpty());
QVERIFY(durationSpy.isEmpty());
@@ -409,7 +315,7 @@ void tst_QAudioDecoderBackend::corruptedFileTest()
// Try read even if the file is corrupted to test the robustness.
buffer = d.read();
- QTRY_VERIFY(d.state() == QAudioDecoder::StoppedState);
+ QTRY_VERIFY(!d.isDecoding());
QVERIFY(!buffer.isValid());
QVERIFY(!d.bufferAvailable());
QCOMPARE(d.position(), qint64(-1));
@@ -417,14 +323,14 @@ void tst_QAudioDecoderBackend::corruptedFileTest()
QVERIFY(errorSpy.isEmpty());
QVERIFY(readySpy.isEmpty());
QVERIFY(bufferChangedSpy.isEmpty());
- QVERIFY(stateSpy.isEmpty());
+ QVERIFY(isDecodingSpy.isEmpty());
QVERIFY(finishedSpy.isEmpty());
QVERIFY(positionSpy.isEmpty());
QVERIFY(durationSpy.isEmpty());
d.stop();
- QTRY_COMPARE(d.state(), QAudioDecoder::StoppedState);
+ QTRY_VERIFY(!d.isDecoding());
QCOMPARE(d.duration(), qint64(-1));
QVERIFY(!d.bufferAvailable());
}
@@ -436,31 +342,29 @@ void tst_QAudioDecoderBackend::invalidSource()
QSKIP("There is no audio decoding support on this platform.");
QAudioBuffer buffer;
- QVERIFY(d.state() == QAudioDecoder::StoppedState);
+ QVERIFY(!d.isDecoding());
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.isDecoding());
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 isDecodingSpy(&d, SIGNAL(isDecodingChanged(bool)));
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);
+ QTRY_VERIFY(!d.isDecoding());
QVERIFY(!d.bufferAvailable());
- QCOMPARE(d.audioFormat(), QAudioFormat());
QCOMPARE(d.duration(), qint64(-1));
QCOMPARE(d.position(), qint64(-1));
@@ -475,7 +379,7 @@ void tst_QAudioDecoderBackend::invalidSource()
// Check all other spies.
QVERIFY(readySpy.isEmpty());
QVERIFY(bufferChangedSpy.isEmpty());
- QVERIFY(stateSpy.isEmpty());
+ QVERIFY(isDecodingSpy.isEmpty());
QVERIFY(finishedSpy.isEmpty());
QVERIFY(positionSpy.isEmpty());
QVERIFY(durationSpy.isEmpty());
@@ -483,7 +387,7 @@ void tst_QAudioDecoderBackend::invalidSource()
errorSpy.clear();
d.stop();
- QTRY_COMPARE(d.state(), QAudioDecoder::StoppedState);
+ QTRY_VERIFY(!d.isDecoding());
QCOMPARE(d.duration(), qint64(-1));
QVERIFY(!d.bufferAvailable());
@@ -493,9 +397,8 @@ void tst_QAudioDecoderBackend::invalidSource()
d.setSourceDevice(&file);
d.start();
- QTRY_VERIFY(d.state() == QAudioDecoder::StoppedState);
+ QTRY_VERIFY(!d.isDecoding());
QVERIFY(!d.bufferAvailable());
- QCOMPARE(d.audioFormat(), QAudioFormat());
QCOMPARE(d.duration(), qint64(-1));
QCOMPARE(d.position(), qint64(-1));
@@ -508,7 +411,7 @@ void tst_QAudioDecoderBackend::invalidSource()
// Check all other spies.
QVERIFY(readySpy.isEmpty());
QVERIFY(bufferChangedSpy.isEmpty());
- QVERIFY(stateSpy.isEmpty());
+ QVERIFY(isDecodingSpy.isEmpty());
QVERIFY(finishedSpy.isEmpty());
QVERIFY(positionSpy.isEmpty());
QVERIFY(durationSpy.isEmpty());
@@ -516,7 +419,7 @@ void tst_QAudioDecoderBackend::invalidSource()
errorSpy.clear();
d.stop();
- QTRY_COMPARE(d.state(), QAudioDecoder::StoppedState);
+ QTRY_VERIFY(!d.isDecoding());
QCOMPARE(d.duration(), qint64(-1));
QVERIFY(!d.bufferAvailable());
}
@@ -536,15 +439,14 @@ void tst_QAudioDecoderBackend::deviceTest()
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 isDecodingSpy(&d, SIGNAL(isDecodingChanged(bool)));
QSignalSpy durationSpy(&d, SIGNAL(durationChanged(qint64)));
QSignalSpy finishedSpy(&d, SIGNAL(finished()));
QSignalSpy positionSpy(&d, SIGNAL(positionChanged(qint64)));
- QVERIFY(d.state() == QAudioDecoder::StoppedState);
+ QVERIFY(!d.isDecoding());
QVERIFY(d.bufferAvailable() == false);
QCOMPARE(d.source(), QString(""));
- QVERIFY(d.audioFormat() == QAudioFormat());
QFileInfo fileInfo(QFINDTESTDATA(TEST_FILE_NAME));
QFile file(fileInfo.absoluteFilePath());
@@ -554,13 +456,10 @@ void tst_QAudioDecoderBackend::deviceTest()
QVERIFY(d.sourceDevice() == &file);
QVERIFY(d.source().isEmpty());
- // We haven't set the format yet
- QVERIFY(d.audioFormat() == QAudioFormat());
-
d.start();
- QTRY_VERIFY(d.state() == QAudioDecoder::DecodingState);
- QTRY_VERIFY(!stateSpy.isEmpty());
+ QTRY_VERIFY(d.isDecoding());
+ QTRY_VERIFY(!isDecodingSpy.isEmpty());
QTRY_VERIFY(!readySpy.isEmpty());
QTRY_VERIFY(!bufferChangedSpy.isEmpty());
QVERIFY(d.bufferAvailable());
@@ -605,52 +504,10 @@ void tst_QAudioDecoderBackend::deviceTest()
QVERIFY(qAbs((d.position() + (buffer.duration() / 1000)) - 1000) < 20);
QTRY_COMPARE(finishedSpy.count(), 1);
QVERIFY(!d.bufferAvailable());
- QTRY_COMPARE(d.state(), QAudioDecoder::StoppedState);
-
- d.stop();
- QTRY_COMPARE(d.state(), QAudioDecoder::StoppedState);
- QVERIFY(!d.bufferAvailable());
- QTRY_COMPARE(durationSpy.count(), 2);
- QCOMPARE(d.duration(), qint64(-1));
- readySpy.clear();
- bufferChangedSpy.clear();
- stateSpy.clear();
- durationSpy.clear();
- finishedSpy.clear();
- positionSpy.clear();
-
- // Now try changing formats
- QAudioFormat format;
- format.setChannelCount(2);
- format.setSampleRate(8000);
- format.setSampleFormat(QAudioFormat::UInt8);
-
- d.setAudioFormat(format);
-
- // Make sure it stuck
- QVERIFY(d.audioFormat() == format);
-
- d.start();
- QTRY_VERIFY(d.state() == QAudioDecoder::DecodingState);
- QTRY_VERIFY(!stateSpy.isEmpty());
- QTRY_VERIFY(!readySpy.isEmpty());
- QTRY_VERIFY(!bufferChangedSpy.isEmpty());
- QVERIFY(d.bufferAvailable());
- QTRY_VERIFY(!durationSpy.isEmpty());
- QVERIFY(qAbs(d.duration() - 1000) < 20);
-
- buffer = d.read();
- QVERIFY(buffer.isValid());
- // See if we got the right format
- QVERIFY(buffer.format() == format);
-
- // The decoder should still have the same format
- QVERIFY(d.audioFormat() == format);
-
- QVERIFY(errorSpy.isEmpty());
+ QTRY_VERIFY(!d.isDecoding());
d.stop();
- QTRY_COMPARE(d.state(), QAudioDecoder::StoppedState);
+ QTRY_VERIFY(!d.isDecoding());
QVERIFY(!d.bufferAvailable());
QTRY_COMPARE(durationSpy.count(), 2);
QCOMPARE(d.duration(), qint64(-1));