--- a/sysstatemgmt/systemstateplugins/test/tintgsapolicy/src/tgsastatetranfromnormal.cpp Tue Aug 31 16:29:05 2010 +0300
+++ b/sysstatemgmt/systemstateplugins/test/tintgsapolicy/src/tgsastatetranfromnormal.cpp Wed Sep 01 12:34:26 2010 +0100
@@ -1,4 +1,4 @@
-// Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
// All rights reserved.
// This component and the accompanying materials are made available
// under the terms of "Eclipse Public License v1.0"
@@ -46,7 +46,12 @@
void DoTestStateTranFromNormalL();
};
-
+static TInt StopScheduler(TAny* aStateTranFromNormal)
+ {
+ CStateTranFromNormal* stateTran = reinterpret_cast<CStateTranFromNormal*>(aStateTranFromNormal);
+ TRAPD(err,stateTran->CallStopSchedulerL());
+ return err;
+ }
static TInt StartTest(TAny* aStateTranFromNormal)
{
@@ -82,9 +87,16 @@
// Tests the Fail state transitions under different scenarios
void CStateTranFromNormal::DoTestStateTranFromNormalL()
{
+ // This async callback is used to stop the scheduler once the system goes into fail state.
+ iAsyncCallbackForStopScheduler = new(ELeave) CAsyncCallBack(CActive::EPriorityIdle);
+ TCallBack stopSchedulerCallback(StopScheduler, this);
+ iAsyncCallbackForStopScheduler->Set(stopSchedulerCallback);
+
+ // call the callback function which keeps looping until the system state gets into fail state.
+ iAsyncCallbackForStopScheduler->CallBack();
+
RSsmStateManager stateMan;
TInt err = stateMan.Connect();
- CleanupClosePushL(stateMan);
if (err == KErrNone)
RDebug::Print(_L("\nStateTran Test: RSsmStateManager sess Connect %d\n"), err);
else
@@ -189,92 +201,62 @@
RDebug::Print(_L("\nStateTran Test: RequestStateTransition from Normal to shutdown state Failed"));
User::Leave(KTestAppFailure);
}
-
- iFileWriteStream.Close();
-
- // Creates and open the result file for streaming
- err = iFileWriteStream.Replace(iFs, KGsaTestStateTranFromShutdownResult, EFileWrite);
- RDebug::Print(_L("\nStateTran Test: iFileWriteStream open with %d\n"), err);
-
-
- // Gets the Current system state before starting the test
- CurrentSystemStateL();
-
- //Scenario 1 - Request for state change from Normal to shutdown state to critical substate
- // Cancel the request immediately
- RDebug::Print(_L("\nScenario 1 \n"));
- TRequestStatus status_shutdowncritsubstate;
- /*TSsmState shutdownState_Critical(ESsmShutdown, ESsmShutdownSubStateCritical);
- TSsmStateTransition stateTrans_Shutdowncritical(shutdownState_Critical, 1);*/
-
- stateMan.RequestStateTransition(stateTrans_Shutdowncritical, status_shutdowncritsubstate);
- RDebug::Print(_L("\n RequestStateTransition from Normal to shutdown state critical substate %d\n "), status_shutdowncritsubstate.Int());
- stateMan.RequestStateTransitionCancel();
-
- iFileWriteStream.WriteInt32L(status_shutdowncritsubstate.Int());
- if (status_shutdowncritsubstate.Int() == KErrCancel)
- {
- CurrentSystemStateL();
- RDebug::Print(_L("\n RequestStateTransition from Normal to shutdown state critical substate completed %d Expected -3\n "), status_shutdowncritsubstate.Int());
- }
- else
- User::Leave(KTestAppFailure);
+ //Scenario 4 - Request for two state changes one after the other without waiting for the first one to complete
+ // Once first and second request are completed the system will be in fail state, now issue another state transition
+ // request to fail state again.
+ // The first request to the fail state will be completed with KErrCancel
+ // the second request to transit to the fail state will be completed with KErrNone.
+ // the third request to transit to the fail state will be completed with KErrNotSupported.
+
+ RDebug::Print(_L("\nStateTran Test: Scenario 4 \n"));
+ stateMan.RequestStateTransition(stateTrans3, status1);
+ RDebug::Print(_L("\nStateTran Test: Start First RequestStateTransition from Normal to fail state %d\n "), status1.Int());
+
+ stateMan.RequestStateTransition(stateTrans3, status2);
+ RDebug::Print(_L("\nStateTran Test: Start Second RequestStateTransition from Normal to fail state %d\n "), status2.Int());
- //Scenario 2 - Request for state change from Normal to shutdown state to any substate
- // Cancel the request immediately, so that we can proceed with the next test scenario.
- RDebug::Print(_L("\nScenario 2 \n"));
- TRequestStatus status_shutdownanysubstate;
- TSsmState shutdownState_Any(ESsmShutdown, KSsmAnySubState);
- TSsmStateTransition stateTrans_shutdownAnySubState(shutdownState_Any, 1);
-
- stateMan.RequestStateTransition(stateTrans_shutdownAnySubState, status_shutdownanysubstate);
- RDebug::Print(_L("\n RequestStateTransition from Normal to shutdown state any substate %d\n "), status_shutdownanysubstate.Int());
+ User::WaitForRequest(status1);
+ iFileWriteStream.WriteInt32L(status1.Int());
+ if (status1.Int() == KErrCancel)
+ {
+ RDebug::Print(_L("\nStateTran Test: First RequestStateTransition from Normal to fail state completes with %d Expected -3\n "), status1.Int());
+ CurrentSystemStateL();
+ }
+ else
+ {
+ RDebug::Print(_L("\nStateTran Test: First RequestStateTransition from Normal to fail state Failed"));
+ User::Leave(KTestAppFailure);
+ }
- stateMan.RequestStateTransitionCancel();
-
- iFileWriteStream.WriteInt32L(status_shutdownanysubstate.Int());
- if (status_shutdownanysubstate.Int() == KErrCancel)
- {
- CurrentSystemStateL();
- RDebug::Print(_L("\n RequestStateTransition from Normal to shutdown state any substate completed %d Expected -3\n "), status_shutdownanysubstate.Int());
- }
- else
- User::Leave(KTestAppFailure);
-
- iFileWriteStream.Close();
-
- // Creates and open the result file for streaming
- err = iFileWriteStream.Replace(iFs, KGsaTestStateTranToShutdownResult, EFileWrite);
- RDebug::Print(_L("\nStateTran Test: iFileWriteStream open with %d\n"), err);
-
-
- // Gets the Current system state before starting the test
- CurrentSystemStateL();
-
- //Scenario 1 - Request for state transition to shutdown state - invalid substate
- // request to transit to the shutdown state will be completed with KErrNotSupported
- RDebug::Print(_L("\nScenario 1 \n"));
-
- TRequestStatus status_invalidsubstate;
- TSsmState shutdownState_Invalid(ESsmShutdown, 150);
- TSsmStateTransition stateTrans_Invalid(shutdownState_Invalid, 1);
-
- stateMan.RequestStateTransition(stateTrans_Invalid, status_invalidsubstate);
- RDebug::Print(_L("\n Start RequestStateTransition from Normal to shutdown state with invalid substate %d\n "), status_invalidsubstate.Int());
-
- User::WaitForRequest(status_invalidsubstate);
- iFileWriteStream.WriteInt32L(status_invalidsubstate.Int());
- if (status_invalidsubstate.Int() == KErrNotSupported)
- {
- CurrentSystemStateL();
- RDebug::Print(_L("\n RequestStateTransition from Normal to shutdown state with invalid substate completes with %d Expected -5\n "), status_invalidsubstate.Int());
- }
- else
- User::Leave(KTestAppFailure);
-
- iFileWriteStream.Close();
- CleanupStack::PopAndDestroy(&stateMan);
+ User::WaitForRequest(status2);
+ iFileWriteStream.WriteInt32L(status2.Int());
+ if (status2.Int() == KErrNone)
+ {
+ RDebug::Print(_L("\nStateTran Test: Second RequestStateTransition from Normal to fail state %d Expected 0\n "), status2.Int());
+ CurrentSystemStateL();
+ }
+ else
+ {
+ RDebug::Print(_L("\nStateTran Test: Second RequestStateTransition from Normal to fail state Failed"));
+ User::Leave(KTestAppFailure);
+ }
+
+ stateMan.RequestStateTransition(stateTrans3, status2); //System is in fail state
+ RDebug::Print(_L("\nStateTran Test: Start RequestStateTransition from fail to fail state %d\n "), status2.Int());
+
+ User::WaitForRequest(status2);
+ iFileWriteStream.WriteInt32L(status2.Int());
+ if (status2.Int() == KErrNotSupported)
+ {
+ RDebug::Print(_L("\nStateTran Test: RequestStateTransition from fail to fail state completed with %d Expected -5\n "), status2.Int());
+ CurrentSystemStateL();
+ }
+ else
+ {
+ RDebug::Print(_L("\nStateTran Test: RequestStateTransition from fail to fail state Failed"));
+ User::Leave(KTestAppFailure);
+ }
}
void CStateTranFromNormal::StartTestL()
@@ -283,6 +265,10 @@
CleanupStack::PushL(sched);
CActiveScheduler::Install(sched);
+ // Notifier used to get the notification when system gets to fail state
+ CSsmStateAwareSession* notif_for_failstate = CSsmStateAwareSession::NewLC(KSM2UiServicesDomain3);
+ notif_for_failstate->AddSubscriberL(*this);
+
// This async callback is used to start the state transition test once system enters to normal state.
iAsyncCallbackForStartTest = new(ELeave) CAsyncCallBack(CActive::EPriorityIdle);
TCallBack startTestCallback(StartTest, this);
@@ -294,7 +280,7 @@
RProcess::Rendezvous(KErrNone);
sched->Start();
- CleanupStack::PopAndDestroy(1);
+ CleanupStack::PopAndDestroy(2);
}
TInt E32Main()