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