From a6e88ea87f544638cf15f3bb61ccc276b1cc5664 Mon Sep 17 00:00:00 2001 From: Kurt Korbatits Date: Tue, 31 Jul 2012 10:26:28 +1000 Subject: [PATCH] Added check to qsound and qsoundeffect unit tests for audio support - skip tests if QSoundEffect::supportedMimeTypes() returns empty list Change-Id: I0f8d6f854c46b74f8518c4d969bd31ea167d20b2 Reviewed-by: Ling Hu Reviewed-by: Michael Goddard --- src/multimedia/audio/qsoundeffect_qaudio_p.cpp | 5 +++++ tests/auto/integration/qsound/tst_qsound.cpp | 7 +++++++ tests/auto/integration/qsoundeffect/tst_qsoundeffect.cpp | 5 +++++ 3 files changed, 17 insertions(+) diff --git a/src/multimedia/audio/qsoundeffect_qaudio_p.cpp b/src/multimedia/audio/qsoundeffect_qaudio_p.cpp index 77270637..b8076a99 100644 --- a/src/multimedia/audio/qsoundeffect_qaudio_p.cpp +++ b/src/multimedia/audio/qsoundeffect_qaudio_p.cpp @@ -89,6 +89,11 @@ void QSoundEffectPrivate::release() QStringList QSoundEffectPrivate::supportedMimeTypes() { + // Only return supported mime types if we have a audio device available + const QList devices = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput); + if (devices.size() <= 0) + return QStringList(); + return QStringList() << QLatin1String("audio/x-wav") << QLatin1String("audio/wav") << QLatin1String("audio/wave") diff --git a/tests/auto/integration/qsound/tst_qsound.cpp b/tests/auto/integration/qsound/tst_qsound.cpp index 490a4fbf..89579b93 100644 --- a/tests/auto/integration/qsound/tst_qsound.cpp +++ b/tests/auto/integration/qsound/tst_qsound.cpp @@ -43,6 +43,7 @@ #include #include #include +#include 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)); diff --git a/tests/auto/integration/qsoundeffect/tst_qsoundeffect.cpp b/tests/auto/integration/qsoundeffect/tst_qsoundeffect.cpp index adcb9cd8..b01bf1e8 100644 --- a/tests/auto/integration/qsoundeffect/tst_qsoundeffect.cpp +++ b/tests/auto/integration/qsoundeffect/tst_qsoundeffect.cpp @@ -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));