messagingfw/biomsgfw/IACPTSRC/T_iacp.cpp
changeset 0 8e480a14352b
child 58 6c34d0baa0b1
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     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 Internet Access Configuration Parser
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "biotestutils.h"
       
    19 //
       
    20 #include "IACPERR.H"
       
    21 #include "IACPDEF.H"
       
    22 #include "tmsvbioinfo.h"
       
    23 
       
    24 //
       
    25 //SMS configuration files path
       
    26 _LIT(IACP_TEST_MSG_PATH,	"c:\\test\\bio\\iacp\\");
       
    27 
       
    28 //forward reference
       
    29 class CExampleScheduler;
       
    30 
       
    31 //global declarations
       
    32 LOCAL_D CExampleScheduler *exampleScheduler;
       
    33 LOCAL_D RTest test(_L("IACP Test Harness"));
       
    34 
       
    35 
       
    36 //
       
    37 //-- CExampleScheduler --
       
    38 //
       
    39 class CExampleScheduler : public CActiveScheduler 
       
    40 	{
       
    41 	public:
       
    42 	void Error (TInt aError) const;
       
    43 	};
       
    44 
       
    45 void CExampleScheduler::Error(TInt anError) const
       
    46 	{
       
    47 	CActiveScheduler::Stop();
       
    48 	test.Printf(_L("\nLeave signalled, reason=%d\n"),anError);
       
    49 	}
       
    50 
       
    51 LOCAL_C void DisplayErrorReason(TInt& aReason,CBioTestUtils* aBioTestUtils)
       
    52 	{
       
    53 	if(aReason==KErrNone)
       
    54 		{
       
    55 		aBioTestUtils->TestHarnessCompleted();
       
    56 		return;
       
    57 		}
       
    58 
       
    59 	TBuf<256> tempBuf;
       
    60 	switch (aReason)
       
    61 		{
       
    62 		case KErrCancel:
       
    63 			tempBuf= _L("\r\n-->Session cancelled");
       
    64 			break;
       
    65 		case KErrEof:
       
    66 			tempBuf= _L("\r\n-->KErrEof");
       
    67 			break;
       
    68 		case KErrNoMemory:
       
    69 			tempBuf= _L("\r\n-->KErrNoMemory");
       
    70 			break;
       
    71 		case KErrDisconnected:
       
    72 			tempBuf= _L("\r\n-->KErrDisconnected");
       
    73 			break;
       
    74 		case KErrAccessDenied:
       
    75 			tempBuf= _L("\r\n-->KErrAccessDenied");
       
    76 			break;
       
    77 		case KBspInvalidMessage:
       
    78 			tempBuf= _L("\r\n-->Error: Invalid SMS Message. For Internet Access Configuration,\r\nSMS Header Field should be //SIAP11 ");
       
    79 			break;
       
    80 		case KIacpUnknownSmsType:
       
    81 			tempBuf=_L("\r\n-->Error:SMS 1st Left Token does not start with niether M  nor I ");
       
    82 			break;
       
    83 		case KIacpBIOMsgTypeNotSupported:
       
    84 			tempBuf= _L("\r\n-->this Bio msg is not suppported");
       
    85 			break;
       
    86 		case KIacpMandatoryDataNotSet:
       
    87 			tempBuf= _L("\r\n-->Error: Mandatory data missing in SMS message.");
       
    88 			break;
       
    89 		case KIacpUnknownMailProtocol:
       
    90 			tempBuf= _L("\r\n-->Error: Unknown Mail Protocol Not a Pop3/Imap4");
       
    91 			break;
       
    92 		case KIacpErrRightToken:
       
    93 			tempBuf= _L("\r\n-->Error: improper right token  i.e not equal t/f (True/False)");
       
    94 			break;
       
    95 		case KIacpErrLeftToken:
       
    96 			tempBuf=_L("\r\n-->Error:SMS Left Tokens should start with 'M' for Mailbox account configuration\r\n and with 'I' for Internet service configuration");
       
    97 			break;
       
    98 		case KIacpErrSmsDataNotParsed:
       
    99 			tempBuf= _L("\r\n-->sms data should be parsed before processing");
       
   100 			break;
       
   101 		case KIacpErrSmsDataNotRestored:
       
   102 			tempBuf= _L("\r\n-->Error: sms data should be parsed before commiting (KIacpErrSmsDataNotRestored)");
       
   103 			break;
       
   104 		case KIacpScriptErrISPNotFound:
       
   105 			tempBuf= _L("\r\n-->Internet Service not found in Dial Out DB");
       
   106 			break;
       
   107 		case KIacpErrScriptNotDefined: 
       
   108 			tempBuf= _L("\r\n-->Sript not included in sms");
       
   109 			break;
       
   110 		case KIacpErrScriptNotFoundInDB:
       
   111 			tempBuf= _L("\r\n-->There is no script in DB to append to.");
       
   112 			break;
       
   113 		case KIacpErrScriptAlreadyAdd:
       
   114 			tempBuf= _L("\r\n-->Script cannot be add more than ounce for each Bio Msg");
       
   115 			break;
       
   116 		default:
       
   117 			tempBuf.Format(_L("\r\n-->Error !!!= %dview"), aReason );
       
   118 			break;
       
   119 		}
       
   120 
       
   121 	aBioTestUtils->Printf(tempBuf);			  
       
   122 	aBioTestUtils->TestHarnessFailed(aReason);
       
   123 	}
       
   124 
       
   125 //--------------------------------------
       
   126 //
       
   127 //-- CTestIacp --
       
   128 //
       
   129 
       
   130 enum TSessionState
       
   131 	{
       
   132 	EParse,  // parsing is done at ParseL() stage. and data are externalised.
       
   133 	EProcess, //parsed data are internalised, then commited
       
   134 	EReparse,
       
   135 	EReProcess,
       
   136 	EDisplay,  //Display entry data
       
   137 	};
       
   138 
       
   139 class CTestIacp : public CActive 
       
   140 	{
       
   141 	public:
       
   142 		~CTestIacp();
       
   143 		static  CTestIacp * NewL(CBioTestUtils* aBioTestUtils);
       
   144 		void StartL(TInt aCmd);
       
   145 
       
   146 	public:
       
   147 		CTestIacp(CBioTestUtils* aBioTestUtils);
       
   148 		void ConstructL();
       
   149 
       
   150 		void CreateParserL(); //sets 'iParser' to point to the created iacp parser
       
   151 		void GetMessageBodyL();
       
   152 		
       
   153 		void ParseMsgWithHeapTest();
       
   154 		void ProcessMsgWithHeapTest();
       
   155 
       
   156 		void DisplayEntryDataL();
       
   157 		void DisplayFinalSummary();
       
   158 
       
   159 		void RequestComplete(TRequestStatus& aStatus,TInt aCompletion);
       
   160 		void DoCancel();
       
   161 		void RunL();
       
   162 
       
   163 	private:
       
   164 		TInt iState;
       
   165 		CBioTestUtils*		iBioTestUtils;
       
   166 		CBaseScriptParser2*	iParser;
       
   167 
       
   168 		HBufC* iSmsMsg;			//sms body build dependent		
       
   169 		TMsvId						iEntryId;       //ID of sms entry
       
   170 		CMsvEntrySelection*			iIacpSelection;
       
   171 		TInt						iIacpMsgCtr;
       
   172 		TInt						iFailedToProcess;
       
   173 
       
   174 		TInt			iParseFailCount;//heap testing (Parsing state)
       
   175 		TInt			iProcessFailCount;//heap testing (processing state)
       
   176 	};
       
   177 
       
   178 
       
   179 //
       
   180 CTestIacp::CTestIacp(CBioTestUtils* aBioTestUtils)
       
   181 :CActive(EPriorityStandard),iBioTestUtils(aBioTestUtils)
       
   182 	{
       
   183 	}
       
   184 
       
   185 CTestIacp* CTestIacp::NewL(CBioTestUtils* aBioTestUtils)
       
   186 	{
       
   187 	CTestIacp* self = new(ELeave) CTestIacp(aBioTestUtils);
       
   188 	CleanupStack::PushL(self);
       
   189 	self->ConstructL();
       
   190 	CleanupStack::Pop();  //self 
       
   191 	return self;
       
   192 	}
       
   193 
       
   194 void CTestIacp::ConstructL()
       
   195 	{
       
   196 	iBioTestUtils->WriteComment(_L("CTestIacp::ConstructL()."));
       
   197 	CreateParserL();
       
   198 
       
   199 	iIacpSelection=	iBioTestUtils->GenerateMessagesL(IACP_TEST_MSG_PATH);
       
   200 	CActiveScheduler::Add(this);
       
   201 	}
       
   202 
       
   203 CTestIacp::~CTestIacp()
       
   204 	{
       
   205 	Cancel();
       
   206 
       
   207 	delete iIacpSelection;
       
   208 	delete iSmsMsg;
       
   209 	delete iParser;
       
   210 	}
       
   211 
       
   212 void CTestIacp::CreateParserL()
       
   213 	{
       
   214 	TInt error = KErrNone;
       
   215 	TBool finished = EFalse;
       
   216 
       
   217 #ifdef _DEBUG
       
   218 	TInt failCount = 0;
       
   219 #endif
       
   220 
       
   221 	while(!finished)
       
   222 		{
       
   223 		__UHEAP_FAILNEXT(failCount++);
       
   224 		TRAP(error,(iParser = iBioTestUtils->CreateParserTypeL(KUidBIOInternetAccessPointMsg)));
       
   225 		if (error == KErrNone)
       
   226 			{
       
   227 			__UHEAP_RESET;
       
   228 			iBioTestUtils->WriteComment(_L("Created IACP Parser object"));
       
   229 			finished = ETrue;
       
   230 			__UHEAP_RESET;
       
   231 			}
       
   232 		// Handle error
       
   233 		else
       
   234 			{
       
   235 			test(error == KErrNoMemory);
       
   236 			__UHEAP_RESET;
       
   237 			}
       
   238 		}
       
   239 
       
   240 	}
       
   241 
       
   242 void CTestIacp::GetMessageBodyL()
       
   243 	{
       
   244 	delete iSmsMsg;
       
   245 	iSmsMsg = NULL;
       
   246 	iSmsMsg= iBioTestUtils->MessageBodyL(iEntryId).AllocL();
       
   247 	}
       
   248 
       
   249 void CTestIacp::StartL(TInt aCmd)
       
   250 	{
       
   251 	iState=aCmd;
       
   252 	iEntryId = (*iIacpSelection)[iIacpMsgCtr];
       
   253 
       
   254 	switch (iState)
       
   255 		{
       
   256 		case EParse:
       
   257 			iBioTestUtils->Printf(_L("Parsing...\n"));
       
   258 			iBioTestUtils->SetEntryL(iEntryId); //clients have to set the right context before calling ParseL() 
       
   259 			GetMessageBodyL();
       
   260 			ParseMsgWithHeapTest();
       
   261 			break;
       
   262 
       
   263 		case EProcess:
       
   264 			iBioTestUtils->Printf(_L("Processing...\n"));
       
   265 			iBioTestUtils->SetEntryL(iEntryId); //clients have to set the right context before calling CommitL() 
       
   266 			ProcessMsgWithHeapTest();
       
   267 			break;
       
   268 
       
   269 		case EReparse:
       
   270 			{
       
   271 			delete iParser;
       
   272 			CreateParserL();
       
   273 			iBioTestUtils->Printf(_L("Re-parsing...\n"));
       
   274 			iBioTestUtils->SetEntryL(iEntryId); //clients have to set the right context before calling CommitL() 
       
   275 			iParser->ParseL(iStatus,iSmsMsg->Des());
       
   276 			SetActive();
       
   277 			//ParseMsgWithHeapTest();
       
   278 			}
       
   279 			break;
       
   280 
       
   281 		case EReProcess:
       
   282 			{
       
   283 			delete iParser;
       
   284 			CreateParserL();
       
   285 			iBioTestUtils->Printf(_L("Re-Processing...\n"));
       
   286 			iBioTestUtils->SetEntryL(iEntryId); //clients have to set the right context before calling CommitL() 
       
   287          	iParser->ProcessL(iStatus); //internalise and commit
       
   288  			SetActive();
       
   289 			//ProcessMsgWithHeapTest();
       
   290 			}
       
   291 			break;
       
   292 
       
   293 		case EDisplay:
       
   294             DisplayEntryDataL();
       
   295 			RequestComplete(iStatus,KErrNone);
       
   296             SetActive();
       
   297 			break;
       
   298 
       
   299 		default:
       
   300 			break;
       
   301 		}
       
   302 	}
       
   303 
       
   304 void CTestIacp::ParseMsgWithHeapTest()
       
   305 	{
       
   306 	TInt error = KErrNone;
       
   307 	TBool finished = EFalse;
       
   308 	
       
   309 	while(!finished)
       
   310 		{
       
   311 	//	__UHEAP_FAILNEXT(iParseFailCount++);
       
   312 		// 
       
   313 		TRAP(error, iParser->ParseL(iStatus,iSmsMsg->Des())); 
       
   314 		if (error == KErrNone)
       
   315 			{
       
   316 	//		__UHEAP_RESET;
       
   317 			finished = ETrue;
       
   318 			SetActive();
       
   319 			}
       
   320 		else
       
   321 			{
       
   322 			test(error == KErrNoMemory);
       
   323 	//		__UHEAP_RESET;
       
   324 			}		
       
   325 		}
       
   326 			
       
   327 	}
       
   328 
       
   329 void CTestIacp::ProcessMsgWithHeapTest()
       
   330 	{
       
   331 	TInt error = KErrNone;
       
   332 	TBool finished = EFalse;
       
   333 	while(!finished)
       
   334 		{
       
   335 	//	__UHEAP_FAILNEXT(iProcessFailCount++);
       
   336 		// 
       
   337 		TRAP(error, iParser->ProcessL(iStatus)); //internalise and process
       
   338 		if (error == KErrNone)
       
   339 			{
       
   340 	//		__UHEAP_RESET;
       
   341 			finished = ETrue;
       
   342 			SetActive();
       
   343 			}
       
   344 		else
       
   345 			{
       
   346 			test(error == KErrNoMemory);
       
   347 	//		__UHEAP_RESET;
       
   348 			}		
       
   349 		}
       
   350 	}
       
   351 
       
   352 void CTestIacp::DoCancel()
       
   353 	{
       
   354 	iBioTestUtils->WriteComment(_L("DoCancel()"));
       
   355 	}
       
   356 
       
   357 void CTestIacp::RequestComplete(TRequestStatus& aStatus,TInt aCompletion)
       
   358 	{
       
   359 	TRequestStatus* statusPtr=&aStatus;
       
   360 	User::RequestComplete(statusPtr,aCompletion);
       
   361 	}
       
   362 
       
   363 void CTestIacp::RunL()
       
   364 	{
       
   365 	TInt result=iStatus.Int();
       
   366 
       
   367 	//heap test faillure
       
   368 	if( result == KErrNoMemory)
       
   369 		{
       
   370 		if(iState==EParse)
       
   371 			{
       
   372 			iParseFailCount++;
       
   373 			StartL(EParse);
       
   374 			return;
       
   375 			}
       
   376 		else if(iState==EProcess)
       
   377 			{
       
   378 			iProcessFailCount++;
       
   379 			StartL(EProcess);
       
   380 			return;
       
   381 			}
       
   382 		else if(iState==EReparse)
       
   383 			{
       
   384 			iParseFailCount++;
       
   385 			StartL(EReparse);
       
   386 			}
       
   387 		else if(iState==EReProcess)
       
   388 			{
       
   389 			iProcessFailCount++;
       
   390 			StartL(EReProcess);
       
   391 			}
       
   392 		}
       
   393 
       
   394 	if ( result== KIacpErrSmsDataNotParsed)
       
   395 		{
       
   396 		iBioTestUtils->ClearScreen();
       
   397 		iBioTestUtils->Printf(_L("Error: Processing before parsing SMS.\n"));
       
   398 		iBioTestUtils->Printf(_L("Press any key to continue parsing\n\n"));
       
   399 		}
       
   400 
       
   401 	switch (iState)
       
   402 		{
       
   403 		case EParse:
       
   404 			iParseFailCount=0;
       
   405 			iProcessFailCount=0;	
       
   406 			iBioTestUtils->WriteComment(_L("Parsed Ok."));
       
   407 			if(result==KErrNone)
       
   408 				StartL(EProcess);
       
   409 			else
       
   410 				{
       
   411 				iFailedToProcess++;
       
   412 				iIacpMsgCtr++;
       
   413 				if(iIacpMsgCtr < iIacpSelection->Count())
       
   414 					{
       
   415 					StartL(EParse);
       
   416 					}
       
   417 				else
       
   418 					{
       
   419 					DisplayFinalSummary();
       
   420 					DisplayErrorReason(result,iBioTestUtils);
       
   421 					iParser->Cancel();
       
   422 					CActiveScheduler::Stop();
       
   423 					}
       
   424 				}
       
   425 			break;
       
   426 
       
   427 		case EProcess:
       
   428 			iParseFailCount=0;
       
   429 			iBioTestUtils->WriteComment(_L("Processed Ok."));
       
   430 			StartL(EReparse);
       
   431 			break;
       
   432 
       
   433 		case EReparse:
       
   434 			iProcessFailCount=0;		
       
   435 			iBioTestUtils->WriteComment(_L("Re-Parsed Ok."));
       
   436 			StartL(EReProcess);
       
   437 			break;
       
   438 
       
   439 		case EReProcess:
       
   440 			iBioTestUtils->WriteComment(_L("Re-Processed Ok."));
       
   441 			StartL(EDisplay);
       
   442 			break;
       
   443 
       
   444 		case EDisplay:
       
   445 			iParseFailCount=0;
       
   446 			iProcessFailCount=0;
       
   447 			iBioTestUtils->TestFinish(iIacpMsgCtr);
       
   448 			iIacpMsgCtr++;
       
   449 			if(iIacpMsgCtr < iIacpSelection->Count())
       
   450 				{
       
   451 				iBioTestUtils->TestStart(iIacpMsgCtr);
       
   452 				StartL(EParse);
       
   453 				}
       
   454 			else
       
   455 				{
       
   456 				DisplayFinalSummary();
       
   457 				DisplayErrorReason(result,iBioTestUtils);
       
   458 				iParser->Cancel();
       
   459 				CActiveScheduler::Stop();
       
   460 				}
       
   461 			break;
       
   462 
       
   463 		default:
       
   464 			break;
       
   465 		}
       
   466 	}
       
   467 
       
   468 
       
   469 void CTestIacp::DisplayEntryDataL()
       
   470     {
       
   471     iBioTestUtils->SetEntryL(iEntryId);
       
   472 
       
   473     iBioTestUtils->ClearScreen();
       
   474     //test.Console()->SetPos(0,0);
       
   475 
       
   476     TMsvEntry entry = iBioTestUtils->Entry();
       
   477     iBioTestUtils->Printf(_L("===== MESSAGE DETAILS =====\n"));
       
   478 	iBioTestUtils->Printf(_L("Id:			  0x%x\n"), iEntryId);
       
   479     iBioTestUtils->Printf(_L("iServiceId:     0x%x\n"), entry.iServiceId);
       
   480     iBioTestUtils->Printf(_L("iRelatedId:     0x%x\n"), entry.iRelatedId);
       
   481     iBioTestUtils->Printf(_L("iType:          0x%x\n"), entry.iType);
       
   482     iBioTestUtils->Printf(_L("iMtm:           0x%x\n"), entry.iMtm);
       
   483     TBuf<128> dateStr;
       
   484     entry.iDate.FormatL(dateStr, (_L("%D%M%Y%/0%1%/1%2%/2%3%/3")));
       
   485     iBioTestUtils->Printf(_L("iDate:          %S\n"), &dateStr);
       
   486 
       
   487     iBioTestUtils->Printf(_L("iSize:          %d\n"), entry.iSize);
       
   488     iBioTestUtils->Printf(_L("iError:         %d\n"), entry.iError);
       
   489     iBioTestUtils->Printf(_L("iBioType:		0x%x\n"), entry.iBioType);
       
   490     iBioTestUtils->Printf(_L("iMtmData1:      %d\n"), entry.MtmData1());
       
   491     iBioTestUtils->Printf(_L("iMtmData2:      %d\n"), entry.MtmData2());
       
   492     iBioTestUtils->Printf(_L("iMtmData3:      %d\n"), entry.MtmData3());
       
   493     iBioTestUtils->Printf(_L("iDescription:  %S\n"), &entry.iDescription);
       
   494     iBioTestUtils->Printf(_L("iDetails:      %S\n "), &entry.iDetails);
       
   495 
       
   496     iBioTestUtils->ClearScreen();
       
   497     //test.Console()->SetPos(0,0);
       
   498 
       
   499 
       
   500 	if(iBioTestUtils->Entry().MtmData3() ==0)
       
   501 		{
       
   502 		iBioTestUtils->WriteComment(_L("BioMg has not been parsed or processed"));
       
   503 		User::Leave(KErrGeneral);
       
   504 		}
       
   505 
       
   506 	iBioTestUtils->Printf(_L("===== Extracted Fields =====\n"));
       
   507 	iBioTestUtils->LogExtractedFieldsL(iEntryId);
       
   508 
       
   509     }
       
   510 
       
   511 void CTestIacp::DisplayFinalSummary()
       
   512 	{
       
   513 	iBioTestUtils->Printf(_L("\nFinal summary\n"));
       
   514 	iBioTestUtils->Printf(_L("%d messages processed\n"), iIacpMsgCtr);
       
   515 	iBioTestUtils->Printf(_L("%d failed\n"), iFailedToProcess);
       
   516 	}
       
   517 
       
   518 LOCAL_C void doMainL()
       
   519 	{
       
   520 	//create a scheduler
       
   521 	exampleScheduler = new (ELeave) CExampleScheduler;
       
   522 	CleanupStack::PushL( exampleScheduler );
       
   523 	CActiveScheduler::Install( exampleScheduler );
       
   524 
       
   525 	CBioTestUtils* BioTestUtils = CBioTestUtils::NewL(test,ETuGoClientSide);
       
   526 	CleanupStack::PushL(BioTestUtils);
       
   527 
       
   528 	BioTestUtils->WriteComment(_L("Msv Server Side Created"));
       
   529 
       
   530 	CTestIacp* testParser = CTestIacp::NewL(BioTestUtils);
       
   531 	CleanupStack::PushL( testParser );
       
   532 	test(testParser != NULL);
       
   533 	BioTestUtils->WriteComment(_L("CTestIacp Object Created."));
       
   534 	
       
   535 	BioTestUtils->TestStart(0);
       
   536 	testParser->StartL(EParse);
       
   537 	
       
   538 	CActiveScheduler::Start();
       
   539 
       
   540 	CleanupStack::PopAndDestroy(3);    // testParser, BioTestUtils, exampleScheduler
       
   541 
       
   542 	testParser=NULL;
       
   543 	BioTestUtils=NULL;
       
   544 	exampleScheduler = NULL;
       
   545 	}
       
   546 
       
   547 GLDEF_C TInt E32Main()
       
   548 	{
       
   549 	test.Title();
       
   550 	test.Start(_L("IACP Test Harness"));
       
   551 	__UHEAP_MARK;
       
   552 	CTrapCleanup* cleanup=CTrapCleanup::New();
       
   553 	test(cleanup!=NULL);
       
   554 	TRAPD(error,doMainL());
       
   555 	if (error) 
       
   556 		test.Printf(_L("Completed with return code %d"),error);
       
   557 	delete cleanup;
       
   558 
       
   559 	__UHEAP_MARKEND;
       
   560 	test.Close();
       
   561 	test.End();
       
   562 	return KErrNone;
       
   563 	}