phonebookengines/contactsmodel/tsrc/Integration/TCntPolice/Template/CSuite.cpp
changeset 0 e686773b3f54
child 24 0ba2181d7c28
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 // Copyright (c) 2004-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 // for (WINS && !EKA2) versions will be xxxServer.Dll and require a thread to be started
       
    15 // in the process of the client. The client initialises the server by calling the
       
    16 // one and only ordinal.
       
    17 // 
       
    18 //
       
    19 
       
    20 #include <e32base.h>
       
    21 #include <e32cmn.h> 
       
    22 
       
    23 #if (!defined TS_PARAM_SVR_SUITENAME_SERVER_H_)
       
    24 	#include "CSuite.h"
       
    25 #endif
       
    26 
       
    27 
       
    28 PARAM_FOREACH_MESS_BEGIN
       
    29 #include "PARAM_MESS_NAME_CStep.h"
       
    30 PARAM_FOREACH_MESS_END
       
    31 
       
    32 // __EDIT_ME__ - Substitute the name of your test server 
       
    33 _LIT(KServerName,"Cap_PARAM_SVR_SUITENAME_sc");
       
    34 // __EDIT_ME__ - Use your own server class name
       
    35 
       
    36 CTestPARAM_SVR_SUITENAMEServer* CTestPARAM_SVR_SUITENAMEServer::NewL()
       
    37 /**
       
    38  * @return - Instance of the test server
       
    39  * Same code for Secure and non-secure variants
       
    40  * Called inside the MainL() function to create and start the
       
    41  * CTestServer derived server.
       
    42  */
       
    43 	{
       
    44 // __EDIT_ME__ - Use your own server class name
       
    45 	CTestPARAM_SVR_SUITENAMEServer * server = new (ELeave) CTestPARAM_SVR_SUITENAMEServer();
       
    46 	CleanupStack::PushL(server);
       
    47 	// CServer base class call
       
    48 	server->StartL(KServerName);
       
    49 	CleanupStack::Pop(server);
       
    50 	return server;
       
    51 	}
       
    52 
       
    53 CTestStep* CTestPARAM_SVR_SUITENAMEServer::CreateTestStep(const TDesC& aStepName)
       
    54 /**
       
    55  * @return - A CTestStep derived instance
       
    56  * Secure and non-secure variants
       
    57  * Implementation of CTestServer pure virtual
       
    58  */
       
    59 	{
       
    60 	 CTestStep* testStep = NULL;
       
    61 	// add test steps
       
    62 PARAM_FOREACH_MESS_BEGIN
       
    63 		if (aStepName == _L("CPARAM_MESS_NAMEStep"))
       
    64 			{
       
    65 			testStep =  new CPARAM_MESS_NAMEStep  ;
       
    66 			if (!testStep)
       
    67 				{
       
    68 				_LIT(KAllocationFailed, 
       
    69 					"Could not allocate teststep in CTestPARAM_SVR_SUITENAMEServer::CreateTestStep()\n");
       
    70 				ERR_PRINTF1(KAllocationFailed);
       
    71 				User::Invariant();
       
    72 				}
       
    73 			return testStep;
       
    74 			 }
       
    75 			 
       
    76 PARAM_FOREACH_MESS_END
       
    77 		return testStep;
       
    78 	 }
       
    79 
       
    80 	
       
    81 
       
    82 // Secure variants much simpler
       
    83 // Just an E32Main and a MainL()
       
    84 LOCAL_C void MainL()
       
    85 /**
       
    86  * Secure variant
       
    87  * Much simpler, uses the new Rendezvous() call to sync with the client
       
    88  */
       
    89 	{
       
    90 #if (defined __DATA_CAGING__)
       
    91 	RProcess().DataCaging(RProcess::EDataCagingOn);
       
    92 	RProcess().DataCaging(RProcess::ESecureApiOn);
       
    93 #endif
       
    94 	CActiveScheduler* sched=NULL;
       
    95 	sched=new(ELeave) CActiveScheduler;
       
    96 	CActiveScheduler::Install(sched);
       
    97 // __EDIT_ME__ - Use your own server class name
       
    98 	CTestPARAM_SVR_SUITENAMEServer* server = NULL;
       
    99 	// Create the CTestServer derived server
       
   100 	TRAPD(err,server = CTestPARAM_SVR_SUITENAMEServer::NewL());
       
   101 	if(!err)
       
   102 		{
       
   103 		// Sync with the client and enter the active scheduler
       
   104 		RProcess::Rendezvous(KErrNone);
       
   105 		sched->Start();
       
   106 		}
       
   107 	delete server;
       
   108 	delete sched;
       
   109 	}
       
   110 
       
   111 
       
   112 GLDEF_C TInt E32Main()
       
   113 /**
       
   114  * @return - Standard Epoc error code on process exit
       
   115  * Secure variant only
       
   116  * Process entry point. Called by client using RProcess API
       
   117  */
       
   118 	{
       
   119 	__UHEAP_MARK;
       
   120 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
   121 	if(cleanup == NULL)
       
   122 		{
       
   123 		return KErrNoMemory;
       
   124 		}
       
   125 	TRAPD(err,MainL());
       
   126 	delete cleanup;
       
   127 	__UHEAP_MARKEND;
       
   128 	return KErrNone;
       
   129     }
       
   130 
       
   131 
       
   132 TVerdict CCapabilityTestStep::doTestStepPreambleL( void )
       
   133 	{
       
   134 	//If Preamble is not required just pass a success value
       
   135 	TVerdict testResult = CTestStep::doTestStepPreambleL();
       
   136 	
       
   137 	
       
   138 	return TestStepResult();
       
   139 	
       
   140 	}
       
   141 TVerdict CCapabilityTestStep::doTestStepPostambleL( void )
       
   142 	{
       
   143 	//If Postamble is not required just pass a success value
       
   144 	TVerdict testResult = CTestStep::doTestStepPostambleL();
       
   145 
       
   146 	return TestStepResult();
       
   147 	
       
   148 	}
       
   149 
       
   150 
       
   151 // Moved from CStep.cpp
       
   152 
       
   153 enum TVerdict CCapabilityTestStep::doTestStepL()
       
   154 	{
       
   155 	//DEF! INFO_PRINTF2(_L("%S - Starting ..."), &iTestStepName);
       
   156 
       
   157 	//The MainThread()creates a separate thread that executes SendReceive
       
   158 	TVerdict vResult = MainThread();
       
   159 	
       
   160 	SetTestStepResult(vResult);
       
   161 	return TestStepResult();
       
   162 	}
       
   163 
       
   164 /*
       
   165 ThreadStartFn:
       
   166 Called by:	The Child thread
       
   167 Function:	Calls the Exec_SendReceive
       
   168 */
       
   169 static TInt ThreadStartFn( TAny * ptr )
       
   170 	{
       
   171 	return(((CCapabilityTestStep *)ptr)->Exec_SendReceive());
       
   172 	}
       
   173 
       
   174 /*
       
   175 TVerdict GetVerdict(TInt aAPIretValue)
       
   176 
       
   177 Called by: "MainThread" for returning verdict
       
   178 
       
   179 Parameters(TInt aRetValue) :	0 if API call gets thru without any rejection
       
   180 								1 if API call is rejected for capability error	
       
   181 */
       
   182 enum TVerdict CCapabilityTestStep::GetVerdict(TInt aAPIretValue)
       
   183 	{
       
   184 	TVerdict vVerdict[] = {EPass, EFail};
       
   185 
       
   186 	//please leave the following if/else block as the information printed by INFO_PRINTF1 is used bu CapTestSumm
       
   187 	if(iExpect_Rejection)//[Inverse Test] EPass for 1 while EFail for 0
       
   188 		{
       
   189 		INFO_PRINTF1(_L("Test Expected to Fail due to lack of capabilities"));
       
   190 		return vVerdict[(aAPIretValue)?0:1];
       
   191 		
       
   192 		}
       
   193 	else //[Direct Test] EPass for 0 while EFail for 1
       
   194 		{
       
   195 		INFO_PRINTF1(_L("Test Expected to Pass with correct capabilities"));
       
   196 		return vVerdict[(aAPIretValue)?1:0];
       
   197 		}
       
   198 	}
       
   199 
       
   200 
       
   201 /*
       
   202 TVerdict MainThread()
       
   203 
       
   204 Called by: "doTestStepL"
       
   205 
       
   206 Purpose:	Creates the child thread(which calls the respective function with regard
       
   207 			to the server and also implements the Message Call). Then this fn.waits for the
       
   208 			completion of the childthread( doesnt matter how the thread did die!)
       
   209 
       
   210 Return Value(Verdict of the TestStep):
       
   211 
       
   212 			A.Reporting PASS/FAIL
       
   213 				Direct Test:
       
   214 						When a message call gets thru. Please note that in such cases
       
   215 						actually the implementation of the message has started. As we
       
   216 						are passing "0" Parameters, server may panic, though our botheration
       
   217 						stops once the call gets thru.
       
   218 						NOTE:	The style is the same when CONNECTION capabilities
       
   219 								are tested, the only diff is you dont have to expect a 
       
   220 								panic from server
       
   221 				Inverse Test:
       
   222 						The call should be either failed or panicked with
       
   223 						"KErrPermissionDenied" flag. 
       
   224 
       
   225 				General Case:
       
   226 						If a thread creation failed or if the server couldnt be connected
       
   227 						apart from the above two cases, then a FAIL is reported
       
   228 			
       
   229 			B.Reporting INCONCLUSIVE
       
   230 						Any panic say from unexpected source (eg:KERN-EXEC) will be
       
   231 						reported INCONCLUSIVE														
       
   232 */
       
   233 TVerdict CCapabilityTestStep::MainThread()
       
   234 	{
       
   235 
       
   236 	TBuf<100>	tExitCategory;
       
   237 	TInt		tExitReason = 0;		
       
   238 	TBuf<100>	TestStyle;
       
   239 
       
   240 	iExpect_Rejection?TestStyle = _L("Inverse"):TestStyle = _L("Direct");
       
   241 	TCapabilitySet theCaps =  TSecurityInfo(RProcess()).iCaps ;
       
   242 	const TInt KMaxTestThreadHeapSize = 0x10000;
       
   243 
       
   244 	//Initialize return values
       
   245 	iResult_SR = iResult_Server = KErrNone;	
       
   246 		
       
   247 
       
   248 	// Create a child thread, with a new heap
       
   249 	TInt nRes_Thread =	tChildThread.Create(
       
   250 						ChildThread_SR,
       
   251 						ThreadStartFn,
       
   252 						KDefaultStackSize,
       
   253 						KMinHeapSize,
       
   254 						KMaxTestThreadHeapSize,
       
   255 						this,			
       
   256 						EOwnerProcess);
       
   257 
       
   258 
       
   259 	if(nRes_Thread == KErrNone)//Thread Created
       
   260 		{
       
   261 
       
   262 		//Let me know when the thread is dead
       
   263 		TRequestStatus ThreadStatus;
       
   264 		tChildThread.Logon(ThreadStatus);
       
   265 		tChildThread.Resume(); 
       
   266 		//Is the thread dead?
       
   267 		User::WaitForRequest( ThreadStatus );
       
   268 		
       
   269 		//yes, he is dead. RIP!  Now the Killer's profile
       
   270 		tExitCategory	=	tChildThread.ExitCategory();
       
   271 		tExitReason		=	tChildThread.ExitReason();
       
   272 		
       
   273 	
       
   274 		//Somebody Please say what are we testing!!		
       
   275 		if(iSessionCreated && (SR_MESSAGE_ID >=0))//Flag set by Child thread when connected to Server
       
   276 		{
       
   277 			//DEF INFO_PRINTF5(_L("Connected to Server(%S) for %S Test [MessageID: %d,Req.Cap: 0x%x,Present.Cap: 0x%x]"),&SR_ServerName,&TestStyle,SR_MESSAGE_ID,iStepCap,TSecurityInfo(RProcess()));			
       
   278 		}
       
   279 		else if(SR_MESSAGE_ID < 0)
       
   280 		{
       
   281 			//DEF INFO_PRINTF5(_L("Testing Connection capabilities[%S Test] for Server(%S)  [Req.Cap: 0x%x,Present.Cap: 0x%x]"),&TestStyle,
       
   282 			//&SR_ServerName,TSecurityInfo(RProcess()));			
       
   283 		}
       
   284 		else if(!iSessionCreated)// NO Connection
       
   285 			{
       
   286 			INFO_PRINTF4(_L("Couldnt connect to the Server(%S) ErrorCode - ServerRet: %d C32ret: %d"),&SR_ServerName,iResult_Server,iResult_C32);
       
   287 			//INFO_PRINTF3(_L("Child Thread: ExitCategory : %S ExitReason : %d"),&tExitCategory,tExitReason);
       
   288   			return EFail;
       
   289  			}
       
   290 
       
   291 
       
   292 
       
   293 		switch(tChildThread.ExitType())
       
   294 			{			
       
   295 			case EExitPanic:
       
   296 				//1.A Panic from the connected Server 
       
   297 				//2.A CServer Panic normally for capability rejection
       
   298 				//3.A kernel Panic (consider yourself doomed!)
       
   299 				if((tExitReason == KErrPermissionDenied) ||
       
   300 					//DEF ? 	it's old version (tExitReason == CServer::EClientDoesntHaveRequiredCaps))//Rejected for Insufficient Cap.
       
   301 					// is it correct ?
       
   302 					(tExitReason == CServer2::EClientDoesntHaveRequiredCaps))//Rejected for Insufficient Cap.
       
   303 					{
       
   304 					INFO_PRINTF2(_L("Rejected for insufficient capabilities [Return Value : %d] "),tExitReason);
       
   305 					return(GetVerdict(API_RetValue_PermissionDenied));
       
   306 					}
       
   307 				else if(tExitCategory == iServer_Panic) //Panic from Server
       
   308 					{
       
   309 					INFO_PRINTF2(_L("Server(%S) Panic to child thread"),&tExitCategory);	
       
   310 					INFO_PRINTF3(_L("Child Thread: ExitCategory : %S ExitReason : %d"),&tExitCategory,tExitReason);			
       
   311 					return(GetVerdict(API_RetValue_ServerPanic));
       
   312 					}
       
   313 				else//A kernel Panic possibly
       
   314 					{
       
   315 					INFO_PRINTF3(_L("Child Thread: Panic from unexpected source (ExitCategory: %S ExitReason : %d)!"),&tExitCategory,tExitReason);
       
   316 					return EInconclusive;
       
   317 					}
       
   318 
       
   319 					break;
       
   320 			case EExitKill:
       
   321 				if(iResult_SR != KErrPermissionDenied)
       
   322 					{
       
   323 					INFO_PRINTF2(_L("A Successfull call (Return Value : %d)"),((SR_MESSAGE_ID >=0)?iResult_SR:iResult_Server));
       
   324 					return(GetVerdict(API_RetValue_NoCapError));
       
   325 					}
       
   326 				else 
       
   327 					{
       
   328 					INFO_PRINTF2(_L("Rejected for insufficient capabilities [Return Value : %d] "),((SR_MESSAGE_ID >=0)?iResult_SR:iResult_Server));
       
   329 					return(GetVerdict(API_RetValue_PermissionDenied));			
       
   330 					}
       
   331 
       
   332 					break;
       
   333 			default:					
       
   334 					break;
       
   335 			}
       
   336 		}			
       
   337 	else //Our thread couldnt start	:o(
       
   338 		{
       
   339 		INFO_PRINTF2(_L("ERROR: Failed to create Child thread,  ErrorCode:(%d)"),nRes_Thread);
       
   340 		return EFail;
       
   341 		}
       
   342 
       
   343 	return EInconclusive;
       
   344 	}
       
   345 
       
   346 TInt CCapabilityTestStep::StartServer()
       
   347 {
       
   348 	TInt err =  KErrNone ;
       
   349 	// EKA2 is simple No path required
       
   350 	TBuf<32> serverFile;
       
   351 	serverFile.Copy(_L("PARAM_SVR_SUITENAME"));
       
   352 	_LIT(KExe,".exe");
       
   353 	serverFile.Append(KExe);
       
   354 	RProcess server;
       
   355 	err = server.Create(serverFile,_L(""));
       
   356 	if(err != KErrNone)
       
   357 		return err;
       
   358 	// Synchronise with the server
       
   359 	TRequestStatus reqStatus;
       
   360 	server.Rendezvous(reqStatus);
       
   361 	server.Resume();
       
   362 	 //Server will call the reciprocal static synchronise call
       
   363 	User::WaitForRequest(reqStatus);
       
   364 	//server.Close();
       
   365 	if(reqStatus.Int() != KErrNone)
       
   366 		return reqStatus.Int();
       
   367 	return err;
       
   368 }	
       
   369 	
       
   370  	TInt CCapabilityTestStep::TestDebugHeap(TInt* iDbgIPCNo)
       
   371  	{
       
   372  	
       
   373  	//TDbgFns  {MarkHeapStart, MarkHeapEnd, CheckHeap, FailNext, ResetFailNext};
       
   374  	TInt aFnToTest= iDbgIPCNo[5];
       
   375  			
       
   376  	
       
   377  	TInt iResult_SR [6] ={0};
       
   378  	TInt i = 1;
       
   379  	TInt testedFn = 0;
       
   380  
       
   381  	TInt dbgTestSequence[5][6]	=	{	{MarkHeapStart	,2,0,1,-1,-1}, 
       
   382  										{MarkHeapEnd	,2,0,1,-1,-1},
       
   383  										{CheckHeap		,3,0,2, 1,-1},
       
   384  										{FailNext		,4,0,3, 4, 1},
       
   385  										{ResetFailNext	,4,0,3, 4, 1}
       
   386  										
       
   387  									};
       
   388  
       
   389  	
       
   390  	TInt aCount = dbgTestSequence[aFnToTest][i];
       
   391  
       
   392  	while(aCount--  )
       
   393  		{
       
   394  		testedFn =  dbgTestSequence[aFnToTest][(++i)];
       
   395  		
       
   396 			iResult_SR[testedFn ]= SendReceive( iDbgIPCNo[testedFn],TIpcArgs(((iDbgIPCNo[testedFn]==3 )?4:0),0,0,0));
       
   397    		
       
   398  		
       
   399  		if( ((testedFn !=aFnToTest)?iResult_SR[testedFn]:KErrNone) == KErrPermissionDenied) 			
       
   400 			
       
   401 			User::Panic(_L("Failed at Initialization"),iResult_SR[testedFn]);		
       
   402 
       
   403 		}
       
   404 
       
   405 	return iResult_SR[aFnToTest];
       
   406 	}
       
   407 	
       
   408