Update contrib.
1 // Copyright (c) 2009-2010 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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
18 #include <featureuids.h>
19 #include <featurecontrol.h>
20 #include <featdiscovery.h>
22 using namespace NFeature;
24 const TInt KInvalidFeatureId1 = 90901671;
25 const TInt KInvalidNegFeatureId2 = -90901671;
26 const TUid KInvalidFeatureUid1 = {KInvalidFeatureId1};
28 ///////////////////////////////////////////////////////////////////////////////////////
30 static RTest TheTest(_L("t_fmgrapi"));
31 TUid SupportedFeature = KConnectivity; //Defaulted to KConnectivity, but we will re-assign it in FeatureTestPreparation().
32 TUid SupportedFeature2 = KSip; //Defaulted to KSip, but we will re-assign it in FeatureTestPreparation().
34 ///////////////////////////////////////////////////////////////////////////////////////
36 //Deletes all created test files.
41 ///////////////////////////////////////////////////////////////////////////////////////
42 ///////////////////////////////////////////////////////////////////////////////////////
43 //Test macros and functions
44 void Check1(TInt aValue, TInt aLine)
49 RDebug::Print(_L("*** Expression evaluated to false. Line %d\r\n"), aLine);
50 TheTest(EFalse, aLine);
53 void Check2(TInt aValue, TInt aExpected, TInt aLine)
55 if(aValue != aExpected)
58 RDebug::Print(_L("*** Expected: %d, got: %d. Line %d\r\n"), aExpected, aValue, aLine);
59 TheTest(EFalse, aLine);
62 #define TEST(arg) ::Check1((arg), __LINE__)
63 #define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__)
65 ///////////////////////////////////////////////////////////////////////////////////////
68 @SYMTestCaseID PDS-EFM-CT-4059
72 @SYMTestExpectedResults Test must not fail
75 void FeatureSupportedTestL()
77 FeatureManager::InitializeLibL();
78 FeatureManager::InitializeLibL();
80 //Feature, default present
81 TBool rc = FeatureManager::FeatureSupported(KConnectivity.iUid);
83 //Feature, default not present
84 rc = FeatureManager::FeatureSupported(KPrint.iUid);
88 rc = FeatureManager::FeatureSupported(KInvalidFeatureId1);
90 //Ivalid feature UID - negative
91 rc = FeatureManager::FeatureSupported(KInvalidNegFeatureId2);
94 FeatureManager::UnInitializeLib();
95 FeatureManager::UnInitializeLib();
96 FeatureManager::UnInitializeLib();//it should be safe to call UnInitializeLib() even without matching InitializeLibL() call
100 @SYMTestCaseID PDS-EFM-CT-4060
102 @SYMTestPriority High
104 @SYMTestExpectedResults Test must not fail
107 void FeatureControlTest1()
109 RFeatureControl ctrl;
110 TInt err = ctrl.Open();
111 TEST2(err, KErrNone);
112 /////////////////////////////////////////////////////////////
113 RFeatureUidArray farray;
114 err = ctrl.ListSupportedFeatures(farray);
115 TEST2(err, KErrNone);
116 TheTest.Printf(_L("RFeatureControl::ListSupportedFeatures()\r\n"));
117 for(TInt i=0;i<farray.Count();++i)
119 TheTest.Printf(_L(" Feature: %08X\r\n"), farray[i].iUid);
121 /////////////////////////////////////////////////////////////
122 RFeatureArray farray2;
123 for(TInt i=0;i<farray.Count();++i)
125 err = farray2.Append(farray[i]);
126 TEST2(err, KErrNone);
129 err = ctrl.FeaturesSupported(farray2);
130 TEST2(err, KErrNone);
132 TheTest.Printf(_L("RFeatureControl::FeaturesSupported()\r\n"));
133 for(TInt i=0;i<farray2.Count();++i)
135 TheTest.Printf(_L(" Feature: %08X, Flags: %08X, Data: %08X\r\n"), farray2[i].FeatureUid(), farray2[i].FeatureFlags().iFlags, farray2[i].FeatureData());
138 RFeatureArray farray3;
139 err = ctrl.FeaturesSupported(farray3);
140 TEST2(err, KErrArgument);
142 /////////////////////////////////////////////////////////////
146 ctrl.Close();//It should be safe to call Close() again
150 @SYMTestCaseID PDS-EFM-CT-4061
152 @SYMTestPriority High
154 @SYMTestExpectedResults Test must not fail
157 void FeatureControlTest2()
159 RFeatureControl ctrl;
160 TInt err = ctrl.Open();
161 TEST2(err, KErrNone);
162 /////////////////////////////////////////////////////////////
163 RFeatureUidArray farray;
164 err = ctrl.ListSupportedFeatures(farray);
165 TEST2(err, KErrNone);
166 for(TInt i=0;i<farray.Count();++i)
168 err = ctrl.FeatureSupported(farray[i]);
169 TEST2(err, KFeatureSupported);
171 TFeatureEntry feat(farray[i]);
172 err = ctrl.FeatureSupported(feat);
173 TEST2(err, KFeatureSupported);
176 err = ctrl.FeatureSupported(TUid::Uid(KInvalidFeatureId1));
177 TEST2(err, KErrNotFound);
179 TFeatureEntry feat1(TUid::Uid(KInvalidFeatureId1));
180 err = ctrl.FeatureSupported(feat1);
181 TEST2(err, KErrNotFound);
183 const TUint KFlags = 0x0134357;
184 const TUint KData = 0xAB5234;
185 TFeatureEntry feat2(TUid::Uid(KInvalidFeatureId1), KFlags, KData);
186 err = ctrl.FeatureSupported(feat2);
187 TEST2(err, KErrNotFound);
189 /////////////////////////////////////////////////////////////
195 @SYMTestCaseID PDS-EFM-CT-4062
197 @SYMTestPriority High
199 @SYMTestExpectedResults Test must not fail
202 void FeatureControlTest3()
204 RFeatureControl ctrl;
205 TInt err = ctrl.Open();
206 TEST2(err, KErrNone);
208 //Retrieve a uid list of all supported features
209 RFeatureUidArray farray;
210 err = ctrl.ListSupportedFeatures(farray);
211 TEST2(err, KErrNone);
212 //Retrieve a TFeaureEntry list of all supported features
213 RFeatureArray farray2;
214 for(TInt i=0;i<farray.Count();++i)
216 err = farray2.Append(farray[i]);
217 TEST2(err, KErrNone);
219 err = ctrl.FeaturesSupported(farray2);
220 TEST2(err, KErrNone);
221 //Play with EnableFeature()/DisableFeature() calls. If the EFeatureModifiable flag is not set then
222 //the feature cannot be enabled or disabled.
223 for(TInt i=0;i<farray2.Count();++i)
225 const TFeatureEntry& fentry = farray2[i];
226 TBitFlags32 flags = fentry.FeatureFlags();
228 err = ctrl.DisableFeature(fentry.FeatureUid());
229 TEST2(err, flags.IsSet(EFeatureModifiable) ? KErrNone : KErrAccessDenied);
231 err = ctrl.EnableFeature(fentry.FeatureUid());
232 TEST2(err, flags.IsSet(EFeatureModifiable) ? KErrNone : KErrAccessDenied);
234 //It is impossible to set non-existing feature
235 const TUid KNewFeatureUid = {0x7888ABCD};
236 err = ctrl.SetFeature(KNewFeatureUid, ETrue, 0x0);
237 TEST2(err, KErrNotFound);
238 //It is impossible to set non-modifiable feature
239 TBitFlags32 flags = farray2[0].FeatureFlags();
240 err = ctrl.SetFeature(farray2[0].FeatureUid(), ETrue, 0x0);
241 TEST2(err, flags.IsSet(EFeatureModifiable) ? KErrNone : KErrAccessDenied);
244 flags.Set(EFeatureSupported);
245 flags.Set(EFeatureModifiable);
246 TFeatureEntry fentry(KNewFeatureUid, flags, 0x0);
247 err = ctrl.AddFeature(fentry);
248 TEST2(err, KErrNone);
249 //Retrieve the new feature and check flags
250 err = ctrl.FeatureSupported(fentry);
251 TEST2(err, KFeatureSupported);
252 flags = fentry.FeatureFlags();
253 TEST(flags.IsSet(EFeatureSupported));
254 TEST(flags.IsSet(EFeatureModifiable));
255 //Now, it should be possible to set the new feature - it is modifiable.
256 err = ctrl.SetFeature(fentry.FeatureUid(), ETrue, 0x0);
257 TEST2(err, KErrNone);
258 err = ctrl.SetFeature(fentry.FeatureUid(), EFalse, 0x0);
259 TEST2(err, KErrNone);
261 err = ctrl.EnableFeature(fentry.FeatureUid());
262 TEST2(err, KErrNone);
263 err = ctrl.DisableFeature(fentry.FeatureUid());
264 TEST2(err, KErrNone);
265 //Delete the added feature
266 err = ctrl.DeleteFeature(fentry.FeatureUid());
267 TEST2(err, KErrNone);
268 err = ctrl.DeleteFeature(fentry.FeatureUid());
269 TEST2(err, KErrNotFound);
271 /////////////////////////////////////////////////////////////
278 @SYMTestCaseID PDS-EFM-CT-4063
280 @SYMTestPriority High
282 @SYMTestExpectedResults Test must not fail
285 void FeatureDiscoveryTest1L()
287 TBool rc = CFeatureDiscovery::IsFeatureSupportedL(KInvalidFeatureId1);
289 rc = CFeatureDiscovery::IsFeatureSupportedL(SupportedFeature.iUid);
292 rc = CFeatureDiscovery::IsFeatureSupportedL(KInvalidFeatureUid1);
294 rc = CFeatureDiscovery::IsFeatureSupportedL(SupportedFeature);
297 CFeatureDiscovery* fdiscovery = CFeatureDiscovery::NewLC();
299 rc = fdiscovery->IsSupported(KInvalidFeatureId1);
301 rc = fdiscovery->IsSupported(SupportedFeature.iUid);
304 rc = fdiscovery->IsSupported(KInvalidFeatureUid1);
306 rc = fdiscovery->IsSupported(SupportedFeature);
309 CleanupStack::PopAndDestroy(fdiscovery);
312 void DoFeatureDiscoveryTest2L(TBool aStaticMethodsUsed)
314 CFeatureDiscovery* fdiscovery = NULL;
315 if(!aStaticMethodsUsed)
317 fdiscovery = CFeatureDiscovery::NewL();
319 //////////////////////////////////////////////////////////
320 //A test with a set: one valid and one invalid feature
322 TInt err = fset.Append(SupportedFeature);
323 TEST2(err, KErrNone);
324 err = fset.Append(KInvalidFeatureUid1);
325 TEST2(err, KErrNone);
326 TBool rc = fset.IsFeatureSupported(SupportedFeature);
328 rc = fset.IsFeatureSupported(KInvalidFeatureUid1);
330 if(aStaticMethodsUsed)
332 TRAP(err, CFeatureDiscovery::FeaturesSupportedL(fset));
336 err = fdiscovery->FeaturesSupported(fset);
338 TEST2(err, KErrNone);
339 rc = fset.IsFeatureSupported(SupportedFeature);
341 rc = fset.IsFeatureSupported(KInvalidFeatureUid1);
343 rc = fset.AreAllFeaturesSupported();
345 //////////////////////////////////////////////////////////
346 //A test with an empty set
348 rc = fset2.IsFeatureSupported(SupportedFeature);
350 rc = fset2.IsFeatureSupported(KInvalidFeatureUid1);
352 if(aStaticMethodsUsed)
354 TRAP(err, CFeatureDiscovery::FeaturesSupportedL(fset2));
358 err = fdiscovery->FeaturesSupported(fset2);
360 TEST2(err, KErrArgument);
361 rc = fset2.IsFeatureSupported(SupportedFeature);
363 rc = fset2.IsFeatureSupported(KInvalidFeatureUid1);
365 rc = fset2.AreAllFeaturesSupported();
366 TEST(rc);//because fset2 is empty
367 //////////////////////////////////////////////////////////
368 //A test with a set: two valid features
370 err = fset3.Append(SupportedFeature);
371 TEST2(err, KErrNone);
372 err = fset3.Append(SupportedFeature2);
373 TEST2(err, KErrNone);
374 if(aStaticMethodsUsed)
376 TRAP(err, CFeatureDiscovery::FeaturesSupportedL(fset3));
380 err = fdiscovery->FeaturesSupported(fset3);
382 TEST2(err, KErrNone);
383 rc = fset3.IsFeatureSupported(SupportedFeature);
385 rc = fset3.IsFeatureSupported(SupportedFeature2);
387 rc = fset3.AreAllFeaturesSupported();
389 //////////////////////////////////////////////////////////
394 @SYMTestCaseID PDS-EFM-CT-4064
396 @SYMTestPriority High
398 @SYMTestExpectedResults Test must not fail
401 void FeatureDiscoveryTest2L()
403 DoFeatureDiscoveryTest2L(ETrue);
404 DoFeatureDiscoveryTest2L(EFalse);
407 void FeatureTestPreparation()
409 RFeatureControl ctrl;
410 TInt err = ctrl.Open();
411 TEST2(err, KErrNone);
412 /////////////////////////////////////////////////////////////
413 RFeatureUidArray farray;
414 TheTest.Printf(_L("Getting supported feature for CFeatureDiscovery test\r\n"));
415 err = ctrl.ListSupportedFeatures(farray);
416 if (err == KErrNone && farray.Count() > 1)
418 SupportedFeature = farray[0]; //Take the first supported value
419 SupportedFeature2 = farray[1]; //Take the first supported value
423 TheTest.Printf(_L("Warning: Failed to get supported feature for testing. CFeatureDiscovery tests are going to fail\r\n"));
431 FeatureTestPreparation(); //Preparation for the test.
432 TheTest.Start(_L("@SYMTestCaseID:PDS-EFM-CT-4059 FeatureManager::FeatureSupported() test"));
433 FeatureSupportedTestL();
434 TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4060 RFeatureControl tests-1"));
435 FeatureControlTest1();
436 TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4061 RFeatureControl tests-2"));
437 FeatureControlTest2();
438 TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4062 RFeatureControl tests-3"));
439 FeatureControlTest3();
440 TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4063 CFeatureDiscovery tests-1"));
441 FeatureDiscoveryTest1L();
442 TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4064 CFeatureDiscovery & TFeatureSet tests"));
443 FeatureDiscoveryTest2L();
450 CTrapCleanup* tc = CTrapCleanup::New();
455 TRAPD(err, DoTestsL());
457 TEST2(err, KErrNone);
466 User::Heap().Check();