|
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 // |
|
15 |
|
16 #include "T_ImapBadlyFormedAddressStep.h" |
|
17 #include "T_ImapBadlyFormedAddressClient.h" |
|
18 |
|
19 #include "emailtestutils.h" |
|
20 |
|
21 #include <e32test.h> |
|
22 |
|
23 RTest test(_L("IMAP receive new message while synch is cancelling idle")); |
|
24 |
|
25 const TInt KSizeDateTimeBuffer = 45; |
|
26 const TInt KImapPort = 143; |
|
27 |
|
28 LOCAL_C void FormatDateTime(TDes& aBuffer, const TTime& aTime) |
|
29 { |
|
30 aBuffer.Zero(); |
|
31 _LIT(KFormat4,"%/0%1%/1%2%/2%3%/3 %-B%:0%J%:1%T%:2%S%:3%+B"); |
|
32 aTime.FormatL(aBuffer,KFormat4); |
|
33 } |
|
34 |
|
35 CImapBadlyFormedAddressStep::CImapBadlyFormedAddressStep() |
|
36 { |
|
37 // Call base class method to set up the human readable name for logging |
|
38 SetTestStepName(KTestImapBadlyFormedAddress); |
|
39 } |
|
40 |
|
41 CImapBadlyFormedAddressStep::~CImapBadlyFormedAddressStep() |
|
42 { |
|
43 delete iConsole; |
|
44 delete iSpoofServer; |
|
45 delete iTestUtils; |
|
46 delete iImapClient; |
|
47 delete iScheduler; |
|
48 if(iSession!=NULL) |
|
49 iSession->CloseMessageServer(); |
|
50 delete iSession; |
|
51 delete iSessionObserver; |
|
52 } |
|
53 |
|
54 void CImapBadlyFormedAddressStep::TestComplete(TInt aEventCode) |
|
55 { |
|
56 CActiveScheduler::Stop(); |
|
57 |
|
58 if(aEventCode!=KErrNone && aEventCode!=KErrEof) |
|
59 { |
|
60 ERR_PRINTF2(_L("Error: %d"),aEventCode); |
|
61 } |
|
62 } |
|
63 |
|
64 void CImapBadlyFormedAddressStep::PrintEntryTime(TTime* aTIme) |
|
65 { |
|
66 TBuf<KSizeDateTimeBuffer> dateTimeString; |
|
67 FormatDateTime(dateTimeString,*aTIme); |
|
68 INFO_PRINTF2(_L("%S"),&dateTimeString); |
|
69 } |
|
70 |
|
71 void CImapBadlyFormedAddressStep::GetDetailsFromIniFileL() |
|
72 { |
|
73 // get the script file path |
|
74 _LIT(KScriptFile,"ScriptFile"); |
|
75 if(!GetStringFromConfig(ConfigSection(),KScriptFile,iScriptFile)) |
|
76 { |
|
77 _LIT(KErrorScriptFile, "Error reading script file path from ini file"); |
|
78 ERR_PRINTF1(KErrorScriptFile); |
|
79 User::Leave(KErrArgument); |
|
80 } |
|
81 |
|
82 // get the expected number of mails |
|
83 _LIT(KExpectedCountString, "ExpectedEntryCount"); |
|
84 if(!GetIntFromConfig(ConfigSection(),KExpectedCountString,iExpectedEntryCount)) |
|
85 { |
|
86 _LIT(KErrorExpectedCount, "Error reading expected entry count from ini file"); |
|
87 ERR_PRINTF1(KErrorExpectedCount); |
|
88 User::Leave(KErrArgument); |
|
89 } |
|
90 } |
|
91 |
|
92 TVerdict CImapBadlyFormedAddressStep::doTestStepPreambleL() |
|
93 { |
|
94 SetTestStepResult(EPass); |
|
95 iScheduler = new (ELeave) CActiveScheduler; |
|
96 CActiveScheduler::Install(iScheduler); |
|
97 |
|
98 iTestUtils = CEmailTestUtils::NewL(test); |
|
99 iTestUtils->FileSession().SetSessionPath(_L("C:\\")); |
|
100 iTestUtils->CleanMessageFolderL(); |
|
101 iTestUtils->ClearEmailAccountsL(); |
|
102 |
|
103 iTestUtils->GoClientSideL(); |
|
104 |
|
105 // start the imap server |
|
106 GetDetailsFromIniFileL(); |
|
107 iConsole=Console::NewL(_L("IMAP Receive New Msg During Sync Idle Cancel"),TSize(KConsFullScreen,KConsFullScreen)); |
|
108 iSpoofServer = CSpoofServer::NewL(*this,iScriptFile); |
|
109 iSpoofServer->StartL(KImapPort); |
|
110 |
|
111 // start the imap client |
|
112 iImapClient = CImapBadlyFormedAddressClient::NewL(this); |
|
113 iImapClient->StartL(); |
|
114 |
|
115 CActiveScheduler::Start(); |
|
116 return TestStepResult(); |
|
117 } |
|
118 |
|
119 TInt CImapBadlyFormedAddressStep::GetEntryCountL() |
|
120 { |
|
121 TImapAccount imapAccount=iImapClient->GetImapAccount(); |
|
122 |
|
123 TMsvSelectionOrdering ordering; |
|
124 |
|
125 // open the imap service entry |
|
126 CMsvEntry* imapService = CMsvEntry::NewL(*iSession,imapAccount.iImapService,ordering); |
|
127 CleanupStack::PushL(imapService); |
|
128 // get its children |
|
129 CMsvEntrySelection* msvEntrySelection; |
|
130 msvEntrySelection=imapService->ChildrenL(); |
|
131 // open its child inbox entry |
|
132 CMsvEntry* inboxEntry = CMsvEntry::NewL(*iSession, (*msvEntrySelection)[0],ordering); |
|
133 CleanupStack::PushL(inboxEntry); |
|
134 |
|
135 // get the childeren of the inbox |
|
136 delete msvEntrySelection; |
|
137 msvEntrySelection=NULL; |
|
138 msvEntrySelection=inboxEntry->ChildrenL(); |
|
139 TInt count=msvEntrySelection->Count(); |
|
140 |
|
141 delete msvEntrySelection; |
|
142 msvEntrySelection=NULL; |
|
143 CleanupStack::PopAndDestroy(2,imapService); |
|
144 |
|
145 return count; |
|
146 } |
|
147 |
|
148 |
|
149 TVerdict CImapBadlyFormedAddressStep::doTestStepL() |
|
150 { |
|
151 TVerdict result; |
|
152 // Session observer. Needed to create a session |
|
153 iSessionObserver = new (ELeave) TDummySessionObserver; |
|
154 // Session. Needed to create a client registry. |
|
155 iSession=CMsvSession::OpenSyncL(*iSessionObserver); |
|
156 // get entry count |
|
157 TInt entryCount=GetEntryCountL(); |
|
158 result = (entryCount==iExpectedEntryCount? EPass:EFail); |
|
159 SetTestStepResult(result); |
|
160 return TestStepResult(); |
|
161 } |
|
162 |
|
163 TVerdict CImapBadlyFormedAddressStep::doTestStepPostambleL() |
|
164 { |
|
165 return TestStepResult(); |
|
166 } |