QAudioIn/Output-tests: Remove SRCDIR-macro/stabilize.
- Introduce QTemporaryDir to create a temporary directory to write the files, preventing file open failures caused by left-overs of failed tests. - Use smart pointers for files and QTemporaryDir to ensure that files and the directory are always cleaned up at destruction time. Change-Id: Icfbb331dbdd586012b5787f91c36e164033c4120 Reviewed-by: Michael Goddard <michael.goddard@nokia.com>
This commit is contained in:
committed by
Qt by Nokia
parent
093a3efbf3
commit
5dfb698016
@@ -6,7 +6,5 @@ CONFIG += no_private_qt_headers_warning
|
|||||||
# This is more of a system test
|
# This is more of a system test
|
||||||
# CONFIG += testcase
|
# CONFIG += testcase
|
||||||
|
|
||||||
DEFINES += SRCDIR=\\\"$$PWD/\\\"
|
|
||||||
|
|
||||||
HEADERS += wavheader.h
|
HEADERS += wavheader.h
|
||||||
SOURCES += wavheader.cpp tst_qaudioinput.cpp
|
SOURCES += wavheader.cpp tst_qaudioinput.cpp
|
||||||
|
|||||||
@@ -41,6 +41,9 @@
|
|||||||
|
|
||||||
#include <QtTest/QtTest>
|
#include <QtTest/QtTest>
|
||||||
#include <QtCore/qlocale.h>
|
#include <QtCore/qlocale.h>
|
||||||
|
#include <QtCore/QTemporaryDir>
|
||||||
|
#include <QtCore/QSharedPointer>
|
||||||
|
#include <QtCore/QScopedPointer>
|
||||||
|
|
||||||
#include <qaudioinput.h>
|
#include <qaudioinput.h>
|
||||||
#include <qaudiodeviceinfo.h>
|
#include <qaudiodeviceinfo.h>
|
||||||
@@ -98,15 +101,15 @@ private slots:
|
|||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
void cleanupTestCase();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
typedef QSharedPointer<QFile> FilePtr;
|
||||||
|
|
||||||
QString formatToFileName(const QAudioFormat &format);
|
QString formatToFileName(const QAudioFormat &format);
|
||||||
QString workingDir();
|
|
||||||
|
|
||||||
QAudioDeviceInfo audioDevice;
|
QAudioDeviceInfo audioDevice;
|
||||||
QList<QAudioFormat> testFormats;
|
QList<QAudioFormat> testFormats;
|
||||||
QList<QFile*> audioFiles;
|
QList<FilePtr> audioFiles;
|
||||||
|
QScopedPointer<QTemporaryDir> m_temporaryDir;
|
||||||
|
|
||||||
QScopedPointer<QByteArray> m_byteArray;
|
QScopedPointer<QByteArray> m_byteArray;
|
||||||
QScopedPointer<QBuffer> m_buffer;
|
QScopedPointer<QBuffer> m_buffer;
|
||||||
@@ -128,17 +131,6 @@ QString tst_QAudioInput::formatToFileName(const QAudioFormat &format)
|
|||||||
.arg(format.channels());
|
.arg(format.channels());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString tst_QAudioInput::workingDir()
|
|
||||||
{
|
|
||||||
QDir working(QString(SRCDIR));
|
|
||||||
|
|
||||||
if (working.exists())
|
|
||||||
return QString(SRCDIR);
|
|
||||||
|
|
||||||
return QDir::currentPath();
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QAudioInput::initTestCase()
|
void tst_QAudioInput::initTestCase()
|
||||||
{
|
{
|
||||||
qRegisterMetaType<QAudioFormat>();
|
qRegisterMetaType<QAudioFormat>();
|
||||||
@@ -197,9 +189,19 @@ void tst_QAudioInput::initTestCase()
|
|||||||
|
|
||||||
QVERIFY(testFormats.size());
|
QVERIFY(testFormats.size());
|
||||||
|
|
||||||
|
const QChar slash = QLatin1Char('/');
|
||||||
|
QString temporaryPattern = QDir::tempPath();
|
||||||
|
if (!temporaryPattern.endsWith(slash))
|
||||||
|
temporaryPattern += slash;
|
||||||
|
temporaryPattern += "tst_qaudioinputXXXXXX";
|
||||||
|
m_temporaryDir.reset(new QTemporaryDir(temporaryPattern));
|
||||||
|
m_temporaryDir->setAutoRemove(true);
|
||||||
|
QVERIFY(m_temporaryDir->isValid());
|
||||||
|
|
||||||
|
const QString temporaryAudioPath = m_temporaryDir->path() + slash;
|
||||||
foreach (const QAudioFormat &format, testFormats) {
|
foreach (const QAudioFormat &format, testFormats) {
|
||||||
QFile* file = new QFile(workingDir() + formatToFileName(format) + QString(".wav"));
|
const QString fileName = temporaryAudioPath + formatToFileName(format) + QStringLiteral(".wav");
|
||||||
audioFiles.append(file);
|
audioFiles.append(FilePtr(new QFile(fileName)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -343,13 +345,14 @@ void tst_QAudioInput::disableNotifyInterval()
|
|||||||
QAudioInput audioInputCheck(testFormats.at(0), this);
|
QAudioInput audioInputCheck(testFormats.at(0), this);
|
||||||
audioInputCheck.setNotifyInterval(0);
|
audioInputCheck.setNotifyInterval(0);
|
||||||
QSignalSpy notifySignal(&audioInputCheck, SIGNAL(notify()));
|
QSignalSpy notifySignal(&audioInputCheck, SIGNAL(notify()));
|
||||||
audioFiles.at(0)->open(QIODevice::WriteOnly);
|
QFile *audioFile = audioFiles.at(0).data();
|
||||||
audioInputCheck.start(audioFiles.at(0));
|
audioFile->open(QIODevice::WriteOnly);
|
||||||
|
audioInputCheck.start(audioFile);
|
||||||
QTest::qWait(3000); // 3 seconds should be plenty
|
QTest::qWait(3000); // 3 seconds should be plenty
|
||||||
audioInputCheck.stop();
|
audioInputCheck.stop();
|
||||||
QVERIFY2((notifySignal.count() == 0),
|
QVERIFY2((notifySignal.count() == 0),
|
||||||
QString("didn't disable notify interval: shouldn't have got any but got %1").arg(notifySignal.count()).toLocal8Bit().constData());
|
QString("didn't disable notify interval: shouldn't have got any but got %1").arg(notifySignal.count()).toLocal8Bit().constData());
|
||||||
audioFiles.at(0)->close();
|
audioFile->close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -417,6 +420,7 @@ void tst_QAudioInput::pull()
|
|||||||
{
|
{
|
||||||
for(int i=0; i<audioFiles.count(); i++) {
|
for(int i=0; i<audioFiles.count(); i++) {
|
||||||
QAudioInput audioInput(testFormats.at(i), this);
|
QAudioInput audioInput(testFormats.at(i), this);
|
||||||
|
QFile *audioFile = audioFiles.at(i).data();
|
||||||
|
|
||||||
audioInput.setNotifyInterval(100);
|
audioInput.setNotifyInterval(100);
|
||||||
|
|
||||||
@@ -428,12 +432,12 @@ void tst_QAudioInput::pull()
|
|||||||
QVERIFY2((audioInput.error() == QAudio::NoError), "error() was not set to QAudio::NoError before start()");
|
QVERIFY2((audioInput.error() == QAudio::NoError), "error() was not set to QAudio::NoError before start()");
|
||||||
QVERIFY2((audioInput.elapsedUSecs() == qint64(0)),"elapsedUSecs() not zero on creation");
|
QVERIFY2((audioInput.elapsedUSecs() == qint64(0)),"elapsedUSecs() not zero on creation");
|
||||||
|
|
||||||
audioFiles.at(i)->close();
|
audioFile->close();
|
||||||
audioFiles.at(i)->open(QIODevice::WriteOnly);
|
audioFile->open(QIODevice::WriteOnly);
|
||||||
WavHeader wavHeader(testFormats.at(i));
|
WavHeader wavHeader(testFormats.at(i));
|
||||||
QVERIFY(wavHeader.write(*audioFiles.at(i)));
|
QVERIFY(wavHeader.write(*audioFile));
|
||||||
|
|
||||||
audioInput.start(audioFiles.at(i));
|
audioInput.start(audioFile);
|
||||||
|
|
||||||
// Check that QAudioInput immediately transitions to ActiveState or IdleState
|
// Check that QAudioInput immediately transitions to ActiveState or IdleState
|
||||||
QTRY_VERIFY2((stateSignal.count() > 0),"didn't emit signals on start()");
|
QTRY_VERIFY2((stateSignal.count() > 0),"didn't emit signals on start()");
|
||||||
@@ -467,8 +471,8 @@ void tst_QAudioInput::pull()
|
|||||||
QVERIFY2((notifySignal.count() > 20 && notifySignal.count() < 40),
|
QVERIFY2((notifySignal.count() > 20 && notifySignal.count() < 40),
|
||||||
QString("notify() signals emitted (%1) should be 30").arg(notifySignal.count()).toLocal8Bit().constData());
|
QString("notify() signals emitted (%1) should be 30").arg(notifySignal.count()).toLocal8Bit().constData());
|
||||||
|
|
||||||
WavHeader::writeDataLength(*audioFiles.at(i),audioFiles.at(i)->pos()-WavHeader::headerLength());
|
WavHeader::writeDataLength(*audioFile, audioFile->pos() - WavHeader::headerLength());
|
||||||
audioFiles.at(i)->close();
|
audioFile->close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -476,6 +480,7 @@ void tst_QAudioInput::pullSuspendResume()
|
|||||||
{
|
{
|
||||||
for(int i=0; i<audioFiles.count(); i++) {
|
for(int i=0; i<audioFiles.count(); i++) {
|
||||||
QAudioInput audioInput(testFormats.at(i), this);
|
QAudioInput audioInput(testFormats.at(i), this);
|
||||||
|
QFile *audioFile = audioFiles.at(i).data();
|
||||||
|
|
||||||
audioInput.setNotifyInterval(100);
|
audioInput.setNotifyInterval(100);
|
||||||
|
|
||||||
@@ -492,7 +497,7 @@ void tst_QAudioInput::pullSuspendResume()
|
|||||||
WavHeader wavHeader(testFormats.at(i));
|
WavHeader wavHeader(testFormats.at(i));
|
||||||
QVERIFY(wavHeader.write(*audioFiles.at(i)));
|
QVERIFY(wavHeader.write(*audioFiles.at(i)));
|
||||||
|
|
||||||
audioInput.start(audioFiles.at(i));
|
audioInput.start(audioFile);
|
||||||
|
|
||||||
// Check that QAudioInput immediately transitions to ActiveState or IdleState
|
// Check that QAudioInput immediately transitions to ActiveState or IdleState
|
||||||
QTRY_VERIFY2((stateSignal.count() > 0),"didn't emit signals on start()");
|
QTRY_VERIFY2((stateSignal.count() > 0),"didn't emit signals on start()");
|
||||||
@@ -561,7 +566,7 @@ void tst_QAudioInput::pullSuspendResume()
|
|||||||
QString("notify() signals emitted (%1) should be 30").arg(notifySignal.count()).toLocal8Bit().constData());
|
QString("notify() signals emitted (%1) should be 30").arg(notifySignal.count()).toLocal8Bit().constData());
|
||||||
|
|
||||||
WavHeader::writeDataLength(*audioFiles.at(i),audioFiles.at(i)->pos()-WavHeader::headerLength());
|
WavHeader::writeDataLength(*audioFiles.at(i),audioFiles.at(i)->pos()-WavHeader::headerLength());
|
||||||
audioFiles.at(i)->close();
|
audioFile->close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -835,16 +840,6 @@ void tst_QAudioInput::reset()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QAudioInput::cleanupTestCase()
|
|
||||||
{
|
|
||||||
QFile* file;
|
|
||||||
|
|
||||||
foreach (file, audioFiles) {
|
|
||||||
file->remove();
|
|
||||||
delete file;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QTEST_MAIN(tst_QAudioInput)
|
QTEST_MAIN(tst_QAudioInput)
|
||||||
|
|
||||||
#include "tst_qaudioinput.moc"
|
#include "tst_qaudioinput.moc"
|
||||||
|
|||||||
@@ -6,7 +6,5 @@ CONFIG += no_private_qt_headers_warning
|
|||||||
# This is more of a system test
|
# This is more of a system test
|
||||||
# CONFIG += testcase
|
# CONFIG += testcase
|
||||||
|
|
||||||
DEFINES += SRCDIR=\\\"$$PWD/\\\"
|
|
||||||
|
|
||||||
HEADERS += wavheader.h
|
HEADERS += wavheader.h
|
||||||
SOURCES += wavheader.cpp tst_qaudiooutput.cpp
|
SOURCES += wavheader.cpp tst_qaudiooutput.cpp
|
||||||
|
|||||||
@@ -43,6 +43,9 @@
|
|||||||
|
|
||||||
#include <QtTest/QtTest>
|
#include <QtTest/QtTest>
|
||||||
#include <QtCore/qlocale.h>
|
#include <QtCore/qlocale.h>
|
||||||
|
#include <QtCore/QTemporaryDir>
|
||||||
|
#include <QtCore/QSharedPointer>
|
||||||
|
#include <QtCore/QScopedPointer>
|
||||||
|
|
||||||
#include <qaudiooutput.h>
|
#include <qaudiooutput.h>
|
||||||
#include <qaudiodeviceinfo.h>
|
#include <qaudiodeviceinfo.h>
|
||||||
@@ -97,16 +100,16 @@ private slots:
|
|||||||
void pushSuspendResume();
|
void pushSuspendResume();
|
||||||
void pushUnderrun();
|
void pushUnderrun();
|
||||||
|
|
||||||
void cleanupTestCase();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
typedef QSharedPointer<QFile> FilePtr;
|
||||||
|
|
||||||
QString formatToFileName(const QAudioFormat &format);
|
QString formatToFileName(const QAudioFormat &format);
|
||||||
QString workingDir();
|
|
||||||
void createSineWaveData(const QAudioFormat &format, qint64 length, int frequency = 440);
|
void createSineWaveData(const QAudioFormat &format, qint64 length, int frequency = 440);
|
||||||
|
|
||||||
QAudioDeviceInfo audioDevice;
|
QAudioDeviceInfo audioDevice;
|
||||||
QList<QAudioFormat> testFormats;
|
QList<QAudioFormat> testFormats;
|
||||||
QList<QFile*> audioFiles;
|
QList<FilePtr> audioFiles;
|
||||||
|
QScopedPointer<QTemporaryDir> m_temporaryDir;
|
||||||
|
|
||||||
QScopedPointer<QByteArray> m_byteArray;
|
QScopedPointer<QByteArray> m_byteArray;
|
||||||
QScopedPointer<QBuffer> m_buffer;
|
QScopedPointer<QBuffer> m_buffer;
|
||||||
@@ -128,17 +131,6 @@ QString tst_QAudioOutput::formatToFileName(const QAudioFormat &format)
|
|||||||
.arg(format.channels());
|
.arg(format.channels());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString tst_QAudioOutput::workingDir()
|
|
||||||
{
|
|
||||||
QDir working(QString(SRCDIR));
|
|
||||||
|
|
||||||
if (working.exists())
|
|
||||||
return QString(SRCDIR);
|
|
||||||
|
|
||||||
return QDir::currentPath();
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QAudioOutput::createSineWaveData(const QAudioFormat &format, qint64 length, int frequency)
|
void tst_QAudioOutput::createSineWaveData(const QAudioFormat &format, qint64 length, int frequency)
|
||||||
{
|
{
|
||||||
const int channelBytes = format.sampleSize() / 8;
|
const int channelBytes = format.sampleSize() / 8;
|
||||||
@@ -242,19 +234,30 @@ void tst_QAudioOutput::initTestCase()
|
|||||||
|
|
||||||
QVERIFY(testFormats.size());
|
QVERIFY(testFormats.size());
|
||||||
|
|
||||||
|
const QChar slash = QLatin1Char('/');
|
||||||
|
QString temporaryPattern = QDir::tempPath();
|
||||||
|
if (!temporaryPattern.endsWith(slash))
|
||||||
|
temporaryPattern += slash;
|
||||||
|
temporaryPattern += "tst_qaudiooutputXXXXXX";
|
||||||
|
m_temporaryDir.reset(new QTemporaryDir(temporaryPattern));
|
||||||
|
m_temporaryDir->setAutoRemove(true);
|
||||||
|
QVERIFY(m_temporaryDir->isValid());
|
||||||
|
|
||||||
|
const QString temporaryAudioPath = m_temporaryDir->path() + slash;
|
||||||
foreach (const QAudioFormat &format, testFormats) {
|
foreach (const QAudioFormat &format, testFormats) {
|
||||||
qint64 len = (format.frequency()*format.channels()*(format.sampleSize()/8)*2); // 2 seconds
|
qint64 len = (format.frequency()*format.channels()*(format.sampleSize()/8)*2); // 2 seconds
|
||||||
createSineWaveData(format, len);
|
createSineWaveData(format, len);
|
||||||
// Write generate sine wave data to file
|
// Write generate sine wave data to file
|
||||||
QFile* file = new QFile(workingDir() + QString("generated") + formatToFileName(format) + QString(".wav"));
|
const QString fileName = temporaryAudioPath + QStringLiteral("generated")
|
||||||
if (file->open(QIODevice::WriteOnly)) {
|
+ formatToFileName(format) + QStringLiteral(".wav");
|
||||||
|
FilePtr file(new QFile(fileName));
|
||||||
|
QVERIFY2(file->open(QIODevice::WriteOnly), qPrintable(file->errorString()));
|
||||||
WavHeader wavHeader(format, len);
|
WavHeader wavHeader(format, len);
|
||||||
wavHeader.write(*file);
|
wavHeader.write(*file.data());
|
||||||
file->write(m_byteArray->data(), len);
|
file->write(m_byteArray->data(), len);
|
||||||
file->close();
|
file->close();
|
||||||
audioFiles.append(file);
|
audioFiles.append(file);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QAudioOutput::format()
|
void tst_QAudioOutput::format()
|
||||||
@@ -396,13 +399,14 @@ void tst_QAudioOutput::disableNotifyInterval()
|
|||||||
QAudioOutput audioOutputCheck(testFormats.at(0), this);
|
QAudioOutput audioOutputCheck(testFormats.at(0), this);
|
||||||
audioOutputCheck.setNotifyInterval(0);
|
audioOutputCheck.setNotifyInterval(0);
|
||||||
QSignalSpy notifySignal(&audioOutputCheck, SIGNAL(notify()));
|
QSignalSpy notifySignal(&audioOutputCheck, SIGNAL(notify()));
|
||||||
audioFiles.at(0)->open(QIODevice::ReadOnly);
|
QFile *audioFile = audioFiles.at(0).data();
|
||||||
audioOutputCheck.start(audioFiles.at(0));
|
audioFile->open(QIODevice::ReadOnly);
|
||||||
|
audioOutputCheck.start(audioFile);
|
||||||
QTest::qWait(3000); // 3 seconds should be plenty
|
QTest::qWait(3000); // 3 seconds should be plenty
|
||||||
audioOutputCheck.stop();
|
audioOutputCheck.stop();
|
||||||
QVERIFY2((notifySignal.count() == 0),
|
QVERIFY2((notifySignal.count() == 0),
|
||||||
QString("didn't disable notify interval: shouldn't have got any but got %1").arg(notifySignal.count()).toLocal8Bit().constData());
|
QString("didn't disable notify interval: shouldn't have got any but got %1").arg(notifySignal.count()).toLocal8Bit().constData());
|
||||||
audioFiles.at(0)->close();
|
audioFile->close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -481,11 +485,12 @@ void tst_QAudioOutput::pull()
|
|||||||
QVERIFY2((audioOutput.error() == QAudio::NoError), "error() was not set to QAudio::NoError before start()");
|
QVERIFY2((audioOutput.error() == QAudio::NoError), "error() was not set to QAudio::NoError before start()");
|
||||||
QVERIFY2((audioOutput.elapsedUSecs() == qint64(0)),"elapsedUSecs() not zero on creation");
|
QVERIFY2((audioOutput.elapsedUSecs() == qint64(0)),"elapsedUSecs() not zero on creation");
|
||||||
|
|
||||||
audioFiles.at(i)->close();
|
QFile *audioFile = audioFiles.at(i).data();
|
||||||
audioFiles.at(i)->open(QIODevice::ReadOnly);
|
audioFile->close();
|
||||||
audioFiles.at(i)->seek(WavHeader::headerLength());
|
audioFile->open(QIODevice::ReadOnly);
|
||||||
|
audioFile->seek(WavHeader::headerLength());
|
||||||
|
|
||||||
audioOutput.start(audioFiles.at(i));
|
audioOutput.start(audioFile);
|
||||||
|
|
||||||
// Check that QAudioOutput immediately transitions to ActiveState
|
// Check that QAudioOutput immediately transitions to ActiveState
|
||||||
QTRY_VERIFY2((stateSignal.count() == 1),
|
QTRY_VERIFY2((stateSignal.count() == 1),
|
||||||
@@ -502,7 +507,7 @@ void tst_QAudioOutput::pull()
|
|||||||
// Wait until playback finishes
|
// Wait until playback finishes
|
||||||
QTest::qWait(3000); // 3 seconds should be plenty
|
QTest::qWait(3000); // 3 seconds should be plenty
|
||||||
|
|
||||||
QVERIFY2(audioFiles.at(i)->atEnd(), "didn't play to EOF");
|
QVERIFY2(audioFile->atEnd(), "didn't play to EOF");
|
||||||
QVERIFY2((stateSignal.count() == 1),
|
QVERIFY2((stateSignal.count() == 1),
|
||||||
QString("didn't emit IdleState signal when at EOF, got %1 signals instead").arg(stateSignal.count()).toLocal8Bit().constData());
|
QString("didn't emit IdleState signal when at EOF, got %1 signals instead").arg(stateSignal.count()).toLocal8Bit().constData());
|
||||||
QVERIFY2((audioOutput.state() == QAudio::IdleState), "didn't transitions to IdleState when at EOF");
|
QVERIFY2((audioOutput.state() == QAudio::IdleState), "didn't transitions to IdleState when at EOF");
|
||||||
@@ -523,7 +528,7 @@ void tst_QAudioOutput::pull()
|
|||||||
QVERIFY2((notifySignal.count() > 15 && notifySignal.count() < 25),
|
QVERIFY2((notifySignal.count() > 15 && notifySignal.count() < 25),
|
||||||
QString("too many notify() signals emitted (%1)").arg(notifySignal.count()).toLocal8Bit().constData());
|
QString("too many notify() signals emitted (%1)").arg(notifySignal.count()).toLocal8Bit().constData());
|
||||||
|
|
||||||
audioFiles.at(i)->close();
|
audioFile->close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -542,11 +547,12 @@ void tst_QAudioOutput::pullSuspendResume()
|
|||||||
QVERIFY2((audioOutput.error() == QAudio::NoError), "error() was not set to QAudio::NoError before start()");
|
QVERIFY2((audioOutput.error() == QAudio::NoError), "error() was not set to QAudio::NoError before start()");
|
||||||
QVERIFY2((audioOutput.elapsedUSecs() == qint64(0)),"elapsedUSecs() not zero on creation");
|
QVERIFY2((audioOutput.elapsedUSecs() == qint64(0)),"elapsedUSecs() not zero on creation");
|
||||||
|
|
||||||
audioFiles.at(i)->close();
|
QFile *audioFile = audioFiles.at(i).data();
|
||||||
audioFiles.at(i)->open(QIODevice::ReadOnly);
|
audioFile->close();
|
||||||
audioFiles.at(i)->seek(WavHeader::headerLength());
|
audioFile->open(QIODevice::ReadOnly);
|
||||||
|
audioFile->seek(WavHeader::headerLength());
|
||||||
|
|
||||||
audioOutput.start(audioFiles.at(i));
|
audioOutput.start(audioFile);
|
||||||
// Check that QAudioOutput immediately transitions to ActiveState
|
// Check that QAudioOutput immediately transitions to ActiveState
|
||||||
QTRY_VERIFY2((stateSignal.count() == 1),
|
QTRY_VERIFY2((stateSignal.count() == 1),
|
||||||
QString("didn't emit signal on start(), got %1 signals instead").arg(stateSignal.count()).toLocal8Bit().constData());
|
QString("didn't emit signal on start(), got %1 signals instead").arg(stateSignal.count()).toLocal8Bit().constData());
|
||||||
@@ -592,7 +598,7 @@ void tst_QAudioOutput::pullSuspendResume()
|
|||||||
// Wait until playback finishes
|
// Wait until playback finishes
|
||||||
QTest::qWait(3000); // 3 seconds should be plenty
|
QTest::qWait(3000); // 3 seconds should be plenty
|
||||||
|
|
||||||
QVERIFY2(audioFiles.at(i)->atEnd(), "didn't play to EOF");
|
QVERIFY2(audioFile->atEnd(), "didn't play to EOF");
|
||||||
QVERIFY2((stateSignal.count() == 1),
|
QVERIFY2((stateSignal.count() == 1),
|
||||||
QString("didn't emit IdleState signal when at EOF, got %1 signals instead").arg(stateSignal.count()).toLocal8Bit().constData());
|
QString("didn't emit IdleState signal when at EOF, got %1 signals instead").arg(stateSignal.count()).toLocal8Bit().constData());
|
||||||
QVERIFY2((audioOutput.state() == QAudio::IdleState), "didn't transitions to IdleState when at EOF");
|
QVERIFY2((audioOutput.state() == QAudio::IdleState), "didn't transitions to IdleState when at EOF");
|
||||||
@@ -611,7 +617,7 @@ void tst_QAudioOutput::pullSuspendResume()
|
|||||||
QVERIFY2((audioOutput.error() == QAudio::NoError), "error() is not QAudio::NoError after stop()");
|
QVERIFY2((audioOutput.error() == QAudio::NoError), "error() is not QAudio::NoError after stop()");
|
||||||
QVERIFY2((audioOutput.elapsedUSecs() == (qint64)0), "elapsedUSecs() not equal to zero in StoppedState");
|
QVERIFY2((audioOutput.elapsedUSecs() == (qint64)0), "elapsedUSecs() not equal to zero in StoppedState");
|
||||||
|
|
||||||
audioFiles.at(i)->close();
|
audioFile->close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -630,9 +636,10 @@ void tst_QAudioOutput::push()
|
|||||||
QVERIFY2((audioOutput.error() == QAudio::NoError), "error() was not set to QAudio::NoError before start()");
|
QVERIFY2((audioOutput.error() == QAudio::NoError), "error() was not set to QAudio::NoError before start()");
|
||||||
QVERIFY2((audioOutput.elapsedUSecs() == qint64(0)),"elapsedUSecs() not zero on creation");
|
QVERIFY2((audioOutput.elapsedUSecs() == qint64(0)),"elapsedUSecs() not zero on creation");
|
||||||
|
|
||||||
audioFiles.at(i)->close();
|
QFile *audioFile = audioFiles.at(i).data();
|
||||||
audioFiles.at(i)->open(QIODevice::ReadOnly);
|
audioFile->close();
|
||||||
audioFiles.at(i)->seek(WavHeader::headerLength());
|
audioFile->open(QIODevice::ReadOnly);
|
||||||
|
audioFile->seek(WavHeader::headerLength());
|
||||||
|
|
||||||
QIODevice* feed = audioOutput.start();
|
QIODevice* feed = audioOutput.start();
|
||||||
|
|
||||||
@@ -653,10 +660,10 @@ void tst_QAudioOutput::push()
|
|||||||
bool firstBuffer = true;
|
bool firstBuffer = true;
|
||||||
QByteArray buffer(AUDIO_BUFFER, 0);
|
QByteArray buffer(AUDIO_BUFFER, 0);
|
||||||
|
|
||||||
while (written < audioFiles.at(i)->size()-WavHeader::headerLength()) {
|
while (written < audioFile->size()-WavHeader::headerLength()) {
|
||||||
|
|
||||||
if (audioOutput.bytesFree() >= audioOutput.periodSize()) {
|
if (audioOutput.bytesFree() >= audioOutput.periodSize()) {
|
||||||
qint64 len = audioFiles.at(i)->read(buffer.data(),audioOutput.periodSize());
|
qint64 len = audioFile->read(buffer.data(),audioOutput.periodSize());
|
||||||
written += feed->write(buffer.constData(), len);
|
written += feed->write(buffer.constData(), len);
|
||||||
|
|
||||||
if (firstBuffer) {
|
if (firstBuffer) {
|
||||||
@@ -676,7 +683,7 @@ void tst_QAudioOutput::push()
|
|||||||
// Wait until playback finishes
|
// Wait until playback finishes
|
||||||
QTest::qWait(3000); // 3 seconds should be plenty
|
QTest::qWait(3000); // 3 seconds should be plenty
|
||||||
|
|
||||||
QVERIFY2(audioFiles.at(i)->atEnd(), "didn't play to EOF");
|
QVERIFY2(audioFile->atEnd(), "didn't play to EOF");
|
||||||
QVERIFY2((stateSignal.count() == 1),
|
QVERIFY2((stateSignal.count() == 1),
|
||||||
QString("didn't emit IdleState signal when at EOF, got %1 signals instead").arg(stateSignal.count()).toLocal8Bit().constData());
|
QString("didn't emit IdleState signal when at EOF, got %1 signals instead").arg(stateSignal.count()).toLocal8Bit().constData());
|
||||||
QVERIFY2((audioOutput.state() == QAudio::IdleState), "didn't transitions to IdleState when at EOF");
|
QVERIFY2((audioOutput.state() == QAudio::IdleState), "didn't transitions to IdleState when at EOF");
|
||||||
@@ -697,7 +704,7 @@ void tst_QAudioOutput::push()
|
|||||||
QVERIFY2((notifySignal.count() > 15 && notifySignal.count() < 25),
|
QVERIFY2((notifySignal.count() > 15 && notifySignal.count() < 25),
|
||||||
QString("too many notify() signals emitted (%1)").arg(notifySignal.count()).toLocal8Bit().constData());
|
QString("too many notify() signals emitted (%1)").arg(notifySignal.count()).toLocal8Bit().constData());
|
||||||
|
|
||||||
audioFiles.at(i)->close();
|
audioFile->close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -716,9 +723,10 @@ void tst_QAudioOutput::pushSuspendResume()
|
|||||||
QVERIFY2((audioOutput.error() == QAudio::NoError), "error() was not set to QAudio::NoError before start()");
|
QVERIFY2((audioOutput.error() == QAudio::NoError), "error() was not set to QAudio::NoError before start()");
|
||||||
QVERIFY2((audioOutput.elapsedUSecs() == qint64(0)),"elapsedUSecs() not zero on creation");
|
QVERIFY2((audioOutput.elapsedUSecs() == qint64(0)),"elapsedUSecs() not zero on creation");
|
||||||
|
|
||||||
audioFiles.at(i)->close();
|
QFile *audioFile = audioFiles.at(i).data();
|
||||||
audioFiles.at(i)->open(QIODevice::ReadOnly);
|
audioFile->close();
|
||||||
audioFiles.at(i)->seek(WavHeader::headerLength());
|
audioFile->open(QIODevice::ReadOnly);
|
||||||
|
audioFile->seek(WavHeader::headerLength());
|
||||||
|
|
||||||
QIODevice* feed = audioOutput.start();
|
QIODevice* feed = audioOutput.start();
|
||||||
|
|
||||||
@@ -740,10 +748,10 @@ void tst_QAudioOutput::pushSuspendResume()
|
|||||||
QByteArray buffer(AUDIO_BUFFER, 0);
|
QByteArray buffer(AUDIO_BUFFER, 0);
|
||||||
|
|
||||||
// Play half of the clip
|
// Play half of the clip
|
||||||
while (written < (audioFiles.at(i)->size()-WavHeader::headerLength())/2) {
|
while (written < (audioFile->size()-WavHeader::headerLength())/2) {
|
||||||
|
|
||||||
if (audioOutput.bytesFree() >= audioOutput.periodSize()) {
|
if (audioOutput.bytesFree() >= audioOutput.periodSize()) {
|
||||||
qint64 len = audioFiles.at(i)->read(buffer.data(),audioOutput.periodSize());
|
qint64 len = audioFile->read(buffer.data(),audioOutput.periodSize());
|
||||||
written += feed->write(buffer.constData(), len);
|
written += feed->write(buffer.constData(), len);
|
||||||
|
|
||||||
if (firstBuffer) {
|
if (firstBuffer) {
|
||||||
@@ -792,9 +800,9 @@ void tst_QAudioOutput::pushSuspendResume()
|
|||||||
stateSignal.clear();
|
stateSignal.clear();
|
||||||
|
|
||||||
// Play rest of the clip
|
// Play rest of the clip
|
||||||
while (!audioFiles.at(i)->atEnd()) {
|
while (!audioFile->atEnd()) {
|
||||||
if (audioOutput.bytesFree() >= audioOutput.periodSize()) {
|
if (audioOutput.bytesFree() >= audioOutput.periodSize()) {
|
||||||
qint64 len = audioFiles.at(i)->read(buffer.data(),audioOutput.periodSize());
|
qint64 len = audioFile->read(buffer.data(),audioOutput.periodSize());
|
||||||
written += feed->write(buffer.constData(), len);
|
written += feed->write(buffer.constData(), len);
|
||||||
} else
|
} else
|
||||||
QTest::qWait(20);
|
QTest::qWait(20);
|
||||||
@@ -804,7 +812,7 @@ void tst_QAudioOutput::pushSuspendResume()
|
|||||||
// Wait until playback finishes
|
// Wait until playback finishes
|
||||||
QTest::qWait(1000); // 1 seconds should be plenty
|
QTest::qWait(1000); // 1 seconds should be plenty
|
||||||
|
|
||||||
QVERIFY2(audioFiles.at(i)->atEnd(), "didn't play to EOF");
|
QVERIFY2(audioFile->atEnd(), "didn't play to EOF");
|
||||||
QVERIFY2((stateSignal.count() == 1),
|
QVERIFY2((stateSignal.count() == 1),
|
||||||
QString("didn't emit IdleState signal when at EOF, got %1 signals instead").arg(stateSignal.count()).toLocal8Bit().constData());
|
QString("didn't emit IdleState signal when at EOF, got %1 signals instead").arg(stateSignal.count()).toLocal8Bit().constData());
|
||||||
QVERIFY2((audioOutput.state() == QAudio::IdleState), "didn't transitions to IdleState when at EOF");
|
QVERIFY2((audioOutput.state() == QAudio::IdleState), "didn't transitions to IdleState when at EOF");
|
||||||
@@ -823,7 +831,7 @@ void tst_QAudioOutput::pushSuspendResume()
|
|||||||
QVERIFY2((audioOutput.error() == QAudio::NoError), "error() is not QAudio::NoError after stop()");
|
QVERIFY2((audioOutput.error() == QAudio::NoError), "error() is not QAudio::NoError after stop()");
|
||||||
QVERIFY2((audioOutput.elapsedUSecs() == (qint64)0), "elapsedUSecs() not equal to zero in StoppedState");
|
QVERIFY2((audioOutput.elapsedUSecs() == (qint64)0), "elapsedUSecs() not equal to zero in StoppedState");
|
||||||
|
|
||||||
audioFiles.at(i)->close();
|
audioFile->close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -842,9 +850,10 @@ void tst_QAudioOutput::pushUnderrun()
|
|||||||
QVERIFY2((audioOutput.error() == QAudio::NoError), "error() was not set to QAudio::NoError before start()");
|
QVERIFY2((audioOutput.error() == QAudio::NoError), "error() was not set to QAudio::NoError before start()");
|
||||||
QVERIFY2((audioOutput.elapsedUSecs() == qint64(0)),"elapsedUSecs() not zero on creation");
|
QVERIFY2((audioOutput.elapsedUSecs() == qint64(0)),"elapsedUSecs() not zero on creation");
|
||||||
|
|
||||||
audioFiles.at(i)->close();
|
QFile *audioFile = audioFiles.at(i).data();
|
||||||
audioFiles.at(i)->open(QIODevice::ReadOnly);
|
audioFile->close();
|
||||||
audioFiles.at(i)->seek(WavHeader::headerLength());
|
audioFile->open(QIODevice::ReadOnly);
|
||||||
|
audioFile->seek(WavHeader::headerLength());
|
||||||
|
|
||||||
QIODevice* feed = audioOutput.start();
|
QIODevice* feed = audioOutput.start();
|
||||||
|
|
||||||
@@ -866,10 +875,10 @@ void tst_QAudioOutput::pushUnderrun()
|
|||||||
QByteArray buffer(AUDIO_BUFFER, 0);
|
QByteArray buffer(AUDIO_BUFFER, 0);
|
||||||
|
|
||||||
// Play half of the clip
|
// Play half of the clip
|
||||||
while (written < (audioFiles.at(i)->size()-WavHeader::headerLength())/2) {
|
while (written < (audioFile->size()-WavHeader::headerLength())/2) {
|
||||||
|
|
||||||
if (audioOutput.bytesFree() >= audioOutput.periodSize()) {
|
if (audioOutput.bytesFree() >= audioOutput.periodSize()) {
|
||||||
qint64 len = audioFiles.at(i)->read(buffer.data(),audioOutput.periodSize());
|
qint64 len = audioFile->read(buffer.data(),audioOutput.periodSize());
|
||||||
written += feed->write(buffer.constData(), len);
|
written += feed->write(buffer.constData(), len);
|
||||||
|
|
||||||
if (firstBuffer) {
|
if (firstBuffer) {
|
||||||
@@ -898,9 +907,9 @@ void tst_QAudioOutput::pushUnderrun()
|
|||||||
|
|
||||||
firstBuffer = true;
|
firstBuffer = true;
|
||||||
// Play rest of the clip
|
// Play rest of the clip
|
||||||
while (!audioFiles.at(i)->atEnd()) {
|
while (!audioFile->atEnd()) {
|
||||||
if (audioOutput.bytesFree() >= audioOutput.periodSize()) {
|
if (audioOutput.bytesFree() >= audioOutput.periodSize()) {
|
||||||
qint64 len = audioFiles.at(i)->read(buffer.data(),audioOutput.periodSize());
|
qint64 len = audioFile->read(buffer.data(),audioOutput.periodSize());
|
||||||
written += feed->write(buffer.constData(), len);
|
written += feed->write(buffer.constData(), len);
|
||||||
if (firstBuffer) {
|
if (firstBuffer) {
|
||||||
// Check for transition to ActiveState when data is provided
|
// Check for transition to ActiveState when data is provided
|
||||||
@@ -919,7 +928,7 @@ void tst_QAudioOutput::pushUnderrun()
|
|||||||
// Wait until playback finishes
|
// Wait until playback finishes
|
||||||
QTest::qWait(1000); // 1 seconds should be plenty
|
QTest::qWait(1000); // 1 seconds should be plenty
|
||||||
|
|
||||||
QVERIFY2(audioFiles.at(i)->atEnd(), "didn't play to EOF");
|
QVERIFY2(audioFile->atEnd(), "didn't play to EOF");
|
||||||
QVERIFY2((stateSignal.count() == 1),
|
QVERIFY2((stateSignal.count() == 1),
|
||||||
QString("didn't emit IdleState signal when at EOF, got %1 signals instead").arg(stateSignal.count()).toLocal8Bit().constData());
|
QString("didn't emit IdleState signal when at EOF, got %1 signals instead").arg(stateSignal.count()).toLocal8Bit().constData());
|
||||||
QVERIFY2((audioOutput.state() == QAudio::IdleState), "didn't transitions to IdleState when at EOF");
|
QVERIFY2((audioOutput.state() == QAudio::IdleState), "didn't transitions to IdleState when at EOF");
|
||||||
@@ -938,17 +947,7 @@ void tst_QAudioOutput::pushUnderrun()
|
|||||||
QVERIFY2((audioOutput.error() == QAudio::NoError), "error() is not QAudio::NoError after stop()");
|
QVERIFY2((audioOutput.error() == QAudio::NoError), "error() is not QAudio::NoError after stop()");
|
||||||
QVERIFY2((audioOutput.elapsedUSecs() == (qint64)0), "elapsedUSecs() not equal to zero in StoppedState");
|
QVERIFY2((audioOutput.elapsedUSecs() == (qint64)0), "elapsedUSecs() not equal to zero in StoppedState");
|
||||||
|
|
||||||
audioFiles.at(i)->close();
|
audioFile->close();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QAudioOutput::cleanupTestCase()
|
|
||||||
{
|
|
||||||
QFile* file;
|
|
||||||
|
|
||||||
foreach (file, audioFiles) {
|
|
||||||
file->remove();
|
|
||||||
delete file;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user