os/security/authorisation/userpromptservice/database/test/tupsdb/source/tupsdbstep.h
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/tupsdbstep.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,250 @@
     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 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +/**
    1.23 + @file
    1.24 + @internalComponent
    1.25 +*/
    1.26 +
    1.27 +#ifndef TUPSDBSTEP_H
    1.28 +#define TUPSDBSTEP_H
    1.29 +
    1.30 +#include "tupsdb.h"
    1.31 +#include "activewaiter.h"
    1.32 +#include "upsdbw.h"
    1.33 +
    1.34 +#include <test/testexecutelogger.h>
    1.35 +#include <test/tefunit.h>
    1.36 +#include <hash.h>
    1.37 +#include "upscommon.h"
    1.38 +#include <scs/cleanuputils.h>
    1.39 +
    1.40 +using namespace UserPromptService;
    1.41 +
    1.42 +_LIT8(KFingerprint, "FingerprintABCDEFGHIJKLMNOPR%d");
    1.43 +_LIT8(KClientEntity,"ClientEntityABCDEFGHIJKLMNOP%d");
    1.44 +_LIT(KDescription,  "DestinationABCDEFGHIJKLMNOPRSVWXYZ0123456789%d");
    1.45 +_LIT(KDbName,       "tupsdecisions.db");
    1.46 +_LIT(KLogName,       "tperfomance.log");
    1.47 +
    1.48 +//Constants for performance test
    1.49 +_LIT(KServerNum,    "server_num");
    1.50 +_LIT(KServiceNum,   "service_num");
    1.51 +_LIT(KClientNum,    "client_num");
    1.52 +_LIT(KEvaluatorNum, "evaluator_num");
    1.53 +_LIT(KRecordNum,    "records_num");
    1.54 +_LIT(KRetrieveNum,  "retrieve_num");
    1.55 +
    1.56 +//Constants for unit tests
    1.57 +_LIT(KOpType,        "OperationType");
    1.58 +_LIT(KCreateDatabase,"CreateDatabase");
    1.59 +_LIT(KDeleteDatabase,"DeleteDatabase");
    1.60 +_LIT(KCreateFilterSingleCall,  "CreateFilterSingleCall");
    1.61 +_LIT(KCreateFilterMultipleCalls,  "CreateFilterMultipleCalls");
    1.62 +_LIT(KCreateDecision, "CreateDecision");
    1.63 +_LIT(KInsertRecord,   "Insert");
    1.64 +_LIT(KDeleteRecord,   "Delete");
    1.65 +_LIT(KSingleLookup,   "SingleLookup");
    1.66 +_LIT(KMultipleLookup, "MultipleLookup");
    1.67 +_LIT(KVerifyRecord,   "Verify");
    1.68 +_LIT(KFillTable,      "FillTable");
    1.69 +_LIT(KAllFingerprints,"AllFingerprints");
    1.70 +_LIT(KCompactDatabase,"Compact");
    1.71 +_LIT(KUpdateRecord,   "Update");
    1.72 +
    1.73 +
    1.74 +_LIT(KDbLocation,     "DatabaseLocation");
    1.75 +_LIT(KExpectedResult, "ExpectedResult");
    1.76 +_LIT(KExpectedRecords,"ExpectedRecords");
    1.77 +_LIT(KOOMCondition,   "OOMCondition");
    1.78 +_LIT(KComparison,	  "ComparisonOp");
    1.79 +_LIT(KCancel,	      "Cancel");
    1.80 +
    1.81 +_LIT(KStepPerformance, "MeasurePerformance");
    1.82 +_LIT(KStepUnitTest,    "RunUpsDbUnitTest");
    1.83 +_LIT(KDecisionFileName,"decisions.dat");
    1.84 +
    1.85 +//Errors
    1.86 +_LIT(KStrErrNone,    				 "KErrNone");
    1.87 +_LIT(KStrErrUpsBadFingerprintLength, "KErrUpsBadFingerprintLength");
    1.88 +_LIT(KStrErrUpsMissingArgument,		 "KErrUpsMissingArgument");
    1.89 +_LIT(KStrErrUpsBadClientEntityLength,"KErrUpsBadClientEntityLength");
    1.90 +_LIT(KStrErrUpsBadDescriptionLength, "KErrUpsBadDescriptionLength");
    1.91 +
    1.92 +const TInt KMd5Length = 0x10;
    1.93 +
    1.94 +static const TInt KUpsDescriptionLength = 255;
    1.95 +
    1.96 +class CUpsDbBaseStep : public CTestStep
    1.97 +/**
    1.98 +	Implements handy functions used for testing decision database.
    1.99 + */
   1.100 +	{	
   1.101 +protected:
   1.102 +	CUpsDbBaseStep();
   1.103 +	~CUpsDbBaseStep();
   1.104 +	//Start a timer
   1.105 +	void StartTimer(TTime &aTime);
   1.106 +
   1.107 +	//Stops the timer and returns the elapsed time
   1.108 +	void StopTimer(TTime &aStartTime, TInt64 &aElapsedTime);
   1.109 +
   1.110 +	//Fill the decision table with a specified number of sample decision records
   1.111 +	void FillTableL(CDecisionDbW &aUpsDb, TInt aRecordNum, TInt aClientNum, TInt aServiceNum, TInt aServerNum, TInt aEvaluatorNum);
   1.112 +
   1.113 +	//Create a writable decision database object
   1.114 +	CDecisionDbW* CreateDatabaseLC(TDesC &aDbLocation, RFs& aFs);
   1.115 +
   1.116 +	//Get a decision record from the database
   1.117 +	CDecisionRecord *GetDecisionLC(CDecisionDbW &aUpsDb, CDecisionFilter &aFilter);
   1.118 +
   1.119 +	//Get a set of decision records from the database
   1.120 +	void GetDecisionsL(CDecisionDbW &aUpsDb, CDecisionFilter &aFilter, TBool aCancel, RPointerArray<CDecisionRecord>& aRecordList);
   1.121 +
   1.122 +	//Delete a set of records
   1.123 +	void RemoveDecisionsL(CDecisionDbW &aUpsDb, CDecisionFilter &aFilter);	
   1.124 +
   1.125 +	//Delete all records
   1.126 +	void RemoveAllDecisionsL(CDecisionDbW &aUpsDb, RFs& aFs);
   1.127 +
   1.128 +	//Insert a record into the decision database
   1.129 +	void InsertRecordL(CDecisionDbW &aUpsDb, CDecisionRecord &aRecord);
   1.130 +	
   1.131 +	//Creates a filter
   1.132 +	CDecisionFilter *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.133 +	CDecisionFilter *CreateFilterLC(TInt aFlag, TInt aClientId, TInt aEvaluatorId, TInt aServiceId, TInt aServerId, TDesC8 &aFingerPrint, TDesC8& aClientEntity,TInt aMajorPolicyVersion, TInt aRecordId, TDesC& aDescription, TInt aResult, TInt aEvaluatorInfo, TComparisonOp aComparisonOp);
   1.134 +	
   1.135 +	//Create a decision
   1.136 +	CDecisionRecord *CreateRecordL(TInt aClientId, TInt aEvaluatorId, TInt aServiceId, TInt aServerId, TDesC8 &aFingerPrint, TDesC8 &aClientEntity, 
   1.137 +								   TDesC &aDecription, TInt aResult, TInt aMajorPolicyVersion, TInt aEvaluatorInfo, TInt aRecordId);
   1.138 +	
   1.139 +	//Updates a decision record
   1.140 +	void UpdateRecordL(CDecisionDbW& aUpsDb, CDecisionFilter& aFilter, CDecisionRecord& aRecord);
   1.141 +	
   1.142 +	//Creates a number of decision records by using all characters between 0x01 and 0xFF in Fingerprint value
   1.143 +	void TestFingerprintValuesL(CDecisionDbW& aUpsDb);
   1.144 +	
   1.145 +	//Compacts decision database
   1.146 +	void CompactDatabaseL(CDecisionDbW& aUpsDb, TBool aCancel);
   1.147 +	
   1.148 +	//Assigns member variables from configuration file
   1.149 +	void ReadConfigurationFile(TDes &aKeyNotFound);
   1.150 +	
   1.151 +	//Converts error string  to number
   1.152 +	TInt ConvertNumber(TDesC& aError);
   1.153 +	
   1.154 +private:
   1.155 +	void SetFilterFiledsL(CDecisionFilter &aFilter, TInt aFlag, TInt aClientId, TInt aEvaluatorId, TInt aServiceId, TInt aServerId, TDesC8 &aFingerPrint, TDesC8& aClientEntity,TInt aMajorPolicyVersion, TInt aRecordId, TDesC& aDescription, TInt aResult, TInt aEvaluatorInfo, TComparisonOp aComparisonOp);
   1.156 +
   1.157 +protected:
   1.158 +	TInt iRecordNum;
   1.159 +	TInt iServerNum;
   1.160 +	TInt iServiceNum;
   1.161 +	TInt iClientNum;
   1.162 +	TInt iEvaluatorNum;
   1.163 +	TInt iRetrieveNum;
   1.164 +	RFs  iFs;
   1.165 +	RFile iFile;
   1.166 +	CActiveScheduler *iScheduler;
   1.167 +	CActiveWaiter	 *iWaiter;
   1.168 +	TBool iLog;
   1.169 +	TBuf8<256> iBuffer;
   1.170 +	};
   1.171 +
   1.172 +class CUpsDbStepPerformance : public CUpsDbBaseStep
   1.173 +//Performs perfomance tests
   1.174 +	{
   1.175 +public:
   1.176 +	CUpsDbStepPerformance();
   1.177 +	~CUpsDbStepPerformance();
   1.178 +	virtual TVerdict doTestStepPreambleL();
   1.179 +	virtual TVerdict doTestStepPostambleL();
   1.180 +	virtual TVerdict doTestStepL();
   1.181 +
   1.182 +private:
   1.183 +	void PrintHeader();
   1.184 +		
   1.185 +private:
   1.186 +	TFileName iDbLocation;
   1.187 +	TFileName iPerformanceLog;
   1.188 +	};
   1.189 +	
   1.190 +class CUpsDbStepUnitTest : public CUpsDbBaseStep
   1.191 +//Performs all unit tests tests
   1.192 +	{
   1.193 +public:
   1.194 +	enum TUpsDbUnitTest
   1.195 +		{
   1.196 +		ENotSupported,	  		    //Requested operation is not supported
   1.197 +		ECreateDatabase,  		    //Create a new database
   1.198 +		EDeleteDatabase,  		    //Delete all records and the database
   1.199 +		ECreateFilterSingleCall,    //Creates a filter object with single call
   1.200 +		ECreateFilterMultipleCalls, //Creates a filter object with multiple call
   1.201 +		ECreateDecision,  			//Creates a decision record object
   1.202 +		EInsertRecord, 	  			//Insert a number of decision
   1.203 +		EDeleteRecord, 	  			//Delete a record from the decision database
   1.204 +		ESingleLookup, 	  			//Lookup for single decision record
   1.205 +		EMultipleLookup,  			//Lookup for multipe decision records
   1.206 +		EVerifyRecord,	 		    //Verify the record read in previous operation
   1.207 +		EFillTable,		  			//Fill anumber of records into the decision table
   1.208 +		EAllFingerprints, 			//Tries all binary values between 0-255 to create a fingerprint
   1.209 +		ECompact,		  			//Compact the decision database
   1.210 +		EUpdate			  			//Update the last retrieved record
   1.211 +		};	
   1.212 +public:
   1.213 +	CUpsDbStepUnitTest();
   1.214 +	~CUpsDbStepUnitTest();
   1.215 +	virtual TVerdict doTestStepPreambleL();
   1.216 +	virtual TVerdict doTestStepPostambleL();
   1.217 +	virtual TVerdict doTestStepL();
   1.218 +	TVerdict doTestL();
   1.219 +	TVerdict doOOMTestL();
   1.220 +
   1.221 +protected:
   1.222 +	void ReadDecisionFieldsL(TBool aHash);
   1.223 +	void OpenDecisionFileL(TFileMode aMode);
   1.224 +	void WriteDecisionL(CDecisionRecord &aRecord);
   1.225 +	CDecisionRecord *ReadDecisionL();
   1.226 +	void CloseDecisionFile();
   1.227 +	
   1.228 +protected:
   1.229 +	TUpsDbUnitTest iOpType;
   1.230 +	TPtrC iDbLocation;
   1.231 +	
   1.232 +	TInt  iClientSid;
   1.233 +	TInt  iEvaluatorId;
   1.234 +	TInt  iServiceId;
   1.235 +	TInt  iServerSid;
   1.236 +	RBuf8 iFingerprint;
   1.237 +	RBuf8 iClientEntity;
   1.238 +	TPtrC iDescription;
   1.239 +	TInt  iResult;
   1.240 +	TInt  iEvaluatorInfo;
   1.241 +	TInt  iMajorPolicyVersion;
   1.242 +	TInt  iRecordId;
   1.243 +	TComparisonOp  iComparison;
   1.244 +	TInt  iSetFlag;
   1.245 +	TBool iOOMCondition;
   1.246 +	TBool iCancel;
   1.247 +	
   1.248 +	TFileName iDecisionFileName;
   1.249 +	RFileWriteStream iFileWriteStream;
   1.250 +	RFileReadStream iFileReadStream;
   1.251 +	};
   1.252 +	
   1.253 +#endif //TUPSDBSTEP_H