os/security/authorisation/userpromptservice/server/test/upstest/upstest.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
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 skeleton UPS server 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 <ups/upserr.h>
sl@0
    31
#include "f32file.h"
sl@0
    32
sl@0
    33
using namespace UserPromptService;
sl@0
    34
sl@0
    35
/** Top-level test object renders stages and confirms conditions. */
sl@0
    36
static RTestWrapper test(_L("UPSTEST"));
sl@0
    37
sl@0
    38
/**
sl@0
    39
	This session handle is defined at the file level so each individual test
sl@0
    40
	does not have to connect to the server.
sl@0
    41
 */
sl@0
    42
static RUpsSession sTestSession;
sl@0
    43
/**
sl@0
    44
	This subsession handle is defined at the file level so each individual test
sl@0
    45
	does not have to connect to the server and create a subssesion.
sl@0
    46
 */
sl@0
    47
static RUpsSubsession sTestSubsession;
sl@0
    48
sl@0
    49
// -------- open / close session --------
sl@0
    50
sl@0
    51
static void TestOpenCloseSession()
sl@0
    52
/**
sl@0
    53
	Open and close a connection to the UPS server.
sl@0
    54
 */
sl@0
    55
	{
sl@0
    56
	test.Start(_L("TestOpenCloseSession"));
sl@0
    57
	
sl@0
    58
	RUpsSession s;
sl@0
    59
	TInt r = s.Connect();
sl@0
    60
	test(r == KErrNone);
sl@0
    61
sl@0
    62
	r = s.ShareAuto();
sl@0
    63
	test(r == KErrNone);
sl@0
    64
	
sl@0
    65
	s.Close();
sl@0
    66
	
sl@0
    67
	test.End();
sl@0
    68
	}
sl@0
    69
sl@0
    70
// -------- open / close subsession --------
sl@0
    71
sl@0
    72
static void TestOpenCloseSubsession()
sl@0
    73
/**
sl@0
    74
	Open and close a subsession on the UPS server.
sl@0
    75
 */
sl@0
    76
	{
sl@0
    77
	test.Start(_L("TestOpenCloseSubsession"));
sl@0
    78
	
sl@0
    79
	RUpsSubsession ss;
sl@0
    80
	RThread thd;
sl@0
    81
	TInt r = ss.Initialise(sTestSession, thd);
sl@0
    82
	test(r == KErrNone);
sl@0
    83
	ss.Close();
sl@0
    84
	
sl@0
    85
	test.End();
sl@0
    86
	}
sl@0
    87
sl@0
    88
// -------- Authorise succeed, cancel --------
sl@0
    89
_LIT8(KOpaqueData, "<ce>fred</ce>");
sl@0
    90
static void TestAuthoriseL()
sl@0
    91
/**
sl@0
    92
	Launch an asynchronous Authorise request on a UPS subsession.
sl@0
    93
	Let it complete normally, and also cancel it.
sl@0
    94
 */
sl@0
    95
	{
sl@0
    96
	test.Start(_L("TestAuthorise"));
sl@0
    97
	
sl@0
    98
	TServiceId serviceId = {43};
sl@0
    99
	TRequestStatus rs;
sl@0
   100
sl@0
   101
	
sl@0
   102
	test.Next(_L("complete normally - no opaque data\n"));
sl@0
   103
	TUpsDecision dec = EUpsDecYes;
sl@0
   104
	sTestSubsession.Authorise(EFalse, serviceId, KNullDesC, dec, rs);
sl@0
   105
	test(dec == EUpsDecYes);	// not changed yet
sl@0
   106
	User::WaitForRequest(rs);
sl@0
   107
	test(rs == KErrNone);
sl@0
   108
	test(dec == EUpsDecNo);
sl@0
   109
	
sl@0
   110
	test.Next(_L("cancel - empty opaque data\n"));
sl@0
   111
	dec = EUpsDecYes;	// ensure changed
sl@0
   112
	sTestSubsession.Authorise(EFalse, serviceId, KNullDesC, KNullDesC8, dec, rs);
sl@0
   113
	test(dec == EUpsDecYes);	// not changed yet
sl@0
   114
	test.Printf(_L("About to cancel - current status is %d"), rs.Int());
sl@0
   115
	sTestSubsession.CancelPrompt();
sl@0
   116
	User::WaitForRequest(rs);
sl@0
   117
	test(rs == KErrCancel);
sl@0
   118
	test(dec == EUpsDecYes);	// not changed
sl@0
   119
sl@0
   120
	test.Next(_L("Opaque data\n"));
sl@0
   121
	dec = EUpsDecYes;	// ensure changed
sl@0
   122
	sTestSubsession.Authorise(EFalse, serviceId, _L("opaque data test"), KOpaqueData, dec, rs);
sl@0
   123
	test(dec == EUpsDecYes);	// not changed yet
sl@0
   124
	User::WaitForRequest(rs);
sl@0
   125
	test(rs == KErrNone);
sl@0
   126
	test(dec == EUpsDecNo);
sl@0
   127
sl@0
   128
	
sl@0
   129
	test.Next(_L("cancel when no outstanding - harmless\n"));
sl@0
   130
	sTestSubsession.CancelPrompt();
sl@0
   131
sl@0
   132
	test.Next(_L("cancel/close when sub session never created - harmless\n"));
sl@0
   133
	RUpsSubsession uninitialisedCancel;
sl@0
   134
	uninitialisedCancel.CancelPrompt();
sl@0
   135
	uninitialisedCancel.Close();
sl@0
   136
	
sl@0
   137
	test.End();
sl@0
   138
	}
