os/security/authorisation/userpromptservice/policies/test/tupspolicies/source/tserviceconfig.cpp
Update contrib.
2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 #include "tserviceconfig.h"
20 #include <test/testexecutelog.h>
21 #include <test/tefunit.h>
23 #include "policycache.h"
25 using namespace UserPromptService;
27 CServiceConfigTestStep::CServiceConfigTestStep()
32 // Set human readable name for logging
33 SetTestStepName(KServiceConfigStep);
36 CServiceConfigTestStep::~CServiceConfigTestStep()
46 TVerdict CServiceConfigTestStep::doTestStepPreambleL()
49 @return Whether the test initialization passed or failed.
52 User::LeaveIfError(iFs.Connect());
53 SetTestStepResult(EPass);
54 return TestStepResult();
57 TVerdict CServiceConfigTestStep::doTestStepL()
60 @return Whether the test passed or failed.
64 ASSERT_TRUE(GetStringFromConfig(ConfigSection(), _L("policydir"), policyDir));
66 iPolicyCache = CPolicyCache::NewL(iFs, policyDir);
69 ASSERT_TRUE(GetHexFromConfig(ConfigSection(), _L("serversid"), serverSid));
71 INFO_PRINTF2(_L("Loading service configuration for system server 0x%08x"), serverSid);
72 RArray<TServiceConfig> serviceConfigs;
73 iPolicyCache->ServiceConfigL(TSecureId(serverSid), serviceConfigs);
74 CleanupClosePushL(serviceConfigs);
77 ASSERT_TRUE(GetIntFromConfig(ConfigSection(), _L("numservices"), numServices));
79 if (numServices != serviceConfigs.Count())
81 ERR_PRINTF3(_L("Number of services = %d, expected number of services = %d"),
82 serviceConfigs.Count(), numServices);
83 SetTestStepResult(EFail);
86 for (TInt i = 0; i < Min(serviceConfigs.Count(), numServices); ++i)
90 INFO_PRINTF3(_L("service %08x, policy %d"),
91 serviceConfigs[i].iServiceId, serviceConfigs[i].iPolicy);
94 key.AppendFormat(_L("service%d"), i);
95 ASSERT_TRUE(GetHexFromConfig(ConfigSection(), key, serviceId));
96 if (serviceConfigs[i].iServiceId != serviceId)
98 ERR_PRINTF4(_L("Config %d, expected service id = %08x, actual service id %08x"),
99 i, serviceId, serviceConfigs[i].iServiceId);
100 SetTestStepResult(EFail);
105 key.AppendFormat(_L("policy%d"), i);
106 ASSERT_TRUE(GetStringFromConfig(ConfigSection(), key, policyString));
107 TAuthorisationPolicy policy = PolicyEnumFromString(policyString);
108 if (serviceConfigs[i].iPolicy != policy)
110 ERR_PRINTF4(_L("Config %d, expected authorisation policy = %d, actual authorisation policy = %d"),
111 i, policy, serviceConfigs[i].iPolicy);
112 SetTestStepResult(EFail);
116 CleanupStack::PopAndDestroy(&serviceConfigs);
117 return TestStepResult();
120 TAuthorisationPolicy CServiceConfigTestStep::PolicyEnumFromString(const TDesC& aEnumString)
122 TAuthorisationPolicy policy(EAlwaysCheck);
124 if (aEnumString.CompareF(_L("EAlwaysCheck")) == 0)
126 policy = EAlwaysCheck;
128 else if (aEnumString.CompareF(_L("ECheckPostManufacture")) == 0)
130 policy = ECheckPostManufacture;
132 else if (aEnumString.CompareF(_L("ECheckUnprotectedSids")) == 0)
134 policy = ECheckUnprotectedSids;
136 else if (aEnumString.CompareF(_L("ECheckIfFailed")) == 0)
138 policy = ECheckIfFailed;
140 else if (aEnumString.CompareF(_L("ENeverCheck")) == 0)
142 policy = ENeverCheck;
146 ERR_PRINTF2(_L("TAuthorisationPolicy enum %S not recognised"), &aEnumString);
152 TVerdict CServiceConfigTestStep::doTestStepPostambleL()
155 @return Whether cleanup passed or failed.
158 return TestStepResult();