|
1 /* |
|
2 * Copyright (c) 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: Unit test for satappmainhandler |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QTimer> |
|
19 #include <QAction> |
|
20 |
|
21 #include <hbinputdialog.h> |
|
22 #include <hbmessagebox.h> |
|
23 |
|
24 #include "ut_satappinputprovider.h" |
|
25 #include "satappinputprovider.h" |
|
26 #include "satappaction.h" |
|
27 |
|
28 |
|
29 // -------------------------------------------------------- |
|
30 // The unit tests begin here |
|
31 // -------------------------------------------------------- |
|
32 |
|
33 Ut_SatAppInputProvider::Ut_SatAppInputProvider( |
|
34 QObject *parent) |
|
35 :QObject(parent) |
|
36 { |
|
37 } |
|
38 |
|
39 void Ut_SatAppInputProvider::testResetState() |
|
40 { |
|
41 InputProviderTest test; |
|
42 test.mInput->resetState(); |
|
43 } |
|
44 |
|
45 void Ut_SatAppInputProvider::testGetInkeyAndOk_data() |
|
46 { |
|
47 QTest::addColumn<QString>("text"); |
|
48 QTest::addColumn<int>("charset"); |
|
49 QTest::addColumn<int>("inkey"); |
|
50 |
|
51 QTest::newRow("t01") << "title" << (int)ESatDigitOnly << 0; |
|
52 QTest::newRow("t02") << "title" << (int)ESatCharSmsDefaultAlphabet << 0; |
|
53 QTest::newRow("t03") << "title" << (int)ESatCharUcs2Alphabet << 0; |
|
54 QTest::newRow("t04") << "title" << (int)ESatYesNo << 0; |
|
55 QTest::newRow("t05") << "long title that does not fix to screen" << (int)ESatDigitOnly << 0; |
|
56 QTest::newRow("t06") << "long title that does not fix to screen" << (int)ESatCharSmsDefaultAlphabet << 0; |
|
57 QTest::newRow("t07") << "long title that does not fix to screen" << (int)ESatCharUcs2Alphabet << 0; |
|
58 QTest::newRow("t08") << "long title that does not fix to screen" << (int)ESatYesNo << 0; |
|
59 QTest::newRow("t09") << "" << (int)ESatDigitOnly << 1; |
|
60 QTest::newRow("t10") << "" << (int)ESatCharSmsDefaultAlphabet << 47; |
|
61 QTest::newRow("t11") << "" << (int)ESatCharUcs2Alphabet << 58; |
|
62 QTest::newRow("t12") << "" << (int)ESatYesNo << 0; |
|
63 } |
|
64 |
|
65 void Ut_SatAppInputProvider::testGetInkeyAndOk() |
|
66 { |
|
67 QFETCH(QString, text); |
|
68 QFETCH(int, charset); |
|
69 QFETCH(int, inkey); |
|
70 bool selfExp = false; |
|
71 |
|
72 SatAppAction a(ESatGetInkeyAction); |
|
73 a.set(KeyText,text); |
|
74 a.set(KeyCharacterSet,charset); |
|
75 a.set(KeyInKey,inkey); |
|
76 a.set(KeyImmediate,false); |
|
77 a.set(KeyDuration,10000); |
|
78 |
|
79 InputProviderTest test; |
|
80 test.mInput->getInkey(a); |
|
81 // simulate press OK |
|
82 if( (charset!=ESatYesNo) || (text.length()>0)){ |
|
83 test.simulateFirstActionClicked(); |
|
84 } |
|
85 |
|
86 if (charset==ESatYesNo) { |
|
87 if( text.length()>0 ){ |
|
88 QCOMPARE(a.response(),ESatSuccess); |
|
89 QCOMPARE(a.value(KeyInKey).toInt(),1); |
|
90 } |
|
91 else { |
|
92 QCOMPARE(a.response(),ESatFailure); |
|
93 } |
|
94 |
|
95 } |
|
96 else { |
|
97 QCOMPARE(a.response(),ESatSuccess); |
|
98 } |
|
99 |
|
100 } |
|
101 |
|
102 void Ut_SatAppInputProvider::testGetInkeyAndCancel_data() |
|
103 { |
|
104 // uses same test materil as testGetInkeyAndOk() |
|
105 testGetInkeyAndOk_data(); |
|
106 } |
|
107 |
|
108 void Ut_SatAppInputProvider::testGetInkeyAndCancel() |
|
109 { |
|
110 QFETCH(QString, text); |
|
111 QFETCH(int, charset); |
|
112 QFETCH(int, inkey); |
|
113 bool selfExp = false; |
|
114 |
|
115 SatAppAction a(ESatGetInkeyAction); |
|
116 a.set(KeyText,text); |
|
117 a.set(KeyCharacterSet,charset); |
|
118 a.set(KeyInKey,inkey); |
|
119 a.set(KeyImmediate,false); |
|
120 a.set(KeyDuration,10000); |
|
121 |
|
122 InputProviderTest test; |
|
123 test.mInput->getInkey(a); |
|
124 // simulate press CANCEL |
|
125 if((charset!=ESatYesNo) || (text.length()>0)) { |
|
126 test.simulateSecondActionClicked(); |
|
127 } |
|
128 |
|
129 if (charset==ESatYesNo) { |
|
130 if( text.length()>0 ){ |
|
131 QCOMPARE(a.response(),ESatSuccess); |
|
132 QCOMPARE(a.value(KeyInKey).toInt(),0); |
|
133 } |
|
134 else { |
|
135 QCOMPARE(a.response(),ESatFailure); |
|
136 } } |
|
137 else { |
|
138 QCOMPARE(a.response(),ESatBackwardModeRequestedByUser); |
|
139 } |
|
140 } |
|
141 |
|
142 void Ut_SatAppInputProvider::testGetInkeyAndTimeout() |
|
143 { |
|
144 SatAppAction a(ESatGetInkeyAction); |
|
145 a.set(KeyText,"hello"); |
|
146 a.set(KeyCharacterSet,ESatCharSmsDefaultAlphabet); |
|
147 a.set(KeyInKey,64); |
|
148 a.set(KeyImmediate,false); |
|
149 a.set(KeyDuration,1000); |
|
150 |
|
151 InputProviderTest test; |
|
152 test.mInput->getInkey(a); |
|
153 a.waitUntilCompleted(); |
|
154 |
|
155 QCOMPARE(a.response(),ESatNoResponseFromUser); |
|
156 } |
|
157 |
|
158 void Ut_SatAppInputProvider::testGetInkeyAndReset() |
|
159 { |
|
160 SatAppAction a(ESatGetInkeyAction); |
|
161 a.set(KeyText,"hello"); |
|
162 a.set(KeyCharacterSet,ESatCharSmsDefaultAlphabet); |
|
163 a.set(KeyInKey,64); |
|
164 a.set(KeyImmediate,false); |
|
165 a.set(KeyDuration,10000); |
|
166 a.setResponse(ESatFailure); |
|
167 |
|
168 InputProviderTest test; |
|
169 test.mInput->getInkey(a); |
|
170 test.mInput->resetState(); |
|
171 |
|
172 QCOMPARE(a.response(),ESatNoResponseFromUser); |
|
173 } |
|
174 |
|
175 void Ut_SatAppInputProvider::testGetInkeyAndDelete() |
|
176 { |
|
177 SatAppAction a(ESatGetInkeyAction); |
|
178 a.set(KeyText,"hello"); |
|
179 a.set(KeyCharacterSet,ESatCharSmsDefaultAlphabet); |
|
180 a.set(KeyInKey,64); |
|
181 a.set(KeyImmediate,false); |
|
182 a.set(KeyDuration,10000); |
|
183 a.setResponse(ESatFailure); |
|
184 |
|
185 { |
|
186 InputProviderTest test; |
|
187 test.mInput->getInkey(a); |
|
188 } |
|
189 // at this point everything should be cleaned up safely, and action |
|
190 // should be completed later when application exit or timeout |
|
191 |
|
192 QCOMPARE(a.response(),ESatFailure); |
|
193 } |
|
194 |
|
195 void Ut_SatAppInputProvider::testGetInkeyImmediateAndOk() |
|
196 { |
|
197 SatAppAction a(ESatGetInkeyAction); |
|
198 a.set(KeyText,"hello"); |
|
199 a.set(KeyCharacterSet,ESatDigitOnly); |
|
200 a.set(KeyInKey,64); |
|
201 a.set(KeyImmediate,true); |
|
202 a.set(KeyDuration,10000); |
|
203 a.setResponse(ESatFailure); |
|
204 |
|
205 InputProviderTest test; |
|
206 test.mInput->getInkey(a); |
|
207 test.simulateImmediateKeypress("0"); |
|
208 |
|
209 QCOMPARE(a.response(),ESatSuccess); |
|
210 QCOMPARE(a.value(KeyInKey).toInt(),0x30); |
|
211 } |
|
212 |
|
213 void Ut_SatAppInputProvider::testGetInkeyImmediateAndCancel() |
|
214 { |
|
215 SatAppAction a(ESatGetInkeyAction); |
|
216 a.set(KeyText,"hello"); |
|
217 a.set(KeyCharacterSet,ESatDigitOnly); |
|
218 a.set(KeyInKey,64); |
|
219 a.set(KeyImmediate,true); |
|
220 a.set(KeyDuration,10000); |
|
221 a.setResponse(ESatFailure); |
|
222 |
|
223 InputProviderTest test; |
|
224 test.mInput->getInkey(a); |
|
225 test.simulateFirstActionClicked(); // cancel |
|
226 |
|
227 QCOMPARE(a.response(),ESatBackwardModeRequestedByUser); |
|
228 } |
|
229 |
|
230 void Ut_SatAppInputProvider::testGetInputAndOk_data() |
|
231 { |
|
232 QTest::addColumn<QString>("text"); |
|
233 QTest::addColumn<int>("charset"); |
|
234 QTest::addColumn<QString>("input"); |
|
235 QTest::addColumn<int>("min"); |
|
236 QTest::addColumn<int>("max"); |
|
237 QTest::addColumn<bool>("hide"); |
|
238 |
|
239 QTest::newRow("t01") << "title" << (int)ESatDigitOnly << "" << 1 << 5 << false; |
|
240 QTest::newRow("t02") << "title" << (int)ESatCharSmsDefaultAlphabet << "" << 1 << 5 << false; |
|
241 QTest::newRow("t03") << "title" << (int)ESatCharUcs2Alphabet << "" << 1 << 5 << false; |
|
242 QTest::newRow("t04") << "very long title that does not fit into screen" << (int)ESatDigitOnly << "" << 1 << 5 << false; |
|
243 QTest::newRow("t05") << "very long title that does not fit into screen" << (int)ESatCharSmsDefaultAlphabet << "" << 2 << 8 << false; |
|
244 QTest::newRow("t06") << "very long title that does not fit into screen" << (int)ESatCharUcs2Alphabet << "" << 2 << 8 << false; |
|
245 QTest::newRow("t07") << "title" << (int)ESatDigitOnly << "12345" << 1 << 5 << false; |
|
246 QTest::newRow("t08") << "title" << (int)ESatCharSmsDefaultAlphabet << "12345" << 1 << 5 << false; |
|
247 QTest::newRow("t09") << "title" << (int)ESatCharUcs2Alphabet << "12345" << 1 << 5 << false; |
|
248 QTest::newRow("t10") << "title" << (int)ESatDigitOnly << "12345" << 1 << 5 << true; |
|
249 QTest::newRow("t11") << "title" << (int)ESatCharSmsDefaultAlphabet << "12345" << 1 << 5 << true; |
|
250 QTest::newRow("t12") << "title" << (int)ESatCharUcs2Alphabet << "12345" << 1 << 5 << true; |
|
251 QTest::newRow("t13") << "" << (int)ESatDigitOnly << "" << 1 << 5 << false; |
|
252 QTest::newRow("t14") << "" << (int)ESatCharSmsDefaultAlphabet << "" << 1 << 5 << false; |
|
253 QTest::newRow("t15") << "" << (int)ESatCharUcs2Alphabet << "" << 1 << 5 << false; |
|
254 QTest::newRow("t16") << "" << (int)ESatDigitOnly << "123456789123456789" << 1 << 5 << false; |
|
255 QTest::newRow("t17") << "" << (int)ESatCharSmsDefaultAlphabet << "123456789123456789" << 1 << 5 << false; |
|
256 QTest::newRow("t18") << "" << (int)ESatCharUcs2Alphabet << "123456789123456789" << 1 << 5 << false; |
|
257 |
|
258 } |
|
259 |
|
260 void Ut_SatAppInputProvider::testGetInputAndOk() |
|
261 { |
|
262 QFETCH(QString, text); |
|
263 QFETCH(int, charset); |
|
264 QFETCH(QString, input); |
|
265 QFETCH(int, min); |
|
266 QFETCH(int, max); |
|
267 QFETCH(bool, hide); |
|
268 |
|
269 SatAppAction a(ESatGetInputAction); |
|
270 a.set(KeyText,text); |
|
271 a.set(KeyCharacterSet,charset); |
|
272 a.set(KeyInputString,input); |
|
273 a.set(KeyMinLength,min); |
|
274 a.set(KeyMaxLength,max); |
|
275 a.set(KeyHideInput,hide); |
|
276 a.set(KeyDuration,10000); |
|
277 |
|
278 InputProviderTest test; |
|
279 test.mInput->getInput(a); |
|
280 test.simulateFirstActionClicked(); |
|
281 |
|
282 QCOMPARE(a.response(),ESatSuccess); |
|
283 } |
|
284 |
|
285 void Ut_SatAppInputProvider::testGetInputAndCancel_data() |
|
286 { |
|
287 // uses same test data as testGetInputAndOk |
|
288 testGetInputAndOk_data(); |
|
289 } |
|
290 |
|
291 void Ut_SatAppInputProvider::testGetInputAndCancel() |
|
292 { |
|
293 QFETCH(QString, text); |
|
294 QFETCH(int, charset); |
|
295 QFETCH(QString, input); |
|
296 QFETCH(int, min); |
|
297 QFETCH(int, max); |
|
298 QFETCH(bool, hide); |
|
299 |
|
300 SatAppAction a(ESatGetInputAction); |
|
301 a.set(KeyText,text); |
|
302 a.set(KeyCharacterSet,charset); |
|
303 a.set(KeyInputString,input); |
|
304 a.set(KeyMinLength,min); |
|
305 a.set(KeyMaxLength,max); |
|
306 a.set(KeyHideInput,hide); |
|
307 a.set(KeyDuration,10000); |
|
308 |
|
309 InputProviderTest test; |
|
310 test.mInput->getInput(a); |
|
311 test.simulateSecondActionClicked(); |
|
312 |
|
313 QCOMPARE(a.response(),ESatBackwardModeRequestedByUser); |
|
314 } |
|
315 |
|
316 void Ut_SatAppInputProvider::testGetInputAndTimeout() |
|
317 { |
|
318 SatAppAction a(ESatGetInputAction); |
|
319 a.set(KeyText,"hello"); |
|
320 a.set(KeyCharacterSet,ESatCharSmsDefaultAlphabet); |
|
321 a.set(KeyInputString,"12345"); |
|
322 a.set(KeyMinLength,1); |
|
323 a.set(KeyMaxLength,10); |
|
324 a.set(KeyHideInput,false); |
|
325 a.set(KeyDuration,1000); |
|
326 |
|
327 InputProviderTest test; |
|
328 test.mInput->getInput(a); |
|
329 a.waitUntilCompleted(); |
|
330 |
|
331 QCOMPARE(a.response(),ESatNoResponseFromUser); |
|
332 } |
|
333 |
|
334 void Ut_SatAppInputProvider::testGetInputAndReset() |
|
335 { |
|
336 SatAppAction a(ESatGetInputAction); |
|
337 a.set(KeyText,"hello"); |
|
338 a.set(KeyCharacterSet,ESatCharSmsDefaultAlphabet); |
|
339 a.set(KeyInputString,"12345"); |
|
340 a.set(KeyMinLength,1); |
|
341 a.set(KeyMaxLength,10); |
|
342 a.set(KeyHideInput,false); |
|
343 a.set(KeyDuration,10000); |
|
344 |
|
345 InputProviderTest test; |
|
346 test.mInput->getInput(a); |
|
347 test.mInput->resetState(); |
|
348 |
|
349 QCOMPARE(a.response(),ESatNoResponseFromUser); |
|
350 } |
|
351 |
|
352 void Ut_SatAppInputProvider::testGetInputAndDelete() |
|
353 { |
|
354 SatAppAction a(ESatGetInputAction); |
|
355 a.set(KeyText,"hello"); |
|
356 a.set(KeyCharacterSet,ESatCharSmsDefaultAlphabet); |
|
357 a.set(KeyInputString,"12345"); |
|
358 a.set(KeyMinLength,1); |
|
359 a.set(KeyMaxLength,10); |
|
360 a.set(KeyHideInput,false); |
|
361 a.set(KeyDuration,10000); |
|
362 a.setResponse(ESatFailure); |
|
363 |
|
364 { |
|
365 InputProviderTest test; |
|
366 test.mInput->getInput(a); |
|
367 } |
|
368 // at this point input dialog out of scope and destroyed. |
|
369 // pending action should have been completed later when application exit or timeout |
|
370 |
|
371 QCOMPARE(a.response(),ESatFailure); |
|
372 } |
|
373 |
|
374 |
|
375 // --------------------------------------------------------------- |
|
376 // internal helper class |
|
377 // --------------------------------------------------------------- |
|
378 |
|
379 InputProviderTest::InputProviderTest() |
|
380 { |
|
381 mInput = new SatAppInputProvider(this); |
|
382 } |
|
383 |
|
384 InputProviderTest::~InputProviderTest() |
|
385 { |
|
386 cleanup(); |
|
387 } |
|
388 |
|
389 void InputProviderTest::simulateFirstActionClicked() |
|
390 { |
|
391 mInput->mCurrentDialog->actions().at(0)->trigger(); |
|
392 } |
|
393 |
|
394 void InputProviderTest::simulateSecondActionClicked() |
|
395 { |
|
396 mInput->mCurrentDialog->actions().at(1)->trigger(); |
|
397 } |
|
398 |
|
399 void InputProviderTest::simulateImmediateKeypress(QString s) |
|
400 { |
|
401 mInput->transmitInkeyImmediately(s); |
|
402 } |
|
403 |
|
404 void InputProviderTest::cleanup() |
|
405 { |
|
406 delete mInput; |
|
407 mInput = 0; |
|
408 } |
|
409 |
|
410 |
|
411 // End of file |