diff -r c084286672be -r 15018f1726c7 featuremgmt/featuremgr/test/rtest/src/t_fmgrapi.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/featuremgmt/featuremgr/test/rtest/src/t_fmgrapi.cpp Fri Mar 19 10:00:55 2010 +0200 @@ -0,0 +1,443 @@ +// Copyright (c) 2009 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")); + +/////////////////////////////////////////////////////////////////////////////////////// + +//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(KLocationManagement.iUid); + TEST(rc); + + rc = fdiscovery->IsSupported(KInvalidFeatureUid1); + TEST(!rc); + rc = fdiscovery->IsSupported(KLocationManagement); + TEST(rc); + + CleanupStack::PopAndDestroy(fdiscovery); + } + +void DoFeatureDiscoveryTest2(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(KConnectivity); + TEST2(err, KErrNone); + err = fset.Append(KInvalidFeatureUid1); + TEST2(err, KErrNone); + TBool rc = fset.IsFeatureSupported(KConnectivity); + 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(KConnectivity); + TEST(rc); + rc = fset.IsFeatureSupported(KInvalidFeatureUid1); + TEST(!rc); + rc = fset.AreAllFeaturesSupported(); + TEST(!rc); + ////////////////////////////////////////////////////////// + //A test with an empty set + TFeatureSet fset2; + rc = fset2.IsFeatureSupported(KConnectivity); + 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(KConnectivity); + 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(KConnectivity); + TEST2(err, KErrNone); + err = fset3.Append(KSip); + TEST2(err, KErrNone); + if(aStaticMethodsUsed) + { + TRAP(err, CFeatureDiscovery::FeaturesSupportedL(fset3)); + } + else + { + err = fdiscovery->FeaturesSupported(fset3); + } + TEST2(err, KErrNone); + rc = fset3.IsFeatureSupported(KConnectivity); + TEST(rc); + rc = fset3.IsFeatureSupported(KSip); + 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() + { + DoFeatureDiscoveryTest2(ETrue); + DoFeatureDiscoveryTest2(EFalse); + } + +void DoTestsL() + { + 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; + }