|
1 // Copyright (c) 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: Test wrapper for RSsmStateAwareSession |
|
14 |
|
15 #include <test/datawrapper.h> |
|
16 #include <ssm/ssmdomaindefs.h> |
|
17 #include <ssm/ssmsubstates.hrh> |
|
18 #include <ssm/startupdomainpskeys.h> |
|
19 |
|
20 #include "t_stateawaresession.h" |
|
21 |
|
22 // |
|
23 _LIT(KDomainId, "domainId"); |
|
24 _LIT(KAckNotify, "AckNotify%d"); |
|
25 _LIT(KAcknowledge, "acknowledge"); |
|
26 _LIT(KExpectedState, "expectedState"); |
|
27 _LIT(KError, "error"); |
|
28 |
|
29 static TInt AckNotifyCounter = KErrNone; |
|
30 //commands |
|
31 _LIT(KCmdNewL, "NewL"); |
|
32 _LIT(KCmdConnect, "Connect"); |
|
33 _LIT(KCmdRequestStateNotification, "RequestStateNotification"); |
|
34 _LIT(KCmdAcknowledgeStateNotification, "AcknowledgeStateNotification"); |
|
35 _LIT(KCmdClose, "Close"); |
|
36 _LIT(KCmdState, "State"); |
|
37 _LIT(KCmdRequestStateNotificationCancel, "RequestStateNotificationCancel"); |
|
38 _LIT(KCmdAcknowledgeAndRequestStateNotification, "AcknowledgeAndRequestStateNotification"); |
|
39 _LIT(KCmdDestructor, "~"); |
|
40 |
|
41 /** |
|
42 * Two phase constructor |
|
43 */ |
|
44 CTestRStateAwareSession* CTestRStateAwareSession::NewL() |
|
45 { |
|
46 CTestRStateAwareSession* testStateAwareSession = new (ELeave) CTestRStateAwareSession(); |
|
47 CleanupStack::PushL(testStateAwareSession); |
|
48 testStateAwareSession->ConstructL(); |
|
49 CleanupStack::Pop(testStateAwareSession); |
|
50 return testStateAwareSession; |
|
51 } |
|
52 |
|
53 /** |
|
54 * @return pointer to the object that the data wraps |
|
55 */ |
|
56 TAny* CTestRStateAwareSession::GetObject() |
|
57 { |
|
58 return iSsmStateAwareSession; |
|
59 } |
|
60 |
|
61 /** |
|
62 * SetObjectL |
|
63 */ |
|
64 void CTestRStateAwareSession::SetObjectL(TAny* aAny) |
|
65 { |
|
66 DoCleanup(); |
|
67 iSsmStateAwareSession=static_cast<RSsmStateAwareSession*> (aAny); |
|
68 } |
|
69 |
|
70 /** |
|
71 * DisownObjectL |
|
72 */ |
|
73 void CTestRStateAwareSession::DisownObjectL() |
|
74 { |
|
75 iSsmStateAwareSession=NULL; |
|
76 } |
|
77 |
|
78 /** |
|
79 * Protected constructor. First phase construction |
|
80 */ |
|
81 CTestRStateAwareSession::CTestRStateAwareSession(): |
|
82 CDataWrapper() |
|
83 { |
|
84 } |
|
85 |
|
86 /** |
|
87 * Protected constructor. Second phase construction |
|
88 */ |
|
89 void CTestRStateAwareSession::ConstructL() |
|
90 { |
|
91 iActiveNotifyOnChange = CActiveCallback::NewL(*this); |
|
92 } |
|
93 |
|
94 /** |
|
95 * Destructor. |
|
96 */ |
|
97 CTestRStateAwareSession::~CTestRStateAwareSession() |
|
98 { |
|
99 DoCleanup(); |
|
100 delete iActiveNotifyOnChange; |
|
101 } |
|
102 |
|
103 /** |
|
104 * Process a command read from the ini file |
|
105 * |
|
106 * @param aCommand the command to process |
|
107 * @param aSection the entry in the ini file requiring the command to be processed |
|
108 * |
|
109 * @return ETrue if the command is processed |
|
110 */ |
|
111 TBool CTestRStateAwareSession::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex) |
|
112 { |
|
113 TBool retVal = ETrue; |
|
114 if (aCommand == KCmdNewL) |
|
115 { |
|
116 DoCmdNew(); |
|
117 } |
|
118 else if (aCommand == KCmdConnect) |
|
119 { |
|
120 DoCmdConnect(aSection); |
|
121 } |
|
122 else if (aCommand == KCmdRequestStateNotification) |
|
123 { |
|
124 DoCmdRequestStateNotification(aAsyncErrorIndex); |
|
125 } |
|
126 else if (aCommand == KCmdAcknowledgeStateNotification) |
|
127 { |
|
128 DoCmdAcknowledgeStateNotification(aSection); |
|
129 } |
|
130 else if (aCommand == KCmdClose) |
|
131 { |
|
132 DoCmdClose(); |
|
133 } |
|
134 else if (aCommand == KCmdState) |
|
135 { |
|
136 DoCmdState(aSection); |
|
137 } |
|
138 else if (aCommand == KCmdRequestStateNotificationCancel) |
|
139 { |
|
140 DoCmdRequestStateNotificationCancel(); |
|
141 } |
|
142 else if (aCommand == KCmdAcknowledgeAndRequestStateNotification) |
|
143 { |
|
144 DoCmdAcknowledgeAndRequestStateNotification(aSection, aAsyncErrorIndex); |
|
145 } |
|
146 else if (aCommand == KCmdDestructor) |
|
147 { |
|
148 DoCmdDestructor(); |
|
149 } |
|
150 else |
|
151 { |
|
152 retVal = EFalse; |
|
153 } |
|
154 |
|
155 return retVal; |
|
156 } |
|
157 |
|
158 /** |
|
159 * Creates RSSmStateAwareSession class instance |
|
160 */ |
|
161 void CTestRStateAwareSession::DoCmdNew() |
|
162 { |
|
163 INFO_PRINTF1(_L("Create RSsmStateAwareSession class instance")); |
|
164 DoCleanup(); |
|
165 |
|
166 TRAPD(err, iSsmStateAwareSession = new (ELeave)RSsmStateAwareSession()); |
|
167 |
|
168 if (err != KErrNone) |
|
169 { |
|
170 ERR_PRINTF2(_L("new error %d"), err); |
|
171 SetError(err); |
|
172 } |
|
173 } |
|
174 |
|
175 /** |
|
176 * Close RSsmStateAwareSession handle |
|
177 */ |
|
178 void CTestRStateAwareSession::DoCmdClose() |
|
179 { |
|
180 INFO_PRINTF1(_L("Close RSsmStateAwareSession")); |
|
181 iSsmStateAwareSession->Close(); |
|
182 } |
|
183 |
|
184 /** |
|
185 * Contains cleanup implementation |
|
186 */ |
|
187 void CTestRStateAwareSession::DoCleanup() |
|
188 { |
|
189 if(iSsmStateAwareSession != NULL) |
|
190 { |
|
191 INFO_PRINTF1(_L("Deleting current RSsmStateAwareSession")); |
|
192 delete iSsmStateAwareSession; |
|
193 iSsmStateAwareSession = NULL; |
|
194 } |
|
195 } |
|
196 |
|
197 /** |
|
198 * Destroy RStateAwareSession object |
|
199 */ |
|
200 void CTestRStateAwareSession::DoCmdDestructor() |
|
201 { |
|
202 INFO_PRINTF1(_L("Destroying the RStateAwareSession object")); |
|
203 DoCleanup(); |
|
204 } |
|
205 |
|
206 /** |
|
207 * Connects a client to RStateAwareSession with Domain Id |
|
208 */ |
|
209 void CTestRStateAwareSession::DoCmdConnect(const TDesC& aSection) |
|
210 { |
|
211 TPtrC domainIdName; |
|
212 if (!GetStringFromConfig(aSection, KDomainId(), domainIdName)) |
|
213 { |
|
214 //set default domainId if value is not provided in .ini file |
|
215 domainIdName.Set(_L("KSM2UiServicesDomain1")); |
|
216 } |
|
217 TDmDomainId domainId; |
|
218 if(MapToDomainId(domainIdName, domainId )) |
|
219 { |
|
220 INFO_PRINTF2(_L(" Calling RSsmStateAwareSession->Connect with domain id %S"), &domainIdName ); |
|
221 TInt err = iSsmStateAwareSession->Connect(domainId); |
|
222 if (KErrNone != err) |
|
223 { |
|
224 ERR_PRINTF2(_L("Connect() error %d"), err); |
|
225 SetError(err); |
|
226 } |
|
227 } |
|
228 else |
|
229 { |
|
230 ERR_PRINTF2(_L("Could not map %S to domain Id"), &domainIdName ); |
|
231 SetBlockResult(EFail); |
|
232 } |
|
233 } |
|
234 |
|
235 /** |
|
236 * DoCmdRequestStateNotification |
|
237 */ |
|
238 void CTestRStateAwareSession::DoCmdRequestStateNotification(const TInt aAsyncErrorIndex) |
|
239 { |
|
240 INFO_PRINTF2(_L("RequestStateNotification with Asyc Error Index: %d"), aAsyncErrorIndex); |
|
241 iSsmStateAwareSession->RequestStateNotification(iActiveNotifyOnChange->iStatus); |
|
242 iActiveNotifyOnChange->Activate(aAsyncErrorIndex); |
|
243 IncOutstanding(); |
|
244 } |
|
245 |
|
246 /** |
|
247 * DoCmdAcknowledgeStateNotification |
|
248 */ |
|
249 void CTestRStateAwareSession::DoCmdAcknowledgeStateNotification(const TDesC& aSection) |
|
250 { |
|
251 TInt error; |
|
252 if (!GetIntFromConfig(aSection, KError(), error )) |
|
253 { |
|
254 //set default error value if value is not provided in .ini file |
|
255 error = KErrNone; |
|
256 } |
|
257 iSsmStateAwareSession->AcknowledgeStateNotification(error); |
|
258 } |
|
259 |
|
260 /** |
|
261 * DoCmdAcknowledgeAndRequestStateNotification |
|
262 */ |
|
263 void CTestRStateAwareSession::DoCmdAcknowledgeAndRequestStateNotification(const TDesC& aSection, const TInt aAsyncErrorIndex) |
|
264 { |
|
265 TInt error; |
|
266 if (!GetIntFromConfig(aSection, KError(), error )) |
|
267 { |
|
268 //set default error value if value is not provided in .ini file |
|
269 error = KErrNone; |
|
270 } |
|
271 iSsmStateAwareSession->AcknowledgeAndRequestStateNotification(error, iActiveNotifyOnChange->iStatus ); |
|
272 iActiveNotifyOnChange->Activate(aAsyncErrorIndex); |
|
273 IncOutstanding(); |
|
274 } |
|
275 |
|
276 /** |
|
277 * DoCmdRequestStateNotificationCancel |
|
278 */ |
|
279 void CTestRStateAwareSession::DoCmdRequestStateNotificationCancel() |
|
280 { |
|
281 INFO_PRINTF1(_L("RequestStateNotificationCancel is called ")); |
|
282 iSsmStateAwareSession->RequestStateNotificationCancel(); |
|
283 } |
|
284 |
|
285 /** |
|
286 * DoCmdState() |
|
287 */ |
|
288 void CTestRStateAwareSession::DoCmdState(const TDesC& aSection) |
|
289 { |
|
290 TSsmState state; |
|
291 state = iSsmStateAwareSession->State(); |
|
292 INFO_PRINTF3(_L("Call to State() returned MainState %d : Substate %d"),state.MainState(),state.SubState()); |
|
293 TPtrC readExpectedState; |
|
294 // Comparision will be done only when value is read from the ini file...other wise expected value is ignored |
|
295 if (GetStringFromConfig(aSection, KExpectedState(), readExpectedState )) |
|
296 { |
|
297 TUint16 expectedState; |
|
298 if (MapToMainState(readExpectedState, expectedState)) |
|
299 { |
|
300 if(expectedState!=state.MainState()) |
|
301 { |
|
302 ERR_PRINTF3(_L("Expected State is %d : Actual State is %d"), expectedState,state.MainState() ); |
|
303 SetBlockResult(EFail); |
|
304 } |
|
305 } |
|
306 else |
|
307 { |
|
308 ERR_PRINTF2(_L("Could not map %S to any state"), &readExpectedState ); |
|
309 SetBlockResult(EFail); |
|
310 } |
|
311 } |
|
312 } |
|
313 |
|
314 /** |
|
315 Virtual RunL - Called on completion of an asynchronous command |
|
316 @see MTPActiveCallback |
|
317 @param aActive Active Object that RunL has been called on |
|
318 @pre N/A |
|
319 @post N/A |
|
320 @leave system wide error code |
|
321 */ |
|
322 void CTestRStateAwareSession::RunL(CActive* aActive, TInt aIndex) |
|
323 { |
|
324 TInt error = KErrNone; |
|
325 if (aActive == iActiveNotifyOnChange) |
|
326 { |
|
327 error = iActiveNotifyOnChange->iStatus.Int(); |
|
328 if (error == KErrNone) |
|
329 { |
|
330 TSsmState currentState = iSsmStateAwareSession->State(); |
|
331 // This component only responds to Offline state events. |
|
332 if (currentState.MainState() == ESsmNormal && currentState.SubState() == ESsmNormalRfOffSubState ) |
|
333 { |
|
334 TInt globalSystemState; |
|
335 error =RProperty::Get(KPSUidStartup, KPSGlobalSystemState, globalSystemState); |
|
336 const TInt ackErr = ( error != KErrNone || globalSystemState == ESwStateNormalRfOff )? KErrGeneral : KErrNone; |
|
337 //Acknowledge the state change |
|
338 INFO_PRINTF2(_L("RunL() called with AsyncIndex %d"), aIndex); |
|
339 TBuf<KMaxTestExecuteCommandLength> tempStore; |
|
340 tempStore.Format(KAckNotify(),++AckNotifyCounter); |
|
341 TBool acknowledge = ETrue; |
|
342 GetBoolFromConfig(tempStore,KAcknowledge(),acknowledge); |
|
343 //Acknowledge with success/failure |
|
344 if (acknowledge) |
|
345 { |
|
346 iSsmStateAwareSession->AcknowledgeStateNotification(ackErr); |
|
347 } |
|
348 } |
|
349 } |
|
350 else |
|
351 { |
|
352 ERR_PRINTF2(_L("RunL Error %d"), error); |
|
353 SetAsyncError(aIndex, error); |
|
354 } |
|
355 } |
|
356 DecOutstanding(); |
|
357 } |
|
358 |
|
359 /** |
|
360 Virtual DoCancel - Request to cancel the asynchronous command |
|
361 @see - MTPActiveCallback |
|
362 @param aActive Active Object that DoCancel has been called on |
|
363 @pre - N/A |
|
364 @post - N/A |
|
365 @leave system wide error code |
|
366 */ |
|
367 void CTestRStateAwareSession::DoCancel(CActive* aActive, TInt aIndex) |
|
368 { |
|
369 INFO_PRINTF1(_L("DoCancel")); |
|
370 if(aActive == iActiveNotifyOnChange) |
|
371 { |
|
372 TInt err = iActiveNotifyOnChange->iStatus.Int(); |
|
373 if (err!=KErrNone) |
|
374 { |
|
375 ERR_PRINTF2(_L("DoCancel Error %d"), err); |
|
376 SetAsyncError(aIndex, err); |
|
377 } |
|
378 } |
|
379 DecOutstanding(); |
|
380 } |
|
381 /** |
|
382 * Helper method to map the DomainIds. This can be extendable for other domain Ids |
|
383 */ |
|
384 TBool CTestRStateAwareSession::MapToDomainId(TPtrC& aDomainIdName, TDmDomainId& aDomainId) |
|
385 { |
|
386 TBool ret = ETrue; |
|
387 if (!(aDomainIdName.Compare(_L("KSM2UiServicesDomain1")))) |
|
388 { |
|
389 aDomainId = KSM2UiServicesDomain1; |
|
390 } |
|
391 else if (!(aDomainIdName.Compare(_L("KSM2HALDomain2")))) |
|
392 { |
|
393 aDomainId = KSM2HALDomain2; |
|
394 } |
|
395 else if (!(aDomainIdName.Compare(_L("KSM2HALDomain3")))) |
|
396 { |
|
397 aDomainId = KSM2HALDomain3; |
|
398 } |
|
399 else if (!(aDomainIdName.Compare(_L("KSM2AppServicesDomain1")))) |
|
400 { |
|
401 aDomainId = KSM2AppServicesDomain1; |
|
402 } |
|
403 else if (!(aDomainIdName.Compare(_L("KSM2AppServicesDomain2")))) |
|
404 { |
|
405 aDomainId = KSM2AppServicesDomain2; |
|
406 } |
|
407 else if (!(aDomainIdName.Compare(_L("KSM2AppServicesDomain3")))) |
|
408 { |
|
409 aDomainId = KSM2AppServicesDomain3; |
|
410 } |
|
411 else if (!(aDomainIdName.Compare(_L("KSM2AppServicesDomain4")))) |
|
412 { |
|
413 aDomainId = KSM2AppServicesDomain4; |
|
414 } |
|
415 else |
|
416 { |
|
417 ret = EFalse; |
|
418 } |
|
419 return ret; |
|
420 } |
|
421 |
|
422 /** |
|
423 * Helper method to Map defined MainState on ssmstates.hrh |
|
424 */ |
|
425 TBool CTestRStateAwareSession::MapToMainState( TPtrC& aGetMainState, TUint16& aMainState ) |
|
426 { |
|
427 TInt ret = ETrue; |
|
428 if(!(aGetMainState.Compare(_L("ESsmStartup")))) |
|
429 { |
|
430 aMainState = ESsmStartup; |
|
431 } |
|
432 else if(!(aGetMainState.Compare(_L("ESsmNormal")))) |
|
433 { |
|
434 aMainState = ESsmNormal; |
|
435 } |
|
436 else if(!(aGetMainState.Compare(_L("ESsmShutdown")))) |
|
437 { |
|
438 aMainState = ESsmShutdown; |
|
439 } |
|
440 else if(!(aGetMainState.Compare(_L("ESsmFail")))) |
|
441 { |
|
442 aMainState = ESsmFail; |
|
443 } |
|
444 else if(!(aGetMainState.Compare(_L("ESsmRestore")))) |
|
445 { |
|
446 aMainState = ESsmRestore; |
|
447 } |
|
448 else if(!(aGetMainState.Compare(_L("ESsmEmergencyCallsOnly")))) |
|
449 { |
|
450 aMainState = ESsmEmergencyCallsOnly; |
|
451 } |
|
452 else |
|
453 { |
|
454 ret = EFalse; |
|
455 } |
|
456 return ret; |
|
457 } |
|
458 |