os/security/authorisation/userpromptservice/policies/test/tupspolicies/source/tserviceconfig.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/authorisation/userpromptservice/policies/test/tupspolicies/source/tserviceconfig.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,160 @@
     1.4 +/*
     1.5 +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include "tserviceconfig.h"
    1.23 +#include <test/testexecutelog.h>
    1.24 +#include <test/tefunit.h>
    1.25 +
    1.26 +#include "policycache.h"
    1.27 +
    1.28 +using namespace UserPromptService;
    1.29 +
    1.30 +CServiceConfigTestStep::CServiceConfigTestStep()
    1.31 +/**
    1.32 +Constructor
    1.33 +*/
    1.34 +	{
    1.35 +	// Set human readable name for logging
    1.36 +	SetTestStepName(KServiceConfigStep);		
    1.37 +	}
    1.38 +	
    1.39 +CServiceConfigTestStep::~CServiceConfigTestStep()
    1.40 +/**
    1.41 +Destructor
    1.42 +*/
    1.43 +	{
    1.44 +	delete iPolicyCache;
    1.45 +	iPolicyCache = 0;
    1.46 +	iFs.Close();
    1.47 +	}
    1.48 +
    1.49 +TVerdict CServiceConfigTestStep::doTestStepPreambleL()
    1.50 +/**
    1.51 +Initialise
    1.52 +@return Whether the test initialization passed or failed.
    1.53 + */
    1.54 +	{
    1.55 +	User::LeaveIfError(iFs.Connect());
    1.56 +	SetTestStepResult(EPass);
    1.57 +	return TestStepResult();
    1.58 +	}
    1.59 +
    1.60 +TVerdict CServiceConfigTestStep::doTestStepL()
    1.61 +/**
    1.62 +Do the test
    1.63 +@return Whether the test passed or failed.
    1.64 + */
    1.65 +	{
    1.66 +	TPtrC policyDir;
    1.67 +	ASSERT_TRUE(GetStringFromConfig(ConfigSection(), _L("policydir"), policyDir));
    1.68 +	
    1.69 +	iPolicyCache = CPolicyCache::NewL(iFs, policyDir);	
    1.70 +
    1.71 +	TInt serverSid;
    1.72 +	ASSERT_TRUE(GetHexFromConfig(ConfigSection(), _L("serversid"), serverSid));
    1.73 +	
    1.74 +	INFO_PRINTF2(_L("Loading service configuration for system server 0x%08x"), serverSid);
    1.75 +	RArray<TServiceConfig> serviceConfigs;
    1.76 +	iPolicyCache->ServiceConfigL(TSecureId(serverSid), serviceConfigs);
    1.77 +	CleanupClosePushL(serviceConfigs);
    1.78 +	
    1.79 +	TInt numServices;
    1.80 +	ASSERT_TRUE(GetIntFromConfig(ConfigSection(), _L("numservices"), numServices));
    1.81 +	
    1.82 +	if (numServices != serviceConfigs.Count())
    1.83 +		{
    1.84 +		ERR_PRINTF3(_L("Number of services = %d, expected number of services = %d"),
    1.85 +			serviceConfigs.Count(), numServices);
    1.86 +			SetTestStepResult(EFail);			
    1.87 +		}
    1.88 +	
    1.89 +	for (TInt i = 0; i < Min(serviceConfigs.Count(), numServices); ++i)
    1.90 +		{		
    1.91 +		TBuf<32> key;
    1.92 +		
    1.93 +		INFO_PRINTF3(_L("service %08x, policy %d"), 
    1.94 +			serviceConfigs[i].iServiceId, serviceConfigs[i].iPolicy);
    1.95 +		
    1.96 +		TInt serviceId;
    1.97 +		key.AppendFormat(_L("service%d"), i);
    1.98 +		ASSERT_TRUE(GetHexFromConfig(ConfigSection(), key, serviceId));		
    1.99 +		if (serviceConfigs[i].iServiceId != serviceId)
   1.100 +			{
   1.101 +			ERR_PRINTF4(_L("Config %d, expected service id = %08x, actual service id %08x"),
   1.102 +				i, serviceId, serviceConfigs[i].iServiceId);
   1.103 +			SetTestStepResult(EFail);			
   1.104 +			}
   1.105 +				
   1.106 +		TPtrC policyString;
   1.107 +		key.Zero();
   1.108 +		key.AppendFormat(_L("policy%d"), i);
   1.109 +		ASSERT_TRUE(GetStringFromConfig(ConfigSection(), key, policyString));
   1.110 +		TAuthorisationPolicy policy = PolicyEnumFromString(policyString);		
   1.111 +		if (serviceConfigs[i].iPolicy != policy)
   1.112 +			{
   1.113 +			ERR_PRINTF4(_L("Config %d, expected authorisation policy = %d, actual authorisation policy = %d"),
   1.114 +				i, policy, serviceConfigs[i].iPolicy);
   1.115 +			SetTestStepResult(EFail);
   1.116 +			}
   1.117 +		}	
   1.118 +	
   1.119 +	CleanupStack::PopAndDestroy(&serviceConfigs);
   1.120 +	return TestStepResult();
   1.121 +	}
   1.122 +
   1.123 +TAuthorisationPolicy CServiceConfigTestStep::PolicyEnumFromString(const TDesC& aEnumString)
   1.124 +	{
   1.125 +	TAuthorisationPolicy policy(EAlwaysCheck);
   1.126 +	
   1.127 +	if (aEnumString.CompareF(_L("EAlwaysCheck")) == 0)
   1.128 +		{
   1.129 +		policy =  EAlwaysCheck;		
   1.130 +		}
   1.131 +	else if (aEnumString.CompareF(_L("ECheckPostManufacture")) == 0)
   1.132 +		{
   1.133 +		policy =  ECheckPostManufacture;
   1.134 +		}
   1.135 +	else if (aEnumString.CompareF(_L("ECheckUnprotectedSids")) == 0)
   1.136 +		{
   1.137 +		policy = ECheckUnprotectedSids;
   1.138 +		}
   1.139 +	else if (aEnumString.CompareF(_L("ECheckIfFailed")) == 0)
   1.140 +		{
   1.141 +		policy = ECheckIfFailed;
   1.142 +		}
   1.143 +	else if (aEnumString.CompareF(_L("ENeverCheck")) == 0)
   1.144 +		{
   1.145 +		policy = ENeverCheck;
   1.146 +		}
   1.147 +	else 
   1.148 +		{
   1.149 +		ERR_PRINTF2(_L("TAuthorisationPolicy enum %S not recognised"), &aEnumString);
   1.150 +		ASSERT_TRUE(EFalse);	
   1.151 +		}	
   1.152 +	return policy;
   1.153 +	}
   1.154 +
   1.155 +TVerdict CServiceConfigTestStep::doTestStepPostambleL()
   1.156 +/**
   1.157 +Cleanup
   1.158 +@return Whether cleanup passed or failed.
   1.159 + */
   1.160 +	{
   1.161 +	return TestStepResult();
   1.162 +	}
   1.163 +