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