os/security/authorisation/userpromptservice/database/test/tupsdb/source/tupsdbbase.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-2010 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
* Implements basic database test functions.
sl@0
    16
*
sl@0
    17
*/
sl@0
    18
sl@0
    19
sl@0
    20
/**
sl@0
    21
 @file
sl@0
    22
 @test
sl@0
    23
*/
sl@0
    24
sl@0
    25
#include "tupsdbstep.h"
sl@0
    26
#include <test/testexecutelog.h>
sl@0
    27
sl@0
    28
using namespace UserPromptService;
sl@0
    29
sl@0
    30
sl@0
    31
//
sl@0
    32
//CUpsDbBaseStep
sl@0
    33
//
sl@0
    34
sl@0
    35
CUpsDbBaseStep::CUpsDbBaseStep()
sl@0
    36
/**
sl@0
    37
	onstructor Code
sl@0
    38
 */
sl@0
    39
	{
sl@0
    40
   
sl@0
    41
	}
sl@0
    42
	
sl@0
    43
CUpsDbBaseStep::~CUpsDbBaseStep()
sl@0
    44
/**
sl@0
    45
	Destructor Code
sl@0
    46
 */
sl@0
    47
	{
sl@0
    48
sl@0
    49
	} 
sl@0
    50
sl@0
    51
sl@0
    52
CDecisionFilter *CUpsDbBaseStep::CreateFilterL(TInt aFlag, TInt aClientSid, TInt aEvaluatorId, TInt aServiceId, TInt aServerSid, TDesC8 &aFingerprint, TDesC8& aClientEntity,TInt aMajorPolicyVersion, TInt aRecordId, TDesC& aDescription, TInt aResult, TInt aEvaluatorInfo, TComparisonOp aComparisonOp)
sl@0
    53
 /**
sl@0
    54
	Creates an empty filter object and then passes it to SetFilterFiledsL to get assigned all filter keys separately. 
sl@0
    55
	This function is used to test NewL method of CDecisionFilter
sl@0
    56
	
sl@0
    57
	@param aFlag		 Shows which filter keys have been set 
sl@0
    58
	@param aClientSid	 Secure Id of client application
sl@0
    59
	@param aEvaluatorId	 UID for the policy evaluator DLL
sl@0
    60
	@param aServiceId	 UID for service 
sl@0
    61
	@param aServerSid	 UID for the system server
sl@0
    62
	@param aFingerprint	 Hash of the destination and/or opaque data.
sl@0
    63
	@param aClientEntity The name of the entity within the client that requested the service. 
sl@0
    64
	@param aMajorPolicyVersion The major version of the policy file.
sl@0
    65
	@param aRecordId	 An auto-incrementing record number.
sl@0
    66
	@param aDescription A copy of description and/or opaque
sl@0
    67
	@param aResult Whether the request should be approved
sl@0
    68
	@param aEvaluatorInfo Policy evaluator specific data
sl@0
    69
	@param aComparisonOp Comparison Operator (=,!=,<,> etc.)
sl@0
    70
	
sl@0
    71
	@return				 A pointer to the newly allocated filter object.
sl@0
    72
 */	
sl@0
    73
	{
sl@0
    74
	//Create an empty filter
sl@0
    75
	CDecisionFilter *filter = CDecisionFilter::NewL();
sl@0
    76
	CleanupStack::PushL(filter);
sl@0
    77
	
sl@0
    78
	SetFilterFiledsL(*filter, aFlag, aClientSid, aEvaluatorId, aServiceId, aServerSid,aFingerprint, aClientEntity, aMajorPolicyVersion, aRecordId, aDescription, aResult, aEvaluatorInfo, aComparisonOp);
sl@0
    79
	
sl@0
    80
	CleanupStack::Pop(filter);
sl@0
    81
	return filter;
sl@0
    82
	}
sl@0
    83
sl@0
    84
sl@0
    85
CDecisionFilter *CUpsDbBaseStep::CreateFilterLC(TInt aFlag, TInt aClientSid, TInt aEvaluatorId, TInt aServiceId, TInt aServerSid, TDesC8 &aFingerprint, TDesC8& aClientEntity,TInt aMajorPolicyVersion, TInt aRecordId, TDesC& aDescription, TInt aResult, TInt aEvaluatorInfo, TComparisonOp aComparisonOp)
sl@0
    86