sl@0
   139
sl@0
   140
static void TestFlurryL()
sl@0
   141
/**
sl@0
   142
	Launch multiple requests
sl@0
   143
 */
sl@0
   144
	{
sl@0
   145
	test.Start(_L("TestFlurry"));
sl@0
   146
sl@0
   147
	RThread thd;
sl@0
   148
	RUpsSubsession testSubsession1;
sl@0
   149
	testSubsession1.Initialise(sTestSession, thd);
sl@0
   150
	RUpsSubsession testSubsession2;
sl@0
   151
	testSubsession2.Initialise(sTestSession, thd);
sl@0
   152
	RUpsSubsession testSubsession3;
sl@0
   153
	testSubsession3.Initialise(sTestSession, thd);
sl@0
   154
	RUpsSubsession testSubsession4;
sl@0
   155
	testSubsession4.Initialise(sTestSession, thd);
sl@0
   156
	RUpsSubsession testSubsession5;
sl@0
   157
	testSubsession5.Initialise(sTestSession, thd);
sl@0
   158
	RUpsSubsession testSubsession6;
sl@0
   159
	testSubsession6.Initialise(sTestSession, thd);
sl@0
   160
	
sl@0
   161
	TServiceId serviceId = {43};
sl@0
   162
	TRequestStatus rs1;
sl@0
   163
	TRequestStatus rs2;
sl@0
   164
	TRequestStatus rs3;
sl@0
   165
	TRequestStatus rs4;
sl@0
   166
	TRequestStatus rs5;
sl@0
   167
	TRequestStatus rs6;
sl@0
   168
	
sl@0
   169
	// complete normally - no opaque data
sl@0
   170
	TUpsDecision dec1 = EUpsDecYes;
sl@0
   171
	TUpsDecision dec2 = EUpsDecYes;
sl@0
   172
	TUpsDecision dec3 = EUpsDecYes;
sl@0
   173
	TUpsDecision dec4 = EUpsDecYes;
sl@0
   174
	TUpsDecision dec5 = EUpsDecYes;
sl@0
   175
	TUpsDecision dec6 = EUpsDecYes;
sl@0
   176
	testSubsession1.Authorise(EFalse, serviceId, _L("req1"), dec1, rs1);
sl@0
   177
	testSubsession2.Authorise(EFalse, serviceId, _L("reqX"), dec2, rs2);
sl@0
   178
	testSubsession3.Authorise(EFalse, serviceId, _L("req2"), dec3, rs3);
sl@0
   179
	testSubsession4.Authorise(EFalse, serviceId, _L("reqX"), dec4, rs4);
sl@0
   180
	testSubsession5.Authorise(EFalse, serviceId, _L("req3"), dec5, rs5);
sl@0
   181
	testSubsession6.Authorise(EFalse, serviceId, _L("req4"), dec6, rs6);
sl@0
   182
#if 0
sl@0
   183
	// Will change immediately in non-interactive testing
sl@0
   184
	test(dec1 == EUpsDecYes);	// not changed yet
sl@0
   185
	test(dec2 == EUpsDecYes);	// not changed yet
sl@0
   186
	test(dec3 == EUpsDecYes);	// not changed yet
sl@0
   187
	test(dec4 == EUpsDecYes);	// not changed yet
sl@0
   188
	test(dec5 == EUpsDecYes);	// not changed yet
sl@0
   189
	test(dec6 == EUpsDecYes);	// not changed yet
sl@0
   190
#endif
sl@0
   191
	User::After(1000);
sl@0
   192
sl@0
   193
	User::WaitForRequest(rs1);
sl@0
   194
sl@0
   195
	User::WaitForRequest(rs2);
sl@0
   196
	User::WaitForRequest(rs4);
sl@0
   197
sl@0
   198
	User::WaitForRequest(rs3);
sl@0
   199
	User::WaitForRequest(rs5);
sl@0
   200
	User::WaitForRequest(rs6);
sl@0
   201
	test(rs1 == KErrNone);
sl@0
   202
	test(rs2 == KErrNone);
sl@0
   203
	test(rs3 == KErrNone);
sl@0
   204
	test(rs4 == KErrNone);
sl@0
   205
	test(rs5 == KErrNone);
sl@0
   206
	test(rs6 == KErrNone);
sl@0
   207
	test(dec1 == EUpsDecNo);
sl@0
   208
	test(dec2 == EUpsDecNo);
sl@0
   209
	test(dec3 == EUpsDecNo);
sl@0
   210
	test(dec4 == EUpsDecNo);
sl@0
   211
	test(dec5 == EUpsDecNo);
sl@0
   212
	test(dec6 == EUpsDecNo);
sl@0
   213
	
sl@0
   214
	test.End();
sl@0
   215
	}
