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