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