diff options
author | Andrew den Exter <andrew.den-exter@nokia.com> | 2010-09-22 05:41:34 (GMT) |
---|---|---|
committer | Andrew den Exter <andrew.den-exter@nokia.com> | 2010-09-22 08:03:38 (GMT) |
commit | 5b7d75a57e0ec8ee78f843ab0eb6485b8e3b4a22 (patch) | |
tree | 7a474601e5daa4cc6cfb823c0af870f6bd7eb155 /tests | |
parent | 2836c2806e3bdfb6d29d99f74f1b15950fa39e35 (diff) | |
download | Qt-5b7d75a57e0ec8ee78f843ab0eb6485b8e3b4a22.zip Qt-5b7d75a57e0ec8ee78f843ab0eb6485b8e3b4a22.tar.gz Qt-5b7d75a57e0ec8ee78f843ab0eb6485b8e3b4a22.tar.bz2 |
Verify the audio format before trying to open an audio device.
This was causing a crash on windows because the buffer and period sizes
were worked out to 0 with an invalid sample size and dividing one by the
other is division by 0.
Task-number: QTMOBILITY-438
Reviewed-by: Justin McPherson
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qaudioinput/tst_qaudioinput.cpp | 47 | ||||
-rw-r--r-- | tests/auto/qaudiooutput/tst_qaudiooutput.cpp | 47 |
2 files changed, 94 insertions, 0 deletions
diff --git a/tests/auto/qaudioinput/tst_qaudioinput.cpp b/tests/auto/qaudioinput/tst_qaudioinput.cpp index 84c3874..1808b1d 100644 --- a/tests/auto/qaudioinput/tst_qaudioinput.cpp +++ b/tests/auto/qaudioinput/tst_qaudioinput.cpp @@ -50,6 +50,8 @@ #define SRCDIR "" #endif +Q_DECLARE_METATYPE(QAudioFormat) + class tst_QAudioInput : public QObject { Q_OBJECT @@ -58,6 +60,8 @@ public: private slots: void initTestCase(); + void invalidFormat_data(); + void invalidFormat(); void settings(); void buffers(); void notifyInterval(); @@ -71,6 +75,8 @@ private: void tst_QAudioInput::initTestCase() { + qRegisterMetaType<QAudioFormat>(); + format.setFrequency(8000); format.setChannels(1); format.setSampleSize(8); @@ -91,6 +97,47 @@ void tst_QAudioInput::initTestCase() audio = new QAudioInput(format, this); } +void tst_QAudioInput::invalidFormat_data() +{ + QTest::addColumn<QAudioFormat>("invalidFormat"); + + QAudioFormat audioFormat; + + QTest::newRow("Null Format") + << audioFormat; + + audioFormat = format; + audioFormat.setChannels(0); + QTest::newRow("Channel count 0") + << audioFormat; + + audioFormat = format; + audioFormat.setFrequency(0); + QTest::newRow("Sample rate 0") + << audioFormat; + + audioFormat = format; + audioFormat.setSampleSize(0); + QTest::newRow("Sample size 0") + << audioFormat; +} + +void tst_QAudioInput::invalidFormat() +{ + QFETCH(QAudioFormat, invalidFormat); + + QAudioInput audioInput(invalidFormat, this); + + // 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()"); + + audioInput.start(); + + // Check that error is raised + QVERIFY2((audioInput.error() == QAudio::OpenError),"error() was not set to QAudio::OpenError after start()"); +} + void tst_QAudioInput::settings() { if(available) { diff --git a/tests/auto/qaudiooutput/tst_qaudiooutput.cpp b/tests/auto/qaudiooutput/tst_qaudiooutput.cpp index 437ef5e..e6d11a6 100644 --- a/tests/auto/qaudiooutput/tst_qaudiooutput.cpp +++ b/tests/auto/qaudiooutput/tst_qaudiooutput.cpp @@ -52,6 +52,8 @@ #define SRCDIR "" #endif +Q_DECLARE_METATYPE(QAudioFormat) + class tst_QAudioOutput : public QObject { Q_OBJECT @@ -60,6 +62,8 @@ public: private slots: void initTestCase(); + void invalidFormat_data(); + void invalidFormat(); void settings(); void buffers(); void notifyInterval(); @@ -74,6 +78,8 @@ private: void tst_QAudioOutput::initTestCase() { + qRegisterMetaType<QAudioFormat>(); + format.setFrequency(8000); format.setChannels(1); format.setSampleSize(8); @@ -92,6 +98,47 @@ void tst_QAudioOutput::initTestCase() audio = new QAudioOutput(format, this); } +void tst_QAudioOutput::invalidFormat_data() +{ + QTest::addColumn<QAudioFormat>("invalidFormat"); + + QAudioFormat audioFormat; + + QTest::newRow("Null Format") + << audioFormat; + + audioFormat = format; + audioFormat.setChannels(0); + QTest::newRow("Channel count 0") + << audioFormat; + + audioFormat = format; + audioFormat.setFrequency(0); + QTest::newRow("Sample rate 0") + << audioFormat; + + audioFormat = format; + audioFormat.setSampleSize(0); + QTest::newRow("Sample size 0") + << audioFormat; +} + +void tst_QAudioOutput::invalidFormat() +{ + QFETCH(QAudioFormat, invalidFormat); + + QAudioOutput audioOutput(invalidFormat, this); + + // Check that we are in the default state before calling start + QVERIFY2((audioOutput.state() == QAudio::StoppedState), "state() was not set to StoppedState before start()"); + QVERIFY2((audioOutput.error() == QAudio::NoError), "error() was not set to QAudio::NoError before start()"); + + audioOutput.start(); + + // Check that error is raised + QVERIFY2((audioOutput.error() == QAudio::OpenError),"error() was not set to QAudio::OpenError after start()"); +} + void tst_QAudioOutput::settings() { if(available) { |