/**
sl@0
    87
	Creates an empty filter object and then calls SetFilterFiledsL to get assigned all filter keys separately. 
sl@0
    88
	This function is used to test NewLC method of CDecisionFilter
sl@0
    89
	
sl@0
    90
	@see CUpsDbBaseStep::CreateFilterL
sl@0
    91
	
sl@0
    92
	@return A pointer to the newly allocated filter object. The pointer is also put onto the cleanup stack.
sl@0
    93
 */	
sl@0
    94
	{
sl@0
    95
	//Create an empty filter
sl@0
    96
	CDecisionFilter *filter = CDecisionFilter::NewLC();
sl@0
    97
	
sl@0
    98
	SetFilterFiledsL(*filter, aFlag, aClientSid, aEvaluatorId, aServiceId, aServerSid,aFingerprint, aClientEntity, aMajorPolicyVersion, aRecordId, aDescription, aResult, aEvaluatorInfo, aComparisonOp);
sl@0
    99
	
sl@0
   100
	return filter;
sl@0
   101
	}
sl@0
   102
sl@0
   103
sl@0
   104
void CUpsDbBaseStep::SetFilterFiledsL(CDecisionFilter &aFilter, TInt aFlag, TInt aClientSid, TInt aEvaluatorId, TInt aServiceId, TInt aServerSid, TDesC8 &aFingerprint, TDesC8& aClientEntity, TInt aMajorPolicyVersion, TInt aRecordId, TDesC& aDescription, TInt aResult, TInt aEvaluatorInfo, TComparisonOp aComparisonOp)
sl@0
   105
/**
sl@0
   106
	This method assigns all the fields of a provided filter object with the supplied parameters.
sl@0
   107
	The method is called by CreateFilterL and CreateFilterLC methods.
sl@0
   108
	
sl@0
   109
	@see CUpsDbBaseStep::CreateFilterL
sl@0
   110
	@param aFilter Empty decision filter object
sl@0
   111
 */
sl@0
   112
	{
sl@0
   113
	//Sets the variables using aFlag
sl@0
   114
	if(aFlag & KSetClientSid)
sl@0
   115
		{
sl@0
   116
		aFilter.SetClientSid(TSecureId(aClientSid), aComparisonOp);
sl@0
   117
		}
sl@0
   118
	
sl@0
   119
	if(aFlag & KSetEvaluatorId)
sl@0
   120
		{
sl@0
   121
		aFilter.SetEvaluatorId(TUid::Uid(aEvaluatorId),aComparisonOp);
sl@0
   122
		}
sl@0
   123
	
sl@0
   124
	if(aFlag & KSetServiceId)
sl@0
   125
		{
sl@0
   126
		aFilter.SetServiceId(TUid::Uid(aServiceId),aComparisonOp);
sl@0
   127
		}
sl@0
   128
	
sl@0
   129
	if(aFlag & KSetServerSid)
sl@0
   130
		{
sl@0
   131
		aFilter.SetServerSid(TSecureId(aServerSid),aComparisonOp);
sl@0
   132
		}
sl@0
   133
		
sl@0
   134
	if(aFlag & KSetFingerprint)
sl@0
   135
		{
sl@0
   136
		aFilter.SetFingerprintL(aFingerprint,aComparisonOp);
sl@0
   137
		}
sl@0
   138
	
sl@0
   139
	if(aFlag & KSetClientEntity)
sl@0
   140
		{
sl@0
   141
		aFilter.SetClientEntityL(aClientEntity,aComparisonOp);
sl@0
   142
		}
sl@0
   143
	
sl@0
   144
	if(aFlag & KSetMajorPolicyVersion)
sl@0
   145
		{
sl@0
   146
		aFilter.SetMajorPolicyVersion(aMajorPolicyVersion,aComparisonOp);
sl@0
   147
		}
sl@0
   148
	
sl@0
   149
	if(aFlag & KSetRecordId)
sl@0
   150
		{
sl@0
   151
		aFilter.SetRecordId(aRecordId,aComparisonOp);
sl@0
   152
		}
sl@0
   153
	
sl@0
   154
	if(aFlag & KSetDescription)
sl@0
   155
		{
sl@0
   156
		aFilter.SetDescriptionL(aDescription,aComparisonOp);
sl@0
   157
		}
sl@0
   158
		
sl@0
   159
	if(aFlag & KSetResult)
sl@0
   160
		{
sl@0
   161
		aFilter.SetResult(aResult,aComparisonOp);
sl@0
   162
		}
sl@0
   163
		
sl@0
   164
	if(aFlag & KSetEvaluatorInfo)
sl@0
   165
		{
sl@0
   166
		aFilter.SetEvaluatorInfo(aEvaluatorInfo,aComparisonOp);
sl@0
   167
		}
sl@0
   168
	}
