|
1 /* |
|
2 * Copyright (c) 2008 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 the License "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 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <e32math.h> |
|
23 #include "FavouritesEngineTest.h" |
|
24 |
|
25 // EXTERNAL DATA STRUCTURES |
|
26 // None |
|
27 |
|
28 // EXTERNAL FUNCTION PROTOTYPES |
|
29 // None |
|
30 |
|
31 // CONSTANTS |
|
32 // None |
|
33 |
|
34 // MACROS |
|
35 // None |
|
36 |
|
37 // LOCAL CONSTANTS AND MACROS |
|
38 // None |
|
39 |
|
40 // MODULE DATA STRUCTURES |
|
41 // None |
|
42 |
|
43 // LOCAL FUNCTION PROTOTYPES |
|
44 // None |
|
45 |
|
46 // FORWARD DECLARATIONS |
|
47 // None |
|
48 |
|
49 // ==================== LOCAL FUNCTIONS ======================================= |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // CompareItemNamesL |
|
53 // Compare the names of two favourite list items. |
|
54 // Returns: negative, if aItem1.Name is less than aItem2.Name |
|
55 // 0, if aItem1.Name is the same as aItem2.Name |
|
56 // positive, if aItem1.Name is greater than aItem2.Name |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 LOCAL_C TInt CompareItemNamesL(const CFavouritesItem& aItem1, const CFavouritesItem& aItem2) |
|
60 { |
|
61 return aItem1.Name().CompareF(aItem2.Name()); |
|
62 } |
|
63 |
|
64 // ============================ MEMBER FUNCTIONS =============================== |
|
65 |
|
66 /* |
|
67 ------------------------------------------------------------------------------- |
|
68 |
|
69 Class: CFavouritesEngineTest |
|
70 |
|
71 Method: ListConstructorTestL |
|
72 |
|
73 Description: Test the item list constructor method. |
|
74 |
|
75 Parameters: TTestResult& aErrorDescription: out: |
|
76 Test result and on error case a short description of error |
|
77 |
|
78 Return Values: TInt: Always KErrNone to indicate that test was valid |
|
79 |
|
80 Errors/Exceptions: None |
|
81 |
|
82 Status: Approved |
|
83 |
|
84 ------------------------------------------------------------------------------- |
|
85 */ |
|
86 TInt CFavouritesEngineTest::ListConstructorTestL( TTestResult& aResult ) |
|
87 { |
|
88 /* Simple server connect */ |
|
89 _LIT( KDefinition ,"State"); |
|
90 _LIT( KData ,"Test the item list constructor method"); |
|
91 TestModuleIf().Printf( 0, KDefinition, KData ); |
|
92 |
|
93 CFavouritesItemList* list = new (ELeave) CFavouritesItemList(); |
|
94 |
|
95 _LIT( KData2 ,"Finished"); |
|
96 TestModuleIf().Printf( 0, KDefinition, KData2 ); |
|
97 |
|
98 if (list) |
|
99 { |
|
100 _LIT( KDescription , "Test case passed"); |
|
101 aResult.SetResult( KErrNone, KDescription ); |
|
102 |
|
103 delete list; |
|
104 } |
|
105 else |
|
106 { |
|
107 _LIT( KDescription , "Test case failed"); |
|
108 aResult.SetResult( KErrGeneral, KDescription ); |
|
109 } |
|
110 |
|
111 // Case was executed |
|
112 return KErrNone; |
|
113 } |
|
114 |
|
115 /* |
|
116 ------------------------------------------------------------------------------- |
|
117 |
|
118 Class: CFavouritesEngineTest |
|
119 |
|
120 Method: ListDestructorTestL |
|
121 |
|
122 Description: Test the item list destructor method. |
|
123 |
|
124 Parameters: TTestResult& aErrorDescription: out: |
|
125 Test result and on error case a short description of error |
|
126 |
|
127 Return Values: TInt: Always KErrNone to indicate that test was valid |
|
128 |
|
129 Errors/Exceptions: None |
|
130 |
|
131 Status: Approved |
|
132 |
|
133 ------------------------------------------------------------------------------- |
|
134 */ |
|
135 TInt CFavouritesEngineTest::ListDestructorTestL( TTestResult& aResult ) |
|
136 { |
|
137 /* Simple server connect */ |
|
138 _LIT( KDefinition ,"State"); |
|
139 _LIT( KData ,"Test the item list destructor method"); |
|
140 TestModuleIf().Printf( 0, KDefinition, KData ); |
|
141 |
|
142 CFavouritesItemList* list = new (ELeave) CFavouritesItemList(); |
|
143 |
|
144 list->~CFavouritesItemList(); |
|
145 |
|
146 _LIT( KData2 ,"Finished"); |
|
147 TestModuleIf().Printf( 0, KDefinition, KData2 ); |
|
148 |
|
149 if (list) |
|
150 { |
|
151 _LIT( KDescription , "Test case passed"); |
|
152 aResult.SetResult( KErrNone, KDescription ); |
|
153 |
|
154 delete list; |
|
155 } |
|
156 else |
|
157 { |
|
158 _LIT( KDescription , "Test case failed"); |
|
159 aResult.SetResult( KErrGeneral, KDescription ); |
|
160 } |
|
161 |
|
162 // Case was executed |
|
163 return KErrNone; |
|
164 } |
|
165 |
|
166 /* |
|
167 ------------------------------------------------------------------------------- |
|
168 |
|
169 Class: CFavouritesEngineTest |
|
170 |
|
171 Method: ListDeleteTestL |
|
172 |
|
173 Description: Test the item list Delete method. |
|
174 |
|
175 Parameters: TTestResult& aErrorDescription: out: |
|
176 Test result and on error case a short description of error |
|
177 |
|
178 Return Values: TInt: Always KErrNone to indicate that test was valid |
|
179 |
|
180 Errors/Exceptions: None |
|
181 |
|
182 Status: Approved |
|
183 |
|
184 ------------------------------------------------------------------------------- |
|
185 */ |
|
186 TInt CFavouritesEngineTest::ListDeleteTestL( TTestResult& aResult ) |
|
187 { |
|
188 /* Simple server connect */ |
|
189 _LIT( KDefinition ,"State"); |
|
190 _LIT( KData ,"Test the item list Delete method"); |
|
191 TestModuleIf().Printf( 0, KDefinition, KData ); |
|
192 |
|
193 iFavouritesDb.Open( iFavouritesSession, KTestDbName ); |
|
194 CleanupClosePushL<RFavouritesDb>( iFavouritesDb ); |
|
195 |
|
196 CreatePopulatedDbL(); |
|
197 |
|
198 CFavouritesItemList* list = new (ELeave) CFavouritesItemList(); |
|
199 |
|
200 iFavouritesDb.GetAll( *list, KFavouritesRootUid ); |
|
201 |
|
202 TInt countBeforeDelete = list->Count(); |
|
203 |
|
204 list->Delete( 1 ); |
|
205 |
|
206 TInt countAfterDelete = list->Count(); |
|
207 |
|
208 _LIT( KData2 ,"Finished"); |
|
209 TestModuleIf().Printf( 0, KDefinition, KData2 ); |
|
210 |
|
211 if (countAfterDelete == countBeforeDelete - 1) |
|
212 { |
|
213 _LIT( KDescription , "Test case passed"); |
|
214 aResult.SetResult( KErrNone, KDescription ); |
|
215 } |
|
216 else |
|
217 { |
|
218 _LIT( KDescription , "Test case failed"); |
|
219 aResult.SetResult( KErrGeneral, KDescription ); |
|
220 } |
|
221 |
|
222 delete list; |
|
223 CleanupStack::PopAndDestroy(); // iFavouritesDb |
|
224 iFavouritesSession.DeleteDatabase( KTestDbName ); |
|
225 |
|
226 // Case was executed |
|
227 return KErrNone; |
|
228 } |
|
229 |
|
230 /* |
|
231 ------------------------------------------------------------------------------- |
|
232 |
|
233 Class: CFavouritesEngineTest |
|
234 |
|
235 Method: ListDeleteRangeTestL |
|
236 |
|
237 Description: Test deleting a range of items using the item list Delete method. |
|
238 |
|
239 Parameters: TTestResult& aErrorDescription: out: |
|
240 Test result and on error case a short description of error |
|
241 |
|
242 Return Values: TInt: Always KErrNone to indicate that test was valid |
|
243 |
|
244 Errors/Exceptions: None |
|
245 |
|
246 Status: Approved |
|
247 |
|
248 ------------------------------------------------------------------------------- |
|
249 */ |
|
250 TInt CFavouritesEngineTest::ListDeleteRangeTestL( TTestResult& aResult ) |
|
251 { |
|
252 /* Simple server connect */ |
|
253 _LIT( KDefinition ,"State"); |
|
254 _LIT( KData ,"Test the item list Delete method"); |
|
255 TestModuleIf().Printf( 0, KDefinition, KData ); |
|
256 |
|
257 iFavouritesDb.Open( iFavouritesSession, KTestDbName ); |
|
258 CleanupClosePushL<RFavouritesDb>( iFavouritesDb ); |
|
259 |
|
260 CreatePopulatedDbL(); |
|
261 |
|
262 CFavouritesItemList* list = new (ELeave) CFavouritesItemList(); |
|
263 |
|
264 iFavouritesDb.GetAll( *list, KFavouritesRootUid ); |
|
265 |
|
266 TInt countBeforeDelete = list->Count(); |
|
267 |
|
268 list->Delete( 1, 3 ); |
|
269 |
|
270 TInt countAfterDelete = list->Count(); |
|
271 |
|
272 _LIT( KData2 ,"Finished"); |
|
273 TestModuleIf().Printf( 0, KDefinition, KData2 ); |
|
274 |
|
275 if (countAfterDelete == countBeforeDelete - 3) |
|
276 { |
|
277 _LIT( KDescription , "Test case passed"); |
|
278 aResult.SetResult( KErrNone, KDescription ); |
|
279 } |
|
280 else |
|
281 { |
|
282 _LIT( KDescription , "Test case failed"); |
|
283 aResult.SetResult( KErrGeneral, KDescription ); |
|
284 } |
|
285 |
|
286 delete list; |
|
287 CleanupStack::PopAndDestroy(); // iFavouritesDb |
|
288 iFavouritesSession.DeleteDatabase( KTestDbName ); |
|
289 |
|
290 // Case was executed |
|
291 return KErrNone; |
|
292 } |
|
293 |
|
294 /* |
|
295 ------------------------------------------------------------------------------- |
|
296 |
|
297 Class: CFavouritesEngineTest |
|
298 |
|
299 Method: ListSortTestL |
|
300 |
|
301 Description: Test sorting the list using the Sort method. |
|
302 |
|
303 Parameters: TTestResult& aErrorDescription: out: |
|
304 Test result and on error case a short description of error |
|
305 |
|
306 Return Values: TInt: Always KErrNone to indicate that test was valid |
|
307 |
|
308 Errors/Exceptions: None |
|
309 |
|
310 Status: Approved |
|
311 |
|
312 ------------------------------------------------------------------------------- |
|
313 */ |
|
314 TInt CFavouritesEngineTest::ListSortTestL( TTestResult& aResult ) |
|
315 { |
|
316 /* Simple server connect */ |
|
317 _LIT( KDefinition ,"State"); |
|
318 _LIT( KData ,"Test the item list Delete method"); |
|
319 TestModuleIf().Printf( 0, KDefinition, KData ); |
|
320 |
|
321 iFavouritesDb.Open( iFavouritesSession, KTestDbName ); |
|
322 CleanupClosePushL<RFavouritesDb>( iFavouritesDb ); |
|
323 |
|
324 CreatePopulatedDbL(); |
|
325 |
|
326 CFavouritesItemList* list = new (ELeave) CFavouritesItemList(); |
|
327 |
|
328 iFavouritesDb.GetAll( *list, KFavouritesRootUid ); |
|
329 |
|
330 list->SortL( &CompareItemNamesL ); |
|
331 |
|
332 _LIT( KData2 ,"Finished"); |
|
333 TestModuleIf().Printf( 0, KDefinition, KData2 ); |
|
334 |
|
335 const CFavouritesItem* firstItem = list->ItemByUid( list->IndexToUid( 0 ) ); |
|
336 |
|
337 if (firstItem->Name() == _L("iItem1")) |
|
338 { |
|
339 _LIT( KDescription , "Test case passed"); |
|
340 aResult.SetResult( KErrNone, KDescription ); |
|
341 } |
|
342 else |
|
343 { |
|
344 _LIT( KDescription , "Test case failed"); |
|
345 aResult.SetResult( KErrGeneral, KDescription ); |
|
346 } |
|
347 |
|
348 delete list; |
|
349 CleanupStack::PopAndDestroy(); // iFavouritesDb |
|
350 iFavouritesSession.DeleteDatabase( KTestDbName ); |
|
351 |
|
352 // Case was executed |
|
353 return KErrNone; |
|
354 } |
|
355 |
|
356 /* |
|
357 ------------------------------------------------------------------------------- |
|
358 |
|
359 Class: CFavouritesEngineTest |
|
360 |
|
361 Method: ListUidToIndexTestL |
|
362 |
|
363 Description: Test uid to index conversion using the UidToIndex method. |
|
364 |
|
365 Parameters: TTestResult& aErrorDescription: out: |
|
366 Test result and on error case a short description of error |
|
367 |
|
368 Return Values: TInt: Always KErrNone to indicate that test was valid |
|
369 |
|
370 Errors/Exceptions: None |
|
371 |
|
372 Status: Approved |
|
373 |
|
374 ------------------------------------------------------------------------------- |
|
375 */ |
|
376 TInt CFavouritesEngineTest::ListUidToIndexTestL( TTestResult& aResult ) |
|
377 { |
|
378 /* Simple server connect */ |
|
379 _LIT( KDefinition ,"State"); |
|
380 _LIT( KData ,"Test the item list Delete method"); |
|
381 TestModuleIf().Printf( 0, KDefinition, KData ); |
|
382 |
|
383 iFavouritesDb.Open( iFavouritesSession, KTestDbName ); |
|
384 CleanupClosePushL<RFavouritesDb>( iFavouritesDb ); |
|
385 |
|
386 CreatePopulatedDbL(); |
|
387 |
|
388 CFavouritesItemList* list = new (ELeave) CFavouritesItemList(); |
|
389 |
|
390 iFavouritesDb.GetAll( *list, KFavouritesRootUid ); |
|
391 |
|
392 list->SortL( &CompareItemNamesL ); |
|
393 |
|
394 const CFavouritesItem* firstItem = list->ItemByUid( list->IndexToUid( 1 ) ); |
|
395 |
|
396 _LIT( KData2 ,"Finished"); |
|
397 TestModuleIf().Printf( 0, KDefinition, KData2 ); |
|
398 |
|
399 if (firstItem->Uid() == list->IndexToUid( 1 )) |
|
400 { |
|
401 _LIT( KDescription , "Test case passed"); |
|
402 aResult.SetResult( KErrNone, KDescription ); |
|
403 } |
|
404 else |
|
405 { |
|
406 _LIT( KDescription , "Test case failed"); |
|
407 aResult.SetResult( KErrGeneral, KDescription ); |
|
408 } |
|
409 |
|
410 delete list; |
|
411 CleanupStack::PopAndDestroy(); // iFavouritesDb |
|
412 iFavouritesSession.DeleteDatabase( KTestDbName ); |
|
413 |
|
414 // Case was executed |
|
415 return KErrNone; |
|
416 } |
|
417 |
|
418 /* |
|
419 ------------------------------------------------------------------------------- |
|
420 |
|
421 Class: CFavouritesEngineTest |
|
422 |
|
423 Method: ListIndexToUidTestL |
|
424 |
|
425 Description: Test index to uid conversion using the UidToIndex method. |
|
426 |
|
427 Parameters: TTestResult& aErrorDescription: out: |
|
428 Test result and on error case a short description of error |
|
429 |
|
430 Return Values: TInt: Always KErrNone to indicate that test was valid |
|
431 |
|
432 Errors/Exceptions: None |
|
433 |
|
434 Status: Approved |
|
435 |
|
436 ------------------------------------------------------------------------------- |
|
437 */ |
|
438 TInt CFavouritesEngineTest::ListIndexToUidTestL( TTestResult& aResult ) |
|
439 { |
|
440 /* Simple server connect */ |
|
441 _LIT( KDefinition ,"State"); |
|
442 _LIT( KData ,"Test the item list Delete method"); |
|
443 TestModuleIf().Printf( 0, KDefinition, KData ); |
|
444 |
|
445 iFavouritesDb.Open( iFavouritesSession, KTestDbName ); |
|
446 CleanupClosePushL<RFavouritesDb>( iFavouritesDb ); |
|
447 |
|
448 CreatePopulatedDbL(); |
|
449 |
|
450 CFavouritesItemList* list = new (ELeave) CFavouritesItemList(); |
|
451 |
|
452 iFavouritesDb.GetAll( *list, KFavouritesRootUid ); |
|
453 |
|
454 list->SortL( &CompareItemNamesL ); |
|
455 |
|
456 TInt itemUid = list->IndexToUid(1); |
|
457 |
|
458 _LIT( KData2 ,"Finished"); |
|
459 TestModuleIf().Printf( 0, KDefinition, KData2 ); |
|
460 |
|
461 if (itemUid == list->At(1)->Uid()) |
|
462 { |
|
463 _LIT( KDescription , "Test case passed"); |
|
464 aResult.SetResult( KErrNone, KDescription ); |
|
465 } |
|
466 else |
|
467 { |
|
468 _LIT( KDescription , "Test case failed"); |
|
469 aResult.SetResult( KErrGeneral, KDescription ); |
|
470 } |
|
471 |
|
472 delete list; |
|
473 CleanupStack::PopAndDestroy(); // iFavouritesDb |
|
474 iFavouritesSession.DeleteDatabase( KTestDbName ); |
|
475 |
|
476 // Case was executed |
|
477 return KErrNone; |
|
478 } |
|
479 |
|
480 /* |
|
481 ------------------------------------------------------------------------------- |
|
482 |
|
483 Class: CFavouritesEngineTest |
|
484 |
|
485 Method: ListItemByUidTestL |
|
486 |
|
487 Description: Test retrieveing an item by Id using the ItemByUid method. |
|
488 |
|
489 Parameters: TTestResult& aErrorDescription: out: |
|
490 Test result and on error case a short description of error |
|
491 |
|
492 Return Values: TInt: Always KErrNone to indicate that test was valid |
|
493 |
|
494 Errors/Exceptions: None |
|
495 |
|
496 Status: Approved |
|
497 |
|
498 ------------------------------------------------------------------------------- |
|
499 */ |
|
500 TInt CFavouritesEngineTest::ListItemByUidTestL( TTestResult& aResult ) |
|
501 { |
|
502 /* Simple server connect */ |
|
503 _LIT( KDefinition ,"State"); |
|
504 _LIT( KData ,"Test the item list Delete method"); |
|
505 TestModuleIf().Printf( 0, KDefinition, KData ); |
|
506 |
|
507 iFavouritesDb.Open( iFavouritesSession, KTestDbName ); |
|
508 CleanupClosePushL<RFavouritesDb>( iFavouritesDb ); |
|
509 |
|
510 CreatePopulatedDbL(); |
|
511 |
|
512 CFavouritesItemList* list = new (ELeave) CFavouritesItemList(); |
|
513 |
|
514 iFavouritesDb.GetAll( *list, KFavouritesRootUid ); |
|
515 |
|
516 list->SortL( &CompareItemNamesL ); |
|
517 |
|
518 const CFavouritesItem* firstItem = list->ItemByUid( list->IndexToUid( 0 ) ); |
|
519 |
|
520 _LIT( KData2 ,"Finished"); |
|
521 TestModuleIf().Printf( 0, KDefinition, KData2 ); |
|
522 |
|
523 if (firstItem->Name() == _L("iItem1")) |
|
524 { |
|
525 _LIT( KDescription , "Test case passed"); |
|
526 aResult.SetResult( KErrNone, KDescription ); |
|
527 } |
|
528 else |
|
529 { |
|
530 _LIT( KDescription , "Test case failed"); |
|
531 aResult.SetResult( KErrGeneral, KDescription ); |
|
532 } |
|
533 |
|
534 delete list; |
|
535 CleanupStack::PopAndDestroy(); // iFavouritesDb |
|
536 iFavouritesSession.DeleteDatabase( KTestDbName ); |
|
537 |
|
538 // Case was executed |
|
539 return KErrNone; |
|
540 } |
|
541 |
|
542 // ================= OTHER EXPORTED FUNCTIONS ================================= |
|
543 |
|
544 // End of File |