|
1 // Copyright (c) 2004-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 the License "Symbian Foundation License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // This contains CTestStepSmokeTest |
|
15 // |
|
16 // |
|
17 |
|
18 //user include |
|
19 #include "TestStepSmokeTest.h" |
|
20 |
|
21 //Epoc include |
|
22 #include <testconfigfileparser.h> |
|
23 #include <f32file.h> |
|
24 #include <e32std.h> |
|
25 |
|
26 /*@{*/ |
|
27 _LIT(KExpectedCapCheckResult, "ExpectedCapCheckResult"); |
|
28 _LIT(KConfigFile, "C:\\plattest\\platsec\\plattest_capabilities.config"); |
|
29 _LIT(KDefault, "default"); |
|
30 _LIT(KCapTest, "CapabilityTest"); |
|
31 _LIT(KNo, "No"); |
|
32 |
|
33 _LIT(KLogging, "logging"); |
|
34 _LIT(KLoggingMin, "min"); |
|
35 _LIT(KLoggingNormal, "normal"); |
|
36 _LIT(KLoggingMax, "max"); |
|
37 |
|
38 _LIT(KRepetition, "repetition"); |
|
39 /*@}*/ |
|
40 |
|
41 ////////////////////////////////////////////////////////////////////// |
|
42 // Construction/Destruction |
|
43 ////////////////////////////////////////////////////////////////////// |
|
44 |
|
45 /** |
|
46 Constructor |
|
47 */ |
|
48 EXPORT_C CTestStepSmokeTest::CTestStepSmokeTest() |
|
49 : CTestStep() |
|
50 , iLoggingDetail(ETestLoggingDetail_Normal) |
|
51 , iRepetition(1) |
|
52 { |
|
53 } |
|
54 |
|
55 /** |
|
56 Destructor |
|
57 */ |
|
58 EXPORT_C CTestStepSmokeTest::~CTestStepSmokeTest() |
|
59 { |
|
60 } |
|
61 |
|
62 |
|
63 /** |
|
64 The overriden implementation of CTestStep::doTestStepPreambleL() |
|
65 @return TVerdict- result of the test step |
|
66 @leave - system wide error codes |
|
67 */ |
|
68 EXPORT_C TVerdict CTestStepSmokeTest::doTestStepPreambleL() |
|
69 { |
|
70 TVerdict ret = CTestStep::doTestStepPreambleL(); |
|
71 |
|
72 // Get logging |
|
73 TPtrC logging; |
|
74 if ( GetStringFromConfig(ConfigSection(), KLogging, logging) ) |
|
75 { |
|
76 INFO_PRINTF2(_L("Logging value %S"), &logging); |
|
77 if ( logging.Compare(KLoggingMin) == 0 ) |
|
78 { |
|
79 iLoggingDetail=ETestLoggingDetail_Min; |
|
80 } |
|
81 else if ( logging.Compare(KLoggingNormal) == 0 ) |
|
82 { |
|
83 iLoggingDetail=ETestLoggingDetail_Normal; |
|
84 } |
|
85 else if ( logging.Compare(KLoggingMax) == 0 ) |
|
86 { |
|
87 iLoggingDetail=ETestLoggingDetail_Max; |
|
88 } |
|
89 else |
|
90 { |
|
91 ERR_PRINTF1(_L("Illegal logging value, use min, normal or max.")); |
|
92 ret=EFail; |
|
93 } |
|
94 } |
|
95 |
|
96 // Get repetition count of test |
|
97 GetIntFromConfig(ConfigSection(), KRepetition, iRepetition); |
|
98 INFO_PRINTF2(_L("Repetition %d"), iRepetition); |
|
99 |
|
100 return ret; |
|
101 } |
|
102 |
|
103 /** |
|
104 The overriden implementation of CTestStep::doTestStepPostambleL() |
|
105 It implements the functionality of capability checking if |
|
106 _PLATTEST_CAPTEST_ is ON. |
|
107 @return TVerdict- result of the test step |
|
108 @leave - system wide error codes |
|
109 */ |
|
110 |
|
111 EXPORT_C TVerdict CTestStepSmokeTest::doTestStepPostambleL() |
|
112 { |
|
113 |
|
114 //Read whether to do capability testing.. |
|
115 TPtrC captest(KNo); |
|
116 GetStringFromConfig(KDefault, KCapTest, captest); |
|
117 if( captest.Compare(_L("YES")) == 0) |
|
118 { |
|
119 INFO_PRINTF1(_L("---Capability Testing---")); |
|
120 //Gets the capabilities config file |
|
121 TBuf<KMaxTestExecuteCommandLength> scriptFile; |
|
122 scriptFile.Copy(KConfigFile); |
|
123 INFO_PRINTF2(_L("The config file %S"), &scriptFile); |
|
124 |
|
125 TBuf8<KMaxTestExecuteCommandLength> scriptSection; |
|
126 scriptSection.Copy(_L("Capabilities")); |
|
127 |
|
128 TPtrC serverName = GetServerName(); |
|
129 INFO_PRINTF2(_L("The server name is %S"), &serverName); |
|
130 HBufC8 *scriptItem = HBufC8::NewLC(serverName.Length()); |
|
131 scriptItem->Des().Copy(serverName); |
|
132 |
|
133 //Get the file server session object |
|
134 RFs rFs; |
|
135 TInt err=rFs.Connect(); |
|
136 if(err != KErrNone) |
|
137 { |
|
138 ERR_PRINTF1(_L("Failed to connect with File server")); |
|
139 SetTestStepResult(EFail); |
|
140 } |
|
141 else |
|
142 { |
|
143 CleanupClosePushL(rFs); |
|
144 //Get the config file |
|
145 CTestConfig* configFile = CTestConfig::NewLC(rFs, KNullDesC, scriptFile); |
|
146 if( configFile == NULL) |
|
147 { |
|
148 WARN_PRINTF1(_L("NO Config file found -- Plattest_capabilites.config")); |
|
149 } |
|
150 else |
|
151 { |
|
152 //Get the item value from config file |
|
153 TBuf8<KMaxTestExecuteCommandLength> itemValue; |
|
154 itemValue = configFile->Section(scriptSection)->Item(scriptItem->Des())->Value(); |
|
155 TLex8 capabilityParser(itemValue); |
|
156 TBool capCheckResult= ETrue; |
|
157 |
|
158 while(!capabilityParser.Eos()) |
|
159 { |
|
160 //Parse the capabilities |
|
161 TPtrC8 capability(capabilityParser.NextToken()); |
|
162 |
|
163 HBufC* capabilityRead = HBufC::NewLC(capability.Length()); |
|
164 capabilityRead->Des().Copy(capability); |
|
165 INFO_PRINTF2(_L("Capability Read is %S"), capabilityRead); |
|
166 |
|
167 //Get the capability value |
|
168 TCapability capabilityValue; |
|
169 TPtrC ptrCapabilty(capabilityRead->Des()); |
|
170 TInt err = GetCapability(ptrCapabilty, capabilityValue); |
|
171 if( err != KErrNone) |
|
172 { |
|
173 WARN_PRINTF1(_L("The capability is not found")); |
|
174 } |
|
175 else |
|
176 { |
|
177 //Check if the current process posses the required capability |
|
178 if( !RProcess().HasCapability(capabilityValue) ) |
|
179 { |
|
180 INFO_PRINTF2(_L("The capability %S is not possesed."), capabilityRead); |
|
181 capCheckResult=EFalse; |
|
182 } |
|
183 else |
|
184 { |
|
185 INFO_PRINTF2(_L("The capability %S is possesed."), capabilityRead); |
|
186 } |
|
187 } |
|
188 CleanupStack::PopAndDestroy(capabilityRead); |
|
189 } |
|
190 |
|
191 //read the expected capability check result |
|
192 TBool expectedCapCheckResult = ETrue; |
|
193 GetBoolFromConfig(ConfigSection(), KExpectedCapCheckResult, expectedCapCheckResult); |
|
194 INFO_PRINTF2(_L("The expected cap check result is %D"), expectedCapCheckResult); |
|
195 INFO_PRINTF2(_L("The cap check result is %D"), capCheckResult); |
|
196 |
|
197 if(expectedCapCheckResult == capCheckResult) |
|
198 { |
|
199 SetTestStepResult(EPass); |
|
200 } |
|
201 else |
|
202 { |
|
203 SetTestStepResult(EFail); |
|
204 } |
|
205 } |
|
206 CleanupStack::PopAndDestroy(2, &rFs); |
|
207 } |
|
208 CleanupStack::PopAndDestroy(scriptItem); |
|
209 if(TestStepError() == KErrPermissionDenied) |
|
210 { |
|
211 INFO_PRINTF1(_L(" The failure is due to Platform Security")); |
|
212 } |
|
213 } |
|
214 |
|
215 TVerdict ret = CTestStep::doTestStepPostambleL(); |
|
216 return ret; |
|
217 } |
|
218 |
|
219 /** |
|
220 Get the capability id (enum value) for the capability name |
|
221 given as string. |
|
222 @param aCapability - Capability name |
|
223 @param aCapabilityValue - value for the capability name |
|
224 @return TInt - error codes |
|
225 @leave - None |
|
226 */ |
|
227 EXPORT_C TInt CTestStepSmokeTest::GetCapability(TPtrC aCapability, TCapability& aCapabilityValue) |
|
228 { |
|
229 INFO_PRINTF2(_L("The capability get is %S"), &aCapability); |
|
230 TInt ret=KErrNone; |
|
231 |
|
232 TBuf<KMaxTestExecuteCommandLength> capCaseValue(aCapability); |
|
233 capCaseValue.LowerCase(); |
|
234 |
|
235 if(!capCaseValue.Compare(_L("tcb" ))) |
|
236 { |
|
237 aCapabilityValue=ECapabilityTCB; |
|
238 } |
|
239 else if(!capCaseValue.Compare(_L("commdd" ))) |
|
240 { |
|
241 aCapabilityValue=ECapabilityCommDD; |
|
242 } |
|
243 else if(!capCaseValue.Compare(_L("powermgmt" ))) |
|
244 { |
|
245 aCapabilityValue=ECapabilityPowerMgmt; |
|
246 } |
|
247 else if(!capCaseValue.Compare(_L("multimediadd" ))) |
|
248 { |
|
249 aCapabilityValue=ECapabilityMultimediaDD; |
|
250 } |
|
251 else if(!capCaseValue.Compare(_L("readdevicedata" ))) |
|
252 { |
|
253 aCapabilityValue=ECapabilityReadDeviceData; |
|
254 } |
|
255 else if(!capCaseValue.Compare(_L("writedevicedata" ))) |
|
256 { |
|
257 aCapabilityValue=ECapabilityWriteDeviceData; |
|
258 } |
|
259 else if(!capCaseValue.Compare(_L("drm" ))) |
|
260 { |
|
261 aCapabilityValue=ECapabilityDRM; |
|
262 } |
|
263 else if(!capCaseValue.Compare(_L("trustedui" ))) |
|
264 { |
|
265 aCapabilityValue=ECapabilityTrustedUI; |
|
266 } |
|
267 else if(!capCaseValue.Compare(_L("protserv" ))) |
|
268 { |
|
269 aCapabilityValue=ECapabilityProtServ; |
|
270 } |
|
271 else if(!capCaseValue.Compare(_L("diskadmin" ))) |
|
272 { |
|
273 aCapabilityValue=ECapabilityDiskAdmin; |
|
274 } |
|
275 else if(!capCaseValue.Compare(_L("networkcontrol" ))) |
|
276 { |
|
277 aCapabilityValue=ECapabilityNetworkControl; |
|
278 } |
|
279 else if(!capCaseValue.Compare(_L("allfiles" ))) |
|
280 { |
|
281 aCapabilityValue=ECapabilityAllFiles; |
|
282 } |
|
283 else if(!capCaseValue.Compare(_L("swevent" ))) |
|
284 { |
|
285 aCapabilityValue=ECapabilitySwEvent; |
|
286 } |
|
287 else if(!capCaseValue.Compare(_L("networkservices" ))) |
|
288 { |
|
289 aCapabilityValue=ECapabilityNetworkServices; |
|
290 } |
|
291 else if(!capCaseValue.Compare(_L("localservices" ))) |
|
292 { |
|
293 aCapabilityValue=ECapabilityLocalServices; |
|
294 } |
|
295 else if(!capCaseValue.Compare(_L("readuserdata" ))) |
|
296 { |
|
297 aCapabilityValue=ECapabilityReadUserData; |
|
298 } |
|
299 else if(!capCaseValue.Compare(_L("writeuserdata"))) |
|
300 { |
|
301 aCapabilityValue=ECapabilityWriteUserData; |
|
302 } |
|
303 else if(!capCaseValue.Compare(_L("location"))) |
|
304 { |
|
305 aCapabilityValue=ECapabilityLocation; |
|
306 } |
|
307 else if(!capCaseValue.Compare(_L("none"))) |
|
308 { |
|
309 aCapabilityValue=ECapability_None; |
|
310 } |
|
311 else |
|
312 { |
|
313 INFO_PRINTF2(_L("Unrecognised capability %S, will be rejected"), &capCaseValue); |
|
314 ret=KErrNotFound; |
|
315 } |
|
316 |
|
317 return ret; |
|
318 } |
|
319 |
|
320 |
|
321 /** |
|
322 Verifies the given time is nearly equal to current UTC time. |
|
323 @param aTime - Time needs to be verified |
|
324 @return TBool - Returns ETrue if aTime is nearly equal to current UTC |
|
325 time, otherwise EFalse |
|
326 @leave - None |
|
327 */ |
|
328 EXPORT_C TBool CTestStepSmokeTest::VerifyUTCTime(TTime aTime) |
|
329 { |
|
330 TTime homeTime; |
|
331 TTimeIntervalSeconds utcOffset; |
|
332 |
|
333 homeTime.HomeTime(); |
|
334 homeTime.SecondsFrom(aTime, utcOffset); |
|
335 INFO_PRINTF2(_L("Calculated utcOffset: %D"), utcOffset.Int()); |
|
336 if(Abs<TInt>(utcOffset.Int()) <= (User::UTCOffset().Int()+120) |
|
337 && Abs<TInt>(utcOffset.Int()) >= (User::UTCOffset().Int()-120)) |
|
338 { |
|
339 return ETrue; |
|
340 } |
|
341 else |
|
342 { |
|
343 return EFalse; |
|
344 } |
|
345 } |