sl@0
   169
sl@0
   170
	
sl@0
   171
CDecisionRecord *CUpsDbBaseStep::CreateRecordL(TInt aClientSid, TInt aEvaluatorId, TInt aServiceId, TInt aServerSid, TDesC8 &aFingerprint, TDesC8 &aClientEntity,
sl@0
   172
											   TDesC &aDecription, TInt aResult, TInt aMajorPolicyVersion, TInt aEvaluatorInfo, TInt aRecordId)
sl@0
   173
/**
sl@0
   174
	Creates a decision record from provided parameters.
sl@0
   175
	
sl@0
   176
	@param aClientSid	  Secure Id of client application
sl@0
   177
	@param aEvaluatorId	  UID for the policy evaluator DLL
sl@0
   178
	@param aServiceId	  UID for service e.g. sms, mms, telephony, gprs
sl@0
   179
	@param aServerSid	  UID for the system server that the decision applies to
sl@0
   180
	@param aFingerprint	  Hash of the destination and/or opaque data. Maximum length is 32 bytes.
sl@0
   181
	@param aClientEntity  The name of the entity within the client that requested the service. Maximum length is 32 bytes. 
sl@0
   182
	@param aDescription	  A copy of description and/or opaque. 
sl@0
   183
	@param aResult		  Whether the request should be approved (=1) or denied (=0)
sl@0
   184
	@param aMajorPolicyVersion The major version of the policy file.
sl@0
   185
	@param aEvaluatorInfo Policy evaluator specific data
sl@0
   186
	@param aRecordId	  An auto-incrementing record number.
sl@0
   187
	
sl@0
   188
	@return				  A pointer to the newly allocated decision record object, if creation is successful.
sl@0
   189
sl@0
   190
 */
sl@0
   191
	{
sl@0
   192
	CDecisionRecord *newRecord;
sl@0
   193
	
sl@0
   194
	newRecord = CDecisionRecord::NewL(TSecureId(aClientSid),TUid::Uid(aEvaluatorId),TUid::Uid(aServiceId),TSecureId(aServerSid),aFingerprint,aClientEntity,aDecription,aResult,aMajorPolicyVersion,aEvaluatorInfo, aRecordId);
sl@0
   195
	
sl@0
   196
	return newRecord;
sl@0
   197
	}
sl@0
   198
sl@0
   199
sl@0
   200
void CUpsDbBaseStep::StartTimer(TTime &aTime)
sl@0
   201
/**
sl@0
   202
	Assigns current time to the provided parameter
sl@0
   203
	@param aTime Keeps the current time
sl@0
   204
 */
sl@0
   205
	{
sl@0
   206
	aTime.HomeTime();
sl@0
   207
	}
sl@0
   208
		
sl@0
   209
sl@0
   210
void CUpsDbBaseStep::StopTimer(TTime &aStartTime, TInt64 &aElapsedTime)
sl@0
   211
/**
sl@0
   212
	Substracts the provided time from current time and returns the elapsed time.
sl@0
   213
	@param aStartTime First measured time
sl@0
   214
	@param aElapsedTime The elapsed time from the first measurement
sl@0
   215
 */
sl@0
   216
	{
sl@0
   217
	TTime endTime;
sl@0
   218
	endTime.HomeTime();
sl@0
   219
	
sl@0
   220
	TTimeIntervalMicroSeconds timeDiff = endTime.MicroSecondsFrom(aStartTime);
sl@0
   221
	aElapsedTime = timeDiff.Int64();
sl@0
   222
	
sl@0
   223
	if(iLog)
sl@0
   224
		{
sl@0
   225
		_LIT8(KMessage,"%Ld");
sl@0
   226
		iBuffer.AppendFormat(KMessage,aElapsedTime);
sl@0
   227
		iFile.Write(iBuffer);
sl@0
   228
		iFile.Write(_L8(";"));
sl@0
   229
		iBuffer.Zero();
sl@0
   230
		}
sl@0
   231
	}
sl@0
   232
	
sl@0
   233
sl@0
   234
void CUpsDbBaseStep::FillTableL(CDecisionDbW &aUpsDb, TInt aRecordNum, TInt aClientNum, TInt aServiceNum, TInt aServerNum, TInt aEvaluatorNum)
sl@0
   235
