sl@0: /* sl@0: * Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * Performs decision filter, record and database tests sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @test sl@0: */ sl@0: sl@0: #include "tupsdbstep.h" sl@0: #include sl@0: sl@0: using namespace UserPromptService; sl@0: sl@0: sl@0: CUpsDbStepUnitTest::CUpsDbStepUnitTest() sl@0: /** sl@0: Constructer sl@0: */ sl@0: { sl@0: iComparison = EEqual; sl@0: iCancel = EFalse; sl@0: } sl@0: sl@0: CUpsDbStepUnitTest::~CUpsDbStepUnitTest() sl@0: /** sl@0: Destructor sl@0: */ sl@0: { sl@0: iFs.Close(); sl@0: iFileWriteStream.Close(); sl@0: iFileReadStream.Close(); sl@0: delete iWaiter; sl@0: delete iScheduler; sl@0: } sl@0: sl@0: sl@0: TVerdict CUpsDbStepUnitTest::doTestStepPreambleL() sl@0: /** sl@0: This function is called at the beginning of the test step. First reads the operation type sl@0: and converts it to a proper enumaration value (TUpsDbUnitTest). Then gets the specified sl@0: database location. The test fails if the database location can not be found, except sl@0: the unit tests of the decision record and filter objects. sl@0: */ sl@0: { sl@0: iScheduler = new(ELeave) CActiveScheduler; sl@0: CActiveScheduler::Install(iScheduler); sl@0: iWaiter = new(ELeave)CActiveWaiter(Logger()); sl@0: sl@0: iLog = EFalse; sl@0: sl@0: TPtrC opType; sl@0: sl@0: if(EFalse == GetStringFromConfig(ConfigSection(),KOpType,opType)) sl@0: { sl@0: ERR_PRINTF2(_L("Failed to read '%S' key of configuration"),&KOpType); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: if(!opType.CompareF(KInsertRecord)) sl@0: { sl@0: iOpType = EInsertRecord; sl@0: } sl@0: else if(!opType.CompareF(KDeleteRecord)) sl@0: { sl@0: iOpType = EDeleteRecord; sl@0: } sl@0: else if(!opType.CompareF(KSingleLookup)) sl@0: { sl@0: iOpType = ESingleLookup; sl@0: } sl@0: else if(!opType.CompareF(KMultipleLookup)) sl@0: { sl@0: iOpType = EMultipleLookup; sl@0: } sl@0: else if(!opType.CompareF(KVerifyRecord)) sl@0: { sl@0: iOpType = EVerifyRecord; sl@0: } sl@0: else if(!opType.CompareF(KCreateDatabase)) sl@0: { sl@0: iOpType = ECreateDatabase; sl@0: } sl@0: else if(!opType.CompareF(KDeleteDatabase)) sl@0: { sl@0: iOpType = EDeleteDatabase; sl@0: } sl@0: else if(!opType.CompareF(KCreateFilterSingleCall)) sl@0: { sl@0: iOpType = ECreateFilterSingleCall; sl@0: } sl@0: else if(!opType.CompareF(KCreateFilterMultipleCalls)) sl@0: { sl@0: iOpType = ECreateFilterMultipleCalls; sl@0: } sl@0: else if(!opType.CompareF(KCreateDecision)) sl@0: { sl@0: iOpType = ECreateDecision; sl@0: } sl@0: else if(!opType.CompareF(KFillTable)) sl@0: { sl@0: iOpType = EFillTable; sl@0: } sl@0: else if(!opType.CompareF(KAllFingerprints)) sl@0: { sl@0: iOpType = EAllFingerprints; sl@0: } sl@0: else if(!opType.CompareF(KCompactDatabase)) sl@0: { sl@0: iOpType = ECompact; sl@0: } sl@0: else if(!opType.CompareF(KUpdateRecord)) sl@0: { sl@0: iOpType = EUpdate; sl@0: } sl@0: else sl@0: { sl@0: iOpType = ENotSupported; sl@0: } sl@0: sl@0: if(EFalse == GetStringFromConfig(ConfigSection(),KDbLocation,iDbLocation)) sl@0: { sl@0: if((iOpType != ECreateFilterSingleCall) && (iOpType != ECreateDecision) && sl@0: (iOpType != ECreateFilterMultipleCalls) && (iOpType != ENotSupported)) sl@0: { sl@0: ERR_PRINTF2(_L("Failed to read '%S' key of configuration"),&KDbLocation); sl@0: SetTestStepResult(EFail); sl@0: User::Leave(KErrNotFound); sl@0: } sl@0: } sl@0: sl@0: GetBoolFromConfig(ConfigSection(), KOOMCondition,iOOMCondition); sl@0: sl@0: User::LeaveIfError(iFs.Connect()); sl@0: User::LeaveIfError(iFs.CreatePrivatePath(EDriveC)); sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: sl@0: TVerdict CUpsDbStepUnitTest::doTestStepL() sl@0: /** sl@0: Calls actual test step or OOM test sl@0: */ sl@0: { sl@0: if (!iOOMCondition) sl@0: { sl@0: doTestL(); sl@0: } sl@0: else sl@0: { sl@0: return doOOMTestL(); sl@0: } sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: sl@0: TVerdict CUpsDbStepUnitTest::doTestL() sl@0: /** sl@0: Perform the actual test steps. Unit tests for all provided database operations sl@0: and creation of both filter and decision record objects. sl@0: */ sl@0: { sl@0: sl@0: //Define required objects sl@0: CDecisionDbW *upsDb = NULL; sl@0: CDecisionRecord *record = NULL; sl@0: CDecisionFilter *filter = NULL; sl@0: CleanupClosePushL(iFingerprint); sl@0: CleanupClosePushL(iClientEntity); sl@0: sl@0: switch(iOpType) sl@0: { sl@0: case ECreateDatabase: sl@0: { sl@0: //Make sure the database file does not exist sl@0: iFs.Delete(iDbLocation); sl@0: sl@0: //Create the database sl@0: upsDb = CreateDatabaseLC(iDbLocation, iFs); sl@0: sl@0: //Disconnect sl@0: CleanupStack::PopAndDestroy(upsDb); sl@0: break; sl@0: } sl@0: sl@0: case EDeleteDatabase: sl@0: { sl@0: //Connect to the database sl@0: upsDb = CDecisionDbW::NewL(iDbLocation, iFs); sl@0: CleanupStack::PushL(upsDb); sl@0: sl@0: //Delete all records and database sl@0: RemoveAllDecisionsL(*upsDb, iFs); sl@0: sl@0: //Disconnect sl@0: CleanupStack::PopAndDestroy(upsDb); sl@0: break; sl@0: } sl@0: sl@0: case ECreateFilterSingleCall: sl@0: { sl@0: //Read the decision values from the config file sl@0: ReadDecisionFieldsL(EFalse); sl@0: sl@0: TPtrC strExpectedResult; sl@0: if(EFalse == GetStringFromConfig(ConfigSection(),KExpectedResult,strExpectedResult)) sl@0: { sl@0: ERR_PRINTF1(_L("Expected result is missing!")); sl@0: SetTestStepResult(EFail); sl@0: break; sl@0: } sl@0: TInt expectedResult = ConvertNumber(strExpectedResult); sl@0: sl@0: //First method is to create a filter with single function call sl@0: TRAPD(error,filter = CDecisionFilter::NewL(TUid::Uid(iClientSid),TUid::Uid(iEvaluatorId),TUid::Uid(iServiceId),TUid::Uid(iServerSid),iFingerprint,iClientEntity,iMajorPolicyVersion)); sl@0: sl@0: if(error != expectedResult) sl@0: { sl@0: ERR_PRINTF3(_L("In the single call method, the result (%d) is different from the expected result (%d)"), error, expectedResult); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: if(error == KErrNone) sl@0: { sl@0: INFO_PRINTF1(_L("Successful to create a decision filter using the single call method")); sl@0: delete filter; sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Failed to create a decision filter using the single call method")); sl@0: } sl@0: sl@0: break; sl@0: } sl@0: sl@0: case ECreateFilterMultipleCalls: sl@0: { sl@0: //Read the decision values from the config file sl@0: ReadDecisionFieldsL(EFalse); sl@0: sl@0: TPtrC strExpectedResult; sl@0: if(EFalse == GetStringFromConfig(ConfigSection(),KExpectedResult,strExpectedResult)) sl@0: { sl@0: ERR_PRINTF1(_L("Expected result is missing!")); sl@0: SetTestStepResult(EFail); sl@0: break; sl@0: } sl@0: TInt expectedResult = ConvertNumber(strExpectedResult); sl@0: sl@0: //Second method is to create an empty filter and then set provided fields sl@0: TRAPD(error,filter = CreateFilterL(iSetFlag,iClientSid,iEvaluatorId,iServiceId,iServerSid,iFingerprint,iClientEntity,iMajorPolicyVersion,iRecordId,iDescription,iResult,iEvaluatorInfo,iComparison)); sl@0: sl@0: if(error != expectedResult) sl@0: { sl@0: ERR_PRINTF3(_L("In the multiple calls method, the result (%d) is different from the expected result (%d)"), error, expectedResult); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: if(error == KErrNone) sl@0: { sl@0: INFO_PRINTF1(_L("Successful to create a decision filter using the multiple calls method")); sl@0: delete filter; sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Failed to create a decision filter using the multiple calls method")); sl@0: } sl@0: sl@0: break; sl@0: } sl@0: sl@0: case ECreateDecision: sl@0: { sl@0: //Read the decision values from the config file sl@0: ReadDecisionFieldsL(EFalse); sl@0: sl@0: TPtrC strExpectedResult; sl@0: if(EFalse == GetStringFromConfig(ConfigSection(),KExpectedResult,strExpectedResult)) sl@0: { sl@0: ERR_PRINTF1(_L("Expected result is missing!")); sl@0: SetTestStepResult(EFail); sl@0: break; sl@0: } sl@0: TInt expectedResult = ConvertNumber(strExpectedResult); sl@0: sl@0: TRAPD(error,record = CreateRecordL(iClientSid,iEvaluatorId,iServiceId,iServerSid,iFingerprint,iClientEntity,iDescription,iResult,iMajorPolicyVersion,iEvaluatorInfo,iRecordId)); sl@0: sl@0: if(error != expectedResult) sl@0: { sl@0: ERR_PRINTF3(_L("The result (%d) is different from the expected result (%d)"), error, expectedResult); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: if(error == KErrNone) sl@0: { sl@0: INFO_PRINTF1(_L("Successful to create a decision record")); sl@0: delete record; sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Failed to create a decision record")); sl@0: } sl@0: sl@0: break; sl@0: } sl@0: sl@0: case EInsertRecord: sl@0: { sl@0: //Read the decision values from the config file sl@0: ReadDecisionFieldsL(ETrue); sl@0: sl@0: //ClientSid,EvaluatorId,ServiceId,ServerSid and Fingerprint must be provided sl@0: if((iSetFlag & (KSetClientSid|KSetEvaluatorId|KSetServiceId|KSetServerSid|KSetFingerprint))!= sl@0: (KSetClientSid|KSetEvaluatorId|KSetServiceId|KSetServerSid|KSetFingerprint)) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: break; sl@0: } sl@0: sl@0: //Create decision record sl@0: record = CreateRecordL(iClientSid,iEvaluatorId,iServiceId,iServerSid,iFingerprint,iClientEntity,iDescription,iResult,iMajorPolicyVersion,iEvaluatorInfo,iRecordId); sl@0: CleanupStack::PushL(record); sl@0: sl@0: //Connect to the database sl@0: upsDb = CDecisionDbW::NewL(iDbLocation,iFs); sl@0: CleanupStack::PushL(upsDb); sl@0: sl@0: //Insert the decision sl@0: InsertRecordL(*upsDb, *record); sl@0: sl@0: //Disconnect and destroy objects sl@0: CleanupStack::PopAndDestroy(2,record); sl@0: sl@0: break; sl@0: } sl@0: sl@0: case EDeleteRecord: sl@0: { sl@0: //Read the decision values from the config file sl@0: ReadDecisionFieldsL(ETrue); sl@0: sl@0: if(!iSetFlag) sl@0: { sl@0: ERR_PRINTF1(_L("A filter key must be supplied at least!")); sl@0: SetTestStepResult(EFail); sl@0: break; sl@0: } sl@0: sl@0: //Create filter sl@0: filter = CreateFilterLC(iSetFlag,iClientSid,iEvaluatorId,iServiceId,iServerSid,iFingerprint,iClientEntity,iMajorPolicyVersion,iRecordId,iDescription,iResult,iEvaluatorInfo,iComparison); sl@0: sl@0: //Connect to the database sl@0: upsDb = CDecisionDbW::NewLC(iDbLocation,iFs); sl@0: sl@0: //Delete the decision sl@0: RemoveDecisionsL(*upsDb, *filter); sl@0: sl@0: CleanupStack::PopAndDestroy(2,filter); sl@0: break; sl@0: } sl@0: sl@0: case ESingleLookup: sl@0: { sl@0: //Read the decision values from the config file sl@0: ReadDecisionFieldsL(ETrue); sl@0: sl@0: TInt expectedRecords; sl@0: if(EFalse == GetIntFromConfig(ConfigSection(),KExpectedRecords,expectedRecords)) sl@0: { sl@0: ERR_PRINTF1(_L("Expected result is missing!")); sl@0: SetTestStepResult(EFail); sl@0: break; sl@0: } sl@0: sl@0: TPtrC strExpectedResult; sl@0: TInt expectedResult=KErrNone; sl@0: if(GetStringFromConfig(ConfigSection(),KExpectedResult,strExpectedResult)) sl@0: { sl@0: expectedResult = ConvertNumber(strExpectedResult); sl@0: } sl@0: sl@0: //Create filter sl@0: filter = CreateFilterL(iSetFlag,iClientSid,iEvaluatorId,iServiceId,iServerSid,iFingerprint,iClientEntity,iMajorPolicyVersion,iRecordId,iDescription,iResult,iEvaluatorInfo,iComparison); sl@0: CleanupStack::PushL(filter); sl@0: sl@0: //Connect to the database sl@0: upsDb = CDecisionDbW::NewLC(iDbLocation,iFs); sl@0: sl@0: //Retrieve single record sl@0: TRAPD(err,record = GetDecisionLC(*upsDb, *filter);if(record)CleanupStack::Pop(record);); sl@0: if((err==KErrNone)&&(record)) sl@0: { sl@0: CleanupStack::PushL(record); sl@0: } sl@0: sl@0: if(err!=expectedResult) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: if(record) sl@0: { sl@0: OpenDecisionFileL(EFileWrite); sl@0: WriteDecisionL(*record); sl@0: CloseDecisionFile(); sl@0: CleanupStack::PopAndDestroy(); sl@0: } sl@0: else sl@0: { sl@0: if(expectedRecords) sl@0: { sl@0: ERR_PRINTF1(_L("Failed to retrieve a single record")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: } sl@0: sl@0: sl@0: CleanupStack::PopAndDestroy(upsDb); sl@0: CleanupStack::PopAndDestroy(filter); sl@0: break; sl@0: } sl@0: sl@0: case EMultipleLookup: sl@0: { sl@0: //Read the decision values from the config file sl@0: ReadDecisionFieldsL(ETrue); sl@0: sl@0: //Create filter sl@0: filter = CreateFilterL(iSetFlag,iClientSid,iEvaluatorId,iServiceId,iServerSid,iFingerprint,iClientEntity,iMajorPolicyVersion,iRecordId,iDescription,iResult,iEvaluatorInfo,iComparison); sl@0: CleanupStack::PushL(filter); sl@0: sl@0: //Connect to the database sl@0: upsDb = CDecisionDbW::NewL(iDbLocation,iFs); sl@0: CleanupStack::PushL(upsDb); sl@0: sl@0: RPointerArray recordList; sl@0: CleanupResetAndDestroyPushL(recordList); sl@0: GetDecisionsL(*upsDb, *filter, iCancel, recordList); sl@0: sl@0: TInt recNum; sl@0: recNum = recordList.Count(); sl@0: if(recNum) sl@0: { sl@0: OpenDecisionFileL(EFileWrite); sl@0: sl@0: for(TInt i=0; i=0) && (recNum != expectedRecords))||((expectedRecords<0) && (recNum<=0)))) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(2,filter); sl@0: break; sl@0: } sl@0: sl@0: case EVerifyRecord: sl@0: { sl@0: //Read the decision values from the config file sl@0: ReadDecisionFieldsL(ETrue); sl@0: TBool verified = ETrue; sl@0: sl@0: OpenDecisionFileL(EFileRead); sl@0: sl@0: while((record = ReadDecisionL()) != NULL) sl@0: { sl@0: CleanupStack::PushL(record); sl@0: sl@0: if(iSetFlag & KSetClientSid) sl@0: { sl@0: if(record->iClientSid != TSecureId(iClientSid)) sl@0: { sl@0: verified = EFalse; sl@0: break; sl@0: } sl@0: } sl@0: sl@0: if(iSetFlag & KSetEvaluatorId) sl@0: { sl@0: if(record->iEvaluatorId != TUid::Uid(iEvaluatorId)) sl@0: { sl@0: verified = EFalse; sl@0: break; sl@0: } sl@0: } sl@0: sl@0: if(iSetFlag & KSetServiceId) sl@0: { sl@0: if(record->iServiceId != TUid::Uid(iServiceId)) sl@0: { sl@0: verified = EFalse; sl@0: break; sl@0: } sl@0: } sl@0: sl@0: if(iSetFlag & KSetServerSid) sl@0: { sl@0: if(record->iServerSid != TSecureId(iServerSid)) sl@0: { sl@0: verified = EFalse; sl@0: break; sl@0: } sl@0: } sl@0: sl@0: if(iSetFlag & KSetFingerprint) sl@0: { sl@0: if(record->iFingerprint.Compare(iFingerprint)) sl@0: { sl@0: verified = EFalse; sl@0: break; sl@0: } sl@0: } sl@0: sl@0: if(iSetFlag & KSetClientEntity) sl@0: { sl@0: if(record->iClientEntity.Compare(iClientEntity)) sl@0: { sl@0: verified = EFalse; sl@0: break; sl@0: } sl@0: } sl@0: sl@0: if(iSetFlag & KSetDescription) sl@0: { sl@0: if(record->iDescription.Compare(iDescription)) sl@0: { sl@0: verified = EFalse; sl@0: break; sl@0: } sl@0: } sl@0: sl@0: if(iSetFlag & KSetResult) sl@0: { sl@0: if(record->iResult != iResult) sl@0: { sl@0: verified = EFalse; sl@0: break; sl@0: } sl@0: } sl@0: sl@0: if(iSetFlag & KSetEvaluatorInfo) sl@0: { sl@0: if(record->iEvaluatorInfo != iEvaluatorInfo) sl@0: { sl@0: verified = EFalse; sl@0: break; sl@0: } sl@0: } sl@0: sl@0: if(iSetFlag & KSetMajorPolicyVersion) sl@0: { sl@0: if(record->iMajorPolicyVersion != iMajorPolicyVersion) sl@0: { sl@0: verified = EFalse; sl@0: break; sl@0: } sl@0: } sl@0: sl@0: if(iSetFlag & KSetRecordId) sl@0: { sl@0: if(record->iRecordId != iRecordId) sl@0: { sl@0: verified = EFalse; sl@0: break; sl@0: } sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(record); sl@0: }//while sl@0: sl@0: sl@0: if(verified == EFalse) sl@0: { sl@0: ERR_PRINTF1(_L("Retrieved record(s) is(are) different from the supplied one")); sl@0: SetTestStepResult(EFail); sl@0: CleanupStack::PopAndDestroy(record); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Retrieved record(s) have been verified successfully")); sl@0: } sl@0: sl@0: CloseDecisionFile(); sl@0: sl@0: break; sl@0: } sl@0: sl@0: case EFillTable: sl@0: { sl@0: TBuf keyNotFound; sl@0: ReadConfigurationFile(keyNotFound); sl@0: TInt len = keyNotFound.Length(); sl@0: if(len > 0) sl@0: { sl@0: //if more than one keys could not read or retrieve_num is not in the list sl@0: if((len > 13) || (keyNotFound.Find(KRetrieveNum) == KErrNotFound)) sl@0: { sl@0: ERR_PRINTF2(_L("Failed to read '%S' key of configuration"),&keyNotFound); sl@0: SetTestStepResult(EFail); sl@0: User::Leave(KErrNotFound); sl@0: } sl@0: } sl@0: //Connect to the decision database sl@0: CDecisionDbW* upsDb = CreateDatabaseLC(iDbLocation,iFs); sl@0: sl@0: //Fill the table with a specified number of decision records sl@0: FillTableL(*upsDb,iRecordNum,iClientNum,iServiceNum,iServerNum,iEvaluatorNum); sl@0: sl@0: //Disconnect sl@0: CleanupStack::PopAndDestroy(upsDb); sl@0: break; sl@0: } sl@0: sl@0: case EAllFingerprints: sl@0: { sl@0: //Connect to the decision database sl@0: CDecisionDbW* upsDb = CreateDatabaseLC(iDbLocation,iFs); sl@0: TestFingerprintValuesL(*upsDb); sl@0: //Disconnect sl@0: CleanupStack::PopAndDestroy(upsDb); sl@0: break; sl@0: } sl@0: sl@0: case ECompact: sl@0: { sl@0: ReadDecisionFieldsL(ETrue); sl@0: //Connect to the decision database sl@0: CDecisionDbW* upsDb = CreateDatabaseLC(iDbLocation,iFs); sl@0: CompactDatabaseL(*upsDb,iCancel); sl@0: //Disconnect sl@0: CleanupStack::PopAndDestroy(upsDb); sl@0: break; sl@0: } sl@0: sl@0: case EUpdate: sl@0: { sl@0: //Open the decision file containing the record which will be updated sl@0: OpenDecisionFileL(EFileRead); sl@0: //Read the record sl@0: record = ReadDecisionL(); sl@0: //Close the decision file sl@0: CloseDecisionFile(); sl@0: //If we could not read the record, the test step fails sl@0: if(!record) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: break; sl@0: } sl@0: CleanupStack::PushL(record); sl@0: sl@0: //Create filter from the record which has been read from the decision file sl@0: TInt flag = (KSetClientSid|KSetEvaluatorId|KSetServiceId|KSetServerSid|KSetFingerprint|KSetClientEntity|KSetMajorPolicyVersion); sl@0: filter = CreateFilterL(flag,record->iClientSid.iId,record->iEvaluatorId.iUid,record->iServiceId.iUid,record->iServerSid.iId,record->iFingerprint,record->iClientEntity,record->iMajorPolicyVersion,record->iRecordId,iDescription,iResult,iEvaluatorInfo,iComparison); sl@0: CleanupStack::PushL(filter); sl@0: sl@0: //Create a new file sl@0: ReadDecisionFieldsL(ETrue); sl@0: //Create a new record from the values in the configuration file sl@0: CDecisionRecord *newRecord = CreateRecordL(iClientSid,iEvaluatorId,iServiceId,iServerSid,iFingerprint,iClientEntity,iDescription,iResult,iMajorPolicyVersion,iEvaluatorInfo,iRecordId); sl@0: CleanupStack::PushL(newRecord); sl@0: sl@0: //Connect to the decision database sl@0: CDecisionDbW* upsDb = CreateDatabaseLC(iDbLocation,iFs); sl@0: //Update the record sl@0: UpdateRecordL(*upsDb, *filter, *newRecord); sl@0: sl@0: CleanupStack::PopAndDestroy(4, record); sl@0: sl@0: break; sl@0: } sl@0: sl@0: case ENotSupported: sl@0: { sl@0: ERR_PRINTF1(_L("The provided key is not supported!")); sl@0: SetTestStepResult(EFail); sl@0: break; sl@0: } sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(2); //Pop RBufs sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: sl@0: TVerdict CUpsDbStepUnitTest::doOOMTestL() sl@0: /** sl@0: Performs OOM test sl@0: */ sl@0: { sl@0: TVerdict verdict = EFail; sl@0: TInt countAfter = 0; sl@0: TInt countBefore = 0; sl@0: for (TInt oomCount = 0; ; oomCount++) sl@0: { sl@0: INFO_PRINTF2(_L("\n ==== Number of memory allocations %d ===="), oomCount); sl@0: verdict = EFail; sl@0: __UHEAP_RESET; sl@0: __UHEAP_SETFAIL(RHeap::EDeterministic, oomCount); sl@0: countBefore = User::CountAllocCells(); sl@0: TRAPD(error, doTestL());// ----> This is the actual test that runs under OOM conditions. sl@0: countAfter = User::CountAllocCells(); sl@0: __UHEAP_RESET; sl@0: sl@0: TESTL(error == KErrNone || error == KErrNoMemory); sl@0: sl@0: if (error == KErrNone) sl@0: { sl@0: verdict = EPass; sl@0: INFO_PRINTF2(_L("OOM Status %d"),error); sl@0: INFO_PRINTF1(_L("Test outcome : Passed")); sl@0: break; sl@0: } sl@0: else sl@0: { sl@0: if (countBefore != countAfter) sl@0: { sl@0: INFO_PRINTF2(_L("OOM Status %d"),error); sl@0: INFO_PRINTF2(_L("OOM Failed at %d"), oomCount); sl@0: SetTestStepResult(verdict); sl@0: break; sl@0: } sl@0: } sl@0: INFO_PRINTF2(_L("OOM Failed Point status %d"), error); sl@0: } sl@0: INFO_PRINTF3(_L("Heap alloc count ok: %d final vs %d initial"), countAfter,countBefore); sl@0: SetTestStepResult(verdict); sl@0: if (verdict==EFail) sl@0: { sl@0: User::Leave(KErrGeneral); sl@0: } sl@0: return verdict; sl@0: } sl@0: sl@0: sl@0: TVerdict CUpsDbStepUnitTest::doTestStepPostambleL() sl@0: /** sl@0: Runs at the end of the step. Do nothing. sl@0: */ sl@0: { sl@0: iFs.Close(); sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: sl@0: void CUpsDbStepUnitTest::ReadDecisionFieldsL(TBool aHash) sl@0: /** sl@0: Reads the fileds required to create a decision record or filter. sl@0: sl@0: @param aHash Hashes fingerprint and client entity values if ETrue. sl@0: */ sl@0: { sl@0: if(GetHexFromConfig(ConfigSection(),KColClientSid,iClientSid)) sl@0: { sl@0: iSetFlag |= KSetClientSid; sl@0: } sl@0: sl@0: if(GetHexFromConfig(ConfigSection(),KColEvaluatorId,iEvaluatorId)) sl@0: { sl@0: iSetFlag |= KSetEvaluatorId; sl@0: } sl@0: sl@0: if(GetHexFromConfig(ConfigSection(),KColServiceId,iServiceId)) sl@0: { sl@0: iSetFlag |= KSetServiceId; sl@0: } sl@0: sl@0: if(GetHexFromConfig(ConfigSection(),KColServerSid,iServerSid)) sl@0: { sl@0: iSetFlag |= KSetServerSid; sl@0: } sl@0: sl@0: TPtrC string; //16-bit temporary pointer sl@0: CMD5 *md5 = CMD5::NewL(); sl@0: CleanupStack::PushL(md5); sl@0: sl@0: if(GetStringFromConfig(ConfigSection(),KColFingerprint,string)) sl@0: { sl@0: if(string.Length() > 0) sl@0: { sl@0: //Copy to convert 16-bit to 8-bit sl@0: iFingerprint.CreateL(string.Length()*2); sl@0: iFingerprint.Copy(string); sl@0: if(aHash) sl@0: { sl@0: TPtrC8 hashed = md5->Hash(iFingerprint); sl@0: if(string.Length()*2 < hashed.Length()) sl@0: { sl@0: iFingerprint.ReAlloc(hashed.Length()); sl@0: } sl@0: iFingerprint.Copy(hashed); sl@0: md5->Reset(); sl@0: } sl@0: } sl@0: iSetFlag |= KSetFingerprint; sl@0: } sl@0: sl@0: if(GetStringFromConfig(ConfigSection(),KColClientEntity,string)) sl@0: { sl@0: if(string.Length() > 0) sl@0: { sl@0: //Copy to convert 16-bit to 8-bit sl@0: iClientEntity.CreateL(string.Length()*2); sl@0: iClientEntity.Copy(string); sl@0: if(aHash) sl@0: { sl@0: TPtrC8 hashed = md5->Hash(iClientEntity); sl@0: if(string.Length()*2 < hashed.Length()) sl@0: { sl@0: iClientEntity.ReAlloc(hashed.Length()); sl@0: } sl@0: iClientEntity.Copy(hashed); sl@0: } sl@0: } sl@0: iSetFlag |= KSetClientEntity; sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(md5); sl@0: sl@0: if(GetStringFromConfig(ConfigSection(),KColDescription,iDescription)) sl@0: { sl@0: iSetFlag |= KSetDescription; sl@0: } sl@0: sl@0: if(GetIntFromConfig(ConfigSection(),KColResult,iResult)) sl@0: { sl@0: iSetFlag |= KSetResult; sl@0: } sl@0: sl@0: if(GetIntFromConfig(ConfigSection(),KColEvaluatorInfo,iEvaluatorInfo)) sl@0: { sl@0: iSetFlag |= KSetEvaluatorInfo; sl@0: } sl@0: sl@0: if(GetIntFromConfig(ConfigSection(),KColMajorPolicyVersion,iMajorPolicyVersion)) sl@0: { sl@0: iSetFlag |= KSetMajorPolicyVersion; sl@0: } sl@0: sl@0: if(GetIntFromConfig(ConfigSection(),KColRecordId,iRecordId)) sl@0: { sl@0: iSetFlag |= KSetRecordId; sl@0: } sl@0: sl@0: TInt compOp; sl@0: if(GetHexFromConfig(ConfigSection(),KComparison,compOp)) sl@0: { sl@0: iComparison = static_cast(compOp); sl@0: } sl@0: sl@0: GetIntFromConfig(ConfigSection(),KCancel,iCancel); sl@0: } sl@0: sl@0: sl@0: void CUpsDbStepUnitTest::OpenDecisionFileL(TFileMode aMode) sl@0: /** sl@0: Opens a log file which is used to write/read decision records. sl@0: @param aMode File open mode. If EFileWrite, the existed file is replaced with new one. sl@0: */ sl@0: { sl@0: //The file server connection will be closed in the destructor sl@0: User::LeaveIfError(iFs.CreatePrivatePath(EDriveC)); sl@0: sl@0: User::LeaveIfError(iFs.PrivatePath(iDecisionFileName)); sl@0: iDecisionFileName.Append(KDecisionFileName); sl@0: sl@0: if((aMode & EFileWrite)== EFileWrite) sl@0: { sl@0: User::LeaveIfError(iFileWriteStream.Replace(iFs,iDecisionFileName,aMode)); sl@0: } sl@0: else if((aMode & EFileRead)== EFileRead) sl@0: { sl@0: User::LeaveIfError(iFileReadStream.Open(iFs,iDecisionFileName,aMode)); sl@0: } sl@0: //Note that the streams will be closed in the destructor sl@0: } sl@0: sl@0: void CUpsDbStepUnitTest::WriteDecisionL(CDecisionRecord &aRecord) sl@0: /** sl@0: Writes a provided decision into the decision log file. This file is then used sl@0: to verify the written records. sl@0: */ sl@0: { sl@0: iFileWriteStream.WriteInt32L(aRecord.iClientSid.iId); sl@0: iFileWriteStream.WriteInt32L(aRecord.iEvaluatorId.iUid); sl@0: iFileWriteStream.WriteInt32L(aRecord.iServiceId.iUid); sl@0: iFileWriteStream.WriteInt32L(aRecord.iServerSid.iId); sl@0: iFileWriteStream.WriteUint8L(aRecord.iResult); sl@0: iFileWriteStream.WriteUint32L(aRecord.iEvaluatorInfo); sl@0: iFileWriteStream.WriteUint16L(aRecord.iMajorPolicyVersion); sl@0: iFileWriteStream.WriteUint32L(aRecord.iRecordId); sl@0: sl@0: iFileWriteStream.WriteInt16L(aRecord.iFingerprint.Length()); sl@0: iFileWriteStream.WriteL(aRecord.iFingerprint); sl@0: sl@0: if(aRecord.iClientEntity.Length()) sl@0: { sl@0: iFileWriteStream.WriteInt16L(aRecord.iClientEntity.Length()); sl@0: iFileWriteStream.WriteL(aRecord.iClientEntity); sl@0: } sl@0: else sl@0: { sl@0: iFileWriteStream.WriteInt16L(4); sl@0: iFileWriteStream.WriteL(_L8("NULL")); sl@0: } sl@0: sl@0: if(aRecord.iDescription.Length()) sl@0: { sl@0: iFileWriteStream.WriteInt16L(aRecord.iDescription.Length()); sl@0: iFileWriteStream.WriteL(aRecord.iDescription); sl@0: } sl@0: else sl@0: { sl@0: iFileWriteStream.WriteInt16L(4); sl@0: iFileWriteStream.WriteL(_L("NULL")); sl@0: } sl@0: sl@0: iFileWriteStream.CommitL(); sl@0: } sl@0: sl@0: sl@0: CDecisionRecord *CUpsDbStepUnitTest::ReadDecisionL() sl@0: /** sl@0: Reads and returns a decision record from the log file. If reaches the file end, returns NULL. sl@0: The records retrieved from the log file are compared with the records defined in the configuration file. sl@0: */ sl@0: { sl@0: sl@0: TBuf8 fingerPrint; sl@0: TBuf8 clientEntity; sl@0: TBuf description; sl@0: TInt len; sl@0: CDecisionRecord *record = NULL; sl@0: sl@0: TStreamPos currentPosition = iFileReadStream.Source()->TellL(MStreamBuf::ERead); sl@0: TStreamPos endPosition = iFileReadStream.Source()->SeekL(MStreamBuf::ERead,EStreamEnd); sl@0: sl@0: if(currentPosition == endPosition) sl@0: { sl@0: INFO_PRINTF1(_L("Reached to the end of the decision file")); sl@0: return record; sl@0: } sl@0: sl@0: iFileReadStream.Source()->SeekL(MStreamBuf::ERead,currentPosition); sl@0: CleanupClosePushL(iFileReadStream);//In first read a byte is allocated inside the stream, so push it sl@0: TInt32 clientId = iFileReadStream.ReadInt32L(); sl@0: TInt32 evaluatorId = iFileReadStream.ReadInt32L(); sl@0: TInt32 serviceId = iFileReadStream.ReadInt32L(); sl@0: TInt32 serverId = iFileReadStream.ReadInt32L(); sl@0: TUint8 result = iFileReadStream.ReadUint8L(); sl@0: TUint32 evaluatorInfo = iFileReadStream.ReadUint32L(); sl@0: TUint16 policyMajorVersion = iFileReadStream.ReadUint16L(); sl@0: TUint32 recordId = iFileReadStream.ReadUint32L(); sl@0: sl@0: len = iFileReadStream.ReadInt16L(); sl@0: iFileReadStream.ReadL(fingerPrint,len); sl@0: len = iFileReadStream.ReadInt16L(); sl@0: iFileReadStream.ReadL(clientEntity,len); sl@0: len = iFileReadStream.ReadInt16L(); sl@0: iFileReadStream.ReadL(description,len); sl@0: sl@0: if(!clientEntity.Compare(_L8("NULL"))) sl@0: { sl@0: clientEntity.SetLength(0); sl@0: } sl@0: sl@0: if(!description.Compare(_L("NULL"))) sl@0: { sl@0: description.SetLength(0); sl@0: } sl@0: sl@0: //Create a decision record from readings sl@0: record = CreateRecordL((TInt)clientId,(TInt)evaluatorId,(TInt)serviceId,(TInt)serverId,fingerPrint,clientEntity,description,(TInt)result,(TInt)policyMajorVersion,(TInt)evaluatorInfo,(TInt)recordId); sl@0: CleanupStack::Pop(&iFileReadStream); sl@0: return record; sl@0: } sl@0: sl@0: void CUpsDbStepUnitTest::CloseDecisionFile() sl@0: /** sl@0: Closes the file server session and read/write stream objects sl@0: */ sl@0: { sl@0: iFileReadStream.Close(); sl@0: iFileWriteStream.Close(); sl@0: } sl@0: