diff options
author | Dmytro Poplavskiy <dmytro.poplavskiy@nokia.com> | 2012-01-19 10:01:02 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-01-24 09:11:07 +0100 |
commit | a78a95ccd4c876bca7fe748c44c9744e828d375e (patch) | |
tree | 4a72285e10aab435682fb7cdbbc4e70432191b20 | |
parent | adb2bd2cd4bb2b01b15f6213681654949f2c797c (diff) | |
download | qtmultimedia-a78a95ccd4c876bca7fe748c44c9744e828d375e.tar.gz |
Removed QMediaServiceProvider parameter from media objects constructors.
QMediaServiceProvider should be removed from the public API,
to provide media objects with a custom media service.
A protected QMediaPlayer/QCamera/QRadioTuner/etc constructor
with QMediaService* parameter is a cleaner and more
flexible solution.
Change-Id: I335cce4bbebe0e548c3df338f206e7be7c93c3dd
Reviewed-by: Michael Goddard <michael.goddard@nokia.com>
Reviewed-by: Jonas Rabbe <jonas.rabbe@nokia.com>
26 files changed, 307 insertions, 369 deletions
diff --git a/src/imports/multimedia/qdeclarativemediabase_p.h b/src/imports/multimedia/qdeclarativemediabase_p.h index 84db7e50b..707cac94b 100644 --- a/src/imports/multimedia/qdeclarativemediabase_p.h +++ b/src/imports/multimedia/qdeclarativemediabase_p.h @@ -55,6 +55,7 @@ #include <QtCore/qbasictimer.h> #include <qmediaplayer.h> +#include <qmediaserviceprovider.h> QT_BEGIN_HEADER diff --git a/src/multimedia/camera/qcamera.cpp b/src/multimedia/camera/qcamera.cpp index 6160ccb64..a5e5be57c 100644 --- a/src/multimedia/camera/qcamera.cpp +++ b/src/multimedia/camera/qcamera.cpp @@ -41,6 +41,7 @@ #include "qvideosurfaceoutput_p.h" #include "qmediaobject_p.h" +#include "qmediaserviceprovider.h" #include <qcamera.h> #include <qcameracontrol.h> @@ -338,11 +339,13 @@ void QCameraPrivate::_q_updateLockStatus(QCamera::LockType type, QCamera::LockSt Construct a QCamera from service \a provider and \a parent. */ -QCamera::QCamera(QObject *parent, QMediaServiceProvider *provider): - QMediaObject(*new QCameraPrivate, parent, provider->requestService(Q_MEDIASERVICE_CAMERA)) +QCamera::QCamera(QObject *parent): + QMediaObject(*new QCameraPrivate, + parent, + QMediaServiceProvider::defaultServiceProvider()->requestService(Q_MEDIASERVICE_CAMERA)) { Q_D(QCamera); - d->provider = provider; + d->provider = QMediaServiceProvider::defaultServiceProvider(); d->initControls(); d->cameraExposure = new QCameraExposure(this); d->cameraFocus = new QCameraFocus(this); diff --git a/src/multimedia/camera/qcamera.h b/src/multimedia/camera/qcamera.h index 5ea9b4420..da84a692e 100644 --- a/src/multimedia/camera/qcamera.h +++ b/src/multimedia/camera/qcamera.h @@ -56,7 +56,6 @@ #include <qcamerafocus.h> #include <qcameraimageprocessing.h> -#include <qmediaserviceprovider.h> #include <qmediaenumdebug.h> QT_BEGIN_HEADER @@ -144,7 +143,7 @@ public: }; Q_DECLARE_FLAGS(LockTypes, LockType) - QCamera(QObject *parent = 0, QMediaServiceProvider *provider = QMediaServiceProvider::defaultServiceProvider()); + QCamera(QObject *parent = 0); QCamera(const QByteArray& device, QObject *parent = 0); ~QCamera(); diff --git a/src/multimedia/playback/qmediaplayer.cpp b/src/multimedia/playback/qmediaplayer.cpp index b729a5fa8..e54cd7c74 100644 --- a/src/multimedia/playback/qmediaplayer.cpp +++ b/src/multimedia/playback/qmediaplayer.cpp @@ -238,8 +238,9 @@ void QMediaPlayerPrivate::_q_playlistDestroyed() control->setMedia(QMediaContent(), 0); } -static QMediaService *playerService(QMediaPlayer::Flags flags, QMediaServiceProvider *provider) +static QMediaService *playerService(QMediaPlayer::Flags flags) { + QMediaServiceProvider *provider = QMediaServiceProvider::defaultServiceProvider(); if (flags) { QMediaServiceProviderHint::Features features = 0; if (flags & QMediaPlayer::LowLatency) @@ -259,21 +260,18 @@ static QMediaService *playerService(QMediaPlayer::Flags flags, QMediaServiceProv /*! - Construct a QMediaPlayer that uses the playback service from \a provider, + Construct a QMediaPlayer instance parented to \a parent and with \a flags. - - If a playback service is not specified the system default will be used. */ -QMediaPlayer::QMediaPlayer(QObject *parent, QMediaPlayer::Flags flags, QMediaServiceProvider *provider): +QMediaPlayer::QMediaPlayer(QObject *parent, QMediaPlayer::Flags flags): QMediaObject(*new QMediaPlayerPrivate, parent, - playerService(flags,provider)) + playerService(flags)) { Q_D(QMediaPlayer); - d->provider = provider; - + d->provider = QMediaServiceProvider::defaultServiceProvider(); if (d->service == 0) { d->error = ServiceMissingError; } else { @@ -322,9 +320,9 @@ QMediaPlayer::~QMediaPlayer() if (d->service) { if (d->control) d->service->releaseControl(d->control); - } - d->provider->releaseService(d->service); + d->provider->releaseService(d->service); + } } QMediaContent QMediaPlayer::media() const diff --git a/src/multimedia/playback/qmediaplayer.h b/src/multimedia/playback/qmediaplayer.h index 248ca308b..807d6781a 100644 --- a/src/multimedia/playback/qmediaplayer.h +++ b/src/multimedia/playback/qmediaplayer.h @@ -42,8 +42,6 @@ #ifndef QMEDIAPLAYER_H #define QMEDIAPLAYER_H - -#include "qmediaserviceprovider.h" #include "qmediaobject.h" #include "qmediacontent.h" #include "qmediaenumdebug.h" @@ -123,7 +121,7 @@ public: ServiceMissingError }; - QMediaPlayer(QObject *parent = 0, Flags flags = 0, QMediaServiceProvider *provider = QMediaServiceProvider::defaultServiceProvider()); + QMediaPlayer(QObject *parent = 0, Flags flags = 0); ~QMediaPlayer(); static QtMultimedia::SupportEstimate hasSupport(const QString &mimeType, diff --git a/src/multimedia/qmediaserviceprovider.cpp b/src/multimedia/qmediaserviceprovider.cpp index 849a9b602..48640faba 100644 --- a/src/multimedia/qmediaserviceprovider.cpp +++ b/src/multimedia/qmediaserviceprovider.cpp @@ -613,13 +613,11 @@ QString QMediaServiceProvider::deviceDescription(const QByteArray &serviceType, return QString(); } - -#ifdef QT_BUILD_INTERNAL - static QMediaServiceProvider *qt_defaultMediaServiceProvider = 0; /*! Sets a media service \a provider as the default. + It's useful for unit tests to provide mock service. \internal */ @@ -628,20 +626,15 @@ void QMediaServiceProvider::setDefaultServiceProvider(QMediaServiceProvider *pro qt_defaultMediaServiceProvider = provider; } -#endif /*! Returns a default provider of media services. */ QMediaServiceProvider *QMediaServiceProvider::defaultServiceProvider() { -#ifdef QT_BUILD_INTERNAL return qt_defaultMediaServiceProvider != 0 ? qt_defaultMediaServiceProvider : static_cast<QMediaServiceProvider *>(pluginProvider()); -#else - return pluginProvider(); -#endif } /*! diff --git a/src/multimedia/qmediaserviceprovider.h b/src/multimedia/qmediaserviceprovider.h index 6bcbd858c..bb3cc5a9e 100644 --- a/src/multimedia/qmediaserviceprovider.h +++ b/src/multimedia/qmediaserviceprovider.h @@ -120,10 +120,7 @@ public: virtual QString deviceDescription(const QByteArray &serviceType, const QByteArray &device); static QMediaServiceProvider* defaultServiceProvider(); - -#ifdef QT_BUILD_INTERNAL static void setDefaultServiceProvider(QMediaServiceProvider *provider); -#endif }; /*! diff --git a/src/multimedia/radio/qradiodata.cpp b/src/multimedia/radio/qradiodata.cpp index 004880af8..8fb160f01 100644 --- a/src/multimedia/radio/qradiodata.cpp +++ b/src/multimedia/radio/qradiodata.cpp @@ -43,6 +43,7 @@ #include "qmediaservice.h" #include "qmediaobject_p.h" #include "qradiodatacontrol.h" +#include "qmediaserviceprovider.h" #include <QPair> @@ -93,12 +94,14 @@ public: The \a parent is passed to QMediaObject. */ -QRadioData::QRadioData(QObject *parent, QMediaServiceProvider* provider): - QMediaObject(*new QRadioDataPrivate, parent, provider->requestService(Q_MEDIASERVICE_RADIO)) +QRadioData::QRadioData(QObject *parent): + QMediaObject(*new QRadioDataPrivate, + parent, + QMediaServiceProvider::defaultServiceProvider()->requestService(Q_MEDIASERVICE_RADIO)) { Q_D(QRadioData); - d->provider = provider; + d->provider = QMediaServiceProvider::defaultServiceProvider(); if (d->service != 0) { d->control = qobject_cast<QRadioDataControl*>(d->service->requestControl(QRadioDataControl_iid)); diff --git a/src/multimedia/radio/qradiodata.h b/src/multimedia/radio/qradiodata.h index e82029690..934b86b0f 100644 --- a/src/multimedia/radio/qradiodata.h +++ b/src/multimedia/radio/qradiodata.h @@ -45,7 +45,6 @@ #include <QtCore/qobject.h> #include "qmediaobject.h" -#include "qmediaserviceprovider.h" #include <qmediaenumdebug.h> #include <QPair> @@ -88,7 +87,7 @@ public: College }; - QRadioData(QObject *parent = 0, QMediaServiceProvider *provider = QMediaServiceProvider::defaultServiceProvider()); + QRadioData(QObject *parent = 0); ~QRadioData(); bool isAvailable() const; diff --git a/src/multimedia/radio/qradiotuner.cpp b/src/multimedia/radio/qradiotuner.cpp index c4a8cfc47..ee69c6370 100644 --- a/src/multimedia/radio/qradiotuner.cpp +++ b/src/multimedia/radio/qradiotuner.cpp @@ -43,6 +43,7 @@ #include "qmediaservice.h" #include "qmediaobject_p.h" #include "qradiotunercontrol.h" +#include "qmediaserviceprovider.h" #include <QPair> @@ -106,12 +107,14 @@ public: The \a parent is passed to QMediaObject. */ -QRadioTuner::QRadioTuner(QObject *parent, QMediaServiceProvider* provider): - QMediaObject(*new QRadioTunerPrivate, parent, provider->requestService(Q_MEDIASERVICE_RADIO)) +QRadioTuner::QRadioTuner(QObject *parent): + QMediaObject(*new QRadioTunerPrivate, + parent, + QMediaServiceProvider::defaultServiceProvider()->requestService(Q_MEDIASERVICE_RADIO)) { Q_D(QRadioTuner); - d->provider = provider; + d->provider = QMediaServiceProvider::defaultServiceProvider(); if (d->service != 0) { d->control = qobject_cast<QRadioTunerControl*>(d->service->requestControl(QRadioTunerControl_iid)); diff --git a/src/multimedia/radio/qradiotuner.h b/src/multimedia/radio/qradiotuner.h index 87a2ed4d2..c254c72e5 100644 --- a/src/multimedia/radio/qradiotuner.h +++ b/src/multimedia/radio/qradiotuner.h @@ -45,7 +45,6 @@ #include <QtCore/qobject.h> #include "qmediaobject.h" -#include "qmediaserviceprovider.h" #include <qmediaenumdebug.h> #include <QPair> @@ -83,7 +82,7 @@ public: enum StereoMode { ForceStereo, ForceMono, Auto }; enum SearchMode { SearchFast, SearchGetStationId }; - QRadioTuner(QObject *parent = 0, QMediaServiceProvider *provider = QMediaServiceProvider::defaultServiceProvider()); + QRadioTuner(QObject *parent = 0); ~QRadioTuner(); bool isAvailable() const; diff --git a/src/multimedia/recording/qaudiorecorder.cpp b/src/multimedia/recording/qaudiorecorder.cpp index 333ba4ae7..2357ae3c1 100644 --- a/src/multimedia/recording/qaudiorecorder.cpp +++ b/src/multimedia/recording/qaudiorecorder.cpp @@ -118,11 +118,11 @@ public: The \a parent is passed to QMediaObject. */ -QAudioRecorder::QAudioRecorder(QObject *parent, QMediaServiceProvider *serviceProvider): +QAudioRecorder::QAudioRecorder(QObject *parent): QMediaRecorder(*new QAudioRecorderPrivate, 0, parent) { Q_D(QAudioRecorder); - d->provider = serviceProvider; + d->provider = QMediaServiceProvider::defaultServiceProvider(); QMediaService *service = d->provider->requestService(Q_MEDIASERVICE_AUDIOSOURCE); setMediaObject(new QAudioRecorderObject(this, service)); diff --git a/src/multimedia/recording/qaudiorecorder.h b/src/multimedia/recording/qaudiorecorder.h index 84d19e61c..3d59dfb07 100644 --- a/src/multimedia/recording/qaudiorecorder.h +++ b/src/multimedia/recording/qaudiorecorder.h @@ -68,7 +68,7 @@ class Q_MULTIMEDIA_EXPORT QAudioRecorder : public QMediaRecorder Q_OBJECT Q_PROPERTY(QString audioInput READ audioInput WRITE setAudioInput NOTIFY audioInputChanged) public: - QAudioRecorder(QObject *parent = 0, QMediaServiceProvider *serviceProvider = QMediaServiceProvider::defaultServiceProvider()); + QAudioRecorder(QObject *parent = 0); ~QAudioRecorder(); QStringList audioInputs() const; diff --git a/src/multimedia/recording/qmediarecorder.h b/src/multimedia/recording/qmediarecorder.h index 4a46371bc..dcdbb7426 100644 --- a/src/multimedia/recording/qmediarecorder.h +++ b/src/multimedia/recording/qmediarecorder.h @@ -43,7 +43,6 @@ #define QMEDIARECORDER_H #include <qmediaobject.h> -#include <qmediaserviceprovider.h> #include <qmediaencodersettings.h> #include <qmediabindableinterface.h> #include <qmediaenumdebug.h> diff --git a/src/multimediawidgets/qcameraviewfinder.h b/src/multimediawidgets/qcameraviewfinder.h index 8eec67e31..1a08dfea2 100644 --- a/src/multimediawidgets/qcameraviewfinder.h +++ b/src/multimediawidgets/qcameraviewfinder.h @@ -53,8 +53,6 @@ #include <qmediaservice.h> #include <qvideowidget.h> -#include <qmediaserviceprovider.h> - QT_BEGIN_HEADER QT_BEGIN_NAMESPACE diff --git a/tests/auto/integration/qcamerabackend/tst_qcamerabackend.cpp b/tests/auto/integration/qcamerabackend/tst_qcamerabackend.cpp index 0729d32d0..65898df22 100644 --- a/tests/auto/integration/qcamerabackend/tst_qcamerabackend.cpp +++ b/tests/auto/integration/qcamerabackend/tst_qcamerabackend.cpp @@ -60,6 +60,7 @@ #include <qcamera.h> #include <qcameraimagecapture.h> #include <qvideorenderercontrol.h> +#include <qmediaserviceprovider.h> QT_USE_NAMESPACE diff --git a/tests/auto/unit/qaudiorecorder/tst_qaudiorecorder.cpp b/tests/auto/unit/qaudiorecorder/tst_qaudiorecorder.cpp index 7df7e00fa..84b179e25 100644 --- a/tests/auto/unit/qaudiorecorder/tst_qaudiorecorder.cpp +++ b/tests/auto/unit/qaudiorecorder/tst_qaudiorecorder.cpp @@ -87,6 +87,8 @@ void tst_QAudioRecorder::init() mockMediaRecorderService = new MockMediaRecorderService(this, new MockMediaRecorderControl(this)); mockProvider = new MockMediaServiceProvider(mockMediaRecorderService); audiosource = 0; + + QMediaServiceProvider::setDefaultServiceProvider(mockProvider); } void tst_QAudioRecorder::cleanup() @@ -102,7 +104,10 @@ void tst_QAudioRecorder::cleanup() void tst_QAudioRecorder::testNullService() { mockProvider->service = 0; - QAudioRecorder source(0, mockProvider); + QAudioRecorder source; + + QVERIFY(!source.isAvailable()); + QCOMPARE(source.availabilityError(), QtMultimedia::ServiceMissingError); QCOMPARE(source.audioInputs().size(), 0); QCOMPARE(source.defaultAudioInput(), QString()); @@ -113,7 +118,10 @@ void tst_QAudioRecorder::testNullService() void tst_QAudioRecorder::testNullControl() { mockMediaRecorderService->hasControls = false; - QAudioRecorder source(0, mockProvider); + QAudioRecorder source; + + QVERIFY(!source.isAvailable()); + QCOMPARE(source.availabilityError(), QtMultimedia::ServiceMissingError); QCOMPARE(source.audioInputs().size(), 0); QCOMPARE(source.defaultAudioInput(), QString()); @@ -129,7 +137,7 @@ void tst_QAudioRecorder::testNullControl() void tst_QAudioRecorder::testAudioSource() { - audiosource = new QAudioRecorder(0, mockProvider); + audiosource = new QAudioRecorder; QCOMPARE(audiosource->mediaObject()->service(),(QMediaService *) mockMediaRecorderService); } @@ -146,7 +154,7 @@ void tst_QAudioRecorder::testOptions() void tst_QAudioRecorder::testDevices() { - audiosource = new QAudioRecorder(0,mockProvider); + audiosource = new QAudioRecorder; QList<QString> devices = audiosource->audioInputs(); QVERIFY(devices.size() > 0); QVERIFY(devices.at(0).compare("device1") == 0); @@ -163,26 +171,16 @@ void tst_QAudioRecorder::testDevices() void tst_QAudioRecorder::testAvailability() { - MockMediaRecorderService service(this, new MockMediaRecorderControl(this)); - service.hasControls = false; - MockMediaServiceProvider provider(&service); - QAudioRecorder source(0, &provider); - - QVERIFY(source.isAvailable() == false); - QVERIFY(source.availabilityError() == QtMultimedia::ServiceMissingError); - - service.hasControls = true; - MockMediaServiceProvider provider2(&service); - QAudioRecorder source2(0, &provider2); + QAudioRecorder source; - QVERIFY(source2.isAvailable() == true); - QVERIFY(source2.availabilityError() == QtMultimedia::NoError); + QVERIFY(source.isAvailable()); + QCOMPARE(source.availabilityError(), QtMultimedia::NoError); } void tst_QAudioRecorder::testAvailableAudioInputChangedSignal() { // The availabilityChangedSignal is implemented in QAudioRecorder. SO using it to test the signal. - audiosource = new QAudioRecorder(0, mockProvider); + audiosource = new QAudioRecorder; /* Spy the signal availableEndpointChanged and audioInputchanged */ QSignalSpy changed(mockMediaRecorderService->mockAudioEndpointSelector, SIGNAL(availableEndpointsChanged())); diff --git a/tests/auto/unit/qcamera/tst_qcamera.cpp b/tests/auto/unit/qcamera/tst_qcamera.cpp index 6c8ee4f4b..d972abff9 100644 --- a/tests/auto/unit/qcamera/tst_qcamera.cpp +++ b/tests/auto/unit/qcamera/tst_qcamera.cpp @@ -76,7 +76,8 @@ class tst_QCamera: public QObject public slots: void initTestCase(); - void cleanupTestCase(); + void init(); + void cleanup(); private slots: void testSimpleCamera(); @@ -106,7 +107,7 @@ private slots: void testRequestedLocks(); void testSupportedLocks(); void testQCameraIsAvailable(); - void testAvailabilityError(); + void testQCameraIsNotAvailable(); void testSearchAndLockWithLockTypes(); void testSetCaptureMode(); void testUnlockWithType(); @@ -163,25 +164,35 @@ private slots: private: MockSimpleCameraService *mockSimpleCameraService; + MockCameraService *mockCameraService; MockMediaServiceProvider *provider; }; void tst_QCamera::initTestCase() { +} + +void tst_QCamera::init() +{ provider = new MockMediaServiceProvider; mockSimpleCameraService = new MockSimpleCameraService; - provider->service = mockSimpleCameraService; + mockCameraService = new MockCameraService; + + provider->service = mockCameraService; + QMediaServiceProvider::setDefaultServiceProvider(provider); } -void tst_QCamera::cleanupTestCase() +void tst_QCamera::cleanup() { - delete mockSimpleCameraService; delete provider; + delete mockCameraService; + delete mockSimpleCameraService; } void tst_QCamera::testSimpleCamera() { - QCamera camera(0, provider); + provider->service = mockSimpleCameraService; + QCamera camera; QCOMPARE(camera.service(), (QMediaService*)mockSimpleCameraService); QCOMPARE(camera.state(), QCamera::UnloadedState); @@ -197,7 +208,8 @@ void tst_QCamera::testSimpleCamera() void tst_QCamera::testSimpleCameraWhiteBalance() { - QCamera camera(0, provider); + provider->service = mockSimpleCameraService; + QCamera camera; //only WhiteBalanceAuto is supported QVERIFY(!camera.imageProcessing()->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceAuto)); @@ -212,7 +224,8 @@ void tst_QCamera::testSimpleCameraWhiteBalance() void tst_QCamera::testSimpleCameraExposure() { - QCamera camera(0, provider); + provider->service = mockSimpleCameraService; + QCamera camera; QCameraExposure *cameraExposure = camera.exposure(); QVERIFY(cameraExposure != 0); @@ -266,7 +279,8 @@ void tst_QCamera::testSimpleCameraExposure() void tst_QCamera::testSimpleCameraFocus() { - QCamera camera(0, provider); + provider->service = mockSimpleCameraService; + QCamera camera; QCameraFocus *cameraFocus = camera.focus(); QVERIFY(cameraFocus != 0); @@ -306,7 +320,8 @@ void tst_QCamera::testSimpleCameraFocus() void tst_QCamera::testSimpleCameraCapture() { - QCamera camera(0, provider); + provider->service = mockSimpleCameraService; + QCamera camera; QCameraImageCapture imageCapture(&camera); QVERIFY(!imageCapture.isReadyForCapture()); @@ -324,7 +339,8 @@ void tst_QCamera::testSimpleCameraCapture() void tst_QCamera::testSimpleCameraLock() { - QCamera camera(0, provider); + provider->service = mockSimpleCameraService; + QCamera camera; QCOMPARE(camera.lockStatus(), QCamera::Unlocked); QCOMPARE(camera.lockStatus(QCamera::LockExposure), QCamera::Unlocked); QCOMPARE(camera.lockStatus(QCamera::LockFocus), QCamera::Unlocked); @@ -360,7 +376,8 @@ void tst_QCamera::testSimpleCameraLock() void tst_QCamera::testSimpleCaptureDestination() { - QCamera camera(0, provider); + provider->service = mockSimpleCameraService; + QCamera camera; QCameraImageCapture imageCapture(&camera); QVERIFY(imageCapture.isCaptureDestinationSupported(QCameraImageCapture::CaptureToFile)); @@ -375,7 +392,8 @@ void tst_QCamera::testSimpleCaptureDestination() void tst_QCamera::testSimpleCaptureFormat() { - QCamera camera(0, provider); + provider->service = mockSimpleCameraService; + QCamera camera; QCameraImageCapture imageCapture(&camera); QCOMPARE(imageCapture.bufferFormat(), QVideoFrame::Format_Invalid); @@ -387,9 +405,7 @@ void tst_QCamera::testSimpleCaptureFormat() void tst_QCamera::testCaptureDestination() { - MockCameraService service; - provider->service = &service; - QCamera camera(0, provider); + QCamera camera; QCameraImageCapture imageCapture(&camera); QVERIFY(imageCapture.isCaptureDestinationSupported(QCameraImageCapture::CaptureToFile)); @@ -414,9 +430,7 @@ void tst_QCamera::testCaptureDestination() void tst_QCamera::testCaptureFormat() { - MockCameraService service; - provider->service = &service; - QCamera camera(0, provider); + QCamera camera; QCameraImageCapture imageCapture(&camera); QSignalSpy formatChangedSignal(&imageCapture, SIGNAL(bufferFormatChanged(QVideoFrame::PixelFormat))); @@ -440,9 +454,7 @@ void tst_QCamera::testCaptureFormat() void tst_QCamera::testCameraCapture() { - MockCameraService service; - provider->service = &service; - QCamera camera(0, provider); + QCamera camera; QCameraImageCapture imageCapture(&camera); QVERIFY(!imageCapture.isReadyForCapture()); @@ -473,9 +485,7 @@ void tst_QCamera::testCameraCapture() void tst_QCamera::testCameraCaptureMetadata() { - MockCameraService service; - provider->service = &service; - QCamera camera(0, provider); + QCamera camera; QCameraImageCapture imageCapture(&camera); QSignalSpy metadataSignal(&imageCapture, SIGNAL(imageMetadataAvailable(int,QString,QVariant))); @@ -523,10 +533,9 @@ void tst_QCamera::testCameraWhiteBalance() QCameraImageProcessingControl::ColorTemperature, QVariant(34)); - MockMediaServiceProvider provider; - provider.service = &service; + provider->service = &service; - QCamera camera(0, &provider); + QCamera camera; QCameraImageProcessing *cameraImageProcessing = camera.imageProcessing(); QCOMPARE(cameraImageProcessing->whiteBalanceMode(), QCameraImageProcessing::WhiteBalanceFlash); @@ -548,9 +557,7 @@ void tst_QCamera::testCameraWhiteBalance() void tst_QCamera::testCameraExposure() { - MockCameraService service; - provider->service = &service; - QCamera camera(0, provider); + QCamera camera; QCameraExposure *cameraExposure = camera.exposure(); QVERIFY(cameraExposure != 0); @@ -692,9 +699,7 @@ void tst_QCamera::testCameraExposure() void tst_QCamera::testCameraFocus() { - MockCameraService service; - provider->service = &service; - QCamera camera(0, provider); + QCamera camera; QCameraFocus *cameraFocus = camera.focus(); QVERIFY(cameraFocus != 0); @@ -836,9 +841,7 @@ void tst_QCamera::testImageSettings() void tst_QCamera::testCameraLock() { - MockCameraService service; - provider->service = &service; - QCamera camera(0, provider); + QCamera camera; camera.focus()->setFocusMode(QCameraFocus::AutoFocus); @@ -919,9 +922,7 @@ void tst_QCamera::testCameraLockCancel() void tst_QCamera::testCameraEncodingProperyChange() { - MockCameraService service; - provider->service = &service; - QCamera camera(0, provider); + QCamera camera; QCameraImageCapture imageCapture(&camera); QSignalSpy stateChangedSignal(&camera, SIGNAL(stateChanged(QCamera::State))); @@ -1009,30 +1010,26 @@ void tst_QCamera::testCameraEncodingProperyChange() void tst_QCamera::testSetVideoOutput() { MockVideoSurface surface; - - MockCameraService service; - MockMediaServiceProvider provider; - provider.service = &service; - QCamera camera(0, &provider); + QCamera camera; camera.setViewfinder(reinterpret_cast<QVideoWidget *>(0)); camera.setViewfinder(reinterpret_cast<QGraphicsVideoItem *>(0)); camera.setViewfinder(&surface); - QVERIFY(service.rendererControl->surface() == &surface); + QVERIFY(mockCameraService->rendererControl->surface() == &surface); camera.setViewfinder(reinterpret_cast<QAbstractVideoSurface *>(0)); - QVERIFY(service.rendererControl->surface() == 0); + QVERIFY(mockCameraService->rendererControl->surface() == 0); camera.setViewfinder(&surface); - QVERIFY(service.rendererControl->surface() == &surface); + QVERIFY(mockCameraService->rendererControl->surface() == &surface); camera.setViewfinder(reinterpret_cast<QVideoWidget *>(0)); - QVERIFY(service.rendererControl->surface() == 0); + QVERIFY(mockCameraService->rendererControl->surface() == 0); camera.setViewfinder(&surface); - QVERIFY(service.rendererControl->surface() == &surface); + QVERIFY(mockCameraService->rendererControl->surface() == &surface); } @@ -1040,9 +1037,8 @@ void tst_QCamera::testSetVideoOutputNoService() { MockVideoSurface surface; - MockMediaServiceProvider provider; - provider.service = 0; - QCamera camera(0, &provider); + provider->service = 0; + QCamera camera; camera.setViewfinder(&surface); // Nothing we can verify here other than it doesn't assert. @@ -1054,10 +1050,9 @@ void tst_QCamera::testSetVideoOutputNoControl() MockCameraService service; service.rendererRef = 1; + provider->service = &service; - MockMediaServiceProvider provider; - provider.service = &service; - QCamera camera(0, &provider); + QCamera camera; camera.setViewfinder(&surface); QVERIFY(service.rendererControl->surface() == 0); @@ -1066,13 +1061,11 @@ void tst_QCamera::testSetVideoOutputNoControl() void tst_QCamera::testSetVideoOutputDestruction() { MockVideoSurface surface; - MockCameraService service; - MockMediaServiceProvider provider; - provider.service = &service; + provider->service = &service; { - QCamera camera(0, &provider); + QCamera camera; camera.setViewfinder(&surface); QVERIFY(service.rendererControl->surface() == &surface); QCOMPARE(service.rendererRef, 1); @@ -1133,9 +1126,7 @@ void tst_QCamera::testCaptureModeChanged_signal() /* Test case for captureMode */ void tst_QCamera::testCaptureMode() { - MockCameraService service; - provider->service = &service; - QCamera camera(0, provider); + QCamera camera; QVERIFY(camera.captureMode() == QCamera::CaptureStillImage); camera.setCaptureMode(QCamera::CaptureVideo); @@ -1145,9 +1136,7 @@ void tst_QCamera::testCaptureMode() /* Test case for isCaptureModeSupported */ void tst_QCamera::testIsCaptureModeSupported() { - MockCameraService service; - provider->service = &service; - QCamera camera(0, provider); + QCamera camera; QVERIFY(camera.isCaptureModeSupported(QCamera::CaptureStillImage) == true); QVERIFY(camera.isCaptureModeSupported(QCamera::CaptureVideo) == true); } @@ -1156,9 +1145,7 @@ void tst_QCamera::testIsCaptureModeSupported() types of combinations are verified here.*/ void tst_QCamera::testRequestedLocks() { - MockCameraService service; - provider->service = &service; - QCamera camera(0, provider); + QCamera camera; QCOMPARE(camera.requestedLocks(),QCamera::NoLock); @@ -1188,9 +1175,7 @@ void tst_QCamera::testRequestedLocks() /* Test case for supportedLocks() */ void tst_QCamera::testSupportedLocks() { - MockCameraService service; - provider->service = &service; - QCamera camera(0, provider); + QCamera camera; QCOMPARE(camera.supportedLocks(),QCamera::LockExposure | QCamera::LockFocus); } @@ -1198,37 +1183,25 @@ void tst_QCamera::testSupportedLocks() /* Test case for isAvailable */ void tst_QCamera::testQCameraIsAvailable() { - MockCameraService service; - provider->service = &service; - QCamera camera(0, provider); + QCamera camera; QVERIFY(camera.isAvailable()); - - QCamera *camera1 = new QCamera("random"); - - QVERIFY(camera1->error() == QCamera::ServiceMissingError); - QVERIFY(!camera1->isAvailable()); - delete camera1; + QVERIFY(camera.availabilityError() == QtMultimedia::NoError); } -/* Test case for availabilityError */ -void tst_QCamera::testAvailabilityError() +void tst_QCamera::testQCameraIsNotAvailable() { - MockCameraService service; - provider->service = &service; - QCamera camera(0, provider); - QVERIFY(camera.availabilityError() == QtMultimedia::NoError); + provider->service = 0; + QCamera camera("random"); - QCamera *camera1 = new QCamera("random"); - QVERIFY(camera1->availabilityError() == QtMultimedia::ServiceMissingError); - delete camera1; + QCOMPARE(camera.error(), QCamera::ServiceMissingError); + QVERIFY(!camera.isAvailable()); + QCOMPARE(camera.availabilityError(), QtMultimedia::ServiceMissingError); } /* Test case for searchAndLock ( QCamera::LockTypes locks ) */ void tst_QCamera::testSearchAndLockWithLockTypes() { - MockCameraService service; - provider->service = &service; - QCamera camera(0, provider); + QCamera camera; QCOMPARE(camera.lockStatus(), QCamera::Unlocked); @@ -1250,9 +1223,7 @@ void tst_QCamera::testSearchAndLockWithLockTypes() /* Test case for setCaptureMode() */ void tst_QCamera::testSetCaptureMode() { - MockCameraService service; - provider->service = &service; - QCamera camera(0, provider); + QCamera camera; /* Set the capture mode and verify if it set correctly */ camera.setCaptureMode(QCamera::CaptureVideo); @@ -1265,9 +1236,7 @@ void tst_QCamera::testSetCaptureMode() /* Test case for unlock (QCamera::LockTypes) */ void tst_QCamera::testUnlockWithType() { - MockCameraService service; - provider->service = &service; - QCamera camera(0, provider); + QCamera camera; QCOMPARE(camera.lockStatus(), QCamera::Unlocked); @@ -1331,9 +1300,7 @@ void tst_QCamera::testUnlockWithType() /* Test case for signal captureModeChanged(QCamera::CaptureModes) */ void tst_QCamera::testCaptureModeChangedSignal() { - MockCameraService service; - provider->service = &service; - QCamera camera(0, provider); + QCamera camera; QVERIFY(camera.captureMode() == QCamera::CaptureStillImage); qRegisterMetaType<QCamera::CaptureModes>("QCamera::CaptureModes"); @@ -1352,9 +1319,7 @@ void tst_QCamera::testCaptureModeChangedSignal() /* Test case for signal lockStatusChanged(QCamera::LockType,QCamera::LockStatus, QCamera::LockChangeReason) */ void tst_QCamera::testLockStatusChangedWithTypesSignal() { - MockCameraService service; - provider->service = &service; - QCamera camera(0, provider); + QCamera camera; QCOMPARE(camera.lockStatus(), QCamera::Unlocked); @@ -1391,7 +1356,8 @@ void tst_QCamera::testErrorSignal() { MockCameraService service; provider->service = &service; - QCamera camera(0, provider); + + QCamera camera; QSignalSpy spyError(&camera, SIGNAL(error(QCamera::Error))); @@ -1425,7 +1391,8 @@ void tst_QCamera::testError() { MockCameraService service; provider->service = &service; - QCamera camera(0, provider); + + QCamera camera; /* Set the QCameraControl error and verify if it is set correctly in QCamera */ service.mockControl->setError(QCamera::CameraError,QString("Camera Error")); @@ -1446,7 +1413,8 @@ void tst_QCamera::testErrorString() { MockCameraService service; provider->service = &service; - QCamera camera(0, provider); + + QCamera camera; /* Set the QCameraControl error and verify if it is set correctly in QCamera */ service.mockControl->setError(QCamera::CameraError,QString("Camera Error")); @@ -1466,7 +1434,8 @@ void tst_QCamera::testStatus() { MockCameraService service; provider->service = &service; - QCamera camera(0, provider); + + QCamera camera; /* Set the QCameraControl status and verify if it is set correctly in QCamera */ service.mockControl->setStatus(QCamera::StartingStatus); @@ -1488,9 +1457,7 @@ void tst_QCamera::testStatus() /* Test case for verifying default locktype QCamera::NoLock */ void tst_QCamera::testLockType() { - MockCameraService service; - provider->service = &service; - QCamera camera(0, provider); + QCamera camera; QCOMPARE(camera.requestedLocks(),QCamera::NoLock); } @@ -1500,7 +1467,8 @@ void tst_QCamera::testLockChangeReason() { MockCameraService service; provider->service = &service; - QCamera camera(0, provider); + + QCamera camera; QSignalSpy lockStatusChangedSignalWithType(&camera, SIGNAL(lockStatusChanged(QCamera::LockType,QCamera::LockStatus, QCamera::LockChangeReason))); @@ -1554,11 +1522,7 @@ void tst_QCamera::testEnumsOfQCameraControl() // Test case for QCameraImageProcessing class void tst_QCamera::testContrast() { - MockCameraService service; - MockMediaServiceProvider provider; - provider.service = &service; - - QCamera camera(0, &provider); + QCamera camera; QCameraImageProcessing *cameraImageProcessing = camera.imageProcessing(); QVERIFY(cameraImageProcessing->contrast() ==0); @@ -1571,11 +1535,7 @@ void tst_QCamera::testContrast() void tst_QCamera::testDenoisingLevel() { - MockCameraService service; - MockMediaServiceProvider provider; - provider.service = &service; - - QCamera camera(0, &provider); + QCamera camera; QCameraImageProcessing *cameraImageProcessing = camera.imageProcessing(); if (cameraImageProcessing->isDenoisingSupported()) @@ -1594,22 +1554,14 @@ void tst_QCamera::testDenoisingLevel() void tst_QCamera::testIsAvailable() { - MockCameraService service; - MockMediaServiceProvider provider; - provider.service = &service; - - QCamera camera(0, &provider); + QCamera camera; QCameraImageProcessing *cameraImageProcessing = camera.imageProcessing(); QVERIFY(cameraImageProcessing->isAvailable() == true); } void tst_QCamera::testSaturation() { - MockCameraService service; - MockMediaServiceProvider provider; - provider.service = &service; - - QCamera camera(0, &provider); + QCamera camera; QCameraImageProcessing *cameraImageProcessing = camera.imageProcessing(); QVERIFY(cameraImageProcessing->saturation() == 0); @@ -1628,11 +1580,8 @@ void tst_QCamera::testSaturation() void tst_QCamera::testSharpeningLevel() { - MockCameraService service; - MockMediaServiceProvider provider; - provider.service = &service; + QCamera camera; - QCamera camera(0, &provider); QCameraImageProcessing *cameraImageProcessing = camera.imageProcessing(); QVERIFY(cameraImageProcessing->isSharpeningSupported()); QVERIFY(cameraImageProcessing->sharpeningLevel() == -1); @@ -1705,9 +1654,8 @@ void tst_QCamera::testEnumOfQCameraImageProcessing() //Added test cases for QCameraFocus void tst_QCamera::testCameraFocusIsAvailable() { - MockCameraService service; - provider->service = &service; - QCamera camera(0, provider); + QCamera camera; + QCameraFocus *cameraFocus = camera.focus(); QVERIFY(cameraFocus != 0); QVERIFY(cameraFocus->isAvailable()); @@ -1717,9 +1665,8 @@ void tst_QCamera::testCameraFocusIsAvailable() //As the HyperfocalFocus and MacroFocus are not supported we can not set the focus mode to these Focus Modes void tst_QCamera::testFocusModes() { - MockCameraService service; - provider->service = &service; - QCamera camera(0, provider); + QCamera camera; + QCameraFocus *cameraFocus = camera.focus(); QVERIFY(cameraFocus != 0); QVERIFY(!cameraFocus->isFocusModeSupported(QCameraFocus::HyperfocalFocus)); @@ -1735,9 +1682,8 @@ void tst_QCamera::testFocusModes() void tst_QCamera::testOpticalAndDigitalZoomChanged() { - MockCameraService service; - provider->service = &service; - QCamera camera(0, provider); + QCamera camera; + QCameraFocus *cameraFocus = camera.focus(); QVERIFY(cameraFocus != 0); QSignalSpy spy1(cameraFocus,SIGNAL(digitalZoomChanged(qreal))); @@ -1751,9 +1697,8 @@ void tst_QCamera::testOpticalAndDigitalZoomChanged() void tst_QCamera::testMaxDigitalZoomChangedSignal() { - MockCameraService service; - provider->service = &service; - QCamera camera(0, provider); + QCamera camera; + QCameraFocus *cameraFocus = camera.focus(); QVERIFY(cameraFocus != 0); QSignalSpy spy(cameraFocus,SIGNAL(maximumDigitalZoomChanged(qreal))); @@ -1764,9 +1709,8 @@ void tst_QCamera::testMaxDigitalZoomChangedSignal() void tst_QCamera::testMaxOpticalZoomChangedSignal() { - MockCameraService service; - provider->service = &service; - QCamera camera(0, provider); + QCamera camera; + QCameraFocus *cameraFocus = camera.focus(); QVERIFY(cameraFocus != 0); QSignalSpy spy(cameraFocus,SIGNAL(maximumOpticalZoomChanged(qreal))); @@ -1777,9 +1721,8 @@ void tst_QCamera::testMaxOpticalZoomChangedSignal() void tst_QCamera::testfocusZonesChangedSignal() { - MockCameraService service; - provider->service = &service; - QCamera camera(0, provider); + QCamera camera; + QCameraFocus *cameraFocus = camera.focus(); QVERIFY(cameraFocus != 0); @@ -1797,10 +1740,7 @@ void tst_QCamera :: testImageProcessingControl() void tst_QCamera::testSignalApertureChanged() { - MockMediaServiceProvider provider1; - MockCameraService service; - provider1.service = &service; - QCamera camera(0, &provider1); + QCamera camera; QCameraExposure *cameraExposure = camera.exposure(); //create camera expose instance QVERIFY(cameraExposure != 0); @@ -1819,10 +1759,7 @@ void tst_QCamera::testSignalApertureChanged() void tst_QCamera::testSignalExposureCompensationChanged() { - MockMediaServiceProvider provider1; - MockCameraService service; - provider1.service = &service; - QCamera camera(0, &provider1); + QCamera camera; QCameraExposure *cameraExposure = camera.exposure(); //create camera expose instance QVERIFY(cameraExposure != 0); @@ -1850,11 +1787,7 @@ void tst_QCamera::testSignalExposureCompensationChanged() void tst_QCamera::testSignalIsoSensitivityChanged() { - - MockMediaServiceProvider provider1; - MockCameraService service; - provider1.service = &service; - QCamera camera(0, &provider1); + QCamera camera; QCameraExposure *cameraExposure = camera.exposure(); //create camera expose instance QVERIFY(cameraExposure != 0); @@ -1870,11 +1803,7 @@ void tst_QCamera::testSignalIsoSensitivityChanged() } void tst_QCamera::testSignalShutterSpeedChanged() { - - MockMediaServiceProvider provider1; - MockCameraService service; - provider1.service = &service; - QCamera camera(0, &provider1); + QCamera camera; QCameraExposure *cameraExposure = camera.exposure(); //create camera expose instance QVERIFY(cameraExposure != 0); @@ -1893,10 +1822,7 @@ void tst_QCamera::testSignalShutterSpeedChanged() void tst_QCamera::testSignalFlashReady() { - MockMediaServiceProvider provider1; - MockCameraService service; - provider1.service = &service; - QCamera camera(0, &provider1); + QCamera camera; QCameraExposure *cameraExposure = camera.exposure(); //create camera expose instance QVERIFY(cameraExposure != 0); diff --git a/tests/auto/unit/qcameraimagecapture/tst_qcameraimagecapture.cpp b/tests/auto/unit/qcameraimagecapture/tst_qcameraimagecapture.cpp index 32c4a4c3e..64b3bdb80 100644 --- a/tests/auto/unit/qcameraimagecapture/tst_qcameraimagecapture.cpp +++ b/tests/auto/unit/qcameraimagecapture/tst_qcameraimagecapture.cpp @@ -100,6 +100,8 @@ class tst_QCameraImageCapture: public QObject public slots: void initTestCase(); + void init(); + void cleanup(); void cleanupTestCase(); private slots: @@ -129,20 +131,30 @@ private: void tst_QCameraImageCapture::initTestCase() { provider = new MockMediaServiceProvider; + QMediaServiceProvider::setDefaultServiceProvider(provider); +} + +void tst_QCameraImageCapture::init() +{ mockcameraservice = new MockCameraService; provider->service = mockcameraservice; } -void tst_QCameraImageCapture::cleanupTestCase() +void tst_QCameraImageCapture::cleanup() { delete mockcameraservice; + mockcameraservice = 0; +} + +void tst_QCameraImageCapture::cleanupTestCase() +{ delete provider; } //MaemoAPI-1823:test QCameraImageCapture Constructor void tst_QCameraImageCapture::constructor() { - QCamera camera(0, provider); + QCamera camera; QCameraImageCapture imageCapture(&camera); QVERIFY(imageCapture.isAvailable() == true); } @@ -150,15 +162,14 @@ void tst_QCameraImageCapture::constructor() //MaemoAPI-1824:test mediaObject void tst_QCameraImageCapture::mediaObject() { - MockMediaServiceProvider provider1; NullService mymockcameraservice ; - provider1.service = &mymockcameraservice; - QCamera camera(0, &provider1); + provider->service = &mymockcameraservice; + QCamera camera; QCameraImageCapture imageCapture(&camera); - QMediaObject *medobj = imageCapture.mediaObject(); - QVERIFY(medobj == NULL); + QVERIFY(imageCapture.mediaObject() == NULL); - QCamera camera1(0, provider); + provider->service = mockcameraservice; + QCamera camera1; QCameraImageCapture imageCapture1(&camera1); QMediaObject *medobj1 = imageCapture1.mediaObject(); QCOMPARE(medobj1, &camera1); @@ -166,10 +177,9 @@ void tst_QCameraImageCapture::mediaObject() void tst_QCameraImageCapture::deleteMediaObject() { - MockMediaServiceProvider *provider = new MockMediaServiceProvider; provider->service = new MockCameraService; - QCamera *camera = new QCamera(0, provider); + QCamera *camera = new QCamera; QCameraImageCapture *capture = new QCameraImageCapture(camera); QVERIFY(capture->mediaObject() == camera); @@ -177,7 +187,6 @@ void tst_QCameraImageCapture::deleteMediaObject() delete camera; delete provider->service; - delete provider; //capture should detach from camera QVERIFY(capture->mediaObject() == 0); @@ -190,7 +199,7 @@ void tst_QCameraImageCapture::deleteMediaObject() //MaemoAPI-1825:test isReadyForCapture void tst_QCameraImageCapture::isReadyForCapture() { - QCamera camera(0, provider); + QCamera camera; QCameraImageCapture imageCapture(&camera); QVERIFY(imageCapture.isAvailable() == true); QVERIFY(imageCapture.isReadyForCapture() == false); @@ -204,7 +213,7 @@ void tst_QCameraImageCapture::isReadyForCapture() //MaemoAPI-1826:test capture void tst_QCameraImageCapture::capture() { - QCamera camera(0, provider); + QCamera camera; QCameraImageCapture imageCapture(&camera); QVERIFY(imageCapture.isAvailable() == true); QVERIFY(imageCapture.isReadyForCapture() == false); @@ -219,7 +228,7 @@ void tst_QCameraImageCapture::capture() //MaemoAPI-1827:test cancelCapture void tst_QCameraImageCapture::cancelCapture() { - QCamera camera(0, provider); + QCamera camera; QCameraImageCapture imageCapture(&camera); QSignalSpy spy(&imageCapture, SIGNAL(imageCaptured(int,QImage))); QSignalSpy spy1(&imageCapture, SIGNAL(imageSaved(int,QString))); @@ -248,7 +257,7 @@ void tst_QCameraImageCapture::cancelCapture() //MaemoAPI-1829:test set encodingSettings void tst_QCameraImageCapture::encodingSettings() { - QCamera camera(0, provider); + QCamera camera; QCameraImageCapture imageCapture(&camera); QVERIFY(imageCapture.isAvailable() == true); QVERIFY(imageCapture.encodingSettings() == QImageEncoderSettings()); @@ -264,7 +273,7 @@ void tst_QCameraImageCapture::encodingSettings() //MaemoAPI-1838:test supportedImageCodecs void tst_QCameraImageCapture::supportedImageCodecs() { - QCamera camera(0, provider); + QCamera camera; QCameraImageCapture imageCapture(&camera); QVERIFY(imageCapture.isAvailable() == true); QVERIFY(!imageCapture.supportedImageCodecs().isEmpty()); @@ -273,7 +282,7 @@ void tst_QCameraImageCapture::supportedImageCodecs() //MaemoAPI-1836:test supportedResolutions void tst_QCameraImageCapture::supportedResolutions() { - QCamera camera(0, provider); + QCamera camera; QCameraImageCapture imageCapture(&camera); QVERIFY(imageCapture.isAvailable() == true); QVERIFY(imageCapture.supportedResolutions().count() == 2); @@ -287,7 +296,7 @@ void tst_QCameraImageCapture::supportedResolutions() //MaemoAPI-1837:test imageCodecDescription void tst_QCameraImageCapture::imageCodecDescription() { - QCamera camera(0, provider); + QCamera camera; QCameraImageCapture imageCapture(&camera); QVERIFY(imageCapture.isAvailable() == true); QVERIFY(imageCapture.imageCodecDescription(" ").isNull()); @@ -297,11 +306,10 @@ void tst_QCameraImageCapture::imageCodecDescription() //MaemoAPI-1830:test errors void tst_QCameraImageCapture::errors() { - MockMediaServiceProvider provider1 ; MockSimpleCameraService mockSimpleCameraService ; - provider1.service = &mockSimpleCameraService; + provider->service = &mockSimpleCameraService; - QCamera camera1(0, &provider1); + QCamera camera1; QCameraImageCapture imageCapture1(&camera1); QVERIFY(imageCapture1.isAvailable() == false); imageCapture1.capture(QString::fromLatin1("/dev/null")); @@ -309,8 +317,9 @@ void tst_QCameraImageCapture::errors() QVERIFY2(!imageCapture1.errorString().isEmpty(), "Device does not support images capture"); QVERIFY(imageCapture1.availabilityError() == QtMultimedia::ServiceMissingError); + provider->service = mockcameraservice; - QCamera camera(0, provider); + QCamera camera; QCameraImageCapture imageCapture(&camera); QVERIFY(imageCapture.isAvailable() == true); QVERIFY(imageCapture.error() == QCameraImageCapture::NoError); @@ -326,7 +335,7 @@ void tst_QCameraImageCapture::errors() //MaemoAPI-1831:test error void tst_QCameraImageCapture::error() { - QCamera camera(0, provider); + QCamera camera; QCameraImageCapture imageCapture(&camera); QSignalSpy spy(&imageCapture, SIGNAL(error(int,QCameraImageCapture::Error,QString))); imageCapture.capture(); @@ -341,7 +350,7 @@ void tst_QCameraImageCapture::error() //MaemoAPI-1832:test imageCaptured void tst_QCameraImageCapture::imageCaptured() { - QCamera camera(0, provider); + QCamera camera; QCameraImageCapture imageCapture(&camera); QSignalSpy spy(&imageCapture, SIGNAL(imageCaptured(int,QImage))); QVERIFY(imageCapture.isAvailable() == true); @@ -362,7 +371,7 @@ void tst_QCameraImageCapture::imageCaptured() //MaemoAPI-1833:test imageExposed void tst_QCameraImageCapture::imageExposed() { - QCamera camera(0, provider); + QCamera camera; QCameraImageCapture imageCapture(&camera); QSignalSpy spy(&imageCapture, SIGNAL(imageExposed(int))); QVERIFY(imageCapture.isAvailable() == true); @@ -381,7 +390,7 @@ void tst_QCameraImageCapture::imageExposed() //MaemoAPI-1834:test imageSaved void tst_QCameraImageCapture::imageSaved() { - QCamera camera(0, provider); + QCamera camera; QCameraImageCapture imageCapture(&camera); QSignalSpy spy(&imageCapture, SIGNAL(imageSaved(int,QString))); QVERIFY(imageCapture.isAvailable() == true); @@ -401,7 +410,7 @@ void tst_QCameraImageCapture::imageSaved() //MaemoAPI-1835:test readyForCaptureChanged void tst_QCameraImageCapture::readyForCaptureChanged() { - QCamera camera(0, provider); + QCamera camera; QCameraImageCapture imageCapture(&camera); QSignalSpy spy(&imageCapture, SIGNAL(readyForCaptureChanged(bool))); QVERIFY(imageCapture.isReadyForCapture() == false); diff --git a/tests/auto/unit/qcameraviewfinder/tst_qcameraviewfinder.cpp b/tests/auto/unit/qcameraviewfinder/tst_qcameraviewfinder.cpp index 7b73b0a30..2d376abf6 100644 --- a/tests/auto/unit/qcameraviewfinder/tst_qcameraviewfinder.cpp +++ b/tests/auto/unit/qcameraviewfinder/tst_qcameraviewfinder.cpp @@ -74,8 +74,9 @@ void tst_QCameraViewFinder::initTestCase() provider = new MockMediaServiceProvider; mockcameraservice = new MockCameraService; provider->service = mockcameraservice; + QMediaServiceProvider::setDefaultServiceProvider(provider); - camera = new QCamera(0, provider); + camera = new QCamera; viewFinder = new QCameraViewfinder(); } diff --git a/tests/auto/unit/qcamerawidgets/tst_qcamerawidgets.cpp b/tests/auto/unit/qcamerawidgets/tst_qcamerawidgets.cpp index 9ddc713c1..16c724aae 100644 --- a/tests/auto/unit/qcamerawidgets/tst_qcamerawidgets.cpp +++ b/tests/auto/unit/qcamerawidgets/tst_qcamerawidgets.cpp @@ -79,6 +79,8 @@ class tst_QCameraWidgets: public QObject public slots: void initTestCase(); + void init(); + void cleanup(); void cleanupTestCase(); private slots: @@ -88,28 +90,37 @@ private slots: void testSetVideoOutputNoControl(); private: - MockSimpleCameraService *mockSimpleCameraService; + MockCameraService *mockCameraService; MockMediaServiceProvider *provider; }; void tst_QCameraWidgets::initTestCase() { provider = new MockMediaServiceProvider; - mockSimpleCameraService = new MockSimpleCameraService; - provider->service = mockSimpleCameraService; + QMediaServiceProvider::setDefaultServiceProvider(provider); } +void tst_QCameraWidgets::init() +{ + mockCameraService = new MockCameraService; + provider->service = mockCameraService; +} + +void tst_QCameraWidgets::cleanup() +{ + delete mockCameraService; + provider->service = 0; +} + + void tst_QCameraWidgets::cleanupTestCase() { - delete mockSimpleCameraService; delete provider; } void tst_QCameraWidgets::testCameraEncodingProperyChange() { - MockCameraService service; - provider->service = &service; - QCamera camera(0, provider); + QCamera camera; QCameraImageCapture imageCapture(&camera); QSignalSpy stateChangedSignal(&camera, SIGNAL(stateChanged(QCamera::State))); @@ -205,7 +216,7 @@ void tst_QCameraWidgets::testCameraEncodingProperyChange() QTest::qWait(10); - service.mockControl->m_propertyChangesSupported = true; + mockCameraService->mockControl->m_propertyChangesSupported = true; //the changes to encoding settings, //capture mode and encoding parameters should not trigger service restart stateChangedSignal.clear(); @@ -226,11 +237,7 @@ void tst_QCameraWidgets::testSetVideoOutput() QVideoWidget widget; QGraphicsVideoItem item; MockVideoSurface surface; - - MockCameraService service; - MockMediaServiceProvider provider; - provider.service = &service; - QCamera camera(0, &provider); + QCamera camera; camera.setViewfinder(&widget); qDebug() << widget.mediaObject(); @@ -250,20 +257,20 @@ void tst_QCameraWidgets::testSetVideoOutput() QVERIFY(widget.mediaObject() == 0); camera.setViewfinder(&surface); - QVERIFY(service.rendererControl->surface() == &surface); + QVERIFY(mockCameraService->rendererControl->surface() == &surface); camera.setViewfinder(reinterpret_cast<QAbstractVideoSurface *>(0)); - QVERIFY(service.rendererControl->surface() == 0); + QVERIFY(mockCameraService->rendererControl->surface() == 0); camera.setViewfinder(&surface); - QVERIFY(service.rendererControl->surface() == &surface); + QVERIFY(mockCameraService->rendererControl->surface() == &surface); camera.setViewfinder(&widget); - QVERIFY(service.rendererControl->surface() == 0); + QVERIFY(mockCameraService->rendererControl->surface() == 0); QVERIFY(widget.mediaObject() == &camera); camera.setViewfinder(&surface); - QVERIFY(service.rendererControl->surface() == &surface); + QVERIFY(mockCameraService->rendererControl->surface() == &surface); QVERIFY(widget.mediaObject() == 0); } @@ -274,9 +281,8 @@ void tst_QCameraWidgets::testSetVideoOutputNoService() QGraphicsVideoItem item; MockVideoSurface surface; - MockMediaServiceProvider provider; - provider.service = 0; - QCamera camera(0, &provider); + provider->service = 0; + QCamera camera; camera.setViewfinder(&widget); QVERIFY(widget.mediaObject() == 0); @@ -294,13 +300,10 @@ void tst_QCameraWidgets::testSetVideoOutputNoControl() QGraphicsVideoItem item; MockVideoSurface surface; - MockCameraService service; - service.rendererRef = 1; - service.windowRef = 1; + mockCameraService->rendererRef = 1; + mockCameraService->windowRef = 1; - MockMediaServiceProvider provider; - provider.service = &service; - QCamera camera(0, &provider); + QCamera camera; camera.setViewfinder(&widget); QVERIFY(widget.mediaObject() == 0); @@ -309,7 +312,7 @@ void tst_QCameraWidgets::testSetVideoOutputNoControl() QVERIFY(item.mediaObject() == 0); camera.setViewfinder(&surface); - QVERIFY(service.rendererControl->surface() == 0); + QVERIFY(mockCameraService->rendererControl->surface() == 0); } QTEST_MAIN(tst_QCameraWidgets) diff --git a/tests/auto/unit/qmediaplayer/tst_qmediaplayer.cpp b/tests/auto/unit/qmediaplayer/tst_qmediaplayer.cpp index e2131cc45..e441d26b9 100644 --- a/tests/auto/unit/qmediaplayer/tst_qmediaplayer.cpp +++ b/tests/auto/unit/qmediaplayer/tst_qmediaplayer.cpp @@ -179,30 +179,32 @@ void tst_QMediaPlayer::initTestCase() qRegisterMetaType<QMediaPlayer::Error>("QMediaPlayer::Error"); qRegisterMetaType<QMediaPlayer::MediaStatus>("QMediaPlayer::MediaStatus"); qRegisterMetaType<QMediaContent>("QMediaContent"); - - mockService = new MockMediaPlayerService; - mockProvider = new MockMediaServiceProvider(mockService, true); - player = new QMediaPlayer(0, 0, mockProvider); } void tst_QMediaPlayer::cleanupTestCase() { - delete player; } void tst_QMediaPlayer::init() { - mockService->reset(); + mockService = new MockMediaPlayerService; + mockProvider = new MockMediaServiceProvider(mockService); + QMediaServiceProvider::setDefaultServiceProvider(mockProvider); + + player = new QMediaPlayer; } void tst_QMediaPlayer::cleanup() { + delete player; + delete mockProvider; + delete mockService; } void tst_QMediaPlayer::testNullService() { - MockMediaServiceProvider provider(0); - QMediaPlayer player(0, 0, &provider); + mockProvider->service = 0; + QMediaPlayer player; const QIODevice *nullDevice = 0; @@ -901,7 +903,6 @@ void tst_QMediaPlayer::testPlayerFlags() MockMediaServiceProvider provider(0, true); QMediaPlayer::Flag flags = QMediaPlayer::LowLatency; - QMediaPlayer player(0, flags, &provider); QMediaServiceProviderHint::Feature feature; if (flags & QMediaPlayer::LowLatency) @@ -926,7 +927,6 @@ void tst_QMediaPlayer::testPlayerFlags() flags = QMediaPlayer::StreamPlayback; /* Construct a QMediaPlayer that uses the playback service from provider, parented to parent and with flags.*/ - QMediaPlayer player2(0,flags , &provider); if (flags & QMediaPlayer::StreamPlayback) { @@ -948,16 +948,23 @@ void tst_QMediaPlayer::testPlayerFlags() void tst_QMediaPlayer::testDestructor() { + //don't use the same service as tst_QMediaPlayer::player + mockProvider->service = new MockMediaPlayerService; + mockProvider->deleteServiceOnRelease = true; + /* create an object for player */ - MockMediaPlayerService service; - MockMediaServiceProvider provider(&service); - QMediaPlayer *victim = new QMediaPlayer(0, 0, &provider); + QMediaPlayer *victim = new QMediaPlayer; /* check whether the object is created */ QVERIFY(victim); /* delete the instance (a crash is a failure :) */ delete victim; + + //service is released + QVERIFY(mockProvider->service == 0); + + mockProvider->deleteServiceOnRelease = false; } void tst_QMediaPlayer::testNetworkAccess() @@ -992,27 +999,23 @@ void tst_QMediaPlayer::testSetVideoOutput() { MockVideoSurface surface; - MockMediaPlayerService service; - MockMediaServiceProvider provider(&service); - QMediaPlayer player(0, 0, &provider); - - player.setVideoOutput(reinterpret_cast<QVideoWidget *>(0)); - player.setVideoOutput(reinterpret_cast<QGraphicsVideoItem *>(0)); + player->setVideoOutput(reinterpret_cast<QVideoWidget *>(0)); + player->setVideoOutput(reinterpret_cast<QGraphicsVideoItem *>(0)); - player.setVideoOutput(&surface); - QVERIFY(service.rendererControl->surface() == &surface); + player->setVideoOutput(&surface); + QVERIFY(mockService->rendererControl->surface() == &surface); - player.setVideoOutput(reinterpret_cast<QAbstractVideoSurface *>(0)); - QVERIFY(service.rendererControl->surface() == 0); + player->setVideoOutput(reinterpret_cast<QAbstractVideoSurface *>(0)); + QVERIFY(mockService->rendererControl->surface() == 0); - player.setVideoOutput(&surface); - QVERIFY(service.rendererControl->surface() == &surface); + player->setVideoOutput(&surface); + QVERIFY(mockService->rendererControl->surface() == &surface); - player.setVideoOutput(reinterpret_cast<QVideoWidget *>(0)); - QVERIFY(service.rendererControl->surface() == 0); + player->setVideoOutput(reinterpret_cast<QVideoWidget *>(0)); + QVERIFY(mockService->rendererControl->surface() == 0); - player.setVideoOutput(&surface); - QVERIFY(service.rendererControl->surface() == &surface); + player->setVideoOutput(&surface); + QVERIFY(mockService->rendererControl->surface() == &surface); } @@ -1021,7 +1024,8 @@ void tst_QMediaPlayer::testSetVideoOutputNoService() MockVideoSurface surface; MockMediaServiceProvider provider(0, true); - QMediaPlayer player(0, 0, &provider); + QMediaServiceProvider::setDefaultServiceProvider(&provider); + QMediaPlayer player; player.setVideoOutput(&surface); // Nothing we can verify here other than it doesn't assert. @@ -1035,7 +1039,8 @@ void tst_QMediaPlayer::testSetVideoOutputNoControl() service.rendererRef = 1; MockMediaServiceProvider provider(&service); - QMediaPlayer player(0, 0, &provider); + QMediaServiceProvider::setDefaultServiceProvider(&provider); + QMediaPlayer player; player.setVideoOutput(&surface); QVERIFY(service.rendererControl->surface() == 0); @@ -1044,18 +1049,14 @@ void tst_QMediaPlayer::testSetVideoOutputNoControl() void tst_QMediaPlayer::testSetVideoOutputDestruction() { MockVideoSurface surface; - - MockMediaPlayerService service; - MockMediaServiceProvider provider(&service); - { - QMediaPlayer player(0, 0, &provider); + QMediaPlayer player; player.setVideoOutput(&surface); - QVERIFY(service.rendererControl->surface() == &surface); - QCOMPARE(service.rendererRef, 1); + QVERIFY(mockService->rendererControl->surface() == &surface); + QCOMPARE(mockService->rendererRef, 1); } - QVERIFY(service.rendererControl->surface() == 0); - QCOMPARE(service.rendererRef, 0); + QVERIFY(mockService->rendererControl->surface() == 0); + QCOMPARE(mockService->rendererRef, 0); } void tst_QMediaPlayer::testPositionPropertyWatch() diff --git a/tests/auto/unit/qmediaplayerwidgets/tst_qmediaplayerwidgets.cpp b/tests/auto/unit/qmediaplayerwidgets/tst_qmediaplayerwidgets.cpp index 042abfe4f..228f31224 100644 --- a/tests/auto/unit/qmediaplayerwidgets/tst_qmediaplayerwidgets.cpp +++ b/tests/auto/unit/qmediaplayerwidgets/tst_qmediaplayerwidgets.cpp @@ -73,31 +73,25 @@ private slots: void testSetVideoOutputNoControl(); private: - MockMediaServiceProvider *mockProvider; + MockMediaServiceProvider *provider; MockMediaPlayerService *mockService; - QMediaPlayer *player; }; void tst_QMediaPlayerWidgets::initTestCase() { - qRegisterMetaType<QMediaPlayer::State>("QMediaPlayer::State"); - qRegisterMetaType<QMediaPlayer::Error>("QMediaPlayer::Error"); - qRegisterMetaType<QMediaPlayer::MediaStatus>("QMediaPlayer::MediaStatus"); - qRegisterMetaType<QMediaContent>("QMediaContent"); - - mockService = new MockMediaPlayerService; - mockProvider = new MockMediaServiceProvider(mockService, true); - player = new QMediaPlayer(0, 0, mockProvider); + provider = new MockMediaServiceProvider; + QMediaServiceProvider::setDefaultServiceProvider(provider); } void tst_QMediaPlayerWidgets::cleanupTestCase() { - delete player; + delete provider; } void tst_QMediaPlayerWidgets::init() { - mockService->reset(); + mockService = new MockMediaPlayerService; + provider->service = mockService; } void tst_QMediaPlayerWidgets::cleanup() @@ -110,9 +104,7 @@ void tst_QMediaPlayerWidgets::testSetVideoOutput() QGraphicsVideoItem item; MockVideoSurface surface; - MockMediaPlayerService service; - MockMediaServiceProvider provider(&service); - QMediaPlayer player(0, 0, &provider); + QMediaPlayer player; player.setVideoOutput(&widget); QVERIFY(widget.mediaObject() == &player); @@ -131,20 +123,20 @@ void tst_QMediaPlayerWidgets::testSetVideoOutput() QVERIFY(widget.mediaObject() == 0); player.setVideoOutput(&surface); - QVERIFY(service.rendererControl->surface() == &surface); + QVERIFY(mockService->rendererControl->surface() == &surface); player.setVideoOutput(reinterpret_cast<QAbstractVideoSurface *>(0)); - QVERIFY(service.rendererControl->surface() == 0); + QVERIFY(mockService->rendererControl->surface() == 0); player.setVideoOutput(&surface); - QVERIFY(service.rendererControl->surface() == &surface); + QVERIFY(mockService->rendererControl->surface() == &surface); player.setVideoOutput(&widget); - QVERIFY(service.rendererControl->surface() == 0); + QVERIFY(mockService->rendererControl->surface() == 0); QVERIFY(widget.mediaObject() == &player); player.setVideoOutput(&surface); - QVERIFY(service.rendererControl->surface() == &surface); + QVERIFY(mockService->rendererControl->surface() == &surface); QVERIFY(widget.mediaObject() == 0); } @@ -155,8 +147,8 @@ void tst_QMediaPlayerWidgets::testSetVideoOutputNoService() QGraphicsVideoItem item; MockVideoSurface surface; - MockMediaServiceProvider provider(0, true); - QMediaPlayer player(0, 0, &provider); + provider->service = 0; + QMediaPlayer player; player.setVideoOutput(&widget); QVERIFY(widget.mediaObject() == 0); @@ -178,8 +170,9 @@ void tst_QMediaPlayerWidgets::testSetVideoOutputNoControl() service.rendererRef = 1; service.windowRef = 1; - MockMediaServiceProvider provider(&service); - QMediaPlayer player(0, 0, &provider); + provider->service = &service; + + QMediaPlayer player; player.setVideoOutput(&widget); QVERIFY(widget.mediaObject() == 0); diff --git a/tests/auto/unit/qmultimedia_common/mockmediaserviceprovider.h b/tests/auto/unit/qmultimedia_common/mockmediaserviceprovider.h index 3fc941ecf..c31cccd24 100644 --- a/tests/auto/unit/qmultimedia_common/mockmediaserviceprovider.h +++ b/tests/auto/unit/qmultimedia_common/mockmediaserviceprovider.h @@ -63,7 +63,7 @@ public: { if (deleteServiceOnRelease) { delete service; - service = 0; + this->service = 0; } } diff --git a/tests/auto/unit/qradiodata/tst_qradiodata.cpp b/tests/auto/unit/qradiodata/tst_qradiodata.cpp index 59fcedb64..cf6a7f13a 100644 --- a/tests/auto/unit/qradiodata/tst_qradiodata.cpp +++ b/tests/auto/unit/qradiodata/tst_qradiodata.cpp @@ -85,7 +85,8 @@ void tst_QRadioData::initTestCase() mock = new MockRadioDataControl(this); service = new MockMediaService(this, mock); provider = new MockMediaServiceProvider(service); - radio = new QRadioData(0,provider); + QMediaServiceProvider::setDefaultServiceProvider(provider); + radio = new QRadioData; QVERIFY(radio->service() != 0); QVERIFY(radio->isAvailable()); QVERIFY(radio->availabilityError() == QtMultimedia::NoError); @@ -105,8 +106,10 @@ void tst_QRadioData::testNullService() { const QPair<int, int> nullRange(0, 0); - MockMediaServiceProvider provider(0); - QRadioData radio(0, &provider); + MockMediaServiceProvider nullProvider(0); + QMediaServiceProvider::setDefaultServiceProvider(&nullProvider); + QRadioData radio; + QVERIFY(!radio.isAvailable()); QCOMPARE(radio.error(), QRadioData::ResourceError); QCOMPARE(radio.errorString(), QString()); @@ -125,7 +128,8 @@ void tst_QRadioData::testNullControl() MockMediaService service(0, 0); MockMediaServiceProvider provider(&service); - QRadioData radio(0, &provider); + QMediaServiceProvider::setDefaultServiceProvider(&provider); + QRadioData radio; QVERIFY(!radio.isAvailable()); QCOMPARE(radio.error(), QRadioData::ResourceError); QCOMPARE(radio.errorString(), QString()); diff --git a/tests/auto/unit/qradiotuner/tst_qradiotuner.cpp b/tests/auto/unit/qradiotuner/tst_qradiotuner.cpp index b391424be..8351fa9e2 100644 --- a/tests/auto/unit/qradiotuner/tst_qradiotuner.cpp +++ b/tests/auto/unit/qradiotuner/tst_qradiotuner.cpp @@ -64,6 +64,7 @@ class tst_QRadioTuner: public QObject public slots: void initTestCase(); void cleanupTestCase(); + void init(); private slots: void testNullService(); @@ -93,7 +94,9 @@ void tst_QRadioTuner::initTestCase() mock = new MockRadioTunerControl(this); service = new MockMediaService(this, mock); provider = new MockMediaServiceProvider(service); - radio = new QRadioTuner(0,provider); + QMediaServiceProvider::setDefaultServiceProvider(provider); + + radio = new QRadioTuner; QVERIFY(radio->service() != 0); QVERIFY(radio->isAvailable()); QVERIFY(radio->availabilityError() == QtMultimedia::NoError); @@ -128,12 +131,19 @@ void tst_QRadioTuner::cleanupTestCase() delete provider; } +void tst_QRadioTuner::init() +{ + QMediaServiceProvider::setDefaultServiceProvider(provider); +} + void tst_QRadioTuner::testNullService() { const QPair<int, int> nullRange(0, 0); MockMediaServiceProvider provider(0); - QRadioTuner radio(0, &provider); + QMediaServiceProvider::setDefaultServiceProvider(&provider); + + QRadioTuner radio; QVERIFY(!radio.isAvailable()); radio.start(); QCOMPARE(radio.error(), QRadioTuner::ResourceError); @@ -161,7 +171,8 @@ void tst_QRadioTuner::testNullControl() MockMediaService service(0, 0); MockMediaServiceProvider provider(&service); - QRadioTuner radio(0, &provider); + QMediaServiceProvider::setDefaultServiceProvider(&provider); + QRadioTuner radio; QVERIFY(!radio.isAvailable()); radio.start(); @@ -346,7 +357,8 @@ void tst_QRadioTuner::errorSignal() MockRadioTunerControl dctrl(&obj); MockMediaService service(&obj, &dctrl); MockMediaServiceProvider provider(&service); - QRadioTuner radio(0,&provider); + QMediaServiceProvider::setDefaultServiceProvider(&provider); + QRadioTuner radio; QSignalSpy spy(&radio, SIGNAL(error(QRadioTuner::Error))); QVERIFY(radio.service() != 0); QVERIFY(radio.isAvailable()); |