|
1 // Copyright (c) 2006-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 // Test for CImPruneMessage class. |
|
15 // This class removes body text and attachment data from messages, leaving the message structure intact |
|
16 // |
|
17 // |
|
18 |
|
19 #include "emailtestutils.h" |
|
20 #include <miutlog.h> |
|
21 #include <cacheman.h> |
|
22 #include <cimprunemessage.h> |
|
23 |
|
24 _LIT(K_PLAIN_MSG, "c:\\mailtest\\rfc822\\plain_text.txt"); |
|
25 _LIT(K_HTML_ATTACHMENT_MSG, "c:\\mailtest\\rfc822\\html_with_attachment.txt" ); |
|
26 _LIT(K_TEST_INFO, "T_CImPruneMessage Test"); |
|
27 _LIT(K_DESCRIPTION, "Testing pruning of messages containing text and attachment."); |
|
28 _LIT(K_MSG_NOT_PRUNED,"\nWarning email not pruned\n* BODY text or attachment data still exists!*---Message entry id: %d--"); |
|
29 _LIT(K_MSG_PRUNED,"\nSuccess: email pruned! Message entry id: %d "); |
|
30 #define KErrMsgNotPruned 5601 |
|
31 |
|
32 RTest test(K_TEST_INFO); |
|
33 LOCAL_D TMsvId pop3Service; |
|
34 LOCAL_D CTrapCleanup* theCleanup; |
|
35 LOCAL_D CEmailTestUtils* testUtils; |
|
36 LOCAL_D TInt globalError = KErrNone; |
|
37 |
|
38 |
|
39 LOCAL_C void InitL() |
|
40 { |
|
41 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler; |
|
42 CActiveScheduler::Install(scheduler); |
|
43 CleanupStack::PushL(scheduler); |
|
44 |
|
45 testUtils = CEmailTestUtils::NewLC(test); |
|
46 testUtils->CreateAllTestDirectories(); |
|
47 |
|
48 testUtils->WriteComment(K_TEST_INFO); |
|
49 |
|
50 testUtils->FileSession().SetSessionPath(_L("C:\\")); |
|
51 testUtils->CleanMessageFolderL(); |
|
52 testUtils->ClearEmailAccountsL(); |
|
53 testUtils->GoServerSideL(); |
|
54 } |
|
55 |
|
56 LOCAL_C void Closedown() |
|
57 { |
|
58 CleanupStack::PopAndDestroy(2); //testUtils, scheduler |
|
59 } |
|
60 |
|
61 LOCAL_C void TestMessagePartsL(CMsvEntry& aEntry) |
|
62 { |
|
63 CMsvEntrySelection* sel = aEntry.ChildrenL(); |
|
64 CleanupStack::PushL(sel); |
|
65 |
|
66 TInt count = sel->Count(); |
|
67 for(TInt ii=0; ii<sel->Count(); ++ii) |
|
68 { |
|
69 aEntry.SetEntryL(sel->At(ii)); |
|
70 |
|
71 CMsvStore* store = aEntry.ReadStoreL(); |
|
72 CleanupStack::PushL(store); |
|
73 if (store->IsPresentL(KMsvEntryRichTextBody)) |
|
74 { |
|
75 // body text exist |
|
76 globalError = KErrMsgNotPruned; |
|
77 } |
|
78 |
|
79 MMsvAttachmentManager& attachmentMgr = store->AttachmentManagerL(); |
|
80 if(attachmentMgr.AttachmentCount() > 0) |
|
81 { |
|
82 CMsvAttachment* attachmentInfo = attachmentMgr.GetAttachmentInfoL(0); |
|
83 CleanupStack::PushL(attachmentInfo); |
|
84 |
|
85 if ((attachmentInfo->Type() == CMsvAttachment::EMsvFile) && (attachmentInfo->Size() != 0)) |
|
86 { |
|
87 // attachment data exist |
|
88 globalError = KErrMsgNotPruned; |
|
89 } |
|
90 CleanupStack::PopAndDestroy(attachmentInfo); |
|
91 } |
|
92 CleanupStack::PopAndDestroy(store); |
|
93 |
|
94 |
|
95 // recursively test other message parts |
|
96 TestMessagePartsL(aEntry); |
|
97 } |
|
98 CleanupStack::PopAndDestroy(sel); |
|
99 } |
|
100 |
|
101 LOCAL_C void doMainL() |
|
102 { |
|
103 // CImPruneMessage class removes body text and attachment data from messages, |
|
104 // leaving the message structure intact |
|
105 |
|
106 InitL(); |
|
107 |
|
108 testUtils->FileSession().SetSessionPath(_L("c:\\")); |
|
109 |
|
110 testUtils->GoClientSideL(); |
|
111 pop3Service = testUtils->CreatePopServiceL(); |
|
112 |
|
113 testUtils->GoServerSideL(); |
|
114 |
|
115 testUtils->CreateMessageL(K_PLAIN_MSG, pop3Service, pop3Service); |
|
116 testUtils->CreateMessageL(K_HTML_ATTACHMENT_MSG, pop3Service, pop3Service); |
|
117 testUtils->CreateMessageL(K_PLAIN_MSG, pop3Service, pop3Service); |
|
118 testUtils->CreateMessageL(K_HTML_ATTACHMENT_MSG, pop3Service, pop3Service); |
|
119 |
|
120 test.Printf(_L("\nPerforming Prune Message Tests\n")); |
|
121 |
|
122 testUtils->GoClientSideL(); |
|
123 |
|
124 testUtils->iMsvEntry->SetEntryL(pop3Service); |
|
125 TMsvEntry entry = testUtils->iMsvEntry->Entry(); |
|
126 entry.SetVisible(ETrue); |
|
127 testUtils->iMsvEntry->ChangeL(entry); |
|
128 |
|
129 CImPruneMessage* pruneMessage = CImPruneMessage::NewL(*testUtils->iMsvEntry, testUtils->FileSession()); |
|
130 CleanupStack::PushL(pruneMessage); |
|
131 CTestActive* testActive = new (ELeave) CTestActive(); |
|
132 CleanupStack::PushL(testActive); |
|
133 |
|
134 testActive->StartL(); |
|
135 |
|
136 testUtils->TestStart(0, K_DESCRIPTION); |
|
137 |
|
138 pruneMessage->StartL(pop3Service, testActive->iStatus); |
|
139 |
|
140 CActiveScheduler::Start(); |
|
141 |
|
142 |
|
143 // Get a list of pop messages (created above) |
|
144 testUtils->iMsvEntry->SetEntryL(pop3Service); |
|
145 CMsvEntrySelection* popMessages = testUtils->iMsvEntry->ChildrenL(); |
|
146 CleanupStack::PushL(popMessages); |
|
147 |
|
148 TInt messageCount = popMessages->Count(); |
|
149 TMsvId msgId; |
|
150 TBuf<128> msgFail; |
|
151 TBuf<128> msgPass; |
|
152 |
|
153 for(TInt ii=0; ii<messageCount; ++ii) |
|
154 { |
|
155 // Check that there are no body text and no data in the attachment file for this message |
|
156 msgId = popMessages->At(ii); |
|
157 testUtils->iMsvEntry->SetEntryL(msgId); |
|
158 |
|
159 // Go through the message parts and check that body text and attachment data are removed |
|
160 TestMessagePartsL(*testUtils->iMsvEntry); |
|
161 |
|
162 if (globalError == KErrNone) |
|
163 { |
|
164 //email successfully prunned |
|
165 msgPass.Format(K_MSG_PRUNED,msgId); |
|
166 testUtils->WriteComment(msgPass); |
|
167 } |
|
168 else |
|
169 { |
|
170 msgFail.Format(K_MSG_NOT_PRUNED,msgId); |
|
171 testUtils->WriteComment(msgFail); |
|
172 break; |
|
173 } |
|
174 } |
|
175 |
|
176 testUtils->TestFinish(0, globalError); |
|
177 |
|
178 if (globalError == KErrNone) |
|
179 { |
|
180 testUtils->TestHarnessCompleted(); |
|
181 } |
|
182 else |
|
183 { |
|
184 testUtils->TestHarnessFailed(globalError); |
|
185 } |
|
186 |
|
187 CleanupStack::PopAndDestroy(3,pruneMessage); // pruneMessage, testActive, popMessages |
|
188 |
|
189 Closedown(); |
|
190 } |
|
191 |
|
192 GLDEF_C TInt E32Main() |
|
193 { |
|
194 __UHEAP_MARK; |
|
195 test.Start(_L("T_CImPruneMessage Test\n")); |
|
196 theCleanup=CTrapCleanup::New(); |
|
197 TRAPD(ret,doMainL()); |
|
198 test(ret==KErrNone); |
|
199 delete theCleanup; |
|
200 test.End(); |
|
201 test.Close(); |
|
202 __UHEAP_MARKEND; |
|
203 User::Heap().Check(); |
|
204 return(KErrNone); |
|
205 } |
|
206 |