|
1 // Copyright (c) 1999-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 // |
|
15 |
|
16 #include "emailtestutils.h" |
|
17 #include "scripttestutils.h" |
|
18 #include <iapprefs.h> |
|
19 #include <es_sock.h> |
|
20 #include <commdb.h> |
|
21 #include <cdbpreftable.h> |
|
22 #include <imsk.h> |
|
23 #include <commdbconnpref.h> |
|
24 #include <bacline.h> |
|
25 #include <cemailaccounts.h> |
|
26 #include <commsdattypesv1_1.h> |
|
27 #include <commsdat.h> |
|
28 using namespace CommsDat; |
|
29 |
|
30 // For loading the serial comms device drivers |
|
31 #if defined (__WINS__) |
|
32 #define PDD_NAME _L("ECDRV") |
|
33 #define LDD_NAME _L("ECOMM") |
|
34 #else |
|
35 #define PDD_NAME _L("EUART1") |
|
36 #define LDD_NAME _L("ECOMM") |
|
37 #endif |
|
38 |
|
39 |
|
40 _LIT(KSmtsTest, "T_SMTS02 - Testing SMTS Server MTM using dial out with On-line"); |
|
41 RTest test(KSmtsTest); |
|
42 |
|
43 _LIT(KTestParams,"-testparams"); |
|
44 enum TCmdLineArgs |
|
45 { |
|
46 EArgProgramName, |
|
47 EArgTestParams, |
|
48 EArgServerAddress, |
|
49 EArgEmail, |
|
50 EArgEnd |
|
51 }; |
|
52 |
|
53 _LIT(KImskOutFile, "c:\\logs\\email\\imsk25.out"); |
|
54 _LIT(KImskScrFile, "c:\\logs\\email\\imsk25.scr"); |
|
55 _LIT(KSmtsComponent,"SMTS"); |
|
56 _LIT(KSmtsRFCEmails,"RFC822\\"); |
|
57 |
|
58 LOCAL_D CTrapCleanup* theCleanup; |
|
59 LOCAL_D CEmailTestUtils* testUtils; |
|
60 LOCAL_D TMsvId smtpService; |
|
61 LOCAL_D CBaseServerMtm* serverMtm; |
|
62 LOCAL_D CActiveScheduler* scheduler; |
|
63 LOCAL_D TInt globalError; |
|
64 LOCAL_D RConnection gConnection; |
|
65 LOCAL_D RSocketServ gSocketServ; |
|
66 |
|
67 |
|
68 |
|
69 LOCAL_C void DisplayProgress() |
|
70 { |
|
71 TImSmtpProgress temp; |
|
72 TPckgC<TImSmtpProgress> paramPack(temp); |
|
73 |
|
74 const TDesC8& progBuf =serverMtm->Progress(); |
|
75 paramPack.Set(progBuf); |
|
76 TImSmtpProgress progress=paramPack(); |
|
77 |
|
78 TBuf<128> logString; |
|
79 // State of Smtp session? |
|
80 TInt state = progress.Status(); |
|
81 switch(state) |
|
82 { |
|
83 case EMsgOutboxProgressWaiting: |
|
84 testUtils->WriteComment(_L("Waiting to start\n")); |
|
85 break; |
|
86 case EMsgOutboxProgressDone: |
|
87 testUtils->WriteComment(_L("Connection Closed.\n")); |
|
88 logString.Format(_L("%d messages: Sent %d, failed to send %d, didn't attempt to send %d.\n"), |
|
89 progress.SendTotal(), |
|
90 progress.Sent(), |
|
91 progress.FailedToSend(), |
|
92 progress.NotSent()); |
|
93 testUtils->WriteComment(logString); |
|
94 break; |
|
95 case EMsgOutboxProgressConnecting: |
|
96 logString.Format(_L("Connecting to SMTP server. Sending %d messages.\n"), |
|
97 progress.SendTotal()); |
|
98 testUtils->WriteComment(logString); |
|
99 break; |
|
100 case EMsgOutboxProgressSending: |
|
101 logString.Format(_L("Sending message No.%d/%d. Transmitted %d bytes of %d \n"), |
|
102 progress.MsgNo()+1, |
|
103 progress.SendTotal(), |
|
104 progress.iSendFileProgress.iBytesSent, |
|
105 progress.iSendFileProgress.iBytesToSend); |
|
106 testUtils->WriteComment(logString); |
|
107 break; |
|
108 } |
|
109 } |
|
110 |
|
111 class CSmtpTimer : public CTimer |
|
112 { |
|
113 public: |
|
114 static CSmtpTimer* NewL(CTestActive& aActive); |
|
115 void StartL(); |
|
116 private: |
|
117 CSmtpTimer(CTestActive& aActive); |
|
118 void RunL(); |
|
119 CTestActive& iSmtpActive; |
|
120 }; |
|
121 |
|
122 CSmtpTimer::CSmtpTimer(CTestActive& aActive) |
|
123 : CTimer(EPriorityLow), iSmtpActive(aActive) |
|
124 |
|
125 {} |
|
126 |
|
127 |
|
128 CSmtpTimer* CSmtpTimer::NewL(CTestActive& aActive) |
|
129 { |
|
130 CSmtpTimer* self = new(ELeave) CSmtpTimer(aActive); |
|
131 CleanupStack::PushL(self); |
|
132 CActiveScheduler::Add(self); |
|
133 CleanupStack::Pop(); |
|
134 return self; |
|
135 } |
|
136 |
|
137 void CSmtpTimer::StartL() |
|
138 { |
|
139 CTimer::ConstructL(); |
|
140 TRequestStatus* status=&iStatus; |
|
141 User::RequestComplete(status,KErrNone); |
|
142 SetActive(); |
|
143 } |
|
144 |
|
145 void CSmtpTimer::RunL() |
|
146 { |
|
147 test.Console()->SetPos(0, 10); |
|
148 DisplayProgress(); |
|
149 |
|
150 if (!iSmtpActive.IsActive()) //this is how you check if the MTM is finished or not! |
|
151 { |
|
152 iSmtpActive.Cancel(); |
|
153 CActiveScheduler::Stop(); |
|
154 return; |
|
155 } |
|
156 else |
|
157 After(4000000); |
|
158 } |
|
159 |
|
160 |
|
161 LOCAL_C void TestSendingMessagesL() |
|
162 { |
|
163 CTestActive* testActive = new (ELeave) CTestActive(); |
|
164 CleanupStack::PushL(testActive); |
|
165 |
|
166 CMsvEntrySelection* sendSel = new(ELeave) CMsvEntrySelection(); |
|
167 CleanupStack::PushL(sendSel); |
|
168 |
|
169 testUtils->iServerEntry->SetEntry(KMsvGlobalOutBoxIndexEntryId); |
|
170 User::LeaveIfError(testUtils->iServerEntry->GetChildren(*sendSel)); |
|
171 TInt count=sendSel->Count(); |
|
172 if (!count) |
|
173 { |
|
174 testUtils->WriteComment(_L("\t No messages to send in the outbox")); |
|
175 CleanupStack::PopAndDestroy(2); //testActive, sendsel |
|
176 return; |
|
177 } |
|
178 TBuf<100> logString; |
|
179 testUtils->WriteComment(_L("Issuing CopyFromLocal request...\n")); |
|
180 logString.Format(_L("\t messages to send in the outbox - %d"), count); |
|
181 testUtils->WriteComment(logString); |
|
182 |
|
183 testUtils->InstantiateSmtpServerMtmL(); |
|
184 serverMtm=testUtils->iSmtpServerMtm; |
|
185 |
|
186 serverMtm->CopyFromLocalL(*sendSel,smtpService, testActive->iStatus); |
|
187 CSmtpTimer* timer=CSmtpTimer::NewL(*testActive); |
|
188 CleanupStack::PushL(timer); |
|
189 |
|
190 testActive->StartL(); |
|
191 timer->StartL(); |
|
192 CActiveScheduler::Start(); |
|
193 //check progress |
|
194 DisplayProgress(); |
|
195 logString.Zero(); |
|
196 logString.Format(_L("\t CopyFromLocalL completed with %d"), testActive->iStatus.Int()); |
|
197 testUtils->WriteComment(logString); |
|
198 TImSmtpProgress temp; |
|
199 TPckgC<TImSmtpProgress> paramPack(temp); |
|
200 |
|
201 const TDesC8& progBuf =serverMtm->Progress(); |
|
202 paramPack.Set(progBuf); |
|
203 TImSmtpProgress progress=paramPack(); |
|
204 globalError=progress.Error(); |
|
205 CleanupStack::PopAndDestroy(3); //testActive, sendsel, /*timer*/ |
|
206 } |
|
207 |
|
208 |
|
209 LOCAL_C void InitL() |
|
210 { |
|
211 scheduler = new (ELeave) CActiveScheduler; |
|
212 CleanupStack::PushL(scheduler); |
|
213 CActiveScheduler::Install( scheduler ); |
|
214 |
|
215 testUtils = CEmailTestUtils::NewLC(test); |
|
216 testUtils->WriteComment(KSmtsTest); |
|
217 testUtils->FileSession().Delete(KImskOutFile); |
|
218 testUtils->FileSession().Delete(KImskScrFile); |
|
219 testUtils->CleanMessageFolderL(); |
|
220 testUtils->ClearEmailAccountsL(); |
|
221 |
|
222 if (!testUtils->FileSession().MkDir(KEmailDataDir)) |
|
223 { |
|
224 testUtils->Printf(_L("Created c:\\logs\\email directory\n")); |
|
225 } |
|
226 |
|
227 testUtils->GoClientSideL(); |
|
228 smtpService = testUtils->CreateSmtpServiceL(); |
|
229 |
|
230 } |
|
231 |
|
232 LOCAL_C void ClosedownL() |
|
233 { |
|
234 if (globalError==-245 || globalError==-183 || globalError == -36|| !globalError) |
|
235 testUtils->TestHarnessCompleted(); |
|
236 else |
|
237 testUtils->TestHarnessFailed(globalError); |
|
238 |
|
239 gConnection.Stop(); |
|
240 gConnection.Close(); |
|
241 CleanupStack::PopAndDestroy(2); //testUtils, ischeduler |
|
242 } |
|
243 |
|
244 |
|
245 LOCAL_C void doMainL() |
|
246 { |
|
247 InitL(); |
|
248 |
|
249 // Load the serial comms device drivers. If this is not done, |
|
250 // connecting via NT-RAS returns KErrNotFound (-1). |
|
251 TInt driverErr; |
|
252 driverErr=User::LoadPhysicalDevice(PDD_NAME); |
|
253 if (driverErr!=KErrNone && driverErr!=KErrAlreadyExists) |
|
254 User::Leave(driverErr); |
|
255 driverErr=User::LoadLogicalDevice(LDD_NAME); |
|
256 if (driverErr!=KErrNone && driverErr!=KErrAlreadyExists) |
|
257 User::Leave(driverErr); |
|
258 |
|
259 |
|
260 testUtils->WriteComment(_L(" Create 2 ISPs - pipex and demon by running T_CREATEDB. Set demon as the default ISP.")); |
|
261 testUtils->WriteComment(_L(" Run T_EDITDB and select '1) outgoing connection pref'. Set Ranking 1 - IAP to Demon.")); |
|
262 testUtils->WriteComment(_L(" press page down and set ranking 2 IAP to pipex.")); |
|
263 //overwrite the setings with test code one. Don't want the default settings. |
|
264 |
|
265 // Handle command line arguments |
|
266 CCommandLineArguments* cmdLineArg=CCommandLineArguments::NewLC(); |
|
267 TInt count = cmdLineArg->Count(); |
|
268 TBool isCmdLine=FALSE; |
|
269 if (count>2) // Command line arguments? |
|
270 { |
|
271 if ((!(cmdLineArg->Arg(EArgTestParams).Compare(KTestParams))) && count==EArgEnd) |
|
272 isCmdLine=TRUE; |
|
273 } |
|
274 |
|
275 |
|
276 CImSmtpSettings* settings = new(ELeave) CImSmtpSettings(); |
|
277 CleanupStack::PushL(settings); |
|
278 settings->Reset(); |
|
279 |
|
280 if (isCmdLine) |
|
281 { |
|
282 TBuf<100> buf; |
|
283 TLex lex(cmdLineArg->Arg(EArgServerAddress)); |
|
284 buf=lex.NextToken(); |
|
285 test.Printf(_L("Server address: %S\n"),&buf); |
|
286 settings->SetServerAddressL(buf); |
|
287 } |
|
288 else |
|
289 { |
|
290 _LIT(KSmtpServer, "smtp.demon.co.uk"); |
|
291 settings->SetServerAddressL(KSmtpServer); |
|
292 } |
|
293 settings->SetEmailAliasL(_L("SMTP Test1")); |
|
294 |
|
295 if (isCmdLine) |
|
296 { |
|
297 TBuf<100> buf; |
|
298 TLex lex(cmdLineArg->Arg(EArgEmail)); |
|
299 buf=lex.NextToken(); |
|
300 test.Printf(_L("Mail: %S\n"),&buf); |
|
301 settings->SetEmailAddressL(buf); |
|
302 settings->SetReplyToAddressL(buf); |
|
303 settings->SetReceiptAddressL(buf); |
|
304 } |
|
305 else |
|
306 { |
|
307 _LIT(KSmtpEmailAddress, "<test@psion9.demon.co.uk>"); |
|
308 settings->SetEmailAddressL(KSmtpEmailAddress); |
|
309 settings->SetReplyToAddressL(KSmtpEmailAddress); |
|
310 settings->SetReceiptAddressL(KSmtpEmailAddress); |
|
311 } |
|
312 |
|
313 settings->SetBodyEncoding(EMsgOutboxMIME); |
|
314 settings->SetPort(25); |
|
315 |
|
316 CImIAPPreferences* prefs = CImIAPPreferences::NewLC(); |
|
317 // Add IAP's to iIAPPreferences |
|
318 TImIAPChoice iap; |
|
319 |
|
320 TInt iapID = 0; |
|
321 CMDBSession* dbSession = CMDBSession::NewL(CMDBSession::LatestVersion()); |
|
322 CleanupStack::PushL(dbSession); |
|
323 CCDConnectionPrefsRecord *connPrefRecord = static_cast<CCDConnectionPrefsRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdConnectionPrefsRecord)); |
|
324 CleanupStack::PushL(connPrefRecord); |
|
325 |
|
326 connPrefRecord->iDirection = ECommDbConnectionDirectionOutgoing; |
|
327 connPrefRecord->iRanking = 1; |
|
328 if(!connPrefRecord->FindL(*dbSession)) |
|
329 { |
|
330 User::Leave(KErrNotFound); |
|
331 } |
|
332 iapID = connPrefRecord->iDefaultIAP; |
|
333 |
|
334 CleanupStack::PopAndDestroy(2); //dbSession, connPrefRecord |
|
335 |
|
336 iap.iIAP = iapID; |
|
337 iap.iDialogPref = ECommDbDialogPrefDoNotPrompt; |
|
338 prefs->AddIAPL(iap); |
|
339 CEmailAccounts* accounts = CEmailAccounts::NewLC(); |
|
340 |
|
341 TSmtpAccount smtpAccountId; |
|
342 accounts->GetSmtpAccountL(smtpService,smtpAccountId); |
|
343 accounts->SaveSmtpSettingsL(smtpAccountId, *settings); |
|
344 accounts->SaveSmtpIapSettingsL(smtpAccountId, *prefs); |
|
345 |
|
346 CleanupStack::PopAndDestroy(4, cmdLineArg); // accounts, prefs, settings, cmdLineArg |
|
347 |
|
348 testUtils->WriteComment(_L(" smtp server created")); |
|
349 |
|
350 TParse dir; |
|
351 testUtils->ResolveFile(KSmtsComponent,KSmtsRFCEmails,dir); |
|
352 testUtils->GoServerSideL(); |
|
353 |
|
354 testUtils->CreateMessageFilesL(smtpService,KMsvGlobalOutBoxIndexEntryId,dir.FullName()); |
|
355 testUtils->WriteComment(_L(" Messages created in the outbox")); |
|
356 testUtils->WriteComment(_L("Instantiated smtp server mtm")); |
|
357 |
|
358 testUtils->iServerEntry->SetEntry(smtpService); |
|
359 TBuf<64> logString; |
|
360 logString.Format(_L(" IAP is %d"),iapID); |
|
361 |
|
362 testUtils->WriteComment(logString); |
|
363 |
|
364 gSocketServ.Connect(); |
|
365 User::LeaveIfError(gConnection.Open(gSocketServ)); |
|
366 testUtils->TestStart(1,_L("SocketServ startDialout called")); |
|
367 TRequestStatus status; |
|
368 gConnection.Start(status); |
|
369 |
|
370 TInt err=0; |
|
371 while(status==KRequestPending) |
|
372 { |
|
373 CActiveScheduler::Current()->RunIfReady(err,0); |
|
374 User::WaitForAnyRequest(); |
|
375 } |
|
376 testUtils->TestFinish(1,status.Int()); |
|
377 if (status.Int()) |
|
378 { |
|
379 ClosedownL(); |
|
380 return; |
|
381 } |
|
382 testUtils->WriteComment(_L("Genconn startDialout successful")); |
|
383 TUint32 address=0; |
|
384 TUint32 activeIAP; |
|
385 TBuf<KCommsDbSvrMaxColumnNameLength> settingName; |
|
386 |
|
387 settingName.Copy(TPtrC(IAP)); |
|
388 settingName.Append(TChar('\\')); |
|
389 settingName.Append(TPtrC(COMMDB_ID)); |
|
390 address = gConnection.GetIntSetting(settingName, activeIAP); |
|
391 |
|
392 logString.Zero(); |
|
393 logString.Format(_L(" Active iap from genconn is %d"),address); |
|
394 testUtils->WriteComment(logString); |
|
395 |
|
396 testUtils->TestStart(2,_L("sending msgs with IAP same as active IAP")); |
|
397 TestSendingMessagesL(); |
|
398 testUtils->TestFinish(2,globalError); |
|
399 |
|
400 |
|
401 if (globalError) |
|
402 { |
|
403 ClosedownL(); |
|
404 return; |
|
405 } |
|
406 gConnection.Stop(); |
|
407 gConnection.Close(); |
|
408 |
|
409 testUtils->TestStart(3,_L("sending msgs with IAP different to active IAP")); |
|
410 testUtils->CreateMessageFilesL(smtpService,KMsvGlobalOutBoxIndexEntryId,dir.FullName()); |
|
411 |
|
412 logString.Zero(); |
|
413 testUtils->WriteComment(logString); |
|
414 gSocketServ.Connect(); |
|
415 globalError=gConnection.Open(gSocketServ); |
|
416 if (!globalError) |
|
417 { |
|
418 CMDBSession* dbSession = CMDBSession::NewL(CMDBSession::LatestVersion()); |
|
419 CleanupStack::PushL(dbSession); |
|
420 connPrefRecord = static_cast<CCDConnectionPrefsRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdConnectionPrefsRecord)); |
|
421 CleanupStack::PushL(connPrefRecord); |
|
422 |
|
423 connPrefRecord->iDirection = ECommDbConnectionDirectionOutgoing; |
|
424 connPrefRecord->iRanking = 2; |
|
425 connPrefRecord->FindL(*dbSession); |
|
426 iapID = connPrefRecord->iDefaultIAP; |
|
427 |
|
428 CleanupStack::PopAndDestroy(2); //dbSession, connPrefRecord |
|
429 |
|
430 TCommDbMultiConnPref prefs; |
|
431 TInt rank=1; |
|
432 TCommDbConnPref pref; |
|
433 pref.SetDirection(ECommDbConnectionDirectionOutgoing); |
|
434 pref.SetBearerSet(KCommDbBearerPSD | KCommDbBearerCSD); |
|
435 |
|
436 pref.SetDirection(ECommDbConnectionDirectionOutgoing); |
|
437 pref.SetBearerSet(KCommDbBearerPSD | KCommDbBearerCSD); |
|
438 iap.iIAP = iapID; |
|
439 iap.iDialogPref = ECommDbDialogPrefDoNotPrompt; |
|
440 |
|
441 pref.SetIapId(iap.iIAP); |
|
442 pref.SetDialogPreference(iap.iDialogPref); |
|
443 User::LeaveIfError(prefs.SetPreference(rank, pref)); |
|
444 |
|
445 prefs.SetConnectionAttempts(rank); |
|
446 gConnection.Start(prefs, status); |
|
447 |
|
448 |
|
449 while(status==KRequestPending) |
|
450 { |
|
451 CActiveScheduler::Current()->RunIfReady(err,0); |
|
452 User::WaitForAnyRequest(); |
|
453 } |
|
454 |
|
455 } |
|
456 if (globalError || status.Int()) |
|
457 { |
|
458 if (!globalError) |
|
459 globalError=status.Int(); |
|
460 ClosedownL(); |
|
461 return; |
|
462 } |
|
463 address=0; |
|
464 settingName.Copy(TPtrC(KCDTypeNameIAP)); |
|
465 settingName.Append(TChar('\\')); |
|
466 settingName.Append(TPtrC(KCDTypeNameRecordTag)); |
|
467 err = gConnection.GetIntSetting(settingName, activeIAP); |
|
468 |
|
469 logString.Zero(); |
|
470 logString.Format(_L(" Active IAP from genconn is %d"),address); |
|
471 testUtils->WriteComment(logString); |
|
472 TestSendingMessagesL(); |
|
473 globalError=(globalError==-183)? 0 : globalError; |
|
474 |
|
475 testUtils->TestFinish(3,globalError); |
|
476 testUtils->WriteComment(_L("Test 3 should complete with -183")); |
|
477 ClosedownL(); |
|
478 } |
|
479 |
|
480 |
|
481 GLDEF_C TInt E32Main() |
|
482 { |
|
483 __UHEAP_MARK; |
|
484 test.Start(_L("T_SMTS02 Test SMTP server MTM class")); |
|
485 theCleanup=CTrapCleanup::New(); |
|
486 TRAPD(ret,doMainL()); |
|
487 test(ret==KErrNone); |
|
488 delete theCleanup; |
|
489 test.End(); |
|
490 test.Close(); |
|
491 __UHEAP_MARKEND; |
|
492 User::Heap().Check(); |
|
493 return(KErrNone); |
|
494 } |