|
1 // Copyright (c) 1998-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 // Test harness for Email Notification Parser |
|
15 // |
|
16 // |
|
17 |
|
18 //Create a buffer containing an sms message with the relevant field |
|
19 //then pass it by reference to the parser dll |
|
20 #include <e32uid.h> |
|
21 #include <e32test.h> |
|
22 #include <e32cons.h> |
|
23 #include <s32file.h> |
|
24 #include <e32base.h> |
|
25 |
|
26 #include "TESTENV.H" |
|
27 |
|
28 #include <regpsdll.h> |
|
29 |
|
30 #include "biotestutils.h" |
|
31 |
|
32 #define BIO_MSG_ENTRY_PARSED 1 // Set entry .iMtmData3 to 1 to indicate that the entry has store i.e parsed,externalised |
|
33 |
|
34 #define KTestEnpPriority (1) //Change this.... |
|
35 |
|
36 #define KEmailNotificationTextFilePath _L("c:\\test\\bio\\enp\\") |
|
37 |
|
38 // |
|
39 |
|
40 //forward reference |
|
41 class CExampleScheduler; |
|
42 LOCAL_C void DisplayErrorReason(TInt& aReason); |
|
43 |
|
44 //global declarations |
|
45 LOCAL_D RTest test(_L("ENP Test Harness")); |
|
46 |
|
47 // |
|
48 // CExampleScheduler // |
|
49 // |
|
50 |
|
51 class CExampleScheduler : public CActiveScheduler |
|
52 { |
|
53 public: |
|
54 void Error (TInt aError) const; |
|
55 }; |
|
56 |
|
57 void CExampleScheduler::Error(TInt anError) const |
|
58 { |
|
59 CActiveScheduler::Stop(); |
|
60 test.Printf(_L("\nLeave signalled, reason=%d\n"),anError); |
|
61 } |
|
62 // end CExampleScheduler::Error(TInt) const |
|
63 |
|
64 |
|
65 // |
|
66 // CTestEnp: INTERFACE // |
|
67 // |
|
68 LOCAL_D CExampleScheduler *exampleScheduler; |
|
69 |
|
70 class CTestEnp : public CActive |
|
71 { |
|
72 public: |
|
73 ~CTestEnp(); |
|
74 CTestEnp(); |
|
75 |
|
76 static CTestEnp* NewL(); |
|
77 void ConstructL(); |
|
78 void Start(TInt aCmd); |
|
79 void RunL(); |
|
80 void DoCancel(); |
|
81 void RequestComplete(TRequestStatus& aStatus,TInt aCompletion); |
|
82 |
|
83 enum TSessionState |
|
84 { |
|
85 EParse, |
|
86 EProcess, |
|
87 EReparse, |
|
88 EDisplay, //Display entry data |
|
89 }; |
|
90 |
|
91 private: |
|
92 TInt iState; |
|
93 TInt iMsgCtr; |
|
94 TInt iMsgCount; |
|
95 |
|
96 TInt iTestCtr; |
|
97 |
|
98 CBaseScriptParser2* iParser; |
|
99 CMsvEntrySelection* iMsvSelection; |
|
100 |
|
101 CArrayPtrSeg<CParsedField>* iTestParsedFieldArray; |
|
102 CBioTestUtils* iBioTestUtils; |
|
103 HBufC* iMsgBuffer; |
|
104 }; |
|
105 |
|
106 |
|
107 |
|
108 // |
|
109 // CTestEnp: IMPLEMENTATION // |
|
110 // |
|
111 |
|
112 CTestEnp* CTestEnp::NewL() |
|
113 { |
|
114 CTestEnp* self = new (ELeave) CTestEnp(); |
|
115 CleanupStack::PushL(self); |
|
116 self->ConstructL(); |
|
117 CleanupStack::Pop(); //self |
|
118 return self; |
|
119 } |
|
120 // end CTestEnp::NewL(CMsvServerEntry*) |
|
121 |
|
122 |
|
123 void CTestEnp::ConstructL() |
|
124 { |
|
125 // create test utilities object & go server side |
|
126 iBioTestUtils = CBioTestUtils::NewL(test, ETuGoClientSide | ETuDeleteService | ETuCreateService); |
|
127 |
|
128 // create some messages |
|
129 iMsvSelection = iBioTestUtils->GenerateMessagesL(KEmailNotificationTextFilePath); |
|
130 iMsgCount = iMsvSelection->Count(); |
|
131 |
|
132 // create the parser |
|
133 TBool finished = EFalse; |
|
134 #ifdef _DEBUG |
|
135 TInt failCount = 0; |
|
136 #endif |
|
137 while(!finished) |
|
138 { |
|
139 __UHEAP_FAILNEXT(failCount++); |
|
140 // |
|
141 TRAPD(error, iParser = iBioTestUtils->CreateParserTypeL(KUidBIOEmailNotificationMsg);); |
|
142 if (error == KErrNone) |
|
143 { |
|
144 __UHEAP_RESET; |
|
145 finished = ETrue; |
|
146 __UHEAP_RESET; |
|
147 } |
|
148 // Handle error |
|
149 else |
|
150 { |
|
151 // Check if error is out of memory or a specific fax rendering error |
|
152 test(error == KErrNoMemory); |
|
153 __UHEAP_RESET; |
|
154 } |
|
155 } |
|
156 |
|
157 CActiveScheduler::Add(this); |
|
158 } |
|
159 // end CTestEnp::ConstructL() |
|
160 |
|
161 |
|
162 void CTestEnp::Start(TInt aCmd) |
|
163 { |
|
164 TInt error = KErrNone; |
|
165 TBool finished = EFalse; |
|
166 #ifdef _DEBUG |
|
167 TInt failCount = 0; |
|
168 #endif |
|
169 iState=aCmd; |
|
170 |
|
171 switch (iState) |
|
172 { |
|
173 case EParse: |
|
174 test.Printf(_L("Parsing...\n")); |
|
175 iBioTestUtils->TestStart(iTestCtr,_L("Parsing")); |
|
176 delete iMsgBuffer; |
|
177 iMsgBuffer = iBioTestUtils->MessageBodyL((*iMsvSelection)[iMsgCtr]).AllocL(); |
|
178 |
|
179 while(!finished) |
|
180 { |
|
181 __UHEAP_FAILNEXT(failCount++); |
|
182 // |
|
183 TRAP(error, iParser->ParseL(iStatus,*iMsgBuffer)); |
|
184 if (error == KErrNone) |
|
185 { |
|
186 __UHEAP_RESET; |
|
187 finished = ETrue; |
|
188 SetActive(); |
|
189 } |
|
190 // Handle error |
|
191 else |
|
192 { |
|
193 // Check if error is out of memory or a specific fax rendering error |
|
194 test(error == KErrNoMemory); |
|
195 __UHEAP_RESET; |
|
196 } |
|
197 } |
|
198 break; |
|
199 |
|
200 case EProcess: |
|
201 test.Printf(_L("process...(This is not supported in Email Notification Parser)\n")); |
|
202 iBioTestUtils->TestStart(iTestCtr,_L("Calling process")); |
|
203 TRAP(error,iParser->ProcessL(iStatus); ); |
|
204 while(!finished) |
|
205 { |
|
206 __UHEAP_FAILNEXT(failCount++); |
|
207 // |
|
208 TRAP(error, iParser->ProcessL(iStatus)); |
|
209 if (error == KErrNone) |
|
210 { |
|
211 __UHEAP_RESET; |
|
212 finished = ETrue; |
|
213 SetActive(); |
|
214 } |
|
215 // Handle error |
|
216 else |
|
217 { |
|
218 // Check if error is out of memory or a specific fax rendering error |
|
219 test(error == KErrNoMemory); |
|
220 __UHEAP_RESET; |
|
221 } |
|
222 } |
|
223 break; |
|
224 |
|
225 case EReparse: |
|
226 test.Printf(_L("Reparsing...\n")); |
|
227 iBioTestUtils->TestStart(iTestCtr,_L("Re-Parsing")); |
|
228 while(!finished) |
|
229 { |
|
230 __UHEAP_FAILNEXT(failCount++); |
|
231 // |
|
232 TRAP(error, iParser->ParseL(iStatus,*iMsgBuffer)); |
|
233 if (error == KErrNone) |
|
234 { |
|
235 __UHEAP_RESET; |
|
236 finished = ETrue; |
|
237 SetActive(); |
|
238 } |
|
239 // Handle error |
|
240 else |
|
241 { |
|
242 // Check if error is out of memory or a specific fax rendering error |
|
243 test(error == KErrNoMemory); |
|
244 __UHEAP_RESET; |
|
245 } |
|
246 } |
|
247 break; |
|
248 |
|
249 case EDisplay: |
|
250 iBioTestUtils->TestStart(iTestCtr,_L("Printing parsed fields")); |
|
251 TRAP(error,iBioTestUtils->LogExtractedFieldsL((*iMsvSelection)[iMsgCtr])); |
|
252 RequestComplete(iStatus,error); |
|
253 SetActive(); |
|
254 break; |
|
255 |
|
256 default: |
|
257 break; |
|
258 } |
|
259 } |
|
260 // end CTestEnp::StartL(TInt) |
|
261 |
|
262 |
|
263 void CTestEnp::RunL() |
|
264 { |
|
265 TInt result=iStatus.Int(); |
|
266 |
|
267 if (result != KErrNone && result != KErrNotSupported) |
|
268 { |
|
269 test.Console()->ClearScreen(); |
|
270 test.Console()->SetPos(0,0); |
|
271 DisplayErrorReason(result); |
|
272 iBioTestUtils->TestHarnessFailed(result); |
|
273 CActiveScheduler::Stop(); |
|
274 return; |
|
275 } |
|
276 |
|
277 if(iState==EProcess) |
|
278 iBioTestUtils->WriteComment(_L("ProcessL not supported")); |
|
279 iBioTestUtils->TestFinish(iTestCtr); |
|
280 iTestCtr++; |
|
281 switch (iState) |
|
282 { |
|
283 case EParse: |
|
284 Start(EProcess); |
|
285 break; |
|
286 |
|
287 case EProcess: |
|
288 Start(EReparse); |
|
289 break; |
|
290 |
|
291 case EReparse: |
|
292 Start(EDisplay); |
|
293 break; |
|
294 |
|
295 case EDisplay: |
|
296 { |
|
297 if(++iMsgCtr < iMsgCount) |
|
298 Start(EParse); |
|
299 else |
|
300 { |
|
301 test.Console()->ClearScreen(); |
|
302 test.Console()->SetPos(0,0); |
|
303 DisplayErrorReason(result); |
|
304 iParser->Cancel(); |
|
305 iBioTestUtils->TestHarnessCompleted(); |
|
306 CActiveScheduler::Stop(); |
|
307 } |
|
308 } |
|
309 break; |
|
310 |
|
311 default: |
|
312 break; |
|
313 } |
|
314 } |
|
315 // end CTestEnp::RunL() |
|
316 |
|
317 |
|
318 void CTestEnp::DoCancel() |
|
319 { |
|
320 } |
|
321 // end CTestEnp::DoCancel() |
|
322 |
|
323 void CTestEnp::RequestComplete(TRequestStatus& aStatus,TInt aCompletion) |
|
324 { |
|
325 TRequestStatus* statusPtr=&aStatus; |
|
326 User::RequestComplete(statusPtr,aCompletion); |
|
327 } |
|
328 |
|
329 LOCAL_C void DisplayErrorReason(TInt& aReason) |
|
330 { |
|
331 switch (aReason) |
|
332 { |
|
333 case KErrNone: |
|
334 test.Printf(_L("Session completed successfully")); |
|
335 break; |
|
336 case KErrCancel: |
|
337 test.Printf(_L("Session cancelled")); |
|
338 break; |
|
339 case KErrEof: |
|
340 test.Printf(_L("KErrEof")); |
|
341 break; |
|
342 case KErrNoMemory: |
|
343 test.Printf(_L("No memory")); |
|
344 break; |
|
345 case KErrDisconnected: |
|
346 test.Printf(_L(" KErrDisconnected")); |
|
347 break; |
|
348 case KErrAccessDenied: |
|
349 test.Printf(_L("KErrAccessDenied")); |
|
350 break; |
|
351 case KErrNotSupported: |
|
352 test.Printf(_L("Function Not Supported, Error = %d\n"), aReason); |
|
353 break; |
|
354 default: |
|
355 test.Printf(_L("Error !!!= %d\n"), aReason ); |
|
356 break; |
|
357 } |
|
358 } |
|
359 |
|
360 LOCAL_C void doMainL() |
|
361 { |
|
362 |
|
363 //create a scheduler |
|
364 exampleScheduler = new (ELeave) CExampleScheduler; |
|
365 CleanupStack::PushL( exampleScheduler ); |
|
366 CActiveScheduler::Install( exampleScheduler ); |
|
367 |
|
368 CTestEnp* testParser = CTestEnp::NewL(); |
|
369 CleanupStack::PushL(testParser); |
|
370 |
|
371 test(testParser != NULL); |
|
372 |
|
373 testParser->Start(CTestEnp::EParse); |
|
374 CActiveScheduler::Start(); |
|
375 |
|
376 CleanupStack::PopAndDestroy(2); // testParser, exampleScheduler, sEntry ,theServer |
|
377 } |
|
378 // end doMainL() |
|
379 |
|
380 CTestEnp::CTestEnp() |
|
381 :CActive(KTestEnpPriority) |
|
382 { |
|
383 } |
|
384 // end CTestEnp::CTestEnp() |
|
385 |
|
386 |
|
387 CTestEnp::~CTestEnp() |
|
388 { |
|
389 Cancel(); |
|
390 |
|
391 delete iParser; |
|
392 delete iMsvSelection; |
|
393 delete iBioTestUtils; |
|
394 delete iMsgBuffer; |
|
395 |
|
396 if(iTestParsedFieldArray) |
|
397 { |
|
398 iTestParsedFieldArray->ResetAndDestroy(); |
|
399 delete iTestParsedFieldArray; |
|
400 iTestParsedFieldArray=NULL; |
|
401 } |
|
402 } |
|
403 // end CTestEnp::~CTestEnp() |
|
404 |
|
405 |
|
406 GLDEF_C TInt E32Main() |
|
407 { |
|
408 test.Title(); |
|
409 test.Start(_L("ENP Test Harness")); |
|
410 __UHEAP_MARK; |
|
411 CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
412 test(cleanup!=NULL); |
|
413 TRAPD(error,doMainL()); |
|
414 if (error) test.Printf(_L("Completed with return code %d"),error); |
|
415 delete cleanup; |
|
416 __UHEAP_MARKEND; |
|
417 test.Close(); |
|
418 test.End(); |
|
419 return KErrNone; |
|
420 } |
|
421 // end E32Main() |