/**
sl@0
   236
	Fill the decision table with a specified number of decision records.
sl@0
   237
	The parameteres are used as seeds to create sample decision records. 
sl@0
   238
	
sl@0
   239
	@param aUpsDb		 Handle to the database
sl@0
   240
	@param aRecordNum	 Number of records which will be inserted into the database
sl@0
   241
	@param aClientNum	 Number of different clients 
sl@0
   242
	@param aServiceNum	 Number of different services provided by each server
sl@0
   243
	@param aServerNum	 Number of different servers
sl@0
   244
	@param aEvaluatorNum Number of different policy evaluator DLLs
sl@0
   245
 */
sl@0
   246
	{
sl@0
   247
	TSecureId clientId = TSecureId(0);
sl@0
   248
	TSecureId serverId = TSecureId(0);
sl@0
   249
	TUid serviceId	 =TUid::Null();
sl@0
   250
	TUid evaluatorId =TUid::Null();
sl@0
   251
	
sl@0
   252
	TUint8 result = 0;
sl@0
   253
	TUint16 policyMajorVersion = 2;
sl@0
   254
	
sl@0
   255
	TBuf8<KDbMaxName> bufFP;
sl@0
   256
	TBuf8<KDbMaxName> bufCE;
sl@0
   257
	TBuf<KDbMaxName> bufD;
sl@0
   258
	
sl@0
   259
	CDecisionRecord* newRecord = NULL;
sl@0
   260
	
sl@0
   261
	for(TInt i=0; i<aRecordNum; i++)
sl@0
   262
		{
sl@0
   263
		bufFP.AppendFormat(KFingerprint,i);
sl@0
   264
		bufCE.AppendFormat(KClientEntity,i);
sl@0
   265
		bufD.AppendFormat(KDescription,i);
sl@0
   266
		
sl@0
   267
		CMD5* md5FP = CMD5::NewL();
sl@0
   268
		CleanupStack::PushL(md5FP);
sl@0
   269
		
sl@0
   270
		CMD5* md5CE = CMD5::NewL();
sl@0
   271
		CleanupStack::PushL(md5CE);
sl@0
   272
		
sl@0
   273
		clientId=TSecureId(i%aClientNum + aRecordNum);
sl@0
   274
		serviceId=TUid::Uid(i%aServiceNum + 10000 + aRecordNum);
sl@0
   275
		serverId =TSecureId(i%aServerNum + 100000 + aRecordNum);
sl@0
   276
		evaluatorId = TUid::Uid(i%aEvaluatorNum + 1000000 + aRecordNum);
sl@0
   277
		
sl@0
   278
		result = i%2;
sl@0
   279
		
sl@0
   280
		newRecord = CDecisionRecord::NewLC(clientId,evaluatorId,serviceId,serverId,md5FP->Hash(bufFP),md5CE->Hash(bufCE),bufD, result,policyMajorVersion, 0);
sl@0
   281
		
sl@0
   282
		aUpsDb.CreateDecisionL(*newRecord);
sl@0
   283
		
sl@0
   284
		CleanupStack::PopAndDestroy(newRecord);
sl@0
   285
		CleanupStack::PopAndDestroy(2); //md5FP and md5CE
sl@0
   286
		
sl@0
   287
		bufFP.Zero();
sl@0
   288
		bufCE.Zero();
sl@0
   289
		bufD.Zero();
sl@0
   290
		}
sl@0
   291
	}
sl@0
   292
	
sl@0
   293
sl@0
   294
CDecisionDbW *CUpsDbBaseStep::CreateDatabaseLC(TDesC& aDbLocation, RFs& aFs)
sl@0
   295
/**
sl@0
   296
	Create a writable decision database object. Prints the consumed time to perform this operation.
sl@0
   297
	
sl@0
   298
	@param aDbLocation Where the database will be created
sl@0
   299
 */
sl@0
   300
	{
sl@0
   301
	TTime startTime;
sl@0
   302
	//Timer is started
sl@0
   303
	StartTimer(startTime);
sl@0
   304
	
sl@0
   305
	//Database is created
sl@0
   306
	CDecisionDbW *upsDb = CDecisionDbW::NewLC(aDbLocation, aFs);
sl@0
   307
	
sl@0
   308
	//Timer is stopped
sl@0
   309
	TInt64 elapsedTime = 0;
sl@0
   310
	StopTimer(startTime,elapsedTime);
sl@0
   311
	
sl@0
   312
	INFO_PRINTF2(_L("Decision database created in %Ld microseconds."), elapsedTime);
sl@0
   313
	
sl@0
   314
	return upsDb;
sl@0
   315
	}
sl@0
   316
	
