|
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: Base class for all test cases class member functions |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // [INCLUDE FILES] - do not remove |
|
21 #include <tz.h> |
|
22 #include "MessageTests.h" |
|
23 //#include <ismsgstorepropertykeys.h> |
|
24 #include "messagestoreclientserver.h" |
|
25 |
|
26 // ============================ MEMBER FUNCTIONS =============================== |
|
27 |
|
28 CMessageTests* CMessageTests::NewL( CStifLogger* aLog ) |
|
29 { |
|
30 CMessageTests* self = new(ELeave) CMessageTests( aLog ); |
|
31 CleanupStack::PushL( self ); |
|
32 self->ConstructL(); |
|
33 CleanupStack::Pop( self ); |
|
34 return self; |
|
35 } |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // Constructor |
|
39 // ----------------------------------------------------------------------------- |
|
40 CMessageTests::CMessageTests( CStifLogger* aLog ) : CAsyncTestCaseBase( aLog ) |
|
41 { |
|
42 } |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // Destructor |
|
46 // ----------------------------------------------------------------------------- |
|
47 CMessageTests::~CMessageTests() |
|
48 { |
|
49 } |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // 2nd phase constructor |
|
53 // ----------------------------------------------------------------------------- |
|
54 void CMessageTests::ConstructL() |
|
55 { |
|
56 CAsyncTestCaseBase::ConstructL(); |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // ExecuteL : start executing the test case |
|
61 // ----------------------------------------------------------------------------- |
|
62 TBool CMessageTests::ExecuteL() |
|
63 { |
|
64 LogHeader( _L("Message") ); |
|
65 |
|
66 //account 1 |
|
67 CMsgStoreAccount* account1 = CMsgStoreAccount::NewLC( 1234, KNullDesC ); //+1 |
|
68 CMsgStoreMailBox* mailBox1 = iMsgStore->CreateAccountL( *account1 ); |
|
69 CleanupStack::PushL( mailBox1 ); //+2 |
|
70 |
|
71 //accoun 2 |
|
72 CMsgStoreAccount* account2 = CMsgStoreAccount::NewLC( 4567, _L("Account 2") ); //+3 |
|
73 CMsgStoreMailBox* mailBox2 = iMsgStore->CreateAccountL( *account2 ); |
|
74 CleanupStack::PushL( mailBox2 ); //+4 |
|
75 |
|
76 CMsgStorePropertyContainer* properties = CMsgStorePropertyContainer::NewL(); |
|
77 |
|
78 CleanupStack::PushL( properties ); //+5 |
|
79 TestAddIntegerPropertyL( *properties, _L8("INTEGER PROPERTY"), 99999 ); |
|
80 TestAddDes8PropertyL( *properties, _L8("STRING PROPERTY"), _L8("STRING VALUE") ); |
|
81 TestAddDesPropertyL( *properties, _L8("name"), _L("Inbox") ); |
|
82 |
|
83 TMsgStoreId inbox1Id = mailBox1->CreateFolderL( mailBox1->Id(), *properties ); |
|
84 CMsgStoreFolder* inbox1 = mailBox1->FolderL( inbox1Id ); |
|
85 CleanupStack::PushL( inbox1 ); //+6 |
|
86 |
|
87 TMsgStoreId inbox2Id = mailBox2->CreateFolderL( mailBox2->Id(), *properties ); |
|
88 CMsgStoreFolder* inbox2 = mailBox2->FolderL( inbox2Id ); |
|
89 CleanupStack::PushL( inbox2 ); //+7 |
|
90 |
|
91 //create outbox folders for mailbox1 and mailbox2 |
|
92 CMsgStorePropertyContainer* outboxProp = CMsgStorePropertyContainer::NewL(); |
|
93 CleanupStack::PushL( outboxProp ); //+8 |
|
94 |
|
95 TestAddIntegerPropertyL( *outboxProp, _L8("INTEGER PROPERTY"), 99999 ); |
|
96 TestAddDes8PropertyL( *outboxProp, _L8("STRING PROPERTY"), _L8("STRING VALUE") ); |
|
97 TestAddDesPropertyL( *outboxProp, _L8("name"), _L("Outbox") ); |
|
98 |
|
99 TMsgStoreId outbox1Id = mailBox1->CreateFolderL( mailBox1->Id(), *outboxProp ); |
|
100 CMsgStoreFolder* outbox1 = mailBox1->FolderL( outbox1Id ); |
|
101 CleanupStack::PushL( outbox1 ); //+9 |
|
102 |
|
103 TMsgStoreId outbox2Id = mailBox1->CreateFolderL( mailBox2->Id(), *outboxProp ); |
|
104 CMsgStoreFolder* outbox2 = mailBox1->FolderL( outbox2Id ); |
|
105 CleanupStack::PushL( outbox2 ); //+10 |
|
106 |
|
107 |
|
108 RArray<TMsgStoreId> expectedIds; |
|
109 |
|
110 CMsgStorePropertyContainer* properties2 = CMsgStorePropertyContainer::NewL(); |
|
111 CleanupStack::PushL( properties2 ); //+11 |
|
112 TestAddIntegerPropertyL( *properties2, KMsgStorePropertyFlags, 0 ); |
|
113 TestAddIntegerPropertyL( *properties2, KMsgStorePropertyReplyBy, 1 ); |
|
114 TestAddIntegerPropertyL( *properties2, _L8("SOME INTEGER PROPERTY"), KMaxTUint32 ); |
|
115 TestAddDes8PropertyL( *properties2, _L8("SOME OTHER PROPERTY"), _L8("SOME VALUE") ); |
|
116 |
|
117 iLog->Log( _L("Case %d: Create messages"), iCaseId++ ); |
|
118 |
|
119 _LIT8( KTestContent, "TEST CONTENT" ); |
|
120 |
|
121 CMsgStoreMessage* message1 = mailBox1->CreateMessageL( inbox1Id, *properties2 ); |
|
122 CleanupStack::PushL( message1 ); //+12 |
|
123 |
|
124 iLog->Log( _L("Case %d: Total Message Count"), iCaseId++ ); |
|
125 |
|
126 //get message counts |
|
127 TUint totalCount, unreadCount; |
|
128 mailBox1->TotalMessageCountsL( totalCount, unreadCount ); |
|
129 |
|
130 CheckCondition( _L("Msg Not Committed. Count=0"), totalCount==0 && unreadCount==0 ); |
|
131 |
|
132 message1->CommitL(); |
|
133 |
|
134 mailBox1->TotalMessageCountsL( totalCount, unreadCount ); |
|
135 CheckCondition( _L("Msg Commited. Count=1"), totalCount==1 && unreadCount==1 ); |
|
136 |
|
137 iLog->Log( _L("Case %d: Create message in a different way"), iCaseId++ ); |
|
138 CMsgStorePropertyContainer* props = CMsgStorePropertyContainer::NewL(); |
|
139 props->AddOrUpdatePropertyL( KMsgStorePropertyFlags, (TUint32) 0 ); //set the unread flag |
|
140 |
|
141 CMsgStoreMessage* tmpMsg = mailBox1->CreateMessageL( inbox1Id, *props ); |
|
142 |
|
143 mailBox1->TotalMessageCountsL( totalCount, unreadCount ); |
|
144 CheckCondition( _L("Msg Not Committed. Count=1"), totalCount==1 && unreadCount==1 ); |
|
145 |
|
146 mailBox1->TotalMessageCountsL( totalCount, unreadCount ); |
|
147 CheckCondition( _L("Msg Not Committed. Count=1"), totalCount==1 && unreadCount==1 ); |
|
148 |
|
149 tmpMsg->CommitL(); |
|
150 |
|
151 mailBox1->TotalMessageCountsL( totalCount, unreadCount ); |
|
152 CheckCondition( _L("Msg Commited. Count=2"), totalCount==2 && unreadCount==2 ); |
|
153 |
|
154 iLog->Log( _L("Case %d: Delete Message"), iCaseId++ ); |
|
155 mailBox1->DeleteMessageL( tmpMsg->Id(), inbox1Id ); |
|
156 |
|
157 delete tmpMsg; |
|
158 |
|
159 iLog->Log( _L("Case %d: Abandon Uncommitted Message"), iCaseId++ ); |
|
160 tmpMsg = mailBox1->CreateMessageL( inbox1Id, *props ); |
|
161 //Instead commit, abandon it |
|
162 tmpMsg->AbandonL(); |
|
163 |
|
164 delete tmpMsg; |
|
165 |
|
166 delete props; |
|
167 |
|
168 iLog->Log( _L("Case %d: StorePropertiesL in between create and commit"), iCaseId++ ); |
|
169 CMsgStoreMessage* message2 = mailBox1->CreateMessageL( inbox1Id, *properties2 ); |
|
170 CleanupStack::PushL( message2 ); //+13 |
|
171 |
|
172 // Test StorePropertiesL in between create and commit. This is no supported |
|
173 // for uncommitted messages. |
|
174 TRAPD( err, message2->StorePropertiesL() ); |
|
175 // Test StorePropertyL in between create and commit. |
|
176 TRAPD( err1, message2->StorePropertyL( 0 ) ); |
|
177 |
|
178 CheckCondition( _L("StoreProperties failed as expected. Count=2"), |
|
179 err==KErrNotFound && err1==KErrNotFound ); |
|
180 message2->CommitL(); |
|
181 |
|
182 iLog->Log( _L("Case %d: Create message in different folders/mailboxes"), iCaseId++ ); |
|
183 CMsgStoreMessage* message3 = mailBox1->CreateMessageL( outbox1Id, *properties2 ); |
|
184 CleanupStack::PushL( message3 ); //+14 |
|
185 message3->CommitL(); |
|
186 |
|
187 CMsgStoreMessage* message4 = mailBox1->CreateMessageL( outbox1Id, *properties2 ); |
|
188 CleanupStack::PushL( message4 ); //+15 |
|
189 message4->CommitL(); |
|
190 |
|
191 CMsgStoreMessage* message5 = mailBox2->CreateMessageL( inbox2Id, *properties2 ); |
|
192 CleanupStack::PushL( message5 ); //+16 |
|
193 message5->CommitL(); |
|
194 |
|
195 CMsgStoreMessage* message6 = mailBox2->CreateMessageL( inbox2Id, *properties2 ); |
|
196 CleanupStack::PushL( message6 ); //+17 |
|
197 message6->CommitL(); |
|
198 |
|
199 CMsgStoreMessage* message7 = mailBox2->CreateMessageL( outbox2Id, *properties2 ); |
|
200 CleanupStack::PushL( message7 ); //+18 |
|
201 message7->CommitL(); |
|
202 |
|
203 CMsgStoreMessage* message8 = mailBox2->CreateMessageL( outbox2Id, *properties2 ); |
|
204 CleanupStack::PushL( message8 ); //+19 |
|
205 message8->CommitL(); |
|
206 |
|
207 message1->ReplaceContentL( KTestContent ); |
|
208 message2->ReplaceContentL( KTestContent ); |
|
209 message3->ReplaceContentL( KTestContent ); |
|
210 message4->ReplaceContentL( KTestContent ); |
|
211 message5->ReplaceContentL( KTestContent ); |
|
212 |
|
213 iLog->Log( _L(" Verify contents of each folder") ); |
|
214 |
|
215 expectedIds.AppendL( message1->Id() ); |
|
216 expectedIds.AppendL( message2->Id() ); |
|
217 VerifyMessageIdsL( *mailBox1, inbox1Id, expectedIds ); |
|
218 expectedIds.Reset(); |
|
219 |
|
220 expectedIds.AppendL( message3->Id() ); |
|
221 expectedIds.AppendL( message4->Id() ); |
|
222 VerifyMessageIdsL( *mailBox1, outbox1Id, expectedIds ); |
|
223 expectedIds.Reset(); |
|
224 |
|
225 expectedIds.AppendL( message5->Id() ); |
|
226 expectedIds.AppendL( message6->Id() ); |
|
227 VerifyMessageIdsL( *mailBox2, inbox2Id, expectedIds ); |
|
228 expectedIds.Reset(); |
|
229 |
|
230 expectedIds.AppendL( message7->Id() ); |
|
231 expectedIds.AppendL( message8->Id() ); |
|
232 VerifyMessageIdsL( *mailBox2, outbox2Id, expectedIds ); |
|
233 expectedIds.Reset(); |
|
234 |
|
235 //Message counts |
|
236 DoMessageCountsL( *mailBox1 ); |
|
237 DoMessageCountsL( *mailBox2 ); |
|
238 |
|
239 iLog->Log( _L("Case %d: Move messages"), iCaseId++ ); |
|
240 |
|
241 mailBox1->MoveMessageL( message1->Id(), inbox1Id, outbox1Id ); |
|
242 mailBox1->MoveMessageL( message2->Id(), inbox1Id, outbox1Id ); |
|
243 mailBox2->MoveMessageL( message7->Id(), outbox2Id, inbox2Id ); |
|
244 mailBox2->MoveMessageL( message8->Id(), outbox2Id, inbox2Id ); |
|
245 |
|
246 iLog->Log( _L(" Verify contents of each folder") ); |
|
247 |
|
248 VerifyMessageIdsL( *mailBox1, inbox1Id, expectedIds ); |
|
249 expectedIds.Reset(); |
|
250 |
|
251 expectedIds.AppendL( message1->Id() ); |
|
252 expectedIds.AppendL( message2->Id() ); |
|
253 expectedIds.AppendL( message3->Id() ); |
|
254 expectedIds.AppendL( message4->Id() ); |
|
255 VerifyMessageIdsL( *mailBox1, outbox1->Id(), expectedIds ); |
|
256 expectedIds.Reset(); |
|
257 |
|
258 VerifyMessageIdsL( *mailBox2, outbox2->Id(), expectedIds ); |
|
259 expectedIds.Reset(); |
|
260 |
|
261 expectedIds.AppendL( message5->Id() ); |
|
262 expectedIds.AppendL( message6->Id() ); |
|
263 expectedIds.AppendL( message7->Id() ); |
|
264 expectedIds.AppendL( message8->Id() ); |
|
265 VerifyMessageIdsL( *mailBox2, inbox2->Id(), expectedIds ); |
|
266 expectedIds.Reset(); |
|
267 |
|
268 DoMessageCountsL( *mailBox1 ); |
|
269 DoMessageCountsL( *mailBox2 ); |
|
270 |
|
271 iLog->Log( _L("Case %d: Delete messages"), iCaseId++ ); |
|
272 |
|
273 mailBox1->DeleteMessageL( message1->Id(), outbox1Id ); |
|
274 mailBox2->DeleteMessageL( message8->Id(), inbox2Id ); |
|
275 |
|
276 iLog->Log( _L(" Verify contents of each folder") ); |
|
277 |
|
278 VerifyMessageIdsL( *mailBox1, inbox1Id, expectedIds ); |
|
279 expectedIds.Reset(); |
|
280 |
|
281 expectedIds.AppendL( message2->Id() ); |
|
282 expectedIds.AppendL( message3->Id() ); |
|
283 expectedIds.AppendL( message4->Id() ); |
|
284 VerifyMessageIdsL( *mailBox1, outbox1->Id(), expectedIds ); |
|
285 expectedIds.Reset(); |
|
286 |
|
287 VerifyMessageIdsL( *mailBox2, outbox2->Id(), expectedIds ); |
|
288 expectedIds.Reset(); |
|
289 |
|
290 expectedIds.AppendL( message5->Id() ); |
|
291 expectedIds.AppendL( message6->Id() ); |
|
292 expectedIds.AppendL( message7->Id() ); |
|
293 VerifyMessageIdsL( *mailBox2, inbox2->Id(), expectedIds ); |
|
294 expectedIds.Reset(); |
|
295 |
|
296 DoMessageCountsL( *mailBox1 ); |
|
297 DoMessageCountsL( *mailBox2 ); |
|
298 |
|
299 iLog->Log( _L("Case %d: Copy message"), iCaseId++ ); |
|
300 |
|
301 TMsgStoreId newId = mailBox1->CopyMessageL( message3->Id(), outbox1->Id(), inbox1->Id() ); |
|
302 |
|
303 iLog->Log( _L(" Delete all other messages") ); |
|
304 |
|
305 mailBox1->DeleteMessageL( message2->Id(), outbox1->Id() ); |
|
306 mailBox1->DeleteMessageL( message3->Id(), outbox1->Id() ); |
|
307 mailBox1->DeleteMessageL( message4->Id(), outbox1->Id() ); |
|
308 mailBox2->DeleteMessageL( message5->Id(), inbox2->Id() ); |
|
309 mailBox2->DeleteMessageL( message6->Id(), inbox2->Id() ); |
|
310 mailBox2->DeleteMessageL( message7->Id(), inbox2->Id() ); |
|
311 |
|
312 iLog->Log( _L(" Verify contents of each folder") ); |
|
313 |
|
314 expectedIds.AppendL( newId ); |
|
315 VerifyMessageIdsL( *mailBox1, inbox1->Id(), expectedIds ); |
|
316 expectedIds.Reset(); |
|
317 |
|
318 VerifyMessageIdsL( *mailBox1, outbox1->Id(), expectedIds ); |
|
319 VerifyMessageIdsL( *mailBox2, inbox2->Id(), expectedIds ); |
|
320 VerifyMessageIdsL( *mailBox2, outbox2->Id(), expectedIds ); |
|
321 |
|
322 iLog->Log( _L(" Fetch copied message") ); |
|
323 |
|
324 CMsgStoreMessage* newMessage = mailBox1->FetchMessageL( newId, inbox1->Id() ); |
|
325 |
|
326 iLog->Log( _L(" Verify properties and content") ); |
|
327 |
|
328 ComparePropertiesL( *newMessage, *properties2 ); |
|
329 |
|
330 TBuf8<1000> contentBuf; |
|
331 newMessage->FetchContentToBufferL( contentBuf ); |
|
332 CheckCondition( _L("content matches"), contentBuf.Compare( KTestContent ) == 0 ); |
|
333 |
|
334 delete newMessage; |
|
335 |
|
336 iLog->Log( _L("Case %d: Message Commit"), iCaseId++ ); |
|
337 |
|
338 CMsgStoreMessage* msg1 = mailBox1->CreateMessageL( inbox1Id, *properties ); |
|
339 CleanupStack::PushL( msg1 ); //+20 |
|
340 msg1->ReplaceContentL( _L8("CONTENT1") ); |
|
341 TInt result = KErrNone; |
|
342 TRAP( result, mailBox1->FetchMessageL( msg1->Id(), inbox1Id ) ); |
|
343 CheckCondition( _L("uncommitted message not found"), result == KErrNotFound ); |
|
344 |
|
345 CMsgStoreMessagePart* part1 = msg1->AddChildPartL( *properties ); |
|
346 part1->AppendToContentL( _L8("CONTENT2") ); |
|
347 // TRAP( result, msg1->ChildPartL( part1->Id() ) ); |
|
348 // CheckCondition( _L("uncommitted message not found"), result == KErrNotFound ); |
|
349 |
|
350 _LIT( KFilename, "C:\\test_content.txt" ); |
|
351 _LIT8( KContent, "THIS IS THE CONTENT FOR THIS TEST" ); |
|
352 RFs fs; |
|
353 User::LeaveIfError( fs.Connect() ); |
|
354 RFile file; |
|
355 User::LeaveIfError( file.Replace( fs, KFilename, EFileWrite ) ); |
|
356 file.Write( KContent ); |
|
357 file.Close(); |
|
358 fs.Close(); |
|
359 |
|
360 // CMsgStoreMessagePart* part2 = msg1->AddChildPartL( *properties ); |
|
361 // part2->ReplaceContentWithFileL( KFilename ); |
|
362 // TRAP( result, tmpPart = msg1->ChildPartL( part2->Id() ) ); |
|
363 // CheckCondition( _L("uncommitted message not found"), result == KErrNotFound ); |
|
364 |
|
365 msg1->CommitL(); |
|
366 iLog->Log( _L(" Message committed") ); |
|
367 |
|
368 TMsgStoreId message1Id = msg1->Id(); |
|
369 |
|
370 iLog->Log( _L("Case %d: Fetch message in a specific folder"), iCaseId++ ); |
|
371 message2 = mailBox1->FetchMessageL( message1Id, inbox1->Id() ); |
|
372 ComparePropertiesL( *message2, *properties ); |
|
373 delete message2; |
|
374 |
|
375 iLog->Log( _L("Case %d: Fetch message in an unknown folder"), iCaseId++ ); |
|
376 message2 = mailBox1->FetchMessageL( message1Id, KMsgStoreInvalidId ); |
|
377 ComparePropertiesL( *message2, *properties ); |
|
378 |
|
379 iLog->Log( _L(" Verify contents") ); |
|
380 |
|
381 TBuf8<100> tmpBuf; |
|
382 message2->FetchContentToBufferL( tmpBuf ); |
|
383 CheckCondition( _L("content fetched"), tmpBuf.Compare(_L8("CONTENT1")) == 0 ); |
|
384 |
|
385 CMsgStoreMessagePart* part3 = msg1->ChildPartL( part1->Id() ); |
|
386 ComparePropertiesL( *part3, *properties ); |
|
387 |
|
388 part3->FetchContentToBufferL( tmpBuf ); |
|
389 CheckCondition( _L("content fetched"), tmpBuf.Compare(_L8("CONTENT2")) == 0 ); |
|
390 |
|
391 delete part1; |
|
392 // delete part2; |
|
393 delete part3; |
|
394 delete message2; |
|
395 |
|
396 // OUT OF MEMORY ERROR PATH TESTS |
|
397 |
|
398 iLog->Log( _L("Case %d: Error - Out of memory"), iCaseId++ ); |
|
399 for( TInt i = 0; i < 4; i++ ) |
|
400 { |
|
401 SimulateLowDiskSpaceL( i ); |
|
402 TRAP( result, mailBox1->CopyMessageL( message1Id, inbox1Id, outbox1Id ) ); |
|
403 CheckCondition( _L("out of memory"), result == KErrNoMemory ); |
|
404 } |
|
405 |
|
406 // ERROR PATH TESTS |
|
407 |
|
408 // Nonexistent message/folder or wrong folder |
|
409 |
|
410 iLog->Log( _L("Case %d: Error - Delete nonexistent message"), iCaseId++ ); |
|
411 |
|
412 TRAP( result, mailBox1->DeleteMessageL( message1Id, outbox1Id ) ); |
|
413 CheckCondition( _L("not found"), result == KErrNotFound ); |
|
414 |
|
415 iLog->Log( _L("Case %d: Error - Move nonexistent message"), iCaseId++ ); |
|
416 |
|
417 TRAP( result, mailBox1->MoveMessageL( message1Id, outbox1Id, inbox1Id ) ); |
|
418 CheckCondition( _L("not found"), result == KErrNotFound ); |
|
419 |
|
420 // __LOG_WRITE_INFO( "Replace content for nonexistent message." ) |
|
421 |
|
422 // TRAP( result, message1->ReplaceContentL( _L8("CONTENT") ) ); |
|
423 // CheckCondition( _L("not found"), result == KErrNotFound ); |
|
424 |
|
425 iLog->Log( _L("Case %d: Error - ReplaceContentWithFileL for nonexistent message"), iCaseId++ ); |
|
426 |
|
427 TRAP( result, message1->ReplaceContentWithFileL( KFilename ) ); |
|
428 CheckCondition( _L("not found"), result == KErrNotFound ); |
|
429 |
|
430 iLog->Log( _L("Case %d: Error - Append to content for nonexistent message"), iCaseId++ ); |
|
431 |
|
432 TRAP( result, message1->AppendToContentL( _L8("CONTENT") ) ); |
|
433 CheckCondition( _L("not found"), result == KErrNotFound ); |
|
434 |
|
435 iLog->Log( _L("Case %d: Error - ContentLengthL for nonexistent message"), iCaseId++ ); |
|
436 |
|
437 TRAP( result, message1->ContentLengthL() ); |
|
438 CheckCondition( _L("not found"), result == KErrNotFound ); |
|
439 |
|
440 iLog->Log( _L("Case %d: Error - FetchContentToBufferL for nonexistent message"), iCaseId++ ); |
|
441 |
|
442 TRAP( result, message1->FetchContentToBufferL( contentBuf ) ); |
|
443 CheckCondition( _L("not found"), result == KErrNotFound ); |
|
444 |
|
445 iLog->Log( _L("Case %d: Error - FetchContentToFileL for nonexistent message"), iCaseId++ ); |
|
446 |
|
447 TRAP( result, message1->FetchContentToFileL( KFilename ) ); |
|
448 CheckCondition( _L("not found"), result == KErrNotFound ); |
|
449 |
|
450 CMsgStoreMessage* msg3 = mailBox1->CreateMessageL( inbox1Id, *properties ); |
|
451 CleanupStack::PushL( msg3 ); //+21 |
|
452 msg3->CommitL(); |
|
453 |
|
454 iLog->Log( _L("Case %d: Error - Delete message from wrong folder"), iCaseId++ ); |
|
455 |
|
456 TRAP( result, mailBox1->DeleteMessageL( msg3->Id(), outbox1Id ) ); |
|
457 CheckCondition( _L("not found"), result == KErrNotFound ); |
|
458 |
|
459 iLog->Log( _L("Case %d: Error - Move message from wrong folder"), iCaseId++ ); |
|
460 |
|
461 TRAP( result, mailBox1->MoveMessageL( msg3->Id(), outbox1Id, inbox1Id ) ); |
|
462 CheckCondition( _L("not found"), result == KErrNotFound ); |
|
463 |
|
464 iLog->Log( _L("Case %d: Error - Move message from nonexistent folder"), iCaseId++ ); |
|
465 |
|
466 TRAP( result, mailBox1->MoveMessageL( msg3->Id(), inbox1Id, inbox1Id + 50 ) ); |
|
467 CheckCondition( _L("not found"), result == KErrNotFound ); |
|
468 |
|
469 iLog->Log( _L("Case %d: Error - Create message in nonexistent folder"), iCaseId++ ); |
|
470 |
|
471 TRAP( result, |
|
472 CMsgStoreMessage* msg = mailBox1->CreateMessageL( inbox1Id + 50, *properties ); |
|
473 CleanupStack::PushL( msg ); |
|
474 msg->CommitL(); |
|
475 CleanupStack::PopAndDestroy( msg ); |
|
476 ); |
|
477 CheckCondition( _L("not found"), result == KErrNotFound ); |
|
478 |
|
479 // Content file not found |
|
480 iLog->Log( _L("Case %d: Error - ReplaceContentWithFileL with nonexistent file"), iCaseId++ ); |
|
481 |
|
482 TRAP( result, msg3->ReplaceContentWithFileL( _L("c:\\some_nonexistent_file.txt") ) ); |
|
483 CheckCondition( _L("not found"), result == KErrNotFound ); |
|
484 |
|
485 TMsgStoreId messageId = msg3->Id(); |
|
486 |
|
487 iLog->Log( _L("Case %d: Error - Commit message into deleted folder"), iCaseId++ ); |
|
488 |
|
489 TMsgStoreId folderId = mailBox1->CreateFolderL( inbox1Id, *properties ); |
|
490 CMsgStoreMessage* msg4 = mailBox1->CreateMessageL( folderId, *properties ); |
|
491 CleanupStack::PushL( msg4 ); //+22 |
|
492 mailBox1->DeleteFolderL( folderId ); |
|
493 TRAP( result, msg4->CommitL() ); |
|
494 CheckCondition( _L("not found"), result == KErrNotFound ); |
|
495 |
|
496 // Wrong types |
|
497 |
|
498 iLog->Log( _L("Case %d: Error - Create message with invalid type for folder"), iCaseId++ ); |
|
499 |
|
500 TRAP( result, mailBox1->CreateMessageL( messageId, *properties ) ); |
|
501 CheckCondition( _L("argument error"), result == KErrArgument ); |
|
502 |
|
503 iLog->Log( _L("Case %d: Error - Delete message with invalid type for message"), iCaseId++ ); |
|
504 |
|
505 TRAP( result, mailBox1->DeleteMessageL( folderId, folderId ) ); |
|
506 CheckCondition( _L("argument error"), result == KErrArgument ); |
|
507 |
|
508 iLog->Log( _L("Case %d: Error - Delete message with invalid type for folder"), iCaseId++ ); |
|
509 |
|
510 TRAP( result, mailBox1->DeleteMessageL( messageId, messageId ) ); |
|
511 CheckCondition( _L("argument error"), result == KErrArgument ); |
|
512 |
|
513 iLog->Log( _L("Case %d: Error - Move message with invalid type for message"), iCaseId++ ); |
|
514 |
|
515 TRAP( result, mailBox1->MoveMessageL( folderId, folderId, folderId ) ); |
|
516 CheckCondition( _L("argument error"), result == KErrArgument ); |
|
517 |
|
518 iLog->Log( _L("Case %d: Error - Move message with invalid type for source folder"), iCaseId++ ); |
|
519 |
|
520 TRAP( result, mailBox1->MoveMessageL( messageId, messageId, folderId ) ); |
|
521 CheckCondition( _L("argument error"), result == KErrArgument ); |
|
522 |
|
523 iLog->Log( _L("Case %d: Error - Move message with invalid type for destination folder"), iCaseId++ ); |
|
524 |
|
525 TRAP( result, mailBox1->MoveMessageL( messageId, folderId, messageId ) ); |
|
526 CheckCondition( _L("argument error"), result == KErrArgument ); |
|
527 |
|
528 iLog->Log( _L("Case %d: Error - Fetch message with invalid type for message"), iCaseId++ ); |
|
529 |
|
530 TRAP( result, mailBox1->FetchMessageL( folderId, folderId ) ); |
|
531 CheckCondition( _L("argument error"), result == KErrArgument ); |
|
532 |
|
533 CleanupStack::PopAndDestroy( 22 ); |
|
534 |
|
535 //we are done |
|
536 return ETrue; |
|
537 } |
|
538 |
|
539 void CMessageTests::VerifyMessageIdsL( CMsgStoreMailBox& aMailBox, TMsgStoreId aFolderId, RArray<TMsgStoreId>& expectedIds ) |
|
540 { |
|
541 iLog->Log( _L(" >> VerifyMessageIdsL") ); |
|
542 |
|
543 RArray<TMsgStoreId> ids; |
|
544 |
|
545 aMailBox.MessageIdsL( aFolderId, ids ); |
|
546 |
|
547 TBool passed = (ids.Count() == expectedIds.Count() ); |
|
548 |
|
549 for( TInt i = 0; i < ids.Count(); i++ ) |
|
550 { |
|
551 TBool found = EFalse; |
|
552 for ( TInt j = 0; j < expectedIds.Count() && !found; j++ ) |
|
553 { |
|
554 found = (ids[i] == expectedIds[j]); |
|
555 } |
|
556 passed = passed && found; |
|
557 } |
|
558 |
|
559 if( !passed ) |
|
560 { |
|
561 for( TInt i = 0; i < expectedIds.Count(); i++ ) |
|
562 { |
|
563 iLog->Log( _L(" expected=%i"), expectedIds[i] ); |
|
564 } |
|
565 for( TInt i = 0; i < ids.Count(); i++ ) |
|
566 { |
|
567 iLog->Log( _L(" found=%i"), ids[i] ); |
|
568 } |
|
569 } |
|
570 |
|
571 TBuf<30> text; |
|
572 text.Format( _L("%i ids matched"), ids.Count() ); |
|
573 CheckCondition( text, passed ); |
|
574 |
|
575 ids.Close(); |
|
576 |
|
577 iLog->Log( _L(" << VerifyMessageIdsL") ); |
|
578 } |
|
579 |
|
580 |
|
581 void CMessageTests::DoMessageCountsL( CMsgStoreMailBox& aMailBox ) |
|
582 { |
|
583 iLog->Log( _L(" Message counts") ); |
|
584 |
|
585 TUint totalCount, unreadCount; |
|
586 aMailBox.TotalMessageCountsL( totalCount, unreadCount ); |
|
587 iLog->Log( _L(" mb=%u total=%u, unread=%u"), aMailBox.Id(), totalCount, unreadCount ); |
|
588 |
|
589 RPointerArray<CMsgStoreFolder> folders; |
|
590 aMailBox.FoldersL( folders ); |
|
591 |
|
592 for ( TInt i = 0 ; i < folders.Count() ; i++ ) |
|
593 { |
|
594 aMailBox.MessageCountsL( folders[i]->Id(), totalCount, unreadCount ); |
|
595 iLog->Log( _L(" folder=%u total=%u, unread=%u"), folders[i]->Id(), totalCount, unreadCount ); |
|
596 } |
|
597 |
|
598 folders.ResetAndDestroy(); |
|
599 } |
|
600 |
|
601 |
|
602 |
|
603 // End of File |