1 /* |
|
2 * Copyright (c) 2009-2010 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 |
|
20 #include "cxetestutils.h" |
|
21 #include "unittest_cxevideocapturecontrolsymbian.h" |
|
22 #include "cxevideocapturecontrolsymbian.h" |
|
23 #include "cxevideocapturecontrolsymbianunit.h" |
|
24 #include "cxesnapshotcontrol.h" |
|
25 #include "cxefakefilenamegenerator.h" |
|
26 #include "cxedummycamera.h" |
|
27 #include "cxefakecameradevice.h" |
|
28 #include "cxefakeviewfindercontrol.h" |
|
29 #include "cxefakecameradevicecontrol.h" |
|
30 #include "cxefakequalitypresets.h" |
|
31 #include "cxefakesettings.h" |
|
32 #include "cxutils.h" |
|
33 #include "cxediskmonitor.h" |
|
34 |
|
35 |
|
36 // Enums |
|
37 |
|
38 |
|
39 UnitTestCxeVideoCaptureControlSymbian::UnitTestCxeVideoCaptureControlSymbian() |
|
40 : mCxeVideoCaptureControlSymbian(0) |
|
41 { |
|
42 mSettings = new CxeFakeSettings(); |
|
43 qRegisterMetaType<CxeError::Id>("CxeError::Id"); |
|
44 qRegisterMetaType<CxeVideoCaptureControl::State>("CxeVideoCaptureControl::State"); |
|
45 } |
|
46 |
|
47 UnitTestCxeVideoCaptureControlSymbian::~UnitTestCxeVideoCaptureControlSymbian() |
|
48 { |
|
49 cleanup(); |
|
50 } |
|
51 |
|
52 // Run before each individual test case |
|
53 void UnitTestCxeVideoCaptureControlSymbian::init() |
|
54 { |
|
55 } |
|
56 |
|
57 // Run after each individual test case |
|
58 void UnitTestCxeVideoCaptureControlSymbian::cleanup() |
|
59 { |
|
60 } |
|
61 |
|
62 // Run before each individual test case |
|
63 void UnitTestCxeVideoCaptureControlSymbian::initTestCase() |
|
64 { |
|
65 CX_DEBUG_ENTER_FUNCTION(); |
|
66 mCameraDeviceControl = new CxeFakeCameraDeviceControl(); |
|
67 mCameraDeviceControl->setMode(Cxe::VideoMode); |
|
68 mCameraDevice = new CxeFakeCameraDevice(); |
|
69 mViewfinderControl = new CxeFakeViewfinderControl(); |
|
70 mSnapshotControl = new CxeSnapshotControl(*mCameraDevice); |
|
71 mSettings->set(CxeSettingIds::VIDEO_SHOWCAPTURED, -1); |
|
72 mFilenameGeneratorSymbian = new CxeFakeFilenameGenerator(); |
|
73 mFilenameGeneratorSymbian->init(Cxe::VideoMode); |
|
74 mFakeQualityPresets = new CxeFakeQualityPresets(); |
|
75 mDiskMonitor = new CxeDiskMonitor(*mSettings); |
|
76 mCxeVideoCaptureControlSymbian = new CxeVideoCaptureControlSymbianUnit(*mCameraDevice, |
|
77 *mViewfinderControl, |
|
78 *mSnapshotControl, |
|
79 *mCameraDeviceControl, |
|
80 *mFilenameGeneratorSymbian, |
|
81 *mSettings, |
|
82 *mFakeQualityPresets, |
|
83 *mDiskMonitor); |
|
84 mCameraDevice->newCamera(mCameraDeviceControl->cameraIndex(), mCameraDeviceControl); |
|
85 |
|
86 mSpyState = new QSignalSpy(mCxeVideoCaptureControlSymbian, |
|
87 SIGNAL(stateChanged( |
|
88 CxeVideoCaptureControl::State, |
|
89 CxeError::Id))); |
|
90 |
|
91 |
|
92 // Connect video init complete signal to CameraDeviceControl initModeComplete |
|
93 connect(mCxeVideoCaptureControlSymbian, SIGNAL(videoPrepareComplete(CxeError::Id)), |
|
94 mCameraDeviceControl, SIGNAL(initModeComplete(CxeError::Id)) ); |
|
95 |
|
96 CX_DEBUG_EXIT_FUNCTION(); |
|
97 } |
|
98 |
|
99 void UnitTestCxeVideoCaptureControlSymbian::cleanupTestCase() |
|
100 { |
|
101 CX_DEBUG_ENTER_FUNCTION(); |
|
102 delete mCxeVideoCaptureControlSymbian; |
|
103 mCxeVideoCaptureControlSymbian = 0; |
|
104 delete mFilenameGeneratorSymbian; |
|
105 mFilenameGeneratorSymbian = 0; |
|
106 delete mViewfinderControl; |
|
107 mViewfinderControl = 0; |
|
108 delete mSnapshotControl; |
|
109 mSnapshotControl = 0; |
|
110 delete mCameraDeviceControl; |
|
111 mCameraDeviceControl = 0; |
|
112 delete mCameraDevice; |
|
113 mCameraDevice = 0; |
|
114 delete mFakeQualityPresets; |
|
115 mFakeQualityPresets = 0; |
|
116 delete mDiskMonitor; |
|
117 mDiskMonitor = 0; |
|
118 delete mSettings; |
|
119 mSettings = 0; |
|
120 delete mSpyState; |
|
121 mSpyState = 0; |
|
122 CX_DEBUG_EXIT_FUNCTION(); |
|
123 } |
|
124 |
|
125 |
|
126 void UnitTestCxeVideoCaptureControlSymbian::testState() |
|
127 { |
|
128 CX_DEBUG_ENTER_FUNCTION(); |
|
129 QVERIFY(mCxeVideoCaptureControlSymbian->state() == CxeVideoCaptureControl::Idle); |
|
130 CX_DEBUG_EXIT_FUNCTION(); |
|
131 } |
|
132 |
|
133 |
|
134 |
|
135 void UnitTestCxeVideoCaptureControlSymbian::testRecord() |
|
136 { |
|
137 CX_DEBUG_ENTER_FUNCTION(); |
|
138 |
|
139 doPrepareStuff(); |
|
140 QCOMPARE(mCxeVideoCaptureControlSymbian->state(), CxeVideoCaptureControl::Ready); |
|
141 mCxeVideoCaptureControlSymbian->record(); |
|
142 QCOMPARE(mCxeVideoCaptureControlSymbian->state(), CxeVideoCaptureControl::Recording); |
|
143 |
|
144 CX_DEBUG_EXIT_FUNCTION(); |
|
145 } |
|
146 |
|
147 void UnitTestCxeVideoCaptureControlSymbian::testPause() |
|
148 { |
|
149 CX_DEBUG_ENTER_FUNCTION(); |
|
150 |
|
151 doPrepareStuff(); |
|
152 mCxeVideoCaptureControlSymbian->record(); |
|
153 mCxeVideoCaptureControlSymbian->pause(); |
|
154 QCOMPARE(mCxeVideoCaptureControlSymbian->state(), CxeVideoCaptureControl::Paused); |
|
155 |
|
156 CX_DEBUG_EXIT_FUNCTION(); |
|
157 } |
|
158 |
|
159 void UnitTestCxeVideoCaptureControlSymbian::testStop() |
|
160 { |
|
161 CX_DEBUG_ENTER_FUNCTION(); |
|
162 |
|
163 doPrepareStuff(); |
|
164 mCxeVideoCaptureControlSymbian->record(); |
|
165 mCxeVideoCaptureControlSymbian->stop(); |
|
166 QVERIFY((mCxeVideoCaptureControlSymbian->state() == CxeVideoCaptureControl::Stopping) |
|
167 || (mCxeVideoCaptureControlSymbian->state() == CxeVideoCaptureControl::Initialized) |
|
168 || (mCxeVideoCaptureControlSymbian->state() == CxeVideoCaptureControl::Idle) |
|
169 || (mCxeVideoCaptureControlSymbian->state() == CxeVideoCaptureControl::Ready)); |
|
170 |
|
171 CX_DEBUG_EXIT_FUNCTION(); |
|
172 } |
|
173 |
|
174 void UnitTestCxeVideoCaptureControlSymbian::testRemainingTime() |
|
175 { |
|
176 CX_DEBUG_ENTER_FUNCTION(); |
|
177 |
|
178 int remainingtime = 0; |
|
179 mCxeVideoCaptureControlSymbian->remainingTime(remainingtime); |
|
180 // not possible to test more. |
|
181 |
|
182 CX_DEBUG_EXIT_FUNCTION(); |
|
183 } |
|
184 |
|
185 void UnitTestCxeVideoCaptureControlSymbian::testElapsedTime() |
|
186 { |
|
187 CX_DEBUG_ENTER_FUNCTION(); |
|
188 |
|
189 int elapsedtime = 0; |
|
190 bool timefetched = mCxeVideoCaptureControlSymbian->elapsedTime(elapsedtime); |
|
191 QVERIFY(timefetched == false); |
|
192 // not possible to test more. |
|
193 |
|
194 CX_DEBUG_EXIT_FUNCTION(); |
|
195 } |
|
196 |
|
197 void UnitTestCxeVideoCaptureControlSymbian::testReset() |
|
198 { |
|
199 CX_DEBUG_ENTER_FUNCTION(); |
|
200 |
|
201 doPrepareStuff(); |
|
202 mCxeVideoCaptureControlSymbian->record(); |
|
203 QTest::qWait(1000); |
|
204 mCxeVideoCaptureControlSymbian->stop(); |
|
205 // just call to see if it doesn't crash |
|
206 mCxeVideoCaptureControlSymbian->reset(); |
|
207 QVERIFY(mCxeVideoCaptureControlSymbian->snapshot().isNull()); |
|
208 QVERIFY(mCxeVideoCaptureControlSymbian->filename().isEmpty()); |
|
209 |
|
210 CX_DEBUG_EXIT_FUNCTION(); |
|
211 } |
|
212 |
|
213 void UnitTestCxeVideoCaptureControlSymbian::testFilename() |
|
214 { |
|
215 CX_DEBUG_ENTER_FUNCTION(); |
|
216 |
|
217 doPrepareStuff(); |
|
218 QString filename = mCxeVideoCaptureControlSymbian->filename(); |
|
219 QVERIFY(!mCxeVideoCaptureControlSymbian->filename().isEmpty()); |
|
220 |
|
221 CX_DEBUG_EXIT_FUNCTION(); |
|
222 } |
|
223 |
|
224 void UnitTestCxeVideoCaptureControlSymbian::testSnapshot() |
|
225 { |
|
226 CX_DEBUG_ENTER_FUNCTION(); |
|
227 |
|
228 QCOMPARE(mCxeVideoCaptureControlSymbian->snapshot(), QPixmap()); |
|
229 doPrepareStuff(); |
|
230 mCxeVideoCaptureControlSymbian->record(); |
|
231 QTest::qWait(1000); |
|
232 mCxeVideoCaptureControlSymbian->stop(); |
|
233 // snapshot is not created with dummycamera. |
|
234 // snapshot should still be null |
|
235 QCOMPARE(mCxeVideoCaptureControlSymbian->snapshot(), QPixmap()); |
|
236 |
|
237 CX_DEBUG_EXIT_FUNCTION(); |
|
238 } |
|
239 |
|
240 void UnitTestCxeVideoCaptureControlSymbian::testHandleSnapshotReady() |
|
241 { |
|
242 CX_DEBUG_ENTER_FUNCTION(); |
|
243 QImage snapshot; |
|
244 |
|
245 QSignalSpy spy(mCxeVideoCaptureControlSymbian, SIGNAL(snapshotReady(CxeError::Id, const QImage&, const QString&))); |
|
246 mCxeVideoCaptureControlSymbian->deinit(); |
|
247 doPrepareStuff(); |
|
248 mCxeVideoCaptureControlSymbian->handleSnapshotReady(CxeError::OutOfMemory, snapshot); |
|
249 QCOMPARE(mCxeVideoCaptureControlSymbian->state(), CxeVideoCaptureControl::Ready); |
|
250 |
|
251 // check that we receive this signal once the snapshot is ready |
|
252 QVERIFY(CxeTestUtils::waitForSignal(spy, 1000)); |
|
253 |
|
254 doPrepareStuff(); |
|
255 mCxeVideoCaptureControlSymbian->handleSnapshotReady(CxeError::None, snapshot); |
|
256 QVERIFY(CxeTestUtils::waitForSignal(spy, 1000)); |
|
257 |
|
258 CX_DEBUG_EXIT_FUNCTION(); |
|
259 } |
|
260 |
|
261 void UnitTestCxeVideoCaptureControlSymbian::testInit() |
|
262 { |
|
263 CX_DEBUG_ENTER_FUNCTION(); |
|
264 |
|
265 mCxeVideoCaptureControlSymbian->deinit(); |
|
266 QCOMPARE(mCxeVideoCaptureControlSymbian->state(), CxeVideoCaptureControl::Idle); |
|
267 mCxeVideoCaptureControlSymbian->init(); |
|
268 QCOMPARE(mCxeVideoCaptureControlSymbian->state(),CxeVideoCaptureControl::Ready); |
|
269 |
|
270 CX_DEBUG_EXIT_FUNCTION(); |
|
271 } |
|
272 |
|
273 void UnitTestCxeVideoCaptureControlSymbian::testDeinit() |
|
274 { |
|
275 CX_DEBUG_ENTER_FUNCTION(); |
|
276 |
|
277 mCxeVideoCaptureControlSymbian->init(); |
|
278 |
|
279 QCOMPARE(mCxeVideoCaptureControlSymbian->state(),CxeVideoCaptureControl::Ready); |
|
280 mCxeVideoCaptureControlSymbian->deinit(); |
|
281 QCOMPARE(mCxeVideoCaptureControlSymbian->state(),CxeVideoCaptureControl::Idle); |
|
282 |
|
283 |
|
284 CX_DEBUG_EXIT_FUNCTION(); |
|
285 } |
|
286 |
|
287 void UnitTestCxeVideoCaptureControlSymbian::testHandleSoundPlayed() |
|
288 { |
|
289 CX_DEBUG_ENTER_FUNCTION(); |
|
290 |
|
291 doPrepareStuff(); |
|
292 mCxeVideoCaptureControlSymbian->handleSoundPlayed(); |
|
293 QCOMPARE(mCxeVideoCaptureControlSymbian->state(), CxeVideoCaptureControl::Ready); |
|
294 |
|
295 CX_DEBUG_EXIT_FUNCTION(); |
|
296 } |
|
297 |
|
298 void UnitTestCxeVideoCaptureControlSymbian::testMvruoOpenComplete() |
|
299 { |
|
300 CX_DEBUG_ENTER_FUNCTION(); |
|
301 |
|
302 doPrepareStuff(); |
|
303 QCOMPARE(mCxeVideoCaptureControlSymbian->state(), CxeVideoCaptureControl::Ready); |
|
304 mCxeVideoCaptureControlSymbian->MvruoOpenComplete(CxeError::NotSupported); |
|
305 doPrepareStuff(); |
|
306 mCxeVideoCaptureControlSymbian->MvruoOpenComplete(CxeError::None); |
|
307 QCOMPARE(mCxeVideoCaptureControlSymbian->state(), CxeVideoCaptureControl::Ready); |
|
308 |
|
309 CX_DEBUG_EXIT_FUNCTION(); |
|
310 } |
|
311 |
|
312 void UnitTestCxeVideoCaptureControlSymbian::testMvruoPrepareComplete() |
|
313 { |
|
314 CX_DEBUG_ENTER_FUNCTION(); |
|
315 |
|
316 // since we can't go to preparing state using fake classes |
|
317 // and current implementation of CxeVideoCaptureControlSymbian |
|
318 // we just check that it doesn't crash, or change the state |
|
319 // unnecessarily. |
|
320 doPrepareStuff(); |
|
321 mCxeVideoCaptureControlSymbian->MvruoPrepareComplete(-5); |
|
322 doPrepareStuff(); |
|
323 mCxeVideoCaptureControlSymbian->MvruoPrepareComplete(0); |
|
324 QCOMPARE(mCxeVideoCaptureControlSymbian->state(), CxeVideoCaptureControl::Ready); |
|
325 |
|
326 CX_DEBUG_EXIT_FUNCTION(); |
|
327 } |
|
328 |
|
329 void UnitTestCxeVideoCaptureControlSymbian::testMvruoRecordComplete() |
|
330 { |
|
331 CX_DEBUG_ENTER_FUNCTION(); |
|
332 |
|
333 mCxeVideoCaptureControlSymbian->MvruoRecordComplete(-5); |
|
334 QCOMPARE(mCxeVideoCaptureControlSymbian->state(), CxeVideoCaptureControl::Idle); |
|
335 doPrepareStuff(); |
|
336 mCxeVideoCaptureControlSymbian->MvruoRecordComplete(0); |
|
337 QCOMPARE(mCxeVideoCaptureControlSymbian->state(), CxeVideoCaptureControl::Ready); |
|
338 |
|
339 CX_DEBUG_EXIT_FUNCTION(); |
|
340 } |
|
341 |
|
342 void UnitTestCxeVideoCaptureControlSymbian::testMvruoEvent() |
|
343 { |
|
344 CX_DEBUG_ENTER_FUNCTION(); |
|
345 |
|
346 QSignalSpy spy(mCxeVideoCaptureControlSymbian, SIGNAL(videoComposed(CxeError::Id, const QString&))); |
|
347 |
|
348 const TUid KCamCControllerCCVideoRecordStopped = {0x2000E546}; |
|
349 const TUid KCamCControllerCCVideoFileComposed = {0x2000E547}; |
|
350 |
|
351 TMMFEvent event; |
|
352 event.iEventType.iUid = KCamCControllerCCVideoRecordStopped.iUid; |
|
353 mCxeVideoCaptureControlSymbian->MvruoEvent(event); |
|
354 event.iEventType.iUid = KCamCControllerCCVideoFileComposed.iUid; |
|
355 mCxeVideoCaptureControlSymbian->MvruoEvent(event); |
|
356 QVERIFY(CxeTestUtils::waitForSignal(spy, 1000)); |
|
357 |
|
358 CX_DEBUG_EXIT_FUNCTION(); |
|
359 } |
|
360 |
|
361 |
|
362 void UnitTestCxeVideoCaptureControlSymbian::doPrepareStuff() |
|
363 { |
|
364 CX_DEBUG_ENTER_FUNCTION(); |
|
365 |
|
366 mCxeVideoCaptureControlSymbian->init(); |
|
367 CX_DEBUG((("QTest::qWait(100)"))); |
|
368 QTest::qWait(100); |
|
369 |
|
370 CX_DEBUG_EXIT_FUNCTION(); |
|
371 } |
|
372 |
|
373 |
|
374 // main() function non-GUI testing |
|
375 QTEST_MAIN(UnitTestCxeVideoCaptureControlSymbian); |
|
376 |
|
377 // end of file |
|
378 |
|