Added check to qsound and qsoundeffect unit tests for audio support
authorKurt Korbatits <kurt.korbatits@nokia.com>
Tue, 31 Jul 2012 00:26:28 +0000 (10:26 +1000)
committerQt by Nokia <qt-info@nokia.com>
Fri, 3 Aug 2012 02:11:48 +0000 (04:11 +0200)
- skip tests if QSoundEffect::supportedMimeTypes() returns empty list

Change-Id: I0f8d6f854c46b74f8518c4d969bd31ea167d20b2
Reviewed-by: Ling Hu <ling.hu@nokia.com>
Reviewed-by: Michael Goddard <michael.goddard@nokia.com>
src/multimedia/audio/qsoundeffect_qaudio_p.cpp
tests/auto/integration/qsound/tst_qsound.cpp
tests/auto/integration/qsoundeffect/tst_qsoundeffect.cpp

index 7727063..b8076a9 100644 (file)
@@ -89,6 +89,11 @@ void QSoundEffectPrivate::release()
 
 QStringList QSoundEffectPrivate::supportedMimeTypes()
 {
+    // Only return supported mime types if we have a audio device available
+    const QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
+    if (devices.size() <= 0)
+        return QStringList();
+
     return QStringList() << QLatin1String("audio/x-wav")
                          << QLatin1String("audio/wav")
                          << QLatin1String("audio/wave")
index 490a4fb..89579b9 100644 (file)
@@ -43,6 +43,7 @@
 #include <QtTest/QtTest>
 #include <QtCore/QString>
 #include <QSound>
+#include <QSoundEffect>
 
 class tst_QSound : public QObject
 {
@@ -67,6 +68,12 @@ private:
 
 void tst_QSound::initTestCase()
 {
+    sound = 0;
+    // Only perform tests if audio device exists
+    QStringList mimeTypes = QSoundEffect::supportedMimeTypes();
+    if (mimeTypes.empty())
+        QSKIP("No audio devices available");
+
     const QString testFileName = QStringLiteral("test.wav");
     const QString fullPath = QFINDTESTDATA(testFileName);
     QVERIFY2(!fullPath.isEmpty(), qPrintable(QStringLiteral("Unable to locate ") + testFileName));
index adcb9cd..b01bf1e 100644 (file)
@@ -98,6 +98,11 @@ void tst_QSoundEffect::cleanup()
 
 void tst_QSoundEffect::initTestCase()
 {
+    // Only perform tests if audio device exists
+    QStringList mimeTypes = sound->supportedMimeTypes();
+    if (mimeTypes.empty())
+        QSKIP("No audio devices available");
+
     QString testFileName = QStringLiteral("test.wav");
     QString fullPath = QFINDTESTDATA(testFileName);
     QVERIFY2(!fullPath.isEmpty(), qPrintable(QStringLiteral("Unable to locate ") + testFileName));