|
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 */ |
|
18 |
|
19 |
|
20 |
|
21 // [INCLUDE FILES] - do not remove |
|
22 #include <e32svr.h> |
|
23 #include <StifParser.h> |
|
24 #include <StifTestInterface.h> |
|
25 #include "CVIMPSTStorageContactSorter_UT.h" |
|
26 #include "cvimpststoragecontactsorter.h" |
|
27 #include "vimpstdebugtrace.h" |
|
28 #include <flogger.h> |
|
29 #include "mvimpststoragecontact.h" |
|
30 #include "cvimpststoragecontact.h" |
|
31 #include "tvimpstenums.h" |
|
32 #include "tvimpststoragepanics.h" |
|
33 |
|
34 _LIT( KUserId1, "vidic@mu.com"); |
|
35 _LIT( KUserId2, "carr@mu.com"); |
|
36 _LIT( KUserId3, "terry@mu.com"); |
|
37 _LIT( KUserId4, "gibbs@mu.com"); |
|
38 |
|
39 _LIT( KDisplayName1, "vidic"); |
|
40 _LIT( KDisplayName2, "carr"); |
|
41 _LIT( KDisplayName3, "terry"); |
|
42 _LIT( KDisplayName4, "gibbs"); |
|
43 // ============================ MEMBER FUNCTIONS =============================== |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CCVIMPSTStorageContactSorter_UT::Delete |
|
47 // Delete here all resources allocated and opened from test methods. |
|
48 // Called from destructor. |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 void CCVIMPSTStorageContactSorter_UT::Delete() |
|
52 { |
|
53 |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CCVIMPSTStorageContactSorter_UT::RunMethodL |
|
58 // Run specified method. Contains also table of test mothods and their names. |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 TInt CCVIMPSTStorageContactSorter_UT::RunMethodL( |
|
62 CStifItemParser& aItem ) |
|
63 { |
|
64 |
|
65 static TStifFunctionInfo const KFunctions[] = |
|
66 { |
|
67 // Copy this line for every implemented function. |
|
68 // First string is the function name used in TestScripter script file. |
|
69 // Second is the actual implementation member function. |
|
70 ENTRY( "CreateSorter", CCVIMPSTStorageContactSorter_UT::Test_NewL ), |
|
71 ENTRY( "DoSort", CCVIMPSTStorageContactSorter_UT::Test_SortL ), |
|
72 ENTRY( "SelectAlgorithm", CCVIMPSTStorageContactSorter_UT::SetSortAlgorithm ), |
|
73 ENTRY( "CompareContacts", CCVIMPSTStorageContactSorter_UT::Test_CompareL ), |
|
74 //ADD NEW ENTRY HERE |
|
75 // [test cases entries] - Do not remove |
|
76 |
|
77 }; |
|
78 |
|
79 const TInt count = sizeof( KFunctions ) / |
|
80 sizeof( TStifFunctionInfo ); |
|
81 |
|
82 return RunInternalL( KFunctions, count, aItem ); |
|
83 |
|
84 } |
|
85 |
|
86 // -- -- -- -- ------------------------------------------------- |
|
87 // @ see CVIMPSTStorageSorter_UT.h for description. |
|
88 // -- -- -- -- ------------------------------------------------- |
|
89 // |
|
90 TInt CCVIMPSTStorageContactSorter_UT::Test_NewL( CStifItemParser& aItem ) |
|
91 { |
|
92 TInt result = KErrGeneral; |
|
93 |
|
94 CVIMPSTStorageContactSorter* sorter = NULL; |
|
95 |
|
96 sorter = CVIMPSTStorageContactSorter::NewL(); |
|
97 |
|
98 if( sorter ) |
|
99 { |
|
100 result = KErrNone; |
|
101 } |
|
102 if( sorter ) |
|
103 { |
|
104 delete sorter; |
|
105 } |
|
106 return result; |
|
107 } |
|
108 |
|
109 // -- -- -- -- ------------------------------------------------- |
|
110 // @ see CVIMPSTStorageSorter_UT.h for description. |
|
111 // -- -- -- -- ------------------------------------------------- |
|
112 // |
|
113 TInt CCVIMPSTStorageContactSorter_UT::Test_SortL( CStifItemParser& aItem ) |
|
114 { |
|
115 TInt result = KErrGeneral; |
|
116 |
|
117 TPtrC param; |
|
118 |
|
119 MVIMPSTStorageContact::TSortAlgorithm sortAlgorithm; |
|
120 |
|
121 aItem.GetNextString( param ); |
|
122 |
|
123 CVIMPSTStorageContactSorter* sorter = NULL; |
|
124 |
|
125 sorter = CVIMPSTStorageContactSorter::NewL(); |
|
126 |
|
127 // setting the algorithm to be used for sorting. |
|
128 if( param.Compare( _L("alpha") ) == 0 ) |
|
129 { |
|
130 sortAlgorithm = MVIMPSTStorageContact::ECompareAlphabetically; |
|
131 } |
|
132 else if( param.Compare( _L("presence") ) == 0 ) |
|
133 { |
|
134 sortAlgorithm = MVIMPSTStorageContact::ECompareByPresence; |
|
135 } |
|
136 |
|
137 // comparing the sorted array and result array. |
|
138 // setting the result for the test case. |
|
139 TInt compareResult = -1; |
|
140 |
|
141 CreateContactArray(); |
|
142 |
|
143 switch( sortAlgorithm ) |
|
144 { |
|
145 case MVIMPSTStorageContact::ECompareByPresence: |
|
146 { |
|
147 // sorting the contact array |
|
148 sorter->SetSortAlgorithm( sortAlgorithm ); |
|
149 CreatePresenceSortArray(); |
|
150 sorter->Sort( iContactArray ); |
|
151 compareResult = CompareArray( iContactArray, iPresenceSortArray ); |
|
152 ResetArray( iPresenceSortArray ); |
|
153 break; |
|
154 } |
|
155 case MVIMPSTStorageContact::ECompareAlphabetically: |
|
156 default: |
|
157 { |
|
158 // sorting the contact array |
|
159 sorter->SetSortAlgorithm( sortAlgorithm ); |
|
160 CreateAlphabeticalSortArray(); |
|
161 sorter->Sort( iContactArray ); |
|
162 compareResult = CompareArray( iContactArray, iAlphabeticalSortArray ); |
|
163 ResetArray( iAlphabeticalSortArray ); |
|
164 break; |
|
165 } |
|
166 } |
|
167 ResetArray( iContactArray ); |
|
168 |
|
169 if( -1 == compareResult ) |
|
170 { |
|
171 result = KErrNone; |
|
172 } |
|
173 |
|
174 if( sorter ) |
|
175 delete sorter; |
|
176 |
|
177 return result; |
|
178 } |
|
179 |
|
180 // -- -- -- -- ------------------------------------------------- |
|
181 // @ see CVIMPSTStorageSorter_UT.h for description. |
|
182 // -- -- -- -- ------------------------------------------------- |
|
183 // |
|
184 TInt CCVIMPSTStorageContactSorter_UT::Test_CompareL( CStifItemParser& aItem ) |
|
185 { |
|
186 TInt result = KErrGeneral; |
|
187 |
|
188 CVIMPSTStorageContactSorter* sorter = NULL; |
|
189 |
|
190 sorter = CVIMPSTStorageContactSorter::NewL(); |
|
191 |
|
192 CVIMPSTStorageContact* contact1 = NULL; |
|
193 CVIMPSTStorageContact* contact2 = NULL; |
|
194 TBuf<64> userId; |
|
195 TBuf<64> displayName; |
|
196 |
|
197 TPtrC param; |
|
198 aItem.GetNextString( param ); |
|
199 TInt compareResult; |
|
200 |
|
201 if( param.Compare( _L("2validcontacts") ) == 0 ) |
|
202 { |
|
203 // first contact |
|
204 userId.Copy(KUserId1); |
|
205 displayName.Copy( KDisplayName1 ); |
|
206 contact1 = CVIMPSTStorageContact::NewL( userId, displayName ); |
|
207 |
|
208 // second contact |
|
209 userId.Copy(KUserId2); |
|
210 displayName.Copy( KDisplayName2 ); |
|
211 contact2 = CVIMPSTStorageContact::NewL( userId, displayName ); |
|
212 |
|
213 compareResult = sorter->Compare( *contact1, *contact2 ); |
|
214 |
|
215 if( compareResult ) |
|
216 { |
|
217 result = KErrNone; |
|
218 } |
|
219 |
|
220 } |
|
221 else if( param.Compare( _L("1validcontact") ) == 0 ) |
|
222 { |
|
223 // first contact |
|
224 userId.Copy(KUserId1); |
|
225 displayName.Copy( KDisplayName1 ); |
|
226 contact1 = CVIMPSTStorageContact::NewL( userId, displayName ); |
|
227 |
|
228 // null contact |
|
229 |
|
230 userId.Copy( KNullDesC ); |
|
231 displayName.Copy( KNullDesC ); |
|
232 contact2 = CVIMPSTStorageContact::NewL( userId, displayName ); |
|
233 |
|
234 compareResult = sorter->Compare( *contact1, *contact2 ); |
|
235 |
|
236 if( compareResult ) // Not Equal |
|
237 { |
|
238 result = KErrNone; |
|
239 } |
|
240 |
|
241 } |
|
242 else if( param.Compare( _L("1nullcontact") ) == 0 ) |
|
243 { |
|
244 |
|
245 // nullcontact |
|
246 userId.Copy( KNullDesC ); |
|
247 displayName.Copy( KNullDesC ); |
|
248 contact1 = CVIMPSTStorageContact::NewL( userId, displayName ); |
|
249 |
|
250 // second contact |
|
251 userId.Copy(KUserId2); |
|
252 displayName.Copy( KDisplayName2 ); |
|
253 contact2 = CVIMPSTStorageContact::NewL( userId, displayName ); |
|
254 |
|
255 compareResult = sorter->Compare( *contact1, *contact2 ); |
|
256 |
|
257 if( compareResult ) // Not Equal |
|
258 { |
|
259 result = KErrNone; |
|
260 } |
|
261 |
|
262 } |
|
263 else if( param.Compare( _L( "2nullcontacts") ) == 0 ) |
|
264 { |
|
265 // first contact, null |
|
266 userId.Copy( KNullDesC ); |
|
267 displayName.Copy( KNullDesC ); |
|
268 contact1 = CVIMPSTStorageContact::NewL( userId, displayName ); |
|
269 |
|
270 // second contact, null |
|
271 userId.Copy( KNullDesC ); |
|
272 displayName.Copy( KNullDesC ); |
|
273 contact2 = CVIMPSTStorageContact::NewL( userId, displayName ); |
|
274 |
|
275 |
|
276 // no contact |
|
277 compareResult = sorter->Compare( *contact1, *contact2 ); |
|
278 |
|
279 if( compareResult == 0 ) |
|
280 { |
|
281 result = KErrNone; |
|
282 } |
|
283 |
|
284 } |
|
285 else if( param.Compare( _L( "samecontacts") ) == 0 ) |
|
286 { |
|
287 // first contact |
|
288 userId.Copy(KUserId1); |
|
289 displayName.Copy( KDisplayName1 ); |
|
290 contact1 = CVIMPSTStorageContact::NewL( userId, displayName ); |
|
291 // second contact |
|
292 userId.Copy(KUserId1); |
|
293 displayName.Copy( KDisplayName1 ); |
|
294 contact2 = CVIMPSTStorageContact::NewL( userId, displayName ); |
|
295 |
|
296 compareResult = sorter->Compare( *contact1, *contact2 ); |
|
297 |
|
298 if( compareResult == 0 ) |
|
299 { |
|
300 result = KErrNone; |
|
301 } |
|
302 |
|
303 } |
|
304 if( contact1 ) |
|
305 delete contact1; |
|
306 if( contact2 ) |
|
307 delete contact2; |
|
308 if( sorter ) |
|
309 delete sorter; |
|
310 return result; |
|
311 |
|
312 } |
|
313 |
|
314 // -- -- -- -- ------------------------------------------------- |
|
315 // @ see CVIMPSTStorageSorter_UT.h for description. |
|
316 // -- -- -- -- ------------------------------------------------- |
|
317 // |
|
318 TInt CCVIMPSTStorageContactSorter_UT::SetSortAlgorithm( CStifItemParser& aItem ) |
|
319 { |
|
320 TInt result = KErrGeneral; |
|
321 |
|
322 TInt input; |
|
323 |
|
324 aItem.GetNextInt( input ); |
|
325 |
|
326 CVIMPSTStorageContactSorter* sorter = NULL; |
|
327 |
|
328 sorter = CVIMPSTStorageContactSorter::NewL(); |
|
329 |
|
330 switch( input ) |
|
331 { |
|
332 case 1: |
|
333 { |
|
334 sorter->SetSortAlgorithm( MVIMPSTStorageContact::ECompareByPresence ); |
|
335 result = KErrNone; |
|
336 } |
|
337 break; |
|
338 case 2: |
|
339 { |
|
340 sorter->SetSortAlgorithm( MVIMPSTStorageContact::ECompareAlphabetically ); |
|
341 result = KErrNone; |
|
342 } |
|
343 break; |
|
344 } |
|
345 |
|
346 delete sorter; |
|
347 |
|
348 return result; |
|
349 |
|
350 } |
|
351 |
|
352 |
|
353 // -- -- -- -- ------------------------------------------------- |
|
354 // @ see CVIMPSTStorageSorter_UT.h for description. |
|
355 // -- -- -- -- ------------------------------------------------- |
|
356 // |
|
357 void CCVIMPSTStorageContactSorter_UT::CreateContactArray() |
|
358 { |
|
359 |
|
360 CVIMPSTStorageContact* contact = NULL; |
|
361 |
|
362 TBuf<64> userId; |
|
363 TBuf<64> displayName; |
|
364 |
|
365 // first contact |
|
366 userId.Copy(KUserId1); |
|
367 displayName.Copy( KDisplayName1 ); |
|
368 contact = CVIMPSTStorageContact::NewL( userId, displayName ); |
|
369 contact->SetOnlineStatus( TVIMPSTEnums::EBusy ); |
|
370 iContactArray.AppendL( contact ); |
|
371 |
|
372 // second contact |
|
373 userId.Copy(KUserId2); |
|
374 displayName.Copy( KDisplayName2 ); |
|
375 contact = CVIMPSTStorageContact::NewL( userId, displayName ); |
|
376 contact->SetOnlineStatus( TVIMPSTEnums::EOnline ); |
|
377 iContactArray.AppendL( contact ); |
|
378 |
|
379 // third contact |
|
380 userId.Copy(KUserId3); |
|
381 displayName.Copy( KDisplayName3 ); |
|
382 contact = CVIMPSTStorageContact::NewL( userId, displayName ); |
|
383 contact->SetOnlineStatus( TVIMPSTEnums::EPending ); |
|
384 |
|
385 iContactArray.AppendL( contact ); |
|
386 |
|
387 // fourth contact |
|
388 userId.Copy(KUserId4); |
|
389 displayName.Copy( KDisplayName4 ); |
|
390 contact = CVIMPSTStorageContact::NewL( userId, displayName ); |
|
391 contact->SetOnlineStatus( TVIMPSTEnums::EOnPhone ); |
|
392 iContactArray.AppendL( contact ); |
|
393 |
|
394 } |
|
395 |
|
396 // -- -- -- -- ------------------------------------------------- |
|
397 // @ see CVIMPSTStorageSorter_UT.h for description. |
|
398 // -- -- -- -- ------------------------------------------------- |
|
399 // |
|
400 void CCVIMPSTStorageContactSorter_UT::CreateAlphabeticalSortArray() |
|
401 { |
|
402 // order of sort : contact2, contact4, contact3, contact1 |
|
403 CVIMPSTStorageContact* contact = NULL; |
|
404 |
|
405 TBuf<64> userId; |
|
406 TBuf<64> displayName; |
|
407 |
|
408 // first contact |
|
409 userId.Copy(KUserId2); |
|
410 displayName.Copy( KDisplayName2 ); |
|
411 contact = CVIMPSTStorageContact::NewL( userId, displayName ); |
|
412 contact->SetOnlineStatus( TVIMPSTEnums::EBusy ); |
|
413 iAlphabeticalSortArray.AppendL( contact ); |
|
414 |
|
415 // second contact |
|
416 userId.Copy( KUserId4 ); |
|
417 displayName.Copy( KDisplayName4 ); |
|
418 contact = CVIMPSTStorageContact::NewL( userId, displayName ); |
|
419 contact->SetOnlineStatus( TVIMPSTEnums::EOnline ); |
|
420 iAlphabeticalSortArray.AppendL( contact ); |
|
421 |
|
422 // third contact |
|
423 userId.Copy(KUserId3); |
|
424 displayName.Copy( KDisplayName3 ); |
|
425 contact = CVIMPSTStorageContact::NewL( userId, displayName ); |
|
426 contact->SetOnlineStatus( TVIMPSTEnums::EPending ); |
|
427 iAlphabeticalSortArray.AppendL( contact ); |
|
428 |
|
429 // fourth contact |
|
430 userId.Copy(KUserId1); |
|
431 displayName.Copy( KDisplayName1 ); |
|
432 contact = CVIMPSTStorageContact::NewL( userId, displayName ); |
|
433 contact->SetOnlineStatus( TVIMPSTEnums::EOnPhone ); |
|
434 iAlphabeticalSortArray.AppendL( contact ); |
|
435 |
|
436 } |
|
437 // -- -- -- -- ------------------------------------------------- |
|
438 // @ see CVIMPSTStorageSorter_UT.h for description. |
|
439 // -- -- -- -- ------------------------------------------------- |
|
440 // |
|
441 void CCVIMPSTStorageContactSorter_UT::CreatePresenceSortArray() |
|
442 { |
|
443 // order of sort : contact2, contact1, contact4, contact 3 |
|
444 |
|
445 CVIMPSTStorageContact* contact = NULL; |
|
446 |
|
447 TBuf<64> userId; |
|
448 TBuf<64> displayName; |
|
449 |
|
450 // first contact |
|
451 userId.Copy(KUserId2); |
|
452 displayName.Copy( KDisplayName2 ); |
|
453 contact = CVIMPSTStorageContact::NewL( userId, displayName ); |
|
454 contact->SetOnlineStatus( TVIMPSTEnums::EBusy ); |
|
455 iPresenceSortArray.AppendL( contact ); |
|
456 |
|
457 // second contact |
|
458 userId.Copy( KUserId1 ); |
|
459 displayName.Copy( KDisplayName1 ); |
|
460 contact = CVIMPSTStorageContact::NewL( userId, displayName ); |
|
461 contact->SetOnlineStatus( TVIMPSTEnums::EOnline ); |
|
462 iPresenceSortArray.AppendL( contact ); |
|
463 |
|
464 // third contact |
|
465 userId.Copy( KUserId4 ); |
|
466 displayName.Copy( KDisplayName4 ); |
|
467 contact = CVIMPSTStorageContact::NewL( userId, displayName ); |
|
468 contact->SetOnlineStatus( TVIMPSTEnums::EPending ); |
|
469 iPresenceSortArray.AppendL( contact ); |
|
470 |
|
471 // fourth contact |
|
472 userId.Copy( KUserId3 ); |
|
473 displayName.Copy( KDisplayName3 ); |
|
474 contact = CVIMPSTStorageContact::NewL( userId, displayName ); |
|
475 contact->SetOnlineStatus( TVIMPSTEnums::EOnPhone ); |
|
476 iPresenceSortArray.AppendL( contact ); |
|
477 |
|
478 |
|
479 } |
|
480 |
|
481 // -- -- -- -- ------------------------------------------------- |
|
482 // @ see CVIMPSTStorageSorter_UT.h for description. |
|
483 // -- -- -- -- ------------------------------------------------- |
|
484 // |
|
485 TInt CCVIMPSTStorageContactSorter_UT::CompareArray(RPointerArray< MVIMPSTStorageContact > & aFirstArray, RPointerArray< MVIMPSTStorageContact >& aSecondArray ) |
|
486 { |
|
487 // Number of contacts to be compared |
|
488 TInt count = 4; |
|
489 TInt result = -1; |
|
490 |
|
491 |
|
492 TBuf<64> userId1,userId2; |
|
493 |
|
494 |
|
495 // loop index |
|
496 TInt i = -1; |
|
497 for( i=0; i<count; i++ ) |
|
498 { |
|
499 userId1.Copy( aFirstArray[i]->UserId() ); |
|
500 userId2.Copy( aSecondArray[i]->UserId() ); |
|
501 |
|
502 if( userId1.Compare( userId2 ) != 0 ) |
|
503 { |
|
504 result = i; |
|
505 break; |
|
506 } |
|
507 } |
|
508 |
|
509 return result; |
|
510 |
|
511 } |
|
512 |
|
513 // -- -- -- -- ------------------------------------------------- |
|
514 // @ see CVIMPSTStorageSorter_UT.h for description. |
|
515 // -- -- -- -- ------------------------------------------------- |
|
516 // |
|
517 void CCVIMPSTStorageContactSorter_UT::ResetArray( RPointerArray< MVIMPSTStorageContact > & aArray ) |
|
518 { |
|
519 aArray.ResetAndDestroy(); |
|
520 } |
|
521 |
|
522 //---------------------------- |
|
523 // To fix build break, please refer task no. in synergy. |
|
524 //---------------------------- |
|
525 // |
|
526 void Panic( TVIMPSTStoragePanics aPanic ) |
|
527 { |
|
528 User::Panic( KPanicCategory, aPanic ); |
|
529 } |
|
530 // [End of File] - Do not remove |