1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the test suite of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29//TESTED_COMPONENT=src/multimedia
30
31#include <QtTest/QtTest>
32#include <QDebug>
33#include <QtMultimedia/qmediametadata.h>
34#include <qmediaobject.h>
35#include <qmediacontrol.h>
36#include <qmediaservice.h>
37#include <qmediarecordercontrol.h>
38#include <qmediarecorder.h>
39#include <qmetadatawritercontrol.h>
40#include <qaudioinputselectorcontrol.h>
41#include <qaudioencodersettingscontrol.h>
42#include <qmediacontainercontrol.h>
43#include <qvideoencodersettingscontrol.h>
44#include <qaudioformat.h>
45
46#include "mockmediarecorderservice.h"
47#include "mockmediaobject.h"
48
49QT_USE_NAMESPACE
50
51class tst_QMediaRecorder: public QObject
52{
53 Q_OBJECT
54
55public slots:
56 void initTestCase();
57 void cleanupTestCase();
58
59private slots:
60 void testNullService();
61 void testNullControls();
62 void testDeleteMediaObject();
63 void testError();
64 void testSink();
65 void testRecord();
66 void testMute();
67 void testVolume();
68 void testAudioDeviceControl();
69 void testAudioEncodeControl();
70 void testMediaFormatsControl();
71 void testVideoEncodeControl();
72 void testEncodingSettings();
73 void testAudioSettings();
74 void testVideoSettings();
75 void testSettingsApplied();
76
77 void nullMetaDataControl();
78 void isMetaDataAvailable();
79 void isWritable();
80 void metaDataChanged();
81 void metaData_data();
82 void metaData();
83 void setMetaData_data();
84 void setMetaData();
85
86 void testAudioSettingsCopyConstructor();
87 void testAudioSettingsOperatorNotEqual();
88 void testAudioSettingsOperatorEqual();
89 void testAudioSettingsOperatorAssign();
90 void testAudioSettingsDestructor();
91
92 void testAvailabilityStatus();
93 void testIsAvailable();
94 void testMediaObject();
95 void testEnum();
96
97 void testVideoSettingsQuality();
98 void testVideoSettingsEncodingMode();
99 void testVideoSettingsCopyConstructor();
100 void testVideoSettingsOperatorAssignment();
101 void testVideoSettingsOperatorNotEqual();
102 void testVideoSettingsOperatorComparison();
103 void testVideoSettingsDestructor();
104
105private:
106 QAudioEncoderSettingsControl* encode;
107 QAudioInputSelectorControl* audio;
108 MockMediaObject *object;
109 MockMediaRecorderService*service;
110 MockMediaRecorderControl *mock;
111 QMediaRecorder *capture;
112 QVideoEncoderSettingsControl* videoEncode;
113};
114
115void tst_QMediaRecorder::initTestCase()
116{
117 qRegisterMetaType<QMediaRecorder::State>(typeName: "QMediaRecorder::State");
118 qRegisterMetaType<QMediaRecorder::Error>(typeName: "QMediaRecorder::Error");
119
120 mock = new MockMediaRecorderControl(this);
121 service = new MockMediaRecorderService(this, mock);
122 object = new MockMediaObject(this, service);
123 capture = new QMediaRecorder(object);
124
125 audio = qobject_cast<QAudioInputSelectorControl*>(object: service->requestControl(QAudioInputSelectorControl_iid));
126 encode = qobject_cast<QAudioEncoderSettingsControl*>(object: service->requestControl(QAudioEncoderSettingsControl_iid));
127 videoEncode = qobject_cast<QVideoEncoderSettingsControl*>(object: service->requestControl(QVideoEncoderSettingsControl_iid));
128}
129
130void tst_QMediaRecorder::cleanupTestCase()
131{
132 delete capture;
133 delete object;
134 delete service;
135 delete mock;
136}
137
138void tst_QMediaRecorder::testNullService()
139{
140 const QString id(QLatin1String("application/x-format"));
141
142 MockMediaObject object(0, 0);
143 QMediaRecorder recorder(&object);
144
145 QCOMPARE(recorder.outputLocation(), QUrl());
146 QCOMPARE(recorder.state(), QMediaRecorder::StoppedState);
147 QCOMPARE(recorder.error(), QMediaRecorder::NoError);
148 QCOMPARE(recorder.duration(), qint64(0));
149 QCOMPARE(recorder.supportedContainers(), QStringList());
150 QCOMPARE(recorder.containerDescription(id), QString());
151 QCOMPARE(recorder.supportedAudioCodecs(), QStringList());
152 QCOMPARE(recorder.audioCodecDescription(id), QString());
153 QCOMPARE(recorder.supportedAudioSampleRates(), QList<int>());
154 QCOMPARE(recorder.supportedVideoCodecs(), QStringList());
155 QCOMPARE(recorder.videoCodecDescription(id), QString());
156 bool continuous = true;
157 QCOMPARE(recorder.supportedResolutions(QVideoEncoderSettings(), &continuous), QList<QSize>());
158 QCOMPARE(continuous, false);
159 continuous = true;
160 QCOMPARE(recorder.supportedFrameRates(QVideoEncoderSettings(), &continuous), QList<qreal>());
161 QCOMPARE(continuous, false);
162 QCOMPARE(recorder.audioSettings(), QAudioEncoderSettings());
163 QCOMPARE(recorder.videoSettings(), QVideoEncoderSettings());
164 QCOMPARE(recorder.containerFormat(), QString());
165 QVERIFY(!recorder.isMuted());
166 recorder.setMuted(true);
167 QVERIFY(!recorder.isMuted());
168}
169
170void tst_QMediaRecorder::testNullControls()
171{
172 const QString id(QLatin1String("application/x-format"));
173
174 MockMediaRecorderService service(0, 0);
175 service.hasControls = false;
176 MockMediaObject object(0, &service);
177 QMediaRecorder recorder(&object);
178
179 QCOMPARE(recorder.outputLocation(), QUrl());
180 QCOMPARE(recorder.state(), QMediaRecorder::StoppedState);
181 QCOMPARE(recorder.error(), QMediaRecorder::NoError);
182 QCOMPARE(recorder.duration(), qint64(0));
183 QCOMPARE(recorder.supportedContainers(), QStringList());
184 QCOMPARE(recorder.containerDescription(id), QString());
185 QCOMPARE(recorder.supportedAudioCodecs(), QStringList());
186 QCOMPARE(recorder.audioCodecDescription(id), QString());
187 QCOMPARE(recorder.supportedAudioSampleRates(), QList<int>());
188 QCOMPARE(recorder.supportedVideoCodecs(), QStringList());
189 QCOMPARE(recorder.videoCodecDescription(id), QString());
190 bool continuous = true;
191 QCOMPARE(recorder.supportedResolutions(QVideoEncoderSettings(), &continuous), QList<QSize>());
192 QCOMPARE(continuous, false);
193 continuous = true;
194 QCOMPARE(recorder.supportedFrameRates(QVideoEncoderSettings(), &continuous), QList<qreal>());
195 QCOMPARE(continuous, false);
196 QCOMPARE(recorder.audioSettings(), QAudioEncoderSettings());
197 QCOMPARE(recorder.videoSettings(), QVideoEncoderSettings());
198 QCOMPARE(recorder.containerFormat(), QString());
199
200 recorder.setOutputLocation(QUrl("file://test/save/file.mp4"));
201 QCOMPARE(recorder.outputLocation(), QUrl());
202 QCOMPARE(recorder.actualLocation(), QUrl());
203
204 QAudioEncoderSettings audio;
205 audio.setCodec(id);
206 audio.setQuality(QMultimedia::LowQuality);
207
208 QVideoEncoderSettings video;
209 video.setCodec(id);
210 video.setResolution(width: 640, height: 480);
211
212 recorder.setEncodingSettings(audioSettings: audio, videoSettings: video, containerMimeType: id);
213
214 QCOMPARE(recorder.audioSettings(), QAudioEncoderSettings());
215 QCOMPARE(recorder.videoSettings(), QVideoEncoderSettings());
216 QCOMPARE(recorder.containerFormat(), QString());
217
218 QSignalSpy spy(&recorder, SIGNAL(stateChanged(QMediaRecorder::State)));
219
220 recorder.record();
221 QCOMPARE(recorder.state(), QMediaRecorder::StoppedState);
222 QCOMPARE(recorder.error(), QMediaRecorder::NoError);
223 QCOMPARE(spy.count(), 0);
224
225 recorder.pause();
226 QCOMPARE(recorder.state(), QMediaRecorder::StoppedState);
227 QCOMPARE(recorder.error(), QMediaRecorder::NoError);
228 QCOMPARE(spy.count(), 0);
229
230 recorder.stop();
231 QCOMPARE(recorder.state(), QMediaRecorder::StoppedState);
232 QCOMPARE(recorder.error(), QMediaRecorder::NoError);
233 QCOMPARE(spy.count(), 0);
234}
235
236void tst_QMediaRecorder::testDeleteMediaObject()
237{
238 MockMediaRecorderControl *mock = new MockMediaRecorderControl(this);
239 MockMediaRecorderService *service = new MockMediaRecorderService(this, mock);
240 MockMediaObject *object = new MockMediaObject(this, service);
241 QMediaRecorder *capture = new QMediaRecorder(object);
242
243 QVERIFY(capture->mediaObject() == object);
244 QVERIFY(capture->isAvailable());
245
246 delete object;
247 delete service;
248 delete mock;
249
250 QVERIFY(capture->mediaObject() == 0);
251 QVERIFY(!capture->isAvailable());
252
253 delete capture;
254}
255
256void tst_QMediaRecorder::testError()
257{
258 const QString errorString(QLatin1String("format error"));
259
260 QSignalSpy spy(capture, SIGNAL(error(QMediaRecorder::Error)));
261
262 QCOMPARE(capture->error(), QMediaRecorder::NoError);
263 QCOMPARE(capture->errorString(), QString());
264
265 mock->error(error: QMediaRecorder::FormatError, errorString);
266 QCOMPARE(capture->error(), QMediaRecorder::FormatError);
267 QCOMPARE(capture->errorString(), errorString);
268 QCOMPARE(spy.count(), 1);
269
270 QCOMPARE(spy.last()[0].value<QMediaRecorder::Error>(), QMediaRecorder::FormatError);
271}
272
273void tst_QMediaRecorder::testSink()
274{
275 capture->setOutputLocation(QUrl("test.tmp"));
276 QUrl s = capture->outputLocation();
277 QCOMPARE(s.toString(), QString("test.tmp"));
278 QCOMPARE(capture->actualLocation(), QUrl());
279
280 //the actual location is available after record
281 capture->record();
282 QCOMPARE(capture->actualLocation().toString(), QString("test.tmp"));
283 capture->stop();
284 QCOMPARE(capture->actualLocation().toString(), QString("test.tmp"));
285
286 //setOutputLocation resets the actual location
287 capture->setOutputLocation(QUrl());
288 QCOMPARE(capture->actualLocation(), QUrl());
289
290 capture->record();
291 QCOMPARE(capture->actualLocation(), QUrl::fromLocalFile("default_name.mp4"));
292 capture->stop();
293 QCOMPARE(capture->actualLocation(), QUrl::fromLocalFile("default_name.mp4"));
294}
295
296void tst_QMediaRecorder::testRecord()
297{
298 QSignalSpy stateSignal(capture,SIGNAL(stateChanged(QMediaRecorder::State)));
299 QSignalSpy statusSignal(capture,SIGNAL(statusChanged(QMediaRecorder::Status)));
300 QSignalSpy progressSignal(capture, SIGNAL(durationChanged(qint64)));
301 capture->record();
302 QCOMPARE(capture->state(), QMediaRecorder::RecordingState);
303 QCOMPARE(capture->error(), QMediaRecorder::NoError);
304 QCOMPARE(capture->errorString(), QString());
305
306 QCOMPARE(stateSignal.count(), 1);
307 QCOMPARE(stateSignal.last()[0].value<QMediaRecorder::State>(), QMediaRecorder::RecordingState);
308
309 QTestEventLoop::instance().enterLoop(secs: 1);
310
311 QCOMPARE(capture->status(), QMediaRecorder::RecordingStatus);
312 QVERIFY(!statusSignal.isEmpty());
313 QCOMPARE(statusSignal.last()[0].value<QMediaRecorder::Status>(), QMediaRecorder::RecordingStatus);
314 statusSignal.clear();
315
316 QVERIFY(progressSignal.count() > 0);
317
318 capture->pause();
319
320 QCOMPARE(capture->state(), QMediaRecorder::PausedState);
321
322 QCOMPARE(stateSignal.count(), 2);
323
324 QTestEventLoop::instance().enterLoop(secs: 1);
325 QCOMPARE(capture->status(), QMediaRecorder::PausedStatus);
326 QVERIFY(!statusSignal.isEmpty());
327 QCOMPARE(statusSignal.last()[0].value<QMediaRecorder::Status>(), QMediaRecorder::PausedStatus);
328 statusSignal.clear();
329
330 capture->stop();
331
332 QCOMPARE(capture->state(), QMediaRecorder::StoppedState);
333 QCOMPARE(stateSignal.count(), 3);
334
335 QTestEventLoop::instance().enterLoop(secs: 1);
336 QCOMPARE(capture->status(), QMediaRecorder::LoadedStatus);
337 QVERIFY(!statusSignal.isEmpty());
338 QCOMPARE(statusSignal.last()[0].value<QMediaRecorder::Status>(), QMediaRecorder::LoadedStatus);
339 statusSignal.clear();
340
341 mock->stop();
342 QCOMPARE(stateSignal.count(), 3);
343}
344
345void tst_QMediaRecorder::testMute()
346{
347 QSignalSpy mutedChanged(capture, SIGNAL(mutedChanged(bool)));
348 QVERIFY(!capture->isMuted());
349 capture->setMuted(true);
350
351 QCOMPARE(mutedChanged.size(), 1);
352 QCOMPARE(mutedChanged[0][0].toBool(), true);
353 QVERIFY(capture->isMuted());
354
355 capture->setMuted(false);
356
357 QCOMPARE(mutedChanged.size(), 2);
358 QCOMPARE(mutedChanged[1][0].toBool(), false);
359 QVERIFY(!capture->isMuted());
360
361 capture->setMuted(false);
362 QCOMPARE(mutedChanged.size(), 2);
363}
364
365void tst_QMediaRecorder::testVolume()
366{
367 QSignalSpy volumeChanged(capture, SIGNAL(volumeChanged(qreal)));
368 QCOMPARE(capture->volume(), 1.0);
369 capture->setVolume(2.0);
370
371 QCOMPARE(volumeChanged.size(), 1);
372 QCOMPARE(volumeChanged[0][0].toReal(), 2.0);
373 QCOMPARE(capture->volume(), 2.0);
374
375 capture->setVolume(1.0);
376
377 QCOMPARE(volumeChanged.size(), 2);
378 QCOMPARE(volumeChanged[1][0].toReal(), 1.0);
379 QCOMPARE(capture->volume(), 1.0);
380
381 capture->setVolume(1.0);
382 QCOMPARE(volumeChanged.size(), 2);
383}
384
385void tst_QMediaRecorder::testAudioDeviceControl()
386{
387 QSignalSpy readSignal(audio,SIGNAL(activeInputChanged(QString)));
388 QVERIFY(audio->availableInputs().size() == 3);
389 QVERIFY(audio->defaultInput().compare("device1") == 0);
390 audio->setActiveInput("device2");
391 QTestEventLoop::instance().enterLoop(secs: 1);
392 QVERIFY(audio->activeInput().compare("device2") == 0);
393 QVERIFY(readSignal.count() == 1);
394 QVERIFY(audio->inputDescription("device2").compare("dev2 comment") == 0);
395}
396
397void tst_QMediaRecorder::testAudioEncodeControl()
398{
399 QStringList codecs = capture->supportedAudioCodecs();
400 QVERIFY(codecs.count() == 2);
401 QVERIFY(capture->audioCodecDescription("audio/pcm") == "Pulse Code Modulation");
402 QList<int> rates;
403 rates << 8000 << 11025 << 22050 << 44100;
404 QCOMPARE(capture->supportedAudioSampleRates(), rates);
405}
406
407void tst_QMediaRecorder::testMediaFormatsControl()
408{
409 QCOMPARE(capture->supportedContainers(), QStringList() << "wav" << "mp3" << "mov");
410
411 QCOMPARE(capture->containerDescription("wav"), QString("WAV format"));
412 QCOMPARE(capture->containerDescription("mp3"), QString("MP3 format"));
413 QCOMPARE(capture->containerDescription("ogg"), QString());
414}
415
416void tst_QMediaRecorder::testVideoEncodeControl()
417{
418 bool continuous = false;
419 QList<QSize> sizes = capture->supportedResolutions(settings: QVideoEncoderSettings(), continuous: &continuous);
420 QCOMPARE(sizes.count(), 2);
421 QCOMPARE(continuous, true);
422
423 QList<qreal> rates = capture->supportedFrameRates(settings: QVideoEncoderSettings(), continuous: &continuous);
424 QCOMPARE(rates.count(), 3);
425 QCOMPARE(continuous, false);
426
427 QStringList vCodecs = capture->supportedVideoCodecs();
428 QVERIFY(vCodecs.count() == 2);
429 QCOMPARE(capture->videoCodecDescription("video/3gpp"), QString("video/3gpp"));
430}
431
432void tst_QMediaRecorder::testEncodingSettings()
433{
434 QAudioEncoderSettings audioSettings = capture->audioSettings();
435 QCOMPARE(audioSettings.codec(), QString("audio/pcm"));
436 QCOMPARE(audioSettings.bitRate(), 128*1024);
437 QCOMPARE(audioSettings.sampleRate(), 8000);
438 QCOMPARE(audioSettings.quality(), QMultimedia::NormalQuality);
439 QCOMPARE(audioSettings.channelCount(), -1);
440
441 QCOMPARE(audioSettings.encodingMode(), QMultimedia::ConstantQualityEncoding);
442
443 QVideoEncoderSettings videoSettings = capture->videoSettings();
444 QCOMPARE(videoSettings.codec(), QString());
445 QCOMPARE(videoSettings.bitRate(), -1);
446 QCOMPARE(videoSettings.resolution(), QSize());
447 QCOMPARE(videoSettings.frameRate(), 0.0);
448 QCOMPARE(videoSettings.quality(), QMultimedia::NormalQuality);
449 QCOMPARE(videoSettings.encodingMode(), QMultimedia::ConstantQualityEncoding);
450
451 QString format = capture->containerFormat();
452 QCOMPARE(format, QString());
453
454 audioSettings.setCodec("audio/mpeg");
455 audioSettings.setSampleRate(44100);
456 audioSettings.setBitRate(256*1024);
457 audioSettings.setQuality(QMultimedia::HighQuality);
458 audioSettings.setEncodingMode(QMultimedia::AverageBitRateEncoding);
459
460 videoSettings.setCodec("video/3gpp");
461 videoSettings.setBitRate(800);
462 videoSettings.setFrameRate(24*1024);
463 videoSettings.setResolution(QSize(800,600));
464 videoSettings.setQuality(QMultimedia::HighQuality);
465 audioSettings.setEncodingMode(QMultimedia::TwoPassEncoding);
466
467 format = QString("mov");
468
469 capture->setAudioSettings(audioSettings);
470 capture->setVideoSettings(videoSettings);
471 capture->setContainerFormat(format);
472
473 QCOMPARE(capture->audioSettings(), audioSettings);
474 QCOMPARE(capture->videoSettings(), videoSettings);
475 QCOMPARE(capture->containerFormat(), format);
476}
477
478void tst_QMediaRecorder::testAudioSettings()
479{
480 QAudioEncoderSettings settings;
481 QVERIFY(settings.isNull());
482 QVERIFY(settings == QAudioEncoderSettings());
483
484 QCOMPARE(settings.codec(), QString());
485 settings.setCodec(QLatin1String("codecName"));
486 QCOMPARE(settings.codec(), QLatin1String("codecName"));
487 QVERIFY(!settings.isNull());
488 QVERIFY(settings != QAudioEncoderSettings());
489
490 settings = QAudioEncoderSettings();
491 QCOMPARE(settings.bitRate(), -1);
492 settings.setBitRate(128000);
493 QCOMPARE(settings.bitRate(), 128000);
494 QVERIFY(!settings.isNull());
495
496 settings = QAudioEncoderSettings();
497 QCOMPARE(settings.quality(), QMultimedia::NormalQuality);
498 settings.setQuality(QMultimedia::HighQuality);
499 QCOMPARE(settings.quality(), QMultimedia::HighQuality);
500 QVERIFY(!settings.isNull());
501
502 settings = QAudioEncoderSettings();
503 QCOMPARE(settings.sampleRate(), -1);
504 settings.setSampleRate(44100);
505 QCOMPARE(settings.sampleRate(), 44100);
506 QVERIFY(!settings.isNull());
507
508 settings = QAudioEncoderSettings();
509 QCOMPARE(settings.channelCount(), -1);
510 settings.setChannelCount(2);
511 QCOMPARE(settings.channelCount(), 2);
512 QVERIFY(!settings.isNull());
513
514 settings = QAudioEncoderSettings();
515 settings.setEncodingOption(option: QLatin1String("encoderOption"), value: QVariant(1));
516 QCOMPARE(settings.encodingOption(QLatin1String("encoderOption")), QVariant(1));
517 QVariantMap options;
518 options.insert(akey: QLatin1String("encoderOption"), avalue: QVariant(1));
519 QCOMPARE(settings.encodingOptions(), options);
520 options.insert(akey: QLatin1String("encoderOption2"), avalue: QVariant(2));
521 options.remove(akey: QLatin1String("encoderOption"));
522 settings.setEncodingOptions(options);
523 QCOMPARE(settings.encodingOption(QLatin1String("encoderOption")), QVariant());
524 QCOMPARE(settings.encodingOption(QLatin1String("encoderOption2")), QVariant(2));
525 QVERIFY(!settings.isNull());
526 QVERIFY(settings != QAudioEncoderSettings());
527
528 settings = QAudioEncoderSettings();
529 QVERIFY(settings.isNull());
530 QCOMPARE(settings.codec(), QString());
531 QCOMPARE(settings.bitRate(), -1);
532 QCOMPARE(settings.quality(), QMultimedia::NormalQuality);
533 QCOMPARE(settings.sampleRate(), -1);
534 QVERIFY(settings.encodingOptions().isEmpty());
535
536 {
537 QAudioEncoderSettings settings1;
538 QAudioEncoderSettings settings2;
539 QCOMPARE(settings2, settings1);
540
541 settings2 = settings1;
542 QCOMPARE(settings2, settings1);
543 QVERIFY(settings2.isNull());
544
545 settings1.setQuality(QMultimedia::HighQuality);
546
547 QVERIFY(settings2.isNull());
548 QVERIFY(!settings1.isNull());
549 QVERIFY(settings1 != settings2);
550 }
551
552 {
553 QAudioEncoderSettings settings1;
554 QAudioEncoderSettings settings2(settings1);
555 QCOMPARE(settings2, settings1);
556
557 settings2 = settings1;
558 QCOMPARE(settings2, settings1);
559 QVERIFY(settings2.isNull());
560
561 settings1.setQuality(QMultimedia::HighQuality);
562
563 QVERIFY(settings2.isNull());
564 QVERIFY(!settings1.isNull());
565 QVERIFY(settings1 != settings2);
566 }
567
568 QAudioEncoderSettings settings1;
569 settings1.setBitRate(1);
570 QAudioEncoderSettings settings2;
571 settings2.setBitRate(1);
572 QVERIFY(settings1 == settings2);
573 settings2.setBitRate(2);
574 QVERIFY(settings1 != settings2);
575
576 settings1 = QAudioEncoderSettings();
577 settings1.setChannelCount(1);
578 settings2 = QAudioEncoderSettings();
579 settings2.setChannelCount(1);
580 QVERIFY(settings1 == settings2);
581 settings2.setChannelCount(2);
582 QVERIFY(settings1 != settings2);
583
584 settings1 = QAudioEncoderSettings();
585 settings1.setCodec("codec1");
586 settings2 = QAudioEncoderSettings();
587 settings2.setCodec("codec1");
588 QVERIFY(settings1 == settings2);
589 settings2.setCodec("codec2");
590 QVERIFY(settings1 != settings2);
591
592 settings1 = QAudioEncoderSettings();
593 settings1.setEncodingMode(QMultimedia::ConstantBitRateEncoding);
594 settings2 = QAudioEncoderSettings();
595 settings2.setEncodingMode(QMultimedia::ConstantBitRateEncoding);
596 QVERIFY(settings1 == settings2);
597 settings2.setEncodingMode(QMultimedia::TwoPassEncoding);
598 QVERIFY(settings1 != settings2);
599
600 settings1 = QAudioEncoderSettings();
601 settings1.setQuality(QMultimedia::NormalQuality);
602 settings2 = QAudioEncoderSettings();
603 settings2.setQuality(QMultimedia::NormalQuality);
604 QVERIFY(settings1 == settings2);
605 settings2.setQuality(QMultimedia::LowQuality);
606 QVERIFY(settings1 != settings2);
607
608 settings1 = QAudioEncoderSettings();
609 settings1.setSampleRate(1);
610 settings2 = QAudioEncoderSettings();
611 settings2.setSampleRate(1);
612 QVERIFY(settings1 == settings2);
613 settings2.setSampleRate(2);
614 QVERIFY(settings1 != settings2);
615
616 settings1 = QAudioEncoderSettings();
617 settings1.setEncodingOption(option: QLatin1String("encoderOption"), value: QVariant(1));
618 settings2 = QAudioEncoderSettings();
619 settings2.setEncodingOption(option: QLatin1String("encoderOption"), value: QVariant(1));
620 QVERIFY(settings1 == settings2);
621 settings2.setEncodingOption(option: QLatin1String("encoderOption"), value: QVariant(2));
622 QVERIFY(settings1 != settings2);
623}
624
625void tst_QMediaRecorder::testVideoSettings()
626{
627 QVideoEncoderSettings settings;
628 QVERIFY(settings.isNull());
629 QVERIFY(settings == QVideoEncoderSettings());
630
631 QCOMPARE(settings.codec(), QString());
632 settings.setCodec(QLatin1String("codecName"));
633 QCOMPARE(settings.codec(), QLatin1String("codecName"));
634 QVERIFY(!settings.isNull());
635 QVERIFY(settings != QVideoEncoderSettings());
636
637 settings = QVideoEncoderSettings();
638 QCOMPARE(settings.bitRate(), -1);
639 settings.setBitRate(128000);
640 QCOMPARE(settings.bitRate(), 128000);
641 QVERIFY(!settings.isNull());
642
643 settings = QVideoEncoderSettings();
644 QCOMPARE(settings.quality(), QMultimedia::NormalQuality);
645 settings.setQuality(QMultimedia::HighQuality);
646 QCOMPARE(settings.quality(), QMultimedia::HighQuality);
647 QVERIFY(!settings.isNull());
648
649 settings = QVideoEncoderSettings();
650 QCOMPARE(settings.frameRate(), qreal());
651 settings.setFrameRate(30000.0/10001);
652 QVERIFY(qFuzzyCompare(settings.frameRate(), qreal(30000.0/10001)));
653 settings.setFrameRate(24.0);
654 QVERIFY(qFuzzyCompare(settings.frameRate(), qreal(24.0)));
655 QVERIFY(!settings.isNull());
656
657 settings = QVideoEncoderSettings();
658 QCOMPARE(settings.resolution(), QSize());
659 settings.setResolution(QSize(320,240));
660 QCOMPARE(settings.resolution(), QSize(320,240));
661 settings.setResolution(width: 800,height: 600);
662 QCOMPARE(settings.resolution(), QSize(800,600));
663 QVERIFY(!settings.isNull());
664
665 settings = QVideoEncoderSettings();
666 settings.setEncodingOption(option: QLatin1String("encoderOption"), value: QVariant(1));
667 QCOMPARE(settings.encodingOption(QLatin1String("encoderOption")), QVariant(1));
668 QVariantMap options;
669 options.insert(akey: QLatin1String("encoderOption"), avalue: QVariant(1));
670 QCOMPARE(settings.encodingOptions(), options);
671 options.insert(akey: QLatin1String("encoderOption2"), avalue: QVariant(2));
672 options.remove(akey: QLatin1String("encoderOption"));
673 settings.setEncodingOptions(options);
674 QCOMPARE(settings.encodingOption(QLatin1String("encoderOption")), QVariant());
675 QCOMPARE(settings.encodingOption(QLatin1String("encoderOption2")), QVariant(2));
676 QVERIFY(!settings.isNull());
677 QVERIFY(settings != QVideoEncoderSettings());
678
679 settings = QVideoEncoderSettings();
680 QVERIFY(settings.isNull());
681 QCOMPARE(settings.codec(), QString());
682 QCOMPARE(settings.bitRate(), -1);
683 QCOMPARE(settings.quality(), QMultimedia::NormalQuality);
684 QCOMPARE(settings.frameRate(), qreal());
685 QCOMPARE(settings.resolution(), QSize());
686 QVERIFY(settings.encodingOptions().isEmpty());
687
688 {
689 QVideoEncoderSettings settings1;
690 QVideoEncoderSettings settings2;
691 QCOMPARE(settings2, settings1);
692
693 settings2 = settings1;
694 QCOMPARE(settings2, settings1);
695 QVERIFY(settings2.isNull());
696
697 settings1.setQuality(QMultimedia::HighQuality);
698
699 QVERIFY(settings2.isNull());
700 QVERIFY(!settings1.isNull());
701 QVERIFY(settings1 != settings2);
702 }
703
704 {
705 QVideoEncoderSettings settings1;
706 QVideoEncoderSettings settings2(settings1);
707 QCOMPARE(settings2, settings1);
708
709 settings2 = settings1;
710 QCOMPARE(settings2, settings1);
711 QVERIFY(settings2.isNull());
712
713 settings1.setQuality(QMultimedia::HighQuality);
714
715 QVERIFY(settings2.isNull());
716 QVERIFY(!settings1.isNull());
717 QVERIFY(settings1 != settings2);
718 }
719
720 QVideoEncoderSettings settings1;
721 settings1.setBitRate(1);
722 QVideoEncoderSettings settings2;
723 settings2.setBitRate(1);
724 QVERIFY(settings1 == settings2);
725 settings2.setBitRate(2);
726 QVERIFY(settings1 != settings2);
727
728 settings1 = QVideoEncoderSettings();
729 settings1.setResolution(width: 800,height: 600);
730 settings2 = QVideoEncoderSettings();
731 settings2.setResolution(QSize(800,600));
732 QVERIFY(settings1 == settings2);
733 settings2.setResolution(QSize(400,300));
734 QVERIFY(settings1 != settings2);
735
736 settings1 = QVideoEncoderSettings();
737 settings1.setCodec("codec1");
738 settings2 = QVideoEncoderSettings();
739 settings2.setCodec("codec1");
740 QVERIFY(settings1 == settings2);
741 settings2.setCodec("codec2");
742 QVERIFY(settings1 != settings2);
743
744 settings1 = QVideoEncoderSettings();
745 settings1.setEncodingMode(QMultimedia::ConstantBitRateEncoding);
746 settings2 = QVideoEncoderSettings();
747 settings2.setEncodingMode(QMultimedia::ConstantBitRateEncoding);
748 QVERIFY(settings1 == settings2);
749 settings2.setEncodingMode(QMultimedia::TwoPassEncoding);
750 QVERIFY(settings1 != settings2);
751
752 settings1 = QVideoEncoderSettings();
753 settings1.setQuality(QMultimedia::NormalQuality);
754 settings2 = QVideoEncoderSettings();
755 settings2.setQuality(QMultimedia::NormalQuality);
756 QVERIFY(settings1 == settings2);
757 settings2.setQuality(QMultimedia::LowQuality);
758 QVERIFY(settings1 != settings2);
759
760 settings1 = QVideoEncoderSettings();
761 settings1.setFrameRate(1);
762 settings2 = QVideoEncoderSettings();
763 settings2.setFrameRate(1);
764 QVERIFY(settings1 == settings2);
765 settings2.setFrameRate(2);
766 QVERIFY(settings1 != settings2);
767
768 settings1 = QVideoEncoderSettings();
769 settings1.setEncodingOption(option: QLatin1String("encoderOption"), value: QVariant(1));
770 settings2 = QVideoEncoderSettings();
771 settings2.setEncodingOption(option: QLatin1String("encoderOption"), value: QVariant(1));
772 QVERIFY(settings1 == settings2);
773 settings2.setEncodingOption(option: QLatin1String("encoderOption"), value: QVariant(2));
774 QVERIFY(settings1 != settings2);
775}
776
777void tst_QMediaRecorder::testSettingsApplied()
778{
779 MockMediaRecorderControl recorderControl(0);
780 MockMediaRecorderService service(0, &recorderControl);
781 MockMediaObject object(0, &service);
782
783 //if the media recorder is not configured after construction
784 //the settings are applied in the next event loop
785 QMediaRecorder recorder(&object);
786 QCOMPARE(recorderControl.m_settingAppliedCount, 0);
787 QTRY_COMPARE(recorderControl.m_settingAppliedCount, 1);
788
789 QVideoEncoderSettings videoSettings;
790 videoSettings.setResolution(width: 640,height: 480);
791 recorder.setVideoSettings(videoSettings);
792
793 QAudioEncoderSettings audioSettings;
794 audioSettings.setQuality(QMultimedia::HighQuality);
795 recorder.setAudioSettings(audioSettings);
796
797 recorder.setContainerFormat("mkv");
798
799 QCOMPARE(recorderControl.m_settingAppliedCount, 1);
800 QTRY_COMPARE(recorderControl.m_settingAppliedCount, 2);
801
802 //encoder settings are applied before recording if changed
803 audioSettings.setQuality(QMultimedia::VeryHighQuality);
804 recorder.setAudioSettings(audioSettings);
805
806 QCOMPARE(recorderControl.m_settingAppliedCount, 2);
807 recorder.record();
808 QCOMPARE(recorderControl.m_settingAppliedCount, 3);
809
810 recorder.stop();
811
812 //applySettings is not called if setting has not changes
813 recorder.record();
814 QCOMPARE(recorderControl.m_settingAppliedCount, 3);
815}
816
817void tst_QMediaRecorder::nullMetaDataControl()
818{
819 const QString titleKey(QLatin1String("Title"));
820 const QString title(QLatin1String("Host of Seraphim"));
821
822 MockMediaRecorderControl recorderControl(0);
823 MockMediaRecorderService service(0, &recorderControl);
824 service.hasControls = false;
825 MockMediaObject object(0, &service);
826
827 QMediaRecorder recorder(&object);
828
829 QSignalSpy spy(&recorder, SIGNAL(metaDataChanged()));
830
831 QCOMPARE(recorder.isMetaDataAvailable(), false);
832 QCOMPARE(recorder.isMetaDataWritable(), false);
833
834 recorder.setMetaData(key: QMediaMetaData::Title, value: title);
835
836 QCOMPARE(recorder.metaData(QMediaMetaData::Title).toString(), QString());
837 QCOMPARE(recorder.availableMetaData(), QStringList());
838 QCOMPARE(spy.count(), 0);
839}
840
841void tst_QMediaRecorder::isMetaDataAvailable()
842{
843 MockMediaRecorderControl recorderControl(0);
844 MockMediaRecorderService service(0, &recorderControl);
845 service.mockMetaDataControl->setMetaDataAvailable(false);
846 MockMediaObject object(0, &service);
847
848 QMediaRecorder recorder(&object);
849 QCOMPARE(recorder.isMetaDataAvailable(), false);
850
851 QSignalSpy spy(&recorder, SIGNAL(metaDataAvailableChanged(bool)));
852 service.mockMetaDataControl->setMetaDataAvailable(true);
853
854 QCOMPARE(recorder.isMetaDataAvailable(), true);
855 QCOMPARE(spy.count(), 1);
856 QCOMPARE(spy.at(0).at(0).toBool(), true);
857
858 service.mockMetaDataControl->setMetaDataAvailable(false);
859
860 QCOMPARE(recorder.isMetaDataAvailable(), false);
861 QCOMPARE(spy.count(), 2);
862 QCOMPARE(spy.at(1).at(0).toBool(), false);
863}
864
865void tst_QMediaRecorder::isWritable()
866{
867 MockMediaRecorderControl recorderControl(0);
868 MockMediaRecorderService service(0, &recorderControl);
869 service.mockMetaDataControl->setWritable(false);
870
871 MockMediaObject object(0, &service);
872
873 QMediaRecorder recorder(&object);
874
875 QSignalSpy spy(&recorder, SIGNAL(metaDataWritableChanged(bool)));
876
877 QCOMPARE(recorder.isMetaDataWritable(), false);
878
879 service.mockMetaDataControl->setWritable(true);
880
881 QCOMPARE(recorder.isMetaDataWritable(), true);
882 QCOMPARE(spy.count(), 1);
883 QCOMPARE(spy.at(0).at(0).toBool(), true);
884
885 service.mockMetaDataControl->setWritable(false);
886
887 QCOMPARE(recorder.isMetaDataWritable(), false);
888 QCOMPARE(spy.count(), 2);
889 QCOMPARE(spy.at(1).at(0).toBool(), false);
890}
891
892void tst_QMediaRecorder::metaDataChanged()
893{
894 MockMediaRecorderControl recorderControl(0);
895 MockMediaRecorderService service(0, &recorderControl);
896 MockMediaObject object(0, &service);
897
898 QMediaRecorder recorder(&object);
899
900 QSignalSpy changedSpy(&recorder, SIGNAL(metaDataChanged()));
901 QSignalSpy changedWithValueSpy(&recorder, SIGNAL(metaDataChanged(QString,QVariant)));
902
903 service.mockMetaDataControl->setMetaData(key: "key", value: "Value");
904 QCOMPARE(changedSpy.count(), 1);
905 QCOMPARE(changedWithValueSpy.count(), 1);
906 QCOMPARE(changedWithValueSpy.last()[0], QVariant("key"));
907 QCOMPARE(changedWithValueSpy.last()[1].value<QVariant>(), QVariant("Value"));
908
909 service.mockMetaDataControl->setMetaData(key: "key", value: "Value");
910 QCOMPARE(changedSpy.count(), 1);
911 QCOMPARE(changedWithValueSpy.count(), 1);
912
913 service.mockMetaDataControl->setMetaData(key: "key2", value: "Value");
914 QCOMPARE(changedSpy.count(), 2);
915 QCOMPARE(changedWithValueSpy.count(), 2);
916 QCOMPARE(changedWithValueSpy.last()[0], QVariant("key2"));
917 QCOMPARE(changedWithValueSpy.last()[1].value<QVariant>(), QVariant("Value"));
918}
919
920void tst_QMediaRecorder::metaData_data()
921{
922 QTest::addColumn<QString>(name: "artist");
923 QTest::addColumn<QString>(name: "title");
924 QTest::addColumn<QString>(name: "genre");
925 QTest::addColumn<QString>(name: "custom");
926
927 QTest::newRow(dataTag: "")
928 << QString::fromLatin1(str: "Dead Can Dance")
929 << QString::fromLatin1(str: "Host of Seraphim")
930 << QString::fromLatin1(str: "Awesome")
931 << QString::fromLatin1(str: "Something else");
932}
933
934void tst_QMediaRecorder::metaData()
935{
936 QFETCH(QString, artist);
937 QFETCH(QString, title);
938 QFETCH(QString, genre);
939 QFETCH(QString, custom);
940
941 MockMediaRecorderControl recorderControl(0);
942 MockMediaRecorderService service(0, &recorderControl);
943 service.mockMetaDataControl->populateMetaData();
944
945 MockMediaObject object(0, &service);
946
947 QMediaRecorder recorder(&object);
948 QVERIFY(object.availableMetaData().isEmpty());
949
950 service.mockMetaDataControl->m_data.insert(akey: QMediaMetaData::AlbumArtist, avalue: artist);
951 service.mockMetaDataControl->m_data.insert(akey: QMediaMetaData::Title, avalue: title);
952 service.mockMetaDataControl->m_data.insert(akey: QMediaMetaData::Genre, avalue: genre);
953 service.mockMetaDataControl->m_data.insert(akey: QLatin1String("CustomEntry"), avalue: custom );
954
955 QCOMPARE(recorder.metaData(QMediaMetaData::AlbumArtist).toString(), artist);
956 QCOMPARE(recorder.metaData(QMediaMetaData::Title).toString(), title);
957
958 QStringList metaDataKeys = recorder.availableMetaData();
959 QCOMPARE(metaDataKeys.size(), 4);
960 QVERIFY(metaDataKeys.contains(QMediaMetaData::AlbumArtist));
961 QVERIFY(metaDataKeys.contains(QMediaMetaData::Title));
962 QVERIFY(metaDataKeys.contains(QMediaMetaData::Genre));
963 QVERIFY(metaDataKeys.contains(QLatin1String("CustomEntry")));
964}
965
966void tst_QMediaRecorder::setMetaData_data()
967{
968 QTest::addColumn<QString>(name: "title");
969
970 QTest::newRow(dataTag: "")
971 << QString::fromLatin1(str: "In the Kingdom of the Blind the One eyed are Kings");
972}
973
974void tst_QMediaRecorder::setMetaData()
975{
976 QFETCH(QString, title);
977
978 MockMediaRecorderControl recorderControl(0);
979 MockMediaRecorderService service(0, &recorderControl);
980 service.mockMetaDataControl->populateMetaData();
981
982 MockMediaObject object(0, &service);
983
984 QMediaRecorder recorder(&object);
985
986 recorder.setMetaData(key: QMediaMetaData::Title, value: title);
987 QCOMPARE(recorder.metaData(QMediaMetaData::Title).toString(), title);
988 QCOMPARE(service.mockMetaDataControl->m_data.value(QMediaMetaData::Title).toString(), title);
989}
990
991void tst_QMediaRecorder::testAudioSettingsCopyConstructor()
992{
993 /* create an object for AudioEncodersettings */
994 QAudioEncoderSettings audiosettings;
995 QVERIFY(audiosettings.isNull());
996
997 /* setting the desired properties for the AudioEncoder */
998 audiosettings.setBitRate(128*1000);
999 audiosettings.setChannelCount(4);
1000 audiosettings.setCodec("audio/pcm");
1001 audiosettings.setEncodingMode(QMultimedia::ConstantBitRateEncoding);
1002 audiosettings.setQuality(QMultimedia::LowQuality);
1003 audiosettings.setSampleRate(44100);
1004
1005 /* Copy constructor */
1006 QAudioEncoderSettings other(audiosettings);
1007 QVERIFY(!(other.isNull()));
1008
1009 /* Verifying whether data is copied properly or not */
1010 QVERIFY(other.bitRate() == audiosettings.bitRate());
1011 QVERIFY(other.sampleRate() == audiosettings.sampleRate());
1012 QVERIFY(other.channelCount() == audiosettings.channelCount());
1013 QCOMPARE(other.codec(), audiosettings.codec());
1014 QVERIFY(other.encodingMode() == audiosettings.encodingMode());
1015 QVERIFY(other.quality() == audiosettings.quality());
1016}
1017
1018void tst_QMediaRecorder::testAudioSettingsOperatorNotEqual()
1019{
1020 /* create an object for AudioEncodersettings */
1021 QAudioEncoderSettings audiosettings1;
1022 QVERIFY(audiosettings1.isNull());
1023
1024 QAudioEncoderSettings audiosettings2;
1025 QVERIFY(audiosettings2.isNull());
1026
1027 /* setting the desired properties to for the AudioEncoder */
1028 audiosettings1.setBitRate(128*1000);
1029 audiosettings1.setChannelCount(4);
1030 audiosettings1.setCodec("audio/pcm");
1031 audiosettings1.setEncodingMode(QMultimedia::ConstantBitRateEncoding);
1032 audiosettings1.setQuality(QMultimedia::LowQuality);
1033 audiosettings1.setSampleRate(44100);
1034
1035 /* setting the desired properties for the AudioEncoder */
1036 audiosettings2.setBitRate(128*1000);
1037 audiosettings2.setChannelCount(4);
1038 audiosettings2.setCodec("audio/pcm");
1039 audiosettings2.setEncodingMode(QMultimedia::ConstantBitRateEncoding);
1040 audiosettings2.setQuality(QMultimedia::LowQuality);
1041 audiosettings2.setSampleRate(44100);
1042
1043 /* verify the both are equal or not */
1044 QVERIFY(!(audiosettings1 != audiosettings2));
1045
1046 /* Modify the settings value for one object */
1047 audiosettings2.setBitRate(64*1000);
1048 audiosettings2.setEncodingMode(QMultimedia::ConstantQualityEncoding);
1049
1050 /* verify the not equal opertor */
1051 QVERIFY(audiosettings1 != audiosettings2);
1052
1053 QVERIFY(audiosettings2.bitRate() != audiosettings1.bitRate());
1054 QVERIFY(audiosettings2.encodingMode() != audiosettings1.encodingMode());
1055}
1056
1057void tst_QMediaRecorder::testAudioSettingsOperatorEqual()
1058{
1059 /* create an object for AudioEncodersettings */
1060 QAudioEncoderSettings audiosettings1;
1061 QVERIFY(audiosettings1.isNull());
1062
1063 /* setting the desired properties to for the AudioEncoder */
1064 audiosettings1.setBitRate(128*1000);
1065 audiosettings1.setChannelCount(4);
1066 audiosettings1.setCodec("audio/pcm");
1067 audiosettings1.setEncodingMode(QMultimedia::ConstantBitRateEncoding);
1068 audiosettings1.setQuality(QMultimedia::LowQuality);
1069 audiosettings1.setSampleRate(44100);
1070
1071 QAudioEncoderSettings audiosettings2;
1072 QVERIFY(audiosettings2.isNull());
1073
1074 /* setting the desired properties for the AudioEncoder */
1075 audiosettings2.setBitRate(128*1000);
1076 audiosettings2.setChannelCount(4);
1077 audiosettings2.setCodec("audio/pcm");
1078 audiosettings2.setEncodingMode(QMultimedia::ConstantBitRateEncoding);
1079 audiosettings2.setQuality(QMultimedia::LowQuality);
1080 audiosettings2.setSampleRate(44100);
1081
1082 /* verify both the values are same or not */
1083 QVERIFY(audiosettings1 == audiosettings2);
1084 audiosettings2.setChannelCount(2);
1085 QVERIFY(audiosettings1 != audiosettings2);
1086}
1087
1088void tst_QMediaRecorder::testAudioSettingsOperatorAssign()
1089{
1090
1091 /* create an object for AudioEncodersettings */
1092 QAudioEncoderSettings audiosettings1;
1093 QVERIFY(audiosettings1.isNull());
1094
1095 /* setting the desired properties for the AudioEncoder */
1096 audiosettings1.setBitRate(128*1000);
1097 audiosettings1.setChannelCount(4);
1098 audiosettings1.setCodec("audio/pcm");
1099 audiosettings1.setEncodingMode(QMultimedia::ConstantBitRateEncoding);
1100 audiosettings1.setQuality(QMultimedia::LowQuality);
1101 audiosettings1.setSampleRate(44100);
1102
1103 QAudioEncoderSettings audiosettings2;
1104 audiosettings2 = audiosettings1;
1105 /* Verifying whether data is copied properly or not */
1106 QVERIFY(audiosettings2.bitRate() == audiosettings1.bitRate());
1107 QVERIFY(audiosettings2.sampleRate() == audiosettings1.sampleRate());
1108 QVERIFY(audiosettings2.channelCount() == audiosettings1.channelCount());
1109 QCOMPARE(audiosettings2.codec(), audiosettings1.codec());
1110 QVERIFY(audiosettings2.encodingMode() == audiosettings1.encodingMode());
1111 QVERIFY(audiosettings2.quality() == audiosettings1.quality());
1112}
1113
1114void tst_QMediaRecorder::testAudioSettingsDestructor()
1115{
1116 /* Creating null object for the audioencodersettings */
1117 QAudioEncoderSettings * audiosettings = new QAudioEncoderSettings;
1118
1119 /* Verifying the object is null or not */
1120 QVERIFY(audiosettings->isNull());
1121 /* delete the allocated memory */
1122 delete audiosettings;
1123}
1124
1125/* availability() API test. */
1126void tst_QMediaRecorder::testAvailabilityStatus()
1127{
1128 {
1129 MockMediaRecorderService service(0, 0);
1130 MockMediaObject object(0, &service);
1131 QMediaRecorder recorder(&object);
1132 QCOMPARE(recorder.availability(), QMultimedia::ServiceMissing);
1133 QCOMPARE(recorder.isAvailable(), false);
1134 }
1135 {
1136 MockMediaRecorderControl recorderControl(0);
1137 MockMediaRecorderService service1(0, &recorderControl);
1138 service1.mockMetaDataControl->populateMetaData();
1139 MockMediaObject object1(0, &service1);
1140 QMediaRecorder recorder1(&object1);
1141 QCOMPARE(recorder1.availability(), QMultimedia::Available);
1142 QCOMPARE(recorder1.isAvailable(), true);
1143 }
1144 {
1145 MockMediaRecorderControl recorderControl(0);
1146 MockMediaRecorderService service1(0, &recorderControl, 0);
1147 service1.mockMetaDataControl->populateMetaData();
1148 MockMediaObject object1(0, &service1);
1149 QMediaRecorder recorder1(&object1);
1150
1151 QCOMPARE(recorder1.availability(), QMultimedia::Available);
1152 QCOMPARE(recorder1.isAvailable(), true);
1153 }
1154 {
1155 MockMediaRecorderControl recorderControl(0);
1156 MockAvailabilityControl availability(QMultimedia::Available);
1157 MockMediaRecorderService service1(0, &recorderControl, &availability);
1158 service1.mockMetaDataControl->populateMetaData();
1159 MockMediaObject object1(0, &service1);
1160 QMediaRecorder recorder1(&object1);
1161
1162 QSignalSpy spy(&object1, SIGNAL(availabilityChanged(QMultimedia::AvailabilityStatus)));
1163
1164 QCOMPARE(recorder1.availability(), QMultimedia::Available);
1165 QCOMPARE(recorder1.isAvailable(), true);
1166
1167 availability.setAvailability(QMultimedia::Busy);
1168 QCOMPARE(recorder1.availability(), QMultimedia::Busy);
1169 QCOMPARE(recorder1.isAvailable(), false);
1170 QCOMPARE(spy.count(), 1);
1171
1172 availability.setAvailability(QMultimedia::Available);
1173 QCOMPARE(recorder1.availability(), QMultimedia::Available);
1174 QCOMPARE(recorder1.isAvailable(), true);
1175 QCOMPARE(spy.count(), 2);
1176 }
1177}
1178
1179/* isAvailable() API test. */
1180void tst_QMediaRecorder::testIsAvailable()
1181{
1182 MockMediaRecorderService service(0, 0);
1183 MockMediaObject object(0, &service);
1184 QMediaRecorder recorder(&object);
1185 QCOMPARE(recorder.isAvailable(), false);
1186
1187 MockMediaRecorderControl recorderControl(0);
1188 MockMediaRecorderService service1(0, &recorderControl);
1189 service1.mockMetaDataControl->populateMetaData();
1190 MockMediaObject object1(0, &service1);
1191 QMediaRecorder recorder1(&object1);
1192 QCOMPARE(recorder1.isAvailable(), true);
1193}
1194
1195/* mediaObject() API test. */
1196void tst_QMediaRecorder::testMediaObject()
1197{
1198 MockMediaRecorderService service(0, 0);
1199 service.hasControls = false;
1200 MockMediaObject object(0, &service);
1201 QMediaRecorder recorder(&object);
1202
1203 QMediaObject *medobj = recorder.mediaObject();
1204 QVERIFY(medobj == NULL);
1205
1206 QMediaObject *medobj1 = capture->mediaObject();
1207 QVERIFY(medobj1 != NULL);
1208}
1209
1210/* enum QMediaRecorder::ResourceError property test. */
1211void tst_QMediaRecorder::testEnum()
1212{
1213 const QString errorString(QLatin1String("resource error"));
1214
1215 QSignalSpy spy(capture, SIGNAL(error(QMediaRecorder::Error)));
1216
1217 QCOMPARE(capture->error(), QMediaRecorder::NoError);
1218 QCOMPARE(capture->errorString(), QString());
1219
1220 mock->error(error: QMediaRecorder::ResourceError, errorString);
1221 QCOMPARE(capture->error(), QMediaRecorder::ResourceError);
1222 QCOMPARE(capture->errorString(), errorString);
1223 QCOMPARE(spy.count(), 1);
1224
1225 QCOMPARE(spy.last()[0].value<QMediaRecorder::Error>(), QMediaRecorder::ResourceError);
1226}
1227
1228/* Test the QVideoEncoderSettings quality API*/
1229void tst_QMediaRecorder::testVideoSettingsQuality()
1230{
1231 /* Create the instance*/
1232 QVideoEncoderSettings settings;
1233 QVERIFY(settings.isNull());
1234 QVERIFY(settings == QVideoEncoderSettings());
1235
1236 /* Verify the default value is intialised correctly*/
1237 QCOMPARE(settings.quality(), QMultimedia::NormalQuality);
1238
1239 /* Set all types of Quality parameter and Verify if it is set correctly*/
1240 settings.setQuality(QMultimedia::HighQuality);
1241 QCOMPARE(settings.quality(), QMultimedia::HighQuality);
1242 QVERIFY(!settings.isNull());
1243
1244 settings.setQuality(QMultimedia::VeryLowQuality);
1245 QCOMPARE(settings.quality(), QMultimedia::VeryLowQuality);
1246
1247 settings.setQuality(QMultimedia::LowQuality);
1248 QCOMPARE(settings.quality(), QMultimedia::LowQuality);
1249
1250 settings.setQuality(QMultimedia::VeryHighQuality);
1251 QCOMPARE(settings.quality(), QMultimedia::VeryHighQuality);
1252}
1253
1254/* Test QVideoEncoderSettings encodingMode */
1255void tst_QMediaRecorder::testVideoSettingsEncodingMode()
1256{
1257 /* Create the instance*/
1258 QVideoEncoderSettings settings;
1259 QVERIFY(settings.isNull());
1260 QVERIFY(settings == QVideoEncoderSettings());
1261
1262 /* Verify the default values are initialised correctly*/
1263 QCOMPARE(settings.encodingMode(), QMultimedia::ConstantQualityEncoding);
1264 QVERIFY(settings.isNull());
1265
1266 /* Set each type of encoding mode and Verify if it is set correctly*/
1267 settings.setEncodingMode(QMultimedia::ConstantBitRateEncoding);
1268 QCOMPARE(settings.encodingMode(),QMultimedia::ConstantBitRateEncoding);
1269 QVERIFY(!settings.isNull());
1270
1271 settings.setEncodingMode(QMultimedia::AverageBitRateEncoding);
1272 QCOMPARE(settings.encodingMode(), QMultimedia::AverageBitRateEncoding);
1273
1274 settings.setEncodingMode(QMultimedia::TwoPassEncoding);
1275 QCOMPARE(settings.encodingMode(), QMultimedia::TwoPassEncoding);
1276}
1277
1278/* Test QVideoEncoderSettings copy constructor */
1279void tst_QMediaRecorder::testVideoSettingsCopyConstructor()
1280{
1281 /* Create the instance and initialise it*/
1282 QVideoEncoderSettings settings1;
1283 settings1.setCodec(QLatin1String("codecName"));
1284 settings1.setBitRate(128000);
1285 settings1.setQuality(QMultimedia::HighQuality);
1286 settings1.setEncodingMode(QMultimedia::ConstantBitRateEncoding);
1287 settings1.setFrameRate(30000.0/10001);
1288 settings1.setResolution(QSize(320,240));
1289
1290 /* Create another instance with instance1 as argument*/
1291 QVideoEncoderSettings settings2(settings1);
1292
1293 /* Verify if all the parameters are copied correctly*/
1294 QCOMPARE(settings2 != settings1, false);
1295 QCOMPARE(settings2.codec(), QLatin1String("codecName"));
1296 QCOMPARE(settings2.bitRate(), 128000);
1297 QCOMPARE(settings2.encodingMode(), QMultimedia::ConstantBitRateEncoding);
1298 QVERIFY(qFuzzyCompare(settings2.frameRate(), qreal(30000.0/10001)));
1299 QCOMPARE(settings2.resolution(), QSize(320,240));
1300 QCOMPARE(settings2.quality(), QMultimedia::HighQuality);
1301
1302 /* Verify both the instances are equal*/
1303 QCOMPARE(settings2, settings1);
1304 QVERIFY(!settings2.isNull());
1305}
1306
1307/* Test QVideoEncoderSettings Overloaded Operator assignment*/
1308void tst_QMediaRecorder::testVideoSettingsOperatorAssignment()
1309{
1310 /* Create two instances.*/
1311 QVideoEncoderSettings settings1;
1312 QVideoEncoderSettings settings2;
1313 QCOMPARE(settings2, settings1);
1314 QVERIFY(settings2.isNull());
1315
1316 /* Initialize all the parameters */
1317 settings1.setCodec(QLatin1String("codecName"));
1318 settings1.setBitRate(128000);
1319 settings1.setEncodingMode(QMultimedia::ConstantBitRateEncoding);
1320 settings1.setFrameRate(30000.0/10001);
1321 settings1.setResolution(QSize(320,240));
1322 settings1.setQuality(QMultimedia::HighQuality);
1323 /* Assign one object to other*/
1324 settings2 = settings1;
1325
1326 /* Verify all the parameters are copied correctly*/
1327 QCOMPARE(settings2, settings1);
1328 QCOMPARE(settings2.codec(), QLatin1String("codecName"));
1329 QCOMPARE(settings2.bitRate(), 128000);
1330 QCOMPARE(settings2.encodingMode(), QMultimedia::ConstantBitRateEncoding);
1331 QVERIFY(qFuzzyCompare(settings2.frameRate(), qreal(30000.0/10001)));
1332 QCOMPARE(settings2.resolution(), QSize(320,240));
1333 QCOMPARE(settings2.quality(), QMultimedia::HighQuality);
1334 QCOMPARE(settings2, settings1);
1335 QVERIFY(!settings2.isNull());
1336}
1337
1338/* Test QVideoEncoderSettings Overloaded OperatorNotEqual*/
1339void tst_QMediaRecorder::testVideoSettingsOperatorNotEqual()
1340{
1341 /* Create the instance and set the bit rate and Verify objects with OperatorNotEqual*/
1342 QVideoEncoderSettings settings1;
1343 settings1.setBitRate(1);
1344 QVideoEncoderSettings settings2;
1345 settings2.setBitRate(1);
1346 /* OperatorNotEqual returns false when both objects are equal*/
1347 QCOMPARE(settings1 != settings2, false);
1348 settings2.setBitRate(2);
1349 /* OperatorNotEqual returns true when both objects are not equal*/
1350 QVERIFY(settings1 != settings2);
1351
1352 /* Verify Resolution with not equal operator*/
1353 settings1 = QVideoEncoderSettings();
1354 settings1.setResolution(width: 800,height: 600);
1355 settings2 = QVideoEncoderSettings();
1356 settings2.setResolution(QSize(800,600));
1357 /* OperatorNotEqual returns false when both objects are equal*/
1358 QCOMPARE(settings1 != settings2, false);
1359 settings2.setResolution(QSize(400,300));
1360 /* OperatorNotEqual returns true when both objects are not equal*/
1361 QVERIFY(settings1 != settings2);
1362
1363 /* Verify Codec with not equal operator*/
1364 settings1 = QVideoEncoderSettings();
1365 settings1.setCodec("codec1");
1366 settings2 = QVideoEncoderSettings();
1367 settings2.setCodec("codec1");
1368 /* OperatorNotEqual returns false when both objects are equal*/
1369 QCOMPARE(settings1 != settings2, false);
1370 settings2.setCodec("codec2");
1371 /* OperatorNotEqual returns true when both objects are not equal*/
1372 QVERIFY(settings1 != settings2);
1373
1374 /* Verify EncodingMode with not equal operator*/
1375 settings1 = QVideoEncoderSettings();
1376 settings1.setEncodingMode(QMultimedia::ConstantBitRateEncoding);
1377 settings2 = QVideoEncoderSettings();
1378 settings2.setEncodingMode(QMultimedia::ConstantBitRateEncoding);
1379 /* OperatorNotEqual returns false when both objects are equal*/
1380 QCOMPARE(settings1 != settings2, false);
1381 settings2.setEncodingMode(QMultimedia::TwoPassEncoding);
1382 /* OperatorNotEqual returns true when both objects are not equal*/
1383 QVERIFY(settings1 != settings2);
1384
1385 /* Verify Quality with not equal operator*/
1386 settings1 = QVideoEncoderSettings();
1387 settings1.setQuality(QMultimedia::NormalQuality);
1388 settings2 = QVideoEncoderSettings();
1389 settings2.setQuality(QMultimedia::NormalQuality);
1390 /* OperatorNotEqual returns false when both objects are equal*/
1391 QCOMPARE(settings1 != settings2, false);
1392 settings2.setQuality(QMultimedia::LowQuality);
1393 /* OperatorNotEqual returns true when both objects are not equal*/
1394 QVERIFY(settings1 != settings2);
1395
1396 /* Verify FrameRate with not equal operator*/
1397 settings1 = QVideoEncoderSettings();
1398 settings1.setFrameRate(1);
1399 settings2 = QVideoEncoderSettings();
1400 settings2.setFrameRate(1);
1401 /* OperatorNotEqual returns false when both objects are equal*/
1402 QCOMPARE(settings1 != settings2, false);
1403 settings2.setFrameRate(2);
1404 /* OperatorNotEqual returns true when both objects are not equal*/
1405 QVERIFY(settings1 != settings2);
1406}
1407
1408/* Test QVideoEncoderSettings Overloaded comparison operator*/
1409void tst_QMediaRecorder::testVideoSettingsOperatorComparison()
1410{
1411 /* Create the instance and set the bit rate and Verify objects with comparison operator*/
1412 QVideoEncoderSettings settings1;
1413 settings1.setBitRate(1);
1414 QVideoEncoderSettings settings2;
1415 settings2.setBitRate(1);
1416
1417 /* Comparison operator returns true when both objects are equal*/
1418 QVERIFY(settings1 == settings2);
1419 settings2.setBitRate(2);
1420 /* Comparison operator returns false when both objects are not equal*/
1421 QCOMPARE(settings1 == settings2, false);
1422
1423 /* Verify resolution with comparison operator*/
1424 settings1 = QVideoEncoderSettings();
1425 settings1.setResolution(width: 800,height: 600);
1426 settings2 = QVideoEncoderSettings();
1427 settings2.setResolution(QSize(800,600));
1428 /* Comparison operator returns true when both objects are equal*/
1429 QVERIFY(settings1 == settings2);
1430 settings2.setResolution(QSize(400,300));
1431 /* Comparison operator returns false when both objects are not equal*/
1432 QCOMPARE(settings1 == settings2, false);
1433
1434 /* Verify Codec with comparison operator*/
1435 settings1 = QVideoEncoderSettings();
1436 settings1.setCodec("codec1");
1437 settings2 = QVideoEncoderSettings();
1438 settings2.setCodec("codec1");
1439 /* Comparison operator returns true when both objects are equal*/
1440 QVERIFY(settings1 == settings2);
1441 settings2.setCodec("codec2");
1442 /* Comparison operator returns false when both objects are not equal*/
1443 QCOMPARE(settings1 == settings2, false);
1444
1445 /* Verify EncodingMode with comparison operator*/
1446 settings1 = QVideoEncoderSettings();
1447 settings1.setEncodingMode(QMultimedia::ConstantBitRateEncoding);
1448 settings2 = QVideoEncoderSettings();
1449 settings2.setEncodingMode(QMultimedia::ConstantBitRateEncoding);
1450 /* Comparison operator returns true when both objects are equal*/
1451 QVERIFY(settings1 == settings2);
1452 settings2.setEncodingMode(QMultimedia::TwoPassEncoding);
1453 /* Comparison operator returns false when both objects are not equal*/
1454 QCOMPARE(settings1 == settings2, false);
1455
1456 /* Verify Quality with comparison operator*/
1457 settings1 = QVideoEncoderSettings();
1458 settings1.setQuality(QMultimedia::NormalQuality);
1459 settings2 = QVideoEncoderSettings();
1460 settings2.setQuality(QMultimedia::NormalQuality);
1461 /* Comparison operator returns true when both objects are equal*/
1462 QVERIFY(settings1 == settings2);
1463 settings2.setQuality(QMultimedia::LowQuality);
1464 /* Comparison operator returns false when both objects are not equal*/
1465 QCOMPARE(settings1 == settings2, false);
1466
1467 /* Verify FrameRate with comparison operator*/
1468 settings1 = QVideoEncoderSettings();
1469 settings1.setFrameRate(1);
1470 settings2 = QVideoEncoderSettings();
1471 settings2.setFrameRate(1);
1472 /* Comparison operator returns true when both objects are equal*/
1473 QVERIFY(settings1 == settings2);
1474 settings2.setFrameRate(2);
1475 /* Comparison operator returns false when both objects are not equal*/
1476 QCOMPARE(settings1 == settings2, false);
1477}
1478
1479/* Test the destuctor of the QVideoEncoderSettings*/
1480void tst_QMediaRecorder::testVideoSettingsDestructor()
1481{
1482 /* Create the instance on heap and verify if object deleted correctly*/
1483 QVideoEncoderSettings *settings1 = new QVideoEncoderSettings();
1484 QVERIFY(settings1 != NULL);
1485 QVERIFY(settings1->isNull());
1486 delete settings1;
1487
1488 /* Create the instance on heap and initialise it and verify if object deleted correctly.*/
1489 QVideoEncoderSettings *settings2 = new QVideoEncoderSettings();
1490 QVERIFY(settings2 != NULL);
1491 settings2->setCodec(QString("codec"));
1492 QVERIFY(!settings2->isNull());
1493 delete settings2;
1494}
1495
1496QTEST_GUILESS_MAIN(tst_QMediaRecorder)
1497#include "tst_qmediarecorder.moc"
1498

source code of qtmultimedia/tests/auto/unit/qmediarecorder/tst_qmediarecorder.cpp