|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @test |
|
19 @internalComponent - Internal Symbian test code |
|
20 */ |
|
21 |
|
22 #include "tgsastatetran_base.h" |
|
23 #include "gsatestapps.h" |
|
24 |
|
25 #include <ssm/ssmstates.hrh> |
|
26 #include <ssm/ssmsubstates.hrh> |
|
27 #include <ssm/ssmstate.h> |
|
28 #include <ssm/ssmstatetransition.h> |
|
29 #include <ssm/ssmstatemanager.h> |
|
30 #include <ssm/ssmdomaindefs.h> |
|
31 |
|
32 #include <e32debug.h> |
|
33 |
|
34 void CTGsaStateTransition::ConstructL(const TDesC& aResultFile) |
|
35 { |
|
36 // Connects to RSsmStateAwareSession in order to enquire about the current system state |
|
37 TInt err = iSsmStateAwareSess.Connect(KSM2UiServicesDomain3); |
|
38 if (err == KErrNone) |
|
39 RDebug::Print(_L("\nStateTran Test: RSsmStateAwareSession sess Connect %d\n"), err); |
|
40 else |
|
41 { |
|
42 RDebug::Print(_L("\nStateTran Test: RSsmStateAwareSession sess Connect Failed\n")); |
|
43 User::Leave(err); |
|
44 } |
|
45 |
|
46 //Connects to file server |
|
47 err = iFs.Connect(); |
|
48 if (err == KErrNone) |
|
49 RDebug::Print(_L("\nStateTran Test: RFs sess Connect %d\n"), err); |
|
50 else |
|
51 { |
|
52 RDebug::Print(_L("\nStateTran Test: RFs sess Connect Failed\n")); |
|
53 User::Leave(err); |
|
54 } |
|
55 |
|
56 err = iFs.MkDirAll(aResultFile); |
|
57 if (err == KErrNone || err == KErrAlreadyExists) |
|
58 RDebug::Print(_L("\nStateTran Test: RFs sess Connect %d\n"), err); |
|
59 else |
|
60 { |
|
61 RDebug::Print(_L("\nStateTran Test: RFs sess Connect Failed\n")); |
|
62 User::Leave(err); |
|
63 } |
|
64 } |
|
65 |
|
66 CTGsaStateTransition::~CTGsaStateTransition() |
|
67 { |
|
68 iSsmStateAwareSess.Close(); |
|
69 iFileWriteStream.Close(); |
|
70 iFs.Close(); |
|
71 if (iAsyncCallbackForStartTest) |
|
72 delete iAsyncCallbackForStartTest; |
|
73 if(iAsyncCallbackForStopScheduler) |
|
74 delete iAsyncCallbackForStopScheduler; |
|
75 } |
|
76 |
|
77 CTGsaStateTransition::CTGsaStateTransition() |
|
78 { |
|
79 } |
|
80 |
|
81 // Gets the current system state and checks whether it is in Normal state. |
|
82 void CTGsaStateTransition::CurrentSystemStateL() |
|
83 { |
|
84 TSsmState currenState; |
|
85 currenState = iSsmStateAwareSess.State(); |
|
86 |
|
87 // Writes the current system state to the file |
|
88 iFileWriteStream.WriteUint16L(currenState.MainState()); |
|
89 if (currenState.MainState() == ESsmStartup || currenState.MainState() == ESsmNormal || currenState.MainState() == ESsmShutdown) |
|
90 RDebug::Print(_L("\nStateTran Test: Current System State is %d\n"), currenState.MainState()); |
|
91 else |
|
92 { |
|
93 RDebug::Print(_L("\nStateTran Test: System is not in Startup / Normal / Shutdown State\n")); |
|
94 User::Leave(KTestAppFailure); |
|
95 } |
|
96 } |
|
97 |
|
98 TBool CTGsaStateTransition::DoStartStateTranTest() |
|
99 { |
|
100 TSsmState currenState; |
|
101 currenState = iSsmStateAwareSess.State(); |
|
102 |
|
103 // Once the system enters into normal state start the state transition test |
|
104 if (currenState.MainState() == ESsmNormal) |
|
105 { |
|
106 RDebug::Print(_L("\nStateTran Test: System is in Normal state, so start the test\n")); |
|
107 return ETrue; |
|
108 } |
|
109 else |
|
110 { |
|
111 iAsyncCallbackForStartTest->CallBack(); |
|
112 return EFalse; |
|
113 } |
|
114 } |
|
115 |
|
116 void CTGsaStateTransition::CallStopSchedulerL() |
|
117 { |
|
118 TSsmState currenState; |
|
119 currenState = iSsmStateAwareSess.State(); |
|
120 |
|
121 TUint16 currentMainState = currenState.MainState(); |
|
122 // Active scheduler is stopped once the system goes into shudown state, else it issues a request for callback again |
|
123 // Once the system gets into normal state start the state transition test |
|
124 if (currentMainState == ESsmFail || currentMainState == ESsmShutdown) |
|
125 { |
|
126 RDebug::Print(_L("\nStateTran Test: Stop Active Scheduler\n")); |
|
127 iFileWriteStream.WriteUint16L(currentMainState); |
|
128 CActiveScheduler::Stop(); |
|
129 } |
|
130 else |
|
131 { |
|
132 iAsyncCallbackForStopScheduler->CallBack(); |
|
133 } |
|
134 } |
|
135 |
|
136 void CTGsaStateTransition::CommitTestResultsL(TInt aTestCompletionReason) |
|
137 { |
|
138 // Writes the test completion reason to the file |
|
139 iFileWriteStream.WriteInt32L(aTestCompletionReason); |
|
140 iFileWriteStream.CommitL(); |
|
141 } |
|
142 |
|
143 void CTGsaStateTransition::StateChanged(TSsmState aSsmState) |
|
144 { |
|
145 if (aSsmState.MainState() == ESsmFail || aSsmState.MainState() == ESsmShutdown) |
|
146 RDebug::Print(_L("\nStateTran Test: Current System State after completing the test %d\n"), aSsmState.MainState()); |
|
147 else |
|
148 { |
|
149 RDebug::Print(_L("\nStateTran Test: System is not in Fail or Shutdown State\n")); |
|
150 } |
|
151 } |
|
152 |
|
153 |
|
154 |
|
155 |