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 <QDebug> |
|
19 #include <QSignalSpy> |
|
20 #include <QMetaType> |
|
21 |
|
22 #include "cxutils.h" |
|
23 #include "cxetestutils.h" |
|
24 #include "cxefakesettingsstore.h" |
|
25 #include "unittest_cxesettingsimp.h" |
|
26 #include "cxecenrepkeys.h" |
|
27 |
|
28 const char* FAIL_TEST_SETTING = "Fail test"; |
|
29 const char* EMPTY_STRING = ""; |
|
30 const int CAMERA_MODE_STILL = 0; |
|
31 const int CAMERA_MODE_VIDEO = 1; |
|
32 //Default EV compensation value for auto still and auto video scene mode |
|
33 const int SCENE_AUTO_EV_VALUE = 0; |
|
34 const int SIGNAL_TIMEOUT = 3000; //milliseconds |
|
35 |
|
36 UnitTestCxeSettingsImp::UnitTestCxeSettingsImp() : |
|
37 mSettingsImp(NULL), mSettingsStore(NULL) |
|
38 { |
|
39 qRegisterMetaType<CxeScene>("CxeScene"); |
|
40 qRegisterMetaType<CxeError::Id>("CxeError::Id"); |
|
41 qRegisterMetaType<Cxe::CameraMode>("Cxe::CameraMode"); |
|
42 } |
|
43 |
|
44 UnitTestCxeSettingsImp::~UnitTestCxeSettingsImp() |
|
45 { |
|
46 } |
|
47 |
|
48 void UnitTestCxeSettingsImp::init() |
|
49 { |
|
50 mSettingsStore = new CxeFakeSettingsStore(); |
|
51 mSettingsImp = new CxeSettingsImp(mSettingsStore); |
|
52 } |
|
53 |
|
54 void UnitTestCxeSettingsImp::cleanup() |
|
55 { |
|
56 delete mSettingsImp; |
|
57 mSettingsImp = NULL; |
|
58 } |
|
59 |
|
60 /* |
|
61 * Testing loadSettings() with Cxe::ImageMode argument |
|
62 */ |
|
63 void UnitTestCxeSettingsImp::testLoadImageSettings() |
|
64 { |
|
65 CX_DEBUG_ENTER_FUNCTION(); |
|
66 QSignalSpy spy(mSettingsImp, SIGNAL(settingValueChanged(QString,QVariant))); |
|
67 mSettingsImp->loadSettings(Cxe::ImageMode); |
|
68 |
|
69 //signal should be emitted when loading settings |
|
70 QVERIFY(spy.count() > 0); |
|
71 |
|
72 //now let's take a look inside a signal content |
|
73 QList<QVariant> arguments = spy.takeFirst(); |
|
74 QVERIFY(arguments.at(0).toString().toAscii() == CxeSettingIds::IMAGE_SCENE); |
|
75 CX_DEBUG_EXIT_FUNCTION(); |
|
76 } |
|
77 |
|
78 /* |
|
79 * Testing loadSettings() with Cxe::VideoMode argument |
|
80 */ |
|
81 void UnitTestCxeSettingsImp::testLoadVideoSettings() |
|
82 { |
|
83 CX_DEBUG_ENTER_FUNCTION(); |
|
84 QSignalSpy spy(mSettingsImp, SIGNAL(settingValueChanged(QString,QVariant))); |
|
85 mSettingsImp->loadSettings(Cxe::VideoMode); |
|
86 |
|
87 //signal should be emitted when loading settings |
|
88 QVERIFY(spy.count() > 0); |
|
89 |
|
90 //now let's take a look inside a signal content |
|
91 QList<QVariant> arguments = spy.takeFirst(); |
|
92 QVERIFY(arguments.at(0).toString().toAscii() == CxeSettingIds::VIDEO_SCENE); |
|
93 |
|
94 CX_DEBUG_EXIT_FUNCTION(); |
|
95 } |
|
96 |
|
97 /* |
|
98 * Advanced test case for loadSettings() |
|
99 */ |
|
100 void UnitTestCxeSettingsImp::testLoadImageAndVideoSettings() |
|
101 { |
|
102 CX_DEBUG_ENTER_FUNCTION(); |
|
103 QSignalSpy spy(mSettingsImp, SIGNAL(settingValueChanged(QString,QVariant))); |
|
104 mSettingsImp->loadSettings(Cxe::VideoMode); |
|
105 |
|
106 //signal should be emitted when loading settings |
|
107 QVERIFY(spy.count() > 0); |
|
108 |
|
109 //now let's take a look inside a signal content |
|
110 QList<QVariant> arguments = spy.takeFirst(); |
|
111 QVERIFY(arguments.at(0).toString().toAscii() == CxeSettingIds::VIDEO_SCENE); |
|
112 spy.clear(); |
|
113 |
|
114 mSettingsImp->loadSettings(Cxe::ImageMode); |
|
115 |
|
116 //signal should be emitted when loading settings |
|
117 QVERIFY(spy.count() > 0); |
|
118 |
|
119 //now let's take a look inside a signal content |
|
120 arguments = spy.takeFirst(); |
|
121 QVERIFY(arguments.at(0).toString().toAscii() == CxeSettingIds::IMAGE_SCENE); |
|
122 |
|
123 CX_DEBUG_EXIT_FUNCTION(); |
|
124 } |
|
125 |
|
126 /* |
|
127 * Testing inline get(const QString &key) |
|
128 * defined in cxesettings.h as template |
|
129 */ |
|
130 void UnitTestCxeSettingsImp::testGet() |
|
131 { |
|
132 CX_DEBUG_ENTER_FUNCTION(); |
|
133 CxeError::Id err = CxeError::None; |
|
134 |
|
135 // The idea of this test case is to test as much of different type of settings |
|
136 // as possible |
|
137 |
|
138 // Testing reading brightness setting value |
|
139 int brightnessValue; |
|
140 QVariant testValue; |
|
141 |
|
142 try { |
|
143 brightnessValue = mSettingsImp->CxeSettings::get<int>(CxeSettingIds::BRIGHTNESS); |
|
144 } |
|
145 catch (CxeException exception) { |
|
146 QString message = "Exception thrown, error id = "; |
|
147 message.append(exception.error()); |
|
148 QFAIL(message.toAscii()); |
|
149 return; |
|
150 } |
|
151 |
|
152 mSettingsStore->get(CxeSettingIds::BRIGHTNESS, testValue); |
|
153 QCOMPARE(brightnessValue, testValue.toInt()); |
|
154 |
|
155 // Testing reading color tone setting value |
|
156 Cxe::Colortone colorTone; |
|
157 try { |
|
158 colorTone = mSettingsImp->CxeSettings::get<Cxe::Colortone>(CxeSettingIds::COLOR_TONE); |
|
159 } |
|
160 catch (CxeException exception) { |
|
161 QString message = "Exception thrown, error id = "; |
|
162 message.append(exception.error()); |
|
163 QFAIL(message.toAscii()); |
|
164 return; |
|
165 } |
|
166 |
|
167 QVariant colorTone2; |
|
168 mSettingsStore->get(CxeSettingIds::COLOR_TONE, colorTone2); |
|
169 QVERIFY(colorTone2 == colorTone); |
|
170 |
|
171 // Testing reading contrast setting value |
|
172 int contrastValue; |
|
173 try { |
|
174 contrastValue = mSettingsImp->CxeSettings::get<int>(CxeSettingIds::CONTRAST); |
|
175 } |
|
176 catch (CxeException exception) { |
|
177 QString message = "Exception thrown, error id = "; |
|
178 message.append(exception.error()); |
|
179 QFAIL(message.toAscii()); |
|
180 return; |
|
181 } |
|
182 |
|
183 mSettingsStore->get(CxeSettingIds::CONTRAST, testValue); |
|
184 QCOMPARE(testValue.toInt(), contrastValue); |
|
185 |
|
186 // Testing reading file name folder suffix setting value |
|
187 QString fnameValue; |
|
188 try { |
|
189 fnameValue = mSettingsImp->CxeSettings::get<QString>(CxeSettingIds::FNAME_FOLDER_SUFFIX); |
|
190 } |
|
191 catch (CxeException exception) { |
|
192 QString message = "Exception thrown, error id = "; |
|
193 message.append(exception.error()); |
|
194 QFAIL(message.toAscii()); |
|
195 return; |
|
196 } |
|
197 |
|
198 mSettingsStore->get(CxeSettingIds::FNAME_FOLDER_SUFFIX, testValue); |
|
199 QCOMPARE(testValue.toString(), fnameValue); |
|
200 |
|
201 // Testing reading scene data |
|
202 QVariantMap sceneData; |
|
203 |
|
204 // First set the still camera scene to auto |
|
205 mSettingsStore->set(CxeSettingIds::IMAGE_SCENE, Cxe::IMAGE_SCENE_AUTO); |
|
206 |
|
207 try { |
|
208 sceneData = mSettingsImp->CxeSettings::get<QVariantMap>(CxeSettingIds::IMAGE_SCENE_DATA); |
|
209 } |
|
210 catch (CxeException exception) { |
|
211 QString message = "Exception thrown, error id = "; |
|
212 message.append(exception.error()); |
|
213 QFAIL(message.toAscii()); |
|
214 return; |
|
215 } |
|
216 |
|
217 QCOMPARE(sceneData[CxeSettingIds::EV_COMPENSATION_VALUE].toInt(), SCENE_AUTO_EV_VALUE); |
|
218 |
|
219 // Now let's try same with video scene |
|
220 sceneData.clear(); |
|
221 mSettingsStore->set(CxeSettingIds::VIDEO_SCENE, Cxe::VIDEO_SCENE_AUTO); |
|
222 try { |
|
223 sceneData = mSettingsImp->CxeSettings::get<QVariantMap>(CxeSettingIds::VIDEO_SCENE_DATA); |
|
224 } |
|
225 catch (CxeException exception) { |
|
226 QString message = "Exception thrown, error id = "; |
|
227 message.append(exception.error()); |
|
228 QFAIL(message.toAscii()); |
|
229 return; |
|
230 } |
|
231 |
|
232 QCOMPARE(sceneData[CxeSettingIds::EV_COMPENSATION_VALUE].toInt(), SCENE_AUTO_EV_VALUE); |
|
233 |
|
234 CX_DEBUG_EXIT_FUNCTION(); |
|
235 } |
|
236 |
|
237 /* |
|
238 * Testing get(long int uid, |
|
239 * unsigned long int key, |
|
240 * Cxe::SettingKeyType type, |
|
241 * QVariant &value) |
|
242 */ |
|
243 void UnitTestCxeSettingsImp::testGet2() |
|
244 { |
|
245 CX_DEBUG_ENTER_FUNCTION(); |
|
246 QVariant value; |
|
247 |
|
248 mSettingsImp->get(CxSettingsCrUid, FileNameSuffixCr, Cxe::Repository, value); |
|
249 // 42 is just a test value from cxefakesettingsstore |
|
250 // we just check that it is correctly returned |
|
251 QCOMPARE(value.toInt(), 42); |
|
252 |
|
253 mSettingsImp->get(0, 0, Cxe::PublishAndSubscribe, value); |
|
254 // 42 is just a test value from cxefakesettingsstore |
|
255 // we just check that it is correctly returned |
|
256 QCOMPARE(value.toInt(), 42); |
|
257 CX_DEBUG_EXIT_FUNCTION(); |
|
258 } |
|
259 |
|
260 /* |
|
261 * Testing get(const QString &key, const T &defaultValue) |
|
262 * defined in cxesettings.h as template |
|
263 */ |
|
264 void UnitTestCxeSettingsImp::testGet3() |
|
265 { |
|
266 CX_DEBUG_ENTER_FUNCTION(); |
|
267 Cxe::Colortone defaultTone = Cxe::ColortoneNormal; |
|
268 mSettingsStore->set(CxeSettingIds::COLOR_TONE, Cxe::ColortoneVivid); |
|
269 Cxe::Colortone colorTone = mSettingsImp->CxeSettings::get<Cxe::Colortone>( |
|
270 CxeSettingIds::COLOR_TONE, defaultTone); |
|
271 QVERIFY(colorTone == Cxe::ColortoneVivid); |
|
272 |
|
273 // Now when using this version of the overloaded get<int>() |
|
274 // with invalid key parameter, it should internally |
|
275 // catch the exception and not modify the default value |
|
276 int defaultValue = 0; |
|
277 int value = mSettingsImp->CxeSettings::get<int>( |
|
278 FAIL_TEST_SETTING, defaultValue); |
|
279 QVERIFY(value == defaultValue); |
|
280 CX_DEBUG_EXIT_FUNCTION(); |
|
281 } |
|
282 |
|
283 /* |
|
284 * Testing inputting some garbage into CxeSettingsImp::get() |
|
285 */ |
|
286 void UnitTestCxeSettingsImp::testGetGarbage() |
|
287 { |
|
288 CX_DEBUG_ENTER_FUNCTION(); |
|
289 int intTestValue = 0; |
|
290 CxeError::Id errorId; |
|
291 |
|
292 try { |
|
293 mSettingsImp->CxeSettings::get<int>(EMPTY_STRING, intTestValue); |
|
294 } |
|
295 catch (CxeException exception) { |
|
296 QString message = "Exception thrown, error id = "; |
|
297 message.append(exception.error()); |
|
298 errorId = CxeError::Id(exception.error()); |
|
299 QCOMPARE(errorId, CxeError::NotFound); |
|
300 } |
|
301 |
|
302 try { |
|
303 mSettingsImp->CxeSettings::get<int>(FAIL_TEST_SETTING, intTestValue); |
|
304 } |
|
305 catch (CxeException exception) { |
|
306 QString message = "Exception thrown, error id = "; |
|
307 message.append(exception.error()); |
|
308 errorId = CxeError::Id(exception.error()); |
|
309 QCOMPARE(errorId, CxeError::NotFound); |
|
310 } |
|
311 |
|
312 CX_DEBUG_EXIT_FUNCTION(); |
|
313 } |
|
314 |
|
315 /* |
|
316 * Testing inline void set(const QString &key, const T &value) |
|
317 * defined in cxesettings.h |
|
318 */ |
|
319 void UnitTestCxeSettingsImp::testSet() |
|
320 { |
|
321 CX_DEBUG_ENTER_FUNCTION(); |
|
322 |
|
323 // Point of this test case is to try all versions of the set() |
|
324 // method defined in cxesettings.inl |
|
325 |
|
326 // Testing set<int>() version |
|
327 QVariant value; |
|
328 try { |
|
329 mSettingsImp->set(CxeSettingIds::COLOR_TONE, Cxe::ColortoneBlackAndWhite); |
|
330 } |
|
331 catch (CxeException exception) { |
|
332 QString message = "Exception thrown, error id = "; |
|
333 message.append(exception.error()); |
|
334 QFAIL(message.toAscii()); |
|
335 return; |
|
336 } |
|
337 mSettingsStore->get(CxeSettingIds::COLOR_TONE, value); |
|
338 QCOMPARE(value.toInt(), (int)Cxe::ColortoneBlackAndWhite); |
|
339 |
|
340 // Testing set<QString>() version |
|
341 QString stringValue = "some text"; |
|
342 try { |
|
343 mSettingsImp->set(CxeSettingIds::FNAME_FOLDER_SUFFIX, stringValue); |
|
344 } |
|
345 catch (CxeException exception) { |
|
346 QString message = "Exception thrown, error id = "; |
|
347 message.append(exception.error()); |
|
348 QFAIL(message.toAscii()); |
|
349 return; |
|
350 } |
|
351 mSettingsStore->get(CxeSettingIds::FNAME_FOLDER_SUFFIX, value); |
|
352 QCOMPARE(value.toString(), stringValue); |
|
353 |
|
354 // Testing set<bool>() version |
|
355 bool boolValue = true; |
|
356 try { |
|
357 mSettingsImp->set(CxeSettingIds::STILL_SHOWCAPTURED, boolValue); |
|
358 } |
|
359 catch (CxeException exception) { |
|
360 QString message = "Exception thrown, error id = "; |
|
361 message.append(exception.error()); |
|
362 QFAIL(message.toAscii()); |
|
363 return; |
|
364 } |
|
365 mSettingsStore->get(CxeSettingIds::STILL_SHOWCAPTURED, value); |
|
366 QCOMPARE(value.toBool(), boolValue); |
|
367 |
|
368 // Testing set<qreal>() version |
|
369 qreal qrealValue = -1.25; |
|
370 try { |
|
371 mSettingsImp->set(CxeSettingIds::EV_COMPENSATION_VALUE, qrealValue); |
|
372 } |
|
373 catch (CxeException exception) { |
|
374 QString message = "Exception thrown, error id = "; |
|
375 message.append(exception.error()); |
|
376 QFAIL(message.toAscii()); |
|
377 return; |
|
378 } |
|
379 mSettingsStore->get(CxeSettingIds::EV_COMPENSATION_VALUE, value); |
|
380 QCOMPARE(value.toReal(), qrealValue); |
|
381 |
|
382 // Testing set<QVariantMap>() version |
|
383 CxeScene testSceneData; |
|
384 |
|
385 testSceneData.insert(CxeSettingIds::SCENE_ID, Cxe::IMAGE_SCENE_AUTO); |
|
386 testSceneData.insert(CxeSettingIds::WHITE_BALANCE, Cxe::WhitebalanceAutomatic); |
|
387 testSceneData.insert(CxeSettingIds::EXPOSURE_MODE, Cxe::ExposureAuto); |
|
388 testSceneData.insert(CxeSettingIds::COLOR_TONE, Cxe::ColortoneNormal); |
|
389 testSceneData.insert(CxeSettingIds::CONTRAST, 5); |
|
390 testSceneData.insert(CxeSettingIds::SHARPNESS, Cxe::SharpnessNormal); |
|
391 testSceneData.insert(CxeSettingIds::LIGHT_SENSITIVITY, Cxe::LightSensitivityAutomatic); |
|
392 testSceneData.insert(CxeSettingIds::EV_COMPENSATION_VALUE, -2); |
|
393 testSceneData.insert(CxeSettingIds::BRIGHTNESS, 8); |
|
394 testSceneData.insert(CxeSettingIds::FLASH_MODE, Cxe::FlashAuto); |
|
395 testSceneData.insert(CxeSettingIds::FACE_TRACKING, 1); |
|
396 |
|
397 // First set the still camera scene to auto |
|
398 mSettingsStore->set(CxeSettingIds::IMAGE_SCENE, Cxe::IMAGE_SCENE_AUTO); |
|
399 |
|
400 // Now setting the value |
|
401 try { |
|
402 //This should throw an exception with CxeError::NotSupported |
|
403 mSettingsImp->set(CxeSettingIds::IMAGE_SCENE_DATA, testSceneData); |
|
404 } |
|
405 catch (CxeException exception) { |
|
406 QString message = "Exception thrown, error id = "; |
|
407 message.append((int)exception.error()); |
|
408 QCOMPARE(exception.error(), (int)CxeError::NotSupported); |
|
409 } |
|
410 |
|
411 CX_DEBUG_EXIT_FUNCTION(); |
|
412 } |
|
413 |
|
414 /* |
|
415 * This will test calling void method of reset() |
|
416 */ |
|
417 void UnitTestCxeSettingsImp::testReset() |
|
418 { |
|
419 CX_DEBUG_ENTER_FUNCTION(); |
|
420 mSettingsImp->reset(); |
|
421 CX_DEBUG_EXIT_FUNCTION(); |
|
422 } |
|
423 |
|
424 void UnitTestCxeSettingsImp::testGetVariationSetting() |
|
425 { |
|
426 CX_DEBUG_ENTER_FUNCTION(); |
|
427 QVariant value; |
|
428 CxeError::Id error = mSettingsImp->getVariationValue(CxeVariationKeys::STILL_MAX_ZOOM_LIMITS, value); |
|
429 QCOMPARE(error, CxeError::None); |
|
430 |
|
431 error = mSettingsImp->getVariationValue(FAIL_TEST_SETTING, value); |
|
432 QCOMPARE(error, CxeError::NotFound); |
|
433 CX_DEBUG_EXIT_FUNCTION(); |
|
434 } |
|
435 |
|
436 void UnitTestCxeSettingsImp::testListenForSetting() |
|
437 { |
|
438 CX_DEBUG_ENTER_FUNCTION(); |
|
439 |
|
440 // This test case will initialize listening for certain setting changes |
|
441 // and will verify that listener has succesfully deployed the signal |
|
442 |
|
443 // First let's initialize a signal spy |
|
444 QSignalSpy spy(mSettingsImp, SIGNAL(settingValueChanged(QString, QVariant))); |
|
445 |
|
446 // Initializing the original value to make sure it changes later on |
|
447 mSettingsStore->set(CxeSettingIds::CAMERA_MODE, Cxe::ImageMode); |
|
448 |
|
449 // Now start listening and verify that starting was succesfull |
|
450 bool result = mSettingsImp->listenForSetting(CxeSettingIds::CAMERA_MODE, this, SLOT(testSlot())); |
|
451 QVERIFY(result); |
|
452 |
|
453 // Now change the setting and wait for the signal |
|
454 //mSettingsStore->set(CxeSettingIds::CAMERA_MODE, Cxe::VideoMode); |
|
455 mSettingsImp->set(CxeSettingIds::CAMERA_MODE, Cxe::VideoMode); |
|
456 |
|
457 |
|
458 // Check that signal was emitted |
|
459 QVERIFY(CxeTestUtils::waitForSignal(spy, SIGNAL_TIMEOUT)); |
|
460 |
|
461 // One more check with invalid input parameter |
|
462 result = mSettingsImp->listenForSetting(FAIL_TEST_SETTING, this, SLOT(testSlot())); |
|
463 // This should still return true, since the function adds listener to any |
|
464 // setting, regardless if the setting key is valid or not. This is ok. |
|
465 QVERIFY(result); |
|
466 |
|
467 // Now disconnecting the listener and checking if the signal is still emitted |
|
468 disconnect(mSettingsImp, SIGNAL(settingValueChanged(QString,QVariant)), this, SLOT(testSlot())); |
|
469 delete mSettingsImp; |
|
470 mSettingsImp = NULL; |
|
471 |
|
472 CX_DEBUG_EXIT_FUNCTION(); |
|
473 } |
|
474 |
|
475 /* |
|
476 * Just a dummy slot |
|
477 */ |
|
478 void UnitTestCxeSettingsImp::testSlot() |
|
479 { |
|
480 CX_DEBUG_IN_FUNCTION(); |
|
481 } |
|
482 |
|
483 // main() function non-GUI testing |
|
484 QTEST_MAIN(UnitTestCxeSettingsImp) |
|
485 |
|