summaryrefslogtreecommitdiffstats
path: root/tests/auto/qaudiooutput
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/qaudiooutput
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/qaudiooutput')
-rw-r--r--tests/auto/qaudiooutput/tst_qaudiooutput.cpp123
1 files changed, 70 insertions, 53 deletions
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)