diff -r ccb4f6b3db21 -r 8cb079868133 sysstatemgmt/systemstateplugins/test/tintgsapolicy/src/tgsa_step_statetrantodiffstates.cpp --- a/sysstatemgmt/systemstateplugins/test/tintgsapolicy/src/tgsa_step_statetrantodiffstates.cpp Tue Aug 31 16:29:05 2010 +0300 +++ b/sysstatemgmt/systemstateplugins/test/tintgsapolicy/src/tgsa_step_statetrantodiffstates.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,101 +46,202 @@ if (iProcessName == KTestProcTranFromNormal) { - RFileReadStream fileReadStream1; - err = fileReadStream1.Open(fs, KGsaTestStateTranFromNormalResult, EFileRead); - INFO_PRINTF2(_L("Error in opening file: %d"), err); + RFileReadStream fileReadStream; + err = fileReadStream.Open(fs, KGsaTestStateTranFromNormalResult, EFileRead); TEST(err == KErrNone); User::LeaveIfError(err); - CleanupClosePushL(fileReadStream1); + CleanupClosePushL(fileReadStream); //System state before starting the test. - CurrentSystemStateForStateTranTestL(fileReadStream1, ESsmNormal); + CurrentSystemStateForStateTranTestL(fileReadStream, ESsmNormal); //Scenario 1 - Request for state change from Normal to invalid state results in KErrNotSupported INFO_PRINTF1(_L("Request for state change from Normal to invalid state")); - TInt stateTranResult = fileReadStream1.ReadInt32L(); + TInt stateTranResult = fileReadStream.ReadInt32L(); TEST(stateTranResult == KErrNotSupported); INFO_PRINTF2(_L("Actual : %d Expected : -5"), stateTranResult); - CurrentSystemStateForStateTranTestL(fileReadStream1, ESsmNormal); + CurrentSystemStateForStateTranTestL(fileReadStream, ESsmNormal); //Scenario 2 - Request for state change from Normal to fail state with invalid substate results in KErrNotSupported INFO_PRINTF1(_L("Request for state change from Normal to fail state with invalid substate")); - stateTranResult = fileReadStream1.ReadInt32L(); + stateTranResult = fileReadStream.ReadInt32L(); TEST(stateTranResult == KErrNotSupported); INFO_PRINTF2(_L("Actual : %d Expected : -5"), stateTranResult); - CurrentSystemStateForStateTranTestL(fileReadStream1, ESsmNormal); + CurrentSystemStateForStateTranTestL(fileReadStream, ESsmNormal); //Scenario 3 - Request for two state changes(1. fail state 2. shutdown state) one after the other without waiting // for the first one to complete. Cancels both transition request. INFO_PRINTF1(_L("Request for two state changes(1. fail state 2. shutdown state)")); INFO_PRINTF1(_L("one after the other without waiting for the first one to complete.")); INFO_PRINTF1(_L("Cancel the fail state transition request.")); - stateTranResult = fileReadStream1.ReadInt32L(); + stateTranResult = fileReadStream.ReadInt32L(); TEST(stateTranResult == KErrCancel); INFO_PRINTF2(_L("First request to the fail state will be completed with %d Expected -3"), stateTranResult); - CurrentSystemStateForStateTranTestL(fileReadStream1, ESsmNormal); + CurrentSystemStateForStateTranTestL(fileReadStream, ESsmNormal); - stateTranResult = fileReadStream1.ReadInt32L(); + stateTranResult = fileReadStream.ReadInt32L(); TEST(stateTranResult == KErrCancel); INFO_PRINTF2(_L("Second request to transit to the shutdown state will be completed with %d Expected -3"), stateTranResult); - CurrentSystemStateForStateTranTestL(fileReadStream1, ESsmNormal); + CurrentSystemStateForStateTranTestL(fileReadStream, ESsmNormal); + + //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. + INFO_PRINTF1(_L("Request for two state changes one after the other without waiting")); + INFO_PRINTF1(_L("for the first one to complete. Once first and second request are completed the system will be in")); + INFO_PRINTF1(_L("fail state, now issue another state transition request to fail state again.")); + stateTranResult = fileReadStream.ReadInt32L(); + TEST(stateTranResult == KErrCancel); + INFO_PRINTF2(_L("First request to the fail state will be completed with %d Expected -3"), stateTranResult); + CurrentSystemStateForStateTranTestL(fileReadStream, ESsmNormal); - INFO_PRINTF2(_L("Test process exits with %d Expected -3"), stateTranResult); + stateTranResult = fileReadStream.ReadInt32L(); + TEST(stateTranResult == KErrNone); + INFO_PRINTF2(_L("Second request to the fail state will be completed with %d Expected 0"), stateTranResult); + CurrentSystemStateForStateTranTestL(fileReadStream, ESsmNormal); + + stateTranResult = fileReadStream.ReadInt32L(); + TEST(stateTranResult == KErrNotSupported); + INFO_PRINTF2(_L("Third request to the fail state will be completed with %d Expected -5"), stateTranResult); + CurrentSystemStateForStateTranTestL(fileReadStream, ESsmNormal); + + //Finally the system should be in fail state i.e., just before the test application is closed. + CurrentSystemStateForStateTranTestL(fileReadStream, ESsmFail); + INFO_PRINTF1(_L("Test Process Exit Reason")); + stateTranResult = fileReadStream.ReadInt32L(); + TEST(stateTranResult == KErrNone && stateTranResult != KTestAppFailure); + INFO_PRINTF2(_L("Test process exits with %d Expected 0"), stateTranResult); CleanupStack::PopAndDestroy(); // Delete the result file //err = fs.Delete(KGsaTestStateTranFromNormalResult); - - RFileReadStream fileReadStream2; - err = fileReadStream2.Open(fs, KGsaTestStateTranToShutdownResult, EFileRead); + } + else if (iProcessName == KTestProcTranToShutdown) + { + RFileReadStream fileReadStream; + err = fileReadStream.Open(fs, KGsaTestStateTranToShutdownResult, EFileRead); TEST(err == KErrNone); User::LeaveIfError(err); - CleanupClosePushL(fileReadStream2); + CleanupClosePushL(fileReadStream); //System state before starting the test. - CurrentSystemStateForStateTranTestL(fileReadStream2, ESsmNormal); + CurrentSystemStateForStateTranTestL(fileReadStream, ESsmNormal); //Scenario 1 - Request for state transition to shutdown state - invalid substate // request to transit to the shutdown state will be completed with KErrNotSupported INFO_PRINTF1(_L("Request for state transition to shutdown state - invalid substate")); - stateTranResult = fileReadStream2.ReadInt32L(); + TInt stateTranResult = fileReadStream.ReadInt32L(); TEST(stateTranResult == KErrNotSupported); INFO_PRINTF2(_L("Actual : %d Expected : -5"), stateTranResult); - CurrentSystemStateForStateTranTestL(fileReadStream2, ESsmNormal); + CurrentSystemStateForStateTranTestL(fileReadStream, ESsmNormal); - INFO_PRINTF2(_L("Test process exits with %d Expected -5"), stateTranResult); + //Scenario 2 - Request for state transition to shutdown state - critical substate(Restart) + // Request for state transition to shutdown state - critical substate(Standby) + // first request to transit to the shutdown state critical substate(Restart)will be completed with KErrCancel + // second request to transit to the shutdown state critical substate(Standby)will be completed with KErrNone + INFO_PRINTF1(_L("Request for state transition to shutdown state - critical substate(Standby)")); + stateTranResult = fileReadStream.ReadInt32L(); + TEST(stateTranResult == KErrNone); + INFO_PRINTF2(_L("Actual : %d Expected : 0"), stateTranResult); + CurrentSystemStateForStateTranTestL(fileReadStream, ESsmNormal); + + INFO_PRINTF1(_L("Request for state transition to shutdown state - critical substate(Restart)")); + stateTranResult = fileReadStream.ReadInt32L(); + TEST(stateTranResult == KErrCancel); + INFO_PRINTF2(_L("Actual : %d Expected : -3"), stateTranResult); + CurrentSystemStateForStateTranTestL(fileReadStream, ESsmNormal); + + //Finally the system should be in fail state i.e., just before the test application is closed. + CurrentSystemStateForStateTranTestL(fileReadStream, ESsmShutdown); + + INFO_PRINTF1(_L("Test Process Exit Reason")); + stateTranResult = fileReadStream.ReadInt32L(); + TEST(stateTranResult == KErrNone && stateTranResult != KTestAppFailure); + INFO_PRINTF2(_L("Test process exits with %d Expected 0"), stateTranResult); CleanupStack::PopAndDestroy(); // Delete the result file //err = fs.Delete(KGsaTestStateTranToShutdownResult); - - RFileReadStream fileReadStream3; - err = fileReadStream3.Open(fs, KGsaTestStateTranFromShutdownResult, EFileRead); + } + else if (iProcessName == KTestProcTranFromShutdown) + { + RFileReadStream fileReadStream; + err = fileReadStream.Open(fs, KGsaTestStateTranFromShutdownResult, EFileRead); TEST(err == KErrNone); User::LeaveIfError(err); - CleanupClosePushL(fileReadStream3); + CleanupClosePushL(fileReadStream); //System state before starting the test. - CurrentSystemStateForStateTranTestL(fileReadStream3, ESsmNormal); + CurrentSystemStateForStateTranTestL(fileReadStream, ESsmNormal); //Scenario 1 - Request for state change from Normal to shutdown state to critical substate // Cancel the request immediately INFO_PRINTF1(_L("Request for state change from Normal to shutdown critical substate and Cancel the request")); - stateTranResult = fileReadStream3.ReadInt32L(); + TInt stateTranResult = fileReadStream.ReadInt32L(); TEST(stateTranResult == KErrCancel); INFO_PRINTF2(_L("Actual : %d Expected : -3"), stateTranResult); - CurrentSystemStateForStateTranTestL(fileReadStream3, ESsmNormal); + CurrentSystemStateForStateTranTestL(fileReadStream, ESsmNormal); //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. INFO_PRINTF1(_L("Request for state change from Normal to shutdown any substate and Cancel the request")); - stateTranResult = fileReadStream3.ReadInt32L(); + stateTranResult = fileReadStream.ReadInt32L(); TEST(stateTranResult == KErrCancel); INFO_PRINTF2(_L("Actual : %d Expected : -3"), stateTranResult); - CurrentSystemStateForStateTranTestL(fileReadStream3, ESsmNormal); + CurrentSystemStateForStateTranTestL(fileReadStream, ESsmNormal); + + //Scenario 3 - Request for three state changes(1. shutdown state 2. invalid state 3. fail state) one after the other + // i.e., second request is issued once first one is completed and the third one is issued after the second request is completed. + // Cancel the third request. + // first request to the shutdown state will be completed with KErrNone + // second request to transit to the fail state will be completed with KErrNotSupported + // third request to transit to the fail state will be completed with KErrCancel + INFO_PRINTF1(_L("Request for 3 state changes(1. shutdown state 2. invalid state 3. fail state)")); + INFO_PRINTF1(_L("one after the other. i.e., second request is issued once first one is completed")); + INFO_PRINTF1(_L("and the third one is issued after the second request is completed.")); + INFO_PRINTF1(_L("Cancel the third request.")); + stateTranResult = fileReadStream.ReadInt32L(); + TEST(stateTranResult == KErrNone); + INFO_PRINTF2(_L("First request to the shutdown state will be completed with %d Expected 0"), stateTranResult); + CurrentSystemStateForStateTranTestL(fileReadStream, ESsmNormal); + + stateTranResult = fileReadStream.ReadInt32L(); + TEST(stateTranResult == KErrNotSupported); + INFO_PRINTF2(_L("Second request to transit to the fail state will be completed with %d Expected -5"), stateTranResult); + CurrentSystemStateForStateTranTestL(fileReadStream, ESsmNormal); - INFO_PRINTF2(_L("Test process exits with %d Expected -3"), stateTranResult); + stateTranResult = fileReadStream.ReadInt32L(); + TEST(stateTranResult == KErrCancel); + INFO_PRINTF2(_L("Third request to transit to the fail state will be completed with %d Expected -3"), stateTranResult); + CurrentSystemStateForStateTranTestL(fileReadStream, ESsmShutdown); + + //Scenario 4 - The system is now in shutdown state, request for state transition to normal state. + // request to transit to the normal state will be completed with KErrNotSupported + INFO_PRINTF1(_L("The system is now in shutdown state, request for state transition to normal state")); + stateTranResult = fileReadStream.ReadInt32L(); + TEST(stateTranResult == KErrNotSupported); + INFO_PRINTF2(_L("Request to transit to the normal state will be completed with %d Expected -5"), stateTranResult); + CurrentSystemStateForStateTranTestL(fileReadStream, ESsmShutdown); + + //Scenario 5 - The system is now in shutdown state, request for state transition to fail state. + // request to transit to the fail state will be completed with KErrNone + INFO_PRINTF1(_L("The system is now in shutdown state, request for state transition to fail state")); + stateTranResult = fileReadStream.ReadInt32L(); + TEST(stateTranResult == KErrNone); + INFO_PRINTF2(_L("Request to transit to the normal state will be completed with %d Expected 0"), stateTranResult); + CurrentSystemStateForStateTranTestL(fileReadStream, ESsmShutdown); + + //Finally the system should be in fail state i.e., just before the test application is closed. + CurrentSystemStateForStateTranTestL(fileReadStream, ESsmFail); + + INFO_PRINTF1(_L("Test Process Exit Reason")); + stateTranResult = fileReadStream.ReadInt32L(); + TEST(stateTranResult == KErrNone && stateTranResult != KTestAppFailure); + INFO_PRINTF2(_L("Test process exits with %d Expected 0"), stateTranResult); CleanupStack::PopAndDestroy(); // Delete the result file @@ -164,12 +265,68 @@ INFO_PRINTF2(_L("Actual : %d Expected : -5"), stateTranResult); CurrentSystemStateForStateTranTestL(fileReadStream, ESsmStartup); - INFO_PRINTF2(_L("Test process exits with %d Expected -5"), stateTranResult); + //Scenario 2 - Request for state change from Startup to fail state with invalid substate + INFO_PRINTF1(_L("Request for state change from Startup to fail state with invalid substate")); + stateTranResult = fileReadStream.ReadInt32L(); + TEST(stateTranResult == KErrNotSupported); + INFO_PRINTF2(_L("Actual : %d Expected : -5"), stateTranResult); + CurrentSystemStateForStateTranTestL(fileReadStream, ESsmStartup); + + //Scenario 3 - Request for state change from Startup to shutdown invalid substate + INFO_PRINTF1(_L("Request for state change from Startup to shutdown invalid substate")); + stateTranResult = fileReadStream.ReadInt32L(); + TEST(stateTranResult == KErrNotSupported); + INFO_PRINTF2(_L("Request for state change from Startup to shutdown invalid state completed with %d Expected -5"), stateTranResult); + CurrentSystemStateForStateTranTestL(fileReadStream, ESsmStartup); + + //Scenario 4 - Request for two state changes to fail state one after the other + //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. + INFO_PRINTF1(_L("Request for two state changes to fail state one after the other")); + stateTranResult = fileReadStream.ReadInt32L(); + TEST(stateTranResult == KErrCancel); + INFO_PRINTF2(_L("First request to the fail state will be completed with %d Expected -3"), stateTranResult); + CurrentSystemStateForStateTranTestL(fileReadStream, ESsmStartup); + + stateTranResult = fileReadStream.ReadInt32L(); + TEST(stateTranResult == KErrNone); + INFO_PRINTF2(_L("Second request to the fail state will be completed with %d Expected 0"), stateTranResult); + CurrentSystemStateForStateTranTestL(fileReadStream, ESsmStartup); + + //Finally the system should be in fail state i.e., just before the test application is closed. + CurrentSystemStateForStateTranTestL(fileReadStream, ESsmFail); + INFO_PRINTF1(_L("Test Process Exit Reason")); + stateTranResult = fileReadStream.ReadInt32L(); + TEST(stateTranResult == KErrNone && stateTranResult != KTestAppFailure); + INFO_PRINTF2(_L("Test process exits with %d Expected 0"), stateTranResult); CleanupStack::PopAndDestroy(); // Delete the result file //err = fs.Delete(KGsaTestStateTranFromStartupResult); } + else if (iProcessName == KTGsaStateTranFromStartuptoShutdownStep) + { + RFileReadStream fileReadStream; + User::LeaveIfError(fileReadStream.Open(fs, KGsaTestStateTranFromStartupResult, EFileRead)); + CleanupClosePushL(fileReadStream); + + //Scenario 1 - Request for state change from Startup to shutdown critical substate + INFO_PRINTF1(_L("Request for state change from Startup to shutdown critical substate")); + TInt stateTranResult = fileReadStream.ReadInt32L(); + TEST(stateTranResult == KErrNone); + INFO_PRINTF2(_L("Request for state change from Startup to shutdown critical substate completed with %d Expected 0"), stateTranResult); + CurrentSystemStateForStateTranTestL(fileReadStream, ESsmStartup); + + CurrentSystemStateForStateTranTestL(fileReadStream, ESsmStartup); + + //Finally the system should be in Shutdown state i.e., just before the test application is closed. + CurrentSystemStateForStateTranTestL(fileReadStream, ESsmShutdown); + INFO_PRINTF1(_L("Test Process Exit Reason")); + stateTranResult = fileReadStream.ReadInt32L(); + TEST(stateTranResult == KErrNone && stateTranResult != KTestAppFailure); + INFO_PRINTF2(_L("Test process exits with %d Expected 0"), stateTranResult); + + CleanupStack::PopAndDestroy(); + } else { TEST(err == KErrArgument); @@ -202,10 +359,16 @@ CGsaStateTranToDiffStatesTest::CGsaStateTranToDiffStatesTest(const TDesC& aProcessName) : iProcessName(aProcessName) { - if (iProcessName == KTestProcTranFromNormal) + if (iProcessName == KTestProcTranToShutdown) + SetTestStepName(KTGsaStateTranToShutdownStep); + else if (iProcessName == KTestProcTranFromShutdown) + SetTestStepName(KTGsaStateTranFromShutdownStep); + else if (iProcessName == KTestProcTranFromNormal) SetTestStepName(KTGsaStateTranFromNormalStep); else if (iProcessName == KTestProcTranFromStartup) SetTestStepName(KTGsaStateTranFromStartupStep); + else if (iProcessName == KTGsaStateTranFromStartuptoShutdownStep) + SetTestStepName(KTGsaStateTranFromStartuptoShutdownStep); else {