sl@0
   317
sl@0
   318
CDecisionRecord *CUpsDbBaseStep::GetDecisionLC(CDecisionDbW &aUpsDb, CDecisionFilter &aFilter)
sl@0
   319
/**
sl@0
   320
	Get a decision record from the database. This function uses single record lookup method (RDbTable).
sl@0
   321
	Prints the consumed time to perform this operation.
sl@0
   322
	
sl@0
   323
	@param aUpsDb Handle to the database
sl@0
   324
	@param aFilter Filter
sl@0
   325
 */
sl@0
   326
	{
sl@0
   327
	TTime startTime;
sl@0
   328
	//Timer is started
sl@0
   329
	StartTimer(startTime);
sl@0
   330
	
sl@0
   331
	CDecisionRecord *retRecord = NULL;
sl@0
   332
	retRecord = aUpsDb.GetDecisionL(aFilter);
sl@0
   333
	if(retRecord)
sl@0
   334
		{
sl@0
   335
		CleanupStack::PushL(retRecord);
sl@0
   336
		}
sl@0
   337
	
sl@0
   338
	//Timer is stopped
sl@0
   339
	TInt64 elapsedTime = 0;
sl@0
   340
	StopTimer(startTime,elapsedTime);
sl@0
   341
	
sl@0
   342
	if(retRecord)
sl@0
   343
		{
sl@0
   344
		INFO_PRINTF2(_L("A single record retrieved in %Ld microseconds."), elapsedTime);
sl@0
   345
		}
sl@0
   346
	
sl@0
   347
	return retRecord;
sl@0
   348
	}
sl@0
   349
	
sl@0
   350
sl@0
   351
void CUpsDbBaseStep::GetDecisionsL(CDecisionDbW &aUpsDb, CDecisionFilter &aFilter, TBool aCancel, RPointerArray<CDecisionRecord>& aRecordList)
sl@0
   352
/**
sl@0
   353
   Get a set of decision records from the database. Uses multiple records lookup method (RDbView).
sl@0
   354
   Prints the consumed time to perform this operation.
sl@0
   355
 */
sl@0
   356
	{
sl@0
   357
	TTime startTime;
sl@0
   358
	//Timer is started
sl@0
   359
	StartTimer(startTime);
sl@0
   360
	
sl@0
   361
	CDecisionView *dbView = aUpsDb.CreateViewL(aFilter);
sl@0
   362
	CleanupStack::PushL(dbView);
sl@0
   363
sl@0
   364
	dbView->EvaluateView(iWaiter->iStatus);
sl@0
   365
	TInt num = 0;
sl@0
   366
	if(aCancel)
sl@0
   367
		{
sl@0
   368
		dbView->Cancel();
sl@0
   369
		iWaiter->WaitActiveL(KErrCancel);
sl@0
   370
		}
sl@0
   371
	else
sl@0
   372
		{
sl@0
   373
		iWaiter->WaitActiveL(KErrNone);
sl@0
   374
		CDecisionRecord *record = NULL;		
sl@0
   375
		
sl@0
   376
		while((record = dbView->NextDecisionL()) != NULL)
sl@0
   377
			{
sl@0
   378
			CleanupStack::PushL(record);
sl@0
   379
			num++;
sl@0
   380
			aRecordList.AppendL(record);
sl@0
   381
			CleanupStack::Pop(record);
sl@0
   382
			}
sl@0
   383
		}
sl@0
   384
	
sl@0
   385
	//Timer is stopped
sl@0
   386
	TInt64 elapsedTime = 0;
sl@0
   387
	StopTimer(startTime,elapsedTime);
sl@0
   388
	
sl@0
   389
	INFO_PRINTF3(_L("%d records retrieved in %Ld microseconds."), num, elapsedTime);
sl@0
   390
	CleanupStack::PopAndDestroy(dbView);
sl@0
   391
	}
sl@0
   392
	
sl@0
   393
sl@0
   394
void CUpsDbBaseStep::RemoveDecisionsL(CDecisionDbW &aUpsDb, CDecisionFilter &aFilter)
sl@0
   395
/**
sl@0
   396
	Delete a set of records. Prints the consumed time to perform this operation.
sl@0
   397
 */
