sysstatemgmt/systemstateplugins/test/tintgsapolicy/src/tgsastatetranfromnormal.cpp
branchRCL_3
changeset 22 8cb079868133
parent 21 ccb4f6b3db21
equal deleted inserted replaced
21:ccb4f6b3db21 22:8cb079868133
     1 // Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    44 
    44 
    45 public:
    45 public:
    46 	void DoTestStateTranFromNormalL();
    46 	void DoTestStateTranFromNormalL();
    47 	};
    47 	};
    48 
    48 
    49 
    49 static TInt StopScheduler(TAny* aStateTranFromNormal)
       
    50  	{
       
    51  	CStateTranFromNormal* stateTran = reinterpret_cast<CStateTranFromNormal*>(aStateTranFromNormal);
       
    52  	TRAPD(err,stateTran->CallStopSchedulerL());
       
    53  	return err;
       
    54  	}
    50 
    55 
    51 static TInt StartTest(TAny* aStateTranFromNormal)
    56 static TInt StartTest(TAny* aStateTranFromNormal)
    52  	{
    57  	{
    53  	TInt testCompletionReason = KErrNone;
    58  	TInt testCompletionReason = KErrNone;
    54  	CStateTranFromNormal* stateTran = reinterpret_cast<CStateTranFromNormal*>(aStateTranFromNormal);
    59  	CStateTranFromNormal* stateTran = reinterpret_cast<CStateTranFromNormal*>(aStateTranFromNormal);
    80 	}
    85 	}
    81 
    86 
    82 // Tests the Fail state transitions under different scenarios
    87 // Tests the Fail state transitions under different scenarios
    83 void CStateTranFromNormal::DoTestStateTranFromNormalL()
    88 void CStateTranFromNormal::DoTestStateTranFromNormalL()
    84 	{
    89 	{
       
    90 	// This async callback is used to stop the scheduler once the system goes into fail state.
       
    91 	iAsyncCallbackForStopScheduler =  new(ELeave) CAsyncCallBack(CActive::EPriorityIdle);
       
    92 	TCallBack stopSchedulerCallback(StopScheduler, this);
       
    93 	iAsyncCallbackForStopScheduler->Set(stopSchedulerCallback);
       
    94 
       
    95 	// call the callback function which keeps looping until the system state gets into fail state.
       
    96 	iAsyncCallbackForStopScheduler->CallBack();
       
    97 
    85 	RSsmStateManager stateMan;
    98 	RSsmStateManager stateMan;
    86 	TInt err = stateMan.Connect();
    99 	TInt err = stateMan.Connect();
    87 	CleanupClosePushL(stateMan);
       
    88 	if (err == KErrNone)
   100 	if (err == KErrNone)
    89 		RDebug::Print(_L("\nStateTran Test: RSsmStateManager sess Connect %d\n"), err);
   101 		RDebug::Print(_L("\nStateTran Test: RSsmStateManager sess Connect %d\n"), err);
    90 	else
   102 	else
    91 		{
   103 		{
    92 		RDebug::Print(_L("\nStateTran Test: Unable to connect to RSsmStateManager sess\n"));	
   104 		RDebug::Print(_L("\nStateTran Test: Unable to connect to RSsmStateManager sess\n"));	
   187 	else
   199 	else
   188 		{
   200 		{
   189 		RDebug::Print(_L("\nStateTran Test: RequestStateTransition from Normal to shutdown state Failed"));
   201 		RDebug::Print(_L("\nStateTran Test: RequestStateTransition from Normal to shutdown state Failed"));
   190 		User::Leave(KTestAppFailure);		
   202 		User::Leave(KTestAppFailure);		
   191 		}
   203 		}
   192 	
   204 
   193 	iFileWriteStream.Close();
   205 	//Scenario 4 - Request for two state changes one after the other without waiting for the first one to complete
   194 	
   206 	// Once first and second request are completed the system will be in fail state, now issue another state transition
   195 	// Creates and open the result file for streaming
   207 	// request to fail state again.
   196 	    err = iFileWriteStream.Replace(iFs, KGsaTestStateTranFromShutdownResult, EFileWrite);
   208 	// The first request to the fail state will be completed with KErrCancel 
   197 	    RDebug::Print(_L("\nStateTran Test: iFileWriteStream open with %d\n"), err);
   209 	// the second request to transit to the fail state will be completed with KErrNone.
   198 
   210 	// the third request to transit to the fail state will be completed with KErrNotSupported.
   199 
   211 	
   200 	    // Gets the Current system state before starting the test
   212 	RDebug::Print(_L("\nStateTran Test: Scenario 4 \n"));
   201 	    CurrentSystemStateL();
   213 	stateMan.RequestStateTransition(stateTrans3, status1);
   202 
   214 	RDebug::Print(_L("\nStateTran Test: Start First RequestStateTransition from Normal to fail state %d\n "), status1.Int());
   203 	    //Scenario 1 - Request for state change from Normal to shutdown state to critical substate
   215 	
   204 	    // Cancel the request immediately
   216 	stateMan.RequestStateTransition(stateTrans3, status2);
   205 	    RDebug::Print(_L("\nScenario 1 \n"));
   217 	RDebug::Print(_L("\nStateTran Test: Start Second RequestStateTransition from Normal to fail state %d\n "), status2.Int());
   206 	    TRequestStatus status_shutdowncritsubstate;
   218 
   207 	    /*TSsmState shutdownState_Critical(ESsmShutdown, ESsmShutdownSubStateCritical);
   219 	User::WaitForRequest(status1);
   208 	    TSsmStateTransition stateTrans_Shutdowncritical(shutdownState_Critical, 1);*/
   220 	iFileWriteStream.WriteInt32L(status1.Int());
   209 
   221 	if (status1.Int() == KErrCancel)
   210 	    stateMan.RequestStateTransition(stateTrans_Shutdowncritical, status_shutdowncritsubstate);
   222 		{
   211 	    RDebug::Print(_L("\n RequestStateTransition from Normal to shutdown state critical substate %d\n "), status_shutdowncritsubstate.Int());
   223 		RDebug::Print(_L("\nStateTran Test: First RequestStateTransition from Normal to fail state completes with %d Expected -3\n "), status1.Int());
   212 
   224 		CurrentSystemStateL();
   213 	    stateMan.RequestStateTransitionCancel();
   225 		}
   214 	    
   226 	else
   215 	    iFileWriteStream.WriteInt32L(status_shutdowncritsubstate.Int());
   227 		{
   216 	    if (status_shutdowncritsubstate.Int() == KErrCancel)
   228 		RDebug::Print(_L("\nStateTran Test: First RequestStateTransition from Normal to fail state Failed"));
   217 	        {
   229 		User::Leave(KTestAppFailure);		
   218 	        CurrentSystemStateL();
   230 		}
   219 	        RDebug::Print(_L("\n RequestStateTransition from Normal to shutdown state critical substate completed %d Expected -3\n "), status_shutdowncritsubstate.Int());
   231 
   220 	        }
   232 	User::WaitForRequest(status2);
   221 	    else
   233 	iFileWriteStream.WriteInt32L(status2.Int());
   222 	        User::Leave(KTestAppFailure);
   234 	if (status2.Int() == KErrNone)
   223 
   235 		{
   224 	    //Scenario 2 - Request for state change from Normal to shutdown state to any substate
   236 		RDebug::Print(_L("\nStateTran Test: Second RequestStateTransition from Normal to fail state %d Expected 0\n "), status2.Int());
   225 	    // Cancel the request immediately, so that we can proceed with the next test scenario.
   237 		CurrentSystemStateL();
   226 	    RDebug::Print(_L("\nScenario 2 \n"));
   238 		}
   227 	    TRequestStatus status_shutdownanysubstate;
   239 	else
   228 	    TSsmState shutdownState_Any(ESsmShutdown, KSsmAnySubState);
   240 		{
   229 	    TSsmStateTransition stateTrans_shutdownAnySubState(shutdownState_Any, 1);
   241 		RDebug::Print(_L("\nStateTran Test: Second RequestStateTransition from Normal to fail state Failed"));
   230 
   242 		User::Leave(KTestAppFailure);		
   231 	    stateMan.RequestStateTransition(stateTrans_shutdownAnySubState, status_shutdownanysubstate);
   243 		}
   232 	    RDebug::Print(_L("\n RequestStateTransition from Normal to shutdown state any substate %d\n "), status_shutdownanysubstate.Int());
   244 	
   233 
   245 	stateMan.RequestStateTransition(stateTrans3, status2); //System is in fail state
   234 	    stateMan.RequestStateTransitionCancel();
   246 	RDebug::Print(_L("\nStateTran Test: Start RequestStateTransition from fail to fail state %d\n "), status2.Int());
   235 	    
   247 	
   236 	    iFileWriteStream.WriteInt32L(status_shutdownanysubstate.Int());
   248 	User::WaitForRequest(status2);
   237 	    if (status_shutdownanysubstate.Int() == KErrCancel)
   249 	iFileWriteStream.WriteInt32L(status2.Int());
   238 	        {
   250 	if (status2.Int() == KErrNotSupported)
   239 	        CurrentSystemStateL();
   251 		{
   240 	        RDebug::Print(_L("\n RequestStateTransition from Normal to shutdown state any substate completed %d Expected -3\n "), status_shutdownanysubstate.Int());
   252 		RDebug::Print(_L("\nStateTran Test: RequestStateTransition from fail to fail state completed with %d Expected -5\n "), status2.Int());
   241 	        }
   253 		CurrentSystemStateL();
   242 	    else
   254 		}
   243 	        User::Leave(KTestAppFailure);
   255 	else
   244 	    
   256 		{
   245 	    iFileWriteStream.Close();
   257 		RDebug::Print(_L("\nStateTran Test: RequestStateTransition from fail to fail state Failed"));
   246 	    
   258 		User::Leave(KTestAppFailure);
   247 	    // Creates and open the result file for streaming
   259 		}
   248 	        err = iFileWriteStream.Replace(iFs, KGsaTestStateTranToShutdownResult, EFileWrite);
       
   249 	        RDebug::Print(_L("\nStateTran Test: iFileWriteStream open with %d\n"), err);
       
   250 
       
   251 
       
   252 	        // Gets the Current system state before starting the test
       
   253 	        CurrentSystemStateL();
       
   254 
       
   255 	        //Scenario 1 - Request for state transition to shutdown state - invalid substate
       
   256 	        // request to transit to the shutdown state will be completed with KErrNotSupported
       
   257 	        RDebug::Print(_L("\nScenario 1 \n"));
       
   258 
       
   259 	        TRequestStatus status_invalidsubstate;
       
   260 	        TSsmState shutdownState_Invalid(ESsmShutdown, 150);
       
   261 	        TSsmStateTransition stateTrans_Invalid(shutdownState_Invalid, 1);
       
   262 
       
   263 	        stateMan.RequestStateTransition(stateTrans_Invalid, status_invalidsubstate);
       
   264 	        RDebug::Print(_L("\n Start RequestStateTransition from Normal to shutdown state with invalid substate %d\n "), status_invalidsubstate.Int());
       
   265 	        
       
   266 	        User::WaitForRequest(status_invalidsubstate);
       
   267 	        iFileWriteStream.WriteInt32L(status_invalidsubstate.Int());
       
   268 	        if (status_invalidsubstate.Int() == KErrNotSupported)
       
   269 	            {
       
   270 	            CurrentSystemStateL();
       
   271 	            RDebug::Print(_L("\n RequestStateTransition from Normal to shutdown state with invalid substate completes with %d Expected -5\n "), status_invalidsubstate.Int());
       
   272 	            }
       
   273 	        else
       
   274 	            User::Leave(KTestAppFailure);
       
   275 	        
       
   276 	        iFileWriteStream.Close();
       
   277 	    CleanupStack::PopAndDestroy(&stateMan);
       
   278 	}
   260 	}
   279 
   261 
   280 void CStateTranFromNormal::StartTestL()
   262 void CStateTranFromNormal::StartTestL()
   281 	{
   263 	{
   282 	CActiveScheduler* sched=new(ELeave) CActiveScheduler;
   264 	CActiveScheduler* sched=new(ELeave) CActiveScheduler;
   283 	CleanupStack::PushL(sched);
   265 	CleanupStack::PushL(sched);
   284 	CActiveScheduler::Install(sched);
   266 	CActiveScheduler::Install(sched);
       
   267 
       
   268 	// Notifier used to get the notification when system gets to fail state
       
   269 	CSsmStateAwareSession* notif_for_failstate = CSsmStateAwareSession::NewLC(KSM2UiServicesDomain3);
       
   270 	notif_for_failstate->AddSubscriberL(*this);
   285 
   271 
   286 	// This async callback is used to start the state transition test once system enters to normal state.
   272 	// This async callback is used to start the state transition test once system enters to normal state.
   287 	iAsyncCallbackForStartTest =  new(ELeave) CAsyncCallBack(CActive::EPriorityIdle);
   273 	iAsyncCallbackForStartTest =  new(ELeave) CAsyncCallBack(CActive::EPriorityIdle);
   288 	TCallBack startTestCallback(StartTest, this);
   274 	TCallBack startTestCallback(StartTest, this);
   289 	iAsyncCallbackForStartTest->Set(startTestCallback);
   275 	iAsyncCallbackForStartTest->Set(startTestCallback);
   292 	iAsyncCallbackForStartTest->CallBack();
   278 	iAsyncCallbackForStartTest->CallBack();
   293 	
   279 	
   294 	RProcess::Rendezvous(KErrNone);
   280 	RProcess::Rendezvous(KErrNone);
   295 	sched->Start();
   281 	sched->Start();
   296 
   282 
   297 	CleanupStack::PopAndDestroy(1);
   283 	CleanupStack::PopAndDestroy(2);
   298 	}
   284 	}
   299 
   285 
   300 TInt E32Main()
   286 TInt E32Main()
   301 	{
   287 	{
   302 	__UHEAP_MARK;
   288 	__UHEAP_MARK;