os/security/authorisation/userpromptservice/database/test/tupsdb/source/tupsdbstep.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 /**
    20  @file
    21  @internalComponent
    22 */
    23 
    24 #ifndef TUPSDBSTEP_H
    25 #define TUPSDBSTEP_H
    26 
    27 #include "tupsdb.h"
    28 #include "activewaiter.h"
    29 #include "upsdbw.h"
    30 
    31 #include <test/testexecutelogger.h>
    32 #include <test/tefunit.h>
    33 #include <hash.h>
    34 #include "upscommon.h"
    35 #include <scs/cleanuputils.h>
    36 
    37 using namespace UserPromptService;
    38 
    39 _LIT8(KFingerprint, "FingerprintABCDEFGHIJKLMNOPR%d");
    40 _LIT8(KClientEntity,"ClientEntityABCDEFGHIJKLMNOP%d");
    41 _LIT(KDescription,  "DestinationABCDEFGHIJKLMNOPRSVWXYZ0123456789%d");
    42 _LIT(KDbName,       "tupsdecisions.db");
    43 _LIT(KLogName,       "tperfomance.log");
    44 
    45 //Constants for performance test
    46 _LIT(KServerNum,    "server_num");
    47 _LIT(KServiceNum,   "service_num");
    48 _LIT(KClientNum,    "client_num");
    49 _LIT(KEvaluatorNum, "evaluator_num");
    50 _LIT(KRecordNum,    "records_num");
    51 _LIT(KRetrieveNum,  "retrieve_num");
    52 
    53 //Constants for unit tests
    54 _LIT(KOpType,        "OperationType");
    55 _LIT(KCreateDatabase,"CreateDatabase");
    56 _LIT(KDeleteDatabase,"DeleteDatabase");
    57 _LIT(KCreateFilterSingleCall,  "CreateFilterSingleCall");
    58 _LIT(KCreateFilterMultipleCalls,  "CreateFilterMultipleCalls");
    59 _LIT(KCreateDecision, "CreateDecision");
    60 _LIT(KInsertRecord,   "Insert");
    61 _LIT(KDeleteRecord,   "Delete");
    62 _LIT(KSingleLookup,   "SingleLookup");
    63 _LIT(KMultipleLookup, "MultipleLookup");
    64 _LIT(KVerifyRecord,   "Verify");
    65 _LIT(KFillTable,      "FillTable");
    66 _LIT(KAllFingerprints,"AllFingerprints");
    67 _LIT(KCompactDatabase,"Compact");
    68 _LIT(KUpdateRecord,   "Update");
    69 
    70 
    71 _LIT(KDbLocation,     "DatabaseLocation");
    72 _LIT(KExpectedResult, "ExpectedResult");
    73 _LIT(KExpectedRecords,"ExpectedRecords");
    74 _LIT(KOOMCondition,   "OOMCondition");
    75 _LIT(KComparison,	  "ComparisonOp");
    76 _LIT(KCancel,	      "Cancel");
    77 
    78 _LIT(KStepPerformance, "MeasurePerformance");
    79 _LIT(KStepUnitTest,    "RunUpsDbUnitTest");
    80 _LIT(KDecisionFileName,"decisions.dat");
    81 
    82 //Errors
    83 _LIT(KStrErrNone,    				 "KErrNone");
    84 _LIT(KStrErrUpsBadFingerprintLength, "KErrUpsBadFingerprintLength");
    85 _LIT(KStrErrUpsMissingArgument,		 "KErrUpsMissingArgument");
    86 _LIT(KStrErrUpsBadClientEntityLength,"KErrUpsBadClientEntityLength");
    87 _LIT(KStrErrUpsBadDescriptionLength, "KErrUpsBadDescriptionLength");
    88 
    89 const TInt KMd5Length = 0x10;
    90 
    91 static const TInt KUpsDescriptionLength = 255;
    92 
    93 class CUpsDbBaseStep : public CTestStep
    94 /**
    95 	Implements handy functions used for testing decision database.
    96  */
    97 	{	
    98 protected:
    99 	CUpsDbBaseStep();
   100 	~CUpsDbBaseStep();
   101 	//Start a timer
   102 	void StartTimer(TTime &aTime);
   103 
   104 	//Stops the timer and returns the elapsed time
   105 	void StopTimer(TTime &aStartTime, TInt64 &aElapsedTime);
   106 
   107 	//Fill the decision table with a specified number of sample decision records
   108 	void FillTableL(CDecisionDbW &aUpsDb, TInt aRecordNum, TInt aClientNum, TInt aServiceNum, TInt aServerNum, TInt aEvaluatorNum);
   109 
   110 	//Create a writable decision database object
   111 	CDecisionDbW* CreateDatabaseLC(TDesC &aDbLocation, RFs& aFs);
   112 
   113 	//Get a decision record from the database
   114 	CDecisionRecord *GetDecisionLC(CDecisionDbW &aUpsDb, CDecisionFilter &aFilter);
   115 
   116 	//Get a set of decision records from the database
   117 	void GetDecisionsL(CDecisionDbW &aUpsDb, CDecisionFilter &aFilter, TBool aCancel, RPointerArray<CDecisionRecord>& aRecordList);
   118 
   119 	//Delete a set of records
   120 	void RemoveDecisionsL(CDecisionDbW &aUpsDb, CDecisionFilter &aFilter);	
   121 
   122 	//Delete all records
   123 	void RemoveAllDecisionsL(CDecisionDbW &aUpsDb, RFs& aFs);
   124 
   125 	//Insert a record into the decision database
   126 	void InsertRecordL(CDecisionDbW &aUpsDb, CDecisionRecord &aRecord);
   127 	
   128 	//Creates a filter
   129 	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);
   130 	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);
   131 	
   132 	//Create a decision
   133 	CDecisionRecord *CreateRecordL(TInt aClientId, TInt aEvaluatorId, TInt aServiceId, TInt aServerId, TDesC8 &aFingerPrint, TDesC8 &aClientEntity, 
   134 								   TDesC &aDecription, TInt aResult, TInt aMajorPolicyVersion, TInt aEvaluatorInfo, TInt aRecordId);
   135 	
   136 	//Updates a decision record
   137 	void UpdateRecordL(CDecisionDbW& aUpsDb, CDecisionFilter& aFilter, CDecisionRecord& aRecord);
   138 	
   139 	//Creates a number of decision records by using all characters between 0x01 and 0xFF in Fingerprint value
   140 	void TestFingerprintValuesL(CDecisionDbW& aUpsDb);
   141 	
   142 	//Compacts decision database
   143 	void CompactDatabaseL(CDecisionDbW& aUpsDb, TBool aCancel);
   144 	
   145 	//Assigns member variables from configuration file
   146 	void ReadConfigurationFile(TDes &aKeyNotFound);
   147 	
   148 	//Converts error string  to number
   149 	TInt ConvertNumber(TDesC& aError);
   150 	
   151 private:
   152 	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);
   153 
   154 protected:
   155 	TInt iRecordNum;
   156 	TInt iServerNum;
   157 	TInt iServiceNum;
   158 	TInt iClientNum;
   159 	TInt iEvaluatorNum;
   160 	TInt iRetrieveNum;
   161 	RFs  iFs;
   162 	RFile iFile;
   163 	CActiveScheduler *iScheduler;
   164 	CActiveWaiter	 *iWaiter;
   165 	TBool iLog;
   166 	TBuf8<256> iBuffer;
   167 	};
   168 
   169 class CUpsDbStepPerformance : public CUpsDbBaseStep
   170 //Performs perfomance tests
   171 	{
   172 public:
   173 	CUpsDbStepPerformance();
   174 	~CUpsDbStepPerformance();
   175 	virtual TVerdict doTestStepPreambleL();
   176 	virtual TVerdict doTestStepPostambleL();
   177 	virtual TVerdict doTestStepL();
   178 
   179 private:
   180 	void PrintHeader();
   181 		
   182 private:
   183 	TFileName iDbLocation;
   184 	TFileName iPerformanceLog;
   185 	};
   186 	
   187 class CUpsDbStepUnitTest : public CUpsDbBaseStep
   188 //Performs all unit tests tests
   189 	{
   190 public:
   191 	enum TUpsDbUnitTest
   192 		{
   193 		ENotSupported,	  		    //Requested operation is not supported
   194 		ECreateDatabase,  		    //Create a new database
   195 		EDeleteDatabase,  		    //Delete all records and the database
   196 		ECreateFilterSingleCall,    //Creates a filter object with single call
   197 		ECreateFilterMultipleCalls, //Creates a filter object with multiple call
   198 		ECreateDecision,  			//Creates a decision record object
   199 		EInsertRecord, 	  			//Insert a number of decision
   200 		EDeleteRecord, 	  			//Delete a record from the decision database
   201 		ESingleLookup, 	  			//Lookup for single decision record
   202 		EMultipleLookup,  			//Lookup for multipe decision records
   203 		EVerifyRecord,	 		    //Verify the record read in previous operation
   204 		EFillTable,		  			//Fill anumber of records into the decision table
   205 		EAllFingerprints, 			//Tries all binary values between 0-255 to create a fingerprint
   206 		ECompact,		  			//Compact the decision database
   207 		EUpdate			  			//Update the last retrieved record
   208 		};	
   209 public:
   210 	CUpsDbStepUnitTest();
   211 	~CUpsDbStepUnitTest();
   212 	virtual TVerdict doTestStepPreambleL();
   213 	virtual TVerdict doTestStepPostambleL();
   214 	virtual TVerdict doTestStepL();
   215 	TVerdict doTestL();
   216 	TVerdict doOOMTestL();
   217 
   218 protected:
   219 	void ReadDecisionFieldsL(TBool aHash);
   220 	void OpenDecisionFileL(TFileMode aMode);
   221 	void WriteDecisionL(CDecisionRecord &aRecord);
   222 	CDecisionRecord *ReadDecisionL();
   223 	void CloseDecisionFile();
   224 	
   225 protected:
   226 	TUpsDbUnitTest iOpType;
   227 	TPtrC iDbLocation;
   228 	
   229 	TInt  iClientSid;
   230 	TInt  iEvaluatorId;
   231 	TInt  iServiceId;
   232 	TInt  iServerSid;
   233 	RBuf8 iFingerprint;
   234 	RBuf8 iClientEntity;
   235 	TPtrC iDescription;
   236 	TInt  iResult;
   237 	TInt  iEvaluatorInfo;
   238 	TInt  iMajorPolicyVersion;
   239 	TInt  iRecordId;
   240 	TComparisonOp  iComparison;
   241 	TInt  iSetFlag;
   242 	TBool iOOMCondition;
   243 	TBool iCancel;
   244 	
   245 	TFileName iDecisionFileName;
   246 	RFileWriteStream iFileWriteStream;
   247 	RFileReadStream iFileReadStream;
   248 	};
   249 	
   250 #endif //TUPSDBSTEP_H