sl@0
   216
sl@0
   217
// -------- RUpsSubsession --------
sl@0
   218
_LIT(KSayYes,"SayYes");
sl@0
   219
static void TestRUpsSubsession()
sl@0
   220
/**
sl@0
   221
	Attempt query with server checks passed and without
sl@0
   222
 */
sl@0
   223
	{
sl@0
   224
	//
sl@0
   225
	// Tests for RUpsSubsession
sl@0
   226
	//
sl@0
   227
	RThread thd;
sl@0
   228
sl@0
   229
	test.Start(_L("Testing RUpsSubsession"));
sl@0
   230
	RUpsSubsession clientSubsession;
sl@0
   231
	TInt r = clientSubsession.Initialise(sTestSession, thd);
sl@0
   232
	test(r == KErrNone);
sl@0
   233
sl@0
   234
	test.Next(_L("Query with server checks passed"));
sl@0
   235
	TServiceId serviceId = {42};
sl@0
   236
	TUpsDecision dec = EUpsDecNo;
sl@0
   237
	TRequestStatus rs;
sl@0
   238
	// Query saying our checks were ok, expect to get decision set to EUpsDecYes
sl@0
   239
	clientSubsession.Authorise(ETrue, serviceId, _L("Destination"), _L8("Opaque data"), dec, rs);
sl@0
   240
	User::WaitForRequest(rs);
sl@0
   241
	test(rs == KErrNone);
sl@0
   242
	test(dec == EUpsDecYes);
sl@0
   243
sl@0
   244
sl@0
   245
sl@0
   246
	test.Next(_L("Try closing client subsession before it is really created"));
sl@0
   247
	clientSubsession.Close();
sl@0
   248
sl@0
   249
	test.Next(_L("Re-\"create\" client subsession"));
sl@0
   250
	r = clientSubsession.Initialise(sTestSession, thd);
sl@0
   251
	test(r == KErrNone);
sl@0
   252
sl@0
   253
	test.Next(_L("Query with server checks failed, ie query UPS, expect fail"));
sl@0
   254
	// Query saying our checks failed, should talk to UPS and change decision to EUpsDecNo
sl@0
   255
	dec = EUpsDecYes;
sl@0
   256
	clientSubsession.Authorise(EFalse, serviceId, KNullDesC, dec, rs);
sl@0
   257
	User::WaitForRequest(rs);
sl@0
   258
	test(rs == KErrNone);
sl@0
   259
	test(dec == EUpsDecNo);
sl@0
   260
sl@0
   261
sl@0
   262
	test.Next(_L("Query with server checks failed, ie query UPS, special destination, expect yes"));
sl@0
   263
	// Query saying our checks failed, should talk to UPS and change decision to EUpsDecNo
sl@0
   264
	dec = EUpsDecYes;
sl@0
   265
	clientSubsession.Authorise(EFalse, serviceId, KSayYes(), dec, rs);
sl@0
   266
	User::WaitForRequest(rs);
sl@0
   267
	test(rs == KErrNone);
sl@0
   268
	test(dec == EUpsDecYes);
sl@0
   269
sl@0
   270
sl@0
   271
	clientSubsession.Close();
sl@0
   272
	test.End();
sl@0
   273
	}
