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 "tupsplugins.h"
|
sl@0
|
20 |
|
sl@0
|
21 |
#include <ecom/ecom.h>
|
sl@0
|
22 |
#include <ups/upsconst.h>
|
sl@0
|
23 |
#include <ups/fingerprint.h>
|
sl@0
|
24 |
#include <ups/upserr.h>
|
sl@0
|
25 |
#include "cleanuputils.h"
|
sl@0
|
26 |
#include "util.h"
|
sl@0
|
27 |
|
sl@0
|
28 |
using namespace UserPromptService;
|
sl@0
|
29 |
|
sl@0
|
30 |
_LIT(KRequestsSection, "requests");
|
sl@0
|
31 |
|
sl@0
|
32 |
void CTestPlugins::SetupL()
|
sl@0
|
33 |
/**
|
sl@0
|
34 |
Initialise policy library objects.
|
sl@0
|
35 |
*/
|
sl@0
|
36 |
{
|
sl@0
|
37 |
__UHEAP_MARK;
|
sl@0
|
38 |
User::LeaveIfError(iFs.Connect());
|
sl@0
|
39 |
iActiveWaiter = new(ELeave)CActiveWaiter(Logger());
|
sl@0
|
40 |
|
sl@0
|
41 |
// Dummy decision record for ForcePromptL
|
sl@0
|
42 |
iDecisionRecord = CDecisionRecord::NewL(TSecureId(0), TUid::Null(), TUid::Null(),
|
sl@0
|
43 |
TSecureId(0), _L8("foo"), KNullDesC8, KNullDesC, EFalse, 0, 0);
|
sl@0
|
44 |
}
|
sl@0
|
45 |
|
sl@0
|
46 |
void CTestPlugins::TearDownL()
|
sl@0
|
47 |
/**
|
sl@0
|
48 |
Destroy policy library objects.
|
sl@0
|
49 |
*/
|
sl@0
|
50 |
{
|
sl@0
|
51 |
iRequests.ResetAndDestroy();
|
sl@0
|
52 |
iExpectedValues.ResetAndDestroy();
|
sl@0
|
53 |
delete iDecisionRecord;
|
sl@0
|
54 |
iDecisionRecord = 0;
|
sl@0
|
55 |
delete iActiveWaiter;
|
sl@0
|
56 |
iActiveWaiter = 0;
|
sl@0
|
57 |
iFs.Close();
|
sl@0
|
58 |
__UHEAP_MARKEND;
|
sl@0
|
59 |
}
|
sl@0
|
60 |
|
sl@0
|
61 |
void CTestPlugins::DoCancel()
|
sl@0
|
62 |
{
|
sl@0
|
63 |
}
|
sl@0
|
64 |
|
sl@0
|
65 |
void CTestPlugins::TestCacheL()
|
sl@0
|
66 |
/**
|
sl@0
|
67 |
*/
|
sl@0
|
68 |
{
|
sl@0
|
69 |
TBool passed(ETrue);
|
sl@0
|
70 |
|
sl@0
|
71 |
TInt numRequests;
|
sl@0
|
72 |
ASSERT_TRUE(iConfig.GetInt(KRequestsSection,_L("numrequests"), numRequests));
|
sl@0
|
73 |
ASSERT_TRUE(numRequests > 0);
|
sl@0
|
74 |
|
sl@0
|
75 |
LoadTestDataL(numRequests);
|
sl@0
|
76 |
for (TInt i = 0; i < numRequests; ++i)
|
sl@0
|
77 |
{
|
sl@0
|
78 |
TBuf<16> section(_L("request"));
|
sl@0
|
79 |
section.AppendNum(i);
|
sl@0
|
80 |
|
sl@0
|
81 |
// Is the test expected to fail ?
|
sl@0
|
82 |
iExpectedError = KErrNone;
|
sl@0
|
83 |
(void) iConfig.GetInt(section, _L("expectederror"), iExpectedError);
|
sl@0
|
84 |
|
sl@0
|
85 |
if (! iInteractive) GetResponseL(section);
|
sl@0
|
86 |
|
sl@0
|
87 |
if (iOom)
|
sl@0
|
88 |
{
|
sl@0
|
89 |
INFO_PRINTF2(_L("Running OOM test for request %d"), i);
|
sl@0
|
90 |
passed &= DoOomRequestL(*iExpectedValues[i], *iRequests[i]);
|
sl@0
|
91 |
}
|
sl@0
|
92 |
else
|
sl@0
|
93 |
{
|
sl@0
|
94 |
TRAPD(err, passed &= DoRequestL(*iExpectedValues[i], *iRequests[i]));
|
sl@0
|
95 |
if (err == KErrNoMemory) User::Leave(err);
|
sl@0
|
96 |
passed &= CheckExpectedError(Logger(), iExpectedError, err);
|
sl@0
|
97 |
}
|
sl@0
|
98 |
}
|
sl@0
|
99 |
if (!passed)
|
sl@0
|
100 |
{
|
sl@0
|
101 |
User::Leave(KErrTEFUnitFail);
|
sl@0
|
102 |
}
|
sl@0
|
103 |
}
|
sl@0
|
104 |
|
sl@0
|
105 |
void CTestPlugins::LoadTestDataL(TInt aNumRequests)
|
sl@0
|
106 |
{
|
sl@0
|
107 |
(void) iConfig.GetBool(KRequestsSection,_L("oom"), iOom);
|
sl@0
|
108 |
// Gets the scripted prompt response
|
sl@0
|
109 |
(void) iConfig.GetBool(KRequestsSection,_L("interactive"), iInteractive);
|
sl@0
|
110 |
|
sl@0
|
111 |
// Read all the requests up front
|
sl@0
|
112 |
for (TInt i = 0; i < aNumRequests; ++i)
|
sl@0
|
113 |
{
|
sl@0
|
114 |
TBuf<16> section(_L("request"));
|
sl@0
|
115 |
section.AppendNum(i);
|
sl@0
|
116 |
|
sl@0
|
117 |
GetExpectedValuesL(section);
|
sl@0
|
118 |
CPromptRequest* req = GetRequestParamsLC(section, iExpectedValues[i]->iClientEntity);
|
sl@0
|
119 |
iRequests.AppendL(req);
|
sl@0
|
120 |
CleanupStack::Pop(req);
|
sl@0
|
121 |
}
|
sl@0
|
122 |
}
|
sl@0
|
123 |
|
sl@0
|
124 |
void CTestPlugins::GetResponseL(const TDesC& aSection)
|
sl@0
|
125 |
{
|
sl@0
|
126 |
TPtrC response;
|
sl@0
|
127 |
TBool ret = iConfig.GetString(aSection, _L("response"), response);
|
sl@0
|
128 |
ASSERT_TRUE(ret);
|
sl@0
|
129 |
iResponse = static_cast<CPolicy::TOptions>(StringToOptionL(response));
|
sl@0
|
130 |
|
sl@0
|
131 |
RFile file;
|
sl@0
|
132 |
TBuf<21> name(_L("!:\\upsrefnotifier.txt"));
|
sl@0
|
133 |
name[0] = iFs.GetSystemDriveChar();
|
sl@0
|
134 |
User::LeaveIfError(file.Replace(iFs, name, EFileShareExclusive | EFileWrite));
|
sl@0
|
135 |
CleanupClosePushL(file);
|
sl@0
|
136 |
|
sl@0
|
137 |
HBufC* opt = OptionToString(iResponse).AllocLC();
|
sl@0
|
138 |
User::LeaveIfError(file.Write(opt->Des().Collapse()));
|
sl@0
|
139 |
|
sl@0
|
140 |
if (! iOom) INFO_PRINTF2(_L("Scripted prompt response = %S"), &OptionToString(iResponse));
|
sl@0
|
141 |
CleanupStack::PopAndDestroy(2, &file); // file, opt
|
sl@0
|
142 |
}
|
sl@0
|
143 |
|
sl@0
|
144 |
TBool CTestPlugins::DoRequestL(const TExpectedValue& aExpected, const CPromptRequest& aRequest)
|
sl@0
|
145 |
{
|
sl@0
|
146 |
TBool passed(ETrue);
|
sl@0
|
147 |
|
sl@0
|
148 |
CPluginManager* pluginManager = CPluginManager::NewL();
|
sl@0
|
149 |
CleanupStack::PushL(pluginManager);
|
sl@0
|
150 |
CPolicyCache* policyCache = CPolicyCache::NewL(iFs, _L("\\tups\\tpolicies\\policies\\"));
|
sl@0
|
151 |
CleanupStack::PushL(policyCache);
|
sl@0
|
152 |
|
sl@0
|
153 |
TBool protectedSid = ((aRequest.ClientSid().iId & 0x80000000) == 0);
|
sl@0
|
154 |
if (protectedSid != aRequest.IsClientSidProtected())
|
sl@0
|
155 |
{
|
sl@0
|
156 |
ERR_PRINTF3(_L("Expected value for CPromptRequest::IsProtectedSid() = %d, actual value = %d"),
|
sl@0
|
157 |
protectedSid, aRequest.IsClientSidProtected());
|
sl@0
|
158 |
passed = EFalse;
|
sl@0
|
159 |
}
|
sl@0
|
160 |
|
sl@0
|
161 |
const CPolicy* policy = policyCache->MatchL(aRequest);
|
sl@0
|
162 |
ASSERT_NOT_NULL(policy);
|
sl@0
|
163 |
// Attempt to load the policy a second time, should get the same
|
sl@0
|
164 |
// policy object and policy cache should not leak.
|
sl@0
|
165 |
__UHEAP_MARK;
|
sl@0
|
166 |
ASSERT_EQUALS(policy, policyCache->MatchL(aRequest));
|
sl@0
|
167 |
__UHEAP_MARKEND;
|
sl@0
|
168 |
|
sl@0
|
169 |
// It should also be safe to load the service configuration if we have loaded a single
|
sl@0
|
170 |
// policy file.
|
sl@0
|
171 |
RArray<TServiceConfig> configs;
|
sl@0
|
172 |
CleanupClosePushL(configs);
|
sl@0
|
173 |
policyCache->ServiceConfigL(aRequest.ServerSid().iId, configs);
|
sl@0
|
174 |
ASSERT_TRUE(configs.Count() > 0); // If policy was loaded there must be at least one service config
|
sl@0
|
175 |
CleanupStack::PopAndDestroy(&configs);
|
sl@0
|
176 |
|
sl@0
|
177 |
passed &= CheckPolicyL(aExpected, policy);
|
sl@0
|
178 |
|
sl@0
|
179 |
if (policy->PromptRequired())
|
sl@0
|
180 |
{
|
sl@0
|
181 |
// Just verify that GetExtension doesn't crash
|
sl@0
|
182 |
TAny* extensionPtr(0);
|
sl@0
|
183 |
CPlugin<CPolicyEvaluator>* policyEvaluator =
|
sl@0
|
184 |
pluginManager->CreateEvaluatorL(policy->PolicyEvaluator());
|
sl@0
|
185 |
CleanupStack::PushL(policyEvaluator);
|
sl@0
|
186 |
policyEvaluator->Imp().GetExtension(0, extensionPtr, NULL);
|
sl@0
|
187 |
|
sl@0
|
188 |
RPointerArray<CFingerprint> fingerprints;
|
sl@0
|
189 |
CleanupResetAndDestroyPushL(fingerprints);
|
sl@0
|
190 |
const CClientEntity* clientEntity(0);
|
sl@0
|
191 |
const TAny* dialogCreatorParams(0);
|
sl@0
|
192 |
|
sl@0
|
193 |
policyEvaluator->Imp().GenerateFingerprints(aRequest, *policy,
|
sl@0
|
194 |
fingerprints, clientEntity, dialogCreatorParams, iActiveWaiter->iStatus);
|
sl@0
|
195 |
iActiveWaiter->WaitActive(KErrNone);
|
sl@0
|
196 |
|
sl@0
|
197 |
if (! iOom) INFO_PRINTF3(_L("Policy Evaluator 0x%08x: num fingerprints = %d"),
|
sl@0
|
198 |
policy->PolicyEvaluator(), fingerprints.Count());
|
sl@0
|
199 |
|
sl@0
|
200 |
if (aExpected.iClientEntity.Length())
|
sl@0
|
201 |
{
|
sl@0
|
202 |
if (! clientEntity)
|
sl@0
|
203 |
{
|
sl@0
|
204 |
ERR_PRINTF1(_L("Client entity expected"));
|
sl@0
|
205 |
passed = EFalse;
|
sl@0
|
206 |
}
|
sl@0
|
207 |
else if (clientEntity->Name() != aExpected.iClientEntity)
|
sl@0
|
208 |
{
|
sl@0
|
209 |
ERR_PRINTF1(_L("Cliententity name mismatch"));
|
sl@0
|
210 |
passed = EFalse;
|
sl@0
|
211 |
}
|
sl@0
|
212 |
}
|
sl@0
|
213 |
else if (aExpected.iClientEntity.Length() == 0 && clientEntity)
|
sl@0
|
214 |
{
|
sl@0
|
215 |
ERR_PRINTF1(_L("Unexpected client entity"));
|
sl@0
|
216 |
passed = EFalse;
|
sl@0
|
217 |
}
|
sl@0
|
218 |
|
sl@0
|
219 |
// Make sure base class implementation for ForcePromptL returns EFalse
|
sl@0
|
220 |
TUint evaluatorInfo(0);
|
sl@0
|
221 |
ASSERT_FALSE(policyEvaluator->Imp().CPolicyEvaluator::ForcePromptL(*iDecisionRecord, evaluatorInfo));
|
sl@0
|
222 |
|
sl@0
|
223 |
CPlugin<CDialogCreator>* dialogCreator
|
sl@0
|
224 |
= pluginManager->CreateDialogCreatorL(policy->DialogCreator());
|
sl@0
|
225 |
CleanupStack::PushL(dialogCreator);
|
sl@0
|
226 |
dialogCreator->Imp().GetExtension(0, extensionPtr, NULL);
|
sl@0
|
227 |
|
sl@0
|
228 |
dialogCreator->Imp().PrepareDialog(
|
sl@0
|
229 |
aRequest, *policy, fingerprints, clientEntity, dialogCreatorParams, iActiveWaiter->iStatus);
|
sl@0
|
230 |
iActiveWaiter->WaitActive(KErrNone);
|
sl@0
|
231 |
|
sl@0
|
232 |
const CFingerprint* fingerprint(0);
|
sl@0
|
233 |
CPolicy::TOptions selected;
|
sl@0
|
234 |
dialogCreator->Imp().DisplayDialog(
|
sl@0
|
235 |
selected, fingerprint, evaluatorInfo, iActiveWaiter->iStatus);
|
sl@0
|
236 |
iActiveWaiter->WaitActive(KErrNone);
|
sl@0
|
237 |
|
sl@0
|
238 |
if (! iOom) INFO_PRINTF2(_L("User response: %S"), &OptionToString(selected));
|
sl@0
|
239 |
if (! iInteractive && selected != iResponse) // don't check response in interactive mode
|
sl@0
|
240 |
{
|
sl@0
|
241 |
ERR_PRINTF3(_L("Expected user response = %S, actual user response = %S"),
|
sl@0
|
242 |
&OptionToString(iResponse), &OptionToString(selected));
|
sl@0
|
243 |
passed = EFalse;
|
sl@0
|
244 |
}
|
sl@0
|
245 |
|
sl@0
|
246 |
if (fingerprint)
|
sl@0
|
247 |
{
|
sl@0
|
248 |
if (! iOom) INFO_PRINTF2(_L("Description for selected fingerprint: %S"), &fingerprint->Description());
|
sl@0
|
249 |
}
|
sl@0
|
250 |
CleanupStack::PopAndDestroy(3, policyEvaluator); // fingerprint, dialogcreator
|
sl@0
|
251 |
}
|
sl@0
|
252 |
else
|
sl@0
|
253 |
{
|
sl@0
|
254 |
if (! iOom) INFO_PRINTF2(_L("Policy %d does not require a prompt to be displayed"), policy->Flags());
|
sl@0
|
255 |
}
|
sl@0
|
256 |
CleanupStack::PopAndDestroy(2, pluginManager); // policyCache
|
sl@0
|
257 |
return passed;
|
sl@0
|
258 |
}
|
sl@0
|
259 |
|
sl@0
|
260 |
void CTestPlugins::GetExpectedValuesL(const TDesC& aSection)
|
sl@0
|
261 |
{
|
sl@0
|
262 |
TExpectedValue* expected = new(ELeave) TExpectedValue();
|
sl@0
|
263 |
CleanupStack::PushL(expected);
|
sl@0
|
264 |
iExpectedValues.AppendL(expected);
|
sl@0
|
265 |
CleanupStack::Pop(expected);
|
sl@0
|
266 |
|
sl@0
|
267 |
iConfig.GetHex(aSection, _L("expectedflags"), expected->iFlags);
|
sl@0
|
268 |
iConfig.GetHex(aSection, _L("expectedmajorversion"), expected->iMajorVersion);
|
sl@0
|
269 |
iConfig.GetHex(aSection, _L("expectedminorversion"), expected->iMinorVersion);
|
sl@0
|
270 |
iConfig.GetBool(aSection, _L("expectedsilent"), expected->iSilent);
|
sl@0
|
271 |
iConfig.GetHex(aSection, _L("expectedpolicyevaluator"), expected->iPolicyEvaluator);
|
sl@0
|
272 |
|
sl@0
|
273 |
TPtrC clientEntity;
|
sl@0
|
274 |
if (iConfig.GetString(aSection, _L("cliententity"), clientEntity))
|
sl@0
|
275 |
{
|
sl@0
|
276 |
ASSERT_TRUE(clientEntity.Length() < expected->iClientEntity.MaxLength());
|
sl@0
|
277 |
expected->iClientEntity.Copy(clientEntity);
|
sl@0
|
278 |
}
|
sl@0
|
279 |
}
|
sl@0
|
280 |
|
sl@0
|
281 |
TBool CTestPlugins::CheckPolicyL(const TExpectedValue& aExpected, const CPolicy* aPolicy)
|
sl@0
|
282 |
/**
|
sl@0
|
283 |
Checks the correct policy was found for the request.
|
sl@0
|
284 |
@param aPolicy The policy object returned by the policy cache.
|
sl@0
|
285 |
@return ETrue if successful; otherwise, EFalse is returned.
|
sl@0
|
286 |
*/
|
sl@0
|
287 |
{
|
sl@0
|
288 |
TBool passed = ETrue;
|
sl@0
|
289 |
|
sl@0
|
290 |
if (aExpected.iFlags != aPolicy->Flags())
|
sl@0
|
291 |
{
|
sl@0
|
292 |
ERR_PRINTF3(_L("Expected flags = 0x%04x, actual flags 0x%04x"),
|
sl@0
|
293 |
aExpected.iFlags, aPolicy->Flags());
|
sl@0
|
294 |
passed = EFalse;
|
sl@0
|
295 |
}
|
sl@0
|
296 |
|
sl@0
|
297 |
if (aExpected.iMajorVersion != aPolicy->MajorVersion())
|
sl@0
|
298 |
{
|
sl@0
|
299 |
ERR_PRINTF3(_L("Expected major version = %d, actual major version = %d"),
|
sl@0
|
300 |
aExpected.iMajorVersion, aPolicy->MajorVersion());
|
sl@0
|
301 |
passed = EFalse;
|
sl@0
|
302 |
}
|
sl@0
|
303 |
|
sl@0
|
304 |
if (aExpected.iMinorVersion != aPolicy->MinorVersion())
|
sl@0
|
305 |
{
|
sl@0
|
306 |
ERR_PRINTF3(_L("Expected minor version = %d, actual minor version = %d"),
|
sl@0
|
307 |
aExpected.iMinorVersion, aPolicy->MinorVersion());
|
sl@0
|
308 |
passed = EFalse;
|
sl@0
|
309 |
}
|
sl@0
|
310 |
|
sl@0
|
311 |
if ((TUint)aExpected.iPolicyEvaluator != aPolicy->PolicyEvaluator().iUid)
|
sl@0
|
312 |
{
|
sl@0
|
313 |
ERR_PRINTF3(_L("Expected policy evaluator = %08x, actual policy evaluator = %08x"),
|
sl@0
|
314 |
aExpected.iPolicyEvaluator, aPolicy->PolicyEvaluator().iUid)
|
sl@0
|
315 |
passed = EFalse;
|
sl@0
|
316 |
}
|
sl@0
|
317 |
|
sl@0
|
318 |
TBool silent = ! aPolicy->PromptRequired();
|
sl@0
|
319 |
if (silent)
|
sl@0
|
320 |
{
|
sl@0
|
321 |
if (! iOom) INFO_PRINTF1(_L("Policy never requires a prompt."));
|
sl@0
|
322 |
}
|
sl@0
|
323 |
|
sl@0
|
324 |
if (silent != aExpected.iSilent)
|
sl@0
|
325 |
{
|
sl@0
|
326 |
ERR_PRINTF3(_L("Expected value for silent policy = %d, actual = %d"),
|
sl@0
|
327 |
aExpected.iSilent, silent);
|
sl@0
|
328 |
passed = EFalse;
|
sl@0
|
329 |
}
|
sl@0
|
330 |
|
sl@0
|
331 |
return passed;
|
sl@0
|
332 |
}
|
sl@0
|
333 |
|
sl@0
|
334 |
CTestSuite* CTestPlugins::CreateSuiteL(const TDesC& aName)
|
sl@0
|
335 |
/**
|
sl@0
|
336 |
Creates the test suite for User Prompt Service ECOM plug-ins
|
sl@0
|
337 |
@param aName - Suite name
|
sl@0
|
338 |
@return - Suite
|
sl@0
|
339 |
*/
|
sl@0
|
340 |
{
|
sl@0
|
341 |
SUB_SUITE
|
sl@0
|
342 |
AddAsyncTestCase(lTestSuite, _L("TestCacheL"), &CTestPlugins::TestCacheL);
|
sl@0
|
343 |
AddAsyncTestCase(lTestSuite, _L("TestPluginManagerL"), &CTestPlugins::TestPluginManagerL);
|
sl@0
|
344 |
AddAsyncTestCase(lTestSuite, _L("TestLengthsL"), &CTestPlugins::TestLengthsL);
|
sl@0
|
345 |
END_SUITE
|
sl@0
|
346 |
}
|
sl@0
|
347 |
|
sl@0
|
348 |
CPromptRequest* CTestPlugins::GetRequestParamsLC(const TDesC& aSection, const TDesC8& aClientEntity)
|
sl@0
|
349 |
/**
|
sl@0
|
350 |
Gets the data from the CPromptRequest from a section in the config file.
|
sl@0
|
351 |
@param aSection The name of the section containing the prompt request data.
|
sl@0
|
352 |
@return The new CPromptRequest object.
|
sl@0
|
353 |
*/
|
sl@0
|
354 |
{
|
sl@0
|
355 |
TInt clientSid;
|
sl@0
|
356 |
ASSERT_TRUE(iConfig.GetHex(aSection,_L("clientsid"), clientSid));
|
sl@0
|
357 |
|
sl@0
|
358 |
TInt clientVid;
|
sl@0
|
359 |
ASSERT_TRUE(iConfig.GetHex(aSection,_L("clientvid"), clientVid));
|
sl@0
|
360 |
|
sl@0
|
361 |
TInt serverSid;
|
sl@0
|
362 |
ASSERT_TRUE(iConfig.GetHex(aSection,_L("serversid"), serverSid));
|
sl@0
|
363 |
|
sl@0
|
364 |
TInt serviceId;
|
sl@0
|
365 |
ASSERT_TRUE(iConfig.GetHex(aSection,_L("serviceid"), serviceId));
|
sl@0
|
366 |
|
sl@0
|
367 |
TPtrC destination;
|
sl@0
|
368 |
ASSERT_TRUE(iConfig.GetString(aSection,_L("destination"), destination));
|
sl@0
|
369 |
|
sl@0
|
370 |
TBool securityResult;
|
sl@0
|
371 |
ASSERT_TRUE(iConfig.GetBool(aSection,_L("securityresult"), securityResult));
|
sl@0
|
372 |
|
sl@0
|
373 |
TPtrC opaqueData;
|
sl@0
|
374 |
ASSERT_TRUE(iConfig.GetString(aSection,_L("opaquedata"), opaqueData));
|
sl@0
|
375 |
|
sl@0
|
376 |
TThreadId myThreadId;
|
sl@0
|
377 |
RThread me;
|
sl@0
|
378 |
myThreadId = me.Id();
|
sl@0
|
379 |
me.Close();
|
sl@0
|
380 |
|
sl@0
|
381 |
TProcessId myProcessId;
|
sl@0
|
382 |
RProcess mep;
|
sl@0
|
383 |
myProcessId = mep.Id();
|
sl@0
|
384 |
mep.Close();
|
sl@0
|
385 |
|
sl@0
|
386 |
RBuf destinationRb;
|
sl@0
|
387 |
destinationRb.CreateL(destination);
|
sl@0
|
388 |
CleanupClosePushL(destinationRb);
|
sl@0
|
389 |
|
sl@0
|
390 |
RBuf8 opaqueDataRb;
|
sl@0
|
391 |
opaqueDataRb.CreateL(opaqueData.Length() + aClientEntity.Length() + 64);
|
sl@0
|
392 |
CleanupClosePushL(opaqueDataRb);
|
sl@0
|
393 |
opaqueDataRb.Copy(opaqueData);
|
sl@0
|
394 |
if (aClientEntity.Length())
|
sl@0
|
395 |
{
|
sl@0
|
396 |
opaqueDataRb.Append(_L8("<ce>"));
|
sl@0
|
397 |
opaqueDataRb.Append(aClientEntity);
|
sl@0
|
398 |
opaqueDataRb.Append(_L8("</ce>"));
|
sl@0
|
399 |
}
|
sl@0
|
400 |
|
sl@0
|
401 |
|
sl@0
|
402 |
CPromptRequest* req =
|
sl@0
|
403 |
CPromptRequest::NewL(TUid::Uid(clientSid), TUid::Uid(clientVid), myThreadId, myProcessId,
|
sl@0
|
404 |
TUid::Uid(serverSid), TUid::Uid(serviceId),
|
sl@0
|
405 |
destinationRb, opaqueDataRb, securityResult);
|
sl@0
|
406 |
|
sl@0
|
407 |
CleanupStack::PopAndDestroy(&opaqueDataRb);
|
sl@0
|
408 |
CleanupStack::PopAndDestroy(&destinationRb);
|
sl@0
|
409 |
|
sl@0
|
410 |
CleanupStack::PushL(req);
|
sl@0
|
411 |
|
sl@0
|
412 |
return req;
|
sl@0
|
413 |
}
|
sl@0
|
414 |
|
sl@0
|
415 |
void CTestPlugins::TestLengthsL()
|
sl@0
|
416 |
/**
|
sl@0
|
417 |
Tests length constrains in the CFingerprint and CClientEntity classes
|
sl@0
|
418 |
*/
|
sl@0
|
419 |
{
|
sl@0
|
420 |
TInt maxLen = KUpsMaxFingerprintLength + 1;
|
sl@0
|
421 |
HBufC8* bigBuffer = HBufC8::NewMaxLC(maxLen);
|
sl@0
|
422 |
TPtrC8 emptyBuf;
|
sl@0
|
423 |
|
sl@0
|
424 |
_LIT8(K32Bytes, "01234567890123456789012345678901");
|
sl@0
|
425 |
_LIT(KDescription, "description");
|
sl@0
|
426 |
|
sl@0
|
427 |
CFingerprint* fp(0);
|
sl@0
|
428 |
CClientEntity* ce(0);
|
sl@0
|
429 |
|
sl@0
|
430 |
TInt err(KErrNone);
|
sl@0
|
431 |
|
sl@0
|
432 |
if (! iOom) INFO_PRINTF1(_L("Create a fingerprint with an empty value - should pass"));
|
sl@0
|
433 |
fp = CFingerprint::NewL(emptyBuf, KDescription);
|
sl@0
|
434 |
delete fp;
|
sl@0
|
435 |
|
sl@0
|
436 |
if (! iOom) INFO_PRINTF1(_L("Create a fingerprint with value that's too long - should fail"));
|
sl@0
|
437 |
TRAP(err, fp = CFingerprint::NewL(*bigBuffer, KDescription));
|
sl@0
|
438 |
ASSERT_EQUALS(err, KErrUpsBadFingerprintLength);
|
sl@0
|
439 |
|
sl@0
|
440 |
if (! iOom) INFO_PRINTF1(_L("Create a fingerprint with 32 bytes of data - should pass"));
|
sl@0
|
441 |
fp = CFingerprint::NewLC(K32Bytes, KDescription);
|
sl@0
|
442 |
ASSERT_TRUE(fp->Fingerprint() == K32Bytes);
|
sl@0
|
443 |
ASSERT_TRUE(fp->Description() == KDescription);
|
sl@0
|
444 |
CleanupStack::PopAndDestroy(fp);
|
sl@0
|
445 |
|
sl@0
|
446 |
if (! iOom) INFO_PRINTF1(_L("Create a client entity with an empty value - should pass"));
|
sl@0
|
447 |
ce = CClientEntity::NewLC(emptyBuf);
|
sl@0
|
448 |
ASSERT_TRUE(ce->Name() == emptyBuf);
|
sl@0
|
449 |
CleanupStack::PopAndDestroy(ce);
|
sl@0
|
450 |
|
sl@0
|
451 |
if (! iOom) INFO_PRINTF1(_L("Create a client entity with a name that's too long - should fail"));
|
sl@0
|
452 |
TRAP(err, ce = CClientEntity::NewL(*bigBuffer));
|
sl@0
|
453 |
ASSERT_EQUALS(err, KErrUpsBadClientEntityLength);
|
sl@0
|
454 |
|
sl@0
|
455 |
if (! iOom) INFO_PRINTF1(_L("Create a client entity with a 32 byte name - should pass"));
|
sl@0
|
456 |
ce = CClientEntity::NewLC(K32Bytes);
|
sl@0
|
457 |
ASSERT_TRUE(ce->Name() == K32Bytes);
|
sl@0
|
458 |
CleanupStack::PopAndDestroy(ce);
|
sl@0
|
459 |
|
sl@0
|
460 |
CleanupStack::PopAndDestroy(bigBuffer);
|
sl@0
|
461 |
}
|
sl@0
|
462 |
|
sl@0
|
463 |
void CTestPlugins::TestPluginManagerL()
|
sl@0
|
464 |
/**
|
sl@0
|
465 |
Creates and destroy UPS plug-ins to test CPluginManager.
|
sl@0
|
466 |
*/
|
sl@0
|
467 |
{
|
sl@0
|
468 |
TInt uidVal;
|
sl@0
|
469 |
CPluginManager* pluginManager = CPluginManager::NewL();
|
sl@0
|
470 |
CleanupStack::PushL(pluginManager);
|
sl@0
|
471 |
|
sl@0
|
472 |
CPlugin<CPolicyEvaluator>* policyEvaluator(0);
|
sl@0
|
473 |
CPlugin<CDialogCreator>* dialogCreator(0);
|
sl@0
|
474 |
|
sl@0
|
475 |
ASSERT_TRUE(iConfig.GetHex(_L("pluginmanager"),_L("policyevaluatoruid"), uidVal));
|
sl@0
|
476 |
TUid policyEvaluatorUid = TUid::Uid(uidVal);
|
sl@0
|
477 |
|
sl@0
|
478 |
ASSERT_TRUE(iConfig.GetHex(_L("pluginmanager"),_L("dialogcreatoruid"), uidVal));
|
sl@0
|
479 |
TUid dialogCreatorUid = TUid::Uid(uidVal);
|
sl@0
|
480 |
|
sl@0
|
481 |
if (! iOom) INFO_PRINTF1(_L("Calling unload with no active plug-ins"));
|
sl@0
|
482 |
pluginManager->Unload();
|
sl@0
|
483 |
ASSERT_EQUALS(pluginManager->iPluginCount, 0);
|
sl@0
|
484 |
|
sl@0
|
485 |
if (! iOom) INFO_PRINTF1(_L("Calling unload after creating and destroying a plug-in"));
|
sl@0
|
486 |
policyEvaluator = pluginManager->CreateEvaluatorL(policyEvaluatorUid);
|
sl@0
|
487 |
ASSERT_EQUALS(pluginManager->iPluginCount, 1);
|
sl@0
|
488 |
delete policyEvaluator;
|
sl@0
|
489 |
ASSERT_EQUALS(pluginManager->iPluginCount, 0);
|
sl@0
|
490 |
pluginManager->Unload();
|
sl@0
|
491 |
ASSERT_EQUALS(pluginManager->iPluginCount, 0);
|
sl@0
|
492 |
|
sl@0
|
493 |
if (! iOom) INFO_PRINTF1(_L("Calling unload after deleting last plug-in"));
|
sl@0
|
494 |
policyEvaluator = pluginManager->CreateEvaluatorL(policyEvaluatorUid);
|
sl@0
|
495 |
ASSERT_EQUALS(pluginManager->iPluginCount, 1);
|
sl@0
|
496 |
delete policyEvaluator;
|
sl@0
|
497 |
ASSERT_EQUALS(pluginManager->iPluginCount, 0);
|
sl@0
|
498 |
policyEvaluator = pluginManager->CreateEvaluatorL(policyEvaluatorUid);
|
sl@0
|
499 |
ASSERT_EQUALS(pluginManager->iPluginCount, 1);
|
sl@0
|
500 |
pluginManager->Unload();
|
sl@0
|
501 |
ASSERT_EQUALS(pluginManager->iPluginCount, 1);
|
sl@0
|
502 |
delete policyEvaluator;
|
sl@0
|
503 |
ASSERT_EQUALS(pluginManager->iPluginCount, 0);
|
sl@0
|
504 |
|
sl@0
|
505 |
INFO_PRINTF1(_L("Policy evaluators and dialog creators"));
|
sl@0
|
506 |
policyEvaluator = pluginManager->CreateEvaluatorL(policyEvaluatorUid);
|
sl@0
|
507 |
ASSERT_EQUALS(pluginManager->iPluginCount, 1);
|
sl@0
|
508 |
CleanupStack::PushL(policyEvaluator);
|
sl@0
|
509 |
pluginManager->Unload();
|
sl@0
|
510 |
ASSERT_EQUALS(pluginManager->iPluginCount, 1);
|
sl@0
|
511 |
dialogCreator = pluginManager->CreateDialogCreatorL(dialogCreatorUid);
|
sl@0
|
512 |
ASSERT_EQUALS(pluginManager->iPluginCount, 2);
|
sl@0
|
513 |
CleanupStack::PushL(dialogCreator);
|
sl@0
|
514 |
CleanupStack::PopAndDestroy(2, policyEvaluator); // dialogCreator
|
sl@0
|
515 |
ASSERT_EQUALS(pluginManager->iPluginCount, 0);
|
sl@0
|
516 |
|
sl@0
|
517 |
CleanupStack::PopAndDestroy(pluginManager);
|
sl@0
|
518 |
}
|
sl@0
|
519 |
|
sl@0
|
520 |
TBool CTestPlugins::DoOomRequestL(const TExpectedValue& aExpected, const CPromptRequest& aRequest)
|
sl@0
|
521 |
/**
|
sl@0
|
522 |
Performs OOM test
|
sl@0
|
523 |
*/
|
sl@0
|
524 |
{
|
sl@0
|
525 |
TBool passed = EFalse;
|
sl@0
|
526 |
|
sl@0
|
527 |
TInt countAfter = 0;
|
sl@0
|
528 |
TInt countBefore = 0;
|
sl@0
|
529 |
for (TInt oomCount = 0; ; oomCount++)
|
sl@0
|
530 |
{
|
sl@0
|
531 |
INFO_PRINTF2(_L("\n ==== Number of memory allocations %d ===="), oomCount);
|
sl@0
|
532 |
passed = EFalse;
|
sl@0
|
533 |
__UHEAP_RESET;
|
sl@0
|
534 |
__UHEAP_SETFAIL(RHeap::EDeterministic, oomCount);
|
sl@0
|
535 |
countBefore = User::CountAllocCells();
|
sl@0
|
536 |
TRAPD(error, DoRequestL(aExpected, aRequest));// ----> This is the actual test that runs under OOM conditions.
|
sl@0
|
537 |
countAfter = User::CountAllocCells();
|
sl@0
|
538 |
__UHEAP_RESET;
|
sl@0
|
539 |
|
sl@0
|
540 |
ASSERT_TRUE(error == KErrNone || error == KErrNoMemory);
|
sl@0
|
541 |
|
sl@0
|
542 |
if (error == KErrNone)
|
sl@0
|
543 |
{
|
sl@0
|
544 |
passed = ETrue;
|
sl@0
|
545 |
INFO_PRINTF2(_L("OOM Status %d"),error);
|
sl@0
|
546 |
INFO_PRINTF1(_L("Test outcome : Passed"));
|
sl@0
|
547 |
break;
|
sl@0
|
548 |
}
|
sl@0
|
549 |
else
|
sl@0
|
550 |
{
|
sl@0
|
551 |
if (countBefore != countAfter)
|
sl@0
|
552 |
{
|
sl@0
|
553 |
INFO_PRINTF2(_L("OOM Status %d"),error);
|
sl@0
|
554 |
INFO_PRINTF2(_L("OOM Failed at %d"), oomCount);
|
sl@0
|
555 |
break;
|
sl@0
|
556 |
}
|
sl@0
|
557 |
}
|
sl@0
|
558 |
INFO_PRINTF2(_L("OOM Failed Point status %d"), error);
|
sl@0
|
559 |
}
|
sl@0
|
560 |
INFO_PRINTF3(_L("Heap alloc count ok: %d final vs %d initial"), countAfter,countBefore);
|
sl@0
|
561 |
return passed;
|
sl@0
|
562 |
}
|