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 |
* Test program exercises the swi observer UPS API.
|
sl@0
|
16 |
* See individual test functions for more information.
|
sl@0
|
17 |
*
|
sl@0
|
18 |
*/
|
sl@0
|
19 |
|
sl@0
|
20 |
|
sl@0
|
21 |
/**
|
sl@0
|
22 |
@file
|
sl@0
|
23 |
*/
|
sl@0
|
24 |
|
sl@0
|
25 |
#include <e32ldr.h>
|
sl@0
|
26 |
#include <e32ldr_private.h>
|
sl@0
|
27 |
#include "rtestwrapper.h"
|
sl@0
|
28 |
|
sl@0
|
29 |
#include <ups/upsclient.h>
|
sl@0
|
30 |
#include "f32file.h"
|
sl@0
|
31 |
|
sl@0
|
32 |
using namespace UserPromptService;
|
sl@0
|
33 |
|
sl@0
|
34 |
/** Top-level test object renders stages and confirms conditions. */
|
sl@0
|
35 |
static RTestWrapper test(_L("UPSTESTOBSIFOOM"));
|
sl@0
|
36 |
|
sl@0
|
37 |
static RUpsManagement sMngmntSession;
|
sl@0
|
38 |
|
sl@0
|
39 |
void PopulateDatabaseL()
|
sl@0
|
40 |
{
|
sl@0
|
41 |
//test.Start(_L("Populate database"));
|
sl@0
|
42 |
RUpsSession session;
|
sl@0
|
43 |
User::LeaveIfError(session.Connect());
|
sl@0
|
44 |
CleanupClosePushL(session);
|
sl@0
|
45 |
|
sl@0
|
46 |
RThread thd;
|
sl@0
|
47 |
RUpsSubsession clientSubsession;
|
sl@0
|
48 |
TInt r = clientSubsession.Initialise(session, thd);
|
sl@0
|
49 |
test(r == KErrNone);
|
sl@0
|
50 |
CleanupClosePushL(clientSubsession);
|
sl@0
|
51 |
|
sl@0
|
52 |
RBuf destination;
|
sl@0
|
53 |
destination.CreateL(100);
|
sl@0
|
54 |
CleanupClosePushL(destination);
|
sl@0
|
55 |
|
sl@0
|
56 |
for(TInt i=0 ; i<10; ++i)
|
sl@0
|
57 |
{
|
sl@0
|
58 |
TServiceId serviceId = {42};
|
sl@0
|
59 |
if( i & 1) serviceId.iUid = 43;
|
sl@0
|
60 |
destination.Zero();
|
sl@0
|
61 |
destination.AppendFormat(_L("destination %x"), i);
|
sl@0
|
62 |
|
sl@0
|
63 |
TUpsDecision dec = EUpsDecNo;
|
sl@0
|
64 |
TRequestStatus rs;
|
sl@0
|
65 |
clientSubsession.Authorise(EFalse, serviceId, destination, _L8("Opaque data"), dec, rs);
|
sl@0
|
66 |
User::WaitForRequest(rs);
|
sl@0
|
67 |
test((rs == KErrNone) || (rs == KErrNoMemory));
|
sl@0
|
68 |
if(rs == KErrNone)
|
sl@0
|
69 |
{
|
sl@0
|
70 |
if(serviceId.iUid == 42)
|
sl@0
|
71 |
{
|
sl@0
|
72 |
test(dec == EUpsDecYes);
|
sl@0
|
73 |
}
|
sl@0
|
74 |
else
|
sl@0
|
75 |
{
|
sl@0
|
76 |
test(dec == EUpsDecNo);
|
sl@0
|
77 |
}
|
sl@0
|
78 |
}
|
sl@0
|
79 |
}
|
sl@0
|
80 |
|
sl@0
|
81 |
CleanupStack::PopAndDestroy(&destination);
|
sl@0
|
82 |
CleanupStack::PopAndDestroy(&clientSubsession);
|
sl@0
|
83 |
CleanupStack::PopAndDestroy(&session);
|
sl@0
|
84 |
//test.End();
|
sl@0
|
85 |
}
|
sl@0
|
86 |
|
sl@0
|
87 |
#if 1
|
sl@0
|
88 |
class CTestSwiIf;
|
sl@0
|
89 |
NONSHARABLE_CLASS(CRequest) : public CActive
|
sl@0
|
90 |
{
|
sl@0
|
91 |
public:
|
sl@0
|
92 |
static CRequest *NewL(RUpsSession &aSession, CTestSwiIf &aParent, TInt aId, TUpsDecision aExpected);
|
sl@0
|
93 |
~CRequest();
|
sl@0
|
94 |
private:
|
sl@0
|
95 |
CRequest(CTestSwiIf &aParent, TUpsDecision aExpected);
|
sl@0
|
96 |
void ConstructL(RUpsSession &aSession, TInt aId);
|
sl@0
|
97 |
|
sl@0
|
98 |
virtual void RunL();
|
sl@0
|
99 |
virtual void DoCancel();
|
sl@0
|
100 |
virtual TInt RunError(TInt aError);
|
sl@0
|
101 |
|
sl@0
|
102 |
CTestSwiIf &iParent;
|
sl@0
|
103 |
|
sl@0
|
104 |
RUpsSubsession iSubSession;
|
sl@0
|
105 |
|
sl@0
|
106 |
TUpsDecision iDec;
|
sl@0
|
107 |
TUpsDecision iExpected;
|
sl@0
|
108 |
};
|
sl@0
|
109 |
|
sl@0
|
110 |
|
sl@0
|
111 |
NONSHARABLE_CLASS(CTestSwiIf) : public CActive
|
sl@0
|
112 |
{
|
sl@0
|
113 |
public:
|
sl@0
|
114 |
static CTestSwiIf *NewL();
|
sl@0
|
115 |
|
sl@0
|
116 |
~CTestSwiIf();
|
sl@0
|
117 |
|
sl@0
|
118 |
void IncUsers();
|
sl@0
|
119 |
void DecUsers();
|
sl@0
|
120 |
|
sl@0
|
121 |
TInt Result();
|
sl@0
|
122 |
private:
|
sl@0
|
123 |
CTestSwiIf();
|
sl@0
|
124 |
void ConstructL();
|
sl@0
|
125 |
|
sl@0
|
126 |
enum EState
|
sl@0
|
127 |
{
|
sl@0
|
128 |
EPrePolicyChange,
|
sl@0
|
129 |
EPostPolicyChange,
|
sl@0
|
130 |
ERevertPolicyChange,
|
sl@0
|
131 |
ETestingComplete
|
sl@0
|
132 |
};
|
sl@0
|
133 |
|
sl@0
|
134 |
virtual void RunL();
|
sl@0
|
135 |
virtual void DoCancel();
|
sl@0
|
136 |
virtual TInt RunError(TInt aError);
|
sl@0
|
137 |
|
sl@0
|
138 |
TInt iUsers;
|
sl@0
|
139 |
|
sl@0
|
140 |
RFs iFs;
|
sl@0
|
141 |
EState iState;
|
sl@0
|
142 |
RUpsSession iUpsSession;
|
sl@0
|
143 |
RUpsManagement iManagementSession;
|
sl@0
|
144 |
|
sl@0
|
145 |
TInt iResult;
|
sl@0
|
146 |
};
|
sl@0
|
147 |
|
sl@0
|
148 |
CTestSwiIf *CTestSwiIf::NewL()
|
sl@0
|
149 |
{
|
sl@0
|
150 |
CTestSwiIf *self = new(ELeave) CTestSwiIf;
|
sl@0
|
151 |
CleanupStack::PushL(self);
|
sl@0
|
152 |
self->ConstructL();
|
sl@0
|
153 |
CleanupStack::Pop(self);
|
sl@0
|
154 |
return self;
|
sl@0
|
155 |
}
|
sl@0
|
156 |
|
sl@0
|
157 |
CTestSwiIf::CTestSwiIf()
|
sl@0
|
158 |
: CActive(CActive::EPriorityStandard), iState(EPrePolicyChange)
|
sl@0
|
159 |
{
|
sl@0
|
160 |
CActiveScheduler::Add(this);
|
sl@0
|
161 |
}
|
sl@0
|
162 |
|
sl@0
|
163 |
_LIT(KCheckIfFailed, "z:\\private\\10283558\\policies\\ups_102836c3_0000002b_checkiffailed.rsc");
|
sl@0
|
164 |
_LIT(KResourceFileDirC, "c:\\private\\10283558\\policies\\");
|
sl@0
|
165 |
_LIT(KResourceFileOnC, "c:\\private\\10283558\\policies\\ups_102836c3_0000002b.rsc");
|
sl@0
|
166 |
|
sl@0
|
167 |
void CTestSwiIf::ConstructL()
|
sl@0
|
168 |
{
|
sl@0
|
169 |
User::LeaveIfError(iFs.Connect());
|
sl@0
|
170 |
|
sl@0
|
171 |
|
sl@0
|
172 |
User::LeaveIfError(iUpsSession.Connect());
|
sl@0
|
173 |
User::LeaveIfError(iManagementSession.Connect());
|
sl@0
|
174 |
|
sl@0
|
175 |
|
sl@0
|
176 |
TRequestStatus *rs = &iStatus;
|
sl@0
|
177 |
*rs = KRequestPending;
|
sl@0
|
178 |
User::RequestComplete(rs, KErrNone);
|
sl@0
|
179 |
SetActive();
|
sl@0
|
180 |
}
|
sl@0
|
181 |
|
sl@0
|
182 |
|
sl@0
|
183 |
CTestSwiIf::~CTestSwiIf()
|
sl@0
|
184 |
{
|
sl@0
|
185 |
Cancel();
|
sl@0
|
186 |
iManagementSession.Close();
|
sl@0
|
187 |
iUpsSession.Close();
|
sl@0
|
188 |
iFs.Close();
|
sl@0
|
189 |
}
|
sl@0
|
190 |
|
sl@0
|
191 |
TInt CTestSwiIf::Result()
|
sl@0
|
192 |
{
|
sl@0
|
193 |
return iResult;
|
sl@0
|
194 |
}
|
sl@0
|
195 |
|
sl@0
|
196 |
void CTestSwiIf::IncUsers()
|
sl@0
|
197 |
{
|
sl@0
|
198 |
++iUsers;
|
sl@0
|
199 |
}
|
sl@0
|
200 |
|
sl@0
|
201 |
void CTestSwiIf::DecUsers()
|
sl@0
|
202 |
{
|
sl@0
|
203 |
--iUsers;
|
sl@0
|
204 |
if((iUsers <= 0) &&
|
sl@0
|
205 |
((iState == ETestingComplete) || (iResult != KErrNone)))
|
sl@0
|
206 |
{
|
sl@0
|
207 |
CActiveScheduler::Stop();
|
sl@0
|
208 |
}
|
sl@0
|
209 |
}
|
sl@0
|
210 |
void CTestSwiIf::RunL()
|
sl@0
|
211 |
{
|
sl@0
|
212 |
User::LeaveIfError(iStatus.Int());
|
sl@0
|
213 |
switch(iState)
|
sl@0
|
214 |
{
|
sl@0
|
215 |
case EPrePolicyChange:
|
sl@0
|
216 |
{
|
sl@0
|
217 |
PopulateDatabaseL();
|
sl@0
|
218 |
|
sl@0
|
219 |
(void)CRequest::NewL(iUpsSession, *this, 8, EUpsDecYes);
|
sl@0
|
220 |
(void)CRequest::NewL(iUpsSession, *this, 4, EUpsDecYes);
|
sl@0
|
221 |
(void)CRequest::NewL(iUpsSession, *this, 5, EUpsDecNo);
|
sl@0
|
222 |
(void)CRequest::NewL(iUpsSession, *this, 2, EUpsDecYes);
|
sl@0
|
223 |
(void)CRequest::NewL(iUpsSession, *this, 7, EUpsDecNo);
|
sl@0
|
224 |
|
sl@0
|
225 |
(void)iFs.MkDirAll(KResourceFileDirC);
|
sl@0
|
226 |
|
sl@0
|
227 |
CFileMan *fileman = CFileMan::NewL(iFs);
|
sl@0
|
228 |
CleanupStack::PushL(fileman);
|
sl@0
|
229 |
TInt r = fileman->Copy(KCheckIfFailed, KResourceFileOnC);
|
sl@0
|
230 |
User::LeaveIfError(r);
|
sl@0
|
231 |
CleanupStack::PopAndDestroy(fileman);
|
sl@0
|
232 |
|
sl@0
|
233 |
TRequestStatus rs;
|
sl@0
|
234 |
iManagementSession.NotifyPolicyFilesChanged(rs);
|
sl@0
|
235 |
iManagementSession.CancelNotifyPolicyFilesChanged();
|
sl@0
|
236 |
User::WaitForRequest(rs);
|
sl@0
|
237 |
if(rs.Int() != KErrCancel) User::Leave(rs.Int());
|
sl@0
|
238 |
|
sl@0
|
239 |
iState = EPostPolicyChange;
|
sl@0
|
240 |
iManagementSession.NotifyPolicyFilesChanged(iStatus);
|
sl@0
|
241 |
SetActive();
|
sl@0
|
242 |
break;
|
sl@0
|
243 |
}
|
sl@0
|
244 |
case EPostPolicyChange:
|
sl@0
|
245 |
// Notify complete, do some more queries
|
sl@0
|
246 |
(void)CRequest::NewL(iUpsSession, *this, 2, EUpsDecYes);
|
sl@0
|
247 |
(void)CRequest::NewL(iUpsSession, *this, 8, EUpsDecYes);
|
sl@0
|
248 |
(void)CRequest::NewL(iUpsSession, *this, 5, EUpsDecYes);
|
sl@0
|
249 |
(void)CRequest::NewL(iUpsSession, *this, 4, EUpsDecYes);
|
sl@0
|
250 |
(void)CRequest::NewL(iUpsSession, *this, 3, EUpsDecYes);
|
sl@0
|
251 |
|
sl@0
|
252 |
// Revert change
|
sl@0
|
253 |
User::LeaveIfError(iFs.Delete(KResourceFileOnC));
|
sl@0
|
254 |
|
sl@0
|
255 |
iState = ERevertPolicyChange;
|
sl@0
|
256 |
iManagementSession.NotifyPolicyFilesChanged(iStatus);
|
sl@0
|
257 |
SetActive();
|
sl@0
|
258 |
break;
|
sl@0
|
259 |
|
sl@0
|
260 |
case ERevertPolicyChange:
|
sl@0
|
261 |
iState = ETestingComplete;
|
sl@0
|
262 |
if(iUsers <= 0)
|
sl@0
|
263 |
{
|
sl@0
|
264 |
CActiveScheduler::Stop();
|
sl@0
|
265 |
}
|
sl@0
|
266 |
break;
|
sl@0
|
267 |
|
sl@0
|
268 |
case ETestingComplete:
|
sl@0
|
269 |
break;
|
sl@0
|
270 |
}
|
sl@0
|
271 |
}
|
sl@0
|
272 |
|
sl@0
|
273 |
void CTestSwiIf::DoCancel()
|
sl@0
|
274 |
{
|
sl@0
|
275 |
switch(iState)
|
sl@0
|
276 |
{
|
sl@0
|
277 |
case EPrePolicyChange:
|
sl@0
|
278 |
{
|
sl@0
|
279 |
TRequestStatus *rs = &iStatus;
|
sl@0
|
280 |
if(*rs == KRequestPending)
|
sl@0
|
281 |
{
|
sl@0
|
282 |
User::RequestComplete(rs, KErrCancel);
|
sl@0
|
283 |
}
|
sl@0
|
284 |
break;
|
sl@0
|
285 |
}
|
sl@0
|
286 |
|
sl@0
|
287 |
case EPostPolicyChange:
|
sl@0
|
288 |
iManagementSession.CancelNotifyPolicyFilesChanged();
|
sl@0
|
289 |
break;
|
sl@0
|
290 |
|
sl@0
|
291 |
case ERevertPolicyChange:
|
sl@0
|
292 |
iManagementSession.CancelNotifyPolicyFilesChanged();
|
sl@0
|
293 |
break;
|
sl@0
|
294 |
|
sl@0
|
295 |
case ETestingComplete:
|
sl@0
|
296 |
break;
|
sl@0
|
297 |
default:
|
sl@0
|
298 |
ASSERT(0); // Unknown state
|
sl@0
|
299 |
}
|
sl@0
|
300 |
|
sl@0
|
301 |
}
|
sl@0
|
302 |
|
sl@0
|
303 |
TInt CTestSwiIf::RunError(TInt aError)
|
sl@0
|
304 |
{
|
sl@0
|
305 |
iResult = aError;
|
sl@0
|
306 |
if(iUsers <= 0)
|
sl@0
|
307 |
{
|
sl@0
|
308 |
CActiveScheduler::Stop();
|
sl@0
|
309 |
}
|
sl@0
|
310 |
return KErrNone;
|
sl@0
|
311 |
}
|
sl@0
|
312 |
|
sl@0
|
313 |
CRequest *CRequest::NewL(RUpsSession &aSession, CTestSwiIf &aParent, TInt aId, TUpsDecision aExpected)
|
sl@0
|
314 |
{
|
sl@0
|
315 |
CRequest *self = new(ELeave) CRequest(aParent, aExpected);
|
sl@0
|
316 |
CleanupStack::PushL(self);
|
sl@0
|
317 |
self->ConstructL(aSession, aId);
|
sl@0
|
318 |
CleanupStack::Pop(self);
|
sl@0
|
319 |
return self;
|
sl@0
|
320 |
}
|
sl@0
|
321 |
|
sl@0
|
322 |
CRequest::CRequest(CTestSwiIf &aParent, TUpsDecision aExpected)
|
sl@0
|
323 |
: CActive(CActive::EPriorityStandard-1),
|
sl@0
|
324 |
iParent(aParent),
|
sl@0
|
325 |
iExpected(aExpected)
|
sl@0
|
326 |
{
|
sl@0
|
327 |
CActiveScheduler::Add(this);
|
sl@0
|
328 |
iParent.IncUsers();
|
sl@0
|
329 |
}
|
sl@0
|
330 |
|
sl@0
|
331 |
void CRequest::ConstructL(RUpsSession &aSession, TInt aId)
|
sl@0
|
332 |
{
|
sl@0
|
333 |
RThread thd;
|
sl@0
|
334 |
User::LeaveIfError(iSubSession.Initialise(aSession, thd));
|
sl@0
|
335 |
TServiceId serviceId = {42};
|
sl@0
|
336 |
if( aId & 1) serviceId.iUid = 43;
|
sl@0
|
337 |
RBuf destination;
|
sl@0
|
338 |
destination.CreateL(100);
|
sl@0
|
339 |
CleanupClosePushL(destination);
|
sl@0
|
340 |
destination.AppendFormat(_L("destination %x"), aId);
|
sl@0
|
341 |
|
sl@0
|
342 |
iDec = EUpsDecNo;
|
sl@0
|
343 |
iSubSession.Authorise(EFalse, serviceId, destination, _L8("Opaque data"), iDec, iStatus);
|
sl@0
|
344 |
SetActive();
|
sl@0
|
345 |
|
sl@0
|
346 |
CleanupStack::PopAndDestroy(&destination);
|
sl@0
|
347 |
}
|
sl@0
|
348 |
|
sl@0
|
349 |
CRequest::~CRequest()
|
sl@0
|
350 |
{
|
sl@0
|
351 |
iSubSession.Close();
|
sl@0
|
352 |
iParent.DecUsers();
|
sl@0
|
353 |
}
|
sl@0
|
354 |
|
sl@0
|
355 |
void CRequest::RunL()
|
sl@0
|
356 |
{
|
sl@0
|
357 |
test((iStatus.Int() == KErrNone) || (iStatus.Int() == KErrNoMemory));
|
sl@0
|
358 |
if(iStatus.Int() == KErrNone)
|
sl@0
|
359 |
{
|
sl@0
|
360 |
// Some OOM situations appear to cause us to return NO.
|
sl@0
|
361 |
test((iDec == iExpected) || (iDec == EUpsDecNo));
|
sl@0
|
362 |
}
|
sl@0
|
363 |
delete this;
|
sl@0
|
364 |
}
|
sl@0
|
365 |
|
sl@0
|
366 |
void CRequest::DoCancel()
|
sl@0
|
367 |
{
|
sl@0
|
368 |
}
|
sl@0
|
369 |
|
sl@0
|
370 |
TInt CRequest::RunError(TInt aError)
|
sl@0
|
371 |
{
|
sl@0
|
372 |
User::Panic(_L("CRequest::RunError"), aError);
|
sl@0
|
373 |
/*lint -unreachable*/
|
sl@0
|
374 |
return KErrNone;
|
sl@0
|
375 |
}
|
sl@0
|
376 |
|
sl@0
|
377 |
|
sl@0
|
378 |
#endif
|
sl@0
|
379 |
void TestSwiObserverL()
|
sl@0
|
380 |
{
|
sl@0
|
381 |
RUpsManagement session;
|
sl@0
|
382 |
User::LeaveIfError(session.Connect());
|
sl@0
|
383 |
CleanupClosePushL(session);
|
sl@0
|
384 |
|
sl@0
|
385 |
session.NotifyPluginsMayHaveChangedL();
|
sl@0
|
386 |
|
sl@0
|
387 |
TRequestStatus rs;
|
sl@0
|
388 |
session.NotifyPolicyFilesChanged(rs);
|
sl@0
|
389 |
User::WaitForRequest(rs);
|
sl@0
|
390 |
|
sl@0
|
391 |
test((rs.Int() == KErrNone) || (rs.Int() == KErrNoMemory));
|
sl@0
|
392 |
if(rs.Int() == KErrNone)
|
sl@0
|
393 |
{
|
sl@0
|
394 |
session.CancelNotifyPolicyFilesChanged();
|
sl@0
|
395 |
}
|
sl@0
|
396 |
|
sl@0
|
397 |
TSecureId ourSid(0x10283559);
|
sl@0
|
398 |
session.DeleteDecisionsForExeL(ourSid);
|
sl@0
|
399 |
|
sl@0
|
400 |
|
sl@0
|
401 |
CleanupStack::PopAndDestroy(&session);
|
sl@0
|
402 |
}
|
sl@0
|
403 |
|
sl@0
|
404 |
|
sl@0
|
405 |
// -------- entrypoint --------
|
sl@0
|
406 |
void MainL()
|
sl@0
|
407 |
{
|
sl@0
|
408 |
// We need to increase the priority of the thread running the test code to make sure
|
sl@0
|
409 |
// that asynchronous ups management calls, for example CreateView() , won't finish
|
sl@0
|
410 |
// before following synchronous cancellation or termination calls, for example:
|
sl@0
|
411 |
// DeleteDatabaseL() or CancelAndCloseView().
|
sl@0
|
412 |
RThread thread;
|
sl@0
|
413 |
TThreadPriority currentPri = thread.Priority();
|
sl@0
|
414 |
currentPri = (TThreadPriority)((TInt)currentPri+10);
|
sl@0
|
415 |
thread.SetPriority(currentPri);
|
sl@0
|
416 |
|
sl@0
|
417 |
CActiveScheduler *scheduler = new(ELeave) CActiveScheduler;
|
sl@0
|
418 |
CActiveScheduler::Install(scheduler);
|
sl@0
|
419 |
CleanupStack::PushL(scheduler);
|
sl@0
|
420 |
|
sl@0
|
421 |
test.Title(_L("c:\\upstestobsifoom.log"));
|
sl@0
|
422 |
test.Start(_L(" @SYMTestCaseID:SEC-UPS-OBSIF_OOM-0001 Testing RUpsSession SWI observer IF "));
|
sl@0
|
423 |
|
sl@0
|
424 |
RFs fs;
|
sl@0
|
425 |
User::LeaveIfError(fs.Connect());
|
sl@0
|
426 |
CleanupClosePushL(fs);
|
sl@0
|
427 |
|
sl@0
|
428 |
User::LeaveIfError(sMngmntSession.Connect());
|
sl@0
|
429 |
sMngmntSession.ShutdownServer();
|
sl@0
|
430 |
sMngmntSession.Close();
|
sl@0
|
431 |
|
sl@0
|
432 |
TBuf<21> notifierConfig(_L("!:\\upsrefnotifier.txt"));
|
sl@0
|
433 |
notifierConfig[0] = fs.GetSystemDriveChar();
|
sl@0
|
434 |
|
sl@0
|
435 |
TInt lineLength = User::CommandLineLength();
|
sl@0
|
436 |
switch(lineLength)
|
sl@0
|
437 |
{
|
sl@0
|
438 |
default:
|
sl@0
|
439 |
// fall through - extra command line arguments are ignored
|
sl@0
|
440 |
case 2:
|
sl@0
|
441 |
// 2 char arg - Delete DB and run interactive
|
sl@0
|
442 |
(void) fs.Delete(_L("c:\\Private\\10283558\\database\\ups.db"));
|
sl@0
|
443 |
// Fall through to also delete notifier config file
|
sl@0
|
444 |
case 1:
|
sl@0
|
445 |
// 1 char arg - Run interactive, without deleting DB
|
sl@0
|
446 |
(void) fs.Delete(notifierConfig);
|
sl@0
|
447 |
break;
|
sl@0
|
448 |
case 0:
|
sl@0
|
449 |
{
|
sl@0
|
450 |
// No args - delete DB and run in silent mode
|
sl@0
|
451 |
(void) fs.Delete(_L("c:\\Private\\10283558\\database\\ups.db"));
|
sl@0
|
452 |
|
sl@0
|
453 |
(void) fs.Delete(notifierConfig);
|
sl@0
|
454 |
RFile file;
|
sl@0
|
455 |
User::LeaveIfError(file.Create(fs, notifierConfig, EFileShareExclusive | EFileWrite));
|
sl@0
|
456 |
User::LeaveIfError(file.Write(_L8("Always")));
|
sl@0
|
457 |
file.Close();
|
sl@0
|
458 |
break;
|
sl@0
|
459 |
}
|
sl@0
|
460 |
}
|
sl@0
|
461 |
|
sl@0
|
462 |
User::LeaveIfError(sMngmntSession.Connect());
|
sl@0
|
463 |
CleanupClosePushL(sMngmntSession);
|
sl@0
|
464 |
|
sl@0
|
465 |
|
sl@0
|
466 |
TInt err = KErrNone;
|
sl@0
|
467 |
TInt errTmp = KErrNone;
|
sl@0
|
468 |
TInt run = 0;
|
sl@0
|
469 |
TInt passingRuns = 0;
|
sl@0
|
470 |
static const TInt maxRun = 1000;
|
sl@0
|
471 |
static const TInt passThreshold = 5;
|
sl@0
|
472 |
|
sl@0
|
473 |
for(run=1; run<=maxRun; ++run)
|
sl@0
|
474 |
{
|
sl@0
|
475 |
test.Printf(_L("\n\nOBSIF OOM -- Run %d\n"), run);
|
sl@0
|
476 |
|
sl@0
|
477 |
// Make sure the C: policy is deleted.
|
sl@0
|
478 |
(void)fs.Delete(KResourceFileOnC);
|
sl@0
|
479 |
|
sl@0
|
480 |
// Make sure server is not holding cached values for the C: policy
|
sl@0
|
481 |
// We could stop/restart the server, but that is very slow...
|
sl@0
|
482 |
TRequestStatus rs;
|
sl@0
|
483 |
sMngmntSession.NotifyPolicyFilesChanged(rs);
|
sl@0
|
484 |
User::WaitForRequest(rs);
|
sl@0
|
485 |
|
sl@0
|
486 |
err = sMngmntSession.SetServerHeapFail(run);
|
sl@0
|
487 |
if(err == KErrNoMemory)
|
sl@0
|
488 |
{
|
sl@0
|
489 |
// Reinitialisation failed
|
sl@0
|
490 |
test.Printf(_L("\tReinitialisation failed\n"));
|
sl@0
|
491 |
sMngmntSession.ResetServerHeapFail();
|
sl@0
|
492 |
continue;
|
sl@0
|
493 |
}
|
sl@0
|
494 |
if(err != KErrNone)
|
sl@0
|
495 |
{
|
sl@0
|
496 |
// Failed to set heap fail, maybe the previous loop crashed the server??
|
sl@0
|
497 |
test.Printf(_L("Failed to set heap fail with error code %d"), err);
|
sl@0
|
498 |
test(EFalse);
|
sl@0
|
499 |
break;
|
sl@0
|
500 |
}
|
sl@0
|
501 |
|
sl@0
|
502 |
// Run the test
|
sl@0
|
503 |
#if 1
|
sl@0
|
504 |
CTestSwiIf *t = 0;
|
sl@0
|
505 |
TRAP(err, t = CTestSwiIf::NewL());
|
sl@0
|
506 |
if(err == KErrNone)
|
sl@0
|
507 |
{
|
sl@0
|
508 |
CActiveScheduler::Start();
|
sl@0
|
509 |
err = t->Result();
|
sl@0
|
510 |
delete t;
|
sl@0
|
511 |
}
|
sl@0
|
512 |
#else
|
sl@0
|
513 |
err = KErrNone;
|
sl@0
|
514 |
#endif
|
sl@0
|
515 |
|
sl@0
|
516 |
#if 1
|
sl@0
|
517 |
if(err == KErrNone)
|
sl@0
|
518 |
{
|
sl@0
|
519 |
TRAP(err, TestSwiObserverL());
|
sl@0
|
520 |
}
|
sl@0
|
521 |
#endif
|
sl@0
|
522 |
|
sl@0
|
523 |
// Clear the heap fail
|
sl@0
|
524 |
test.Printf(_L("Reseting heap failure\n"));
|
sl@0
|
525 |
errTmp = sMngmntSession.ResetServerHeapFail();
|
sl@0
|
526 |
if((err == KErrServerTerminated) || (errTmp == KErrServerTerminated))
|
sl@0
|
527 |
{
|
sl@0
|
528 |
test.Printf(_L("\tUPS server died"));
|
sl@0
|
529 |
test(EFalse);
|
sl@0
|
530 |
break;
|
sl@0
|
531 |
}
|
sl@0
|
532 |
if((err == KErrNone) && (errTmp != KErrNone))
|
sl@0
|
533 |
{
|
sl@0
|
534 |
err = errTmp;
|
sl@0
|
535 |
}
|
sl@0
|
536 |
|
sl@0
|
537 |
// Did it work?
|
sl@0
|
538 |
if(err == KErrNone)
|
sl@0
|
539 |
{
|
sl@0
|
540 |
++passingRuns;
|
sl@0
|
541 |
}
|
sl@0
|
542 |
else
|
sl@0
|
543 |
{
|
sl@0
|
544 |
passingRuns = 0;
|
sl@0
|
545 |
}
|
sl@0
|
546 |
|
sl@0
|
547 |
if(passingRuns > passThreshold) break;
|
sl@0
|
548 |
} // End of OOM loop
|
sl@0
|
549 |
|
sl@0
|
550 |
if(run > maxRun)
|
sl@0
|
551 |
{
|
sl@0
|
552 |
User::Leave(err);
|
sl@0
|
553 |
}
|
sl@0
|
554 |
|
sl@0
|
555 |
sMngmntSession.ShutdownServer();
|
sl@0
|
556 |
|
sl@0
|
557 |
// Close top level session (low level session was closed by
|
sl@0
|
558 |
// ShutdownServer, but we still need to do the RUpsManagement
|
sl@0
|
559 |
// cleanup).
|
sl@0
|
560 |
CleanupStack::PopAndDestroy(&sMngmntSession);
|
sl@0
|
561 |
|
sl@0
|
562 |
(void) fs.Delete(notifierConfig);
|
sl@0
|
563 |
CleanupStack::PopAndDestroy(&fs);
|
sl@0
|
564 |
|
sl@0
|
565 |
test.End();
|
sl@0
|
566 |
test.Close();
|
sl@0
|
567 |
|
sl@0
|
568 |
CleanupStack::PopAndDestroy(scheduler);
|
sl@0
|
569 |
}
|
sl@0
|
570 |
|
sl@0
|
571 |
void PanicIfError(TInt r)
|
sl@0
|
572 |
{
|
sl@0
|
573 |
if(r != KErrNone)
|
sl@0
|
574 |
{
|
sl@0
|
575 |
User::Panic(_L("upstest failed: "), r);
|
sl@0
|
576 |
}
|
sl@0
|
577 |
}
|
sl@0
|
578 |
|
sl@0
|
579 |
|
sl@0
|
580 |
TInt E32Main()
|
sl@0
|
581 |
/**
|
sl@0
|
582 |
Executable entrypoint establishes connection with UPS server
|
sl@0
|
583 |
and then invokes tests for each functional area.
|
sl@0
|
584 |
|
sl@0
|
585 |
@return Symbian OS error code where KErrNone indicates
|
sl@0
|
586 |
success and any other value indicates failure.
|
sl@0
|
587 |
*/
|
sl@0
|
588 |
{
|
sl@0
|
589 |
// disable lazy DLL unloading so kernel heap balances at end
|
sl@0
|
590 |
RLoader l;
|
sl@0
|
591 |
PanicIfError(l.Connect());
|
sl@0
|
592 |
PanicIfError(l.CancelLazyDllUnload());
|
sl@0
|
593 |
l.Close();
|
sl@0
|
594 |
|
sl@0
|
595 |
__UHEAP_MARK;
|
sl@0
|
596 |
//__KHEAP_MARK;
|
sl@0
|
597 |
|
sl@0
|
598 |
// allocating a cleanup stack also installs it
|
sl@0
|
599 |
CTrapCleanup* tc = CTrapCleanup::New();
|
sl@0
|
600 |
if (tc == 0)
|
sl@0
|
601 |
return KErrNoMemory;
|
sl@0
|
602 |
|
sl@0
|
603 |
|
sl@0
|
604 |
TRAPD(err, MainL());
|
sl@0
|
605 |
if(err != KErrNone)
|
sl@0
|
606 |
{
|
sl@0
|
607 |
User::Panic(_L("upstest failed: "), err);
|
sl@0
|
608 |
}
|
sl@0
|
609 |
delete tc;
|
sl@0
|
610 |
|
sl@0
|
611 |
//__KHEAP_MARKEND;
|
sl@0
|
612 |
__UHEAP_MARKEND;
|
sl@0
|
613 |
|
sl@0
|
614 |
|
sl@0
|
615 |
return KErrNone;
|
sl@0
|
616 |
}
|
sl@0
|
617 |
|