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