|
1 // Copyright (c) 2005-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 // The sever contains emails with multiple or missing date header fields to ensure that the IAMP |
|
15 // parser correctly parses the data. The first received header should be used where present, |
|
16 // the date header when its not. The current UTC time should be used if neither are present. |
|
17 // 2. The client connects to the server and request a sync. |
|
18 // 3. The server reads the protocol information from a file specified in the ini file (mapUTCTest.ini). |
|
19 // 4. The client disconnects. |
|
20 // 5. The message store is traversed to see if the correct timestamps have been given to the |
|
21 // message entries. |
|
22 // |
|
23 // |
|
24 |
|
25 /** |
|
26 @SYMTestCaseID MSG-IMAP-0243 |
|
27 @SYMTestType UT |
|
28 @SYMTestPriority High |
|
29 @SYMPREQ 234 |
|
30 @SYMTestCaseDesc Implements an IMAP server to facilitate offline testing of imap parsing. |
|
31 @SYMTestActions 1. The Server is started and listens on port 143. |
|
32 @SYMTestExpectedResults The timestamps of the message entries should be the same as in the ini file. |
|
33 */ |
|
34 |
|
35 #include <testexecutelog.h> |
|
36 #include "t_parse_utc_imapstep.h" |
|
37 |
|
38 |
|
39 _LIT(KUTCTest,"UTC-TIME"); |
|
40 _LIT(KTestMessageDir,"rfc822\\parse\\"); |
|
41 RTest test(_L("UTC Parse Test")); |
|
42 |
|
43 |
|
44 LOCAL_C void FormatDateTime(TDes& aBuffer, const TTime& aTime) |
|
45 { |
|
46 aBuffer.Zero(); |
|
47 _LIT(KFormat4,"%/0%1%/1%2%/2%3%/3 %-B%:0%J%:1%T%:2%S%:3%+B"); |
|
48 aTime.FormatL(aBuffer,KFormat4); |
|
49 } |
|
50 |
|
51 CTestUTCParse::~CTestUTCParse() |
|
52 { |
|
53 delete iConsole; |
|
54 delete iImapServer; |
|
55 delete iTestUtils; |
|
56 delete iImapClient; |
|
57 delete iScheduler; |
|
58 iSession->CloseMessageServer(); |
|
59 delete iSession; |
|
60 delete iSessionObserver; |
|
61 } |
|
62 |
|
63 CTestUTCParse::CTestUTCParse() |
|
64 { |
|
65 // Call base class method to set up the human readable name for logging |
|
66 SetTestStepName(KTestUTCParse); |
|
67 } |
|
68 |
|
69 |
|
70 |
|
71 void CTestUTCParse::HandleEvent(TInt aEventCode) |
|
72 { |
|
73 CActiveScheduler::Stop(); |
|
74 |
|
75 if(aEventCode!=KErrNone && aEventCode!=KErrEof) |
|
76 { |
|
77 ERR_PRINTF2(_L("Error: %d"),aEventCode); |
|
78 } |
|
79 |
|
80 } |
|
81 |
|
82 |
|
83 void CTestUTCParse::PrintEntryTime(TTime* aTIme) |
|
84 { |
|
85 TBuf<45> lDateTimeString; |
|
86 FormatDateTime(lDateTimeString,*aTIme); |
|
87 INFO_PRINTF2(_L("%S"),&lDateTimeString); |
|
88 } |
|
89 |
|
90 |
|
91 void CTestUTCParse::GetDetailsFromIniFileL() |
|
92 { |
|
93 |
|
94 //get the script file path |
|
95 if(!GetStringFromConfig(ConfigSection(),_L("ScriptFile"),iScriptFile)) |
|
96 |
|
97 { |
|
98 ERR_PRINTF1(_L("Error reading script file path from ini file")); |
|
99 User::Leave(KErrArgument); |
|
100 } |
|
101 |
|
102 TPtrC16 expectedTime; |
|
103 //get the expected time stamp |
|
104 if(!GetStringFromConfig(ConfigSection(),_L("ExpectedTime"),expectedTime)) |
|
105 |
|
106 { |
|
107 ERR_PRINTF1(_L("Error reading expected time stamp file path from ini file")); |
|
108 User::Leave(KErrArgument); |
|
109 } |
|
110 else |
|
111 { |
|
112 TInt pos=expectedTime.Find(KUTCTest); |
|
113 |
|
114 if(pos!=KErrNotFound) |
|
115 { |
|
116 iExpectedTimeStampIsNow=ETrue; |
|
117 iExpectedTimeStamp.UniversalTime(); |
|
118 } |
|
119 else |
|
120 { |
|
121 iExpectedTimeStampIsNow=EFalse; |
|
122 iExpectedTimeStamp.Set(expectedTime); |
|
123 } |
|
124 |
|
125 } |
|
126 |
|
127 //get the script file path |
|
128 if(!GetBoolFromConfig(ConfigSection(),_L("FetchWholeMessage"),iFetchWholeMessage)) |
|
129 |
|
130 { |
|
131 ERR_PRINTF1(_L("Error reading script file path from ini file")); |
|
132 User::Leave(KErrArgument); |
|
133 } |
|
134 //if the test contains an embedded test then get the expected timestamp for the |
|
135 //embedded message |
|
136 if(iFetchWholeMessage==1) |
|
137 { |
|
138 if(!GetStringFromConfig(ConfigSection(),_L("ExpectedTime2"),expectedTime)) |
|
139 { |
|
140 ERR_PRINTF1(_L("Error reading expected time stamp file path from ini file")); |
|
141 User::Leave(KErrArgument); |
|
142 } |
|
143 else |
|
144 { |
|
145 TInt pos=expectedTime.Find(KUTCTest); |
|
146 |
|
147 if(pos!=KErrNotFound) |
|
148 { |
|
149 iExpectedTimeStampIsNow2=ETrue; |
|
150 iExpectedTimeStamp2.UniversalTime(); |
|
151 } |
|
152 else |
|
153 { |
|
154 iExpectedTimeStampIsNow2=EFalse; |
|
155 iExpectedTimeStamp2.Set(expectedTime); |
|
156 } |
|
157 } |
|
158 } |
|
159 |
|
160 } |
|
161 |
|
162 |
|
163 void CTestUTCParse::WriteStoreL() |
|
164 { |
|
165 //create the entry_structure file |
|
166 TParse parsedFileName; |
|
167 TFileName lName(KTestMessageDir); |
|
168 iTestUtils->ResolveLogFile(lName, parsedFileName); |
|
169 iTestUtils->FindChildrenL(KMsvRootIndexEntryIdValue, parsedFileName.FullName(), ETrue, EFalse); |
|
170 } |
|
171 |
|
172 void CTestUTCParse::TraverseL(const TMsvId aTMsvId) |
|
173 { |
|
174 //open the entry, dont sort |
|
175 TMsvSelectionOrdering ordering; |
|
176 ordering.SetSorting(EMsvSortByNone); |
|
177 CMsvEntry* entry = CMsvEntry::NewL(*iSession, aTMsvId,ordering); |
|
178 CleanupStack::PushL(entry); |
|
179 |
|
180 //retrieve the entries children |
|
181 CMsvEntrySelection* msvEntrySelection; |
|
182 msvEntrySelection=entry->ChildrenL(); |
|
183 CleanupStack::PushL(msvEntrySelection); |
|
184 TInt count = entry->Count(); |
|
185 |
|
186 CMsvEntry* child; |
|
187 TMsvEntry childDetails; |
|
188 |
|
189 //for each child test if its a message entry |
|
190 for(TInt i=0;i<count;i++) |
|
191 { |
|
192 child=iSession->GetEntryL((*msvEntrySelection)[i]); |
|
193 childDetails=child->Entry(); |
|
194 |
|
195 if(childDetails.iType==KUidMsvMessageEntry) |
|
196 { |
|
197 iMessageEntryCount++; |
|
198 //if this is the first timestamp the us iActualTimeStamp, else use iActualTimeStamp2 |
|
199 if(iActualTimeStamp==0) |
|
200 { |
|
201 iActualTimeStamp=childDetails.iDate; |
|
202 PrintEntryTime(&childDetails.iDate); |
|
203 } |
|
204 else |
|
205 { |
|
206 iActualTimeStamp2=childDetails.iDate; |
|
207 PrintEntryTime(&childDetails.iDate); |
|
208 } |
|
209 } |
|
210 //recursive call |
|
211 TraverseL(childDetails.Id()); |
|
212 |
|
213 delete child; |
|
214 } |
|
215 |
|
216 CleanupStack::PopAndDestroy(msvEntrySelection); |
|
217 CleanupStack::PopAndDestroy(entry); |
|
218 |
|
219 } |
|
220 |
|
221 |
|
222 TVerdict CTestUTCParse::doTestStepPreambleL() |
|
223 { |
|
224 |
|
225 SetTestStepResult(EPass); |
|
226 iScheduler = new (ELeave) CActiveScheduler; |
|
227 CActiveScheduler::Install(iScheduler); |
|
228 |
|
229 iTestUtils = CEmailTestUtils::NewL(test); |
|
230 iTestUtils->FileSession().SetSessionPath(_L("C:\\")); |
|
231 iTestUtils->CleanMessageFolderL(); |
|
232 iTestUtils->ClearEmailAccountsL(); |
|
233 |
|
234 iTestUtils->GoClientSideL(); |
|
235 |
|
236 //start the imap server |
|
237 GetDetailsFromIniFileL(); |
|
238 iConsole=Console::NewL(_L("IMAP UTC Parse Test"),TSize(KConsFullScreen,KConsFullScreen)); |
|
239 iImapServer = CImapSpoofServer::NewL(this,iScriptFile); |
|
240 iImapServer->StartL(); |
|
241 |
|
242 //start the imap client |
|
243 iImapClient = CActiveImapClient::NewL(this,iFetchWholeMessage); |
|
244 iImapClient->StartL(); |
|
245 |
|
246 CActiveScheduler::Start(); |
|
247 |
|
248 return TestStepResult(); |
|
249 } |
|
250 |
|
251 |
|
252 TVerdict CTestUTCParse::CheckTimeStamps() |
|
253 { |
|
254 TVerdict lResult; |
|
255 |
|
256 if(iExpectedTimeStampIsNow==EFalse) |
|
257 { |
|
258 lResult = (iActualTimeStamp==iExpectedTimeStamp? EPass:EFail); |
|
259 } |
|
260 else |
|
261 { |
|
262 TTimeIntervalMicroSeconds difference; |
|
263 difference=iExpectedTimeStamp.MicroSecondsFrom(iActualTimeStamp); |
|
264 lResult = (difference<5000000? EPass:EFail); |
|
265 } |
|
266 |
|
267 // If there is an embedded message, check the times on that as well |
|
268 if ((lResult == EPass) && (iFetchWholeMessage)) |
|
269 { |
|
270 if(iExpectedTimeStampIsNow2==EFalse) |
|
271 { |
|
272 lResult = (iActualTimeStamp2==iExpectedTimeStamp2 ? EPass:EFail); |
|
273 } |
|
274 else |
|
275 { |
|
276 TTimeIntervalMicroSeconds difference; |
|
277 difference=iExpectedTimeStamp2.MicroSecondsFrom(iActualTimeStamp2); |
|
278 lResult = (difference<5000000? EPass:EFail); |
|
279 } |
|
280 } |
|
281 |
|
282 return lResult; |
|
283 } |
|
284 |
|
285 TVerdict CTestUTCParse::doTestStepL() |
|
286 { |
|
287 TVerdict result; |
|
288 // Session observer. Needed to create a session |
|
289 iSessionObserver = new (ELeave) TDummySessionObserver; |
|
290 // Session. Needed to create a client registry. |
|
291 iSession=CMsvSession::OpenSyncL(*iSessionObserver); |
|
292 // Client registry. Needed to get the MTM component |
|
293 TraverseL(iImapClient->GetAccount().iImapService); |
|
294 WriteStoreL(); |
|
295 |
|
296 result=CheckTimeStamps(); |
|
297 |
|
298 SetTestStepResult(result); |
|
299 |
|
300 return TestStepResult(); |
|
301 } |
|
302 |
|
303 |
|
304 TVerdict CTestUTCParse::doTestStepPostambleL() |
|
305 { |
|
306 return TestStepResult(); |
|
307 } |