|
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 |
|
19 #include "cxeerror.h" |
|
20 #include "e32err.h" |
|
21 #include "cxenamespace.h" |
|
22 #include "cxesettingsmodelimp.h" |
|
23 #include "cxefakesettingsstore.h" |
|
24 #include "unittest_cxesettingsmodelimp.h" |
|
25 |
|
26 // constants |
|
27 static const char* INVALID_KEY = "invalid key"; |
|
28 static const char* EMPTY_KEY = ""; |
|
29 |
|
30 UnitTestCxeSettingsModelImp::UnitTestCxeSettingsModelImp() |
|
31 { |
|
32 } |
|
33 |
|
34 UnitTestCxeSettingsModelImp::~UnitTestCxeSettingsModelImp() |
|
35 { |
|
36 } |
|
37 |
|
38 // Run before each individual test case |
|
39 void UnitTestCxeSettingsModelImp::init() |
|
40 { |
|
41 CxeSettingsStore *fakeSettingsStore = new CxeFakeSettingsStore(); |
|
42 mSettingsModel = new CxeSettingsModelImp(fakeSettingsStore); |
|
43 } |
|
44 |
|
45 // Run after each individual test case |
|
46 void UnitTestCxeSettingsModelImp::cleanup() |
|
47 { |
|
48 delete mSettingsModel; |
|
49 mSettingsModel = NULL; |
|
50 } |
|
51 |
|
52 // test case to test Setting Values |
|
53 // 1. default values of setting keys |
|
54 // 2. set values to setting keys |
|
55 // 3. checking if set values are set correctly |
|
56 // 4. covers also cases where we test with invalid cases |
|
57 void UnitTestCxeSettingsModelImp::testSettingValues() |
|
58 { |
|
59 CxeError::Id error; |
|
60 QVariant result; |
|
61 |
|
62 // case 0: check default value of a real setting for e.g. FNAME_IMAGE_COUNTER |
|
63 error = mSettingsModel->getSettingValue(CxeSettingIds::FNAME_IMAGE_COUNTER, result); |
|
64 QVERIFY(error == CxeError::None); |
|
65 QCOMPARE(result.toInt(), 0); |
|
66 |
|
67 // case 1: setting a value to a valid key |
|
68 error = mSettingsModel->set(CxeSettingIds::FNAME_IMAGE_COUNTER, 12); |
|
69 QVERIFY(error == CxeError::None); |
|
70 |
|
71 // case 2: testing if the value set is right to sharpness key |
|
72 error = mSettingsModel->getSettingValue(CxeSettingIds::FNAME_IMAGE_COUNTER, result); |
|
73 QVERIFY(error == CxeError::None); |
|
74 QCOMPARE(result.toInt(), 12); |
|
75 |
|
76 // case 3: trying to set a value to an invalid key which doesnt exit |
|
77 error = mSettingsModel->set(INVALID_KEY, QVariant(10)); |
|
78 QVERIFY(error == CxeError::NotFound); |
|
79 |
|
80 // case 4: trying to get a value from invalid key |
|
81 error = mSettingsModel->getSettingValue(INVALID_KEY, result); |
|
82 QVERIFY(error == CxeError::NotFound); |
|
83 |
|
84 // case 5: try with an empty string |
|
85 error = mSettingsModel->set(EMPTY_KEY, QVariant(10)); |
|
86 QVERIFY(error == CxeError::NotFound); |
|
87 |
|
88 // case 6: try with an empty string |
|
89 error = mSettingsModel->getSettingValue(EMPTY_KEY, result); |
|
90 QVERIFY(error == CxeError::NotFound); |
|
91 } |
|
92 |
|
93 // test case to test RuntimeKeys |
|
94 // 1. default values of runtime keys |
|
95 // 2. try set values to runtime keys |
|
96 // 3. covers also cases where we test with invalid cases |
|
97 void UnitTestCxeSettingsModelImp::testRuntimeValues() |
|
98 { |
|
99 CxeError::Id error; |
|
100 QVariant result; |
|
101 QVariantList values; |
|
102 |
|
103 // case 1: check the default value of runtime |
|
104 error = mSettingsModel->getRuntimeValue(CxeRuntimeKeys::PRIMARY_CAMERA_CAPTURE_KEYS, result); |
|
105 QVERIFY(error == CxeError::None); |
|
106 // checking value |
|
107 if( error == CxeError::None ) { |
|
108 values = qVariantValue<QList<QVariant> >(result); |
|
109 QCOMPARE(values[0].toInt(), 1); |
|
110 } |
|
111 |
|
112 // case 2: trying to get a value from invalid key |
|
113 error = mSettingsModel->getRuntimeValue(INVALID_KEY, result); |
|
114 QVERIFY(error == CxeError::NotFound); |
|
115 |
|
116 // case 3: trying to set a value to a runtime key |
|
117 error = mSettingsModel->set(CxeRuntimeKeys::PRIMARY_CAMERA_CAPTURE_KEYS, 10); |
|
118 QVERIFY(error == CxeError::NotFound); |
|
119 |
|
120 // case 4: try with an empty string |
|
121 error = mSettingsModel->set(EMPTY_KEY, 10); |
|
122 QVERIFY(error == CxeError::NotFound); |
|
123 |
|
124 // case 5: try with an empty string |
|
125 error = mSettingsModel->getRuntimeValue(EMPTY_KEY, result); |
|
126 QVERIFY(error == CxeError::NotFound); |
|
127 |
|
128 } |
|
129 |
|
130 |
|
131 // test case to test Image scene Setting Values |
|
132 // 1. default values of setting keys |
|
133 // 2. set values to setting keys |
|
134 // 3. checking if set values are set correctly |
|
135 // 4. covers also cases where we test with invalid cases |
|
136 void UnitTestCxeSettingsModelImp::testImageSceneSettingValues() |
|
137 { |
|
138 CxeError::Id error; |
|
139 QVariant result; |
|
140 // testing for image mode settings |
|
141 mSettingsModel->cameraModeChanged(Cxe::ImageMode); |
|
142 |
|
143 // case 0: check sharpness default value |
|
144 error = mSettingsModel->getSettingValue(CxeSettingIds::SHARPNESS, result); |
|
145 QVERIFY(error == CxeError::None); |
|
146 QCOMPARE(result.toInt(), 0); |
|
147 |
|
148 // case 1: setting a value to a valid key |
|
149 error = mSettingsModel->set(CxeSettingIds::SHARPNESS, 100); |
|
150 QVERIFY(error == CxeError::None); |
|
151 |
|
152 // case 2: testing if the value set is right to sharpness key |
|
153 error = mSettingsModel->getSettingValue(CxeSettingIds::SHARPNESS, result); |
|
154 QVERIFY(error == CxeError::None); |
|
155 QCOMPARE(result.toInt(), 100); |
|
156 |
|
157 // case 3: trying to set a value to an invalid key which doesnt exit |
|
158 error = mSettingsModel->set(INVALID_KEY, 10); |
|
159 QVERIFY(error == CxeError::NotFound); |
|
160 |
|
161 // case 4: trying to get a value from invalid key |
|
162 error = mSettingsModel->getSettingValue(INVALID_KEY, result); |
|
163 QVERIFY(error == CxeError::NotFound); |
|
164 |
|
165 // case 5: try with an empty string |
|
166 error = mSettingsModel->set(EMPTY_KEY, 10); |
|
167 QVERIFY(error == CxeError::NotFound); |
|
168 |
|
169 // case 6: try with an empty string |
|
170 error = mSettingsModel->getSettingValue(EMPTY_KEY, result); |
|
171 QVERIFY(error == CxeError::NotFound); |
|
172 } |
|
173 |
|
174 |
|
175 // test case to test Image scene Setting Values |
|
176 // 1. default values of setting keys |
|
177 // 2. set values to setting keys |
|
178 // 3. checking if set values are set correctly |
|
179 // 4. covers also cases where we test with invalid cases |
|
180 void UnitTestCxeSettingsModelImp::testVideoSceneSettingValues() |
|
181 { |
|
182 CxeError::Id error; |
|
183 QVariant result; |
|
184 // testing for image mode settings |
|
185 mSettingsModel->cameraModeChanged(Cxe::VideoMode); |
|
186 |
|
187 // case 0: check colortone default value |
|
188 error = mSettingsModel->getSettingValue(CxeSettingIds::COLOR_TONE, result); |
|
189 QVERIFY(error == CxeError::None); |
|
190 QVERIFY(result.toInt() == Cxe::ColortoneNormal); |
|
191 |
|
192 error = mSettingsModel->set(CxeSettingIds::COLOR_TONE, Cxe::ColortoneNegative); |
|
193 QVERIFY(error == CxeError::None); |
|
194 |
|
195 // case 2: testing if the value set to invalid sharpness key |
|
196 error = mSettingsModel->getSettingValue(CxeSettingIds::COLOR_TONE, result); |
|
197 QVERIFY(error == CxeError::None); |
|
198 QVERIFY(result.toInt() == Cxe::ColortoneNegative); |
|
199 |
|
200 // case 1: setting a value to a invalid key |
|
201 error = mSettingsModel->set(CxeSettingIds::SHARPNESS, 100); |
|
202 QVERIFY(error == CxeError::NotFound); |
|
203 |
|
204 // case 2: testing if the value set to invalid sharpness key |
|
205 error = mSettingsModel->getSettingValue(CxeSettingIds::SHARPNESS, result); |
|
206 QVERIFY(error == CxeError::NotFound); |
|
207 |
|
208 |
|
209 // case 3: trying to set a value to an invalid key which doesnt exit |
|
210 error = mSettingsModel->set(INVALID_KEY, 10); |
|
211 QVERIFY(error == CxeError::NotFound); |
|
212 |
|
213 // case 4: trying to get a value from invalid key |
|
214 error = mSettingsModel->getSettingValue(INVALID_KEY, result); |
|
215 QVERIFY(error == CxeError::NotFound); |
|
216 |
|
217 // case 5: try with an empty string |
|
218 error = mSettingsModel->set(EMPTY_KEY, 10); |
|
219 QVERIFY(error == CxeError::NotFound); |
|
220 |
|
221 // case 6: try with an empty string |
|
222 error = mSettingsModel->getSettingValue(EMPTY_KEY, result); |
|
223 QVERIFY(error == CxeError::NotFound); |
|
224 } |
|
225 |
|
226 |
|
227 |
|
228 // test case to test ImageScene |
|
229 // 1. default values of image scene |
|
230 // 2. try set new image scene and checking if its succesful |
|
231 // 3. covers also cases where we test with invalid cases |
|
232 void UnitTestCxeSettingsModelImp::testImageScene() |
|
233 { |
|
234 CxeScene result; |
|
235 CxeError::Id error; |
|
236 // case 1: check the default image scene sharpness value |
|
237 result = mSettingsModel->currentImageScene(); |
|
238 QVERIFY(result[CxeSettingIds::SCENE_ID] == CxeSettingIds::IMAGE_SCENE_AUTO); |
|
239 QVERIFY(result[CxeSettingIds::SHARPNESS] == Cxe::SharpnessNormal); |
|
240 |
|
241 QString key = CxeSettingIds::IMAGE_SCENE_PORTRAIT; |
|
242 |
|
243 // case 2: trying to set a new image scene |
|
244 error = mSettingsModel->setImageScene(key); |
|
245 QVERIFY(error == CxeError::None); |
|
246 |
|
247 // case 3: testing if NIGHT image scene is set correctly. checking its sharpness value |
|
248 result = mSettingsModel->currentImageScene(); |
|
249 QVERIFY(result[CxeSettingIds::SCENE_ID] == key); |
|
250 QVERIFY(result[CxeSettingIds::SHARPNESS] == Cxe::SharpnessSoft); |
|
251 |
|
252 // case 3: trying to set a image scene with invalid value |
|
253 error = mSettingsModel->setImageScene(INVALID_KEY); |
|
254 QVERIFY(error == CxeError::NotFound); |
|
255 |
|
256 // case 4: try with an empty string |
|
257 error = mSettingsModel->setImageScene(EMPTY_KEY); |
|
258 QVERIFY(error == CxeError::NotFound); |
|
259 |
|
260 } |
|
261 |
|
262 |
|
263 // test case to test VideoScene |
|
264 // 1. default values of video scene |
|
265 // 2. try set new video scene and checking if its succesful |
|
266 // 3. covers also cases where we test with invalid cases |
|
267 void UnitTestCxeSettingsModelImp::testVideoScene() |
|
268 { |
|
269 CxeScene result; |
|
270 CxeError::Id error; |
|
271 // case 1: check the default image scene |
|
272 result = mSettingsModel->currentVideoScene(); |
|
273 QVERIFY(result[CxeSettingIds::SCENE_ID] == CxeSettingIds::VIDEO_SCENE_AUTO); |
|
274 QVERIFY(result[CxeSettingIds::FRAME_RATE] == 0); |
|
275 |
|
276 QString key = CxeSettingIds::VIDEO_SCENE_LOWLIGHT; |
|
277 |
|
278 // case 2: trying to set a new image scene |
|
279 error = mSettingsModel->setVideoScene(key); |
|
280 QVERIFY(error == CxeError::None); |
|
281 |
|
282 // case 3: testing if NIGHT image scene is set correctly |
|
283 result = mSettingsModel->currentVideoScene(); |
|
284 QVERIFY(result[CxeSettingIds::SCENE_ID] == key); |
|
285 QVERIFY(result[CxeSettingIds::FRAME_RATE] == 15); |
|
286 |
|
287 // case 3: trying to set a image scene with invalid value |
|
288 error = mSettingsModel->setVideoScene(INVALID_KEY); |
|
289 QVERIFY(error == CxeError::NotFound); |
|
290 |
|
291 // case 4: try with an empty string |
|
292 error = mSettingsModel->setVideoScene(EMPTY_KEY); |
|
293 QVERIFY(error == CxeError::NotFound); |
|
294 |
|
295 } |
|
296 |
|
297 |
|
298 // main() function non-GUI testing |
|
299 QTEST_APPLESS_MAIN(UnitTestCxeSettingsModelImp) |
|
300 ; |