|
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 // T_DEF079867_OFFLINE_DELETE.CPP |
|
15 // Name of test harness: T_DEF079867_Offline_Delete.cpp |
|
16 // Component: imapservermtm |
|
17 // Output files produced by running test harness: |
|
18 // <DRIVE>:\msglogs\T_DEF079867_Offline_Delete.WINSCW.DEB.LOG |
|
19 // |
|
20 // |
|
21 |
|
22 |
|
23 #include "EmailTestUtils.h" |
|
24 #include <ImapConnectionObserver.H> |
|
25 #include <cemailaccounts.h> |
|
26 |
|
27 |
|
28 _LIT(KAt ,"@"); |
|
29 _LIT(KDelete ,"Offline Deleted File = %d"); |
|
30 _LIT8(KFolderPath, ""); |
|
31 _LIT(KServer, ".intra"); |
|
32 _LIT(KImOffDelete, " Testing Offline_Delete"); |
|
33 _LIT(KMsgCompleted, "\t CopyL completed with : %d"); |
|
34 _LIT(KMsgSend, "\t messages to send in the outbox = : %d"); |
|
35 _LIT(KProgressError, "\t Progress error = %d"); |
|
36 |
|
37 RTest test(KImOffDelete); |
|
38 TImapAccount imapAccount; |
|
39 LOCAL_D TMsvId imap4Service; |
|
40 LOCAL_D TMsvId smtpService; |
|
41 LOCAL_D CEmailTestUtils* testUtils; |
|
42 LOCAL_D CTrapCleanup* theCleanup; |
|
43 |
|
44 #if defined (__WINS__) |
|
45 #define PDD_NAME _L("ECDRV") |
|
46 #define LDD_NAME _L("ECOMM") |
|
47 #else |
|
48 #define PDD_NAME _L("EUART1") |
|
49 #define LDD_NAME _L("ECOMM") |
|
50 #endif |
|
51 // local variables etc // |
|
52 |
|
53 class TDummySessionObserver : public CBase , public MMsvSessionObserver |
|
54 { |
|
55 public: |
|
56 void HandleSessionEventL(TMsvSessionEvent, TAny*, TAny*, TAny*) |
|
57 { |
|
58 } |
|
59 }; |
|
60 |
|
61 |
|
62 class CDummyConnectionObserver : public MMsvImapConnectionObserver |
|
63 { |
|
64 void HandleImapConnectionEvent(TImapConnectionEvent) |
|
65 { |
|
66 } |
|
67 }; |
|
68 |
|
69 // Disconnect from ImapServer |
|
70 LOCAL_C void DisconnectImapServerL() |
|
71 { |
|
72 test.Printf(_L("DisConnecting to IMAP server \n")); |
|
73 CTestActive* testActive = new (ELeave) CTestActive(); |
|
74 CleanupStack::PushL(testActive); |
|
75 |
|
76 CMsvEntrySelection *msvSelection = new(ELeave) CMsvEntrySelection; |
|
77 CleanupStack::PushL(msvSelection); |
|
78 msvSelection->AppendL(imap4Service); |
|
79 |
|
80 TBuf8 <1> aParameter; |
|
81 CMsvOperation* msvOperation = testUtils->iImapClientMtm->InvokeAsyncFunctionL(KIMAP4MTMDisconnect,*msvSelection, aParameter, testActive->iStatus); |
|
82 testUtils->WriteComment(_L("Dissconnect from IMAP server ")); |
|
83 CleanupStack::PushL(msvOperation); |
|
84 |
|
85 testActive->StartL(); |
|
86 CActiveScheduler::Start(); |
|
87 CleanupStack::PopAndDestroy(3,testActive);//msvOperation,msvSelection,children,testActive |
|
88 } |
|
89 |
|
90 |
|
91 LOCAL_C void ConnectAndFullSyncImapServerL() |
|
92 { |
|
93 CTestActive* testActive = new(ELeave) CTestActive(); |
|
94 CleanupStack::PushL(testActive); |
|
95 |
|
96 CMsvEntrySelection * msvSelection = new(ELeave) CMsvEntrySelection; |
|
97 CleanupStack::PushL(msvSelection); |
|
98 |
|
99 test.Printf(_L("Connecting to IMAP server \n")); |
|
100 msvSelection->AppendL(imap4Service); |
|
101 |
|
102 CDummyConnectionObserver *dummyObserver = new(ELeave)CDummyConnectionObserver; |
|
103 CleanupStack::PushL(dummyObserver); |
|
104 TPckg<MMsvImapConnectionObserver*> aParameter(dummyObserver); |
|
105 |
|
106 CMsvOperation* msvOperation = testUtils->iImapClientMtm->InvokeAsyncFunctionL(KIMAP4MTMConnectAndSyncCompleteAfterFullSync,*msvSelection, aParameter, testActive->iStatus); |
|
107 testUtils->WriteComment(_L(" Connect to Imap server and Sync the mails ")); |
|
108 CleanupStack::PushL(msvOperation); |
|
109 |
|
110 testActive->StartL(); |
|
111 CActiveScheduler::Start(); |
|
112 |
|
113 CleanupStack::PopAndDestroy(4,testActive);//msvOperation,dummyObserver,msvSelection,testActive |
|
114 } |
|
115 |
|
116 LOCAL_C void ConnectAndSyncCompleteAfterConnectL() |
|
117 { |
|
118 CTestActive* testActive = new(ELeave) CTestActive(); |
|
119 CleanupStack::PushL(testActive); |
|
120 |
|
121 CMsvEntrySelection * msvSelection = new(ELeave) CMsvEntrySelection; |
|
122 CleanupStack::PushL(msvSelection); |
|
123 |
|
124 test.Printf(_L("Connecting to IMAP server \n")); |
|
125 msvSelection->AppendL(imap4Service); |
|
126 |
|
127 CDummyConnectionObserver *dummyObserver = new(ELeave)CDummyConnectionObserver; |
|
128 CleanupStack::PushL(dummyObserver); |
|
129 TPckg<MMsvImapConnectionObserver*> aParameter(dummyObserver); |
|
130 |
|
131 CMsvOperation* msvOperation = testUtils->iImapClientMtm->InvokeAsyncFunctionL(KIMAP4MTMConnectAndSyncCompleteAfterConnect,*msvSelection, aParameter, testActive->iStatus); |
|
132 testUtils->WriteComment(_L(" Connect to Imap server and Sync the mails ")); |
|
133 CleanupStack::PushL(msvOperation); |
|
134 |
|
135 testActive->StartL(); |
|
136 CActiveScheduler::Start(); |
|
137 |
|
138 CleanupStack::PopAndDestroy(4,testActive);//msvOperation,dummyObserver,msvSelection,testActive |
|
139 |
|
140 } |
|
141 |
|
142 |
|
143 LOCAL_C void OfflineDeleteL(CMsvEntry & aInboxEntry) |
|
144 { |
|
145 CTestActive* testActive = new(ELeave) CTestActive(); |
|
146 CleanupStack::PushL(testActive); |
|
147 TBuf8 <1> aParameter; |
|
148 |
|
149 CMsvEntrySelection* children = aInboxEntry.ChildrenL(); |
|
150 CleanupStack::PushL(children); |
|
151 |
|
152 |
|
153 CMsvOperation* msvOperation = aInboxEntry.DeleteL(children[0],testActive->iStatus); |
|
154 testUtils->Printf(KDelete, aInboxEntry.Count()); |
|
155 CleanupStack::PushL(msvOperation); |
|
156 testActive->StartL(); |
|
157 CActiveScheduler::Start(); |
|
158 |
|
159 ConnectAndSyncCompleteAfterConnectL(); |
|
160 |
|
161 CMsvOperation* msvOperation1 = testUtils->iImapClientMtm->InvokeAsyncFunctionL(KIMAP4MTMUndeleteAll , children[0], aParameter, testActive->iStatus); |
|
162 CleanupStack::PushL(msvOperation1); |
|
163 testActive->StartL(); |
|
164 CActiveScheduler::Start(); |
|
165 |
|
166 CleanupStack::PopAndDestroy(msvOperation1); |
|
167 CleanupStack::PopAndDestroy(3,testActive); |
|
168 |
|
169 } |
|
170 |
|
171 // |
|
172 LOCAL_C void CreateNewSmtpSettingsL() |
|
173 { |
|
174 testUtils->iMsvEntry->SetEntryL(smtpService); |
|
175 TMsvId serviceId = smtpService; |
|
176 //overwrite the settings with test code one. Don't want the default settings. |
|
177 CImSmtpSettings* settings = new(ELeave) CImSmtpSettings(); |
|
178 CleanupStack::PushL(settings); |
|
179 |
|
180 CEmailAccounts* accounts = CEmailAccounts::NewLC(); |
|
181 TSmtpAccount smtpAccountId; |
|
182 |
|
183 accounts->GetSmtpAccountL( serviceId, smtpAccountId); |
|
184 accounts->LoadSmtpSettingsL(smtpAccountId, *settings); |
|
185 |
|
186 TInt serverLength = testUtils->MachineName().Length(); |
|
187 HBufC* serverad = HBufC::NewL(serverLength + 7 ); // 7 is the length of KServerAddress |
|
188 CleanupStack::PushL(serverad); |
|
189 |
|
190 serverad->Des().Copy(testUtils->MachineName()); |
|
191 serverad->Des().Append(KServer); |
|
192 settings->SetServerAddressL(*serverad); |
|
193 |
|
194 HBufC* emailaddress = HBufC::NewL(serverLength + 8 + serverad->Des().Length() + 1 ); |
|
195 CleanupStack::PushL(emailaddress); |
|
196 |
|
197 emailaddress->Des().Copy(testUtils->MachineName()); |
|
198 emailaddress->Des().Append(KAt); |
|
199 emailaddress->Des().Append(*serverad); |
|
200 |
|
201 settings->SetEmailAddressL(*emailaddress); |
|
202 settings->SetReplyToAddressL(*emailaddress); |
|
203 settings->SetReceiptAddressL(*emailaddress); |
|
204 settings->SetEmailAliasL(_L("Test Account")); |
|
205 settings->SetBodyEncoding(EMsgOutboxMIME); |
|
206 settings->SetRequestReceipts(EFalse); |
|
207 settings->SetPort(25); |
|
208 |
|
209 TSmtpAccount smtpAccount; |
|
210 accounts->GetSmtpAccountL(smtpService, smtpAccount); |
|
211 accounts->SaveSmtpSettingsL(smtpAccount, *settings); |
|
212 |
|
213 CleanupStack::PopAndDestroy(emailaddress); |
|
214 CleanupStack::PopAndDestroy(serverad); |
|
215 CleanupStack::PopAndDestroy(2,settings); |
|
216 testUtils->WriteComment(_L("Created New SmtpSettings ")); |
|
217 } |
|
218 |
|
219 |
|
220 LOCAL_C void CreateNewPlaintextMessageL() |
|
221 { |
|
222 CTestActive* testActive = new(ELeave) CTestActive(); |
|
223 CleanupStack::PushL(testActive); |
|
224 |
|
225 TMsvEmailTypeList msvEmailTypeList = 0; |
|
226 TMsvPartList partList = (KMsvMessagePartBody | KMsvMessagePartAttachments); |
|
227 |
|
228 CImEmailOperation* emailOperation = CImEmailOperation::CreateNewL(testActive->iStatus, *(testUtils->iMsvSession),KMsvGlobalOutBoxIndexEntryId, partList, msvEmailTypeList, KUidMsgTypeSMTP); |
|
229 CleanupStack::PushL(emailOperation); |
|
230 TestMsvOperationTimer* testMsvOperationTimer = TestMsvOperationTimer::NewLC(test.Console(), emailOperation, test); |
|
231 |
|
232 testActive->StartL(); |
|
233 testMsvOperationTimer->IssueRequest(); |
|
234 CActiveScheduler::Start(); |
|
235 |
|
236 //check progress |
|
237 TMsvId temp; |
|
238 TPckgC<TMsvId> paramPack(temp); |
|
239 |
|
240 const TDesC8& progBuf = emailOperation->ProgressL(); |
|
241 paramPack.Set(progBuf); |
|
242 |
|
243 TMsvId newMessageId; |
|
244 newMessageId = paramPack(); |
|
245 |
|
246 test(newMessageId != NULL); |
|
247 testUtils->WriteComment(_L("\t Created New plaintext message")); |
|
248 testUtils->iMsvEntry->SetEntryL(newMessageId); |
|
249 |
|
250 CMsvStore* store = testUtils->iMsvEntry->EditStoreL(); |
|
251 CleanupStack::PushL(store); |
|
252 CImHeader* header = CImHeader::NewLC(); |
|
253 header->RestoreL(*store); |
|
254 |
|
255 TInt serverLength = testUtils->MachineName().Length(); |
|
256 HBufC* serverad = HBufC::NewL(serverLength + 7 ); // 7 is the length of KServerAddress |
|
257 CleanupStack::PushL(serverad); |
|
258 |
|
259 serverad->Des().Copy(testUtils->MachineName()); |
|
260 serverad->Des().Append(KServer); |
|
261 |
|
262 HBufC* emailaddress = HBufC::NewL(serverLength + 8 + serverad->Des().Length() + 1 ); |
|
263 CleanupStack::PushL(emailaddress); |
|
264 |
|
265 emailaddress->Des().Copy(testUtils->MachineName()); |
|
266 emailaddress->Des().Append(KAt); |
|
267 emailaddress->Des().Append(*serverad); |
|
268 header->ToRecipients().AppendL(*emailaddress); |
|
269 |
|
270 header->SetSubjectL(_L("Test sending message using CMsvEntry::CopyL!!")); |
|
271 header->StoreL(*store); |
|
272 store->CommitL(); |
|
273 |
|
274 CleanupStack::PopAndDestroy(emailaddress); |
|
275 CleanupStack::PopAndDestroy(serverad); |
|
276 CleanupStack::PopAndDestroy(5,testActive); // header,store,testMsvOperationTimer,emailOperation,testActive |
|
277 } |
|
278 |
|
279 |
|
280 LOCAL_C void SendSmtpMessageL() |
|
281 { |
|
282 CTestActive* testActive = new (ELeave) CTestActive(); |
|
283 CleanupStack::PushL(testActive); |
|
284 |
|
285 testUtils->iMsvEntry->SetEntryL(KMsvGlobalOutBoxIndexEntryId); |
|
286 testUtils->InstantiateSmtpClientMtmL(); |
|
287 |
|
288 CMsvEntrySelection* sendSel = testUtils->iMsvEntry->ChildrenL(); |
|
289 CleanupStack::PushL(sendSel); |
|
290 |
|
291 TInt count = sendSel->Count(); |
|
292 test(count >= 1); |
|
293 testUtils->Printf(KMsgSend, count); |
|
294 testUtils->iSmtpClientMtm->SetCurrentEntryL(testUtils->iMsvSession->GetEntryL(KMsvGlobalOutBoxIndexEntryId)); |
|
295 |
|
296 CMsvOperation* msvOperation = testUtils->iSmtpClientMtm->Entry().CopyL(*sendSel, smtpService, testActive->iStatus); |
|
297 CleanupStack::PushL(msvOperation); |
|
298 |
|
299 testActive->StartL(); |
|
300 CActiveScheduler::Start(); |
|
301 |
|
302 //check progress |
|
303 testUtils->Printf(KMsgCompleted, testActive->iStatus.Int()); |
|
304 |
|
305 CMsvEntrySelection* sendSelc = testUtils->iMsvEntry->ChildrenL(); |
|
306 TInt noOfMessages = sendSelc->Count(); |
|
307 |
|
308 // Check Whether the mails in Outbox is Zero (i.e. mails has been sent..). |
|
309 test(noOfMessages == 0); |
|
310 delete sendSelc; |
|
311 TImSmtpProgress temp; |
|
312 TPckgC<TImSmtpProgress> paramPack(temp); |
|
313 const TDesC8& progBuf = msvOperation->ProgressL(); |
|
314 paramPack.Set(progBuf); |
|
315 TImSmtpProgress progress = paramPack(); |
|
316 |
|
317 testUtils->Printf(KProgressError, progress.Error()); |
|
318 test(progress.Error()==0); |
|
319 CleanupStack::PopAndDestroy(3,testActive); //msvOperation,sendsel,testActive |
|
320 } |
|
321 |
|
322 LOCAL_C void CreateandSendMessageL() |
|
323 { |
|
324 test.Next(_L("Test sending message to server ")); |
|
325 CreateNewSmtpSettingsL(); |
|
326 |
|
327 testUtils->iMsvEntry->SetEntryL(smtpService); |
|
328 |
|
329 CreateNewPlaintextMessageL(); |
|
330 SendSmtpMessageL(); |
|
331 } |
|
332 |
|
333 LOCAL_C void TestOfflineDeleteL() |
|
334 { |
|
335 CreateandSendMessageL(); |
|
336 // Tests start here |
|
337 testUtils->iImapClientMtm->SwitchCurrentEntryL(imap4Service); |
|
338 // connect, do full sync and then so that the inbox can be synced |
|
339 test.Printf(_L("Connecting to IMAP server \n")); |
|
340 |
|
341 ConnectAndFullSyncImapServerL(); |
|
342 |
|
343 CMsvEntry* imapService=NULL; |
|
344 CMsvEntry* inboxEntry=NULL; |
|
345 TMsvSelectionOrdering ordering; |
|
346 |
|
347 TDummySessionObserver *sessionObserver = new (ELeave) TDummySessionObserver; |
|
348 // Session. Needed to create a client registry. |
|
349 CMsvSession* session = CMsvSession::OpenSyncL(*sessionObserver); |
|
350 |
|
351 // message in remote inbox |
|
352 //create a CMsvEntry for the service entry |
|
353 imapService = CMsvEntry::NewL(*session, imapAccount.iImapService,ordering); |
|
354 CleanupStack::PushL(imapService); |
|
355 //retrieve the inbox from the imap service entry |
|
356 CMsvEntrySelection* msvEntrySelection =imapService->ChildrenL(); |
|
357 CleanupStack::PushL(msvEntrySelection); |
|
358 |
|
359 //create a CMsvEntry for the inbox entry |
|
360 inboxEntry = CMsvEntry::NewL(*session, (*msvEntrySelection)[0],ordering); |
|
361 CleanupStack::PushL(inboxEntry); |
|
362 TBuf8 <1> aParameter; |
|
363 |
|
364 CMsvEntrySelection * selection = inboxEntry->ChildrenL();//no of msg |
|
365 CleanupStack::PushL(selection); |
|
366 |
|
367 DisconnectImapServerL(); |
|
368 |
|
369 OfflineDeleteL(*inboxEntry); |
|
370 |
|
371 CleanupStack::PopAndDestroy(4,imapService);//selection,inboxEntry,msvEntrySelection |
|
372 |
|
373 delete sessionObserver; |
|
374 delete session; |
|
375 |
|
376 } |
|
377 |
|
378 LOCAL_C void InitL() |
|
379 { |
|
380 // Load the serial comms device drivers. If this is not done, |
|
381 // connecting via NT-RAS returns KErrNotFound (-1). |
|
382 TInt driverErr; |
|
383 driverErr=User::LoadPhysicalDevice(PDD_NAME); |
|
384 if (driverErr!=KErrNone && driverErr!=KErrAlreadyExists) |
|
385 User::Leave(driverErr); |
|
386 driverErr=User::LoadLogicalDevice(LDD_NAME); |
|
387 if (driverErr!=KErrNone && driverErr!=KErrAlreadyExists) |
|
388 User::Leave(driverErr); |
|
389 |
|
390 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler; |
|
391 CActiveScheduler::Install(scheduler); |
|
392 CleanupStack::PushL(scheduler); |
|
393 |
|
394 testUtils = CEmailTestUtils::NewLC(test); |
|
395 testUtils->CreateAllTestDirectories(); |
|
396 testUtils->FileSession().SetSessionPath(_L("C:\\")); |
|
397 testUtils->CleanMessageFolderL(); |
|
398 testUtils->GoServerSideL(); |
|
399 testUtils->ClearEmailAccountsL(); |
|
400 test.Next(_L("Create Data Component FileStores")); |
|
401 testUtils->CreateSmtpServerMtmRegL(); |
|
402 |
|
403 // Loading the DLLs |
|
404 testUtils->CreateRegistryObjectAndControlL(); |
|
405 testUtils->InstallSmtpMtmGroupL(); |
|
406 testUtils->GoClientSideL(); |
|
407 |
|
408 // Create Services |
|
409 smtpService = testUtils->CreateSmtpServiceL(); |
|
410 imap4Service = testUtils->CreateImapServiceL(); |
|
411 CEmailAccounts* accounts = CEmailAccounts::NewLC(); |
|
412 TSmtpAccount smtpAccount; |
|
413 |
|
414 accounts->GetSmtpAccountL(smtpService, smtpAccount); |
|
415 accounts->SetDefaultSmtpAccountL(smtpAccount); |
|
416 |
|
417 testUtils->WriteComment(_L("Create Imap Services ")); |
|
418 |
|
419 // Delete any *.scr files in c:\logs\email directory. |
|
420 testUtils->DeleteScriptFilesFromLogsDirL(); |
|
421 testUtils->iMsvEntry->SetEntryL(imap4Service); |
|
422 |
|
423 //overwrite the settings with test code one. Don't want the default settings. |
|
424 CImImap4Settings* settings = new(ELeave) CImImap4Settings(); |
|
425 CleanupStack::PushL(settings); |
|
426 |
|
427 settings->Reset(); |
|
428 |
|
429 TInt serverLength = testUtils->MachineName().Length(); |
|
430 HBufC* serverad = HBufC::NewL(serverLength + 7 ); // 7 is the length of KServerAddress |
|
431 CleanupStack::PushL(serverad); |
|
432 |
|
433 serverad->Des().Copy(testUtils->MachineName()); |
|
434 serverad->Des().Append(KServer); |
|
435 settings->SetServerAddressL(*serverad); |
|
436 CleanupStack::PopAndDestroy(serverad); |
|
437 |
|
438 settings->SetDeleteEmailsWhenDisconnecting(ETrue); |
|
439 settings->SetAcknowledgeReceipts(ETrue); |
|
440 settings->SetAutoSendOnConnect(ETrue); |
|
441 settings->SetLoginNameL(testUtils->MachineName()); |
|
442 settings->SetPasswordL(testUtils->MachineName()); |
|
443 settings->SetPort(143); |
|
444 settings->SetFolderPathL(KFolderPath); |
|
445 |
|
446 accounts->GetImapAccountL(imap4Service, imapAccount); |
|
447 accounts->SaveImapSettingsL(imapAccount, *settings); |
|
448 CleanupStack::PopAndDestroy(2,accounts); //accounts,settings |
|
449 |
|
450 test.Printf(_L("Instantiating IMAP4 Client MTM")); |
|
451 testUtils->InstantiateImapClientMtmL(); |
|
452 } |
|
453 |
|
454 LOCAL_C void Closedown() |
|
455 { |
|
456 CleanupStack::PopAndDestroy(2); //testUtils, scheduler |
|
457 } |
|
458 |
|
459 LOCAL_C void doMainL() |
|
460 { |
|
461 test.Start(_L("IMAP4 - Offline Delete")); |
|
462 InitL(); |
|
463 testUtils->TestStart(1); |
|
464 TestOfflineDeleteL(); |
|
465 testUtils->TestFinish(1); |
|
466 testUtils->TestHarnessCompleted(); |
|
467 Closedown(); |
|
468 } |
|
469 |
|
470 |
|
471 GLDEF_C TInt E32Main() |
|
472 { |
|
473 __UHEAP_MARK; |
|
474 theCleanup=CTrapCleanup::New(); |
|
475 TRAPD(ret,doMainL()); |
|
476 test(ret==KErrNone); |
|
477 delete theCleanup; |
|
478 test.Console()->SetPos(0, 13); |
|
479 test.End(); |
|
480 test.Close(); |
|
481 __UHEAP_MARKEND; |
|
482 return(KErrNone); |
|
483 } |
|
484 |