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 "gsatestapps.h" |
|
23 |
|
24 #include <ssm/ssmstates.hrh> |
|
25 #include <ssm/ssmsubstates.hrh> |
|
26 #include <ssm/ssmstate.h> |
|
27 #include <ssm/ssmstatetransition.h> |
|
28 #include <ssm/ssmstatemanager.h> |
|
29 #include <ssm/ssmstateawaresession.h> |
|
30 #include <ssm/ssmdomaindefs.h> |
|
31 |
|
32 #include "tgsastatetran_base.h" |
|
33 |
|
34 class CStateTranFromShutdown : public CTGsaStateTransition |
|
35 { |
|
36 public: |
|
37 static CStateTranFromShutdown* NewL(); |
|
38 ~CStateTranFromShutdown(); |
|
39 void StartTestL(); |
|
40 void CallStopSchedulerL(); |
|
41 |
|
42 private: |
|
43 void ConstructL(); |
|
44 CStateTranFromShutdown(); |
|
45 |
|
46 public: |
|
47 void DoTestStateTranFromShutdownL(); |
|
48 }; |
|
49 |
|
50 static TInt StopScheduler(TAny* aStateTranFromShutdown) |
|
51 { |
|
52 CStateTranFromShutdown* stateTran = reinterpret_cast<CStateTranFromShutdown*>(aStateTranFromShutdown); |
|
53 TRAPD(err,stateTran->CallStopSchedulerL()); |
|
54 return err; |
|
55 } |
|
56 |
|
57 static TInt StartTest(TAny* aStateTranFromShutdown) |
|
58 { |
|
59 TInt testCompletionReason = KErrNone; |
|
60 CStateTranFromShutdown* stateTran = reinterpret_cast<CStateTranFromShutdown*>(aStateTranFromShutdown); |
|
61 TBool stateTest = stateTran->DoStartStateTranTest(); |
|
62 if (stateTest) |
|
63 { |
|
64 RDebug::Print(_L("\nStateTran Test: Start the tgsastatetranfromshutdown test\n")); |
|
65 TRAP(testCompletionReason, stateTran->DoTestStateTranFromShutdownL()); |
|
66 } |
|
67 |
|
68 return testCompletionReason; |
|
69 } |
|
70 |
|
71 CStateTranFromShutdown* CStateTranFromShutdown::NewL() |
|
72 { |
|
73 CStateTranFromShutdown* self = new(ELeave) CStateTranFromShutdown(); |
|
74 self->ConstructL(); |
|
75 return self; |
|
76 } |
|
77 |
|
78 void CStateTranFromShutdown::ConstructL() |
|
79 { |
|
80 CTGsaStateTransition::ConstructL(KGsaTestStateTranResultFilePath); |
|
81 } |
|
82 |
|
83 CStateTranFromShutdown::~CStateTranFromShutdown() |
|
84 { |
|
85 } |
|
86 |
|
87 CStateTranFromShutdown::CStateTranFromShutdown() |
|
88 { |
|
89 } |
|
90 |
|
91 // Tests the Shutdown state transitions under different scenarios |
|
92 void CStateTranFromShutdown::DoTestStateTranFromShutdownL() |
|
93 { |
|
94 // This async callback is used to stop the scheduler once the system goes into fail state. |
|
95 iAsyncCallbackForStopScheduler = new(ELeave) CAsyncCallBack(CActive::EPriorityIdle); |
|
96 TCallBack stopSchedulerCallback(StopScheduler, this); |
|
97 iAsyncCallbackForStopScheduler->Set(stopSchedulerCallback); |
|
98 |
|
99 // call the callback function which keeps looping until the system state gets into fail state. |
|
100 iAsyncCallbackForStopScheduler->CallBack(); |
|
101 |
|
102 RSsmStateManager stateMan; |
|
103 TInt err = stateMan.Connect(); |
|
104 if (err == KErrNone) |
|
105 RDebug::Print(_L("\nStateTran Test: RSsmStateManager sess Connect %d\n"), err); |
|
106 else |
|
107 { |
|
108 RDebug::Print(_L("\nStateTran Test: Unable to connect to RSsmStateManager sess\n")); |
|
109 User::Leave(KTestAppFailure); |
|
110 } |
|
111 |
|
112 // Creates and open the result file for streaming |
|
113 err = iFileWriteStream.Replace(iFs, KGsaTestStateTranFromShutdownResult, EFileWrite); |
|
114 RDebug::Print(_L("\nStateTran Test: iFileWriteStream open with %d\n"), err); |
|
115 |
|
116 |
|
117 // Gets the Current system state before starting the test |
|
118 CurrentSystemStateL(); |
|
119 |
|
120 //Scenario 1 - Request for state change from Normal to shutdown state to critical substate |
|
121 // Cancel the request immediately |
|
122 RDebug::Print(_L("\nScenario 1 \n")); |
|
123 TRequestStatus status_shutdowncritsubstate; |
|
124 TSsmState shutdownState_Critical(ESsmShutdown, ESsmShutdownSubStateCritical); |
|
125 TSsmStateTransition stateTrans_Shutdowncritical(shutdownState_Critical, 1); |
|
126 |
|
127 stateMan.RequestStateTransition(stateTrans_Shutdowncritical, status_shutdowncritsubstate); |
|
128 RDebug::Print(_L("\n RequestStateTransition from Normal to shutdown state critical substate %d\n "), status_shutdowncritsubstate.Int()); |
|
129 |
|
130 stateMan.RequestStateTransitionCancel(); |
|
131 |
|
132 iFileWriteStream.WriteInt32L(status_shutdowncritsubstate.Int()); |
|
133 if (status_shutdowncritsubstate.Int() == KErrCancel) |
|
134 { |
|
135 CurrentSystemStateL(); |
|
136 RDebug::Print(_L("\n RequestStateTransition from Normal to shutdown state critical substate completed %d Expected -3\n "), status_shutdowncritsubstate.Int()); |
|
137 } |
|
138 else |
|
139 User::Leave(KTestAppFailure); |
|
140 |
|
141 //Scenario 2 - Request for state change from Normal to shutdown state to any substate |
|
142 // Cancel the request immediately, so that we can proceed with the next test scenario. |
|
143 RDebug::Print(_L("\nScenario 2 \n")); |
|
144 TRequestStatus status_shutdownanysubstate; |
|
145 TSsmState shutdownState_Any(ESsmShutdown, KSsmAnySubState); |
|
146 TSsmStateTransition stateTrans_shutdownAnySubState(shutdownState_Any, 1); |
|
147 |
|
148 stateMan.RequestStateTransition(stateTrans_shutdownAnySubState, status_shutdownanysubstate); |
|
149 RDebug::Print(_L("\n RequestStateTransition from Normal to shutdown state any substate %d\n "), status_shutdownanysubstate.Int()); |
|
150 |
|
151 stateMan.RequestStateTransitionCancel(); |
|
152 |
|
153 iFileWriteStream.WriteInt32L(status_shutdownanysubstate.Int()); |
|
154 if (status_shutdownanysubstate.Int() == KErrCancel) |
|
155 { |
|
156 CurrentSystemStateL(); |
|
157 RDebug::Print(_L("\n RequestStateTransition from Normal to shutdown state any substate completed %d Expected -3\n "), status_shutdownanysubstate.Int()); |
|
158 } |
|
159 else |
|
160 User::Leave(KTestAppFailure); |
|
161 |
|
162 //Scenario 3 - Request for three state changes(1. shutdown state 2. invalid state 3. fail state) one after the other |
|
163 // i.e., second request is issued once first one is completed and the third one is issued after the second request is completed. |
|
164 // Cancel the third request. |
|
165 // first request to the shutdown state will be completed with KErrNone |
|
166 // second request to transit to the fail state will be completed with KErrNotSupported |
|
167 // third request to transit to the fail state will be completed with KErrCancel |
|
168 RDebug::Print(_L("\nScenario 3 \n")); |
|
169 |
|
170 TRequestStatus status; |
|
171 stateMan.RequestStateTransition(stateTrans_Shutdowncritical, status); |
|
172 RDebug::Print(_L("\n Start First RequestStateTransition from Normal to shutdown state %d\n "), status.Int()); |
|
173 |
|
174 User::WaitForRequest(status); |
|
175 iFileWriteStream.WriteInt32L(status.Int()); |
|
176 if (status.Int() == KErrNone) |
|
177 { |
|
178 CurrentSystemStateL(); |
|
179 RDebug::Print(_L("\n First RequestStateTransition from Normal to shutdown state completes with %d Expected 0\n "), status.Int()); |
|
180 } |
|
181 else |
|
182 User::Leave(KTestAppFailure); |
|
183 |
|
184 TRequestStatus status1; |
|
185 TSsmState state(10, KSsmAnySubState); |
|
186 TSsmStateTransition stateTrans_InvalidState(state, 1); |
|
187 |
|
188 stateMan.RequestStateTransition(stateTrans_InvalidState, status1); |
|
189 RDebug::Print(_L("\n Start Second RequestStateTransition from shutdown to invalid state %d\n "), status1.Int()); |
|
190 |
|
191 User::WaitForRequest(status1); |
|
192 |
|
193 iFileWriteStream.WriteInt32L(status1.Int()); |
|
194 if (status1.Int() == KErrNotSupported) |
|
195 { |
|
196 CurrentSystemStateL(); |
|
197 RDebug::Print(_L("\n Second RequestStateTransition from shutdown to invalid state completes %d Expected -5\n "), status1.Int()); |
|
198 } |
|
199 else |
|
200 User::Leave(KTestAppFailure); |
|
201 |
|
202 TRequestStatus status2; |
|
203 state.Set(ESsmFail, KSsmAnySubState); |
|
204 TSsmStateTransition stateTrans3(state, 1); |
|
205 |
|
206 stateMan.RequestStateTransition(stateTrans3, status2); |
|
207 RDebug::Print(_L("\n Start Third RequestStateTransition from Shutdown to fail state %d\n "), status2.Int()); |
|
208 |
|
209 stateMan.RequestStateTransitionCancel(); |
|
210 User::WaitForRequest(status2); |
|
211 |
|
212 iFileWriteStream.WriteInt32L(status2.Int()); |
|
213 if (status2.Int() == KErrCancel) |
|
214 { |
|
215 CurrentSystemStateL(); |
|
216 RDebug::Print(_L("\n Third RequestStateTransitionCancel from Shutdown to fail state completes %d Expected -3\n "), status2.Int()); |
|
217 } |
|
218 else |
|
219 User::Leave(KTestAppFailure); |
|
220 |
|
221 //Scenario 4 - The system is now in shutdown state, request for state transition to normal state. |
|
222 // request to transit to the normal state will be completed with KErrNotSupported |
|
223 RDebug::Print(_L("\nScenario 4 \n")); |
|
224 |
|
225 TSsmState state_Normal(ESsmNormal, KSsmAnySubState); |
|
226 TSsmStateTransition stateTrans_NormalState(state_Normal, 1); |
|
227 |
|
228 stateMan.RequestStateTransition(stateTrans_NormalState, status1); |
|
229 RDebug::Print(_L("\n RequestStateTransition from Shutdown to normal state %d\n "), status1.Int()); |
|
230 |
|
231 User::WaitForRequest(status1); |
|
232 |
|
233 iFileWriteStream.WriteInt32L(status1.Int()); |
|
234 if (status1.Int() == KErrNotSupported) |
|
235 { |
|
236 CurrentSystemStateL(); |
|
237 RDebug::Print(_L("\n RequestStateTransition from Shutdown to normal state completes %d Expected -5\n "), status1.Int()); |
|
238 } |
|
239 else |
|
240 User::Leave(KTestAppFailure); |
|
241 |
|
242 //Scenario 5 - The system is now in shutdown state, request for state transition to fail state. |
|
243 // request to transit to the fail state will be completed with KErrNone |
|
244 RDebug::Print(_L("\nScenario 5 \n")); |
|
245 |
|
246 stateMan.RequestStateTransition(stateTrans3, status1); |
|
247 RDebug::Print(_L("\n RequestStateTransition from Shutdown to fail state %d\n "), status1.Int()); |
|
248 |
|
249 User::WaitForRequest(status1); |
|
250 |
|
251 iFileWriteStream.WriteInt32L(status1.Int()); |
|
252 if (status1.Int() == KErrNone) |
|
253 { |
|
254 CurrentSystemStateL(); |
|
255 RDebug::Print(_L("\n RequestStateTransition from Shutdown to fail state completes %d Expected 0\n "), status1.Int()); |
|
256 } |
|
257 else |
|
258 User::Leave(KTestAppFailure); |
|
259 } |
|
260 |
|
261 void CStateTranFromShutdown::StartTestL() |
|
262 { |
|
263 CActiveScheduler* sched=new(ELeave) CActiveScheduler; |
|
264 CleanupStack::PushL(sched); |
|
265 CActiveScheduler::Install(sched); |
|
266 |
|
267 // Notifier used to get the notification when system gets to fail state |
|
268 CSsmStateAwareSession* notif_for_failstate = CSsmStateAwareSession::NewLC(KSM2UiServicesDomain3); |
|
269 notif_for_failstate->AddSubscriberL(*this); |
|
270 |
|
271 // This async callback is used to start the state transition test once system enters to normal state. |
|
272 iAsyncCallbackForStartTest = new(ELeave) CAsyncCallBack(CActive::EPriorityIdle); |
|
273 TCallBack startTestCallback(StartTest, this); |
|
274 iAsyncCallbackForStartTest->Set(startTestCallback); |
|
275 |
|
276 // call the callback function which keeps looping until the system state gets into normal state. |
|
277 iAsyncCallbackForStartTest->CallBack(); |
|
278 |
|
279 RProcess::Rendezvous(KErrNone); |
|
280 sched->Start(); |
|
281 |
|
282 CleanupStack::PopAndDestroy(2); |
|
283 } |
|
284 |
|
285 void CStateTranFromShutdown::CallStopSchedulerL() |
|
286 { |
|
287 TSsmState currenState; |
|
288 currenState = iSsmStateAwareSess.State(); |
|
289 |
|
290 TUint16 currentMainState = currenState.MainState(); |
|
291 // Active scheduler is stopped once the system goes into fail state, else it issues a request for callback again |
|
292 if (currentMainState == ESsmFail) |
|
293 { |
|
294 RDebug::Print(_L("\nStateTran Test: Stop Active Scheduler\n")); |
|
295 iFileWriteStream.WriteUint16L(currentMainState); |
|
296 CActiveScheduler::Stop(); |
|
297 } |
|
298 else |
|
299 { |
|
300 iAsyncCallbackForStopScheduler->CallBack(); |
|
301 } |
|
302 } |
|
303 |
|
304 TInt E32Main() |
|
305 { |
|
306 __UHEAP_MARK; |
|
307 |
|
308 CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
309 TInt r=KErrNoMemory; |
|
310 TInt testCompletionReason = KErrNone; |
|
311 if (cleanup) |
|
312 { |
|
313 __UHEAP_MARK; |
|
314 CStateTranFromShutdown* stateTran = NULL; |
|
315 TRAP(r, stateTran = CStateTranFromShutdown::NewL()); |
|
316 if (r == KErrNone) |
|
317 { |
|
318 TRAP(testCompletionReason, stateTran->StartTestL()); |
|
319 // testCompletionReason is the reason with which the test case completes. |
|
320 TRAP(r, stateTran->CommitTestResultsL(testCompletionReason)); |
|
321 delete stateTran; |
|
322 } |
|
323 delete cleanup; |
|
324 __UHEAP_MARKEND; |
|
325 |
|
326 if (r != KErrNone) |
|
327 { |
|
328 User::Panic(_L("tgsastatetranfromnormalPanic"), r); |
|
329 } |
|
330 } |
|
331 |
|
332 __UHEAP_MARKEND; |
|
333 return r; |
|
334 } |
|
335 |
|
336 |
|
337 |
|