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/auto/qaudioinput | |
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/auto/qaudioinput')
-rw-r--r-- | tests/auto/qaudioinput/tst_qaudioinput.cpp | 47 |
1 files changed, 47 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) { |