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