os/security/authorisation/userpromptservice/policies/test/tupspolicies/source/tserviceconfig.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 #include "tserviceconfig.h"
    20 #include <test/testexecutelog.h>
    21 #include <test/tefunit.h>
    22 
    23 #include "policycache.h"
    24 
    25 using namespace UserPromptService;
    26 
    27 CServiceConfigTestStep::CServiceConfigTestStep()
    28 /**
    29 Constructor
    30 */
    31 	{
    32 	// Set human readable name for logging
    33 	SetTestStepName(KServiceConfigStep);		
    34 	}
    35 	
    36 CServiceConfigTestStep::~CServiceConfigTestStep()
    37 /**
    38 Destructor
    39 */
    40 	{
    41 	delete iPolicyCache;
    42 	iPolicyCache = 0;
    43 	iFs.Close();
    44 	}
    45 
    46 TVerdict CServiceConfigTestStep::doTestStepPreambleL()
    47 /**
    48 Initialise
    49 @return Whether the test initialization passed or failed.
    50  */
    51 	{
    52 	User::LeaveIfError(iFs.Connect());
    53 	SetTestStepResult(EPass);
    54 	return TestStepResult();
    55 	}
    56 
    57 TVerdict CServiceConfigTestStep::doTestStepL()
    58 /**
    59 Do the test
    60 @return Whether the test passed or failed.
    61  */
    62 	{
    63 	TPtrC policyDir;
    64 	ASSERT_TRUE(GetStringFromConfig(ConfigSection(), _L("policydir"), policyDir));
    65 	
    66 	iPolicyCache = CPolicyCache::NewL(iFs, policyDir);	
    67 
    68 	TInt serverSid;
    69 	ASSERT_TRUE(GetHexFromConfig(ConfigSection(), _L("serversid"), serverSid));
    70 	
    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);
    75 	
    76 	TInt numServices;
    77 	ASSERT_TRUE(GetIntFromConfig(ConfigSection(), _L("numservices"), numServices));
    78 	
    79 	if (numServices != serviceConfigs.Count())
    80 		{
    81 		ERR_PRINTF3(_L("Number of services = %d, expected number of services = %d"),
    82 			serviceConfigs.Count(), numServices);
    83 			SetTestStepResult(EFail);			
    84 		}
    85 	
    86 	for (TInt i = 0; i < Min(serviceConfigs.Count(), numServices); ++i)
    87 		{		
    88 		TBuf<32> key;
    89 		
    90 		INFO_PRINTF3(_L("service %08x, policy %d"), 
    91 			serviceConfigs[i].iServiceId, serviceConfigs[i].iPolicy);
    92 		
    93 		TInt serviceId;
    94 		key.AppendFormat(_L("service%d"), i);
    95 		ASSERT_TRUE(GetHexFromConfig(ConfigSection(), key, serviceId));		
    96 		if (serviceConfigs[i].iServiceId != serviceId)
    97 			{
    98 			ERR_PRINTF4(_L("Config %d, expected service id = %08x, actual service id %08x"),
    99 				i, serviceId, serviceConfigs[i].iServiceId);
   100 			SetTestStepResult(EFail);			
   101 			}
   102 				
   103 		TPtrC policyString;
   104 		key.Zero();
   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)
   109 			{
   110 			ERR_PRINTF4(_L("Config %d, expected authorisation policy = %d, actual authorisation policy = %d"),
   111 				i, policy, serviceConfigs[i].iPolicy);
   112 			SetTestStepResult(EFail);
   113 			}
   114 		}	
   115 	
   116 	CleanupStack::PopAndDestroy(&serviceConfigs);
   117 	return TestStepResult();
   118 	}
   119 
   120 TAuthorisationPolicy CServiceConfigTestStep::PolicyEnumFromString(const TDesC& aEnumString)
   121 	{
   122 	TAuthorisationPolicy policy(EAlwaysCheck);
   123 	
   124 	if (aEnumString.CompareF(_L("EAlwaysCheck")) == 0)
   125 		{
   126 		policy =  EAlwaysCheck;		
   127 		}
   128 	else if (aEnumString.CompareF(_L("ECheckPostManufacture")) == 0)
   129 		{
   130 		policy =  ECheckPostManufacture;
   131 		}
   132 	else if (aEnumString.CompareF(_L("ECheckUnprotectedSids")) == 0)
   133 		{
   134 		policy = ECheckUnprotectedSids;
   135 		}
   136 	else if (aEnumString.CompareF(_L("ECheckIfFailed")) == 0)
   137 		{
   138 		policy = ECheckIfFailed;
   139 		}
   140 	else if (aEnumString.CompareF(_L("ENeverCheck")) == 0)
   141 		{
   142 		policy = ENeverCheck;
   143 		}
   144 	else 
   145 		{
   146 		ERR_PRINTF2(_L("TAuthorisationPolicy enum %S not recognised"), &aEnumString);
   147 		ASSERT_TRUE(EFalse);	
   148 		}	
   149 	return policy;
   150 	}
   151 
   152 TVerdict CServiceConfigTestStep::doTestStepPostambleL()
   153 /**
   154 Cleanup
   155 @return Whether cleanup passed or failed.
   156  */
   157 	{
   158 	return TestStepResult();
   159 	}
   160