|
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 CStateTranFromStartup : public CTGsaStateTransition |
|
35 { |
|
36 public: |
|
37 static CStateTranFromStartup* NewL(); |
|
38 ~CStateTranFromStartup(); |
|
39 |
|
40 private: |
|
41 void ConstructL(); |
|
42 CStateTranFromStartup(); |
|
43 |
|
44 public: |
|
45 void DoTestStateTranFromStartupL(); |
|
46 void DoTestStateTranFromStartuptoShutdownL(); |
|
47 }; |
|
48 |
|
49 static TInt StopScheduler(TAny* aStateTranFromStartup) |
|
50 { |
|
51 CStateTranFromStartup* stateTran = reinterpret_cast<CStateTranFromStartup*>(aStateTranFromStartup); |
|
52 TRAPD(err,stateTran->CallStopSchedulerL()); |
|
53 return err; |
|
54 } |
|
55 |
|
56 CStateTranFromStartup* CStateTranFromStartup::NewL() |
|
57 { |
|
58 CStateTranFromStartup* self = new(ELeave) CStateTranFromStartup(); |
|
59 self->ConstructL(); |
|
60 return self; |
|
61 } |
|
62 |
|
63 void CStateTranFromStartup::ConstructL() |
|
64 { |
|
65 CTGsaStateTransition::ConstructL(KGsaTestStateTranFromStartupResult); |
|
66 } |
|
67 |
|
68 CStateTranFromStartup::~CStateTranFromStartup() |
|
69 { |
|
70 } |
|
71 |
|
72 CStateTranFromStartup::CStateTranFromStartup() |
|
73 { |
|
74 } |
|
75 |
|
76 // Tests the Fail state transitions from startup under different scenarios |
|
77 void CStateTranFromStartup::DoTestStateTranFromStartupL() |
|
78 { |
|
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; |
|
88 TInt err = stateMan.Connect(); |
|
89 CleanupClosePushL(stateMan); |
|
90 if (err == KErrNone) |
|
91 RDebug::Print(_L("\nStateTran Test: RSsmStateManager sess Connect %d\n"), err); |
|
92 else |
|
93 { |
|
94 RDebug::Print(_L("\nStateTran Test: Unable to connect to RSsmStateManager sess\n")); |
|
95 User::Leave(KTestAppFailure); |
|
96 } |
|
97 |
|
98 // Creates and open the result file for streaming |
|
99 err = iFileWriteStream.Replace(iFs, KGsaTestStateTranFromStartupResult, EFileWrite); |
|
100 RDebug::Print(_L("\nStateTran Test: iFileWriteStream open with %d\n"), err); |
|
101 |
|
102 CurrentSystemStateL(); |
|
103 //Scenario 1 - Request for state change from Startup to invalid state |
|
104 RDebug::Print(_L("\nStateTran Test: Scenario 1 \n")); |
|
105 TSsmState state(10, KSsmAnySubState); |
|
106 TSsmStateTransition stateTrans_InvalidState(state, 1); |
|
107 |
|
108 TRequestStatus status; |
|
109 stateMan.RequestStateTransition(stateTrans_InvalidState, status); |
|
110 RDebug::Print(_L("\nStateTran Test: Start RequestStateTransition from Startup to Invalid state with %d\n "), status.Int()); |
|
111 |
|
112 User::WaitForRequest(status); |
|
113 iFileWriteStream.WriteInt32L(status.Int()); |
|
114 if (status.Int() == KErrNotSupported) |
|
115 { |
|
116 CurrentSystemStateL(); |
|
117 RDebug::Print(_L("\nStateTran Test: RequestStateTransition from Normal to Invalid state completes with %d Expected -5\n "), status.Int()); |
|
118 } |
|
119 else |
|
120 { |
|
121 RDebug::Print(_L("\nStateTran Test: RequestStateTransition from Normal to Invalid state Failed")); |
|
122 User::Leave(KTestAppFailure); |
|
123 } |
|
124 |
|
125 //Scenario 2 - Request for state change from Startup to fail state with invalid substate |
|
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 } |
|
218 |
|
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 |
|
282 TInt E32Main() |
|
283 { |
|
284 __UHEAP_MARK; |
|
285 |
|
286 CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
287 TInt r=KErrNoMemory; |
|
288 TInt testCompletionReason = KErrNone; |
|
289 TInt argc = User::CommandLineLength(); |
|
290 if (cleanup) |
|
291 { |
|
292 __UHEAP_MARK; |
|
293 CStateTranFromStartup* stateTran = NULL; |
|
294 TRAP(r, stateTran = CStateTranFromStartup::NewL()); |
|
295 if (r == KErrNone) |
|
296 { |
|
297 if(argc>0) |
|
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. |
|
306 TRAP(r, stateTran->CommitTestResultsL(testCompletionReason)); |
|
307 |
|
308 // Rendezvous'ng the process as it started as WaitForSignal execution behaviour |
|
309 RProcess::Rendezvous(KErrNone); |
|
310 delete stateTran; |
|
311 } |
|
312 delete cleanup; |
|
313 __UHEAP_MARKEND; |
|
314 |
|
315 if (r != KErrNone) |
|
316 { |
|
317 User::Panic(_L("tgsastatetranfromstartuppanic"), r); |
|
318 } |
|
319 } |
|
320 |
|
321 __UHEAP_MARKEND; |
|
322 return r; |
|
323 } |
|
324 |
|
325 |
|
326 |