sl@0: // Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: using namespace NFeature; sl@0: sl@0: const TInt KInvalidFeatureId1 = 90901671; sl@0: const TInt KInvalidNegFeatureId2 = -90901671; sl@0: const TUid KInvalidFeatureUid1 = {KInvalidFeatureId1}; sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: static RTest TheTest(_L("t_fmgrapi")); sl@0: TUid SupportedFeature = KConnectivity; //Defaulted to KConnectivity, but we will re-assign it in FeatureTestPreparation(). sl@0: TUid SupportedFeature2 = KSip; //Defaulted to KSip, but we will re-assign it in FeatureTestPreparation(). sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: //Deletes all created test files. sl@0: void DestroyTestEnv() sl@0: { sl@0: } sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: //Test macros and functions sl@0: void Check1(TInt aValue, TInt aLine) sl@0: { sl@0: if(!aValue) sl@0: { sl@0: DestroyTestEnv(); sl@0: RDebug::Print(_L("*** Expression evaluated to false. Line %d\r\n"), aLine); sl@0: TheTest(EFalse, aLine); sl@0: } sl@0: } sl@0: void Check2(TInt aValue, TInt aExpected, TInt aLine) sl@0: { sl@0: if(aValue != aExpected) sl@0: { sl@0: DestroyTestEnv(); sl@0: RDebug::Print(_L("*** Expected: %d, got: %d. Line %d\r\n"), aExpected, aValue, aLine); sl@0: TheTest(EFalse, aLine); sl@0: } sl@0: } sl@0: #define TEST(arg) ::Check1((arg), __LINE__) sl@0: #define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__) sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: /** sl@0: @SYMTestCaseID PDS-EFM-CT-4059 sl@0: @SYMTestCaseDesc sl@0: @SYMTestPriority High sl@0: @SYMTestActions sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMDEF DEF144262 sl@0: */ sl@0: void FeatureSupportedTestL() sl@0: { sl@0: FeatureManager::InitializeLibL(); sl@0: FeatureManager::InitializeLibL(); sl@0: sl@0: //Feature, default present sl@0: TBool rc = FeatureManager::FeatureSupported(KConnectivity.iUid); sl@0: TEST(rc); sl@0: //Feature, default not present sl@0: rc = FeatureManager::FeatureSupported(KPrint.iUid); sl@0: TEST(rc); sl@0: sl@0: //Ivalid feature UID sl@0: rc = FeatureManager::FeatureSupported(KInvalidFeatureId1); sl@0: TEST(!rc); sl@0: //Ivalid feature UID - negative sl@0: rc = FeatureManager::FeatureSupported(KInvalidNegFeatureId2); sl@0: TEST(!rc); sl@0: sl@0: FeatureManager::UnInitializeLib(); sl@0: FeatureManager::UnInitializeLib(); sl@0: FeatureManager::UnInitializeLib();//it should be safe to call UnInitializeLib() even without matching InitializeLibL() call sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID PDS-EFM-CT-4060 sl@0: @SYMTestCaseDesc sl@0: @SYMTestPriority High sl@0: @SYMTestActions sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMDEF DEF144262 sl@0: */ sl@0: void FeatureControlTest1() sl@0: { sl@0: RFeatureControl ctrl; sl@0: TInt err = ctrl.Open(); sl@0: TEST2(err, KErrNone); sl@0: ///////////////////////////////////////////////////////////// sl@0: RFeatureUidArray farray; sl@0: err = ctrl.ListSupportedFeatures(farray); sl@0: TEST2(err, KErrNone); sl@0: TheTest.Printf(_L("RFeatureControl::ListSupportedFeatures()\r\n")); sl@0: for(TInt i=0;iIsSupported(KInvalidFeatureId1); sl@0: TEST(!rc); sl@0: rc = fdiscovery->IsSupported(SupportedFeature.iUid); sl@0: TEST(rc); sl@0: sl@0: rc = fdiscovery->IsSupported(KInvalidFeatureUid1); sl@0: TEST(!rc); sl@0: rc = fdiscovery->IsSupported(SupportedFeature); sl@0: TEST(rc); sl@0: sl@0: CleanupStack::PopAndDestroy(fdiscovery); sl@0: } sl@0: sl@0: void DoFeatureDiscoveryTest2L(TBool aStaticMethodsUsed) sl@0: { sl@0: CFeatureDiscovery* fdiscovery = NULL; sl@0: if(!aStaticMethodsUsed) sl@0: { sl@0: fdiscovery = CFeatureDiscovery::NewL(); sl@0: } sl@0: ////////////////////////////////////////////////////////// sl@0: //A test with a set: one valid and one invalid feature sl@0: TFeatureSet fset; sl@0: TInt err = fset.Append(SupportedFeature); sl@0: TEST2(err, KErrNone); sl@0: err = fset.Append(KInvalidFeatureUid1); sl@0: TEST2(err, KErrNone); sl@0: TBool rc = fset.IsFeatureSupported(SupportedFeature); sl@0: TEST(!rc); sl@0: rc = fset.IsFeatureSupported(KInvalidFeatureUid1); sl@0: TEST(!rc); sl@0: if(aStaticMethodsUsed) sl@0: { sl@0: TRAP(err, CFeatureDiscovery::FeaturesSupportedL(fset)); sl@0: } sl@0: else sl@0: { sl@0: err = fdiscovery->FeaturesSupported(fset); sl@0: } sl@0: TEST2(err, KErrNone); sl@0: rc = fset.IsFeatureSupported(SupportedFeature); sl@0: TEST(rc); sl@0: rc = fset.IsFeatureSupported(KInvalidFeatureUid1); sl@0: TEST(!rc); sl@0: rc = fset.AreAllFeaturesSupported(); sl@0: TEST(!rc); sl@0: ////////////////////////////////////////////////////////// sl@0: //A test with an empty set sl@0: TFeatureSet fset2; sl@0: rc = fset2.IsFeatureSupported(SupportedFeature); sl@0: TEST(!rc); sl@0: rc = fset2.IsFeatureSupported(KInvalidFeatureUid1); sl@0: TEST(!rc); sl@0: if(aStaticMethodsUsed) sl@0: { sl@0: TRAP(err, CFeatureDiscovery::FeaturesSupportedL(fset2)); sl@0: } sl@0: else sl@0: { sl@0: err = fdiscovery->FeaturesSupported(fset2); sl@0: } sl@0: TEST2(err, KErrArgument); sl@0: rc = fset2.IsFeatureSupported(SupportedFeature); sl@0: TEST(!rc); sl@0: rc = fset2.IsFeatureSupported(KInvalidFeatureUid1); sl@0: TEST(!rc); sl@0: rc = fset2.AreAllFeaturesSupported(); sl@0: TEST(rc);//because fset2 is empty sl@0: ////////////////////////////////////////////////////////// sl@0: //A test with a set: two valid features sl@0: TFeatureSet fset3; sl@0: err = fset3.Append(SupportedFeature); sl@0: TEST2(err, KErrNone); sl@0: err = fset3.Append(SupportedFeature2); sl@0: TEST2(err, KErrNone); sl@0: if(aStaticMethodsUsed) sl@0: { sl@0: TRAP(err, CFeatureDiscovery::FeaturesSupportedL(fset3)); sl@0: } sl@0: else sl@0: { sl@0: err = fdiscovery->FeaturesSupported(fset3); sl@0: } sl@0: TEST2(err, KErrNone); sl@0: rc = fset3.IsFeatureSupported(SupportedFeature); sl@0: TEST(rc); sl@0: rc = fset3.IsFeatureSupported(SupportedFeature2); sl@0: TEST(rc); sl@0: rc = fset3.AreAllFeaturesSupported(); sl@0: TEST(rc); sl@0: ////////////////////////////////////////////////////////// sl@0: delete fdiscovery; sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID PDS-EFM-CT-4064 sl@0: @SYMTestCaseDesc sl@0: @SYMTestPriority High sl@0: @SYMTestActions sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMDEF DEF144262 sl@0: */ sl@0: void FeatureDiscoveryTest2L() sl@0: { sl@0: DoFeatureDiscoveryTest2L(ETrue); sl@0: DoFeatureDiscoveryTest2L(EFalse); sl@0: } sl@0: sl@0: void FeatureTestPreparation() sl@0: { sl@0: RFeatureControl ctrl; sl@0: TInt err = ctrl.Open(); sl@0: TEST2(err, KErrNone); sl@0: ///////////////////////////////////////////////////////////// sl@0: RFeatureUidArray farray; sl@0: TheTest.Printf(_L("Getting supported feature for CFeatureDiscovery test\r\n")); sl@0: err = ctrl.ListSupportedFeatures(farray); sl@0: if (err == KErrNone && farray.Count() > 1) sl@0: { sl@0: SupportedFeature = farray[0]; //Take the first supported value sl@0: SupportedFeature2 = farray[1]; //Take the first supported value sl@0: } sl@0: else sl@0: { sl@0: TheTest.Printf(_L("Warning: Failed to get supported feature for testing. CFeatureDiscovery tests are going to fail\r\n")); sl@0: } sl@0: farray.Close(); sl@0: ctrl.Close(); sl@0: } sl@0: sl@0: void DoTestsL() sl@0: { sl@0: FeatureTestPreparation(); //Preparation for the test. sl@0: TheTest.Start(_L("@SYMTestCaseID:PDS-EFM-CT-4059 FeatureManager::FeatureSupported() test")); sl@0: FeatureSupportedTestL(); sl@0: TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4060 RFeatureControl tests-1")); sl@0: FeatureControlTest1(); sl@0: TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4061 RFeatureControl tests-2")); sl@0: FeatureControlTest2(); sl@0: TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4062 RFeatureControl tests-3")); sl@0: FeatureControlTest3(); sl@0: TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4063 CFeatureDiscovery tests-1")); sl@0: FeatureDiscoveryTest1L(); sl@0: TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4064 CFeatureDiscovery & TFeatureSet tests")); sl@0: FeatureDiscoveryTest2L(); sl@0: } sl@0: sl@0: TInt E32Main() sl@0: { sl@0: TheTest.Title(); sl@0: sl@0: CTrapCleanup* tc = CTrapCleanup::New(); sl@0: TheTest(tc != NULL); sl@0: sl@0: __UHEAP_MARK; sl@0: sl@0: TRAPD(err, DoTestsL()); sl@0: DestroyTestEnv(); sl@0: TEST2(err, KErrNone); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: TheTest.End(); sl@0: TheTest.Close(); sl@0: sl@0: delete tc; sl@0: sl@0: User::Heap().Check(); sl@0: return KErrNone; sl@0: }