|
1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // To build: bldmake bldfiles |
|
15 // abld test build wins udeb |
|
16 // To run from windows command prompt: |
|
17 // cd epoc32\release\wins\udeb |
|
18 // T_CIMEMAILMESSAGE -dtextshell -- |
|
19 // |
|
20 // |
|
21 |
|
22 |
|
23 #include <e32base.h> |
|
24 #include <e32std.h> |
|
25 #include <e32cons.h> |
|
26 #include <e32test.h> |
|
27 #include <s32file.h> |
|
28 |
|
29 // Message Server headers for linking to msgs.dll. |
|
30 #include <msvapi.h> |
|
31 #include <msvids.h> |
|
32 #include <msvuids.h> |
|
33 #include <msvstd.h> |
|
34 |
|
35 // Class under test. |
|
36 #include <miutmsg.h> |
|
37 |
|
38 #include <mmsvattachmentmanager.h> |
|
39 |
|
40 #include "emailtestutils.h" |
|
41 |
|
42 typedef enum |
|
43 { |
|
44 EGetBodyTextL, |
|
45 EFindFirstHTMLPageL, |
|
46 EGetMessageDigestEntriesL, |
|
47 EGetAttachmentListsL, |
|
48 EDeleteAttachmentLId1, |
|
49 EDeleteAttachmentLId2, |
|
50 EFindUniversalResourceIdentifierL, |
|
51 EAddMessageAsAttachmentLId1, |
|
52 EAddMessageAsAttachmentLId2, |
|
53 EAddRelatedPartL, |
|
54 EStoreBodyTextL, |
|
55 EGetCharacterSetL, |
|
56 EDeleteAttachedMessageL |
|
57 } TMethodType; |
|
58 |
|
59 // Forwards |
|
60 class CMyScheduler; |
|
61 class CObserver; |
|
62 |
|
63 |
|
64 // Test harness constants and global variables... |
|
65 _LIT(KTitle, "T_CIMEMAILMESSAGE"); |
|
66 _LIT(KFolderName, "DeleteMe"); |
|
67 CTrapCleanup* pcleanup = NULL; |
|
68 CMyScheduler* pscheduler = NULL; |
|
69 RTest test(KTitle); |
|
70 LOCAL_D CEmailTestUtils* testUtils; |
|
71 RFs gFs; |
|
72 CMsvSession* pSession = NULL; |
|
73 CObserver* pObserver = NULL; |
|
74 CMsvEntry* pContext = NULL; |
|
75 CTestActive* pTestActive = NULL; |
|
76 |
|
77 // Global email message entry identifiers. |
|
78 TMsvId gEmailMessageID; |
|
79 TMsvId gEmailMessageID2; |
|
80 TMethodType gMethodType; |
|
81 |
|
82 |
|
83 // Test utility classes |
|
84 class CMyScheduler : public CActiveScheduler |
|
85 { |
|
86 private: |
|
87 void Error(TInt aError) const; |
|
88 }; |
|
89 void CMyScheduler::Error(TInt /*aError*/) const {} |
|
90 |
|
91 |
|
92 class CObserver : public MMsvSessionObserver |
|
93 { |
|
94 public: |
|
95 void HandleSessionEvent(TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* aArg3); |
|
96 void HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* aArg3); |
|
97 }; |
|
98 |
|
99 |
|
100 void CObserver::HandleSessionEvent(TMsvSessionEvent /*aEvent*/, TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/) |
|
101 { |
|
102 } |
|
103 |
|
104 |
|
105 void CObserver::HandleSessionEventL(TMsvSessionEvent /*aEvent*/, TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/) |
|
106 { |
|
107 } |
|
108 |
|
109 // Test Case Prototypes |
|
110 LOCAL_C TBool TestAttachmentFlagL(); |
|
111 LOCAL_C void TestGetBodyTextL(CImEmailMessage* aEmailMessage, TRequestStatus& aStatus); |
|
112 LOCAL_C void TestStoreBodyTextL(CImEmailMessage* aEmailMessage, TRequestStatus& aStatus); |
|
113 LOCAL_C TBool TestPanicsL(); |
|
114 |
|
115 // Test Harness Prototypes |
|
116 LOCAL_C void DoTestThreadWorkL(); |
|
117 static TInt DoTestThreadStart(TAny*); |
|
118 LOCAL_C void InitL(); |
|
119 LOCAL_C void UninitL(); |
|
120 LOCAL_C void doTests(); |
|
121 LOCAL_C void doMainL(); |
|
122 GLDEF_C TInt E32Main(); |
|
123 |
|
124 _LIT(KTestThreadName, "CImEmailMessage Test Thread"); |
|
125 |
|
126 LOCAL_C void TestGetBodyTextL(CImEmailMessage* aEmailMessage, TRequestStatus& aStatus) |
|
127 { |
|
128 CParaFormatLayer* paraFormatLayer=CParaFormatLayer::NewL(); |
|
129 CleanupStack::PushL(paraFormatLayer); |
|
130 |
|
131 CCharFormatLayer* charFormatLayer=CCharFormatLayer::NewL(); |
|
132 CleanupStack::PushL(charFormatLayer); |
|
133 |
|
134 CRichText* bodyText=CRichText::NewL(paraFormatLayer, charFormatLayer, CEditableText::EFlatStorage, 256); |
|
135 CleanupStack::PushL(bodyText); |
|
136 |
|
137 TBuf<100> bodyContents = _L("Test body contents so that we can test the store body text code."); |
|
138 bodyText->InsertL(0, bodyContents); |
|
139 aEmailMessage->GetBodyTextL( |
|
140 aStatus, |
|
141 gEmailMessageID2, |
|
142 CImEmailMessage::EThisMessageOnly, |
|
143 *bodyText, |
|
144 *paraFormatLayer, |
|
145 *charFormatLayer); |
|
146 |
|
147 CleanupStack::PopAndDestroy(3, paraFormatLayer); |
|
148 } |
|
149 |
|
150 LOCAL_C void TestStoreBodyTextL(CImEmailMessage* aEmailMessage, TRequestStatus& aStatus) |
|
151 { |
|
152 CParaFormatLayer* paraFormatLayer=CParaFormatLayer::NewL(); |
|
153 CleanupStack::PushL(paraFormatLayer); |
|
154 |
|
155 CCharFormatLayer* charFormatLayer=CCharFormatLayer::NewL(); |
|
156 CleanupStack::PushL(charFormatLayer); |
|
157 |
|
158 CRichText* bodyText=CRichText::NewL(paraFormatLayer, charFormatLayer, CEditableText::EFlatStorage, 256); |
|
159 CleanupStack::PushL(bodyText); |
|
160 |
|
161 TBuf<100> bodyContents = _L("Test body contents so that we can test the store body text code."); |
|
162 bodyText->InsertL(0, bodyContents); |
|
163 aEmailMessage->StoreBodyTextL(gEmailMessageID2, *bodyText, aStatus); |
|
164 |
|
165 CleanupStack::PopAndDestroy(3, paraFormatLayer); |
|
166 } |
|
167 |
|
168 LOCAL_C void DoTestThreadWorkL() |
|
169 { |
|
170 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler; |
|
171 CActiveScheduler::Install(scheduler); |
|
172 CleanupStack::PushL(scheduler); |
|
173 |
|
174 // Connect to the Message Server... |
|
175 CObserver* ob = new (ELeave) CObserver; |
|
176 CleanupStack::PushL(ob); |
|
177 |
|
178 CMsvSession* session = CMsvSession::OpenSyncL(*ob); |
|
179 CleanupStack::PushL(session); |
|
180 |
|
181 CMsvEntry* cEntry = CMsvEntry::NewL(*session, KMsvGlobalInBoxIndexEntryId, TMsvSelectionOrdering()); |
|
182 CleanupStack::PushL(cEntry); |
|
183 CImEmailMessage* emailMessage = CImEmailMessage::NewLC(*cEntry); |
|
184 |
|
185 switch(gMethodType) |
|
186 { |
|
187 case EGetBodyTextL: |
|
188 TestGetBodyTextL(emailMessage, pTestActive->iStatus); |
|
189 break; |
|
190 |
|
191 case EFindFirstHTMLPageL: |
|
192 emailMessage->FindFirstHTMLPageL(gEmailMessageID2, pTestActive->iStatus); |
|
193 break; |
|
194 |
|
195 case EGetMessageDigestEntriesL: |
|
196 emailMessage->GetMessageDigestEntriesL(pTestActive->iStatus, gEmailMessageID2); |
|
197 break; |
|
198 |
|
199 case EGetAttachmentListsL: |
|
200 emailMessage->GetAttachmentsListL( |
|
201 gEmailMessageID2, |
|
202 CImEmailMessage::EAllAttachments, |
|
203 CImEmailMessage::EThisMessageOnly); |
|
204 break; |
|
205 |
|
206 case EDeleteAttachmentLId1: |
|
207 { |
|
208 TMsvAttachmentId attachmentId = gEmailMessageID; |
|
209 emailMessage->AttachmentManager().RemoveAttachmentL(attachmentId,pTestActive->iStatus); |
|
210 } |
|
211 break; |
|
212 |
|
213 case EDeleteAttachmentLId2: |
|
214 { |
|
215 TMsvAttachmentId attachmentId = gEmailMessageID; |
|
216 emailMessage->AttachmentManager().RemoveAttachmentL(attachmentId,pTestActive->iStatus); |
|
217 } |
|
218 break; |
|
219 |
|
220 case EFindUniversalResourceIdentifierL: |
|
221 emailMessage->FindUniversalResourceIdentifierL( |
|
222 gEmailMessageID2, |
|
223 _L("a description"), |
|
224 _L("http://someuri.com"), |
|
225 pTestActive->iStatus); |
|
226 break; |
|
227 |
|
228 case EAddMessageAsAttachmentLId1: |
|
229 { |
|
230 CMsvAttachment* attachmentInfo = CMsvAttachment::NewL(CMsvAttachment::EMsvFile); |
|
231 CleanupStack::PushL(attachmentInfo); |
|
232 emailMessage->AttachmentManager().AddEntryAsAttachmentL(gEmailMessageID,attachmentInfo,pTestActive->iStatus); |
|
233 CleanupStack::Pop(attachmentInfo); |
|
234 } |
|
235 break; |
|
236 |
|
237 case EAddMessageAsAttachmentLId2: |
|
238 { |
|
239 CMsvAttachment* attachmentInfo = CMsvAttachment::NewL(CMsvAttachment::EMsvFile); |
|
240 CleanupStack::PushL(attachmentInfo); |
|
241 emailMessage->AttachmentManager().AddEntryAsAttachmentL(gEmailMessageID2,attachmentInfo,pTestActive->iStatus); |
|
242 CleanupStack::Pop(attachmentInfo); |
|
243 } |
|
244 break; |
|
245 |
|
246 case EAddRelatedPartL: |
|
247 emailMessage->AddRelatedPartL(gEmailMessageID2, _L("some text"), pTestActive->iStatus, gEmailMessageID, _L8("some text")); |
|
248 break; |
|
249 |
|
250 case EStoreBodyTextL: |
|
251 TestStoreBodyTextL(emailMessage, pTestActive->iStatus); |
|
252 break; |
|
253 |
|
254 case EGetCharacterSetL: |
|
255 { |
|
256 TUint charSetId = 0; |
|
257 TBool override = EFalse; |
|
258 emailMessage->GetCharacterSetL(gEmailMessageID2, charSetId, override); |
|
259 break; |
|
260 } |
|
261 case EDeleteAttachedMessageL: |
|
262 { |
|
263 TMsvAttachmentId attachmentId = gEmailMessageID; |
|
264 emailMessage->AttachmentManager().RemoveAttachmentL(attachmentId,pTestActive->iStatus); |
|
265 } |
|
266 break; |
|
267 } |
|
268 |
|
269 CleanupStack::PopAndDestroy(5, scheduler); |
|
270 } |
|
271 |
|
272 static TInt DoTestThreadStart(TAny*) |
|
273 { |
|
274 // Entry function for the child thread which is created then killed. |
|
275 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
276 test(cleanup != NULL); |
|
277 TRAPD(ret, DoTestThreadWorkL()); |
|
278 delete cleanup; |
|
279 return 0; |
|
280 } |
|
281 |
|
282 LOCAL_C TBool TestAttachmentFlagL() |
|
283 { |
|
284 TBool result = EFalse; |
|
285 TMsvId emailMessageID; |
|
286 TMsvId attachMessageID; |
|
287 |
|
288 // Create an email message entry. |
|
289 CImEmailOperation* emailOp = CImEmailOperation::CreateNewL(pTestActive->iStatus, *pSession, KMsvGlobalInBoxIndexEntryId, KMsvMessagePartBody, 0, KUidMsgTypeSMTP); |
|
290 CleanupStack::PushL(emailOp); |
|
291 pTestActive->StartL(); // Active object which stops the active scheduler |
|
292 CActiveScheduler::Start(); |
|
293 // Get the new message id. |
|
294 TPckg<TMsvId> param(emailMessageID); |
|
295 param.Copy(emailOp->FinalProgress()); |
|
296 CleanupStack::PopAndDestroy(emailOp); |
|
297 |
|
298 emailOp = CImEmailOperation::CreateNewL(pTestActive->iStatus, *pSession, KMsvGlobalInBoxIndexEntryId, KMsvMessagePartBody, 0, KUidMsgTypeSMTP); |
|
299 CleanupStack::PushL(emailOp); |
|
300 pTestActive->StartL(); // Active object which stops the active scheduler |
|
301 CActiveScheduler::Start(); |
|
302 TPckg<TMsvId> param2(attachMessageID); |
|
303 param2.Copy(emailOp->FinalProgress()); |
|
304 CleanupStack::PopAndDestroy(emailOp); |
|
305 |
|
306 CImEmailMessage* obj = CImEmailMessage::NewLC(*pContext); |
|
307 |
|
308 pContext->SetEntryL(emailMessageID); |
|
309 TMsvEntry entry = pContext->Entry(); |
|
310 result = !(entry.Attachment()); |
|
311 CMsvAttachment* attachmentInfo = CMsvAttachment::NewL(CMsvAttachment::EMsvFile); |
|
312 CleanupStack::PushL(attachmentInfo); |
|
313 obj->AttachmentManager().AddEntryAsAttachmentL(attachMessageID,attachmentInfo,pTestActive->iStatus); |
|
314 CleanupStack::Pop(attachmentInfo); |
|
315 pTestActive->StartL(); |
|
316 CActiveScheduler::Start(); |
|
317 CleanupStack::PopAndDestroy(obj); |
|
318 obj = NULL; |
|
319 |
|
320 // Want to test that the entry's attachment flag is true; |
|
321 pContext->SetEntryL(emailMessageID); |
|
322 entry = pContext->Entry(); |
|
323 result &= (entry.Attachment() != EFalse); |
|
324 |
|
325 pContext->DeleteL(attachMessageID); |
|
326 pContext->DeleteL(emailMessageID); |
|
327 |
|
328 return result; |
|
329 } |
|
330 |
|
331 LOCAL_C TBool TestPanicsL() |
|
332 { |
|
333 const TInt KMinTestHeapSize = 0x10000; |
|
334 const TInt KMaxTestHeapSize = 0x100000; |
|
335 |
|
336 RThread testThread; |
|
337 TRequestStatus requestStatus; |
|
338 |
|
339 TBool result = ETrue; |
|
340 TMsvEntry entry; |
|
341 |
|
342 // Make sure paniced threads don't cause us trouble. |
|
343 User::SetJustInTime(EFalse); |
|
344 |
|
345 // |
|
346 //-------------------------------------------------------------------------- |
|
347 // Create email message entries. |
|
348 //-------------------------------------------------------------------------- |
|
349 // |
|
350 CImEmailOperation* emailOp = CImEmailOperation::CreateNewL(pTestActive->iStatus, *pSession, KMsvGlobalInBoxIndexEntryId, KMsvMessagePartBody, 0, KUidMsgTypeSMTP); |
|
351 CleanupStack::PushL(emailOp); |
|
352 pTestActive->StartL(); // Active object which stops the active scheduler |
|
353 CActiveScheduler::Start(); |
|
354 // Get the new message id. |
|
355 TPckg<TMsvId> param(gEmailMessageID); |
|
356 param.Copy(emailOp->FinalProgress()); |
|
357 CleanupStack::PopAndDestroy(emailOp); |
|
358 |
|
359 emailOp = CImEmailOperation::CreateNewL(pTestActive->iStatus, *pSession, KMsvGlobalInBoxIndexEntryId, KMsvMessagePartBody, 0, KUidMsgTypeSMTP); |
|
360 CleanupStack::PushL(emailOp); |
|
361 pTestActive->StartL(); // Active object which stops the active scheduler |
|
362 CActiveScheduler::Start(); |
|
363 TPckg<TMsvId> param2(gEmailMessageID2); |
|
364 param2.Copy(emailOp->FinalProgress()); |
|
365 CleanupStack::PopAndDestroy(emailOp); |
|
366 |
|
367 CImEmailMessage* emailMessage = CImEmailMessage::NewLC(*pContext); |
|
368 |
|
369 pContext->SetEntryL(gEmailMessageID2); |
|
370 entry = pContext->Entry(); |
|
371 // Set to something inappropriate |
|
372 entry.iType = KUidMsvAttachmentEntry; |
|
373 pContext->ChangeL(entry); |
|
374 |
|
375 // |
|
376 //-------------------------------------------------------------------------- |
|
377 //- Test CImEmailMessage::GetBodyTextL ------------------------------------- |
|
378 //-------------------------------------------------------------------------- |
|
379 // |
|
380 gMethodType = EGetBodyTextL; |
|
381 testThread.Create( |
|
382 KTestThreadName, |
|
383 DoTestThreadStart, |
|
384 KDefaultStackSize, |
|
385 KMinTestHeapSize, |
|
386 KMaxTestHeapSize, |
|
387 NULL, |
|
388 EOwnerThread); |
|
389 testThread.Logon(requestStatus); |
|
390 |
|
391 // Let the thread run |
|
392 testThread.Resume(); |
|
393 User::WaitForRequest(requestStatus); |
|
394 result &= |
|
395 ((testThread.ExitType() == EExitPanic) && |
|
396 (testThread.ExitReason() == EEntryIsNotMessage)); |
|
397 testThread.Close(); |
|
398 |
|
399 // |
|
400 //-------------------------------------------------------------------------- |
|
401 //- Test CImEmailMessage::FindFirstHTMLPageL ------------------------------- |
|
402 //-------------------------------------------------------------------------- |
|
403 // |
|
404 gMethodType = EFindFirstHTMLPageL; |
|
405 testThread.Create( |
|
406 KTestThreadName, |
|
407 DoTestThreadStart, |
|
408 KDefaultStackSize, |
|
409 KMinTestHeapSize, |
|
410 KMaxTestHeapSize, |
|
411 NULL, |
|
412 EOwnerThread); |
|
413 testThread.Logon(requestStatus); |
|
414 |
|
415 // Let the thread run |
|
416 testThread.Resume(); |
|
417 User::WaitForRequest(requestStatus); |
|
418 result &= |
|
419 ((testThread.ExitType() == EExitPanic) && |
|
420 (testThread.ExitReason() == EEntryIsNotMessage)); |
|
421 testThread.Close(); |
|
422 |
|
423 |
|
424 // |
|
425 //-------------------------------------------------------------------------- |
|
426 //- Test CImEmailMessage::GetMessageDigestEntriesL ------------------------- |
|
427 //-------------------------------------------------------------------------- |
|
428 // |
|
429 gMethodType = EGetMessageDigestEntriesL; |
|
430 testThread.Create( |
|
431 KTestThreadName, |
|
432 DoTestThreadStart, |
|
433 KDefaultStackSize, |
|
434 KMinTestHeapSize, |
|
435 KMaxTestHeapSize, |
|
436 NULL, |
|
437 EOwnerThread); |
|
438 testThread.Logon(requestStatus); |
|
439 |
|
440 // Let the thread run |
|
441 testThread.Resume(); |
|
442 User::WaitForRequest(requestStatus); |
|
443 result &= |
|
444 ((testThread.ExitType() == EExitPanic) && |
|
445 (testThread.ExitReason() == EEntryIsNotMessage)); |
|
446 testThread.Close(); |
|
447 |
|
448 |
|
449 // |
|
450 //-------------------------------------------------------------------------- |
|
451 //- Test CImEmailMessage::GetAttachmentListsL ------------------------------ |
|
452 //-------------------------------------------------------------------------- |
|
453 // |
|
454 gMethodType = EGetAttachmentListsL; |
|
455 testThread.Create( |
|
456 KTestThreadName, |
|
457 DoTestThreadStart, |
|
458 KDefaultStackSize, |
|
459 KMinTestHeapSize, |
|
460 KMaxTestHeapSize, |
|
461 NULL, |
|
462 EOwnerThread); |
|
463 testThread.Logon(requestStatus); |
|
464 |
|
465 // Let the thread run |
|
466 testThread.Resume(); |
|
467 User::WaitForRequest(requestStatus); |
|
468 result &= |
|
469 ((testThread.ExitType() == EExitPanic) && |
|
470 (testThread.ExitReason() == EEntryIsNotMessage)); |
|
471 testThread.Close(); |
|
472 |
|
473 |
|
474 // |
|
475 //-------------------------------------------------------------------------- |
|
476 //- Test CImEmailMessage::DeleteAttachmentL -------------------------------- |
|
477 //-------------------------------------------------------------------------- |
|
478 // |
|
479 |
|
480 gMethodType = EDeleteAttachmentLId1; |
|
481 testThread.Create( |
|
482 KTestThreadName, |
|
483 DoTestThreadStart, |
|
484 KDefaultStackSize, |
|
485 KMinTestHeapSize, |
|
486 KMaxTestHeapSize, |
|
487 NULL, |
|
488 EOwnerThread); |
|
489 testThread.Logon(requestStatus); |
|
490 |
|
491 // Let the thread run |
|
492 testThread.Resume(); |
|
493 User::WaitForRequest(requestStatus); |
|
494 result &= |
|
495 ((testThread.ExitType() == EExitPanic) && |
|
496 (testThread.ExitReason() == EEntryIsNotMessage)); |
|
497 testThread.Close(); |
|
498 |
|
499 pContext->SetEntryL(gEmailMessageID2); |
|
500 entry = pContext->Entry(); |
|
501 entry.iType = KUidMsvMessageEntry; |
|
502 pContext->ChangeL(entry); |
|
503 |
|
504 // The first message ID points to an entry of type KUidMsvMessageEntry. |
|
505 // The second message ID will cause a leave because it isn't a KUidMsvAttachmentEntry |
|
506 gMethodType = EDeleteAttachmentLId2; |
|
507 testThread.Create( |
|
508 KTestThreadName, |
|
509 DoTestThreadStart, |
|
510 KDefaultStackSize, |
|
511 KMinTestHeapSize, |
|
512 KMaxTestHeapSize, |
|
513 NULL, |
|
514 EOwnerThread); |
|
515 testThread.Logon(requestStatus); |
|
516 |
|
517 // Let the thread run |
|
518 testThread.Resume(); |
|
519 User::WaitForRequest(requestStatus); |
|
520 result &= |
|
521 ((testThread.ExitType() == EExitPanic) && |
|
522 (testThread.ExitReason() == EEntryIsNotMessage)); |
|
523 testThread.Close(); |
|
524 |
|
525 pContext->SetEntryL(gEmailMessageID2); |
|
526 entry = pContext->Entry(); |
|
527 entry.iType = KUidMsvAttachmentEntry; |
|
528 pContext->ChangeL(entry); |
|
529 |
|
530 // |
|
531 //-------------------------------------------------------------------------- |
|
532 //- Test CImEmailMessage::FindUniversalResourceIdentifierL ----------------- |
|
533 //-------------------------------------------------------------------------- |
|
534 // |
|
535 |
|
536 gMethodType = EFindUniversalResourceIdentifierL; |
|
537 testThread.Create( |
|
538 KTestThreadName, |
|
539 DoTestThreadStart, |
|
540 KDefaultStackSize, |
|
541 KMinTestHeapSize, |
|
542 KMaxTestHeapSize, |
|
543 NULL, |
|
544 EOwnerThread); |
|
545 testThread.Logon(requestStatus); |
|
546 |
|
547 // Let the thread run |
|
548 testThread.Resume(); |
|
549 User::WaitForRequest(requestStatus); |
|
550 result &= |
|
551 ((testThread.ExitType() == EExitPanic) && |
|
552 (testThread.ExitReason() == EEntryIsNotMessage)); |
|
553 testThread.Close(); |
|
554 |
|
555 |
|
556 // |
|
557 //-------------------------------------------------------------------------- |
|
558 //- Test CImEmailMessage::AddMessageAsAttachmentL -------------------------- |
|
559 //-------------------------------------------------------------------------- |
|
560 // |
|
561 |
|
562 gMethodType = EAddMessageAsAttachmentLId1; |
|
563 testThread.Create( |
|
564 KTestThreadName, |
|
565 DoTestThreadStart, |
|
566 KDefaultStackSize, |
|
567 KMinTestHeapSize, |
|
568 KMaxTestHeapSize, |
|
569 NULL, |
|
570 EOwnerThread); |
|
571 testThread.Logon(requestStatus); |
|
572 |
|
573 // Let the thread run |
|
574 testThread.Resume(); |
|
575 User::WaitForRequest(requestStatus); |
|
576 result &= |
|
577 ((testThread.ExitType() == EExitPanic) && |
|
578 (testThread.ExitReason() == EEntryIsNotMessage)); |
|
579 testThread.Close(); |
|
580 |
|
581 // The first message ID points to an entry of type KUidMsvMessageEntry. |
|
582 // The second message ID will cause a leave because it isn't a KUidMsvMessageEntry |
|
583 gMethodType = EAddMessageAsAttachmentLId2; |
|
584 testThread.Create( |
|
585 KTestThreadName, |
|
586 DoTestThreadStart, |
|
587 KDefaultStackSize, |
|
588 KMinTestHeapSize, |
|
589 KMaxTestHeapSize, |
|
590 NULL, |
|
591 EOwnerThread); |
|
592 testThread.Logon(requestStatus); |
|
593 |
|
594 // Let the thread run |
|
595 testThread.Resume(); |
|
596 User::WaitForRequest(requestStatus); |
|
597 result &= |
|
598 ((testThread.ExitType() == EExitPanic) && |
|
599 (testThread.ExitReason() == EEntryIsNotMessage)); |
|
600 testThread.Close(); |
|
601 |
|
602 // |
|
603 //-------------------------------------------------------------------------- |
|
604 //- Test CImEmailMessage::AddRelatedPartL ---------------------------------- |
|
605 //-------------------------------------------------------------------------- |
|
606 // |
|
607 pContext->SetEntryL(KMsvGlobalInBoxIndexEntryId); |
|
608 TMsvId folderId = 0; |
|
609 TMsvEmailEntry folderEntry; |
|
610 folderEntry.iType = KUidMsvFolderEntry; |
|
611 folderEntry.iMtm = KUidMsvLocalServiceMtm; |
|
612 folderEntry.iServiceId = KMsvLocalServiceIndexEntryId; |
|
613 folderEntry.iDetails.Set(KFolderName); |
|
614 // Set the relatedPartID's parent folder type to something acceptable |
|
615 |
|
616 TMsvLocalOperationProgress details; |
|
617 CMsvOperation* opert = pContext->CreateL(folderEntry, pTestActive->iStatus); |
|
618 CleanupStack::PushL(opert); |
|
619 pTestActive->StartL(); // Active object which stops the active scheduler |
|
620 CActiveScheduler::Start(); |
|
621 TPckg<TMsvLocalOperationProgress> folderParam(details); |
|
622 folderParam.Copy(opert->FinalProgress()); |
|
623 folderId = details.iId; |
|
624 pContext->SetEntryL(folderId); |
|
625 CleanupStack::PopAndDestroy(opert); |
|
626 |
|
627 // Set the relatedPartID's parent folder to the one just created |
|
628 opert = NULL; |
|
629 pContext->SetEntryL(KMsvGlobalInBoxIndexEntryId); |
|
630 pTestActive->StartL(); // Active object which stops the active scheduler |
|
631 opert = pContext->MoveL(gEmailMessageID2, folderId, pTestActive->iStatus); |
|
632 CleanupStack::PushL(opert); |
|
633 CActiveScheduler::Start(); |
|
634 CleanupStack::PopAndDestroy(opert); |
|
635 |
|
636 // emailMessageID2 is not of KUidMsvMessageEntry. |
|
637 gMethodType = EAddRelatedPartL; |
|
638 testThread.Create( |
|
639 KTestThreadName, |
|
640 DoTestThreadStart, |
|
641 KDefaultStackSize, |
|
642 KMinTestHeapSize, |
|
643 KMaxTestHeapSize, |
|
644 NULL, |
|
645 EOwnerThread); |
|
646 testThread.Logon(requestStatus); |
|
647 |
|
648 // Let the thread run |
|
649 testThread.Resume(); |
|
650 User::WaitForRequest(requestStatus); |
|
651 result &= |
|
652 ((testThread.ExitType() == EExitPanic) && |
|
653 (testThread.ExitReason() == EEntryIsNotMessage)); |
|
654 testThread.Close(); |
|
655 |
|
656 // |
|
657 //-------------------------------------------------------------------------- |
|
658 //- Test CImEmailMessage::StoreBodyTextL ----------------- |
|
659 //-------------------------------------------------------------------------- |
|
660 // |
|
661 |
|
662 gMethodType = EStoreBodyTextL; |
|
663 testThread.Create( |
|
664 KTestThreadName, |
|
665 DoTestThreadStart, |
|
666 KDefaultStackSize, |
|
667 KMinTestHeapSize, |
|
668 KMaxTestHeapSize, |
|
669 NULL, |
|
670 EOwnerThread); |
|
671 testThread.Logon(requestStatus); |
|
672 |
|
673 // Let the thread run |
|
674 testThread.Resume(); |
|
675 User::WaitForRequest(requestStatus); |
|
676 result &= |
|
677 ((testThread.ExitType() == EExitPanic) && |
|
678 (testThread.ExitReason() == EEntryIsNotMessage)); |
|
679 testThread.Close(); |
|
680 |
|
681 // |
|
682 //-------------------------------------------------------------------------- |
|
683 //- Test CImEmailMessage::GetCharacterSetL ----------------- |
|
684 //-------------------------------------------------------------------------- |
|
685 // |
|
686 |
|
687 gMethodType = EGetCharacterSetL; |
|
688 testThread.Create( |
|
689 KTestThreadName, |
|
690 DoTestThreadStart, |
|
691 KDefaultStackSize, |
|
692 KMinTestHeapSize, |
|
693 KMaxTestHeapSize, |
|
694 NULL, |
|
695 EOwnerThread); |
|
696 testThread.Logon(requestStatus); |
|
697 |
|
698 // Let the thread run |
|
699 testThread.Resume(); |
|
700 User::WaitForRequest(requestStatus); |
|
701 result &= |
|
702 ((testThread.ExitType() == EExitPanic) && |
|
703 (testThread.ExitReason() == EEntryIsNotMessage)); |
|
704 testThread.Close(); |
|
705 |
|
706 // |
|
707 //-------------------------------------------------------------------------- |
|
708 //- Test CImEmailMessage::DeleteAttachedMesageL ----------------- |
|
709 //-------------------------------------------------------------------------- |
|
710 // |
|
711 |
|
712 gMethodType = EDeleteAttachedMessageL; |
|
713 testThread.Create( |
|
714 KTestThreadName, |
|
715 DoTestThreadStart, |
|
716 KDefaultStackSize, |
|
717 KMinTestHeapSize, |
|
718 KMaxTestHeapSize, |
|
719 NULL, |
|
720 EOwnerThread); |
|
721 testThread.Logon(requestStatus); |
|
722 |
|
723 // Let the thread run |
|
724 testThread.Resume(); |
|
725 User::WaitForRequest(requestStatus); |
|
726 result &= |
|
727 ((testThread.ExitType() == EExitPanic) && |
|
728 (testThread.ExitReason() == EEntryIsNotMessage)); |
|
729 testThread.Close(); |
|
730 |
|
731 User::SetJustInTime(ETrue); |
|
732 |
|
733 CleanupStack::PopAndDestroy(emailMessage); |
|
734 emailMessage = NULL; |
|
735 pContext->SetEntryL(gEmailMessageID2); |
|
736 entry = pContext->Entry(); |
|
737 entry.iType = KUidMsvMessageEntry; |
|
738 pContext->ChangeL(entry); |
|
739 |
|
740 pContext->SetEntryL(KMsvGlobalInBoxIndexEntryId); |
|
741 pContext->DeleteL(gEmailMessageID); |
|
742 pContext->DeleteL(gEmailMessageID2); |
|
743 pContext->DeleteL(folderId); |
|
744 |
|
745 return result; |
|
746 } |
|
747 |
|
748 |
|
749 LOCAL_C void InitL() |
|
750 { |
|
751 // Connect to the file system... |
|
752 gFs.Connect(); |
|
753 |
|
754 // Connect to the Message Server... |
|
755 pObserver = new (ELeave) CObserver(); |
|
756 CleanupStack::PushL(pObserver); |
|
757 pSession = CMsvSession::OpenSyncL(*pObserver); |
|
758 CleanupStack::PushL(pSession); |
|
759 |
|
760 pContext = CMsvEntry::NewL(*pSession, KMsvGlobalInBoxIndexEntryId, TMsvSelectionOrdering()); |
|
761 CleanupStack::PushL(pContext); |
|
762 |
|
763 pTestActive = new (ELeave) CTestActive(); |
|
764 CleanupStack::PushL(pTestActive); |
|
765 |
|
766 testUtils = CEmailTestUtils::NewLC(test); |
|
767 testUtils->CreateAllTestDirectories(); |
|
768 testUtils->FileSession().SetSessionPath(_L("C:\\")); |
|
769 } |
|
770 |
|
771 |
|
772 LOCAL_C void UninitL() |
|
773 { |
|
774 CleanupStack::PopAndDestroy(testUtils); |
|
775 CleanupStack::PopAndDestroy(pTestActive); |
|
776 CleanupStack::PopAndDestroy(pContext); |
|
777 CleanupStack::PopAndDestroy(pSession); |
|
778 CleanupStack::PopAndDestroy(pObserver); |
|
779 gFs.Close(); |
|
780 } |
|
781 |
|
782 |
|
783 LOCAL_C void doTests() |
|
784 { |
|
785 testUtils->TestStart(1); |
|
786 |
|
787 test.Start(_L("Testing CImEmailMessage attachment flag")); |
|
788 test(TestAttachmentFlagL()); |
|
789 test.End(); |
|
790 testUtils->TestFinish(1); |
|
791 |
|
792 testUtils->TestStart(2); |
|
793 test.Start(_L("Testing CImEmailMessage panics")); |
|
794 test(TestPanicsL()); |
|
795 test.End(); |
|
796 testUtils->TestFinish(2); |
|
797 testUtils->TestHarnessCompleted(); |
|
798 } |
|
799 |
|
800 |
|
801 LOCAL_C void doMainL() |
|
802 { |
|
803 InitL(); |
|
804 doTests(); |
|
805 UninitL(); |
|
806 } |
|
807 |
|
808 |
|
809 GLDEF_C TInt E32Main() |
|
810 { |
|
811 pcleanup = CTrapCleanup::New(); |
|
812 pscheduler = new (ELeave) CMyScheduler(); |
|
813 CActiveScheduler::Install(pscheduler); |
|
814 TRAPD(ret,doMainL()); |
|
815 delete pcleanup; |
|
816 delete pscheduler; |
|
817 return(KErrNone); |
|
818 } |