|
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: |
|
14 //Check SetState functionality for ENormal,EBTSap,EOffline of RStarterSession class. |
|
15 //Check ResetNetwork() behaviour of RStarterSession class. |
|
16 //Check IsRTCTimeValid when property is valid and invalid |
|
17 //Check rfstatusswp transition failure when process does not have WriteDeviceData or PowerMgmt Capabilities. |
|
18 |
|
19 //In case of a system wide errors, Set error should be passed with the system wide error else |
|
20 //ETrue should be passed to mark the test block as Fail. |
|
21 //Note that ETrue value is 1 and incase where test block expects the result to be 1 some appropriate value other than ETrue should be used. |
|
22 |
|
23 /** |
|
24 @file |
|
25 @SetError |
|
26 @internalComponent - Internal Symbian SetError code |
|
27 */ |
|
28 |
|
29 #include <ssm/clayerswp.hrh> |
|
30 #include <ssm/ssmuiproviderdll.h> |
|
31 #include <ssm/startupdomainpskeys.h> |
|
32 |
|
33 #include "tclayer_step_startersessionwithssm.h" |
|
34 |
|
35 const TUint KRFStatusPropertyKey = 0x2001D2A9; |
|
36 const TUid KRFStatusPropertyCategory = {0x2000D75B}; |
|
37 |
|
38 _LIT(KPolicyFilename, "rfstatusswppolicy.dll"); |
|
39 |
|
40 // Parameters |
|
41 _LIT(KRTCTimeValidity, "RTCTimeValidity"); |
|
42 _LIT(KGlobalState, "GlobalState"); |
|
43 _LIT(KGlobalStateName, "GlobalStateName"); |
|
44 _LIT(KRfStatus, "RfStatus"); |
|
45 #ifdef TEST_SSM_GRACEFUL_OFFLINE |
|
46 _LIT(KWaitToSubscribe, "waitToSubscribe"); |
|
47 #endif |
|
48 |
|
49 // Commands |
|
50 _LIT(KDefineSwpCmd, "DefineSwpCmd"); |
|
51 _LIT(KSetStateCmd, "SetStateCmd"); |
|
52 _LIT(KRequestResetNetworkCmd, "RequestResetNetworkCmd"); |
|
53 _LIT(KIsRTCTimeValidCmd, "IsRTCTimeValidCmd"); |
|
54 _LIT(KRFSwpTransitionNotAllowCmd, "RFSwpTransitionNotAllowCmd"); |
|
55 |
|
56 /** |
|
57 * Constructs a complete CCLayerTestRFSwpStatus object |
|
58 */ |
|
59 CCLayerTestWrapperWithSsm::CCLayerTestWrapperWithSsm():iObject() |
|
60 { |
|
61 |
|
62 } |
|
63 |
|
64 CCLayerTestWrapperWithSsm::~CCLayerTestWrapperWithSsm() |
|
65 { |
|
66 iStarterSession.Close(); |
|
67 iSwp.Close(); |
|
68 } |
|
69 |
|
70 CCLayerTestWrapperWithSsm* CCLayerTestWrapperWithSsm::NewL() |
|
71 { |
|
72 CCLayerTestWrapperWithSsm* ret = new (ELeave) CCLayerTestWrapperWithSsm(); |
|
73 CleanupStack::PushL(ret); |
|
74 ret->ConstructL(); |
|
75 CleanupStack::Pop(ret); |
|
76 return ret; |
|
77 } |
|
78 |
|
79 void CCLayerTestWrapperWithSsm::ConstructL() |
|
80 { |
|
81 User::LeaveIfError(iStarterSession.Connect()); |
|
82 } |
|
83 |
|
84 /** |
|
85 Purpose: Command fuction for a wrapper class |
|
86 |
|
87 */ |
|
88 TBool CCLayerTestWrapperWithSsm::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex) |
|
89 { |
|
90 __UHEAP_MARK; |
|
91 |
|
92 TBool ret = ETrue; |
|
93 // Print out the parameters for debugging |
|
94 INFO_PRINTF2( _L("<font size=3 color=990000><b>aCommand = %S</b></font>"), &aCommand ); |
|
95 INFO_PRINTF3( _L("aSection = %S aAsyncErrorIndex = %D"), &aSection,aAsyncErrorIndex ); |
|
96 TRAPD(err, DoCommandProcessL(aCommand,aSection)); |
|
97 if(err != KErrNone) |
|
98 { |
|
99 SetError(err); |
|
100 ret = EFalse; |
|
101 } |
|
102 |
|
103 __UHEAP_MARKEND; |
|
104 return ret; |
|
105 } |
|
106 |
|
107 /* |
|
108 * Commands are called, implemented only to catch the error in case of Leave |
|
109 */ |
|
110 void CCLayerTestWrapperWithSsm::DoCommandProcessL(const TTEFFunction& aCommand, const TTEFSectionName& aSection) |
|
111 { |
|
112 if(KRFSwpTransitionNotAllowCmd() == aCommand) |
|
113 { |
|
114 doTestRFSwpTransitionNotAllowedCmdL(aSection); |
|
115 } |
|
116 else if(KDefineSwpCmd() == aCommand) |
|
117 { |
|
118 DefineAndRegisterPropertyL(); |
|
119 } |
|
120 else if(KSetStateCmd() == aCommand) |
|
121 { |
|
122 doTestSetStateCmdL(aSection); |
|
123 } |
|
124 else if(KRequestResetNetworkCmd() == aCommand) |
|
125 { |
|
126 doTestRequestResetNetworkCmdL(); |
|
127 } |
|
128 else if(KIsRTCTimeValidCmd() == aCommand) |
|
129 { |
|
130 doTestIsRTCTimeValidCmdL(aSection); |
|
131 } |
|
132 else |
|
133 { |
|
134 User::Leave(EFalse); |
|
135 } |
|
136 } |
|
137 |
|
138 /** |
|
139 * SetError is set to KErrNotSupported and KErrArgument which is expected value of transition not allowed for RFStatusSwPPolicy |
|
140 * RSsmStateManager session request for swp change to check transition allowed or not |
|
141 */ |
|
142 void CCLayerTestWrapperWithSsm::doTestRFSwpTransitionNotAllowedCmdL(const TDesC& aSection) |
|
143 { |
|
144 INFO_PRINTF1(_L("Entering CCLayerTestWrapperWithSsm::doTestRFSwpTransitionNotAllowedCmdL()")); |
|
145 |
|
146 //Connect RSsmSystemWideProperty |
|
147 User::LeaveIfError(iSwp.Connect(KRFStatusPropertyKey)); |
|
148 |
|
149 TInt value = 0; |
|
150 User::LeaveIfError(GetIntFromConfig(aSection, KGlobalState(), value)); |
|
151 RStarterSession::TGlobalState state = static_cast<RStarterSession::TGlobalState>(value); |
|
152 TPtrC name; |
|
153 User::LeaveIfError(GetStringFromConfig(aSection, KGlobalStateName(), name)); |
|
154 INFO_PRINTF2(_L("SetState %S"),&name); |
|
155 TInt err = iStarterSession.SetState(state); |
|
156 SetError(err); |
|
157 if(value == RStarterSession::EOffline) |
|
158 { |
|
159 //RF SwP policy returns KErrNotSupported when process does not have required capability |
|
160 INFO_PRINTF3(_L("Completing SwpTransition with expected error %d, and actual error %d"),KErrNotSupported,err); |
|
161 } |
|
162 else if(value == RStarterSession::ENormal) |
|
163 { |
|
164 INFO_PRINTF3(_L("Completing SwpTransition with expected error %d, and actual error %d"),KErrArgument,err); |
|
165 } |
|
166 iSwp.Close(); |
|
167 INFO_PRINTF1(_L("Exiting CCLayerTestWrapperWithSsm::doTestRFSwpTransitionNotAllowedCmdL()")); |
|
168 } |
|
169 |
|
170 /** |
|
171 * SetError is set to KErrNone which is expected value to pass SetState functionality of RStarterSession class |
|
172 * which is specific to RF SwP change |
|
173 */ |
|
174 void CCLayerTestWrapperWithSsm::doTestSetStateCmdL(const TDesC& aSection) |
|
175 { |
|
176 INFO_PRINTF1(_L("Entering CCLayerTestWrapperWithSsm::doTestSetStateCmdL()")); |
|
177 //Connect RSsmSystemWideProperty |
|
178 User::LeaveIfError(iSwp.Connect(KRFStatusPropertyKey)); |
|
179 |
|
180 TInt value = 0; |
|
181 User::LeaveIfError(GetIntFromConfig(aSection, KGlobalState(), value)); |
|
182 RStarterSession::TGlobalState state = static_cast<RStarterSession::TGlobalState>(value); |
|
183 TPtrC name; |
|
184 User::LeaveIfError(GetStringFromConfig(aSection, KGlobalStateName(), name)); |
|
185 INFO_PRINTF2(_L("SetState %S"),&name); |
|
186 User::LeaveIfError(GetIntFromConfig(aSection, KRfStatus(), value)); |
|
187 TInt currentSwpVal; |
|
188 RProperty::Get(KRFStatusPropertyCategory,KRFStatusPropertyKey,currentSwpVal); |
|
189 //iStarterSession.SetState only called when currentSwpVal and called setting state's SwP value are different |
|
190 if(currentSwpVal != value) |
|
191 { |
|
192 TInt err = iStarterSession.SetState(state); |
|
193 if(err != KErrNone) |
|
194 { |
|
195 SetError(err); |
|
196 INFO_PRINTF4(_L("Completing SetState(%S) with expected value %d, and actual value %d"),&name,KErrArgument,err); |
|
197 } |
|
198 #ifdef TEST_SSM_GRACEFUL_OFFLINE |
|
199 //Wait until RequestStateTransition() completes and KPSGlobalSystemState is changed |
|
200 else |
|
201 { |
|
202 TBool waitToSubscribe = EFalse; |
|
203 GetBoolFromConfig(aSection, KWaitToSubscribe(), waitToSubscribe); |
|
204 if (waitToSubscribe) |
|
205 { |
|
206 TRequestStatus status; |
|
207 RProperty property; |
|
208 if(property.Attach(KPSUidStartup, KPSGlobalSystemState, EOwnerThread ) == KErrNone) |
|
209 { |
|
210 property.Subscribe(status); |
|
211 User::WaitForRequest(status); |
|
212 if ((status.Int()!= KErrNone)) |
|
213 { |
|
214 SetError(status.Int()); |
|
215 ERR_PRINTF2(_L("Subscribing for the status returned an error: %d"),status.Int()); |
|
216 } |
|
217 property.Close(); |
|
218 } |
|
219 else |
|
220 { |
|
221 SetBlockResult(EFail); |
|
222 ERR_PRINTF1(_L("Coudnot attach the property to KPSUidStartup, KPSGlobalSystemState")); |
|
223 } |
|
224 } |
|
225 } |
|
226 #else |
|
227 //wait until RequestSwpChange() completes and rfsatus is changed. |
|
228 else |
|
229 { |
|
230 TRequestStatus status; |
|
231 TInt rfStatus = 0; |
|
232 iSwp.Subscribe(status); |
|
233 User::WaitForRequest(status); |
|
234 TInt err = iSwp.GetValue(rfStatus); |
|
235 //Test will fail if the new rfstatus value is not same as what it is set with |
|
236 //or if status completed with error |
|
237 //or when GetValue returned an error |
|
238 if((rfStatus != value) || |
|
239 (status.Int() != KErrNone) || |
|
240 (err != KErrNone)) |
|
241 { |
|
242 SetError(err); |
|
243 } |
|
244 INFO_PRINTF4(_L("Completing SetState(%S) with expected rfstatus value %d, and actual rfstatus value %d"),&name,value,rfStatus); |
|
245 } |
|
246 #endif // TEST_SSM_GRACEFUL_OFFLINE |
|
247 } |
|
248 else |
|
249 { |
|
250 SetError(ETrue); |
|
251 } |
|
252 //closing swp |
|
253 iSwp.Close(); |
|
254 INFO_PRINTF1(_L("Exiting CCLayerTestWrapperWithSsm::doTestSetStateCmdL()")); |
|
255 } |
|
256 |
|
257 /** |
|
258 * SetError is set to KErrNone which is expected value to pass ResetNetwork functionality of RStarterSession class |
|
259 * It checks rf SwP changes untill it will be ESsmRfOn |
|
260 */ |
|
261 void CCLayerTestWrapperWithSsm::doTestRequestResetNetworkCmdL() |
|
262 { |
|
263 INFO_PRINTF1(_L("Entering CCLayerTestWrapperWithSsm::doTestRequestResetNetworkCmdL()")); |
|
264 User::LeaveIfError(iSwp.Connect(KRFStatusPropertyKey)); |
|
265 |
|
266 User::LeaveIfError(iStarterSession.ResetNetwork()); |
|
267 |
|
268 TInt value = 1; |
|
269 iSwp.GetValue(value); |
|
270 if(value == ESsmRfOff) |
|
271 { |
|
272 TRequestStatus status; |
|
273 iSwp.Subscribe(status); |
|
274 User::WaitForRequest(status); |
|
275 iSwp.GetValue(value); |
|
276 } |
|
277 if(value != ESsmRfOn) |
|
278 { |
|
279 SetError(ETrue); |
|
280 } |
|
281 iSwp.Close(); |
|
282 INFO_PRINTF1(_L("Exiting CCLayerTestWrapperWithSsm::doTestRequestResetNetworkCmdL()")); |
|
283 } |
|
284 |
|
285 /** |
|
286 * SetError is set to KErrNone which is expected value to pass IsRTCTimeValid functionality of RStarterSession class |
|
287 * It define the property with True and False value and checks its validity |
|
288 */ |
|
289 void CCLayerTestWrapperWithSsm::doTestIsRTCTimeValidCmdL(const TDesC& aSection) |
|
290 { |
|
291 INFO_PRINTF1(_L("Entering CCLayerTestWrapperWithSsm::doTestIsRTCTimeValidCmdL()")); |
|
292 |
|
293 TBool value = EFalse; |
|
294 User::LeaveIfError(GetBoolFromConfig(aSection, KRTCTimeValidity(), value)); |
|
295 INFO_PRINTF2(_L("Define Property for IsRTCTimeValid with value %d"), value); |
|
296 TInt ret = RProperty::Set(CSsmUiSpecific::ValidateRTCPropertyCategory(), |
|
297 CSsmUiSpecific::ValidateRTCPropertyKey(), value); |
|
298 TBool validity = EFalse; |
|
299 if( KErrNone == ret ) |
|
300 { |
|
301 validity = iStarterSession.IsRTCTimeValid(); |
|
302 INFO_PRINTF2(_L("IsRTCTimeValid returns with validity %d"),validity); |
|
303 } |
|
304 else |
|
305 { |
|
306 SetError(ret); |
|
307 } |
|
308 |
|
309 //to pass the test value and validity should always be same |
|
310 if(value != validity) |
|
311 { |
|
312 SetError(ETrue); |
|
313 } |
|
314 INFO_PRINTF1(_L("Exiting CCLayerTestWrapperWithSsm::doTestIsRTCTimeValidCmdL()")); |
|
315 } |
|
316 /* |
|
317 * Define property and register |
|
318 */ |
|
319 void CCLayerTestWrapperWithSsm::DefineAndRegisterPropertyL() |
|
320 { |
|
321 //Define the property for rfstatusswppolicy |
|
322 _LIT_SECURITY_POLICY_PASS(KAllowAllPolicy); |
|
323 TInt result = RProperty::Define(KRFStatusPropertyCategory, KRFStatusPropertyKey, RProperty::EInt, |
|
324 KAllowAllPolicy, KAllowAllPolicy); |
|
325 |
|
326 _LIT(KPRINT,"Return code for RProperty::Define for RFstate property key - %d -"); |
|
327 RDebug::Print(KPRINT, result); |
|
328 |
|
329 if( KErrNone != result && KErrAlreadyExists != result) |
|
330 { |
|
331 User::Leave(result); |
|
332 } |
|
333 //define property for ValidateRTC |
|
334 result = RProperty::Define(CSsmUiSpecific::ValidateRTCPropertyCategory(), |
|
335 CSsmUiSpecific::ValidateRTCPropertyKey(), RProperty::EInt, |
|
336 KAllowAllPolicy, KAllowAllPolicy); |
|
337 |
|
338 _LIT(KPRINT2,"Return code for RProperty::Define for ValidateRTCPropertyKey - %d -"); |
|
339 RDebug::Print(KPRINT2, result); |
|
340 |
|
341 if(KErrNone != result && KErrAlreadyExists != result) |
|
342 { |
|
343 User::Leave(result); |
|
344 } |
|
345 RSsmStateManager ssmSession; |
|
346 User::LeaveIfError(ssmSession.Connect()); |
|
347 CleanupClosePushL(ssmSession); |
|
348 TInt err = ssmSession.RegisterSwpMapping(KRFStatusPropertyKey, KPolicyFilename); |
|
349 if(err != KErrAlreadyExists && KErrNone != err ) |
|
350 { |
|
351 User::Leave(err); |
|
352 } |
|
353 RProperty::Set(KRFStatusPropertyCategory,KRFStatusPropertyKey,0xABAC); |
|
354 CleanupStack::PopAndDestroy();//RSsmStateManager ssmSession |
|
355 } |