diff options
author | Kurt Korbatits <kurt.korbatits@nokia.com> | 2009-08-13 22:59:56 (GMT) |
---|---|---|
committer | Kurt Korbatits <kurt.korbatits@nokia.com> | 2009-08-13 22:59:56 (GMT) |
commit | 5a3d956ae19ad411d13c7db28eb7705f4ffaad9d (patch) | |
tree | 8a5e5f2e8972efda09acb81709c9a2fd4f99dbd0 /tests/auto/qaudiodeviceinfo | |
parent | 47603b9873071fa9463ce2bed01b4998ed340d7e (diff) | |
download | Qt-5a3d956ae19ad411d13c7db28eb7705f4ffaad9d.zip Qt-5a3d956ae19ad411d13c7db28eb7705f4ffaad9d.tar.gz Qt-5a3d956ae19ad411d13c7db28eb7705f4ffaad9d.tar.bz2 |
Fixed audio auto tests.
Handle platforms that don't have backends.
Reviewed-by: Bill King
Diffstat (limited to 'tests/auto/qaudiodeviceinfo')
-rw-r--r-- | tests/auto/qaudiodeviceinfo/tst_qaudiodeviceinfo.cpp | 114 |
1 files changed, 80 insertions, 34 deletions
diff --git a/tests/auto/qaudiodeviceinfo/tst_qaudiodeviceinfo.cpp b/tests/auto/qaudiodeviceinfo/tst_qaudiodeviceinfo.cpp index 72121a7..47f3d00 100644 --- a/tests/auto/qaudiodeviceinfo/tst_qaudiodeviceinfo.cpp +++ b/tests/auto/qaudiodeviceinfo/tst_qaudiodeviceinfo.cpp @@ -55,6 +55,7 @@ public: tst_QAudioDeviceInfo(QObject* parent=0) : QObject(parent) {} private slots: + void initTestCase(); void checkAvailableDefaultInput(); void checkAvailableDefaultOutput(); void outputList(); @@ -69,89 +70,134 @@ private slots: void nearest(); private: + bool available; QAudioDeviceInfo* device; }; +void tst_QAudioDeviceInfo::initTestCase() +{ + // Only perform tests if audio output device exists! + QList<QAudioDeviceId> devices = QAudioDeviceInfo::deviceList(QAudio::AudioOutput); + if(devices.size() > 0) + available = true; + else { + qWarning()<<"NOTE: no audio output device found, no test will be performed"; + available = false; + } +} + void tst_QAudioDeviceInfo::checkAvailableDefaultInput() { - QVERIFY(!QAudioDeviceInfo::defaultInputDevice().isNull()); + // Only perform tests if audio input device exists! + bool storeAvailable = available; + QList<QAudioDeviceId> devices = QAudioDeviceInfo::deviceList(QAudio::AudioInput); + if(devices.size() > 0) + available = true; + else { + qWarning()<<"NOTE: no audio input device found, no test will be performed"; + available = false; + } + if(available) + QVERIFY(!QAudioDeviceInfo::defaultInputDevice().isNull()); + available = storeAvailable; } void tst_QAudioDeviceInfo::checkAvailableDefaultOutput() { - QVERIFY(!QAudioDeviceInfo::defaultOutputDevice().isNull()); + if(available) + QVERIFY(!QAudioDeviceInfo::defaultOutputDevice().isNull()); } void tst_QAudioDeviceInfo::outputList() { - QList<QAudioDeviceId> devices = QAudioDeviceInfo::deviceList(QAudio::AudioOutput); - QVERIFY(devices.size() > 0); - device = new QAudioDeviceInfo(devices.at(0), this); + if(available) { + QList<QAudioDeviceId> devices = QAudioDeviceInfo::deviceList(QAudio::AudioOutput); + QVERIFY(devices.size() > 0); + device = new QAudioDeviceInfo(devices.at(0), this); + } } void tst_QAudioDeviceInfo::codecs() { - QStringList avail = device->supportedCodecs(); - QVERIFY(avail.size() > 0); + if(available) { + QStringList avail = device->supportedCodecs(); + QVERIFY(avail.size() > 0); + } } void tst_QAudioDeviceInfo::channels() { - QList<int> avail = device->supportedChannels(); - QVERIFY(avail.size() > 0); + if(available) { + QList<int> avail = device->supportedChannels(); + QVERIFY(avail.size() > 0); + } } void tst_QAudioDeviceInfo::sampleSizes() { - QList<int> avail = device->supportedSampleSizes(); - QVERIFY(avail.size() > 0); + if(available) { + QList<int> avail = device->supportedSampleSizes(); + QVERIFY(avail.size() > 0); + } } void tst_QAudioDeviceInfo::byteOrders() { - QList<QAudioFormat::Endian> avail = device->supportedByteOrders(); - QVERIFY(avail.size() > 0); + if(available) { + QList<QAudioFormat::Endian> avail = device->supportedByteOrders(); + QVERIFY(avail.size() > 0); + } } void tst_QAudioDeviceInfo::sampleTypes() { - QList<QAudioFormat::SampleType> avail = device->supportedSampleTypes(); - QVERIFY(avail.size() > 0); + if(available) { + QList<QAudioFormat::SampleType> avail = device->supportedSampleTypes(); + QVERIFY(avail.size() > 0); + } } void tst_QAudioDeviceInfo::frequencies() { - QList<int> avail = device->supportedFrequencies(); - QVERIFY(avail.size() > 0); + if(available) { + QList<int> avail = device->supportedFrequencies(); + QVERIFY(avail.size() > 0); + } } void tst_QAudioDeviceInfo::isformat() { - QAudioFormat format; - format.setFrequency(44100); - format.setChannels(2); - format.setSampleType(QAudioFormat::SignedInt); - format.setByteOrder(QAudioFormat::LittleEndian); - format.setSampleSize(16); - format.setCodec("audio/pcm"); - - // Should always be true for these format - QVERIFY(device->isFormatSupported(format)); + if(available) { + QAudioFormat format; + format.setFrequency(44100); + format.setChannels(2); + format.setSampleType(QAudioFormat::SignedInt); + format.setByteOrder(QAudioFormat::LittleEndian); + format.setSampleSize(16); + format.setCodec("audio/pcm"); + + // Should always be true for these format + QVERIFY(device->isFormatSupported(format)); + } } void tst_QAudioDeviceInfo::preferred() { - QAudioFormat format = device->preferredFormat(); - QVERIFY(format.frequency() == 44100); - QVERIFY(format.channels() == 2); + if(available) { + QAudioFormat format = device->preferredFormat(); + QVERIFY(format.frequency() == 44100); + QVERIFY(format.channels() == 2); + } } void tst_QAudioDeviceInfo::nearest() { - QAudioFormat format1, format2; - format1.setFrequency(8000); - format2 = device->nearestFormat(format1); - QVERIFY(format2.frequency() == 44100); + if(available) { + QAudioFormat format1, format2; + format1.setFrequency(8000); + format2 = device->nearestFormat(format1); + QVERIFY(format2.frequency() == 44100); + } } QTEST_MAIN(tst_QAudioDeviceInfo) |