Added data driven integration tests for qaudioinput.
Change-Id: I42256833173e9ca94931ff35210802457d407e39 Reviewed-by: Michael Goddard <michael.goddard@nokia.com>
This commit is contained in:
committed by
Qt by Nokia
parent
403eee4d87
commit
27a7559c7e
@@ -91,7 +91,6 @@ private slots:
|
||||
void invalidFormat();
|
||||
|
||||
void bufferSize();
|
||||
|
||||
void notifyInterval();
|
||||
void disableNotifyInterval();
|
||||
|
||||
@@ -99,14 +98,22 @@ private slots:
|
||||
void suspendWhileStopped();
|
||||
void resumeWhileStopped();
|
||||
|
||||
void pull_data(){generate_audiofile_testrows();}
|
||||
void pull();
|
||||
|
||||
void pullSuspendResume_data(){generate_audiofile_testrows();}
|
||||
void pullSuspendResume();
|
||||
|
||||
void push_data(){generate_audiofile_testrows();}
|
||||
void push();
|
||||
|
||||
void pushSuspendResume_data(){generate_audiofile_testrows();}
|
||||
void pushSuspendResume();
|
||||
|
||||
void reset_data(){generate_audiofile_testrows();}
|
||||
void reset();
|
||||
|
||||
void volume_data(){generate_audiofile_testrows();}
|
||||
void volume();
|
||||
|
||||
private:
|
||||
@@ -114,6 +121,8 @@ private:
|
||||
|
||||
QString formatToFileName(const QAudioFormat &format);
|
||||
|
||||
void generate_audiofile_testrows();
|
||||
|
||||
QAudioDeviceInfo audioDevice;
|
||||
QList<QAudioFormat> testFormats;
|
||||
QList<FilePtr> audioFiles;
|
||||
@@ -125,6 +134,21 @@ private:
|
||||
bool m_inCISystem;
|
||||
};
|
||||
|
||||
void tst_QAudioInput::generate_audiofile_testrows()
|
||||
{
|
||||
QTest::addColumn<FilePtr>("audioFile");
|
||||
QTest::addColumn<QAudioFormat>("audioFormat");
|
||||
|
||||
for (int i=0; i<audioFiles.count(); i++) {
|
||||
QTest::newRow(QString("Audio File %1").arg(i).toLocal8Bit().constData())
|
||||
<< audioFiles.at(i) << testFormats.at(i);
|
||||
|
||||
// Only run first format in CI system to reduce test times
|
||||
if (m_inCISystem)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QString tst_QAudioInput::formatToFileName(const QAudioFormat &format)
|
||||
{
|
||||
const QString formatEndian = (format.byteOrder() == QAudioFormat::LittleEndian)
|
||||
@@ -429,9 +453,10 @@ void tst_QAudioInput::resumeWhileStopped()
|
||||
|
||||
void tst_QAudioInput::pull()
|
||||
{
|
||||
for(int i=0; i<audioFiles.count(); i++) {
|
||||
QAudioInput audioInput(testFormats.at(i), this);
|
||||
QFile *audioFile = audioFiles.at(i).data();
|
||||
QFETCH(FilePtr, audioFile);
|
||||
QFETCH(QAudioFormat, audioFormat);
|
||||
|
||||
QAudioInput audioInput(audioFormat, this);
|
||||
|
||||
audioInput.setNotifyInterval(100);
|
||||
|
||||
@@ -445,10 +470,10 @@ void tst_QAudioInput::pull()
|
||||
|
||||
audioFile->close();
|
||||
audioFile->open(QIODevice::WriteOnly);
|
||||
WavHeader wavHeader(testFormats.at(i));
|
||||
WavHeader wavHeader(audioFormat);
|
||||
QVERIFY(wavHeader.write(*audioFile));
|
||||
|
||||
audioInput.start(audioFile);
|
||||
audioInput.start(audioFile.data());
|
||||
|
||||
// Check that QAudioInput immediately transitions to ActiveState or IdleState
|
||||
QTRY_VERIFY2((stateSignal.count() > 0),"didn't emit signals on start()");
|
||||
@@ -484,10 +509,6 @@ void tst_QAudioInput::pull()
|
||||
WavHeader::writeDataLength(*audioFile, audioFile->pos() - WavHeader::headerLength());
|
||||
audioFile->close();
|
||||
|
||||
// Only run first format in CI system to reduce test times
|
||||
if (m_inCISystem)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QAudioInput::pullSuspendResume()
|
||||
@@ -496,9 +517,10 @@ void tst_QAudioInput::pullSuspendResume()
|
||||
if (m_inCISystem)
|
||||
QSKIP("QTBUG-26504 Fails 20% of time with pulseaudio backend");
|
||||
#endif
|
||||
for(int i=0; i<audioFiles.count(); i++) {
|
||||
QAudioInput audioInput(testFormats.at(i), this);
|
||||
QFile *audioFile = audioFiles.at(i).data();
|
||||
QFETCH(FilePtr, audioFile);
|
||||
QFETCH(QAudioFormat, audioFormat);
|
||||
|
||||
QAudioInput audioInput(audioFormat, this);
|
||||
|
||||
audioInput.setNotifyInterval(100);
|
||||
|
||||
@@ -510,12 +532,12 @@ void tst_QAudioInput::pullSuspendResume()
|
||||
QVERIFY2((audioInput.error() == QAudio::NoError), "error() was not set to QAudio::NoError before start()");
|
||||
QVERIFY2((audioInput.elapsedUSecs() == qint64(0)),"elapsedUSecs() not zero on creation");
|
||||
|
||||
audioFiles.at(i)->close();
|
||||
audioFiles.at(i)->open(QIODevice::WriteOnly);
|
||||
WavHeader wavHeader(testFormats.at(i));
|
||||
QVERIFY(wavHeader.write(*audioFiles.at(i)));
|
||||
audioFile->close();
|
||||
audioFile->open(QIODevice::WriteOnly);
|
||||
WavHeader wavHeader(audioFormat);
|
||||
QVERIFY(wavHeader.write(*audioFile));
|
||||
|
||||
audioInput.start(audioFile);
|
||||
audioInput.start(audioFile.data());
|
||||
|
||||
// Check that QAudioInput immediately transitions to ActiveState or IdleState
|
||||
QTRY_VERIFY2((stateSignal.count() > 0),"didn't emit signals on start()");
|
||||
@@ -582,19 +604,16 @@ void tst_QAudioInput::pullSuspendResume()
|
||||
QVERIFY2((audioInput.elapsedUSecs() == (qint64)0), "elapsedUSecs() not equal to zero in StoppedState");
|
||||
QVERIFY2(notifySignal.count() > 0, "not emitting notify() signal");
|
||||
|
||||
WavHeader::writeDataLength(*audioFiles.at(i),audioFiles.at(i)->pos()-WavHeader::headerLength());
|
||||
WavHeader::writeDataLength(*audioFile,audioFile->pos()-WavHeader::headerLength());
|
||||
audioFile->close();
|
||||
|
||||
// Only run first format in CI system to reduce test times
|
||||
if (m_inCISystem)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QAudioInput::push()
|
||||
{
|
||||
for(int i=0; i<audioFiles.count(); i++) {
|
||||
QAudioInput audioInput(testFormats.at(i), this);
|
||||
QFETCH(FilePtr, audioFile);
|
||||
QFETCH(QAudioFormat, audioFormat);
|
||||
|
||||
QAudioInput audioInput(audioFormat, this);
|
||||
|
||||
audioInput.setNotifyInterval(100);
|
||||
|
||||
@@ -606,10 +625,10 @@ void tst_QAudioInput::push()
|
||||
QVERIFY2((audioInput.error() == QAudio::NoError), "error() was not set to QAudio::NoError before start()");
|
||||
QVERIFY2((audioInput.elapsedUSecs() == qint64(0)),"elapsedUSecs() not zero on creation");
|
||||
|
||||
audioFiles.at(i)->close();
|
||||
audioFiles.at(i)->open(QIODevice::WriteOnly);
|
||||
WavHeader wavHeader(testFormats.at(i));
|
||||
QVERIFY(wavHeader.write(*audioFiles.at(i)));
|
||||
audioFile->close();
|
||||
audioFile->open(QIODevice::WriteOnly);
|
||||
WavHeader wavHeader(audioFormat);
|
||||
QVERIFY(wavHeader.write(*audioFile));
|
||||
|
||||
QIODevice* feed = audioInput.start();
|
||||
|
||||
@@ -628,11 +647,11 @@ void tst_QAudioInput::push()
|
||||
qint64 totalBytesRead = 0;
|
||||
bool firstBuffer = true;
|
||||
QByteArray buffer(AUDIO_BUFFER, 0);
|
||||
qint64 len = (testFormats.at(i).sampleRate()*testFormats.at(i).channelCount()*(testFormats.at(i).sampleSize()/8)*2); // 2 seconds
|
||||
qint64 len = (audioFormat.sampleRate()*audioFormat.channelCount()*(audioFormat.sampleSize()/8)*2); // 2 seconds
|
||||
while (totalBytesRead < len) {
|
||||
if (audioInput.bytesReady() >= audioInput.periodSize()) {
|
||||
qint64 bytesRead = feed->read(buffer.data(), audioInput.periodSize());
|
||||
audioFiles.at(i)->write(buffer.constData(),bytesRead);
|
||||
audioFile->write(buffer.constData(),bytesRead);
|
||||
totalBytesRead+=bytesRead;
|
||||
if (firstBuffer && bytesRead) {
|
||||
// Check for transition to ActiveState when data is provided
|
||||
@@ -664,13 +683,8 @@ void tst_QAudioInput::push()
|
||||
QVERIFY2((audioInput.elapsedUSecs() == (qint64)0), "elapsedUSecs() not equal to zero in StoppedState");
|
||||
QVERIFY2(notifySignal.count() > 0, "not emitting notify() signal");
|
||||
|
||||
WavHeader::writeDataLength(*audioFiles.at(i),audioFiles.at(i)->pos()-WavHeader::headerLength());
|
||||
audioFiles.at(i)->close();
|
||||
|
||||
// Only run first format in CI system to reduce test times
|
||||
if (m_inCISystem)
|
||||
break;
|
||||
}
|
||||
WavHeader::writeDataLength(*audioFile,audioFile->pos()-WavHeader::headerLength());
|
||||
audioFile->close();
|
||||
}
|
||||
|
||||
void tst_QAudioInput::pushSuspendResume()
|
||||
@@ -679,8 +693,9 @@ void tst_QAudioInput::pushSuspendResume()
|
||||
if (m_inCISystem)
|
||||
QSKIP("QTBUG-26504 Fails 20% of time with pulseaudio backend");
|
||||
#endif
|
||||
for(int i=0; i<audioFiles.count(); i++) {
|
||||
QAudioInput audioInput(testFormats.at(i), this);
|
||||
QFETCH(FilePtr, audioFile);
|
||||
QFETCH(QAudioFormat, audioFormat);
|
||||
QAudioInput audioInput(audioFormat, this);
|
||||
|
||||
audioInput.setNotifyInterval(100);
|
||||
|
||||
@@ -692,10 +707,10 @@ void tst_QAudioInput::pushSuspendResume()
|
||||
QVERIFY2((audioInput.error() == QAudio::NoError), "error() was not set to QAudio::NoError before start()");
|
||||
QVERIFY2((audioInput.elapsedUSecs() == qint64(0)),"elapsedUSecs() not zero on creation");
|
||||
|
||||
audioFiles.at(i)->close();
|
||||
audioFiles.at(i)->open(QIODevice::WriteOnly);
|
||||
WavHeader wavHeader(testFormats.at(i));
|
||||
QVERIFY(wavHeader.write(*audioFiles.at(i)));
|
||||
audioFile->close();
|
||||
audioFile->open(QIODevice::WriteOnly);
|
||||
WavHeader wavHeader(audioFormat);
|
||||
QVERIFY(wavHeader.write(*audioFile));
|
||||
|
||||
QIODevice* feed = audioInput.start();
|
||||
|
||||
@@ -714,11 +729,11 @@ void tst_QAudioInput::pushSuspendResume()
|
||||
qint64 totalBytesRead = 0;
|
||||
bool firstBuffer = true;
|
||||
QByteArray buffer(AUDIO_BUFFER, 0);
|
||||
qint64 len = (testFormats.at(i).sampleRate()*testFormats.at(i).channelCount()*(testFormats.at(i).sampleSize()/8)); // 1 seconds
|
||||
qint64 len = (audioFormat.sampleRate()*audioFormat.channelCount()*(audioFormat.sampleSize()/8)); // 1 seconds
|
||||
while (totalBytesRead < len) {
|
||||
if (audioInput.bytesReady() >= audioInput.periodSize()) {
|
||||
qint64 bytesRead = feed->read(buffer.data(), audioInput.periodSize());
|
||||
audioFiles.at(i)->write(buffer.constData(),bytesRead);
|
||||
audioFile->write(buffer.constData(),bytesRead);
|
||||
totalBytesRead+=bytesRead;
|
||||
if (firstBuffer && bytesRead) {
|
||||
// Check for transition to ActiveState when data is provided
|
||||
@@ -773,7 +788,7 @@ void tst_QAudioInput::pushSuspendResume()
|
||||
while (totalBytesRead < len) {
|
||||
if (audioInput.bytesReady() >= audioInput.periodSize()) {
|
||||
qint64 bytesRead = feed->read(buffer.data(), audioInput.periodSize());
|
||||
audioFiles.at(i)->write(buffer.constData(),bytesRead);
|
||||
audioFile->write(buffer.constData(),bytesRead);
|
||||
totalBytesRead+=bytesRead;
|
||||
} else
|
||||
QTest::qWait(20);
|
||||
@@ -792,22 +807,17 @@ void tst_QAudioInput::pushSuspendResume()
|
||||
QString("processedUSecs() doesn't fall in acceptable range, should be 2040000 (%1)").arg(processedUs).toLocal8Bit().constData());
|
||||
QVERIFY2((audioInput.elapsedUSecs() == (qint64)0), "elapsedUSecs() not equal to zero in StoppedState");
|
||||
|
||||
WavHeader::writeDataLength(*audioFiles.at(i),audioFiles.at(i)->pos()-WavHeader::headerLength());
|
||||
audioFiles.at(i)->close();
|
||||
|
||||
// Only run first format in CI system to reduce test times
|
||||
if (m_inCISystem)
|
||||
break;
|
||||
}
|
||||
WavHeader::writeDataLength(*audioFile,audioFile->pos()-WavHeader::headerLength());
|
||||
audioFile->close();
|
||||
}
|
||||
|
||||
void tst_QAudioInput::reset()
|
||||
{
|
||||
for(int i=0; i<audioFiles.count(); i++) {
|
||||
QFETCH(QAudioFormat, audioFormat);
|
||||
|
||||
// Try both push/pull.. the vagaries of Active vs Idle are tested elsewhere
|
||||
{
|
||||
QAudioInput audioInput(testFormats.at(i), this);
|
||||
QAudioInput audioInput(audioFormat, this);
|
||||
|
||||
audioInput.setNotifyInterval(100);
|
||||
|
||||
@@ -839,7 +849,7 @@ void tst_QAudioInput::reset()
|
||||
}
|
||||
|
||||
{
|
||||
QAudioInput audioInput(testFormats.at(i), this);
|
||||
QAudioInput audioInput(audioFormat, this);
|
||||
QBuffer buffer;
|
||||
|
||||
audioInput.setNotifyInterval(100);
|
||||
@@ -866,19 +876,16 @@ void tst_QAudioInput::reset()
|
||||
QVERIFY2((audioInput.state() == QAudio::StoppedState), "didn't transitions to StoppedState after reset()");
|
||||
QVERIFY2((audioInput.bytesReady() == 0), "buffer not cleared after reset()");
|
||||
}
|
||||
// Only run first format in CI system to reduce test times
|
||||
if (m_inCISystem)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QAudioInput::volume()
|
||||
{
|
||||
QFETCH(QAudioFormat, audioFormat);
|
||||
|
||||
const qreal half(0.5f);
|
||||
const qreal one(1.0f);
|
||||
// Hard to automatically test, but we can test the get/set a little
|
||||
for (int i=0; i < testFormats.count(); i++) {
|
||||
QAudioInput audioInput(testFormats.at(i), this);
|
||||
|
||||
QAudioInput audioInput(audioFormat, this);
|
||||
|
||||
qreal volume = audioInput.volume();
|
||||
audioInput.setVolume(half);
|
||||
@@ -894,7 +901,6 @@ void tst_QAudioInput::volume()
|
||||
QTRY_VERIFY(qRound(audioInput.volume()*10.0f) == 10);
|
||||
|
||||
audioInput.setVolume(volume);
|
||||
}
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QAudioInput)
|
||||
|
||||
Reference in New Issue
Block a user