22 |
22 |
23 #include "cxetestutils.h" |
23 #include "cxetestutils.h" |
24 #include "cxefakecameradevicecontrol.h" |
24 #include "cxefakecameradevicecontrol.h" |
25 #include "cxefakecameradevice.h" |
25 #include "cxefakecameradevice.h" |
26 #include "cxefakesettings.h" |
26 #include "cxefakesettings.h" |
27 #include "cxeautofocuscontrolsymbian.h" |
27 #include "cxeautofocuscontrolsymbianunit.h" |
28 #include "unittest_cxeautofocuscontrolsymbian.h" |
28 #include "unittest_cxeautofocuscontrolsymbian.h" |
|
29 #include "cxenamespace.h" |
29 |
30 |
30 UnitTestCxeAutoFocusControlSymbian::UnitTestCxeAutoFocusControlSymbian() |
31 UnitTestCxeAutoFocusControlSymbian::UnitTestCxeAutoFocusControlSymbian() |
31 : mAutoFocusControl(NULL), |
32 : mAutoFocusControl(NULL), |
32 mCameraDeviceControl(NULL), |
33 mCameraDeviceControl(NULL), |
33 mCameraDevice(NULL), |
34 mCameraDevice(NULL), |
34 mFakeSettings(NULL) |
35 mFakeSettings(NULL) |
35 { |
36 { |
|
37 qRegisterMetaType<CxeError::Id>("CxeError::Id"); |
|
38 qRegisterMetaType<CxeAutoFocusControl::State>("CxeAutoFocusControl::State"); |
|
39 qRegisterMetaType<CxeAutoFocusControl::Mode>("CxeAutoFocusControl::Mode"); |
36 } |
40 } |
37 |
41 |
38 UnitTestCxeAutoFocusControlSymbian::~UnitTestCxeAutoFocusControlSymbian() |
42 UnitTestCxeAutoFocusControlSymbian::~UnitTestCxeAutoFocusControlSymbian() |
39 { |
43 { |
40 cleanup(); |
|
41 } |
44 } |
42 |
45 |
43 // Run before each individual test case |
46 // Run before each individual test case |
44 void UnitTestCxeAutoFocusControlSymbian::init() |
47 void UnitTestCxeAutoFocusControlSymbian::init() |
45 { |
48 { |
46 qDebug() << "UnitTestCxeAutoFocusControlSymbian::init =>"; |
49 CX_DEBUG_ENTER_FUNCTION(); |
47 |
50 |
48 mFakeSettings = new CxeFakeSettings(); |
51 mFakeSettings = new CxeFakeSettings(); |
49 |
52 |
50 mCameraDeviceControl = new CxeFakeCameraDeviceControl(); |
53 mCameraDeviceControl = new CxeFakeCameraDeviceControl(); |
51 mCameraDevice = new CxeFakeCameraDevice(); |
54 mCameraDevice = new CxeFakeCameraDevice(); |
52 mCameraDevice->newCamera(mCameraDeviceControl->cameraIndex(), mCameraDeviceControl); |
55 mCameraDevice->newCamera(mCameraDeviceControl->cameraIndex(), mCameraDeviceControl); |
53 |
56 |
54 mAutoFocusControl = new CxeAutoFocusControlSymbian(*mCameraDevice, *mFakeSettings); |
57 mAutoFocusControl = new CxeAutoFocusControlSymbianUnit(*mCameraDevice, *mFakeSettings); |
55 //mAutoFocusControl->initializeResources(); |
58 |
56 |
59 // make sure that initialization is correct |
57 connect(mCameraDeviceControl, SIGNAL(cameraEvent(int,int)), |
60 QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Unknown); |
58 mAutoFocusControl, SLOT(handleCameraEvent(int,int))); |
61 QCOMPARE(mAutoFocusControl->mode(), CxeAutoFocusControl::Hyperfocal); |
59 |
62 QCOMPARE(mAutoFocusControl->isSoundEnabled(), false); |
60 qDebug() << "UnitTestCxeAutoFocusControlSymbian::init <="; |
63 QCOMPARE(mAutoFocusControl->supported(), true); |
|
64 |
|
65 CX_DEBUG_EXIT_FUNCTION(); |
61 } |
66 } |
62 |
67 |
63 // Run after each individual test case |
68 // Run after each individual test case |
64 void UnitTestCxeAutoFocusControlSymbian::cleanup() |
69 void UnitTestCxeAutoFocusControlSymbian::cleanup() |
65 { |
70 { |
66 qDebug() << "UnitTestCxeAutoFocusControlSymbian::cleanup =>"; |
71 CX_DEBUG_ENTER_FUNCTION(); |
|
72 |
67 delete mAutoFocusControl; |
73 delete mAutoFocusControl; |
68 mAutoFocusControl = NULL; |
74 mAutoFocusControl = NULL; |
69 |
75 |
70 delete mCameraDeviceControl; |
76 delete mCameraDeviceControl; |
71 mCameraDeviceControl = NULL; |
77 mCameraDeviceControl = NULL; |
74 mCameraDevice = NULL; |
80 mCameraDevice = NULL; |
75 |
81 |
76 delete mFakeSettings; |
82 delete mFakeSettings; |
77 mFakeSettings = NULL; |
83 mFakeSettings = NULL; |
78 |
84 |
79 qDebug() << "UnitTestCxeAutoFocusControlSymbian::cleanup <="; |
85 CX_DEBUG_EXIT_FUNCTION(); |
80 } |
86 } |
81 |
87 |
82 |
88 |
83 void UnitTestCxeAutoFocusControlSymbian::testStart() |
89 void UnitTestCxeAutoFocusControlSymbian::testStart() |
84 { |
90 { |
85 QVERIFY(mAutoFocusControl->state() == CxeAutoFocusControl::Unknown); |
91 // start takes a boolean input and returns CxeError |
86 mAutoFocusControl->start(); |
92 // functionality depends on current state and current autofocus mode |
87 QVERIFY(mAutoFocusControl->state() == CxeAutoFocusControl::InProgress); |
93 |
88 QVERIFY(CxeTestUtils::waitForState<CxeAutoFocusControl>(*mAutoFocusControl, CxeAutoFocusControl::Ready, 500)); |
94 QSignalSpy stateSpy(mAutoFocusControl, |
|
95 SIGNAL(stateChanged(CxeAutoFocusControl::State, |
|
96 CxeError::Id))); |
|
97 |
|
98 CxeError::Id returnValue = CxeError::None; |
|
99 // 1) Default input after initialisation (fixed focus) -> nothing should happen |
|
100 returnValue = mAutoFocusControl->start(); |
|
101 // verifying the result: |
|
102 QVERIFY(returnValue == CxeError::None); |
|
103 QCOMPARE(mAutoFocusControl->isSoundEnabled(), true); // check for input paramete |
|
104 // no state changes |
|
105 QVERIFY(!CxeTestUtils::waitForSignal(stateSpy, 1000)); |
|
106 QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Unknown); |
|
107 |
|
108 // 2) Input parameter false is handled correctly |
|
109 // prequisites: not fixed mode & unknown state -> normal functionality |
|
110 mAutoFocusControl->setMode(CxeAutoFocusControl::Auto); // non-fixed |
|
111 // function call |
|
112 returnValue = mAutoFocusControl->start(false); |
|
113 // verifying the result: |
|
114 QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::InProgress); |
|
115 QCOMPARE(returnValue, CxeError::None); |
|
116 QCOMPARE(mAutoFocusControl->isSoundEnabled(), false); // check for input parameter |
|
117 |
|
118 // 3) Autofocus is not ready (state is cancelling or in progress) |
|
119 // prequisites: |
|
120 mAutoFocusControl->setMode(CxeAutoFocusControl::Macro); // non-fixed mode |
|
121 QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::InProgress); |
|
122 // start should return CxeError::InUse |
|
123 returnValue = mAutoFocusControl->start(); |
|
124 QCOMPARE(returnValue, CxeError::InUse); |
|
125 |
|
126 // 4) Camera has been released |
|
127 mAutoFocusControl->prepareForCameraDelete(); |
|
128 stateSpy.clear(); |
|
129 returnValue = mAutoFocusControl->start(); |
|
130 // result: no signal should be emitted |
|
131 QVERIFY(!CxeTestUtils::waitForSignal(stateSpy, 1000)); |
|
132 QCOMPARE(returnValue, CxeError::None); // should there be and error here? |
89 } |
133 } |
90 |
134 |
91 void UnitTestCxeAutoFocusControlSymbian::testCancel() |
135 void UnitTestCxeAutoFocusControlSymbian::testCancel() |
92 { |
136 { |
93 mAutoFocusControl->start(); |
137 // create signalspy to monitor that state changed signal |
94 QVERIFY(mAutoFocusControl->state() == CxeAutoFocusControl::InProgress); |
138 QSignalSpy spy(mAutoFocusControl, |
95 mAutoFocusControl->cancel(); |
139 SIGNAL(stateChanged(CxeAutoFocusControl::State, |
96 QVERIFY(mAutoFocusControl->state() == CxeAutoFocusControl::Canceling); |
140 CxeError::Id))); |
97 QVERIFY(CxeTestUtils::waitForState<CxeAutoFocusControl>(*mAutoFocusControl, CxeAutoFocusControl::Unknown, 500)); |
141 |
98 } |
142 // 1) after initialisation cancel does nothing |
99 |
143 mAutoFocusControl->cancel(); |
100 void UnitTestCxeAutoFocusControlSymbian::testMode() |
144 // no state changes |
101 { |
145 QCOMPARE(spy.count(), 0); |
|
146 QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Unknown); |
|
147 |
|
148 // 2) When in fixed focus mode, cancel does nothing |
|
149 mAutoFocusControl->setMode(CxeAutoFocusControl::Auto); // non fixed mode so that start works |
|
150 mAutoFocusControl->start(); |
|
151 QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::InProgress); //verify start state |
|
152 mAutoFocusControl->setMode(CxeAutoFocusControl::Infinity); // fixed mode |
|
153 spy.clear(); |
|
154 mAutoFocusControl->cancel(); |
|
155 QCOMPARE(spy.count(), 0); |
|
156 QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::InProgress); |
|
157 |
|
158 // 3) InProgress state and "normal cancel" |
|
159 // set mode back to non fixed mode |
102 mAutoFocusControl->setMode(CxeAutoFocusControl::Auto); |
160 mAutoFocusControl->setMode(CxeAutoFocusControl::Auto); |
103 QVERIFY(mAutoFocusControl->mode() == CxeAutoFocusControl::Auto); |
161 mAutoFocusControl->cancel(); |
104 |
162 // -> state is changed to Canceling |
105 mAutoFocusControl->setMode(CxeAutoFocusControl::Hyperfocal); |
163 QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Canceling); |
106 QVERIFY(mAutoFocusControl->mode() == CxeAutoFocusControl::Hyperfocal); |
164 // -> focustype set correctly |
107 |
165 QVERIFY(mAutoFocusControl->focusType() |
108 mAutoFocusControl->setMode(CxeAutoFocusControl::Macro); |
166 == CCamera::CCameraAdvancedSettings::EAutoFocusTypeOff); |
109 QVERIFY(mAutoFocusControl->mode() == CxeAutoFocusControl::Macro); |
167 |
110 |
168 // 4) Canceling state (reached when calling canceling twice in a row, |
|
169 // now already in canceling state after previous test) |
|
170 QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Canceling); |
|
171 mAutoFocusControl->cancel(); |
|
172 // -> state or focustype is not changing |
|
173 QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Canceling); |
|
174 QVERIFY(mAutoFocusControl->focusType() |
|
175 == CCamera::CCameraAdvancedSettings::EAutoFocusTypeOff); |
|
176 |
|
177 // 5) Ready state (cancel called after start has been called and focus |
|
178 // found) |
|
179 // force state to ready in order to test canceling |
|
180 mAutoFocusControl->setState(CxeAutoFocusControl::Unknown); |
|
181 mAutoFocusControl->start(); // changes to in progress + sets focus type & range |
|
182 mAutoFocusControl->setState(CxeAutoFocusControl::Ready); |
|
183 mAutoFocusControl->cancel(); |
|
184 // state is changed to canceling |
|
185 QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Canceling); |
|
186 |
|
187 } |
|
188 |
|
189 |
|
190 void UnitTestCxeAutoFocusControlSymbian::testIsFixedFocusMode() |
|
191 { |
|
192 // default value (hyperfocal) |
|
193 QCOMPARE(mAutoFocusControl->isFixedFocusMode(mAutoFocusControl->mode()), true); |
|
194 |
|
195 // set non fixed focus mode |
|
196 mAutoFocusControl->setMode(CxeAutoFocusControl::Auto); |
|
197 QCOMPARE(mAutoFocusControl->isFixedFocusMode(mAutoFocusControl->mode()), false); |
|
198 |
|
199 // set fixed focus mode |
111 mAutoFocusControl->setMode(CxeAutoFocusControl::Infinity); |
200 mAutoFocusControl->setMode(CxeAutoFocusControl::Infinity); |
112 QVERIFY(mAutoFocusControl->mode() == CxeAutoFocusControl::Infinity); |
201 QCOMPARE(mAutoFocusControl->isFixedFocusMode(mAutoFocusControl->mode()), true); |
113 |
202 |
114 mAutoFocusControl->setMode(CxeAutoFocusControl::Portrait); |
|
115 QVERIFY(mAutoFocusControl->mode() == CxeAutoFocusControl::Portrait); |
|
116 } |
|
117 |
|
118 void UnitTestCxeAutoFocusControlSymbian::testIsFixedFocusMode() |
|
119 { |
|
120 QVERIFY(mAutoFocusControl->isFixedFocusMode(CxeAutoFocusControl::Auto) == false); |
|
121 QVERIFY(mAutoFocusControl->isFixedFocusMode(CxeAutoFocusControl::Hyperfocal) == true); |
|
122 QVERIFY(mAutoFocusControl->isFixedFocusMode(CxeAutoFocusControl::Macro) == false); |
|
123 QVERIFY(mAutoFocusControl->isFixedFocusMode(CxeAutoFocusControl::Infinity) == true); |
|
124 QVERIFY(mAutoFocusControl->isFixedFocusMode(CxeAutoFocusControl::Portrait) == false); |
|
125 } |
203 } |
126 |
204 |
127 void UnitTestCxeAutoFocusControlSymbian::testSupported() |
205 void UnitTestCxeAutoFocusControlSymbian::testSupported() |
128 { |
206 { |
129 bool supported = mAutoFocusControl->supported(); |
207 bool supported = mAutoFocusControl->supported(); |
130 QVERIFY(supported); |
208 QVERIFY(supported); |
131 } |
209 } |
|
210 |
|
211 |
|
212 void UnitTestCxeAutoFocusControlSymbian::testPrepareForCameraDelete() |
|
213 { |
|
214 // prepareCameraDelete calls prepareCameraRelease plus sets advanced |
|
215 // settings false (supported() will return false) |
|
216 // this test is for both methods |
|
217 |
|
218 // 1) initial values |
|
219 mAutoFocusControl->prepareForCameraDelete(); |
|
220 QCOMPARE(mAutoFocusControl->supported(), false); |
|
221 QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Unknown); |
|
222 |
|
223 // 2) test prepareForCameraDelete with non-initial values |
|
224 mAutoFocusControl->handleCameraAllocated(CxeError::None); |
|
225 // force state to be something else than Unknown and check that it will be changed |
|
226 mAutoFocusControl->setState(CxeAutoFocusControl::Canceling); |
|
227 // force mCancelled to be false and check that it will be changed |
|
228 mAutoFocusControl->mCancelled = true; |
|
229 mAutoFocusControl->prepareForCameraDelete(); |
|
230 QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Unknown); |
|
231 QCOMPARE(mAutoFocusControl->mCancelled, false); |
|
232 QCOMPARE(mAutoFocusControl->supported(), false); |
|
233 |
|
234 } |
|
235 |
|
236 void UnitTestCxeAutoFocusControlSymbian::testHandleCameraAllocated() |
|
237 { |
|
238 // create signalspy to monitor that state changed signal |
|
239 QSignalSpy stateSpy(mAutoFocusControl, |
|
240 SIGNAL(stateChanged(CxeAutoFocusControl::State, |
|
241 CxeError::Id))); |
|
242 |
|
243 // 1) initial setup without an error (camera is allocated already) |
|
244 mAutoFocusControl->handleCameraAllocated(CxeError::None); |
|
245 QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Unknown); |
|
246 QCOMPARE(mAutoFocusControl->supported(), true); |
|
247 |
|
248 // 2) release camera and call with an error code |
|
249 // -> supported should return false since initializeResources is not called in error case |
|
250 // -> state is not changed |
|
251 mAutoFocusControl->prepareForCameraDelete(); |
|
252 stateSpy.clear(); |
|
253 mAutoFocusControl->handleCameraAllocated(CxeError::General); |
|
254 QVERIFY(!CxeTestUtils::waitForSignal(stateSpy, 1000)); |
|
255 QCOMPARE(mAutoFocusControl->supported(), false); |
|
256 |
|
257 // 3) release camera and call without an error |
|
258 // (prepareForCameraDelete has been called in previous test) |
|
259 // -> resources are initialized i.e. supported returns true |
|
260 // first force state to something else so state change can be verified |
|
261 mAutoFocusControl->setState(CxeAutoFocusControl::Canceling); |
|
262 mAutoFocusControl->handleCameraAllocated(CxeError::None); |
|
263 QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Unknown); |
|
264 QCOMPARE(mAutoFocusControl->supported(), true); |
|
265 |
|
266 } |
|
267 |
|
268 void UnitTestCxeAutoFocusControlSymbian::testPrepareForRelease() |
|
269 { |
|
270 // see testPrepareForCameraDelete |
|
271 } |
|
272 |
|
273 void UnitTestCxeAutoFocusControlSymbian::testHandleCameraEvent() |
|
274 { |
|
275 // handleCameraEvent handles callbacks and gets information about |
|
276 // focus events. handleCameraEvent calls private method handleAfEvent |
|
277 // for the focusing events that CxeAutoFocusControlSymbian needs |
|
278 |
|
279 // testing handleAfEvent is done by calling handleCameraEvent |
|
280 // and monitoring state changes after each "event" |
|
281 |
|
282 QSignalSpy stateSpy(mAutoFocusControl, |
|
283 SIGNAL(stateChanged(CxeAutoFocusControl::State, |
|
284 CxeError::Id))); |
|
285 |
|
286 |
|
287 // Input 1 ---------------------------------------------------- |
|
288 // Optimal focus was reached or couldn't be found |
|
289 int eventUid = KUidECamEventCameraSettingsOptimalFocusUidValue; |
|
290 int symbianError = 0; //KErrNone |
|
291 |
|
292 // AutofocusControl class is not InProgress or Canceling state |
|
293 // => event ignored, nothing is changed |
|
294 mAutoFocusControl->handleCameraEvent(eventUid, symbianError); |
|
295 QVERIFY(!CxeTestUtils::waitForSignal(stateSpy, 1000)); |
|
296 |
|
297 // AutoFocusControl is InProgress state (waiting for the focus) |
|
298 mAutoFocusControl->setMode(CxeAutoFocusControl::Auto); // not fixed focus |
|
299 mAutoFocusControl->start(); |
|
300 QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::InProgress); //verify start state |
|
301 mAutoFocusControl->handleCameraEvent(eventUid, symbianError); |
|
302 // => state should change to Ready |
|
303 QVERIFY(CxeTestUtils::waitForSignal(stateSpy, 1000)); |
|
304 QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Ready); |
|
305 |
|
306 // InProgress state but focus fails |
|
307 mAutoFocusControl->start(); |
|
308 stateSpy.clear(); |
|
309 QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::InProgress); //verify start state |
|
310 mAutoFocusControl->handleCameraEvent(eventUid, -18); // KErrNotReady |
|
311 // => state should change to Failed |
|
312 QVERIFY(CxeTestUtils::waitForSignal(stateSpy, 1000)); |
|
313 QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Failed); |
|
314 |
|
315 // AutoFocusControl is in Canceling state |
|
316 mAutoFocusControl->start(); |
|
317 mAutoFocusControl->cancel(); |
|
318 QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Canceling); //verify start state |
|
319 stateSpy.clear(); |
|
320 mAutoFocusControl->handleCameraEvent(eventUid, symbianError); |
|
321 // => state should change to Unknown |
|
322 QVERIFY(CxeTestUtils::waitForSignal(stateSpy, 1000)); |
|
323 QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Unknown); |
|
324 |
|
325 // cleanup and init to make sure that the dummy engine is not messed up |
|
326 // and we get to initial state |
|
327 cleanup(); |
|
328 init(); |
|
329 |
|
330 // Input 2 ----------------------------------------------------- |
|
331 // Notifies a change in autofocus type |
|
332 eventUid = KUidECamEventCameraSettingAutoFocusType2UidValue; |
|
333 symbianError = -18; // == KErrNotReady |
|
334 |
|
335 // InProgress: event is ignored |
|
336 mAutoFocusControl->setMode(CxeAutoFocusControl::Auto); // not fixed focus |
|
337 mAutoFocusControl->start(); |
|
338 QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::InProgress); //verify start state |
|
339 stateSpy.clear(); |
|
340 mAutoFocusControl->handleCameraEvent(eventUid, symbianError); |
|
341 QVERIFY(!CxeTestUtils::waitForSignal(stateSpy, 1000)); |
|
342 |
|
343 // Canceling: |
|
344 // error parameter is ignored, state is not changed |
|
345 mAutoFocusControl->cancel(); |
|
346 QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Canceling); //verify start state |
|
347 stateSpy.clear(); |
|
348 mAutoFocusControl->handleCameraEvent(eventUid, symbianError); |
|
349 QVERIFY(!CxeTestUtils::waitForSignal(stateSpy, 1000)); |
|
350 |
|
351 // cleanup and init to make sure that the dummy engine is not messed up |
|
352 // and we get to initial state |
|
353 cleanup(); |
|
354 init(); |
|
355 |
|
356 // Input 3 ----------------------------------------------------- |
|
357 // Focus range have changed |
|
358 eventUid = KUidECamEventCameraSettingFocusRangeUidValue; |
|
359 symbianError = -2; // == KErrGeneral |
|
360 |
|
361 // In any other state than InProgress this event is ignored |
|
362 stateSpy.clear(); |
|
363 mAutoFocusControl->handleCameraEvent(eventUid, symbianError); |
|
364 QVERIFY(!CxeTestUtils::waitForSignal(stateSpy, 1000)); |
|
365 |
|
366 // InProgress: because of the error parameter state changes to failed |
|
367 // (focus range change failed because of error) |
|
368 mAutoFocusControl->setMode(CxeAutoFocusControl::Auto); // not fixed focus |
|
369 mAutoFocusControl->start(); |
|
370 QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::InProgress); //verify start state |
|
371 mAutoFocusControl->handleCameraEvent(eventUid, symbianError); |
|
372 // => state should change to Failed |
|
373 QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Failed); |
|
374 } |
|
375 |
|
376 void UnitTestCxeAutoFocusControlSymbian::testHandleSceneChanged() |
|
377 { |
|
378 // changes the autofocus settings to match the new scene settings |
|
379 QVariantMap scene; |
|
380 |
|
381 // changes focus if new scene setting defines fixed focus |
|
382 // otherwise sets the autofocus control to Unknown state (==initial state) |
|
383 |
|
384 // 1) change to a scene with fixed focus mode (Infinity & Hyperfocal) |
|
385 scene.insert(CxeSettingIds::FOCAL_RANGE, CxeAutoFocusControl::Infinity); |
|
386 mAutoFocusControl->handleSceneChanged(scene); |
|
387 // states are changed and mode is set correctly ->Unknown->InProgress |
|
388 QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::InProgress); // end state |
|
389 QCOMPARE(mAutoFocusControl->mode(), CxeAutoFocusControl::Infinity); |
|
390 |
|
391 // 2) change to non-fixed mode (like Macro) |
|
392 scene.clear(); |
|
393 scene.insert(CxeSettingIds::FOCAL_RANGE, CxeAutoFocusControl::Macro); |
|
394 mAutoFocusControl->handleSceneChanged(scene); |
|
395 // states are changed and mode is set correctly |
|
396 QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Unknown); |
|
397 QCOMPARE(mAutoFocusControl->mode(), CxeAutoFocusControl::Macro); |
|
398 |
|
399 // 3) try with error input (scene does not contain focal_range) |
|
400 scene.clear(); |
|
401 // change the autofocuscontrol state from Unknown (last test) to |
|
402 // something else calling start() for example |
|
403 mAutoFocusControl->start(); |
|
404 QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::InProgress); //verify start state |
|
405 mAutoFocusControl->handleSceneChanged(scene); |
|
406 // state is changed and mode is not changed |
|
407 QCOMPARE(mAutoFocusControl->state(), CxeAutoFocusControl::Unknown); |
|
408 QCOMPARE(mAutoFocusControl->mode(), CxeAutoFocusControl::Macro); |
|
409 |
|
410 } |
|
411 |
|
412 void UnitTestCxeAutoFocusControlSymbian::testHandleSettingValueChanged() |
|
413 { |
|
414 // Autofocus mode needs to be updated when face trackin is actived in |
|
415 // scene mod which doesn't support facetracking |
|
416 |
|
417 QVariant on = QVariant(1); |
|
418 QVariant off = QVariant(0); |
|
419 |
|
420 // 1) check that mode does not change when some other setting value |
|
421 // than face tracking is given |
|
422 mAutoFocusControl->handleSettingValueChanged(CxeSettingIds::LIGHT_SENSITIVITY, on); |
|
423 QCOMPARE(mAutoFocusControl->mode(), CxeAutoFocusControl::Hyperfocal); |
|
424 |
|
425 // 2) check turning facetracking on, when mode is fixed |
|
426 mAutoFocusControl->setMode(CxeAutoFocusControl::Infinity); |
|
427 mAutoFocusControl->handleSettingValueChanged(CxeSettingIds::FACE_TRACKING, on); |
|
428 QCOMPARE(mAutoFocusControl->mode(), CxeAutoFocusControl::Auto); |
|
429 QCOMPARE(mAutoFocusControl->mFaceTrackingOverride, true); |
|
430 |
|
431 // 3) check turning facetracking off will return the previous mode |
|
432 mAutoFocusControl->handleSettingValueChanged(CxeSettingIds::FACE_TRACKING, off); |
|
433 QCOMPARE(mAutoFocusControl->mode(), CxeAutoFocusControl::Infinity); |
|
434 QCOMPARE(mAutoFocusControl->mFaceTrackingOverride, false); |
|
435 |
|
436 // 4) check that turning facetracking off, when it is not on, won't |
|
437 // set the previous mode |
|
438 mAutoFocusControl->setMode(CxeAutoFocusControl::Macro); |
|
439 mAutoFocusControl->handleSettingValueChanged(CxeSettingIds::FACE_TRACKING, off); |
|
440 QCOMPARE(mAutoFocusControl->mode(), CxeAutoFocusControl::Macro); |
|
441 QCOMPARE(mAutoFocusControl->mFaceTrackingOverride, false); |
|
442 |
|
443 |
|
444 } |
|
445 |
132 |
446 |
133 |
447 |
134 // main() function - Need event loop for waiting signals, |
448 // main() function - Need event loop for waiting signals, |
135 // so can't use QTEST_APPLESS_MAIN. |
449 // so can't use QTEST_APPLESS_MAIN. |
136 QTEST_MAIN(UnitTestCxeAutoFocusControlSymbian); |
450 QTEST_MAIN(UnitTestCxeAutoFocusControlSymbian); |