sl@0
   398
	{
sl@0
   399
	TTime startTime;
sl@0
   400
	//Timer is started
sl@0
   401
	StartTimer(startTime);
sl@0
   402
	
sl@0
   403
	aUpsDb.RemoveDecisionsL(aFilter);
sl@0
   404
	
sl@0
   405
	//Timer is stopped
sl@0
   406
	TInt64 elapsedTime = 0;
sl@0
   407
	StopTimer(startTime,elapsedTime);
sl@0
   408
	
sl@0
   409
	INFO_PRINTF2(_L("A set of records deleted in %Ld microseconds."), elapsedTime);
sl@0
   410
	}
sl@0
   411
	
sl@0
   412
	
sl@0
   413
void CUpsDbBaseStep::RemoveAllDecisionsL(CDecisionDbW &aUpsDb, RFs& aFs)
sl@0
   414
/**
sl@0
   415
	Deletes all records in the database. Actually delete all database.
sl@0
   416
	Prints the consumed time to perform this operation.
sl@0
   417
 */
sl@0
   418
	{
sl@0
   419
	TTime startTime;
sl@0
   420
	//Timer is started
sl@0
   421
	StartTimer(startTime);
sl@0
   422
	
sl@0
   423
	aUpsDb.DeleteDatabaseL(aFs);
sl@0
   424
	
sl@0
   425
	//Timer is stopped
sl@0
   426
	TInt64 elapsedTime = 0;
sl@0
   427
	StopTimer(startTime,elapsedTime);
sl@0
   428
	
sl@0
   429
	INFO_PRINTF2(_L("All records deleted in %Ld microseconds."), elapsedTime);
sl@0
   430
	}
sl@0
   431
	
sl@0
   432
sl@0
   433
void CUpsDbBaseStep::InsertRecordL(CDecisionDbW &aUpsDb, CDecisionRecord &aRecord)
sl@0
   434
/**
sl@0
   435
	Inserts the provided record into the decision database. Prints the consumed time to perform this operation.
sl@0
   436
 */
sl@0
   437
	{
sl@0
   438
	TTime startTime;
sl@0
   439
	//Timer is started
sl@0
   440
	StartTimer(startTime);
sl@0
   441
	
sl@0
   442
	aUpsDb.CreateDecisionL(aRecord);
sl@0
   443
	
sl@0
   444
	//Timer is stopped
sl@0
   445
	TInt64 elapsedTime = 0;
sl@0
   446
	StopTimer(startTime,elapsedTime);
sl@0
   447
	
sl@0
   448
	INFO_PRINTF2(_L("A record inserted in %Ld microseconds."), elapsedTime);
sl@0
   449
	}
sl@0
   450
	
sl@0
   451
sl@0
   452
void CUpsDbBaseStep::ReadConfigurationFile(TDes &aKeyNotFound)
sl@0
   453
/**
sl@0
   454
	Reads the key fileds from the ini file which are used to fill table with a specified number of
sl@0
   455
	sample records.
sl@0
   456
	@param aKeyNotFound The appended list of the key names which have not been found
sl@0
   457
 */
sl@0
   458
	{
sl@0
   459
	
sl@0
   460
	if(EFalse == GetIntFromConfig(ConfigSection(),KRecordNum, iRecordNum))
sl@0
   461
		{
sl@0
   462
		aKeyNotFound.Append(KRecordNum);
sl@0
   463
		aKeyNotFound.Append(_L(" "));
sl@0
   464
		}
sl@0
   465
	else if(EFalse == GetIntFromConfig(ConfigSection(),KServerNum, iServerNum))
sl@0
   466
		{
sl@0
   467
		aKeyNotFound.Append(KServerNum);
sl@0
   468
		aKeyNotFound.Append(_L(" "));
sl@0
   469
		}
sl@0
   470
	else if(EFalse == GetIntFromConfig(ConfigSection(),KServiceNum, iServiceNum))
sl@0
   471
		{
sl@0
   472
		aKeyNotFound.Append(KServiceNum);
sl@0
   473
		aKeyNotFound.Append(_L(" "));
sl@0
   474
		}
sl@0
   475
	else if(EFalse == GetIntFromConfig(ConfigSection(),KClientNum, iClientNum))
sl@0
   476
		{
sl@0
   477
		aKeyNotFound.Append(KClientNum);
sl@0
   478
		aKeyNotFound.Append(_L(" "));
sl@0
   479
		}
sl@0
   480
	else if(EFalse == GetIntFromConfig(ConfigSection(),KEvaluatorNum, iEvaluatorNum))
sl@0
   481
		{
sl@0
   482
		aKeyNotFound.Append(KEvaluatorNum);
sl@0
   483
		aKeyNotFound.Append(_L(" "));
sl@0
   484
		}
sl@0
   485
	else if(EFalse == GetIntFromConfig(ConfigSection(),KRetrieveNum, iRetrieveNum))
sl@0
   486
		{
sl@0
   487
		aKeyNotFound.Append(KRetrieveNum);
sl@0
   488
		aKeyNotFound.Append(_L(" "));
sl@0
   489
		}
sl@0
   490
	}
