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