Update contrib.
2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * Test program exercises the skeleton UPS server API.
16 * See individual test functions for more information.
26 #include <e32ldr_private.h>
27 #include "rtestwrapper.h"
29 #include <ups/upsclient.h>
30 #include <ups/upserr.h>
33 using namespace UserPromptService;
35 /** Top-level test object renders stages and confirms conditions. */
36 static RTestWrapper test(_L("UPSTEST"));
39 This session handle is defined at the file level so each individual test
40 does not have to connect to the server.
42 static RUpsSession sTestSession;
44 This subsession handle is defined at the file level so each individual test
45 does not have to connect to the server and create a subssesion.
47 static RUpsSubsession sTestSubsession;
49 // -------- open / close session --------
51 static void TestOpenCloseSession()
53 Open and close a connection to the UPS server.
56 test.Start(_L("TestOpenCloseSession"));
70 // -------- open / close subsession --------
72 static void TestOpenCloseSubsession()
74 Open and close a subsession on the UPS server.
77 test.Start(_L("TestOpenCloseSubsession"));
81 TInt r = ss.Initialise(sTestSession, thd);
88 // -------- Authorise succeed, cancel --------
89 _LIT8(KOpaqueData, "<ce>fred</ce>");
90 static void TestAuthoriseL()
92 Launch an asynchronous Authorise request on a UPS subsession.
93 Let it complete normally, and also cancel it.
96 test.Start(_L("TestAuthorise"));
98 TServiceId serviceId = {43};
102 test.Next(_L("complete normally - no opaque data\n"));
103 TUpsDecision dec = EUpsDecYes;
104 sTestSubsession.Authorise(EFalse, serviceId, KNullDesC, dec, rs);
105 test(dec == EUpsDecYes); // not changed yet
106 User::WaitForRequest(rs);
107 test(rs == KErrNone);
108 test(dec == EUpsDecNo);
110 test.Next(_L("cancel - empty opaque data\n"));
111 dec = EUpsDecYes; // ensure changed
112 sTestSubsession.Authorise(EFalse, serviceId, KNullDesC, KNullDesC8, dec, rs);
113 test(dec == EUpsDecYes); // not changed yet
114 test.Printf(_L("About to cancel - current status is %d"), rs.Int());
115 sTestSubsession.CancelPrompt();
116 User::WaitForRequest(rs);
117 test(rs == KErrCancel);
118 test(dec == EUpsDecYes); // not changed
120 test.Next(_L("Opaque data\n"));
121 dec = EUpsDecYes; // ensure changed
122 sTestSubsession.Authorise(EFalse, serviceId, _L("opaque data test"), KOpaqueData, dec, rs);
123 test(dec == EUpsDecYes); // not changed yet
124 User::WaitForRequest(rs);
125 test(rs == KErrNone);
126 test(dec == EUpsDecNo);
129 test.Next(_L("cancel when no outstanding - harmless\n"));
130 sTestSubsession.CancelPrompt();
132 test.Next(_L("cancel/close when sub session never created - harmless\n"));
133 RUpsSubsession uninitialisedCancel;
134 uninitialisedCancel.CancelPrompt();
135 uninitialisedCancel.Close();
140 static void TestFlurryL()
142 Launch multiple requests
145 test.Start(_L("TestFlurry"));
148 RUpsSubsession testSubsession1;
149 testSubsession1.Initialise(sTestSession, thd);
150 RUpsSubsession testSubsession2;
151 testSubsession2.Initialise(sTestSession, thd);
152 RUpsSubsession testSubsession3;
153 testSubsession3.Initialise(sTestSession, thd);
154 RUpsSubsession testSubsession4;
155 testSubsession4.Initialise(sTestSession, thd);
156 RUpsSubsession testSubsession5;
157 testSubsession5.Initialise(sTestSession, thd);
158 RUpsSubsession testSubsession6;
159 testSubsession6.Initialise(sTestSession, thd);
161 TServiceId serviceId = {43};
169 // complete normally - no opaque data
170 TUpsDecision dec1 = EUpsDecYes;
171 TUpsDecision dec2 = EUpsDecYes;
172 TUpsDecision dec3 = EUpsDecYes;
173 TUpsDecision dec4 = EUpsDecYes;
174 TUpsDecision dec5 = EUpsDecYes;
175 TUpsDecision dec6 = EUpsDecYes;
176 testSubsession1.Authorise(EFalse, serviceId, _L("req1"), dec1, rs1);
177 testSubsession2.Authorise(EFalse, serviceId, _L("reqX"), dec2, rs2);
178 testSubsession3.Authorise(EFalse, serviceId, _L("req2"), dec3, rs3);
179 testSubsession4.Authorise(EFalse, serviceId, _L("reqX"), dec4, rs4);
180 testSubsession5.Authorise(EFalse, serviceId, _L("req3"), dec5, rs5);
181 testSubsession6.Authorise(EFalse, serviceId, _L("req4"), dec6, rs6);
183 // Will change immediately in non-interactive testing
184 test(dec1 == EUpsDecYes); // not changed yet
185 test(dec2 == EUpsDecYes); // not changed yet
186 test(dec3 == EUpsDecYes); // not changed yet
187 test(dec4 == EUpsDecYes); // not changed yet
188 test(dec5 == EUpsDecYes); // not changed yet
189 test(dec6 == EUpsDecYes); // not changed yet
193 User::WaitForRequest(rs1);
195 User::WaitForRequest(rs2);
196 User::WaitForRequest(rs4);
198 User::WaitForRequest(rs3);
199 User::WaitForRequest(rs5);
200 User::WaitForRequest(rs6);
201 test(rs1 == KErrNone);
202 test(rs2 == KErrNone);
203 test(rs3 == KErrNone);
204 test(rs4 == KErrNone);
205 test(rs5 == KErrNone);
206 test(rs6 == KErrNone);
207 test(dec1 == EUpsDecNo);
208 test(dec2 == EUpsDecNo);
209 test(dec3 == EUpsDecNo);
210 test(dec4 == EUpsDecNo);
211 test(dec5 == EUpsDecNo);
212 test(dec6 == EUpsDecNo);
217 // -------- RUpsSubsession --------
218 _LIT(KSayYes,"SayYes");
219 static void TestRUpsSubsession()
221 Attempt query with server checks passed and without
225 // Tests for RUpsSubsession
229 test.Start(_L("Testing RUpsSubsession"));
230 RUpsSubsession clientSubsession;
231 TInt r = clientSubsession.Initialise(sTestSession, thd);
234 test.Next(_L("Query with server checks passed"));
235 TServiceId serviceId = {42};
236 TUpsDecision dec = EUpsDecNo;
238 // Query saying our checks were ok, expect to get decision set to EUpsDecYes
239 clientSubsession.Authorise(ETrue, serviceId, _L("Destination"), _L8("Opaque data"), dec, rs);
240 User::WaitForRequest(rs);
241 test(rs == KErrNone);
242 test(dec == EUpsDecYes);
246 test.Next(_L("Try closing client subsession before it is really created"));
247 clientSubsession.Close();
249 test.Next(_L("Re-\"create\" client subsession"));
250 r = clientSubsession.Initialise(sTestSession, thd);
253 test.Next(_L("Query with server checks failed, ie query UPS, expect fail"));
254 // Query saying our checks failed, should talk to UPS and change decision to EUpsDecNo
256 clientSubsession.Authorise(EFalse, serviceId, KNullDesC, dec, rs);
257 User::WaitForRequest(rs);
258 test(rs == KErrNone);
259 test(dec == EUpsDecNo);
262 test.Next(_L("Query with server checks failed, ie query UPS, special destination, expect yes"));
263 // Query saying our checks failed, should talk to UPS and change decision to EUpsDecNo
265 clientSubsession.Authorise(EFalse, serviceId, KSayYes(), dec, rs);
266 User::WaitForRequest(rs);
267 test(rs == KErrNone);
268 test(dec == EUpsDecYes);
271 clientSubsession.Close();
275 TInt ThreadFunction(TAny *)
280 static void TestRUpsSubsessionDeathL()
283 TRequestStatus thdStatus;
284 User::LeaveIfError(thd.Create(_L("MyThread"), ThreadFunction, 4096, 4096, 4096, 0, EOwnerThread));
285 // thd.SetHandle(666);
286 thd.Rendezvous(thdStatus);
288 User::WaitForRequest(thdStatus);
290 test.Start(_L("Testing RUpsSubsession"));
291 RUpsSubsession clientSubsession;
292 TInt r = clientSubsession.Initialise(sTestSession, thd);
295 test.Next(_L("Query with dead thread id"));
296 TServiceId serviceId = {43};
297 TUpsDecision dec = EUpsDecYes;
300 clientSubsession.Authorise(EFalse, serviceId, _L("req1"), dec, rs);
301 User::WaitForRequest(rs);
302 test(rs == KErrNone);
303 test(dec == EUpsDecNo);
306 clientSubsession.Close();
310 static void TestRUpsManagementL()
312 Attempt to delete database
315 test.Start(_L("Testing RUpsManagement"));
320 TServiceId serviceId = {43};
321 CDecisionFilter *filter = CDecisionFilter::NewLC();
322 filter->SetClientSid(thd.SecureId(), EEqual);
323 filter->SetServerSid(thd.SecureId(), EEqual);
324 filter->SetServiceId(serviceId, EEqual);
326 RUpsSubsession clientSubsession;
327 TInt r = clientSubsession.Initialise(sTestSession, thd);
330 test.Next(_L("Open management session"));
331 RUpsManagement mngmnt;
332 r = mngmnt.Connect();
334 User::LeaveIfError(r);
336 test.Next(_L("View create - then delete DB"));
337 mngmnt.CreateView(*filter, rs);
339 test.Next(_L("Delete database"));
340 TRAP(r, mngmnt.DeleteDatabaseL());
343 test.Next(_L("Now see what view create completed with...."));
344 User::WaitForRequest(rs);
345 test(rs.Int() == KErrAbort);
347 test.Next(_L("Add entry to new database"));
348 TUpsDecision dec = EUpsDecYes;
349 clientSubsession.Authorise(EFalse, serviceId, _L("DB delete 1"), _L8("Opaque data"), dec, rs);
350 User::WaitForRequest(rs);
351 test(rs == KErrNone);
352 test(dec == EUpsDecNo);
355 clientSubsession.Authorise(EFalse, serviceId, _L("DB delete 2"), _L8("Opaque data"), dec, rs);
356 User::WaitForRequest(rs);
357 test(rs == KErrNone);
358 test(dec == EUpsDecNo);
361 test.Next(_L("View create - immediate cancel"));
362 mngmnt.CreateView(*filter, rs);
363 mngmnt.CancelAndCloseView();
364 User::WaitForRequest(rs);
365 test(rs.Int() == KErrCancel);
367 mngmnt.UpdateDecision(TUint32(-23), ETrue, rs);
368 mngmnt.CancelUpdateDecision();
369 User::WaitForRequest(rs);
370 test(rs.Int() == KErrCancel);
372 mngmnt.UpdateDecision(TUint32(-23), ETrue, rs);
373 User::WaitForRequest(rs);
374 test(rs.Int() == KErrNotFound);
376 test.Next(_L("View create - when busy"));
378 mngmnt.CreateView(*filter, rs);
379 mngmnt.CreateView(*filter, rs2);
380 User::WaitForRequest(rs2);
381 test(rs2.Int() == KErrServerBusy);
382 User::WaitForRequest(rs);
383 test(rs.Int() == KErrNone);
384 mngmnt.CancelAndCloseView();
386 test.Next(_L("View create - iterate through it"));
387 mngmnt.CreateView(*filter, rs);
389 User::WaitForRequest(rs);
390 test(rs.Int() == KErrNone);
392 CleanupStack::PopAndDestroy(filter);
394 CDecisionRecord *record = 0;
396 TInt recordCount = 0;
399 TRAP(r, record = mngmnt.NextMatchL());
408 CleanupStack::PushL(record);
409 CDecisionFilter *exactFilter = CDecisionFilter::NewLC(record->iClientSid,
410 record->iEvaluatorId,
413 record->iFingerprint,
414 record->iClientEntity,
415 record->iMajorPolicyVersion);
418 mngmnt.UpdateDecision(record->iRecordId, ETrue, rs);
419 User::WaitForRequest(rs);
420 test(rs.Int() == KErrNone);
421 TRAP(r, mngmnt.RemoveDecisionsL(*exactFilter));
424 CleanupStack::PopAndDestroy(exactFilter);
425 CleanupStack::PopAndDestroy(record);
429 test(recordCount == 2);
431 TRAP(r, record = mngmnt.NextMatchL());
432 test((r == KErrNone) && (record == 0));
434 mngmnt.CancelAndCloseView();
436 test.Next(_L("Close management session and clientSubsession"));
438 clientSubsession.Close();
443 void TestSwiObserverSecurityL()
445 test.Start(_L("Testing swi observer functions do not work from here..."));
449 RUpsManagement session;
450 User::LeaveIfError(session.Connect());
451 CleanupClosePushL(session);
454 ourSid.iUid = 0x10283559;
455 TRAP(r, session.DeleteDecisionsForExeL(ourSid));
456 test(r == KErrPermissionDenied);
458 TRAP(r, session.NotifyPluginsMayHaveChangedL());
459 test(r == KErrPermissionDenied);
462 session.NotifyPolicyFilesChanged(rs);
463 User::WaitForRequest(rs);
465 test(rs.Int() == KErrPermissionDenied);
467 session.CancelNotifyPolicyFilesChanged();
469 CleanupStack::PopAndDestroy(&session);
474 // -------- entrypoint --------
479 test.Title(_L("c:\\upstest.log"));
480 test.Start(_L(" @SYMTestCaseID:SEC-UPS-0001 Testing RUpsSubsession "));
483 User::LeaveIfError(fs.Connect());
484 CleanupClosePushL(fs);
486 TBuf<21> notifierConfig(_L("!:\\upsrefnotifier.txt"));
487 notifierConfig[0] = fs.GetSystemDriveChar();
489 TBuf<35> database(_L("!:\\Private\\10283558\\database\\ups.db"));
490 database[0] = fs.GetSystemDriveChar();
492 TInt lineLength = User::CommandLineLength();
497 (void) fs.Delete(database);
498 // Fall through to also delete notifier config file
500 (void) fs.Delete(notifierConfig);
504 // No args so run in silent mode
505 (void) fs.Delete(database);
506 (void) fs.Delete(notifierConfig);
508 User::LeaveIfError(file.Create(fs, notifierConfig, EFileShareExclusive | EFileWrite));
509 User::LeaveIfError(file.Write(_L8("Never")));
516 //ourThread.SetPriority(EPriorityMore);
518 // User::SetProcessCritical(User::ESystemCritical);
519 // User::SetCritical(User::ESystemCritical);
520 TestOpenCloseSession();
523 TInt r = sTestSession.Connect();
525 User::LeaveIfError(r);
527 TestRUpsSubsessionDeathL();
529 TestOpenCloseSubsession();
531 TestSwiObserverSecurityL();
534 r = sTestSubsession.Initialise(sTestSession, thd);
536 User::LeaveIfError(r);
542 sTestSubsession.Close();
544 TestRUpsSubsession();
546 TestRUpsManagementL();
548 sTestSession.ShutdownServer();
550 // Close top level session (low level session was closed by
551 // ShutdownServer, but we still need to do the RUpsSession
553 sTestSession.Close();
555 (void) fs.Delete(notifierConfig);
556 CleanupStack::PopAndDestroy(&fs);
562 void PanicIfError(TInt r)
566 User::Panic(_L("upstest failed: "), r);
573 Executable entrypoint establishes connection with UPS server
574 and then invokes tests for each functional area.
576 @return Symbian OS error code where KErrNone indicates
577 success and any other value indicates failure.
580 // disable lazy DLL unloading so kernel heap balances at end
582 PanicIfError(l.Connect());
583 PanicIfError(l.CancelLazyDllUnload());
589 // allocating a cleanup stack also installs it
590 CTrapCleanup* tc = CTrapCleanup::New();
597 User::Panic(_L("upstest failed: "), err);