sl@0
   491
sl@0
   492
sl@0
   493
TInt CUpsDbBaseStep::ConvertNumber(TDesC& aError)
sl@0
   494
/**
sl@0
   495
	Converts error string  to number
sl@0
   496
	@param aError Error string
sl@0
   497
*/	
sl@0
   498
		{
sl@0
   499
		TInt error = KErrNotFound;
sl@0
   500
		
sl@0
   501
		if(!aError.CompareF(KStrErrNone))
sl@0
   502
			{
sl@0
   503
			error = KErrNone;	
sl@0
   504
			}
sl@0
   505
		else if(!aError.CompareF(KStrErrUpsBadFingerprintLength))
sl@0
   506
			{
sl@0
   507
			error = KErrUpsBadFingerprintLength;
sl@0
   508
			}
sl@0
   509
		else if(!aError.CompareF(KStrErrUpsMissingArgument))
sl@0
   510
			{
sl@0
   511
			error = KErrUpsMissingArgument;
sl@0
   512
			}
sl@0
   513
		else if(!aError.CompareF(KStrErrUpsBadClientEntityLength))
sl@0
   514
			{
sl@0
   515
			error = KErrUpsBadClientEntityLength;
sl@0
   516
			}
sl@0
   517
			
sl@0
   518
		return error;
sl@0
   519
		}
sl@0
   520
		
sl@0
   521
static void PopulateFingerPrint(TDes8& aBuf, TInt aStart)
sl@0
   522
	{
sl@0
   523
	TUint8 *ptr = (TUint8 *)aBuf.Ptr();
sl@0
   524
	
sl@0
   525
	TInt pos;
sl@0
   526
	TInt value;
sl@0
   527
	
sl@0
   528
	for(pos = 0, value = aStart; pos < KUpsMaxFingerprintLength; ++pos, ++value )
sl@0
   529
		{
sl@0
   530
		ptr[pos] = value;
sl@0
   531
		}
sl@0
   532
	aBuf.SetLength(pos);	
sl@0
   533
	}
sl@0
   534
sl@0
   535
void CUpsDbBaseStep::TestFingerprintValuesL(CDecisionDbW& aUpsDb)
sl@0
   536
/**
sl@0
   537
	Creates a number of decision records by using all characters 
sl@0
   538
	between 0x01 and 0xFF in Fingerprint value.
sl@0
   539
 */
sl@0
   540
sl@0
   541
	{
sl@0
   542
	TInt clientId		= 1;
sl@0
   543
	TInt serverId		= 2;
sl@0
   544
	TInt serviceId		= 3;
sl@0
   545
	TInt evaluatorId	= 4;
sl@0
   546
	TInt evaluatorInfo	= 5;
sl@0
   547
	TInt result			= 0;
sl@0
   548
	TInt policyVersion	= 9;
sl@0
   549
	TInt recordId		= 0;
sl@0
   550
	
sl@0
   551
	CDecisionRecord *record = NULL;
sl@0
   552
	CDecisionFilter *filter = NULL;
sl@0
   553
	RPointerArray<CDecisionRecord> recordList;	
sl@0
   554
	TBuf8<KUpsMaxFingerprintLength> bufFp;
sl@0
   555
	TBuf8<KUpsMaxClientEntityLength> bufCe;
sl@0
   556
	TBuf<KUpsDescriptionLength> bufDes;
sl@0
   557
	bufFp.SetLength(KUpsMaxFingerprintLength);
sl@0
   558
	bufCe.SetLength(KUpsMaxClientEntityLength);
sl@0
   559
	TInt flag = KSetClientSid|KSetEvaluatorId|KSetServiceId|KSetServerSid|KSetFingerprint|KSetClientEntity;
sl@0
   560
	TInt pos = 0;
sl@0
   561
	
sl@0
   562
	for(pos=0; pos <= KUpsDescriptionLength+1; pos+= KUpsMaxFingerprintLength)
sl@0
   563
		{
sl@0
   564
		PopulateFingerPrint(bufFp, pos);
sl@0
   565
		record = CreateRecordL(++clientId,++evaluatorId,++serviceId,++serverId, bufFp, bufCe, bufDes, result, policyVersion, evaluatorInfo, recordId);
sl@0
   566
		CleanupStack::PushL(record);
sl@0
   567
		InsertRecordL(aUpsDb,*record);
sl@0
   568
		
sl@0
   569
		filter = CreateFilterLC(flag,clientId,evaluatorId,serviceId,serverId,bufFp,bufCe,policyVersion,recordId,bufDes,result,evaluatorInfo,EEqual);
sl@0
   570
		CleanupResetAndDestroyPushL(recordList);
sl@0
   571
		GetDecisionsL(aUpsDb, *filter, EFalse, recordList);
sl@0
   572
		if(recordList.Count() != 1)
sl@0
   573
			{
sl@0
   574
			SetTestStepResult(EFail);
sl@0
   575
			CleanupStack::PopAndDestroy(3, record);
sl@0
   576
			break;
sl@0
   577
			}		
sl@0
   578
		CleanupStack::PopAndDestroy(3, record);
sl@0
   579
		}	
sl@0
   580
	}
