112 User::WaitForRequest(status); |
97 User::WaitForRequest(status); |
113 iFileWriteStream.WriteInt32L(status.Int()); |
98 iFileWriteStream.WriteInt32L(status.Int()); |
114 if (status.Int() == KErrNotSupported) |
99 if (status.Int() == KErrNotSupported) |
115 { |
100 { |
116 CurrentSystemStateL(); |
101 CurrentSystemStateL(); |
117 RDebug::Print(_L("\nStateTran Test: RequestStateTransition from Normal to Invalid state completes with %d Expected -5\n "), status.Int()); |
102 RDebug::Print(_L("\nStateTran Test: RequestStateTransition from Startup to Invalid state completes with %d Expected -5\n "), status.Int()); |
118 } |
103 } |
119 else |
104 else |
120 { |
105 { |
121 RDebug::Print(_L("\nStateTran Test: RequestStateTransition from Normal to Invalid state Failed")); |
106 RDebug::Print(_L("\nStateTran Test: RequestStateTransition from Startup to Invalid state Failed")); |
122 User::Leave(KTestAppFailure); |
107 User::Leave(KTestAppFailure); |
123 } |
108 } |
124 |
109 |
125 //Scenario 2 - Request for state change from Startup to fail state with invalid substate |
110 CleanupStack::PopAndDestroy(&stateMan); |
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 } |
111 } |
218 |
112 |
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 |
113 |
282 TInt E32Main() |
114 TInt E32Main() |
283 { |
115 { |
284 __UHEAP_MARK; |
116 __UHEAP_MARK; |
285 |
117 |