|
1 /* |
|
2 * Copyright (c) 2002 - 2007 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: implements all sorting related test cases |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 //#include <BAUTILS.H> |
|
20 #include <e32math.h> |
|
21 #include <tz.h> |
|
22 #include "SortTests.h" |
|
23 //#include <ismsgstorepropertykeys.h> |
|
24 //#include "messagestoreclientserver.h" |
|
25 |
|
26 const TInt32 KOwner1 = 1234; |
|
27 _LIT(KAccount1, "My Account"); |
|
28 _LIT(KInbox, "inbox"); |
|
29 |
|
30 // ============================ MEMBER FUNCTIONS =============================== |
|
31 |
|
32 CSortTests* CSortTests::NewL( CStifLogger* aLog ) |
|
33 { |
|
34 CSortTests* self = new(ELeave) CSortTests( aLog ); |
|
35 CleanupStack::PushL( self ); |
|
36 self->ConstructL(); |
|
37 CleanupStack::Pop( self ); |
|
38 return self; |
|
39 } |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // Constructor |
|
43 // ----------------------------------------------------------------------------- |
|
44 CSortTests::CSortTests( CStifLogger* aLog ) : CAsyncTestCaseBase( aLog ) |
|
45 { |
|
46 } |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // Destructor |
|
50 // ----------------------------------------------------------------------------- |
|
51 CSortTests::~CSortTests() |
|
52 { |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // 2nd phase constructor |
|
57 // ----------------------------------------------------------------------------- |
|
58 void CSortTests::ConstructL() |
|
59 { |
|
60 CAsyncTestCaseBase::ConstructL(); |
|
61 } |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // ExecuteL : start executing the test case |
|
65 // ----------------------------------------------------------------------------- |
|
66 TBool CSortTests::ExecuteL() |
|
67 { |
|
68 LogHeader( _L("Sort") ); |
|
69 |
|
70 TInt msgCount = 200; |
|
71 |
|
72 iLog->Log( _L(" Create %d messages"), msgCount ); |
|
73 DoCreateMessagesL( msgCount ); |
|
74 |
|
75 //Open Account |
|
76 CMsgStoreAccount* account = CMsgStoreAccount::NewLC( KOwner1, KAccount1 ); //+1 |
|
77 CMsgStoreMailBox* mailBox = iMsgStore->OpenAccountL( *account ); |
|
78 CleanupStack::PushL( mailBox ); //+2 |
|
79 |
|
80 TUint total, unread; |
|
81 mailBox->TotalMessageCountsL( total, unread ); |
|
82 iLog->Log( _L(" Total msg=%u, unread=%u"), total, unread); |
|
83 |
|
84 RPointerArray<CMsgStoreFolder> folders; |
|
85 |
|
86 mailBox->FoldersL( mailBox->Id(), folders ); |
|
87 |
|
88 TMsgStoreId inboxId = 0; |
|
89 for ( TInt ii = 0 ; ii < folders.Count() ; ii++ ) |
|
90 { |
|
91 CMsgStoreFolder* folder = folders[ii]; |
|
92 TUint index = 0; |
|
93 if ( folder->FindProperty( KMsgStorePropertyName, index ) ) |
|
94 { |
|
95 if ( folder->PropertyValueDesL( index ) == KInbox ) |
|
96 { |
|
97 //found inbox |
|
98 inboxId = folder->Id(); |
|
99 break; |
|
100 } |
|
101 } |
|
102 } |
|
103 folders.ResetAndDestroy(); |
|
104 |
|
105 if ( inboxId == 0 ) |
|
106 { |
|
107 User::Leave( KErrNotFound ); |
|
108 } |
|
109 |
|
110 |
|
111 RArray<RMsgStoreSortCriteria> criteriaArray; |
|
112 RPointerArray<CMsgStoreSortResultIterator> iteratorArray; |
|
113 RArray<TMsgStoreId> curIdArray; |
|
114 RArray<TBool> hasMoreArray; |
|
115 RArray<TMsgStoreIteratorDirection> checkDirectionArray; |
|
116 RArray<TInt> bucketSizeArray; |
|
117 |
|
118 // UpdateText( 2, _L("Start sorting") ); |
|
119 |
|
120 RPointerArray<CMsgStorePropertyContainer> results; |
|
121 |
|
122 //test each sort by field |
|
123 for ( TInt i = 0 ; i < 10 ; i++ ) |
|
124 { |
|
125 RMsgStoreSortCriteria criteria; |
|
126 criteria.iFolderId = inboxId; |
|
127 criteria.AddResultPropertyL( KMsgStorePropertyReceivedAt ); |
|
128 criteria.AddResultPropertyL( KMsgStorePropertyFlags ); |
|
129 criteria.AddResultPropertyL( KMsgStorePropertyMessageSizeOnServer ); |
|
130 criteria.AddResultPropertyL( KMsgStorePropertyFrom ); |
|
131 criteria.AddResultPropertyL( KMsgStorePropertyTo ); |
|
132 criteria.AddResultPropertyL( KMsgStorePropertySubject ); |
|
133 |
|
134 switch( i ) |
|
135 { |
|
136 case 0: |
|
137 //sort by received date |
|
138 iLog->Log( _L("Case %d: Sort By: ReceivedData, Order: Desc"), iCaseId++ ); |
|
139 criteria.iSortBy = EMsgStoreSortByReceivedDate; |
|
140 criteria.iSortOrder = EMsgStoreSortDescending; |
|
141 break; |
|
142 |
|
143 case 1: |
|
144 //sort by EMsgStoreSortByPriority |
|
145 iLog->Log( _L("Case %d: Sort By: Priority, Order: Desc/Desc"), iCaseId++ ); |
|
146 criteria.iSortBy = EMsgStoreSortByPriority; |
|
147 criteria.iSortOrder = EMsgStoreSortDescending; //primary = DESC |
|
148 criteria.iSecondarySortOrder = EMsgStoreSortDescending; //secondary = DESC |
|
149 break; |
|
150 |
|
151 case 2: |
|
152 //sort by EMsgStoreSortByFlagStatus |
|
153 iLog->Log( _L("Case %d: Sort By: Flag, Order: Desc/Asc"), iCaseId++ ); |
|
154 criteria.iSortBy = EMsgStoreSortByFlagStatus; |
|
155 criteria.iSortOrder = EMsgStoreSortDescending; //Primary = DESC |
|
156 criteria.iSecondarySortOrder = EMsgStoreSortAscending; //secondary = ASC |
|
157 break; |
|
158 |
|
159 case 3: |
|
160 //sort by EMsgStoreSortByUnRead |
|
161 iLog->Log( _L("Case %d: Sort By: Unread, Order: Asc/Desc"), iCaseId++ ); |
|
162 criteria.iSortBy = EMsgStoreSortByUnRead; |
|
163 criteria.iSortOrder = EMsgStoreSortAscending; //Primary = ASC |
|
164 criteria.iSecondarySortOrder = EMsgStoreSortDescending; //Secondary = DESC |
|
165 break; |
|
166 |
|
167 case 4: |
|
168 //sort by EMsgStoreSortByAttachment |
|
169 iLog->Log( _L("Case %d: Sort By: Attachment, Order: Asc/Asc"), iCaseId++ ); |
|
170 criteria.iSortBy = EMsgStoreSortByAttachment; |
|
171 criteria.iSortOrder = EMsgStoreSortAscending; //Primary = ASC |
|
172 criteria.iSecondarySortOrder = EMsgStoreSortAscending; //Secondary = ASC |
|
173 break; |
|
174 |
|
175 case 5: |
|
176 //sort by EMsgStoreSortBySize |
|
177 iLog->Log( _L("Case %d: Sort By: Size, Order: Desc/Desc"), iCaseId++ ); |
|
178 criteria.iSortBy = EMsgStoreSortBySize; |
|
179 criteria.iSortOrder = EMsgStoreSortDescending; //Primary = DESC |
|
180 criteria.iSecondarySortOrder = EMsgStoreSortDescending; //Secondary = DESC |
|
181 break; |
|
182 |
|
183 case 6: |
|
184 //sort by EMsgStoreSortBySender |
|
185 iLog->Log( _L("Case %d: Sort By: Sender, Order: Desc/Desc"), iCaseId++ ); |
|
186 criteria.iSortBy = EMsgStoreSortBySender; |
|
187 criteria.iSortOrder = EMsgStoreSortDescending; //Primary = DESC |
|
188 criteria.iSecondarySortOrder = EMsgStoreSortDescending; //Secondary = DESC |
|
189 break; |
|
190 |
|
191 case 7: |
|
192 //sort by EMsgStoreSortByTo |
|
193 iLog->Log( _L("Case %d: Sort By: Recipient, Order: Desc/Desc"), iCaseId++ ); |
|
194 criteria.iSortBy = EMsgStoreSortByRecipient; |
|
195 criteria.iSortOrder = EMsgStoreSortDescending; //Primary = DESC |
|
196 criteria.iSecondarySortOrder = EMsgStoreSortDescending; //Secondary = DESC |
|
197 break; |
|
198 |
|
199 case 8: |
|
200 //sort by EMsgStoreSortBySubject |
|
201 iLog->Log( _L("Case %d: Sort By: Subject, Order: Asc/Desc"), iCaseId++ ); |
|
202 criteria.iSortBy = EMsgStoreSortBySubject; |
|
203 criteria.iSortOrder = EMsgStoreSortAscending; //Primary = ASC |
|
204 criteria.iSecondarySortOrder = EMsgStoreSortDescending; //Secondary = DESC |
|
205 break; |
|
206 |
|
207 case 9: |
|
208 //sort by EMsgStoreSortBySubject |
|
209 iLog->Log( _L("Case %d: Sort By: Subject, Order: Asc/Desc"), iCaseId++ ); |
|
210 criteria.iSortBy = EMsgStoreSortBySubject; |
|
211 criteria.iSortOrder = EMsgStoreSortAscending; //Primary = ASC |
|
212 criteria.iSecondarySortOrder = EMsgStoreSortDescending; //Secondary = DESC |
|
213 break; |
|
214 |
|
215 default: |
|
216 break; |
|
217 } |
|
218 |
|
219 criteriaArray.Append( criteria ); |
|
220 |
|
221 //set the direction |
|
222 TMsgStoreIteratorDirection direction = static_cast<TMsgStoreIteratorDirection>(i % 2); //forward (next) or backward (previous) |
|
223 checkDirectionArray.Append( direction ); |
|
224 |
|
225 //initialize currentId, if forward, start from the top, if backward, start from the bottom |
|
226 TMsgStoreId curId = ( direction == EMsgStoreIteratorForward ) ? KMsgStoreSortResultTop : KMsgStoreSortResultBottom ; |
|
227 curIdArray.Append( curId ); |
|
228 |
|
229 //initialze hasMore to true |
|
230 hasMoreArray.Append(ETrue); |
|
231 |
|
232 CMsgStoreSortResultIterator* iterator = mailBox->SortL( criteria, (i % 2 ? ETrue : EFalse) ); |
|
233 |
|
234 for( TInt jj = 0; jj < 10; jj++ ) |
|
235 { |
|
236 Yield( 25000 ); |
|
237 } |
|
238 |
|
239 if ( i != 5 && i <= 8 ) |
|
240 { |
|
241 iLog->Log( _L("Case %d: Test GroupCountL"), iCaseId++ ); |
|
242 |
|
243 RArray<TUint> itemCounts; |
|
244 CleanupClosePushL( itemCounts ); |
|
245 TInt count = iterator->GroupCountL( itemCounts ); |
|
246 iLog->Log( _L(" GroupCount=%d"), count ); |
|
247 |
|
248 CleanupStack::PopAndDestroy( &itemCounts ); |
|
249 } |
|
250 |
|
251 TBool hasMore = EFalse; |
|
252 TInt bucketSize = 20; |
|
253 |
|
254 //get the results |
|
255 do { |
|
256 results.ResetAndDestroy(); |
|
257 |
|
258 TTime startTime; |
|
259 startTime.HomeTime(); |
|
260 |
|
261 TInt startId = curIdArray[i]; |
|
262 |
|
263 if ( checkDirectionArray[i] == EMsgStoreIteratorForward ) |
|
264 { |
|
265 |
|
266 if ( i == 9 ) |
|
267 { |
|
268 iLog->Log( _L("Case %d: Calling NextL(string)"), iCaseId++ ); |
|
269 hasMore = iterator->NextL( _L("nzz") , bucketSize, results ); |
|
270 } |
|
271 else |
|
272 { |
|
273 iLog->Log( _L("Case %d: Calling NextL"), iCaseId++ ); |
|
274 hasMore = iterator->NextL( curIdArray[i] , bucketSize, results ); |
|
275 } |
|
276 } |
|
277 else |
|
278 { |
|
279 if ( i == 9 ) |
|
280 { |
|
281 iLog->Log( _L("Case %d: Calling PreviousL(string)"), iCaseId++ ); |
|
282 hasMore = iterator->PreviousL( _L("nzz") , bucketSize, results ); |
|
283 } |
|
284 else |
|
285 { |
|
286 iLog->Log( _L("Case %d: Calling PreviousL()"), iCaseId++ ); |
|
287 hasMore = iterator->PreviousL( curIdArray[i] , bucketSize, results ); |
|
288 } |
|
289 } |
|
290 |
|
291 iLog->Log( _L(" Comparing results") ); |
|
292 curIdArray[i] = CompareSortResultsL( criteriaArray[i], checkDirectionArray[i], results ); |
|
293 |
|
294 //TEST SkipAndNext() and SkupAndPrevioud |
|
295 if ( i >= 0 && i <= 8 ) |
|
296 { |
|
297 RPointerArray<CMsgStorePropertyContainer> skipResults; |
|
298 |
|
299 startTime.HomeTime(); |
|
300 |
|
301 TBool hasNextGroup = ETrue; |
|
302 if ( checkDirectionArray[i] == EMsgStoreIteratorForward ) |
|
303 { |
|
304 iLog->Log( _L("Case %d: Testing SkipAndNextL()"), iCaseId++ ); |
|
305 |
|
306 hasNextGroup = iterator->SkipAndNextL( startId , bucketSize, skipResults ); |
|
307 } |
|
308 else |
|
309 { |
|
310 iLog->Log( _L("Case %d: Testing SkipAndPreviousL()"), iCaseId++ ); |
|
311 |
|
312 hasNextGroup = iterator->SkipAndPreviousL( startId, bucketSize, skipResults ); |
|
313 } |
|
314 iLog->Log( _L(" Skip returns %d"), hasNextGroup); |
|
315 |
|
316 iLog->Log( _L(" Comparing results") ); |
|
317 CompareSortResultsL( criteriaArray[i], checkDirectionArray[i], skipResults ); |
|
318 skipResults.ResetAndDestroy(); |
|
319 } |
|
320 |
|
321 if ( bucketSize == 100 ) |
|
322 { |
|
323 hasMore = EFalse; |
|
324 } |
|
325 else |
|
326 { |
|
327 bucketSize += 10; |
|
328 } |
|
329 |
|
330 //add a message while there are sorting sessions |
|
331 if ( bucketSize == 30 ) |
|
332 { |
|
333 iLog->Log( _L("Case %d: Add messages while sort session is open"), iCaseId++ ); |
|
334 CreateRandomMessagesL( mailBox, inboxId, 2, ETrue, ETrue); |
|
335 } |
|
336 else if ( bucketSize == 40 ) |
|
337 { |
|
338 //delete iMatches[0] |
|
339 iLog->Log( _L("Case %d: Delete message while sort session is open"), iCaseId++ ); |
|
340 mailBox->DeleteMessageL( iMatches[0], inboxId ); |
|
341 } |
|
342 else if ( bucketSize == 50 ) |
|
343 { |
|
344 iLog->Log( _L("Case %d: Update message while sort session is open"), iCaseId++ ); |
|
345 CMsgStoreMessage* msg = mailBox->FetchMessageL( iMatches[1], inboxId ); |
|
346 CleanupStack::PushL( msg ); //+msg |
|
347 |
|
348 TTime time; |
|
349 time.HomeTime(); |
|
350 TInt64 seed = time.Int64(); |
|
351 |
|
352 TInt64 date = Math::Rand( seed ); |
|
353 TTime randTime( date ); |
|
354 msg->AddOrUpdatePropertyL( KMsgStorePropertyReceivedAt, randTime ); |
|
355 |
|
356 TUint32 flags = Math::Rand( seed ); |
|
357 msg->AddOrUpdatePropertyL( KMsgStorePropertyFlags, (TUint32) flags ); |
|
358 |
|
359 TUint32 size = Math::Rand( seed ); |
|
360 msg->AddOrUpdatePropertyL( KMsgStorePropertyMessageSizeOnServer, (TUint32) size ); |
|
361 TBuf<30> subject; |
|
362 CreateRandomString( subject, 30, seed ); |
|
363 msg->AddOrUpdatePropertyL( KMsgStorePropertySubject, subject ); |
|
364 |
|
365 TBuf<6> fname, lname; |
|
366 CreateRandomString( fname, 6, seed ); |
|
367 CreateRandomString( lname, 6, seed ); |
|
368 RMsgStoreAddress address; |
|
369 address.iDisplayName.Create( 50 ); |
|
370 address.iEmailAddress.Create( 50 ); |
|
371 |
|
372 address.iDisplayName.Format( _L("%S %S"), &fname, &lname ); |
|
373 address.iEmailAddress.Format( _L("%S.%S@%S"), &fname, &lname, &_L("nokia.com")); |
|
374 msg->AddOrUpdatePropertyL( KMsgStorePropertyFrom, address ); |
|
375 |
|
376 address.iDisplayName.Append(_L("TO")); |
|
377 msg->AddOrUpdatePropertyL( KMsgStorePropertyTo, address ); |
|
378 |
|
379 msg->StorePropertiesL(); |
|
380 |
|
381 //iLog->Log( _L(" msgId=%x, flags=%x, size=%d, date=%Ld"), msg->Id(), flags, size, date ); |
|
382 //iLog->Log( _L(" subject=%S"), &subject ); |
|
383 |
|
384 address.Close(); |
|
385 CleanupStack::PopAndDestroy( msg ); |
|
386 } |
|
387 |
|
388 //update iMatches[1] |
|
389 |
|
390 } while ( hasMore ); |
|
391 |
|
392 |
|
393 //testing IdsAndFlags |
|
394 iLog->Log( _L("Case %d: Testing IdsAndFlagsL()"), iCaseId++ ); |
|
395 RArray<TMsgStoreIdAndFlag> idsAndFlags; |
|
396 iterator->IdsAndFlagsL( idsAndFlags ); |
|
397 |
|
398 iLog->Log( _L(" IdsAndFlagsL returned %d objects"), idsAndFlags.Count() ); |
|
399 |
|
400 idsAndFlags.Reset(); |
|
401 |
|
402 //testing get sorted MessageIds |
|
403 iLog->Log( _L("Case %d: Testing MessageIdsL()"), iCaseId++ ); |
|
404 RArray<TMsgStoreId> ids; |
|
405 //start sorting |
|
406 iterator->MessageIdsL( ids ); |
|
407 |
|
408 iLog->Log( _L(" MessageIds returned %d objects"), ids.Count() ); |
|
409 |
|
410 ids.Reset(); |
|
411 |
|
412 //testing IdsAndGroupCount |
|
413 iLog->Log( _L("Case %d: Testing IdsAndGroupCountL()"), iCaseId++ ); |
|
414 RArray<TUint> itemCounts; |
|
415 CleanupClosePushL( itemCounts ); |
|
416 |
|
417 iterator->IdsAndGroupCountL( ids, itemCounts ); |
|
418 |
|
419 iLog->Log( _L(" GroupCount=%d"), itemCounts.Count() ); |
|
420 |
|
421 //if ( itemCounts.Count() > 0 ) |
|
422 // { |
|
423 // TInt needNToBeMod8 = 8 - itemCounts.Count() % 8; |
|
424 // if ( needNToBeMod8 != 8 ) |
|
425 // { |
|
426 // for ( TInt i = 0 ; i < needNToBeMod8 ; i++ ) |
|
427 // { |
|
428 // itemCounts.Append(0); |
|
429 // } |
|
430 // } |
|
431 // |
|
432 // for ( TInt i = 0 ; i < itemCounts.Count() ; i += 8 ) |
|
433 // { |
|
434 // iLog->Log( _L(" counts: %d, %d, %d, %d, %d, %d, %d, %d"), |
|
435 // itemCounts[i], itemCounts[i+1], itemCounts[i+2], itemCounts[i+3], |
|
436 // itemCounts[i+4], itemCounts[i+5], itemCounts[i+6], itemCounts[i+7] ); |
|
437 // } |
|
438 // } |
|
439 |
|
440 CleanupStack::PopAndDestroy( &itemCounts ); |
|
441 |
|
442 iLog->Log( _L(" MessageIds returned %d objects"), ids.Count() ); |
|
443 |
|
444 ids.Reset(); |
|
445 |
|
446 iLog->Log( _L("Case %d: Testing IndexOfL()"), iCaseId++ ); |
|
447 //add a message after the iterator has been created |
|
448 CreateRandomMessagesL( mailBox, inboxId, 1, ETrue, ETrue ); |
|
449 TInt index = iterator->IndexOfL( iMatches[0] ); |
|
450 |
|
451 iLog->Log( _L(" id=%08x, index=%d"), iMatches[0], index); |
|
452 |
|
453 delete iterator; |
|
454 bucketSizeArray.Append( bucketSize ); |
|
455 } //end for |
|
456 |
|
457 results.ResetAndDestroy(); |
|
458 iMatches.Reset(); |
|
459 |
|
460 |
|
461 CMsgStoreAccount* account2 = CMsgStoreAccount::NewLC( 9999, _L("") ); //+3 |
|
462 CMsgStoreMailBox* mailBox2; |
|
463 TRAPD(err, mailBox2 = iMsgStore->OpenAccountL( *account2 ) ) |
|
464 if ( err != KErrNone ) |
|
465 { |
|
466 mailBox2 = iMsgStore->CreateAccountL( *account2 ); |
|
467 } |
|
468 CleanupStack::PushL( mailBox2 ); //+4 |
|
469 CMsgStorePropertyContainer* prop2 = CMsgStorePropertyContainer::NewL(); |
|
470 CleanupStack::PushL( prop2 ); //+5 |
|
471 |
|
472 TMsgStoreId folder2; |
|
473 |
|
474 for ( TInt i = 0 ; i < 2 ; i++ ) |
|
475 { |
|
476 |
|
477 folder2 = mailBox2->CreateFolderL( mailBox2->Id(), *prop2 ); |
|
478 |
|
479 CreateRandomMessagesL( mailBox2, folder2, 50 ); |
|
480 |
|
481 criteriaArray[0].iFolderId = folder2; |
|
482 criteriaArray[criteriaArray.Count()-1].iFolderId = folder2; |
|
483 |
|
484 CMsgStoreSortResultIterator* iterator1 = mailBox2->SortL( criteriaArray[0] ); |
|
485 CMsgStoreSortResultIterator* iterator2 = mailBox2->SortL( criteriaArray[criteriaArray.Count()-1] ); |
|
486 |
|
487 iterator1->NextL( KMsgStoreSortResultTop, 20, results ); |
|
488 CheckCondition( _L("traverse halfway"), results.Count() == 20 ); |
|
489 results.ResetAndDestroy(); |
|
490 |
|
491 //now we have two sort session, one traversed to half way, one not travesed yet |
|
492 if ( i == 0 ) |
|
493 { |
|
494 iLog->Log( _L("Case %d: Testing delete folder while iterator is open"), iCaseId++ ); |
|
495 //delete the |
|
496 mailBox2->DeleteFolderL( folder2 ); |
|
497 } |
|
498 else |
|
499 { |
|
500 //delete the |
|
501 iLog->Log( _L("Case %d: Testing delete mailbox while iterator is open"), iCaseId++ ); |
|
502 iMsgStore->DeleteAccountL( *account2 ); |
|
503 } |
|
504 |
|
505 TBool hasMore = iterator1->NextL( KMsgStoreSortResultTop , 20, results ); |
|
506 CheckCondition( _L("hasMore==EFalse"), !hasMore ); |
|
507 CheckCondition( _L("no result"), results.Count() == 0 ); |
|
508 |
|
509 |
|
510 hasMore = iterator2->NextL( _L("nzz") , 20, results ); |
|
511 CheckCondition( _L("hasMore==EFalse"), !hasMore ); |
|
512 CheckCondition( _L("no result"), results.Count() == 0 ); |
|
513 |
|
514 delete iterator1; |
|
515 delete iterator2; |
|
516 } |
|
517 |
|
518 for ( int i = 0 ; i < criteriaArray.Count() ; i++ ) |
|
519 { |
|
520 criteriaArray[i].Close(); |
|
521 } |
|
522 |
|
523 criteriaArray.Close(); |
|
524 iteratorArray.ResetAndDestroy(); |
|
525 curIdArray.Close(); |
|
526 hasMoreArray.Close(); |
|
527 checkDirectionArray.Close(); |
|
528 bucketSizeArray.Close(); |
|
529 |
|
530 CleanupStack::PopAndDestroy( 5 ); |
|
531 |
|
532 //we are done |
|
533 return ETrue; |
|
534 } |
|
535 |
|
536 |
|
537 void CSortTests::DoCreateMessagesL( TInt aMsgCount ) |
|
538 { |
|
539 iLog->Log( _L(" >> DoCreateMessages") ); |
|
540 |
|
541 TBool isNew = ETrue; |
|
542 |
|
543 CMsgStore* session = CMsgStore::NewL(); //+1 |
|
544 CleanupStack::PushL( session ); |
|
545 |
|
546 CMsgStoreAccount* account = CMsgStoreAccount::NewLC( KOwner1, KAccount1 ); //+2 |
|
547 CMsgStoreMailBox* mailBox = NULL; |
|
548 TRAPD( err, mailBox = session->CreateAccountL( *account ) ); |
|
549 if ( err != KErrNone ) |
|
550 { |
|
551 mailBox = session->OpenAccountL( *account ); |
|
552 isNew = EFalse; |
|
553 } |
|
554 CleanupStack::PushL( mailBox ); //+3 |
|
555 |
|
556 TMsgStoreId inboxId; |
|
557 |
|
558 if ( isNew ) |
|
559 { |
|
560 CMsgStorePropertyContainer* prop = CMsgStorePropertyContainer::NewL(); |
|
561 CleanupStack::PushL( prop ); |
|
562 |
|
563 inboxId = mailBox->CreateFolderL( mailBox->Id(), *prop ); |
|
564 |
|
565 CleanupStack::PopAndDestroy( prop ); |
|
566 |
|
567 CMsgStoreFolder* folder = mailBox->FolderL( inboxId ); |
|
568 CleanupStack::PushL( folder ); |
|
569 |
|
570 folder->AddPropertyL( KMsgStorePropertyName, KInbox ); |
|
571 folder->StorePropertiesL(); |
|
572 |
|
573 CleanupStack::PopAndDestroy( folder ); |
|
574 } |
|
575 else |
|
576 { |
|
577 RPointerArray<CMsgStoreFolder> folders; |
|
578 |
|
579 mailBox->FoldersL( mailBox->Id(), folders ); |
|
580 |
|
581 for ( int i = 0 ; i < folders.Count() ; i++ ) |
|
582 { |
|
583 CMsgStoreFolder* folder = folders[i]; |
|
584 TUint index = 0; |
|
585 if ( folder->FindProperty( KMsgStorePropertyName, index ) ) |
|
586 { |
|
587 if ( folder->PropertyValueDesL( index ) == KInbox ) |
|
588 { |
|
589 //found inbox |
|
590 inboxId = folder->Id(); |
|
591 break; |
|
592 } |
|
593 } |
|
594 } |
|
595 folders.ResetAndDestroy(); |
|
596 } |
|
597 |
|
598 CreateRandomMessagesL( mailBox, inboxId, aMsgCount ); |
|
599 |
|
600 CleanupStack::PopAndDestroy( 3 ); |
|
601 iLog->Log( _L(" << DoCreateMessages") ); |
|
602 } |
|
603 |
|
604 TMsgStoreId CSortTests::CompareSortResultsL( RMsgStoreSortCriteria aCriteria, |
|
605 TMsgStoreIteratorDirection aDirection, |
|
606 const RPointerArray<CMsgStorePropertyContainer>& aResults ) |
|
607 { |
|
608 iLog->Log( _L(" >> CompareSortResultsL") ); |
|
609 iLog->Log( _L(" result count=%d"), aResults.Count() ); |
|
610 |
|
611 TMsgStoreId lastMsgId; |
|
612 TUint index; |
|
613 TInt64 curVal1, curVal2, nextVal1, nextVal2; |
|
614 TUint size; |
|
615 RBuf curString, nextString; |
|
616 curString.Create(100); |
|
617 nextString.Create(100); |
|
618 TBuf<100> timeString; |
|
619 |
|
620 TBool checkSecondaryOrder = EFalse; |
|
621 TMsgStoreSortOrder compareOrder1, compareOrder2; |
|
622 |
|
623 if ( ( aCriteria.iSortOrder == EMsgStoreSortDescending && aDirection == EMsgStoreIteratorForward ) || |
|
624 ( aCriteria.iSortOrder == EMsgStoreSortAscending && aDirection == EMsgStoreIteratorBackward ) ) |
|
625 { |
|
626 compareOrder1 = EMsgStoreSortDescending; |
|
627 curVal1 = nextVal1 = KMaxTInt64; |
|
628 curString.AppendFill(TChar('z'), 100); |
|
629 } |
|
630 else |
|
631 { |
|
632 compareOrder1 = EMsgStoreSortAscending; |
|
633 curVal1 = nextVal1 = KMinTInt64; |
|
634 curString.AppendFill(TChar('!'), 100); |
|
635 } |
|
636 |
|
637 if ( aCriteria.iSortBy != EMsgStoreSortByReceivedDate ) |
|
638 { |
|
639 checkSecondaryOrder = ETrue; |
|
640 if ( ( aCriteria.iSecondarySortOrder == EMsgStoreSortDescending && aDirection == EMsgStoreIteratorForward ) || |
|
641 ( aCriteria.iSecondarySortOrder == EMsgStoreSortAscending && aDirection == EMsgStoreIteratorBackward ) ) |
|
642 { |
|
643 compareOrder2 = EMsgStoreSortDescending; |
|
644 curVal2 = nextVal2 = KMaxTInt64; |
|
645 } |
|
646 else |
|
647 { |
|
648 compareOrder2 = EMsgStoreSortAscending; |
|
649 curVal2 = nextVal2 = KMinTInt64; |
|
650 } |
|
651 } |
|
652 |
|
653 RTz timeZoneServer; |
|
654 User::LeaveIfError( timeZoneServer.Connect() ); |
|
655 CleanupClosePushL( timeZoneServer ); //+timeZoneServer |
|
656 |
|
657 for ( int i = 0 ; i < aResults.Count() ; i++ ) |
|
658 { |
|
659 CMsgStorePropertyContainer* msg = aResults[i]; |
|
660 |
|
661 CheckCondition( _L("received date property exists"), msg->FindProperty( KMsgStorePropertyReceivedAt, index ), EFalse ); |
|
662 TTime time; |
|
663 msg->PropertyValueTimeL( index, time ); |
|
664 timeZoneServer.ConvertToLocalTime( time ); |
|
665 |
|
666 CheckCondition( _L("flags property exists"), msg->FindProperty( KMsgStorePropertyFlags, index ), EFalse ); |
|
667 TUint32 flags; |
|
668 flags = msg->PropertyValueUint32L( index ); |
|
669 |
|
670 switch( aCriteria.iSortBy ) |
|
671 { |
|
672 case EMsgStoreSortByReceivedDate: |
|
673 time.FormatL( timeString, _L("%F%M/%D/%Y %H:%T:%S") ); |
|
674 nextVal1 = time.Int64(); |
|
675 //iLog->Log( _L(" msg id=%x, received date=%S"), msg->Id(), &timeString); |
|
676 break; |
|
677 |
|
678 case EMsgStoreSortByPriority: |
|
679 nextVal1 = 0; |
|
680 if ( flags & EMsgStoreFlag_Important ) |
|
681 { |
|
682 nextVal1 = 1; |
|
683 } |
|
684 else if ( flags & EMsgStoreFlag_Low ) |
|
685 { |
|
686 nextVal1 = -1; |
|
687 } |
|
688 nextVal2 = time.Int64(); |
|
689 break; |
|
690 |
|
691 case EMsgStoreSortByFlagStatus: |
|
692 nextVal1 = 0; |
|
693 if ( flags & EMsgStoreFlag_FollowUp ) |
|
694 { |
|
695 nextVal1 = 2; |
|
696 } |
|
697 else if ( flags & EMsgStoreFlag_FollowUpComplete ) |
|
698 { |
|
699 nextVal1 = 1; |
|
700 } |
|
701 nextVal2 = time.Int64(); |
|
702 break; |
|
703 |
|
704 case EMsgStoreSortByUnRead: |
|
705 nextVal1 = flags & ( EMsgStoreFlag_Read | EMsgStoreFlag_Read_Locally ); |
|
706 nextVal2 = time.Int64(); |
|
707 //iLog->Log( _L(" msg id=%x, readFlag=%Ld date=%Ld"), msg->Id(), nextVal1, nextVal2); |
|
708 break; |
|
709 |
|
710 case EMsgStoreSortByAttachment: |
|
711 nextVal1 = flags & EMsgStoreFlag_Attachments; |
|
712 nextVal2 = time.Int64(); |
|
713 //iLog->Log( _L(" msg id=%x, attachmentFlag=%Ld date=%Ld"), msg->Id(), nextVal1, nextVal2); |
|
714 break; |
|
715 |
|
716 case EMsgStoreSortBySize: |
|
717 size = 0; |
|
718 if ( msg->FindProperty( KMsgStorePropertyMessageSizeOnServer, index ) ) |
|
719 { |
|
720 size = msg->PropertyValueUint32L( index ); |
|
721 } |
|
722 nextVal1 = size; |
|
723 nextVal2 = time.Int64(); |
|
724 //iLog->Log( _L(" msg id=%x, size=%Ld date=%Ld"), msg->Id(), nextVal1, nextVal2); |
|
725 break; |
|
726 |
|
727 case EMsgStoreSortBySender: |
|
728 { |
|
729 CheckCondition( _L("from property exists"), msg->FindProperty( KMsgStorePropertyFrom, index ), EFalse ); |
|
730 RMsgStoreAddress address; |
|
731 msg->PropertyValueAddressL( index, address ); |
|
732 nextString.Copy( address.iDisplayName ); |
|
733 nextString.Append( address.iEmailAddress ); |
|
734 address.Close(); |
|
735 nextVal2 = time.Int64(); |
|
736 //iLog->Log( _L(" msg id=%x, date=%Ld from=%S"), msg->Id(), nextVal2, &nextString ); |
|
737 } |
|
738 break; |
|
739 |
|
740 case EMsgStoreSortByRecipient: |
|
741 { |
|
742 CheckCondition( _L("to property exists"), msg->FindProperty( KMsgStorePropertyTo, index ), EFalse ); |
|
743 RMsgStoreAddress address; |
|
744 msg->PropertyValueAddressL( index, address ); |
|
745 nextString.Copy( address.iDisplayName ); |
|
746 nextString.Append( address.iEmailAddress ); |
|
747 address.Close(); |
|
748 nextVal2 = time.Int64(); |
|
749 //iLog->Log( _L(" msg id=%x, date=%Ld to=%S"), msg->Id(), nextVal2, &nextString ); |
|
750 } |
|
751 break; |
|
752 |
|
753 case EMsgStoreSortBySubject: |
|
754 { |
|
755 CheckCondition( _L("subject property exists"), msg->FindProperty( KMsgStorePropertySubject, index ), EFalse ); |
|
756 const TDesC& subject = msg->PropertyValueDesL( index ); |
|
757 nextVal2 = time.Int64(); |
|
758 //iLog->Log( _L(" msg id=%x, date=%Ld subj=%S"), msg->Id(), nextVal2, &subject ); |
|
759 |
|
760 //get rid of the "Alpha:" "AlphaAlpha:" "AlphaAlphaAlpha:" |
|
761 nextString.Copy( subject ); |
|
762 TPtr16 ptr = nextString.MidTPtr(0); |
|
763 TBool prefixFound = ETrue; |
|
764 while ( prefixFound ) |
|
765 { |
|
766 ptr.TrimLeft(); |
|
767 TInt pos = ptr.Locate( TChar(':') ); |
|
768 if ( pos > 0 && pos <= 3 ) |
|
769 { |
|
770 for ( TInt i = 0; i < pos; i++ ) |
|
771 { |
|
772 TChar ch = ptr[i]; |
|
773 if ( !ch.IsAlpha() ) |
|
774 { |
|
775 prefixFound = EFalse; |
|
776 break; |
|
777 } |
|
778 } |
|
779 if ( prefixFound ) |
|
780 { |
|
781 ptr = ptr.Mid( pos + 1 ); |
|
782 } |
|
783 } |
|
784 else |
|
785 { |
|
786 prefixFound = EFalse; |
|
787 } |
|
788 } |
|
789 |
|
790 nextString.Copy( ptr ); |
|
791 } |
|
792 break; |
|
793 |
|
794 default: |
|
795 break; |
|
796 } |
|
797 |
|
798 TInt primaryOrder = 0; |
|
799 if ( aCriteria.iSortBy == EMsgStoreSortBySender || |
|
800 aCriteria.iSortBy == EMsgStoreSortByRecipient || |
|
801 aCriteria.iSortBy == EMsgStoreSortBySubject ) |
|
802 { |
|
803 primaryOrder = nextString.CompareC( curString, 1, NULL ); |
|
804 } |
|
805 else |
|
806 { |
|
807 primaryOrder = ( nextVal1 < curVal1 ? -1 : ( nextVal1 == curVal1 ? 0 : 1 ) ); |
|
808 } |
|
809 |
|
810 if ( compareOrder1 == EMsgStoreSortDescending ) |
|
811 { |
|
812 CheckCondition( _L("primary order"), primaryOrder <= 0, EFalse ); |
|
813 } |
|
814 else |
|
815 { |
|
816 CheckCondition( _L("primary order"), primaryOrder >= 0, EFalse ); |
|
817 } |
|
818 |
|
819 if ( checkSecondaryOrder && primaryOrder == 0 ) |
|
820 { |
|
821 //compare the secondary order |
|
822 if ( compareOrder2 == EMsgStoreSortDescending ) |
|
823 { |
|
824 CheckCondition( _L("2nd value order"), nextVal2 <= curVal2, EFalse ); |
|
825 } |
|
826 else |
|
827 { |
|
828 CheckCondition( _L("2nd value order"), nextVal2 >= curVal2, EFalse ); |
|
829 } |
|
830 } |
|
831 |
|
832 curVal1 = nextVal1; |
|
833 curVal2 = nextVal2; |
|
834 curString.Copy( nextString ); |
|
835 |
|
836 if ( i == aResults.Count() - 1 ) |
|
837 { |
|
838 lastMsgId = msg->Id(); |
|
839 } |
|
840 } |
|
841 |
|
842 CleanupStack::PopAndDestroy( &timeZoneServer ); |
|
843 |
|
844 curString.Close(); |
|
845 nextString.Close(); |
|
846 |
|
847 iLog->Log( _L(" << CompareSortResultsL - PASSED") ); |
|
848 |
|
849 return lastMsgId; |
|
850 |
|
851 } |
|
852 |
|
853 |
|
854 // End of File |