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