sl@0
   581
sl@0
   582
sl@0
   583
void CUpsDbBaseStep::CompactDatabaseL(CDecisionDbW& aUpsDb, TBool aCancel)
sl@0
   584
/**
sl@0
   585
	Compacts the decision database.
sl@0
   586
 */
sl@0
   587
	{
sl@0
   588
	TTime startTime;
sl@0
   589
	//Timer is started
sl@0
   590
	StartTimer(startTime);
sl@0
   591
	
sl@0
   592
	CDecisionDbCompactor *dbCompact = aUpsDb.PrepareCompactionLC();
sl@0
   593
	dbCompact->Compact(iWaiter->iStatus);
sl@0
   594
	
sl@0
   595
	if(aCancel)
sl@0
   596
		{
sl@0
   597
		dbCompact->Cancel();
sl@0
   598
		iWaiter->WaitActiveL(KErrCancel);
sl@0
   599
		}
sl@0
   600
	else
sl@0
   601
		{
sl@0
   602
		iWaiter->WaitActiveL(KErrNone);		
sl@0
   603
		}
sl@0
   604
		
sl@0
   605
	//Timer is stopped
sl@0
   606
	TInt64 elapsedTime = 0;
sl@0
   607
	StopTimer(startTime,elapsedTime);
sl@0
   608
			
sl@0
   609
	if(iWaiter->iStatus == 0)
sl@0
   610
		{
sl@0
   611
		INFO_PRINTF2(_L("Compaction has been achieved in %Ld microseconds."), elapsedTime);
sl@0
   612
		}
sl@0
   613
	else
sl@0
   614
		{
sl@0
   615
		if(!aCancel && iWaiter->iStatus!=KErrCancel)
sl@0
   616
			{
sl@0
   617
			ERR_PRINTF1(_L("Failed to compact database!"));
sl@0
   618
			SetTestStepResult(EFail);		
sl@0
   619
			}
sl@0
   620
		}
sl@0
   621
		
sl@0
   622
	CleanupStack::PopAndDestroy(dbCompact);
sl@0
   623
	}
sl@0
   624
sl@0
   625
sl@0
   626
void CUpsDbBaseStep::UpdateRecordL(CDecisionDbW& aUpsDb, CDecisionFilter& aFilter, CDecisionRecord& aRecord)
sl@0
   627
/**
sl@0
   628
	Updates a decision record from the decision database.
sl@0
   629
	
sl@0
   630
	@param aUpsDb A pointer to the decision database object
sl@0
   631
	@param aFilter Filter used to find the record which will be updated
sl@0
   632
	@param aRecord New record containing the values which will be updated
sl@0
   633
 */
sl@0
   634
	{
sl@0
   635
	TTime startTime;
sl@0
   636
	//Timer is started
sl@0
   637
	StartTimer(startTime);
sl@0
   638
	
sl@0
   639
	if(EFalse == aUpsDb.UpdateDecisionL(aFilter,aRecord))
sl@0
   640
		{
sl@0
   641
		SetTestStepResult(EFail);
sl@0
   642
		User::Leave(KErrNotFound);
sl@0
   643
		}
sl@0
   644
	else
sl@0
   645
		{
sl@0
   646
		//Timer is stopped
sl@0
   647
		TInt64 elapsedTime = 0;
sl@0
   648
		StopTimer(startTime,elapsedTime);
sl@0
   649
		INFO_PRINTF2(_L("The record was updated in %Ld microseconds."), elapsedTime);	
sl@0
   650
		}
sl@0
   651
		
sl@0
   652
	}