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 <ling.hu@nokia.com>
Reviewed-by: Michael Goddard <michael.goddard@nokia.com>
This commit is contained in:
Kurt Korbatits
2012-07-31 10:26:28 +10:00
committed by Qt by Nokia
parent 86553ef811
commit a6e88ea87f
3 changed files with 17 additions and 0 deletions

View File

@@ -89,6 +89,11 @@ void QSoundEffectPrivate::release()
QStringList QSoundEffectPrivate::supportedMimeTypes() 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") return QStringList() << QLatin1String("audio/x-wav")
<< QLatin1String("audio/wav") << QLatin1String("audio/wav")
<< QLatin1String("audio/wave") << QLatin1String("audio/wave")

View File

@@ -43,6 +43,7 @@
#include <QtTest/QtTest> #include <QtTest/QtTest>
#include <QtCore/QString> #include <QtCore/QString>
#include <QSound> #include <QSound>
#include <QSoundEffect>
class tst_QSound : public QObject class tst_QSound : public QObject
{ {
@@ -67,6 +68,12 @@ private:
void tst_QSound::initTestCase() 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 testFileName = QStringLiteral("test.wav");
const QString fullPath = QFINDTESTDATA(testFileName); const QString fullPath = QFINDTESTDATA(testFileName);
QVERIFY2(!fullPath.isEmpty(), qPrintable(QStringLiteral("Unable to locate ") + testFileName)); QVERIFY2(!fullPath.isEmpty(), qPrintable(QStringLiteral("Unable to locate ") + testFileName));

View File

@@ -98,6 +98,11 @@ void tst_QSoundEffect::cleanup()
void tst_QSoundEffect::initTestCase() 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 testFileName = QStringLiteral("test.wav");
QString fullPath = QFINDTESTDATA(testFileName); QString fullPath = QFINDTESTDATA(testFileName);
QVERIFY2(!fullPath.isEmpty(), qPrintable(QStringLiteral("Unable to locate ") + testFileName)); QVERIFY2(!fullPath.isEmpty(), qPrintable(QStringLiteral("Unable to locate ") + testFileName));