os/security/authorisation/userpromptservice/database/test/tupsdb/source/tupsdbbase.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/authorisation/userpromptservice/database/test/tupsdb/source/tupsdbbase.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,652 @@
     1.4 +/*
     1.5 +* Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +* Implements basic database test functions.
    1.19 +*
    1.20 +*/
    1.21 +
    1.22 +
    1.23 +/**
    1.24 + @file
    1.25 + @test
    1.26 +*/
    1.27 +
    1.28 +#include "tupsdbstep.h"
    1.29 +#include <test/testexecutelog.h>
    1.30 +
    1.31 +using namespace UserPromptService;
    1.32 +
    1.33 +
    1.34 +//
    1.35 +//CUpsDbBaseStep
    1.36 +//
    1.37 +
    1.38 +CUpsDbBaseStep::CUpsDbBaseStep()
    1.39 +/**
    1.40 +	onstructor Code
    1.41 + */
    1.42 +	{
    1.43 +   
    1.44 +	}
    1.45 +	
    1.46 +CUpsDbBaseStep::~CUpsDbBaseStep()
    1.47 +/**
    1.48 +	Destructor Code
    1.49 + */
    1.50 +	{
    1.51 +
    1.52 +	} 
    1.53 +
    1.54 +
    1.55 +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)
    1.56 + /**
    1.57 +	Creates an empty filter object and then passes it to SetFilterFiledsL to get assigned all filter keys separately. 
    1.58 +	This function is used to test NewL method of CDecisionFilter
    1.59 +	
    1.60 +	@param aFlag		 Shows which filter keys have been set 
    1.61 +	@param aClientSid	 Secure Id of client application
    1.62 +	@param aEvaluatorId	 UID for the policy evaluator DLL
    1.63 +	@param aServiceId	 UID for service 
    1.64 +	@param aServerSid	 UID for the system server
    1.65 +	@param aFingerprint	 Hash of the destination and/or opaque data.
    1.66 +	@param aClientEntity The name of the entity within the client that requested the service. 
    1.67 +	@param aMajorPolicyVersion The major version of the policy file.
    1.68 +	@param aRecordId	 An auto-incrementing record number.
    1.69 +	@param aDescription A copy of description and/or opaque
    1.70 +	@param aResult Whether the request should be approved
    1.71 +	@param aEvaluatorInfo Policy evaluator specific data
    1.72 +	@param aComparisonOp Comparison Operator (=,!=,<,> etc.)
    1.73 +	
    1.74 +	@return				 A pointer to the newly allocated filter object.
    1.75 + */	
    1.76 +	{
    1.77 +	//Create an empty filter
    1.78 +	CDecisionFilter *filter = CDecisionFilter::NewL();
    1.79 +	CleanupStack::PushL(filter);
    1.80 +	
    1.81 +	SetFilterFiledsL(*filter, aFlag, aClientSid, aEvaluatorId, aServiceId, aServerSid,aFingerprint, aClientEntity, aMajorPolicyVersion, aRecordId, aDescription, aResult, aEvaluatorInfo, aComparisonOp);
    1.82 +	
    1.83 +	CleanupStack::Pop(filter);
    1.84 +	return filter;
    1.85 +	}
    1.86 +
    1.87 +
    1.88 +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)
    1.89 +/**
    1.90 +	Creates an empty filter object and then calls SetFilterFiledsL to get assigned all filter keys separately. 
    1.91 +	This function is used to test NewLC method of CDecisionFilter
    1.92 +	
    1.93 +	@see CUpsDbBaseStep::CreateFilterL
    1.94 +	
    1.95 +	@return A pointer to the newly allocated filter object. The pointer is also put onto the cleanup stack.
    1.96 + */	
    1.97 +	{
    1.98 +	//Create an empty filter
    1.99 +	CDecisionFilter *filter = CDecisionFilter::NewLC();
   1.100 +	
   1.101 +	SetFilterFiledsL(*filter, aFlag, aClientSid, aEvaluatorId, aServiceId, aServerSid,aFingerprint, aClientEntity, aMajorPolicyVersion, aRecordId, aDescription, aResult, aEvaluatorInfo, aComparisonOp);
   1.102 +	
   1.103 +	return filter;
   1.104 +	}
   1.105 +
   1.106 +
   1.107 +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)
   1.108 +/**
   1.109 +	This method assigns all the fields of a provided filter object with the supplied parameters.
   1.110 +	The method is called by CreateFilterL and CreateFilterLC methods.
   1.111 +	
   1.112 +	@see CUpsDbBaseStep::CreateFilterL
   1.113 +	@param aFilter Empty decision filter object
   1.114 + */
   1.115 +	{
   1.116 +	//Sets the variables using aFlag
   1.117 +	if(aFlag & KSetClientSid)
   1.118 +		{
   1.119 +		aFilter.SetClientSid(TSecureId(aClientSid), aComparisonOp);
   1.120 +		}
   1.121 +	
   1.122 +	if(aFlag & KSetEvaluatorId)
   1.123 +		{
   1.124 +		aFilter.SetEvaluatorId(TUid::Uid(aEvaluatorId),aComparisonOp);
   1.125 +		}
   1.126 +	
   1.127 +	if(aFlag & KSetServiceId)
   1.128 +		{
   1.129 +		aFilter.SetServiceId(TUid::Uid(aServiceId),aComparisonOp);
   1.130 +		}
   1.131 +	
   1.132 +	if(aFlag & KSetServerSid)
   1.133 +		{
   1.134 +		aFilter.SetServerSid(TSecureId(aServerSid),aComparisonOp);
   1.135 +		}
   1.136 +		
   1.137 +	if(aFlag & KSetFingerprint)
   1.138 +		{
   1.139 +		aFilter.SetFingerprintL(aFingerprint,aComparisonOp);
   1.140 +		}
   1.141 +	
   1.142 +	if(aFlag & KSetClientEntity)
   1.143 +		{
   1.144 +		aFilter.SetClientEntityL(aClientEntity,aComparisonOp);
   1.145 +		}
   1.146 +	
   1.147 +	if(aFlag & KSetMajorPolicyVersion)
   1.148 +		{
   1.149 +		aFilter.SetMajorPolicyVersion(aMajorPolicyVersion,aComparisonOp);
   1.150 +		}
   1.151 +	
   1.152 +	if(aFlag & KSetRecordId)
   1.153 +		{
   1.154 +		aFilter.SetRecordId(aRecordId,aComparisonOp);
   1.155 +		}
   1.156 +	
   1.157 +	if(aFlag & KSetDescription)
   1.158 +		{
   1.159 +		aFilter.SetDescriptionL(aDescription,aComparisonOp);
   1.160 +		}
   1.161 +		
   1.162 +	if(aFlag & KSetResult)
   1.163 +		{
   1.164 +		aFilter.SetResult(aResult,aComparisonOp);
   1.165 +		}
   1.166 +		
   1.167 +	if(aFlag & KSetEvaluatorInfo)
   1.168 +		{
   1.169 +		aFilter.SetEvaluatorInfo(aEvaluatorInfo,aComparisonOp);
   1.170 +		}
   1.171 +	}
   1.172 +
   1.173 +	
   1.174 +CDecisionRecord *CUpsDbBaseStep::CreateRecordL(TInt aClientSid, TInt aEvaluatorId, TInt aServiceId, TInt aServerSid, TDesC8 &aFingerprint, TDesC8 &aClientEntity,
   1.175 +											   TDesC &aDecription, TInt aResult, TInt aMajorPolicyVersion, TInt aEvaluatorInfo, TInt aRecordId)
   1.176 +/**
   1.177 +	Creates a decision record from provided parameters.
   1.178 +	
   1.179 +	@param aClientSid	  Secure Id of client application
   1.180 +	@param aEvaluatorId	  UID for the policy evaluator DLL
   1.181 +	@param aServiceId	  UID for service e.g. sms, mms, telephony, gprs
   1.182 +	@param aServerSid	  UID for the system server that the decision applies to
   1.183 +	@param aFingerprint	  Hash of the destination and/or opaque data. Maximum length is 32 bytes.
   1.184 +	@param aClientEntity  The name of the entity within the client that requested the service. Maximum length is 32 bytes. 
   1.185 +	@param aDescription	  A copy of description and/or opaque. 
   1.186 +	@param aResult		  Whether the request should be approved (=1) or denied (=0)
   1.187 +	@param aMajorPolicyVersion The major version of the policy file.
   1.188 +	@param aEvaluatorInfo Policy evaluator specific data
   1.189 +	@param aRecordId	  An auto-incrementing record number.
   1.190 +	
   1.191 +	@return				  A pointer to the newly allocated decision record object, if creation is successful.
   1.192 +
   1.193 + */
   1.194 +	{
   1.195 +	CDecisionRecord *newRecord;
   1.196 +	
   1.197 +	newRecord = CDecisionRecord::NewL(TSecureId(aClientSid),TUid::Uid(aEvaluatorId),TUid::Uid(aServiceId),TSecureId(aServerSid),aFingerprint,aClientEntity,aDecription,aResult,aMajorPolicyVersion,aEvaluatorInfo, aRecordId);
   1.198 +	
   1.199 +	return newRecord;
   1.200 +	}
   1.201 +
   1.202 +
   1.203 +void CUpsDbBaseStep::StartTimer(TTime &aTime)
   1.204 +/**
   1.205 +	Assigns current time to the provided parameter
   1.206 +	@param aTime Keeps the current time
   1.207 + */
   1.208 +	{
   1.209 +	aTime.HomeTime();
   1.210 +	}
   1.211 +		
   1.212 +
   1.213 +void CUpsDbBaseStep::StopTimer(TTime &aStartTime, TInt64 &aElapsedTime)
   1.214 +/**
   1.215 +	Substracts the provided time from current time and returns the elapsed time.
   1.216 +	@param aStartTime First measured time
   1.217 +	@param aElapsedTime The elapsed time from the first measurement
   1.218 + */
   1.219 +	{
   1.220 +	TTime endTime;
   1.221 +	endTime.HomeTime();
   1.222 +	
   1.223 +	TTimeIntervalMicroSeconds timeDiff = endTime.MicroSecondsFrom(aStartTime);
   1.224 +	aElapsedTime = timeDiff.Int64();
   1.225 +	
   1.226 +	if(iLog)
   1.227 +		{
   1.228 +		_LIT8(KMessage,"%Ld");
   1.229 +		iBuffer.AppendFormat(KMessage,aElapsedTime);
   1.230 +		iFile.Write(iBuffer);
   1.231 +		iFile.Write(_L8(";"));
   1.232 +		iBuffer.Zero();
   1.233 +		}
   1.234 +	}
   1.235 +	
   1.236 +
   1.237 +void CUpsDbBaseStep::FillTableL(CDecisionDbW &aUpsDb, TInt aRecordNum, TInt aClientNum, TInt aServiceNum, TInt aServerNum, TInt aEvaluatorNum)
   1.238 +/**
   1.239 +	Fill the decision table with a specified number of decision records.
   1.240 +	The parameteres are used as seeds to create sample decision records. 
   1.241 +	
   1.242 +	@param aUpsDb		 Handle to the database
   1.243 +	@param aRecordNum	 Number of records which will be inserted into the database
   1.244 +	@param aClientNum	 Number of different clients 
   1.245 +	@param aServiceNum	 Number of different services provided by each server
   1.246 +	@param aServerNum	 Number of different servers
   1.247 +	@param aEvaluatorNum Number of different policy evaluator DLLs
   1.248 + */
   1.249 +	{
   1.250 +	TSecureId clientId = TSecureId(0);
   1.251 +	TSecureId serverId = TSecureId(0);
   1.252 +	TUid serviceId	 =TUid::Null();
   1.253 +	TUid evaluatorId =TUid::Null();
   1.254 +	
   1.255 +	TUint8 result = 0;
   1.256 +	TUint16 policyMajorVersion = 2;
   1.257 +	
   1.258 +	TBuf8<KDbMaxName> bufFP;
   1.259 +	TBuf8<KDbMaxName> bufCE;
   1.260 +	TBuf<KDbMaxName> bufD;
   1.261 +	
   1.262 +	CDecisionRecord* newRecord = NULL;
   1.263 +	
   1.264 +	for(TInt i=0; i<aRecordNum; i++)
   1.265 +		{
   1.266 +		bufFP.AppendFormat(KFingerprint,i);
   1.267 +		bufCE.AppendFormat(KClientEntity,i);
   1.268 +		bufD.AppendFormat(KDescription,i);
   1.269 +		
   1.270 +		CMD5* md5FP = CMD5::NewL();
   1.271 +		CleanupStack::PushL(md5FP);
   1.272 +		
   1.273 +		CMD5* md5CE = CMD5::NewL();
   1.274 +		CleanupStack::PushL(md5CE);
   1.275 +		
   1.276 +		clientId=TSecureId(i%aClientNum + aRecordNum);
   1.277 +		serviceId=TUid::Uid(i%aServiceNum + 10000 + aRecordNum);
   1.278 +		serverId =TSecureId(i%aServerNum + 100000 + aRecordNum);
   1.279 +		evaluatorId = TUid::Uid(i%aEvaluatorNum + 1000000 + aRecordNum);
   1.280 +		
   1.281 +		result = i%2;
   1.282 +		
   1.283 +		newRecord = CDecisionRecord::NewLC(clientId,evaluatorId,serviceId,serverId,md5FP->Hash(bufFP),md5CE->Hash(bufCE),bufD, result,policyMajorVersion, 0);
   1.284 +		
   1.285 +		aUpsDb.CreateDecisionL(*newRecord);
   1.286 +		
   1.287 +		CleanupStack::PopAndDestroy(newRecord);
   1.288 +		CleanupStack::PopAndDestroy(2); //md5FP and md5CE
   1.289 +		
   1.290 +		bufFP.Zero();
   1.291 +		bufCE.Zero();
   1.292 +		bufD.Zero();
   1.293 +		}
   1.294 +	}
   1.295 +	
   1.296 +
   1.297 +CDecisionDbW *CUpsDbBaseStep::CreateDatabaseLC(TDesC& aDbLocation, RFs& aFs)
   1.298 +/**
   1.299 +	Create a writable decision database object. Prints the consumed time to perform this operation.
   1.300 +	
   1.301 +	@param aDbLocation Where the database will be created
   1.302 + */
   1.303 +	{
   1.304 +	TTime startTime;
   1.305 +	//Timer is started
   1.306 +	StartTimer(startTime);
   1.307 +	
   1.308 +	//Database is created
   1.309 +	CDecisionDbW *upsDb = CDecisionDbW::NewLC(aDbLocation, aFs);
   1.310 +	
   1.311 +	//Timer is stopped
   1.312 +	TInt64 elapsedTime = 0;
   1.313 +	StopTimer(startTime,elapsedTime);
   1.314 +	
   1.315 +	INFO_PRINTF2(_L("Decision database created in %Ld microseconds."), elapsedTime);
   1.316 +	
   1.317 +	return upsDb;
   1.318 +	}
   1.319 +	
   1.320 +
   1.321 +CDecisionRecord *CUpsDbBaseStep::GetDecisionLC(CDecisionDbW &aUpsDb, CDecisionFilter &aFilter)
   1.322 +/**
   1.323 +	Get a decision record from the database. This function uses single record lookup method (RDbTable).
   1.324 +	Prints the consumed time to perform this operation.
   1.325 +	
   1.326 +	@param aUpsDb Handle to the database
   1.327 +	@param aFilter Filter
   1.328 + */
   1.329 +	{
   1.330 +	TTime startTime;
   1.331 +	//Timer is started
   1.332 +	StartTimer(startTime);
   1.333 +	
   1.334 +	CDecisionRecord *retRecord = NULL;
   1.335 +	retRecord = aUpsDb.GetDecisionL(aFilter);
   1.336 +	if(retRecord)
   1.337 +		{
   1.338 +		CleanupStack::PushL(retRecord);
   1.339 +		}
   1.340 +	
   1.341 +	//Timer is stopped
   1.342 +	TInt64 elapsedTime = 0;
   1.343 +	StopTimer(startTime,elapsedTime);
   1.344 +	
   1.345 +	if(retRecord)
   1.346 +		{
   1.347 +		INFO_PRINTF2(_L("A single record retrieved in %Ld microseconds."), elapsedTime);
   1.348 +		}
   1.349 +	
   1.350 +	return retRecord;
   1.351 +	}
   1.352 +	
   1.353 +
   1.354 +void CUpsDbBaseStep::GetDecisionsL(CDecisionDbW &aUpsDb, CDecisionFilter &aFilter, TBool aCancel, RPointerArray<CDecisionRecord>& aRecordList)
   1.355 +/**
   1.356 +   Get a set of decision records from the database. Uses multiple records lookup method (RDbView).
   1.357 +   Prints the consumed time to perform this operation.
   1.358 + */
   1.359 +	{
   1.360 +	TTime startTime;
   1.361 +	//Timer is started
   1.362 +	StartTimer(startTime);
   1.363 +	
   1.364 +	CDecisionView *dbView = aUpsDb.CreateViewL(aFilter);
   1.365 +	CleanupStack::PushL(dbView);
   1.366 +
   1.367 +	dbView->EvaluateView(iWaiter->iStatus);
   1.368 +	TInt num = 0;
   1.369 +	if(aCancel)
   1.370 +		{
   1.371 +		dbView->Cancel();
   1.372 +		iWaiter->WaitActiveL(KErrCancel);
   1.373 +		}
   1.374 +	else
   1.375 +		{
   1.376 +		iWaiter->WaitActiveL(KErrNone);
   1.377 +		CDecisionRecord *record = NULL;		
   1.378 +		
   1.379 +		while((record = dbView->NextDecisionL()) != NULL)
   1.380 +			{
   1.381 +			CleanupStack::PushL(record);
   1.382 +			num++;
   1.383 +			aRecordList.AppendL(record);
   1.384 +			CleanupStack::Pop(record);
   1.385 +			}
   1.386 +		}
   1.387 +	
   1.388 +	//Timer is stopped
   1.389 +	TInt64 elapsedTime = 0;
   1.390 +	StopTimer(startTime,elapsedTime);
   1.391 +	
   1.392 +	INFO_PRINTF3(_L("%d records retrieved in %Ld microseconds."), num, elapsedTime);
   1.393 +	CleanupStack::PopAndDestroy(dbView);
   1.394 +	}
   1.395 +	
   1.396 +
   1.397 +void CUpsDbBaseStep::RemoveDecisionsL(CDecisionDbW &aUpsDb, CDecisionFilter &aFilter)
   1.398 +/**
   1.399 +	Delete a set of records. Prints the consumed time to perform this operation.
   1.400 + */
   1.401 +	{
   1.402 +	TTime startTime;
   1.403 +	//Timer is started
   1.404 +	StartTimer(startTime);
   1.405 +	
   1.406 +	aUpsDb.RemoveDecisionsL(aFilter);
   1.407 +	
   1.408 +	//Timer is stopped
   1.409 +	TInt64 elapsedTime = 0;
   1.410 +	StopTimer(startTime,elapsedTime);
   1.411 +	
   1.412 +	INFO_PRINTF2(_L("A set of records deleted in %Ld microseconds."), elapsedTime);
   1.413 +	}
   1.414 +	
   1.415 +	
   1.416 +void CUpsDbBaseStep::RemoveAllDecisionsL(CDecisionDbW &aUpsDb, RFs& aFs)
   1.417 +/**
   1.418 +	Deletes all records in the database. Actually delete all database.
   1.419 +	Prints the consumed time to perform this operation.
   1.420 + */
   1.421 +	{
   1.422 +	TTime startTime;
   1.423 +	//Timer is started
   1.424 +	StartTimer(startTime);
   1.425 +	
   1.426 +	aUpsDb.DeleteDatabaseL(aFs);
   1.427 +	
   1.428 +	//Timer is stopped
   1.429 +	TInt64 elapsedTime = 0;
   1.430 +	StopTimer(startTime,elapsedTime);
   1.431 +	
   1.432 +	INFO_PRINTF2(_L("All records deleted in %Ld microseconds."), elapsedTime);
   1.433 +	}
   1.434 +	
   1.435 +
   1.436 +void CUpsDbBaseStep::InsertRecordL(CDecisionDbW &aUpsDb, CDecisionRecord &aRecord)
   1.437 +/**
   1.438 +	Inserts the provided record into the decision database. Prints the consumed time to perform this operation.
   1.439 + */
   1.440 +	{
   1.441 +	TTime startTime;
   1.442 +	//Timer is started
   1.443 +	StartTimer(startTime);
   1.444 +	
   1.445 +	aUpsDb.CreateDecisionL(aRecord);
   1.446 +	
   1.447 +	//Timer is stopped
   1.448 +	TInt64 elapsedTime = 0;
   1.449 +	StopTimer(startTime,elapsedTime);
   1.450 +	
   1.451 +	INFO_PRINTF2(_L("A record inserted in %Ld microseconds."), elapsedTime);
   1.452 +	}
   1.453 +	
   1.454 +
   1.455 +void CUpsDbBaseStep::ReadConfigurationFile(TDes &aKeyNotFound)
   1.456 +/**
   1.457 +	Reads the key fileds from the ini file which are used to fill table with a specified number of
   1.458 +	sample records.
   1.459 +	@param aKeyNotFound The appended list of the key names which have not been found
   1.460 + */
   1.461 +	{
   1.462 +	
   1.463 +	if(EFalse == GetIntFromConfig(ConfigSection(),KRecordNum, iRecordNum))
   1.464 +		{
   1.465 +		aKeyNotFound.Append(KRecordNum);
   1.466 +		aKeyNotFound.Append(_L(" "));
   1.467 +		}
   1.468 +	else if(EFalse == GetIntFromConfig(ConfigSection(),KServerNum, iServerNum))
   1.469 +		{
   1.470 +		aKeyNotFound.Append(KServerNum);
   1.471 +		aKeyNotFound.Append(_L(" "));
   1.472 +		}
   1.473 +	else if(EFalse == GetIntFromConfig(ConfigSection(),KServiceNum, iServiceNum))
   1.474 +		{
   1.475 +		aKeyNotFound.Append(KServiceNum);
   1.476 +		aKeyNotFound.Append(_L(" "));
   1.477 +		}
   1.478 +	else if(EFalse == GetIntFromConfig(ConfigSection(),KClientNum, iClientNum))
   1.479 +		{
   1.480 +		aKeyNotFound.Append(KClientNum);
   1.481 +		aKeyNotFound.Append(_L(" "));
   1.482 +		}
   1.483 +	else if(EFalse == GetIntFromConfig(ConfigSection(),KEvaluatorNum, iEvaluatorNum))
   1.484 +		{
   1.485 +		aKeyNotFound.Append(KEvaluatorNum);
   1.486 +		aKeyNotFound.Append(_L(" "));
   1.487 +		}
   1.488 +	else if(EFalse == GetIntFromConfig(ConfigSection(),KRetrieveNum, iRetrieveNum))
   1.489 +		{
   1.490 +		aKeyNotFound.Append(KRetrieveNum);
   1.491 +		aKeyNotFound.Append(_L(" "));
   1.492 +		}
   1.493 +	}
   1.494 +
   1.495 +
   1.496 +TInt CUpsDbBaseStep::ConvertNumber(TDesC& aError)
   1.497 +/**
   1.498 +	Converts error string  to number
   1.499 +	@param aError Error string
   1.500 +*/	
   1.501 +		{
   1.502 +		TInt error = KErrNotFound;
   1.503 +		
   1.504 +		if(!aError.CompareF(KStrErrNone))
   1.505 +			{
   1.506 +			error = KErrNone;	
   1.507 +			}
   1.508 +		else if(!aError.CompareF(KStrErrUpsBadFingerprintLength))
   1.509 +			{
   1.510 +			error = KErrUpsBadFingerprintLength;
   1.511 +			}
   1.512 +		else if(!aError.CompareF(KStrErrUpsMissingArgument))
   1.513 +			{
   1.514 +			error = KErrUpsMissingArgument;
   1.515 +			}
   1.516 +		else if(!aError.CompareF(KStrErrUpsBadClientEntityLength))
   1.517 +			{
   1.518 +			error = KErrUpsBadClientEntityLength;
   1.519 +			}
   1.520 +			
   1.521 +		return error;
   1.522 +		}
   1.523 +		
   1.524 +static void PopulateFingerPrint(TDes8& aBuf, TInt aStart)
   1.525 +	{
   1.526 +	TUint8 *ptr = (TUint8 *)aBuf.Ptr();
   1.527 +	
   1.528 +	TInt pos;
   1.529 +	TInt value;
   1.530 +	
   1.531 +	for(pos = 0, value = aStart; pos < KUpsMaxFingerprintLength; ++pos, ++value )
   1.532 +		{
   1.533 +		ptr[pos] = value;
   1.534 +		}
   1.535 +	aBuf.SetLength(pos);	
   1.536 +	}
   1.537 +
   1.538 +void CUpsDbBaseStep::TestFingerprintValuesL(CDecisionDbW& aUpsDb)
   1.539 +/**
   1.540 +	Creates a number of decision records by using all characters 
   1.541 +	between 0x01 and 0xFF in Fingerprint value.
   1.542 + */
   1.543 +
   1.544 +	{
   1.545 +	TInt clientId		= 1;
   1.546 +	TInt serverId		= 2;
   1.547 +	TInt serviceId		= 3;
   1.548 +	TInt evaluatorId	= 4;
   1.549 +	TInt evaluatorInfo	= 5;
   1.550 +	TInt result			= 0;
   1.551 +	TInt policyVersion	= 9;
   1.552 +	TInt recordId		= 0;
   1.553 +	
   1.554 +	CDecisionRecord *record = NULL;
   1.555 +	CDecisionFilter *filter = NULL;
   1.556 +	RPointerArray<CDecisionRecord> recordList;	
   1.557 +	TBuf8<KUpsMaxFingerprintLength> bufFp;
   1.558 +	TBuf8<KUpsMaxClientEntityLength> bufCe;
   1.559 +	TBuf<KUpsDescriptionLength> bufDes;
   1.560 +	bufFp.SetLength(KUpsMaxFingerprintLength);
   1.561 +	bufCe.SetLength(KUpsMaxClientEntityLength);
   1.562 +	TInt flag = KSetClientSid|KSetEvaluatorId|KSetServiceId|KSetServerSid|KSetFingerprint|KSetClientEntity;
   1.563 +	TInt pos = 0;
   1.564 +	
   1.565 +	for(pos=0; pos <= KUpsDescriptionLength+1; pos+= KUpsMaxFingerprintLength)
   1.566 +		{
   1.567 +		PopulateFingerPrint(bufFp, pos);
   1.568 +		record = CreateRecordL(++clientId,++evaluatorId,++serviceId,++serverId, bufFp, bufCe, bufDes, result, policyVersion, evaluatorInfo, recordId);
   1.569 +		CleanupStack::PushL(record);
   1.570 +		InsertRecordL(aUpsDb,*record);
   1.571 +		
   1.572 +		filter = CreateFilterLC(flag,clientId,evaluatorId,serviceId,serverId,bufFp,bufCe,policyVersion,recordId,bufDes,result,evaluatorInfo,EEqual);
   1.573 +		CleanupResetAndDestroyPushL(recordList);
   1.574 +		GetDecisionsL(aUpsDb, *filter, EFalse, recordList);
   1.575 +		if(recordList.Count() != 1)
   1.576 +			{
   1.577 +			SetTestStepResult(EFail);
   1.578 +			CleanupStack::PopAndDestroy(3, record);
   1.579 +			break;
   1.580 +			}		
   1.581 +		CleanupStack::PopAndDestroy(3, record);
   1.582 +		}	
   1.583 +	}
   1.584 +
   1.585 +
   1.586 +void CUpsDbBaseStep::CompactDatabaseL(CDecisionDbW& aUpsDb, TBool aCancel)
   1.587 +/**
   1.588 +	Compacts the decision database.
   1.589 + */
   1.590 +	{
   1.591 +	TTime startTime;
   1.592 +	//Timer is started
   1.593 +	StartTimer(startTime);
   1.594 +	
   1.595 +	CDecisionDbCompactor *dbCompact = aUpsDb.PrepareCompactionLC();
   1.596 +	dbCompact->Compact(iWaiter->iStatus);
   1.597 +	
   1.598 +	if(aCancel)
   1.599 +		{
   1.600 +		dbCompact->Cancel();
   1.601 +		iWaiter->WaitActiveL(KErrCancel);
   1.602 +		}
   1.603 +	else
   1.604 +		{
   1.605 +		iWaiter->WaitActiveL(KErrNone);		
   1.606 +		}
   1.607 +		
   1.608 +	//Timer is stopped
   1.609 +	TInt64 elapsedTime = 0;
   1.610 +	StopTimer(startTime,elapsedTime);
   1.611 +			
   1.612 +	if(iWaiter->iStatus == 0)
   1.613 +		{
   1.614 +		INFO_PRINTF2(_L("Compaction has been achieved in %Ld microseconds."), elapsedTime);
   1.615 +		}
   1.616 +	else
   1.617 +		{
   1.618 +		if(!aCancel && iWaiter->iStatus!=KErrCancel)
   1.619 +			{
   1.620 +			ERR_PRINTF1(_L("Failed to compact database!"));
   1.621 +			SetTestStepResult(EFail);		
   1.622 +			}
   1.623 +		}
   1.624 +		
   1.625 +	CleanupStack::PopAndDestroy(dbCompact);
   1.626 +	}
   1.627 +
   1.628 +
   1.629 +void CUpsDbBaseStep::UpdateRecordL(CDecisionDbW& aUpsDb, CDecisionFilter& aFilter, CDecisionRecord& aRecord)
   1.630 +/**
   1.631 +	Updates a decision record from the decision database.
   1.632 +	
   1.633 +	@param aUpsDb A pointer to the decision database object
   1.634 +	@param aFilter Filter used to find the record which will be updated
   1.635 +	@param aRecord New record containing the values which will be updated
   1.636 + */
   1.637 +	{
   1.638 +	TTime startTime;
   1.639 +	//Timer is started
   1.640 +	StartTimer(startTime);
   1.641 +	
   1.642 +	if(EFalse == aUpsDb.UpdateDecisionL(aFilter,aRecord))
   1.643 +		{
   1.644 +		SetTestStepResult(EFail);
   1.645 +		User::Leave(KErrNotFound);
   1.646 +		}
   1.647 +	else
   1.648 +		{
   1.649 +		//Timer is stopped
   1.650 +		TInt64 elapsedTime = 0;
   1.651 +		StopTimer(startTime,elapsedTime);
   1.652 +		INFO_PRINTF2(_L("The record was updated in %Ld microseconds."), elapsedTime);	
   1.653 +		}
   1.654 +		
   1.655 +	}