sl@0
   274
sl@0
   275
TInt ThreadFunction(TAny *)
sl@0
   276
	{
sl@0
   277
	return KErrNone;
sl@0
   278
	}
sl@0
   279
sl@0
   280
static void TestRUpsSubsessionDeathL()
sl@0
   281
	{
sl@0
   282
	RThread thd;
sl@0
   283
	TRequestStatus thdStatus;
sl@0
   284
	User::LeaveIfError(thd.Create(_L("MyThread"), ThreadFunction, 4096, 4096, 4096, 0, EOwnerThread));
sl@0
   285
//	thd.SetHandle(666);
sl@0
   286
	thd.Rendezvous(thdStatus);
sl@0
   287
	thd.Kill(KErrAbort);
sl@0
   288
	User::WaitForRequest(thdStatus);
sl@0
   289
sl@0
   290
	test.Start(_L("Testing RUpsSubsession"));
sl@0
   291
	RUpsSubsession clientSubsession;
sl@0
   292
	TInt r = clientSubsession.Initialise(sTestSession, thd);
sl@0
   293
	test(r == KErrNone);
sl@0
   294
sl@0
   295
	test.Next(_L("Query with dead thread id"));
sl@0
   296
	TServiceId serviceId = {43};
sl@0
   297
	TUpsDecision dec = EUpsDecYes;
sl@0
   298
	TRequestStatus rs;
sl@0
   299
	thd.Close();
sl@0
   300
	clientSubsession.Authorise(EFalse, serviceId, _L("req1"), dec, rs);
sl@0
   301
	User::WaitForRequest(rs);
sl@0
   302
	test(rs == KErrNone);
sl@0
   303
	test(dec == EUpsDecNo);
sl@0
   304
sl@0
   305
	
sl@0
   306
	clientSubsession.Close();
sl@0
   307
	test.End();
sl@0
   308
	}
sl@0
   309
sl@0
   310
static void TestRUpsManagementL()
sl@0
   311
/**
sl@0
   312
	Attempt to delete database
sl@0
   313
 */
