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 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 | |
34 | #include <qabstractvideosurface.h> |
35 | #include <qcameracontrol.h> |
36 | #include <qcameralockscontrol.h> |
37 | #include <qcameraexposurecontrol.h> |
38 | #include <qcameraflashcontrol.h> |
39 | #include <qcamerafocuscontrol.h> |
40 | #include <qcameraimagecapturecontrol.h> |
41 | #include <qimageencodercontrol.h> |
42 | #include <qcameraimageprocessingcontrol.h> |
43 | #include <qcameracapturebufferformatcontrol.h> |
44 | #include <qcameracapturedestinationcontrol.h> |
45 | #include <qmediaservice.h> |
46 | #include <qcamera.h> |
47 | #include <qcamerainfo.h> |
48 | #include <qcameraimagecapture.h> |
49 | #include <qvideorenderercontrol.h> |
50 | |
51 | #include "mockcameraservice.h" |
52 | |
53 | #include "mockmediaserviceprovider.h" |
54 | #include "mockvideosurface.h" |
55 | #include "mockvideorenderercontrol.h" |
56 | #include "mockvideowindowcontrol.h" |
57 | |
58 | QT_USE_NAMESPACE |
59 | |
60 | |
61 | class tst_QCamera: public QObject |
62 | { |
63 | Q_OBJECT |
64 | |
65 | public slots: |
66 | void initTestCase(); |
67 | void init(); |
68 | void cleanup(); |
69 | |
70 | private slots: |
71 | void testSimpleCamera(); |
72 | void testSimpleCameraWhiteBalance(); |
73 | void testSimpleCameraExposure(); |
74 | void testSimpleCameraFocus(); |
75 | void testSimpleCameraCapture(); |
76 | void testSimpleCameraLock(); |
77 | void testSimpleCaptureDestination(); |
78 | void testSimpleCaptureFormat(); |
79 | |
80 | void testCameraWhiteBalance(); |
81 | void testCameraExposure(); |
82 | void testCameraFocus(); |
83 | void testCameraCapture(); |
84 | void testCameraCaptureMetadata(); |
85 | void testImageSettings(); |
86 | void testViewfinderSettings(); |
87 | void testViewfinderSettingsChange(); |
88 | void testSupportedViewfinderSettings_data(); |
89 | void testSupportedViewfinderSettings(); |
90 | void testSupportedViewfinderResolutions_data(); |
91 | void testSupportedViewfinderResolutions(); |
92 | void testSupportedViewfinderFrameRateRanges_data(); |
93 | void testSupportedViewfinderFrameRateRanges(); |
94 | void testSupportedViewfinderPixelFormats_data(); |
95 | void testSupportedViewfinderPixelFormats(); |
96 | void testCameraLock(); |
97 | void testCameraLockCancel(); |
98 | void testCameraEncodingProperyChange(); |
99 | void testCaptureDestination(); |
100 | void testCaptureFormat(); |
101 | |
102 | void testConstructor(); |
103 | void testCaptureMode(); |
104 | void testIsCaptureModeSupported(); |
105 | void testRequestedLocks(); |
106 | void testSupportedLocks(); |
107 | void testQCameraIsAvailable(); |
108 | void testQCameraIsNotAvailable(); |
109 | void testSearchAndLockWithLockTypes(); |
110 | void testSetCaptureMode(); |
111 | void testUnlockWithType(); |
112 | void testCaptureModeChangedSignal(); |
113 | void testLockStatusChangedWithTypesSignal(); |
114 | void testErrorSignal(); |
115 | void testError(); |
116 | void testErrorString(); |
117 | void testStatus(); |
118 | void testLockType(); |
119 | void testLockChangeReason(); |
120 | |
121 | |
122 | // Test cases to for QCameraFocus |
123 | void testCameraFocusIsAvailable(); |
124 | void testFocusModes(); |
125 | void testOpticalAndDigitalZoomChanged(); |
126 | void testMaxOpticalZoomChangedSignal(); |
127 | void testMaxDigitalZoomChangedSignal(); |
128 | void testfocusZonesChangedSignal(); |
129 | |
130 | // Test cases for QCameraControl class. |
131 | void testCameraControl(); |
132 | void testCaptureModeChanged_signal(); |
133 | void testEnumsOfQCameraControl(); |
134 | |
135 | // Test case for QCameraImageProcessing class |
136 | void testContrast(); |
137 | void testDenoisingLevel(); |
138 | void testIsAvailable(); |
139 | void testSaturation(); |
140 | void testSharpeningLevel(); |
141 | void testEnumOfQCameraImageProcessing(); |
142 | |
143 | void testSetVideoOutput(); |
144 | void testSetVideoOutputNoService(); |
145 | void testSetVideoOutputNoControl(); |
146 | void testSetVideoOutputDestruction(); |
147 | |
148 | void testEnumDebug(); |
149 | |
150 | // constructor for QCameraImageProceesing |
151 | void testImageProcessingControl(); |
152 | |
153 | // Signals test cases for QCameraExposure |
154 | void testSignalApertureChanged(); |
155 | void testSignalExposureCompensationChanged(); |
156 | void testSignalIsoSensitivityChanged(); |
157 | void testSignalShutterSpeedChanged(); |
158 | void testSignalFlashReady(); |
159 | |
160 | // test constructor |
161 | void testExposureControlConstructor(); |
162 | |
163 | private: |
164 | MockSimpleCameraService *mockSimpleCameraService; |
165 | MockCameraService *mockCameraService; |
166 | MockMediaServiceProvider *provider; |
167 | }; |
168 | |
169 | Q_DECLARE_METATYPE(QCamera::FrameRateRange) |
170 | |
171 | void tst_QCamera::initTestCase() |
172 | { |
173 | qRegisterMetaType<QCamera::FrameRateRange>(typeName: "FrameRateRange" ); |
174 | } |
175 | |
176 | void tst_QCamera::init() |
177 | { |
178 | provider = new MockMediaServiceProvider; |
179 | mockSimpleCameraService = new MockSimpleCameraService; |
180 | mockCameraService = new MockCameraService; |
181 | |
182 | provider->service = mockCameraService; |
183 | QMediaServiceProvider::setDefaultServiceProvider(provider); |
184 | } |
185 | |
186 | void tst_QCamera::cleanup() |
187 | { |
188 | delete provider; |
189 | delete mockCameraService; |
190 | delete mockSimpleCameraService; |
191 | } |
192 | |
193 | void tst_QCamera::testSimpleCamera() |
194 | { |
195 | provider->service = mockSimpleCameraService; |
196 | QCamera camera; |
197 | QCOMPARE(camera.service(), (QMediaService*)mockSimpleCameraService); |
198 | |
199 | QCOMPARE(camera.state(), QCamera::UnloadedState); |
200 | camera.start(); |
201 | QCOMPARE(camera.state(), QCamera::ActiveState); |
202 | camera.stop(); |
203 | QCOMPARE(camera.state(), QCamera::LoadedState); |
204 | camera.unload(); |
205 | QCOMPARE(camera.state(), QCamera::UnloadedState); |
206 | camera.load(); |
207 | QCOMPARE(camera.state(), QCamera::LoadedState); |
208 | } |
209 | |
210 | void tst_QCamera::testSimpleCameraWhiteBalance() |
211 | { |
212 | provider->service = mockSimpleCameraService; |
213 | QCamera camera; |
214 | |
215 | //only WhiteBalanceAuto is supported |
216 | QVERIFY(!camera.imageProcessing()->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceAuto)); |
217 | QVERIFY(!camera.imageProcessing()->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceCloudy)); |
218 | QCOMPARE(camera.imageProcessing()->whiteBalanceMode(), QCameraImageProcessing::WhiteBalanceAuto); |
219 | camera.imageProcessing()->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceCloudy); |
220 | QCOMPARE(camera.imageProcessing()->whiteBalanceMode(), QCameraImageProcessing::WhiteBalanceAuto); |
221 | QCOMPARE(camera.imageProcessing()->manualWhiteBalance()+1.0, 1.0); |
222 | camera.imageProcessing()->setManualWhiteBalance(5000); |
223 | QCOMPARE(camera.imageProcessing()->manualWhiteBalance()+1.0, 1.0); |
224 | } |
225 | |
226 | void tst_QCamera::testSimpleCameraExposure() |
227 | { |
228 | provider->service = mockSimpleCameraService; |
229 | QCamera camera; |
230 | QCameraExposure *cameraExposure = camera.exposure(); |
231 | QVERIFY(cameraExposure != 0); |
232 | |
233 | QVERIFY(!cameraExposure->isExposureModeSupported(QCameraExposure::ExposureAuto)); |
234 | QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureAuto); |
235 | cameraExposure->setExposureMode(QCameraExposure::ExposureManual);//should be ignored |
236 | QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureAuto); |
237 | |
238 | QVERIFY(!cameraExposure->isFlashModeSupported(QCameraExposure::FlashOff)); |
239 | QCOMPARE(cameraExposure->flashMode(), QCameraExposure::FlashOff); |
240 | QCOMPARE(cameraExposure->isFlashReady(), false); |
241 | cameraExposure->setFlashMode(QCameraExposure::FlashOn); |
242 | QCOMPARE(cameraExposure->flashMode(), QCameraExposure::FlashOff); |
243 | |
244 | QVERIFY(!cameraExposure->isMeteringModeSupported(QCameraExposure::MeteringAverage)); |
245 | QVERIFY(!cameraExposure->isMeteringModeSupported(QCameraExposure::MeteringSpot)); |
246 | QVERIFY(!cameraExposure->isMeteringModeSupported(QCameraExposure::MeteringMatrix)); |
247 | QCOMPARE(cameraExposure->meteringMode(), QCameraExposure::MeteringMatrix); |
248 | cameraExposure->setMeteringMode(QCameraExposure::MeteringSpot); |
249 | QCOMPARE(cameraExposure->meteringMode(), QCameraExposure::MeteringMatrix); |
250 | |
251 | QCOMPARE(cameraExposure->spotMeteringPoint(), QPointF()); |
252 | cameraExposure->setSpotMeteringPoint(QPointF(0.5f, 0.5f)); |
253 | QCOMPARE(cameraExposure->spotMeteringPoint(), QPointF()); |
254 | |
255 | QCOMPARE(cameraExposure->exposureCompensation(), 0.0); |
256 | cameraExposure->setExposureCompensation(2.0); |
257 | QCOMPARE(cameraExposure->exposureCompensation(), 0.0); |
258 | |
259 | QCOMPARE(cameraExposure->isoSensitivity(), -1); |
260 | QVERIFY(cameraExposure->supportedIsoSensitivities().isEmpty()); |
261 | cameraExposure->setManualIsoSensitivity(100); |
262 | QCOMPARE(cameraExposure->isoSensitivity(), -1); |
263 | cameraExposure->setAutoIsoSensitivity(); |
264 | QCOMPARE(cameraExposure->isoSensitivity(), -1); |
265 | |
266 | QVERIFY(cameraExposure->aperture() < 0); |
267 | QVERIFY(cameraExposure->supportedApertures().isEmpty()); |
268 | cameraExposure->setAutoAperture(); |
269 | QVERIFY(cameraExposure->aperture() < 0); |
270 | cameraExposure->setManualAperture(5.6); |
271 | QVERIFY(cameraExposure->aperture() < 0); |
272 | |
273 | QVERIFY(cameraExposure->shutterSpeed() < 0); |
274 | QVERIFY(cameraExposure->supportedShutterSpeeds().isEmpty()); |
275 | cameraExposure->setAutoShutterSpeed(); |
276 | QVERIFY(cameraExposure->shutterSpeed() < 0); |
277 | cameraExposure->setManualShutterSpeed(1/128.0); |
278 | QVERIFY(cameraExposure->shutterSpeed() < 0); |
279 | } |
280 | |
281 | void tst_QCamera::testSimpleCameraFocus() |
282 | { |
283 | provider->service = mockSimpleCameraService; |
284 | QCamera camera; |
285 | |
286 | QCameraFocus *cameraFocus = camera.focus(); |
287 | QVERIFY(cameraFocus != 0); |
288 | |
289 | QVERIFY(!cameraFocus->isFocusModeSupported(QCameraFocus::AutoFocus)); |
290 | QVERIFY(!cameraFocus->isFocusModeSupported(QCameraFocus::ContinuousFocus)); |
291 | QVERIFY(!cameraFocus->isFocusModeSupported(QCameraFocus::InfinityFocus)); |
292 | |
293 | QCOMPARE(cameraFocus->focusMode(), QCameraFocus::AutoFocus); |
294 | QTest::ignoreMessage(type: QtWarningMsg, message: "Focus mode selection is not supported" ); |
295 | cameraFocus->setFocusMode(QCameraFocus::ContinuousFocus); |
296 | QCOMPARE(cameraFocus->focusMode(), QCameraFocus::AutoFocus); |
297 | |
298 | QCOMPARE(cameraFocus->maximumOpticalZoom(), 1.0); |
299 | QCOMPARE(cameraFocus->maximumDigitalZoom(), 1.0); |
300 | QCOMPARE(cameraFocus->opticalZoom(), 1.0); |
301 | QCOMPARE(cameraFocus->digitalZoom(), 1.0); |
302 | |
303 | QTest::ignoreMessage(type: QtWarningMsg, message: "The camera doesn't support zooming." ); |
304 | cameraFocus->zoomTo(opticalZoom: 100.0, digitalZoom: 100.0); |
305 | QCOMPARE(cameraFocus->opticalZoom(), 1.0); |
306 | QCOMPARE(cameraFocus->digitalZoom(), 1.0); |
307 | |
308 | |
309 | QVERIFY(!cameraFocus->isFocusPointModeSupported(QCameraFocus::FocusPointAuto)); |
310 | QCOMPARE(cameraFocus->focusPointMode(), QCameraFocus::FocusPointAuto); |
311 | |
312 | QTest::ignoreMessage(type: QtWarningMsg, message: "Focus points mode selection is not supported" ); |
313 | cameraFocus->setFocusPointMode( QCameraFocus::FocusPointCenter ); |
314 | QCOMPARE(cameraFocus->focusPointMode(), QCameraFocus::FocusPointAuto); |
315 | |
316 | QCOMPARE(cameraFocus->customFocusPoint(), QPointF(0.5, 0.5)); |
317 | QTest::ignoreMessage(type: QtWarningMsg, message: "Focus points selection is not supported" ); |
318 | cameraFocus->setCustomFocusPoint(QPointF(1.0, 1.0)); |
319 | QCOMPARE(cameraFocus->customFocusPoint(), QPointF(0.5, 0.5)); |
320 | } |
321 | |
322 | void tst_QCamera::testSimpleCameraCapture() |
323 | { |
324 | provider->service = mockSimpleCameraService; |
325 | QCamera camera; |
326 | QCameraImageCapture imageCapture(&camera); |
327 | |
328 | QVERIFY(!imageCapture.isReadyForCapture()); |
329 | QVERIFY(!imageCapture.isAvailable()); |
330 | |
331 | QCOMPARE(imageCapture.error(), QCameraImageCapture::NoError); |
332 | QVERIFY(imageCapture.errorString().isEmpty()); |
333 | |
334 | QSignalSpy errorSignal(&imageCapture, SIGNAL(error(int,QCameraImageCapture::Error,QString))); |
335 | imageCapture.capture(location: QString::fromLatin1(str: "/dev/null" )); |
336 | QCOMPARE(errorSignal.size(), 1); |
337 | QCOMPARE(imageCapture.error(), QCameraImageCapture::NotSupportedFeatureError); |
338 | QVERIFY(!imageCapture.errorString().isEmpty()); |
339 | } |
340 | |
341 | void tst_QCamera::testSimpleCameraLock() |
342 | { |
343 | provider->service = mockSimpleCameraService; |
344 | QCamera camera; |
345 | QCOMPARE(camera.lockStatus(), QCamera::Unlocked); |
346 | QCOMPARE(camera.lockStatus(QCamera::LockExposure), QCamera::Unlocked); |
347 | QCOMPARE(camera.lockStatus(QCamera::LockFocus), QCamera::Unlocked); |
348 | QCOMPARE(camera.lockStatus(QCamera::LockWhiteBalance), QCamera::Unlocked); |
349 | |
350 | QSignalSpy lockedSignal(&camera, SIGNAL(locked())); |
351 | QSignalSpy lockFailedSignal(&camera, SIGNAL(lockFailed())); |
352 | QSignalSpy lockStatusChangedSignal(&camera, SIGNAL(lockStatusChanged(QCamera::LockStatus,QCamera::LockChangeReason))); |
353 | |
354 | camera.searchAndLock(); |
355 | QCOMPARE(camera.lockStatus(), QCamera::Unlocked); |
356 | QCOMPARE(camera.lockStatus(QCamera::LockExposure), QCamera::Unlocked); |
357 | QCOMPARE(camera.lockStatus(QCamera::LockFocus), QCamera::Unlocked); |
358 | QCOMPARE(camera.lockStatus(QCamera::LockWhiteBalance), QCamera::Unlocked); |
359 | QCOMPARE(lockedSignal.count(), 0); |
360 | QCOMPARE(lockFailedSignal.count(), 0); |
361 | QCOMPARE(lockStatusChangedSignal.count(), 0); |
362 | |
363 | lockedSignal.clear(); |
364 | lockFailedSignal.clear(); |
365 | lockStatusChangedSignal.clear(); |
366 | |
367 | camera.unlock(); |
368 | QCOMPARE(camera.lockStatus(), QCamera::Unlocked); |
369 | QCOMPARE(camera.lockStatus(QCamera::LockExposure), QCamera::Unlocked); |
370 | QCOMPARE(camera.lockStatus(QCamera::LockFocus), QCamera::Unlocked); |
371 | QCOMPARE(camera.lockStatus(QCamera::LockWhiteBalance), QCamera::Unlocked); |
372 | |
373 | QCOMPARE(lockedSignal.count(), 0); |
374 | QCOMPARE(lockFailedSignal.count(), 0); |
375 | QCOMPARE(lockStatusChangedSignal.count(), 0); |
376 | } |
377 | |
378 | void tst_QCamera::testSimpleCaptureDestination() |
379 | { |
380 | provider->service = mockSimpleCameraService; |
381 | QCamera camera; |
382 | QCameraImageCapture imageCapture(&camera); |
383 | |
384 | QVERIFY(imageCapture.isCaptureDestinationSupported(QCameraImageCapture::CaptureToFile)); |
385 | QVERIFY(!imageCapture.isCaptureDestinationSupported(QCameraImageCapture::CaptureToBuffer)); |
386 | QVERIFY(!imageCapture.isCaptureDestinationSupported( |
387 | QCameraImageCapture::CaptureToBuffer | QCameraImageCapture::CaptureToFile)); |
388 | |
389 | QCOMPARE(imageCapture.captureDestination(), QCameraImageCapture::CaptureToFile); |
390 | imageCapture.setCaptureDestination(QCameraImageCapture::CaptureToBuffer); |
391 | QCOMPARE(imageCapture.captureDestination(), QCameraImageCapture::CaptureToFile); |
392 | } |
393 | |
394 | void tst_QCamera::testSimpleCaptureFormat() |
395 | { |
396 | provider->service = mockSimpleCameraService; |
397 | QCamera camera; |
398 | QCameraImageCapture imageCapture(&camera); |
399 | |
400 | QCOMPARE(imageCapture.bufferFormat(), QVideoFrame::Format_Invalid); |
401 | QVERIFY(imageCapture.supportedBufferFormats().isEmpty()); |
402 | |
403 | imageCapture.setBufferFormat(QVideoFrame::Format_AdobeDng); |
404 | QCOMPARE(imageCapture.bufferFormat(), QVideoFrame::Format_Invalid); |
405 | } |
406 | |
407 | void tst_QCamera::testCaptureDestination() |
408 | { |
409 | QCamera camera; |
410 | QCameraImageCapture imageCapture(&camera); |
411 | |
412 | QVERIFY(imageCapture.isCaptureDestinationSupported(QCameraImageCapture::CaptureToFile)); |
413 | QVERIFY(imageCapture.isCaptureDestinationSupported(QCameraImageCapture::CaptureToBuffer)); |
414 | QVERIFY(!imageCapture.isCaptureDestinationSupported( |
415 | QCameraImageCapture::CaptureToBuffer | QCameraImageCapture::CaptureToFile)); |
416 | |
417 | QSignalSpy destinationChangedSignal(&imageCapture, SIGNAL(captureDestinationChanged(QCameraImageCapture::CaptureDestinations))); |
418 | |
419 | QCOMPARE(imageCapture.captureDestination(), QCameraImageCapture::CaptureToFile); |
420 | imageCapture.setCaptureDestination(QCameraImageCapture::CaptureToBuffer); |
421 | QCOMPARE(imageCapture.captureDestination(), QCameraImageCapture::CaptureToBuffer); |
422 | QCOMPARE(destinationChangedSignal.size(), 1); |
423 | QCOMPARE(destinationChangedSignal.first().first().value<QCameraImageCapture::CaptureDestinations>(), |
424 | QCameraImageCapture::CaptureToBuffer); |
425 | |
426 | //not supported combination |
427 | imageCapture.setCaptureDestination(QCameraImageCapture::CaptureToBuffer | QCameraImageCapture::CaptureToFile); |
428 | QCOMPARE(imageCapture.captureDestination(), QCameraImageCapture::CaptureToBuffer); |
429 | QCOMPARE(destinationChangedSignal.size(), 1); |
430 | } |
431 | |
432 | void tst_QCamera::testCaptureFormat() |
433 | { |
434 | QCamera camera; |
435 | QCameraImageCapture imageCapture(&camera); |
436 | |
437 | QSignalSpy formatChangedSignal(&imageCapture, SIGNAL(bufferFormatChanged(QVideoFrame::PixelFormat))); |
438 | |
439 | QCOMPARE(imageCapture.bufferFormat(), QVideoFrame::Format_Jpeg); |
440 | QCOMPARE(imageCapture.supportedBufferFormats().size(), 3); |
441 | |
442 | imageCapture.setBufferFormat(QVideoFrame::Format_AdobeDng); |
443 | QCOMPARE(imageCapture.bufferFormat(), QVideoFrame::Format_AdobeDng); |
444 | |
445 | QCOMPARE(formatChangedSignal.size(), 1); |
446 | QCOMPARE(formatChangedSignal.first().first().value<QVideoFrame::PixelFormat>(), |
447 | QVideoFrame::Format_AdobeDng); |
448 | |
449 | imageCapture.setBufferFormat(QVideoFrame::Format_Y16); |
450 | QCOMPARE(imageCapture.bufferFormat(), QVideoFrame::Format_AdobeDng); |
451 | |
452 | QCOMPARE(formatChangedSignal.size(), 1); |
453 | } |
454 | |
455 | |
456 | void tst_QCamera::testCameraCapture() |
457 | { |
458 | QCamera camera; |
459 | QCameraImageCapture imageCapture(&camera); |
460 | |
461 | QVERIFY(!imageCapture.isReadyForCapture()); |
462 | |
463 | QSignalSpy capturedSignal(&imageCapture, SIGNAL(imageCaptured(int,QImage))); |
464 | QSignalSpy errorSignal(&imageCapture, SIGNAL(error(int,QCameraImageCapture::Error,QString))); |
465 | |
466 | imageCapture.capture(location: QString::fromLatin1(str: "/dev/null" )); |
467 | QCOMPARE(capturedSignal.size(), 0); |
468 | QCOMPARE(errorSignal.size(), 1); |
469 | QCOMPARE(imageCapture.error(), QCameraImageCapture::NotReadyError); |
470 | |
471 | errorSignal.clear(); |
472 | |
473 | camera.start(); |
474 | QVERIFY(imageCapture.isReadyForCapture()); |
475 | QCOMPARE(errorSignal.size(), 0); |
476 | |
477 | imageCapture.capture(location: QString::fromLatin1(str: "/dev/null" )); |
478 | |
479 | QTRY_COMPARE(capturedSignal.size(), 1); |
480 | QCOMPARE(errorSignal.size(), 0); |
481 | QCOMPARE(imageCapture.error(), QCameraImageCapture::NoError); |
482 | } |
483 | |
484 | void tst_QCamera::testCameraCaptureMetadata() |
485 | { |
486 | QCamera camera; |
487 | QCameraImageCapture imageCapture(&camera); |
488 | |
489 | QSignalSpy metadataSignal(&imageCapture, SIGNAL(imageMetadataAvailable(int,QString,QVariant))); |
490 | QSignalSpy savedSignal(&imageCapture, SIGNAL(imageSaved(int,QString))); |
491 | |
492 | camera.start(); |
493 | int id = imageCapture.capture(location: QString::fromLatin1(str: "/dev/null" )); |
494 | |
495 | QTRY_COMPARE(savedSignal.size(), 1); |
496 | |
497 | QCOMPARE(metadataSignal.size(), 3); |
498 | |
499 | QVariantList metadata = metadataSignal[0]; |
500 | QCOMPARE(metadata[0].toInt(), id); |
501 | QCOMPARE(metadata[1].toString(), QMediaMetaData::FocalLengthIn35mmFilm); |
502 | QCOMPARE(metadata[2].value<QVariant>().toInt(), 50); |
503 | |
504 | metadata = metadataSignal[1]; |
505 | QCOMPARE(metadata[0].toInt(), id); |
506 | QCOMPARE(metadata[1].toString(), QMediaMetaData::DateTimeOriginal); |
507 | QDateTime captureTime = metadata[2].value<QVariant>().value<QDateTime>(); |
508 | const qint64 dt = captureTime.secsTo(QDateTime::currentDateTime()); |
509 | QVERIFY2(qAbs(dt) < 5, QByteArray::number(dt).constData()); // it should not take more than 5 seconds for signal to arrive here |
510 | |
511 | metadata = metadataSignal[2]; |
512 | QCOMPARE(metadata[0].toInt(), id); |
513 | QCOMPARE(metadata[1].toString(), QLatin1String("Answer to the Ultimate Question of Life, the Universe, and Everything" )); |
514 | QCOMPARE(metadata[2].value<QVariant>().toInt(), 42); |
515 | } |
516 | |
517 | |
518 | void tst_QCamera::testCameraWhiteBalance() |
519 | { |
520 | QSet<QCameraImageProcessing::WhiteBalanceMode> whiteBalanceModes; |
521 | whiteBalanceModes << QCameraImageProcessing::WhiteBalanceAuto; |
522 | whiteBalanceModes << QCameraImageProcessing::WhiteBalanceFlash; |
523 | whiteBalanceModes << QCameraImageProcessing::WhiteBalanceTungsten; |
524 | |
525 | MockCameraService service; |
526 | service.mockImageProcessingControl->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceFlash); |
527 | service.mockImageProcessingControl->setSupportedWhiteBalanceModes(whiteBalanceModes); |
528 | service.mockImageProcessingControl->setParameter( |
529 | parameter: QCameraImageProcessingControl::ColorTemperature, |
530 | value: QVariant(34)); |
531 | |
532 | provider->service = &service; |
533 | |
534 | QCamera camera; |
535 | QCameraImageProcessing *cameraImageProcessing = camera.imageProcessing(); |
536 | |
537 | QCOMPARE(cameraImageProcessing->whiteBalanceMode(), QCameraImageProcessing::WhiteBalanceFlash); |
538 | QVERIFY(camera.imageProcessing()->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceAuto)); |
539 | QVERIFY(camera.imageProcessing()->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceFlash)); |
540 | QVERIFY(camera.imageProcessing()->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceTungsten)); |
541 | QVERIFY(!camera.imageProcessing()->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceCloudy)); |
542 | |
543 | cameraImageProcessing->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceTungsten); |
544 | QCOMPARE(cameraImageProcessing->whiteBalanceMode(), QCameraImageProcessing::WhiteBalanceTungsten); |
545 | |
546 | cameraImageProcessing->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceManual); |
547 | QCOMPARE(cameraImageProcessing->whiteBalanceMode(), QCameraImageProcessing::WhiteBalanceManual); |
548 | QCOMPARE(cameraImageProcessing->manualWhiteBalance(), 34.0); |
549 | |
550 | cameraImageProcessing->setManualWhiteBalance(432.0); |
551 | QCOMPARE(cameraImageProcessing->manualWhiteBalance(), 432.0); |
552 | } |
553 | |
554 | void tst_QCamera::testCameraExposure() |
555 | { |
556 | QCamera camera; |
557 | |
558 | QCameraExposure *cameraExposure = camera.exposure(); |
559 | QVERIFY(cameraExposure != 0); |
560 | |
561 | QVERIFY(cameraExposure->isExposureModeSupported(QCameraExposure::ExposureAuto)); |
562 | QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureAuto); |
563 | |
564 | // Test Cases For QCameraExposure |
565 | QVERIFY(cameraExposure->isExposureModeSupported(QCameraExposure::ExposureManual)); |
566 | cameraExposure->setExposureMode(QCameraExposure::ExposureManual); |
567 | QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureManual); |
568 | |
569 | QVERIFY(cameraExposure->isExposureModeSupported(QCameraExposure::ExposureNight)); |
570 | cameraExposure->setExposureMode(QCameraExposure::ExposureNight); |
571 | QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureNight); |
572 | |
573 | QVERIFY(cameraExposure->isExposureModeSupported(QCameraExposure::ExposureBacklight)); |
574 | cameraExposure->setExposureMode(QCameraExposure::ExposureBacklight); |
575 | QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureBacklight); |
576 | |
577 | |
578 | QVERIFY(cameraExposure->isExposureModeSupported(QCameraExposure::ExposureSpotlight )); |
579 | cameraExposure->setExposureMode(QCameraExposure::ExposureSpotlight); |
580 | QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureSpotlight); |
581 | |
582 | QVERIFY(cameraExposure->isExposureModeSupported(QCameraExposure::ExposureSports )); |
583 | cameraExposure->setExposureMode(QCameraExposure::ExposureSports); |
584 | QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureSports); |
585 | |
586 | QVERIFY(cameraExposure->isExposureModeSupported(QCameraExposure::ExposureSnow )); |
587 | cameraExposure->setExposureMode(QCameraExposure::ExposureSnow); |
588 | QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureSnow); |
589 | |
590 | QVERIFY(cameraExposure->isExposureModeSupported(QCameraExposure::ExposureBeach )); |
591 | cameraExposure->setExposureMode(QCameraExposure::ExposureBeach); |
592 | QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureBeach); |
593 | |
594 | QVERIFY(cameraExposure->isExposureModeSupported(QCameraExposure::ExposureLargeAperture )); |
595 | cameraExposure->setExposureMode(QCameraExposure::ExposureLargeAperture); |
596 | QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureLargeAperture); |
597 | |
598 | QVERIFY(cameraExposure->isExposureModeSupported(QCameraExposure::ExposureSmallAperture )); |
599 | cameraExposure->setExposureMode(QCameraExposure::ExposureSmallAperture); |
600 | QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureSmallAperture); |
601 | |
602 | QVERIFY(cameraExposure->isExposureModeSupported(QCameraExposure::ExposurePortrait )); |
603 | cameraExposure->setExposureMode(QCameraExposure::ExposurePortrait); |
604 | QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposurePortrait); |
605 | |
606 | QVERIFY(cameraExposure->isExposureModeSupported(QCameraExposure::ExposureModeVendor )); |
607 | cameraExposure->setExposureMode(QCameraExposure::ExposureModeVendor); |
608 | QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureModeVendor); |
609 | |
610 | |
611 | cameraExposure->setFlashMode(QCameraExposure::FlashAuto); |
612 | QCOMPARE(cameraExposure->flashMode(), QCameraExposure::FlashAuto); |
613 | QCOMPARE(cameraExposure->isFlashReady(), true); |
614 | cameraExposure->setFlashMode(QCameraExposure::FlashRedEyeReduction); |
615 | QCOMPARE(cameraExposure->flashMode(), QCameraExposure::FlashRedEyeReduction); |
616 | cameraExposure->setFlashMode(QCameraExposure::FlashOn); |
617 | QCOMPARE(cameraExposure->flashMode(), QCameraExposure::FlashOn); |
618 | cameraExposure->setFlashMode(QCameraExposure::FlashFill); |
619 | QCOMPARE(cameraExposure->flashMode(), QCameraExposure::FlashFill); |
620 | cameraExposure->setFlashMode(QCameraExposure::FlashTorch); |
621 | QCOMPARE(cameraExposure->flashMode(), QCameraExposure::FlashTorch); |
622 | cameraExposure->setFlashMode(QCameraExposure::FlashSlowSyncFrontCurtain); |
623 | QCOMPARE(cameraExposure->flashMode(), QCameraExposure::FlashSlowSyncFrontCurtain); |
624 | |
625 | QVERIFY(!cameraExposure->isMeteringModeSupported(QCameraExposure::MeteringAverage)); |
626 | QVERIFY(cameraExposure->isMeteringModeSupported(QCameraExposure::MeteringSpot)); |
627 | QVERIFY(cameraExposure->isMeteringModeSupported(QCameraExposure::MeteringMatrix)); |
628 | |
629 | cameraExposure->setMeteringMode(QCameraExposure::MeteringMatrix); |
630 | QCOMPARE(cameraExposure->meteringMode(), QCameraExposure::MeteringMatrix); |
631 | |
632 | //MeteringAverage is not supported, metering mode should not be changed |
633 | cameraExposure->setMeteringMode(QCameraExposure::MeteringAverage); |
634 | QCOMPARE(cameraExposure->meteringMode(), QCameraExposure::MeteringMatrix); |
635 | |
636 | cameraExposure->setMeteringMode(QCameraExposure::MeteringSpot); |
637 | QCOMPARE(cameraExposure->meteringMode(), QCameraExposure::MeteringSpot); |
638 | |
639 | cameraExposure->setSpotMeteringPoint(QPointF(0.5f, 0.25f)); |
640 | QCOMPARE(cameraExposure->spotMeteringPoint(), QPointF(0.5f, 0.25f)); |
641 | cameraExposure->setSpotMeteringPoint(QPointF(0.25f, 56.3f)); |
642 | QCOMPARE(cameraExposure->spotMeteringPoint(), QPointF(0.5f, 0.25f)); |
643 | cameraExposure->setSpotMeteringPoint(QPointF(0, 0)); |
644 | QCOMPARE(cameraExposure->spotMeteringPoint(), QPointF(0, 0)); |
645 | cameraExposure->setSpotMeteringPoint(QPointF(1, 1)); |
646 | QCOMPARE(cameraExposure->spotMeteringPoint(), QPointF(1, 1)); |
647 | |
648 | QCOMPARE(cameraExposure->exposureCompensation(), 0.0); |
649 | cameraExposure->setExposureCompensation(2.0); |
650 | QCOMPARE(cameraExposure->exposureCompensation(), 2.0); |
651 | |
652 | int minIso = cameraExposure->supportedIsoSensitivities().first(); |
653 | int maxIso = cameraExposure->supportedIsoSensitivities().last(); |
654 | QVERIFY(cameraExposure->isoSensitivity() > 0); |
655 | QCOMPARE(cameraExposure->requestedIsoSensitivity(), -1); |
656 | QVERIFY(minIso > 0); |
657 | QVERIFY(maxIso > 0); |
658 | cameraExposure->setManualIsoSensitivity(minIso); |
659 | QCOMPARE(cameraExposure->isoSensitivity(), minIso); |
660 | cameraExposure->setManualIsoSensitivity(maxIso*10); |
661 | QCOMPARE(cameraExposure->isoSensitivity(), maxIso); |
662 | QCOMPARE(cameraExposure->requestedIsoSensitivity(), maxIso*10); |
663 | |
664 | cameraExposure->setManualIsoSensitivity(-10); |
665 | QCOMPARE(cameraExposure->isoSensitivity(), minIso); |
666 | QCOMPARE(cameraExposure->requestedIsoSensitivity(), -10); |
667 | cameraExposure->setAutoIsoSensitivity(); |
668 | QCOMPARE(cameraExposure->isoSensitivity(), 100); |
669 | QCOMPARE(cameraExposure->requestedIsoSensitivity(), -1); |
670 | |
671 | QCOMPARE(cameraExposure->requestedAperture(), -1.0); |
672 | qreal minAperture = cameraExposure->supportedApertures().first(); |
673 | qreal maxAperture = cameraExposure->supportedApertures().last(); |
674 | QVERIFY(minAperture > 0); |
675 | QVERIFY(maxAperture > 0); |
676 | QVERIFY(cameraExposure->aperture() >= minAperture); |
677 | QVERIFY(cameraExposure->aperture() <= maxAperture); |
678 | |
679 | cameraExposure->setAutoAperture(); |
680 | QVERIFY(cameraExposure->aperture() >= minAperture); |
681 | QVERIFY(cameraExposure->aperture() <= maxAperture); |
682 | QCOMPARE(cameraExposure->requestedAperture(), -1.0); |
683 | |
684 | cameraExposure->setManualAperture(0); |
685 | QCOMPARE(cameraExposure->aperture(), minAperture); |
686 | QCOMPARE(cameraExposure->requestedAperture()+1.0, 1.0); |
687 | |
688 | cameraExposure->setManualAperture(10000); |
689 | QCOMPARE(cameraExposure->aperture(), maxAperture); |
690 | QCOMPARE(cameraExposure->requestedAperture(), 10000.0); |
691 | |
692 | cameraExposure->setAutoAperture(); |
693 | QCOMPARE(cameraExposure->requestedAperture(), -1.0); |
694 | |
695 | QCOMPARE(cameraExposure->requestedShutterSpeed(), -1.0); |
696 | qreal minShutterSpeed = cameraExposure->supportedShutterSpeeds().first(); |
697 | qreal maxShutterSpeed = cameraExposure->supportedShutterSpeeds().last(); |
698 | QVERIFY(minShutterSpeed > 0); |
699 | QVERIFY(maxShutterSpeed > 0); |
700 | QVERIFY(cameraExposure->shutterSpeed() >= minShutterSpeed); |
701 | QVERIFY(cameraExposure->shutterSpeed() <= maxShutterSpeed); |
702 | |
703 | cameraExposure->setAutoShutterSpeed(); |
704 | QVERIFY(cameraExposure->shutterSpeed() >= minShutterSpeed); |
705 | QVERIFY(cameraExposure->shutterSpeed() <= maxShutterSpeed); |
706 | QCOMPARE(cameraExposure->requestedShutterSpeed(), -1.0); |
707 | |
708 | cameraExposure->setManualShutterSpeed(0); |
709 | QCOMPARE(cameraExposure->shutterSpeed(), minShutterSpeed); |
710 | QCOMPARE(cameraExposure->requestedShutterSpeed()+1.0, 1.0); |
711 | |
712 | cameraExposure->setManualShutterSpeed(10000); |
713 | QCOMPARE(cameraExposure->shutterSpeed(), maxShutterSpeed); |
714 | QCOMPARE(cameraExposure->requestedShutterSpeed(), 10000.0); |
715 | |
716 | cameraExposure->setAutoShutterSpeed(); |
717 | QCOMPARE(cameraExposure->requestedShutterSpeed(), -1.0); |
718 | } |
719 | |
720 | void tst_QCamera::testCameraFocus() |
721 | { |
722 | QCamera camera; |
723 | |
724 | QCameraFocus *cameraFocus = camera.focus(); |
725 | QVERIFY(cameraFocus != 0); |
726 | |
727 | QVERIFY(cameraFocus->isFocusModeSupported(QCameraFocus::AutoFocus)); |
728 | QVERIFY(cameraFocus->isFocusModeSupported(QCameraFocus::ContinuousFocus)); |
729 | QVERIFY(!cameraFocus->isFocusModeSupported(QCameraFocus::InfinityFocus)); |
730 | |
731 | QCOMPARE(cameraFocus->focusMode(), QCameraFocus::AutoFocus); |
732 | cameraFocus->setFocusMode(QCameraFocus::ManualFocus); |
733 | QCOMPARE(cameraFocus->focusMode(), QCameraFocus::AutoFocus); |
734 | cameraFocus->setFocusMode(QCameraFocus::ContinuousFocus); |
735 | QCOMPARE(cameraFocus->focusMode(), QCameraFocus::ContinuousFocus); |
736 | |
737 | QVERIFY(cameraFocus->maximumOpticalZoom() >= 1.0); |
738 | QVERIFY(cameraFocus->maximumDigitalZoom() >= 1.0); |
739 | QCOMPARE(cameraFocus->opticalZoom(), 1.0); |
740 | QCOMPARE(cameraFocus->digitalZoom(), 1.0); |
741 | cameraFocus->zoomTo(opticalZoom: 0.5, digitalZoom: 1.0); |
742 | QCOMPARE(cameraFocus->opticalZoom(), 1.0); |
743 | QCOMPARE(cameraFocus->digitalZoom(), 1.0); |
744 | cameraFocus->zoomTo(opticalZoom: 2.0, digitalZoom: 0.5); |
745 | QCOMPARE(cameraFocus->opticalZoom(), 2.0); |
746 | QCOMPARE(cameraFocus->digitalZoom(), 1.0); |
747 | cameraFocus->zoomTo(opticalZoom: 2.0, digitalZoom: 2.5); |
748 | QCOMPARE(cameraFocus->opticalZoom(), 2.0); |
749 | QCOMPARE(cameraFocus->digitalZoom(), 2.5); |
750 | cameraFocus->zoomTo(opticalZoom: 2000000.0, digitalZoom: 1000000.0); |
751 | QVERIFY(qFuzzyCompare(cameraFocus->opticalZoom(), cameraFocus->maximumOpticalZoom())); |
752 | QVERIFY(qFuzzyCompare(cameraFocus->digitalZoom(), cameraFocus->maximumDigitalZoom())); |
753 | |
754 | QVERIFY(cameraFocus->isFocusPointModeSupported(QCameraFocus::FocusPointAuto)); |
755 | QVERIFY(cameraFocus->isFocusPointModeSupported(QCameraFocus::FocusPointCenter)); |
756 | QVERIFY(cameraFocus->isFocusPointModeSupported(QCameraFocus::FocusPointCustom)); |
757 | QCOMPARE(cameraFocus->focusPointMode(), QCameraFocus::FocusPointAuto); |
758 | |
759 | cameraFocus->setFocusPointMode( QCameraFocus::FocusPointCenter ); |
760 | QCOMPARE(cameraFocus->focusPointMode(), QCameraFocus::FocusPointCenter); |
761 | |
762 | cameraFocus->setFocusPointMode( QCameraFocus::FocusPointFaceDetection ); |
763 | QCOMPARE(cameraFocus->focusPointMode(), QCameraFocus::FocusPointCenter); |
764 | |
765 | QCOMPARE(cameraFocus->customFocusPoint(), QPointF(0.5, 0.5)); |
766 | cameraFocus->setCustomFocusPoint(QPointF(1.0, 1.0)); |
767 | QCOMPARE(cameraFocus->customFocusPoint(), QPointF(1.0, 1.0)); |
768 | } |
769 | |
770 | void tst_QCamera::testImageSettings() |
771 | { |
772 | QImageEncoderSettings settings; |
773 | QVERIFY(settings.isNull()); |
774 | QVERIFY(settings == QImageEncoderSettings()); |
775 | |
776 | QCOMPARE(settings.codec(), QString()); |
777 | settings.setCodec(QLatin1String("codecName" )); |
778 | QCOMPARE(settings.codec(), QLatin1String("codecName" )); |
779 | QVERIFY(!settings.isNull()); |
780 | QVERIFY(settings != QImageEncoderSettings()); |
781 | |
782 | settings = QImageEncoderSettings(); |
783 | QCOMPARE(settings.quality(), QMultimedia::NormalQuality); |
784 | settings.setQuality(QMultimedia::HighQuality); |
785 | QCOMPARE(settings.quality(), QMultimedia::HighQuality); |
786 | QVERIFY(!settings.isNull()); |
787 | |
788 | settings = QImageEncoderSettings(); |
789 | QCOMPARE(settings.resolution(), QSize()); |
790 | settings.setResolution(QSize(320,240)); |
791 | QCOMPARE(settings.resolution(), QSize(320,240)); |
792 | settings.setResolution(width: 800,height: 600); |
793 | QCOMPARE(settings.resolution(), QSize(800,600)); |
794 | QVERIFY(!settings.isNull()); |
795 | |
796 | settings = QImageEncoderSettings(); |
797 | settings.setEncodingOption(option: QLatin1String("encoderOption" ), value: QVariant(1)); |
798 | QCOMPARE(settings.encodingOption(QLatin1String("encoderOption" )), QVariant(1)); |
799 | QVariantMap options; |
800 | options.insert(key: QLatin1String("encoderOption" ), value: QVariant(1)); |
801 | QCOMPARE(settings.encodingOptions(), options); |
802 | options.insert(key: QLatin1String("encoderOption2" ), value: QVariant(2)); |
803 | options.remove(key: QLatin1String("encoderOption" )); |
804 | settings.setEncodingOptions(options); |
805 | QCOMPARE(settings.encodingOption(QLatin1String("encoderOption" )), QVariant()); |
806 | QCOMPARE(settings.encodingOption(QLatin1String("encoderOption2" )), QVariant(2)); |
807 | QVERIFY(!settings.isNull()); |
808 | QVERIFY(settings != QImageEncoderSettings()); |
809 | |
810 | settings = QImageEncoderSettings(); |
811 | QVERIFY(settings.isNull()); |
812 | QCOMPARE(settings.codec(), QString()); |
813 | QCOMPARE(settings.quality(), QMultimedia::NormalQuality); |
814 | QCOMPARE(settings.resolution(), QSize()); |
815 | QVERIFY(settings.encodingOptions().isEmpty()); |
816 | |
817 | { |
818 | QImageEncoderSettings settings1; |
819 | QImageEncoderSettings settings2; |
820 | QCOMPARE(settings2, settings1); |
821 | |
822 | settings2 = settings1; |
823 | QCOMPARE(settings2, settings1); |
824 | QVERIFY(settings2.isNull()); |
825 | |
826 | settings1.setQuality(QMultimedia::HighQuality); |
827 | |
828 | QVERIFY(settings2.isNull()); |
829 | QVERIFY(!settings1.isNull()); |
830 | QVERIFY(settings1 != settings2); |
831 | } |
832 | |
833 | { |
834 | QImageEncoderSettings settings1; |
835 | QImageEncoderSettings settings2(settings1); |
836 | QCOMPARE(settings2, settings1); |
837 | |
838 | settings2 = settings1; |
839 | QCOMPARE(settings2, settings1); |
840 | QVERIFY(settings2.isNull()); |
841 | |
842 | settings1.setQuality(QMultimedia::HighQuality); |
843 | |
844 | QVERIFY(settings2.isNull()); |
845 | QVERIFY(!settings1.isNull()); |
846 | QVERIFY(settings1 != settings2); |
847 | } |
848 | |
849 | QImageEncoderSettings settings1; |
850 | QImageEncoderSettings settings2; |
851 | |
852 | settings1 = QImageEncoderSettings(); |
853 | settings1.setResolution(width: 800,height: 600); |
854 | settings2 = QImageEncoderSettings(); |
855 | settings2.setResolution(QSize(800,600)); |
856 | QVERIFY(settings1 == settings2); |
857 | settings2.setResolution(QSize(400,300)); |
858 | QVERIFY(settings1 != settings2); |
859 | |
860 | settings1 = QImageEncoderSettings(); |
861 | settings1.setCodec("codec1" ); |
862 | settings2 = QImageEncoderSettings(); |
863 | settings2.setCodec("codec1" ); |
864 | QVERIFY(settings1 == settings2); |
865 | settings2.setCodec("codec2" ); |
866 | QVERIFY(settings1 != settings2); |
867 | |
868 | settings1 = QImageEncoderSettings(); |
869 | settings1.setQuality(QMultimedia::NormalQuality); |
870 | settings2 = QImageEncoderSettings(); |
871 | settings2.setQuality(QMultimedia::NormalQuality); |
872 | QVERIFY(settings1 == settings2); |
873 | settings2.setQuality(QMultimedia::LowQuality); |
874 | QVERIFY(settings1 != settings2); |
875 | |
876 | settings1 = QImageEncoderSettings(); |
877 | settings1.setEncodingOption(option: QLatin1String("encoderOption" ), value: QVariant(1)); |
878 | settings2 = QImageEncoderSettings(); |
879 | settings2.setEncodingOption(option: QLatin1String("encoderOption" ), value: QVariant(1)); |
880 | QVERIFY(settings1 == settings2); |
881 | settings2.setEncodingOption(option: QLatin1String("encoderOption" ), value: QVariant(2)); |
882 | QVERIFY(settings1 != settings2); |
883 | } |
884 | |
885 | void tst_QCamera::testViewfinderSettings() |
886 | { |
887 | QCameraViewfinderSettings settings; |
888 | QVERIFY(settings.isNull()); |
889 | QVERIFY(settings == QCameraViewfinderSettings()); |
890 | |
891 | QCOMPARE(settings.resolution(), QSize()); |
892 | settings.setResolution(QSize(640, 480)); |
893 | QCOMPARE(settings.resolution(), QSize(640, 480)); |
894 | settings.setResolution(width: 1280, height: 720); |
895 | QCOMPARE(settings.resolution(), QSize(1280, 720)); |
896 | QVERIFY(!settings.isNull()); |
897 | QVERIFY(settings != QCameraViewfinderSettings()); |
898 | |
899 | settings = QCameraViewfinderSettings(); |
900 | QVERIFY(qFuzzyIsNull(settings.minimumFrameRate())); |
901 | settings.setMinimumFrameRate(10.0); |
902 | QVERIFY(qFuzzyCompare(settings.minimumFrameRate(), 10.0)); |
903 | QVERIFY(qFuzzyIsNull(settings.maximumFrameRate())); |
904 | settings.setMaximumFrameRate(20.0); |
905 | QVERIFY(qFuzzyCompare(settings.maximumFrameRate(), 20.0)); |
906 | QVERIFY(!settings.isNull()); |
907 | |
908 | settings = QCameraViewfinderSettings(); |
909 | QCOMPARE(settings.pixelFormat(), QVideoFrame::Format_Invalid); |
910 | settings.setPixelFormat(QVideoFrame::Format_RGB32); |
911 | QCOMPARE(settings.pixelFormat(), QVideoFrame::Format_RGB32); |
912 | QVERIFY(!settings.isNull()); |
913 | |
914 | settings = QCameraViewfinderSettings(); |
915 | QCOMPARE(settings.pixelAspectRatio(), QSize()); |
916 | settings.setPixelAspectRatio(QSize(2, 1)); |
917 | QCOMPARE(settings.pixelAspectRatio(), QSize(2, 1)); |
918 | settings.setPixelAspectRatio(horizontal: 3, vertical: 2); |
919 | QCOMPARE(settings.pixelAspectRatio(), QSize(3, 2)); |
920 | QVERIFY(!settings.isNull()); |
921 | |
922 | settings = QCameraViewfinderSettings(); |
923 | |
924 | { |
925 | QCameraViewfinderSettings settings1; |
926 | QCameraViewfinderSettings settings2; |
927 | QCOMPARE(settings2, settings1); |
928 | |
929 | settings2 = settings1; |
930 | QCOMPARE(settings2, settings1); |
931 | QVERIFY(settings2.isNull()); |
932 | |
933 | settings1.setResolution(width: 800, height: 600); |
934 | |
935 | QVERIFY(settings2.isNull()); |
936 | QVERIFY(!settings1.isNull()); |
937 | QVERIFY(settings1 != settings2); |
938 | } |
939 | |
940 | { |
941 | QCameraViewfinderSettings settings1; |
942 | QCameraViewfinderSettings settings2(settings1); |
943 | QCOMPARE(settings2, settings1); |
944 | |
945 | settings2 = settings1; |
946 | QCOMPARE(settings2, settings1); |
947 | QVERIFY(settings2.isNull()); |
948 | |
949 | settings1.setResolution(width: 800, height: 600); |
950 | |
951 | QVERIFY(settings2.isNull()); |
952 | QVERIFY(!settings1.isNull()); |
953 | QVERIFY(settings1 != settings2); |
954 | } |
955 | |
956 | QCameraViewfinderSettings settings1; |
957 | QCameraViewfinderSettings settings2; |
958 | |
959 | settings1 = QCameraViewfinderSettings(); |
960 | settings1.setResolution(width: 800,height: 600); |
961 | settings2 = QCameraViewfinderSettings(); |
962 | settings2.setResolution(QSize(800,600)); |
963 | QVERIFY(settings1 == settings2); |
964 | settings2.setResolution(QSize(400,300)); |
965 | QVERIFY(settings1 != settings2); |
966 | |
967 | settings1 = QCameraViewfinderSettings(); |
968 | settings1.setMinimumFrameRate(10.0); |
969 | settings2 = QCameraViewfinderSettings(); |
970 | settings2.setMinimumFrameRate(10.0); |
971 | QVERIFY(settings1 == settings2); |
972 | settings2.setMinimumFrameRate(15.0); |
973 | QVERIFY(settings1 != settings2); |
974 | |
975 | settings1 = QCameraViewfinderSettings(); |
976 | settings1.setMaximumFrameRate(30.0); |
977 | settings2 = QCameraViewfinderSettings(); |
978 | settings2.setMaximumFrameRate(30.0); |
979 | QVERIFY(settings1 == settings2); |
980 | settings2.setMaximumFrameRate(15.0); |
981 | QVERIFY(settings1 != settings2); |
982 | |
983 | settings1 = QCameraViewfinderSettings(); |
984 | settings1.setPixelFormat(QVideoFrame::Format_YV12); |
985 | settings2 = QCameraViewfinderSettings(); |
986 | settings2.setPixelFormat(QVideoFrame::Format_YV12); |
987 | QVERIFY(settings1 == settings2); |
988 | settings2.setPixelFormat(QVideoFrame::Format_NV21); |
989 | QVERIFY(settings1 != settings2); |
990 | |
991 | settings1 = QCameraViewfinderSettings(); |
992 | settings1.setPixelAspectRatio(horizontal: 2,vertical: 1); |
993 | settings2 = QCameraViewfinderSettings(); |
994 | settings2.setPixelAspectRatio(QSize(2,1)); |
995 | QVERIFY(settings1 == settings2); |
996 | settings2.setPixelAspectRatio(QSize(1,2)); |
997 | QVERIFY(settings1 != settings2); |
998 | } |
999 | |
1000 | void tst_QCamera::testViewfinderSettingsChange() |
1001 | { |
1002 | QCamera camera; |
1003 | |
1004 | QSignalSpy stateChangedSignal(&camera, SIGNAL(stateChanged(QCamera::State))); |
1005 | QSignalSpy statusChangedSignal(&camera, SIGNAL(statusChanged(QCamera::Status))); |
1006 | |
1007 | camera.start(); |
1008 | QCOMPARE(camera.state(), QCamera::ActiveState); |
1009 | QCOMPARE(camera.status(), QCamera::ActiveStatus); |
1010 | |
1011 | QCOMPARE(stateChangedSignal.count(), 1); |
1012 | QCOMPARE(statusChangedSignal.count(), 1); |
1013 | stateChangedSignal.clear(); |
1014 | statusChangedSignal.clear(); |
1015 | |
1016 | //the settings change should trigger camera stop/start |
1017 | camera.setViewfinderSettings(QCameraViewfinderSettings()); |
1018 | QCOMPARE(camera.state(), QCamera::ActiveState); |
1019 | QCOMPARE(camera.status(), QCamera::LoadedStatus); |
1020 | |
1021 | QCOMPARE(stateChangedSignal.count(), 0); |
1022 | QCOMPARE(statusChangedSignal.count(), 1); |
1023 | stateChangedSignal.clear(); |
1024 | statusChangedSignal.clear(); |
1025 | |
1026 | QCOMPARE(camera.state(), QCamera::ActiveState); |
1027 | QTRY_COMPARE(camera.status(), QCamera::ActiveStatus); |
1028 | |
1029 | QCOMPARE(stateChangedSignal.count(), 0); |
1030 | QCOMPARE(statusChangedSignal.count(), 1); |
1031 | stateChangedSignal.clear(); |
1032 | statusChangedSignal.clear(); |
1033 | |
1034 | //the settings change should trigger camera stop/start only once |
1035 | camera.setViewfinderSettings(QCameraViewfinderSettings()); |
1036 | camera.setViewfinderSettings(QCameraViewfinderSettings()); |
1037 | |
1038 | QCOMPARE(camera.state(), QCamera::ActiveState); |
1039 | QCOMPARE(camera.status(), QCamera::LoadedStatus); |
1040 | |
1041 | QCOMPARE(stateChangedSignal.count(), 0); |
1042 | QCOMPARE(statusChangedSignal.count(), 1); |
1043 | stateChangedSignal.clear(); |
1044 | statusChangedSignal.clear(); |
1045 | |
1046 | QCOMPARE(camera.state(), QCamera::ActiveState); |
1047 | QTRY_COMPARE(camera.status(), QCamera::ActiveStatus); |
1048 | |
1049 | QCOMPARE(stateChangedSignal.count(), 0); |
1050 | QCOMPARE(statusChangedSignal.count(), 1); |
1051 | } |
1052 | |
1053 | class ViewfinderSettingsBuilder |
1054 | { |
1055 | public: |
1056 | ViewfinderSettingsBuilder &setResolution(int width, int height) { |
1057 | m_settings.setResolution(width, height); |
1058 | return *this; |
1059 | } |
1060 | |
1061 | ViewfinderSettingsBuilder &setMinimumFrameRate(qreal r) { |
1062 | m_settings.setMinimumFrameRate(r); |
1063 | return *this; |
1064 | } |
1065 | |
1066 | ViewfinderSettingsBuilder &setMaximumFrameRate(qreal r) { |
1067 | m_settings.setMaximumFrameRate(r); |
1068 | return *this; |
1069 | } |
1070 | |
1071 | ViewfinderSettingsBuilder &setPixelFormat(QVideoFrame::PixelFormat f) { |
1072 | m_settings.setPixelFormat(f); |
1073 | return *this; |
1074 | } |
1075 | |
1076 | ViewfinderSettingsBuilder &setPixelAspectRatio(int h, int v) { |
1077 | m_settings.setPixelAspectRatio(horizontal: h, vertical: v); |
1078 | return *this; |
1079 | } |
1080 | |
1081 | QCameraViewfinderSettings build() { |
1082 | QCameraViewfinderSettings s = m_settings; |
1083 | m_settings = QCameraViewfinderSettings(); |
1084 | return s; |
1085 | } |
1086 | |
1087 | private: |
1088 | QCameraViewfinderSettings m_settings; |
1089 | }; |
1090 | |
1091 | void tst_QCamera::testSupportedViewfinderSettings_data() |
1092 | { |
1093 | // see mockcameraviewfindersettingscontrol.h for expected values |
1094 | |
1095 | ViewfinderSettingsBuilder builder; |
1096 | |
1097 | QTest::addColumn<QCameraViewfinderSettings>(name: "settings" ); |
1098 | QTest::addColumn< QList<int> >(name: "expectedSupportedSettings" ); |
1099 | |
1100 | QTest::newRow(dataTag: "all supported settings" ) << QCameraViewfinderSettings() |
1101 | << (QList<int>() << 0 << 1 << 2 << 3 << 4 << 5); |
1102 | |
1103 | QTest::newRow(dataTag: "invalid resolution" ) << builder.setResolution(width: 452472, height: 44453).build() |
1104 | << QList<int>(); |
1105 | |
1106 | QTest::newRow(dataTag: "resolution (1)" ) << builder.setResolution(width: 640, height: 480).build() |
1107 | << (QList<int>() << 0); |
1108 | |
1109 | QTest::newRow(dataTag: "resolution (2)" ) << builder.setResolution(width: 1280, height: 720).build() |
1110 | << (QList<int>() << 1 << 3 << 4); |
1111 | |
1112 | QTest::newRow(dataTag: "invalid minimum frame rate" ) << builder.setMinimumFrameRate(2).build() |
1113 | << QList<int>(); |
1114 | |
1115 | QTest::newRow(dataTag: "minimum frame rate (1)" ) << builder.setMinimumFrameRate(5).build() |
1116 | << (QList<int>() << 2); |
1117 | |
1118 | QTest::newRow(dataTag: "minimum frame rate (2)" ) << builder.setMinimumFrameRate(10).build() |
1119 | << (QList<int>() << 1 << 3); |
1120 | |
1121 | QTest::newRow(dataTag: "minimum frame rate (3)" ) << builder.setMinimumFrameRate(30).build() |
1122 | << (QList<int>() << 0 << 4 << 5); |
1123 | |
1124 | QTest::newRow(dataTag: "invalid maximum frame rate" ) << builder.setMaximumFrameRate(2).build() |
1125 | << QList<int>(); |
1126 | |
1127 | QTest::newRow(dataTag: "maximum frame rate (1)" ) << builder.setMaximumFrameRate(10).build() |
1128 | << (QList<int>() << 1 << 2 << 3); |
1129 | |
1130 | QTest::newRow(dataTag: "maximum frame rate (2)" ) << builder.setMaximumFrameRate(30).build() |
1131 | << (QList<int>() << 0 << 4 << 5); |
1132 | |
1133 | QTest::newRow(dataTag: "invalid pixel format" ) << builder.setPixelFormat(QVideoFrame::Format_CameraRaw).build() |
1134 | << QList<int>(); |
1135 | |
1136 | QTest::newRow(dataTag: "pixel format (1)" ) << builder.setPixelFormat(QVideoFrame::Format_BGR32).build() |
1137 | << (QList<int>() << 2); |
1138 | |
1139 | QTest::newRow(dataTag: "pixel format (2)" ) << builder.setPixelFormat(QVideoFrame::Format_YV12).build() |
1140 | << (QList<int>() << 3 << 4); |
1141 | |
1142 | QTest::newRow(dataTag: "pixel format (3)" ) << builder.setPixelFormat(QVideoFrame::Format_NV12).build() |
1143 | << (QList<int>() << 0 << 1 << 5); |
1144 | |
1145 | QTest::newRow(dataTag: "invalid pixel aspect ratio" ) << builder.setPixelAspectRatio(h: 5, v: 3).build() |
1146 | << QList<int>(); |
1147 | |
1148 | QTest::newRow(dataTag: "pixel aspect ratio (1)" ) << builder.setPixelAspectRatio(h: 2, v: 1).build() |
1149 | << (QList<int>() << 2); |
1150 | |
1151 | QTest::newRow(dataTag: "pixel aspect ratio (2)" ) << builder.setPixelAspectRatio(h: 1, v: 1).build() |
1152 | << (QList<int>() << 0 << 1 << 3 << 4 << 5); |
1153 | |
1154 | QTest::newRow(dataTag: "invalid multi settings" ) << builder.setResolution(width: 640, height: 480) |
1155 | .setMinimumFrameRate(10) |
1156 | .setMaximumFrameRate(10) |
1157 | .build() |
1158 | << QList<int>(); |
1159 | |
1160 | QTest::newRow(dataTag: "multi settings (1)" ) << builder.setResolution(width: 640, height: 480) |
1161 | .setMinimumFrameRate(30) |
1162 | .setMaximumFrameRate(30) |
1163 | .build() |
1164 | << (QList<int>() << 0); |
1165 | |
1166 | QTest::newRow(dataTag: "multi settings (2)" ) << builder.setResolution(width: 1280, height: 720) |
1167 | .setMinimumFrameRate(10) |
1168 | .setMaximumFrameRate(10) |
1169 | .build() |
1170 | << (QList<int>() << 1 << 3); |
1171 | |
1172 | QTest::newRow(dataTag: "multi settings (3)" ) << builder.setPixelFormat(QVideoFrame::Format_NV12) |
1173 | .setMinimumFrameRate(30) |
1174 | .build() |
1175 | << (QList<int>() << 0 << 5); |
1176 | |
1177 | QTest::newRow(dataTag: "multi settings (4)" ) << builder.setPixelAspectRatio(h: 1, v: 1) |
1178 | .setMaximumFrameRate(10) |
1179 | .build() |
1180 | << (QList<int>() << 1 << 3); |
1181 | } |
1182 | |
1183 | void tst_QCamera::testSupportedViewfinderSettings() |
1184 | { |
1185 | QFETCH(QCameraViewfinderSettings, settings); |
1186 | QFETCH(QList<int>, expectedSupportedSettings); |
1187 | |
1188 | QList<QCameraViewfinderSettings> actualSupportedSettings = QCamera().supportedViewfinderSettings(settings); |
1189 | QCOMPARE(actualSupportedSettings.size(), expectedSupportedSettings.size()); |
1190 | for (int i = 0; i < expectedSupportedSettings.size(); ++i) { |
1191 | QCameraViewfinderSettings expectedSettings = mockCameraService->mockViewfinderSettingsControl->supportedSettings.at(i: expectedSupportedSettings.at(i)); |
1192 | QCOMPARE(actualSupportedSettings.at(i), expectedSettings); |
1193 | } |
1194 | } |
1195 | |
1196 | void tst_QCamera::testSupportedViewfinderResolutions_data() |
1197 | { |
1198 | // see mockcameraviewfindersettingscontrol.h for expected values |
1199 | |
1200 | typedef QList<QSize> SizeList; |
1201 | ViewfinderSettingsBuilder builder; |
1202 | |
1203 | QTest::addColumn<QCameraViewfinderSettings>(name: "settings" ); |
1204 | QTest::addColumn<SizeList>(name: "expectedResolutions" ); |
1205 | |
1206 | QTest::newRow(dataTag: "empty settings" ) << QCameraViewfinderSettings() |
1207 | << (SizeList() << QSize(320, 240) |
1208 | << QSize(640, 480) |
1209 | << QSize(1280, 720) |
1210 | << QSize(1920, 1080)); |
1211 | |
1212 | QTest::newRow(dataTag: "invalid minimum frame rate" ) << builder.setMinimumFrameRate(2).build() |
1213 | << SizeList(); |
1214 | |
1215 | QTest::newRow(dataTag: "minimum frame rate (1)" ) << builder.setMinimumFrameRate(5).build() |
1216 | << (SizeList() << QSize(1920, 1080)); |
1217 | |
1218 | QTest::newRow(dataTag: "minimum frame rate (2)" ) << builder.setMinimumFrameRate(10).build() |
1219 | << (SizeList() << QSize(1280, 720)); |
1220 | |
1221 | QTest::newRow(dataTag: "minimum frame rate (3)" ) << builder.setMinimumFrameRate(30).build() |
1222 | << (SizeList() << QSize(320, 240) |
1223 | << QSize(640, 480) |
1224 | << QSize(1280, 720)); |
1225 | |
1226 | QTest::newRow(dataTag: "invalid maximum frame rate" ) << builder.setMaximumFrameRate(2).build() |
1227 | << SizeList(); |
1228 | |
1229 | QTest::newRow(dataTag: "maximum frame rate" ) << builder.setMaximumFrameRate(10).build() |
1230 | << (SizeList() << QSize(1280, 720) |
1231 | << QSize(1920, 1080)); |
1232 | |
1233 | QTest::newRow(dataTag: "invalid pixel format" ) << builder.setPixelFormat(QVideoFrame::Format_CameraRaw).build() |
1234 | << SizeList(); |
1235 | |
1236 | QTest::newRow(dataTag: "pixel format (1)" ) << builder.setPixelFormat(QVideoFrame::Format_BGR32).build() |
1237 | << (SizeList() << QSize(1920, 1080)); |
1238 | |
1239 | QTest::newRow(dataTag: "pixel format (2)" ) << builder.setPixelFormat(QVideoFrame::Format_YV12).build() |
1240 | << (SizeList() << QSize(1280, 720)); |
1241 | |
1242 | QTest::newRow(dataTag: "pixel format (3)" ) << builder.setPixelFormat(QVideoFrame::Format_NV12).build() |
1243 | << (SizeList() << QSize(320, 240) |
1244 | << QSize(640, 480) |
1245 | << QSize(1280, 720)); |
1246 | |
1247 | QTest::newRow(dataTag: "invalid pixel aspect ratio" ) << builder.setPixelAspectRatio(h: 7, v: 2).build() |
1248 | << SizeList(); |
1249 | |
1250 | QTest::newRow(dataTag: "pixel aspect ratio (1" ) << builder.setPixelAspectRatio(h: 2, v: 1).build() |
1251 | << (SizeList() << QSize(1920, 1080)); |
1252 | |
1253 | QTest::newRow(dataTag: "pixel aspect ratio (2" ) << builder.setPixelAspectRatio(h: 1, v: 1).build() |
1254 | << (SizeList() << QSize(320, 240) |
1255 | << QSize(640, 480) |
1256 | << QSize(1280, 720)); |
1257 | |
1258 | QTest::newRow(dataTag: "invalid multi settings (1)" ) << builder.setMinimumFrameRate(2) |
1259 | .setMaximumFrameRate(3) |
1260 | .build() |
1261 | << SizeList(); |
1262 | |
1263 | QTest::newRow(dataTag: "invalid multi settings (2)" ) << builder.setMinimumFrameRate(5) |
1264 | .setMaximumFrameRate(11) |
1265 | .build() |
1266 | << SizeList(); |
1267 | |
1268 | QTest::newRow(dataTag: "multi settings (1)" ) << builder.setMinimumFrameRate(10) |
1269 | .setMaximumFrameRate(10) |
1270 | .build() |
1271 | << (SizeList() << QSize(1280, 720)); |
1272 | |
1273 | QTest::newRow(dataTag: "multi settings (2)" ) << builder.setMinimumFrameRate(30) |
1274 | .setMaximumFrameRate(30) |
1275 | .build() |
1276 | << (SizeList() << QSize(320, 240) |
1277 | << QSize(640, 480) |
1278 | << QSize(1280, 720)); |
1279 | |
1280 | QTest::newRow(dataTag: "multi settings (3)" ) << builder.setPixelFormat(QVideoFrame::Format_NV12) |
1281 | .setMinimumFrameRate(30) |
1282 | .build() |
1283 | << (SizeList() << QSize(320, 240) |
1284 | << QSize(640, 480)); |
1285 | |
1286 | QTest::newRow(dataTag: "multi settings (4)" ) << builder.setPixelAspectRatio(h: 1, v: 1) |
1287 | .setMaximumFrameRate(10) |
1288 | .build() |
1289 | << (SizeList() << QSize(1280, 720)); |
1290 | } |
1291 | |
1292 | void tst_QCamera::testSupportedViewfinderResolutions() |
1293 | { |
1294 | QFETCH(QCameraViewfinderSettings, settings); |
1295 | QFETCH(QList<QSize>, expectedResolutions); |
1296 | |
1297 | QList<QSize> actualResolutions = QCamera().supportedViewfinderResolutions(settings); |
1298 | QCOMPARE(actualResolutions.size(), expectedResolutions.size()); |
1299 | for (int i = 0; i < actualResolutions.size(); ++i) |
1300 | QCOMPARE(actualResolutions.at(i), expectedResolutions.at(i)); |
1301 | } |
1302 | |
1303 | void tst_QCamera::testSupportedViewfinderFrameRateRanges_data() |
1304 | { |
1305 | // see mockcameraviewfindersettingscontrol.h for expected values |
1306 | |
1307 | typedef QList<QCamera::FrameRateRange> RangeList; |
1308 | ViewfinderSettingsBuilder builder; |
1309 | |
1310 | QTest::addColumn<QCameraViewfinderSettings>(name: "settings" ); |
1311 | QTest::addColumn<RangeList>(name: "expectedFrameRateRanges" ); |
1312 | |
1313 | QTest::newRow(dataTag: "empty settings" ) << QCameraViewfinderSettings() |
1314 | << (RangeList() << QCamera::FrameRateRange(5, 10) |
1315 | << QCamera::FrameRateRange(10, 10) |
1316 | << QCamera::FrameRateRange(30, 30)); |
1317 | |
1318 | QTest::newRow(dataTag: "invalid resolution" ) << builder.setResolution(width: 452472, height: 444534).build() |
1319 | << RangeList(); |
1320 | |
1321 | QTest::newRow(dataTag: "resolution (1)" ) << builder.setResolution(width: 320, height: 240).build() |
1322 | << (RangeList() << QCamera::FrameRateRange(30, 30)); |
1323 | |
1324 | QTest::newRow(dataTag: "resolution (2)" ) << builder.setResolution(width: 1280, height: 720).build() |
1325 | << (RangeList() << QCamera::FrameRateRange(10, 10) |
1326 | << QCamera::FrameRateRange(30, 30)); |
1327 | |
1328 | QTest::newRow(dataTag: "resolution (3)" ) << builder.setResolution(width: 1920, height: 1080).build() |
1329 | << (RangeList() << QCamera::FrameRateRange(5, 10)); |
1330 | |
1331 | QTest::newRow(dataTag: "invalid minimum frame rate" ) << builder.setMinimumFrameRate(2).build() |
1332 | << RangeList(); |
1333 | |
1334 | QTest::newRow(dataTag: "minimum frame rate (1)" ) << builder.setMinimumFrameRate(5).build() |
1335 | << (RangeList() << QCamera::FrameRateRange(5, 10)); |
1336 | |
1337 | QTest::newRow(dataTag: "minimum frame rate (2)" ) << builder.setMinimumFrameRate(10).build() |
1338 | << (RangeList() << QCamera::FrameRateRange(10, 10)); |
1339 | |
1340 | QTest::newRow(dataTag: "invalid maximum frame rate" ) << builder.setMaximumFrameRate(2).build() |
1341 | << RangeList(); |
1342 | |
1343 | QTest::newRow(dataTag: "maximum frame rate (1)" ) << builder.setMaximumFrameRate(10).build() |
1344 | << (RangeList() << QCamera::FrameRateRange(5, 10) |
1345 | << QCamera::FrameRateRange(10, 10)); |
1346 | |
1347 | QTest::newRow(dataTag: "maximum frame rate (2)" ) << builder.setMaximumFrameRate(30).build() |
1348 | << (RangeList() << QCamera::FrameRateRange(30, 30)); |
1349 | |
1350 | QTest::newRow(dataTag: "invalid pixel format" ) << builder.setPixelFormat(QVideoFrame::Format_IMC1).build() |
1351 | << RangeList(); |
1352 | |
1353 | QTest::newRow(dataTag: "pixel format (1)" ) << builder.setPixelFormat(QVideoFrame::Format_BGR32).build() |
1354 | << (RangeList() << QCamera::FrameRateRange(5, 10)); |
1355 | |
1356 | QTest::newRow(dataTag: "pixel format (2)" ) << builder.setPixelFormat(QVideoFrame::Format_NV12).build() |
1357 | << (RangeList() << QCamera::FrameRateRange(10, 10) |
1358 | << QCamera::FrameRateRange(30, 30)); |
1359 | |
1360 | QTest::newRow(dataTag: "invalid pixel aspect ratio" ) << builder.setPixelAspectRatio(h: 2, v: 3).build() |
1361 | << RangeList(); |
1362 | |
1363 | QTest::newRow(dataTag: "pixel aspect ratio (1)" ) << builder.setPixelAspectRatio(h: 2, v: 1).build() |
1364 | << (RangeList() << QCamera::FrameRateRange(5, 10)); |
1365 | |
1366 | QTest::newRow(dataTag: "pixel aspect ratio (2)" ) << builder.setPixelAspectRatio(h: 1, v: 1).build() |
1367 | << (RangeList() << QCamera::FrameRateRange(10, 10) |
1368 | << QCamera::FrameRateRange(30, 30)); |
1369 | } |
1370 | |
1371 | void tst_QCamera::testSupportedViewfinderFrameRateRanges() |
1372 | { |
1373 | QFETCH(QCameraViewfinderSettings, settings); |
1374 | QFETCH(QList<QCamera::FrameRateRange>, expectedFrameRateRanges); |
1375 | |
1376 | QList<QCamera::FrameRateRange> actualFrameRateRanges = QCamera().supportedViewfinderFrameRateRanges(settings); |
1377 | QCOMPARE(actualFrameRateRanges.size(), expectedFrameRateRanges.size()); |
1378 | for (int i = 0; i < actualFrameRateRanges.size(); ++i) |
1379 | QCOMPARE(actualFrameRateRanges.at(i), expectedFrameRateRanges.at(i)); |
1380 | } |
1381 | |
1382 | void tst_QCamera::testSupportedViewfinderPixelFormats_data() |
1383 | { |
1384 | // see mockcameraviewfindersettingscontrol.h for expected values |
1385 | |
1386 | typedef QList<QVideoFrame::PixelFormat> FormatList; |
1387 | ViewfinderSettingsBuilder builder; |
1388 | |
1389 | QTest::addColumn<QCameraViewfinderSettings>(name: "settings" ); |
1390 | QTest::addColumn<FormatList>(name: "expectedPixelFormats" ); |
1391 | |
1392 | QTest::newRow(dataTag: "empty settings" ) << QCameraViewfinderSettings() |
1393 | << (FormatList() << QVideoFrame::Format_NV12 |
1394 | << QVideoFrame::Format_BGR32 |
1395 | << QVideoFrame::Format_YV12); |
1396 | |
1397 | QTest::newRow(dataTag: "invalid resolution" ) << builder.setResolution(width: 452472, height: 444534).build() |
1398 | << FormatList(); |
1399 | |
1400 | QTest::newRow(dataTag: "resolution (1)" ) << builder.setResolution(width: 640, height: 480).build() |
1401 | << (FormatList() << QVideoFrame::Format_NV12); |
1402 | |
1403 | QTest::newRow(dataTag: "resolution (2)" ) << builder.setResolution(width: 1280, height: 720).build() |
1404 | << (FormatList() << QVideoFrame::Format_NV12 |
1405 | << QVideoFrame::Format_YV12); |
1406 | |
1407 | QTest::newRow(dataTag: "invalid minimum frame rate" ) << builder.setMinimumFrameRate(2).build() |
1408 | << FormatList(); |
1409 | |
1410 | QTest::newRow(dataTag: "minimum frame rate (1)" ) << builder.setMinimumFrameRate(5).build() |
1411 | << (FormatList() << QVideoFrame::Format_BGR32); |
1412 | |
1413 | QTest::newRow(dataTag: "minimum frame rate (2)" ) << builder.setMinimumFrameRate(10).build() |
1414 | << (FormatList() << QVideoFrame::Format_NV12 |
1415 | << QVideoFrame::Format_YV12); |
1416 | |
1417 | QTest::newRow(dataTag: "invalid maximum frame rate" ) << builder.setMaximumFrameRate(2).build() |
1418 | << FormatList(); |
1419 | |
1420 | QTest::newRow(dataTag: "maximum frame rate (1)" ) << builder.setMaximumFrameRate(10).build() |
1421 | << (FormatList() << QVideoFrame::Format_NV12 |
1422 | << QVideoFrame::Format_BGR32 |
1423 | << QVideoFrame::Format_YV12); |
1424 | |
1425 | QTest::newRow(dataTag: "maximum frame rate (2)" ) << builder.setMinimumFrameRate(30).build() |
1426 | << (FormatList() << QVideoFrame::Format_NV12 |
1427 | << QVideoFrame::Format_YV12); |
1428 | |
1429 | QTest::newRow(dataTag: "invalid pixel aspect ratio" ) << builder.setPixelAspectRatio(h: 2, v: 3).build() |
1430 | << FormatList(); |
1431 | |
1432 | QTest::newRow(dataTag: "pixel aspect ratio (1)" ) << builder.setPixelAspectRatio(h: 2, v: 1).build() |
1433 | << (FormatList() << QVideoFrame::Format_BGR32); |
1434 | |
1435 | QTest::newRow(dataTag: "pixel aspect ratio (2)" ) << builder.setPixelAspectRatio(h: 1, v: 1).build() |
1436 | << (FormatList() << QVideoFrame::Format_NV12 |
1437 | << QVideoFrame::Format_YV12); |
1438 | } |
1439 | |
1440 | void tst_QCamera::testSupportedViewfinderPixelFormats() |
1441 | { |
1442 | QFETCH(QCameraViewfinderSettings, settings); |
1443 | QFETCH(QList<QVideoFrame::PixelFormat>, expectedPixelFormats); |
1444 | |
1445 | QList<QVideoFrame::PixelFormat> actualPixelFormats = QCamera().supportedViewfinderPixelFormats(settings); |
1446 | QCOMPARE(actualPixelFormats.size(), expectedPixelFormats.size()); |
1447 | for (int i = 0; i < actualPixelFormats.size(); ++i) |
1448 | QCOMPARE(actualPixelFormats.at(i), expectedPixelFormats.at(i)); |
1449 | } |
1450 | |
1451 | void tst_QCamera::testCameraLock() |
1452 | { |
1453 | QCamera camera; |
1454 | |
1455 | camera.focus()->setFocusMode(QCameraFocus::AutoFocus); |
1456 | |
1457 | QCOMPARE(camera.lockStatus(), QCamera::Unlocked); |
1458 | |
1459 | QSignalSpy lockedSignal(&camera, SIGNAL(locked())); |
1460 | QSignalSpy lockFailedSignal(&camera, SIGNAL(lockFailed())); |
1461 | QSignalSpy lockStatusChangedSignal(&camera, SIGNAL(lockStatusChanged(QCamera::LockStatus,QCamera::LockChangeReason))); |
1462 | |
1463 | camera.searchAndLock(); |
1464 | QCOMPARE(camera.lockStatus(), QCamera::Searching); |
1465 | QCOMPARE(lockedSignal.count(), 0); |
1466 | QCOMPARE(lockFailedSignal.count(), 0); |
1467 | QCOMPARE(lockStatusChangedSignal.count(), 1); |
1468 | |
1469 | lockedSignal.clear(); |
1470 | lockFailedSignal.clear(); |
1471 | lockStatusChangedSignal.clear(); |
1472 | |
1473 | QTRY_COMPARE(camera.lockStatus(), QCamera::Locked); |
1474 | QCOMPARE(lockedSignal.count(), 1); |
1475 | QCOMPARE(lockFailedSignal.count(), 0); |
1476 | QCOMPARE(lockStatusChangedSignal.count(), 1); |
1477 | |
1478 | lockedSignal.clear(); |
1479 | lockFailedSignal.clear(); |
1480 | lockStatusChangedSignal.clear(); |
1481 | |
1482 | camera.searchAndLock(); |
1483 | QCOMPARE(camera.lockStatus(), QCamera::Searching); |
1484 | QCOMPARE(lockedSignal.count(), 0); |
1485 | QCOMPARE(lockFailedSignal.count(), 0); |
1486 | QCOMPARE(lockStatusChangedSignal.count(), 1); |
1487 | |
1488 | lockedSignal.clear(); |
1489 | lockFailedSignal.clear(); |
1490 | lockStatusChangedSignal.clear(); |
1491 | |
1492 | camera.unlock(); |
1493 | QCOMPARE(camera.lockStatus(), QCamera::Unlocked); |
1494 | QCOMPARE(lockedSignal.count(), 0); |
1495 | QCOMPARE(lockFailedSignal.count(), 0); |
1496 | QCOMPARE(lockStatusChangedSignal.count(), 1); |
1497 | } |
1498 | |
1499 | void tst_QCamera::testCameraLockCancel() |
1500 | { |
1501 | MockCameraService service; |
1502 | provider->service = &service; |
1503 | QCamera camera; |
1504 | |
1505 | camera.focus()->setFocusMode(QCameraFocus::AutoFocus); |
1506 | |
1507 | QCOMPARE(camera.lockStatus(), QCamera::Unlocked); |
1508 | |
1509 | QSignalSpy lockedSignal(&camera, SIGNAL(locked())); |
1510 | QSignalSpy lockFailedSignal(&camera, SIGNAL(lockFailed())); |
1511 | QSignalSpy lockStatusChangedSignal(&camera, SIGNAL(lockStatusChanged(QCamera::LockStatus,QCamera::LockChangeReason))); |
1512 | camera.searchAndLock(); |
1513 | QCOMPARE(camera.lockStatus(), QCamera::Searching); |
1514 | QCOMPARE(lockedSignal.count(), 0); |
1515 | QCOMPARE(lockFailedSignal.count(), 0); |
1516 | QCOMPARE(lockStatusChangedSignal.count(), 1); |
1517 | |
1518 | lockedSignal.clear(); |
1519 | lockFailedSignal.clear(); |
1520 | lockStatusChangedSignal.clear(); |
1521 | |
1522 | camera.unlock(); |
1523 | QCOMPARE(camera.lockStatus(), QCamera::Unlocked); |
1524 | QCOMPARE(lockedSignal.count(), 0); |
1525 | QCOMPARE(lockFailedSignal.count(), 0); |
1526 | QCOMPARE(lockStatusChangedSignal.count(), 1); |
1527 | } |
1528 | |
1529 | void tst_QCamera::testCameraEncodingProperyChange() |
1530 | { |
1531 | QCamera camera; |
1532 | QCameraImageCapture imageCapture(&camera); |
1533 | |
1534 | QSignalSpy stateChangedSignal(&camera, SIGNAL(stateChanged(QCamera::State))); |
1535 | QSignalSpy statusChangedSignal(&camera, SIGNAL(statusChanged(QCamera::Status))); |
1536 | |
1537 | camera.start(); |
1538 | QCOMPARE(camera.state(), QCamera::ActiveState); |
1539 | QCOMPARE(camera.status(), QCamera::ActiveStatus); |
1540 | |
1541 | QCOMPARE(stateChangedSignal.count(), 1); |
1542 | QCOMPARE(statusChangedSignal.count(), 1); |
1543 | stateChangedSignal.clear(); |
1544 | statusChangedSignal.clear(); |
1545 | |
1546 | |
1547 | camera.setCaptureMode(QCamera::CaptureVideo); |
1548 | QCOMPARE(camera.state(), QCamera::ActiveState); |
1549 | QCOMPARE(camera.status(), QCamera::LoadedStatus); |
1550 | |
1551 | QCOMPARE(stateChangedSignal.count(), 0); |
1552 | QCOMPARE(statusChangedSignal.count(), 1); |
1553 | stateChangedSignal.clear(); |
1554 | statusChangedSignal.clear(); |
1555 | |
1556 | QCOMPARE(camera.state(), QCamera::ActiveState); |
1557 | QTRY_COMPARE(camera.status(), QCamera::ActiveStatus); |
1558 | |
1559 | QCOMPARE(stateChangedSignal.count(), 0); |
1560 | QCOMPARE(statusChangedSignal.count(), 1); |
1561 | stateChangedSignal.clear(); |
1562 | statusChangedSignal.clear(); |
1563 | |
1564 | //backens should not be stopped since the capture mode is Video |
1565 | imageCapture.setEncodingSettings(QImageEncoderSettings()); |
1566 | QCOMPARE(stateChangedSignal.count(), 0); |
1567 | QCOMPARE(statusChangedSignal.count(), 0); |
1568 | |
1569 | camera.setCaptureMode(QCamera::CaptureStillImage); |
1570 | |
1571 | QCOMPARE(camera.state(), QCamera::ActiveState); |
1572 | QTRY_COMPARE(camera.status(), QCamera::ActiveStatus); |
1573 | |
1574 | stateChangedSignal.clear(); |
1575 | statusChangedSignal.clear(); |
1576 | |
1577 | //the settings change should trigger camera stop/start |
1578 | imageCapture.setEncodingSettings(QImageEncoderSettings()); |
1579 | QCOMPARE(camera.state(), QCamera::ActiveState); |
1580 | QCOMPARE(camera.status(), QCamera::LoadedStatus); |
1581 | |
1582 | QCOMPARE(stateChangedSignal.count(), 0); |
1583 | QCOMPARE(statusChangedSignal.count(), 1); |
1584 | stateChangedSignal.clear(); |
1585 | statusChangedSignal.clear(); |
1586 | |
1587 | QCOMPARE(camera.state(), QCamera::ActiveState); |
1588 | QTRY_COMPARE(camera.status(), QCamera::ActiveStatus); |
1589 | |
1590 | QCOMPARE(stateChangedSignal.count(), 0); |
1591 | QCOMPARE(statusChangedSignal.count(), 1); |
1592 | stateChangedSignal.clear(); |
1593 | statusChangedSignal.clear(); |
1594 | |
1595 | //the settings change should trigger camera stop/start only once |
1596 | camera.setCaptureMode(QCamera::CaptureVideo); |
1597 | camera.setCaptureMode(QCamera::CaptureStillImage); |
1598 | imageCapture.setEncodingSettings(QImageEncoderSettings()); |
1599 | imageCapture.setEncodingSettings(QImageEncoderSettings()); |
1600 | |
1601 | QCOMPARE(camera.state(), QCamera::ActiveState); |
1602 | QCOMPARE(camera.status(), QCamera::LoadedStatus); |
1603 | |
1604 | QCOMPARE(stateChangedSignal.count(), 0); |
1605 | QCOMPARE(statusChangedSignal.count(), 1); |
1606 | stateChangedSignal.clear(); |
1607 | statusChangedSignal.clear(); |
1608 | |
1609 | QCOMPARE(camera.state(), QCamera::ActiveState); |
1610 | QTRY_COMPARE(camera.status(), QCamera::ActiveStatus); |
1611 | |
1612 | QCOMPARE(stateChangedSignal.count(), 0); |
1613 | QCOMPARE(statusChangedSignal.count(), 1); |
1614 | } |
1615 | |
1616 | void tst_QCamera::testSetVideoOutput() |
1617 | { |
1618 | MockVideoSurface surface; |
1619 | QCamera camera; |
1620 | |
1621 | camera.setViewfinder(reinterpret_cast<QVideoWidget *>(0)); |
1622 | |
1623 | camera.setViewfinder(reinterpret_cast<QGraphicsVideoItem *>(0)); |
1624 | |
1625 | QCOMPARE(mockCameraService->rendererRef, 0); |
1626 | |
1627 | camera.setViewfinder(&surface); |
1628 | QVERIFY(mockCameraService->rendererControl->surface() == &surface); |
1629 | QCOMPARE(mockCameraService->rendererRef, 1); |
1630 | |
1631 | camera.setViewfinder(reinterpret_cast<QAbstractVideoSurface *>(0)); |
1632 | QVERIFY(mockCameraService->rendererControl->surface() == 0); |
1633 | |
1634 | //rendererControl is released |
1635 | QCOMPARE(mockCameraService->rendererRef, 0); |
1636 | |
1637 | camera.setViewfinder(&surface); |
1638 | QVERIFY(mockCameraService->rendererControl->surface() == &surface); |
1639 | QCOMPARE(mockCameraService->rendererRef, 1); |
1640 | |
1641 | camera.setViewfinder(reinterpret_cast<QVideoWidget *>(0)); |
1642 | QVERIFY(mockCameraService->rendererControl->surface() == 0); |
1643 | //rendererControl is released |
1644 | QCOMPARE(mockCameraService->rendererRef, 0); |
1645 | |
1646 | camera.setViewfinder(&surface); |
1647 | QVERIFY(mockCameraService->rendererControl->surface() == &surface); |
1648 | QCOMPARE(mockCameraService->rendererRef, 1); |
1649 | } |
1650 | |
1651 | |
1652 | void tst_QCamera::testSetVideoOutputNoService() |
1653 | { |
1654 | MockVideoSurface surface; |
1655 | |
1656 | provider->service = 0; |
1657 | QCamera camera; |
1658 | |
1659 | camera.setViewfinder(&surface); |
1660 | // Nothing we can verify here other than it doesn't assert. |
1661 | } |
1662 | |
1663 | void tst_QCamera::testSetVideoOutputNoControl() |
1664 | { |
1665 | MockVideoSurface surface; |
1666 | |
1667 | MockCameraService service; |
1668 | service.rendererRef = 1; |
1669 | provider->service = &service; |
1670 | |
1671 | QCamera camera; |
1672 | |
1673 | camera.setViewfinder(&surface); |
1674 | QVERIFY(service.rendererControl->surface() == 0); |
1675 | } |
1676 | |
1677 | void tst_QCamera::testSetVideoOutputDestruction() |
1678 | { |
1679 | MockVideoSurface surface; |
1680 | MockCameraService service; |
1681 | provider->service = &service; |
1682 | |
1683 | { |
1684 | QCamera camera; |
1685 | camera.setViewfinder(&surface); |
1686 | QVERIFY(service.rendererControl->surface() == &surface); |
1687 | QCOMPARE(service.rendererRef, 1); |
1688 | } |
1689 | QVERIFY(service.rendererControl->surface() == 0); |
1690 | QCOMPARE(service.rendererRef, 0); |
1691 | } |
1692 | |
1693 | void tst_QCamera::testEnumDebug() |
1694 | { |
1695 | QTest::ignoreMessage(type: QtDebugMsg, message: "QCamera::ActiveState" ); |
1696 | qDebug() << QCamera::ActiveState; |
1697 | QTest::ignoreMessage(type: QtDebugMsg, message: "QCamera::ActiveStatus" ); |
1698 | qDebug() << QCamera::ActiveStatus; |
1699 | QTest::ignoreMessage(type: QtDebugMsg, message: "QCamera::CaptureVideo" ); |
1700 | qDebug() << QCamera::CaptureVideo; |
1701 | QTest::ignoreMessage(type: QtDebugMsg, message: "QCamera::CameraError" ); |
1702 | qDebug() << QCamera::CameraError; |
1703 | QTest::ignoreMessage(type: QtDebugMsg, message: "QCamera::Unlocked" ); |
1704 | qDebug() << QCamera::Unlocked; |
1705 | QTest::ignoreMessage(type: QtDebugMsg, message: "QCamera::LockAcquired" ); |
1706 | qDebug() << QCamera::LockAcquired; |
1707 | QTest::ignoreMessage(type: QtDebugMsg, message: "QCamera::NoLock" ); |
1708 | qDebug() << QCamera::NoLock; |
1709 | QTest::ignoreMessage(type: QtDebugMsg, message: "QCamera::LockExposure" ); |
1710 | qDebug() << QCamera::LockExposure; |
1711 | QTest::ignoreMessage(type: QtDebugMsg, message: "QCamera::FrontFace " ); |
1712 | qDebug() << QCamera::FrontFace; |
1713 | } |
1714 | |
1715 | void tst_QCamera::testCameraControl() |
1716 | { |
1717 | MockCameraControl *m_cameraControl=new MockCameraControl(this); |
1718 | QVERIFY(m_cameraControl != NULL); |
1719 | } |
1720 | |
1721 | void tst_QCamera::testConstructor() |
1722 | { |
1723 | // Service doesn't implement QVideoDeviceSelectorControl |
1724 | provider->service = mockSimpleCameraService; |
1725 | |
1726 | { |
1727 | QCamera camera; |
1728 | QCOMPARE(camera.availability(), QMultimedia::Available); |
1729 | QCOMPARE(camera.error(), QCamera::NoError); |
1730 | } |
1731 | |
1732 | { |
1733 | // Requesting a camera at a specific position from a service which doesn't implement |
1734 | // the QVideoDeviceSelectorControl should result in loading the default camera |
1735 | QCamera camera(QCamera::FrontFace); |
1736 | QCOMPARE(camera.availability(), QMultimedia::Available); |
1737 | QCOMPARE(camera.error(), QCamera::NoError); |
1738 | } |
1739 | |
1740 | // Service implements QVideoDeviceSelectorControl |
1741 | provider->service = mockCameraService; |
1742 | |
1743 | { |
1744 | QCamera camera; |
1745 | QCOMPARE(camera.availability(), QMultimedia::Available); |
1746 | QCOMPARE(camera.error(), QCamera::NoError); |
1747 | QCOMPARE(mockCameraService->mockVideoDeviceSelectorControl->selectedDevice(), 1); // default is 1 |
1748 | } |
1749 | |
1750 | { |
1751 | QCamera camera(QCameraInfo::defaultCamera()); |
1752 | QCOMPARE(camera.availability(), QMultimedia::Available); |
1753 | QCOMPARE(camera.error(), QCamera::NoError); |
1754 | QCOMPARE(mockCameraService->mockVideoDeviceSelectorControl->selectedDevice(), 1); |
1755 | QCOMPARE(QCameraInfo(camera), QCameraInfo::defaultCamera()); |
1756 | } |
1757 | |
1758 | { |
1759 | QCameraInfo cameraInfo = QCameraInfo::availableCameras().at(i: 0); |
1760 | QCamera camera(cameraInfo); |
1761 | QCOMPARE(camera.availability(), QMultimedia::Available); |
1762 | QCOMPARE(camera.error(), QCamera::NoError); |
1763 | QCOMPARE(mockCameraService->mockVideoDeviceSelectorControl->selectedDevice(), 0); |
1764 | QCOMPARE(QCameraInfo(camera), cameraInfo); |
1765 | } |
1766 | |
1767 | { |
1768 | // Requesting a camera at a position which is not available should result in |
1769 | // loading the default camera |
1770 | QCamera camera(QCamera::FrontFace); |
1771 | QCOMPARE(camera.availability(), QMultimedia::Available); |
1772 | QCOMPARE(camera.error(), QCamera::NoError); |
1773 | QCOMPARE(mockCameraService->mockVideoDeviceSelectorControl->selectedDevice(), 1); |
1774 | } |
1775 | |
1776 | { |
1777 | QCamera camera(QCamera::BackFace); |
1778 | QCOMPARE(camera.availability(), QMultimedia::Available); |
1779 | QCOMPARE(camera.error(), QCamera::NoError); |
1780 | QCOMPARE(mockCameraService->mockVideoDeviceSelectorControl->selectedDevice(), 0); |
1781 | } |
1782 | |
1783 | { |
1784 | // Should load the default camera when UnspecifiedPosition is requested |
1785 | QCamera camera(QCamera::UnspecifiedPosition); |
1786 | QCOMPARE(camera.availability(), QMultimedia::Available); |
1787 | QCOMPARE(camera.error(), QCamera::NoError); |
1788 | QCOMPARE(mockCameraService->mockVideoDeviceSelectorControl->selectedDevice(), 1); |
1789 | } |
1790 | } |
1791 | |
1792 | /* captureModeChanged Signal test case. */ |
1793 | void tst_QCamera::testCaptureModeChanged_signal() |
1794 | { |
1795 | MockCameraControl *m_cameraControl= new MockCameraControl(this); |
1796 | QSignalSpy spy(m_cameraControl, SIGNAL(captureModeChanged(QCamera::CaptureModes))); |
1797 | QVERIFY(spy.size() == 0); |
1798 | |
1799 | m_cameraControl->setCaptureMode(QCamera::CaptureVideo); |
1800 | QVERIFY(spy.size() == 1); |
1801 | |
1802 | m_cameraControl->setCaptureMode(QCamera::CaptureStillImage); |
1803 | QVERIFY(spy.size() == 2); |
1804 | } |
1805 | |
1806 | /* Test case for captureMode */ |
1807 | void tst_QCamera::testCaptureMode() |
1808 | { |
1809 | QCamera camera; |
1810 | QVERIFY(camera.captureMode() == QCamera::CaptureStillImage); |
1811 | |
1812 | camera.setCaptureMode(QCamera::CaptureVideo); |
1813 | QVERIFY(camera.captureMode() == QCamera::CaptureVideo); |
1814 | } |
1815 | |
1816 | /* Test case for isCaptureModeSupported */ |
1817 | void tst_QCamera::testIsCaptureModeSupported() |
1818 | { |
1819 | QCamera camera; |
1820 | QVERIFY(camera.isCaptureModeSupported(QCamera::CaptureStillImage) == true); |
1821 | QVERIFY(camera.isCaptureModeSupported(QCamera::CaptureVideo) == true); |
1822 | } |
1823 | |
1824 | /* Test case for requestedLocks. LockType is stored in OR combination so all |
1825 | types of combinations are verified here.*/ |
1826 | void tst_QCamera::testRequestedLocks() |
1827 | { |
1828 | QCamera camera; |
1829 | |
1830 | QCOMPARE(camera.requestedLocks(),QCamera::NoLock); |
1831 | |
1832 | camera.searchAndLock(locks: QCamera::LockExposure); |
1833 | QCOMPARE(camera.requestedLocks(),QCamera::LockExposure); |
1834 | |
1835 | camera.unlock(); |
1836 | camera.searchAndLock(locks: QCamera::LockFocus); |
1837 | QCOMPARE(camera.requestedLocks(),QCamera::LockFocus ); |
1838 | |
1839 | camera.unlock(); |
1840 | camera.searchAndLock(locks: QCamera::LockWhiteBalance); |
1841 | QCOMPARE(camera.requestedLocks(),QCamera::NoLock); |
1842 | |
1843 | camera.unlock(); |
1844 | camera.searchAndLock(locks: QCamera::LockExposure |QCamera::LockFocus ); |
1845 | QCOMPARE(camera.requestedLocks(),QCamera::LockExposure |QCamera::LockFocus ); |
1846 | camera.searchAndLock(locks: QCamera::LockWhiteBalance); |
1847 | QCOMPARE(camera.requestedLocks(),QCamera::LockExposure |QCamera::LockFocus); |
1848 | camera.unlock(locks: QCamera::LockExposure); |
1849 | QCOMPARE(camera.requestedLocks(),QCamera::LockFocus); |
1850 | camera.unlock(locks: QCamera::LockFocus); |
1851 | camera.searchAndLock(locks: QCamera::LockExposure |QCamera::LockWhiteBalance ); |
1852 | QCOMPARE(camera.requestedLocks(),QCamera::LockExposure); |
1853 | } |
1854 | |
1855 | /* Test case for supportedLocks() */ |
1856 | void tst_QCamera::testSupportedLocks() |
1857 | { |
1858 | QCamera camera; |
1859 | |
1860 | QCOMPARE(camera.supportedLocks(),QCamera::LockExposure | QCamera::LockFocus); |
1861 | } |
1862 | |
1863 | /* Test case for isAvailable */ |
1864 | void tst_QCamera::testQCameraIsAvailable() |
1865 | { |
1866 | QCamera camera; |
1867 | QVERIFY(camera.isAvailable()); |
1868 | QVERIFY(camera.availability() == QMultimedia::Available); |
1869 | } |
1870 | |
1871 | void tst_QCamera::testQCameraIsNotAvailable() |
1872 | { |
1873 | provider->service = 0; |
1874 | QCamera camera("random" ); |
1875 | |
1876 | QCOMPARE(camera.error(), QCamera::ServiceMissingError); |
1877 | QVERIFY(!camera.isAvailable()); |
1878 | QCOMPARE(camera.availability(), QMultimedia::ServiceMissing); |
1879 | } |
1880 | |
1881 | /* Test case for searchAndLock ( QCamera::LockTypes locks ) */ |
1882 | void tst_QCamera::testSearchAndLockWithLockTypes() |
1883 | { |
1884 | QCamera camera; |
1885 | |
1886 | QCOMPARE(camera.lockStatus(), QCamera::Unlocked); |
1887 | |
1888 | /* Spy the signals */ |
1889 | QSignalSpy lockedSignal(&camera, SIGNAL(locked())); |
1890 | QSignalSpy lockFailedSignal(&camera, SIGNAL(lockFailed())); |
1891 | QSignalSpy lockStatusChangedSignal(&camera, SIGNAL(lockStatusChanged(QCamera::LockStatus,QCamera::LockChangeReason))); |
1892 | QSignalSpy lockStatusChangedSignalWithType(&camera, SIGNAL(lockStatusChanged(QCamera::LockType,QCamera::LockStatus,QCamera::LockChangeReason))); |
1893 | |
1894 | /* search and lock the camera with QCamera::LockExposure and verify if the signal is emitted correctly */ |
1895 | camera.searchAndLock(locks: QCamera::LockExposure); |
1896 | QCOMPARE(camera.lockStatus(), QCamera::Locked); |
1897 | QCOMPARE(lockedSignal.count(), 1); |
1898 | QCOMPARE(lockFailedSignal.count(), 0); |
1899 | QCOMPARE(lockStatusChangedSignal.count(), 1); |
1900 | QCOMPARE(lockStatusChangedSignalWithType.count(), 1); |
1901 | } |
1902 | |
1903 | /* Test case for setCaptureMode() */ |
1904 | void tst_QCamera::testSetCaptureMode() |
1905 | { |
1906 | QCamera camera; |
1907 | |
1908 | /* Set the capture mode and verify if it set correctly */ |
1909 | camera.setCaptureMode(QCamera::CaptureVideo); |
1910 | QVERIFY(camera.captureMode() == QCamera::CaptureVideo); |
1911 | |
1912 | camera.setCaptureMode(QCamera::CaptureStillImage); |
1913 | QVERIFY(camera.captureMode() == QCamera::CaptureStillImage); |
1914 | } |
1915 | |
1916 | /* Test case for unlock (QCamera::LockTypes) */ |
1917 | void tst_QCamera::testUnlockWithType() |
1918 | { |
1919 | QCamera camera; |
1920 | |
1921 | QCOMPARE(camera.lockStatus(), QCamera::Unlocked); |
1922 | |
1923 | /* Spy the signal */ |
1924 | QSignalSpy lockedSignal(&camera, SIGNAL(locked())); |
1925 | QSignalSpy lockFailedSignal(&camera, SIGNAL(lockFailed())); |
1926 | QSignalSpy lockStatusChangedSignal(&camera, SIGNAL(lockStatusChanged(QCamera::LockStatus,QCamera::LockChangeReason))); |
1927 | QSignalSpy lockStatusChangedSignalWithType(&camera, SIGNAL(lockStatusChanged(QCamera::LockType,QCamera::LockStatus,QCamera::LockChangeReason))); |
1928 | |
1929 | /* lock the camera with QCamera::LockExposure and Verify if the signal is emitted correctly */ |
1930 | camera.searchAndLock(locks: QCamera::LockExposure); |
1931 | QCOMPARE(camera.lockStatus(), QCamera::Locked); |
1932 | QCOMPARE(lockedSignal.count(), 1); |
1933 | QCOMPARE(lockFailedSignal.count(), 0); |
1934 | QCOMPARE(lockStatusChangedSignal.count(), 1); |
1935 | QCOMPARE(lockStatusChangedSignalWithType.count(), 1); |
1936 | |
1937 | /* Clear the signal */ |
1938 | lockedSignal.clear(); |
1939 | lockFailedSignal.clear(); |
1940 | lockStatusChangedSignal.clear(); |
1941 | lockStatusChangedSignalWithType.clear(); |
1942 | |
1943 | /* Unlock the camera and verify if the signal is emitted correctly */ |
1944 | camera.unlock(locks: QCamera::LockExposure); |
1945 | QCOMPARE(camera.lockStatus(), QCamera::Unlocked); |
1946 | QCOMPARE(lockedSignal.count(), 0); |
1947 | QCOMPARE(lockFailedSignal.count(), 0); |
1948 | QCOMPARE(lockStatusChangedSignal.count(), 1); |
1949 | QCOMPARE(lockStatusChangedSignalWithType.count(), 1); |
1950 | QCamera::LockType lockType = qvariant_cast<QCamera::LockType >(v: lockStatusChangedSignalWithType.at(i: 0).at(i: 0)); |
1951 | QCamera::LockStatus lockStatus = qvariant_cast<QCamera::LockStatus >(v: lockStatusChangedSignalWithType.at(i: 0).at(i: 1)); |
1952 | QVERIFY(lockType == QCamera::LockExposure); |
1953 | QVERIFY(lockStatus == QCamera::Unlocked); |
1954 | |
1955 | lockedSignal.clear(); |
1956 | lockFailedSignal.clear(); |
1957 | lockStatusChangedSignal.clear(); |
1958 | lockStatusChangedSignalWithType.clear(); |
1959 | |
1960 | /* Lock the camera with QCamera::LockFocus */ |
1961 | camera.searchAndLock(locks: QCamera::LockFocus); |
1962 | lockedSignal.clear(); |
1963 | lockFailedSignal.clear(); |
1964 | lockStatusChangedSignal.clear(); |
1965 | lockStatusChangedSignalWithType.clear(); |
1966 | |
1967 | /* Unlock the camera and Verify if the signal is emitted correctly */ |
1968 | camera.unlock(locks: QCamera::LockFocus); |
1969 | QCOMPARE(camera.lockStatus(), QCamera::Unlocked); |
1970 | QCOMPARE(lockedSignal.count(), 0); |
1971 | QCOMPARE(lockFailedSignal.count(), 0); |
1972 | QCOMPARE(lockStatusChangedSignal.count(), 1); |
1973 | QCOMPARE(lockStatusChangedSignalWithType.count(), 1); |
1974 | lockType = qvariant_cast<QCamera::LockType >(v: lockStatusChangedSignalWithType.at(i: 0).at(i: 0)); |
1975 | lockStatus = qvariant_cast<QCamera::LockStatus >(v: lockStatusChangedSignalWithType.at(i: 0).at(i: 1)); |
1976 | QVERIFY(lockType == QCamera::LockFocus); |
1977 | QVERIFY(lockStatus == QCamera::Unlocked); |
1978 | } |
1979 | |
1980 | /* Test case for signal captureModeChanged(QCamera::CaptureModes) */ |
1981 | void tst_QCamera::testCaptureModeChangedSignal() |
1982 | { |
1983 | QCamera camera; |
1984 | QVERIFY(camera.captureMode() == QCamera::CaptureStillImage); |
1985 | |
1986 | qRegisterMetaType<QCamera::CaptureModes>(typeName: "QCamera::CaptureModes" ); |
1987 | |
1988 | /* Spy the signal */ |
1989 | QSignalSpy lockCaptureModeChangedSignal(&camera, SIGNAL(captureModeChanged(QCamera::CaptureModes))); |
1990 | |
1991 | /* set the capture mode and Verify if the signal is emitted */ |
1992 | camera.setCaptureMode(QCamera::CaptureVideo); |
1993 | QVERIFY(camera.captureMode() == QCamera::CaptureVideo); |
1994 | QCOMPARE(lockCaptureModeChangedSignal.count(), 1); |
1995 | QCamera::CaptureModes lockCaptureMode = qvariant_cast<QCamera::CaptureModes >(v: lockCaptureModeChangedSignal.at(i: 0).at(i: 0)); |
1996 | QVERIFY(lockCaptureMode == QCamera::CaptureVideo); |
1997 | } |
1998 | |
1999 | /* Test case for signal lockStatusChanged(QCamera::LockType,QCamera::LockStatus, QCamera::LockChangeReason) */ |
2000 | void tst_QCamera::testLockStatusChangedWithTypesSignal() |
2001 | { |
2002 | QCamera camera; |
2003 | |
2004 | QCOMPARE(camera.lockStatus(), QCamera::Unlocked); |
2005 | |
2006 | /* Spy the signal lockStatusChanged(QCamera::LockType,QCamera::LockStatus, QCamera::LockChangeReason) */ |
2007 | QSignalSpy lockStatusChangedSignalWithType(&camera, SIGNAL(lockStatusChanged(QCamera::LockType,QCamera::LockStatus,QCamera::LockChangeReason))); |
2008 | |
2009 | /* Lock the camera with type QCamera::LockExposure */ |
2010 | camera.searchAndLock(locks: QCamera::LockExposure); |
2011 | |
2012 | /* Verify if the signal is emitted and lock status is set correclty */ |
2013 | QCOMPARE(camera.lockStatus(), QCamera::Locked); |
2014 | QCOMPARE(lockStatusChangedSignalWithType.count(), 1); |
2015 | QCamera::LockType lockType = qvariant_cast<QCamera::LockType >(v: lockStatusChangedSignalWithType.at(i: 0).at(i: 0)); |
2016 | QCamera::LockStatus lockStatus = qvariant_cast<QCamera::LockStatus >(v: lockStatusChangedSignalWithType.at(i: 0).at(i: 1)); |
2017 | QVERIFY(lockType == QCamera::LockExposure); |
2018 | QVERIFY(lockStatus == QCamera::Locked); |
2019 | |
2020 | lockStatusChangedSignalWithType.clear(); |
2021 | |
2022 | /* Unlock the camera */ |
2023 | camera.unlock(); |
2024 | |
2025 | /* Verify if the signal is emitted and lock status is set correclty */ |
2026 | QCOMPARE(camera.lockStatus(), QCamera::Unlocked); |
2027 | QCOMPARE(lockStatusChangedSignalWithType.count(), 1); |
2028 | lockType = qvariant_cast<QCamera::LockType >(v: lockStatusChangedSignalWithType.at(i: 0).at(i: 0)); |
2029 | lockStatus = qvariant_cast<QCamera::LockStatus >(v: lockStatusChangedSignalWithType.at(i: 0).at(i: 1)); |
2030 | QVERIFY(lockType == QCamera::LockExposure); |
2031 | QVERIFY(lockStatus == QCamera::Unlocked); |
2032 | } |
2033 | |
2034 | /* Test case for verifying if error signal generated correctly */ |
2035 | void tst_QCamera::testErrorSignal() |
2036 | { |
2037 | MockCameraService service; |
2038 | provider->service = &service; |
2039 | |
2040 | QCamera camera; |
2041 | |
2042 | QSignalSpy spyError(&camera, SIGNAL(errorOccurred(QCamera::Error))); |
2043 | |
2044 | /* Set the QCameraControl error and verify if the signal is emitted correctly in QCamera */ |
2045 | service.mockControl->setError(err: QCamera::CameraError,errorString: QString("Camera Error" )); |
2046 | |
2047 | QVERIFY(spyError.count() == 1); |
2048 | QCamera::Error err = qvariant_cast<QCamera::Error >(v: spyError.at(i: 0).at(i: 0)); |
2049 | QVERIFY(err == QCamera::CameraError); |
2050 | |
2051 | spyError.clear(); |
2052 | |
2053 | /* Set the QCameraControl error and verify if the signal is emitted correctly in QCamera */ |
2054 | service.mockControl->setError(err: QCamera::InvalidRequestError,errorString: QString("InvalidRequestError Error" )); |
2055 | QVERIFY(spyError.count() == 1); |
2056 | err = qvariant_cast<QCamera::Error >(v: spyError.at(i: 0).at(i: 0)); |
2057 | QVERIFY(err == QCamera::InvalidRequestError); |
2058 | |
2059 | spyError.clear(); |
2060 | |
2061 | /* Set the QCameraControl error and verify if the signal is emitted correctly in QCamera */ |
2062 | service.mockControl->setError(err: QCamera::NotSupportedFeatureError,errorString: QString("NotSupportedFeatureError Error" )); |
2063 | QVERIFY(spyError.count() == 1); |
2064 | err = qvariant_cast<QCamera::Error >(v: spyError.at(i: 0).at(i: 0)); |
2065 | QVERIFY(err == QCamera::NotSupportedFeatureError); |
2066 | |
2067 | } |
2068 | |
2069 | /* Test case for verifying the QCamera error */ |
2070 | void tst_QCamera::testError() |
2071 | { |
2072 | MockCameraService service; |
2073 | provider->service = &service; |
2074 | |
2075 | QCamera camera; |
2076 | |
2077 | /* Set the QCameraControl error and verify if it is set correctly in QCamera */ |
2078 | service.mockControl->setError(err: QCamera::CameraError,errorString: QString("Camera Error" )); |
2079 | QVERIFY(camera.error() == QCamera::CameraError); |
2080 | |
2081 | /* Set the QCameraControl error and verify if it is set correctly in QCamera */ |
2082 | service.mockControl->setError(err: QCamera::InvalidRequestError,errorString: QString("InvalidRequestError Error" )); |
2083 | QVERIFY(camera.error() == QCamera::InvalidRequestError); |
2084 | |
2085 | /* Set the QCameraControl error and verify if it is set correctly in QCamera */ |
2086 | service.mockControl->setError(err: QCamera::NotSupportedFeatureError,errorString: QString("NotSupportedFeatureError Error" )); |
2087 | QVERIFY(camera.error() == QCamera::NotSupportedFeatureError); |
2088 | |
2089 | } |
2090 | |
2091 | /* Test the error strings for QCamera class */ |
2092 | void tst_QCamera::testErrorString() |
2093 | { |
2094 | MockCameraService service; |
2095 | provider->service = &service; |
2096 | |
2097 | QCamera camera; |
2098 | |
2099 | /* Set the QCameraControl error and verify if it is set correctly in QCamera */ |
2100 | service.mockControl->setError(err: QCamera::CameraError,errorString: QString("Camera Error" )); |
2101 | QVERIFY(camera.errorString() == QString("Camera Error" )); |
2102 | |
2103 | /* Set the QCameraControl error and verify if it is set correctly in QCamera */ |
2104 | service.mockControl->setError(err: QCamera::InvalidRequestError,errorString: QString("InvalidRequestError Error" )); |
2105 | QVERIFY(camera.errorString() == QString("InvalidRequestError Error" )); |
2106 | |
2107 | /* Set the QCameraControl error and verify if it is set correctly in QCamera */ |
2108 | service.mockControl->setError(err: QCamera::NotSupportedFeatureError,errorString: QString("NotSupportedFeatureError Error" )); |
2109 | QVERIFY(camera.errorString() == QString("NotSupportedFeatureError Error" )); |
2110 | } |
2111 | |
2112 | /* Test case for verifying Status of QCamera. */ |
2113 | void tst_QCamera::testStatus() |
2114 | { |
2115 | MockCameraService service; |
2116 | provider->service = &service; |
2117 | |
2118 | QCamera camera; |
2119 | |
2120 | /* Set the QCameraControl status and verify if it is set correctly in QCamera */ |
2121 | service.mockControl->setStatus(QCamera::StartingStatus); |
2122 | QVERIFY(camera.status() == QCamera::StartingStatus); |
2123 | |
2124 | /* Set the QCameraControl status and verify if it is set correctly in QCamera */ |
2125 | service.mockControl->setStatus(QCamera::StandbyStatus); |
2126 | QVERIFY(camera.status() == QCamera::StandbyStatus); |
2127 | |
2128 | /* Set the QCameraControl status and verify if it is set correctly in QCamera */ |
2129 | service.mockControl->setStatus(QCamera::LoadingStatus); |
2130 | QVERIFY(camera.status() == QCamera::LoadingStatus); |
2131 | |
2132 | /* Set the QCameraControl status and verify if it is set correctly in QCamera */ |
2133 | service.mockControl->setStatus(QCamera::UnavailableStatus); |
2134 | QVERIFY(camera.status() == QCamera::UnavailableStatus); |
2135 | } |
2136 | |
2137 | /* Test case for verifying default locktype QCamera::NoLock */ |
2138 | void tst_QCamera::testLockType() |
2139 | { |
2140 | QCamera camera; |
2141 | |
2142 | QCOMPARE(camera.requestedLocks(),QCamera::NoLock); |
2143 | } |
2144 | |
2145 | /* Test case for QCamera::LockChangeReason with QCamera::LockAcquired */ |
2146 | void tst_QCamera::testLockChangeReason() |
2147 | { |
2148 | MockCameraService service; |
2149 | provider->service = &service; |
2150 | |
2151 | QCamera camera; |
2152 | |
2153 | QSignalSpy lockStatusChangedSignalWithType(&camera, SIGNAL(lockStatusChanged(QCamera::LockType,QCamera::LockStatus,QCamera::LockChangeReason))); |
2154 | |
2155 | /* Set the lockChangeReason */ |
2156 | service.mockLocksControl->setLockChangeReason(QCamera::LockAcquired); |
2157 | |
2158 | /* Verify if lockChangeReson is eqaul toQCamera::LockAcquired */ |
2159 | QCOMPARE(lockStatusChangedSignalWithType.count(), 1); |
2160 | QCamera::LockChangeReason LockChangeReason = qvariant_cast<QCamera::LockChangeReason >(v: lockStatusChangedSignalWithType.at(i: 0).at(i: 2)); |
2161 | QVERIFY(LockChangeReason == QCamera::LockAcquired); |
2162 | |
2163 | } |
2164 | |
2165 | /* All the enums test case for QCameraControl class*/ |
2166 | void tst_QCamera::testEnumsOfQCameraControl() |
2167 | { |
2168 | MockCameraControl *m_cameraControl = new MockCameraControl(this); |
2169 | bool result; |
2170 | |
2171 | // In still mode, can't change much |
2172 | QVERIFY(m_cameraControl->captureMode() == QCamera::CaptureStillImage); |
2173 | result = m_cameraControl->canChangeProperty(changeType: MockCameraControl::CaptureMode, status: QCamera::ActiveStatus); |
2174 | QVERIFY(!result); |
2175 | result = m_cameraControl->canChangeProperty(changeType: MockCameraControl::ImageEncodingSettings, status: QCamera::ActiveStatus); |
2176 | QVERIFY(!result); |
2177 | result = m_cameraControl->canChangeProperty(changeType: MockCameraControl::VideoEncodingSettings, status: QCamera::ActiveStatus); |
2178 | QVERIFY(result); |
2179 | result = m_cameraControl->canChangeProperty(changeType: MockCameraControl::Viewfinder, status: QCamera::ActiveStatus); |
2180 | QVERIFY(!result); |
2181 | |
2182 | // In video mode can change image encoding settings |
2183 | m_cameraControl->setCaptureMode(QCamera::CaptureVideo); |
2184 | result = m_cameraControl->canChangeProperty(changeType: MockCameraControl::ImageEncodingSettings, status: QCamera::ActiveStatus); |
2185 | QVERIFY(result); |
2186 | result = m_cameraControl->canChangeProperty(changeType: MockCameraControl::VideoEncodingSettings, status: QCamera::ActiveStatus); |
2187 | QVERIFY(result); |
2188 | result = m_cameraControl->canChangeProperty(changeType: MockCameraControl::Viewfinder, status: QCamera::ActiveStatus); |
2189 | QVERIFY(!result); |
2190 | |
2191 | // Flip the allow everything bit |
2192 | m_cameraControl->m_propertyChangesSupported = true; |
2193 | result = m_cameraControl->canChangeProperty(changeType: MockCameraControl::CaptureMode, status: QCamera::ActiveStatus); |
2194 | QVERIFY(result); |
2195 | result = m_cameraControl->canChangeProperty(changeType: MockCameraControl::ImageEncodingSettings, status: QCamera::ActiveStatus); |
2196 | QVERIFY(result); |
2197 | result = m_cameraControl->canChangeProperty(changeType: MockCameraControl::VideoEncodingSettings, status: QCamera::ActiveStatus); |
2198 | QVERIFY(result); |
2199 | result = m_cameraControl->canChangeProperty(changeType: MockCameraControl::Viewfinder, status: QCamera::ActiveStatus); |
2200 | QVERIFY(result); |
2201 | } |
2202 | |
2203 | // Test case for QCameraImageProcessing class |
2204 | void tst_QCamera::testContrast() |
2205 | { |
2206 | QCamera camera; |
2207 | QCameraImageProcessing *cameraImageProcessing = camera.imageProcessing(); |
2208 | QVERIFY(cameraImageProcessing->contrast() ==0); |
2209 | |
2210 | cameraImageProcessing->setContrast(0.123); |
2211 | QCOMPARE(cameraImageProcessing->contrast(), 0.123); |
2212 | |
2213 | cameraImageProcessing->setContrast(4.56); |
2214 | QCOMPARE(cameraImageProcessing->contrast(), 4.56); |
2215 | } |
2216 | |
2217 | void tst_QCamera::testDenoisingLevel() |
2218 | { |
2219 | QCamera camera; |
2220 | QCameraImageProcessing *cameraImageProcessing = camera.imageProcessing(); |
2221 | |
2222 | QCOMPARE(cameraImageProcessing->denoisingLevel()+1 , 1.0); |
2223 | |
2224 | cameraImageProcessing->setDenoisingLevel(-0.3); |
2225 | QCOMPARE(cameraImageProcessing->denoisingLevel() , -0.3); |
2226 | |
2227 | cameraImageProcessing->setDenoisingLevel(0.3); |
2228 | QCOMPARE(cameraImageProcessing->denoisingLevel() , 0.3); |
2229 | } |
2230 | |
2231 | void tst_QCamera::testIsAvailable() |
2232 | { |
2233 | QCamera camera; |
2234 | QCameraImageProcessing *cameraImageProcessing = camera.imageProcessing(); |
2235 | QVERIFY(cameraImageProcessing->isAvailable() == true); |
2236 | } |
2237 | |
2238 | void tst_QCamera::testSaturation() |
2239 | { |
2240 | QCamera camera; |
2241 | QCameraImageProcessing *cameraImageProcessing = camera.imageProcessing(); |
2242 | QCOMPARE(cameraImageProcessing->saturation()+1.0, 1.0); |
2243 | |
2244 | cameraImageProcessing->setSaturation(0.5); |
2245 | QCOMPARE(cameraImageProcessing->saturation(), 0.5); |
2246 | |
2247 | cameraImageProcessing->setSaturation(-0.5); |
2248 | QCOMPARE(cameraImageProcessing->saturation(), -0.5); |
2249 | } |
2250 | |
2251 | void tst_QCamera::testSharpeningLevel() |
2252 | { |
2253 | QCamera camera; |
2254 | |
2255 | QCameraImageProcessing *cameraImageProcessing = camera.imageProcessing(); |
2256 | |
2257 | QCOMPARE(cameraImageProcessing->sharpeningLevel()+1 , 1.0); |
2258 | |
2259 | cameraImageProcessing->setSharpeningLevel(-0.3); |
2260 | QCOMPARE(cameraImageProcessing->sharpeningLevel() , -0.3); |
2261 | |
2262 | cameraImageProcessing->setSharpeningLevel(0.3); |
2263 | QCOMPARE(cameraImageProcessing->sharpeningLevel() , 0.3); |
2264 | } |
2265 | |
2266 | void tst_QCamera::testEnumOfQCameraImageProcessing() |
2267 | { |
2268 | QSet<QCameraImageProcessing::WhiteBalanceMode> whiteBalanceModes; |
2269 | whiteBalanceModes << QCameraImageProcessing::WhiteBalanceManual; |
2270 | whiteBalanceModes << QCameraImageProcessing::WhiteBalanceAuto; |
2271 | whiteBalanceModes << QCameraImageProcessing::WhiteBalanceSunlight; |
2272 | whiteBalanceModes << QCameraImageProcessing::WhiteBalanceCloudy; |
2273 | whiteBalanceModes << QCameraImageProcessing::WhiteBalanceShade; |
2274 | whiteBalanceModes << QCameraImageProcessing::WhiteBalanceTungsten; |
2275 | whiteBalanceModes << QCameraImageProcessing::WhiteBalanceFluorescent; |
2276 | whiteBalanceModes << QCameraImageProcessing::WhiteBalanceFlash; |
2277 | whiteBalanceModes << QCameraImageProcessing::WhiteBalanceSunset; |
2278 | whiteBalanceModes << QCameraImageProcessing::WhiteBalanceVendor; |
2279 | |
2280 | MockCameraService service; |
2281 | service.mockImageProcessingControl->setSupportedWhiteBalanceModes(whiteBalanceModes); |
2282 | |
2283 | service.mockImageProcessingControl->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceManual); |
2284 | QVERIFY(service.mockImageProcessingControl->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceManual)); |
2285 | QVERIFY(service.mockImageProcessingControl->whiteBalanceMode() == QCameraImageProcessing::WhiteBalanceManual); |
2286 | |
2287 | service.mockImageProcessingControl->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceAuto); |
2288 | QVERIFY(service.mockImageProcessingControl->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceAuto)); |
2289 | QVERIFY(service.mockImageProcessingControl->whiteBalanceMode() == QCameraImageProcessing::WhiteBalanceAuto); |
2290 | |
2291 | service.mockImageProcessingControl->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceSunlight); |
2292 | QVERIFY(service.mockImageProcessingControl->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceSunlight)); |
2293 | QVERIFY(service.mockImageProcessingControl->whiteBalanceMode() == QCameraImageProcessing::WhiteBalanceSunlight); |
2294 | |
2295 | service.mockImageProcessingControl->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceCloudy); |
2296 | QVERIFY(service.mockImageProcessingControl->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceCloudy)); |
2297 | QVERIFY(service.mockImageProcessingControl->whiteBalanceMode() == QCameraImageProcessing::WhiteBalanceCloudy); |
2298 | |
2299 | service.mockImageProcessingControl->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceShade); |
2300 | QVERIFY(service.mockImageProcessingControl->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceShade)); |
2301 | QVERIFY(service.mockImageProcessingControl->whiteBalanceMode() == QCameraImageProcessing::WhiteBalanceShade); |
2302 | |
2303 | service.mockImageProcessingControl->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceTungsten); |
2304 | QVERIFY(service.mockImageProcessingControl->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceTungsten)); |
2305 | QVERIFY(service.mockImageProcessingControl->whiteBalanceMode() == QCameraImageProcessing::WhiteBalanceTungsten); |
2306 | |
2307 | service.mockImageProcessingControl->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceFluorescent); |
2308 | QVERIFY(service.mockImageProcessingControl->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceFluorescent)); |
2309 | QVERIFY(service.mockImageProcessingControl->whiteBalanceMode() == QCameraImageProcessing::WhiteBalanceFluorescent); |
2310 | |
2311 | service.mockImageProcessingControl->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceFlash); |
2312 | QVERIFY(service.mockImageProcessingControl->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceFlash)); |
2313 | QVERIFY(service.mockImageProcessingControl->whiteBalanceMode() == QCameraImageProcessing::WhiteBalanceFlash); |
2314 | |
2315 | service.mockImageProcessingControl->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceSunset); |
2316 | QVERIFY(service.mockImageProcessingControl->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceSunset)); |
2317 | QVERIFY(service.mockImageProcessingControl->whiteBalanceMode() == QCameraImageProcessing::WhiteBalanceSunset); |
2318 | |
2319 | service.mockImageProcessingControl->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceVendor); |
2320 | QVERIFY(service.mockImageProcessingControl->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceVendor)); |
2321 | QVERIFY(service.mockImageProcessingControl->whiteBalanceMode() == QCameraImageProcessing::WhiteBalanceVendor); |
2322 | } |
2323 | |
2324 | //Added test cases for QCameraFocus |
2325 | void tst_QCamera::testCameraFocusIsAvailable() |
2326 | { |
2327 | QCamera camera; |
2328 | |
2329 | QCameraFocus *cameraFocus = camera.focus(); |
2330 | QVERIFY(cameraFocus != 0); |
2331 | QVERIFY(cameraFocus->isAvailable()); |
2332 | } |
2333 | |
2334 | //Added this code to cover QCameraFocus::HyperfocalFocus and QCameraFocus::MacroFocus |
2335 | //As the HyperfocalFocus and MacroFocus are not supported we can not set the focus mode to these Focus Modes |
2336 | void tst_QCamera::testFocusModes() |
2337 | { |
2338 | QCamera camera; |
2339 | |
2340 | QCameraFocus *cameraFocus = camera.focus(); |
2341 | QVERIFY(cameraFocus != 0); |
2342 | QVERIFY(!cameraFocus->isFocusModeSupported(QCameraFocus::HyperfocalFocus)); |
2343 | QVERIFY(!cameraFocus->isFocusModeSupported(QCameraFocus::MacroFocus)); |
2344 | QCOMPARE(cameraFocus->focusMode(), QCameraFocus::AutoFocus); |
2345 | cameraFocus->setFocusMode(QCameraFocus::HyperfocalFocus); |
2346 | QVERIFY(cameraFocus->focusMode()!= QCameraFocus::HyperfocalFocus); |
2347 | QCOMPARE(cameraFocus->focusMode(), QCameraFocus::AutoFocus); |
2348 | cameraFocus->setFocusMode(QCameraFocus::MacroFocus); |
2349 | QVERIFY(cameraFocus->focusMode()!= QCameraFocus::MacroFocus); |
2350 | QCOMPARE(cameraFocus->focusMode(), QCameraFocus::AutoFocus); |
2351 | } |
2352 | |
2353 | void tst_QCamera::testOpticalAndDigitalZoomChanged() |
2354 | { |
2355 | QCamera camera; |
2356 | |
2357 | QCameraFocus *cameraFocus = camera.focus(); |
2358 | QVERIFY(cameraFocus != 0); |
2359 | QSignalSpy spy1(cameraFocus,SIGNAL(digitalZoomChanged(qreal))); |
2360 | QSignalSpy spy2(cameraFocus,SIGNAL(opticalZoomChanged(qreal))); |
2361 | QVERIFY(spy1.count() == 0); |
2362 | QVERIFY(spy2.count() == 0); |
2363 | cameraFocus->zoomTo(opticalZoom: 2.0,digitalZoom: 3.0); |
2364 | QVERIFY(spy1.count() == 1); |
2365 | QVERIFY(spy2.count() == 1); |
2366 | } |
2367 | |
2368 | void tst_QCamera::testMaxDigitalZoomChangedSignal() |
2369 | { |
2370 | QCamera camera; |
2371 | |
2372 | QCameraFocus *cameraFocus = camera.focus(); |
2373 | QVERIFY(cameraFocus != 0); |
2374 | QSignalSpy spy(cameraFocus,SIGNAL(maximumDigitalZoomChanged(qreal))); |
2375 | QVERIFY(spy.count() == 0); |
2376 | cameraFocus->zoomTo(opticalZoom: 5.0,digitalZoom: 6.0); |
2377 | QVERIFY(spy.count() == 1); |
2378 | } |
2379 | |
2380 | void tst_QCamera::testMaxOpticalZoomChangedSignal() |
2381 | { |
2382 | QCamera camera; |
2383 | |
2384 | QCameraFocus *cameraFocus = camera.focus(); |
2385 | QVERIFY(cameraFocus != 0); |
2386 | QSignalSpy spy(cameraFocus,SIGNAL(maximumOpticalZoomChanged(qreal))); |
2387 | QVERIFY(spy.count() == 0); |
2388 | cameraFocus->zoomTo(opticalZoom: 5.0,digitalZoom: 6.0); |
2389 | QVERIFY(spy.count() == 1); |
2390 | } |
2391 | |
2392 | void tst_QCamera::testfocusZonesChangedSignal() |
2393 | { |
2394 | QCamera camera; |
2395 | |
2396 | QCameraFocus *cameraFocus = camera.focus(); |
2397 | QVERIFY(cameraFocus != 0); |
2398 | |
2399 | QSignalSpy spy(cameraFocus,SIGNAL(focusZonesChanged())); |
2400 | cameraFocus->setCustomFocusPoint(QPointF(0.1, 0.1)); |
2401 | QVERIFY(spy.count() == 1); |
2402 | } |
2403 | |
2404 | // test constructor for abstract class of ImageProcessingControl |
2405 | void tst_QCamera :: testImageProcessingControl() |
2406 | { |
2407 | QObject parent; |
2408 | MockImageProcessingControl processCtrl(&parent); |
2409 | } |
2410 | |
2411 | void tst_QCamera::testSignalApertureChanged() |
2412 | { |
2413 | QCamera camera; |
2414 | |
2415 | QCameraExposure *cameraExposure = camera.exposure(); //create camera expose instance |
2416 | QVERIFY(cameraExposure != 0); |
2417 | |
2418 | QSignalSpy spyApertureChanged(cameraExposure , SIGNAL(apertureChanged(qreal))); |
2419 | QSignalSpy spyApertureRangeChanged(cameraExposure , SIGNAL(apertureRangeChanged())); |
2420 | |
2421 | |
2422 | QVERIFY(spyApertureChanged.count() ==0); |
2423 | cameraExposure->setManualAperture(10.0);//set the ManualAperture to 10.0 |
2424 | |
2425 | QTest::qWait(ms: 100); |
2426 | QVERIFY(spyApertureChanged.count() ==1); |
2427 | QVERIFY(spyApertureRangeChanged.count() ==1); |
2428 | } |
2429 | |
2430 | void tst_QCamera::testSignalExposureCompensationChanged() |
2431 | { |
2432 | QCamera camera; |
2433 | |
2434 | QCameraExposure *cameraExposure = camera.exposure(); //create camera expose instance |
2435 | QVERIFY(cameraExposure != 0); |
2436 | |
2437 | QSignalSpy spyExposureCompensationChanged(cameraExposure , SIGNAL(exposureCompensationChanged(qreal))); |
2438 | |
2439 | QVERIFY(spyExposureCompensationChanged.count() ==0); |
2440 | |
2441 | QVERIFY(cameraExposure->exposureCompensation() != 800); |
2442 | cameraExposure->setExposureCompensation(2.0); |
2443 | |
2444 | QTest::qWait(ms: 100); |
2445 | |
2446 | QVERIFY(cameraExposure->exposureCompensation() == 2.0); |
2447 | |
2448 | QCOMPARE(spyExposureCompensationChanged.count(),1); |
2449 | |
2450 | // Setting the same should not result in a signal |
2451 | cameraExposure->setExposureCompensation(2.0); |
2452 | QTest::qWait(ms: 100); |
2453 | |
2454 | QVERIFY(cameraExposure->exposureCompensation() == 2.0); |
2455 | QCOMPARE(spyExposureCompensationChanged.count(),1); |
2456 | } |
2457 | |
2458 | void tst_QCamera::testSignalIsoSensitivityChanged() |
2459 | { |
2460 | QCamera camera; |
2461 | |
2462 | QCameraExposure *cameraExposure = camera.exposure(); //create camera expose instance |
2463 | QVERIFY(cameraExposure != 0); |
2464 | |
2465 | QSignalSpy spyisoSensitivityChanged(cameraExposure , SIGNAL(isoSensitivityChanged(int))); |
2466 | |
2467 | QVERIFY(spyisoSensitivityChanged.count() ==0); |
2468 | |
2469 | cameraExposure->setManualIsoSensitivity(800); //set the manualiso sentivity to 800 |
2470 | QTest::qWait(ms: 100); |
2471 | QVERIFY(spyisoSensitivityChanged.count() ==1); |
2472 | |
2473 | } |
2474 | void tst_QCamera::testSignalShutterSpeedChanged() |
2475 | { |
2476 | QCamera camera; |
2477 | |
2478 | QCameraExposure *cameraExposure = camera.exposure(); //create camera expose instance |
2479 | QVERIFY(cameraExposure != 0); |
2480 | |
2481 | QSignalSpy spySignalShutterSpeedChanged(cameraExposure , SIGNAL(shutterSpeedChanged(qreal))); |
2482 | QSignalSpy spySignalShutterSpeedRangeChanged(cameraExposure , SIGNAL(shutterSpeedRangeChanged())); |
2483 | |
2484 | QVERIFY(spySignalShutterSpeedChanged.count() ==0); |
2485 | |
2486 | cameraExposure->setManualShutterSpeed(2.0);//set the ManualShutterSpeed to 2.0 |
2487 | QTest::qWait(ms: 100); |
2488 | |
2489 | QVERIFY(spySignalShutterSpeedChanged.count() ==1); |
2490 | QVERIFY(spySignalShutterSpeedRangeChanged.count() ==1); |
2491 | } |
2492 | |
2493 | void tst_QCamera::testSignalFlashReady() |
2494 | { |
2495 | QCamera camera; |
2496 | |
2497 | QCameraExposure *cameraExposure = camera.exposure(); //create camera expose instance |
2498 | QVERIFY(cameraExposure != 0); |
2499 | |
2500 | |
2501 | QSignalSpy spyflashReady(cameraExposure,SIGNAL(flashReady(bool))); |
2502 | |
2503 | QVERIFY(spyflashReady.count() ==0); |
2504 | |
2505 | QVERIFY(cameraExposure->flashMode() ==QCameraExposure::FlashAuto); |
2506 | |
2507 | cameraExposure->setFlashMode(QCameraExposure::FlashOff);//set theFlashMode to QCameraExposure::FlashOff |
2508 | |
2509 | QVERIFY(cameraExposure->flashMode() ==QCameraExposure::FlashOff); |
2510 | |
2511 | QVERIFY(spyflashReady.count() ==1); |
2512 | } |
2513 | |
2514 | // test constructor |
2515 | void tst_QCamera::testExposureControlConstructor() |
2516 | { |
2517 | // To check changes in abstract classes's pure virtual functions |
2518 | MockCameraExposureControl obj; |
2519 | } |
2520 | |
2521 | QTEST_MAIN(tst_QCamera) |
2522 | |
2523 | #include "tst_qcamera.moc" |
2524 | |