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