sl@0
   314
	{
sl@0
   315
	test.Start(_L("Testing RUpsManagement"));
sl@0
   316
	RThread thd;
sl@0
   317
	TRequestStatus rs;
sl@0
   318
sl@0
   319
	// Create filter
sl@0
   320
	TServiceId serviceId = {43};
sl@0
   321
	CDecisionFilter *filter = CDecisionFilter::NewLC();
sl@0
   322
	filter->SetClientSid(thd.SecureId(), EEqual);
sl@0
   323
	filter->SetServerSid(thd.SecureId(), EEqual);
sl@0
   324
	filter->SetServiceId(serviceId, EEqual);
sl@0
   325
sl@0
   326
	RUpsSubsession clientSubsession;
sl@0
   327
	TInt r = clientSubsession.Initialise(sTestSession, thd);
sl@0
   328
	test(r == KErrNone);
sl@0
   329
sl@0
   330
	test.Next(_L("Open management session"));
sl@0
   331
	RUpsManagement mngmnt;
sl@0
   332
	r = mngmnt.Connect();
sl@0
   333
	test(r == KErrNone);
sl@0
   334
	User::LeaveIfError(r);
sl@0
   335
sl@0
   336
	test.Next(_L("View create - then delete DB"));
sl@0
   337
	mngmnt.CreateView(*filter, rs);
sl@0
   338
sl@0
   339
	test.Next(_L("Delete database"));
sl@0
   340
	TRAP(r, mngmnt.DeleteDatabaseL());
sl@0
   341
	test(r == KErrNone);
sl@0
   342
sl@0
   343
	test.Next(_L("Now see what view create completed with...."));
sl@0
   344
	User::WaitForRequest(rs);
sl@0
   345
	test(rs.Int() == KErrAbort);
sl@0
   346
sl@0
   347
	test.Next(_L("Add entry to new database"));
sl@0
   348
	TUpsDecision dec = EUpsDecYes;
sl@0
   349
	clientSubsession.Authorise(EFalse, serviceId, _L("DB delete 1"), _L8("Opaque data"), dec, rs);
sl@0
   350
	User::WaitForRequest(rs);
sl@0
   351
	test(rs == KErrNone);
sl@0
   352
	test(dec == EUpsDecNo);
sl@0
   353
sl@0
   354
	dec = EUpsDecYes;
sl@0
   355
	clientSubsession.Authorise(EFalse, serviceId, _L("DB delete 2"), _L8("Opaque data"), dec, rs);
sl@0
   356
	User::WaitForRequest(rs);
sl@0
   357
	test(rs == KErrNone);
sl@0
   358
	test(dec == EUpsDecNo);
sl@0
   359
sl@0
   360
sl@0
   361
	test.Next(_L("View create - immediate cancel"));
sl@0
   362
	mngmnt.CreateView(*filter, rs);
sl@0
   363
	mngmnt.CancelAndCloseView();
sl@0
   364
	User::WaitForRequest(rs);
sl@0
   365
	test(rs.Int() == KErrCancel);
sl@0
   366
sl@0
   367
	mngmnt.UpdateDecision(TUint32(-23), ETrue, rs);
sl@0
   368
	mngmnt.CancelUpdateDecision();
sl@0
   369
	User::WaitForRequest(rs);
sl@0
   370
	test(rs.Int() == KErrCancel);
sl@0
   371
sl@0
   372
	mngmnt.UpdateDecision(TUint32(-23), ETrue, rs);
sl@0
   373
	User::WaitForRequest(rs);
sl@0
   374
	test(rs.Int() == KErrNotFound);
sl@0
   375
sl@0
   376
	test.Next(_L("View create - when busy"));
sl@0
   377
	TRequestStatus rs2;
sl@0
   378
	mngmnt.CreateView(*filter, rs);
sl@0
   379
	mngmnt.CreateView(*filter, rs2);
sl@0
   380
	User::WaitForRequest(rs2);
sl@0
   381
	test(rs2.Int() == KErrServerBusy);
sl@0
   382
	User::WaitForRequest(rs);
sl@0
   383
	test(rs.Int() == KErrNone);
sl@0
   384
	mngmnt.CancelAndCloseView();
sl@0
   385
sl@0
   386
	test.Next(_L("View create - iterate through it"));
sl@0
   387
	mngmnt.CreateView(*filter, rs);
sl@0
   388
sl@0
   389
	User::WaitForRequest(rs);
sl@0
   390
	test(rs.Int() == KErrNone);
sl@0
   391
	
sl@0
   392
	CleanupStack::PopAndDestroy(filter);
sl@0
   393
sl@0
   394
	CDecisionRecord *record = 0;
sl@0
   395
	r = KErrNone;
sl@0
   396
	TInt recordCount = 0;
sl@0
   397
	while(r == KErrNone)
sl@0
   398
		{
sl@0
   399
		TRAP(r, record = mngmnt.NextMatchL());
sl@0
   400
		if(record == 0)
sl@0
   401
			{
sl@0
   402
			break;
sl@0
   403
			}
sl@0
   404
		test(r == KErrNone);
sl@0
   405
		if(r == KErrNone)
sl@0
   406
			{
sl@0
   407
			++recordCount;
sl@0
   408
			CleanupStack::PushL(record);
sl@0
   409
			CDecisionFilter *exactFilter = CDecisionFilter::NewLC(record->iClientSid,
sl@0
   410
																  record->iEvaluatorId,
sl@0
   411
																  record->iServiceId,
sl@0
   412
																  record->iServerSid,
sl@0
   413
																  record->iFingerprint,
sl@0
   414
																  record->iClientEntity,
sl@0
   415
																  record->iMajorPolicyVersion);
sl@0
   416
				
sl@0
   417
			
sl@0
   418
			mngmnt.UpdateDecision(record->iRecordId, ETrue, rs);
sl@0
   419
			User::WaitForRequest(rs);
sl@0
   420
			test(rs.Int() == KErrNone);
sl@0
   421
			TRAP(r, mngmnt.RemoveDecisionsL(*exactFilter));
sl@0
   422
			test(r == KErrNone);
sl@0
   423
sl@0
   424
			CleanupStack::PopAndDestroy(exactFilter);
sl@0
   425
			CleanupStack::PopAndDestroy(record);
sl@0
   426
			}
sl@0
   427
		
sl@0
   428
		};
sl@0
   429
	test(recordCount == 2);
sl@0
   430
	
sl@0
   431
	TRAP(r, record = mngmnt.NextMatchL());
sl@0
   432
	test((r == KErrNone) && (record == 0));
sl@0
   433
sl@0
   434
	mngmnt.CancelAndCloseView();
sl@0
   435
sl@0
   436
	test.Next(_L("Close management session and clientSubsession"));
sl@0
   437
	mngmnt.Close();
sl@0
   438
	clientSubsession.Close();
sl@0
   439
sl@0
   440
	test.End();
sl@0
   441
	}
