sysstatemgmt/systemstateplugins/test/tintgsapolicy/src/tgsastatetranfromnormal.cpp
changeset 63 09d657f1ee00
parent 0 4e1aa6a622a0
child 61 8cb079868133
equal deleted inserted replaced
54:072a9626b290 63:09d657f1ee00
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2008-2010 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 static TInt StopScheduler(TAny* aStateTranFromNormal)
    49 
    50  	{
       
    51  	CStateTranFromNormal* stateTran = reinterpret_cast<CStateTranFromNormal*>(aStateTranFromNormal);
       
    52  	TRAPD(err,stateTran->CallStopSchedulerL());
       
    53  	return err;
       
    54  	}
       
    55 
    50 
    56 static TInt StartTest(TAny* aStateTranFromNormal)
    51 static TInt StartTest(TAny* aStateTranFromNormal)
    57  	{
    52  	{
    58  	TInt testCompletionReason = KErrNone;
    53  	TInt testCompletionReason = KErrNone;
    59  	CStateTranFromNormal* stateTran = reinterpret_cast<CStateTranFromNormal*>(aStateTranFromNormal);
    54  	CStateTranFromNormal* stateTran = reinterpret_cast<CStateTranFromNormal*>(aStateTranFromNormal);
    85 	}
    80 	}
    86 
    81 
    87 // Tests the Fail state transitions under different scenarios
    82 // Tests the Fail state transitions under different scenarios
    88 void CStateTranFromNormal::DoTestStateTranFromNormalL()
    83 void CStateTranFromNormal::DoTestStateTranFromNormalL()
    89 	{
    84 	{
    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 
       
    98 	RSsmStateManager stateMan;
    85 	RSsmStateManager stateMan;
    99 	TInt err = stateMan.Connect();
    86 	TInt err = stateMan.Connect();
       
    87 	CleanupClosePushL(stateMan);
   100 	if (err == KErrNone)
    88 	if (err == KErrNone)
   101 		RDebug::Print(_L("\nStateTran Test: RSsmStateManager sess Connect %d\n"), err);
    89 		RDebug::Print(_L("\nStateTran Test: RSsmStateManager sess Connect %d\n"), err);
   102 	else
    90 	else
   103 		{
    91 		{
   104 		RDebug::Print(_L("\nStateTran Test: Unable to connect to RSsmStateManager sess\n"));	
    92 		RDebug::Print(_L("\nStateTran Test: Unable to connect to RSsmStateManager sess\n"));	
   199 	else
   187 	else
   200 		{
   188 		{
   201 		RDebug::Print(_L("\nStateTran Test: RequestStateTransition from Normal to shutdown state Failed"));
   189 		RDebug::Print(_L("\nStateTran Test: RequestStateTransition from Normal to shutdown state Failed"));
   202 		User::Leave(KTestAppFailure);		
   190 		User::Leave(KTestAppFailure);		
   203 		}
   191 		}
   204 
   192 	
   205 	//Scenario 4 - Request for two state changes one after the other without waiting for the first one to complete
   193 	iFileWriteStream.Close();
   206 	// Once first and second request are completed the system will be in fail state, now issue another state transition
   194 	
   207 	// request to fail state again.
   195 	// Creates and open the result file for streaming
   208 	// The first request to the fail state will be completed with KErrCancel 
   196 	    err = iFileWriteStream.Replace(iFs, KGsaTestStateTranFromShutdownResult, EFileWrite);
   209 	// the second request to transit to the fail state will be completed with KErrNone.
   197 	    RDebug::Print(_L("\nStateTran Test: iFileWriteStream open with %d\n"), err);
   210 	// the third request to transit to the fail state will be completed with KErrNotSupported.
   198 
   211 	
   199 
   212 	RDebug::Print(_L("\nStateTran Test: Scenario 4 \n"));
   200 	    // Gets the Current system state before starting the test
   213 	stateMan.RequestStateTransition(stateTrans3, status1);
   201 	    CurrentSystemStateL();
   214 	RDebug::Print(_L("\nStateTran Test: Start First RequestStateTransition from Normal to fail state %d\n "), status1.Int());
   202 
   215 	
   203 	    //Scenario 1 - Request for state change from Normal to shutdown state to critical substate
   216 	stateMan.RequestStateTransition(stateTrans3, status2);
   204 	    // Cancel the request immediately
   217 	RDebug::Print(_L("\nStateTran Test: Start Second RequestStateTransition from Normal to fail state %d\n "), status2.Int());
   205 	    RDebug::Print(_L("\nScenario 1 \n"));
   218 
   206 	    TRequestStatus status_shutdowncritsubstate;
   219 	User::WaitForRequest(status1);
   207 	    /*TSsmState shutdownState_Critical(ESsmShutdown, ESsmShutdownSubStateCritical);
   220 	iFileWriteStream.WriteInt32L(status1.Int());
   208 	    TSsmStateTransition stateTrans_Shutdowncritical(shutdownState_Critical, 1);*/
   221 	if (status1.Int() == KErrCancel)
   209 
   222 		{
   210 	    stateMan.RequestStateTransition(stateTrans_Shutdowncritical, status_shutdowncritsubstate);
   223 		RDebug::Print(_L("\nStateTran Test: First RequestStateTransition from Normal to fail state completes with %d Expected -3\n "), status1.Int());
   211 	    RDebug::Print(_L("\n RequestStateTransition from Normal to shutdown state critical substate %d\n "), status_shutdowncritsubstate.Int());
   224 		CurrentSystemStateL();
   212 
   225 		}
   213 	    stateMan.RequestStateTransitionCancel();
   226 	else
   214 	    
   227 		{
   215 	    iFileWriteStream.WriteInt32L(status_shutdowncritsubstate.Int());
   228 		RDebug::Print(_L("\nStateTran Test: First RequestStateTransition from Normal to fail state Failed"));
   216 	    if (status_shutdowncritsubstate.Int() == KErrCancel)
   229 		User::Leave(KTestAppFailure);		
   217 	        {
   230 		}
   218 	        CurrentSystemStateL();
   231 
   219 	        RDebug::Print(_L("\n RequestStateTransition from Normal to shutdown state critical substate completed %d Expected -3\n "), status_shutdowncritsubstate.Int());
   232 	User::WaitForRequest(status2);
   220 	        }
   233 	iFileWriteStream.WriteInt32L(status2.Int());
   221 	    else
   234 	if (status2.Int() == KErrNone)
   222 	        User::Leave(KTestAppFailure);
   235 		{
   223 
   236 		RDebug::Print(_L("\nStateTran Test: Second RequestStateTransition from Normal to fail state %d Expected 0\n "), status2.Int());
   224 	    //Scenario 2 - Request for state change from Normal to shutdown state to any substate
   237 		CurrentSystemStateL();
   225 	    // Cancel the request immediately, so that we can proceed with the next test scenario.
   238 		}
   226 	    RDebug::Print(_L("\nScenario 2 \n"));
   239 	else
   227 	    TRequestStatus status_shutdownanysubstate;
   240 		{
   228 	    TSsmState shutdownState_Any(ESsmShutdown, KSsmAnySubState);
   241 		RDebug::Print(_L("\nStateTran Test: Second RequestStateTransition from Normal to fail state Failed"));
   229 	    TSsmStateTransition stateTrans_shutdownAnySubState(shutdownState_Any, 1);
   242 		User::Leave(KTestAppFailure);		
   230 
   243 		}
   231 	    stateMan.RequestStateTransition(stateTrans_shutdownAnySubState, status_shutdownanysubstate);
   244 	
   232 	    RDebug::Print(_L("\n RequestStateTransition from Normal to shutdown state any substate %d\n "), status_shutdownanysubstate.Int());
   245 	stateMan.RequestStateTransition(stateTrans3, status2); //System is in fail state
   233 
   246 	RDebug::Print(_L("\nStateTran Test: Start RequestStateTransition from fail to fail state %d\n "), status2.Int());
   234 	    stateMan.RequestStateTransitionCancel();
   247 	
   235 	    
   248 	User::WaitForRequest(status2);
   236 	    iFileWriteStream.WriteInt32L(status_shutdownanysubstate.Int());
   249 	iFileWriteStream.WriteInt32L(status2.Int());
   237 	    if (status_shutdownanysubstate.Int() == KErrCancel)
   250 	if (status2.Int() == KErrNotSupported)
   238 	        {
   251 		{
   239 	        CurrentSystemStateL();
   252 		RDebug::Print(_L("\nStateTran Test: RequestStateTransition from fail to fail state completed with %d Expected -5\n "), status2.Int());
   240 	        RDebug::Print(_L("\n RequestStateTransition from Normal to shutdown state any substate completed %d Expected -3\n "), status_shutdownanysubstate.Int());
   253 		CurrentSystemStateL();
   241 	        }
   254 		}
   242 	    else
   255 	else
   243 	        User::Leave(KTestAppFailure);
   256 		{
   244 	    
   257 		RDebug::Print(_L("\nStateTran Test: RequestStateTransition from fail to fail state Failed"));
   245 	    iFileWriteStream.Close();
   258 		User::Leave(KTestAppFailure);
   246 	    
   259 		}
   247 	    // Creates and open the result file for streaming
       
   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);
   260 	}
   278 	}
   261 
   279 
   262 void CStateTranFromNormal::StartTestL()
   280 void CStateTranFromNormal::StartTestL()
   263 	{
   281 	{
   264 	CActiveScheduler* sched=new(ELeave) CActiveScheduler;
   282 	CActiveScheduler* sched=new(ELeave) CActiveScheduler;
   265 	CleanupStack::PushL(sched);
   283 	CleanupStack::PushL(sched);
   266 	CActiveScheduler::Install(sched);
   284 	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);
       
   271 
   285 
   272 	// This async callback is used to start the state transition test once system enters to normal state.
   286 	// This async callback is used to start the state transition test once system enters to normal state.
   273 	iAsyncCallbackForStartTest =  new(ELeave) CAsyncCallBack(CActive::EPriorityIdle);
   287 	iAsyncCallbackForStartTest =  new(ELeave) CAsyncCallBack(CActive::EPriorityIdle);
   274 	TCallBack startTestCallback(StartTest, this);
   288 	TCallBack startTestCallback(StartTest, this);
   275 	iAsyncCallbackForStartTest->Set(startTestCallback);
   289 	iAsyncCallbackForStartTest->Set(startTestCallback);
   278 	iAsyncCallbackForStartTest->CallBack();
   292 	iAsyncCallbackForStartTest->CallBack();
   279 	
   293 	
   280 	RProcess::Rendezvous(KErrNone);
   294 	RProcess::Rendezvous(KErrNone);
   281 	sched->Start();
   295 	sched->Start();
   282 
   296 
   283 	CleanupStack::PopAndDestroy(2);
   297 	CleanupStack::PopAndDestroy(1);
   284 	}
   298 	}
   285 
   299 
   286 TInt E32Main()
   300 TInt E32Main()
   287 	{
   301 	{
   288 	__UHEAP_MARK;
   302 	__UHEAP_MARK;