summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorKurt Korbatits <kurt.korbatits@nokia.com>2009-08-13 22:59:56 (GMT)
committerKurt Korbatits <kurt.korbatits@nokia.com>2009-08-13 22:59:56 (GMT)
commit5a3d956ae19ad411d13c7db28eb7705f4ffaad9d (patch)
tree8a5e5f2e8972efda09acb81709c9a2fd4f99dbd0 /tests/auto
parent47603b9873071fa9463ce2bed01b4998ed340d7e (diff)
downloadQt-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')
-rw-r--r--tests/auto/qaudiodeviceid/tst_qaudiodeviceid.cpp60
-rw-r--r--tests/auto/qaudiodeviceinfo/tst_qaudiodeviceinfo.cpp114
-rw-r--r--tests/auto/qaudioinput/tst_qaudioinput.cpp61
-rw-r--r--tests/auto/qaudiooutput/tst_qaudiooutput.cpp123
4 files changed, 229 insertions, 129 deletions
diff --git a/tests/auto/qaudiodeviceid/tst_qaudiodeviceid.cpp b/tests/auto/qaudiodeviceid/tst_qaudiodeviceid.cpp
index 8f8d6a6..f87500c 100644
--- a/tests/auto/qaudiodeviceid/tst_qaudiodeviceid.cpp
+++ b/tests/auto/qaudiodeviceid/tst_qaudiodeviceid.cpp
@@ -56,41 +56,61 @@ public:
tst_QAudioDeviceId(QObject* parent=0) : QObject(parent) {}
private slots:
+ void initTestCase();
void checkNull();
void checkEquality();
+
+private:
+ bool available;
};
-void tst_QAudioDeviceId::checkNull()
+void tst_QAudioDeviceId::initTestCase()
{
- // Default constructed is null.
- QAudioDeviceId deviceId0;
- QVERIFY(deviceId0.isNull());
+ // 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;
+ }
+}
- // Null is transferred
- QAudioDeviceId deviceId1(deviceId0);
- QVERIFY(deviceId1.isNull());
+void tst_QAudioDeviceId::checkNull()
+{
+ if(available) {
+ // Default constructed is null.
+ QAudioDeviceId deviceId0;
+ QVERIFY(deviceId0.isNull());
+
+ // Null is transferred
+ QAudioDeviceId deviceId1(deviceId0);
+ QVERIFY(deviceId1.isNull());
+ }
}
void tst_QAudioDeviceId::checkEquality()
{
- QAudioDeviceId deviceId0;
- QAudioDeviceId deviceId1;
+ if(available) {
+ QAudioDeviceId deviceId0;
+ QAudioDeviceId deviceId1;
- // Null ids are equivalent
- QVERIFY(deviceId0 == deviceId1);
- QVERIFY(!(deviceId0 != deviceId1));
+ // Null ids are equivalent
+ QVERIFY(deviceId0 == deviceId1);
+ QVERIFY(!(deviceId0 != deviceId1));
- deviceId1 = QAudioDeviceInfo::defaultOutputDevice();
+ deviceId1 = QAudioDeviceInfo::defaultOutputDevice();
- // Different
- QVERIFY(deviceId0 != deviceId1);
- QVERIFY(!(deviceId0 == deviceId1));
+ // Different
+ QVERIFY(deviceId0 != deviceId1);
+ QVERIFY(!(deviceId0 == deviceId1));
- // Same
- deviceId0 = deviceId1;
+ // Same
+ deviceId0 = deviceId1;
- QVERIFY(deviceId0 == deviceId1);
- QVERIFY(!(deviceId0 != deviceId1));
+ QVERIFY(deviceId0 == deviceId1);
+ QVERIFY(!(deviceId0 != deviceId1));
+ }
}
QTEST_MAIN(tst_QAudioDeviceId)
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)
diff --git a/tests/auto/qaudioinput/tst_qaudioinput.cpp b/tests/auto/qaudioinput/tst_qaudioinput.cpp
index 891d1c4..6f1d568 100644
--- a/tests/auto/qaudioinput/tst_qaudioinput.cpp
+++ b/tests/auto/qaudioinput/tst_qaudioinput.cpp
@@ -60,6 +60,7 @@ private slots:
void pullFile();
private:
+ bool available;
QAudioFormat format;
QAudioInput* audio;
};
@@ -73,46 +74,62 @@ void tst_QAudioInput::initTestCase()
format.setByteOrder(QAudioFormat::LittleEndian);
format.setSampleType(QAudioFormat::UnSignedInt);
- audio = new QAudioInput(format, this);
+ // Only perform tests if audio input device exists!
+ 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)
+ audio = new QAudioInput(format, this);
}
void tst_QAudioInput::settings()
{
- QAudioFormat f = audio->format();
-
- QVERIFY(format.channels() == f.channels());
- QVERIFY(format.frequency() == f.frequency());
- QVERIFY(format.sampleSize() == f.sampleSize());
- QVERIFY(format.codec() == f.codec());
- QVERIFY(format.byteOrder() == f.byteOrder());
- QVERIFY(format.sampleType() == f.sampleType());
+ if(available) {
+ QAudioFormat f = audio->format();
+
+ QVERIFY(format.channels() == f.channels());
+ QVERIFY(format.frequency() == f.frequency());
+ QVERIFY(format.sampleSize() == f.sampleSize());
+ QVERIFY(format.codec() == f.codec());
+ QVERIFY(format.byteOrder() == f.byteOrder());
+ QVERIFY(format.sampleType() == f.sampleType());
+ }
}
void tst_QAudioInput::notifyInterval()
{
- QVERIFY(audio->notifyInterval() == 1000); // Default
+ if(available) {
+ QVERIFY(audio->notifyInterval() == 1000); // Default
- audio->setNotifyInterval(500);
- QVERIFY(audio->notifyInterval() == 500); // Custom
+ audio->setNotifyInterval(500);
+ QVERIFY(audio->notifyInterval() == 500); // Custom
- audio->setNotifyInterval(1000); // reset
+ audio->setNotifyInterval(1000); // reset
+ }
}
void tst_QAudioInput::pullFile()
{
- QFile filename(SRCDIR "test.raw");
- filename.open( QIODevice::WriteOnly | QIODevice::Truncate );
+ if(available) {
+ QFile filename(SRCDIR "test.raw");
+ filename.open( QIODevice::WriteOnly | QIODevice::Truncate );
- QSignalSpy readSignal(audio, SIGNAL(notify()));
- audio->start(&filename);
+ QSignalSpy readSignal(audio, SIGNAL(notify()));
+ audio->start(&filename);
- QTest::qWait(5000);
+ QTest::qWait(5000);
- QVERIFY(readSignal.count() > 0);
- QVERIFY(audio->totalTime() > 0);
+ QVERIFY(readSignal.count() > 0);
+ QVERIFY(audio->totalTime() > 0);
- audio->stop();
- filename.close();
+ audio->stop();
+ filename.close();
+ }
}
QTEST_MAIN(tst_QAudioInput)
diff --git a/tests/auto/qaudiooutput/tst_qaudiooutput.cpp b/tests/auto/qaudiooutput/tst_qaudiooutput.cpp
index 2c3f662..0552aa4 100644
--- a/tests/auto/qaudiooutput/tst_qaudiooutput.cpp
+++ b/tests/auto/qaudiooutput/tst_qaudiooutput.cpp
@@ -63,6 +63,7 @@ private slots:
void pushFile();
private:
+ bool available;
QAudioFormat format;
QAudioOutput* audio;
};
@@ -76,79 +77,95 @@ void tst_QAudioOutput::initTestCase()
format.setByteOrder(QAudioFormat::LittleEndian);
format.setSampleType(QAudioFormat::UnSignedInt);
+ // 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;
+ }
audio = new QAudioOutput(format, this);
}
void tst_QAudioOutput::settings()
{
- QAudioFormat f = audio->format();
-
- QVERIFY(format.channels() == f.channels());
- QVERIFY(format.frequency() == f.frequency());
- QVERIFY(format.sampleSize() == f.sampleSize());
- QVERIFY(format.codec() == f.codec());
- QVERIFY(format.byteOrder() == f.byteOrder());
- QVERIFY(format.sampleType() == f.sampleType());
+ if(available) {
+ QAudioFormat f = audio->format();
+
+ QVERIFY(format.channels() == f.channels());
+ QVERIFY(format.frequency() == f.frequency());
+ QVERIFY(format.sampleSize() == f.sampleSize());
+ QVERIFY(format.codec() == f.codec());
+ QVERIFY(format.byteOrder() == f.byteOrder());
+ QVERIFY(format.sampleType() == f.sampleType());
+ }
}
void tst_QAudioOutput::notifyInterval()
{
- QVERIFY(audio->notifyInterval() == 1000); // Default
+ if(available) {
+ QVERIFY(audio->notifyInterval() == 1000); // Default
- audio->setNotifyInterval(500);
- QVERIFY(audio->notifyInterval() == 500); // Custom
+ audio->setNotifyInterval(500);
+ QVERIFY(audio->notifyInterval() == 500); // Custom
- audio->setNotifyInterval(1000); // reset
+ audio->setNotifyInterval(1000); // reset
+ }
}
void tst_QAudioOutput::pullFile()
{
- QFile filename(SRCDIR "4.wav");
- QVERIFY(filename.exists());
- filename.open(QIODevice::ReadOnly);
-
- QSignalSpy readSignal(audio, SIGNAL(notify()));
- audio->setNotifyInterval(100);
- audio->start(&filename);
-
- QTestEventLoop::instance().enterLoop(1);
- // 4.wav is a little less than 700ms, so notify should fire 6 times!
- QVERIFY(readSignal.count() >= 6);
- QVERIFY(audio->totalTime() == 692250);
-
- audio->stop();
- filename.close();
+ if(available) {
+ QFile filename(SRCDIR "4.wav");
+ QVERIFY(filename.exists());
+ filename.open(QIODevice::ReadOnly);
+
+ QSignalSpy readSignal(audio, SIGNAL(notify()));
+ audio->setNotifyInterval(100);
+ audio->start(&filename);
+
+ QTestEventLoop::instance().enterLoop(1);
+ // 4.wav is a little less than 700ms, so notify should fire 6 times!
+ QVERIFY(readSignal.count() >= 6);
+ QVERIFY(audio->totalTime() == 692250);
+
+ audio->stop();
+ filename.close();
+ }
}
void tst_QAudioOutput::pushFile()
{
- QFile filename(SRCDIR "4.wav");
- QVERIFY(filename.exists());
- filename.open(QIODevice::ReadOnly);
-
- const qint64 fileSize = filename.size();
-
- QIODevice* feed = audio->start(0);
-
- char* buffer = new char[fileSize];
- filename.read(buffer, fileSize);
-
- qint64 counter=0;
- qint64 written=0;
- while(written < fileSize) {
- written+=feed->write(buffer+written,fileSize-written);
- QTest::qWait(20);
- counter++;
+ if(available) {
+ QFile filename(SRCDIR "4.wav");
+ QVERIFY(filename.exists());
+ filename.open(QIODevice::ReadOnly);
+
+ const qint64 fileSize = filename.size();
+
+ QIODevice* feed = audio->start(0);
+
+ char* buffer = new char[fileSize];
+ filename.read(buffer, fileSize);
+
+ qint64 counter=0;
+ qint64 written=0;
+ while(written < fileSize) {
+ written+=feed->write(buffer+written,fileSize-written);
+ QTest::qWait(20);
+ counter++;
+ }
+ QTestEventLoop::instance().enterLoop(1);
+
+ QVERIFY(written == fileSize);
+ QVERIFY(audio->totalTime() == 692250);
+
+ audio->stop();
+ filename.close();
+ delete [] buffer;
+ delete audio;
}
- QTestEventLoop::instance().enterLoop(1);
-
- QVERIFY(written == fileSize);
- QVERIFY(audio->totalTime() == 692250);
-
- audio->stop();
- filename.close();
- delete [] buffer;
- delete audio;
}
QTEST_MAIN(tst_QAudioOutput)