diff options
author | Kurt Korbatits <kurt.korbatits@nokia.com> | 2009-09-28 01:17:45 (GMT) |
---|---|---|
committer | Kurt Korbatits <kurt.korbatits@nokia.com> | 2009-09-28 01:17:45 (GMT) |
commit | 2f132101fbc1b9f988e1cd3baf79408d54a69a14 (patch) | |
tree | 5e2864e46fbfabafea1533c68aff884bf8b9c91c | |
parent | 310b993657988220ce45dfd7dbab2ccac34c00e9 (diff) | |
download | Qt-2f132101fbc1b9f988e1cd3baf79408d54a69a14.zip Qt-2f132101fbc1b9f988e1cd3baf79408d54a69a14.tar.gz Qt-2f132101fbc1b9f988e1cd3baf79408d54a69a14.tar.bz2 |
Improved audio unit tests
Added more checking in each step of the playback or recording tests.
Reviewed-by:Justin McPherson
-rw-r--r-- | tests/auto/qaudioinput/tst_qaudioinput.cpp | 34 | ||||
-rw-r--r-- | tests/auto/qaudiooutput/tst_qaudiooutput.cpp | 34 |
2 files changed, 66 insertions, 2 deletions
diff --git a/tests/auto/qaudioinput/tst_qaudioinput.cpp b/tests/auto/qaudioinput/tst_qaudioinput.cpp index 7331072..69b507d 100644 --- a/tests/auto/qaudioinput/tst_qaudioinput.cpp +++ b/tests/auto/qaudioinput/tst_qaudioinput.cpp @@ -56,6 +56,7 @@ public: private slots: void initTestCase(); void settings(); + void buffers(); void notifyInterval(); void pullFile(); @@ -90,6 +91,7 @@ void tst_QAudioInput::initTestCase() void tst_QAudioInput::settings() { if(available) { + // Confirm the setting we added in the init function. QAudioFormat f = audio->format(); QVERIFY(format.channels() == f.channels()); @@ -101,6 +103,18 @@ void tst_QAudioInput::settings() } } +void tst_QAudioInput::buffers() +{ + if(available) { + // Should always have a buffer size greater than zero. + int store = audio->bufferSize(); + audio->setBufferSize(4096); + QVERIFY(audio->bufferSize() > 0); + audio->setBufferSize(store); + QVERIFY(audio->bufferSize() == store); + } +} + void tst_QAudioInput::notifyInterval() { if(available) { @@ -120,14 +134,32 @@ void tst_QAudioInput::pullFile() filename.open( QIODevice::WriteOnly | QIODevice::Truncate ); QSignalSpy readSignal(audio, SIGNAL(notify())); - audio->start(&filename); + QSignalSpy stateSignal(audio, SIGNAL(stateChanged(QAudio::State))); + + // Always have default states, before start + QVERIFY(audio->state() == QAudio::StopState); + QVERIFY(audio->error() == QAudio::NoError); + audio->start(&filename); + QTest::qWait(20); + // Check state and periodSize() are valid non-zero values. + QVERIFY(audio->state() == QAudio::ActiveState); + QVERIFY(audio->error() == QAudio::NoError); + QVERIFY(audio->periodSize() > 0); + QVERIFY(stateSignal.count() == 1); // State changed to QAudio::ActiveState + + // Wait until finished... QTest::qWait(5000); QVERIFY(readSignal.count() > 0); QVERIFY(audio->totalTime() > 0); audio->stop(); + QTest::qWait(20); + QVERIFY(audio->state() == QAudio::StopState); + // Can only check to make sure we got at least 1 more signal, but can be more. + QVERIFY(stateSignal.count() > 1); + filename.close(); } } diff --git a/tests/auto/qaudiooutput/tst_qaudiooutput.cpp b/tests/auto/qaudiooutput/tst_qaudiooutput.cpp index b45a57e..f1c75dc 100644 --- a/tests/auto/qaudiooutput/tst_qaudiooutput.cpp +++ b/tests/auto/qaudiooutput/tst_qaudiooutput.cpp @@ -58,6 +58,7 @@ public: private slots: void initTestCase(); void settings(); + void buffers(); void notifyInterval(); void pullFile(); void pushFile(); @@ -91,6 +92,7 @@ void tst_QAudioOutput::initTestCase() void tst_QAudioOutput::settings() { if(available) { + // Confirm the setting we added in the init function. QAudioFormat f = audio->format(); QVERIFY(format.channels() == f.channels()); @@ -102,6 +104,18 @@ void tst_QAudioOutput::settings() } } +void tst_QAudioOutput::buffers() +{ + if(available) { + // Should always have a buffer size greater than zero. + int store = audio->bufferSize(); + audio->setBufferSize(4096); + QVERIFY(audio->bufferSize() > 0); + audio->setBufferSize(store); + QVERIFY(audio->bufferSize() == store); + } +} + void tst_QAudioOutput::notifyInterval() { if(available) { @@ -122,15 +136,33 @@ void tst_QAudioOutput::pullFile() file.open(QIODevice::ReadOnly); QSignalSpy readSignal(audio, SIGNAL(notify())); + QSignalSpy stateSignal(audio, SIGNAL(stateChanged(QAudio::State))); audio->setNotifyInterval(100); - audio->start(&file); + // Always have default states, before start + QVERIFY(audio->state() == QAudio::StopState); + QVERIFY(audio->error() == QAudio::NoError); + + audio->start(&file); + QTest::qWait(20); // wait 20ms + // Check state, bytesFree() and periodSize() are valid non-zero values. + QVERIFY(audio->state() == QAudio::ActiveState); + QVERIFY(audio->error() == QAudio::NoError); + QVERIFY(audio->periodSize() > 0); + QVERIFY(stateSignal.count() == 1); // State changed to QAudio::ActiveState + + // Wait until finished... QTestEventLoop::instance().enterLoop(1); QCOMPARE(audio->totalTime(), qint64(692250)); // 4.wav is a little less than 700ms, so notify should fire 6 times! QVERIFY(readSignal.count() >= 6); audio->stop(); + QTest::qWait(20); // wait 20ms + QVERIFY(audio->state() == QAudio::StopState); + // Can only check to make sure we got at least 1 more signal, but can be more. + QVERIFY(stateSignal.count() > 1); + file.close(); } } |