diff options
author | Jonas Rabbe <jonas.rabbe@nokia.com> | 2012-03-08 11:05:30 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-12 08:21:07 +0100 |
commit | 942ff7a3c6d25dc3a79d28a79676b0995d95874b (patch) | |
tree | b738fe9761a829e216aeeebdabb3a8febcd3e415 /tests | |
parent | a15b9d3ce88037c973f868fdf6959eea4e157f68 (diff) | |
download | qtmultimedia-942ff7a3c6d25dc3a79d28a79676b0995d95874b.tar.gz |
Made QRadioData bind to QRadioTuner to avoid using multiple services
QRadioData has been updated to be a QMediaBindableInterface, and it
will bind to a QRadioTuner instance, i.e. a QMediaObject that provides
a service which implements the QRadioDataControl.
This change is reflected in the declarative implementations of radio
tuner and data. There is a new `radioData` property in the Radio element
which will give access to the declarative RadioData element for the
tuner.
If a RadioData element is created in QML, it will have an anonymous
tuner which communicates with the underlying media service (which is
pretty much the same how the QRadioTuner and QRadioData classes work
previously).
Updated radio tuner and data test cases to use availability control
and extended the mock media service to allow providing a number of
controls rather than just one (needed for testing availability of
all classes extending from or using QMediaObject).
Change-Id: Id41dde66eee529decd828fd2dcdfe4a54c0e81f4
Reviewed-by: Michael Goddard <michael.goddard@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/unit/qmultimedia_common/mockmediaservice.h | 18 | ||||
-rw-r--r-- | tests/auto/unit/qradiodata/tst_qradiodata.cpp | 128 | ||||
-rw-r--r-- | tests/auto/unit/qradiotuner/tst_qradiotuner.cpp | 12 |
3 files changed, 100 insertions, 58 deletions
diff --git a/tests/auto/unit/qmultimedia_common/mockmediaservice.h b/tests/auto/unit/qmultimedia_common/mockmediaservice.h index 4bd4a396e..316e78d7c 100644 --- a/tests/auto/unit/qmultimedia_common/mockmediaservice.h +++ b/tests/auto/unit/qmultimedia_common/mockmediaservice.h @@ -43,6 +43,9 @@ #define MOCKMEDIASERVICE_H #include "qmediaservice.h" +#include <QtCore/QMap> + +Q_DECLARE_METATYPE(QMediaControl *) class MockMediaService : public QMediaService { @@ -52,14 +55,23 @@ public: QMediaService(parent), mockControl(control) {} - QMediaControl* requestControl(const char *) + MockMediaService(QObject *parent, QMap<QString, QMediaControl *> controls): + QMediaService(parent), + mockControl(0), + mockControls(controls) {} + + QMediaControl* requestControl(const char *key) { - return mockControl; + if (mockControl) + return mockControl; + else + return mockControls.value(key); } void releaseControl(QMediaControl*) {} - QMediaControl *mockControl; + QMediaControl *mockControl; + QMap<QString, QMediaControl *> mockControls; }; diff --git a/tests/auto/unit/qradiodata/tst_qradiodata.cpp b/tests/auto/unit/qradiodata/tst_qradiodata.cpp index 2c3ab49d6..0e1138599 100644 --- a/tests/auto/unit/qradiodata/tst_qradiodata.cpp +++ b/tests/auto/unit/qradiodata/tst_qradiodata.cpp @@ -44,15 +44,19 @@ #include <QtTest/QtTest> #include <QDebug> #include <QTimer> +#include <QtCore/QMap> #include <qmediaobject.h> #include <qmediacontrol.h> #include <qmediaservice.h> #include <qradiodatacontrol.h> #include <qradiodata.h> +#include <qradiotuner.h> #include "mockmediaserviceprovider.h" #include "mockmediaservice.h" +#include "mockavailabilitycontrol.h" +#include "mockradiotunercontrol.h" #include "mockradiodatacontrol.h" QT_USE_NAMESPACE @@ -72,34 +76,47 @@ private slots: void testRadioDataUpdates(); private: - MockRadioDataControl *mock; + MockAvailabilityControl *mockAvailability; + MockRadioTunerControl *mockTuner; + MockRadioDataControl *mockData; MockMediaService *service; MockMediaServiceProvider *provider; - QRadioData *radio; + QRadioTuner * radio; + QRadioData *radioData; }; void tst_QRadioData::initTestCase() { qRegisterMetaType<QRadioData::ProgramType>("QRadioData::ProgramType"); - mock = new MockRadioDataControl(this); - service = new MockMediaService(this, mock); + mockAvailability = new MockAvailabilityControl(QtMultimedia::NoError); + mockTuner = new MockRadioTunerControl(this); + mockData = new MockRadioDataControl(this); + + QMap<QString, QMediaControl *> map; + map.insert(QRadioTunerControl_iid, mockTuner); + map.insert(QRadioDataControl_iid, mockData); + map.insert(QMediaAvailabilityControl_iid, mockAvailability); + + service = new MockMediaService(this, map); provider = new MockMediaServiceProvider(service); QMediaServiceProvider::setDefaultServiceProvider(provider); - radio = new QRadioData; - QVERIFY(radio->service() != 0); - QVERIFY(radio->isAvailable()); - QVERIFY(radio->availabilityError() == QtMultimedia::NoError); + + radio = new QRadioTuner; + radioData = radio->radioData(); + + QVERIFY(radioData->availabilityError() == QtMultimedia::NoError); } void tst_QRadioData::cleanupTestCase() { - QVERIFY(radio->error() == QRadioData::NoError); - QVERIFY(radio->errorString().isEmpty()); + QVERIFY(radioData->error() == QRadioData::NoError); + QVERIFY(radioData->errorString().isEmpty()); delete radio; delete service; delete provider; + delete mockAvailability; } void tst_QRadioData::testNullService() @@ -108,17 +125,21 @@ void tst_QRadioData::testNullService() MockMediaServiceProvider nullProvider(0); QMediaServiceProvider::setDefaultServiceProvider(&nullProvider); - QRadioData radio; - - QVERIFY(!radio.isAvailable()); - QCOMPARE(radio.error(), QRadioData::ResourceError); - QCOMPARE(radio.errorString(), QString()); - QCOMPARE(radio.stationId(), QString()); - QCOMPARE(radio.programType(), QRadioData::Undefined); - QCOMPARE(radio.programTypeName(), QString()); - QCOMPARE(radio.stationName(), QString()); - QCOMPARE(radio.radioText(), QString()); - QCOMPARE(radio.isAlternativeFrequenciesEnabled(), false); + QRadioTuner radio; + QRadioData *nullRadioData = radio.radioData(); + + QVERIFY(nullRadioData == 0); + + QRadioData radioData(&radio); + + QCOMPARE(radioData.error(), QRadioData::ResourceError); + QCOMPARE(radioData.errorString(), QString()); + QCOMPARE(radioData.stationId(), QString()); + QCOMPARE(radioData.programType(), QRadioData::Undefined); + QCOMPARE(radioData.programTypeName(), QString()); + QCOMPARE(radioData.stationName(), QString()); + QCOMPARE(radioData.radioText(), QString()); + QCOMPARE(radioData.isAlternativeFrequenciesEnabled(), false); } @@ -129,59 +150,58 @@ void tst_QRadioData::testNullControl() MockMediaService service(0, 0); MockMediaServiceProvider provider(&service); QMediaServiceProvider::setDefaultServiceProvider(&provider); - QRadioData radio; - QVERIFY(!radio.isAvailable()); - QCOMPARE(radio.error(), QRadioData::ResourceError); - QCOMPARE(radio.errorString(), QString()); - - QCOMPARE(radio.stationId(), QString()); - QCOMPARE(radio.programType(), QRadioData::Undefined); - QCOMPARE(radio.programTypeName(), QString()); - QCOMPARE(radio.stationName(), QString()); - QCOMPARE(radio.radioText(), QString()); - QCOMPARE(radio.isAlternativeFrequenciesEnabled(), false); + QRadioTuner radio; + QRadioData *radioData = radio.radioData(); + QCOMPARE(radioData->error(), QRadioData::ResourceError); + QCOMPARE(radioData->errorString(), QString()); + + QCOMPARE(radioData->stationId(), QString()); + QCOMPARE(radioData->programType(), QRadioData::Undefined); + QCOMPARE(radioData->programTypeName(), QString()); + QCOMPARE(radioData->stationName(), QString()); + QCOMPARE(radioData->radioText(), QString()); + QCOMPARE(radioData->isAlternativeFrequenciesEnabled(), false); { - QSignalSpy spy(&radio, SIGNAL(alternativeFrequenciesEnabledChanged(bool))); + QSignalSpy spy(radioData, SIGNAL(alternativeFrequenciesEnabledChanged(bool))); - radio.setAlternativeFrequenciesEnabled(true); - QCOMPARE(radio.isAlternativeFrequenciesEnabled(), false); + radioData->setAlternativeFrequenciesEnabled(true); + QCOMPARE(radioData->isAlternativeFrequenciesEnabled(), false); QCOMPARE(spy.count(), 0); } } void tst_QRadioData::testAlternativeFrequencies() { - QSignalSpy readSignal(radio, SIGNAL(alternativeFrequenciesEnabledChanged(bool))); - radio->setAlternativeFrequenciesEnabled(true); + QSignalSpy readSignal(radioData, SIGNAL(alternativeFrequenciesEnabledChanged(bool))); + radioData->setAlternativeFrequenciesEnabled(true); QTestEventLoop::instance().enterLoop(1); - QVERIFY(radio->isAlternativeFrequenciesEnabled() == true); + QVERIFY(radioData->isAlternativeFrequenciesEnabled() == true); QVERIFY(readSignal.count() == 1); } void tst_QRadioData::testRadioDataUpdates() { - QSignalSpy rtSpy(radio, SIGNAL(radioTextChanged(QString))); - QSignalSpy ptyPTYSpy(radio, SIGNAL(programTypeChanged(QRadioData::ProgramType))); - QSignalSpy ptynSpy(radio, SIGNAL(programTypeNameChanged(QString))); - QSignalSpy piSpy(radio, SIGNAL(stationIdChanged(QString))); - QSignalSpy psSpy(radio, SIGNAL(stationNameChanged(QString))); - mock->forceRT("Mock Radio Text"); - mock->forceProgramType(static_cast<int>(QRadioData::Sport)); - mock->forcePTYN("Mock Programme Type Name"); - mock->forcePI("Mock Programme Identification"); - mock->forcePS("Mock Programme Service"); + QSignalSpy rtSpy(radioData, SIGNAL(radioTextChanged(QString))); + QSignalSpy ptyPTYSpy(radioData, SIGNAL(programTypeChanged(QRadioData::ProgramType))); + QSignalSpy ptynSpy(radioData, SIGNAL(programTypeNameChanged(QString))); + QSignalSpy piSpy(radioData, SIGNAL(stationIdChanged(QString))); + QSignalSpy psSpy(radioData, SIGNAL(stationNameChanged(QString))); + mockData->forceRT("Mock Radio Text"); + mockData->forceProgramType(static_cast<int>(QRadioData::Sport)); + mockData->forcePTYN("Mock Programme Type Name"); + mockData->forcePI("Mock Programme Identification"); + mockData->forcePS("Mock Programme Service"); QTestEventLoop::instance().enterLoop(1); QVERIFY(rtSpy.count() == 1); QVERIFY(ptyPTYSpy.count() == 1); QVERIFY(ptynSpy.count() == 1); QVERIFY(piSpy.count() == 1); QVERIFY(psSpy.count() == 1); - qDebug()<<radio->radioText(); - QCOMPARE(radio->radioText(), QString("Mock Radio Text")); - QCOMPARE(radio->programType(), QRadioData::Sport); - QCOMPARE(radio->programTypeName(), QString("Mock Programme Type Name")); - QCOMPARE(radio->stationId(), QString("Mock Programme Identification")); - QCOMPARE(radio->stationName(), QString("Mock Programme Service")); + QCOMPARE(radioData->radioText(), QString("Mock Radio Text")); + QCOMPARE(radioData->programType(), QRadioData::Sport); + QCOMPARE(radioData->programTypeName(), QString("Mock Programme Type Name")); + QCOMPARE(radioData->stationId(), QString("Mock Programme Identification")); + QCOMPARE(radioData->stationName(), QString("Mock Programme Service")); } QTEST_GUILESS_MAIN(tst_QRadioData) diff --git a/tests/auto/unit/qradiotuner/tst_qradiotuner.cpp b/tests/auto/unit/qradiotuner/tst_qradiotuner.cpp index 9a0172213..07bf8a8fd 100644 --- a/tests/auto/unit/qradiotuner/tst_qradiotuner.cpp +++ b/tests/auto/unit/qradiotuner/tst_qradiotuner.cpp @@ -44,6 +44,7 @@ #include <QtTest/QtTest> #include <QDebug> #include <QTimer> +#include <QtCore/QMap> #include <qmediaobject.h> #include <qmediacontrol.h> @@ -54,6 +55,7 @@ #include "mockmediaserviceprovider.h" #include "mockmediaservice.h" #include "mockradiotunercontrol.h" +#include "mockavailabilitycontrol.h" QT_USE_NAMESPACE @@ -81,6 +83,7 @@ private slots: private: MockRadioTunerControl *mock; + MockAvailabilityControl *mockAvailability; MockMediaService *service; MockMediaServiceProvider *provider; QRadioTuner *radio; @@ -92,7 +95,13 @@ void tst_QRadioTuner::initTestCase() qRegisterMetaType<QRadioTuner::Band>("QRadioTuner::Band"); mock = new MockRadioTunerControl(this); - service = new MockMediaService(this, mock); + mockAvailability = new MockAvailabilityControl(QtMultimedia::NoError); + + QMap<QString, QMediaControl *> map; + map.insert(QRadioTunerControl_iid, mock); + map.insert(QMediaAvailabilityControl_iid, mockAvailability); + + service = new MockMediaService(this, map); provider = new MockMediaServiceProvider(service); QMediaServiceProvider::setDefaultServiceProvider(provider); @@ -129,6 +138,7 @@ void tst_QRadioTuner::cleanupTestCase() delete radio; delete service; delete provider; + delete mockAvailability; } void tst_QRadioTuner::init() |