diff options
94 files changed, 8812 insertions, 2394 deletions
diff --git a/tests/auto/multimedia.pro b/tests/auto/multimedia.pro index aa3c7861b..9bacbbff6 100644 --- a/tests/auto/multimedia.pro +++ b/tests/auto/multimedia.pro @@ -4,6 +4,17 @@ SUBDIRS += \ qabstractvideobuffer \ qabstractvideosurface \ qaudiocapturesource \ + qaudiodeviceinfo \ + qaudioformat \ + qaudioinput \ + qaudiooutput \ + qcamera \ + qcamerabackend \ + qcameraimagecapture \ + qcameraviewfinder \ + qmediabindableinterface \ + qmediacontainercontrol \ + qmediacontent \ qmediaobject \ qmediaplayer \ qmediaplayerbackend \ @@ -11,17 +22,24 @@ SUBDIRS += \ qmediarecorder \ qmediaresource \ qmediaservice \ - qmediacontent \ - qradiotuner \ - qcamera \ qmediatimerange \ - qaudiodeviceinfo \ - qaudiooutput \ - qaudioinput \ - qaudioformat \ + qradiotuner \ qvideoframe \ qvideosurfaceformat \ - qcamerabackend + qmetadatareadercontrol \ + qmetadatawritercontrol \ + +# This is disabled because it is unfinished +# qmediastreamscontrol \ + +# These is disabled until intent is clearer +# qvideodevicecontrol \ +# qvideoencodercontrol \ + +# This is a commment for the mock backend directory so that maketestselftest +# doesn't believe it's an untested directory +# qmultimedia_common + # Tests depending on private interfaces should only be built if # these interfaces are exported. @@ -47,4 +65,3 @@ contains (QT_CONFIG, declarative) { disabled:SUBDIRS += qdeclarativevideo } } - diff --git a/tests/auto/qabstractvideobuffer/tst_qabstractvideobuffer.cpp b/tests/auto/qabstractvideobuffer/tst_qabstractvideobuffer.cpp index 7e339eefb..f15bed5c7 100644 --- a/tests/auto/qabstractvideobuffer/tst_qabstractvideobuffer.cpp +++ b/tests/auto/qabstractvideobuffer/tst_qabstractvideobuffer.cpp @@ -62,6 +62,7 @@ private slots: void handleType_data(); void handleType(); void handle(); + void mapMode(); }; class QtTestVideoBuffer : public QAbstractVideoBuffer @@ -69,7 +70,7 @@ class QtTestVideoBuffer : public QAbstractVideoBuffer public: QtTestVideoBuffer(QAbstractVideoBuffer::HandleType type) : QAbstractVideoBuffer(type) {} - MapMode mapMode() const { return NotMapped; } + MapMode mapMode() const { return QAbstractVideoBuffer::ReadWrite; } uchar *map(MapMode, int *, int *) { return 0; } void unmap() {} @@ -107,6 +108,12 @@ void tst_QAbstractVideoBuffer::handleType_data() << QAbstractVideoBuffer::NoHandle; QTest::newRow("opengl") << QAbstractVideoBuffer::GLTextureHandle; + QTest::newRow("XvShmImageHandle") + << QAbstractVideoBuffer::XvShmImageHandle; + QTest::newRow("CoreImageHandle") + << QAbstractVideoBuffer::CoreImageHandle; + QTest::newRow("QPixmapHandle") + << QAbstractVideoBuffer::QPixmapHandle; QTest::newRow("user1") << QAbstractVideoBuffer::UserHandle; QTest::newRow("user2") @@ -129,6 +136,12 @@ void tst_QAbstractVideoBuffer::handle() QVERIFY(buffer.handle().isNull()); } +void tst_QAbstractVideoBuffer::mapMode() +{ + QtTestVideoBuffer maptest(QAbstractVideoBuffer::NoHandle); + QVERIFY2(maptest.mapMode() == QAbstractVideoBuffer::ReadWrite, "ReadWrite Failed"); +} + QTEST_MAIN(tst_QAbstractVideoBuffer) #include "tst_qabstractvideobuffer.moc" diff --git a/tests/auto/qabstractvideosurface/tst_qabstractvideosurface.cpp b/tests/auto/qabstractvideosurface/tst_qabstractvideosurface.cpp index bef9c7f38..f62cd5aeb 100644 --- a/tests/auto/qabstractvideosurface/tst_qabstractvideosurface.cpp +++ b/tests/auto/qabstractvideosurface/tst_qabstractvideosurface.cpp @@ -67,6 +67,8 @@ private slots: void nearestFormat(); void start_data(); void start(); + void nativeResolution(); + void supportedFormatsChanged(); }; typedef QMap<QAbstractVideoBuffer::HandleType, QVideoFrame::PixelFormat> SupportedFormatMap; @@ -93,6 +95,20 @@ public: using QAbstractVideoSurface::setError; + /* adding protected setNativeResolution*/ + using QAbstractVideoSurface::setNativeResolution; + + /* fun to generate supportedFormatsChanged signal */ + QList<QVideoFrame::PixelFormat> supportedPixelFormatsChange(QList<QVideoFrame::PixelFormat> formats) + { + supportedFormats.insertMulti(QAbstractVideoBuffer::NoHandle, QVideoFrame::Format_RGB32); + QList<QVideoFrame::PixelFormat> supportedFormats = supportedPixelFormats(); + if (supportedFormats.count() != formats.count()) { + emit supportedFormatsChanged(); + } + return supportedFormats; + } + private: SupportedFormatMap supportedFormats; }; @@ -137,6 +153,12 @@ void tst_QAbstractVideoSurface::setError() surface.setError(QAbstractVideoSurface::NoError); QCOMPARE(surface.error(), QAbstractVideoSurface::NoError); + + surface.setError(QAbstractVideoSurface::UnsupportedFormatError); + QCOMPARE(surface.error(), QAbstractVideoSurface::UnsupportedFormatError); + + surface.setError(QAbstractVideoSurface::IncorrectFormatError); + QCOMPARE(surface.error(), QAbstractVideoSurface::IncorrectFormatError); } void tst_QAbstractVideoSurface::isFormatSupported_data() @@ -307,6 +329,44 @@ void tst_QAbstractVideoSurface::start() QCOMPARE(activeSpy.last().at(0).toBool(), false); } +// Test nativeResolution property +void tst_QAbstractVideoSurface::nativeResolution() +{ + QtTestVideoSurface surface; + QSignalSpy spy(&surface, SIGNAL(nativeResolutionChanged(QSize))); + QSize size1 = surface.nativeResolution(); + QVERIFY(size1.width() == -1); + QVERIFY(size1.height() == -1); + QVERIFY(spy.count() == 0); + + QSize res(100,150); + surface.setNativeResolution(res); + QVERIFY(spy.count() == 1); + + QSize size2 = qvariant_cast<QSize>(spy.at(0).at(0)); + QVERIFY(size2.width() == 100); + QVERIFY(size2.height() == 150); + spy.clear(); +} + +// QAbstractVideoSurface's supported Formats Changed Signal +void tst_QAbstractVideoSurface::supportedFormatsChanged() +{ + SupportedFormatMap formatMap; + formatMap.insertMulti(QAbstractVideoBuffer::NoHandle, QVideoFrame::Format_RGB24); + QtTestVideoSurface surface(formatMap); + QSignalSpy spy(&surface, SIGNAL(supportedFormatsChanged())); + QList<QVideoFrame::PixelFormat> formats = surface.supportedPixelFormats(); + QVERIFY(formats.count() == 1); + QVERIFY(spy.count() == 0); + + // user defined implementation for generation of supportedFormatsChanged signal + QList<QVideoFrame::PixelFormat> newFormats = surface.supportedPixelFormatsChange(formats); + QVERIFY(newFormats.count() == (formats.count() + 1)); + QVERIFY(spy.count() == 1); + spy.clear(); +} + QTEST_MAIN(tst_QAbstractVideoSurface) #include "tst_qabstractvideosurface.moc" diff --git a/tests/auto/qaudiocapturesource/qaudiocapturesource.pro b/tests/auto/qaudiocapturesource/qaudiocapturesource.pro index df9c70eaf..65c6cf3b4 100644 --- a/tests/auto/qaudiocapturesource/qaudiocapturesource.pro +++ b/tests/auto/qaudiocapturesource/qaudiocapturesource.pro @@ -2,8 +2,8 @@ load(qttest_p4) QT += multimediakit-private -# TARGET = tst_qaudiocapturesource -# CONFIG += testcase - SOURCES += tst_qaudiocapturesource.cpp +include (../qmultimedia_common/mockrecorder.pri) +include (../qmultimedia_common/mock.pri) + diff --git a/tests/auto/qaudiocapturesource/tst_qaudiocapturesource.cpp b/tests/auto/qaudiocapturesource/tst_qaudiocapturesource.cpp index 8a40459e4..f798d8f2c 100644 --- a/tests/auto/qaudiocapturesource/tst_qaudiocapturesource.cpp +++ b/tests/auto/qaudiocapturesource/tst_qaudiocapturesource.cpp @@ -48,218 +48,16 @@ #include <qaudioencodercontrol.h> #include <qmediarecordercontrol.h> #include <qaudioendpointselector.h> +#include <qaudiodeviceinfo.h> +#include <qaudioinput.h> +#include <qmediaobject.h> //TESTED_COMPONENT=src/multimedia -QT_USE_NAMESPACE -class MockAudioEncoderControl : public QAudioEncoderControl -{ - Q_OBJECT -public: - MockAudioEncoderControl(QObject *parent = 0): - QAudioEncoderControl(parent) - { - m_codecs << "audio/pcm" << "audio/mpeg"; - m_descriptions << "Pulse Code Modulation" << "mp3 format"; - m_audioSettings.setCodec("audio/pcm"); - m_audioSettings.setSampleRate(8000); - m_freqs << 8000 << 11025 << 22050 << 44100; - } - - ~MockAudioEncoderControl() {} - - QStringList supportedAudioCodecs() const { return m_codecs; } - QString codecDescription(const QString &codecName) const { return m_descriptions.at(m_codecs.indexOf(codecName)); } - - QStringList supportedEncodingOptions(const QString &) const { return QStringList() << "bitrate"; } - QVariant encodingOption(const QString &, const QString &) const { return m_optionValue; } - void setEncodingOption(const QString &, const QString &, const QVariant &value) { m_optionValue = value; } - - QList<int> supportedSampleRates(const QAudioEncoderSettings & = QAudioEncoderSettings(), - bool *continuous = 0) const - { - if (continuous) - *continuous = false; - return m_freqs; - } - QList<int> supportedChannelCounts(const QAudioEncoderSettings & = QAudioEncoderSettings()) const { QList<int> list; list << 1 << 2; return list; } - - QAudioEncoderSettings audioSettings() const { return m_audioSettings; } - void setAudioSettings(const QAudioEncoderSettings &settings) { m_audioSettings = settings;} - - QStringList m_codecs; - QStringList m_descriptions; - - QAudioEncoderSettings m_audioSettings; - - QList<int> m_freqs; - QVariant m_optionValue; -}; - -class MockMediaRecorderControl : public QMediaRecorderControl -{ - Q_OBJECT -public: - MockMediaRecorderControl(QObject *parent = 0): - QMediaRecorderControl(parent), - m_state(QMediaRecorder::StoppedState), - m_position(0), - m_muted(false) {} - - ~MockMediaRecorderControl() {} - - QUrl outputLocation() const { return m_sink; } - bool setOutputLocation(const QUrl &sink) { m_sink = sink; return true; } - QMediaRecorder::State state() const { return m_state; } - qint64 duration() const { return m_position; } - void applySettings() {} - bool isMuted() const { return m_muted; } - -public slots: - void record() - { - m_state = QMediaRecorder::RecordingState; - m_position=1; - emit stateChanged(m_state); - emit durationChanged(m_position); - } - void pause() - { - m_state = QMediaRecorder::PausedState; - emit stateChanged(m_state); - } - - void stop() - { - m_position=0; - m_state = QMediaRecorder::StoppedState; - emit stateChanged(m_state); - } - - void setMuted(bool muted) - { - if (m_muted != muted) - emit mutedChanged(m_muted = muted); - } - -public: - QUrl m_sink; - QMediaRecorder::State m_state; - qint64 m_position; - bool m_muted; -}; - -class MockAudioEndpointSelector : public QAudioEndpointSelector -{ - Q_OBJECT -public: - MockAudioEndpointSelector(QObject *parent): - QAudioEndpointSelector(parent) - { - m_names << "device1" << "device2" << "device3"; - m_descriptions << "dev1 comment" << "dev2 comment" << "dev3 comment"; - m_audioInput = "device1"; - emit availableEndpointsChanged(); - } - ~MockAudioEndpointSelector() {}; - - QList<QString> availableEndpoints() const - { - return m_names; - } - - QString endpointDescription(const QString& name) const - { - QString desc; - - for(int i = 0; i < m_names.count(); i++) { - if (m_names.at(i).compare(name) == 0) { - desc = m_descriptions.at(i); - break; - } - } - return desc; - } - - QString defaultEndpoint() const - { - return m_names.at(0); - } - - QString activeEndpoint() const - { - return m_audioInput; - } - -public Q_SLOTS: - void setActiveEndpoint(const QString& name) - { - m_audioInput = name; - emit activeEndpointChanged(name); - } - -private: - QString m_audioInput; - QList<QString> m_names; - QList<QString> m_descriptions; -}; - - -class MockAudioSourceService : public QMediaService -{ - Q_OBJECT - -public: - MockAudioSourceService(): QMediaService(0), hasAudioDeviceControl(true) - { - mockAudioEncoderControl = new MockAudioEncoderControl(this); - mockMediaRecorderControl = new MockMediaRecorderControl(this); - mockAudioEndpointSelector = new MockAudioEndpointSelector(this); - } - - ~MockAudioSourceService() - { - delete mockAudioEncoderControl; - delete mockMediaRecorderControl; - delete mockAudioEndpointSelector; - } - - QMediaControl* requestControl(const char *iid) - { - if (qstrcmp(iid, QAudioEncoderControl_iid) == 0) - return mockAudioEncoderControl; - - if (qstrcmp(iid, QMediaRecorderControl_iid) == 0) - return mockMediaRecorderControl; - - if (hasAudioDeviceControl && qstrcmp(iid, QAudioEndpointSelector_iid) == 0) - return mockAudioEndpointSelector; - - return 0; - } - - void releaseControl(QMediaControl*) {} - - MockAudioEncoderControl *mockAudioEncoderControl; - MockMediaRecorderControl *mockMediaRecorderControl; - MockAudioEndpointSelector *mockAudioEndpointSelector; - bool hasAudioDeviceControl; -}; - -class MockProvider : public QMediaServiceProvider -{ -public: - MockProvider(MockAudioSourceService *service):mockService(service) {} - QMediaService *requestService(const QByteArray&, const QMediaServiceProviderHint &) - { - return mockService; - } - - void releaseService(QMediaService *) {} - - MockAudioSourceService *mockService; -}; +#include "mockmediaserviceprovider.h" +#include "mockmediarecorderservice.h" +QT_USE_NAMESPACE class tst_QAudioCaptureSource: public QObject { @@ -275,23 +73,26 @@ private slots: void testAudioSource(); void testOptions(); void testDevices(); + void testAvailability(); + void testAvailableAudioInputChangedSignal(); private: QAudioCaptureSource *audiosource; - MockAudioSourceService *mockAudioSourceService; - MockProvider *mockProvider; + MockMediaRecorderService *mockMediaRecorderService; + MockMediaServiceProvider *mockProvider; }; void tst_QAudioCaptureSource::initTestCase() { - mockAudioSourceService = new MockAudioSourceService; - mockProvider = new MockProvider(mockAudioSourceService); + mockMediaRecorderService = new MockMediaRecorderService; + mockProvider = new MockMediaServiceProvider(mockMediaRecorderService); } void tst_QAudioCaptureSource::cleanupTestCase() { delete audiosource; delete mockProvider; + audiosource = 0; } /* void tst_QAudioCaptureSource::testNullService() @@ -307,7 +108,7 @@ void tst_QAudioCaptureSource::testNullService() /* void tst_QAudioCaptureSource::testNullControl() { - MockAudioSourceService service; + MockRecorderService service; service.hasAudioDeviceControl = false; MockProvider provider(&service); QAudioCaptureSource source(0, &provider); @@ -328,31 +129,74 @@ void tst_QAudioCaptureSource::testAudioSource() { audiosource = new QAudioCaptureSource(0, mockProvider); - QCOMPARE(audiosource->service(),(QMediaService *) mockAudioSourceService); + QCOMPARE(audiosource->service(),(QMediaService *) mockMediaRecorderService); } void tst_QAudioCaptureSource::testOptions() { - const QString codec(QLatin1String("mp3")); + const QString codec(QLatin1String("audio/mpeg")); - QStringList options = mockAudioSourceService->mockAudioEncoderControl->supportedEncodingOptions(codec); - QVERIFY(options.count() == 1); - mockAudioSourceService->mockAudioEncoderControl->setEncodingOption(codec, options.first(),8000); - QVERIFY(mockAudioSourceService->mockAudioEncoderControl->encodingOption(codec, options.first()).toInt() == 8000); + QStringList options = mockMediaRecorderService->mockAudioEncoderControl->supportedEncodingOptions(codec); + QCOMPARE(options.count(), 4); + mockMediaRecorderService->mockAudioEncoderControl->setEncodingOption(codec, options.first(),8000); + QVERIFY(mockMediaRecorderService->mockAudioEncoderControl->encodingOption(codec, options.first()).toInt() == 8000); } void tst_QAudioCaptureSource::testDevices() { + audiosource = new QAudioCaptureSource(0,mockProvider); QList<QString> devices = audiosource->audioInputs(); QVERIFY(devices.size() > 0); QVERIFY(devices.at(0).compare("device1") == 0); QVERIFY(audiosource->audioDescription("device1").compare("dev1 comment") == 0); QVERIFY(audiosource->defaultAudioInput() == "device1"); + QVERIFY(audiosource->isAvailable() == true); QSignalSpy checkSignal(audiosource, SIGNAL(activeAudioInputChanged(QString))); audiosource->setAudioInput("device2"); QVERIFY(audiosource->activeAudioInput().compare("device2") == 0); QVERIFY(checkSignal.count() == 1); + QVERIFY(audiosource->isAvailable() == true); +} + +void tst_QAudioCaptureSource::testAvailability() +{ + MockMediaRecorderService service; + service.hasControls = false; + MockMediaServiceProvider provider(&service); + QAudioCaptureSource source(0, &provider); + + QVERIFY(source.isAvailable() == false); + QVERIFY(source.availabilityError() == QtMultimediaKit::ServiceMissingError); + + service.hasControls = true; + MockMediaServiceProvider provider2(&service); + QAudioCaptureSource source2(0, &provider2); + + QVERIFY(source2.isAvailable() == true); + QVERIFY(source2.availabilityError() == QtMultimediaKit::NoError); +} + +void tst_QAudioCaptureSource::testAvailableAudioInputChangedSignal() +{ + // The availabilityChangedSignal is implemented in QAudioCaptureSource. SO using it to test the signal. + audiosource = new QAudioCaptureSource(0, mockProvider); + + /* Spy the signal availableEndpointChanged and audioInputchanged */ + QSignalSpy changed(mockMediaRecorderService->mockAudioEndpointSelector, SIGNAL(availableEndpointsChanged())); + QSignalSpy audioInputchange(audiosource, SIGNAL(availableAudioInputsChanged())); + + /* Add the end points and verify if the available end point changed signal is emitted. */ + QMetaObject::invokeMethod(mockMediaRecorderService->mockAudioEndpointSelector, "addEndpoints"); + QVERIFY(changed.count() == 1); + QVERIFY(audioInputchange.count() == 1); + + /* Now try removes */ + changed.clear(); + audioInputchange.clear(); + QMetaObject::invokeMethod(mockMediaRecorderService->mockAudioEndpointSelector, "removeEndpoints"); + QVERIFY(changed.count() == 1); + QVERIFY(audioInputchange.count() == 1); } QTEST_MAIN(tst_QAudioCaptureSource) diff --git a/tests/auto/qaudiodeviceinfo/tst_qaudiodeviceinfo.cpp b/tests/auto/qaudiodeviceinfo/tst_qaudiodeviceinfo.cpp index 29225bc62..f459a7449 100644 --- a/tests/auto/qaudiodeviceinfo/tst_qaudiodeviceinfo.cpp +++ b/tests/auto/qaudiodeviceinfo/tst_qaudiodeviceinfo.cpp @@ -66,9 +66,14 @@ private slots: void byteOrders(); void sampleTypes(); void frequencies(); - void isformat(); + void isFormatSupported(); void preferred(); void nearest(); + void supportedChannelCounts(); + void supportedSampleRates(); + void assignOperator(); + void deviceName(); + void defaultConstructor(); private: bool available; @@ -79,7 +84,7 @@ void tst_QAudioDeviceInfo::initTestCase() { // Only perform tests if audio output device exists! QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput); - if(devices.size() > 0) + if (devices.size() > 0) available = true; else { qWarning()<<"NOTE: no audio output device found, no test will be performed"; @@ -92,26 +97,26 @@ void tst_QAudioDeviceInfo::checkAvailableDefaultInput() // Only perform tests if audio input device exists! bool storeAvailable = available; QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices(QAudio::AudioInput); - if(devices.size() > 0) + if (devices.size() > 0) available = true; else { qWarning()<<"NOTE: no audio input device found, no test will be performed"; available = false; } - if(available) + if (available) QVERIFY(!QAudioDeviceInfo::defaultInputDevice().isNull()); available = storeAvailable; } void tst_QAudioDeviceInfo::checkAvailableDefaultOutput() { - if(available) + if (available) QVERIFY(!QAudioDeviceInfo::defaultOutputDevice().isNull()); } void tst_QAudioDeviceInfo::outputList() { - if(available) { + if (available) { QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput); QVERIFY(devices.size() > 0); device = new QAudioDeviceInfo(devices.at(0)); @@ -120,7 +125,7 @@ void tst_QAudioDeviceInfo::outputList() void tst_QAudioDeviceInfo::codecs() { - if(available) { + if (available) { QStringList avail = device->supportedCodecs(); QVERIFY(avail.size() > 0); } @@ -128,7 +133,7 @@ void tst_QAudioDeviceInfo::codecs() void tst_QAudioDeviceInfo::channels() { - if(available) { + if (available) { QList<int> avail = device->supportedChannels(); QVERIFY(avail.size() > 0); } @@ -136,7 +141,7 @@ void tst_QAudioDeviceInfo::channels() void tst_QAudioDeviceInfo::sampleSizes() { - if(available) { + if (available) { QList<int> avail = device->supportedSampleSizes(); QVERIFY(avail.size() > 0); } @@ -144,7 +149,7 @@ void tst_QAudioDeviceInfo::sampleSizes() void tst_QAudioDeviceInfo::byteOrders() { - if(available) { + if (available) { QList<QAudioFormat::Endian> avail = device->supportedByteOrders(); QVERIFY(avail.size() > 0); } @@ -152,7 +157,7 @@ void tst_QAudioDeviceInfo::byteOrders() void tst_QAudioDeviceInfo::sampleTypes() { - if(available) { + if (available) { QList<QAudioFormat::SampleType> avail = device->supportedSampleTypes(); QVERIFY(avail.size() > 0); } @@ -160,16 +165,16 @@ void tst_QAudioDeviceInfo::sampleTypes() void tst_QAudioDeviceInfo::frequencies() { - if(available) { + if (available) { QList<int> avail = device->supportedFrequencies(); QVERIFY(avail.size() > 0); } } -void tst_QAudioDeviceInfo::isformat() +void tst_QAudioDeviceInfo::isFormatSupported() { - if(available) { - QAudioFormat format; + if (available) { + QAudioFormat format; format.setFrequency(44100); format.setChannels(2); format.setSampleType(QAudioFormat::SignedInt); @@ -184,24 +189,89 @@ void tst_QAudioDeviceInfo::isformat() void tst_QAudioDeviceInfo::preferred() { - if(available) { + if (available) { QAudioFormat format = device->preferredFormat(); QVERIFY(format.isValid()); } } +// Returns closest QAudioFormat to settings that system audio supports. void tst_QAudioDeviceInfo::nearest() { - if(available) { + if (available) { /* QAudioFormat format1, format2; format1.setFrequency(8000); format2 = device->nearestFormat(format1); QVERIFY(format2.frequency() == 44100); */ + QAudioFormat format; + format.setFrequency(44100); + format.setChannels(2); + format.setSampleType(QAudioFormat::SignedInt); + format.setByteOrder(QAudioFormat::LittleEndian); + format.setSampleSize(16); + format.setCodec("audio/pcm"); + + QAudioFormat format2 = device->nearestFormat(format); + + // This is definitely dependent on platform support (but isFormatSupported tests that above) + QVERIFY(format2.frequency() == 44100); } } +// Returns a list of supported channel counts. +void tst_QAudioDeviceInfo::supportedChannelCounts() +{ + if (available) { + QList<int> avail = device->supportedChannelCounts(); + QVERIFY(avail.size() > 0); + } +} + +// Returns a list of supported sample rates. +void tst_QAudioDeviceInfo::supportedSampleRates() +{ + if (available) { + QList<int> avail = device->supportedSampleRates(); + QVERIFY(avail.size() > 0); + } +} + +// QAudioDeviceInfo's assignOperator method +void tst_QAudioDeviceInfo::assignOperator() +{ + QAudioDeviceInfo dev; + QVERIFY(dev.deviceName() == NULL); + QVERIFY(dev.isNull() == true); + + if (available) { + QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput); + QVERIFY(devices.size() > 0); + QAudioDeviceInfo dev1(devices.at(0)); + dev = dev1; + QVERIFY(dev.isNull() == false); + QVERIFY(dev.deviceName() == dev1.deviceName()); + } +} + +// Returns human readable name of audio device +void tst_QAudioDeviceInfo::deviceName() +{ + if (available) { + QVERIFY(device->deviceName() != NULL); + QVERIFY(device->deviceName() == QAudioDeviceInfo::availableDevices(QAudio::AudioOutput).at(0).deviceName()); + } +} + +// QAudioDeviceInfo's defaultConstructor method +void tst_QAudioDeviceInfo::defaultConstructor() +{ + QAudioDeviceInfo dev; + QVERIFY(dev.isNull() == true); + QVERIFY(dev.deviceName() == NULL); +} + QTEST_MAIN(tst_QAudioDeviceInfo) #include "tst_qaudiodeviceinfo.moc" diff --git a/tests/auto/qaudioformat/tst_qaudioformat.cpp b/tests/auto/qaudioformat/tst_qaudioformat.cpp index d543708ae..4685805c2 100644 --- a/tests/auto/qaudioformat/tst_qaudioformat.cpp +++ b/tests/auto/qaudioformat/tst_qaudioformat.cpp @@ -59,23 +59,24 @@ public: private slots: void checkNull(); void checkFrequency(); - void checkChannels(); void checkSampleSize(); void checkCodec(); void checkByteOrder(); void checkSampleType(); void checkEquality(); void checkAssignment(); + void checkSampleRate(); + void checkChannelCount(); }; void tst_QAudioFormat::checkNull() { // Default constructed QAudioFormat is invalid. - QAudioFormat audioFormat0; + QAudioFormat audioFormat0; QVERIFY(!audioFormat0.isValid()); // validity is transferred - QAudioFormat audioFormat1(audioFormat0); + QAudioFormat audioFormat1(audioFormat0); QVERIFY(!audioFormat1.isValid()); audioFormat0.setFrequency(44100); @@ -88,50 +89,52 @@ void tst_QAudioFormat::checkNull() void tst_QAudioFormat::checkFrequency() { - QAudioFormat audioFormat; + QAudioFormat audioFormat; audioFormat.setFrequency(44100); QVERIFY(audioFormat.frequency() == 44100); } -void tst_QAudioFormat::checkChannels() -{ - QAudioFormat audioFormat; - audioFormat.setChannels(2); - QVERIFY(audioFormat.channels() == 2); -} - void tst_QAudioFormat::checkSampleSize() { - QAudioFormat audioFormat; + QAudioFormat audioFormat; audioFormat.setSampleSize(16); QVERIFY(audioFormat.sampleSize() == 16); } void tst_QAudioFormat::checkCodec() { - QAudioFormat audioFormat; + QAudioFormat audioFormat; audioFormat.setCodec(QString::fromLatin1("audio/pcm")); QVERIFY(audioFormat.codec() == QString::fromLatin1("audio/pcm")); } void tst_QAudioFormat::checkByteOrder() { - QAudioFormat audioFormat; + QAudioFormat audioFormat; audioFormat.setByteOrder(QAudioFormat::LittleEndian); QVERIFY(audioFormat.byteOrder() == QAudioFormat::LittleEndian); + + audioFormat.setByteOrder(QAudioFormat::BigEndian); + QVERIFY(audioFormat.byteOrder() == QAudioFormat::BigEndian); } void tst_QAudioFormat::checkSampleType() { - QAudioFormat audioFormat; + QAudioFormat audioFormat; audioFormat.setSampleType(QAudioFormat::SignedInt); QVERIFY(audioFormat.sampleType() == QAudioFormat::SignedInt); + + audioFormat.setSampleType(QAudioFormat::Unknown); + QVERIFY(audioFormat.sampleType() == QAudioFormat::Unknown); + + audioFormat.setSampleType(QAudioFormat::Float); + QVERIFY(audioFormat.sampleType() == QAudioFormat::Float); } void tst_QAudioFormat::checkEquality() { - QAudioFormat audioFormat0; - QAudioFormat audioFormat1; + QAudioFormat audioFormat0; + QAudioFormat audioFormat1; // Null formats are equivalent QVERIFY(audioFormat0 == audioFormat1); @@ -162,8 +165,8 @@ void tst_QAudioFormat::checkEquality() void tst_QAudioFormat::checkAssignment() { - QAudioFormat audioFormat0; - QAudioFormat audioFormat1; + QAudioFormat audioFormat0; + QAudioFormat audioFormat1; audioFormat0.setFrequency(8000); audioFormat0.setChannels(1); @@ -175,10 +178,38 @@ void tst_QAudioFormat::checkAssignment() audioFormat1 = audioFormat0; QVERIFY(audioFormat1 == audioFormat0); - QAudioFormat audioFormat2(audioFormat0); + QAudioFormat audioFormat2(audioFormat0); QVERIFY(audioFormat2 == audioFormat0); } +/* sampleRate() API property test. */ +void tst_QAudioFormat::checkSampleRate() +{ + QAudioFormat audioFormat; + QVERIFY(audioFormat.sampleRate() == -1); + + audioFormat.setSampleRate(123); + QVERIFY(audioFormat.sampleRate() == 123); +} + +/* channelCount() API property test. */ +void tst_QAudioFormat::checkChannelCount() +{ + // channels is the old name for channelCount, so + // they should always be equal + QAudioFormat audioFormat; + QVERIFY(audioFormat.channelCount() == -1); + QVERIFY(audioFormat.channels() == -1); + + audioFormat.setChannelCount(123); + QVERIFY(audioFormat.channelCount() == 123); + QVERIFY(audioFormat.channels() == 123); + + audioFormat.setChannels(5); + QVERIFY(audioFormat.channelCount() == 5); + QVERIFY(audioFormat.channels() == 5); +} + QTEST_MAIN(tst_QAudioFormat) #include "tst_qaudioformat.moc" diff --git a/tests/auto/qaudioinput/tst_qaudioinput.cpp b/tests/auto/qaudioinput/tst_qaudioinput.cpp index 9ab2512ca..4b6bb662c 100755 --- a/tests/auto/qaudioinput/tst_qaudioinput.cpp +++ b/tests/auto/qaudioinput/tst_qaudioinput.cpp @@ -199,7 +199,7 @@ void tst_QAudioInput::initTestCase() QVERIFY(testFormats.size()); - foreach (format, testFormats) { + foreach (const QAudioFormat &format, testFormats) { QFile* file = new QFile(workingDir() + formatToFileName(format) + QString(".wav")); audioFiles.append(file); } @@ -265,6 +265,7 @@ void tst_QAudioInput::invalidFormat() QVERIFY2((audioInput.error() == QAudio::NoError), "error() was not set to QAudio::NoError before start()"); audioInput.start(); + // Check that error is raised QTRY_VERIFY2((audioInput.error() == QAudio::OpenError),"error() was not set to QAudio::OpenError after start()"); } @@ -435,6 +436,7 @@ void tst_QAudioInput::pull() QVERIFY(wavHeader.write(*audioFiles.at(i))); audioInput.start(audioFiles.at(i)); + // Check that QAudioInput immediately transitions to ActiveState or IdleState QTRY_VERIFY2((stateSignal.count() > 0),"didn't emit signals on start()"); QVERIFY2((audioInput.state() == QAudio::ActiveState || audioInput.state() == QAudio::IdleState), @@ -493,6 +495,7 @@ void tst_QAudioInput::pullSuspendResume() QVERIFY(wavHeader.write(*audioFiles.at(i))); audioInput.start(audioFiles.at(i)); + // Check that QAudioInput immediately transitions to ActiveState or IdleState QTRY_VERIFY2((stateSignal.count() > 0),"didn't emit signals on start()"); QVERIFY2((audioInput.state() == QAudio::ActiveState || audioInput.state() == QAudio::IdleState), @@ -766,32 +769,71 @@ void tst_QAudioInput::pushSuspendResume() void tst_QAudioInput::reset() { for(int i=0; i<audioFiles.count(); i++) { - QAudioInput audioInput(testFormats.at(i), this); - audioInput.setNotifyInterval(100); + // Try both push/pull.. the vagaries of Active vs Idle are tested elsewhere + { + QAudioInput audioInput(testFormats.at(i), this); - QSignalSpy notifySignal(&audioInput, SIGNAL(notify())); - QSignalSpy stateSignal(&audioInput, SIGNAL(stateChanged(QAudio::State))); + audioInput.setNotifyInterval(100); - // Check that we are in the default state before calling start - QVERIFY2((audioInput.state() == QAudio::StoppedState), "state() was not set to StoppedState 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"); + QSignalSpy notifySignal(&audioInput, SIGNAL(notify())); + QSignalSpy stateSignal(&audioInput, SIGNAL(stateChanged(QAudio::State))); - audioInput.start(); - // Check that QAudioInput immediately transitions to IdleState - QTRY_VERIFY2((stateSignal.count() == 1),"didn't emit IdleState signal on start()"); - QVERIFY2((audioInput.state() == QAudio::IdleState), "didn't transition to IdleState after start()"); - QVERIFY2((audioInput.error() == QAudio::NoError), "error state is not equal to QAudio::NoError after start()"); - QVERIFY(audioInput.periodSize() > 0); - QTest::qWait(500); - QVERIFY(audioInput.bytesReady() > 0); - stateSignal.clear(); + // Check that we are in the default state before calling start + QVERIFY2((audioInput.state() == QAudio::StoppedState), "state() was not set to StoppedState 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"); + + QIODevice* device = audioInput.start(); + // Check that QAudioInput immediately transitions to IdleState + QTRY_VERIFY2((stateSignal.count() == 1),"didn't emit IdleState signal on start()"); + QVERIFY2((audioInput.state() == QAudio::IdleState), "didn't transition to IdleState after start()"); + QVERIFY2((audioInput.error() == QAudio::NoError), "error state is not equal to QAudio::NoError after start()"); + QVERIFY(audioInput.periodSize() > 0); + QTRY_VERIFY2((audioInput.bytesReady() > 0), "no bytes available after starting"); + + // Trigger a read + QByteArray data = device->read(1); + + QTRY_VERIFY2((audioInput.state() == QAudio::ActiveState), "didn't transition to ActiveState after read()"); + QVERIFY2((audioInput.error() == QAudio::NoError), "error state is not equal to QAudio::NoError after start()"); + stateSignal.clear(); + + audioInput.reset(); + QTRY_VERIFY2((stateSignal.count() == 1),"didn't emit StoppedState signal after reset()"); + QVERIFY2((audioInput.state() == QAudio::StoppedState), "didn't transitions to StoppedState after reset()"); + QVERIFY2((audioInput.bytesReady() == 0), "buffer not cleared after reset()"); + } - audioInput.reset(); - QTRY_VERIFY2((stateSignal.count() == 1),"didn't emit StoppedState signal after reset()"); - QVERIFY2((audioInput.state() == QAudio::StoppedState), "didn't transitions to StoppedState after reset()"); - QVERIFY2((audioInput.bytesReady() == 0), "buffer not cleared after reset()"); + { + QAudioInput audioInput(testFormats.at(i), this); + QBuffer buffer; + + audioInput.setNotifyInterval(100); + + QSignalSpy notifySignal(&audioInput, SIGNAL(notify())); + QSignalSpy stateSignal(&audioInput, SIGNAL(stateChanged(QAudio::State))); + + // Check that we are in the default state before calling start + QVERIFY2((audioInput.state() == QAudio::StoppedState), "state() was not set to StoppedState 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"); + + audioInput.start(&buffer); + + // Check that QAudioInput immediately transitions to ActiveState + QTRY_VERIFY2((stateSignal.count() >= 1),"didn't emit state changed signal on start()"); + QTRY_VERIFY2((audioInput.state() == QAudio::ActiveState), "didn't transition to ActiveState after start()"); + QVERIFY2((audioInput.error() == QAudio::NoError), "error state is not equal to QAudio::NoError after start()"); + QVERIFY(audioInput.periodSize() > 0); + QTRY_VERIFY2((audioInput.bytesReady() > 0), "no bytes available after starting"); + stateSignal.clear(); + + audioInput.reset(); + QTRY_VERIFY2((stateSignal.count() == 1),"didn't emit StoppedState signal after reset()"); + QVERIFY2((audioInput.state() == QAudio::StoppedState), "didn't transitions to StoppedState after reset()"); + QVERIFY2((audioInput.bytesReady() == 0), "buffer not cleared after reset()"); + } } } diff --git a/tests/auto/qaudiooutput/tst_qaudiooutput.cpp b/tests/auto/qaudiooutput/tst_qaudiooutput.cpp index a1b44430c..18f28a213 100755 --- a/tests/auto/qaudiooutput/tst_qaudiooutput.cpp +++ b/tests/auto/qaudiooutput/tst_qaudiooutput.cpp @@ -244,7 +244,7 @@ void tst_QAudioOutput::initTestCase() QVERIFY(testFormats.size()); - foreach (format, testFormats) { + foreach (const QAudioFormat &format, testFormats) { qint64 len = (format.frequency()*format.channels()*(format.sampleSize()/8)*2); // 2 seconds createSineWaveData(format, len); // Write generate sine wave data to file @@ -488,6 +488,7 @@ void tst_QAudioOutput::pull() audioFiles.at(i)->seek(WavHeader::headerLength()); audioOutput.start(audioFiles.at(i)); + // Check that QAudioOutput immediately transitions to ActiveState QTRY_VERIFY2((stateSignal.count() == 1), QString("didn't emit signal on start(), got %1 signals instead").arg(stateSignal.count()).toLocal8Bit().constData()); diff --git a/tests/auto/qcamera/qcamera.pro b/tests/auto/qcamera/qcamera.pro index 1e6205ac4..baae9dba0 100644 --- a/tests/auto/qcamera/qcamera.pro +++ b/tests/auto/qcamera/qcamera.pro @@ -2,6 +2,9 @@ load(qttest_p4) QT += multimediakit-private +include (../qmultimedia_common/mock.pri) +include (../qmultimedia_common/mockcamera.pri) + # TARGET = tst_qcamera # CONFIG += testcase diff --git a/tests/auto/qcamera/tst_qcamera.cpp b/tests/auto/qcamera/tst_qcamera.cpp index 3dc91214b..9234998dd 100644 --- a/tests/auto/qcamera/tst_qcamera.cpp +++ b/tests/auto/qcamera/tst_qcamera.cpp @@ -63,933 +63,16 @@ #include <qvideowidget.h> #include <qvideowindowcontrol.h> -QT_USE_NAMESPACE -class MockCaptureControl; - -Q_DECLARE_METATYPE(QtMultimediaKit::MetaData) - -class MockCameraControl : public QCameraControl -{ - friend class MockCaptureControl; - Q_OBJECT -public: - MockCameraControl(QObject *parent = 0): - QCameraControl(parent), - m_state(QCamera::UnloadedState), - m_captureMode(QCamera::CaptureStillImage), - m_status(QCamera::UnloadedStatus), - m_propertyChangesSupported(false) - { - } - - ~MockCameraControl() {} - - void start() { m_state = QCamera::ActiveState; } - virtual void stop() { m_state = QCamera::UnloadedState; } - QCamera::State state() const { return m_state; } - void setState(QCamera::State state) { - if (m_state != state) { - m_state = state; - - switch (state) { - case QCamera::UnloadedState: - m_status = QCamera::UnloadedStatus; - break; - case QCamera::LoadedState: - m_status = QCamera::LoadedStatus; - break; - case QCamera::ActiveState: - m_status = QCamera::ActiveStatus; - break; - default: - emit error(QCamera::NotSupportedFeatureError, "State not supported."); - return; - } - - emit stateChanged(m_state); - emit statusChanged(m_status); - } - } - - QCamera::Status status() const { return m_status; } - - QCamera::CaptureMode captureMode() const { return m_captureMode; } - void setCaptureMode(QCamera::CaptureMode mode) - { - if (m_captureMode != mode) { - if (m_state == QCamera::ActiveState) - QVERIFY(m_propertyChangesSupported); - m_captureMode = mode; - emit captureModeChanged(mode); - } - } - - bool isCaptureModeSupported(QCamera::CaptureMode mode) const - { - return mode == QCamera::CaptureStillImage || mode == QCamera::CaptureVideo; - } - - QCamera::LockTypes supportedLocks() const - { - return QCamera::LockExposure | QCamera::LockFocus | QCamera::LockWhiteBalance; - } - - bool canChangeProperty(PropertyChangeType changeType, QCamera::Status status) const - { - Q_UNUSED(changeType); - Q_UNUSED(status); - return m_propertyChangesSupported; - } - - QCamera::State m_state; - QCamera::CaptureMode m_captureMode; - QCamera::Status m_status; - bool m_propertyChangesSupported; -}; - - -class MockCameraLocksControl : public QCameraLocksControl -{ - Q_OBJECT -public: - MockCameraLocksControl(QObject *parent = 0): - QCameraLocksControl(parent), - m_focusLock(QCamera::Unlocked), - m_exposureLock(QCamera::Unlocked) - { - } - - ~MockCameraLocksControl() {} - - QCamera::LockTypes supportedLocks() const - { - return QCamera::LockExposure | QCamera::LockFocus; - } - - QCamera::LockStatus lockStatus(QCamera::LockType lock) const - { - switch (lock) { - case QCamera::LockExposure: - return m_exposureLock; - case QCamera::LockFocus: - return m_focusLock; - default: - return QCamera::Unlocked; - } - } - - void searchAndLock(QCamera::LockTypes locks) - { - if (locks & QCamera::LockExposure) { - QCamera::LockStatus newStatus = locks & QCamera::LockFocus ? QCamera::Searching : QCamera::Locked; - - if (newStatus != m_exposureLock) - emit lockStatusChanged(QCamera::LockExposure, - m_exposureLock = newStatus, - QCamera::UserRequest); - } - - if (locks & QCamera::LockFocus) { - emit lockStatusChanged(QCamera::LockFocus, - m_focusLock = QCamera::Searching, - QCamera::UserRequest); - - QTimer::singleShot(5, this, SLOT(focused())); - } - } - - void unlock(QCamera::LockTypes locks) { - if (locks & QCamera::LockFocus && m_focusLock != QCamera::Unlocked) { - emit lockStatusChanged(QCamera::LockFocus, - m_focusLock = QCamera::Unlocked, - QCamera::UserRequest); - } - - if (locks & QCamera::LockExposure && m_exposureLock != QCamera::Unlocked) { - emit lockStatusChanged(QCamera::LockExposure, - m_exposureLock = QCamera::Unlocked, - QCamera::UserRequest); - } - } - -private slots: - void focused() - { - if (m_focusLock == QCamera::Searching) { - emit lockStatusChanged(QCamera::LockFocus, - m_focusLock = QCamera::Locked, - QCamera::UserRequest); - } - - if (m_exposureLock == QCamera::Searching) { - emit lockStatusChanged(QCamera::LockExposure, - m_exposureLock = QCamera::Locked, - QCamera::UserRequest); - } - } - - -private: - QCamera::LockStatus m_focusLock; - QCamera::LockStatus m_exposureLock; -}; - -class MockCaptureControl : public QCameraImageCaptureControl -{ - Q_OBJECT -public: - MockCaptureControl(MockCameraControl *cameraControl, QObject *parent = 0) - :QCameraImageCaptureControl(parent), m_cameraControl(cameraControl), m_captureRequest(0), m_ready(true), m_captureCanceled(false) - { - } - - ~MockCaptureControl() - { - } - - QCameraImageCapture::DriveMode driveMode() const { return QCameraImageCapture::SingleImageCapture; } - void setDriveMode(QCameraImageCapture::DriveMode) {} - - bool isReadyForCapture() const { return m_ready && m_cameraControl->state() == QCamera::ActiveState; } - - int capture(const QString &fileName) - { - if (isReadyForCapture()) { - m_fileName = fileName; - m_captureRequest++; - emit readyForCaptureChanged(m_ready = false); - QTimer::singleShot(5, this, SLOT(captured())); - return m_captureRequest; - } else { - emit error(-1, QCameraImageCapture::NotReadyError, - QLatin1String("Could not capture in stopped state")); - } - - return -1; - } - - void cancelCapture() - { - m_captureCanceled = true; - } - -private Q_SLOTS: - void captured() - { - if (!m_captureCanceled) { - emit imageCaptured(m_captureRequest, QImage()); - - emit imageMetadataAvailable(m_captureRequest, - QtMultimediaKit::FocalLengthIn35mmFilm, - QVariant(50)); - - emit imageMetadataAvailable(m_captureRequest, - QtMultimediaKit::DateTimeOriginal, - QVariant(QDateTime::currentDateTime())); - - emit imageMetadataAvailable(m_captureRequest, - QLatin1String("Answer to the Ultimate Question of Life, the Universe, and Everything"), - QVariant(42)); - } - - if (!m_ready) - emit readyForCaptureChanged(m_ready = true); - - if (!m_captureCanceled) - emit imageSaved(m_captureRequest, m_fileName); - - m_captureCanceled = false; - } - -private: - MockCameraControl *m_cameraControl; - QString m_fileName; - int m_captureRequest; - bool m_ready; - bool m_captureCanceled; -}; - -class MockCaptureDestinationControl : public QCameraCaptureDestinationControl -{ - Q_OBJECT -public: - MockCaptureDestinationControl(QObject *parent = 0): - QCameraCaptureDestinationControl(parent), - m_destination(QCameraImageCapture::CaptureToFile) - { - } - - bool isCaptureDestinationSupported(QCameraImageCapture::CaptureDestinations destination) const - { - return destination == QCameraImageCapture::CaptureToBuffer || - destination == QCameraImageCapture::CaptureToFile; - } - - QCameraImageCapture::CaptureDestinations captureDestination() const - { - return m_destination; - } - - void setCaptureDestination(QCameraImageCapture::CaptureDestinations destination) - { - if (isCaptureDestinationSupported(destination) && destination != m_destination) { - m_destination = destination; - emit captureDestinationChanged(m_destination); - } - } - -private: - QCameraImageCapture::CaptureDestinations m_destination; -}; - -class MockCaptureBufferFormatControl : public QCameraCaptureBufferFormatControl -{ - Q_OBJECT -public: - MockCaptureBufferFormatControl(QObject *parent = 0): - QCameraCaptureBufferFormatControl(parent), - m_format(QVideoFrame::Format_Jpeg) - { - } - - QList<QVideoFrame::PixelFormat> supportedBufferFormats() const - { - return QList<QVideoFrame::PixelFormat>() - << QVideoFrame::Format_Jpeg - << QVideoFrame::Format_RGB32 - << QVideoFrame::Format_AdobeDng; - } - - QVideoFrame::PixelFormat bufferFormat() const - { - return m_format; - } - - void setBufferFormat(QVideoFrame::PixelFormat format) - { - if (format != m_format && supportedBufferFormats().contains(format)) { - m_format = format; - emit bufferFormatChanged(m_format); - } - } - -private: - QVideoFrame::PixelFormat m_format; -}; - -class MockCameraExposureControl : public QCameraExposureControl -{ - Q_OBJECT -public: - MockCameraExposureControl(QObject *parent = 0): - QCameraExposureControl(parent), - m_aperture(2.8), - m_shutterSpeed(0.01), - m_isoSensitivity(100), - m_meteringMode(QCameraExposure::MeteringMatrix), - m_exposureCompensation(0), - m_exposureMode(QCameraExposure::ExposureAuto), - m_flashMode(QCameraExposure::FlashAuto) - { - } - - ~MockCameraExposureControl() {} - - QCameraExposure::FlashModes flashMode() const - { - return m_flashMode; - } - - void setFlashMode(QCameraExposure::FlashModes mode) - { - if (isFlashModeSupported(mode)) { - m_flashMode = mode; - } - } - - bool isFlashModeSupported(QCameraExposure::FlashModes mode) const - { - return mode & (QCameraExposure::FlashAuto | QCameraExposure::FlashOff | QCameraExposure::FlashOn); - } - - bool isFlashReady() const - { - return true; - } - - QCameraExposure::ExposureMode exposureMode() const - { - return m_exposureMode; - } - - void setExposureMode(QCameraExposure::ExposureMode mode) - { - if (isExposureModeSupported(mode)) - m_exposureMode = mode; - } - - bool isExposureModeSupported(QCameraExposure::ExposureMode mode) const - { - return mode == QCameraExposure::ExposureAuto || - mode == QCameraExposure::ExposureManual; - } - - bool isParameterSupported(ExposureParameter parameter) const - { - switch (parameter) { - case QCameraExposureControl::ExposureCompensation: - case QCameraExposureControl::ISO: - case QCameraExposureControl::Aperture: - case QCameraExposureControl::ShutterSpeed: - return true; - default: - return false; - } - } - - QVariant exposureParameter(ExposureParameter parameter) const - { - switch (parameter) { - case QCameraExposureControl::ExposureCompensation: - return QVariant(m_exposureCompensation); - case QCameraExposureControl::ISO: - return QVariant(m_isoSensitivity); - case QCameraExposureControl::Aperture: - return QVariant(m_aperture); - case QCameraExposureControl::ShutterSpeed: - return QVariant(m_shutterSpeed); - default: - return QVariant(); - } - } - - QVariantList supportedParameterRange(ExposureParameter parameter) const - { - QVariantList res; - switch (parameter) { - case QCameraExposureControl::ExposureCompensation: - res << -2.0 << 2.0; - break; - case QCameraExposureControl::ISO: - res << 100 << 200 << 400 << 800; - break; - case QCameraExposureControl::Aperture: - res << 2.8 << 4.0 << 5.6 << 8.0 << 11.0 << 16.0; - break; - case QCameraExposureControl::ShutterSpeed: - res << 0.001 << 0.01 << 0.1 << 1.0; - break; - default: - break; - } - - return res; - } - - ParameterFlags exposureParameterFlags(ExposureParameter parameter) const - { - ParameterFlags res = 0; - switch (parameter) { - case QCameraExposureControl::ExposureCompensation: - case QCameraExposureControl::Aperture: - case QCameraExposureControl::ShutterSpeed: - res |= ContinuousRange; - default: - break; - } - - return res; - } - - bool setExposureParameter(ExposureParameter parameter, const QVariant& value) - { - switch (parameter) { - case QCameraExposureControl::ExposureCompensation: - m_exposureCompensation = qBound<qreal>(-2.0, value.toReal(), 2.0); - break; - case QCameraExposureControl::ISO: - m_isoSensitivity = 100*qRound(qBound(100, value.toInt(), 800)/100.0); - break; - case QCameraExposureControl::Aperture: - m_aperture = qBound<qreal>(2.8, value.toReal(), 16.0); - break; - case QCameraExposureControl::ShutterSpeed: - m_shutterSpeed = qBound<qreal>(0.001, value.toReal(), 1.0); - break; - default: - return false; - } - - return true; - } - - QString extendedParameterName(ExposureParameter) - { - return QString(); - } - - QCameraExposure::MeteringMode meteringMode() const - { - return m_meteringMode; - } - - void setMeteringMode(QCameraExposure::MeteringMode mode) - { - if (isMeteringModeSupported(mode)) - m_meteringMode = mode; - } - - bool isMeteringModeSupported(QCameraExposure::MeteringMode mode) const - { - return mode == QCameraExposure::MeteringAverage - || mode == QCameraExposure::MeteringMatrix; - } - -private: - qreal m_aperture; - qreal m_shutterSpeed; - int m_isoSensitivity; - QCameraExposure::MeteringMode m_meteringMode; - qreal m_exposureCompensation; - QCameraExposure::ExposureMode m_exposureMode; - QCameraExposure::FlashModes m_flashMode; -}; - -class MockCameraFlashControl : public QCameraFlashControl -{ - Q_OBJECT -public: - MockCameraFlashControl(QObject *parent = 0): - QCameraFlashControl(parent), - m_flashMode(QCameraExposure::FlashAuto) - { - } - - ~MockCameraFlashControl() {} - - QCameraExposure::FlashModes flashMode() const - { - return m_flashMode; - } - - void setFlashMode(QCameraExposure::FlashModes mode) - { - if (isFlashModeSupported(mode)) { - m_flashMode = mode; - } - } - - bool isFlashModeSupported(QCameraExposure::FlashModes mode) const - { - return mode & (QCameraExposure::FlashAuto | QCameraExposure::FlashOff | QCameraExposure::FlashOn); - } - - bool isFlashReady() const - { - return true; - } - -private: - QCameraExposure::FlashModes m_flashMode; -}; - - -class MockCameraFocusControl : public QCameraFocusControl -{ - Q_OBJECT -public: - MockCameraFocusControl(QObject *parent = 0): - QCameraFocusControl(parent), - m_opticalZoom(1.0), - m_digitalZoom(1.0), - m_focusMode(QCameraFocus::AutoFocus), - m_focusPointMode(QCameraFocus::FocusPointAuto), - m_focusPoint(0.5, 0.5) - { - } +#include "mockcameraservice.h" - ~MockCameraFocusControl() {} - - QCameraFocus::FocusMode focusMode() const - { - return m_focusMode; - } - - void setFocusMode(QCameraFocus::FocusMode mode) - { - if (isFocusModeSupported(mode)) - m_focusMode = mode; - } - - bool isFocusModeSupported(QCameraFocus::FocusMode mode) const - { - return mode == QCameraFocus::AutoFocus || mode == QCameraFocus::ContinuousFocus; - } - - qreal maximumOpticalZoom() const - { - return 3.0; - } - - qreal maximumDigitalZoom() const - { - return 4.0; - } - - qreal opticalZoom() const - { - return m_opticalZoom; - } - - qreal digitalZoom() const - { - return m_digitalZoom; - } +#include "mockmediaserviceprovider.h" +#include "mockvideosurface.h" +#include "mockvideorenderercontrol.h" +#include "mockvideowindowcontrol.h" - void zoomTo(qreal optical, qreal digital) - { - optical = qBound<qreal>(1.0, optical, maximumOpticalZoom()); - digital = qBound<qreal>(1.0, digital, maximumDigitalZoom()); - - if (!qFuzzyCompare(digital, m_digitalZoom)) { - m_digitalZoom = digital; - emit digitalZoomChanged(m_digitalZoom); - } - - if (!qFuzzyCompare(optical, m_opticalZoom)) { - m_opticalZoom = optical; - emit opticalZoomChanged(m_opticalZoom); - } - } - - QCameraFocus::FocusPointMode focusPointMode() const - { - return m_focusPointMode; - } - - void setFocusPointMode(QCameraFocus::FocusPointMode mode) - { - if (isFocusPointModeSupported(mode)) - m_focusPointMode = mode; - } - - bool isFocusPointModeSupported(QCameraFocus::FocusPointMode mode) const - { - switch (mode) { - case QCameraFocus::FocusPointAuto: - case QCameraFocus::FocusPointCenter: - case QCameraFocus::FocusPointCustom: - return true; - default: - return false; - } - } - - QPointF customFocusPoint() const - { - return m_focusPoint; - } - - void setCustomFocusPoint(const QPointF &point) - { - m_focusPoint = point; - } - - QCameraFocusZoneList focusZones() const { return QCameraFocusZoneList() << QCameraFocusZone(QRectF(0.45, 0.45, 0.1, 0.1)); } - - -private: - qreal m_opticalZoom; - qreal m_digitalZoom; - QCameraFocus::FocusMode m_focusMode; - QCameraFocus::FocusPointMode m_focusPointMode; - QPointF m_focusPoint; -}; - -class MockImageProcessingControl : public QCameraImageProcessingControl -{ - Q_OBJECT -public: - MockImageProcessingControl(QObject *parent = 0) - : QCameraImageProcessingControl(parent) - { - m_supportedWhiteBalance.insert(QCameraImageProcessing::WhiteBalanceAuto); - } - - QCameraImageProcessing::WhiteBalanceMode whiteBalanceMode() const { return m_whiteBalanceMode; } - void setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceMode mode) { m_whiteBalanceMode = mode; } - - bool isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceMode mode) const { - return m_supportedWhiteBalance.contains(mode); } - - void setSupportedWhiteBalanceModes(QSet<QCameraImageProcessing::WhiteBalanceMode> modes) { - m_supportedWhiteBalance = modes; } - - bool isProcessingParameterSupported(ProcessingParameter parameter) const - { - return parameter == Contrast || parameter == Sharpening || parameter == ColorTemperature; - } - QVariant processingParameter(ProcessingParameter parameter) const - { - switch (parameter) { - case Contrast: - return m_contrast; - case Sharpening: - return m_sharpeningLevel; - case ColorTemperature: - return m_manualWhiteBalance; - default: - return QVariant(); - } - } - void setProcessingParameter(ProcessingParameter parameter, QVariant value) - { - switch (parameter) { - case Contrast: - m_contrast = value; - break; - case Sharpening: - m_sharpeningLevel = value; - break; - case ColorTemperature: - m_manualWhiteBalance = value; - break; - default: - break; - } - } - - -private: - QCameraImageProcessing::WhiteBalanceMode m_whiteBalanceMode; - QSet<QCameraImageProcessing::WhiteBalanceMode> m_supportedWhiteBalance; - QVariant m_manualWhiteBalance; - QVariant m_contrast; - QVariant m_sharpeningLevel; -}; - -class MockImageEncoderControl : public QImageEncoderControl -{ -public: - MockImageEncoderControl(QObject *parent = 0) - : QImageEncoderControl(parent) - { - } - - QList<QSize> supportedResolutions(const QImageEncoderSettings & = QImageEncoderSettings(), - bool *continuous = 0) const - { - if (continuous) - *continuous = true; - - return m_supportedResolutions; - } - - void setSupportedResolutions(const QList<QSize> &resolutions) { - m_supportedResolutions = resolutions; } - - QStringList supportedImageCodecs() const { return m_supportedCodecs; } - void setSupportedImageCodecs(const QStringList &codecs) { m_supportedCodecs = codecs; } - - QString imageCodecDescription(const QString &codecName) const { - return m_codecDescriptions.value(codecName); } - void setImageCodecDescriptions(const QMap<QString, QString> &descriptions) { - m_codecDescriptions = descriptions; } - - QImageEncoderSettings imageSettings() const { return m_settings; } - void setImageSettings(const QImageEncoderSettings &settings) { m_settings = settings; } - -private: - QImageEncoderSettings m_settings; - - QList<QSize> m_supportedResolutions; - QStringList m_supportedCodecs; - QMap<QString, QString> m_codecDescriptions; -}; - -class MockVideoSurface : public QAbstractVideoSurface -{ -public: - QList<QVideoFrame::PixelFormat> supportedPixelFormats( - const QAbstractVideoBuffer::HandleType) const - { - return QList<QVideoFrame::PixelFormat>(); - } - - bool present(const QVideoFrame &) { return false; } -}; - -class MockVideoRendererControl : public QVideoRendererControl -{ -public: - MockVideoRendererControl(QObject *parent) : QVideoRendererControl(parent), m_surface(0) {} - - QAbstractVideoSurface *surface() const { return m_surface; } - void setSurface(QAbstractVideoSurface *surface) { m_surface = surface; } - - QAbstractVideoSurface *m_surface; -}; - -class MockVideoWindowControl : public QVideoWindowControl -{ -public: - MockVideoWindowControl(QObject *parent) : QVideoWindowControl(parent) {} - WId winId() const { return 0; } - void setWinId(WId) {} - QRect displayRect() const { return QRect(); } - void setDisplayRect(const QRect &) {} - bool isFullScreen() const { return false; } - void setFullScreen(bool) {} - void repaint() {} - QSize nativeSize() const { return QSize(); } - Qt::AspectRatioMode aspectRatioMode() const { return Qt::KeepAspectRatio; } - void setAspectRatioMode(Qt::AspectRatioMode) {} - int brightness() const { return 0; } - void setBrightness(int) {} - int contrast() const { return 0; } - void setContrast(int) {} - int hue() const { return 0; } - void setHue(int) {} - int saturation() const { return 0; } - void setSaturation(int) {} -}; - -class MockSimpleCameraService : public QMediaService -{ - Q_OBJECT - -public: - MockSimpleCameraService(): QMediaService(0) - { - mockControl = new MockCameraControl(this); - } - - ~MockSimpleCameraService() - { - } - - QMediaControl* requestControl(const char *iid) - { - if (qstrcmp(iid, QCameraControl_iid) == 0) - return mockControl; - return 0; - } - - void releaseControl(QMediaControl*) {} - - MockCameraControl *mockControl; -}; - -class MockCameraService : public QMediaService -{ - Q_OBJECT - -public: - MockCameraService(): QMediaService(0) - { - mockControl = new MockCameraControl(this); - mockLocksControl = new MockCameraLocksControl(this); - mockExposureControl = new MockCameraExposureControl(this); - mockFlashControl = new MockCameraFlashControl(this); - mockFocusControl = new MockCameraFocusControl(this); - mockCaptureControl = new MockCaptureControl(mockControl, this); - mockCaptureBufferControl = new MockCaptureBufferFormatControl(this); - mockCaptureDestinationControl = new MockCaptureDestinationControl(this); - mockImageProcessingControl = new MockImageProcessingControl(this); - mockImageEncoderControl = new MockImageEncoderControl(this); - rendererControl = new MockVideoRendererControl(this); - windowControl = new MockVideoWindowControl(this); - rendererRef = 0; - windowRef = 0; - } - - ~MockCameraService() - { - } - - QMediaControl* requestControl(const char *iid) - { - if (qstrcmp(iid, QCameraControl_iid) == 0) - return mockControl; - - if (qstrcmp(iid, QCameraLocksControl_iid) == 0) - return mockLocksControl; - - if (qstrcmp(iid, QCameraExposureControl_iid) == 0) - return mockExposureControl; - - if (qstrcmp(iid, QCameraFlashControl_iid) == 0) - return mockFlashControl; - - if (qstrcmp(iid, QCameraFocusControl_iid) == 0) - return mockFocusControl; - - if (qstrcmp(iid, QCameraImageCaptureControl_iid) == 0) - return mockCaptureControl; - - if (qstrcmp(iid, QCameraCaptureBufferFormatControl_iid) == 0) - return mockCaptureBufferControl; - - if (qstrcmp(iid, QCameraCaptureDestinationControl_iid) == 0) - return mockCaptureDestinationControl; - - if (qstrcmp(iid, QCameraImageProcessingControl_iid) == 0) - return mockImageProcessingControl; - - if (qstrcmp(iid, QImageEncoderControl_iid) == 0) - return mockImageEncoderControl; - - if (qstrcmp(iid, QVideoRendererControl_iid) == 0) { - if (rendererRef == 0) { - rendererRef += 1; - return rendererControl; - } - } else if (qstrcmp(iid, QVideoWindowControl_iid) == 0) { - if (windowRef == 0) { - windowRef += 1; - return windowControl; - } - } - return 0; - } - - void releaseControl(QMediaControl *control) - { - if (control == rendererControl) - rendererRef -= 1; - else if (control == windowControl) - windowRef -= 1; - } - - MockCameraControl *mockControl; - MockCameraLocksControl *mockLocksControl; - MockCaptureControl *mockCaptureControl; - MockCaptureBufferFormatControl *mockCaptureBufferControl; - MockCaptureDestinationControl *mockCaptureDestinationControl; - MockCameraExposureControl *mockExposureControl; - MockCameraFlashControl *mockFlashControl; - MockCameraFocusControl *mockFocusControl; - MockImageProcessingControl *mockImageProcessingControl; - MockImageEncoderControl *mockImageEncoderControl; - MockVideoRendererControl *rendererControl; - MockVideoWindowControl *windowControl; - int rendererRef; - int windowRef; -}; - -class MockProvider : public QMediaServiceProvider -{ -public: - QMediaService *requestService(const QByteArray &, const QMediaServiceProviderHint &) - { - return service; - } - - void releaseService(QMediaService *) {} - - QMediaService *service; -}; +QT_USE_NAMESPACE +Q_DECLARE_METATYPE(QtMultimediaKit::MetaData) class tst_QCamera: public QObject { @@ -1024,6 +107,46 @@ private slots: void testCaptureDestination(); void testCaptureFormat(); + void testConstructorWithDefaultProvider(); + void testCaptureMode(); + void testIsCaptureModeSupported(); + void testRequestedLocks(); + void testSupportedLocks(); + void testQCameraIsAvailable(); + void testAvailabilityError(); + void testSearchAndLockWithLockTypes(); + void testSetCaptureMode(); + void testUnlockWithType(); + void testCaptureModeChangedSignal(); + void testLockStatusChangedWithTypesSignal(); + void testErrorSignal(); + void testError(); + void testErrorString(); + void testStatus(); + void testLockType(); + void testLockChangeReason(); + + + // Test cases to for QCameraFocus + void testCameraFocusIsAvailable(); + void testFocusModes(); + void testOpticalAndDigitalZoomChanged(); + void testMaxOpticalZoomChangedSignal(); + void testMaxDigitalZoomChangedSignal(); + void testfocusZonesChangedSignal(); + + // Test cases for QCameraControl class. + void testCameraControl(); + void testCaptureModeChanged_signal(); + void testEnumsOfQCameraControl(); + + // Test case for QCameraImageProcessing class + void testContrast(); + void testDenoisingLevel(); + void testIsAvailable(); + void testSaturation(); + void testSharpeningLevel(); + void testEnumOfQCameraImageProcessing(); void testSetVideoOutput(); void testSetVideoOutputNoService(); @@ -1032,14 +155,27 @@ private slots: void testEnumDebug(); + // constructor for QCameraImageProceesing + void testImageProcessingControl(); + + // Signals test cases for QCameraExposure + void testSignalApertureChanged(); + void testSignalExposureCompensationChanged(); + void testSignalIsoSensitivityChanged(); + void testSignalShutterSpeedChanged(); + void testSignalFlashReady(); + + // test constructor + void testExposureControlConstructor(); + private: MockSimpleCameraService *mockSimpleCameraService; - MockProvider *provider; + MockMediaServiceProvider *provider; }; void tst_QCamera::initTestCase() { - provider = new MockProvider; + provider = new MockMediaServiceProvider; mockSimpleCameraService = new MockSimpleCameraService; provider->service = mockSimpleCameraService; qRegisterMetaType<QtMultimediaKit::MetaData>("QtMultimediaKit::MetaData"); @@ -1349,7 +485,6 @@ void tst_QCamera::testCameraCapture() QCamera camera(0, provider); QCameraImageCapture imageCapture(&camera); - QVERIFY(!imageCapture.isReadyForCapture()); QSignalSpy capturedSignal(&imageCapture, SIGNAL(imageCaptured(int,QImage))); @@ -1430,7 +565,7 @@ void tst_QCamera::testCameraWhiteBalance() QCameraImageProcessingControl::ColorTemperature, QVariant(34)); - MockProvider provider; + MockMediaServiceProvider provider; provider.service = &service; QCamera camera(0, &provider); @@ -1464,23 +599,75 @@ void tst_QCamera::testCameraExposure() QVERIFY(cameraExposure->isExposureModeSupported(QCameraExposure::ExposureAuto)); QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureAuto); + + // Test Cases For QCameraExposure + QVERIFY(cameraExposure->isExposureModeSupported(QCameraExposure::ExposureManual)); cameraExposure->setExposureMode(QCameraExposure::ExposureManual); QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureManual); + QVERIFY(cameraExposure->isExposureModeSupported(QCameraExposure::ExposureNight)); + cameraExposure->setExposureMode(QCameraExposure::ExposureNight); + QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureNight); + + QVERIFY(cameraExposure->isExposureModeSupported(QCameraExposure::ExposureBacklight)); + cameraExposure->setExposureMode(QCameraExposure::ExposureBacklight); + QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureBacklight); + + + QVERIFY(cameraExposure->isExposureModeSupported(QCameraExposure::ExposureSpotlight )); + cameraExposure->setExposureMode(QCameraExposure::ExposureSpotlight); + QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureSpotlight); + + QVERIFY(cameraExposure->isExposureModeSupported(QCameraExposure::ExposureSports )); + cameraExposure->setExposureMode(QCameraExposure::ExposureSports); + QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureSports); + + QVERIFY(cameraExposure->isExposureModeSupported(QCameraExposure::ExposureSnow )); + cameraExposure->setExposureMode(QCameraExposure::ExposureSnow); + QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureSnow); + + QVERIFY(cameraExposure->isExposureModeSupported(QCameraExposure::ExposureBeach )); + cameraExposure->setExposureMode(QCameraExposure::ExposureBeach); + QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureBeach); + + QVERIFY(cameraExposure->isExposureModeSupported(QCameraExposure::ExposureLargeAperture )); + cameraExposure->setExposureMode(QCameraExposure::ExposureLargeAperture); + QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureLargeAperture); + + QVERIFY(cameraExposure->isExposureModeSupported(QCameraExposure::ExposureSmallAperture )); + cameraExposure->setExposureMode(QCameraExposure::ExposureSmallAperture); + QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureSmallAperture); + + QVERIFY(cameraExposure->isExposureModeSupported(QCameraExposure::ExposurePortrait )); + cameraExposure->setExposureMode(QCameraExposure::ExposurePortrait); + QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposurePortrait); + + QVERIFY(cameraExposure->isExposureModeSupported(QCameraExposure::ExposureModeVendor )); + cameraExposure->setExposureMode(QCameraExposure::ExposureModeVendor); + QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureModeVendor); + + + cameraExposure->setFlashMode(QCameraExposure::FlashAuto); QCOMPARE(cameraExposure->flashMode(), QCameraExposure::FlashAuto); QCOMPARE(cameraExposure->isFlashReady(), true); + cameraExposure->setFlashMode(QCameraExposure::FlashRedEyeReduction); + QCOMPARE(cameraExposure->flashMode(), QCameraExposure::FlashRedEyeReduction); cameraExposure->setFlashMode(QCameraExposure::FlashOn); QCOMPARE(cameraExposure->flashMode(), QCameraExposure::FlashOn); + cameraExposure->setFlashMode(QCameraExposure::FlashFill); + QCOMPARE(cameraExposure->flashMode(), QCameraExposure::FlashFill); + cameraExposure->setFlashMode(QCameraExposure::FlashTorch); + QCOMPARE(cameraExposure->flashMode(), QCameraExposure::FlashTorch); + cameraExposure->setFlashMode(QCameraExposure::FlashSlowSyncFrontCurtain); + QCOMPARE(cameraExposure->flashMode(), QCameraExposure::FlashSlowSyncFrontCurtain); - cameraExposure->setFlashMode(QCameraExposure::FlashRedEyeReduction); // not expected to be supported - QCOMPARE(cameraExposure->flashMode(), QCameraExposure::FlashOn); + cameraExposure->setMeteringMode(QCameraExposure::MeteringMatrix); QCOMPARE(cameraExposure->meteringMode(), QCameraExposure::MeteringMatrix); cameraExposure->setMeteringMode(QCameraExposure::MeteringAverage); QCOMPARE(cameraExposure->meteringMode(), QCameraExposure::MeteringAverage); cameraExposure->setMeteringMode(QCameraExposure::MeteringSpot); - QCOMPARE(cameraExposure->meteringMode(), QCameraExposure::MeteringAverage); - + QCOMPARE(cameraExposure->meteringMode(), QCameraExposure::MeteringSpot); QCOMPARE(cameraExposure->exposureCompensation(), 0.0); cameraExposure->setExposureCompensation(2.0); @@ -1782,6 +969,7 @@ void tst_QCamera::testCameraEncodingProperyChange() stateChangedSignal.clear(); statusChangedSignal.clear(); + camera.setCaptureMode(QCamera::CaptureVideo); QCOMPARE(camera.state(), QCamera::ActiveState); QCOMPARE(camera.status(), QCamera::LoadedStatus); @@ -1852,7 +1040,7 @@ void tst_QCamera::testCameraEncodingProperyChange() stateChangedSignal.clear(); statusChangedSignal.clear(); - //setting the viewfinder should also trigget backend to be restarted: + //setting the viewfinder should also trigger backend to be restarted: camera.setViewfinder(new QGraphicsVideoItem()); QCOMPARE(camera.state(), QCamera::ActiveState); QCOMPARE(camera.status(), QCamera::LoadedStatus); @@ -1876,7 +1064,6 @@ void tst_QCamera::testCameraEncodingProperyChange() QCOMPARE(stateChangedSignal.count(), 0); QCOMPARE(statusChangedSignal.count(), 0); - } void tst_QCamera::testSetVideoOutput() @@ -1886,7 +1073,7 @@ void tst_QCamera::testSetVideoOutput() MockVideoSurface surface; MockCameraService service; - MockProvider provider; + MockMediaServiceProvider provider; provider.service = &service; QCamera camera(0, &provider); @@ -1931,7 +1118,7 @@ void tst_QCamera::testSetVideoOutputNoService() QGraphicsVideoItem item; MockVideoSurface surface; - MockProvider provider; + MockMediaServiceProvider provider; provider.service = 0; QCamera camera(0, &provider); @@ -1955,7 +1142,7 @@ void tst_QCamera::testSetVideoOutputNoControl() service.rendererRef = 1; service.windowRef = 1; - MockProvider provider; + MockMediaServiceProvider provider; provider.service = &service; QCamera camera(0, &provider); @@ -1974,7 +1161,7 @@ void tst_QCamera::testSetVideoOutputDestruction() MockVideoSurface surface; MockCameraService service; - MockProvider provider; + MockMediaServiceProvider provider; provider.service = &service; { @@ -2007,6 +1194,832 @@ void tst_QCamera::testEnumDebug() qDebug() << QCamera::LockExposure; } +void tst_QCamera::testCameraControl() +{ + MockCameraControl *m_cameraControl=new MockCameraControl(this); + QVERIFY(m_cameraControl != NULL); +} + +/* Test case for constructor with default provider */ +void tst_QCamera::testConstructorWithDefaultProvider() +{ + QCamera *camera = new QCamera(0); + QVERIFY(camera != NULL); + QCOMPARE(camera->state(), QCamera::UnloadedState); + delete camera; +} + +/* captureModeChanged Signal test case. */ +void tst_QCamera::testCaptureModeChanged_signal() +{ + MockCameraControl *m_cameraControl= new MockCameraControl(this); + QSignalSpy spy(m_cameraControl, SIGNAL(captureModeChanged(QCamera::CaptureMode))); + QVERIFY(spy.size() == 0); + + m_cameraControl->setCaptureMode(QCamera::CaptureVideo); + QVERIFY(spy.size() == 1); + + m_cameraControl->setCaptureMode(QCamera::CaptureStillImage); + QVERIFY(spy.size() == 2); +} + +/* Test case for captureMode */ +void tst_QCamera::testCaptureMode() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + QVERIFY(camera.captureMode() == QCamera::CaptureStillImage); + + camera.setCaptureMode(QCamera::CaptureVideo); + QVERIFY(camera.captureMode() == QCamera::CaptureVideo); +} + +/* Test case for isCaptureModeSupported */ +void tst_QCamera::testIsCaptureModeSupported() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + QVERIFY(camera.isCaptureModeSupported(QCamera::CaptureStillImage) == true); + QVERIFY(camera.isCaptureModeSupported(QCamera::CaptureVideo) == true); +} + +/* Test case for requestedLocks. LockType is stored in OR combination so all + types of combinations are verified here.*/ +void tst_QCamera::testRequestedLocks() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + + QCOMPARE(camera.requestedLocks(),QCamera::NoLock); + + camera.searchAndLock(QCamera::LockExposure); + QCOMPARE(camera.requestedLocks(),QCamera::LockExposure); + + camera.unlock(); + camera.searchAndLock(QCamera::LockFocus); + QCOMPARE(camera.requestedLocks(),QCamera::LockFocus ); + + camera.unlock(); + camera.searchAndLock(QCamera::LockWhiteBalance); + QCOMPARE(camera.requestedLocks(),QCamera::LockWhiteBalance); + + camera.unlock(); + camera.searchAndLock(QCamera::LockExposure |QCamera::LockFocus ); + QCOMPARE(camera.requestedLocks(),QCamera::LockExposure |QCamera::LockFocus ); + camera.searchAndLock(QCamera::LockWhiteBalance); + QCOMPARE(camera.requestedLocks(),QCamera::LockExposure |QCamera::LockFocus|QCamera::LockWhiteBalance ); + camera.unlock(QCamera::LockExposure); + QCOMPARE(camera.requestedLocks(),QCamera::LockFocus|QCamera::LockWhiteBalance ); + camera.unlock(QCamera::LockFocus); + camera.searchAndLock(QCamera::LockExposure |QCamera::LockWhiteBalance ); + QCOMPARE(camera.requestedLocks(),QCamera::LockExposure|QCamera::LockWhiteBalance ); +} + +/* Test case for supportedLocks() */ +void tst_QCamera::testSupportedLocks() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + + QCOMPARE(camera.supportedLocks(),QCamera::LockExposure | QCamera::LockFocus); +} + +/* Test case for isAvailable */ +void tst_QCamera::testQCameraIsAvailable() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + QVERIFY(camera.isAvailable()); + + QCamera *camera1 = new QCamera("random"); + + QVERIFY(camera1->error() == QCamera::ServiceMissingError); + QVERIFY(!camera1->isAvailable()); + delete camera1; +} + +/* Test case for availabilityError */ +void tst_QCamera::testAvailabilityError() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + QVERIFY(camera.availabilityError() == QtMultimediaKit::NoError); + + QCamera *camera1 = new QCamera("random"); + QVERIFY(camera1->availabilityError() == QtMultimediaKit::ServiceMissingError); + delete camera1; +} + +/* Test case for searchAndLock ( QCamera::LockTypes locks ) */ +void tst_QCamera::testSearchAndLockWithLockTypes() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + + QCOMPARE(camera.lockStatus(), QCamera::Unlocked); + + /* Spy the signals */ + QSignalSpy lockedSignal(&camera, SIGNAL(locked())); + QSignalSpy lockFailedSignal(&camera, SIGNAL(lockFailed())); + QSignalSpy lockStatusChangedSignal(&camera, SIGNAL(lockStatusChanged(QCamera::LockStatus, QCamera::LockChangeReason))); + QSignalSpy lockStatusChangedSignalWithType(&camera, SIGNAL(lockStatusChanged(QCamera::LockType,QCamera::LockStatus, QCamera::LockChangeReason))); + + /* search and lock the camera with QCamera::LockExposure and verify if the signal is emitted correctly */ + camera.searchAndLock(QCamera::LockExposure); + QCOMPARE(camera.lockStatus(), QCamera::Locked); + QCOMPARE(lockedSignal.count(), 1); + QCOMPARE(lockFailedSignal.count(), 0); + QCOMPARE(lockStatusChangedSignal.count(), 1); + QCOMPARE(lockStatusChangedSignalWithType.count(), 1); +} + +/* Test case for setCaptureMode() */ +void tst_QCamera::testSetCaptureMode() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + + /* Set the capture mode and verify if it set correctly */ + camera.setCaptureMode(QCamera::CaptureVideo); + QVERIFY(camera.captureMode() == QCamera::CaptureVideo); + + camera.setCaptureMode(QCamera::CaptureStillImage); + QVERIFY(camera.captureMode() == QCamera::CaptureStillImage); +} + +/* Test case for unlock (QCamera::LockTypes) */ +void tst_QCamera::testUnlockWithType() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + + QCOMPARE(camera.lockStatus(), QCamera::Unlocked); + + /* Spy the signal */ + QSignalSpy lockedSignal(&camera, SIGNAL(locked())); + QSignalSpy lockFailedSignal(&camera, SIGNAL(lockFailed())); + QSignalSpy lockStatusChangedSignal(&camera, SIGNAL(lockStatusChanged(QCamera::LockStatus, QCamera::LockChangeReason))); + QSignalSpy lockStatusChangedSignalWithType(&camera, SIGNAL(lockStatusChanged(QCamera::LockType,QCamera::LockStatus, QCamera::LockChangeReason))); + + /* lock the camera with QCamera::LockExposure and Verify if the signal is emitted correctly */ + camera.searchAndLock(QCamera::LockExposure); + QCOMPARE(camera.lockStatus(), QCamera::Locked); + QCOMPARE(lockedSignal.count(), 1); + QCOMPARE(lockFailedSignal.count(), 0); + QCOMPARE(lockStatusChangedSignal.count(), 1); + QCOMPARE(lockStatusChangedSignalWithType.count(), 1); + + /* Clear the signal */ + lockedSignal.clear(); + lockFailedSignal.clear(); + lockStatusChangedSignal.clear(); + lockStatusChangedSignalWithType.clear(); + + /* Unlock the camera and verify if the signal is emitted correctly */ + camera.unlock(QCamera::LockExposure); + QCOMPARE(camera.lockStatus(), QCamera::Unlocked); + QCOMPARE(lockedSignal.count(), 0); + QCOMPARE(lockFailedSignal.count(), 0); + QCOMPARE(lockStatusChangedSignal.count(), 1); + QCOMPARE(lockStatusChangedSignalWithType.count(), 1); + QCamera::LockType lockType = qvariant_cast<QCamera::LockType >(lockStatusChangedSignalWithType.at(0).at(0)); + QCamera::LockStatus lockStatus = qvariant_cast<QCamera::LockStatus >(lockStatusChangedSignalWithType.at(0).at(1)); + QVERIFY(lockType == QCamera::LockExposure); + QVERIFY(lockStatus == QCamera::Unlocked); + + lockedSignal.clear(); + lockFailedSignal.clear(); + lockStatusChangedSignal.clear(); + lockStatusChangedSignalWithType.clear(); + + /* Lock the camera with QCamera::LockFocus */ + camera.searchAndLock(QCamera::LockFocus); + lockedSignal.clear(); + lockFailedSignal.clear(); + lockStatusChangedSignal.clear(); + lockStatusChangedSignalWithType.clear(); + + /* Unlock the camera and Verify if the signal is emitted correctly */ + camera.unlock(QCamera::LockFocus); + QCOMPARE(camera.lockStatus(), QCamera::Unlocked); + QCOMPARE(lockedSignal.count(), 0); + QCOMPARE(lockFailedSignal.count(), 0); + QCOMPARE(lockStatusChangedSignal.count(), 1); + QCOMPARE(lockStatusChangedSignalWithType.count(), 1); + lockType = qvariant_cast<QCamera::LockType >(lockStatusChangedSignalWithType.at(0).at(0)); + lockStatus = qvariant_cast<QCamera::LockStatus >(lockStatusChangedSignalWithType.at(0).at(1)); + QVERIFY(lockType == QCamera::LockFocus); + QVERIFY(lockStatus == QCamera::Unlocked); +} + +/* Test case for signal captureModeChanged(QCamera::CaptureMode) */ +void tst_QCamera::testCaptureModeChangedSignal() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + QVERIFY(camera.captureMode() == QCamera::CaptureStillImage); + + qRegisterMetaType<QCamera::CaptureMode>("QCamera::CaptureMode"); + + /* Spy the signal */ + QSignalSpy lockCaptureModeChangedSignal(&camera, SIGNAL(captureModeChanged(QCamera::CaptureMode))); + + /* set the capture mode and Verify if the signal is emitted */ + camera.setCaptureMode(QCamera::CaptureVideo); + QVERIFY(camera.captureMode() == QCamera::CaptureVideo); + QCOMPARE(lockCaptureModeChangedSignal.count(), 1); + QCamera::CaptureMode lockCaptureMode = qvariant_cast<QCamera::CaptureMode >(lockCaptureModeChangedSignal.at(0).at(0)); + QVERIFY(lockCaptureMode == QCamera::CaptureVideo); +} + +/* Test case for signal lockStatusChanged(QCamera::LockType,QCamera::LockStatus, QCamera::LockChangeReason) */ +void tst_QCamera::testLockStatusChangedWithTypesSignal() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + + QCOMPARE(camera.lockStatus(), QCamera::Unlocked); + + /* Spy the signal lockStatusChanged(QCamera::LockType,QCamera::LockStatus, QCamera::LockChangeReason) */ + QSignalSpy lockStatusChangedSignalWithType(&camera, SIGNAL(lockStatusChanged(QCamera::LockType,QCamera::LockStatus, QCamera::LockChangeReason))); + + /* Lock the camera with type QCamera::LockExposure */ + camera.searchAndLock(QCamera::LockExposure); + + /* Verify if the signal is emitted and lock status is set correclty */ + QCOMPARE(camera.lockStatus(), QCamera::Locked); + QCOMPARE(lockStatusChangedSignalWithType.count(), 1); + QCamera::LockType lockType = qvariant_cast<QCamera::LockType >(lockStatusChangedSignalWithType.at(0).at(0)); + QCamera::LockStatus lockStatus = qvariant_cast<QCamera::LockStatus >(lockStatusChangedSignalWithType.at(0).at(1)); + QVERIFY(lockType == QCamera::LockExposure); + QVERIFY(lockStatus == QCamera::Locked); + + lockStatusChangedSignalWithType.clear(); + + /* Unlock the camera */ + camera.unlock(); + + /* Verify if the signal is emitted and lock status is set correclty */ + QCOMPARE(camera.lockStatus(), QCamera::Unlocked); + QCOMPARE(lockStatusChangedSignalWithType.count(), 1); + lockType = qvariant_cast<QCamera::LockType >(lockStatusChangedSignalWithType.at(0).at(0)); + lockStatus = qvariant_cast<QCamera::LockStatus >(lockStatusChangedSignalWithType.at(0).at(1)); + QVERIFY(lockType == QCamera::LockExposure); + QVERIFY(lockStatus == QCamera::Unlocked); +} + +/* Test case for verifying if error signal generated correctly */ +void tst_QCamera::testErrorSignal() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + + QSignalSpy spyError(&camera, SIGNAL(error(QCamera::Error))); + + /* Set the QCameraControl error and verify if the signal is emitted correctly in QCamera */ + service.mockControl->setError(QCamera::CameraError,QString("Camera Error")); + + QVERIFY(spyError.count() == 1); + QCamera::Error err = qvariant_cast<QCamera::Error >(spyError.at(0).at(0)); + QVERIFY(err == QCamera::CameraError); + + spyError.clear(); + + /* Set the QCameraControl error and verify if the signal is emitted correctly in QCamera */ + service.mockControl->setError(QCamera::InvalidRequestError,QString("InvalidRequestError Error")); + QVERIFY(spyError.count() == 1); + err = qvariant_cast<QCamera::Error >(spyError.at(0).at(0)); + QVERIFY(err == QCamera::InvalidRequestError); + + spyError.clear(); + + /* Set the QCameraControl error and verify if the signal is emitted correctly in QCamera */ + service.mockControl->setError(QCamera::NotSupportedFeatureError,QString("NotSupportedFeatureError Error")); + QVERIFY(spyError.count() == 1); + err = qvariant_cast<QCamera::Error >(spyError.at(0).at(0)); + QVERIFY(err == QCamera::NotSupportedFeatureError); + +} + +/* Test case for verifying the QCamera error */ +void tst_QCamera::testError() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + + /* Set the QCameraControl error and verify if it is set correctly in QCamera */ + service.mockControl->setError(QCamera::CameraError,QString("Camera Error")); + QVERIFY(camera.error() == QCamera::CameraError); + + /* Set the QCameraControl error and verify if it is set correctly in QCamera */ + service.mockControl->setError(QCamera::InvalidRequestError,QString("InvalidRequestError Error")); + QVERIFY(camera.error() == QCamera::InvalidRequestError); + + /* Set the QCameraControl error and verify if it is set correctly in QCamera */ + service.mockControl->setError(QCamera::NotSupportedFeatureError,QString("NotSupportedFeatureError Error")); + QVERIFY(camera.error() == QCamera::NotSupportedFeatureError); + +} + +/* Test the error strings for QCamera class */ +void tst_QCamera::testErrorString() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + + /* Set the QCameraControl error and verify if it is set correctly in QCamera */ + service.mockControl->setError(QCamera::CameraError,QString("Camera Error")); + QVERIFY(camera.errorString() == QString("Camera Error")); + + /* Set the QCameraControl error and verify if it is set correctly in QCamera */ + service.mockControl->setError(QCamera::InvalidRequestError,QString("InvalidRequestError Error")); + QVERIFY(camera.errorString() == QString("InvalidRequestError Error")); + + /* Set the QCameraControl error and verify if it is set correctly in QCamera */ + service.mockControl->setError(QCamera::NotSupportedFeatureError,QString("NotSupportedFeatureError Error")); + QVERIFY(camera.errorString() == QString("NotSupportedFeatureError Error")); +} + +/* Test case for verifying Status of QCamera. */ +void tst_QCamera::testStatus() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + + /* Set the QCameraControl status and verify if it is set correctly in QCamera */ + service.mockControl->setStatus(QCamera::StartingStatus); + QVERIFY(camera.status() == QCamera::StartingStatus); + + /* Set the QCameraControl status and verify if it is set correctly in QCamera */ + service.mockControl->setStatus(QCamera::StandbyStatus); + QVERIFY(camera.status() == QCamera::StandbyStatus); + + /* Set the QCameraControl status and verify if it is set correctly in QCamera */ + service.mockControl->setStatus(QCamera::LoadingStatus); + QVERIFY(camera.status() == QCamera::LoadingStatus); + + /* Set the QCameraControl status and verify if it is set correctly in QCamera */ + service.mockControl->setStatus(QCamera::UnavailableStatus); + QVERIFY(camera.status() == QCamera::UnavailableStatus); +} + +/* Test case for verifying default locktype QCamera::NoLock */ +void tst_QCamera::testLockType() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + + QCOMPARE(camera.requestedLocks(),QCamera::NoLock); +} + +/* Test case for QCamera::LockChangeReason with QCamera::LockAcquired */ +void tst_QCamera::testLockChangeReason() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + + QSignalSpy lockStatusChangedSignalWithType(&camera, SIGNAL(lockStatusChanged(QCamera::LockType,QCamera::LockStatus, QCamera::LockChangeReason))); + + /* Set the lockChangeReason */ + service.mockLocksControl->setLockChangeReason(QCamera::LockAcquired); + + /* Verify if lockChangeReson is eqaul toQCamera::LockAcquired */ + QCOMPARE(lockStatusChangedSignalWithType.count(), 1); + QCamera::LockChangeReason LockChangeReason = qvariant_cast<QCamera::LockChangeReason >(lockStatusChangedSignalWithType.at(0).at(2)); + QVERIFY(LockChangeReason == QCamera::LockAcquired); + +} +/* All the enums test case for QCameraControl class*/ +void tst_QCamera::testEnumsOfQCameraControl() +{ + MockCameraControl *m_cameraControl = new MockCameraControl(this); + bool result; + + // In still mode, can't change much + QVERIFY(m_cameraControl->captureMode() == QCamera::CaptureStillImage); + result = m_cameraControl->canChangeProperty(MockCameraControl::CaptureMode, QCamera::ActiveStatus); + QVERIFY(!result); + result = m_cameraControl->canChangeProperty(MockCameraControl::ImageEncodingSettings, QCamera::ActiveStatus); + QVERIFY(!result); + result = m_cameraControl->canChangeProperty(MockCameraControl::VideoEncodingSettings, QCamera::ActiveStatus); + QVERIFY(result); + result = m_cameraControl->canChangeProperty(MockCameraControl::Viewfinder, QCamera::ActiveStatus); + QVERIFY(!result); + + // In video mode can change image encoding settings + m_cameraControl->setCaptureMode(QCamera::CaptureVideo); + result = m_cameraControl->canChangeProperty(MockCameraControl::ImageEncodingSettings, QCamera::ActiveStatus); + QVERIFY(result); + result = m_cameraControl->canChangeProperty(MockCameraControl::VideoEncodingSettings, QCamera::ActiveStatus); + QVERIFY(result); + result = m_cameraControl->canChangeProperty(MockCameraControl::Viewfinder, QCamera::ActiveStatus); + QVERIFY(!result); + + // Flip the allow everything bit + m_cameraControl->m_propertyChangesSupported = true; + result = m_cameraControl->canChangeProperty(MockCameraControl::CaptureMode, QCamera::ActiveStatus); + QVERIFY(result); + result = m_cameraControl->canChangeProperty(MockCameraControl::ImageEncodingSettings, QCamera::ActiveStatus); + QVERIFY(result); + result = m_cameraControl->canChangeProperty(MockCameraControl::VideoEncodingSettings, QCamera::ActiveStatus); + QVERIFY(result); + result = m_cameraControl->canChangeProperty(MockCameraControl::Viewfinder, QCamera::ActiveStatus); + QVERIFY(result); +} + +// Test case for QCameraImageProcessing class +void tst_QCamera::testContrast() +{ + MockCameraService service; + MockMediaServiceProvider provider; + provider.service = &service; + + QCamera camera(0, &provider); + QCameraImageProcessing *cameraImageProcessing = camera.imageProcessing(); + QVERIFY(cameraImageProcessing->contrast() ==0); + + cameraImageProcessing->setContrast(123); + QVERIFY(cameraImageProcessing->contrast() ==123); + + cameraImageProcessing->setContrast(4.56); + QVERIFY(cameraImageProcessing->contrast() ==4); +} + +void tst_QCamera::testDenoisingLevel() +{ + MockCameraService service; + MockMediaServiceProvider provider; + provider.service = &service; + + QCamera camera(0, &provider); + QCameraImageProcessing *cameraImageProcessing = camera.imageProcessing(); + + if (cameraImageProcessing->isDenoisingSupported()) + { + QVERIFY(cameraImageProcessing->denoisingLevel() == -1); + + cameraImageProcessing->setDenoisingLevel(0); + QVERIFY(cameraImageProcessing->denoisingLevel() == 0); + + cameraImageProcessing->setDenoisingLevel(12); + QVERIFY(cameraImageProcessing->denoisingLevel() == 12); + } + else + QVERIFY(cameraImageProcessing->denoisingLevel() == -1); +} + +void tst_QCamera::testIsAvailable() +{ + MockCameraService service; + MockMediaServiceProvider provider; + provider.service = &service; + + QCamera camera(0, &provider); + QCameraImageProcessing *cameraImageProcessing = camera.imageProcessing(); + QVERIFY(cameraImageProcessing->isAvailable() == true); +} + +void tst_QCamera::testSaturation() +{ + MockCameraService service; + MockMediaServiceProvider provider; + provider.service = &service; + + QCamera camera(0, &provider); + QCameraImageProcessing *cameraImageProcessing = camera.imageProcessing(); + QVERIFY(cameraImageProcessing->saturation() == 0); + + cameraImageProcessing->setSaturation(50); + QVERIFY(cameraImageProcessing->saturation() == 50); + + cameraImageProcessing->setSaturation(-50); + QVERIFY(cameraImageProcessing->saturation() == -50); + + cameraImageProcessing->setSaturation(100); + QVERIFY(cameraImageProcessing->saturation() == 100); + + cameraImageProcessing->setSaturation(-100); + QVERIFY(cameraImageProcessing->saturation() == -100); +} + +void tst_QCamera::testSharpeningLevel() +{ + MockCameraService service; + MockMediaServiceProvider provider; + provider.service = &service; + + QCamera camera(0, &provider); + QCameraImageProcessing *cameraImageProcessing = camera.imageProcessing(); + QVERIFY(cameraImageProcessing->isSharpeningSupported()); + QVERIFY(cameraImageProcessing->sharpeningLevel() == -1); + + cameraImageProcessing->setSharpeningLevel(123); + QVERIFY(cameraImageProcessing->sharpeningLevel() == 123); + + cameraImageProcessing->setSharpeningLevel(4.67); + QVERIFY(cameraImageProcessing->sharpeningLevel() == 4); +} + +void tst_QCamera::testEnumOfQCameraImageProcessing() +{ + QSet<QCameraImageProcessing::WhiteBalanceMode> whiteBalanceModes; + whiteBalanceModes << QCameraImageProcessing::WhiteBalanceManual; + whiteBalanceModes << QCameraImageProcessing::WhiteBalanceAuto; + whiteBalanceModes << QCameraImageProcessing::WhiteBalanceSunlight; + whiteBalanceModes << QCameraImageProcessing::WhiteBalanceCloudy; + whiteBalanceModes << QCameraImageProcessing::WhiteBalanceShade; + whiteBalanceModes << QCameraImageProcessing::WhiteBalanceTungsten; + whiteBalanceModes << QCameraImageProcessing::WhiteBalanceFluorescent; + whiteBalanceModes << QCameraImageProcessing::WhiteBalanceIncandescent; + whiteBalanceModes << QCameraImageProcessing::WhiteBalanceFlash; + whiteBalanceModes << QCameraImageProcessing::WhiteBalanceSunset; + whiteBalanceModes << QCameraImageProcessing::WhiteBalanceVendor; + + MockCameraService service; + service.mockImageProcessingControl->setSupportedWhiteBalanceModes(whiteBalanceModes); + + service.mockImageProcessingControl->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceManual); + QVERIFY(service.mockImageProcessingControl->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceManual)); + QVERIFY(service.mockImageProcessingControl->whiteBalanceMode() == QCameraImageProcessing::WhiteBalanceManual); + + service.mockImageProcessingControl->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceAuto); + QVERIFY(service.mockImageProcessingControl->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceAuto)); + QVERIFY(service.mockImageProcessingControl->whiteBalanceMode() == QCameraImageProcessing::WhiteBalanceAuto); + + service.mockImageProcessingControl->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceSunlight); + QVERIFY(service.mockImageProcessingControl->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceSunlight)); + QVERIFY(service.mockImageProcessingControl->whiteBalanceMode() == QCameraImageProcessing::WhiteBalanceSunlight); + + service.mockImageProcessingControl->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceCloudy); + QVERIFY(service.mockImageProcessingControl->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceCloudy)); + QVERIFY(service.mockImageProcessingControl->whiteBalanceMode() == QCameraImageProcessing::WhiteBalanceCloudy); + + service.mockImageProcessingControl->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceShade); + QVERIFY(service.mockImageProcessingControl->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceShade)); + QVERIFY(service.mockImageProcessingControl->whiteBalanceMode() == QCameraImageProcessing::WhiteBalanceShade); + + service.mockImageProcessingControl->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceTungsten); + QVERIFY(service.mockImageProcessingControl->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceTungsten)); + QVERIFY(service.mockImageProcessingControl->whiteBalanceMode() == QCameraImageProcessing::WhiteBalanceTungsten); + + service.mockImageProcessingControl->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceFluorescent); + QVERIFY(service.mockImageProcessingControl->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceFluorescent)); + QVERIFY(service.mockImageProcessingControl->whiteBalanceMode() == QCameraImageProcessing::WhiteBalanceFluorescent); + + service.mockImageProcessingControl->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceIncandescent); + QVERIFY(service.mockImageProcessingControl->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceIncandescent)); + QVERIFY(service.mockImageProcessingControl->whiteBalanceMode() == QCameraImageProcessing::WhiteBalanceIncandescent); + + service.mockImageProcessingControl->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceFlash); + QVERIFY(service.mockImageProcessingControl->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceFlash)); + QVERIFY(service.mockImageProcessingControl->whiteBalanceMode() == QCameraImageProcessing::WhiteBalanceFlash); + + service.mockImageProcessingControl->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceSunset); + QVERIFY(service.mockImageProcessingControl->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceSunset)); + QVERIFY(service.mockImageProcessingControl->whiteBalanceMode() == QCameraImageProcessing::WhiteBalanceSunset); + + service.mockImageProcessingControl->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceVendor); + QVERIFY(service.mockImageProcessingControl->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceVendor)); + QVERIFY(service.mockImageProcessingControl->whiteBalanceMode() == QCameraImageProcessing::WhiteBalanceVendor); +} + +//Added test cases for QCameraFocus +void tst_QCamera::testCameraFocusIsAvailable() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + QCameraFocus *cameraFocus = camera.focus(); + QVERIFY(cameraFocus != 0); + QVERIFY(cameraFocus->isAvailable()); +} + +//Added this code to cover QCameraFocus::HyperfocalFocus and QCameraFocus::MacroFocus +//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); + QCameraFocus *cameraFocus = camera.focus(); + QVERIFY(cameraFocus != 0); + QVERIFY(!cameraFocus->isFocusModeSupported(QCameraFocus::HyperfocalFocus)); + QVERIFY(!cameraFocus->isFocusModeSupported(QCameraFocus::MacroFocus)); + QCOMPARE(cameraFocus->focusMode(), QCameraFocus::AutoFocus); + cameraFocus->setFocusMode(QCameraFocus::HyperfocalFocus); + QVERIFY(cameraFocus->focusMode()!= QCameraFocus::HyperfocalFocus); + QCOMPARE(cameraFocus->focusMode(), QCameraFocus::AutoFocus); + cameraFocus->setFocusMode(QCameraFocus::MacroFocus); + QVERIFY(cameraFocus->focusMode()!= QCameraFocus::MacroFocus); + QCOMPARE(cameraFocus->focusMode(), QCameraFocus::AutoFocus); +} + +void tst_QCamera::testOpticalAndDigitalZoomChanged() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + QCameraFocus *cameraFocus = camera.focus(); + QVERIFY(cameraFocus != 0); + QSignalSpy spy1(cameraFocus,SIGNAL(digitalZoomChanged(qreal))); + QSignalSpy spy2(cameraFocus,SIGNAL(opticalZoomChanged(qreal))); + QVERIFY(spy1.count() == 0); + QVERIFY(spy2.count() == 0); + cameraFocus->zoomTo(2.0,3.0); + QVERIFY(spy1.count() == 1); + QVERIFY(spy2.count() == 1); +} + +void tst_QCamera::testMaxDigitalZoomChangedSignal() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + QCameraFocus *cameraFocus = camera.focus(); + QVERIFY(cameraFocus != 0); + QSignalSpy spy(cameraFocus,SIGNAL(maximumDigitalZoomChanged(qreal))); + QVERIFY(spy.count() == 0); + cameraFocus->zoomTo(5.0,6.0); + QVERIFY(spy.count() == 1); +} + +void tst_QCamera::testMaxOpticalZoomChangedSignal() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + QCameraFocus *cameraFocus = camera.focus(); + QVERIFY(cameraFocus != 0); + QSignalSpy spy(cameraFocus,SIGNAL(maximumOpticalZoomChanged(qreal))); + QVERIFY(spy.count() == 0); + cameraFocus->zoomTo(5.0,6.0); + QVERIFY(spy.count() == 1); +} + +void tst_QCamera::testfocusZonesChangedSignal() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + QCameraFocus *cameraFocus = camera.focus(); + QVERIFY(cameraFocus != 0); + + QSignalSpy spy(cameraFocus,SIGNAL(focusZonesChanged())); + cameraFocus->zoomTo(5.0,6.0); + QVERIFY(spy.count() == 1); +} + +// test constructor for abstract class of ImageProcessingControl +void tst_QCamera :: testImageProcessingControl() +{ + QObject parent; + MockImageProcessingControl processCtrl(&parent); +} + +void tst_QCamera::testSignalApertureChanged() +{ + MockMediaServiceProvider provider1; + MockCameraService service; + provider1.service = &service; + QCamera camera(0, &provider1); + + QCameraExposure *cameraExposure = camera.exposure(); //create camera expose instance + QVERIFY(cameraExposure != 0); + + QSignalSpy spyApertureChanged(cameraExposure , SIGNAL(apertureChanged(qreal))); + QSignalSpy spyApertureRangeChanged(cameraExposure , SIGNAL(apertureRangeChanged())); + + + QVERIFY(spyApertureChanged.count() ==0); + cameraExposure->setManualAperture(10.0);//set the ManualAperture to 10.0 + + QTest::qWait(100); + QVERIFY(spyApertureChanged.count() ==1); + QVERIFY(spyApertureRangeChanged.count() ==1); +} + +void tst_QCamera::testSignalExposureCompensationChanged() +{ + MockMediaServiceProvider provider1; + MockCameraService service; + provider1.service = &service; + QCamera camera(0, &provider1); + + QCameraExposure *cameraExposure = camera.exposure(); //create camera expose instance + QVERIFY(cameraExposure != 0); + + QSignalSpy spyExposureCompensationChanged(cameraExposure , SIGNAL(exposureCompensationChanged(qreal))); + + QVERIFY(spyExposureCompensationChanged.count() ==0); + + QVERIFY(cameraExposure->exposureCompensation() != 800); + cameraExposure->setExposureCompensation(2.0); + + QTest::qWait(100); + + QVERIFY(cameraExposure->exposureCompensation() == 2.0); + + QCOMPARE(spyExposureCompensationChanged.count(),1); + + // Setting the same should not result in a signal + cameraExposure->setExposureCompensation(2.0); + QTest::qWait(100); + + QVERIFY(cameraExposure->exposureCompensation() == 2.0); + QCOMPARE(spyExposureCompensationChanged.count(),1); +} + +void tst_QCamera::testSignalIsoSensitivityChanged() +{ + + MockMediaServiceProvider provider1; + MockCameraService service; + provider1.service = &service; + QCamera camera(0, &provider1); + + QCameraExposure *cameraExposure = camera.exposure(); //create camera expose instance + QVERIFY(cameraExposure != 0); + + QSignalSpy spyisoSensitivityChanged(cameraExposure , SIGNAL(isoSensitivityChanged(int))); + + QVERIFY(spyisoSensitivityChanged.count() ==0); + + cameraExposure->setManualIsoSensitivity(800); //set the manualiso sentivity to 800 + QTest::qWait(100); + QVERIFY(spyisoSensitivityChanged.count() ==1); + +} +void tst_QCamera::testSignalShutterSpeedChanged() +{ + + MockMediaServiceProvider provider1; + MockCameraService service; + provider1.service = &service; + QCamera camera(0, &provider1); + + QCameraExposure *cameraExposure = camera.exposure(); //create camera expose instance + QVERIFY(cameraExposure != 0); + + QSignalSpy spySignalShutterSpeedChanged(cameraExposure , SIGNAL(shutterSpeedChanged(qreal))); + QSignalSpy spySignalShutterSpeedRangeChanged(cameraExposure , SIGNAL(shutterSpeedRangeChanged())); + + QVERIFY(spySignalShutterSpeedChanged.count() ==0); + + cameraExposure->setManualShutterSpeed(2.0);//set the ManualShutterSpeed to 2.0 + QTest::qWait(100); + + QVERIFY(spySignalShutterSpeedChanged.count() ==1); + QVERIFY(spySignalShutterSpeedRangeChanged.count() ==1); +} + +void tst_QCamera::testSignalFlashReady() +{ + MockMediaServiceProvider provider1; + MockCameraService service; + provider1.service = &service; + QCamera camera(0, &provider1); + + QCameraExposure *cameraExposure = camera.exposure(); //create camera expose instance + QVERIFY(cameraExposure != 0); + + + QSignalSpy spyflashReady(cameraExposure,SIGNAL(flashReady(bool))); + + QVERIFY(spyflashReady.count() ==0); + + QVERIFY(cameraExposure->flashMode() ==QCameraExposure::FlashAuto); + + cameraExposure->setFlashMode(QCameraExposure::FlashOff);//set theFlashMode to QCameraExposure::FlashOff + + QVERIFY(cameraExposure->flashMode() ==QCameraExposure::FlashOff); + + QVERIFY(spyflashReady.count() ==1); +} + +// test constructor +void tst_QCamera::testExposureControlConstructor() +{ + // To check changes in abstract classes's pure virtual functions + MockCameraExposureControl obj; +} + QTEST_MAIN(tst_QCamera) #include "tst_qcamera.moc" diff --git a/tests/auto/qcameraimagecapture/qcameraimagecapture.pro b/tests/auto/qcameraimagecapture/qcameraimagecapture.pro new file mode 100644 index 000000000..946665951 --- /dev/null +++ b/tests/auto/qcameraimagecapture/qcameraimagecapture.pro @@ -0,0 +1,9 @@ +load(qttest_p4) + +QT += multimediakit-private + +SOURCES += \ + tst_qcameraimagecapture.cpp + +include (../qmultimedia_common/mock.pri) +include (../qmultimedia_common/mockcamera.pri) diff --git a/tests/auto/qcameraimagecapture/tst_qcameraimagecapture.cpp b/tests/auto/qcameraimagecapture/tst_qcameraimagecapture.cpp new file mode 100644 index 000000000..8869dd6ce --- /dev/null +++ b/tests/auto/qcameraimagecapture/tst_qcameraimagecapture.cpp @@ -0,0 +1,410 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +/**************************************************************************** +Author : Vijay/Avinash + +Reviewer Name Date Coverage ( Full / Test Case IDs ). +--------------------------------------------------------------------------- + Initial review of test cases. +****************************************************************************/ + +//TESTED_COMPONENT=src/multimedia + +#include <QtTest/QtTest> +#include <QDebug> + +#include <qcameracontrol.h> +#include <qcameralockscontrol.h> +#include <qcameraexposurecontrol.h> +#include <qcameraflashcontrol.h> +#include <qcamerafocuscontrol.h> +#include <qcameraimagecapturecontrol.h> +#include <qimageencodercontrol.h> +#include <qcameraimageprocessingcontrol.h> +#include <qmediaservice.h> +#include <qcamera.h> +#include <qcameraimagecapture.h> +#include <qgraphicsvideoitem.h> +#include <qcameraviewfinder.h> + +#include "mockcameraservice.h" +#include "mockmediaserviceprovider.h" + +QT_USE_NAMESPACE + +class NullService: public QMediaService +{ + Q_OBJECT + +public: + NullService(): QMediaService(0) + { + + } + + ~NullService() + { + + } + + QMediaControl* requestControl(const char *iid) + { + Q_UNUSED(iid); + return 0; + } + + void releaseControl(QMediaControl*) {} + +}; + +class tst_QCameraImageCapture: public QObject +{ + Q_OBJECT + +public slots: + void initTestCase(); + void cleanupTestCase(); + +private slots: + void constructor(); + void mediaObject(); + void isReadyForCapture(); + void capture(); + void cancelCapture(); + void encodingSettings(); + void errors(); + void error(); + void imageCaptured(); + void imageExposed(); + void imageSaved(); + void readyForCaptureChanged(); + void supportedResolutions(); + void imageCodecDescription(); + void supportedImageCodecs(); + void cameraImageCaptureControl(); + +private: + MockCameraService *mockcameraservice; + MockMediaServiceProvider *provider; +}; + +void tst_QCameraImageCapture::initTestCase() +{ + provider = new MockMediaServiceProvider; + mockcameraservice = new MockCameraService; + provider->service = mockcameraservice; +} + +void tst_QCameraImageCapture::cleanupTestCase() +{ + delete mockcameraservice; + delete provider; +} + +//MaemoAPI-1823:test QCameraImageCapture Constructor +void tst_QCameraImageCapture::constructor() +{ + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + QVERIFY(imageCapture.isAvailable() == true); +} + +//MaemoAPI-1824:test mediaObject +void tst_QCameraImageCapture::mediaObject() +{ + MockMediaServiceProvider provider1; + NullService mymockcameraservice ; + provider1.service = &mymockcameraservice; + QCamera camera(0, &provider1); + QCameraImageCapture imageCapture(&camera); + QMediaObject *medobj = imageCapture.mediaObject(); + QVERIFY(medobj == NULL); + + QCamera camera1(0, provider); + QCameraImageCapture imageCapture1(&camera1); + QMediaObject *medobj1 = imageCapture1.mediaObject(); + QCOMPARE(medobj1, &camera1); +} + +//MaemoAPI-1825:test isReadyForCapture +void tst_QCameraImageCapture::isReadyForCapture() +{ + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + QVERIFY(imageCapture.isAvailable() == true); + QVERIFY(imageCapture.isReadyForCapture() == false); + camera.start(); + imageCapture.capture(); + QTest::qWait(300); + QVERIFY(imageCapture.isReadyForCapture() == true); + camera.stop(); +} + +//MaemoAPI-1826:test capture +void tst_QCameraImageCapture::capture() +{ + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + QVERIFY(imageCapture.isAvailable() == true); + QVERIFY(imageCapture.isReadyForCapture() == false); + QVERIFY(imageCapture.capture() == -1); + camera.start(); + QVERIFY(imageCapture.isReadyForCapture() == true); + QTest::qWait(300); + QVERIFY(imageCapture.capture() != -1); + camera.stop(); +} + +//MaemoAPI-1827:test cancelCapture +void tst_QCameraImageCapture::cancelCapture() +{ + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + QSignalSpy spy(&imageCapture, SIGNAL(imageCaptured(int,QImage))); + QSignalSpy spy1(&imageCapture, SIGNAL(imageSaved(int,QString))); + QVERIFY(imageCapture.isAvailable() == true); + QVERIFY(imageCapture.isReadyForCapture() == false); + camera.start(); + imageCapture.capture(); + QTest::qWait(300); + QVERIFY(imageCapture.isReadyForCapture() == true); + QVERIFY(spy.count() == 1 && spy1.count() == 1); + spy.clear(); + spy1.clear(); + camera.stop(); + + QVERIFY(imageCapture.isReadyForCapture() == false); + camera.start(); + imageCapture.capture(); + imageCapture.cancelCapture(); + QTest::qWait(300); + QVERIFY(imageCapture.isReadyForCapture() == true); + QVERIFY(spy.count() == 0 && spy1.count() == 0); + camera.stop(); +} + +//MaemoAPI-1828:test encodingSettings +//MaemoAPI-1829:test set encodingSettings +void tst_QCameraImageCapture::encodingSettings() +{ + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + QVERIFY(imageCapture.isAvailable() == true); + QVERIFY(imageCapture.encodingSettings() == QImageEncoderSettings()); + QImageEncoderSettings settings; + settings.setCodec("JPEG"); + settings.setQuality(QtMultimediaKit::NormalQuality); + imageCapture.setEncodingSettings(settings); + QVERIFY(!imageCapture.encodingSettings().isNull()); + QVERIFY(imageCapture.encodingSettings().codec() == "JPEG"); + QVERIFY(imageCapture.encodingSettings().quality() == QtMultimediaKit::NormalQuality); +} + +//MaemoAPI-1838:test supportedImageCodecs +void tst_QCameraImageCapture::supportedImageCodecs() +{ + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + QVERIFY(imageCapture.isAvailable() == true); + QVERIFY(!imageCapture.supportedImageCodecs().isEmpty()); +} + +//MaemoAPI-1836:test supportedResolutions +void tst_QCameraImageCapture::supportedResolutions() +{ + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + QVERIFY(imageCapture.isAvailable() == true); + QVERIFY(imageCapture.supportedResolutions().count() == 2); + QImageEncoderSettings settings1; + settings1.setCodec("PNG");; + settings1.setResolution(320, 240); + int result = imageCapture.supportedResolutions(settings1).count(); + QVERIFY(result == 1); +} + +//MaemoAPI-1837:test imageCodecDescription +void tst_QCameraImageCapture::imageCodecDescription() +{ + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + QVERIFY(imageCapture.isAvailable() == true); + QVERIFY(imageCapture.imageCodecDescription(" ").isNull()); + QVERIFY(imageCapture.imageCodecDescription("PNG").isNull() == false); +} + +//MaemoAPI-1830:test errors +void tst_QCameraImageCapture::errors() +{ + MockMediaServiceProvider provider1 ; + MockSimpleCameraService mockSimpleCameraService ; + provider1.service = &mockSimpleCameraService; + + QCamera camera1(0, &provider1); + QCameraImageCapture imageCapture1(&camera1); + QVERIFY(imageCapture1.isAvailable() == false); + imageCapture1.capture(QString::fromLatin1("/dev/null")); + QVERIFY(imageCapture1.error() == QCameraImageCapture::NotSupportedFeatureError); + QVERIFY2(!imageCapture1.errorString().isEmpty(), "Device does not support images capture"); + QVERIFY(imageCapture1.availabilityError() == QtMultimediaKit::ServiceMissingError); + + + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + QVERIFY(imageCapture.isAvailable() == true); + QVERIFY(imageCapture.error() == QCameraImageCapture::NoError); + QVERIFY(imageCapture.errorString().isEmpty()); + QVERIFY(imageCapture.availabilityError() == QtMultimediaKit::NoError); + + imageCapture.capture(); + QVERIFY(imageCapture.error() == QCameraImageCapture::NotReadyError); + QVERIFY2(!imageCapture.errorString().isEmpty(), "Could not capture in stopped state"); + QVERIFY(imageCapture.availabilityError() == QtMultimediaKit::NoError); +} + +//MaemoAPI-1831:test error +void tst_QCameraImageCapture::error() +{ + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + QSignalSpy spy(&imageCapture, SIGNAL(error(int,QCameraImageCapture::Error,QString))); + imageCapture.capture(); + QTest::qWait(30); + QVERIFY(spy.count() == 1); + QVERIFY(qvariant_cast<int>(spy.at(0).at(0)) == -1); + QVERIFY(qvariant_cast<QCameraImageCapture::Error>(spy.at(0).at(1)) == QCameraImageCapture::NotReadyError); + QVERIFY(qvariant_cast<QString>(spy.at(0).at(2)) == "Could not capture in stopped state"); + spy.clear(); +} + +//MaemoAPI-1832:test imageCaptured +void tst_QCameraImageCapture::imageCaptured() +{ + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + QSignalSpy spy(&imageCapture, SIGNAL(imageCaptured(int,QImage))); + QVERIFY(imageCapture.isAvailable() == true); + QVERIFY(imageCapture.isReadyForCapture() == false); + camera.start(); + imageCapture.capture(); + QTest::qWait(300); + QVERIFY(imageCapture.isReadyForCapture() == true); + + QVERIFY(spy.count() == 1); + QVERIFY(qvariant_cast<int>(spy.at(0).at(0)) > 0); + QImage image = qvariant_cast<QImage>(spy.at(0).at(1)); + QVERIFY(image.isNull() == true); + spy.clear(); + camera.stop(); +} + +//MaemoAPI-1833:test imageExposed +void tst_QCameraImageCapture::imageExposed() +{ + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + QSignalSpy spy(&imageCapture, SIGNAL(imageExposed(int))); + QVERIFY(imageCapture.isAvailable() == true); + QVERIFY(imageCapture.isReadyForCapture() == false); + camera.start(); + imageCapture.capture(); + QTest::qWait(300); + QVERIFY(imageCapture.isReadyForCapture() == true); + + QVERIFY(spy.count() == 1); + QVERIFY(qvariant_cast<int>(spy.at(0).at(0)) > 0); + spy.clear(); + camera.stop(); +} + +//MaemoAPI-1834:test imageSaved +void tst_QCameraImageCapture::imageSaved() +{ + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + QSignalSpy spy(&imageCapture, SIGNAL(imageSaved(int,QString))); + QVERIFY(imageCapture.isAvailable() == true); + QVERIFY(imageCapture.isReadyForCapture() == false); + camera.start(); + imageCapture.capture(QString::fromLatin1("/usr/share")); + QTest::qWait(300); + QVERIFY(imageCapture.isReadyForCapture() == true); + + QVERIFY(spy.count() == 1); + QVERIFY(qvariant_cast<int>(spy.at(0).at(0)) > 0); + QVERIFY(qvariant_cast<QString>(spy.at(0).at(1)) == "/usr/share"); + spy.clear(); + camera.stop(); +} + +//MaemoAPI-1835:test readyForCaptureChanged +void tst_QCameraImageCapture::readyForCaptureChanged() +{ + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + QSignalSpy spy(&imageCapture, SIGNAL(readyForCaptureChanged(bool))); + QVERIFY(imageCapture.isReadyForCapture() == false); + imageCapture.capture(); + QTest::qWait(100); + QVERIFY(spy.count() == 0); + QVERIFY2(!imageCapture.errorString().isEmpty(),"Could not capture in stopped state" ); + camera.start(); + QTest::qWait(100); + imageCapture.capture(); + QTest::qWait(100); + QVERIFY(spy.count() == 2); + QVERIFY(spy.at(0).at(0).toBool() == false); + QVERIFY(spy.at(1).at(0).toBool() == true); + camera.stop(); + spy.clear(); +} + +//MaemoAPI-1853:test cameraImageCapture control constructor +void tst_QCameraImageCapture::cameraImageCaptureControl() +{ + MockCameraControl ctrl; + MockCaptureControl capctrl(&ctrl); +} + +QTEST_MAIN(tst_QCameraImageCapture) + +#include "tst_qcameraimagecapture.moc" diff --git a/tests/auto/qcameraviewfinder/qcameraviewfinder.pro b/tests/auto/qcameraviewfinder/qcameraviewfinder.pro new file mode 100644 index 000000000..84228acb6 --- /dev/null +++ b/tests/auto/qcameraviewfinder/qcameraviewfinder.pro @@ -0,0 +1,8 @@ +load(qttest_p4) + +QT += multimediakit-private + +include (../qmultimedia_common/mock.pri) +include (../qmultimedia_common/mockcamera.pri) + +SOURCES += tst_qcameraviewfinder.cpp diff --git a/tests/auto/qcameraviewfinder/tst_qcameraviewfinder.cpp b/tests/auto/qcameraviewfinder/tst_qcameraviewfinder.cpp new file mode 100644 index 000000000..106a87bc7 --- /dev/null +++ b/tests/auto/qcameraviewfinder/tst_qcameraviewfinder.cpp @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 <QtTest/QtTest> +#include <QDebug> + +#include "qcameraviewfinder.h" +#include "qcamera.h" +#include "qmediaobject.h" + +#include "mockcameraservice.h" +#include "mockmediaserviceprovider.h" + +class tst_QCameraViewFinder : public QObject +{ + Q_OBJECT +public slots: + void initTestCase(); + void cleanupTestCase(); + +private slots: + void testConstructor(); + void testMediaObject(); + +private: + MockCameraService *mockcameraservice; + MockMediaServiceProvider *provider; + QCamera *camera; + QCameraViewfinder *viewFinder; +}; + +void tst_QCameraViewFinder::initTestCase() +{ + provider = new MockMediaServiceProvider; + mockcameraservice = new MockCameraService; + provider->service = mockcameraservice; + + camera = new QCamera(0, provider); + viewFinder = new QCameraViewfinder(); +} + +void tst_QCameraViewFinder::cleanupTestCase() +{ + delete mockcameraservice; + delete provider; +} + +void tst_QCameraViewFinder::testConstructor() +{ + /* Verify whether the object is created or not */ + QVERIFY(viewFinder != NULL); + QCOMPARE(viewFinder->isVisible(),false); + QCOMPARE(viewFinder->isEnabled(),true); + viewFinder->show(); +} + +void tst_QCameraViewFinder::testMediaObject() +{ + QVERIFY(viewFinder != NULL); + viewFinder->show(); + /* Sets the QVideoWidget based camera viewfinder.*/ + camera->setViewfinder(viewFinder); + QCOMPARE(viewFinder->isVisible(),true); + + /* Return the currently attached media object.*/ + QMediaObject *media = viewFinder->mediaObject(); + + /* Verifying the object */ + QCOMPARE(media, camera); +} + +QTEST_MAIN(tst_QCameraViewFinder) +#include "tst_qcameraviewfinder.moc" diff --git a/tests/auto/qmediabindableinterface/qmediabindableinterface.pro b/tests/auto/qmediabindableinterface/qmediabindableinterface.pro new file mode 100644 index 000000000..347c49d62 --- /dev/null +++ b/tests/auto/qmediabindableinterface/qmediabindableinterface.pro @@ -0,0 +1,9 @@ +load(qttest_p4) + +QT += multimediakit-private + +SOURCES += \ + tst_qmediabindableinterface.cpp + +include (../qmultimedia_common/mock.pri) +include (../qmultimedia_common/mockrecorder.pri) diff --git a/tests/auto/qmediabindableinterface/tst_qmediabindableinterface.cpp b/tests/auto/qmediabindableinterface/tst_qmediabindableinterface.cpp new file mode 100644 index 000000000..d7f06db8a --- /dev/null +++ b/tests/auto/qmediabindableinterface/tst_qmediabindableinterface.cpp @@ -0,0 +1,137 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/multimedia + +#include <QtTest/QtTest> +#include <qmediaobject.h> +#include <qmediacontrol.h> +#include <qmediaservice.h> +#include <qmediarecordercontrol.h> +#include <qmediarecorder.h> +#include <qmetadatawritercontrol.h> +#include <qaudioendpointselector.h> +#include <qaudioencodercontrol.h> +#include <qmediacontainercontrol.h> +#include <qvideoencodercontrol.h> +#include <qaudioformat.h> + +#include "mockmediacontainercontrol.h" +#include "mockmetadatawritercontrol.h" +#include "mockmediarecordercontrol.h" +#include "mockmediaobject.h" + +QT_USE_NAMESPACE + +class TestBindableService : public QMediaService +{ + Q_OBJECT +public: + TestBindableService(QObject *parent, QMediaControl *control): + QMediaService(parent), + mockControl(control), + hasControls(true) + { + mockContainerControl = new MockMediaContainerControl(parent); //Creating the object for Media + mockMetaDataControl = new MockMetaDataWriterControl(parent); //Creating the object for MetaData + } + + QMediaControl* requestControl(const char *name) + { + if (hasControls && qstrcmp(name,QMediaRecorderControl_iid) == 0) + return mockControl; + if (hasControls && qstrcmp(name,QMediaContainerControl_iid) == 0) + return mockContainerControl; + if (hasControls && qstrcmp(name, QMetaDataWriterControl_iid) == 0) + return mockMetaDataControl; + + return 0; + } + + void releaseControl(QMediaControl*) {} + //Initialising the objects for the media + QMediaControl *mockControl; + QMediaContainerControl *mockContainerControl; + MockMetaDataWriterControl *mockMetaDataControl; + bool hasControls; +}; + +class tst_QMediaBindableInterface:public QObject +{ + Q_OBJECT +private slots: + void init() + { + + } + + void cleanup() + { + + } + + void testMediaObject() //Verifying the mediaobject api + { + MockMediaRecorderControl recorderControl(0); + TestBindableService service(0, &recorderControl); + service.mockMetaDataControl->populateMetaData(); + MockMediaObject object(0, &service); + QMediaRecorder recorder(&object); + QMediaObject *obj = recorder.mediaObject(); + QVERIFY(obj != NULL); + QVERIFY(obj->isAvailable()); + } + + void testDestructor() //Invoking the destructor + { + MockMediaRecorderControl recorderControl(0); + TestBindableService service(0, &recorderControl); + service.mockMetaDataControl->populateMetaData(); + MockMediaObject object(0, &service); + QMediaRecorder *recorder = new QMediaRecorder(&object); + QVERIFY(recorder->isAvailable()); + delete recorder; + recorder = NULL; + } +}; + +QTEST_MAIN(tst_QMediaBindableInterface) +#include "tst_qmediabindableinterface.moc" diff --git a/tests/auto/qmediacontainercontrol/qmediacontainercontrol.pro b/tests/auto/qmediacontainercontrol/qmediacontainercontrol.pro new file mode 100644 index 000000000..db5390233 --- /dev/null +++ b/tests/auto/qmediacontainercontrol/qmediacontainercontrol.pro @@ -0,0 +1,8 @@ +load(qttest_p4) + +QT += multimediakit-private + +SOURCES += tst_qmediacontainercontrol.cpp + +include (../qmultimedia_common/mockcontainer.pri) + diff --git a/tests/auto/qmediacontainercontrol/tst_qmediacontainercontrol.cpp b/tests/auto/qmediacontainercontrol/tst_qmediacontainercontrol.cpp new file mode 100644 index 000000000..e5dabd12d --- /dev/null +++ b/tests/auto/qmediacontainercontrol/tst_qmediacontainercontrol.cpp @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/multimedia + +#include <QtTest/QtTest> +#include "qmediacontainercontrol.h" +#include "qmediarecorder.h" + +#include "../qmultimedia_common/mockmediacontainercontrol.h" + +//MaemoAPI- +class tst_QMediaContainerControl :public QObject +{ + Q_OBJECT + +private slots: + //to test the constructor + void tst_mediacontainercontrol() + { + + QObject obj; + MockMediaContainerControl control(&obj); + QStringList strlist=control.supportedContainers(); + QStringList strlist1; + strlist1 << "wav" << "mp3" << "mov"; + QVERIFY(strlist[0]==strlist1[0]); //checking with "wav" mime type + QVERIFY(strlist[1]==strlist1[1]); //checking with "mp3" mime type + QVERIFY(strlist[2]==strlist1[2]); //checking with "mov" mime type + + control.setContainerMimeType("wav"); + const QString str("wav"); + QVERIFY2(control.containerMimeType() == str,"Failed"); + + const QString str1("WAV format"); + QVERIFY2(control.containerDescription("wav") == str1,"FAILED"); + } +}; + +QTEST_MAIN(tst_QMediaContainerControl); +#include "tst_qmediacontainercontrol.moc" diff --git a/tests/auto/qmediacontent/tst_qmediacontent.cpp b/tests/auto/qmediacontent/tst_qmediacontent.cpp index 98758efe4..a215b479c 100644 --- a/tests/auto/qmediacontent/tst_qmediacontent.cpp +++ b/tests/auto/qmediacontent/tst_qmediacontent.cpp @@ -89,6 +89,7 @@ void tst_QMediaContent::testRequestCtor() QMediaContent media(request); QCOMPARE(media.canonicalUrl(), QUrl("http://example.com/movie.mov")); + QCOMPARE(media.canonicalRequest(),request); QCOMPARE(media.canonicalResource().request(), request); QCOMPARE(media.canonicalResource().url(), QUrl("http://example.com/movie.mov")); } diff --git a/tests/auto/qmediaimageviewer/tst_qmediaimageviewer.cpp b/tests/auto/qmediaimageviewer/tst_qmediaimageviewer.cpp index 385a80c7f..ff88b9cb3 100644 --- a/tests/auto/qmediaimageviewer/tst_qmediaimageviewer.cpp +++ b/tests/auto/qmediaimageviewer/tst_qmediaimageviewer.cpp @@ -85,6 +85,8 @@ private slots: void setVideoOutput(); void debugEnums(); + void mediaChanged_signal(); + public: tst_QMediaImageViewer() : m_network(0) {} @@ -386,7 +388,17 @@ void tst_QMediaImageViewer::setConsecutiveMedia() QMediaImageViewerService *service = qobject_cast<QMediaImageViewerService *>(viewer.service()); service->setNetworkManager(m_network); + viewer.setMedia(networkMedia2); viewer.setMedia(networkMedia1); + + QCOMPARE(viewer.media(), networkMedia1); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); + + QTestEventLoop::instance().enterLoop(2); + QCOMPARE(viewer.media(), networkMedia1); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadedMedia); + + viewer.setMedia(fileMedia1); viewer.setMedia(networkMedia2); QCOMPARE(viewer.media(), networkMedia2); @@ -420,6 +432,7 @@ void tst_QMediaImageViewer::setConsecutiveMedia() void tst_QMediaImageViewer::setInvalidMedia() { QMediaImageViewer viewer; + viewer.setTimeout(250); QMediaImageViewerService *service = qobject_cast<QMediaImageViewerService *>(viewer.service()); service->setNetworkManager(m_network); @@ -1031,6 +1044,20 @@ void tst_QMediaImageViewer::debugEnums() qDebug() << QMediaImageViewer::NoMedia; } +void tst_QMediaImageViewer::mediaChanged_signal() +{ + QMediaContent imageMedia(imageUrl("image.png")); + QMediaImageViewer viewer; + viewer.setTimeout(250); + viewer.setNotifyInterval(150); + + QSignalSpy spy(&viewer, SIGNAL(mediaChanged(QMediaContent))); + QVERIFY(spy.size() == 0); + + viewer.setMedia(imageMedia); + QVERIFY(spy.size() == 1); +} + QTEST_MAIN(tst_QMediaImageViewer) #include "tst_qmediaimageviewer.moc" diff --git a/tests/auto/qmediaobject/qmediaobject.pro b/tests/auto/qmediaobject/qmediaobject.pro index c48a679a2..e33804456 100644 --- a/tests/auto/qmediaobject/qmediaobject.pro +++ b/tests/auto/qmediaobject/qmediaobject.pro @@ -5,6 +5,8 @@ QT += multimediakit-private # TARGET = tst_qmediaobject # CONFIG += testcase +include (../qmultimedia_common/mockrecorder.pri) + HEADERS+= tst_qmediaobject.h SOURCES += main.cpp tst_qmediaobject.cpp diff --git a/tests/auto/qmediaobject/tst_qmediaobject.cpp b/tests/auto/qmediaobject/tst_qmediaobject.cpp index 028c5684b..2c96a393c 100644 --- a/tests/auto/qmediaobject/tst_qmediaobject.cpp +++ b/tests/auto/qmediaobject/tst_qmediaobject.cpp @@ -42,6 +42,10 @@ //TESTED_COMPONENT=src/multimedia #include "tst_qmediaobject.h" +#include "qvideowidget.h" + +#include "mockmediarecorderservice.h" +#include "mockmediaserviceprovider.h" QT_USE_NAMESPACE @@ -357,3 +361,44 @@ void tst_QMediaObject::availability() QCOMPARE(object.isAvailable(), true); QCOMPARE(object.availabilityError(), QtMultimediaKit::NoError); } + + void tst_QMediaObject::service() + { + // Create the mediaobject with service. + QtTestMetaDataService service; + QtTestMediaObject mediaObject1(&service); + + // Get service and Compare if it equal to the service passed as an argument in mediaObject1. + QMediaService *service1 = mediaObject1.service(); + QVERIFY(service1 != NULL); + QCOMPARE(service1,&service); + + // Create the mediaobject with empty service and verify that service() returns NULL. + QtTestMediaObject mediaObject2; + QMediaService *service2 = mediaObject2.service(); + QVERIFY(service2 == NULL); + } + + void tst_QMediaObject::availabilityChangedSignal() + { + // The availabilityChangedSignal is implemented in QAudioCaptureSource. So using it to test the signal. + MockMediaRecorderService *mockAudioSourceService = new MockMediaRecorderService; + MockMediaServiceProvider *mockProvider = new MockMediaServiceProvider(mockAudioSourceService); + QAudioCaptureSource *audiosource = new QAudioCaptureSource(0, mockProvider); + + QSignalSpy spy(audiosource, SIGNAL(availabilityChanged(bool))); + + // Add the end points and verify if the availablity changed signal emitted with argument true. + QMetaObject::invokeMethod(mockAudioSourceService->mockAudioEndpointSelector, "addEndpoints"); + QVERIFY(spy.count() == 1); + bool available = qvariant_cast<bool>(spy.at(0).at(0)); + QVERIFY(available == true); + + spy.clear(); + + // Remove all endpoints and verify if the signal is emitted with argument false. + QMetaObject::invokeMethod(mockAudioSourceService->mockAudioEndpointSelector, "removeEndpoints"); + QVERIFY(spy.count() == 1); + available = qvariant_cast<bool>(spy.at(0).at(0)); + QVERIFY(available == false); + } diff --git a/tests/auto/qmediaobject/tst_qmediaobject.h b/tests/auto/qmediaobject/tst_qmediaobject.h index e51e383d9..5bc70c4a4 100644 --- a/tests/auto/qmediaobject/tst_qmediaobject.h +++ b/tests/auto/qmediaobject/tst_qmediaobject.h @@ -48,9 +48,38 @@ #include <qmediaobject.h> #include <qmediaservice.h> #include <qmetadatareadercontrol.h> +#include <qaudiocapturesource.h> +#include <qaudioendpointselector.h> //TESTED_COMPONENT=src/multimedia +#include "mockmetadatareadercontrol.h" + +class QtTestMetaDataService : public QMediaService +{ + Q_OBJECT +public: + QtTestMetaDataService(QObject *parent = 0):QMediaService(parent), metaDataRef(0), hasMetaData(true) + { + } + + QMediaControl *requestControl(const char *iid) + { + if (hasMetaData && qstrcmp(iid, QMetaDataReaderControl_iid) == 0) + return &metaData; + else + return 0; + } + + void releaseControl(QMediaControl *) + { + } + + MockMetaDataReaderControl metaData; + int metaDataRef; + bool hasMetaData; +}; + QT_USE_NAMESPACE class tst_QMediaObject : public QObject { @@ -72,72 +101,13 @@ private slots: void extendedMetaData_data() { metaData_data(); } void extendedMetaData(); + void service(); + void availabilityChangedSignal(); private: void setupNotifyTests(); }; -class QtTestMetaDataProvider : public QMetaDataReaderControl -{ - Q_OBJECT -public: - QtTestMetaDataProvider(QObject *parent = 0) - : QMetaDataReaderControl(parent) - , m_available(false) - { - } - - bool isMetaDataAvailable() const { return m_available; } - void setMetaDataAvailable(bool available) { - if (m_available != available) - emit metaDataAvailableChanged(m_available = available); - } - QList<QtMultimediaKit::MetaData> availableMetaData() const { return m_data.keys(); } - - - QVariant metaData(QtMultimediaKit::MetaData key) const { return m_data.value(key); } - - QVariant extendedMetaData(const QString &key) const { return m_extendedData.value(key); } - - QStringList availableExtendedMetaData() const { return m_extendedData.keys(); } - - using QMetaDataReaderControl::metaDataChanged; - - void populateMetaData() - { - m_available = true; - } - - bool m_available; - QMap<QtMultimediaKit::MetaData, QVariant> m_data; - QMap<QString, QVariant> m_extendedData; -}; - -class QtTestMetaDataService : public QMediaService -{ - Q_OBJECT -public: - QtTestMetaDataService(QObject *parent = 0):QMediaService(parent), metaDataRef(0), hasMetaData(true) - { - } - - QMediaControl *requestControl(const char *iid) - { - if (hasMetaData && qstrcmp(iid, QMetaDataReaderControl_iid) == 0) - return &metaData; - else - return 0; - } - - void releaseControl(QMediaControl *) - { - } - - QtTestMetaDataProvider metaData; - int metaDataRef; - bool hasMetaData; -}; - class QtTestMediaObject : public QMediaObject { Q_OBJECT @@ -174,4 +144,4 @@ private: int m_c; int m_d; }; -#endif //TST_QMEDIAOBJECT_H
\ No newline at end of file +#endif //TST_QMEDIAOBJECT_H diff --git a/tests/auto/qmediaplayer/qmediaplayer.pro b/tests/auto/qmediaplayer/qmediaplayer.pro index 0c2880e0d..26bf81326 100644 --- a/tests/auto/qmediaplayer/qmediaplayer.pro +++ b/tests/auto/qmediaplayer/qmediaplayer.pro @@ -8,3 +8,5 @@ QT += network multimediakit-private HEADERS += tst_qmediaplayer.h SOURCES += main.cpp tst_qmediaplayer.cpp +include (../qmultimedia_common/mock.pri) +include (../qmultimedia_common/mockplayer.pri) diff --git a/tests/auto/qmediaplayer/tst_qmediaplayer.cpp b/tests/auto/qmediaplayer/tst_qmediaplayer.cpp index 277bf7e1c..fb438f626 100644 --- a/tests/auto/qmediaplayer/tst_qmediaplayer.cpp +++ b/tests/auto/qmediaplayer/tst_qmediaplayer.cpp @@ -79,6 +79,8 @@ QT_USE_NAMESPACE +#include "mockvideosurface.h" + void tst_QMediaPlayer::initTestCase_data() { QTest::addColumn<bool>("valid"); @@ -126,8 +128,8 @@ void tst_QMediaPlayer::initTestCase() qRegisterMetaType<QMediaPlayer::MediaStatus>("QMediaPlayer::MediaStatus"); qRegisterMetaType<QMediaContent>("QMediaContent"); - mockService = new MockPlayerService; - mockProvider = new MockProvider(mockService); + mockService = new MockMediaPlayerService; + mockProvider = new MockMediaServiceProvider(mockService, true); player = new QMediaPlayer(0, 0, mockProvider); } @@ -147,7 +149,7 @@ void tst_QMediaPlayer::cleanup() void tst_QMediaPlayer::testNullService() { - MockProvider provider(0); + MockMediaServiceProvider provider(0); QMediaPlayer player(0, 0, &provider); const QIODevice *nullDevice = 0; @@ -842,6 +844,68 @@ void tst_QMediaPlayer::testPlaylist() } +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) + { + /* if the flag is low latency set the low latency play back for the service provider */ + feature = QMediaServiceProviderHint::LowLatencyPlayback; + const QByteArray service(Q_MEDIASERVICE_MEDIAPLAYER); + const QMediaServiceProviderHint providerHint(feature); + /* request service for the service provider */ + provider.requestService(service,providerHint); + + /* Constructs a SupportedFeatures media service provider hint. */ + QMediaServiceProviderHint servicepro(feature); + + /* compare the flag value */ + QVERIFY(servicepro.features() == QMediaServiceProviderHint::LowLatencyPlayback); + } + + /* The player is expected to play QIODevice based streams. + If passed to QMediaPlayer constructor, + the service supporting streams playback will be chosen. */ + 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) + { + /* if the flag is stream play back set the stream play back for the service provider */ + feature = QMediaServiceProviderHint::StreamPlayback; + const QByteArray service(Q_MEDIASERVICE_MEDIAPLAYER); + const QMediaServiceProviderHint providerHint(feature); + + /* request service for the service provider */ + provider.requestService(service,providerHint); + + /* Constructs a SupportedFeatures media service provider hint. */ + QMediaServiceProviderHint servicepro(feature); + + /* compare the flag value */ + QVERIFY(servicepro.features() == QMediaServiceProviderHint::StreamPlayback); + } +} + +void tst_QMediaPlayer::testDestructor() +{ + /* create an object for player */ + QMediaPlayer *player = new QMediaPlayer; + + /* check whether the object is created */ + QVERIFY(player); + + /* delete the instance */ + delete player; +} + void tst_QMediaPlayer::testNetworkAccess() { QNetworkConfigurationManager manager; @@ -876,9 +940,8 @@ void tst_QMediaPlayer::testSetVideoOutput() QGraphicsVideoItem item; MockVideoSurface surface; - MockPlayerService service; - MockProvider provider(&service); - provider.deleteServiceOnRelease = false; + MockMediaPlayerService service; + MockMediaServiceProvider provider(&service); QMediaPlayer player(0, 0, &provider); player.setVideoOutput(&widget); @@ -922,7 +985,7 @@ void tst_QMediaPlayer::testSetVideoOutputNoService() QGraphicsVideoItem item; MockVideoSurface surface; - MockProvider provider(0); + MockMediaServiceProvider provider(0, true); QMediaPlayer player(0, 0, &provider); player.setVideoOutput(&widget); @@ -941,12 +1004,11 @@ void tst_QMediaPlayer::testSetVideoOutputNoControl() QGraphicsVideoItem item; MockVideoSurface surface; - MockPlayerService service; + MockMediaPlayerService service; service.rendererRef = 1; service.windowRef = 1; - MockProvider provider(&service); - provider.deleteServiceOnRelease = false; + MockMediaServiceProvider provider(&service); QMediaPlayer player(0, 0, &provider); player.setVideoOutput(&widget); @@ -963,9 +1025,8 @@ void tst_QMediaPlayer::testSetVideoOutputDestruction() { MockVideoSurface surface; - MockPlayerService service; - MockProvider provider(&service); - provider.deleteServiceOnRelease = false; + MockMediaPlayerService service; + MockMediaServiceProvider provider(&service); { QMediaPlayer player(0, 0, &provider); @@ -1016,4 +1077,9 @@ void tst_QMediaPlayer::debugEnums() qDebug() << QMediaPlayer::NetworkError; } +void tst_QMediaPlayer::testSupportedMimeTypes() +{ + QStringList mimeList = QMediaPlayer::supportedMimeTypes(QMediaPlayer::LowLatency); + // This is empty on some platforms, and not on others, so can't test something here at the moment. +} diff --git a/tests/auto/qmediaplayer/tst_qmediaplayer.h b/tests/auto/qmediaplayer/tst_qmediaplayer.h index 096774316..c87c65a7d 100755 --- a/tests/auto/qmediaplayer/tst_qmediaplayer.h +++ b/tests/auto/qmediaplayer/tst_qmediaplayer.h @@ -56,6 +56,9 @@ #include <qvideorenderercontrol.h> #include <qvideowindowcontrol.h> +#include "mockmediaserviceprovider.h" +#include "mockmediaplayerservice.h" + QT_USE_NAMESPACE class AutoConnection @@ -79,313 +82,6 @@ private: const char *method; }; - -class MockPlayerControl : public QMediaPlayerControl -{ - friend class MockPlayerService; - -public: - MockPlayerControl():QMediaPlayerControl(0) {} - - QMediaPlayer::State state() const { return _state; } - QMediaPlayer::MediaStatus mediaStatus() const { return _mediaStatus; } - - qint64 duration() const { return _duration; } - - qint64 position() const { return _position; } - - void setPosition(qint64 position) { if (position != _position) emit positionChanged(_position = position); } - - int volume() const { return _volume; } - void setVolume(int volume) { emit volumeChanged(_volume = volume); } - - bool isMuted() const { return _muted; } - void setMuted(bool muted) { if (muted != _muted) emit mutedChanged(_muted = muted); } - - int bufferStatus() const { return _bufferStatus; } - - bool isAudioAvailable() const { return _audioAvailable; } - bool isVideoAvailable() const { return _videoAvailable; } - - bool isSeekable() const { return _isSeekable; } - QMediaTimeRange availablePlaybackRanges() const { return QMediaTimeRange(_seekRange.first, _seekRange.second); } - void setSeekRange(qint64 minimum, qint64 maximum) { _seekRange = qMakePair(minimum, maximum); } - - qreal playbackRate() const { return _playbackRate; } - void setPlaybackRate(qreal rate) { if (rate != _playbackRate) emit playbackRateChanged(_playbackRate = rate); } - - QMediaContent media() const { return _media; } - void setMedia(const QMediaContent &content, QIODevice *stream) - { - _stream = stream; - _media = content; - if (_state != QMediaPlayer::StoppedState) { - _mediaStatus = _media.isNull() ? QMediaPlayer::NoMedia : QMediaPlayer::LoadingMedia; - emit stateChanged(_state = QMediaPlayer::StoppedState); - emit mediaStatusChanged(_mediaStatus); - } - emit mediaChanged(_media = content); - } - QIODevice *mediaStream() const { return _stream; } - - void play() { if (_isValid && !_media.isNull() && _state != QMediaPlayer::PlayingState) emit stateChanged(_state = QMediaPlayer::PlayingState); } - void pause() { if (_isValid && !_media.isNull() && _state != QMediaPlayer::PausedState) emit stateChanged(_state = QMediaPlayer::PausedState); } - void stop() { if (_state != QMediaPlayer::StoppedState) emit stateChanged(_state = QMediaPlayer::StoppedState); } - - QMediaPlayer::State _state; - QMediaPlayer::MediaStatus _mediaStatus; - QMediaPlayer::Error _error; - qint64 _duration; - qint64 _position; - int _volume; - bool _muted; - int _bufferStatus; - bool _audioAvailable; - bool _videoAvailable; - bool _isSeekable; - QPair<qint64, qint64> _seekRange; - qreal _playbackRate; - QMediaContent _media; - QIODevice *_stream; - bool _isValid; - QString _errorString; -}; - -class MockVideoSurface : public QAbstractVideoSurface -{ -public: - QList<QVideoFrame::PixelFormat> supportedPixelFormats( - const QAbstractVideoBuffer::HandleType) const - { - return QList<QVideoFrame::PixelFormat>(); - } - - bool present(const QVideoFrame &) { return false; } -}; - -class MockVideoRendererControl : public QVideoRendererControl -{ -public: - MockVideoRendererControl() : m_surface(0) {} - - QAbstractVideoSurface *surface() const { return m_surface; } - void setSurface(QAbstractVideoSurface *surface) { m_surface = surface; } - - QAbstractVideoSurface *m_surface; -}; - -class MockVideoWindowControl : public QVideoWindowControl -{ -public: - WId winId() const { return 0; } - void setWinId(WId) {} - QRect displayRect() const { return QRect(); } - void setDisplayRect(const QRect &) {} - bool isFullScreen() const { return false; } - void setFullScreen(bool) {} - void repaint() {} - QSize nativeSize() const { return QSize(); } - Qt::AspectRatioMode aspectRatioMode() const { return Qt::KeepAspectRatio; } - void setAspectRatioMode(Qt::AspectRatioMode) {} - int brightness() const { return 0; } - void setBrightness(int) {} - int contrast() const { return 0; } - void setContrast(int) {} - int hue() const { return 0; } - void setHue(int) {} - int saturation() const { return 0; } - void setSaturation(int) {} -}; - -class MockStreamsControl : public QMediaStreamsControl -{ -public: - MockStreamsControl(QObject *parent = 0) : QMediaStreamsControl(parent) {} - - int streamCount() { return _streams.count(); } - void setStreamCount(int count) { _streams.resize(count); } - - StreamType streamType(int index) { return _streams.at(index).type; } - void setStreamType(int index, StreamType type) { _streams[index].type = type; } - - QVariant metaData(int index, QtMultimediaKit::MetaData key) { - return _streams.at(index).metaData.value(key); } - void setMetaData(int index, QtMultimediaKit::MetaData key, const QVariant &value) { - _streams[index].metaData.insert(key, value); } - - bool isActive(int index) { return _streams.at(index).active; } - void setActive(int index, bool state) { _streams[index].active = state; } - -private: - struct Stream - { - Stream() : type(UnknownStream), active(false) {} - StreamType type; - QMap<QtMultimediaKit::MetaData, QVariant> metaData; - bool active; - }; - - QVector<Stream> _streams; -}; - -class MockNetworkAccessControl : public QMediaNetworkAccessControl -{ - friend class MockPlayerService; - -public: - MockNetworkAccessControl() {} - ~MockNetworkAccessControl() {} - - void setConfigurations(const QList<QNetworkConfiguration> &configurations) - { - _configurations = configurations; - _current = QNetworkConfiguration(); - } - - QNetworkConfiguration currentConfiguration() const - { - return _current; - } - -private: - void setCurrentConfiguration(QNetworkConfiguration configuration) - { - if (_configurations.contains(configuration)) - emit configurationChanged(_current = configuration); - else - emit configurationChanged(_current = QNetworkConfiguration()); - } - - QList<QNetworkConfiguration> _configurations; - QNetworkConfiguration _current; -}; - -Q_DECLARE_METATYPE(QNetworkConfiguration) - -class MockPlayerService : public QMediaService -{ - Q_OBJECT - -public: - MockPlayerService():QMediaService(0) - { - mockControl = new MockPlayerControl; - mockStreamsControl = new MockStreamsControl; - mockNetworkControl = new MockNetworkAccessControl; - rendererControl = new MockVideoRendererControl; - windowControl = new MockVideoWindowControl; - rendererRef = 0; - windowRef = 0; - } - - ~MockPlayerService() - { - delete mockControl; - delete mockStreamsControl; - delete mockNetworkControl; - delete rendererControl; - delete windowControl; - } - - QMediaControl* requestControl(const char *iid) - { - if (qstrcmp(iid, QMediaPlayerControl_iid) == 0) { - return mockControl; - } else if (qstrcmp(iid, QVideoRendererControl_iid) == 0) { - if (rendererRef == 0) { - rendererRef += 1; - return rendererControl; - } - } else if (qstrcmp(iid, QVideoWindowControl_iid) == 0) { - if (windowRef == 0) { - windowRef += 1; - return windowControl; - } - } - - - if (qstrcmp(iid, QMediaNetworkAccessControl_iid) == 0) - return mockNetworkControl; - return 0; - } - - void releaseControl(QMediaControl *control) - { - if (control == rendererControl) - rendererRef -= 1; - else if (control == windowControl) - windowRef -= 1; - } - - void setState(QMediaPlayer::State state) { emit mockControl->stateChanged(mockControl->_state = state); } - void setState(QMediaPlayer::State state, QMediaPlayer::MediaStatus status) { - mockControl->_state = state; - mockControl->_mediaStatus = status; - emit mockControl->mediaStatusChanged(status); - emit mockControl->stateChanged(state); - } - void setMediaStatus(QMediaPlayer::MediaStatus status) { emit mockControl->mediaStatusChanged(mockControl->_mediaStatus = status); } - void setIsValid(bool isValid) { mockControl->_isValid = isValid; } - void setMedia(QMediaContent media) { mockControl->_media = media; } - void setDuration(qint64 duration) { mockControl->_duration = duration; } - void setPosition(qint64 position) { mockControl->_position = position; } - void setSeekable(bool seekable) { mockControl->_isSeekable = seekable; } - void setVolume(int volume) { mockControl->_volume = volume; } - void setMuted(bool muted) { mockControl->_muted = muted; } - void setVideoAvailable(bool videoAvailable) { mockControl->_videoAvailable = videoAvailable; } - void setBufferStatus(int bufferStatus) { mockControl->_bufferStatus = bufferStatus; } - void setPlaybackRate(qreal playbackRate) { mockControl->_playbackRate = playbackRate; } - void setError(QMediaPlayer::Error error) { mockControl->_error = error; emit mockControl->error(mockControl->_error, mockControl->_errorString); } - void setErrorString(QString errorString) { mockControl->_errorString = errorString; emit mockControl->error(mockControl->_error, mockControl->_errorString); } - - void selectCurrentConfiguration(QNetworkConfiguration config) { mockNetworkControl->setCurrentConfiguration(config); } - - void reset() - { - mockControl->_state = QMediaPlayer::StoppedState; - mockControl->_mediaStatus = QMediaPlayer::UnknownMediaStatus; - mockControl->_error = QMediaPlayer::NoError; - mockControl->_duration = 0; - mockControl->_position = 0; - mockControl->_volume = 0; - mockControl->_muted = false; - mockControl->_bufferStatus = 0; - mockControl->_videoAvailable = false; - mockControl->_isSeekable = false; - mockControl->_playbackRate = 0.0; - mockControl->_media = QMediaContent(); - mockControl->_stream = 0; - mockControl->_isValid = false; - mockControl->_errorString = QString(); - - mockNetworkControl->_current = QNetworkConfiguration(); - mockNetworkControl->_configurations = QList<QNetworkConfiguration>(); - } - - MockPlayerControl *mockControl; - MockStreamsControl *mockStreamsControl; - MockNetworkAccessControl *mockNetworkControl; - MockVideoRendererControl *rendererControl; - MockVideoWindowControl *windowControl; - int rendererRef; - int windowRef; -}; - -class MockProvider : public QMediaServiceProvider -{ -public: - MockProvider(MockPlayerService *service):mockService(service), deleteServiceOnRelease(true) {} - QMediaService *requestService(const QByteArray &, const QMediaServiceProviderHint &) - { - return mockService; - } - - void releaseService(QMediaService *service) { if (deleteServiceOnRelease) delete service; } - - MockPlayerService *mockService; - bool deleteServiceOnRelease; -}; - class tst_QMediaPlayer: public QObject { Q_OBJECT @@ -425,10 +121,13 @@ private slots: void testSetVideoOutputDestruction(); void testPositionPropertyWatch(); void debugEnums(); + void testPlayerFlags(); + void testDestructor(); + void testSupportedMimeTypes(); private: - MockProvider *mockProvider; - MockPlayerService *mockService; + MockMediaServiceProvider *mockProvider; + MockMediaPlayerService *mockService; QMediaPlayer *player; }; diff --git a/tests/auto/qmediaplaylist/qmediaplaylist.pro b/tests/auto/qmediaplaylist/qmediaplaylist.pro index b500f4e66..018d7b08d 100644 --- a/tests/auto/qmediaplaylist/qmediaplaylist.pro +++ b/tests/auto/qmediaplaylist/qmediaplaylist.pro @@ -3,6 +3,8 @@ load(qttest_p4) # temporarily blacklist test because is fails miserably CONFIG += insignificant_test +include (../qmultimedia_common/mockplaylist.pri) + QT += multimediakit-private # TARGET = tst_qmediaplaylist @@ -13,7 +15,6 @@ DEFINES += TESTDATA_DIR=\\\"$$PWD/\\\" HEADERS += \ $$QT.multimediakit.sources/../plugins/m3u/qm3uhandler.h -message($$HEADERS) SOURCES += \ tst_qmediaplaylist.cpp \ $$QT.multimediakit.sources/../plugins/m3u/qm3uhandler.cpp diff --git a/tests/auto/qmediaplaylist/tst_qmediaplaylist.cpp b/tests/auto/qmediaplaylist/tst_qmediaplaylist.cpp index 996275895..e2002435f 100644 --- a/tests/auto/qmediaplaylist/tst_qmediaplaylist.cpp +++ b/tests/auto/qmediaplaylist/tst_qmediaplaylist.cpp @@ -44,6 +44,7 @@ #include "qmediaservice.h" #include "qmediaplaylist.h" #include "qmediaplaylistcontrol.h" +#include "qmediaplaylistsourcecontrol.h" #include "qmediaplaylistnavigator.h" #include <private/qmediapluginloader_p.h> @@ -51,91 +52,16 @@ //TESTED_COMPONENT=src/multimedia +#include "mockplaylistservice.h" +#include "mockmediaplaylistcontrol.h" +#include "mockmediaplaylistsourcecontrol.h" +#include "mockreadonlyplaylistprovider.h" + #ifndef TESTDATA_DIR #define TESTDATA_DIR "./" #endif QT_USE_NAMESPACE -class MockReadOnlyPlaylistProvider : public QMediaPlaylistProvider -{ - Q_OBJECT -public: - MockReadOnlyPlaylistProvider(QObject *parent) - :QMediaPlaylistProvider(parent) - { - m_items.append(QMediaContent(QUrl(QLatin1String("file:///1")))); - m_items.append(QMediaContent(QUrl(QLatin1String("file:///2")))); - m_items.append(QMediaContent(QUrl(QLatin1String("file:///3")))); - } - - int mediaCount() const { return m_items.size(); } - QMediaContent media(int index) const - { - return index >=0 && index < mediaCount() ? m_items.at(index) : QMediaContent(); - } - -private: - QList<QMediaContent> m_items; -}; - -class MockPlaylistControl : public QMediaPlaylistControl -{ - Q_OBJECT -public: - MockPlaylistControl(QObject *parent) : QMediaPlaylistControl(parent) - { - m_navigator = new QMediaPlaylistNavigator(new MockReadOnlyPlaylistProvider(this), this); - } - - ~MockPlaylistControl() - { - } - - QMediaPlaylistProvider* playlistProvider() const { return m_navigator->playlist(); } - bool setPlaylistProvider(QMediaPlaylistProvider *playlist) { m_navigator->setPlaylist(playlist); return true; } - - int currentIndex() const { return m_navigator->currentIndex(); } - void setCurrentIndex(int position) { m_navigator->jump(position); } - int nextIndex(int steps) const { return m_navigator->nextIndex(steps); } - int previousIndex(int steps) const { return m_navigator->previousIndex(steps); } - - void next() { m_navigator->next(); } - void previous() { m_navigator->previous(); } - - QMediaPlaylist::PlaybackMode playbackMode() const { return m_navigator->playbackMode(); } - void setPlaybackMode(QMediaPlaylist::PlaybackMode mode) { m_navigator->setPlaybackMode(mode); } - -private: - QMediaPlaylistNavigator *m_navigator; -}; - -class MockPlaylistService : public QMediaService -{ - Q_OBJECT - -public: - MockPlaylistService():QMediaService(0) - { - mockControl = new MockPlaylistControl(this); - } - - ~MockPlaylistService() - { - } - - QMediaControl* requestControl(const char *iid) - { - if (qstrcmp(iid, QMediaPlaylistControl_iid) == 0) - return mockControl; - return 0; - } - - void releaseControl(QMediaControl *) - { - } - - MockPlaylistControl *mockControl; -}; class MockReadOnlyPlaylistObject : public QMediaObject { @@ -147,7 +73,6 @@ public: } }; - class tst_QMediaPlaylist : public QObject { Q_OBJECT @@ -171,6 +96,19 @@ private slots: void readOnlyPlaylist(); void setMediaObject(); + void testCurrentIndexChanged_signal(); + void testCurrentMediaChanged_signal(); + void testLoaded_signal(); + void testMediaChanged_signal(); + void testPlaybackModeChanged_signal(); + void testEnums(); + + void mediaPlayListProvider(); + // TC for Abstract control classes + void mediaPlayListControl(); + void mediaPlayListSourceControl(); + + private: QMediaContent content1; QMediaContent content2; @@ -183,6 +121,7 @@ void tst_QMediaPlaylist::init() void tst_QMediaPlaylist::initTestCase() { + qRegisterMetaType<QMediaContent>(); content1 = QMediaContent(QUrl(QLatin1String("file:///1"))); content2 = QMediaContent(QUrl(QLatin1String("file:///2"))); content3 = QMediaContent(QUrl(QLatin1String("file:///3"))); @@ -420,7 +359,7 @@ void tst_QMediaPlaylist::saveAndLoad() bool res = playlist.save(&buffer, "unsupported_format"); QVERIFY(!res); - QVERIFY(playlist.error() != QMediaPlaylist::NoError); + QVERIFY(playlist.error() == QMediaPlaylist::FormatNotSupportedError); QVERIFY(!playlist.errorString().isEmpty()); QSignalSpy errorSignal(&playlist, SIGNAL(loadFailed())); @@ -437,7 +376,7 @@ void tst_QMediaPlaylist::saveAndLoad() errorSignal.clear(); playlist.load(QUrl(QLatin1String("tmp.unsupported_format")), "unsupported_format"); QCOMPARE(errorSignal.size(), 1); - QVERIFY(playlist.error() != QMediaPlaylist::NoError); + QVERIFY(playlist.error() == QMediaPlaylist::FormatNotSupportedError); QVERIFY(!playlist.errorString().isEmpty()); res = playlist.save(&buffer, "m3u"); @@ -509,6 +448,7 @@ void tst_QMediaPlaylist::playbackMode_data() QTest::newRow("ItemOnce, 1") << QMediaPlaylist::CurrentItemOnce << -1 << 1 << -1; QTest::newRow("ItemInLoop, 1") << QMediaPlaylist::CurrentItemInLoop << 1 << 1 << 1; + // Bit difficult to test random this way } void tst_QMediaPlaylist::playbackMode() @@ -653,6 +593,191 @@ void tst_QMediaPlaylist::setMediaObject() QVERIFY(playlist.isReadOnly()); } +void tst_QMediaPlaylist::testCurrentIndexChanged_signal() +{ + //create an instance of QMediaPlaylist class. + QMediaPlaylist playlist; + playlist.addMedia(content1); //set the media to playlist + playlist.addMedia(content2); //set the media to playlist + + QSignalSpy spy(&playlist, SIGNAL(currentIndexChanged(int))); + QVERIFY(spy.size()== 0); + QCOMPARE(playlist.currentIndex(), -1); + + //set the current index for playlist. + playlist.setCurrentIndex(0); + QVERIFY(spy.size()== 1); //verify the signal emission. + QCOMPARE(playlist.currentIndex(), 0); //verify the current index of playlist + + //set the current index for playlist. + playlist.setCurrentIndex(1); + QVERIFY(spy.size()== 2); //verify the signal emission. + QCOMPARE(playlist.currentIndex(), 1); //verify the current index of playlist +} + +void tst_QMediaPlaylist::testCurrentMediaChanged_signal() +{ + //create an instance of QMediaPlaylist class. + QMediaPlaylist playlist; + playlist.addMedia(content1); //set the media to playlist + playlist.addMedia(content2); //set the media to playlist + + QSignalSpy spy(&playlist, SIGNAL(currentMediaChanged(QMediaContent))); + QVERIFY(spy.size()== 0); + QCOMPARE(playlist.currentIndex(), -1); + QCOMPARE(playlist.currentMedia(), QMediaContent()); + + //set the current index for playlist. + playlist.setCurrentIndex(0); + QVERIFY(spy.size()== 1); //verify the signal emission. + QCOMPARE(playlist.currentIndex(), 0); //verify the current index of playlist + QCOMPARE(playlist.currentMedia(), content1); //verify the current media of playlist + + //set the current index for playlist. + playlist.setCurrentIndex(1); + QVERIFY(spy.size()== 2); //verify the signal emission. + QCOMPARE(playlist.currentIndex(), 1); //verify the current index of playlist + QCOMPARE(playlist.currentMedia(), content2); //verify the current media of playlist +} + +void tst_QMediaPlaylist::testLoaded_signal() +{ + //create an instance of QMediaPlaylist class. + QMediaPlaylist playlist; + playlist.addMedia(content1); //set the media to playlist + playlist.addMedia(content2); //set the media to playlist + playlist.addMedia(content3); //set the media to playlist + + QSignalSpy spy(&playlist, SIGNAL(loaded())); + QVERIFY(spy.size()== 0); + + QBuffer buffer; + buffer.open(QBuffer::ReadWrite); + + //load the playlist + playlist.load(&buffer,"m3u"); + QVERIFY(spy.size()== 1); //verify the signal emission. +} + +void tst_QMediaPlaylist::testMediaChanged_signal() +{ + //create an instance of QMediaPlaylist class. + QMediaPlaylist playlist; + + QSignalSpy spy(&playlist, SIGNAL(mediaChanged(int,int))); + + // Add media to playlist + playlist.addMedia(content1); //set the media to playlist + playlist.addMedia(content2); //set the media to playlist + playlist.addMedia(content3); //set the media to playlist + + // Adds/inserts do not cause change signals + QVERIFY(spy.size() == 0); + + // Now change the list + playlist.shuffle(); + + QVERIFY(spy.size() == 1); + spy.clear(); + + //create media. + QMediaContent content4(QUrl(QLatin1String("file:///4"))); + QMediaContent content5(QUrl(QLatin1String("file:///5"))); + + //insert media to playlist + playlist.insertMedia(1, content4); + playlist.insertMedia(2, content5); + // Adds/inserts do not cause change signals + QVERIFY(spy.size() == 0); + + // And again + playlist.shuffle(); + + QVERIFY(spy.size() == 1); +} + +void tst_QMediaPlaylist::testPlaybackModeChanged_signal() +{ + //create an instance of QMediaPlaylist class. + QMediaPlaylist playlist; + playlist.addMedia(content1); //set the media to playlist + playlist.addMedia(content2); //set the media to playlist + playlist.addMedia(content3); //set the media to playlist + + QSignalSpy spy(&playlist, SIGNAL(playbackModeChanged(QMediaPlaylist::PlaybackMode))); + QVERIFY(playlist.playbackMode()== QMediaPlaylist::Sequential); + QVERIFY(spy.size() == 0); + + // Set playback mode to the playlist + playlist.setPlaybackMode(QMediaPlaylist::CurrentItemOnce); + QVERIFY(playlist.playbackMode()== QMediaPlaylist::CurrentItemOnce); + QVERIFY(spy.size() == 1); + + // Set playback mode to the playlist + playlist.setPlaybackMode(QMediaPlaylist::CurrentItemInLoop); + QVERIFY(playlist.playbackMode()== QMediaPlaylist::CurrentItemInLoop); + QVERIFY(spy.size() == 2); + + // Set playback mode to the playlist + playlist.setPlaybackMode(QMediaPlaylist::Sequential); + QVERIFY(playlist.playbackMode()== QMediaPlaylist::Sequential); + QVERIFY(spy.size() == 3); + + // Set playback mode to the playlist + playlist.setPlaybackMode(QMediaPlaylist::Loop); + QVERIFY(playlist.playbackMode()== QMediaPlaylist::Loop); + QVERIFY(spy.size() == 4); + + // Set playback mode to the playlist + playlist.setPlaybackMode(QMediaPlaylist::Random); + QVERIFY(playlist.playbackMode()== QMediaPlaylist::Random); + QVERIFY(spy.size() == 5); +} + +void tst_QMediaPlaylist::testEnums() +{ + //create an instance of QMediaPlaylist class. + QMediaPlaylist playlist; + playlist.addMedia(content1); //set the media to playlist + playlist.addMedia(content2); //set the media to playlist + playlist.addMedia(content3); //set the media to playlist + QCOMPARE(playlist.error(), QMediaPlaylist::NoError); + + QBuffer buffer; + buffer.open(QBuffer::ReadWrite); + + // checking for QMediaPlaylist::FormatNotSupportedError enum + QVERIFY(!playlist.save(&buffer, "unsupported_format")); + QVERIFY(playlist.error() == QMediaPlaylist::FormatNotSupportedError); + + playlist.load(&buffer,"unsupported_format"); + QVERIFY(playlist.error() == QMediaPlaylist::FormatNotSupportedError); +} + +// MaemoAPI-1849:test QMediaPlayListControl constructor +void tst_QMediaPlaylist::mediaPlayListControl() +{ + // To check changes in abstract classe's pure virtual functions + QObject parent; + MockMediaPlaylistControl plylistctrl(&parent); +} + +// MaemoAPI-1850:test QMediaPlayListSourceControl constructor +void tst_QMediaPlaylist::mediaPlayListSourceControl() +{ + // To check changes in abstract classe's pure virtual functions + QObject parent; + MockPlaylistSourceControl plylistsrcctrl(&parent); +} + +// MaemoAPI-1852:test constructor +void tst_QMediaPlaylist::mediaPlayListProvider() +{ + // srcs of QMediaPlaylistProvider is incomplete + QObject parent; + MockReadOnlyPlaylistProvider provider(&parent); +} + QTEST_MAIN(tst_QMediaPlaylist) #include "tst_qmediaplaylist.moc" diff --git a/tests/auto/qmediaplaylistnavigator/tst_qmediaplaylistnavigator.cpp b/tests/auto/qmediaplaylistnavigator/tst_qmediaplaylistnavigator.cpp index ce7e8cc40..a88884735 100644 --- a/tests/auto/qmediaplaylistnavigator/tst_qmediaplaylistnavigator.cpp +++ b/tests/auto/qmediaplaylistnavigator/tst_qmediaplaylistnavigator.cpp @@ -62,10 +62,20 @@ private slots: void currentItemOnce(); void currentItemInLoop(); void randomPlayback(); + + void testItemAt(); + void testNextIndex(); + void testPreviousIndex(); + void testCurrentIndexChangedSignal(); + void testPlaybackModeChangedSignal(); + void testSurroundingItemsChangedSignal(); + void testActivatedSignal(); }; void tst_QMediaPlaylistNavigator::init() { + qRegisterMetaType<QMediaPlaylist::PlaybackMode>("QMediaPlaylist::PlaybackMode"); + qRegisterMetaType<QMediaContent>("QMediaContent"); } void tst_QMediaPlaylistNavigator::cleanup() @@ -314,5 +324,202 @@ void tst_QMediaPlaylistNavigator::randomPlayback() } +void tst_QMediaPlaylistNavigator::testItemAt() +{ + QLocalMediaPlaylistProvider playlist; + QMediaPlaylistNavigator navigator(&playlist); + navigator.setPlaybackMode(QMediaPlaylist::Random); + QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Random); + QCOMPARE(navigator.currentIndex(), -1); + + //Adding the media to the playlist + QMediaContent content = QMediaContent(QUrl(QLatin1String("file:///1"))); + playlist.addMedia(content); + + //Currently it is not pointing to any index , Returns Null mediacontent + QCOMPARE(navigator.currentIndex(), -1); + QCOMPARE(navigator.itemAt(navigator.currentIndex()),QMediaContent()); + navigator.next(); + + //Points to the added media + int pos1 = navigator.currentIndex(); + QCOMPARE(content,navigator.itemAt(pos1)); +} + +void tst_QMediaPlaylistNavigator::testNextIndex() +{ + QLocalMediaPlaylistProvider playlist; + QMediaPlaylistNavigator navigator(&playlist); + navigator.setPlaybackMode(QMediaPlaylist::Random); + QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Random); + QCOMPARE(navigator.currentIndex(), -1); + + //Adding the media to the playlist + playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///1")))); + playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///2")))); + playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///3")))); + + playlist.shuffle(); + + //Currently it is not pointing to any index + QCOMPARE(navigator.currentIndex(), -1); + navigator.next(); + int pos1 = navigator.currentIndex(); + //Pointing to the next index + navigator.next(); + int pos2 = navigator.currentIndex(); + navigator.next(); + int pos3 = navigator.currentIndex(); + + //Pointing to the previous index + navigator.previous(); + QCOMPARE(navigator.nextIndex(1), pos3); + navigator.previous(); + QCOMPARE(navigator.nextIndex(1), pos2); + QCOMPARE(navigator.nextIndex(2), pos3); + navigator.previous(); + QCOMPARE(navigator.nextIndex(1), pos1); +} + +void tst_QMediaPlaylistNavigator::testPreviousIndex() +{ + QLocalMediaPlaylistProvider playlist; + QMediaPlaylistNavigator navigator(&playlist); + navigator.setPlaybackMode(QMediaPlaylist::Random); + QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Random); + QCOMPARE(navigator.currentIndex(), -1); + + //Adding the media to the playlist + playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///1")))); + playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///2")))); + playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///3")))); + playlist.shuffle(); + + //Currently it is not pointing to any index + QCOMPARE(navigator.currentIndex(), -1); + + //pointing to next index + navigator.next(); + int pos1 = navigator.currentIndex(); + navigator.next(); + int pos2 = navigator.currentIndex(); + navigator.next(); + int pos3 = navigator.currentIndex(); + QCOMPARE(navigator.previousIndex(1), pos2); + QCOMPARE(navigator.previousIndex(2), pos1); + navigator.next(); + QCOMPARE(navigator.previousIndex(1), pos3); +} + +void tst_QMediaPlaylistNavigator::testCurrentIndexChangedSignal() +{ + QLocalMediaPlaylistProvider playlist; + QMediaPlaylistNavigator navigator(&playlist); + navigator.setPlaybackMode(QMediaPlaylist::Random); + QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Random); + QCOMPARE(navigator.currentIndex(), -1); + + //Creating a QSignalSpy object for currentIndexChanged() signal + QSignalSpy spy(&navigator,SIGNAL(currentIndexChanged(int))); + QVERIFY(spy.count() == 0); + + //Adding the media to the playlist + playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///1")))); + playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///2")))); + playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///3")))); + + //Currently it is not pointing to any index + QCOMPARE(navigator.currentIndex(), -1); + navigator.next(); + QVERIFY(spy.count() == 1); + int pos1 = navigator.currentIndex(); + //Pointing to the next index + navigator.next(); + QVERIFY(navigator.previousIndex(1) == pos1); + QVERIFY(spy.count() == 2); +} + +void tst_QMediaPlaylistNavigator::testPlaybackModeChangedSignal() +{ + QLocalMediaPlaylistProvider playlist; + QMediaPlaylistNavigator navigator(&playlist); + navigator.setPlaybackMode(QMediaPlaylist::Random); + QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Random); + QCOMPARE(navigator.currentIndex(), -1); + + //Creating a QSignalSpy object for currentIndexChanged() signal + QSignalSpy spy(&navigator,SIGNAL(playbackModeChanged(QMediaPlaylist::PlaybackMode))); + QVERIFY(spy.count() == 0); + + //Adding the media to the playlist + playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///1")))); + + //set the play back mode to sequential + navigator.setPlaybackMode(QMediaPlaylist::Sequential); + QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Sequential); + QVERIFY(spy.count() == 1); + + //set the play back mode to loop + navigator.setPlaybackMode(QMediaPlaylist::Loop); + QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Loop); + QVERIFY(spy.count() == 2); +} + +void tst_QMediaPlaylistNavigator::testSurroundingItemsChangedSignal() +{ + QLocalMediaPlaylistProvider playlist; + QMediaPlaylistNavigator navigator(&playlist); + navigator.setPlaybackMode(QMediaPlaylist::Random); + QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Random); + QCOMPARE(navigator.currentIndex(), -1); + + //Creating a QSignalSpy object for surroundingItemsChanged()signal + QSignalSpy spy(&navigator,SIGNAL(surroundingItemsChanged())); + QVERIFY(spy.count() == 0); + + //Adding the media to the playlist + playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///1")))); + QVERIFY(spy.count() == 1); + + //set the play back mode to sequential + navigator.setPlaybackMode(QMediaPlaylist::Sequential); + QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Sequential); + QVERIFY(spy.count() == 2); + + //Point to the next index + navigator.next(); + QVERIFY(spy.count() == 3); +} + +void tst_QMediaPlaylistNavigator::testActivatedSignal() +{ + QLocalMediaPlaylistProvider playlist; + QMediaPlaylistNavigator navigator(&playlist); + navigator.setPlaybackMode(QMediaPlaylist::Random); + QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Random); + QCOMPARE(navigator.currentIndex(), -1); + + //Creating a QSignalSpy object for surroundingItemsChanged()signal + QSignalSpy spy(&navigator,SIGNAL(activated(QMediaContent))); + QVERIFY(spy.count() == 0); + + //Adding the media to the playlist + playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///1")))); + playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///2")))); + playlist.shuffle(); + + //Point to the next index + navigator.next(); + QVERIFY(spy.count() == 1); + + //Jump to 0th item + navigator.jump(0); + QVERIFY(spy.count() == 2); + + //move to previous item + navigator.previous(); + QVERIFY(spy.count() == 3); +} + QTEST_MAIN(tst_QMediaPlaylistNavigator) #include "tst_qmediaplaylistnavigator.moc" diff --git a/tests/auto/qmediarecorder/qmediarecorder.pro b/tests/auto/qmediarecorder/qmediarecorder.pro index 283231fcd..c4395dcc0 100644 --- a/tests/auto/qmediarecorder/qmediarecorder.pro +++ b/tests/auto/qmediarecorder/qmediarecorder.pro @@ -5,6 +5,9 @@ QT += multimediakit-private # TARGET = tst_qmediarecorder # CONFIG += testcase +include (../qmultimedia_common/mock.pri) +include (../qmultimedia_common/mockrecorder.pri) + HEADERS += tst_qmediarecorder.h SOURCES += main.cpp tst_qmediarecorder.cpp diff --git a/tests/auto/qmediarecorder/tst_qmediarecorder.cpp b/tests/auto/qmediarecorder/tst_qmediarecorder.cpp index 3b2f4d1f6..6805a2680 100644 --- a/tests/auto/qmediarecorder/tst_qmediarecorder.cpp +++ b/tests/auto/qmediarecorder/tst_qmediarecorder.cpp @@ -50,9 +50,9 @@ void tst_QMediaRecorder::initTestCase() qRegisterMetaType<QMediaRecorder::State>("QMediaRecorder::State"); qRegisterMetaType<QMediaRecorder::Error>("QMediaRecorder::Error"); - mock = new MockProvider(this); - service = new MockService(this, mock); - object = new MockObject(this, service); + mock = new MockMediaRecorderControl(this); + service = new MockMediaRecorderService(this, mock); + object = new MockMediaObject(this, service); capture = new QMediaRecorder(object); audio = qobject_cast<QAudioEndpointSelector*>(service->requestControl(QAudioEndpointSelector_iid)); @@ -72,7 +72,7 @@ void tst_QMediaRecorder::testNullService() { const QString id(QLatin1String("application/x-format")); - MockObject object(0, 0); + MockMediaObject object(0, 0); QMediaRecorder recorder(&object); QCOMPARE(recorder.outputLocation(), QUrl()); @@ -104,9 +104,9 @@ void tst_QMediaRecorder::testNullControls() { const QString id(QLatin1String("application/x-format")); - MockService service(0, 0); + MockMediaRecorderService service(0, 0); service.hasControls = false; - MockObject object(0, &service); + MockMediaObject object(0, &service); QMediaRecorder recorder(&object); QCOMPARE(recorder.outputLocation(), QUrl()); @@ -256,7 +256,9 @@ void tst_QMediaRecorder::testAudioEncodeControl() QVERIFY(encode->encodingOption("audio/mpeg","bitrate").isNull()); encode->setEncodingOption("audio/mpeg", "bitrate", QString("vbr")); QCOMPARE(encode->encodingOption("audio/mpeg","bitrate").toString(), QString("vbr")); - QCOMPARE(capture->supportedAudioSampleRates(), QList<int>() << 44100); + QList<int> rates; + rates << 8000 << 11025 << 22050 << 44100; + QCOMPARE(capture->supportedAudioSampleRates(), rates); } void tst_QMediaRecorder::testMediaFormatsControl() @@ -297,7 +299,7 @@ void tst_QMediaRecorder::testEncodingSettings() QAudioEncoderSettings audioSettings = capture->audioSettings(); QCOMPARE(audioSettings.codec(), QString("audio/pcm")); QCOMPARE(audioSettings.bitRate(), 128*1024); - QCOMPARE(audioSettings.sampleRate(), -1); + QCOMPARE(audioSettings.sampleRate(), 8000); QCOMPARE(audioSettings.quality(), QtMultimediaKit::NormalQuality); QCOMPARE(audioSettings.channelCount(), -1); @@ -595,10 +597,10 @@ void tst_QMediaRecorder::nullMetaDataControl() const QString titleKey(QLatin1String("Title")); const QString title(QLatin1String("Host of Seraphim")); - MockProvider recorderControl(0); - MockService service(0, &recorderControl); + MockMediaRecorderControl recorderControl(0); + MockMediaRecorderService service(0, &recorderControl); service.hasControls = false; - MockObject object(0, &service); + MockMediaObject object(0, &service); QMediaRecorder recorder(&object); @@ -619,10 +621,10 @@ void tst_QMediaRecorder::nullMetaDataControl() void tst_QMediaRecorder::isMetaDataAvailable() { - MockProvider recorderControl(0); - MockService service(0, &recorderControl); + MockMediaRecorderControl recorderControl(0); + MockMediaRecorderService service(0, &recorderControl); service.mockMetaDataControl->setMetaDataAvailable(false); - MockObject object(0, &service); + MockMediaObject object(0, &service); QMediaRecorder recorder(&object); QCOMPARE(recorder.isMetaDataAvailable(), false); @@ -643,11 +645,11 @@ void tst_QMediaRecorder::isMetaDataAvailable() void tst_QMediaRecorder::isWritable() { - MockProvider recorderControl(0); - MockService service(0, &recorderControl); + MockMediaRecorderControl recorderControl(0); + MockMediaRecorderService service(0, &recorderControl); service.mockMetaDataControl->setWritable(false); - MockObject object(0, &service); + MockMediaObject object(0, &service); QMediaRecorder recorder(&object); @@ -670,9 +672,9 @@ void tst_QMediaRecorder::isWritable() void tst_QMediaRecorder::metaDataChanged() { - MockProvider recorderControl(0); - MockService service(0, &recorderControl); - MockObject object(0, &service); + MockMediaRecorderControl recorderControl(0); + MockMediaRecorderService service(0, &recorderControl); + MockMediaObject object(0, &service); QMediaRecorder recorder(&object); @@ -703,11 +705,11 @@ void tst_QMediaRecorder::metaData() QFETCH(QString, title); QFETCH(QString, genre); - MockProvider recorderControl(0); - MockService service(0, &recorderControl); + MockMediaRecorderControl recorderControl(0); + MockMediaRecorderService service(0, &recorderControl); service.mockMetaDataControl->populateMetaData(); - MockObject object(0, &service); + MockMediaObject object(0, &service); QMediaRecorder recorder(&object); QVERIFY(object.availableMetaData().isEmpty()); @@ -738,11 +740,11 @@ void tst_QMediaRecorder::setMetaData() { QFETCH(QString, title); - MockProvider recorderControl(0); - MockService service(0, &recorderControl); + MockMediaRecorderControl recorderControl(0); + MockMediaRecorderService service(0, &recorderControl); service.mockMetaDataControl->populateMetaData(); - MockObject object(0, &service); + MockMediaObject object(0, &service); QMediaRecorder recorder(&object); @@ -757,9 +759,9 @@ void tst_QMediaRecorder::extendedMetaData() QFETCH(QString, title); QFETCH(QString, genre); - MockProvider recorderControl(0); - MockService service(0, &recorderControl); - MockObject object(0, &service); + MockMediaRecorderControl recorderControl(0); + MockMediaRecorderService service(0, &recorderControl); + MockMediaObject object(0, &service); QMediaRecorder recorder(&object); QVERIFY(recorder.availableExtendedMetaData().isEmpty()); @@ -780,11 +782,11 @@ void tst_QMediaRecorder::extendedMetaData() void tst_QMediaRecorder::setExtendedMetaData() { - MockProvider recorderControl(0); - MockService service(0, &recorderControl); + MockMediaRecorderControl recorderControl(0); + MockMediaRecorderService service(0, &recorderControl); service.mockMetaDataControl->populateMetaData(); - MockObject object(0, &service); + MockMediaObject object(0, &service); QMediaRecorder recorder(&object); @@ -794,3 +796,471 @@ void tst_QMediaRecorder::setExtendedMetaData() QCOMPARE(recorder.extendedMetaData(QLatin1String("Title")).toString(), title); QCOMPARE(service.mockMetaDataControl->m_extendedData.value(QLatin1String("Title")).toString(), title); } + + +void tst_QMediaRecorder::testAudioSettingsCopyConstructor() +{ + /* create an object for AudioEncodersettings */ + QAudioEncoderSettings audiosettings; + QVERIFY(audiosettings.isNull()); + + /* setting the desired properties for the AudioEncoder */ + audiosettings.setBitRate(128*1000); + audiosettings.setChannelCount(4); + audiosettings.setCodec("audio/pcm"); + audiosettings.setEncodingMode(QtMultimediaKit::ConstantBitRateEncoding); + audiosettings.setQuality(QtMultimediaKit::LowQuality); + audiosettings.setSampleRate(44100); + + /* Copy constructor */ + QAudioEncoderSettings other(audiosettings); + QVERIFY(!(other.isNull())); + + /* Verifying whether data is copied properly or not */ + QVERIFY(other.bitRate() == audiosettings.bitRate()); + QVERIFY(other.sampleRate() == audiosettings.sampleRate()); + QVERIFY(other.channelCount() == audiosettings.channelCount()); + QCOMPARE(other.codec(), audiosettings.codec()); + QVERIFY(other.encodingMode() == audiosettings.encodingMode()); + QVERIFY(other.quality() == audiosettings.quality()); +} + +void tst_QMediaRecorder::testAudioSettingsOperatorNotEqual() +{ + /* create an object for AudioEncodersettings */ + QAudioEncoderSettings audiosettings1; + QVERIFY(audiosettings1.isNull()); + + QAudioEncoderSettings audiosettings2; + QVERIFY(audiosettings2.isNull()); + + /* setting the desired properties to for the AudioEncoder */ + audiosettings1.setBitRate(128*1000); + audiosettings1.setChannelCount(4); + audiosettings1.setCodec("audio/pcm"); + audiosettings1.setEncodingMode(QtMultimediaKit::ConstantBitRateEncoding); + audiosettings1.setQuality(QtMultimediaKit::LowQuality); + audiosettings1.setSampleRate(44100); + + /* setting the desired properties for the AudioEncoder */ + audiosettings2.setBitRate(128*1000); + audiosettings2.setChannelCount(4); + audiosettings2.setCodec("audio/pcm"); + audiosettings2.setEncodingMode(QtMultimediaKit::ConstantBitRateEncoding); + audiosettings2.setQuality(QtMultimediaKit::LowQuality); + audiosettings2.setSampleRate(44100); + + /* verify the both are equal or not */ + QVERIFY(!(audiosettings1 != audiosettings2)); + + /* Modify the settings value for one object */ + audiosettings2.setBitRate(64*1000); + audiosettings2.setEncodingMode(QtMultimediaKit::ConstantQualityEncoding); + + /* verify the not equal opertor */ + QVERIFY(audiosettings1 != audiosettings2); + + QVERIFY(audiosettings2.bitRate() != audiosettings1.bitRate()); + QVERIFY(audiosettings2.encodingMode() != audiosettings1.encodingMode()); +} + +void tst_QMediaRecorder::testAudioSettingsOperatorEqual() +{ + /* create an object for AudioEncodersettings */ + QAudioEncoderSettings audiosettings1; + QVERIFY(audiosettings1.isNull()); + + /* setting the desired properties to for the AudioEncoder */ + audiosettings1.setBitRate(128*1000); + audiosettings1.setChannelCount(4); + audiosettings1.setCodec("audio/pcm"); + audiosettings1.setEncodingMode(QtMultimediaKit::ConstantBitRateEncoding); + audiosettings1.setQuality(QtMultimediaKit::LowQuality); + audiosettings1.setSampleRate(44100); + + QAudioEncoderSettings audiosettings2; + QVERIFY(audiosettings2.isNull()); + + /* setting the desired properties for the AudioEncoder */ + audiosettings2.setBitRate(128*1000); + audiosettings2.setChannelCount(4); + audiosettings2.setCodec("audio/pcm"); + audiosettings2.setEncodingMode(QtMultimediaKit::ConstantBitRateEncoding); + audiosettings2.setQuality(QtMultimediaKit::LowQuality); + audiosettings2.setSampleRate(44100); + + /* verify both the values are same or not */ + QVERIFY(audiosettings1 == audiosettings2); + audiosettings2.setChannelCount(2); + QVERIFY(audiosettings1 != audiosettings2); +} + +void tst_QMediaRecorder::testAudioSettingsOperatorAssign() +{ + + /* create an object for AudioEncodersettings */ + QAudioEncoderSettings audiosettings1; + QVERIFY(audiosettings1.isNull()); + + /* setting the desired properties for the AudioEncoder */ + audiosettings1.setBitRate(128*1000); + audiosettings1.setChannelCount(4); + audiosettings1.setCodec("audio/pcm"); + audiosettings1.setEncodingMode(QtMultimediaKit::ConstantBitRateEncoding); + audiosettings1.setQuality(QtMultimediaKit::LowQuality); + audiosettings1.setSampleRate(44100); + + QAudioEncoderSettings audiosettings2; + audiosettings2 = audiosettings1; + /* Verifying whether data is copied properly or not */ + QVERIFY(audiosettings2.bitRate() == audiosettings1.bitRate()); + QVERIFY(audiosettings2.sampleRate() == audiosettings1.sampleRate()); + QVERIFY(audiosettings2.channelCount() == audiosettings1.channelCount()); + QCOMPARE(audiosettings2.codec(), audiosettings1.codec()); + QVERIFY(audiosettings2.encodingMode() == audiosettings1.encodingMode()); + QVERIFY(audiosettings2.quality() == audiosettings1.quality()); +} + +void tst_QMediaRecorder::testAudioSettingsDestructor() +{ + /* Creating null object for the audioencodersettings */ + QAudioEncoderSettings * audiosettings = new QAudioEncoderSettings; + + /* Verifying the object is null or not */ + QVERIFY(audiosettings->isNull()); + /* delete the allocated memory */ + delete audiosettings; +} + +/* availabilityError() API test. */ +void tst_QMediaRecorder::testAvailabilityError() +{ + MockMediaRecorderService service(0, 0); + MockMediaObject object(0, &service); + QMediaRecorder recorder(&object); + QCOMPARE(recorder.availabilityError(), QtMultimediaKit::ServiceMissingError); + + MockMediaRecorderControl recorderControl(0); + MockMediaRecorderService service1(0, &recorderControl); + service1.mockMetaDataControl->populateMetaData(); + MockMediaObject object1(0, &service1); + QMediaRecorder recorder1(&object1); + QCOMPARE(recorder1.availabilityError(), QtMultimediaKit::NoError); +} + +/* isAvailable() API test. */ +void tst_QMediaRecorder::testIsAvailable() +{ + MockMediaRecorderService service(0, 0); + MockMediaObject object(0, &service); + QMediaRecorder recorder(&object); + QCOMPARE(recorder.isAvailable(), false); + + MockMediaRecorderControl recorderControl(0); + MockMediaRecorderService service1(0, &recorderControl); + service1.mockMetaDataControl->populateMetaData(); + MockMediaObject object1(0, &service1); + QMediaRecorder recorder1(&object1); + QCOMPARE(recorder1.isAvailable(), true); +} + +/* mediaObject() API test. */ +void tst_QMediaRecorder::testMediaObject() +{ + MockMediaRecorderService service(0, 0); + service.hasControls = false; + MockMediaObject object(0, &service); + QMediaRecorder recorder(&object); + + QMediaObject *medobj = recorder.mediaObject(); + QVERIFY(medobj == NULL); + + QMediaObject *medobj1 = capture->mediaObject(); + QVERIFY(medobj1 != NULL); +} + +/* enum QMediaRecorder::ResourceError property test. */ +void tst_QMediaRecorder::testEnum() +{ + const QString errorString(QLatin1String("resource error")); + + QSignalSpy spy(capture, SIGNAL(error(QMediaRecorder::Error))); + + QCOMPARE(capture->error(), QMediaRecorder::NoError); + QCOMPARE(capture->errorString(), QString()); + + mock->error(QMediaRecorder::ResourceError, errorString); + QCOMPARE(capture->error(), QMediaRecorder::ResourceError); + QCOMPARE(capture->errorString(), errorString); + QCOMPARE(spy.count(), 1); + + QCOMPARE(spy.last()[0].value<QMediaRecorder::Error>(), QMediaRecorder::ResourceError); +} + +/* Test the QVideoEncoderSettings quality API*/ +void tst_QMediaRecorder::testVideoSettingsQuality() +{ + /* Create the instance*/ + QVideoEncoderSettings settings; + QVERIFY(settings.isNull()); + QVERIFY(settings == QVideoEncoderSettings()); + + /* Verify the default value is intialised correctly*/ + QCOMPARE(settings.quality(), QtMultimediaKit::NormalQuality); + + /* Set all types of Quality parameter and Verify if it is set correctly*/ + settings.setQuality(QtMultimediaKit::HighQuality); + QCOMPARE(settings.quality(), QtMultimediaKit::HighQuality); + QVERIFY(!settings.isNull()); + + settings.setQuality(QtMultimediaKit::VeryLowQuality); + QCOMPARE(settings.quality(), QtMultimediaKit::VeryLowQuality); + + settings.setQuality(QtMultimediaKit::LowQuality); + QCOMPARE(settings.quality(), QtMultimediaKit::LowQuality); + + settings.setQuality(QtMultimediaKit::VeryHighQuality); + QCOMPARE(settings.quality(), QtMultimediaKit::VeryHighQuality); +} + +/* Test QVideoEncoderSettings encodingMode */ +void tst_QMediaRecorder::testVideoSettingsEncodingMode() +{ + /* Create the instance*/ + QVideoEncoderSettings settings; + QVERIFY(settings.isNull()); + QVERIFY(settings == QVideoEncoderSettings()); + + /* Verify the default values are initialised correctly*/ + QCOMPARE(settings.encodingMode(), QtMultimediaKit::ConstantQualityEncoding); + QVERIFY(settings.isNull()); + + /* Set each type of encoding mode and Verify if it is set correctly*/ + settings.setEncodingMode(QtMultimediaKit::ConstantBitRateEncoding); + QCOMPARE(settings.encodingMode(),QtMultimediaKit::ConstantBitRateEncoding); + QVERIFY(!settings.isNull()); + + settings.setEncodingMode(QtMultimediaKit::AverageBitRateEncoding); + QCOMPARE(settings.encodingMode(), QtMultimediaKit::AverageBitRateEncoding); + + settings.setEncodingMode(QtMultimediaKit::TwoPassEncoding); + QCOMPARE(settings.encodingMode(), QtMultimediaKit::TwoPassEncoding); +} + +/* Test QVideoEncoderSettings copy constructor */ +void tst_QMediaRecorder::testVideoSettingsCopyConstructor() +{ + /* Create the instance and initialise it*/ + QVideoEncoderSettings settings1; + settings1.setCodec(QLatin1String("codecName")); + settings1.setBitRate(128000); + settings1.setQuality(QtMultimediaKit::HighQuality); + settings1.setEncodingMode(QtMultimediaKit::ConstantBitRateEncoding); + settings1.setFrameRate(30000.0/10001); + settings1.setResolution(QSize(320,240)); + + /* Create another instance with instance1 as argument*/ + QVideoEncoderSettings settings2(settings1); + + /* Verify if all the parameters are copied correctly*/ + QCOMPARE(settings2 != settings1, false); + QCOMPARE(settings2.codec(), QLatin1String("codecName")); + QCOMPARE(settings2.bitRate(), 128000); + QCOMPARE(settings2.encodingMode(), QtMultimediaKit::ConstantBitRateEncoding); + QVERIFY(qFuzzyCompare(settings2.frameRate(), qreal(30000.0/10001))); + QCOMPARE(settings2.resolution(), QSize(320,240)); + QCOMPARE(settings2.quality(), QtMultimediaKit::HighQuality); + + /* Verify both the instances are equal*/ + QCOMPARE(settings2, settings1); + QVERIFY(!settings2.isNull()); +} + +/* Test QVideoEncoderSettings Overloaded Operator assignment*/ +void tst_QMediaRecorder::testVideoSettingsOperatorAssignment() +{ + /* Create two instances.*/ + QVideoEncoderSettings settings1; + QVideoEncoderSettings settings2; + QCOMPARE(settings2, settings1); + QVERIFY(settings2.isNull()); + + /* Initialize all the parameters */ + settings1.setCodec(QLatin1String("codecName")); + settings1.setBitRate(128000); + settings1.setEncodingMode(QtMultimediaKit::ConstantBitRateEncoding); + settings1.setFrameRate(30000.0/10001); + settings1.setResolution(QSize(320,240)); + settings1.setQuality(QtMultimediaKit::HighQuality); + /* Assign one object to other*/ + settings2 = settings1; + + /* Verify all the parameters are copied correctly*/ + QCOMPARE(settings2, settings1); + QCOMPARE(settings2.codec(), QLatin1String("codecName")); + QCOMPARE(settings2.bitRate(), 128000); + QCOMPARE(settings2.encodingMode(), QtMultimediaKit::ConstantBitRateEncoding); + QVERIFY(qFuzzyCompare(settings2.frameRate(), qreal(30000.0/10001))); + QCOMPARE(settings2.resolution(), QSize(320,240)); + QCOMPARE(settings2.quality(), QtMultimediaKit::HighQuality); + QCOMPARE(settings2, settings1); + QVERIFY(!settings2.isNull()); +} + +/* Test QVideoEncoderSettings Overloaded OperatorNotEqual*/ +void tst_QMediaRecorder::testVideoSettingsOperatorNotEqual() +{ + /* Create the instance and set the bit rate and Verify objects with OperatorNotEqual*/ + QVideoEncoderSettings settings1; + settings1.setBitRate(1); + QVideoEncoderSettings settings2; + settings2.setBitRate(1); + /* OperatorNotEqual returns false when both objects are equal*/ + QCOMPARE(settings1 != settings2, false); + settings2.setBitRate(2); + /* OperatorNotEqual returns true when both objects are not equal*/ + QVERIFY(settings1 != settings2); + + /* Verify Resolution with not equal operator*/ + settings1 = QVideoEncoderSettings(); + settings1.setResolution(800,600); + settings2 = QVideoEncoderSettings(); + settings2.setResolution(QSize(800,600)); + /* OperatorNotEqual returns false when both objects are equal*/ + QCOMPARE(settings1 != settings2, false); + settings2.setResolution(QSize(400,300)); + /* OperatorNotEqual returns true when both objects are not equal*/ + QVERIFY(settings1 != settings2); + + /* Verify Codec with not equal operator*/ + settings1 = QVideoEncoderSettings(); + settings1.setCodec("codec1"); + settings2 = QVideoEncoderSettings(); + settings2.setCodec("codec1"); + /* OperatorNotEqual returns false when both objects are equal*/ + QCOMPARE(settings1 != settings2, false); + settings2.setCodec("codec2"); + /* OperatorNotEqual returns true when both objects are not equal*/ + QVERIFY(settings1 != settings2); + + /* Verify EncodingMode with not equal operator*/ + settings1 = QVideoEncoderSettings(); + settings1.setEncodingMode(QtMultimediaKit::ConstantBitRateEncoding); + settings2 = QVideoEncoderSettings(); + settings2.setEncodingMode(QtMultimediaKit::ConstantBitRateEncoding); + /* OperatorNotEqual returns false when both objects are equal*/ + QCOMPARE(settings1 != settings2, false); + settings2.setEncodingMode(QtMultimediaKit::TwoPassEncoding); + /* OperatorNotEqual returns true when both objects are not equal*/ + QVERIFY(settings1 != settings2); + + /* Verify Quality with not equal operator*/ + settings1 = QVideoEncoderSettings(); + settings1.setQuality(QtMultimediaKit::NormalQuality); + settings2 = QVideoEncoderSettings(); + settings2.setQuality(QtMultimediaKit::NormalQuality); + /* OperatorNotEqual returns false when both objects are equal*/ + QCOMPARE(settings1 != settings2, false); + settings2.setQuality(QtMultimediaKit::LowQuality); + /* OperatorNotEqual returns true when both objects are not equal*/ + QVERIFY(settings1 != settings2); + + /* Verify FrameRate with not equal operator*/ + settings1 = QVideoEncoderSettings(); + settings1.setFrameRate(1); + settings2 = QVideoEncoderSettings(); + settings2.setFrameRate(1); + /* OperatorNotEqual returns false when both objects are equal*/ + QCOMPARE(settings1 != settings2, false); + settings2.setFrameRate(2); + /* OperatorNotEqual returns true when both objects are not equal*/ + QVERIFY(settings1 != settings2); +} + +/* Test QVideoEncoderSettings Overloaded comparison operator*/ +void tst_QMediaRecorder::testVideoSettingsOperatorComparison() +{ + /* Create the instance and set the bit rate and Verify objects with comparison operator*/ + QVideoEncoderSettings settings1; + settings1.setBitRate(1); + QVideoEncoderSettings settings2; + settings2.setBitRate(1); + + /* Comparison operator returns true when both objects are equal*/ + QVERIFY(settings1 == settings2); + settings2.setBitRate(2); + /* Comparison operator returns false when both objects are not equal*/ + QCOMPARE(settings1 == settings2, false); + + /* Verify resolution with comparison operator*/ + settings1 = QVideoEncoderSettings(); + settings1.setResolution(800,600); + settings2 = QVideoEncoderSettings(); + settings2.setResolution(QSize(800,600)); + /* Comparison operator returns true when both objects are equal*/ + QVERIFY(settings1 == settings2); + settings2.setResolution(QSize(400,300)); + /* Comparison operator returns false when both objects are not equal*/ + QCOMPARE(settings1 == settings2, false); + + /* Verify Codec with comparison operator*/ + settings1 = QVideoEncoderSettings(); + settings1.setCodec("codec1"); + settings2 = QVideoEncoderSettings(); + settings2.setCodec("codec1"); + /* Comparison operator returns true when both objects are equal*/ + QVERIFY(settings1 == settings2); + settings2.setCodec("codec2"); + /* Comparison operator returns false when both objects are not equal*/ + QCOMPARE(settings1 == settings2, false); + + /* Verify EncodingMode with comparison operator*/ + settings1 = QVideoEncoderSettings(); + settings1.setEncodingMode(QtMultimediaKit::ConstantBitRateEncoding); + settings2 = QVideoEncoderSettings(); + settings2.setEncodingMode(QtMultimediaKit::ConstantBitRateEncoding); + /* Comparison operator returns true when both objects are equal*/ + QVERIFY(settings1 == settings2); + settings2.setEncodingMode(QtMultimediaKit::TwoPassEncoding); + /* Comparison operator returns false when both objects are not equal*/ + QCOMPARE(settings1 == settings2, false); + + /* Verify Quality with comparison operator*/ + settings1 = QVideoEncoderSettings(); + settings1.setQuality(QtMultimediaKit::NormalQuality); + settings2 = QVideoEncoderSettings(); + settings2.setQuality(QtMultimediaKit::NormalQuality); + /* Comparison operator returns true when both objects are equal*/ + QVERIFY(settings1 == settings2); + settings2.setQuality(QtMultimediaKit::LowQuality); + /* Comparison operator returns false when both objects are not equal*/ + QCOMPARE(settings1 == settings2, false); + + /* Verify FrameRate with comparison operator*/ + settings1 = QVideoEncoderSettings(); + settings1.setFrameRate(1); + settings2 = QVideoEncoderSettings(); + settings2.setFrameRate(1); + /* Comparison operator returns true when both objects are equal*/ + QVERIFY(settings1 == settings2); + settings2.setFrameRate(2); + /* Comparison operator returns false when both objects are not equal*/ + QCOMPARE(settings1 == settings2, false); +} + +/* Test the destuctor of the QVideoEncoderSettings*/ +void tst_QMediaRecorder::testVideoSettingsDestructor() +{ + /* Create the instance on heap and verify if object deleted correctly*/ + QVideoEncoderSettings *settings1 = new QVideoEncoderSettings(); + QVERIFY(settings1 != NULL); + QVERIFY(settings1->isNull()); + delete settings1; + + /* Create the instance on heap and initialise it and verify if object deleted correctly.*/ + QVideoEncoderSettings *settings2 = new QVideoEncoderSettings(); + QVERIFY(settings2 != NULL); + settings2->setCodec(QString("codec")); + QVERIFY(!settings2->isNull()); + delete settings2; +} diff --git a/tests/auto/qmediarecorder/tst_qmediarecorder.h b/tests/auto/qmediarecorder/tst_qmediarecorder.h index ad1d27f86..253a750e6 100755 --- a/tests/auto/qmediarecorder/tst_qmediarecorder.h +++ b/tests/auto/qmediarecorder/tst_qmediarecorder.h @@ -56,417 +56,8 @@ #include <qaudioformat.h> -QT_USE_NAMESPACE -class MockMediaContainerControl : public QMediaContainerControl -{ - Q_OBJECT -public: - MockMediaContainerControl(QObject *parent): - QMediaContainerControl(parent) - { - m_supportedContainers.append("wav"); - m_supportedContainers.append("mp3"); - m_supportedContainers.append("mov"); - - m_descriptions.insert("wav", "WAV format"); - m_descriptions.insert("mp3", "MP3 format"); - m_descriptions.insert("mov", "MOV format"); - } - - virtual ~MockMediaContainerControl() {}; - - QStringList supportedContainers() const - { - return m_supportedContainers; - } - - QString containerMimeType() const - { - return m_format; - } - - void setContainerMimeType(const QString &formatMimeType) - { - if (m_supportedContainers.contains(formatMimeType)) - m_format = formatMimeType; - } - - QString containerDescription(const QString &formatMimeType) const - { - return m_descriptions.value(formatMimeType); - } - -private: - QStringList m_supportedContainers; - QMap<QString, QString> m_descriptions; - QString m_format; -}; - -class MockVideoEncodeProvider : public QVideoEncoderControl -{ - Q_OBJECT -public: - MockVideoEncodeProvider(QObject *parent): - QVideoEncoderControl(parent) - { - m_supportedEncodeOptions.insert("video/3gpp", QStringList() << "quantizer" << "me"); - m_supportedEncodeOptions.insert("video/H264", QStringList() << "quantizer" << "me" << "bframes"); - m_videoCodecs << "video/3gpp" << "video/H264"; - m_sizes << QSize(320,240) << QSize(640,480); - m_framerates << 30 << 15 << 1; - } - ~MockVideoEncodeProvider() {} - - QVideoEncoderSettings videoSettings() const { return m_videoSettings; } - void setVideoSettings(const QVideoEncoderSettings &settings) { m_videoSettings = settings; }; - - QList<QSize> supportedResolutions(const QVideoEncoderSettings & = QVideoEncoderSettings(), - bool *continuous = 0) const - { - if (continuous) - *continuous = true; - - return m_sizes; - } - - QList<qreal> supportedFrameRates(const QVideoEncoderSettings & = QVideoEncoderSettings(), - bool *continuous = 0) const - { - if (continuous) - *continuous = false; - - return m_framerates; - } - - QStringList supportedVideoCodecs() const { return m_videoCodecs; } - QString videoCodecDescription(const QString &codecName) const { return codecName; } - - QStringList supportedEncodingOptions(const QString &codec) const - { - return m_supportedEncodeOptions.value(codec); - } - - QVariant encodingOption(const QString &codec, const QString &name) const - { - return m_encodeOptions[codec].value(name); - } - - void setEncodingOption(const QString &codec, const QString &name, const QVariant &value) - { - m_encodeOptions[codec][name] = value; - } - -private: - QVideoEncoderSettings m_videoSettings; - - QMap<QString, QStringList> m_supportedEncodeOptions; - QMap< QString, QMap<QString, QVariant> > m_encodeOptions; - - QStringList m_videoCodecs; - QList<QSize> m_sizes; - QList<qreal> m_framerates; -}; - -class MockAudioEncodeProvider : public QAudioEncoderControl -{ - Q_OBJECT -public: - MockAudioEncodeProvider(QObject *parent): - QAudioEncoderControl(parent) - { - m_codecs << "audio/pcm" << "audio/mpeg"; - m_supportedEncodeOptions.insert("audio/pcm", QStringList()); - m_supportedEncodeOptions.insert("audio/mpeg", QStringList() << "quality" << "bitrate" << "mode" << "vbr"); - m_audioSettings.setCodec("audio/pcm"); - m_audioSettings.setBitRate(128*1024); - } - - ~MockAudioEncodeProvider() {} - - QAudioEncoderSettings audioSettings() const { return m_audioSettings; } - void setAudioSettings(const QAudioEncoderSettings &settings) { m_audioSettings = settings; } - - QList<int> supportedSampleRates(const QAudioEncoderSettings & = QAudioEncoderSettings(), bool *continuous = 0) const - { - if (continuous) - *continuous = false; - - return QList<int>() << 44100; - } - - QStringList supportedAudioCodecs() const - { - return m_codecs; - } - - QString codecDescription(const QString &codecName) const - { - if (codecName == "audio/pcm") - return QString("Pulse Code Modulation"); - - if (codecName == "audio/mpeg") - return QString("MP3 audio format"); - - return QString(); - } - - - QStringList supportedEncodingOptions(const QString &codec) const - { - return m_supportedEncodeOptions.value(codec); - } - - QVariant encodingOption(const QString &codec, const QString &name) const - { - return m_encodeOptions[codec].value(name); - } - - void setEncodingOption(const QString &codec, const QString &name, const QVariant &value) - { - m_encodeOptions[codec][name] = value; - } - -private: - QAudioEncoderSettings m_audioSettings; - - QStringList m_codecs; - QStringList m_codecsDesc; - - QMap<QString, QStringList> m_supportedEncodeOptions; - QMap< QString, QMap<QString, QVariant> > m_encodeOptions; - -}; - -class MockAudioEndpointSelectorProvider : public QAudioEndpointSelector -{ - Q_OBJECT -public: - MockAudioEndpointSelectorProvider(QObject *parent): - QAudioEndpointSelector(parent) - { - m_names << "device1" << "device2" << "device3"; - m_descriptions << "dev1 comment" << "dev2 comment" << "dev3 comment"; - emit availableEndpointsChanged(); - } - ~MockAudioEndpointSelectorProvider() {}; - - QList<QString> availableEndpoints() const - { - return m_names; - } - - QString endpointDescription(const QString& name) const - { - QString desc; - - for(int i = 0; i < m_names.count(); i++) { - if (m_names.at(i).compare(name) == 0) { - desc = m_descriptions.at(i); - break; - } - } - return desc; - } - - QString defaultEndpoint() const - { - return m_names.at(0); - } - - QString activeEndpoint() const - { - return m_audioInput; - } - -public Q_SLOTS: - - void setActiveEndpoint(const QString& name) - { - m_audioInput = name; - emit activeEndpointChanged(name); - } - -private: - QString m_audioInput; - QList<QString> m_names; - QList<QString> m_descriptions; -}; - -class MockProvider : public QMediaRecorderControl -{ - Q_OBJECT - -public: - MockProvider(QObject *parent): - QMediaRecorderControl(parent), - m_state(QMediaRecorder::StoppedState), - m_position(0), - m_muted(false) {} - - QUrl outputLocation() const - { - return m_sink; - } - - bool setOutputLocation(const QUrl &sink) - { - m_sink = sink; - return true; - } - - QMediaRecorder::State state() const - { - return m_state; - } - - qint64 duration() const - { - return m_position; - } - - bool isMuted() const - { - return m_muted; - } - - void applySettings() {} - - using QMediaRecorderControl::error; - -public slots: - void record() - { - m_state = QMediaRecorder::RecordingState; - m_position=1; - emit stateChanged(m_state); - emit durationChanged(m_position); - } - - void pause() - { - m_state = QMediaRecorder::PausedState; - emit stateChanged(m_state); - } - - void stop() - { - m_position=0; - m_state = QMediaRecorder::StoppedState; - emit stateChanged(m_state); - } - - void setMuted(bool muted) - { - if (m_muted != muted) - emit mutedChanged(m_muted = muted); - } - -public: - QUrl m_sink; - QMediaRecorder::State m_state; - qint64 m_position; - bool m_muted; -}; - - -class QtTestMetaDataProvider : public QMetaDataWriterControl -{ - Q_OBJECT -public: - QtTestMetaDataProvider(QObject *parent = 0) - : QMetaDataWriterControl(parent) - , m_available(false) - , m_writable(false) - { - } - - bool isMetaDataAvailable() const { return m_available; } - void setMetaDataAvailable(bool available) { - if (m_available != available) - emit metaDataAvailableChanged(m_available = available); - } - QList<QtMultimediaKit::MetaData> availableMetaData() const { return m_data.keys(); } - - bool isWritable() const { return m_writable; } - void setWritable(bool writable) { emit writableChanged(m_writable = writable); } - - QVariant metaData(QtMultimediaKit::MetaData key) const { return m_data.value(key); } - void setMetaData(QtMultimediaKit::MetaData key, const QVariant &value) { - m_data.insert(key, value); } - - QVariant extendedMetaData(const QString &key) const { return m_extendedData.value(key); } - void setExtendedMetaData(const QString &key, const QVariant &value) { - m_extendedData.insert(key, value); } - - QStringList availableExtendedMetaData() const { return m_extendedData.keys(); } - - using QMetaDataWriterControl::metaDataChanged; - - void populateMetaData() - { - m_available = true; - } - - bool m_available; - bool m_writable; - QMap<QtMultimediaKit::MetaData, QVariant> m_data; - QMap<QString, QVariant> m_extendedData; -}; - -class MockService : public QMediaService -{ - Q_OBJECT -public: - MockService(QObject *parent, QMediaControl *control): - QMediaService(parent), - mockControl(control), - hasControls(true) - { - mockAudioEndpointSelector = new MockAudioEndpointSelectorProvider(parent); - mockAudioEncodeControl = new MockAudioEncodeProvider(parent); - mockFormatControl = new MockMediaContainerControl(parent); - mockVideoEncodeControl = new MockVideoEncodeProvider(parent); - mockMetaDataControl = new QtTestMetaDataProvider(parent); - } - - QMediaControl* requestControl(const char *name) - { - if(hasControls && qstrcmp(name,QAudioEncoderControl_iid) == 0) - return mockAudioEncodeControl; - if(hasControls && qstrcmp(name,QAudioEndpointSelector_iid) == 0) - return mockAudioEndpointSelector; - if(hasControls && qstrcmp(name,QMediaRecorderControl_iid) == 0) - return mockControl; - if(hasControls && qstrcmp(name,QMediaContainerControl_iid) == 0) - return mockFormatControl; - if(hasControls && qstrcmp(name,QVideoEncoderControl_iid) == 0) - return mockVideoEncodeControl; - if (hasControls && qstrcmp(name, QMetaDataWriterControl_iid) == 0) - return mockMetaDataControl; - - return 0; - } - - void releaseControl(QMediaControl*) {} - - QMediaControl *mockControl; - QAudioEndpointSelector *mockAudioEndpointSelector; - QAudioEncoderControl *mockAudioEncodeControl; - QMediaContainerControl *mockFormatControl; - QVideoEncoderControl *mockVideoEncodeControl; - QtTestMetaDataProvider *mockMetaDataControl; - bool hasControls; -}; - -class MockObject : public QMediaObject -{ - Q_OBJECT -public: - MockObject(QObject *parent, MockService *service): - QMediaObject(parent, service) - { - } -}; +#include "mockmediarecorderservice.h" +#include "mockmediaobject.h" class tst_QMediaRecorder: public QObject { @@ -504,13 +95,32 @@ private slots: void setExtendedMetaData_data() { extendedMetaData_data(); } void setExtendedMetaData(); + void testAudioSettingsCopyConstructor(); + void testAudioSettingsOperatorNotEqual(); + void testAudioSettingsOperatorEqual(); + void testAudioSettingsOperatorAssign(); + void testAudioSettingsDestructor(); + + void testAvailabilityError(); + void testIsAvailable(); + void testMediaObject(); + void testEnum(); + + void testVideoSettingsQuality(); + void testVideoSettingsEncodingMode(); + void testVideoSettingsCopyConstructor(); + void testVideoSettingsOperatorAssignment(); + void testVideoSettingsOperatorNotEqual(); + void testVideoSettingsOperatorComparison(); + void testVideoSettingsDestructor(); + private: QAudioEncoderControl* encode; QAudioEndpointSelector* audio; - MockObject *object; - MockService *service; - MockProvider *mock; - QMediaRecorder *capture; + MockMediaObject *object; + MockMediaRecorderService*service; + MockMediaRecorderControl *mock; + QMediaRecorder *capture; QVideoEncoderControl* videoEncode; }; #endif //TST_QMEDIARECORDER_H diff --git a/tests/auto/qmediaresource/tst_qmediaresource.cpp b/tests/auto/qmediaresource/tst_qmediaresource.cpp index 51b265f3a..8051deb40 100644 --- a/tests/auto/qmediaresource/tst_qmediaresource.cpp +++ b/tests/auto/qmediaresource/tst_qmediaresource.cpp @@ -57,6 +57,9 @@ private slots: void equality(); void copy(); void assign(); + + void constructorRequest(); + void copyConstructor(); }; void tst_QMediaResource::constructNull() @@ -447,6 +450,61 @@ void tst_QMediaResource::equality() // Equal QCOMPARE(resource1 == resource2, true); QCOMPARE(resource1 != resource2, false); + + /* equality tests for constructor of QMediaresource(QNetworkrequest,mimeType)*/ + QNetworkRequest request2(QUrl(QString::fromLatin1("http://test.com/test.mp4"))); + QUrl url(QString::fromLatin1("http://test.com/test.mp4")); + QString mimeType(QLatin1String("video/mp4")); + + QMediaResource resource6(request2,mimeType); + QMediaResource resource7(request2,mimeType); + + + QVERIFY(resource6.request()==request2); + QVERIFY(resource6.mimeType()==mimeType); + + + QVERIFY(resource7.request()==request2); + QVERIFY(resource7.mimeType()==mimeType); + + QVERIFY(resource6.request()==resource7.request()); + QVERIFY(resource6.mimeType()==resource7.mimeType()); + + QVERIFY(resource6==resource7); + + /*for copy constructor*/ + QMediaResource resource8(resource7); + + QVERIFY(resource8.request()==request2); + QVERIFY(resource8.mimeType()==mimeType); + + + QVERIFY(resource7.request()==request2); + QVERIFY(resource7.mimeType()==mimeType); + + QVERIFY(resource8.request()==resource7.request()); + QVERIFY(resource8.mimeType()==resource7.mimeType()); + + + QVERIFY(resource8==resource7); + + /*for assign constructor*/ + + QMediaResource resource9(request2,mimeType); + + QMediaResource resource10=resource9; + + QVERIFY(resource10.request()==request2); + QVERIFY(resource10.mimeType()==mimeType); + + + QVERIFY(resource9.request()==request2); + QVERIFY(resource9.mimeType()==mimeType); + + QVERIFY(resource8.request()==resource7.request()); + QVERIFY(resource8.mimeType()==resource7.mimeType()); + + QVERIFY(resource8==resource7); } void tst_QMediaResource::copy() @@ -494,6 +552,12 @@ void tst_QMediaResource::assign() const QString aacCodec(QLatin1String("aac")); const QString h264Codec(QLatin1String("h264")); + QNetworkRequest request(QUrl(QString::fromLatin1("http://test.com/test.mp4"))); + const qint64 dataSize(23600); + int audioBitRate = 1, sampleRate = 2, channelCount = 3, videoBitRate = 4; + QSize resolution(QSize(640, 480)); + QString language("eng"); + QMediaResource copy(QUrl(QString::fromLatin1("file:///thumbs/test.jpg"))); QMediaResource original(url, mimeType); @@ -521,6 +585,114 @@ void tst_QMediaResource::assign() QCOMPARE(copy.mimeType(), mimeType); QCOMPARE(original.audioCodec(), mp3Codec); + + /* for constructor of QMediaresource(QNetworkrequest,mimeType)*/ + + QMediaResource copy1(QNetworkRequest(QUrl(QString::fromLatin1("file:///thumbs/test.jpg")))); + + QMediaResource original1(request, mimeType); + + original1.setAudioCodec(amrCodec); + original1.setLanguage(QString("eng")); + original1.setVideoCodec(h264Codec); + original1.setDataSize(dataSize); + original1.setAudioBitRate(audioBitRate); + original1.setSampleRate(sampleRate); + original1.setChannelCount(channelCount); + original1.setVideoBitRate(videoBitRate); + original1.setResolution(resolution); + + copy1 = original1; + + QCOMPARE(original1 == copy1, true); +} + +// Constructor for request without passing mimetype. +void tst_QMediaResource::constructorRequest() +{ + //Initialise the request and url. + QNetworkRequest request(QUrl(QString::fromLatin1("http:://test.com/test.mp3"))); + QUrl url(QString::fromLatin1("http:://test.com/test.mp3")); + + // Create the instance with request as parameter. + QMediaResource resource(request); + + // Verify all the parameters of objects. + QCOMPARE(resource.isNull(), false); + QCOMPARE(resource.url(), url); + QCOMPARE(resource.request(), request); + QCOMPARE(resource.mimeType(), QString()); + QCOMPARE(resource.language(), QString()); + QCOMPARE(resource.audioCodec(), QString()); + QCOMPARE(resource.videoCodec(), QString()); + QCOMPARE(resource.dataSize(), qint64(0)); + QCOMPARE(resource.audioBitRate(), 0); + QCOMPARE(resource.sampleRate(), 0); + QCOMPARE(resource.channelCount(), 0); + QCOMPARE(resource.videoBitRate(), 0); + QCOMPARE(resource.resolution(), QSize()); +} + +// Copy constructor with all the parameter and copy constructor for constructor with request and mimetype as parameter. +void tst_QMediaResource::copyConstructor() +{ + // Initialise all the parameters. + const QUrl url(QString::fromLatin1("http://test.com/test.mp4")); + const QString mimeType(QLatin1String("video/mp4")); + const QString amrCodec(QLatin1String("amr")); + const QString h264Codec(QLatin1String("h264")); + + const qint64 dataSize(23600); + int audioBitRate = 1, sampleRate = 2, channelCount = 3, videoBitRate = 4; + QSize resolution(QSize(640, 480)); + QString language("eng"); + + // Create the instance with url and mimetype. + QMediaResource original(url, mimeType); + + // Set all the parameters. + original.setAudioCodec(amrCodec); + original.setLanguage(QString("eng")); + original.setVideoCodec(h264Codec); + original.setDataSize(dataSize); + original.setAudioBitRate(audioBitRate); + original.setSampleRate(sampleRate); + original.setChannelCount(channelCount); + original.setVideoBitRate(videoBitRate); + original.setResolution(resolution); + + // Copy the instance to new object. + QMediaResource copy(original); + + // Verify all the parameters of the copied object. + QCOMPARE(copy.url(), url); + QCOMPARE(copy.mimeType(), mimeType); + QCOMPARE(copy.audioCodec(), amrCodec); + QCOMPARE(copy.language(), language ); + QCOMPARE(copy.videoCodec(), h264Codec); + QCOMPARE(copy.dataSize(), dataSize); + QCOMPARE(copy.audioBitRate(), audioBitRate); + QCOMPARE(copy.sampleRate(), sampleRate); + QCOMPARE(copy.channelCount(), channelCount); + QCOMPARE(copy.videoBitRate(), videoBitRate); + QCOMPARE(copy.resolution(), resolution); + + // Compare both the objects are equal. + QCOMPARE(original == copy, true); + QCOMPARE(original != copy, false); + + // Initialise the request parameter. + QNetworkRequest request1(QUrl(QString::fromLatin1("http://test.com/test.mp4"))); + + // Constructor with rerquest and mimetype. + QMediaResource original1(request1, mimeType); + + // Copy the object and verify if both are eqaul or not. + QMediaResource copy1(original1); + QCOMPARE(copy1.url(), url); + QCOMPARE(copy1.mimeType(), mimeType); + QCOMPARE(copy1.request(), request1); + QCOMPARE(original1 == copy1, true); } QTEST_MAIN(tst_QMediaResource) diff --git a/tests/auto/qmediaservice/tst_qmediaservice.cpp b/tests/auto/qmediaservice/tst_qmediaservice.cpp index 8d4fd9935..8f1dc38d1 100644 --- a/tests/auto/qmediaservice/tst_qmediaservice.cpp +++ b/tests/auto/qmediaservice/tst_qmediaservice.cpp @@ -54,17 +54,6 @@ QT_BEGIN_NAMESPACE class QtTestMediaService; -class tst_QMediaService : public QObject -{ - Q_OBJECT -private slots: - void initTestCase(); - - void control_iid(); - void control(); -}; - - class QtTestMediaControlA : public QMediaControl { Q_OBJECT @@ -98,23 +87,31 @@ class QtTestMediaControlD : public QMediaControl #define QtTestMediaControlD_iid "com.nokia.QtTestMediaControlD" Q_MEDIA_DECLARE_CONTROL(QtTestMediaControlD, QtTestMediaControlD_iid) +//unimplemented service +#define QtTestMediaControlE_iid "com.nokia.QtTestMediaControlF" class QtTestMediaControlE : public QMediaControl { Q_OBJECT }; +/* implementation of child class by inheriting The QMediaService base class for media service implementations. */ class QtTestMediaService : public QMediaService { Q_OBJECT public: - QtTestMediaService() - : QMediaService(0) - , refA(0) - , refB(0) - , refC(0) + int refA; + int refB; + int refC; + QtTestMediaControlA controlA; + QtTestMediaControlB controlB; + QtTestMediaControlC controlC; + + //constructor + QtTestMediaService(): QMediaService(0), refA(0), refB(0), refC(0) { } + //requestControl() pure virtual function of QMediaService class. QMediaControl *requestControl(const char *name) { if (strcmp(name, QtTestMediaControlA_iid) == 0) { @@ -134,6 +131,7 @@ public: } } + //releaseControl() pure virtual function of QMediaService class. void releaseControl(QMediaControl *control) { if (control == &controlA) @@ -144,20 +142,107 @@ public: refC -= 1; } + //requestControl() function of QMediaService class. using QMediaService::requestControl; +}; + +/* Test case implementation for QMediaService class which provides a common base class for media service implementations.*/ +class tst_QMediaService : public QObject +{ + Q_OBJECT +private slots: + void tst_destructor(); + void tst_releaseControl(); + void tst_requestControl(); + void tst_requestControlTemplate(); + + void initTestCase(); + + void control_iid(); + void control(); - int refA; - int refB; - int refC; - QtTestMediaControlA controlA; - QtTestMediaControlB controlB; - QtTestMediaControlC controlC; }; +/*MaemoAPI-1668 :destructor property test. */ +void tst_QMediaService::tst_destructor() +{ + QtTestMediaService *service = new QtTestMediaService; + delete service; +} + void tst_QMediaService::initTestCase() -{ +{ +} + +/*MaemoAPI-1669 :releaseControl() API property test. */ +void tst_QMediaService::tst_releaseControl() +{ + //test class instance creation + QtTestMediaService service; + + //Get a pointer to the media control implementing interface and verify. + QMediaControl* controlA = service.requestControl(QtTestMediaControlA_iid); + QCOMPARE(controlA, &service.controlA); + service.releaseControl(controlA); //Controls must be returned to the service when no longer needed + QVERIFY(service.refA == 0); + + //Get a pointer to the media control implementing interface and verify. + QMediaControl* controlB = service.requestControl(QtTestMediaControlB_iid); + QCOMPARE(controlB, &service.controlB); + service.releaseControl(controlB); //Controls must be returned to the service when no longer needed + QVERIFY(service.refB == 0); +} + +/*MaemoAPI-1670 :requestControl() API property test. */ +void tst_QMediaService::tst_requestControl() +{ + //test class instance creation + QtTestMediaService service; + + //Get a pointer to the media control implementing interface and verify. + QMediaControl* controlA = service.requestControl(QtTestMediaControlA_iid); + QCOMPARE(controlA, &service.controlA); + service.releaseControl(controlA); //Controls must be returned to the service when no longer needed + + //Get a pointer to the media control implementing interface and verify. + QMediaControl* controlB = service.requestControl(QtTestMediaControlB_iid); + QCOMPARE(controlB, &service.controlB); + service.releaseControl(controlB); //Controls must be returned to the service when no longer needed + + //If the service does not implement the control, a null pointer is returned instead. + QMediaControl* controlE = service.requestControl(QtTestMediaControlE_iid); + QVERIFY(!controlE); //should return null pointer + service.releaseControl(controlE); //Controls must be returned to the service when no longer needed + + //If the service is unavailable a null pointer is returned instead. + QMediaControl* control = service.requestControl(""); + QVERIFY(!control); //should return null pointer + service.releaseControl(control); //Controls must be returned to the service when no longer needed } +/*MaemoAPI-1671 :requestControl() API property test. */ +void tst_QMediaService::tst_requestControlTemplate() +{ + //test class instance creation + QtTestMediaService service; + + //Get a pointer to the media control of type T implemented by a media service. + QtTestMediaControlA *controlA = service.requestControl<QtTestMediaControlA *>(); + QCOMPARE(controlA, &service.controlA); + service.releaseControl(controlA); + + //Get a pointer to the media control of type T implemented by a media service. + QtTestMediaControlB *controlB = service.requestControl<QtTestMediaControlB *>(); + QCOMPARE(controlB, &service.controlB); + service.releaseControl(controlB); + + QVERIFY(!service.requestControl<QtTestMediaControlC *>()); // Faulty implementation returns A. + QCOMPARE(service.refA, 0); // Verify the control was released. + + QVERIFY(!service.requestControl<QtTestMediaControlD *>()); // No control of that type. +} + + void tst_QMediaService::control_iid() { const char *nullString = 0; @@ -181,7 +266,7 @@ void tst_QMediaService::control() QCOMPARE(controlB, &service.controlB); service.releaseControl(controlB); - QVERIFY(!service.requestControl<QtTestMediaControlC *>()); // Faulty implementation returns A. + QVERIFY(!service.requestControl<QtTestMediaControlC *>()); // Faulty implementation returns A, but is wrong class QCOMPARE(service.refA, 0); // Verify the control was released. QVERIFY(!service.requestControl<QtTestMediaControlD *>()); // No control of that type. diff --git a/tests/auto/qmediaserviceprovider/tst_qmediaserviceprovider.cpp b/tests/auto/qmediaserviceprovider/tst_qmediaserviceprovider.cpp index 8fe2f13c8..f6b3ad1cd 100644 --- a/tests/auto/qmediaserviceprovider/tst_qmediaserviceprovider.cpp +++ b/tests/auto/qmediaserviceprovider/tst_qmediaserviceprovider.cpp @@ -445,6 +445,16 @@ void tst_QMediaServiceProvider::testProviderHints() } { + QMediaServiceProviderHint hint(QMediaServiceProviderHint::RecordingSupport); + QVERIFY(!hint.isNull()); + QCOMPARE(hint.type(), QMediaServiceProviderHint::SupportedFeatures); + QVERIFY(hint.device().isEmpty()); + QVERIFY(hint.mimeType().isEmpty()); + QVERIFY(hint.codecs().isEmpty()); + QCOMPARE(hint.features(), QMediaServiceProviderHint::RecordingSupport); + } + + { QString mimeType(QLatin1String("video/ogg")); QStringList codecs; codecs << "theora" << "vorbis"; diff --git a/tests/auto/qmediastreamscontrol/qmediastreamscontrol.pro b/tests/auto/qmediastreamscontrol/qmediastreamscontrol.pro new file mode 100644 index 000000000..fcd8116a8 --- /dev/null +++ b/tests/auto/qmediastreamscontrol/qmediastreamscontrol.pro @@ -0,0 +1,8 @@ +load(qttest_p4) + +QT += multimediakit-private + +SOURCES += \ + tst_qmediastreamscontrol.cpp + +include(../multimedia_common.pri) diff --git a/tests/auto/qmediastreamscontrol/tst_qmediastreamscontrol.cpp b/tests/auto/qmediastreamscontrol/tst_qmediastreamscontrol.cpp new file mode 100644 index 000000000..433ee1238 --- /dev/null +++ b/tests/auto/qmediastreamscontrol/tst_qmediastreamscontrol.cpp @@ -0,0 +1,408 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/multimedia + +#include <QtCore/QString> +#include <QtTest/QtTest> +#include <QtCore/QCoreApplication> + + +#include <qmediaplayercontrol.h> +#include <qmediaservice.h> + +#include <qmediastreamscontrol.h> + +#include <QtGui/QImage> +#include <QtCore/QPointer> + +QT_USE_NAMESPACE + + +#define WAIT_FOR_CONDITION(a,e) \ + for (int _i = 0; _i < 500; _i += 1) { \ + if ((a) == (e)) break; \ + QTest::qWait(10);} + +class tst_qmediastreamscontrol : public QObject +{ + Q_OBJECT + +public: + tst_qmediastreamscontrol(); + +private Q_SLOTS: + void initTestCase(); + void cleanupTestCase(); + void control_iid(); + void control(); + void isActive(); + void streamCount(); + void streamsChanged(); + void metadata(); +}; + + + +class mediaStatusList : public QObject, public QList<QMediaStreamsControl::StreamType> +{ + Q_OBJECT +public slots: + void mediaStatus(QMediaStreamsControl::StreamType status) { + append(status); + } + +public: + mediaStatusList(QObject *obj, const char *aSignal) + : QObject() + { + QObject::connect(obj, aSignal, this, SLOT(mediaStatus(QMediaStreamsControl::StreamType))); + } +}; + +class QtTestMediaStreamsControl: public QMediaStreamsControl +{ +public: + QtTestMediaStreamsControl(QObject *parent = 0) + : QMediaStreamsControl(parent) + { + } + + int streamCount() + { + QList <StreamType> m_stype; + + return streams.count(); + } + void setStreamCount(int count) + { + streams.resize(count); + } + + StreamType streamType(int index) + { + return streams.at(index).type; + } + void setStreamType(int index, StreamType type) + { + streams[index].type = type; + } + + QVariant metaData(int index, QtMultimediaKit::MetaData key) + { + QtMultimediaKit::MetaData keys = key; + return keys; + } + + void setMetaData(int index, QtMultimediaKit::MetaData key, const QVariant &value) + { + streams[index].metaData.insert(key, value); + } + + bool isActive(int index) + { + return streams.at(index).active; + } + void setActive(int index, bool state) + { + streams[index].active = state; + } + + void setAudioOnlyContent() + { + mediaContent = audioOnlyContent; + + m_player->setMedia(*mediaContent); + } + + void setVideoOnlyContent() + { + mediaContent = videoOnlyContent; + duration = 60000; + + m_player->setMedia(*mediaContent); + } + + void setAudioVideoContent() + { + if (mediaContent == audioVideoContent) + { + mediaContent = audioVideoAltContent; + duration = 101840; + } + else + { + mediaContent = audioVideoContent; + duration = 141000; + } + + m_player->setMedia(*mediaContent); + } + + void setStreamingContent() + { + mediaContent = streamingContent; + + m_player->setMedia(*mediaContent); + } + + + +public: + struct Stream + { + Stream() : type(UnknownStream), active(false) {} + StreamType type; + QMap<QtMultimediaKit::MetaData, QVariant> metaData; + bool active; + }; + + QVector<Stream> streams; + QMediaContent* audioOnlyContent; + QMediaContent* videoOnlyContent; + QMediaContent* audioVideoContent; + QMediaContent* audioVideoAltContent; + QMediaContent* mediaContent; + QMediaContent* streamingContent; + + qint64 duration; + QMediaPlayer *m_player; + QVideoWidget *m_widget; + QWidget *m_windowWidget; + + +}; + +class QTestMediaStreamsControlA : public QMediaControl +{ + Q_OBJECT +}; + +#define QTestMediaStreamsControlA_iid "com.nokia.QTestMediaStreamsControlA" +Q_MEDIA_DECLARE_CONTROL(QTestMediaStreamsControlA, QTestMediaStreamsControlA_iid) + +class QTestMediaStreamsControlB : public QMediaControl +{ + Q_OBJECT +public: + QTestMediaStreamsControlB() + : QMediaControl(0) + ,ctrlA(0) + ,ctrlB(0) + ,ctrlC(0) {} + + bool isActive(int stream) + { + return 1; + } + + int ctrlA; + int ctrlB; + int ctrlC; +}; + +#define QTestMediaStreamsControlB_iid "com.nokia.QTestMediaStreamsControlB" +Q_MEDIA_DECLARE_CONTROL(QTestMediaStreamsControlB, QTestMediaStreamsControlB_iid) + + +class QTestMediaStreamsControlC : public QMediaControl +{ + Q_OBJECT +}; + +#define QTestMediaStreamsControlC_iid "com.nokia.QTestMediaStreamsControlC" +Q_MEDIA_DECLARE_CONTROL(QTestMediaStreamsControlC, QTestMediaStreamsControlC_iid) // Yes A. + +class QTestMediaStreamsControlD : public QMediaControl +{ + Q_OBJECT +}; + +#define QTestMediaStreamsControlD_iid "com.nokia.QTestMediaStreamsControlD" +Q_MEDIA_DECLARE_CONTROL(QTestMediaStreamsControlD, QTestMediaStreamsControlD_iid) + + +class QtTestMediaService : public QMediaService +{ + Q_OBJECT +public: + QtTestMediaService() + : QMediaService(0) + , refA(0) + , refB(0) + , refC(0) + { + } + + QMediaControl *requestControl(const char *name) + { + if (strcmp(name, QTestMediaStreamsControlA_iid) == 0) { + refA += 1; + + return &controlA; + } else if (strcmp(name, QTestMediaStreamsControlB_iid) == 0) { + refB += 1; + + return &controlB; + } else if (strcmp(name, QTestMediaStreamsControlC_iid) == 0) { + refA += 1; + + return &controlA; + } else { + return 0; + } + } + + void releaseControl(QMediaControl *control) + { + if (control == &controlA) + refA -= 1; + else if (control == &controlB) + refB -= 1; + else if (control == &controlC) + refC -= 1; + } + + using QMediaService::requestControl; + + int refA; + int refB; + int refC; + QTestMediaStreamsControlA controlA; + QTestMediaStreamsControlB controlB; + QTestMediaStreamsControlC controlC; +}; + + +tst_qmediastreamscontrol::tst_qmediastreamscontrol() +{ +} + +void tst_qmediastreamscontrol::initTestCase() +{ +} + +void tst_qmediastreamscontrol::cleanupTestCase() +{ +} + +void tst_qmediastreamscontrol::control_iid() +{ + + // Default implementation. + QCOMPARE(qmediacontrol_iid<QTestMediaStreamsControlA *>(), QTestMediaStreamsControlA_iid); + + // Partial template. + QVERIFY(qstrcmp(qmediacontrol_iid<QTestMediaStreamsControlA *>(), QTestMediaStreamsControlA_iid) == 0); +} + +void tst_qmediastreamscontrol::control() +{ + QtTestMediaService *service = new QtTestMediaService(); + QMediaStreamsControl *control = qobject_cast<QMediaStreamsControl *> + (service->requestControl("com.nokia.Qt.MediaStreamsControl/1.0")); + // QCOMPARE(control,service->controlA.objectName()); + QTestMediaStreamsControlA *controlA = (QTestMediaStreamsControlA *)service->requestControl("controlA"); + // QCOMPARE(controlA,service->controlA); + QVERIFY(service->requestControl<QTestMediaStreamsControlA *>()); + + service->releaseControl(controlA); + delete service; +} + +void tst_qmediastreamscontrol::isActive() +{ + QTestMediaStreamsControlB ser; + QVERIFY(ser.isActive(1)); + QtTestMediaStreamsControl m_active; + //setActive + m_active.setActive(1,1); + QVERIFY(m_active.isActive(1)); + //set InActive + m_active.setActive(2,0); + QVERIFY(!m_active.isActive(0)); +} + +//Returns the number of media streams. +void tst_qmediastreamscontrol::streamCount() +{ + QtTestMediaStreamsControl m_cnt; + m_cnt.setStreamType(0,QMediaStreamsControl::UnknownStream); + m_cnt.setStreamType(1,QMediaStreamsControl::VideoStream); + m_cnt.setStreamType(2,QMediaStreamsControl::AudioStream); + m_cnt.setStreamType(3,QMediaStreamsControl::SubPictureStream); + m_cnt.setStreamType(4,QMediaStreamsControl::DataStream); + m_cnt.setStreamCount(5); + QVERIFY(m_cnt.streamCount() == m_cnt.streams.count()); +} + +//The signal is emitted when the available streams list is changed. +void tst_qmediastreamscontrol::streamsChanged() +{ + QMediaPlayer *m_player = new QMediaPlayer(0); + QMediaStreamsControl* m_streamControl = (QMediaStreamsControl*) + (m_player->service()->requestControl(QTestMediaStreamsControlA_iid)); + + QMediaContent videoOnlyContent; + + m_player->setMedia(videoOnlyContent); + if (m_streamControl) { + QSignalSpy m_strm_lst_chgSpy(m_streamControl,SIGNAL(streamsChanged())); + QVERIFY(m_strm_lst_chgSpy.isValid()); + QVERIFY(m_strm_lst_chgSpy.isEmpty()); + WAIT_FOR_CONDITION(m_player->mediaStatus(),QMediaPlayer::LoadedMedia); + QVERIFY(m_streamControl->streamCount() == 1); + QVERIFY(m_strm_lst_chgSpy.count() == 1); + } + + delete m_player; + m_player = NULL; +} + +void tst_qmediastreamscontrol::metadata() +{ + QtTestMediaStreamsControl m_metadata; + m_metadata.metaData(1,QtMultimediaKit::AlbumArtist); + qDebug() << m_metadata.metaData(1,QtMultimediaKit::AlbumArtist); +} +QTEST_MAIN(tst_qmediastreamscontrol); + +#include "tst_qmediastreamscontrol.moc" diff --git a/tests/auto/qmediatimerange/tst_qmediatimerange.cpp b/tests/auto/qmediatimerange/tst_qmediatimerange.cpp index 01a372d74..dd8dc5ff9 100644 --- a/tests/auto/qmediatimerange/tst_qmediatimerange.cpp +++ b/tests/auto/qmediatimerange/tst_qmediatimerange.cpp @@ -45,6 +45,7 @@ #include <QtCore/qdebug.h> #include <qmediatimerange.h> +#include <qmediatimerange.h> QT_USE_NAMESPACE @@ -56,10 +57,12 @@ public slots: private slots: void testCtor(); + void testIntervalCtor(); void testGetters(); void testAssignment(); - void testNormalize(); - void testTranslated(); + void testIntervalNormalize(); + void testIntervalTranslate(); + void testIntervalContains(); void testEarliestLatest(); void testContains(); void testAddInterval(); @@ -71,6 +74,59 @@ private slots: void testArithmetic(); }; +void tst_QMediaTimeRange::testIntervalCtor() +{ + //Default Ctor for Time Interval + /* create an instance for the time interval and verify the default cases */ + QMediaTimeInterval tInter; + QVERIFY(tInter.isNormal()); + QVERIFY(tInter.start() == 0); + QVERIFY(tInter.end() == 0); + + // (qint, qint) Ctor time interval + /* create an instace of QMediaTimeInterval passing start and end times and verify the all possible scenario's*/ + QMediaTimeInterval time(20,50); + QVERIFY(time.isNormal()); + QVERIFY(time.start() == 20); + QVERIFY(time.end() == 50); + + // Copy Ctor Time interval + QMediaTimeInterval other(time); + QVERIFY(other.isNormal() == time.isNormal()); + QVERIFY(other.start() == time.start()); + QVERIFY(other.end() == time.end()); + QVERIFY(other.contains(20) == time.contains(20)); + QVERIFY(other == time); +} + +void tst_QMediaTimeRange::testIntervalContains() +{ + QMediaTimeInterval time(20,50); + + /* start() <= time <= end(). Returns true if the time interval contains the specified time. */ + QVERIFY(!time.contains(10)); + QVERIFY(time.contains(20)); + QVERIFY(time.contains(30)); + QVERIFY(time.contains(50)); + QVERIFY(!time.contains(60)); + + QMediaTimeInterval x(20, 10); // denormal + + // Check denormal ranges + QVERIFY(!x.contains(5)); + QVERIFY(x.contains(10)); + QVERIFY(x.contains(15)); + QVERIFY(x.contains(20)); + QVERIFY(!x.contains(25)); + + QMediaTimeInterval y = x.normalized(); + QVERIFY(!y.contains(5)); + QVERIFY(y.contains(10)); + QVERIFY(y.contains(15)); + QVERIFY(y.contains(20)); + QVERIFY(!y.contains(25)); +} + void tst_QMediaTimeRange::testCtor() { // Default Ctor @@ -105,6 +161,8 @@ void tst_QMediaTimeRange::testCtor() QVERIFY(e.isContinuous()); QVERIFY(e.earliestTime() == 10); QVERIFY(e.latestTime() == 20); + + QVERIFY(e == b); } void tst_QMediaTimeRange::testGetters() @@ -164,26 +222,35 @@ void tst_QMediaTimeRange::testAssignment() QVERIFY(x.latestTime() == 40); } -void tst_QMediaTimeRange::testNormalize() +void tst_QMediaTimeRange::testIntervalNormalize() { QMediaTimeInterval x(20, 10); QVERIFY(!x.isNormal()); + QVERIFY(x.start() == 20); + QVERIFY(x.end() == 10); - x = x.normalized(); + QMediaTimeInterval y = x.normalized(); - QVERIFY(x.isNormal()); - QVERIFY(x.start() == 10); - QVERIFY(x.end() == 20); + QVERIFY(y.isNormal()); + QVERIFY(y.start() == 10); + QVERIFY(y.end() == 20); + QVERIFY(x != y); } -void tst_QMediaTimeRange::testTranslated() +void tst_QMediaTimeRange::testIntervalTranslate() { QMediaTimeInterval x(10, 20); x = x.translated(10); QVERIFY(x.start() == 20); QVERIFY(x.end() == 30); + + /* verifying the backward through time with a negative offset.*/ + x = x.translated(-10); + + QVERIFY(x.start() == 10); + QVERIFY(x.end() == 20); } void tst_QMediaTimeRange::testEarliestLatest() diff --git a/tests/auto/qmetadatareadercontrol/qmetadatareadercontrol.pro b/tests/auto/qmetadatareadercontrol/qmetadatareadercontrol.pro new file mode 100644 index 000000000..dc2f05123 --- /dev/null +++ b/tests/auto/qmetadatareadercontrol/qmetadatareadercontrol.pro @@ -0,0 +1,8 @@ +load(qttest_p4) + +QT += multimediakit-private + +SOURCES += tst_qmetadatareadercontrol.cpp + +include (../qmultimedia_common/mockcontainer.pri) + diff --git a/tests/auto/qmetadatareadercontrol/tst_qmetadatareadercontrol.cpp b/tests/auto/qmetadatareadercontrol/tst_qmetadatareadercontrol.cpp new file mode 100644 index 000000000..d9de33e16 --- /dev/null +++ b/tests/auto/qmetadatareadercontrol/tst_qmetadatareadercontrol.cpp @@ -0,0 +1,143 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 <QtCore/QCoreApplication> + +#include "mockmetadatareadercontrol.h" + +class tst_QMetaDataReaderControl : public QObject +{ + Q_OBJECT + +private slots: + // Test case for QMetaDataReaderControl + void metaDataReaderControlConstructor(); + void metaDataReaderControlAvailableMetaData(); + void metaDataReaderControlExtendedMetaData(); + void metaDataReaderControlIsMetaDataAvailable(); + void metaDataReaderControlMetaData(); + void metaDataReaderControlAvailableExtendedMetaData(); + void metaDataReaderControlMetaDataAvailableChangedSignal(); + void metaDataReaderControlMetaDataChangedSignal(); +}; + +QTEST_MAIN(tst_QMetaDataReaderControl); + +/* Test case for constructor. */ +void tst_QMetaDataReaderControl::metaDataReaderControlConstructor() +{ + MockMetaDataReaderControl *metaData = new MockMetaDataReaderControl(); + QVERIFY(metaData !=NULL); + delete metaData; +} + +/* Test case for availableMetaData() */ +void tst_QMetaDataReaderControl::metaDataReaderControlAvailableMetaData() +{ + MockMetaDataReaderControl *metaData = new MockMetaDataReaderControl(); + QVERIFY(metaData !=NULL); + metaData->availableMetaData() ; + delete metaData; +} + +/* Test case for extendedMetaData */ +void tst_QMetaDataReaderControl::metaDataReaderControlExtendedMetaData () +{ + const QString titleKey(QLatin1String("Title")); + MockMetaDataReaderControl *metaData = new MockMetaDataReaderControl(); + QVERIFY(metaData !=NULL); + metaData->extendedMetaData(titleKey); + delete metaData; +} + +/* Test case for availableMetaData */ +void tst_QMetaDataReaderControl::metaDataReaderControlIsMetaDataAvailable () +{ + MockMetaDataReaderControl *metaData = new MockMetaDataReaderControl(); + QVERIFY(metaData !=NULL); + metaData->availableMetaData(); + delete metaData; +} + +/* Test case for metaData */ +void tst_QMetaDataReaderControl::metaDataReaderControlMetaData () +{ + MockMetaDataReaderControl *metaData = new MockMetaDataReaderControl(); + QVERIFY(metaData !=NULL); + metaData->metaData(QtMultimediaKit::Title); + delete metaData; +} + +/* Test case for availableExtendedMetaData */ +void tst_QMetaDataReaderControl::metaDataReaderControlAvailableExtendedMetaData () +{ + MockMetaDataReaderControl *metaData = new MockMetaDataReaderControl(); + QVERIFY(metaData !=NULL); + metaData->availableExtendedMetaData(); + delete metaData; +} + +/* Test case for signal metaDataAvailableChanged */ +void tst_QMetaDataReaderControl::metaDataReaderControlMetaDataAvailableChangedSignal () +{ + MockMetaDataReaderControl *metaData = new MockMetaDataReaderControl(); + QVERIFY(metaData !=NULL); + QSignalSpy spy(metaData,SIGNAL(metaDataAvailableChanged(bool))); + metaData->setMetaDataAvailable(true); + QVERIFY(spy.count() == 1); + delete metaData; +} + + /* Test case for signal metaDataChanged */ +void tst_QMetaDataReaderControl::metaDataReaderControlMetaDataChangedSignal () +{ + MockMetaDataReaderControl *metaData = new MockMetaDataReaderControl(); + QVERIFY(metaData !=NULL); + QSignalSpy spy(metaData,SIGNAL(metaDataChanged())); + metaData->metaDataChanged(); + QVERIFY(spy.count () == 1); + delete metaData; +} + +#include "tst_qmetadatareadercontrol.moc" + + diff --git a/tests/auto/qmetadatawritercontrol/qmetadatawritercontrol.pro b/tests/auto/qmetadatawritercontrol/qmetadatawritercontrol.pro new file mode 100644 index 000000000..601b8d61d --- /dev/null +++ b/tests/auto/qmetadatawritercontrol/qmetadatawritercontrol.pro @@ -0,0 +1,7 @@ +load(qttest_p4) + +QT += multimediakit-private + +SOURCES += tst_qmetadatawritercontrol.cpp + +include (../qmultimedia_common/mockcontainer.pri) diff --git a/tests/auto/qmetadatawritercontrol/tst_qmetadatawritercontrol.cpp b/tests/auto/qmetadatawritercontrol/tst_qmetadatawritercontrol.cpp new file mode 100644 index 000000000..8ce1f27b1 --- /dev/null +++ b/tests/auto/qmetadatawritercontrol/tst_qmetadatawritercontrol.cpp @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 <QtCore/QCoreApplication> +#include "qmetadatawritercontrol.h" + +#include "mockmetadatawritercontrol.h" + +class tst_QMetaDataWriterControl: public QObject +{ + Q_OBJECT + +public slots: + void initTestCase(); + void cleanupTestCase(); + +private slots: + void constructor(); +}; + +void tst_QMetaDataWriterControl::initTestCase() +{ + +} + +void tst_QMetaDataWriterControl::cleanupTestCase() +{ + +} + +//MaemoAPI-1862:test constructor +void tst_QMetaDataWriterControl::constructor() +{ + QMetaDataWriterControl *mock = new MockMetaDataWriterControl(); + mock->availableExtendedMetaData(); + mock->availableMetaData(); + mock->isMetaDataAvailable(); + mock->isWritable(); + mock->metaData((QtMultimediaKit::MetaData) 1 ); + mock->extendedMetaData(QString("XYZ")); + mock->setExtendedMetaData(QString("XYZ"),QVariant()); + mock->setMetaData((QtMultimediaKit::MetaData) 1,QVariant()); + ((MockMetaDataWriterControl*)mock)->setWritable(); + ((MockMetaDataWriterControl*)mock)->setMetaDataAvailable(); + delete mock; +} + +QTEST_MAIN(tst_QMetaDataWriterControl); + +#include "tst_qmetadatawritercontrol.moc" diff --git a/tests/auto/qmultimedia_common/mock.pri b/tests/auto/qmultimedia_common/mock.pri new file mode 100644 index 000000000..8b8f3e7fa --- /dev/null +++ b/tests/auto/qmultimedia_common/mock.pri @@ -0,0 +1,7 @@ +INCLUDEPATH += $$PWD \ + ../../../src/multimedia \ + +HEADERS *= \ + ../qmultimedia_common/mockmediaserviceprovider.h \ + ../qmultimedia_common/mockmediaservice.h \ + ../qmultimedia_common/mockmediaobject.h diff --git a/tests/auto/qmultimedia_common/mockaudioencodercontrol.h b/tests/auto/qmultimedia_common/mockaudioencodercontrol.h new file mode 100644 index 000000000..85d18664a --- /dev/null +++ b/tests/auto/qmultimedia_common/mockaudioencodercontrol.h @@ -0,0 +1,127 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +#ifndef MOCKAUDIOENCODERCONTROL_H +#define MOCKAUDIOENCODERCONTROL_H + +#include "qaudioencodercontrol.h" + +class MockAudioEncoderControl : public QAudioEncoderControl +{ + Q_OBJECT +public: + MockAudioEncoderControl(QObject *parent): + QAudioEncoderControl(parent) + { + m_codecs << "audio/pcm" << "audio/mpeg"; + m_descriptions << "Pulse Code Modulation" << "mp3 format"; + m_supportedEncodeOptions.insert("audio/pcm", QStringList()); + m_supportedEncodeOptions.insert("audio/mpeg", QStringList() << "quality" << "bitrate" << "mode" << "vbr"); + m_audioSettings.setCodec("audio/pcm"); + m_audioSettings.setBitRate(128*1024); + m_audioSettings.setSampleRate(8000); + m_freqs << 8000 << 11025 << 22050 << 44100; + } + + ~MockAudioEncoderControl() {} + + QAudioEncoderSettings audioSettings() const + { + return m_audioSettings; + } + + void setAudioSettings(const QAudioEncoderSettings &settings) + { + m_audioSettings = settings; + } + + QList<int> supportedChannelCounts(const QAudioEncoderSettings & = QAudioEncoderSettings()) const + { + QList<int> list; list << 1 << 2; return list; + } + + QList<int> supportedSampleRates(const QAudioEncoderSettings & = QAudioEncoderSettings(), bool *continuous = 0) const + { + if (continuous) + *continuous = false; + + return m_freqs; + } + + QStringList supportedAudioCodecs() const + { + return m_codecs; + } + + QString codecDescription(const QString &codecName) const + { + return m_descriptions.value(m_codecs.indexOf(codecName)); + } + + QStringList supportedEncodingOptions(const QString &codec) const + { + return m_supportedEncodeOptions.value(codec); + } + + QVariant encodingOption(const QString &codec, const QString &name) const + { + return m_encodeOptions[codec].value(name); + } + + void setEncodingOption(const QString &codec, const QString &name, const QVariant &value) + { + m_encodeOptions[codec][name] = value; + } + +private: + QAudioEncoderSettings m_audioSettings; + + QStringList m_codecs; + QStringList m_descriptions; + + QList<int> m_freqs; + + QMap<QString, QStringList> m_supportedEncodeOptions; + QMap<QString, QMap<QString, QVariant> > m_encodeOptions; + +}; + +#endif // MOCKAUDIOENCODERCONTROL_H diff --git a/tests/auto/qmultimedia_common/mockaudioendpointselector.h b/tests/auto/qmultimedia_common/mockaudioendpointselector.h new file mode 100644 index 000000000..2bc118d89 --- /dev/null +++ b/tests/auto/qmultimedia_common/mockaudioendpointselector.h @@ -0,0 +1,117 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +#ifndef MOCKAUDIOENDPOINTSELECTOR_H +#define MOCKAUDIOENDPOINTSELECTOR_H + +#include "qaudioendpointselector.h" + +class MockAudioEndpointSelector : public QAudioEndpointSelector +{ + Q_OBJECT +public: + MockAudioEndpointSelector(QObject *parent): + QAudioEndpointSelector(parent) + { + m_names << "device1" << "device2" << "device3"; + m_descriptions << "dev1 comment" << "dev2 comment" << "dev3 comment"; + m_audioInput = "device1"; + emit availableEndpointsChanged(); + } + ~MockAudioEndpointSelector() {} + + QList<QString> availableEndpoints() const + { + return m_names; + } + + QString endpointDescription(const QString& name) const + { + QString desc; + + for (int i = 0; i < m_names.count(); i++) { + if (m_names.at(i).compare(name) == 0) { + desc = m_descriptions.at(i); + break; + } + } + return desc; + } + + QString defaultEndpoint() const + { + return m_names.at(0); + } + + QString activeEndpoint() const + { + return m_audioInput; + } + +public Q_SLOTS: + + void setActiveEndpoint(const QString& name) + { + m_audioInput = name; + emit activeEndpointChanged(name); + } + + void addEndpoints() + { + m_names << "device4"; + emit availableEndpointsChanged(); + } + + void removeEndpoints() + { + m_names.clear(); + emit availableEndpointsChanged(); + } + +private: + QString m_audioInput; + QList<QString> m_names; + QList<QString> m_descriptions; +}; + + + +#endif // MOCKAUDIOENDPOINTSELECTOR_H diff --git a/tests/auto/qmultimedia_common/mockcamera.pri b/tests/auto/qmultimedia_common/mockcamera.pri new file mode 100644 index 000000000..233d5b8a2 --- /dev/null +++ b/tests/auto/qmultimedia_common/mockcamera.pri @@ -0,0 +1,22 @@ +# Camera related mock backend files +INCLUDEPATH += $$PWD \ + ../../../src/multimedia \ + ../../../src/multimedia/video \ + ../../../src/multimedia/camera + +HEADERS *= \ + ../qmultimedia_common/mockcameraservice.h \ + ../qmultimedia_common/mockcameraflashcontrol.h \ + ../qmultimedia_common/mockcameralockscontrol.h \ + ../qmultimedia_common/mockcamerafocuscontrol.h \ + ../qmultimedia_common/mockcameraimageprocessingcontrol.h \ + ../qmultimedia_common/mockcameraimagecapturecontrol.h \ + ../qmultimedia_common/mockcameraexposurecontrol.h \ + ../qmultimedia_common/mockcameracapturedestinationcontrol.h \ + ../qmultimedia_common/mockcameracapturebuffercontrol.h \ + ../qmultimedia_common/mockimageencodercontrol.h \ + ../qmultimedia_common/mockcameracontrol.h \ + + +include(mockvideo.pri) + diff --git a/tests/auto/qmultimedia_common/mockcameracapturebuffercontrol.h b/tests/auto/qmultimedia_common/mockcameracapturebuffercontrol.h new file mode 100644 index 000000000..d71794635 --- /dev/null +++ b/tests/auto/qmultimedia_common/mockcameracapturebuffercontrol.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +#ifndef MOCKCAMERACAPTUREBUFFERCONTROL_H +#define MOCKCAMERACAPTUREBUFFERCONTROL_H + +#include "qcameracapturebufferformatcontrol.h" + +class MockCaptureBufferFormatControl : public QCameraCaptureBufferFormatControl +{ + Q_OBJECT +public: + MockCaptureBufferFormatControl(QObject *parent = 0): + QCameraCaptureBufferFormatControl(parent), + m_format(QVideoFrame::Format_Jpeg) + { + } + + QList<QVideoFrame::PixelFormat> supportedBufferFormats() const + { + return QList<QVideoFrame::PixelFormat>() + << QVideoFrame::Format_Jpeg + << QVideoFrame::Format_RGB32 + << QVideoFrame::Format_AdobeDng; + } + + QVideoFrame::PixelFormat bufferFormat() const + { + return m_format; + } + + void setBufferFormat(QVideoFrame::PixelFormat format) + { + if (format != m_format && supportedBufferFormats().contains(format)) { + m_format = format; + emit bufferFormatChanged(m_format); + } + } + +private: + QVideoFrame::PixelFormat m_format; +}; + + +#endif // MOCKCAMERACAPTUREBUFFERCONTROL_H diff --git a/tests/auto/qmultimedia_common/mockcameracapturedestinationcontrol.h b/tests/auto/qmultimedia_common/mockcameracapturedestinationcontrol.h new file mode 100644 index 000000000..3f7697d1c --- /dev/null +++ b/tests/auto/qmultimedia_common/mockcameracapturedestinationcontrol.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +#ifndef MOCKCAMERACAPTUREDESTINATIONCONTROL_H +#define MOCKCAMERACAPTUREDESTINATIONCONTROL_H + +#include "qcameracapturedestinationcontrol.h" + +class MockCaptureDestinationControl : public QCameraCaptureDestinationControl +{ + Q_OBJECT +public: + MockCaptureDestinationControl(QObject *parent = 0): + QCameraCaptureDestinationControl(parent), + m_destination(QCameraImageCapture::CaptureToFile) + { + } + + bool isCaptureDestinationSupported(QCameraImageCapture::CaptureDestinations destination) const + { + return destination == QCameraImageCapture::CaptureToBuffer || + destination == QCameraImageCapture::CaptureToFile; + } + + QCameraImageCapture::CaptureDestinations captureDestination() const + { + return m_destination; + } + + void setCaptureDestination(QCameraImageCapture::CaptureDestinations destination) + { + if (isCaptureDestinationSupported(destination) && destination != m_destination) { + m_destination = destination; + emit captureDestinationChanged(m_destination); + } + } + +private: + QCameraImageCapture::CaptureDestinations m_destination; +}; + +#endif // MOCKCAMERACAPTUREDESTINATIONCONTROL_H diff --git a/tests/auto/qmultimedia_common/mockcameracontrol.h b/tests/auto/qmultimedia_common/mockcameracontrol.h new file mode 100644 index 000000000..893ecbfd8 --- /dev/null +++ b/tests/auto/qmultimedia_common/mockcameracontrol.h @@ -0,0 +1,145 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +#ifndef MOCKCAMERACONTROL_H +#define MOCKCAMERACONTROL_H + +#include "qcameracontrol.h" + +class MockCameraControl : public QCameraControl +{ + friend class MockCaptureControl; + Q_OBJECT +public: + MockCameraControl(QObject *parent = 0): + QCameraControl(parent), + m_state(QCamera::UnloadedState), + m_captureMode(QCamera::CaptureStillImage), + m_status(QCamera::UnloadedStatus), + m_propertyChangesSupported(false) + { + } + + ~MockCameraControl() {} + + void start() { m_state = QCamera::ActiveState; } + virtual void stop() { m_state = QCamera::UnloadedState; } + QCamera::State state() const { return m_state; } + void setState(QCamera::State state) { + if (m_state != state) { + m_state = state; + + switch (state) { + case QCamera::UnloadedState: + m_status = QCamera::UnloadedStatus; + break; + case QCamera::LoadedState: + m_status = QCamera::LoadedStatus; + break; + case QCamera::ActiveState: + m_status = QCamera::ActiveStatus; + break; + default: + emit error(QCamera::NotSupportedFeatureError, "State not supported."); + return; + } + + emit stateChanged(m_state); + emit statusChanged(m_status); + } + } + + QCamera::Status status() const { return m_status; } + + QCamera::CaptureMode captureMode() const { return m_captureMode; } + void setCaptureMode(QCamera::CaptureMode mode) + { + if (m_captureMode != mode) { + if (m_state == QCamera::ActiveState && !m_propertyChangesSupported) + return; + m_captureMode = mode; + emit captureModeChanged(mode); + } + } + + bool isCaptureModeSupported(QCamera::CaptureMode mode) const + { + return mode == QCamera::CaptureStillImage || mode == QCamera::CaptureVideo; + } + + QCamera::LockTypes supportedLocks() const + { + return QCamera::LockExposure | QCamera::LockFocus | QCamera::LockWhiteBalance; + } + + bool canChangeProperty(PropertyChangeType changeType, QCamera::Status status) const + { + Q_UNUSED(status); + if (changeType == QCameraControl::ImageEncodingSettings && m_captureMode == QCamera::CaptureVideo) + return true; + else if (changeType== QCameraControl::VideoEncodingSettings) + return true; + else + return m_propertyChangesSupported; + } + + /* helper method to emit the signal error */ + void setError(QCamera::Error err, QString errorString) + { + emit error(err, errorString); + } + + /* helper method to emit the signal statusChaged */ + void setStatus(QCamera::Status newStatus) + { + m_status = newStatus; + emit statusChanged(newStatus); + } + + QCamera::State m_state; + QCamera::CaptureMode m_captureMode; + QCamera::Status m_status; + bool m_propertyChangesSupported; +}; + + + +#endif // MOCKCAMERACONTROL_H diff --git a/tests/auto/qmultimedia_common/mockcameraexposurecontrol.h b/tests/auto/qmultimedia_common/mockcameraexposurecontrol.h new file mode 100644 index 000000000..d89762d43 --- /dev/null +++ b/tests/auto/qmultimedia_common/mockcameraexposurecontrol.h @@ -0,0 +1,282 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +#ifndef MOCKCAMERAEXPOSURECONTROL_H +#define MOCKCAMERAEXPOSURECONTROL_H + +#include "qcameraexposurecontrol.h" + +class MockCameraExposureControl : public QCameraExposureControl +{ + Q_OBJECT +public: + MockCameraExposureControl(QObject *parent = 0): + QCameraExposureControl(parent), + m_aperture(2.8), + m_shutterSpeed(0.01), + m_isoSensitivity(100), + m_meteringMode(QCameraExposure::MeteringMatrix), + m_exposureCompensation(0), + m_exposureMode(QCameraExposure::ExposureAuto), + m_flashMode(QCameraExposure::FlashAuto) + { + m_isoRanges << 100 << 200 << 400 << 800; + m_apertureRanges << 2.8 << 4.0 << 5.6 << 8.0 << 11.0 << 16.0; + m_shutterRanges << 0.001 << 0.01 << 0.1 << 1.0; + m_exposureRanges << -2.0 << 2.0; + } + + ~MockCameraExposureControl() {} + + QCameraExposure::FlashModes flashMode() const {return m_flashMode;} + + void setFlashMode(QCameraExposure::FlashModes mode) + { + if (isFlashModeSupported(mode)) { + m_flashMode = mode; + } + } + + bool isFlashModeSupported(QCameraExposure::FlashModes mode) const + { + return mode & (QCameraExposure::FlashAuto | QCameraExposure::FlashOff | QCameraExposure::FlashOn); + } + + bool isFlashReady() const { return true;} + + QCameraExposure::ExposureMode exposureMode() const { return m_exposureMode; } + + void setExposureMode(QCameraExposure::ExposureMode mode) + { + if (isExposureModeSupported(mode)) + m_exposureMode = mode; + } + + //Setting the Exposure Mode Supported Enum values + bool isExposureModeSupported(QCameraExposure::ExposureMode mode) const + { + return ( mode == QCameraExposure::ExposureAuto || mode == QCameraExposure::ExposureManual || mode == QCameraExposure::ExposureBacklight || + mode == QCameraExposure::ExposureNight || mode == QCameraExposure::ExposureSpotlight ||mode == QCameraExposure::ExposureSports || + mode == QCameraExposure::ExposureSnow || mode == QCameraExposure:: ExposureLargeAperture ||mode == QCameraExposure::ExposureSmallAperture || + mode == QCameraExposure::ExposurePortrait || mode == QCameraExposure::ExposureModeVendor ||mode == QCameraExposure::ExposureBeach ); + } + + bool isParameterSupported(ExposureParameter parameter) const + { + switch (parameter) { + case QCameraExposureControl::ExposureCompensation: + case QCameraExposureControl::ISO: + case QCameraExposureControl::Aperture: + case QCameraExposureControl::ShutterSpeed: + return true; + default: + return false; + } + } + + QVariant exposureParameter(ExposureParameter parameter) const + { + switch (parameter) { + case QCameraExposureControl::ExposureCompensation: + return QVariant(m_exposureCompensation); + case QCameraExposureControl::ISO: + return QVariant(m_isoSensitivity); + case QCameraExposureControl::Aperture: + return QVariant(m_aperture); + case QCameraExposureControl::ShutterSpeed: + return QVariant(m_shutterSpeed); + default: + return QVariant(); + } + } + + QVariantList supportedParameterRange(ExposureParameter parameter) const + { + QVariantList res; + switch (parameter) { + case QCameraExposureControl::ExposureCompensation: + return m_exposureRanges; + case QCameraExposureControl::ISO: + return m_isoRanges; + case QCameraExposureControl::Aperture: + return m_apertureRanges; + case QCameraExposureControl::ShutterSpeed: + return m_shutterRanges; + default: + break; + } + + return res; + } + + ParameterFlags exposureParameterFlags(ExposureParameter parameter) const + { + ParameterFlags res = 0; + switch (parameter) { + case QCameraExposureControl::ExposureCompensation: + case QCameraExposureControl::Aperture: + case QCameraExposureControl::ShutterSpeed: + res |= ContinuousRange; + default: + break; + } + + return res; + } + + // Added exposureParameterChanged and exposureParameterRangeChanged signal + bool setExposureParameter(ExposureParameter parameter, const QVariant& value) + { + switch (parameter) { + case QCameraExposureControl::ExposureCompensation: + { + m_res.clear(); + m_res << -4.0 << 4.0; + qreal exposureCompensationlocal = qBound<qreal>(-2.0, value.toReal(), 2.0); + if (exposureParameter(parameter).toReal() != exposureCompensationlocal) { + m_exposureCompensation = exposureCompensationlocal; + emit exposureParameterChanged(parameter); + } + + if (m_exposureRanges.last().toReal() != m_res.last().toReal()) { + m_exposureRanges.clear(); + m_exposureRanges = m_res; + emit exposureParameterRangeChanged(parameter); + } + } + break; + case QCameraExposureControl::ISO: + { + m_res.clear(); + m_res << 20 << 50; + qreal exposureCompensationlocal = 100*qRound(qBound(100, value.toInt(), 800)/100.0); + if (exposureParameter(parameter).toReal() != exposureCompensationlocal) { + m_isoSensitivity = exposureCompensationlocal; + emit exposureParameterChanged(parameter); + } + + if (m_isoRanges.last().toInt() != m_res.last().toInt()) { + m_isoRanges.clear(); + m_isoRanges = m_res; + emit exposureParameterRangeChanged(parameter); + } + } + break; + case QCameraExposureControl::Aperture: + { + m_res.clear(); + m_res << 12.0 << 18.0 << 20.0; + qreal exposureCompensationlocal = qBound<qreal>(2.8, value.toReal(), 16.0); + if (exposureParameter(parameter).toReal() != exposureCompensationlocal) { + m_aperture = exposureCompensationlocal; + emit exposureParameterChanged(parameter); + } + + if (m_apertureRanges.last().toReal() != m_res.last().toReal()) { + m_apertureRanges.clear(); + m_apertureRanges = m_res; + emit exposureParameterRangeChanged(parameter); + } + } + break; + case QCameraExposureControl::ShutterSpeed: + { + m_res.clear(); + m_res << 0.12 << 1.0 << 2.0; + qreal exposureCompensationlocal = qBound<qreal>(0.001, value.toReal(), 1.0); + if (exposureParameter(parameter).toReal() != exposureCompensationlocal) { + m_shutterSpeed = exposureCompensationlocal; + emit exposureParameterChanged(parameter); + } + + if (m_shutterRanges.last().toReal() != m_res.last().toReal()) { + m_shutterRanges.clear(); + m_shutterRanges = m_res; + emit exposureParameterRangeChanged(parameter); + } + } + break; + default: + return false; + } + + emit flashReady(true); // depends on Flashcontrol + + return true; + } + + QString extendedParameterName(ExposureParameter) + { + return QString(); + } + + QCameraExposure::MeteringMode meteringMode() const + { + return m_meteringMode; + } + + void setMeteringMode(QCameraExposure::MeteringMode mode) + { + if (isMeteringModeSupported(mode)) + m_meteringMode = mode; + } + + //Setting the values for metering mode + bool isMeteringModeSupported(QCameraExposure::MeteringMode mode) const + { + return mode == QCameraExposure::MeteringAverage + || mode == QCameraExposure::MeteringMatrix + || mode == QCameraExposure::MeteringAverage + || mode ==QCameraExposure::MeteringSpot; + } + +private: + qreal m_aperture; + qreal m_shutterSpeed; + int m_isoSensitivity; + QCameraExposure::MeteringMode m_meteringMode; + qreal m_exposureCompensation; + QCameraExposure::ExposureMode m_exposureMode; + QCameraExposure::FlashModes m_flashMode; + QVariantList m_isoRanges,m_apertureRanges, m_shutterRanges, m_exposureRanges, m_res; +}; + +#endif // MOCKCAMERAEXPOSURECONTROL_H diff --git a/tests/auto/qmultimedia_common/mockcameraflashcontrol.h b/tests/auto/qmultimedia_common/mockcameraflashcontrol.h new file mode 100644 index 000000000..f7a795055 --- /dev/null +++ b/tests/auto/qmultimedia_common/mockcameraflashcontrol.h @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +#ifndef MOCKCAMERAFLASHCONTROL_H +#define MOCKCAMERAFLASHCONTROL_H + +#include "qcameraflashcontrol.h" + +class MockCameraFlashControl : public QCameraFlashControl +{ + Q_OBJECT +public: + MockCameraFlashControl(QObject *parent = 0): + QCameraFlashControl(parent), + m_flashMode(QCameraExposure::FlashAuto) + { + } + + ~MockCameraFlashControl() {} + + QCameraExposure::FlashModes flashMode() const + { + return m_flashMode; + } + + void setFlashMode(QCameraExposure::FlashModes mode) + { + if (isFlashModeSupported(mode)) { + m_flashMode = mode; + } + emit flashReady(true); + } + //Setting the values for Flash mode + + bool isFlashModeSupported(QCameraExposure::FlashModes mode) const + { + return (mode || (QCameraExposure::FlashAuto | QCameraExposure::FlashOff | QCameraExposure::FlashOn | + QCameraExposure::FlashFill |QCameraExposure::FlashTorch |QCameraExposure::FlashSlowSyncFrontCurtain | + QCameraExposure::FlashRedEyeReduction)); + } + + bool isFlashReady() const + { + return true; + } + +private: + QCameraExposure::FlashModes m_flashMode; +}; + +#endif // MOCKCAMERAFLASHCONTROL_H diff --git a/tests/auto/qmultimedia_common/mockcamerafocuscontrol.h b/tests/auto/qmultimedia_common/mockcamerafocuscontrol.h new file mode 100644 index 000000000..a0fb48199 --- /dev/null +++ b/tests/auto/qmultimedia_common/mockcamerafocuscontrol.h @@ -0,0 +1,199 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +#ifndef MOCKCAMERAFOCUSCONTROL_H +#define MOCKCAMERAFOCUSCONTROL_H + +#include "qcamerafocuscontrol.h" +#include "qcamerafocus.h" + +class MockCameraFocusControl : public QCameraFocusControl +{ + Q_OBJECT +public: + MockCameraFocusControl(QObject *parent = 0): + QCameraFocusControl(parent), + m_opticalZoom(1.0), + m_digitalZoom(1.0), + m_focusMode(QCameraFocus::AutoFocus), + m_focusPointMode(QCameraFocus::FocusPointAuto), + m_focusPoint(0.5, 0.5), + m_maxOpticalZoom(3.0), + m_maxDigitalZoom(4.0) + + { + m_zones << QCameraFocusZone(QRectF(0.45, 0.45, 0.1, 0.1)); + } + + ~MockCameraFocusControl() {} + + QCameraFocus::FocusMode focusMode() const + { + return m_focusMode; + } + + void setFocusMode(QCameraFocus::FocusMode mode) + { + if (isFocusModeSupported(mode)) + m_focusMode = mode; + } + + bool isFocusModeSupported(QCameraFocus::FocusMode mode) const + { + return mode == QCameraFocus::AutoFocus || mode == QCameraFocus::ContinuousFocus; + } + + qreal maximumOpticalZoom() const + { + return m_maxOpticalZoom; + } + + qreal maximumDigitalZoom() const + { + return m_maxDigitalZoom; + } + + qreal opticalZoom() const + { + return m_opticalZoom; + } + + qreal digitalZoom() const + { + return m_digitalZoom; + } + + void zoomTo(qreal optical, qreal digital) + { + optical = qBound<qreal>(1.0, optical, maximumOpticalZoom()); + digital = qBound<qreal>(1.0, digital, maximumDigitalZoom()); + + if (!qFuzzyCompare(digital, m_digitalZoom)) { + m_digitalZoom = digital; + emit digitalZoomChanged(m_digitalZoom); + } + + if (!qFuzzyCompare(optical, m_opticalZoom)) { + m_opticalZoom = optical; + emit opticalZoomChanged(m_opticalZoom); + } + + maxOpticalDigitalZoomChange(4.0, 5.0); + focusZonesChange(0.50, 0.50, 0.3, 0.3); + } + + QCameraFocus::FocusPointMode focusPointMode() const + { + return m_focusPointMode; + } + + void setFocusPointMode(QCameraFocus::FocusPointMode mode) + { + if (isFocusPointModeSupported(mode)) + m_focusPointMode = mode; + } + + bool isFocusPointModeSupported(QCameraFocus::FocusPointMode mode) const + { + switch (mode) { + case QCameraFocus::FocusPointAuto: + case QCameraFocus::FocusPointCenter: + case QCameraFocus::FocusPointCustom: + return true; + default: + return false; + } + } + + QPointF customFocusPoint() const + { + return m_focusPoint; + } + + void setCustomFocusPoint(const QPointF &point) + { + m_focusPoint = point; + } + + QCameraFocusZoneList focusZones() const + { + return m_zones; + } + + // helper function to emit maximum Optical and Digital Zoom Changed signals + void maxOpticalDigitalZoomChange(qreal maxOptical, qreal maxDigital) + { + if (maxOptical != m_maxOpticalZoom) { + m_maxOpticalZoom = maxOptical; + emit maximumOpticalZoomChanged(m_maxOpticalZoom); + } + + if (maxDigital != m_maxDigitalZoom) { + m_maxDigitalZoom = maxDigital; + emit maximumDigitalZoomChanged(m_maxDigitalZoom); + } + } + + // helper function to emit Focus Zones Changed signals + void focusZonesChange(qreal left, qreal top, qreal width, qreal height) + { + QCameraFocusZone myZone(QRectF(left, top, width, height)); + if (m_zones.last().area() != myZone.area()) { + m_zones.clear(); + m_zones << myZone; + emit focusZonesChanged(); + } + } + +private: + qreal m_opticalZoom; + qreal m_digitalZoom; + QCameraFocus::FocusMode m_focusMode; + QCameraFocus::FocusPointMode m_focusPointMode; + QPointF m_focusPoint; + // to emit maximum Optical and Digital Zoom Changed signals + qreal m_maxOpticalZoom; + qreal m_maxDigitalZoom; + // to emit focus zone changed signal + QCameraFocusZoneList m_zones; +}; + +#endif // MOCKCAMERAFOCUSCONTROL_H diff --git a/tests/auto/qmultimedia_common/mockcameraimagecapturecontrol.h b/tests/auto/qmultimedia_common/mockcameraimagecapturecontrol.h new file mode 100644 index 000000000..78681be80 --- /dev/null +++ b/tests/auto/qmultimedia_common/mockcameraimagecapturecontrol.h @@ -0,0 +1,130 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +#ifndef MOCKCAMERACAPTURECONTROL_H +#define MOCKCAMERACAPTURECONTROL_H + +#include <QDateTime> +#include <QTimer> + +#include "qcameraimagecapturecontrol.h" +#include "qcameracontrol.h" +#include "mockcameracontrol.h" + +class MockCaptureControl : public QCameraImageCaptureControl +{ + Q_OBJECT +public: + MockCaptureControl(MockCameraControl *cameraControl, QObject *parent = 0) + : QCameraImageCaptureControl(parent), m_cameraControl(cameraControl), m_captureRequest(0), m_ready(true), m_captureCanceled(false) + { + } + + ~MockCaptureControl() + { + } + + QCameraImageCapture::DriveMode driveMode() const { return QCameraImageCapture::SingleImageCapture; } + void setDriveMode(QCameraImageCapture::DriveMode) {} + + bool isReadyForCapture() const { return m_ready && m_cameraControl->state() == QCamera::ActiveState; } + + int capture(const QString &fileName) + { + if (isReadyForCapture()) { + m_fileName = fileName; + m_captureRequest++; + emit readyForCaptureChanged(m_ready = false); + QTimer::singleShot(5, this, SLOT(captured())); + return m_captureRequest; + } else { + emit error(-1, QCameraImageCapture::NotReadyError, + QLatin1String("Could not capture in stopped state")); + } + + return -1; + } + + void cancelCapture() + { + m_captureCanceled = true; + } + +private Q_SLOTS: + void captured() + { + if (!m_captureCanceled) { + emit imageCaptured(m_captureRequest, QImage()); + + emit imageMetadataAvailable(m_captureRequest, + QtMultimediaKit::FocalLengthIn35mmFilm, + QVariant(50)); + + emit imageMetadataAvailable(m_captureRequest, + QtMultimediaKit::DateTimeOriginal, + QVariant(QDateTime::currentDateTime())); + + emit imageMetadataAvailable(m_captureRequest, + QLatin1String("Answer to the Ultimate Question of Life, the Universe, and Everything"), + QVariant(42)); + } + + if (!m_ready) + { + emit readyForCaptureChanged(m_ready = true); + emit imageExposed(m_captureRequest); + } + + if (!m_captureCanceled) + emit imageSaved(m_captureRequest, m_fileName); + + m_captureCanceled = false; + } + +private: + MockCameraControl *m_cameraControl; + QString m_fileName; + int m_captureRequest; + bool m_ready; + bool m_captureCanceled; +}; + +#endif // MOCKCAMERACAPTURECONTROL_H diff --git a/tests/auto/qmultimedia_common/mockcameraimageprocessingcontrol.h b/tests/auto/qmultimedia_common/mockcameraimageprocessingcontrol.h new file mode 100644 index 000000000..f02f2b404 --- /dev/null +++ b/tests/auto/qmultimedia_common/mockcameraimageprocessingcontrol.h @@ -0,0 +1,156 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +#ifndef MOCKCAMERAIMAGEPROCESSINGCONTROL_H +#define MOCKCAMERAIMAGEPROCESSINGCONTROL_H + +#include "qcameraimageprocessingcontrol.h" + +class MockImageProcessingControl : public QCameraImageProcessingControl +{ + Q_OBJECT +public: + MockImageProcessingControl(QObject *parent = 0) + : QCameraImageProcessingControl(parent) + { + m_supportedWhiteBalance.insert(QCameraImageProcessing::WhiteBalanceAuto); + } + + QCameraImageProcessing::WhiteBalanceMode whiteBalanceMode() const + { + return m_whiteBalanceMode; + } + void setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceMode mode) + { + m_whiteBalanceMode = mode; + } + + bool isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceMode mode) const + { + return m_supportedWhiteBalance.contains(mode); + } + + void setSupportedWhiteBalanceModes(QSet<QCameraImageProcessing::WhiteBalanceMode> modes) + { + m_supportedWhiteBalance = modes; + } + + bool isProcessingParameterSupported(ProcessingParameter parameter) const + { + //return parameter == Contrast || parameter == Sharpening || parameter == ColorTemperature; + switch (parameter) + { + case Contrast: + case Brightness: + case Sharpening: + case Saturation: + case Denoising: + case ColorTemperature: + case ExtendedParameter: + return true; + default : + return false; + } + } + QVariant processingParameter(ProcessingParameter parameter) const + { + switch (parameter) { + case Contrast: + return m_contrast; + case Saturation: + return m_saturation; + case Brightness: + return m_brightness; + case Sharpening: + return m_sharpeningLevel; + case Denoising: + return m_denoising; + case ColorTemperature: + return m_manualWhiteBalance; + case ExtendedParameter: + return m_extendedParameter; + default: + return QVariant(); + } + } + void setProcessingParameter(ProcessingParameter parameter, QVariant value) + { + switch (parameter) { + case Contrast: + m_contrast = value; + break; + case Saturation: + m_saturation = value; + break; + case Brightness: + m_brightness = value; + break; + case Sharpening: + m_sharpeningLevel = value; + break; + case Denoising: + m_denoising = value; + break; + case ColorTemperature: + m_manualWhiteBalance = value; + break; + case ExtendedParameter: + m_extendedParameter = value; + break; + default: + break; + } + } + + +private: + QCameraImageProcessing::WhiteBalanceMode m_whiteBalanceMode; + QSet<QCameraImageProcessing::WhiteBalanceMode> m_supportedWhiteBalance; + QVariant m_manualWhiteBalance; + QVariant m_contrast; + QVariant m_sharpeningLevel; + QVariant m_saturation; + QVariant m_brightness; + QVariant m_denoising; + QVariant m_extendedParameter; +}; + +#endif // MOCKCAMERAIMAGEPROCESSINGCONTROL_H diff --git a/tests/auto/qmultimedia_common/mockcameralockscontrol.h b/tests/auto/qmultimedia_common/mockcameralockscontrol.h new file mode 100644 index 000000000..87c40947d --- /dev/null +++ b/tests/auto/qmultimedia_common/mockcameralockscontrol.h @@ -0,0 +1,144 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +#ifndef MOCKCAMERALOCKCONTROL_H +#define MOCKCAMERALOCKCONTROL_H + +#include <QTimer> +#include "qcameralockscontrol.h" + +class MockCameraLocksControl : public QCameraLocksControl +{ + Q_OBJECT +public: + MockCameraLocksControl(QObject *parent = 0): + QCameraLocksControl(parent), + m_focusLock(QCamera::Unlocked), + m_exposureLock(QCamera::Unlocked) + { + } + + ~MockCameraLocksControl() {} + + QCamera::LockTypes supportedLocks() const + { + return QCamera::LockExposure | QCamera::LockFocus; + } + + QCamera::LockStatus lockStatus(QCamera::LockType lock) const + { + switch (lock) { + case QCamera::LockExposure: + return m_exposureLock; + case QCamera::LockFocus: + return m_focusLock; + default: + return QCamera::Unlocked; + } + } + + void searchAndLock(QCamera::LockTypes locks) + { + if (locks & QCamera::LockExposure) { + QCamera::LockStatus newStatus = locks & QCamera::LockFocus ? QCamera::Searching : QCamera::Locked; + + if (newStatus != m_exposureLock) + emit lockStatusChanged(QCamera::LockExposure, + m_exposureLock = newStatus, + QCamera::UserRequest); + } + + if (locks & QCamera::LockFocus) { + emit lockStatusChanged(QCamera::LockFocus, + m_focusLock = QCamera::Searching, + QCamera::UserRequest); + + QTimer::singleShot(5, this, SLOT(focused())); + } + } + + void unlock(QCamera::LockTypes locks) { + if (locks & QCamera::LockFocus && m_focusLock != QCamera::Unlocked) { + emit lockStatusChanged(QCamera::LockFocus, + m_focusLock = QCamera::Unlocked, + QCamera::UserRequest); + } + + if (locks & QCamera::LockExposure && m_exposureLock != QCamera::Unlocked) { + emit lockStatusChanged(QCamera::LockExposure, + m_exposureLock = QCamera::Unlocked, + QCamera::UserRequest); + } + } + + /* helper method to emit the signal with LockChangeReason */ + void setLockChangeReason (QCamera::LockChangeReason lockChangeReason) + { + emit lockStatusChanged(QCamera::NoLock, + QCamera::Unlocked, + lockChangeReason); + + } + +private slots: + void focused() + { + if (m_focusLock == QCamera::Searching) { + emit lockStatusChanged(QCamera::LockFocus, + m_focusLock = QCamera::Locked, + QCamera::UserRequest); + } + + if (m_exposureLock == QCamera::Searching) { + emit lockStatusChanged(QCamera::LockExposure, + m_exposureLock = QCamera::Locked, + QCamera::UserRequest); + } + } + + +private: + QCamera::LockStatus m_focusLock; + QCamera::LockStatus m_exposureLock; +}; + + +#endif // MOCKCAMERALOCKCONTROL_H diff --git a/tests/auto/qmultimedia_common/mockcameraservice.h b/tests/auto/qmultimedia_common/mockcameraservice.h new file mode 100644 index 000000000..591745b51 --- /dev/null +++ b/tests/auto/qmultimedia_common/mockcameraservice.h @@ -0,0 +1,184 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +#ifndef MOCKCAMERASERVICE_H +#define MOCKCAMERASERVICE_H + +#include "qmediaservice.h" +#include "../qmultimedia_common/mockcameraflashcontrol.h" +#include "../qmultimedia_common/mockcameralockscontrol.h" +#include "../qmultimedia_common/mockcamerafocuscontrol.h" +#include "../qmultimedia_common/mockcameraimageprocessingcontrol.h" +#include "../qmultimedia_common/mockcameraimagecapturecontrol.h" +#include "../qmultimedia_common/mockcameraexposurecontrol.h" +#include "../qmultimedia_common/mockcameracapturedestinationcontrol.h" +#include "../qmultimedia_common/mockcameracapturebuffercontrol.h" +#include "../qmultimedia_common/mockimageencodercontrol.h" +#include "../qmultimedia_common/mockcameracontrol.h" +#include "../qmultimedia_common/mockvideosurface.h" +#include "../qmultimedia_common/mockvideorenderercontrol.h" +#include "../qmultimedia_common/mockvideowindowcontrol.h" + +class MockSimpleCameraService : public QMediaService +{ + Q_OBJECT + +public: + MockSimpleCameraService(): QMediaService(0) + { + mockControl = new MockCameraControl(this); + } + + ~MockSimpleCameraService() + { + } + + QMediaControl* requestControl(const char *iid) + { + if (qstrcmp(iid, QCameraControl_iid) == 0) + return mockControl; + return 0; + } + + void releaseControl(QMediaControl*) {} + + MockCameraControl *mockControl; +}; + + +class MockCameraService : public QMediaService +{ + Q_OBJECT + +public: + MockCameraService(): QMediaService(0) + { + mockControl = new MockCameraControl(this); + mockLocksControl = new MockCameraLocksControl(this); + mockExposureControl = new MockCameraExposureControl(this); + mockFlashControl = new MockCameraFlashControl(this); + mockFocusControl = new MockCameraFocusControl(this); + mockCaptureControl = new MockCaptureControl(mockControl, this); + mockCaptureBufferControl = new MockCaptureBufferFormatControl(this); + mockCaptureDestinationControl = new MockCaptureDestinationControl(this); + mockImageProcessingControl = new MockImageProcessingControl(this); + mockImageEncoderControl = new MockImageEncoderControl(this); + rendererControl = new MockVideoRendererControl(this); + windowControl = new MockVideoWindowControl(this); + rendererRef = 0; + windowRef = 0; + } + + ~MockCameraService() + { + } + + QMediaControl* requestControl(const char *iid) + { + if (qstrcmp(iid, QCameraControl_iid) == 0) + return mockControl; + + if (qstrcmp(iid, QCameraLocksControl_iid) == 0) + return mockLocksControl; + + if (qstrcmp(iid, QCameraExposureControl_iid) == 0) + return mockExposureControl; + + if (qstrcmp(iid, QCameraFlashControl_iid) == 0) + return mockFlashControl; + + if (qstrcmp(iid, QCameraFocusControl_iid) == 0) + return mockFocusControl; + + if (qstrcmp(iid, QCameraImageCaptureControl_iid) == 0) + return mockCaptureControl; + + if (qstrcmp(iid, QCameraCaptureBufferFormatControl_iid) == 0) + return mockCaptureBufferControl; + + if (qstrcmp(iid, QCameraCaptureDestinationControl_iid) == 0) + return mockCaptureDestinationControl; + + if (qstrcmp(iid, QCameraImageProcessingControl_iid) == 0) + return mockImageProcessingControl; + + if (qstrcmp(iid, QImageEncoderControl_iid) == 0) + return mockImageEncoderControl; + + if (qstrcmp(iid, QVideoRendererControl_iid) == 0) { + if (rendererRef == 0) { + rendererRef += 1; + return rendererControl; + } + } else if (qstrcmp(iid, QVideoWindowControl_iid) == 0) { + if (windowRef == 0) { + windowRef += 1; + return windowControl; + } + } + return 0; + } + + void releaseControl(QMediaControl *control) + { + if (control == rendererControl) + rendererRef -= 1; + else if (control == windowControl) + windowRef -= 1; + } + + MockCameraControl *mockControl; + MockCameraLocksControl *mockLocksControl; + MockCaptureControl *mockCaptureControl; + MockCaptureBufferFormatControl *mockCaptureBufferControl; + MockCaptureDestinationControl *mockCaptureDestinationControl; + MockCameraExposureControl *mockExposureControl; + MockCameraFlashControl *mockFlashControl; + MockCameraFocusControl *mockFocusControl; + MockImageProcessingControl *mockImageProcessingControl; + MockImageEncoderControl *mockImageEncoderControl; + MockVideoRendererControl *rendererControl; + MockVideoWindowControl *windowControl; + int rendererRef; + int windowRef; +}; + +#endif // MOCKCAMERASERVICE_H diff --git a/tests/auto/qmultimedia_common/mockcontainer.pri b/tests/auto/qmultimedia_common/mockcontainer.pri new file mode 100644 index 000000000..e4a345adb --- /dev/null +++ b/tests/auto/qmultimedia_common/mockcontainer.pri @@ -0,0 +1,7 @@ +INCLUDEPATH *= $$PWD \ + ../../../src/multimedia \ + +HEADERS *= \ + ../qmultimedia_common/mockmediacontainercontrol.h \ + ../qmultimedia_common/mockmetadatawritercontrol.h \ + ../qmultimedia_common/mockmetadatareadercontrol.h diff --git a/tests/auto/qmultimedia_common/mockimageencodercontrol.h b/tests/auto/qmultimedia_common/mockimageencodercontrol.h new file mode 100644 index 000000000..0e9d7f38f --- /dev/null +++ b/tests/auto/qmultimedia_common/mockimageencodercontrol.h @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +#ifndef MOCKIMAGEENCODERCONTROL_H +#define MOCKIMAGEENCODERCONTROL_H + +#include "qimageencodercontrol.h" + +class MockImageEncoderControl : public QImageEncoderControl +{ +public: + MockImageEncoderControl(QObject *parent = 0) + : QImageEncoderControl(parent) + { + m_settings = QImageEncoderSettings(); + } + + QList<QSize> supportedResolutions(const QImageEncoderSettings & settings = QImageEncoderSettings(), + bool *continuous = 0) const + { + if (continuous) + *continuous = true; + + QList<QSize> resolutions; + if (settings.resolution().isValid()) { + if (settings.resolution() == QSize(160,160) || + settings.resolution() == QSize(320,240)) + resolutions << settings.resolution(); + + if (settings.quality() == QtMultimediaKit::HighQuality && settings.resolution() == QSize(640,480)) + resolutions << settings.resolution(); + } else { + resolutions << QSize(160, 120); + resolutions << QSize(320, 240); + if (settings.quality() == QtMultimediaKit::HighQuality) + resolutions << QSize(640, 480); + } + + return resolutions; + } + + QStringList supportedImageCodecs() const + { + QStringList codecs; + codecs << "PNG" << "JPEG"; + return codecs; + } + + QString imageCodecDescription(const QString &codecName) const { + if (codecName == "PNG") + return QString("Portable Network Graphic"); + if (codecName == "JPEG") + return QString("Joint Photographic Expert Group"); + return QString(); + } + + QImageEncoderSettings imageSettings() const { return m_settings; } + void setImageSettings(const QImageEncoderSettings &settings) { m_settings = settings; } + +private: + QImageEncoderSettings m_settings; +}; + + +#endif // MOCKIMAGEENCODERCONTROL_H diff --git a/tests/auto/qmultimedia_common/mockmediacontainercontrol.h b/tests/auto/qmultimedia_common/mockmediacontainercontrol.h new file mode 100644 index 000000000..2a8832de2 --- /dev/null +++ b/tests/auto/qmultimedia_common/mockmediacontainercontrol.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +#ifndef MOCKMEDIACONTAINERCONTROL_H +#define MOCKMEDIACONTAINERCONTROL_H + +#include <QObject> +#include "qmediacontainercontrol.h" +#include <QMap> +#include <QString> +#include <QStringList> + +QT_USE_NAMESPACE +class MockMediaContainerControl : public QMediaContainerControl +{ + Q_OBJECT +public: + MockMediaContainerControl(QObject *parent): + QMediaContainerControl(parent) + { + m_supportedContainers.append("wav"); + m_supportedContainers.append("mp3"); + m_supportedContainers.append("mov"); + + m_descriptions.insert("wav", "WAV format"); + m_descriptions.insert("mp3", "MP3 format"); + m_descriptions.insert("mov", "MOV format"); + } + + virtual ~MockMediaContainerControl() {}; + + QStringList supportedContainers() const + { + return m_supportedContainers; + } + + QString containerMimeType() const + { + return m_format; + } + + void setContainerMimeType(const QString &formatMimeType) + { + if (m_supportedContainers.contains(formatMimeType)) + m_format = formatMimeType; + } + + QString containerDescription(const QString &formatMimeType) const + { + return m_descriptions.value(formatMimeType); + } + +private: + QStringList m_supportedContainers; + QMap<QString, QString> m_descriptions; + QString m_format; +}; + +#endif // MOCKMEDIACONTAINERCONTROL_H diff --git a/tests/auto/qmultimedia_common/mockmedianetworkaccesscontrol.h b/tests/auto/qmultimedia_common/mockmedianetworkaccesscontrol.h new file mode 100644 index 000000000..472a30fc7 --- /dev/null +++ b/tests/auto/qmultimedia_common/mockmedianetworkaccesscontrol.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +#ifndef MOCKMEDIANETWORKACCESSCONTROL_H +#define MOCKMEDIANETWORKACCESSCONTROL_H + +#include "qmedianetworkaccesscontrol.h" +#include "qnetworkconfiguration.h" + +class MockNetworkAccessControl : public QMediaNetworkAccessControl +{ + friend class MockMediaPlayerService; + +public: + MockNetworkAccessControl() {} + ~MockNetworkAccessControl() {} + + void setConfigurations(const QList<QNetworkConfiguration> &configurations) + { + _configurations = configurations; + _current = QNetworkConfiguration(); + } + + QNetworkConfiguration currentConfiguration() const + { + return _current; + } + +private: + void setCurrentConfiguration(QNetworkConfiguration configuration) + { + if (_configurations.contains(configuration)) + emit configurationChanged(_current = configuration); + else + emit configurationChanged(_current = QNetworkConfiguration()); + } + + QList<QNetworkConfiguration> _configurations; + QNetworkConfiguration _current; +}; + +Q_DECLARE_METATYPE(QNetworkConfiguration) + + +#endif // MOCKMEDIANETWORKACCESSCONTROL_H diff --git a/tests/auto/qmultimedia_common/mockmediaobject.h b/tests/auto/qmultimedia_common/mockmediaobject.h new file mode 100644 index 000000000..fcc5c3731 --- /dev/null +++ b/tests/auto/qmultimedia_common/mockmediaobject.h @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +#ifndef MOCKMEDIAOBJECT_H +#define MOCKMEDIAOBJECT_H + +#include "qmediaobject.h" + +class MockMediaObject : public QMediaObject +{ + Q_OBJECT +public: + MockMediaObject(QObject *parent, QMediaService *service): + QMediaObject(parent, service) + { + } +}; + +#endif // MOCKMEDIAOBJECT_H diff --git a/tests/auto/qmultimedia_common/mockmediaplayercontrol.h b/tests/auto/qmultimedia_common/mockmediaplayercontrol.h new file mode 100644 index 000000000..d88409ca5 --- /dev/null +++ b/tests/auto/qmultimedia_common/mockmediaplayercontrol.h @@ -0,0 +1,118 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +#ifndef MOCKMEDIAPLAYERCONTROL_H +#define MOCKMEDIAPLAYERCONTROL_H + +#include "qmediaplayercontrol.h" + +class MockMediaPlayerControl : public QMediaPlayerControl +{ + friend class MockMediaPlayerService; + +public: + MockMediaPlayerControl():QMediaPlayerControl(0) {} + + QMediaPlayer::State state() const { return _state; } + QMediaPlayer::MediaStatus mediaStatus() const { return _mediaStatus; } + + qint64 duration() const { return _duration; } + + qint64 position() const { return _position; } + + void setPosition(qint64 position) { if (position != _position) emit positionChanged(_position = position); } + + int volume() const { return _volume; } + void setVolume(int volume) { emit volumeChanged(_volume = volume); } + + bool isMuted() const { return _muted; } + void setMuted(bool muted) { if (muted != _muted) emit mutedChanged(_muted = muted); } + + int bufferStatus() const { return _bufferStatus; } + + bool isAudioAvailable() const { return _audioAvailable; } + bool isVideoAvailable() const { return _videoAvailable; } + + bool isSeekable() const { return _isSeekable; } + QMediaTimeRange availablePlaybackRanges() const { return QMediaTimeRange(_seekRange.first, _seekRange.second); } + void setSeekRange(qint64 minimum, qint64 maximum) { _seekRange = qMakePair(minimum, maximum); } + + qreal playbackRate() const { return _playbackRate; } + void setPlaybackRate(qreal rate) { if (rate != _playbackRate) emit playbackRateChanged(_playbackRate = rate); } + + QMediaContent media() const { return _media; } + void setMedia(const QMediaContent &content, QIODevice *stream) + { + _stream = stream; + _media = content; + if (_state != QMediaPlayer::StoppedState) { + _mediaStatus = _media.isNull() ? QMediaPlayer::NoMedia : QMediaPlayer::LoadingMedia; + emit stateChanged(_state = QMediaPlayer::StoppedState); + emit mediaStatusChanged(_mediaStatus); + } + emit mediaChanged(_media = content); + } + QIODevice *mediaStream() const { return _stream; } + + void play() { if (_isValid && !_media.isNull() && _state != QMediaPlayer::PlayingState) emit stateChanged(_state = QMediaPlayer::PlayingState); } + void pause() { if (_isValid && !_media.isNull() && _state != QMediaPlayer::PausedState) emit stateChanged(_state = QMediaPlayer::PausedState); } + void stop() { if (_state != QMediaPlayer::StoppedState) emit stateChanged(_state = QMediaPlayer::StoppedState); } + + QMediaPlayer::State _state; + QMediaPlayer::MediaStatus _mediaStatus; + QMediaPlayer::Error _error; + qint64 _duration; + qint64 _position; + int _volume; + bool _muted; + int _bufferStatus; + bool _audioAvailable; + bool _videoAvailable; + bool _isSeekable; + QPair<qint64, qint64> _seekRange; + qreal _playbackRate; + QMediaContent _media; + QIODevice *_stream; + bool _isValid; + QString _errorString; +}; + +#endif // MOCKMEDIAPLAYERCONTROL_H diff --git a/tests/auto/qmultimedia_common/mockmediaplayerservice.h b/tests/auto/qmultimedia_common/mockmediaplayerservice.h new file mode 100644 index 000000000..ac1e32bc6 --- /dev/null +++ b/tests/auto/qmultimedia_common/mockmediaplayerservice.h @@ -0,0 +1,164 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +#ifndef MOCKPLAYERSERVICE_H +#define MOCKPLAYERSERVICE_H + +#include "qmediaservice.h" + +#include "mockmediaplayercontrol.h" +#include "mockmediastreamscontrol.h" +#include "mockmedianetworkaccesscontrol.h" +#include "mockvideorenderercontrol.h" +#include "mockvideowindowcontrol.h" + +class MockMediaPlayerService : public QMediaService +{ + Q_OBJECT + +public: + MockMediaPlayerService():QMediaService(0) + { + mockControl = new MockMediaPlayerControl; + mockStreamsControl = new MockStreamsControl; + mockNetworkControl = new MockNetworkAccessControl; + rendererControl = new MockVideoRendererControl; + windowControl = new MockVideoWindowControl; + rendererRef = 0; + windowRef = 0; + } + + ~MockMediaPlayerService() + { + delete mockControl; + delete mockStreamsControl; + delete mockNetworkControl; + delete rendererControl; + delete windowControl; + } + + QMediaControl* requestControl(const char *iid) + { + if (qstrcmp(iid, QMediaPlayerControl_iid) == 0) { + return mockControl; + } else if (qstrcmp(iid, QVideoRendererControl_iid) == 0) { + if (rendererRef == 0) { + rendererRef += 1; + return rendererControl; + } + } else if (qstrcmp(iid, QVideoWindowControl_iid) == 0) { + if (windowRef == 0) { + windowRef += 1; + return windowControl; + } + } + + + if (qstrcmp(iid, QMediaNetworkAccessControl_iid) == 0) + return mockNetworkControl; + return 0; + } + + void releaseControl(QMediaControl *control) + { + if (control == rendererControl) + rendererRef -= 1; + else if (control == windowControl) + windowRef -= 1; + } + + void setState(QMediaPlayer::State state) { emit mockControl->stateChanged(mockControl->_state = state); } + void setState(QMediaPlayer::State state, QMediaPlayer::MediaStatus status) { + mockControl->_state = state; + mockControl->_mediaStatus = status; + emit mockControl->mediaStatusChanged(status); + emit mockControl->stateChanged(state); + } + void setMediaStatus(QMediaPlayer::MediaStatus status) { emit mockControl->mediaStatusChanged(mockControl->_mediaStatus = status); } + void setIsValid(bool isValid) { mockControl->_isValid = isValid; } + void setMedia(QMediaContent media) { mockControl->_media = media; } + void setDuration(qint64 duration) { mockControl->_duration = duration; } + void setPosition(qint64 position) { mockControl->_position = position; } + void setSeekable(bool seekable) { mockControl->_isSeekable = seekable; } + void setVolume(int volume) { mockControl->_volume = volume; } + void setMuted(bool muted) { mockControl->_muted = muted; } + void setVideoAvailable(bool videoAvailable) { mockControl->_videoAvailable = videoAvailable; } + void setBufferStatus(int bufferStatus) { mockControl->_bufferStatus = bufferStatus; } + void setPlaybackRate(qreal playbackRate) { mockControl->_playbackRate = playbackRate; } + void setError(QMediaPlayer::Error error) { mockControl->_error = error; emit mockControl->error(mockControl->_error, mockControl->_errorString); } + void setErrorString(QString errorString) { mockControl->_errorString = errorString; emit mockControl->error(mockControl->_error, mockControl->_errorString); } + + void selectCurrentConfiguration(QNetworkConfiguration config) { mockNetworkControl->setCurrentConfiguration(config); } + + void reset() + { + mockControl->_state = QMediaPlayer::StoppedState; + mockControl->_mediaStatus = QMediaPlayer::UnknownMediaStatus; + mockControl->_error = QMediaPlayer::NoError; + mockControl->_duration = 0; + mockControl->_position = 0; + mockControl->_volume = 0; + mockControl->_muted = false; + mockControl->_bufferStatus = 0; + mockControl->_videoAvailable = false; + mockControl->_isSeekable = false; + mockControl->_playbackRate = 0.0; + mockControl->_media = QMediaContent(); + mockControl->_stream = 0; + mockControl->_isValid = false; + mockControl->_errorString = QString(); + + mockNetworkControl->_current = QNetworkConfiguration(); + mockNetworkControl->_configurations = QList<QNetworkConfiguration>(); + } + + MockMediaPlayerControl *mockControl; + MockStreamsControl *mockStreamsControl; + MockNetworkAccessControl *mockNetworkControl; + MockVideoRendererControl *rendererControl; + MockVideoWindowControl *windowControl; + int rendererRef; + int windowRef; +}; + + + +#endif // MOCKPLAYERSERVICE_H diff --git a/tests/auto/qmultimedia_common/mockmediaplaylistcontrol.h b/tests/auto/qmultimedia_common/mockmediaplaylistcontrol.h new file mode 100644 index 000000000..186db69f1 --- /dev/null +++ b/tests/auto/qmultimedia_common/mockmediaplaylistcontrol.h @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +#ifndef MOCKMEDIAPLAYLISTCONTROL_H +#define MOCKMEDIAPLAYLISTCONTROL_H + +#include "qmediaplaylistcontrol.h" +#include "qmediaplaylistnavigator.h" + +#include "mockreadonlyplaylistprovider.h" + +// Hmm, read only. +class MockMediaPlaylistControl : public QMediaPlaylistControl +{ + Q_OBJECT +public: + MockMediaPlaylistControl(QObject *parent) : QMediaPlaylistControl(parent) + { + m_navigator = new QMediaPlaylistNavigator(new MockReadOnlyPlaylistProvider(this), this); + } + + ~MockMediaPlaylistControl() + { + } + + QMediaPlaylistProvider* playlistProvider() const { return m_navigator->playlist(); } + bool setPlaylistProvider(QMediaPlaylistProvider *newProvider) + { + bool bMediaContentChanged = false; + int i = 0; + for (; i < playlistProvider()->mediaCount(); i++) { + if (playlistProvider()->media(i).canonicalUrl().toString() != newProvider->media(i).canonicalUrl().toString()) { + bMediaContentChanged = true; + break; + } + } + + if (playlistProvider()->mediaCount() != newProvider->mediaCount() || bMediaContentChanged ) { + emit playlistProviderChanged(); + emit currentMediaChanged(newProvider->media(i)); + } + + m_navigator->setPlaylist(newProvider); + return true; + } + + int currentIndex() const { return m_navigator->currentIndex(); } + void setCurrentIndex(int position) + { + if (position != currentIndex()) + emit currentIndexChanged(position); + m_navigator->jump(position); + } + + int nextIndex(int steps) const { return m_navigator->nextIndex(steps); } + int previousIndex(int steps) const { return m_navigator->previousIndex(steps); } + + void next() { m_navigator->next(); } + void previous() { m_navigator->previous(); } + + QMediaPlaylist::PlaybackMode playbackMode() const { return m_navigator->playbackMode(); } + void setPlaybackMode(QMediaPlaylist::PlaybackMode mode) + { + if (playbackMode() != mode) + emit playbackModeChanged(mode); + + m_navigator->setPlaybackMode(mode); + } + +private: + QMediaPlaylistNavigator *m_navigator; +}; + +#endif // MOCKMEDIAPLAYLISTCONTROL_H diff --git a/tests/auto/qmultimedia_common/mockmediaplaylistsourcecontrol.h b/tests/auto/qmultimedia_common/mockmediaplaylistsourcecontrol.h new file mode 100644 index 000000000..c43ef9b5d --- /dev/null +++ b/tests/auto/qmultimedia_common/mockmediaplaylistsourcecontrol.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +#ifndef MOCKMEDIAPLAYLISTSOURCECONTROL_H +#define MOCKMEDIAPLAYLISTSOURCECONTROL_H + +#include "qmediaplaylistsourcecontrol.h" + +class MockPlaylistSourceControl : public QMediaPlaylistSourceControl +{ + Q_OBJECT +public: + MockPlaylistSourceControl(QObject *parent) + : QMediaPlaylistSourceControl(parent), + m_playlist(0) + { + } + + ~MockPlaylistSourceControl() + { + } + + void setPlaylist(QMediaPlaylist *playlist) + { + m_playlist = playlist; + } + + QMediaPlaylist *playlist() const + { + return m_playlist; + } +private: + QMediaPlaylist *m_playlist; +}; + +#endif // MOCKMEDIAPLAYLISTSOURCECONTROL_H diff --git a/tests/auto/qmultimedia_common/mockmediarecordercontrol.h b/tests/auto/qmultimedia_common/mockmediarecordercontrol.h new file mode 100644 index 000000000..77c1378a8 --- /dev/null +++ b/tests/auto/qmultimedia_common/mockmediarecordercontrol.h @@ -0,0 +1,125 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +#ifndef MOCKRECORDERCONTROL_H +#define MOCKRECORDERCONTROL_H + +#include <QUrl> + +#include "qmediarecordercontrol.h" + +class MockMediaRecorderControl : public QMediaRecorderControl +{ + Q_OBJECT + +public: + MockMediaRecorderControl(QObject *parent = 0): + QMediaRecorderControl(parent), + m_state(QMediaRecorder::StoppedState), + m_position(0), + m_muted(false) {} + + QUrl outputLocation() const + { + return m_sink; + } + + bool setOutputLocation(const QUrl &sink) + { + m_sink = sink; + return true; + } + + QMediaRecorder::State state() const + { + return m_state; + } + + qint64 duration() const + { + return m_position; + } + + bool isMuted() const + { + return m_muted; + } + + void applySettings() {} + + using QMediaRecorderControl::error; + +public slots: + void record() + { + m_state = QMediaRecorder::RecordingState; + m_position=1; + emit stateChanged(m_state); + emit durationChanged(m_position); + } + + void pause() + { + m_state = QMediaRecorder::PausedState; + emit stateChanged(m_state); + } + + void stop() + { + m_position=0; + m_state = QMediaRecorder::StoppedState; + emit stateChanged(m_state); + } + + void setMuted(bool muted) + { + if (m_muted != muted) + emit mutedChanged(m_muted = muted); + } + +public: + QUrl m_sink; + QMediaRecorder::State m_state; + qint64 m_position; + bool m_muted; +}; + +#endif // MOCKRECORDERCONTROL_H diff --git a/tests/auto/qmultimedia_common/mockmediarecorderservice.h b/tests/auto/qmultimedia_common/mockmediarecorderservice.h new file mode 100644 index 000000000..fa8c29a5a --- /dev/null +++ b/tests/auto/qmultimedia_common/mockmediarecorderservice.h @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +#ifndef MOCKSERVICE_H +#define MOCKSERVICE_H + +#include "qmediaservice.h" + +#include "mockaudioencodercontrol.h" +#include "mockmediarecordercontrol.h" +#include "mockvideoencodercontrol.h" +#include "mockaudioendpointselector.h" +#include "mockmediacontainercontrol.h" +#include "mockmetadatawritercontrol.h" + +class MockMediaRecorderService : public QMediaService +{ + Q_OBJECT +public: + MockMediaRecorderService(QObject *parent = 0, QMediaControl *control = 0): + QMediaService(parent), + mockControl(control), + hasControls(true) + { + mockAudioEndpointSelector = new MockAudioEndpointSelector(parent); + mockAudioEncoderControl = new MockAudioEncoderControl(parent); + mockFormatControl = new MockMediaContainerControl(parent); + mockVideoEncoderControl = new MockVideoEncoderControl(parent); + mockMetaDataControl = new MockMetaDataWriterControl(parent); + } + + QMediaControl* requestControl(const char *name) + { + if (hasControls && qstrcmp(name,QAudioEncoderControl_iid) == 0) + return mockAudioEncoderControl; + if (hasControls && qstrcmp(name,QAudioEndpointSelector_iid) == 0) + return mockAudioEndpointSelector; + if (hasControls && qstrcmp(name,QMediaRecorderControl_iid) == 0) + return mockControl; + if (hasControls && qstrcmp(name,QMediaContainerControl_iid) == 0) + return mockFormatControl; + if (hasControls && qstrcmp(name,QVideoEncoderControl_iid) == 0) + return mockVideoEncoderControl; + if (hasControls && qstrcmp(name, QMetaDataWriterControl_iid) == 0) + return mockMetaDataControl; + + return 0; + } + + void releaseControl(QMediaControl*) + { + } + + QMediaControl *mockControl; + QAudioEndpointSelector *mockAudioEndpointSelector; + QAudioEncoderControl *mockAudioEncoderControl; + QMediaContainerControl *mockFormatControl; + QVideoEncoderControl *mockVideoEncoderControl; + MockMetaDataWriterControl *mockMetaDataControl; + bool hasControls; +}; + +#endif // MOCKSERVICE_H diff --git a/tests/auto/qmultimedia_common/mockmediaservice.h b/tests/auto/qmultimedia_common/mockmediaservice.h new file mode 100644 index 000000000..3ceb1ad74 --- /dev/null +++ b/tests/auto/qmultimedia_common/mockmediaservice.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +#ifndef MOCKMEDIASERVICE_H +#define MOCKMEDIASERVICE_H + +#include "qmediaservice.h" + +class MockMediaService : public QMediaService +{ + Q_OBJECT +public: + MockMediaService(QObject *parent, QMediaControl *control): + QMediaService(parent), + mockControl(control) {} + + QMediaControl* requestControl(const char *) + { + return mockControl; + } + + void releaseControl(QMediaControl*) {} + + QMediaControl *mockControl; +}; + + +#endif // MOCKMEDIASERVICE_H diff --git a/tests/auto/qmultimedia_common/mockmediaserviceprovider.h b/tests/auto/qmultimedia_common/mockmediaserviceprovider.h new file mode 100644 index 000000000..3509fea9b --- /dev/null +++ b/tests/auto/qmultimedia_common/mockmediaserviceprovider.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +#ifndef MOCKMEDIASERVICEPROVIDER_H +#define MOCKMEDIASERVICEPROVIDER_H + +#include "qmediaserviceprovider.h" + +// Simple provider that lets you set the service +class MockMediaServiceProvider : public QMediaServiceProvider +{ +public: + MockMediaServiceProvider(QMediaService* s = 0, bool del=false) + : service(s), deleteServiceOnRelease(del) + { + } + + QMediaService *requestService(const QByteArray &, const QMediaServiceProviderHint &) + { + return service; + } + + void releaseService(QMediaService *service) + { + if (deleteServiceOnRelease) { + delete service; + service = 0; + } + } + + QMediaService *service; + bool deleteServiceOnRelease; +}; + +#endif // MOCKMEDIASERVICEPROVIDER_H diff --git a/tests/auto/qmultimedia_common/mockmediastreamscontrol.h b/tests/auto/qmultimedia_common/mockmediastreamscontrol.h new file mode 100644 index 000000000..902f4fc12 --- /dev/null +++ b/tests/auto/qmultimedia_common/mockmediastreamscontrol.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +#ifndef MOCKMEDIASTREAMSCONTROL_H +#define MOCKMEDIASTREAMSCONTROL_H + +#include "qmediastreamscontrol.h" + +class MockStreamsControl : public QMediaStreamsControl +{ +public: + MockStreamsControl(QObject *parent = 0) : QMediaStreamsControl(parent) {} + + int streamCount() { return _streams.count(); } + void setStreamCount(int count) { _streams.resize(count); } + + StreamType streamType(int index) { return _streams.at(index).type; } + void setStreamType(int index, StreamType type) { _streams[index].type = type; } + + QVariant metaData(int index, QtMultimediaKit::MetaData key) { + return _streams.at(index).metaData.value(key); } + void setMetaData(int index, QtMultimediaKit::MetaData key, const QVariant &value) { + _streams[index].metaData.insert(key, value); } + + bool isActive(int index) { return _streams.at(index).active; } + void setActive(int index, bool state) { _streams[index].active = state; } + +private: + struct Stream + { + Stream() : type(UnknownStream), active(false) {} + StreamType type; + QMap<QtMultimediaKit::MetaData, QVariant> metaData; + bool active; + }; + + QVector<Stream> _streams; +}; + +#endif // MOCKMEDIASTREAMSCONTROL_H diff --git a/tests/auto/qmultimedia_common/mockmetadatareadercontrol.h b/tests/auto/qmultimedia_common/mockmetadatareadercontrol.h new file mode 100644 index 000000000..6aa08778b --- /dev/null +++ b/tests/auto/qmultimedia_common/mockmetadatareadercontrol.h @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +#ifndef MOCKMETADATAREADERCONTROL_H +#define MOCKMETADATAREADERCONTROL_H + +#include "qmetadatareadercontrol.h" + +class MockMetaDataReaderControl : public QMetaDataReaderControl +{ + Q_OBJECT +public: + MockMetaDataReaderControl(QObject *parent = 0) + : QMetaDataReaderControl(parent) + , m_available(false) + { + } + + bool isMetaDataAvailable() const + { + return m_available; + } + void setMetaDataAvailable(bool available) + { + if (m_available != available) + emit metaDataAvailableChanged(m_available = available); + } + QList<QtMultimediaKit::MetaData> availableMetaData() const + { + return m_data.keys(); + } + + QVariant metaData(QtMultimediaKit::MetaData key) const + { + return m_data.value(key); + } + + QVariant extendedMetaData(const QString &key) const + { + return m_extendedData.value(key); + } + + QStringList availableExtendedMetaData() const + { + return m_extendedData.keys(); + } + + using QMetaDataReaderControl::metaDataChanged; + + void populateMetaData() + { + m_available = true; + } + + bool m_available; + QMap<QtMultimediaKit::MetaData, QVariant> m_data; + QMap<QString, QVariant> m_extendedData; +}; + +#endif // MOCKMETADATAREADERCONTROL_H diff --git a/tests/auto/qmultimedia_common/mockmetadatawritercontrol.h b/tests/auto/qmultimedia_common/mockmetadatawritercontrol.h new file mode 100644 index 000000000..dcd9a8e55 --- /dev/null +++ b/tests/auto/qmultimedia_common/mockmetadatawritercontrol.h @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +#ifndef MOCKMETADATAWRITERCONTROL_H +#define MOCKMETADATAWRITERCONTROL_H + +#include <QObject> +#include <QMap> + +#include "qmetadatawritercontrol.h" + +class MockMetaDataWriterControl : public QMetaDataWriterControl +{ + Q_OBJECT +public: + MockMetaDataWriterControl(QObject *parent = 0) + : QMetaDataWriterControl(parent) + , m_available(false) + , m_writable(false) + { + } + + bool isMetaDataAvailable() const { return m_available; } + void setMetaDataAvailable(bool available) + { + if (m_available != available) + emit metaDataAvailableChanged(m_available = available); + } + QList<QtMultimediaKit::MetaData> availableMetaData() const { return m_data.keys(); } + + bool isWritable() const { return m_writable; } + void setWritable(bool writable) { emit writableChanged(m_writable = writable); } + + QVariant metaData(QtMultimediaKit::MetaData key) const { return m_data.value(key); }//Getting the metadata from Multimediakit + void setMetaData(QtMultimediaKit::MetaData key, const QVariant &value) + { + m_data.insert(key, value); + } + + QVariant extendedMetaData(const QString &key) const { return m_extendedData.value(key); } + void setExtendedMetaData(const QString &key, const QVariant &value) + { + m_extendedData.insert(key, value); + } + + QStringList availableExtendedMetaData() const { return m_extendedData.keys(); } + + using QMetaDataWriterControl::metaDataChanged; + + void populateMetaData() + { + m_available = true; + } + void setWritable() + { + emit writableChanged(true); + } + void setMetaDataAvailable() + { + emit metaDataAvailableChanged(true); + } + + bool m_available; + bool m_writable; + QMap<QtMultimediaKit::MetaData, QVariant> m_data; + QMap<QString, QVariant> m_extendedData; +}; + +#endif // MOCKMETADATAWRITERCONTROL_H diff --git a/tests/auto/qmultimedia_common/mockplayer.pri b/tests/auto/qmultimedia_common/mockplayer.pri new file mode 100644 index 000000000..a5040ac80 --- /dev/null +++ b/tests/auto/qmultimedia_common/mockplayer.pri @@ -0,0 +1,12 @@ +INCLUDEPATH *= $$PWD \ + ../../../src/multimedia \ + ../../../src/multimedia/audio \ + ../../../src/multimedia/video \ + +HEADERS *= \ + ../qmultimedia_common/mockmediaplayerservice.h \ + ../qmultimedia_common/mockmediaplayercontrol.h \ + ../qmultimedia_common/mockmediastreamscontrol.h \ + ../qmultimedia_common/mockmedianetworkaccesscontrol.h + +include(mockvideo.pri) diff --git a/tests/auto/qmultimedia_common/mockplaylist.pri b/tests/auto/qmultimedia_common/mockplaylist.pri new file mode 100644 index 000000000..c27c839c5 --- /dev/null +++ b/tests/auto/qmultimedia_common/mockplaylist.pri @@ -0,0 +1,8 @@ +INCLUDEPATH *= $$PWD \ + ../../../src/multimedia \ + +HEADERS *= \ + ../qmultimedia_common/mockmediaplaylistsourcecontrol.h \ + ../qmultimedia_common/mockmediaplaylistcontrol.h \ + ../qmultimedia_common/mockreadonlyplaylistprovider.h \ + ../qmultimedia_common/mockplaylistservice.h diff --git a/tests/auto/qmultimedia_common/mockplaylistservice.h b/tests/auto/qmultimedia_common/mockplaylistservice.h new file mode 100644 index 000000000..3e1210c28 --- /dev/null +++ b/tests/auto/qmultimedia_common/mockplaylistservice.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +#ifndef MOCKPLAYLISTSERVICE_H +#define MOCKPLAYLISTSERVICE_H + +#include "qmediaservice.h" +#include "mockmediaplaylistcontrol.h" + +class MockPlaylistService : public QMediaService +{ + Q_OBJECT + +public: + MockPlaylistService():QMediaService(0) + { + mockControl = new MockMediaPlaylistControl(this); + } + + ~MockPlaylistService() + { + } + + QMediaControl* requestControl(const char *iid) + { + if (qstrcmp(iid, QMediaPlaylistControl_iid) == 0) + return mockControl; + return 0; + } + + void releaseControl(QMediaControl *) + { + } + + MockMediaPlaylistControl *mockControl; +}; + + +#endif // MOCKPLAYLISTSERVICE_H diff --git a/tests/auto/qmultimedia_common/mockradio.pri b/tests/auto/qmultimedia_common/mockradio.pri new file mode 100644 index 000000000..a56564f98 --- /dev/null +++ b/tests/auto/qmultimedia_common/mockradio.pri @@ -0,0 +1,7 @@ + +# Radio related mock backend files + +INCLUDEPATH += . + +HEADERS += \ + ../qmultimedia_common/mockradiotunercontrol.h diff --git a/tests/auto/qmultimedia_common/mockradiotunercontrol.h b/tests/auto/qmultimedia_common/mockradiotunercontrol.h new file mode 100644 index 000000000..aa446074f --- /dev/null +++ b/tests/auto/qmultimedia_common/mockradiotunercontrol.h @@ -0,0 +1,249 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +#ifndef MOCKRADIOTUNERCONTROL_H +#define MOCKRADIOTUNERCONTROL_H + +#include "qradiotunercontrol.h" + +class MockRadioTunerControl : public QRadioTunerControl +{ + Q_OBJECT + +public: + MockRadioTunerControl(QObject *parent): + QRadioTunerControl(parent), + m_active(false), + m_searching(false),m_muted(false),m_stereo(true), + m_volume(100),m_signal(0),m_frequency(0), + m_band(QRadioTuner::FM),m_err(QRadioTuner::NoError), + m_errstr("") + { + } + + using QRadioTunerControl::error; + + QRadioTuner::State state() const + { + return m_active ? QRadioTuner::ActiveState : QRadioTuner::StoppedState; + } + + bool isAvailable() const + { + return true; + } + QtMultimediaKit::AvailabilityError availabilityError() const + { + return QtMultimediaKit::NoError; + } + + QRadioTuner::Band band() const + { + return m_band; + } + + void setBand(QRadioTuner::Band b) + { + if (b == QRadioTuner::FM2 || b == QRadioTuner::LW) { + m_err = QRadioTuner::OutOfRangeError; + m_errstr.clear(); + m_errstr = QString("band and range not supported"); + } else { + m_err = QRadioTuner::NoError; + m_errstr.clear(); + m_band = b; + emit bandChanged(m_band); + } + emit error(m_err); + + } + + bool isBandSupported(QRadioTuner::Band b) const + { + if (b == QRadioTuner::FM || b == QRadioTuner::AM) + return true; + + return false; + } + + int frequency() const + { + return m_frequency; + } + + QPair<int,int> frequencyRange(QRadioTuner::Band) const + { + return qMakePair<int,int>(1,2); + } + + int frequencyStep(QRadioTuner::Band) const + { + return 1; + } + + void setFrequency(int frequency) + { + if (frequency >= 148500000) { + m_err = QRadioTuner::OutOfRangeError; + m_errstr.clear(); + m_errstr = QString("band and range not supported"); + } else { + m_err = QRadioTuner::NoError; + m_errstr.clear(); + m_frequency = frequency; + emit frequencyChanged(m_frequency); + } + + emit error(m_err); + } + + bool isStereo() const + { + return m_stereo; + } + + void setStereo(bool stereo) + { + emit stereoStatusChanged(m_stereo = stereo); + } + + + QRadioTuner::StereoMode stereoMode() const + { + return m_stereoMode; + } + + void setStereoMode(QRadioTuner::StereoMode mode) + { + m_stereoMode = mode; + } + + QRadioTuner::Error error() const + { + return m_err; + } + + QString errorString() const + { + return m_errstr; + } + + int signalStrength() const + { + return m_signal; + } + + int volume() const + { + return m_volume; + } + + void setVolume(int volume) + { + m_volume = volume; + emit volumeChanged(m_volume); + } + + bool isMuted() const + { + return m_muted; + } + + void setMuted(bool muted) + { + m_muted = muted; + emit mutedChanged(m_muted); + } + + bool isSearching() const + { + return m_searching; + } + + void searchForward() + { + m_searching = true; + emit searchingChanged(m_searching); + } + + void searchBackward() + { + m_searching = true; + emit searchingChanged(m_searching); + } + + void cancelSearch() + { + m_searching = false; + emit searchingChanged(m_searching); + } + + void start() + { + if (!m_active) { + m_active = true; + emit stateChanged(state()); + } + } + + void stop() + { + if (m_active) { + m_active = false; + emit stateChanged(state()); + } + } + +public: + bool m_active; + bool m_searching; + bool m_muted; + bool m_stereo; + int m_volume; + int m_signal; + int m_frequency; + QRadioTuner::StereoMode m_stereoMode; + QRadioTuner::Band m_band; + QRadioTuner::Error m_err; + QString m_errstr; +}; + +#endif // MOCKRADIOTUNERCONTROL_H diff --git a/tests/auto/qmultimedia_common/mockreadonlyplaylistprovider.h b/tests/auto/qmultimedia_common/mockreadonlyplaylistprovider.h new file mode 100644 index 000000000..12e48e03a --- /dev/null +++ b/tests/auto/qmultimedia_common/mockreadonlyplaylistprovider.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +#ifndef MOCKREADONLYPLAYLISTPROVIDER_H +#define MOCKREADONLYPLAYLISTPROVIDER_H + +#include "qmediaplaylistprovider.h" + +class MockReadOnlyPlaylistProvider : public QMediaPlaylistProvider +{ + Q_OBJECT +public: + MockReadOnlyPlaylistProvider(QObject *parent) + :QMediaPlaylistProvider(parent) + { + m_items.append(QMediaContent(QUrl(QLatin1String("file:///1")))); + m_items.append(QMediaContent(QUrl(QLatin1String("file:///2")))); + m_items.append(QMediaContent(QUrl(QLatin1String("file:///3")))); + } + + int mediaCount() const { return m_items.size(); } + QMediaContent media(int index) const + { + return index >=0 && index < mediaCount() ? m_items.at(index) : QMediaContent(); + } + +private: + QList<QMediaContent> m_items; +}; + +#endif // MOCKREADONLYPLAYLISTPROVIDER_H diff --git a/tests/auto/qmultimedia_common/mockrecorder.pri b/tests/auto/qmultimedia_common/mockrecorder.pri new file mode 100644 index 000000000..6f8438d8f --- /dev/null +++ b/tests/auto/qmultimedia_common/mockrecorder.pri @@ -0,0 +1,14 @@ +INCLUDEPATH *= $$PWD \ + ../../../src/multimedia \ + ../../../src/multimedia/audio \ + ../../../src/multimedia/video \ + +HEADERS *= \ + ../qmultimedia_common/mockmediarecorderservice.h \ + ../qmultimedia_common/mockmediarecordercontrol.h \ + ../qmultimedia_common/mockvideoencodercontrol.h \ + ../qmultimedia_common/mockaudioencodercontrol.h \ + ../qmultimedia_common/mockaudioendpointselector.h \ + +# We also need all the container/metadata bits +include(mockcontainer.pri) diff --git a/tests/auto/qmultimedia_common/mockvideo.pri b/tests/auto/qmultimedia_common/mockvideo.pri new file mode 100644 index 000000000..a2492298c --- /dev/null +++ b/tests/auto/qmultimedia_common/mockvideo.pri @@ -0,0 +1,10 @@ +# video related mock backend files +INCLUDEPATH += $$PWD \ + ../../../src/multimedia \ + ../../../src/multimedia/video + +HEADERS *= \ + ../qmultimedia_common/mockvideosurface.h \ + ../qmultimedia_common/mockvideorenderercontrol.h \ + ../qmultimedia_common/mockvideowindowcontrol.h + diff --git a/tests/auto/qmultimedia_common/mockvideoencodercontrol.h b/tests/auto/qmultimedia_common/mockvideoencodercontrol.h new file mode 100644 index 000000000..f628c6730 --- /dev/null +++ b/tests/auto/qmultimedia_common/mockvideoencodercontrol.h @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +#ifndef MOCKVIDEOENCODERCONTROL_H +#define MOCKVIDEOENCODERCONTROL_H + +#include "qvideoencodercontrol.h" + +class MockVideoEncoderControl : public QVideoEncoderControl +{ + Q_OBJECT +public: + MockVideoEncoderControl(QObject *parent): + QVideoEncoderControl(parent) + { + m_supportedEncodeOptions.insert("video/3gpp", QStringList() << "quantizer" << "me"); + m_supportedEncodeOptions.insert("video/H264", QStringList() << "quantizer" << "me" << "bframes"); + m_videoCodecs << "video/3gpp" << "video/H264"; + m_sizes << QSize(320,240) << QSize(640,480); + m_framerates << 30 << 15 << 1; + } + ~MockVideoEncoderControl() {} + + QVideoEncoderSettings videoSettings() const { return m_videoSettings; } + void setVideoSettings(const QVideoEncoderSettings &settings) { m_videoSettings = settings; }; + + QList<QSize> supportedResolutions(const QVideoEncoderSettings & = QVideoEncoderSettings(), + bool *continuous = 0) const + { + if (continuous) + *continuous = true; + + return m_sizes; + } + + QList<qreal> supportedFrameRates(const QVideoEncoderSettings & = QVideoEncoderSettings(), + bool *continuous = 0) const + { + if (continuous) + *continuous = false; + + return m_framerates; + } + + QStringList supportedVideoCodecs() const { return m_videoCodecs; } + QString videoCodecDescription(const QString &codecName) const { return codecName; } + + QStringList supportedEncodingOptions(const QString &codec) const + { + return m_supportedEncodeOptions.value(codec); + } + + QVariant encodingOption(const QString &codec, const QString &name) const + { + return m_encodeOptions[codec].value(name); + } + + void setEncodingOption(const QString &codec, const QString &name, const QVariant &value) + { + m_encodeOptions[codec][name] = value; + } + +private: + QVideoEncoderSettings m_videoSettings; + + QMap<QString, QStringList> m_supportedEncodeOptions; + QMap< QString, QMap<QString, QVariant> > m_encodeOptions; + + QStringList m_videoCodecs; + QList<QSize> m_sizes; + QList<qreal> m_framerates; +}; + +#endif // MOCKVIDEOENCODERCONTROL_H diff --git a/tests/auto/qmultimedia_common/mockvideorenderercontrol.h b/tests/auto/qmultimedia_common/mockvideorenderercontrol.h new file mode 100644 index 000000000..c98dd761a --- /dev/null +++ b/tests/auto/qmultimedia_common/mockvideorenderercontrol.h @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +#ifndef MOCKVIDEORENDERERCONTROL_H +#define MOCKVIDEORENDERERCONTROL_H + +#include "qvideorenderercontrol.h" + +class MockVideoRendererControl : public QVideoRendererControl +{ +public: + MockVideoRendererControl(QObject *parent = 0) : QVideoRendererControl(parent), m_surface(0) {} + + QAbstractVideoSurface *surface() const { return m_surface; } + void setSurface(QAbstractVideoSurface *surface) { m_surface = surface; } + + QAbstractVideoSurface *m_surface; +}; + +#endif // MOCKVIDEORENDERERCONTROL_H diff --git a/tests/auto/qmultimedia_common/mockvideosurface.h b/tests/auto/qmultimedia_common/mockvideosurface.h new file mode 100644 index 000000000..bbfe35448 --- /dev/null +++ b/tests/auto/qmultimedia_common/mockvideosurface.h @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +#ifndef MOCKVIDEOSURFACE_H +#define MOCKVIDEOSURFACE_H + +#include "qabstractvideosurface.h" + +class MockVideoSurface : public QAbstractVideoSurface +{ +public: + QList<QVideoFrame::PixelFormat> supportedPixelFormats( + const QAbstractVideoBuffer::HandleType) const + { + return QList<QVideoFrame::PixelFormat>(); + } + + bool present(const QVideoFrame &) { return false; } +}; + +#endif // MOCKVIDEOSURFACE_H diff --git a/tests/auto/qmultimedia_common/mockvideowindowcontrol.h b/tests/auto/qmultimedia_common/mockvideowindowcontrol.h new file mode 100644 index 000000000..ef8c41d80 --- /dev/null +++ b/tests/auto/qmultimedia_common/mockvideowindowcontrol.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +#ifndef MOCKVIDEOWINDOWCONTROL_H +#define MOCKVIDEOWINDOWCONTROL_H + +#include "qvideowindowcontrol.h" + +class MockVideoWindowControl : public QVideoWindowControl +{ +public: + MockVideoWindowControl(QObject *parent = 0) : QVideoWindowControl(parent) {} + WId winId() const { return 0; } + void setWinId(WId) {} + QRect displayRect() const { return QRect(); } + void setDisplayRect(const QRect &) {} + bool isFullScreen() const { return false; } + void setFullScreen(bool) {} + void repaint() {} + QSize nativeSize() const { return QSize(); } + Qt::AspectRatioMode aspectRatioMode() const { return Qt::KeepAspectRatio; } + void setAspectRatioMode(Qt::AspectRatioMode) {} + int brightness() const { return 0; } + void setBrightness(int) {} + int contrast() const { return 0; } + void setContrast(int) {} + int hue() const { return 0; } + void setHue(int) {} + int saturation() const { return 0; } + void setSaturation(int) {} +}; + +#endif // MOCKVIDEOWINDOWCONTROL_H diff --git a/tests/auto/qradiotuner/qradiotuner.pro b/tests/auto/qradiotuner/qradiotuner.pro index d8818d3db..8e2a07b02 100644 --- a/tests/auto/qradiotuner/qradiotuner.pro +++ b/tests/auto/qradiotuner/qradiotuner.pro @@ -8,3 +8,5 @@ QT += multimediakit-private HEADERS += tst_qradiotuner.h SOURCES += main.cpp tst_qradiotuner.cpp +include (../qmultimedia_common/mock.pri) +include (../qmultimedia_common/mockradio.pri) diff --git a/tests/auto/qradiotuner/tst_qradiotuner.cpp b/tests/auto/qradiotuner/tst_qradiotuner.cpp index 2ecdb016e..80bac62db 100644 --- a/tests/auto/qradiotuner/tst_qradiotuner.cpp +++ b/tests/auto/qradiotuner/tst_qradiotuner.cpp @@ -50,16 +50,19 @@ void tst_QRadioTuner::initTestCase() qRegisterMetaType<QRadioTuner::State>("QRadioTuner::State"); qRegisterMetaType<QRadioTuner::Band>("QRadioTuner::Band"); - mock = new MockControl(this); - service = new MockService(this, mock); - provider = new MockProvider(service); + mock = new MockRadioTunerControl(this); + service = new MockMediaService(this, mock); + provider = new MockMediaServiceProvider(service); radio = new QRadioTuner(0,provider); QVERIFY(radio->service() != 0); + QVERIFY(radio->isAvailable()); + QVERIFY(radio->availabilityError() == QtMultimediaKit::NoError); QSignalSpy stateSpy(radio, SIGNAL(stateChanged(QRadioTuner::State))); QCOMPARE(radio->state(), QRadioTuner::StoppedState); radio->start(); + QVERIFY(radio->availabilityError() == QtMultimediaKit::NoError); QCOMPARE(radio->state(), QRadioTuner::ActiveState); QCOMPARE(stateSpy.count(), 1); @@ -74,6 +77,7 @@ void tst_QRadioTuner::cleanupTestCase() QSignalSpy stateSpy(radio, SIGNAL(stateChanged(QRadioTuner::State))); radio->stop(); + QVERIFY(radio->availabilityError() == QtMultimediaKit::NoError); QCOMPARE(radio->state(), QRadioTuner::StoppedState); QCOMPARE(stateSpy.count(), 1); @@ -88,9 +92,9 @@ void tst_QRadioTuner::testNullService() { const QPair<int, int> nullRange(0, 0); - MockProvider provider(0); + MockMediaServiceProvider provider(0); QRadioTuner radio(0, &provider); - + QVERIFY(!radio.isAvailable()); radio.start(); QCOMPARE(radio.error(), QRadioTuner::ResourceError); QCOMPARE(radio.errorString(), QString()); @@ -115,10 +119,10 @@ void tst_QRadioTuner::testNullControl() { const QPair<int, int> nullRange(0, 0); - MockService service(0, 0); - MockProvider provider(&service); + MockMediaService service(0, 0); + MockMediaServiceProvider provider(&service); QRadioTuner radio(0, &provider); - + QVERIFY(!radio.isAvailable()); radio.start(); QCOMPARE(radio.error(), QRadioTuner::ResourceError); @@ -269,7 +273,47 @@ void tst_QRadioTuner::testSignal() void tst_QRadioTuner::testStereo() { + /* no set function to toggle stereo status; + cannot emit stereoStatusChanged() signal */ + QVERIFY(radio->isStereo()); radio->setStereoMode(QRadioTuner::ForceMono); QVERIFY(radio->stereoMode() == QRadioTuner::ForceMono); } + +// QRadioTuner's errorsignal +void tst_QRadioTuner::errorSignal() +{ + qRegisterMetaType<QRadioTuner::Error>("QRadioTuner::Error"); + QObject obj; + MockRadioTunerControl dctrl(&obj); + MockMediaService service(&obj, &dctrl); + MockMediaServiceProvider provider(&service); + QRadioTuner radio(0,&provider); + QSignalSpy spy(&radio, SIGNAL(error(QRadioTuner::Error))); + QVERIFY(radio.service() != 0); + QVERIFY(radio.isAvailable()); + radio.start(); + radio.setBand(QRadioTuner::FM); + QVERIFY(spy.count() == 1); + QVERIFY(qvariant_cast<QRadioTuner::Error>(spy.at(0).at(0)) == QRadioTuner::NoError); + QVERIFY(radio.error() == QRadioTuner::NoError); + QVERIFY(radio.error() != QRadioTuner::OpenError); + QVERIFY(radio.errorString().isEmpty()); + spy.clear(); + + /* emits QRadioTuner::OutOfRangeError if band is set to FM2 or LW + and frequency set to >= 148500000 */ + + radio.setBand(QRadioTuner::LW); + radio.setBand(QRadioTuner::FM2); + radio.setFrequency(148500000); + QVERIFY(spy.count() == 3); + QVERIFY(qvariant_cast<QRadioTuner::Error>(spy.at(0).at(0)) == QRadioTuner::OutOfRangeError); + QVERIFY(qvariant_cast<QRadioTuner::Error>(spy.at(1).at(0)) == QRadioTuner::OutOfRangeError); + QVERIFY(qvariant_cast<QRadioTuner::Error>(spy.at(2).at(0)) == QRadioTuner::OutOfRangeError); + QVERIFY(radio.error() == QRadioTuner::OutOfRangeError); + QVERIFY2(!radio.errorString().isEmpty(), "band and range not supported"); + spy.clear(); + radio.stop(); +} diff --git a/tests/auto/qradiotuner/tst_qradiotuner.h b/tests/auto/qradiotuner/tst_qradiotuner.h index 478789565..34040ce77 100644 --- a/tests/auto/qradiotuner/tst_qradiotuner.h +++ b/tests/auto/qradiotuner/tst_qradiotuner.h @@ -51,211 +51,11 @@ #include <qradiotunercontrol.h> #include <qradiotuner.h> -QT_USE_NAMESPACE -class MockControl : public QRadioTunerControl -{ - Q_OBJECT - -public: - MockControl(QObject *parent): - QRadioTunerControl(parent), - m_active(false), - m_searching(false),m_muted(false),m_stereo(true), - m_volume(100),m_signal(0),m_frequency(0), - m_band(QRadioTuner::FM) {} - - QRadioTuner::State state() const - { - return m_active ? QRadioTuner::ActiveState : QRadioTuner::StoppedState; - } - bool isAvailable() const - { - return true; - } - QtMultimediaKit::AvailabilityError availabilityError() const - { - return QtMultimediaKit::NoError; - } - - QRadioTuner::Band band() const - { - return m_band; - } - - void setBand(QRadioTuner::Band b) - { - m_band = b; - emit bandChanged(m_band); - } - - bool isBandSupported(QRadioTuner::Band b) const - { - if(b == QRadioTuner::FM || b == QRadioTuner::AM) return true; - - return false; - } - - int frequency() const - { - return m_frequency; - } - - QPair<int,int> frequencyRange(QRadioTuner::Band) const - { - return qMakePair<int,int>(1,2); - } - - int frequencyStep(QRadioTuner::Band) const - { - return 1; - } - - void setFrequency(int frequency) - { - m_frequency = frequency; - emit frequencyChanged(m_frequency); - } - - bool isStereo() const - { - return m_stereo; - } - - void setStereo(bool stereo) - { - emit stereoStatusChanged(m_stereo = stereo); - } - - - QRadioTuner::StereoMode stereoMode() const - { - return m_stereoMode; - } - - void setStereoMode(QRadioTuner::StereoMode mode) - { - m_stereoMode = mode; - } - - QRadioTuner::Error error() const - { - return QRadioTuner::NoError; - } - - QString errorString() const - { - return QString(); - } - - int signalStrength() const - { - return m_signal; - } - - int volume() const - { - return m_volume; - } - - void setVolume(int volume) - { - m_volume = volume; - emit volumeChanged(m_volume); - } +#include "mockmediaserviceprovider.h" +#include "mockmediaservice.h" +#include "mockradiotunercontrol.h" - bool isMuted() const - { - return m_muted; - } - - void setMuted(bool muted) - { - m_muted = muted; - emit mutedChanged(m_muted); - } - - bool isSearching() const - { - return m_searching; - } - - void searchForward() - { - m_searching = true; - emit searchingChanged(m_searching); - } - - void searchBackward() - { - m_searching = true; - emit searchingChanged(m_searching); - } - - void cancelSearch() - { - m_searching = false; - emit searchingChanged(m_searching); - } - - void start() - { - if (!m_active) { - m_active = true; - emit stateChanged(state()); - } - } - - void stop() - { - if (m_active) { - m_active = false; - emit stateChanged(state()); - } - } - -public: - bool m_active; - bool m_searching; - bool m_muted; - bool m_stereo; - int m_volume; - int m_signal; - int m_frequency; - QRadioTuner::StereoMode m_stereoMode; - QRadioTuner::Band m_band; -}; - -class MockService : public QMediaService -{ - Q_OBJECT -public: - MockService(QObject *parent, QMediaControl *control): - QMediaService(parent), - mockControl(control) {} - - QMediaControl* requestControl(const char *) - { - return mockControl; - } - - void releaseControl(QMediaControl*) {} - - QMediaControl *mockControl; -}; - -class MockProvider : public QMediaServiceProvider -{ -public: - MockProvider(MockService *service):mockService(service) {} - QMediaService *requestService(const QByteArray &, const QMediaServiceProviderHint &) - { - return mockService; - } - - void releaseService(QMediaService *) {} - - MockService *mockService; -}; +QT_USE_NAMESPACE class tst_QRadioTuner: public QObject { @@ -275,11 +75,12 @@ private slots: void testVolume(); void testSignal(); void testStereo(); + void errorSignal(); private: - MockControl *mock; - MockService *service; - MockProvider *provider; + MockRadioTunerControl *mock; + MockMediaService *service; + MockMediaServiceProvider *provider; QRadioTuner *radio; }; #endif diff --git a/tests/auto/qvideodevicecontrol/qvideodevicecontrol.pro b/tests/auto/qvideodevicecontrol/qvideodevicecontrol.pro new file mode 100644 index 000000000..486bc1e7d --- /dev/null +++ b/tests/auto/qvideodevicecontrol/qvideodevicecontrol.pro @@ -0,0 +1,5 @@ +load(qttest_p4) + +QT += multimediakit-private + +SOURCES += tst_qvideodevicecontrol.cpp diff --git a/tests/auto/qvideodevicecontrol/tst_qvideodevicecontrol.cpp b/tests/auto/qvideodevicecontrol/tst_qvideodevicecontrol.cpp new file mode 100644 index 000000000..59d2546b3 --- /dev/null +++ b/tests/auto/qvideodevicecontrol/tst_qvideodevicecontrol.cpp @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/multimedia + +#include <QtTest/QtTest> +#include "qvideodevicecontrol.h" +class TestClass: public QVideoDeviceControl +{ + Q_OBJECT + +public: + TestClass(QObject *parent = 0 ):QVideoDeviceControl(parent) + { + + } + + ~TestClass(){} + + virtual int deviceCount() const { return 0; } + + QString deviceName(int index) const + { + QString str; + return str; + } + + QString deviceDescription(int index) const + { + QString str; + return str; + } + + QIcon deviceIcon(int index) const + { + QIcon icon; + return icon; + } + + int defaultDevice() const { return 0; } + int selectedDevice() const { return 0; } + + public Q_SLOTS: + void setSelectedDevice(int index) + { + emit devicesChanged(); + emit selectedDeviceChanged(index); + emit selectedDeviceChanged("abc"); + } +}; + + +class tst_QVideoDeviceControl : public QObject +{ + Q_OBJECT +public: + tst_QVideoDeviceControl(){} + ~tst_QVideoDeviceControl(){} + +private slots: + void testQVideoDeviceControl(); +}; + +//MaemoAPI-1859:QVideoDeviceControl constructor +void tst_QVideoDeviceControl::testQVideoDeviceControl() +{ + TestClass *testClass = new TestClass(this); + QVERIFY(testClass != NULL); +} + +QTEST_MAIN(tst_QVideoDeviceControl) +#include "tst_qvideodevicecontrol.moc" diff --git a/tests/auto/qvideoencodercontrol/qvideoencodercontrol.pro b/tests/auto/qvideoencodercontrol/qvideoencodercontrol.pro new file mode 100644 index 000000000..57e44032f --- /dev/null +++ b/tests/auto/qvideoencodercontrol/qvideoencodercontrol.pro @@ -0,0 +1,7 @@ +load(qttest_p4) + +QT += multimediakit-private + +SOURCES += \ + tst_qvideoencodercontrol.cpp + diff --git a/tests/auto/qvideoencodercontrol/tst_qvideoencodercontrol.cpp b/tests/auto/qvideoencodercontrol/tst_qvideoencodercontrol.cpp new file mode 100644 index 000000000..4f1b99d8e --- /dev/null +++ b/tests/auto/qvideoencodercontrol/tst_qvideoencodercontrol.cpp @@ -0,0 +1,139 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/multimedia + +#include <QtTest/QtTest> +#include "qvideoencodercontrol.h" +class MyVideEncoderControl: public QVideoEncoderControl +{ + Q_OBJECT + +public: + MyVideEncoderControl(QObject *parent = 0 ):QVideoEncoderControl(parent) + { + + } + + ~MyVideEncoderControl() + { + + } + + QList<QSize> supportedResolutions(const QVideoEncoderSettings &settings,bool *continuous = 0) const + { + Q_UNUSED(settings); + Q_UNUSED(continuous); + + return (QList<QSize>()); + } + + QList<qreal> supportedFrameRates(const QVideoEncoderSettings &settings, bool *continuous = 0) const + { + Q_UNUSED(settings); + Q_UNUSED(continuous); + + return (QList<qreal>()); + + } + + QStringList supportedVideoCodecs() const + { + return QStringList(); + + } + + QString videoCodecDescription(const QString &codecName) const + { + Q_UNUSED(codecName) + return QString(); + + } + + QVideoEncoderSettings videoSettings() const + { + return QVideoEncoderSettings(); + } + + void setVideoSettings(const QVideoEncoderSettings &settings) + { + Q_UNUSED(settings); + } + + QStringList supportedEncodingOptions(const QString &codec) const + { + Q_UNUSED(codec); + return QStringList(); + } + + QVariant encodingOption(const QString &codec, const QString &name) const + { + Q_UNUSED(codec); + Q_UNUSED(name); + return QVariant(); + } + + void setEncodingOption(const QString &codec, const QString &name, const QVariant &value) + { + Q_UNUSED(codec); + Q_UNUSED(name); + Q_UNUSED(value); + } + +}; + +class tst_QVideoEncoderControl: public QObject +{ + Q_OBJECT +private slots: + void constructor(); +}; + +void tst_QVideoEncoderControl::constructor() +{ + QObject parent; + MyVideEncoderControl control(&parent); +} + +QTEST_MAIN(tst_QVideoEncoderControl) +#include "tst_qvideoencodercontrol.moc" + + diff --git a/tests/auto/qvideoframe/tst_qvideoframe.cpp b/tests/auto/qvideoframe/tst_qvideoframe.cpp index 58640b71a..37f7dc440 100644 --- a/tests/auto/qvideoframe/tst_qvideoframe.cpp +++ b/tests/auto/qvideoframe/tst_qvideoframe.cpp @@ -83,6 +83,10 @@ private slots: void imageDetach(); void formatConversion_data(); void formatConversion(); + + void isMapped(); + void isReadable(); + void isWritable(); }; Q_DECLARE_METATYPE(QImage::Format) @@ -344,6 +348,27 @@ void tst_QVideoFrame::copy_data() << QVideoFrame::TopField << qint64(63641740) << qint64(63641954); + QTest::newRow("64x64 ARGB32") + << QAbstractVideoBuffer::GLTextureHandle + << QSize(64, 64) + << QVideoFrame::Format_ARGB32 + << QVideoFrame::BottomField + << qint64(63641740) + << qint64(63641954); + QTest::newRow("32x256 YUV420P") + << QAbstractVideoBuffer::UserHandle + << QSize(32, 256) + << QVideoFrame::Format_YUV420P + << QVideoFrame::InterlacedFrame + << qint64(12345) + << qint64(12389); + QTest::newRow("1052x756 ARGB32") + << QAbstractVideoBuffer::NoHandle + << QSize(1052, 756) + << QVideoFrame::Format_ARGB32 + << QVideoFrame::ProgressiveFrame + << qint64(12345) + << qint64(12389); QTest::newRow("32x256 YUV420P") << QAbstractVideoBuffer::UserHandle << QSize(32, 256) @@ -399,7 +424,7 @@ void tst_QVideoFrame::copy() QVERIFY(!buffer.isNull()); - QVERIFY(otherFrame.isValid()); + QVERIFY(otherFrame.isValid()); QCOMPARE(otherFrame.handleType(), handleType); QCOMPARE(otherFrame.pixelFormat(), pixelFormat); QCOMPARE(otherFrame.size(), size); @@ -782,12 +807,98 @@ void tst_QVideoFrame::formatConversion() QFETCH(QVideoFrame::PixelFormat, pixelFormat); QCOMPARE(QVideoFrame::pixelFormatFromImageFormat(imageFormat) == pixelFormat, - imageFormat != QImage::Format_Invalid); + imageFormat != QImage::Format_Invalid); QCOMPARE(QVideoFrame::imageFormatFromPixelFormat(pixelFormat) == imageFormat, pixelFormat != QVideoFrame::Format_Invalid); } +#define TEST_MAPPED(frame, mode) \ +do { \ + QVERIFY(frame.bits()); \ + QVERIFY(frame.isMapped()); \ + QCOMPARE(frame.mappedBytes(), 16384); \ + QCOMPARE(frame.bytesPerLine(), 256); \ + QCOMPARE(frame.mapMode(), mode); \ +} while (0) + +#define TEST_UNMAPPED(frame) \ +do { \ + QVERIFY(!frame.bits()); \ + QVERIFY(!frame.isMapped()); \ + QCOMPARE(frame.mappedBytes(), 0); \ + QCOMPARE(frame.bytesPerLine(), 0); \ + QCOMPARE(frame.mapMode(), QAbstractVideoBuffer::NotMapped); \ +} while (0) + +void tst_QVideoFrame::isMapped() +{ + QVideoFrame frame(16384, QSize(64, 64), 256, QVideoFrame::Format_ARGB32); + TEST_UNMAPPED(frame); + + QVERIFY(frame.map(QAbstractVideoBuffer::ReadOnly)); + TEST_MAPPED(frame, QAbstractVideoBuffer::ReadOnly); + frame.unmap(); + TEST_UNMAPPED(frame); + + QVERIFY(frame.map(QAbstractVideoBuffer::WriteOnly)); + TEST_MAPPED(frame, QAbstractVideoBuffer::WriteOnly); + frame.unmap(); + TEST_UNMAPPED(frame); + + QVERIFY(frame.map(QAbstractVideoBuffer::ReadWrite)); + TEST_MAPPED(frame, QAbstractVideoBuffer::ReadWrite); + frame.unmap(); + TEST_UNMAPPED(frame); +} + +void tst_QVideoFrame::isReadable() +{ + QVideoFrame frame(16384, QSize(64, 64), 256, QVideoFrame::Format_ARGB32); + + QVERIFY(!frame.isMapped()); + QVERIFY(!frame.isReadable()); + + QVERIFY(frame.map(QAbstractVideoBuffer::ReadOnly)); + QVERIFY(frame.isMapped()); + QVERIFY(frame.isReadable()); + frame.unmap(); + + QVERIFY(frame.map(QAbstractVideoBuffer::WriteOnly)); + QVERIFY(frame.isMapped()); + QVERIFY(!frame.isReadable()); + frame.unmap(); + + QVERIFY(frame.map(QAbstractVideoBuffer::ReadWrite)); + QVERIFY(frame.isMapped()); + QVERIFY(frame.isReadable()); + frame.unmap(); +} + +void tst_QVideoFrame::isWritable() +{ + QVideoFrame frame(16384, QSize(64, 64), 256, QVideoFrame::Format_ARGB32); + + QVERIFY(!frame.isMapped()); + QVERIFY(!frame.isWritable()); + + QVERIFY(frame.map(QAbstractVideoBuffer::ReadOnly)); + QVERIFY(frame.isMapped()); + QVERIFY(!frame.isWritable()); + frame.unmap(); + + QVERIFY(frame.map(QAbstractVideoBuffer::WriteOnly)); + QVERIFY(frame.isMapped()); + QVERIFY(frame.isWritable()); + frame.unmap(); + + QVERIFY(frame.map(QAbstractVideoBuffer::ReadWrite)); + QVERIFY(frame.isMapped()); + QVERIFY(frame.isWritable()); + frame.unmap(); +} + + QTEST_MAIN(tst_QVideoFrame) #include "tst_qvideoframe.moc" diff --git a/tests/auto/qvideosurfaceformat/tst_qvideosurfaceformat.cpp b/tests/auto/qvideosurfaceformat/tst_qvideosurfaceformat.cpp index 6a751ff20..c72f5fa94 100644 --- a/tests/auto/qvideosurfaceformat/tst_qvideosurfaceformat.cpp +++ b/tests/auto/qvideosurfaceformat/tst_qvideosurfaceformat.cpp @@ -81,6 +81,12 @@ private slots: void compare(); void copy(); void assign(); + + void isValid(); + void yCbCrColorSpaceEnum_data(); + void yCbCrColorSpaceEnum (); + void copyAllParameters (); + void assignAllParameters (); }; tst_QVideoSurfaceFormat::tst_QVideoSurfaceFormat() @@ -733,6 +739,133 @@ void tst_QVideoSurfaceFormat::assign() QCOMPARE(original != copy, true); } +/* Test case for Enum YCbCr_BT601, YCbCr_xvYCC709 */ +void tst_QVideoSurfaceFormat::yCbCrColorSpaceEnum_data() +{ + QTest::addColumn<QVideoSurfaceFormat::YCbCrColorSpace>("colorspace"); + + QTest::newRow("YCbCr_BT601") + << QVideoSurfaceFormat::YCbCr_BT601; + QTest::newRow("YCbCr_xvYCC709") + << QVideoSurfaceFormat::YCbCr_xvYCC709; +} + +/* Test case for Enum YCbCr_BT601, YCbCr_xvYCC709 */ +void tst_QVideoSurfaceFormat::yCbCrColorSpaceEnum() +{ + QFETCH(QVideoSurfaceFormat::YCbCrColorSpace, colorspace); + + { + QVideoSurfaceFormat format(QSize(64, 64), QVideoFrame::Format_RGB32); + format.setYCbCrColorSpace(colorspace); + + QCOMPARE(format.yCbCrColorSpace(), colorspace); + QCOMPARE(qvariant_cast<QVideoSurfaceFormat::YCbCrColorSpace>(format.property("yCbCrColorSpace")), + colorspace); + } + { + QVideoSurfaceFormat format(QSize(64, 64), QVideoFrame::Format_RGB32); + format.setProperty("yCbCrColorSpace", qVariantFromValue(colorspace)); + + QCOMPARE(format.yCbCrColorSpace(), colorspace); + QCOMPARE(qvariant_cast<QVideoSurfaceFormat::YCbCrColorSpace>(format.property("yCbCrColorSpace")), + colorspace); + } +} + +/* Test case for api isValid */ +void tst_QVideoSurfaceFormat::isValid() +{ + /* When both pixel format and framesize is not valid */ + QVideoSurfaceFormat format; + QVERIFY(!format.isValid()); + + /* When framesize is valid and pixel format is not valid */ + format.setFrameSize(64,64); + QVERIFY(format.frameSize() == QSize(64,64)); + QVERIFY(!format.pixelFormat()); + QVERIFY(!format.isValid()); + + /* When both the pixel format and framesize is valid. */ + QVideoSurfaceFormat format1(QSize(32, 32), QVideoFrame::Format_AYUV444); + QVERIFY(format1.isValid()); + + /* When pixel format is valid and frame size is not valid */ + format1.setFrameSize(-1,-1); + QVERIFY(!format1.frameSize().isValid()); + QVERIFY(!format1.isValid()); +} + +/* Test case for copy constructor with all the parameters. */ +void tst_QVideoSurfaceFormat::copyAllParameters() +{ + /* Create the instance and set all the parameters. */ + QVideoSurfaceFormat original( + QSize(1024, 768), QVideoFrame::Format_ARGB32, QAbstractVideoBuffer::GLTextureHandle); + + original.setScanLineDirection(QVideoSurfaceFormat::BottomToTop); + original.setViewport(QRect(0, 0, 1024, 1024)); + original.setFrameRate(qreal(15.0)); + original.setPixelAspectRatio(QSize(320,480)); + original.setYCbCrColorSpace(QVideoSurfaceFormat::YCbCr_BT709); + + /* Copy the original instance to copy and verify if both the instances + have the same parameters. */ + QVideoSurfaceFormat copy(original); + + QCOMPARE(copy.handleType(), QAbstractVideoBuffer::GLTextureHandle); + QCOMPARE(copy.pixelFormat(), QVideoFrame::Format_ARGB32); + QCOMPARE(copy.frameSize(), QSize(1024, 768)); + QCOMPARE(copy.scanLineDirection(), QVideoSurfaceFormat::BottomToTop); + QCOMPARE(copy.viewport(), QRect(0, 0, 1024, 1024)); + QCOMPARE(copy.frameRate(), qreal(15.0)); + QCOMPARE(copy.pixelAspectRatio(), QSize(320,480)); + QCOMPARE(copy.yCbCrColorSpace(), QVideoSurfaceFormat::YCbCr_BT709); + + /* Verify if both the instances are eqaul */ + QCOMPARE(original == copy, true); + QCOMPARE(original != copy, false); +} + +/* Test case for copy constructor with all the parameters. */ +void tst_QVideoSurfaceFormat::assignAllParameters() +{ + /* Create the instance and set all the parameters. */ + QVideoSurfaceFormat copy( + QSize(64, 64), QVideoFrame::Format_AYUV444, QAbstractVideoBuffer::UserHandle); + copy.setScanLineDirection(QVideoSurfaceFormat::TopToBottom); + copy.setViewport(QRect(0, 0, 640, 320)); + copy.setFrameRate(qreal(7.5)); + copy.setPixelAspectRatio(QSize(640,320)); + copy.setYCbCrColorSpace(QVideoSurfaceFormat::YCbCr_BT601); + + /* Create the instance and set all the parameters. */ + QVideoSurfaceFormat original( + QSize(1024, 768), QVideoFrame::Format_ARGB32, QAbstractVideoBuffer::GLTextureHandle); + original.setScanLineDirection(QVideoSurfaceFormat::BottomToTop); + original.setViewport(QRect(0, 0, 1024, 1024)); + original.setFrameRate(qreal(15.0)); + original.setPixelAspectRatio(QSize(320,480)); + original.setYCbCrColorSpace(QVideoSurfaceFormat::YCbCr_BT709); + + /* Assign the original instance to copy and verify if both the instancess + have the same parameters. */ + copy = original; + + QCOMPARE(copy.handleType(), QAbstractVideoBuffer::GLTextureHandle); + QCOMPARE(copy.pixelFormat(), QVideoFrame::Format_ARGB32); + QCOMPARE(copy.frameSize(), QSize(1024, 768)); + QCOMPARE(copy.scanLineDirection(), QVideoSurfaceFormat::BottomToTop); + QCOMPARE(copy.viewport(), QRect(0, 0, 1024, 1024)); + QCOMPARE(copy.frameRate(), qreal(15.0)); + QCOMPARE(copy.pixelAspectRatio(), QSize(320,480)); + QCOMPARE(copy.yCbCrColorSpace(), QVideoSurfaceFormat::YCbCr_BT709); + + /* Verify if both the instances are eqaul */ + QCOMPARE(original == copy, true); + QCOMPARE(original != copy, false); +} + QTEST_MAIN(tst_QVideoSurfaceFormat) #include "tst_qvideosurfaceformat.moc" |