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