os/security/authorisation/userpromptservice/database/test/tupsdb/source/tupsdbstep.cpp
First public contribution.
2 * Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * Performs decision filter, record and database tests
25 #include "tupsdbstep.h"
26 #include <test/testexecutelog.h>
28 using namespace UserPromptService;
31 CUpsDbStepUnitTest::CUpsDbStepUnitTest()
40 CUpsDbStepUnitTest::~CUpsDbStepUnitTest()
46 iFileWriteStream.Close();
47 iFileReadStream.Close();
53 TVerdict CUpsDbStepUnitTest::doTestStepPreambleL()
55 This function is called at the beginning of the test step. First reads the operation type
56 and converts it to a proper enumaration value (TUpsDbUnitTest). Then gets the specified
57 database location. The test fails if the database location can not be found, except
58 the unit tests of the decision record and filter objects.
61 iScheduler = new(ELeave) CActiveScheduler;
62 CActiveScheduler::Install(iScheduler);
63 iWaiter = new(ELeave)CActiveWaiter(Logger());
69 if(EFalse == GetStringFromConfig(ConfigSection(),KOpType,opType))
71 ERR_PRINTF2(_L("Failed to read '%S' key of configuration"),&KOpType);
72 SetTestStepResult(EFail);
75 if(!opType.CompareF(KInsertRecord))
77 iOpType = EInsertRecord;
79 else if(!opType.CompareF(KDeleteRecord))
81 iOpType = EDeleteRecord;
83 else if(!opType.CompareF(KSingleLookup))
85 iOpType = ESingleLookup;
87 else if(!opType.CompareF(KMultipleLookup))
89 iOpType = EMultipleLookup;
91 else if(!opType.CompareF(KVerifyRecord))
93 iOpType = EVerifyRecord;
95 else if(!opType.CompareF(KCreateDatabase))
97 iOpType = ECreateDatabase;
99 else if(!opType.CompareF(KDeleteDatabase))
101 iOpType = EDeleteDatabase;
103 else if(!opType.CompareF(KCreateFilterSingleCall))
105 iOpType = ECreateFilterSingleCall;
107 else if(!opType.CompareF(KCreateFilterMultipleCalls))
109 iOpType = ECreateFilterMultipleCalls;
111 else if(!opType.CompareF(KCreateDecision))
113 iOpType = ECreateDecision;
115 else if(!opType.CompareF(KFillTable))
117 iOpType = EFillTable;
119 else if(!opType.CompareF(KAllFingerprints))
121 iOpType = EAllFingerprints;
123 else if(!opType.CompareF(KCompactDatabase))
127 else if(!opType.CompareF(KUpdateRecord))
133 iOpType = ENotSupported;
136 if(EFalse == GetStringFromConfig(ConfigSection(),KDbLocation,iDbLocation))
138 if((iOpType != ECreateFilterSingleCall) && (iOpType != ECreateDecision) &&
139 (iOpType != ECreateFilterMultipleCalls) && (iOpType != ENotSupported))
141 ERR_PRINTF2(_L("Failed to read '%S' key of configuration"),&KDbLocation);
142 SetTestStepResult(EFail);
143 User::Leave(KErrNotFound);
147 GetBoolFromConfig(ConfigSection(), KOOMCondition,iOOMCondition);
149 User::LeaveIfError(iFs.Connect());
150 User::LeaveIfError(iFs.CreatePrivatePath(EDriveC));
151 return TestStepResult();
155 TVerdict CUpsDbStepUnitTest::doTestStepL()
157 Calls actual test step or OOM test
169 return TestStepResult();
173 TVerdict CUpsDbStepUnitTest::doTestL()
175 Perform the actual test steps. Unit tests for all provided database operations
176 and creation of both filter and decision record objects.
180 //Define required objects
181 CDecisionDbW *upsDb = NULL;
182 CDecisionRecord *record = NULL;
183 CDecisionFilter *filter = NULL;
184 CleanupClosePushL(iFingerprint);
185 CleanupClosePushL(iClientEntity);
189 case ECreateDatabase:
191 //Make sure the database file does not exist
192 iFs.Delete(iDbLocation);
194 //Create the database
195 upsDb = CreateDatabaseLC(iDbLocation, iFs);
198 CleanupStack::PopAndDestroy(upsDb);
202 case EDeleteDatabase:
204 //Connect to the database
205 upsDb = CDecisionDbW::NewL(iDbLocation, iFs);
206 CleanupStack::PushL(upsDb);
208 //Delete all records and database
209 RemoveAllDecisionsL(*upsDb, iFs);
212 CleanupStack::PopAndDestroy(upsDb);
216 case ECreateFilterSingleCall:
218 //Read the decision values from the config file
219 ReadDecisionFieldsL(EFalse);
221 TPtrC strExpectedResult;
222 if(EFalse == GetStringFromConfig(ConfigSection(),KExpectedResult,strExpectedResult))
224 ERR_PRINTF1(_L("Expected result is missing!"));
225 SetTestStepResult(EFail);
228 TInt expectedResult = ConvertNumber(strExpectedResult);
230 //First method is to create a filter with single function call
231 TRAPD(error,filter = CDecisionFilter::NewL(TUid::Uid(iClientSid),TUid::Uid(iEvaluatorId),TUid::Uid(iServiceId),TUid::Uid(iServerSid),iFingerprint,iClientEntity,iMajorPolicyVersion));
233 if(error != expectedResult)
235 ERR_PRINTF3(_L("In the single call method, the result (%d) is different from the expected result (%d)"), error, expectedResult);
236 SetTestStepResult(EFail);
239 if(error == KErrNone)
241 INFO_PRINTF1(_L("Successful to create a decision filter using the single call method"));
246 INFO_PRINTF1(_L("Failed to create a decision filter using the single call method"));
252 case ECreateFilterMultipleCalls:
254 //Read the decision values from the config file
255 ReadDecisionFieldsL(EFalse);
257 TPtrC strExpectedResult;
258 if(EFalse == GetStringFromConfig(ConfigSection(),KExpectedResult,strExpectedResult))
260 ERR_PRINTF1(_L("Expected result is missing!"));
261 SetTestStepResult(EFail);
264 TInt expectedResult = ConvertNumber(strExpectedResult);
266 //Second method is to create an empty filter and then set provided fields
267 TRAPD(error,filter = CreateFilterL(iSetFlag,iClientSid,iEvaluatorId,iServiceId,iServerSid,iFingerprint,iClientEntity,iMajorPolicyVersion,iRecordId,iDescription,iResult,iEvaluatorInfo,iComparison));
269 if(error != expectedResult)
271 ERR_PRINTF3(_L("In the multiple calls method, the result (%d) is different from the expected result (%d)"), error, expectedResult);
272 SetTestStepResult(EFail);
275 if(error == KErrNone)
277 INFO_PRINTF1(_L("Successful to create a decision filter using the multiple calls method"));
282 INFO_PRINTF1(_L("Failed to create a decision filter using the multiple calls method"));
288 case ECreateDecision:
290 //Read the decision values from the config file
291 ReadDecisionFieldsL(EFalse);
293 TPtrC strExpectedResult;
294 if(EFalse == GetStringFromConfig(ConfigSection(),KExpectedResult,strExpectedResult))
296 ERR_PRINTF1(_L("Expected result is missing!"));
297 SetTestStepResult(EFail);
300 TInt expectedResult = ConvertNumber(strExpectedResult);
302 TRAPD(error,record = CreateRecordL(iClientSid,iEvaluatorId,iServiceId,iServerSid,iFingerprint,iClientEntity,iDescription,iResult,iMajorPolicyVersion,iEvaluatorInfo,iRecordId));
304 if(error != expectedResult)
306 ERR_PRINTF3(_L("The result (%d) is different from the expected result (%d)"), error, expectedResult);
307 SetTestStepResult(EFail);
310 if(error == KErrNone)
312 INFO_PRINTF1(_L("Successful to create a decision record"));
317 INFO_PRINTF1(_L("Failed to create a decision record"));
325 //Read the decision values from the config file
326 ReadDecisionFieldsL(ETrue);
328 //ClientSid,EvaluatorId,ServiceId,ServerSid and Fingerprint must be provided
329 if((iSetFlag & (KSetClientSid|KSetEvaluatorId|KSetServiceId|KSetServerSid|KSetFingerprint))!=
330 (KSetClientSid|KSetEvaluatorId|KSetServiceId|KSetServerSid|KSetFingerprint))
332 SetTestStepResult(EFail);
336 //Create decision record
337 record = CreateRecordL(iClientSid,iEvaluatorId,iServiceId,iServerSid,iFingerprint,iClientEntity,iDescription,iResult,iMajorPolicyVersion,iEvaluatorInfo,iRecordId);
338 CleanupStack::PushL(record);
340 //Connect to the database
341 upsDb = CDecisionDbW::NewL(iDbLocation,iFs);
342 CleanupStack::PushL(upsDb);
344 //Insert the decision
345 InsertRecordL(*upsDb, *record);
347 //Disconnect and destroy objects
348 CleanupStack::PopAndDestroy(2,record);
355 //Read the decision values from the config file
356 ReadDecisionFieldsL(ETrue);
360 ERR_PRINTF1(_L("A filter key must be supplied at least!"));
361 SetTestStepResult(EFail);
366 filter = CreateFilterLC(iSetFlag,iClientSid,iEvaluatorId,iServiceId,iServerSid,iFingerprint,iClientEntity,iMajorPolicyVersion,iRecordId,iDescription,iResult,iEvaluatorInfo,iComparison);
368 //Connect to the database
369 upsDb = CDecisionDbW::NewLC(iDbLocation,iFs);
371 //Delete the decision
372 RemoveDecisionsL(*upsDb, *filter);
374 CleanupStack::PopAndDestroy(2,filter);
380 //Read the decision values from the config file
381 ReadDecisionFieldsL(ETrue);
383 TInt expectedRecords;
384 if(EFalse == GetIntFromConfig(ConfigSection(),KExpectedRecords,expectedRecords))
386 ERR_PRINTF1(_L("Expected result is missing!"));
387 SetTestStepResult(EFail);
391 TPtrC strExpectedResult;
392 TInt expectedResult=KErrNone;
393 if(GetStringFromConfig(ConfigSection(),KExpectedResult,strExpectedResult))
395 expectedResult = ConvertNumber(strExpectedResult);
399 filter = CreateFilterL(iSetFlag,iClientSid,iEvaluatorId,iServiceId,iServerSid,iFingerprint,iClientEntity,iMajorPolicyVersion,iRecordId,iDescription,iResult,iEvaluatorInfo,iComparison);
400 CleanupStack::PushL(filter);
402 //Connect to the database
403 upsDb = CDecisionDbW::NewLC(iDbLocation,iFs);
405 //Retrieve single record
406 TRAPD(err,record = GetDecisionLC(*upsDb, *filter);if(record)CleanupStack::Pop(record););
407 if((err==KErrNone)&&(record))
409 CleanupStack::PushL(record);
412 if(err!=expectedResult)
414 SetTestStepResult(EFail);
419 OpenDecisionFileL(EFileWrite);
420 WriteDecisionL(*record);
422 CleanupStack::PopAndDestroy();
428 ERR_PRINTF1(_L("Failed to retrieve a single record"));
429 SetTestStepResult(EFail);
434 CleanupStack::PopAndDestroy(upsDb);
435 CleanupStack::PopAndDestroy(filter);
439 case EMultipleLookup:
441 //Read the decision values from the config file
442 ReadDecisionFieldsL(ETrue);
445 filter = CreateFilterL(iSetFlag,iClientSid,iEvaluatorId,iServiceId,iServerSid,iFingerprint,iClientEntity,iMajorPolicyVersion,iRecordId,iDescription,iResult,iEvaluatorInfo,iComparison);
446 CleanupStack::PushL(filter);
448 //Connect to the database
449 upsDb = CDecisionDbW::NewL(iDbLocation,iFs);
450 CleanupStack::PushL(upsDb);
452 RPointerArray<CDecisionRecord> recordList;
453 CleanupResetAndDestroyPushL(recordList);
454 GetDecisionsL(*upsDb, *filter, iCancel, recordList);
457 recNum = recordList.Count();
460 OpenDecisionFileL(EFileWrite);
462 for(TInt i=0; i<recNum; ++i)
464 WriteDecisionL(*recordList[i]);
468 CleanupStack::PopAndDestroy(&recordList);
470 TInt expectedRecords;
471 if(EFalse == GetIntFromConfig(ConfigSection(),KExpectedRecords,expectedRecords))
476 if(!iCancel && (((expectedRecords>=0) && (recNum != expectedRecords))||((expectedRecords<0) && (recNum<=0))))
478 SetTestStepResult(EFail);
481 CleanupStack::PopAndDestroy(2,filter);
487 //Read the decision values from the config file
488 ReadDecisionFieldsL(ETrue);
489 TBool verified = ETrue;
491 OpenDecisionFileL(EFileRead);
493 while((record = ReadDecisionL()) != NULL)
495 CleanupStack::PushL(record);
497 if(iSetFlag & KSetClientSid)
499 if(record->iClientSid != TSecureId(iClientSid))
506 if(iSetFlag & KSetEvaluatorId)
508 if(record->iEvaluatorId != TUid::Uid(iEvaluatorId))
515 if(iSetFlag & KSetServiceId)
517 if(record->iServiceId != TUid::Uid(iServiceId))
524 if(iSetFlag & KSetServerSid)
526 if(record->iServerSid != TSecureId(iServerSid))
533 if(iSetFlag & KSetFingerprint)
535 if(record->iFingerprint.Compare(iFingerprint))
542 if(iSetFlag & KSetClientEntity)
544 if(record->iClientEntity.Compare(iClientEntity))
551 if(iSetFlag & KSetDescription)
553 if(record->iDescription.Compare(iDescription))
560 if(iSetFlag & KSetResult)
562 if(record->iResult != iResult)
569 if(iSetFlag & KSetEvaluatorInfo)
571 if(record->iEvaluatorInfo != iEvaluatorInfo)
578 if(iSetFlag & KSetMajorPolicyVersion)
580 if(record->iMajorPolicyVersion != iMajorPolicyVersion)
587 if(iSetFlag & KSetRecordId)
589 if(record->iRecordId != iRecordId)
596 CleanupStack::PopAndDestroy(record);
600 if(verified == EFalse)
602 ERR_PRINTF1(_L("Retrieved record(s) is(are) different from the supplied one"));
603 SetTestStepResult(EFail);
604 CleanupStack::PopAndDestroy(record);
608 INFO_PRINTF1(_L("Retrieved record(s) have been verified successfully"));
618 TBuf<KUpsDescriptionLength> keyNotFound;
619 ReadConfigurationFile(keyNotFound);
620 TInt len = keyNotFound.Length();
623 //if more than one keys could not read or retrieve_num is not in the list
624 if((len > 13) || (keyNotFound.Find(KRetrieveNum) == KErrNotFound))
626 ERR_PRINTF2(_L("Failed to read '%S' key of configuration"),&keyNotFound);
627 SetTestStepResult(EFail);
628 User::Leave(KErrNotFound);
631 //Connect to the decision database
632 CDecisionDbW* upsDb = CreateDatabaseLC(iDbLocation,iFs);
634 //Fill the table with a specified number of decision records
635 FillTableL(*upsDb,iRecordNum,iClientNum,iServiceNum,iServerNum,iEvaluatorNum);
638 CleanupStack::PopAndDestroy(upsDb);
642 case EAllFingerprints:
644 //Connect to the decision database
645 CDecisionDbW* upsDb = CreateDatabaseLC(iDbLocation,iFs);
646 TestFingerprintValuesL(*upsDb);
648 CleanupStack::PopAndDestroy(upsDb);
654 ReadDecisionFieldsL(ETrue);
655 //Connect to the decision database
656 CDecisionDbW* upsDb = CreateDatabaseLC(iDbLocation,iFs);
657 CompactDatabaseL(*upsDb,iCancel);
659 CleanupStack::PopAndDestroy(upsDb);
665 //Open the decision file containing the record which will be updated
666 OpenDecisionFileL(EFileRead);
668 record = ReadDecisionL();
669 //Close the decision file
671 //If we could not read the record, the test step fails
674 SetTestStepResult(EFail);
677 CleanupStack::PushL(record);
679 //Create filter from the record which has been read from the decision file
680 TInt flag = (KSetClientSid|KSetEvaluatorId|KSetServiceId|KSetServerSid|KSetFingerprint|KSetClientEntity|KSetMajorPolicyVersion);
681 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);
682 CleanupStack::PushL(filter);
685 ReadDecisionFieldsL(ETrue);
686 //Create a new record from the values in the configuration file
687 CDecisionRecord *newRecord = CreateRecordL(iClientSid,iEvaluatorId,iServiceId,iServerSid,iFingerprint,iClientEntity,iDescription,iResult,iMajorPolicyVersion,iEvaluatorInfo,iRecordId);
688 CleanupStack::PushL(newRecord);
690 //Connect to the decision database
691 CDecisionDbW* upsDb = CreateDatabaseLC(iDbLocation,iFs);
693 UpdateRecordL(*upsDb, *filter, *newRecord);
695 CleanupStack::PopAndDestroy(4, record);
702 ERR_PRINTF1(_L("The provided key is not supported!"));
703 SetTestStepResult(EFail);
708 CleanupStack::PopAndDestroy(2); //Pop RBufs
709 return TestStepResult();
713 TVerdict CUpsDbStepUnitTest::doOOMTestL()
718 TVerdict verdict = EFail;
720 TInt countBefore = 0;
721 for (TInt oomCount = 0; ; oomCount++)
723 INFO_PRINTF2(_L("\n ==== Number of memory allocations %d ===="), oomCount);
726 __UHEAP_SETFAIL(RHeap::EDeterministic, oomCount);
727 countBefore = User::CountAllocCells();
728 TRAPD(error, doTestL());// ----> This is the actual test that runs under OOM conditions.
729 countAfter = User::CountAllocCells();
732 TESTL(error == KErrNone || error == KErrNoMemory);
734 if (error == KErrNone)
737 INFO_PRINTF2(_L("OOM Status %d"),error);
738 INFO_PRINTF1(_L("Test outcome : Passed"));
743 if (countBefore != countAfter)
745 INFO_PRINTF2(_L("OOM Status %d"),error);
746 INFO_PRINTF2(_L("OOM Failed at %d"), oomCount);
747 SetTestStepResult(verdict);
751 INFO_PRINTF2(_L("OOM Failed Point status %d"), error);
753 INFO_PRINTF3(_L("Heap alloc count ok: %d final vs %d initial"), countAfter,countBefore);
754 SetTestStepResult(verdict);
757 User::Leave(KErrGeneral);
763 TVerdict CUpsDbStepUnitTest::doTestStepPostambleL()
765 Runs at the end of the step. Do nothing.
769 return TestStepResult();
773 void CUpsDbStepUnitTest::ReadDecisionFieldsL(TBool aHash)
775 Reads the fileds required to create a decision record or filter.
777 @param aHash Hashes fingerprint and client entity values if ETrue.
780 if(GetHexFromConfig(ConfigSection(),KColClientSid,iClientSid))
782 iSetFlag |= KSetClientSid;
785 if(GetHexFromConfig(ConfigSection(),KColEvaluatorId,iEvaluatorId))
787 iSetFlag |= KSetEvaluatorId;
790 if(GetHexFromConfig(ConfigSection(),KColServiceId,iServiceId))
792 iSetFlag |= KSetServiceId;
795 if(GetHexFromConfig(ConfigSection(),KColServerSid,iServerSid))
797 iSetFlag |= KSetServerSid;
800 TPtrC string; //16-bit temporary pointer
801 CMD5 *md5 = CMD5::NewL();
802 CleanupStack::PushL(md5);
804 if(GetStringFromConfig(ConfigSection(),KColFingerprint,string))
806 if(string.Length() > 0)
808 //Copy to convert 16-bit to 8-bit
809 iFingerprint.CreateL(string.Length()*2);
810 iFingerprint.Copy(string);
813 TPtrC8 hashed = md5->Hash(iFingerprint);
814 if(string.Length()*2 < hashed.Length())
816 iFingerprint.ReAlloc(hashed.Length());
818 iFingerprint.Copy(hashed);
822 iSetFlag |= KSetFingerprint;
825 if(GetStringFromConfig(ConfigSection(),KColClientEntity,string))
827 if(string.Length() > 0)
829 //Copy to convert 16-bit to 8-bit
830 iClientEntity.CreateL(string.Length()*2);
831 iClientEntity.Copy(string);
834 TPtrC8 hashed = md5->Hash(iClientEntity);
835 if(string.Length()*2 < hashed.Length())
837 iClientEntity.ReAlloc(hashed.Length());
839 iClientEntity.Copy(hashed);
842 iSetFlag |= KSetClientEntity;
845 CleanupStack::PopAndDestroy(md5);
847 if(GetStringFromConfig(ConfigSection(),KColDescription,iDescription))
849 iSetFlag |= KSetDescription;
852 if(GetIntFromConfig(ConfigSection(),KColResult,iResult))
854 iSetFlag |= KSetResult;
857 if(GetIntFromConfig(ConfigSection(),KColEvaluatorInfo,iEvaluatorInfo))
859 iSetFlag |= KSetEvaluatorInfo;
862 if(GetIntFromConfig(ConfigSection(),KColMajorPolicyVersion,iMajorPolicyVersion))
864 iSetFlag |= KSetMajorPolicyVersion;
867 if(GetIntFromConfig(ConfigSection(),KColRecordId,iRecordId))
869 iSetFlag |= KSetRecordId;
873 if(GetHexFromConfig(ConfigSection(),KComparison,compOp))
875 iComparison = static_cast<TComparisonOp>(compOp);
878 GetIntFromConfig(ConfigSection(),KCancel,iCancel);
882 void CUpsDbStepUnitTest::OpenDecisionFileL(TFileMode aMode)
884 Opens a log file which is used to write/read decision records.
885 @param aMode File open mode. If EFileWrite, the existed file is replaced with new one.
888 //The file server connection will be closed in the destructor
889 User::LeaveIfError(iFs.CreatePrivatePath(EDriveC));
891 User::LeaveIfError(iFs.PrivatePath(iDecisionFileName));
892 iDecisionFileName.Append(KDecisionFileName);
894 if((aMode & EFileWrite)== EFileWrite)
896 User::LeaveIfError(iFileWriteStream.Replace(iFs,iDecisionFileName,aMode));
898 else if((aMode & EFileRead)== EFileRead)
900 User::LeaveIfError(iFileReadStream.Open(iFs,iDecisionFileName,aMode));
902 //Note that the streams will be closed in the destructor
905 void CUpsDbStepUnitTest::WriteDecisionL(CDecisionRecord &aRecord)
907 Writes a provided decision into the decision log file. This file is then used
908 to verify the written records.
911 iFileWriteStream.WriteInt32L(aRecord.iClientSid.iId);
912 iFileWriteStream.WriteInt32L(aRecord.iEvaluatorId.iUid);
913 iFileWriteStream.WriteInt32L(aRecord.iServiceId.iUid);
914 iFileWriteStream.WriteInt32L(aRecord.iServerSid.iId);
915 iFileWriteStream.WriteUint8L(aRecord.iResult);
916 iFileWriteStream.WriteUint32L(aRecord.iEvaluatorInfo);
917 iFileWriteStream.WriteUint16L(aRecord.iMajorPolicyVersion);
918 iFileWriteStream.WriteUint32L(aRecord.iRecordId);
920 iFileWriteStream.WriteInt16L(aRecord.iFingerprint.Length());
921 iFileWriteStream.WriteL(aRecord.iFingerprint);
923 if(aRecord.iClientEntity.Length())
925 iFileWriteStream.WriteInt16L(aRecord.iClientEntity.Length());
926 iFileWriteStream.WriteL(aRecord.iClientEntity);
930 iFileWriteStream.WriteInt16L(4);
931 iFileWriteStream.WriteL(_L8("NULL"));
934 if(aRecord.iDescription.Length())
936 iFileWriteStream.WriteInt16L(aRecord.iDescription.Length());
937 iFileWriteStream.WriteL(aRecord.iDescription);
941 iFileWriteStream.WriteInt16L(4);
942 iFileWriteStream.WriteL(_L("NULL"));
945 iFileWriteStream.CommitL();
949 CDecisionRecord *CUpsDbStepUnitTest::ReadDecisionL()
951 Reads and returns a decision record from the log file. If reaches the file end, returns NULL.
952 The records retrieved from the log file are compared with the records defined in the configuration file.
956 TBuf8<KDbMaxName> fingerPrint;
957 TBuf8<KDbMaxName> clientEntity;
958 TBuf<KDbMaxName> description;
960 CDecisionRecord *record = NULL;
962 TStreamPos currentPosition = iFileReadStream.Source()->TellL(MStreamBuf::ERead);
963 TStreamPos endPosition = iFileReadStream.Source()->SeekL(MStreamBuf::ERead,EStreamEnd);
965 if(currentPosition == endPosition)
967 INFO_PRINTF1(_L("Reached to the end of the decision file"));
971 iFileReadStream.Source()->SeekL(MStreamBuf::ERead,currentPosition);
972 CleanupClosePushL(iFileReadStream);//In first read a byte is allocated inside the stream, so push it
973 TInt32 clientId = iFileReadStream.ReadInt32L();
974 TInt32 evaluatorId = iFileReadStream.ReadInt32L();
975 TInt32 serviceId = iFileReadStream.ReadInt32L();
976 TInt32 serverId = iFileReadStream.ReadInt32L();
977 TUint8 result = iFileReadStream.ReadUint8L();
978 TUint32 evaluatorInfo = iFileReadStream.ReadUint32L();
979 TUint16 policyMajorVersion = iFileReadStream.ReadUint16L();
980 TUint32 recordId = iFileReadStream.ReadUint32L();
982 len = iFileReadStream.ReadInt16L();
983 iFileReadStream.ReadL(fingerPrint,len);
984 len = iFileReadStream.ReadInt16L();
985 iFileReadStream.ReadL(clientEntity,len);
986 len = iFileReadStream.ReadInt16L();
987 iFileReadStream.ReadL(description,len);
989 if(!clientEntity.Compare(_L8("NULL")))
991 clientEntity.SetLength(0);
994 if(!description.Compare(_L("NULL")))
996 description.SetLength(0);
999 //Create a decision record from readings
1000 record = CreateRecordL((TInt)clientId,(TInt)evaluatorId,(TInt)serviceId,(TInt)serverId,fingerPrint,clientEntity,description,(TInt)result,(TInt)policyMajorVersion,(TInt)evaluatorInfo,(TInt)recordId);
1001 CleanupStack::Pop(&iFileReadStream);
1005 void CUpsDbStepUnitTest::CloseDecisionFile()
1007 Closes the file server session and read/write stream objects
1010 iFileReadStream.Close();
1011 iFileWriteStream.Close();