messagingfw/biomsgfw/BIOCTSRC/T_BIOC.CPP
changeset 0 8e480a14352b
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     1 // Copyright (c) 1999-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 #include "TESTENV.H"
       
    17 #include <e32test.h>
       
    18 #include <e32uid.h>
       
    19 
       
    20 #include <msvruids.h>
       
    21 #include <msvids.h>
       
    22 #include <msvuids.h>
       
    23 
       
    24 #include <mtmdef.h>
       
    25 
       
    26 #include <txtrich.h>                            //      rich text stuff
       
    27 #include <txtfmlyr.h>                           //      para format gubbins..
       
    28 
       
    29 #include <bsp.h>
       
    30 #include "biotestutils.h"
       
    31 
       
    32 
       
    33 
       
    34 //
       
    35 class TestScheduler : public CActiveScheduler
       
    36 	{
       
    37 	public:
       
    38 	void Error (TInt aError) const;
       
    39 	};
       
    40 
       
    41 //
       
    42 void TestScheduler::Error(TInt /*anError*/) const
       
    43 	{
       
    44 	CActiveScheduler::Stop();
       
    45 	}
       
    46 
       
    47 
       
    48 // local variables etc //
       
    49 
       
    50 LOCAL_D RTest test(_L("BIOC.dll Testrig"));
       
    51 LOCAL_D CTrapCleanup* theCleanup;
       
    52 LOCAL_D RFs theFs;      
       
    53 LOCAL_D TestScheduler* scheduler;
       
    54 
       
    55 LOCAL_D TMsvSelectionOrdering   msvSelectionOrdering;
       
    56 
       
    57 #define KPeriod 10000   // period of timer
       
    58 
       
    59 //
       
    60 
       
    61 //
       
    62 class TestUiTimer : public CTimer
       
    63 	{
       
    64 public:
       
    65 	static TestUiTimer* NewLC();
       
    66 	~TestUiTimer();
       
    67 
       
    68 	void RunL();
       
    69 	void DoCancel();
       
    70 	void ConstructL();
       
    71 	void IssueRequest();
       
    72 	void SetOperation(CMsvOperation*);
       
    73 	TTimeIntervalMicroSeconds32 period;
       
    74 protected:
       
    75 	TestUiTimer();
       
    76 	
       
    77 	CMsvOperation*                          iOperation;
       
    78 	};
       
    79 
       
    80 //
       
    81 TestUiTimer* TestUiTimer::NewLC()
       
    82 	{
       
    83 	TestUiTimer* self = new(ELeave) TestUiTimer();
       
    84 	CleanupStack::PushL(self);
       
    85 	self->ConstructL();
       
    86 	return self;
       
    87 	}
       
    88 
       
    89 TestUiTimer::TestUiTimer()
       
    90 	: CTimer(5)
       
    91 	{
       
    92 	period = KPeriod;
       
    93 	}
       
    94 
       
    95 TestUiTimer::~TestUiTimer()
       
    96 	{
       
    97 	delete iOperation;
       
    98 	}
       
    99 
       
   100 void TestUiTimer::ConstructL()
       
   101 	{
       
   102 	CTimer::ConstructL();
       
   103 	CActiveScheduler::Add(this);
       
   104 	}
       
   105 
       
   106 void TestUiTimer::IssueRequest()
       
   107 	{
       
   108 	After(period);
       
   109 	}
       
   110 
       
   111 void TestUiTimer::SetOperation(CMsvOperation *aOperation)
       
   112 	{
       
   113 	if(iOperation)
       
   114 		{
       
   115 		delete iOperation;
       
   116 		iOperation=NULL;
       
   117 		}
       
   118 	iOperation = aOperation;
       
   119 	}
       
   120 
       
   121 void TestUiTimer::DoCancel()
       
   122 	{
       
   123 	CTimer::DoCancel();
       
   124 //      delete iOperation;
       
   125 //      iOperation = NULL;
       
   126 	}
       
   127 
       
   128 void TestUiTimer::RunL()
       
   129 	{
       
   130 	// display the current progress
       
   131 	if(iOperation!=NULL)
       
   132 		{
       
   133 		TBioProgress temp;      
       
   134 		TPckgC<TBioProgress> paramPack(temp);
       
   135 
       
   136 		const TDesC8& progBuf = iOperation->ProgressL();        
       
   137 		paramPack.Set(progBuf);
       
   138 		TBioProgress progress=paramPack();      
       
   139 
       
   140 		test.Console()->SetPos(0, 13);
       
   141 		test.Printf(TRefByValue<const TDesC>_L("   Operation: %d"),progress.iBioState);
       
   142 		test.Printf(TRefByValue<const TDesC>_L("   Progress:  Error: %d\n"),
       
   143 					progress.iErrorCode);
       
   144 
       
   145 		}
       
   146 	IssueRequest();
       
   147 	};
       
   148 
       
   149 
       
   150 //
       
   151 class CNbscTester : public CBase
       
   152 	{
       
   153 public:
       
   154 	  // Construction
       
   155 	static CNbscTester* NewLC();
       
   156 
       
   157 	  // Destruction
       
   158 	~CNbscTester();
       
   159 
       
   160 	  // Issue request
       
   161 	void StartL();
       
   162 
       
   163 	void TestFindBodyL(const TDesC& aText);
       
   164 	void TestFindSubjectL(const TDesC& aText);
       
   165 
       
   166 private:
       
   167 	CNbscTester();
       
   168 	void ConstructL();
       
   169 	// functions
       
   170 	void CreateParserL();
       
   171 	void ReParseL();
       
   172 	void ReProcessL();
       
   173 	void ProcessError(TInt& aError);
       
   174 	
       
   175 	 // Data members defined by this class
       
   176 	CMsvEntrySelection* iSelection;
       
   177 	CMsvEntrySelection*     iMsvSelection;  // selection of test messages
       
   178 	CBioTestUtils*          iBioTestUtils;
       
   179 	CBIOClientMtm*          iBioClientMtm;
       
   180 
       
   181 	TUint iMenuState;
       
   182 	TUint iPrevState;
       
   183 
       
   184 	TUint iParseState;
       
   185 	TestUiTimer* iTimer;
       
   186 
       
   187 	TInt            iNumMessages;
       
   188 	TInt            iMsgCtr;
       
   189 	TInt            iTestCtr;
       
   190 	TBool           iAllTestsSuccessful;
       
   191 	enum
       
   192 		{
       
   193 		EParserIdle,
       
   194 		EParserCreate,
       
   195 		EParserParse,
       
   196 		EParserCommit
       
   197 		};
       
   198 	};
       
   199 
       
   200 //
       
   201 CNbscTester* CNbscTester::NewLC()
       
   202 	{
       
   203 	CNbscTester* self = new(ELeave) CNbscTester();
       
   204 	CleanupStack::PushL(self);
       
   205 	self->ConstructL();
       
   206 	return self;
       
   207 	}
       
   208 
       
   209 CNbscTester::CNbscTester()
       
   210 	{
       
   211 	}
       
   212 
       
   213 void CNbscTester::ConstructL()
       
   214 	{
       
   215 	// create test utilities
       
   216 	iBioTestUtils = CBioTestUtils::NewL(test, ETuGoClientSide | ETuCleanMessageFolder);
       
   217 
       
   218 	test.Printf(_L("Creating services"));
       
   219 	iBioTestUtils->CreateServicesL();
       
   220 
       
   221 	User::After(2500000);
       
   222 	
       
   223 	iBioTestUtils->TestStart(1,_L("Instant client"));
       
   224 	TRAPD(error,iBioTestUtils->InstantiateClientMtmsL(););
       
   225 	iBioTestUtils->TestFinish(1,error);
       
   226 	if(error)
       
   227 		User::Leave(error);
       
   228 
       
   229 	iBioClientMtm = iBioTestUtils->iBioClientMtm;
       
   230 	
       
   231 	iSelection = new (ELeave) CMsvEntrySelection;
       
   232 	CleanupStack::PushL(iSelection);
       
   233 	CleanupStack::Pop();    //iSelection
       
   234 	iTimer = TestUiTimer::NewLC();
       
   235 	CleanupStack::Pop();    // iTimer
       
   236 	iParseState = EParserCreate;
       
   237 	iAllTestsSuccessful = ETrue;
       
   238 	}
       
   239 
       
   240 CNbscTester::~CNbscTester()
       
   241 	{
       
   242 	delete iSelection;
       
   243 	delete iMsvSelection;
       
   244 	delete iTimer;
       
   245 	delete iBioTestUtils;
       
   246 	}
       
   247 
       
   248 void CNbscTester::StartL()
       
   249     {
       
   250 	iBioTestUtils->TestStart(iTestCtr,_L("Generate Test Messages"));
       
   251 	iMsvSelection = iBioTestUtils->GenerateMessagesL();
       
   252 	iNumMessages = iMsvSelection->Count();
       
   253 	iMsgCtr = 0;
       
   254 	// 
       
   255 	iTestCtr++;
       
   256 
       
   257 	for(TInt i =0; i < iNumMessages; i++)
       
   258 		{
       
   259 		iSelection->Reset();
       
   260 
       
   261 		iSelection->AppendL((*iMsvSelection)[i]);
       
   262 
       
   263 		iBioTestUtils->TestStart(iTestCtr,_L("Parse and process"));
       
   264 		TRAPD(error,CreateParserL());
       
   265 		ProcessError(error);
       
   266 		if(error == KErrNone)
       
   267 			{
       
   268 			iBioTestUtils->TestFinish(iTestCtr);
       
   269 			iTestCtr++;
       
   270 			iBioTestUtils->TestStart(iTestCtr,_L("Reparse"));
       
   271 			TRAP(error,ReParseL());
       
   272 			ProcessError(error);
       
   273 			iBioTestUtils->TestFinish(iTestCtr,error);
       
   274 			if(error == KErrNone)
       
   275 				{
       
   276 				iTestCtr++;
       
   277 				iBioTestUtils->TestStart(iTestCtr,_L("Reprocess"));
       
   278 				TRAP(error,ReProcessL());
       
   279 				ProcessError(error);
       
   280 				if(error==KErrNone)
       
   281 					iBioTestUtils->TestFinish(iTestCtr);
       
   282 				else
       
   283 					{
       
   284 					iBioTestUtils->TestFinish(iTestCtr,error);
       
   285 					iAllTestsSuccessful = EFalse;
       
   286 					}
       
   287 				}
       
   288 			}
       
   289 		else
       
   290 			{
       
   291 			iBioTestUtils->TestFinish(iTestCtr,error);
       
   292 			iAllTestsSuccessful = EFalse;
       
   293 			}
       
   294 
       
   295 		iTestCtr++;
       
   296 		iBioTestUtils->TestStart(iTestCtr,_L("test find in body"));
       
   297 		TRAP(error,TestFindBodyL(_L("yashar")));
       
   298 		iBioTestUtils->TestFinish(iTestCtr,error);
       
   299 
       
   300 		iTestCtr++;
       
   301 		iBioTestUtils->TestStart(iTestCtr,_L("test find in subject"));
       
   302 		TRAP(error,TestFindSubjectL(_L("Configuration")));
       
   303 		iBioTestUtils->TestFinish(iTestCtr,error);
       
   304 		}
       
   305 	if(iAllTestsSuccessful)
       
   306 		iBioTestUtils->TestHarnessCompleted();
       
   307     }
       
   308 
       
   309 void CNbscTester::ProcessError(TInt& aError)
       
   310 	{
       
   311 	if(aError==KErrNotSupported)
       
   312 		{
       
   313 		aError = KErrNone;
       
   314 		iBioTestUtils->WriteComment(_L("Unsupported operation"));
       
   315 		}
       
   316 	else if((aError <= -500 && aError >= -521) || (aError <= -600 && aError >= -614))
       
   317 		{
       
   318 		aError = KErrNone;
       
   319 		iBioTestUtils->WriteComment(_L("Corrupt or missing Bio-data"));
       
   320 		}
       
   321 	}
       
   322 
       
   323 //
       
   324 // Try a get a parser
       
   325 //
       
   326 void CNbscTester::CreateParserL()
       
   327 	{
       
   328 	TBuf8<1> aParameter;
       
   329 	CMsvOperationWait* wait = CMsvOperationWait::NewLC();
       
   330 	wait->iStatus = KRequestPending;
       
   331 	wait->Start();
       
   332 	
       
   333 	CMsvOperation* operation = iBioClientMtm->InvokeAsyncFunctionL( KBiosMtmParseThenProcess, *iSelection, aParameter, wait->iStatus);
       
   334 	
       
   335 	iTimer->SetOperation(operation);
       
   336 	iTimer->IssueRequest();
       
   337 	
       
   338 	CActiveScheduler::Start();
       
   339 
       
   340 	TInt error = operation->iStatus.Int();
       
   341 	iTimer->Cancel();
       
   342 	CleanupStack::PopAndDestroy();  // wait
       
   343 	if(error !=KErrNone)
       
   344 		User::Leave(error);
       
   345 	}
       
   346 
       
   347 //
       
   348 // Interpret the message
       
   349 //
       
   350 void CNbscTester::ReParseL()
       
   351 	{
       
   352 	TBuf8<1> parameter;
       
   353 
       
   354 	CMsvOperationWait* wait = CMsvOperationWait::NewLC();
       
   355 	wait->iStatus = KRequestPending;
       
   356 	wait->Start();
       
   357 	
       
   358 	CMsvOperation* operation = iBioClientMtm->InvokeAsyncFunctionL( KBiosMtmParse, *iSelection, parameter, wait->iStatus);
       
   359 
       
   360 	iTimer->SetOperation(operation);
       
   361 	iTimer->IssueRequest();
       
   362 
       
   363 	CActiveScheduler::Start();
       
   364 	iTimer->Cancel();
       
   365 	TInt error = operation->iStatus.Int();
       
   366 	
       
   367 	CleanupStack::PopAndDestroy();  // wait
       
   368 	if(error !=KErrNone)
       
   369 		User::Leave(error);
       
   370 	}
       
   371 
       
   372 //
       
   373 // Act on the changes
       
   374 // 
       
   375 void CNbscTester::ReProcessL()
       
   376 	{
       
   377 	TBuf8<1> aParameter;
       
   378 	CMsvOperationWait* wait = CMsvOperationWait::NewLC();
       
   379 	wait->iStatus = KRequestPending;
       
   380 	wait->Start();
       
   381 
       
   382 	CMsvOperation* operation = iBioClientMtm->InvokeAsyncFunctionL(KBiosMtmProcess, *iSelection, aParameter, wait->iStatus);
       
   383 	
       
   384 	iTimer->SetOperation(operation);
       
   385 	iTimer->IssueRequest();
       
   386 	
       
   387 	CActiveScheduler::Start();
       
   388 
       
   389 	TInt error = operation->iStatus.Int();
       
   390 	iTimer->Cancel();
       
   391 	
       
   392 	CleanupStack::PopAndDestroy();  // wait
       
   393 	if(error !=KErrNone)
       
   394 		User::Leave(error);
       
   395 	}
       
   396 
       
   397 void CNbscTester::TestFindBodyL(const TDesC& aText)
       
   398 	{
       
   399 	iBioClientMtm->SwitchCurrentEntryL((*iSelection)[0]);
       
   400 	iBioClientMtm->LoadMessageL();
       
   401 	TMsvPartList retPart =  iBioClientMtm->Find(aText,KMsvMessagePartBody);
       
   402 	if(retPart&KMsvMessagePartBody)
       
   403 		iBioTestUtils->WriteComment(_L("Found in body text"));
       
   404 	else
       
   405 		iBioTestUtils->WriteComment(_L("Not found in body text"));
       
   406 	
       
   407 	TRAP_IGNORE(iBioClientMtm->SaveMessageL());
       
   408 	TRequestStatus st;
       
   409 	TMsvId s =0;
       
   410 	TRAP_IGNORE(iBioClientMtm->ReplyL(s,retPart,st));
       
   411 	TRAP_IGNORE(iBioClientMtm->ForwardL(s,retPart,st));
       
   412 	iBioClientMtm->ValidateMessage(retPart);
       
   413 	
       
   414 	const TBufC<1> yy;
       
   415 	TRAP_IGNORE(iBioClientMtm->AddAddresseeL(yy) );
       
   416 	TRAP_IGNORE(iBioClientMtm->AddAddresseeL(yy ,yy) );
       
   417 	TInt ii = 0;
       
   418 	iBioClientMtm->RemoveAddressee(ii);
       
   419 	TBuf8<1> yy1;
       
   420 	const CMsvEntrySelection* selection1 = new(ELeave)CMsvEntrySelection();
       
   421 	TRAP_IGNORE(iBioClientMtm->InvokeSyncFunctionL( ii,*selection1, yy1));
       
   422 	
       
   423 	TUid parserUid =TUid::Uid(10);
       
   424 	iBioClientMtm->QueryCapability(parserUid,ii);
       
   425 	delete selection1;
       
   426 	}
       
   427 
       
   428 void CNbscTester::TestFindSubjectL(const TDesC& aText)
       
   429 	{
       
   430 	iBioClientMtm->LoadMessageL();
       
   431 	TMsvPartList retPart = iBioClientMtm->Find(aText,KMsvMessagePartDescription);
       
   432 	if(retPart&KMsvMessagePartDescription)
       
   433 		iBioTestUtils->WriteComment(_L("Found in Subject"));
       
   434 	else
       
   435 		iBioTestUtils->WriteComment(_L("Not found in sbject"));
       
   436 	}
       
   437 
       
   438 LOCAL_C void doMainL()
       
   439 	{
       
   440 	scheduler = new (ELeave) TestScheduler;
       
   441 	CActiveScheduler::Install( scheduler );
       
   442 
       
   443 	User::LeaveIfError(theFs.Connect());
       
   444 	theFs.SetSessionPath(_L("C:\\"));
       
   445 
       
   446 	test.Console()->SetPos(0, 16);
       
   447 
       
   448 	CNbscTester* activeConsole = CNbscTester::NewLC();
       
   449 	CleanupStack::Pop();
       
   450 	activeConsole->StartL();        //Start the active console
       
   451 	// Cleanup exit
       
   452 	delete activeConsole;
       
   453 
       
   454 	theFs.Close( );
       
   455 	delete scheduler;       
       
   456 
       
   457 	}
       
   458 
       
   459 
       
   460 GLDEF_C TInt E32Main()
       
   461 	{       
       
   462 	__UHEAP_MARK;
       
   463 	test.Start(_L("T_BIOC - Test Harness"));
       
   464 	theCleanup=CTrapCleanup::New();
       
   465 	TRAPD(ret,doMainL());           
       
   466 	test(ret==KErrNone);
       
   467 	delete theCleanup;      
       
   468 	test.Console()->SetPos(0, 13);
       
   469 	test.End();
       
   470 	test.Close();
       
   471 	__UHEAP_MARKEND;
       
   472 	return(KErrNone);
       
   473 	}