|
1 // Copyright (c) 2000-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 |
|
17 #include <e32test.h> |
|
18 #include <e32svr.h> // for RDebug::Print |
|
19 #include <e32std.h> |
|
20 #include <flogger.h> |
|
21 #include "t_wappush.h" |
|
22 #include "pushtests.h" |
|
23 #include <push/pushmessage.h> |
|
24 #include <ecom/ecom.h> |
|
25 |
|
26 // service setup includes... |
|
27 #include <msvstd.h> |
|
28 #include <msvids.h> |
|
29 #include "t_serviceutils.h" |
|
30 #include <pushentry.h> |
|
31 |
|
32 #include "cwappushfailmessagetest.h" |
|
33 |
|
34 _LIT(KPushMtmDatFile, "z:\\system\\mtm\\WapPushMtmU.dat"); |
|
35 _LIT(KWapPushTestTitle,"WAP Push tests"); |
|
36 _LIT(KPushLogDir, "push"); |
|
37 _LIT(KPushLogFile, "WapPushLogging.txt"); |
|
38 _LIT(KSpace, " "); |
|
39 _LIT(KStartTest,"Test Results"); |
|
40 _LIT(KFinishedTest,"Tests Completed"); |
|
41 _LIT(KTestDirectory,"C:\\Logs\\push\\"); |
|
42 _LIT(KTest,"> TEST "); |
|
43 _LIT(KPassed," PASSED\n"); |
|
44 _LIT(KFailed," Failed\n RTEST: FAIL :"); // RTEST: FAIL : required for the DABS RTest result parser to work |
|
45 _LIT (KOOMTestStep, "OOM Test step at %d\n" ); |
|
46 |
|
47 LOCAL_D RTest test( KWapPushTestTitle ); |
|
48 |
|
49 // Test harness requirements |
|
50 // |
|
51 // Uses an active object state machine to run tests. |
|
52 // Creates a Connection Manager object. |
|
53 // Creates a Dummy wap stack via CDummyWapStack::NewL() |
|
54 // Feeds a push message to Dummy wap stack |
|
55 // Starts Connection Manager - just add active object to scheduler and start? |
|
56 // Needs to know when completed - and callback? |
|
57 // Verifies that CPushMessage received is the same as sent |
|
58 // Closes/Destroys connection manager - delete? |
|
59 // |
|
60 |
|
61 // Note : |
|
62 // -To run the test harness on hardware, build the ROM image using |
|
63 // TWappush.iby file in \Wap-Browser\WapPush\rom\.. directory. |
|
64 // -Build the Wappush component and the TWappush test harness for DEBUG mode |
|
65 // -Create a folder c:\logs\push\.. to get the WappushLogging.txt logfile. |
|
66 // |
|
67 |
|
68 class CTestScheduler : public CActiveScheduler |
|
69 { |
|
70 virtual void Error(TInt anError) const; |
|
71 }; |
|
72 |
|
73 void CTestScheduler::Error(TInt anError) const |
|
74 { |
|
75 TBuf<80> buf; |
|
76 |
|
77 _LIT(KComment, "!! Error - %d\n-> Test Scheduler error handler called"); |
|
78 buf.Format(KComment, anError); |
|
79 |
|
80 // Write to log file |
|
81 RFileLogger::Write(KPushLogDir, KPushLogFile, EFileLoggingModeAppend, buf); |
|
82 |
|
83 _LIT(KTestPanic,"CTestScheduler RunL leave"); |
|
84 User::Panic(KTestPanic,anError); |
|
85 } |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 // cwappushtestengine |
|
91 |
|
92 void CWapPushTestEngine::DoCancel() |
|
93 { |
|
94 // cancel the current test |
|
95 if (iCurrentTest) |
|
96 iCurrentTest->Cancel(); |
|
97 } |
|
98 |
|
99 void CWapPushTestEngine::RunL() |
|
100 { |
|
101 switch (iState) |
|
102 { |
|
103 case EIdle: |
|
104 { |
|
105 if(iTest!=EFinished) |
|
106 { |
|
107 test.Start(_L("Starting Unit Test")); |
|
108 } |
|
109 TRAPD(err,RunNextTestL()) |
|
110 if(iTest!=EFinished) |
|
111 { |
|
112 test.End(); |
|
113 test.Close(); |
|
114 } |
|
115 if (err!=KErrNone) |
|
116 iConsole->Printf(KTextFailedTest); |
|
117 } |
|
118 break; |
|
119 case ERunningTest: |
|
120 break; |
|
121 case EShuttingDown: |
|
122 // Clear Out the Plugin Cache |
|
123 // CPluginServerClient* psc = CPluginServerClient::NewL(); |
|
124 // psc->PluginFactory().ClearCache(); |
|
125 // delete psc; |
|
126 CActiveScheduler::Stop(); |
|
127 break; |
|
128 } |
|
129 } |
|
130 |
|
131 /** |
|
132 * Static factory function for a new test engine |
|
133 */ |
|
134 CWapPushTestEngine* CWapPushTestEngine::NewL() |
|
135 { |
|
136 CWapPushTestEngine* self = new(ELeave) CWapPushTestEngine(); |
|
137 CleanupStack::PushL(self); |
|
138 self->ConstructL(); |
|
139 CleanupStack::Pop(self); |
|
140 return self; |
|
141 } |
|
142 |
|
143 /** |
|
144 * Constructor for the test engine |
|
145 * Creates a console and sets itself active |
|
146 */ |
|
147 void CWapPushTestEngine::ConstructL() |
|
148 { |
|
149 // Write to log file |
|
150 RFileLogger::Write(KPushLogDir, KPushLogFile, EFileLoggingModeAppend, KStartTest); |
|
151 RFileLogger::Write(KPushLogDir, KPushLogFile, EFileLoggingModeAppend, KSpace); |
|
152 |
|
153 iConsole = Console::NewL(KWapPushTestTitle,TSize(KConsFullScreen,KConsFullScreen)); |
|
154 // set up service BEFORE active scheduler... |
|
155 InitialiseMsgServiceL(); |
|
156 // |
|
157 CActiveScheduler::Add(this); |
|
158 SetActive(); |
|
159 TRequestStatus* stat = &iStatus; |
|
160 User::RequestComplete(stat,KErrNone); |
|
161 } |
|
162 |
|
163 /** |
|
164 * Destructor for CWapPushTestEngine |
|
165 * Cancels any outstanding requests and deletes member variables |
|
166 */ |
|
167 CWapPushTestEngine::~CWapPushTestEngine() |
|
168 { |
|
169 Cancel(); |
|
170 delete iCurrentTest; |
|
171 delete iConsole; |
|
172 } |
|
173 |
|
174 /** |
|
175 * This should be called by tests to indicate that they have |
|
176 * completed and whether they were sucessful or not |
|
177 */ |
|
178 void CWapPushTestEngine::TestCompleted(TInt aResult) |
|
179 { |
|
180 if (aResult==KErrNone) |
|
181 { |
|
182 TBuf16<124> log; |
|
183 log = iCurrentTest->TestName(); |
|
184 log.Append(KTest); |
|
185 log.Append(iCurrentTest->TestName()); |
|
186 log.Append(KPassed); |
|
187 test.Printf(log); |
|
188 iState=EIdle; |
|
189 iTest=(TTest)(iTest+1); |
|
190 } |
|
191 else |
|
192 { |
|
193 TBuf16<124> log1; |
|
194 log1 = iCurrentTest->TestName(); |
|
195 log1.Append(KTest); |
|
196 log1.Append(iCurrentTest->TestName()); |
|
197 log1.Append(KFailed); |
|
198 test.Printf(log1); |
|
199 test.Printf(KTextFailedTest); |
|
200 iConsole->Printf(KTextFailedTest); |
|
201 iState = EShuttingDown; |
|
202 } |
|
203 // set active again |
|
204 TRequestStatus* stat = &iStatus; |
|
205 User::RequestComplete(stat,KErrNone); |
|
206 SetActive(); |
|
207 } |
|
208 |
|
209 /** |
|
210 * Run the next test |
|
211 * The switch statement lists all tests to be run |
|
212 * |
|
213 */ |
|
214 void CWapPushTestEngine::RunNextTestL() |
|
215 { |
|
216 // delete any old tests |
|
217 delete iCurrentTest; |
|
218 iCurrentTest=NULL; |
|
219 // |
|
220 |
|
221 switch (iTest) |
|
222 { |
|
223 case EFailMessageTest: |
|
224 test.Next( _L("Test - Failing Messages (were causing panics) started")); |
|
225 iCurrentTest = new (ELeave)CWapPushFailMessageTest(); |
|
226 break; |
|
227 case ESIAMessage: |
|
228 test.Next( _L("Test - Service Intiation Application started")); |
|
229 iCurrentTest = new (ELeave) CWapPushSIAMessageTest(); |
|
230 break; |
|
231 case EUnknownMessage: |
|
232 test.Next( _L("Test - Unknown Handler Test started")); |
|
233 iCurrentTest = new (ELeave) CWapPushUnkMessageTest(); |
|
234 break; |
|
235 case ESLMessage: |
|
236 test.Next( _L("Test - Service Loading started")); |
|
237 iCurrentTest = new (ELeave) CWapPushSLMessageTest(); |
|
238 break; |
|
239 case ESLCMessage: |
|
240 test.Next (_L("Test - Service Loading Content started") ); |
|
241 iCurrentTest = new ( ELeave )CWapPushSLCMessageTest(); |
|
242 break; |
|
243 case ESIMessage: |
|
244 test.Next( _L("Test - Service Indication started")); |
|
245 iCurrentTest = new (ELeave) CWapPushSIMessageTest(); |
|
246 break; |
|
247 case ESICMessage: |
|
248 test.Next( _L("Test - Service Indication Content started")); |
|
249 iCurrentTest = new (ELeave) CWapPushSICMessageTest(); |
|
250 break; |
|
251 case EMultipartMixed: |
|
252 test.Next( _L("Test - Multi-part Mixed Message Test started")); |
|
253 iCurrentTest = new (ELeave) CWapPushMMMessageTest(); |
|
254 break; |
|
255 case EMultipartRelated: |
|
256 test.Next( _L("Test - Multi-part Related Message Test started")); |
|
257 iCurrentTest = new (ELeave) CWapPushMRMessageTest(); |
|
258 break; |
|
259 case EMultipartAlternative: |
|
260 test.Next( _L("Test - Multi-part Alternative Message Test started")); |
|
261 iCurrentTest = new (ELeave) CWapPushMAMessageTest(); |
|
262 break; |
|
263 case EReleaseThree: |
|
264 test.Next( _L("Test - Release Three started")); |
|
265 iCurrentTest = new (ELeave) CWapPushR3Test(); |
|
266 break; |
|
267 case ECorruptMsgs: |
|
268 test.Next( _L("Test - Corrupt Message Test started")); |
|
269 iCurrentTest = new (ELeave) CWapPushCorruptMessageTest(); |
|
270 break; |
|
271 case EClientMtmFind: |
|
272 test.Next( _L("Test - WapPushClientMtm Find Test started")); |
|
273 iCurrentTest = new (ELeave) CWapClientMtmFindTest(); |
|
274 break; |
|
275 case EINC081489: |
|
276 test.Next( _L("Duplicate SI messages [CINC081489]")); |
|
277 iCurrentTest = new (ELeave) CINC081489(); |
|
278 break; |
|
279 case EInvalidDTDMessage: |
|
280 test.Next ( _L("Invalid WAP DTD Message Test") ); |
|
281 iCurrentTest = new ( ELeave) CInvalidWAPDTDMessages(); |
|
282 break; |
|
283 case EDRMMessage: |
|
284 test.Next( _L("Test - DRM started")); |
|
285 iCurrentTest = new (ELeave) CWapPushDRMMessageTest(); |
|
286 break; |
|
287 case EReleaseTwo: |
|
288 default: |
|
289 // We've finished - set status to shut down and complete our own request |
|
290 SetPriority(EPriorityIdle); |
|
291 |
|
292 // Write to log file |
|
293 RFileLogger::Write(KPushLogDir, KPushLogFile, EFileLoggingModeAppend, KSpace); |
|
294 RFileLogger::Write(KPushLogDir, KPushLogFile, EFileLoggingModeAppend, KFinishedTest); |
|
295 |
|
296 iConsole->Printf(KTextFinishedTest); |
|
297 iState = EShuttingDown; |
|
298 TRequestStatus* stat = &iStatus; |
|
299 User::RequestComplete(stat,KErrNone); |
|
300 SetActive(); |
|
301 return; |
|
302 } |
|
303 |
|
304 iCurrentTest->SetEngine(this); |
|
305 iState = ERunningTest; |
|
306 iCurrentTest->BeginTest(); |
|
307 } |
|
308 |
|
309 /** |
|
310 * print a descriptor to the console - prefixes aString text with aName |
|
311 * @param aName the name of the test |
|
312 * @param aString the text to be displays |
|
313 */ |
|
314 void CWapPushTestEngine::Printf(const TDesC& aName, const TDesC& aString) |
|
315 { |
|
316 TBuf<12> format; |
|
317 format.Zero(); |
|
318 format.AppendNum((TInt)iTest); |
|
319 _LIT(KTextCoreFormat,".%S: %S\n"); |
|
320 format.Append(KTextCoreFormat); |
|
321 iConsole->Printf(format,&aName,&aString); |
|
322 } |
|
323 |
|
324 /** |
|
325 * get a character from the console |
|
326 */ |
|
327 TKeyCode CWapPushTestEngine::Getch() |
|
328 { |
|
329 return iConsole->Getch(); |
|
330 } |
|
331 |
|
332 /** |
|
333 * return a reference to the console used by the test harness |
|
334 */ |
|
335 CConsoleBase& CWapPushTestEngine::Console() const |
|
336 { |
|
337 return *iConsole; |
|
338 } |
|
339 |
|
340 /** connect to the push message service |
|
341 |
|
342 if no message service set up then create one else |
|
343 use existing service and remove any existing messages |
|
344 */ |
|
345 void CWapPushTestEngine::InitialiseMsgServiceL() |
|
346 { |
|
347 CMsvEntrySelection* idArray = new (ELeave) CMsvEntrySelection(); |
|
348 CleanupStack::PushL(idArray); |
|
349 |
|
350 CWapPushTestMsgUtils* msgUtils = CWapPushTestMsgUtils::NewL(); |
|
351 CleanupStack::PushL(msgUtils); |
|
352 TMsvId pushService = KMsvNullIndexEntryId; |
|
353 TMsvId pushFolder = KMsvNullIndexEntryId; |
|
354 |
|
355 // uncomment this if you want to remove existing service entries |
|
356 //msgUtils->ClearExistingServiceEntriesL(KUidMtmWapPush); |
|
357 |
|
358 msgUtils->PushServiceIdL(pushService, idArray); |
|
359 if ((pushService == KMsvNullIndexEntryId) && (idArray->Count() ==0) ) // Found no service |
|
360 { |
|
361 pushService = msgUtils->CreateServiceL(); |
|
362 } |
|
363 // install mtm - leaves if found to already exist |
|
364 TRAP_IGNORE(msgUtils->InstallMtmGroupL(KPushMtmDatFile)); |
|
365 |
|
366 |
|
367 idArray->Reset(); |
|
368 msgUtils->PushFolderIdL(pushFolder, idArray); |
|
369 |
|
370 if ((pushFolder == KMsvNullIndexEntryId) && (idArray->Count() ==0) ) // Found no service |
|
371 pushFolder = msgUtils->CreatePushMsgFolderL(); |
|
372 |
|
373 |
|
374 //Clean out all previous push entries from under the Push Service Entry |
|
375 msgUtils->RemoveServiceEntryChildrenL(pushService); |
|
376 |
|
377 // Clean the push msg folder of existing entries |
|
378 msgUtils->RemoveEntriesFromLocalServiceFolderL(pushFolder, KUidMtmWapPush); |
|
379 // Clean the inbox of all existing Wap Push entries.... |
|
380 msgUtils->RemoveEntriesFromLocalServiceFolderL(KMsvGlobalInBoxIndexEntryId, KUidMtmWapPush); |
|
381 |
|
382 CleanupStack::PopAndDestroy(2); //idarray, msgUtils |
|
383 } |
|
384 |
|
385 |
|
386 |
|
387 /** Add the test to the active scheduler and set it active |
|
388 * by completing its own request |
|
389 */ |
|
390 void CWapPushTest::BeginTest() |
|
391 { |
|
392 CActiveScheduler::Add(this); |
|
393 SetActive(); |
|
394 TRequestStatus* stat = &iStatus; |
|
395 User::RequestComplete(stat,KErrNone); |
|
396 } |
|
397 |
|
398 |
|
399 /** |
|
400 * Print a descriptor to the console |
|
401 * @param aString descriptor to print |
|
402 */ |
|
403 void CWapPushTest::Printf(const TDesC& aString) |
|
404 { |
|
405 iEngine->Printf(TestName(),aString); |
|
406 } |
|
407 |
|
408 /** |
|
409 * Check a test result and panic if false |
|
410 * @param aTestResult the result to check |
|
411 * @param aLine the line number - can be provided by MSVC macro __LINE__ |
|
412 * #define TEST(A) Test(A,__LINE__) |
|
413 * TEST(err=KErrNone) |
|
414 */ |
|
415 void CWapPushTest::Test(TInt aTestResult,TInt aLine) |
|
416 { |
|
417 if (!aTestResult) |
|
418 { |
|
419 User::Panic(TestName(),aLine); |
|
420 } |
|
421 } |
|
422 |
|
423 /** |
|
424 * Printf |
|
425 * |
|
426 * @param aDescription The text to print/log |
|
427 */ |
|
428 void CWapPushTest::WPLPrintf(const TDesC& aDescription) |
|
429 { |
|
430 const TInt KWatcherLogBuffer = 256; |
|
431 // Write to log file |
|
432 RFileLogger::Write(KPushLogDir, KPushLogFile, EFileLoggingModeAppend, aDescription); |
|
433 |
|
434 // Write to console |
|
435 _LIT(KPushLogFmt,"Push:%S\n"); |
|
436 TPtrC buf = aDescription.Left(Min(KWatcherLogBuffer, aDescription.Length())); |
|
437 iEngine->Console().Printf(KPushLogFmt,&buf); |
|
438 } |
|
439 |
|
440 /** |
|
441 * Takes the data in a Push Message and prints it to console and the logs it to file. |
|
442 * Uses the accessor functions of the CPushMessage class and this classes Printf function |
|
443 * to perform this. Currently 4 headers and the message body are displayed and |
|
444 * logged. The headers are: |
|
445 * PushID, Content-Type, X-Application-ID, Expiry Date, |
|
446 * |
|
447 * @param CPushMessage& aMessage |
|
448 * in: a reference to a Push Message. |
|
449 */ |
|
450 void CWapPushTest::WPLPrintfL(CPushMessage& aMessage) |
|
451 { |
|
452 const TInt KWatcherLogBuffer=256; |
|
453 TBuf<KWatcherLogBuffer> buf; |
|
454 |
|
455 // Content type |
|
456 _LIT(KLogContentFmt,"Content Type : \t%S"); |
|
457 TPtrC contentPointer; |
|
458 aMessage.GetContentType(contentPointer); |
|
459 buf.Format(KLogContentFmt,&contentPointer); |
|
460 buf.Append('\n'); |
|
461 WPLPrintf(buf); |
|
462 |
|
463 // Date Field |
|
464 _LIT(KLogDateTimeFmt," %-B%:0%J%:1%T%:2%S%+B %D %N %Y %4 %5 %3"); |
|
465 _LIT(KLogDateFmt,"Date :\t%S"); |
|
466 TBool foundField; |
|
467 TTime timeValue; |
|
468 foundField = aMessage.GetHeaderField(EHttpDate, timeValue); |
|
469 if (foundField) |
|
470 { |
|
471 TRAPD(err, timeValue.FormatL(buf, KLogDateTimeFmt)); |
|
472 if (err == KErrNone) |
|
473 { |
|
474 TBuf<KWatcherLogBuffer> dateBuf; |
|
475 dateBuf.Format(KLogDateFmt, &buf); |
|
476 WPLPrintf(dateBuf); |
|
477 } |
|
478 } |
|
479 |
|
480 //Expires Field |
|
481 aMessage.GetHeaderField(EHttpExpires, timeValue); |
|
482 if (foundField) |
|
483 { |
|
484 TRAPD(err, timeValue.FormatL(buf, KLogDateTimeFmt)); |
|
485 if (err == KErrNone) |
|
486 { |
|
487 TBuf<KWatcherLogBuffer> dateBuf; |
|
488 dateBuf.Format(KLogDateFmt, &buf); |
|
489 WPLPrintf(dateBuf); |
|
490 } |
|
491 } |
|
492 |
|
493 // X-Wap-Application-ID |
|
494 TBool isInt = EFalse; |
|
495 TInt ID = 0; |
|
496 TPtrC8 generalPtr; |
|
497 _LIT(KLogAppIdIntFmt,"App ID :\t%X"); |
|
498 TRAPD(err, foundField = aMessage.GetAppIdL(generalPtr, ID, isInt)); |
|
499 if ( err == KErrNone && foundField) // App ID is present |
|
500 { |
|
501 if (isInt) // Field in integer format |
|
502 { |
|
503 buf.Format(KLogAppIdIntFmt,ID); |
|
504 } |
|
505 else // should be descriptor format |
|
506 { |
|
507 buf.Copy(generalPtr); |
|
508 } |
|
509 WPLPrintf(buf); |
|
510 } |
|
511 |
|
512 // Content-Disposition |
|
513 TPtrC8 dispositionPtr; |
|
514 _LIT(KLogDisposition,"Content-Disposition:\t"); |
|
515 foundField = aMessage.GetHeaderField(EHttpContentDisposition, dispositionPtr); |
|
516 if (foundField) // App ID is present |
|
517 { |
|
518 // Convert 8 bit to 16 bit |
|
519 HBufC* tempAddr = HBufC::NewLC(dispositionPtr.Length()); |
|
520 tempAddr->Des().Copy(dispositionPtr); |
|
521 WPLPrintf(KLogDisposition); |
|
522 WPLPrintf(*tempAddr); |
|
523 CleanupStack::PopAndDestroy(tempAddr); |
|
524 } |
|
525 |
|
526 //Message Header Binary |
|
527 _LIT(KLogMsgHdr,"Header Binary:"); |
|
528 WPLPrintf(KLogMsgHdr); |
|
529 aMessage.GetHeader(generalPtr); |
|
530 |
|
531 HBufC* tempHdr = HBufC::NewLC(generalPtr.Length()); |
|
532 tempHdr->Des().Copy(generalPtr); |
|
533 WPLLogBinaryAsHex(*tempHdr); |
|
534 CleanupStack::PopAndDestroy(); //tempHdr |
|
535 |
|
536 //Message Body |
|
537 aMessage.GetMessageBody(generalPtr); |
|
538 |
|
539 // Dump Body As Text |
|
540 _LIT(KLogMsgBody,"Body Text:"); |
|
541 WPLPrintf(KLogMsgBody); |
|
542 HBufC* tempBody = HBufC::NewLC(generalPtr.Length()); |
|
543 tempBody->Des().Copy(generalPtr); |
|
544 WPLPrintf(*tempBody); |
|
545 |
|
546 // Dump Body As Hex |
|
547 _LIT(KBodyBinary,"\nBody Binary:"); |
|
548 WPLPrintf(KBodyBinary); |
|
549 WPLLogBinaryAsHex(*tempBody); |
|
550 |
|
551 CleanupStack::PopAndDestroy(); //tempBody |
|
552 } |
|
553 |
|
554 |
|
555 /** |
|
556 * Prints out Buffer data in the format: |
|
557 * %X %X %X %X %X %X %X\n etc |
|
558 * For example |
|
559 * AB CD 01 12 34 A2 |
|
560 * |
|
561 * @param aDescription |
|
562 * in: the descriptor to be dumped into the log |
|
563 */ |
|
564 void CWapPushTest::WPLLogBinaryAsHex(const TDesC& aDescription) |
|
565 { |
|
566 const TInt KWatcherLogBuffer=256; |
|
567 _LIT(KHexSpace,"%02X "); |
|
568 TBuf<KWatcherLogBuffer> hexBuf; |
|
569 TBuf<KWatcherLogBuffer> buf; |
|
570 |
|
571 TInt i = 0, bodyLen = aDescription.Length(); |
|
572 |
|
573 for (; i < bodyLen; i++) |
|
574 { |
|
575 hexBuf.Format(KHexSpace,aDescription[i]); |
|
576 buf.Append(hexBuf); |
|
577 if ( i && ((i+1) % 8) == 0 ) |
|
578 { |
|
579 WPLPrintf(buf); |
|
580 buf.Zero(); |
|
581 } |
|
582 } |
|
583 |
|
584 if (buf.Length()) |
|
585 WPLPrintf(buf); |
|
586 } |
|
587 |
|
588 void CWapPushTest::WPLLogError(const TDesC& aDescription,TInt aError) |
|
589 { |
|
590 _LIT(KErrorLogFmt,"%S, Error\t%d"); |
|
591 const TInt KWatcherLogBuffer=256; |
|
592 TBuf<KWatcherLogBuffer> buf; |
|
593 buf.Format(KErrorLogFmt,&aDescription,aError); |
|
594 buf.Append('\n'); |
|
595 WPLPrintf(buf); |
|
596 } |
|
597 |
|
598 CWapPushOOMTestEngine* CWapPushOOMTestEngine::NewL () |
|
599 { |
|
600 CWapPushOOMTestEngine* self = new (ELeave)CWapPushOOMTestEngine; |
|
601 CleanupStack::PushL ( self ); |
|
602 self->ConstructL (); |
|
603 CleanupStack::Pop (); |
|
604 return self; |
|
605 } |
|
606 |
|
607 CWapPushOOMTestEngine::~CWapPushOOMTestEngine () |
|
608 { |
|
609 // Do nothing. |
|
610 } |
|
611 |
|
612 void CWapPushOOMTestEngine::TestCompleted ( TInt aResult ) |
|
613 { |
|
614 SetError ( aResult ); |
|
615 if ( aResult == KErrNone ) |
|
616 { |
|
617 // The test passed. Increment the test number to next. |
|
618 iTest=(TTest)(iTest+1); |
|
619 iState = EIdle; |
|
620 } |
|
621 else |
|
622 { |
|
623 // Something went wrong shutdown the engine |
|
624 iState = EShuttingDown; |
|
625 } |
|
626 // set active again |
|
627 TRequestStatus* stat = &iStatus; |
|
628 User::RequestComplete(stat,KErrNone); |
|
629 SetActive(); |
|
630 } |
|
631 |
|
632 void CWapPushOOMTestEngine::DoCancel () |
|
633 { |
|
634 CWapPushTestEngine::DoCancel (); |
|
635 } |
|
636 |
|
637 CWapPushTestEngine::TTest CWapPushOOMTestEngine::NextTest () const |
|
638 { |
|
639 return iTest; |
|
640 } |
|
641 |
|
642 void CWapPushOOMTestEngine::SetNextTest ( TInt aTest ) |
|
643 { |
|
644 iTest = (TTest)aTest; |
|
645 } |
|
646 |
|
647 void CWapPushOOMTestEngine::RunL () |
|
648 { |
|
649 switch (iState) |
|
650 { |
|
651 case CWapPushTestEngine::EIdle: |
|
652 { |
|
653 //Skip oom test for ESIMessage. it goes in loop |
|
654 if(iTest==ESIAMessage || iTest==ESICMessage || iTest==EDRMMessage) |
|
655 { |
|
656 iTest=(TTest)(iTest+1); |
|
657 } |
|
658 TRAPD( err,RunNextTestL() ); |
|
659 if ( err != KErrNone ) |
|
660 TestCompleted ( err ); |
|
661 } |
|
662 break; |
|
663 case CWapPushTestEngine::ERunningTest: |
|
664 break; |
|
665 case CWapPushTestEngine::EShuttingDown: |
|
666 // We are stopping. Stop the active scheduler and exit. |
|
667 CActiveScheduler::Stop(); |
|
668 break; |
|
669 } |
|
670 } |
|
671 |
|
672 TInt CWapPushOOMTestEngine::Error () const |
|
673 { |
|
674 return iError; |
|
675 } |
|
676 |
|
677 void CWapPushOOMTestEngine::SetError ( TInt aErr ) |
|
678 { |
|
679 iError = aErr; |
|
680 } |
|
681 |
|
682 LOCAL_C void StartOomTestL ( TInt& aNextTest ) |
|
683 { |
|
684 CWapPushOOMTestEngine* oomEngine = NULL; |
|
685 oomEngine = CWapPushOOMTestEngine::NewL(); |
|
686 CleanupStack::PushL ( oomEngine ); |
|
687 oomEngine->SetNextTest ( aNextTest ); |
|
688 // All the action happens within the main event loop |
|
689 CActiveScheduler::Start(); |
|
690 aNextTest = (TInt)oomEngine->NextTest (); |
|
691 User::LeaveIfError ( oomEngine->Error () ); |
|
692 CleanupStack::PopAndDestroy (); |
|
693 } |
|
694 |
|
695 // main loop |
|
696 // |
|
697 GLDEF_C TInt E32Main() |
|
698 { |
|
699 __UHEAP_MARK; |
|
700 |
|
701 // Install exception handler |
|
702 CTrapCleanup* theCleanup = CTrapCleanup::New(); |
|
703 |
|
704 test.Printf(_L("@SYMTestCaseID IWS-WAPBROWSER-WAPPUSH-TPUSH-T_WAPPUSH-0001 ")); |
|
705 |
|
706 // Create test directory |
|
707 TRAPD( |
|
708 error, |
|
709 RFs fs; |
|
710 User::LeaveIfError(fs.Connect()); |
|
711 CleanupClosePushL(fs); |
|
712 |
|
713 fs.MkDirAll(KTestDirectory); |
|
714 CleanupStack::PopAndDestroy(&fs); |
|
715 ); |
|
716 if (error != KErrNone) |
|
717 User::Panic(_L("Failed to create test directory"), error); |
|
718 |
|
719 CTestScheduler* as = new CTestScheduler; |
|
720 if (!as) |
|
721 User::Panic(_L("Failed to create active scheduler"),KErrNoMemory); |
|
722 CActiveScheduler::Install(as); // Install active scheduler |
|
723 |
|
724 CWapPushTestEngine* engine=NULL; |
|
725 TRAPD(err,engine = CWapPushTestEngine::NewL()); |
|
726 if (err != KErrNone) |
|
727 User::Panic(_L("Failed to create test engine object"),err); |
|
728 |
|
729 // All the action happens within the main event loop |
|
730 CActiveScheduler::Start(); |
|
731 // Returned from start so shutdown |
|
732 |
|
733 delete engine; |
|
734 |
|
735 // Run OOM test cases. |
|
736 TInt nextTest = 1; |
|
737 TInt failAt = 0; |
|
738 err = KErrNoMemory; |
|
739 test.Start(_L("Starting OOM Test")); |
|
740 while ( err != KErrNone ) |
|
741 { |
|
742 failAt++; |
|
743 test.Printf ( KOOMTestStep, failAt ); |
|
744 __UHEAP_SETFAIL( RHeap::EDeterministic, failAt ); |
|
745 __UHEAP_MARK; |
|
746 TRAP ( err, StartOomTestL ( nextTest ) ); |
|
747 REComSession::FinalClose(); |
|
748 __UHEAP_MARKEND; |
|
749 __UHEAP_RESET; |
|
750 } |
|
751 delete as; |
|
752 delete theCleanup; |
|
753 test.End(); |
|
754 test.Close(); |
|
755 __UHEAP_MARKEND; |
|
756 |
|
757 User::Heap().Check(); |
|
758 return(KErrNone); |
|
759 } |
|
760 |
|
761 |
|
762 |