sl@0
   442
sl@0
   443
void TestSwiObserverSecurityL()
sl@0
   444
{
sl@0
   445
	test.Start(_L("Testing swi observer functions do not work from here..."));
sl@0
   446
sl@0
   447
	TInt r;
sl@0
   448
sl@0
   449
	RUpsManagement session;
sl@0
   450
	User::LeaveIfError(session.Connect());
sl@0
   451
	CleanupClosePushL(session);
sl@0
   452
sl@0
   453
	TUid ourSid;
sl@0
   454
	ourSid.iUid = 0x10283559;
sl@0
   455
	TRAP(r, session.DeleteDecisionsForExeL(ourSid));
sl@0
   456
	test(r == KErrPermissionDenied);
sl@0
   457
sl@0
   458
	TRAP(r, session.NotifyPluginsMayHaveChangedL());
sl@0
   459
	test(r == KErrPermissionDenied);
sl@0
   460
sl@0
   461
	TRequestStatus rs;
sl@0
   462
	session.NotifyPolicyFilesChanged(rs);
sl@0
   463
	User::WaitForRequest(rs);
sl@0
   464
sl@0
   465
	test(rs.Int() == KErrPermissionDenied);
sl@0
   466
sl@0
   467
	session.CancelNotifyPolicyFilesChanged();
sl@0
   468
sl@0
   469
	CleanupStack::PopAndDestroy(&session);
sl@0
   470
	
sl@0
   471
	test.End();
sl@0
   472
}
sl@0
   473
sl@0
   474
// -------- entrypoint --------
sl@0
   475
sl@0
   476
sl@0
   477
