sysstatemgmt/systemstateplugins/test/tintgsapolicy/src/tgsastatetranfromstartup.cpp
branchRCL_3
changeset 21 ccb4f6b3db21
parent 0 4e1aa6a622a0
child 22 8cb079868133
equal deleted inserted replaced
20:1ddbe54d0645 21:ccb4f6b3db21
     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".
    41 	void ConstructL();
    41 	void ConstructL();
    42 	CStateTranFromStartup();
    42 	CStateTranFromStartup();
    43 
    43 
    44 public:
    44 public:
    45 	void DoTestStateTranFromStartupL();
    45 	void DoTestStateTranFromStartupL();
    46 	void DoTestStateTranFromStartuptoShutdownL();
       
    47 	};
    46 	};
    48 
    47 
    49 static TInt StopScheduler(TAny* aStateTranFromStartup)
       
    50  	{
       
    51  	CStateTranFromStartup* stateTran = reinterpret_cast<CStateTranFromStartup*>(aStateTranFromStartup);
       
    52  	TRAPD(err,stateTran->CallStopSchedulerL());
       
    53  	return err;
       
    54  	}
       
    55 
    48 
    56 CStateTranFromStartup* CStateTranFromStartup::NewL()
    49 CStateTranFromStartup* CStateTranFromStartup::NewL()
    57 	{
    50 	{
    58 	CStateTranFromStartup* self = new(ELeave) CStateTranFromStartup();
    51 	CStateTranFromStartup* self = new(ELeave) CStateTranFromStartup();
    59 	self->ConstructL();
    52 	self->ConstructL();
    71 
    64 
    72 CStateTranFromStartup::CStateTranFromStartup()
    65 CStateTranFromStartup::CStateTranFromStartup()
    73 	{
    66 	{
    74 	}
    67 	}
    75 
    68 
    76 // Tests the Fail state transitions from startup under different scenarios
    69 // Tests Invalid state transition from startup
    77 void CStateTranFromStartup::DoTestStateTranFromStartupL()
    70 void CStateTranFromStartup::DoTestStateTranFromStartupL()
    78 	{
    71 	{
    79 	CActiveScheduler* sched=new(ELeave) CActiveScheduler;
       
    80 	CleanupStack::PushL(sched);
       
    81 	CActiveScheduler::Install(sched);
       
    82 	
       
    83 	// Notifier used to get the notification when system gets to fail state
       
    84 	CSsmStateAwareSession* notif_for_failstate = CSsmStateAwareSession::NewLC(KSM2UiServicesDomain3);
       
    85 	notif_for_failstate->AddSubscriberL(*this);
       
    86 
       
    87 	RSsmStateManager stateMan;
    72 	RSsmStateManager stateMan;
    88 	TInt err = stateMan.Connect();
    73 	TInt err = stateMan.Connect();
    89 	CleanupClosePushL(stateMan);
    74 	CleanupClosePushL(stateMan);
    90 	if (err == KErrNone)
    75 	if (err == KErrNone)
    91 		RDebug::Print(_L("\nStateTran Test: RSsmStateManager sess Connect %d\n"), err);
    76 		RDebug::Print(_L("\nStateTran Test: RSsmStateManager sess Connect %d\n"), err);
   112 	User::WaitForRequest(status);
    97 	User::WaitForRequest(status);
   113 	iFileWriteStream.WriteInt32L(status.Int());
    98 	iFileWriteStream.WriteInt32L(status.Int());
   114 	if (status.Int() == KErrNotSupported)
    99 	if (status.Int() == KErrNotSupported)
   115 		{
   100 		{
   116 		CurrentSystemStateL();
   101 		CurrentSystemStateL();
   117 		RDebug::Print(_L("\nStateTran Test: RequestStateTransition from Normal to Invalid state completes with %d Expected -5\n "), status.Int());
   102 		RDebug::Print(_L("\nStateTran Test: RequestStateTransition from Startup to Invalid state completes with %d Expected -5\n "), status.Int());
   118 		}
   103 		}
   119 	else
   104 	else
   120 		{
   105 		{
   121 		RDebug::Print(_L("\nStateTran Test: RequestStateTransition from Normal to Invalid state Failed"));
   106 		RDebug::Print(_L("\nStateTran Test: RequestStateTransition from Startup to Invalid state Failed"));
   122 		User::Leave(KTestAppFailure);
   107 		User::Leave(KTestAppFailure);
   123 		}
   108 		}
   124 
   109 
   125 	//Scenario 2 - Request for state change from Startup to fail state with invalid substate
   110 	CleanupStack::PopAndDestroy(&stateMan);
   126 	RDebug::Print(_L("\nStateTran Test: Scenario 2 \n"));
       
   127 	const TInt KInvalidFailSubState = 20;
       
   128 	state.Set(ESsmFail, KInvalidFailSubState);
       
   129 	TSsmStateTransition stateTrans_InvalidSubState(state, 1);
       
   130 
       
   131 	stateMan.RequestStateTransition(stateTrans_InvalidSubState, status);
       
   132 	RDebug::Print(_L("\nStateTran Test: Start RequestStateTransition from Startup to fail state with invalid substate %d\n "), status.Int());
       
   133 	
       
   134 	User::WaitForRequest(status);
       
   135 	iFileWriteStream.WriteInt32L(status.Int());
       
   136 	if (status.Int() == KErrNotSupported)
       
   137 		{
       
   138 		RDebug::Print(_L("\nStateTran Test: RequestStateTransition from Startup to fail state with invalid substate completes with %d Expected -5\n "), status.Int());
       
   139 		CurrentSystemStateL();
       
   140 		}
       
   141 	else
       
   142 		{
       
   143 		RDebug::Print(_L("\nStateTran Test: RequestStateTransition from Startup to fail state with invalid substate Failed"));
       
   144 		User::Leave(KTestAppFailure);		
       
   145 		}
       
   146 
       
   147 	//Scenario 3 - Request for state change from Startup to shutdown invalid substate
       
   148 	RDebug::Print(_L("\nStateTran Test: Scenario 3 \n"));
       
   149 	TRequestStatus status1;
       
   150 	const TInt KInvalidShutdownSubState = 15;
       
   151 	TSsmState shutdownState_Invalid(ESsmShutdown, KInvalidShutdownSubState);
       
   152 	TSsmStateTransition stateTrans_ShutdownInvalid(shutdownState_Invalid, 1);
       
   153 
       
   154 	stateMan.RequestStateTransition(stateTrans_ShutdownInvalid, status);
       
   155 	RDebug::Print(_L("\nStateTran Test: Start RequestStateTransition from Startup to Shutdown state with Invalid Substate %d\n "), status.Int());
       
   156 	
       
   157 	User::WaitForRequest(status);
       
   158 	iFileWriteStream.WriteInt32L(status.Int());
       
   159 	if (status.Int() == KErrNotSupported)
       
   160 		{
       
   161 		RDebug::Print(_L("\nStateTran Test: RequestStateTransition from Startup to Shutdown state with invalid substate completes with %d Expected -5\n "), status.Int());
       
   162 		CurrentSystemStateL();
       
   163 		}
       
   164 	else
       
   165 		{
       
   166 		RDebug::Print(_L("\nStateTran Test: RequestStateTransition from Startup to fail state with invalid substate Failed"));
       
   167 		User::Leave(KTestAppFailure);		
       
   168 		}
       
   169 
       
   170 	//Scenario 4 - Request for two state changes to fail state one after the other
       
   171 	//The first request to the fail state will be completed with KErrCancel and the second request to transit to the fail state will be completed with KErrNone.
       
   172 	RDebug::Print(_L("\nStateTran Test: Scenario 4 \n"));
       
   173 	state.Set(ESsmFail, KSsmAnySubState);
       
   174 	TSsmStateTransition stateTrans_fail(state, 1);
       
   175 
       
   176 	stateMan.RequestStateTransition(stateTrans_fail, status);
       
   177 	RDebug::Print(_L("\nStateTran Test: Start First RequestStateTransition from Startup to fail state %d\n "), status.Int());
       
   178 	
       
   179 	stateMan.RequestStateTransition(stateTrans_fail, status1);
       
   180 	RDebug::Print(_L("\nStateTran Test: Start Second RequestStateTransition from Startup to fail state %d\n "), status1.Int());
       
   181 	
       
   182 	User::WaitForRequest(status);
       
   183 	iFileWriteStream.WriteInt32L(status.Int());
       
   184 	if (status.Int() == KErrCancel)
       
   185 		{
       
   186 		RDebug::Print(_L("\nStateTran Test: First RequestStateTransition from Startup to fail state completes with %d Expected -3\n "), status.Int());
       
   187 		CurrentSystemStateL();
       
   188 		}
       
   189 	else
       
   190 		{
       
   191 		RDebug::Print(_L("\nStateTran Test: First RequestStateTransition from Startup to fail state Failed"));
       
   192 		User::Leave(KTestAppFailure);		
       
   193 		}
       
   194 
       
   195 	User::WaitForRequest(status1);
       
   196 	iFileWriteStream.WriteInt32L(status1.Int());
       
   197 	if (status1.Int() == KErrNone)
       
   198 		{
       
   199 		RDebug::Print(_L("\nStateTran Test: Second RequestStateTransition from Startup to fail state completes %d Expected 0\n "), status1.Int());
       
   200 		CurrentSystemStateL();
       
   201 		}
       
   202 	else
       
   203 		{
       
   204 		RDebug::Print(_L("\nStateTran Test: Second RequestStateTransition from Startup to fail state Failed"));
       
   205 		User::Leave(KTestAppFailure);		
       
   206 		}
       
   207 
       
   208 	// This async callback is used to stop the scheduler once the system goes into fail state.
       
   209 	iAsyncCallbackForStopScheduler =  new(ELeave) CAsyncCallBack(CActive::EPriorityIdle);
       
   210 	TCallBack stopSchedulerCallback(StopScheduler, this);
       
   211 	iAsyncCallbackForStopScheduler->Set(stopSchedulerCallback);
       
   212 
       
   213 	iAsyncCallbackForStopScheduler->CallBack();
       
   214 	sched->Start();
       
   215 
       
   216 	CleanupStack::PopAndDestroy(3);
       
   217 	}
   111 	}
   218 
   112 
   219 // Tests the Shutdown state transitions from startup scenario
       
   220 void CStateTranFromStartup::DoTestStateTranFromStartuptoShutdownL()
       
   221 	{
       
   222 	RDebug::Printf("I am in CStateTranFromStartup::DoTestStateTranFromStartupShutdownL");
       
   223 	CActiveScheduler* sched=new(ELeave) CActiveScheduler;
       
   224 	CleanupStack::PushL(sched);
       
   225 	CActiveScheduler::Install(sched);
       
   226 	
       
   227 	// Notifier used to get the notification when system gets to Shutdown state
       
   228 	CSsmStateAwareSession* notif_for_shutdownstate = CSsmStateAwareSession::NewLC(KSM2UiServicesDomain3);
       
   229 	notif_for_shutdownstate->AddSubscriberL(*this);
       
   230 
       
   231 	RSsmStateManager stateMan;
       
   232 	TRequestStatus status;
       
   233 	TInt err = stateMan.Connect();
       
   234 	CleanupClosePushL(stateMan);
       
   235 	if (err == KErrNone)
       
   236 		RDebug::Print(_L("\nStateTran Shutdown Test: RSsmStateManager sess Connect %d\n"), err);
       
   237 	else
       
   238 		{
       
   239 		RDebug::Print(_L("\nStateTran Shutdown Test: Unable to connect to RSsmStateManager sess\n"));	
       
   240 		User::Leave(KTestAppFailure);
       
   241 		}
       
   242 
       
   243 		// Creates and open the result file for streaming
       
   244 	err = iFileWriteStream.Replace(iFs, KGsaTestStateTranFromStartupResult, EFileWrite);
       
   245 	RDebug::Print(_L("\nStateTran Shutdown Test: iFileWriteStream open with %d\n"), err);
       
   246 
       
   247 	CurrentSystemStateL();
       
   248 
       
   249 	RDebug::Print(_L("\nStateTran Shutdown Test Scenario \n"));
       
   250 	TSsmState shutdownState_Critical(ESsmShutdown, ESsmShutdownSubStateCritical);
       
   251 	TSsmStateTransition stateTrans_ShutdownCritical(shutdownState_Critical, 1);
       
   252 
       
   253 	stateMan.RequestStateTransition(stateTrans_ShutdownCritical, status);
       
   254 	RDebug::Print(_L("\nStateTran Shutdown Test: Start RequestStateTransition from Startup to shutdown state %d\n "), status.Int());
       
   255 		
       
   256 	User::WaitForRequest(status);
       
   257 	iFileWriteStream.WriteInt32L(status.Int());
       
   258 	RDebug::Printf("The value of status is %d",status.Int());
       
   259 	if (status.Int() == KErrNone)
       
   260 		{
       
   261 		RDebug::Print(_L("\nStateTran Shutdown Test: RequestStateTransition from Startup to Shutdown state completes with %d Expected 0\n "), status.Int());
       
   262 		CurrentSystemStateL();
       
   263 		}
       
   264 	else
       
   265 		{
       
   266 		RDebug::Print(_L("\nStateTran Shutdown Test: RequestStateTransition from Startup to Shutdown state Failed"));
       
   267 		User::Leave(KTestAppFailure);		
       
   268 		}
       
   269 
       
   270 	// This async callback is used to stop the scheduler once the system goes into Shutdown state.
       
   271 	iAsyncCallbackForStopScheduler =  new(ELeave) CAsyncCallBack(CActive::EPriorityIdle);
       
   272 	TCallBack stopSchedulerCallback(StopScheduler, this);
       
   273 	iAsyncCallbackForStopScheduler->Set(stopSchedulerCallback);
       
   274 
       
   275 	iAsyncCallbackForStopScheduler->CallBack();
       
   276 	sched->Start();
       
   277 
       
   278 	CleanupStack::PopAndDestroy(3);
       
   279 
       
   280 	}
       
   281 
   113 
   282 TInt E32Main()
   114 TInt E32Main()
   283 	{
   115 	{
   284 	__UHEAP_MARK;
   116 	__UHEAP_MARK;
   285 
   117 
   292 		__UHEAP_MARK;
   124 		__UHEAP_MARK;
   293 		CStateTranFromStartup* stateTran = NULL;
   125 		CStateTranFromStartup* stateTran = NULL;
   294 		TRAP(r, stateTran = CStateTranFromStartup::NewL());
   126 		TRAP(r, stateTran = CStateTranFromStartup::NewL());
   295 		if (r == KErrNone)
   127 		if (r == KErrNone)
   296 			{
   128 			{
   297 			if(argc>0)
   129 			TRAP(testCompletionReason, stateTran->DoTestStateTranFromStartupL());
   298 				{
       
   299 				TRAP(testCompletionReason, stateTran->DoTestStateTranFromStartuptoShutdownL());
       
   300 				}
       
   301 			else
       
   302 				{
       
   303 				TRAP(testCompletionReason, stateTran->DoTestStateTranFromStartupL());
       
   304 				}
       
   305 			// testCompletionReason is the reason with which the test case completes.
   130 			// testCompletionReason is the reason with which the test case completes.
   306 			TRAP(r, stateTran->CommitTestResultsL(testCompletionReason));
   131 			TRAP(r, stateTran->CommitTestResultsL(testCompletionReason));
   307 			
   132 			
   308 			// Rendezvous'ng the process as it started as WaitForSignal execution behaviour
   133 			// Rendezvous'ng the process as it started as WaitForSignal execution behaviour
   309 			RProcess::Rendezvous(KErrNone);
   134 			RProcess::Rendezvous(KErrNone);