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