void MainL()
sl@0
   478
	{
sl@0
   479
	test.Title(_L("c:\\upstest.log"));
sl@0
   480
	test.Start(_L(" @SYMTestCaseID:SEC-UPS-0001 Testing RUpsSubsession "));
sl@0
   481
sl@0
   482
	RFs fs;
sl@0
   483
	User::LeaveIfError(fs.Connect());
sl@0
   484
	CleanupClosePushL(fs);
sl@0
   485
	
sl@0
   486
	TBuf<21> notifierConfig(_L("!:\\upsrefnotifier.txt"));
sl@0
   487
	notifierConfig[0] = fs.GetSystemDriveChar();
sl@0
   488
sl@0
   489
	TBuf<35> database(_L("!:\\Private\\10283558\\database\\ups.db"));
sl@0
   490
	database[0] = fs.GetSystemDriveChar();
sl@0
   491
sl@0
   492
	TInt lineLength = User::CommandLineLength();
sl@0
   493
	switch(lineLength)
sl@0
   494
		{
sl@0
   495
	default:
sl@0
   496
		case 2:
sl@0
   497
			(void) fs.Delete(database);
sl@0
   498
			// Fall through to also delete notifier config file
sl@0
   499
		case 1:
sl@0
   500
			(void) fs.Delete(notifierConfig);
sl@0
   501
			break;
sl@0
   502
		case 0:
sl@0
   503
			{
sl@0
   504
			// No args so run in silent mode
sl@0
   505
			(void) fs.Delete(database);
sl@0
   506
			(void) fs.Delete(notifierConfig);
sl@0
   507
			RFile file;
sl@0
   508
			User::LeaveIfError(file.Create(fs, notifierConfig, EFileShareExclusive | EFileWrite));
sl@0
   509
			User::LeaveIfError(file.Write(_L8("Never")));
sl@0
   510
			file.Close();
sl@0
   511
			break;
sl@0
   512
			}
sl@0
   513
		}
sl@0
   514
sl@0
   515
	//RThread ourThread;
sl@0
   516
	//ourThread.SetPriority(EPriorityMore);
sl@0
   517
	//ourThread.Close();
sl@0
   518
//	User::SetProcessCritical(User::ESystemCritical);
sl@0
   519
//	User::SetCritical(User::ESystemCritical);
sl@0
   520
	TestOpenCloseSession();
sl@0
   521
sl@0
   522
sl@0
   523
	TInt r = sTestSession.Connect();
sl@0
   524
	test(r == KErrNone);
sl@0
   525
	User::LeaveIfError(r);
sl@0
   526
sl@0
   527
	TestRUpsSubsessionDeathL();
sl@0
   528
sl@0
   529
	TestOpenCloseSubsession();
sl@0
   530
sl@0
   531
	TestSwiObserverSecurityL();
sl@0
   532
	
sl@0
   533
	RThread thd;
sl@0
   534
	r = sTestSubsession.Initialise(sTestSession, thd);
sl@0
   535
	test(r == KErrNone);
sl@0
   536
	User::LeaveIfError(r);
sl@0
   537
	
sl@0
   538
	TestFlurryL();
sl@0
   539
sl@0
   540
	TestAuthoriseL();
sl@0
   541
	
sl@0
   542
	sTestSubsession.Close();
sl@0
   543
sl@0
   544
	TestRUpsSubsession();
sl@0
   545
sl@0
   546
	TestRUpsManagementL();
sl@0
   547
sl@0
   548
	sTestSession.ShutdownServer();
sl@0
   549
sl@0
   550
	// Close top level session (low level session was closed by
sl@0
   551
	// ShutdownServer, but we still need to do the RUpsSession
sl@0
   552
	// cleanup).
sl@0
   553
	sTestSession.Close();
sl@0
   554
sl@0
   555
	(void) fs.Delete(notifierConfig);
sl@0
   556
	CleanupStack::PopAndDestroy(&fs);
sl@0
   557
	
sl@0
   558
	test.End();
sl@0
   559
	test.Close();
sl@0
   560
}
sl@0
   561
sl@0
   562
void PanicIfError(TInt r)
sl@0
   563
	{
sl@0
   564
	if(r != KErrNone)
sl@0
   565
		{
sl@0
   566
		User::Panic(_L("upstest failed: "), r);
sl@0
   567
		}
sl@0
   568
	}
sl@0
   569
sl@0
   570
sl@0
   571
TInt E32Main()
sl@0
   572
/**
sl@0
   573
	Executable entrypoint establishes connection with UPS server
sl@0
   574
	and then invokes tests for each functional area.
sl@0
   575
	
sl@0
   576
	@return					Symbian OS error code where KErrNone indicates
sl@0
   577
							success and any other value indicates failure.
sl@0
   578
 */
sl@0
   579
	{
sl@0
   580
	// disable lazy DLL unloading so kernel heap balances at end
sl@0
   581
	RLoader l;
sl@0
   582
	PanicIfError(l.Connect());
sl@0
   583
	PanicIfError(l.CancelLazyDllUnload());
sl@0
   584
	l.Close();
sl@0
   585
	
sl@0
   586
	__UHEAP_MARK;
sl@0
   587
	//__KHEAP_MARK;
sl@0
   588
	
sl@0
   589
	// allocating a cleanup stack also installs it
sl@0
   590
	CTrapCleanup* tc = CTrapCleanup::New();
sl@0
   591
	if (tc == 0)
sl@0
   592
		return KErrNoMemory;
sl@0
   593
sl@0
   594
	TRAPD(err, MainL());
sl@0
   595
	if(err != KErrNone)
sl@0
   596
		{
sl@0
   597
		User::Panic(_L("upstest failed: "), err);
sl@0
   598
		}
sl@0
   599
	delete tc;
sl@0
   600
	
sl@0
   601
	//__KHEAP_MARKEND;
sl@0
   602
	__UHEAP_MARKEND;
sl@0
   603
	
sl@0
   604
	
sl@0
   605
	return KErrNone;
sl@0
   606
	}
sl@0
   607