|
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 // |
|
15 |
|
16 #include <e32test.h> |
|
17 #include <featmgr.h> |
|
18 #include <featureuids.h> |
|
19 #include <featurecontrol.h> |
|
20 #include <featdiscovery.h> |
|
21 |
|
22 using namespace NFeature; |
|
23 |
|
24 const TInt KInvalidFeatureId1 = 90901671; |
|
25 const TInt KInvalidNegFeatureId2 = -90901671; |
|
26 const TUid KInvalidFeatureUid1 = {KInvalidFeatureId1}; |
|
27 |
|
28 /////////////////////////////////////////////////////////////////////////////////////// |
|
29 |
|
30 static RTest TheTest(_L("t_fmgrapi")); |
|
31 |
|
32 /////////////////////////////////////////////////////////////////////////////////////// |
|
33 |
|
34 //Deletes all created test files. |
|
35 void DestroyTestEnv() |
|
36 { |
|
37 } |
|
38 |
|
39 /////////////////////////////////////////////////////////////////////////////////////// |
|
40 /////////////////////////////////////////////////////////////////////////////////////// |
|
41 //Test macros and functions |
|
42 void Check1(TInt aValue, TInt aLine) |
|
43 { |
|
44 if(!aValue) |
|
45 { |
|
46 DestroyTestEnv(); |
|
47 RDebug::Print(_L("*** Expression evaluated to false. Line %d\r\n"), aLine); |
|
48 TheTest(EFalse, aLine); |
|
49 } |
|
50 } |
|
51 void Check2(TInt aValue, TInt aExpected, TInt aLine) |
|
52 { |
|
53 if(aValue != aExpected) |
|
54 { |
|
55 DestroyTestEnv(); |
|
56 RDebug::Print(_L("*** Expected: %d, got: %d. Line %d\r\n"), aExpected, aValue, aLine); |
|
57 TheTest(EFalse, aLine); |
|
58 } |
|
59 } |
|
60 #define TEST(arg) ::Check1((arg), __LINE__) |
|
61 #define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__) |
|
62 |
|
63 /////////////////////////////////////////////////////////////////////////////////////// |
|
64 |
|
65 /** |
|
66 @SYMTestCaseID PDS-EFM-CT-4059 |
|
67 @SYMTestCaseDesc |
|
68 @SYMTestPriority High |
|
69 @SYMTestActions |
|
70 @SYMTestExpectedResults Test must not fail |
|
71 @SYMDEF DEF144262 |
|
72 */ |
|
73 void FeatureSupportedTestL() |
|
74 { |
|
75 FeatureManager::InitializeLibL(); |
|
76 FeatureManager::InitializeLibL(); |
|
77 |
|
78 //Feature, default present |
|
79 TBool rc = FeatureManager::FeatureSupported(KConnectivity.iUid); |
|
80 TEST(rc); |
|
81 //Feature, default not present |
|
82 rc = FeatureManager::FeatureSupported(KPrint.iUid); |
|
83 TEST(rc); |
|
84 |
|
85 //Ivalid feature UID |
|
86 rc = FeatureManager::FeatureSupported(KInvalidFeatureId1); |
|
87 TEST(!rc); |
|
88 //Ivalid feature UID - negative |
|
89 rc = FeatureManager::FeatureSupported(KInvalidNegFeatureId2); |
|
90 TEST(!rc); |
|
91 |
|
92 FeatureManager::UnInitializeLib(); |
|
93 FeatureManager::UnInitializeLib(); |
|
94 FeatureManager::UnInitializeLib();//it should be safe to call UnInitializeLib() even without matching InitializeLibL() call |
|
95 } |
|
96 |
|
97 /** |
|
98 @SYMTestCaseID PDS-EFM-CT-4060 |
|
99 @SYMTestCaseDesc |
|
100 @SYMTestPriority High |
|
101 @SYMTestActions |
|
102 @SYMTestExpectedResults Test must not fail |
|
103 @SYMDEF DEF144262 |
|
104 */ |
|
105 void FeatureControlTest1() |
|
106 { |
|
107 RFeatureControl ctrl; |
|
108 TInt err = ctrl.Open(); |
|
109 TEST2(err, KErrNone); |
|
110 ///////////////////////////////////////////////////////////// |
|
111 RFeatureUidArray farray; |
|
112 err = ctrl.ListSupportedFeatures(farray); |
|
113 TEST2(err, KErrNone); |
|
114 TheTest.Printf(_L("RFeatureControl::ListSupportedFeatures()\r\n")); |
|
115 for(TInt i=0;i<farray.Count();++i) |
|
116 { |
|
117 TheTest.Printf(_L(" Feature: %08X\r\n"), farray[i].iUid); |
|
118 } |
|
119 ///////////////////////////////////////////////////////////// |
|
120 RFeatureArray farray2; |
|
121 for(TInt i=0;i<farray.Count();++i) |
|
122 { |
|
123 err = farray2.Append(farray[i]); |
|
124 TEST2(err, KErrNone); |
|
125 } |
|
126 |
|
127 err = ctrl.FeaturesSupported(farray2); |
|
128 TEST2(err, KErrNone); |
|
129 |
|
130 TheTest.Printf(_L("RFeatureControl::FeaturesSupported()\r\n")); |
|
131 for(TInt i=0;i<farray2.Count();++i) |
|
132 { |
|
133 TheTest.Printf(_L(" Feature: %08X, Flags: %08X, Data: %08X\r\n"), farray2[i].FeatureUid(), farray2[i].FeatureFlags().iFlags, farray2[i].FeatureData()); |
|
134 } |
|
135 |
|
136 RFeatureArray farray3; |
|
137 err = ctrl.FeaturesSupported(farray3); |
|
138 TEST2(err, KErrArgument); |
|
139 |
|
140 ///////////////////////////////////////////////////////////// |
|
141 farray2.Close(); |
|
142 farray.Close(); |
|
143 ctrl.Close(); |
|
144 ctrl.Close();//It should be safe to call Close() again |
|
145 } |
|
146 |
|
147 /** |
|
148 @SYMTestCaseID PDS-EFM-CT-4061 |
|
149 @SYMTestCaseDesc |
|
150 @SYMTestPriority High |
|
151 @SYMTestActions |
|
152 @SYMTestExpectedResults Test must not fail |
|
153 @SYMDEF DEF144262 |
|
154 */ |
|
155 void FeatureControlTest2() |
|
156 { |
|
157 RFeatureControl ctrl; |
|
158 TInt err = ctrl.Open(); |
|
159 TEST2(err, KErrNone); |
|
160 ///////////////////////////////////////////////////////////// |
|
161 RFeatureUidArray farray; |
|
162 err = ctrl.ListSupportedFeatures(farray); |
|
163 TEST2(err, KErrNone); |
|
164 for(TInt i=0;i<farray.Count();++i) |
|
165 { |
|
166 err = ctrl.FeatureSupported(farray[i]); |
|
167 TEST2(err, KFeatureSupported); |
|
168 |
|
169 TFeatureEntry feat(farray[i]); |
|
170 err = ctrl.FeatureSupported(feat); |
|
171 TEST2(err, KFeatureSupported); |
|
172 } |
|
173 |
|
174 err = ctrl.FeatureSupported(TUid::Uid(KInvalidFeatureId1)); |
|
175 TEST2(err, KErrNotFound); |
|
176 |
|
177 TFeatureEntry feat1(TUid::Uid(KInvalidFeatureId1)); |
|
178 err = ctrl.FeatureSupported(feat1); |
|
179 TEST2(err, KErrNotFound); |
|
180 |
|
181 const TUint KFlags = 0x0134357; |
|
182 const TUint KData = 0xAB5234; |
|
183 TFeatureEntry feat2(TUid::Uid(KInvalidFeatureId1), KFlags, KData); |
|
184 err = ctrl.FeatureSupported(feat2); |
|
185 TEST2(err, KErrNotFound); |
|
186 |
|
187 ///////////////////////////////////////////////////////////// |
|
188 farray.Close(); |
|
189 ctrl.Close(); |
|
190 } |
|
191 |
|
192 /** |
|
193 @SYMTestCaseID PDS-EFM-CT-4062 |
|
194 @SYMTestCaseDesc |
|
195 @SYMTestPriority High |
|
196 @SYMTestActions |
|
197 @SYMTestExpectedResults Test must not fail |
|
198 @SYMDEF DEF144262 |
|
199 */ |
|
200 void FeatureControlTest3() |
|
201 { |
|
202 RFeatureControl ctrl; |
|
203 TInt err = ctrl.Open(); |
|
204 TEST2(err, KErrNone); |
|
205 |
|
206 //Retrieve a uid list of all supported features |
|
207 RFeatureUidArray farray; |
|
208 err = ctrl.ListSupportedFeatures(farray); |
|
209 TEST2(err, KErrNone); |
|
210 //Retrieve a TFeaureEntry list of all supported features |
|
211 RFeatureArray farray2; |
|
212 for(TInt i=0;i<farray.Count();++i) |
|
213 { |
|
214 err = farray2.Append(farray[i]); |
|
215 TEST2(err, KErrNone); |
|
216 } |
|
217 err = ctrl.FeaturesSupported(farray2); |
|
218 TEST2(err, KErrNone); |
|
219 //Play with EnableFeature()/DisableFeature() calls. If the EFeatureModifiable flag is not set then |
|
220 //the feature cannot be enabled or disabled. |
|
221 for(TInt i=0;i<farray2.Count();++i) |
|
222 { |
|
223 const TFeatureEntry& fentry = farray2[i]; |
|
224 TBitFlags32 flags = fentry.FeatureFlags(); |
|
225 |
|
226 err = ctrl.DisableFeature(fentry.FeatureUid()); |
|
227 TEST2(err, flags.IsSet(EFeatureModifiable) ? KErrNone : KErrAccessDenied); |
|
228 |
|
229 err = ctrl.EnableFeature(fentry.FeatureUid()); |
|
230 TEST2(err, flags.IsSet(EFeatureModifiable) ? KErrNone : KErrAccessDenied); |
|
231 } |
|
232 //It is impossible to set non-existing feature |
|
233 const TUid KNewFeatureUid = {0x7888ABCD}; |
|
234 err = ctrl.SetFeature(KNewFeatureUid, ETrue, 0x0); |
|
235 TEST2(err, KErrNotFound); |
|
236 //It is impossible to set non-modifiable feature |
|
237 TBitFlags32 flags = farray2[0].FeatureFlags(); |
|
238 err = ctrl.SetFeature(farray2[0].FeatureUid(), ETrue, 0x0); |
|
239 TEST2(err, flags.IsSet(EFeatureModifiable) ? KErrNone : KErrAccessDenied); |
|
240 //Add new feature |
|
241 flags.ClearAll(); |
|
242 flags.Set(EFeatureSupported); |
|
243 flags.Set(EFeatureModifiable); |
|
244 TFeatureEntry fentry(KNewFeatureUid, flags, 0x0); |
|
245 err = ctrl.AddFeature(fentry); |
|
246 TEST2(err, KErrNone); |
|
247 //Retrieve the new feature and check flags |
|
248 err = ctrl.FeatureSupported(fentry); |
|
249 TEST2(err, KFeatureSupported); |
|
250 flags = fentry.FeatureFlags(); |
|
251 TEST(flags.IsSet(EFeatureSupported)); |
|
252 TEST(flags.IsSet(EFeatureModifiable)); |
|
253 //Now, it should be possible to set the new feature - it is modifiable. |
|
254 err = ctrl.SetFeature(fentry.FeatureUid(), ETrue, 0x0); |
|
255 TEST2(err, KErrNone); |
|
256 err = ctrl.SetFeature(fentry.FeatureUid(), EFalse, 0x0); |
|
257 TEST2(err, KErrNone); |
|
258 //Enable/disable |
|
259 err = ctrl.EnableFeature(fentry.FeatureUid()); |
|
260 TEST2(err, KErrNone); |
|
261 err = ctrl.DisableFeature(fentry.FeatureUid()); |
|
262 TEST2(err, KErrNone); |
|
263 //Delete the added feature |
|
264 err = ctrl.DeleteFeature(fentry.FeatureUid()); |
|
265 TEST2(err, KErrNone); |
|
266 err = ctrl.DeleteFeature(fentry.FeatureUid()); |
|
267 TEST2(err, KErrNotFound); |
|
268 |
|
269 ///////////////////////////////////////////////////////////// |
|
270 farray2.Close(); |
|
271 farray.Close(); |
|
272 ctrl.Close(); |
|
273 } |
|
274 |
|
275 /** |
|
276 @SYMTestCaseID PDS-EFM-CT-4063 |
|
277 @SYMTestCaseDesc |
|
278 @SYMTestPriority High |
|
279 @SYMTestActions |
|
280 @SYMTestExpectedResults Test must not fail |
|
281 @SYMDEF DEF144262 |
|
282 */ |
|
283 void FeatureDiscoveryTest1L() |
|
284 { |
|
285 TBool rc = CFeatureDiscovery::IsFeatureSupportedL(KInvalidFeatureId1); |
|
286 TEST(!rc); |
|
287 rc = CFeatureDiscovery::IsFeatureSupportedL(KLocationManagement.iUid); |
|
288 TEST(rc); |
|
289 |
|
290 rc = CFeatureDiscovery::IsFeatureSupportedL(KInvalidFeatureUid1); |
|
291 TEST(!rc); |
|
292 rc = CFeatureDiscovery::IsFeatureSupportedL(KLocationManagement); |
|
293 TEST(rc); |
|
294 |
|
295 CFeatureDiscovery* fdiscovery = CFeatureDiscovery::NewLC(); |
|
296 |
|
297 rc = fdiscovery->IsSupported(KInvalidFeatureId1); |
|
298 TEST(!rc); |
|
299 rc = fdiscovery->IsSupported(KLocationManagement.iUid); |
|
300 TEST(rc); |
|
301 |
|
302 rc = fdiscovery->IsSupported(KInvalidFeatureUid1); |
|
303 TEST(!rc); |
|
304 rc = fdiscovery->IsSupported(KLocationManagement); |
|
305 TEST(rc); |
|
306 |
|
307 CleanupStack::PopAndDestroy(fdiscovery); |
|
308 } |
|
309 |
|
310 void DoFeatureDiscoveryTest2(TBool aStaticMethodsUsed) |
|
311 { |
|
312 CFeatureDiscovery* fdiscovery = NULL; |
|
313 if(!aStaticMethodsUsed) |
|
314 { |
|
315 fdiscovery = CFeatureDiscovery::NewL(); |
|
316 } |
|
317 ////////////////////////////////////////////////////////// |
|
318 //A test with a set: one valid and one invalid feature |
|
319 TFeatureSet fset; |
|
320 TInt err = fset.Append(KConnectivity); |
|
321 TEST2(err, KErrNone); |
|
322 err = fset.Append(KInvalidFeatureUid1); |
|
323 TEST2(err, KErrNone); |
|
324 TBool rc = fset.IsFeatureSupported(KConnectivity); |
|
325 TEST(!rc); |
|
326 rc = fset.IsFeatureSupported(KInvalidFeatureUid1); |
|
327 TEST(!rc); |
|
328 if(aStaticMethodsUsed) |
|
329 { |
|
330 TRAP(err, CFeatureDiscovery::FeaturesSupportedL(fset)); |
|
331 } |
|
332 else |
|
333 { |
|
334 err = fdiscovery->FeaturesSupported(fset); |
|
335 } |
|
336 TEST2(err, KErrNone); |
|
337 rc = fset.IsFeatureSupported(KConnectivity); |
|
338 TEST(rc); |
|
339 rc = fset.IsFeatureSupported(KInvalidFeatureUid1); |
|
340 TEST(!rc); |
|
341 rc = fset.AreAllFeaturesSupported(); |
|
342 TEST(!rc); |
|
343 ////////////////////////////////////////////////////////// |
|
344 //A test with an empty set |
|
345 TFeatureSet fset2; |
|
346 rc = fset2.IsFeatureSupported(KConnectivity); |
|
347 TEST(!rc); |
|
348 rc = fset2.IsFeatureSupported(KInvalidFeatureUid1); |
|
349 TEST(!rc); |
|
350 if(aStaticMethodsUsed) |
|
351 { |
|
352 TRAP(err, CFeatureDiscovery::FeaturesSupportedL(fset2)); |
|
353 } |
|
354 else |
|
355 { |
|
356 err = fdiscovery->FeaturesSupported(fset2); |
|
357 } |
|
358 TEST2(err, KErrArgument); |
|
359 rc = fset2.IsFeatureSupported(KConnectivity); |
|
360 TEST(!rc); |
|
361 rc = fset2.IsFeatureSupported(KInvalidFeatureUid1); |
|
362 TEST(!rc); |
|
363 rc = fset2.AreAllFeaturesSupported(); |
|
364 TEST(rc);//because fset2 is empty |
|
365 ////////////////////////////////////////////////////////// |
|
366 //A test with a set: two valid features |
|
367 TFeatureSet fset3; |
|
368 err = fset3.Append(KConnectivity); |
|
369 TEST2(err, KErrNone); |
|
370 err = fset3.Append(KSip); |
|
371 TEST2(err, KErrNone); |
|
372 if(aStaticMethodsUsed) |
|
373 { |
|
374 TRAP(err, CFeatureDiscovery::FeaturesSupportedL(fset3)); |
|
375 } |
|
376 else |
|
377 { |
|
378 err = fdiscovery->FeaturesSupported(fset3); |
|
379 } |
|
380 TEST2(err, KErrNone); |
|
381 rc = fset3.IsFeatureSupported(KConnectivity); |
|
382 TEST(rc); |
|
383 rc = fset3.IsFeatureSupported(KSip); |
|
384 TEST(rc); |
|
385 rc = fset3.AreAllFeaturesSupported(); |
|
386 TEST(rc); |
|
387 ////////////////////////////////////////////////////////// |
|
388 delete fdiscovery; |
|
389 } |
|
390 |
|
391 /** |
|
392 @SYMTestCaseID PDS-EFM-CT-4064 |
|
393 @SYMTestCaseDesc |
|
394 @SYMTestPriority High |
|
395 @SYMTestActions |
|
396 @SYMTestExpectedResults Test must not fail |
|
397 @SYMDEF DEF144262 |
|
398 */ |
|
399 void FeatureDiscoveryTest2L() |
|
400 { |
|
401 DoFeatureDiscoveryTest2(ETrue); |
|
402 DoFeatureDiscoveryTest2(EFalse); |
|
403 } |
|
404 |
|
405 void DoTestsL() |
|
406 { |
|
407 TheTest.Start(_L("@SYMTestCaseID:PDS-EFM-CT-4059 FeatureManager::FeatureSupported() test")); |
|
408 FeatureSupportedTestL(); |
|
409 TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4060 RFeatureControl tests-1")); |
|
410 FeatureControlTest1(); |
|
411 TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4061 RFeatureControl tests-2")); |
|
412 FeatureControlTest2(); |
|
413 TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4062 RFeatureControl tests-3")); |
|
414 FeatureControlTest3(); |
|
415 TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4063 CFeatureDiscovery tests-1")); |
|
416 FeatureDiscoveryTest1L(); |
|
417 TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4064 CFeatureDiscovery & TFeatureSet tests")); |
|
418 FeatureDiscoveryTest2L(); |
|
419 } |
|
420 |
|
421 TInt E32Main() |
|
422 { |
|
423 TheTest.Title(); |
|
424 |
|
425 CTrapCleanup* tc = CTrapCleanup::New(); |
|
426 TheTest(tc != NULL); |
|
427 |
|
428 __UHEAP_MARK; |
|
429 |
|
430 TRAPD(err, DoTestsL()); |
|
431 DestroyTestEnv(); |
|
432 TEST2(err, KErrNone); |
|
433 |
|
434 __UHEAP_MARKEND; |
|
435 |
|
436 TheTest.End(); |
|
437 TheTest.Close(); |
|
438 |
|
439 delete tc; |
|
440 |
|
441 User::Heap().Check(); |
|
442 return KErrNone; |
|
443 } |