diff options
Diffstat (limited to 'tests/auto/unit/qaudiodecoder')
-rw-r--r-- | tests/auto/unit/qaudiodecoder/qaudiodecoder.pro | 22 | ||||
-rw-r--r-- | tests/auto/unit/qaudiodecoder/tst_qaudiodecoder.cpp | 306 |
2 files changed, 328 insertions, 0 deletions
diff --git a/tests/auto/unit/qaudiodecoder/qaudiodecoder.pro b/tests/auto/unit/qaudiodecoder/qaudiodecoder.pro new file mode 100644 index 000000000..5b189522f --- /dev/null +++ b/tests/auto/unit/qaudiodecoder/qaudiodecoder.pro @@ -0,0 +1,22 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2012-02-07T15:27:07 +# +#------------------------------------------------- + +QT += multimedia multimedia-private testlib gui + +TARGET = tst_qaudiodecoder + +CONFIG += testcase no_private_qt_headers_warning + +TEMPLATE = app + +INCLUDEPATH += \ + ../../../../src/multimedia/audio + +include (../qmultimedia_common/mock.pri) +include (../qmultimedia_common/mockdecoder.pri) + +SOURCES += tst_qaudiodecoder.cpp +DEFINES += SRCDIR=\\\"$$PWD/\\\" diff --git a/tests/auto/unit/qaudiodecoder/tst_qaudiodecoder.cpp b/tests/auto/unit/qaudiodecoder/tst_qaudiodecoder.cpp new file mode 100644 index 000000000..aacc607f9 --- /dev/null +++ b/tests/auto/unit/qaudiodecoder/tst_qaudiodecoder.cpp @@ -0,0 +1,306 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include <QtCore/QString> +#include <QtTest/QtTest> + +#include "qaudiodecoder_p.h" +#include "mockaudiodecoderservice.h" +#include "mockmediaserviceprovider.h" + +class tst_QAudioDecoder : public QObject +{ + Q_OBJECT + +public: + tst_QAudioDecoder(); + +private Q_SLOTS: + void init(); + void ctors(); + void read(); + void stop(); + void format(); + void source(); + +private: + MockAudioDecoderService *mockAudioDecoderService; + MockMediaServiceProvider *mockProvider; +}; + +tst_QAudioDecoder::tst_QAudioDecoder() +{ +} + +void tst_QAudioDecoder::init() +{ + mockAudioDecoderService = new MockAudioDecoderService(this); + mockProvider = new MockMediaServiceProvider(mockAudioDecoderService); + + QMediaServiceProvider::setDefaultServiceProvider(mockProvider); +} + +void tst_QAudioDecoder::ctors() +{ + QAudioDecoder d; + QVERIFY(d.state() == QAudioDecoder::StoppedState); + QVERIFY(d.bufferAvailable() == false); + QCOMPARE(d.sourceFilename(), QString("")); + + d.setSourceFilename(""); + QVERIFY(d.state() == QAudioDecoder::StoppedState); + QVERIFY(d.bufferAvailable() == false); + QCOMPARE(d.sourceFilename(), QString("")); +} + +void tst_QAudioDecoder::read() +{ + QAudioDecoder d; + QVERIFY(d.state() == QAudioDecoder::StoppedState); + QVERIFY(d.bufferAvailable() == false); + + QSignalSpy readySpy(&d, SIGNAL(bufferReady())); + QSignalSpy bufferChangedSpy(&d, SIGNAL(bufferAvailableChanged(bool))); + QSignalSpy errorSpy(&d, SIGNAL(error(QAudioDecoder::Error))); + + // Starting with empty source == error + d.start(); + + QVERIFY(d.state() == QAudioDecoder::StoppedState); + QVERIFY(d.bufferAvailable() == false); + + QCOMPARE(readySpy.count(), 0); + QCOMPARE(bufferChangedSpy.count(), 0); + QCOMPARE(errorSpy.count(), 1); + + // Set the source to something + d.setSourceFilename("Blah"); + QCOMPARE(d.sourceFilename(), QString("Blah")); + + readySpy.clear(); + errorSpy.clear(); + bufferChangedSpy.clear(); + + d.start(); + QCOMPARE(d.state(), QAudioDecoder::DecodingState); + QCOMPARE(d.bufferAvailable(), false); // not yet + + // Try to read + bool ok = false; + QAudioBuffer b = d.read(&ok); + + QVERIFY(ok == false); + QVERIFY(!b.isValid()); + + // Read again with no parameter + b = d.read(); + QVERIFY(!b.isValid()); + + // Wait a while + QTRY_COMPARE(d.bufferAvailable(), 1); + + QVERIFY(d.bufferAvailable()); + + b = d.read(&ok); + QVERIFY(b.format().isValid()); + QVERIFY(b.isValid()); + QVERIFY(b.format().channelCount() == 1); + QVERIFY(b.sampleCount() == 4); + + QVERIFY(readySpy.count() >= 1); + QVERIFY(errorSpy.count() == 0); + + if (d.bufferAvailable()) { + QVERIFY(bufferChangedSpy.count() == 1); + } else { + QVERIFY(bufferChangedSpy.count() == 2); + } +} + +void tst_QAudioDecoder::stop() +{ + QAudioDecoder d; + QVERIFY(d.state() == QAudioDecoder::StoppedState); + QVERIFY(d.bufferAvailable() == false); + + QSignalSpy readySpy(&d, SIGNAL(bufferReady())); + QSignalSpy bufferChangedSpy(&d, SIGNAL(bufferAvailableChanged(bool))); + QSignalSpy errorSpy(&d, SIGNAL(error(QAudioDecoder::Error))); + + // Starting with empty source == error + d.start(); + + QVERIFY(d.state() == QAudioDecoder::StoppedState); + QVERIFY(d.bufferAvailable() == false); + + QCOMPARE(readySpy.count(), 0); + QCOMPARE(bufferChangedSpy.count(), 0); + QCOMPARE(errorSpy.count(), 1); + + // Set the source to something + d.setSourceFilename("Blah"); + QCOMPARE(d.sourceFilename(), QString("Blah")); + + readySpy.clear(); + errorSpy.clear(); + bufferChangedSpy.clear(); + + d.start(); + QCOMPARE(d.state(), QAudioDecoder::DecodingState); + QCOMPARE(d.bufferAvailable(), false); // not yet + + // Try to read + bool ok = false; + QAudioBuffer b = d.read(&ok); + + QVERIFY(ok == false); + QVERIFY(!b.isValid()); + + // Read again with no parameter + b = d.read(); + QVERIFY(!b.isValid()); + + // Wait a while + QTRY_COMPARE(d.bufferAvailable(), 1); + + QVERIFY(d.bufferAvailable()); + + // Now stop + d.stop(); + + QVERIFY(d.state() == QAudioDecoder::StoppedState); + QVERIFY(d.bufferAvailable() == false); +} + +void tst_QAudioDecoder::format() +{ + QAudioDecoder d; + QVERIFY(d.state() == QAudioDecoder::StoppedState); + QVERIFY(d.bufferAvailable() == false); + + QSignalSpy readySpy(&d, SIGNAL(bufferReady())); + QSignalSpy bufferChangedSpy(&d, SIGNAL(bufferAvailableChanged(bool))); + QSignalSpy errorSpy(&d, SIGNAL(error(QAudioDecoder::Error))); + + // Set the source to something + d.setSourceFilename("Blah"); + QCOMPARE(d.sourceFilename(), QString("Blah")); + + readySpy.clear(); + errorSpy.clear(); + bufferChangedSpy.clear(); + + d.start(); + QCOMPARE(d.state(), QAudioDecoder::DecodingState); + QCOMPARE(d.bufferAvailable(), false); // not yet + + // Try to read + bool ok = false; + QAudioBuffer b = d.read(&ok); + + QVERIFY(ok == false); + QVERIFY(!b.isValid()); + + // Read again with no parameter + b = d.read(); + QVERIFY(!b.isValid()); + + // Wait a while + QTRY_COMPARE(d.bufferAvailable(), 1); + + b = d.read(&ok); + QVERIFY(d.audioFormat() == b.format()); + + // Setting format while decoding is forbidden + QAudioFormat f(d.audioFormat()); + f.setChannelCount(2); + + d.setAudioFormat(f); + QVERIFY(d.audioFormat() != f); + QVERIFY(d.audioFormat() == b.format()); + + // Now stop, and set something specific + d.stop(); + d.setAudioFormat(f); + QVERIFY(d.audioFormat() == f); + + // Decode again + d.start(); + QTRY_COMPARE(d.bufferAvailable(), 1); + + b = d.read(&ok); + QVERIFY(d.audioFormat() == f); + QVERIFY(b.format() == f); +} + +void tst_QAudioDecoder::source() +{ + QAudioDecoder d; + + QVERIFY(d.sourceFilename().isEmpty()); + QVERIFY(d.sourceDevice() == 0); + + QFile f; + d.setSourceDevice(&f); + QVERIFY(d.sourceFilename().isEmpty()); + QVERIFY(d.sourceDevice() == &f); + + d.setSourceFilename("Foo"); + QVERIFY(d.sourceFilename() == QString("Foo")); + QVERIFY(d.sourceDevice() == 0); + + d.setSourceDevice(0); + QVERIFY(d.sourceFilename().isEmpty()); + QVERIFY(d.sourceDevice() == 0); + + d.setSourceFilename("Foo"); + QVERIFY(d.sourceFilename() == QString("Foo")); + QVERIFY(d.sourceDevice() == 0); + + d.setSourceFilename(QString()); + QVERIFY(d.sourceFilename() == QString()); + QVERIFY(d.sourceDevice() == 0); +} + +QTEST_MAIN(tst_QAudioDecoder) + +#include "tst_qaudiodecoder.moc" |