|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 #include <QTest> |
|
18 #include <QSignalSpy> |
|
19 #include "cxutils.h" |
|
20 #include "cxeenginetest.h" |
|
21 #include "cxeengine.h" |
|
22 #include "cxecameradevicecontrol.h" |
|
23 #include "cxestillcapturecontrol.h" |
|
24 #include "cxevideocapturecontrol.h" |
|
25 #include "cxeviewfindercontrol.h" |
|
26 #include "cxeautofocuscontrol.h" |
|
27 #include "cxeerror.h" |
|
28 |
|
29 using namespace Cxe; |
|
30 |
|
31 /** |
|
32 * void TestCxeEngine::init() |
|
33 * Helper function to initialize the engine. |
|
34 * Run at the start of each test case. |
|
35 */ |
|
36 void TestCxeEngine::init() |
|
37 { |
|
38 // Commented out because engine deletion fails -> engine created only once |
|
39 // mEngine = CxeEngine::createEngine(); |
|
40 } |
|
41 |
|
42 /** |
|
43 * void TestCxeEngine::initTestCase() |
|
44 * Tests that the engine initialization works properly |
|
45 */ |
|
46 void TestCxeEngine::initTestCase() |
|
47 { |
|
48 mWindow = new HbMainWindow(); |
|
49 mEngine = CxeEngine::createEngine(); |
|
50 |
|
51 mWindow->setOrientation(Qt::Horizontal); |
|
52 mWindow->showFullScreen(); |
|
53 |
|
54 // For viewfinder to be started, window needs to be set |
|
55 mEngine->viewfinderControl().setWindow( mWindow->effectiveWinId()); |
|
56 } |
|
57 |
|
58 /** |
|
59 * Cleans up the engine. |
|
60 * Run after each test case. |
|
61 */ |
|
62 void TestCxeEngine::cleanup() |
|
63 { |
|
64 // commented out because engine delete fails |
|
65 // delete mEngine; |
|
66 // mEngine = NULL; |
|
67 } |
|
68 |
|
69 /** |
|
70 * void TestCxeEngine::cleanupTestCase() |
|
71 * Cleans up the engine and rest of the test environment. |
|
72 * NOTE: This should be the last test case to be executed |
|
73 */ |
|
74 void TestCxeEngine::cleanupTestCase() |
|
75 { |
|
76 delete mEngine; |
|
77 mEngine = NULL; |
|
78 delete mWindow; |
|
79 mWindow = NULL; |
|
80 } |
|
81 |
|
82 /** |
|
83 * void TestCxeEngine::createAndDestroyEngine() |
|
84 * Tests that the engine construction and deletion works without errors. |
|
85 */ |
|
86 void TestCxeEngine::createAndDestroyEngine() |
|
87 { |
|
88 // Do nothing here... just test that we can create and delete the engine |
|
89 // instance without problems. |
|
90 QVERIFY( mEngine != NULL ); |
|
91 } |
|
92 |
|
93 /** |
|
94 * void TestCxeEngine::initStillImageMode() |
|
95 * Initializes the still image mode. |
|
96 * NOTE: No initialization and cleanup, so that it can be used in test cases |
|
97 * requiring still image mode to be ready. |
|
98 */ |
|
99 void TestCxeEngine::initStillImageMode() |
|
100 { |
|
101 CX_DEBUG_ENTER_FUNCTION(); |
|
102 CxeCameraDeviceControl &deviceControl = mEngine->cameraDeviceControl(); |
|
103 CxeStillCaptureControl &stillCaptureControl = mEngine->stillCaptureControl(); |
|
104 |
|
105 QSignalSpy deviceStateSpy(&deviceControl, SIGNAL(initModeComplete(CxeError::Id))); |
|
106 QSignalSpy stillStateSpy(&stillCaptureControl, SIGNAL(stateChanged(CxeStillCaptureControl::State, CxeError::Id))); |
|
107 |
|
108 // Check that the signals were connected withtout errors |
|
109 QVERIFY( deviceStateSpy.isValid() ); |
|
110 QVERIFY( stillStateSpy.isValid() ); |
|
111 |
|
112 if (stillCaptureControl.state()!=CxeStillCaptureControl::Ready) { |
|
113 mEngine->initMode(ImageMode); |
|
114 |
|
115 // Wait for a maximum of 7 seconds for the operation to finish |
|
116 int waitCount = 0; |
|
117 while (deviceStateSpy.count() < 1) { |
|
118 QTest::qWait(1000); // wait one second |
|
119 waitCount++; |
|
120 if (waitCount >= 7) { |
|
121 QFAIL("initModeComplete timed out"); |
|
122 } |
|
123 } |
|
124 |
|
125 // Wait for any unexpected extra signals |
|
126 QTest::qWait(2000); |
|
127 |
|
128 // Check signal lists... Expect exactly one initModeComplete signal |
|
129 QCOMPARE( deviceStateSpy.count(), 1 ); |
|
130 |
|
131 // Expect zero error code |
|
132 QList<QVariant> initModeArguments = deviceStateSpy.takeFirst(); |
|
133 QVERIFY( initModeArguments.at(0).toInt() == 0 ); // CxeError::None |
|
134 |
|
135 // Check signal changes for still capture control |
|
136 // Just 1 state change signal expected: (Uninitialized ->) Ready |
|
137 /* |
|
138 int count = stillStateSpy.count(); |
|
139 for (int i=0; i<count ; i++) { |
|
140 QList<QVariant> capArgs = stillStateSpy.takeAt(0); |
|
141 qDebug("State:%d, err:%d", capArgs.at(0).value<CxeStillCaptureControl::State> (), |
|
142 capArgs.at(1).toInt()); |
|
143 } |
|
144 */ |
|
145 |
|
146 QCOMPARE( stillStateSpy.count(), 1 ); |
|
147 QList<QVariant> initArgs = stillStateSpy.takeFirst(); |
|
148 QVERIFY( initArgs.at(0).value<CxeStillCaptureControl::State>() == CxeStillCaptureControl::Ready ); |
|
149 QVERIFY( initArgs.at(1).toInt() == 0 ); |
|
150 |
|
151 //! @todo: check devicecontrolstate and stillcapturestate |
|
152 } |
|
153 |
|
154 CX_DEBUG_EXIT_FUNCTION(); |
|
155 } |
|
156 |
|
157 /** |
|
158 * void TestCxeEngine::testAutoFocusBasic() |
|
159 * Test that AF either succeeds or fails when attempted. |
|
160 */ |
|
161 void TestCxeEngine::testAutoFocusBasic() |
|
162 { |
|
163 CX_DEBUG_ENTER_FUNCTION(); |
|
164 |
|
165 // Initialize before every test case |
|
166 init(); |
|
167 |
|
168 // Initialize still mode - other details tested internally |
|
169 initStillImageMode(); |
|
170 |
|
171 // Actual test of autofocus |
|
172 CxeAutoFocusControl &afControl = mEngine->autoFocusControl(); |
|
173 QSignalSpy afDeviceStateSpy(&afControl, SIGNAL(stateChanged(CxeAutoFocusControl::State, CxeError::Id)) ); |
|
174 QVERIFY( afDeviceStateSpy.isValid() ); |
|
175 |
|
176 // Wait half a second before starting AF |
|
177 QTest::qWait(500); |
|
178 afControl.start(); |
|
179 QTest::qWait(3000); |
|
180 afControl.cancel(); |
|
181 |
|
182 // Wait for signals |
|
183 QTest::qWait(2000); |
|
184 qDebug("AF signals:%d", afDeviceStateSpy.count()); |
|
185 |
|
186 int count = afDeviceStateSpy.count(); |
|
187 for (int i=0; i<count; i++) { |
|
188 QList<QVariant> afArgs = afDeviceStateSpy.takeAt(0); |
|
189 qDebug("State:%d, err:%d", afArgs.at(0).value<CxeAutoFocusControl::State> (), |
|
190 afArgs.at(1).toInt()); |
|
191 } |
|
192 |
|
193 /* |
|
194 QCOMPARE( afDeviceStateSpy.count(), 2 ); |
|
195 |
|
196 QList<QVariant> afArguments = afDeviceStateSpy.takeAt(0); |
|
197 QVERIFY( afArguments.at(0).value<CxeAutoFocusControl::State>() == CxeAutoFocusControl::InProgress ); |
|
198 QVERIFY( afArguments.at(1).toInt() == 0 ); |
|
199 |
|
200 afArguments = afDeviceStateSpy.takeAt(0); |
|
201 QVERIFY( afArguments.at(0).value<CxeAutoFocusControl::State>() == CxeAutoFocusControl::Ready || |
|
202 afArguments.at(0).value<CxeAutoFocusControl::State>() == CxeAutoFocusControl::Failed ); |
|
203 QVERIFY( afArguments.at(1).toInt() == 0 ); |
|
204 */ |
|
205 |
|
206 // Cleanup after every test case |
|
207 cleanup(); |
|
208 CX_DEBUG_EXIT_FUNCTION(); |
|
209 } |
|
210 |
|
211 /** |
|
212 * void TestCxeEngine::testImageCapture() |
|
213 * Tests that image capture works properly. |
|
214 */ |
|
215 void TestCxeEngine::testImageCapture() |
|
216 { |
|
217 CX_DEBUG_ENTER_FUNCTION(); |
|
218 // Initialize before every test case |
|
219 init(); |
|
220 |
|
221 // Initialize still mode - other details tested internally |
|
222 initStillImageMode(); |
|
223 |
|
224 // Init signal spy for still capture control |
|
225 CxeStillCaptureControl &stillCaptureControl = mEngine->stillCaptureControl(); |
|
226 QSignalSpy stillStateSpy(&stillCaptureControl, SIGNAL(stateChanged(CxeStillCaptureControl::State, CxeError::Id))); |
|
227 QSignalSpy stillSnapSpy(&stillCaptureControl, SIGNAL(snapshotReady(int, CxeError::Id))); |
|
228 QSignalSpy stillImageSpy(&stillCaptureControl, SIGNAL(imageCaptured(CxeError::Id))); |
|
229 |
|
230 // Check that the signals were connected withtout errors |
|
231 QVERIFY( stillStateSpy.isValid() ); |
|
232 QVERIFY( stillSnapSpy.isValid() ); |
|
233 QVERIFY( stillImageSpy.isValid() ); |
|
234 |
|
235 // Wait half a second before starting capture |
|
236 CX_DEBUG(("Waiting before starting capture")); |
|
237 QTest::qWait(500); |
|
238 stillCaptureControl.capture(); |
|
239 CX_DEBUG(("Capture command executed")); |
|
240 |
|
241 // Wait for signals and saving to complete |
|
242 QTest::qWait(5000); |
|
243 |
|
244 // Confirm that one snapshot signal and one image captured signal are received |
|
245 QCOMPARE( stillSnapSpy.count(), 1 ); |
|
246 QCOMPARE( stillImageSpy.count(), 1 ); |
|
247 |
|
248 // 2 Signal expected: Capturing -> Ready/Uninitialized |
|
249 qDebug("Still capture control state signals:%d", stillStateSpy.count()); |
|
250 QCOMPARE( stillStateSpy.count(), 2 ); |
|
251 |
|
252 QList<QVariant> capArguments = stillStateSpy.takeAt(0); |
|
253 QVERIFY( capArguments.at(0).value<CxeStillCaptureControl::State>() == CxeStillCaptureControl::Capturing ); |
|
254 QVERIFY( capArguments.at(1).toInt() == 0 ); |
|
255 |
|
256 capArguments = stillStateSpy.takeAt(0); |
|
257 QVERIFY( capArguments.at(0).value<CxeStillCaptureControl::State>() == CxeStillCaptureControl::Ready ); |
|
258 QVERIFY( capArguments.at(1).toInt() == 0 ); |
|
259 |
|
260 // Cleanup after every test case |
|
261 cleanup(); |
|
262 CX_DEBUG_EXIT_FUNCTION(); |
|
263 } |
|
264 |
|
265 /** |
|
266 * void TestCxeEngine::testBatchCapture() |
|
267 * Test that a number of images can be captured. |
|
268 */ |
|
269 void TestCxeEngine::testBatchCapture() |
|
270 { |
|
271 CX_DEBUG_ENTER_FUNCTION(); |
|
272 for(int i=0; i<3; i++) { |
|
273 testImageCapture(); |
|
274 mEngine->stillCaptureControl().reset(); |
|
275 } |
|
276 CX_DEBUG_EXIT_FUNCTION(); |
|
277 } |
|
278 |
|
279 /** |
|
280 * void TestCxeEngine::initVideoMode() |
|
281 * Initializes the video mode. |
|
282 * NOTE: No initialization and cleanup in done here, so that it can be used in |
|
283 * test cases requiring video mode to be ready. |
|
284 */ |
|
285 void TestCxeEngine::initVideoMode() |
|
286 { |
|
287 CX_DEBUG_ENTER_FUNCTION(); |
|
288 |
|
289 QSignalSpy deviceStateSpy(&mEngine->videoCaptureControl(), SIGNAL(stateChanged(CxeVideoCaptureControl::State, CxeError::Id))); |
|
290 QVERIFY( deviceStateSpy.isValid() ); |
|
291 |
|
292 if (mEngine->videoCaptureControl().state()!=CxeVideoCaptureControl::Ready) { |
|
293 // Call initialize and wait 500ms for signals |
|
294 mEngine->initMode(VideoMode); |
|
295 QTest::qWait(500); |
|
296 |
|
297 // 3 state change signals expected: Open -> Preparing -> Ready |
|
298 QCOMPARE( deviceStateSpy.count(), 3 ); |
|
299 |
|
300 /* |
|
301 int count = deviceStateSpy.count() |
|
302 for (int i=0; i<count ; i++) { |
|
303 QList<QVariant> capArgs = deviceStateSpy.takeAt(0); |
|
304 qDebug("State:%d, err:%d", capArgs.at(0).value<CxeVideoCaptureControl::State> (), |
|
305 capArgs.at(1).toInt()); |
|
306 } |
|
307 */ |
|
308 |
|
309 QList<QVariant> initArgs = deviceStateSpy.takeAt(0); |
|
310 QVERIFY(initArgs.at(0).value<CxeVideoCaptureControl::State>() == CxeVideoCaptureControl::Initialized); |
|
311 QVERIFY( initArgs.at(1).toInt() == 0 ); |
|
312 |
|
313 initArgs = deviceStateSpy.takeAt(0); |
|
314 QVERIFY( initArgs.at(0).value<CxeVideoCaptureControl::State>() == CxeVideoCaptureControl::Preparing ); |
|
315 QVERIFY( initArgs.at(1).toInt() == 0 ); |
|
316 |
|
317 initArgs = deviceStateSpy.takeAt(0); |
|
318 QVERIFY( initArgs.at(0).value<CxeVideoCaptureControl::State>() == CxeVideoCaptureControl::Ready ); |
|
319 QVERIFY( initArgs.at(1).toInt() == 0 ); |
|
320 } |
|
321 |
|
322 CX_DEBUG_EXIT_FUNCTION(); |
|
323 } |
|
324 |
|
325 /** |
|
326 * void TestCxeEngine::testVideoCapture() |
|
327 * Tests that video capture works properly. |
|
328 */ |
|
329 void TestCxeEngine::testVideoCapture() |
|
330 { |
|
331 CX_DEBUG_ENTER_FUNCTION(); |
|
332 |
|
333 // Initialize before every test case |
|
334 init(); |
|
335 |
|
336 // Initialize the video mode |
|
337 initVideoMode(); |
|
338 |
|
339 // Init signal spy for still capture control |
|
340 CxeVideoCaptureControl &videoCaptureControl = mEngine->videoCaptureControl(); |
|
341 QSignalSpy videoStateSpy(&videoCaptureControl, SIGNAL(stateChanged(CxeVideoCaptureControl::State, CxeError::Id))); |
|
342 QSignalSpy videoSnapSpy(&videoCaptureControl, SIGNAL(snapshotReady(CxeError::Id))); |
|
343 QSignalSpy videoSpy(&videoCaptureControl, SIGNAL(videoComposed())); |
|
344 |
|
345 // Check that the signals were connected withtout errors |
|
346 QVERIFY( videoStateSpy.isValid() ); |
|
347 QVERIFY( videoSnapSpy.isValid() ); |
|
348 QVERIFY( videoSpy.isValid() ); |
|
349 |
|
350 // Wait half a second before starting recording |
|
351 QTest::qWait(500); |
|
352 videoCaptureControl.record(); |
|
353 |
|
354 // Wait for 2 seconds before stopping video |
|
355 QTest::qWait(2000); |
|
356 videoCaptureControl.stop(); |
|
357 |
|
358 // Wait some time for video to stop and signals to arrive |
|
359 QTest::qWait(2000); |
|
360 |
|
361 // Expected state sequence: PlayingStartSound -> Recording -> Stopping -> Idle/Ready |
|
362 qDebug("Video capture control state signals:%d", videoStateSpy.count()); |
|
363 QCOMPARE(videoStateSpy.count(), 4); |
|
364 |
|
365 QList<QVariant> stateArgs = videoStateSpy.takeAt(0); |
|
366 QVERIFY( stateArgs.at(0).value<CxeVideoCaptureControl::State>() == CxeVideoCaptureControl::PlayingStartSound ); |
|
367 QVERIFY( stateArgs.at(1).toInt() == 0 ); |
|
368 |
|
369 stateArgs = videoStateSpy.takeAt(0); |
|
370 QVERIFY( stateArgs.at(0).value<CxeVideoCaptureControl::State>() == CxeVideoCaptureControl::Recording ); |
|
371 QVERIFY( stateArgs.at(1).toInt() == 0 ); |
|
372 |
|
373 stateArgs = videoStateSpy.takeAt(0); |
|
374 QVERIFY( stateArgs.at(0).value<CxeVideoCaptureControl::State>() == CxeVideoCaptureControl::Stopping ); |
|
375 QVERIFY( stateArgs.at(1).toInt() == 0 ); |
|
376 |
|
377 stateArgs = videoStateSpy.takeAt(0); |
|
378 QVERIFY( stateArgs.at(0).value<CxeVideoCaptureControl::State>() == CxeVideoCaptureControl::Idle ); |
|
379 QVERIFY( stateArgs.at(1).toInt() == 0 ); |
|
380 |
|
381 /* |
|
382 int count = videoStateSpy.count(); |
|
383 for (int i=0; i<count; i++) { |
|
384 QList<QVariant> capArgs = videoStateSpy.takeAt(0); |
|
385 qDebug("State:%d, err:%d", capArgs.at(0).value<CxeVideoCaptureControl::State> (), |
|
386 capArgs.at(1).toInt()); |
|
387 } |
|
388 */ |
|
389 |
|
390 // Confirm that one snapshot signal and one video composed signal is received |
|
391 QCOMPARE( videoSnapSpy.count(), 1 ); |
|
392 QCOMPARE( videoSpy.count(), 1 ); |
|
393 |
|
394 // Cleanup after every test case |
|
395 cleanup(); |
|
396 CX_DEBUG_EXIT_FUNCTION(); |
|
397 } |
|
398 |
|
399 /* |
|
400 void TestCxeEngine::testTemplate() |
|
401 { |
|
402 // Initialize before every test case |
|
403 init(); |
|
404 |
|
405 // Initialize the image mode |
|
406 initTestCase(); |
|
407 |
|
408 // Cleanup after every test case |
|
409 cleanup(); |
|
410 } |
|
411 */ |
|
412 |
|
413 // main() function non-GUI testing |
|
414 QTEST_MAIN( TestCxeEngine ); |