1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the test suite of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | |
29 | /**************************************************************************** |
30 | Author : Vijay/Avinash |
31 | |
32 | Reviewer Name Date Coverage ( Full / Test Case IDs ). |
33 | --------------------------------------------------------------------------- |
34 | Initial review of test cases. |
35 | ****************************************************************************/ |
36 | |
37 | //TESTED_COMPONENT=src/multimedia |
38 | |
39 | #include <QtTest/QtTest> |
40 | #include <QDebug> |
41 | |
42 | #include <qcameracontrol.h> |
43 | #include <qcameralockscontrol.h> |
44 | #include <qcameraexposurecontrol.h> |
45 | #include <qcameraflashcontrol.h> |
46 | #include <qcamerafocuscontrol.h> |
47 | #include <qcameraimagecapturecontrol.h> |
48 | #include <qimageencodercontrol.h> |
49 | #include <qcameraimageprocessingcontrol.h> |
50 | #include <qmediaservice.h> |
51 | #include <qcamera.h> |
52 | #include <qcameraimagecapture.h> |
53 | |
54 | #include "mockcameraservice.h" |
55 | #include "mockmediaserviceprovider.h" |
56 | |
57 | QT_USE_NAMESPACE |
58 | |
59 | class NullService: public QMediaService |
60 | { |
61 | Q_OBJECT |
62 | |
63 | public: |
64 | NullService(): QMediaService(0) |
65 | { |
66 | |
67 | } |
68 | |
69 | ~NullService() |
70 | { |
71 | |
72 | } |
73 | |
74 | QMediaControl* requestControl(const char *iid) |
75 | { |
76 | Q_UNUSED(iid); |
77 | return 0; |
78 | } |
79 | |
80 | void releaseControl(QMediaControl*) {} |
81 | |
82 | }; |
83 | |
84 | class tst_QCameraImageCapture: public QObject |
85 | { |
86 | Q_OBJECT |
87 | |
88 | public slots: |
89 | void initTestCase(); |
90 | void init(); |
91 | void cleanup(); |
92 | void cleanupTestCase(); |
93 | |
94 | private slots: |
95 | void constructor(); |
96 | void mediaObject(); |
97 | void deleteMediaObject(); |
98 | void isReadyForCapture(); |
99 | void capture(); |
100 | void cancelCapture(); |
101 | void encodingSettings(); |
102 | void errors(); |
103 | void error(); |
104 | void imageCaptured(); |
105 | void imageExposed(); |
106 | void imageSaved(); |
107 | void readyForCaptureChanged(); |
108 | void supportedResolutions(); |
109 | void imageCodecDescription(); |
110 | void supportedImageCodecs(); |
111 | void cameraImageCaptureControl(); |
112 | |
113 | private: |
114 | MockCameraService *mockcameraservice; |
115 | MockMediaServiceProvider *provider; |
116 | }; |
117 | |
118 | void tst_QCameraImageCapture::initTestCase() |
119 | { |
120 | provider = new MockMediaServiceProvider; |
121 | QMediaServiceProvider::setDefaultServiceProvider(provider); |
122 | } |
123 | |
124 | void tst_QCameraImageCapture::init() |
125 | { |
126 | mockcameraservice = new MockCameraService; |
127 | provider->service = mockcameraservice; |
128 | } |
129 | |
130 | void tst_QCameraImageCapture::cleanup() |
131 | { |
132 | delete mockcameraservice; |
133 | mockcameraservice = 0; |
134 | } |
135 | |
136 | void tst_QCameraImageCapture::cleanupTestCase() |
137 | { |
138 | delete provider; |
139 | } |
140 | |
141 | //MaemoAPI-1823:test QCameraImageCapture Constructor |
142 | void tst_QCameraImageCapture::constructor() |
143 | { |
144 | QCamera camera; |
145 | QCameraImageCapture imageCapture(&camera); |
146 | QVERIFY(imageCapture.isAvailable() == true); |
147 | } |
148 | |
149 | //MaemoAPI-1824:test mediaObject |
150 | void tst_QCameraImageCapture::mediaObject() |
151 | { |
152 | NullService mymockcameraservice ; |
153 | provider->service = &mymockcameraservice; |
154 | QCamera camera; |
155 | QCameraImageCapture imageCapture(&camera); |
156 | QVERIFY(imageCapture.mediaObject() == NULL); |
157 | |
158 | provider->service = mockcameraservice; |
159 | QCamera camera1; |
160 | QCameraImageCapture imageCapture1(&camera1); |
161 | QMediaObject *medobj1 = imageCapture1.mediaObject(); |
162 | QCOMPARE(medobj1, &camera1); |
163 | } |
164 | |
165 | void tst_QCameraImageCapture::deleteMediaObject() |
166 | { |
167 | provider->service = new MockCameraService; |
168 | |
169 | QCamera *camera = new QCamera; |
170 | QCameraImageCapture *capture = new QCameraImageCapture(camera); |
171 | |
172 | QVERIFY(capture->mediaObject() == camera); |
173 | QVERIFY(capture->isAvailable()); |
174 | |
175 | delete camera; |
176 | delete provider->service; |
177 | |
178 | //capture should detach from camera |
179 | QVERIFY(capture->mediaObject() == 0); |
180 | QVERIFY(!capture->isAvailable()); |
181 | |
182 | capture->capture(); |
183 | delete capture; |
184 | } |
185 | |
186 | //MaemoAPI-1825:test isReadyForCapture |
187 | void tst_QCameraImageCapture::isReadyForCapture() |
188 | { |
189 | QCamera camera; |
190 | QCameraImageCapture imageCapture(&camera); |
191 | QVERIFY(imageCapture.isAvailable() == true); |
192 | QVERIFY(imageCapture.isReadyForCapture() == false); |
193 | camera.start(); |
194 | imageCapture.capture(); |
195 | QTRY_VERIFY(imageCapture.isReadyForCapture()); |
196 | camera.stop(); |
197 | } |
198 | |
199 | //MaemoAPI-1826:test capture |
200 | void tst_QCameraImageCapture::capture() |
201 | { |
202 | QCamera camera; |
203 | QCameraImageCapture imageCapture(&camera); |
204 | QVERIFY(imageCapture.isAvailable() == true); |
205 | QVERIFY(imageCapture.isReadyForCapture() == false); |
206 | QVERIFY(imageCapture.capture() == -1); |
207 | camera.start(); |
208 | QVERIFY(imageCapture.isReadyForCapture() == true); |
209 | QTest::qWait(ms: 300); |
210 | QVERIFY(imageCapture.capture() != -1); |
211 | camera.stop(); |
212 | } |
213 | |
214 | //MaemoAPI-1827:test cancelCapture |
215 | void tst_QCameraImageCapture::cancelCapture() |
216 | { |
217 | QCamera camera; |
218 | QCameraImageCapture imageCapture(&camera); |
219 | QSignalSpy spy(&imageCapture, SIGNAL(imageCaptured(int,QImage))); |
220 | QSignalSpy spy1(&imageCapture, SIGNAL(imageSaved(int,QString))); |
221 | QVERIFY(imageCapture.isAvailable() == true); |
222 | QVERIFY(imageCapture.isReadyForCapture() == false); |
223 | camera.start(); |
224 | imageCapture.capture(); |
225 | QTRY_VERIFY(imageCapture.isReadyForCapture()); |
226 | QVERIFY(spy.count() == 1 && spy1.count() == 1); |
227 | spy.clear(); |
228 | spy1.clear(); |
229 | camera.stop(); |
230 | |
231 | QVERIFY(imageCapture.isReadyForCapture() == false); |
232 | camera.start(); |
233 | imageCapture.capture(); |
234 | imageCapture.cancelCapture(); |
235 | QTRY_VERIFY(imageCapture.isReadyForCapture()); |
236 | QVERIFY(spy.count() == 0 && spy1.count() == 0); |
237 | camera.stop(); |
238 | } |
239 | |
240 | //MaemoAPI-1828:test encodingSettings |
241 | //MaemoAPI-1829:test set encodingSettings |
242 | void tst_QCameraImageCapture::encodingSettings() |
243 | { |
244 | QCamera camera; |
245 | QCameraImageCapture imageCapture(&camera); |
246 | QVERIFY(imageCapture.isAvailable() == true); |
247 | QVERIFY(imageCapture.encodingSettings() == QImageEncoderSettings()); |
248 | QImageEncoderSettings settings; |
249 | settings.setCodec("JPEG" ); |
250 | settings.setQuality(QMultimedia::NormalQuality); |
251 | imageCapture.setEncodingSettings(settings); |
252 | QVERIFY(!imageCapture.encodingSettings().isNull()); |
253 | QVERIFY(imageCapture.encodingSettings().codec() == "JPEG" ); |
254 | QVERIFY(imageCapture.encodingSettings().quality() == QMultimedia::NormalQuality); |
255 | } |
256 | |
257 | //MaemoAPI-1838:test supportedImageCodecs |
258 | void tst_QCameraImageCapture::supportedImageCodecs() |
259 | { |
260 | QCamera camera; |
261 | QCameraImageCapture imageCapture(&camera); |
262 | QVERIFY(imageCapture.isAvailable() == true); |
263 | QVERIFY(!imageCapture.supportedImageCodecs().isEmpty()); |
264 | } |
265 | |
266 | //MaemoAPI-1836:test supportedResolutions |
267 | void tst_QCameraImageCapture::supportedResolutions() |
268 | { |
269 | QCamera camera; |
270 | QCameraImageCapture imageCapture(&camera); |
271 | QVERIFY(imageCapture.isAvailable() == true); |
272 | QVERIFY(imageCapture.supportedResolutions().count() == 2); |
273 | QImageEncoderSettings settings1; |
274 | settings1.setCodec("PNG" );; |
275 | settings1.setResolution(width: 320, height: 240); |
276 | int result = imageCapture.supportedResolutions(settings: settings1).count(); |
277 | QVERIFY(result == 1); |
278 | } |
279 | |
280 | //MaemoAPI-1837:test imageCodecDescription |
281 | void tst_QCameraImageCapture::imageCodecDescription() |
282 | { |
283 | QCamera camera; |
284 | QCameraImageCapture imageCapture(&camera); |
285 | QVERIFY(imageCapture.isAvailable() == true); |
286 | QVERIFY(imageCapture.imageCodecDescription(" " ).isNull()); |
287 | QVERIFY(imageCapture.imageCodecDescription("PNG" ).isNull() == false); |
288 | } |
289 | |
290 | //MaemoAPI-1830:test errors |
291 | void tst_QCameraImageCapture::errors() |
292 | { |
293 | MockSimpleCameraService mockSimpleCameraService ; |
294 | provider->service = &mockSimpleCameraService; |
295 | |
296 | QCamera camera1; |
297 | QCameraImageCapture imageCapture1(&camera1); |
298 | QVERIFY(imageCapture1.isAvailable() == false); |
299 | imageCapture1.capture(location: QString::fromLatin1(str: "/dev/null" )); |
300 | QVERIFY(imageCapture1.error() == QCameraImageCapture::NotSupportedFeatureError); |
301 | QVERIFY2(!imageCapture1.errorString().isEmpty(), "Device does not support images capture" ); |
302 | QVERIFY(imageCapture1.availability() == QMultimedia::ServiceMissing); |
303 | |
304 | provider->service = mockcameraservice; |
305 | |
306 | QCamera camera; |
307 | QCameraImageCapture imageCapture(&camera); |
308 | QVERIFY(imageCapture.isAvailable() == true); |
309 | QVERIFY(imageCapture.error() == QCameraImageCapture::NoError); |
310 | QVERIFY(imageCapture.errorString().isEmpty()); |
311 | QVERIFY(imageCapture.availability() == QMultimedia::Available); |
312 | |
313 | imageCapture.capture(); |
314 | QVERIFY(imageCapture.error() == QCameraImageCapture::NotReadyError); |
315 | QVERIFY2(!imageCapture.errorString().isEmpty(), "Could not capture in stopped state" ); |
316 | QVERIFY(imageCapture.availability() == QMultimedia::Available); |
317 | } |
318 | |
319 | //MaemoAPI-1831:test error |
320 | void tst_QCameraImageCapture::error() |
321 | { |
322 | QCamera camera; |
323 | QCameraImageCapture imageCapture(&camera); |
324 | QSignalSpy spy(&imageCapture, SIGNAL(error(int,QCameraImageCapture::Error,QString))); |
325 | imageCapture.capture(); |
326 | QTest::qWait(ms: 30); |
327 | QVERIFY(spy.count() == 1); |
328 | QVERIFY(qvariant_cast<int>(spy.at(0).at(0)) == -1); |
329 | QVERIFY(qvariant_cast<QCameraImageCapture::Error>(spy.at(0).at(1)) == QCameraImageCapture::NotReadyError); |
330 | QVERIFY(qvariant_cast<QString>(spy.at(0).at(2)) == "Could not capture in stopped state" ); |
331 | spy.clear(); |
332 | } |
333 | |
334 | //MaemoAPI-1832:test imageCaptured |
335 | void tst_QCameraImageCapture::imageCaptured() |
336 | { |
337 | QCamera camera; |
338 | QCameraImageCapture imageCapture(&camera); |
339 | QSignalSpy spy(&imageCapture, SIGNAL(imageCaptured(int,QImage))); |
340 | QVERIFY(imageCapture.isAvailable() == true); |
341 | QVERIFY(imageCapture.isReadyForCapture() == false); |
342 | camera.start(); |
343 | imageCapture.capture(); |
344 | QTRY_VERIFY(imageCapture.isReadyForCapture()); |
345 | |
346 | QVERIFY(spy.count() == 1); |
347 | QVERIFY(qvariant_cast<int>(spy.at(0).at(0)) > 0); |
348 | QImage image = qvariant_cast<QImage>(v: spy.at(i: 0).at(i: 1)); |
349 | QVERIFY(image.isNull() == true); |
350 | spy.clear(); |
351 | camera.stop(); |
352 | } |
353 | |
354 | //MaemoAPI-1833:test imageExposed |
355 | void tst_QCameraImageCapture::imageExposed() |
356 | { |
357 | QCamera camera; |
358 | QCameraImageCapture imageCapture(&camera); |
359 | QSignalSpy spy(&imageCapture, SIGNAL(imageExposed(int))); |
360 | QVERIFY(imageCapture.isAvailable() == true); |
361 | QVERIFY(imageCapture.isReadyForCapture() == false); |
362 | camera.start(); |
363 | imageCapture.capture(); |
364 | QTRY_VERIFY(imageCapture.isReadyForCapture()); |
365 | |
366 | QVERIFY(spy.count() == 1); |
367 | QVERIFY(qvariant_cast<int>(spy.at(0).at(0)) > 0); |
368 | spy.clear(); |
369 | camera.stop(); |
370 | } |
371 | |
372 | //MaemoAPI-1834:test imageSaved |
373 | void tst_QCameraImageCapture::imageSaved() |
374 | { |
375 | QCamera camera; |
376 | QCameraImageCapture imageCapture(&camera); |
377 | QSignalSpy spy(&imageCapture, SIGNAL(imageSaved(int,QString))); |
378 | QVERIFY(imageCapture.isAvailable() == true); |
379 | QVERIFY(imageCapture.isReadyForCapture() == false); |
380 | camera.start(); |
381 | imageCapture.capture(location: QString::fromLatin1(str: "/usr/share" )); |
382 | QTRY_VERIFY(imageCapture.isReadyForCapture()); |
383 | |
384 | QVERIFY(spy.count() == 1); |
385 | QVERIFY(qvariant_cast<int>(spy.at(0).at(0)) > 0); |
386 | QVERIFY(qvariant_cast<QString>(spy.at(0).at(1)) == "/usr/share" ); |
387 | spy.clear(); |
388 | camera.stop(); |
389 | } |
390 | |
391 | //MaemoAPI-1835:test readyForCaptureChanged |
392 | void tst_QCameraImageCapture::readyForCaptureChanged() |
393 | { |
394 | QCamera camera; |
395 | QCameraImageCapture imageCapture(&camera); |
396 | QSignalSpy spy(&imageCapture, SIGNAL(readyForCaptureChanged(bool))); |
397 | QVERIFY(imageCapture.isReadyForCapture() == false); |
398 | imageCapture.capture(); |
399 | QTest::qWait(ms: 100); |
400 | QVERIFY(spy.count() == 0); |
401 | QVERIFY2(!imageCapture.errorString().isEmpty(),"Could not capture in stopped state" ); |
402 | camera.start(); |
403 | QTest::qWait(ms: 100); |
404 | imageCapture.capture(); |
405 | QTest::qWait(ms: 100); |
406 | QVERIFY(spy.count() == 2); |
407 | QVERIFY(spy.at(0).at(0).toBool() == false); |
408 | QVERIFY(spy.at(1).at(0).toBool() == true); |
409 | camera.stop(); |
410 | spy.clear(); |
411 | } |
412 | |
413 | //MaemoAPI-1853:test cameraImageCapture control constructor |
414 | void tst_QCameraImageCapture::cameraImageCaptureControl() |
415 | { |
416 | MockCameraControl ctrl; |
417 | MockCaptureControl capctrl(&ctrl); |
418 | } |
419 | |
420 | QTEST_MAIN(tst_QCameraImageCapture) |
421 | |
422 | #include "tst_qcameraimagecapture.moc" |
423 | |