diff options
author | Michael Goddard <michael.goddard@nokia.com> | 2011-07-25 15:02:51 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-07-26 06:45:46 +0200 |
commit | a6128410da0fc11b2ce7d3ecb8d5f75a011897ef (patch) | |
tree | 7df32e185f68115f967d94540c6e9389c9669b66 /tests/auto/qaudioinput | |
parent | 1e4dda971098656dad390478601ee932e9c4e3e3 (diff) |
API unit tests from Maemo API test team.
A large number of tweaks and changes to original tests, and refactor
a lot of the mock backends to reduce duplication.
Changed viewfinder test case to use mock service and provider so
that it matches the image capture test case.
Reviewed-by: Jonas Rabbe
(cherry picked from commit e40bef5508a4165cec4a46b97115aed461027fa5)
Also licence header fix:
(cherry picked from commit e9ee9e8c48b45b97d62ee4a82e400fa9d8ea8107)
Change-Id: Ic59891d75563bb2e008a336eea859e8c44d8d831
Reviewed-on: http://codereview.qt.nokia.com/2078
Reviewed-by: Jonas Rabbe <jonas.rabbe@nokia.com>
Diffstat (limited to 'tests/auto/qaudioinput')
-rwxr-xr-x | tests/auto/qaudioinput/tst_qaudioinput.cpp | 86 |
1 files changed, 64 insertions, 22 deletions
diff --git a/tests/auto/qaudioinput/tst_qaudioinput.cpp b/tests/auto/qaudioinput/tst_qaudioinput.cpp index 9ab2512ca..4b6bb662c 100755 --- a/tests/auto/qaudioinput/tst_qaudioinput.cpp +++ b/tests/auto/qaudioinput/tst_qaudioinput.cpp @@ -199,7 +199,7 @@ void tst_QAudioInput::initTestCase() QVERIFY(testFormats.size()); - foreach (format, testFormats) { + foreach (const QAudioFormat &format, testFormats) { QFile* file = new QFile(workingDir() + formatToFileName(format) + QString(".wav")); audioFiles.append(file); } @@ -265,6 +265,7 @@ void tst_QAudioInput::invalidFormat() QVERIFY2((audioInput.error() == QAudio::NoError), "error() was not set to QAudio::NoError before start()"); audioInput.start(); + // Check that error is raised QTRY_VERIFY2((audioInput.error() == QAudio::OpenError),"error() was not set to QAudio::OpenError after start()"); } @@ -435,6 +436,7 @@ void tst_QAudioInput::pull() QVERIFY(wavHeader.write(*audioFiles.at(i))); audioInput.start(audioFiles.at(i)); + // Check that QAudioInput immediately transitions to ActiveState or IdleState QTRY_VERIFY2((stateSignal.count() > 0),"didn't emit signals on start()"); QVERIFY2((audioInput.state() == QAudio::ActiveState || audioInput.state() == QAudio::IdleState), @@ -493,6 +495,7 @@ void tst_QAudioInput::pullSuspendResume() QVERIFY(wavHeader.write(*audioFiles.at(i))); audioInput.start(audioFiles.at(i)); + // Check that QAudioInput immediately transitions to ActiveState or IdleState QTRY_VERIFY2((stateSignal.count() > 0),"didn't emit signals on start()"); QVERIFY2((audioInput.state() == QAudio::ActiveState || audioInput.state() == QAudio::IdleState), @@ -766,32 +769,71 @@ void tst_QAudioInput::pushSuspendResume() void tst_QAudioInput::reset() { for(int i=0; i<audioFiles.count(); i++) { - QAudioInput audioInput(testFormats.at(i), this); - audioInput.setNotifyInterval(100); + // Try both push/pull.. the vagaries of Active vs Idle are tested elsewhere + { + QAudioInput audioInput(testFormats.at(i), this); - QSignalSpy notifySignal(&audioInput, SIGNAL(notify())); - QSignalSpy stateSignal(&audioInput, SIGNAL(stateChanged(QAudio::State))); + audioInput.setNotifyInterval(100); - // Check that we are in the default state before calling start - QVERIFY2((audioInput.state() == QAudio::StoppedState), "state() was not set to StoppedState before start()"); - QVERIFY2((audioInput.error() == QAudio::NoError), "error() was not set to QAudio::NoError before start()"); - QVERIFY2((audioInput.elapsedUSecs() == qint64(0)),"elapsedUSecs() not zero on creation"); + QSignalSpy notifySignal(&audioInput, SIGNAL(notify())); + QSignalSpy stateSignal(&audioInput, SIGNAL(stateChanged(QAudio::State))); - audioInput.start(); - // Check that QAudioInput immediately transitions to IdleState - QTRY_VERIFY2((stateSignal.count() == 1),"didn't emit IdleState signal on start()"); - QVERIFY2((audioInput.state() == QAudio::IdleState), "didn't transition to IdleState after start()"); - QVERIFY2((audioInput.error() == QAudio::NoError), "error state is not equal to QAudio::NoError after start()"); - QVERIFY(audioInput.periodSize() > 0); - QTest::qWait(500); - QVERIFY(audioInput.bytesReady() > 0); - stateSignal.clear(); + // Check that we are in the default state before calling start + QVERIFY2((audioInput.state() == QAudio::StoppedState), "state() was not set to StoppedState before start()"); + QVERIFY2((audioInput.error() == QAudio::NoError), "error() was not set to QAudio::NoError before start()"); + QVERIFY2((audioInput.elapsedUSecs() == qint64(0)),"elapsedUSecs() not zero on creation"); + + QIODevice* device = audioInput.start(); + // Check that QAudioInput immediately transitions to IdleState + QTRY_VERIFY2((stateSignal.count() == 1),"didn't emit IdleState signal on start()"); + QVERIFY2((audioInput.state() == QAudio::IdleState), "didn't transition to IdleState after start()"); + QVERIFY2((audioInput.error() == QAudio::NoError), "error state is not equal to QAudio::NoError after start()"); + QVERIFY(audioInput.periodSize() > 0); + QTRY_VERIFY2((audioInput.bytesReady() > 0), "no bytes available after starting"); + + // Trigger a read + QByteArray data = device->read(1); + + QTRY_VERIFY2((audioInput.state() == QAudio::ActiveState), "didn't transition to ActiveState after read()"); + QVERIFY2((audioInput.error() == QAudio::NoError), "error state is not equal to QAudio::NoError after start()"); + stateSignal.clear(); + + audioInput.reset(); + QTRY_VERIFY2((stateSignal.count() == 1),"didn't emit StoppedState signal after reset()"); + QVERIFY2((audioInput.state() == QAudio::StoppedState), "didn't transitions to StoppedState after reset()"); + QVERIFY2((audioInput.bytesReady() == 0), "buffer not cleared after reset()"); + } - audioInput.reset(); - QTRY_VERIFY2((stateSignal.count() == 1),"didn't emit StoppedState signal after reset()"); - QVERIFY2((audioInput.state() == QAudio::StoppedState), "didn't transitions to StoppedState after reset()"); - QVERIFY2((audioInput.bytesReady() == 0), "buffer not cleared after reset()"); + { + QAudioInput audioInput(testFormats.at(i), this); + QBuffer buffer; + + audioInput.setNotifyInterval(100); + + QSignalSpy notifySignal(&audioInput, SIGNAL(notify())); + QSignalSpy stateSignal(&audioInput, SIGNAL(stateChanged(QAudio::State))); + + // Check that we are in the default state before calling start + QVERIFY2((audioInput.state() == QAudio::StoppedState), "state() was not set to StoppedState before start()"); + QVERIFY2((audioInput.error() == QAudio::NoError), "error() was not set to QAudio::NoError before start()"); + QVERIFY2((audioInput.elapsedUSecs() == qint64(0)),"elapsedUSecs() not zero on creation"); + + audioInput.start(&buffer); + + // Check that QAudioInput immediately transitions to ActiveState + QTRY_VERIFY2((stateSignal.count() >= 1),"didn't emit state changed signal on start()"); + QTRY_VERIFY2((audioInput.state() == QAudio::ActiveState), "didn't transition to ActiveState after start()"); + QVERIFY2((audioInput.error() == QAudio::NoError), "error state is not equal to QAudio::NoError after start()"); + QVERIFY(audioInput.periodSize() > 0); + QTRY_VERIFY2((audioInput.bytesReady() > 0), "no bytes available after starting"); + stateSignal.clear(); + + audioInput.reset(); + QTRY_VERIFY2((stateSignal.count() == 1),"didn't emit StoppedState signal after reset()"); + QVERIFY2((audioInput.state() == QAudio::StoppedState), "didn't transitions to StoppedState after reset()"); + QVERIFY2((audioInput.bytesReady() == 0), "buffer not cleared after reset()"); + } } } |