sl@0: // Copyright (c) 2004-2009 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 "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: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "../sfbs/UTILS.H" sl@0: #include "TSecureFBS.h" sl@0: sl@0: sl@0: sl@0: LOCAL_C RFs fs; sl@0: sl@0: //----------------------TEST DATA------------------------------------- sl@0: //RC_ROM12 is a ROM type mbm sl@0: //RC_RAM16 is a File Store type mbm sl@0: //TFBS inside TFBS_RSC is a File Store type mbm sl@0: //Bitmap for testing purposes sl@0: _LIT(KBmp1_Z,"z:\\system\\data\\RC_ROM12.mbm"); sl@0: _LIT(KBmp2_Z,"z:\\system\\data\\RC_RAM16.mbm"); sl@0: sl@0: //Private path in C: sl@0: _LIT(KBmp2_CP,"c:\\private\\10273364\\RC_RAM16.mbm"); sl@0: //Private path in Z: sl@0: _LIT(KBmp1_ZP,"z:\\private\\10273364\\RC_ROM12.mbm"); sl@0: _LIT(KBmp2_ZP,"z:\\private\\10273364\\RC_RAM16.mbm"); sl@0: _LIT(KRscHeader_ZP,"z:\\private\\10273364\\RscHeader3.bin"); sl@0: _LIT(KDummyRsc_ZP,"z:\\private\\10273364\\DummyRscFile3.rsc"); sl@0: _LIT(KTbsRsc_ZP,"z:\\private\\10273364\\TFBS_RSC.rsc"); sl@0: _LIT(KInvalid_Bitmap,"z:\\private\\10273364\\invalid.mbm"); sl@0: sl@0: //Other private path 00999999 used for data caging test sl@0: _LIT(KBmp1_ZOP,"z:\\private\\00999999\\RC_ROM12.mbm"); sl@0: _LIT(KBmp2_ZOP,"z:\\private\\00999999\\RC_RAM16.mbm"); sl@0: sl@0: _LIT(KPlatsecBegin,"*PlatSec* ERROR - BEGIN NEGATIVE PLATSEC TESTING"); sl@0: _LIT(KPlatsecEnd,"*PlatSec* ERROR - END NEGATIVE PLATSEC TESTING"); sl@0: //--------------------------------------------------------------------- sl@0: sl@0: CTFbsSecure::CTFbsSecure(CTestStep* aStep) : sl@0: CTGraphicsBase(aStep) sl@0: { sl@0: sl@0: } sl@0: sl@0: //--------------------UTILITY Function--------------------------------- sl@0: //This function is here to measure the offset in the rsc file sl@0: TInt CTFbsSecure::FileSizeL(const TDesC& aFileName) sl@0: { sl@0: RFile file; sl@0: User::LeaveIfError(file.Open(fs, aFileName, EFileRead)); sl@0: CleanupClosePushL(file); sl@0: TInt size = 0; sl@0: User::LeaveIfError(file.Size(size)); sl@0: CleanupStack::PopAndDestroy(&file); sl@0: return size; sl@0: } sl@0: sl@0: //--------------------TEST CASE Function------------------------------- sl@0: /** sl@0: sl@0: -Using two type of bitmaps Rom and File Store Bitmap sl@0: -Testing will focus on File Store type bitmap only sl@0: -Loading a bitmap in private data cage, expect KErrNone sl@0: -Loading a bitmap in other private data cage, expect KErrPermissionDenied(-46) sl@0: -Loading a bitmap from a public path, expect KErrNone sl@0: -Loading a bitmap from an rsc file inside the private data path sl@0: */ sl@0: /** sl@0: @SYMTestCaseID sl@0: GRAPHICS-FBSERV-0585 sl@0: sl@0: @SYMTestCaseDesc sl@0: TestCase1 for testing data caging properties. sl@0: sl@0: @SYMTestActions sl@0: Using two type of bitmaps Rom and File Store Bitmap. sl@0: Testing will focus on File Store type bitmap only. sl@0: Loading a bitmap in private data cage, expect KErrNone. sl@0: Loading a bitmap in other private data cage, expect KErrPermissionDenied(-46). sl@0: Loading a bitmap from a public path, expect KErrNone. sl@0: Loading a bitmap from an rsc file inside the private data path. sl@0: sl@0: @SYMTestExpectedResults sl@0: Test should pass sl@0: */ sl@0: void CTFbsSecure::TestCase1() sl@0: { sl@0: INFO_PRINTF1(_L("Test Case 1")); sl@0: TInt skipRomBitmapTests = EFalse; sl@0: TUint32* romAddress = NULL; sl@0: if(!CFbsBitmap::IsFileInRom(KBmp1_ZP, romAddress)) //any ROM bitmap sl@0: { sl@0: INFO_PRINTF2(_L("Skipping ROM bitmap tests since file \"%S\" is reported to not be a ROM bitmap."), sl@0: &KBmp1_ZP); sl@0: INFO_PRINTF1(_L("This should only occur on non-XIP ROMs, e.g. NAND ROMs, where ROM bitmaps aren't supported.")); sl@0: skipRomBitmapTests = ETrue; sl@0: } sl@0: sl@0: TInt ret; sl@0: if(!skipRomBitmapTests) sl@0: { sl@0: //Loading a ROM bitmap from its own private data cage \private\00099999 sl@0: CFbsBitmap bmp1; sl@0: ret=bmp1.Load(KBmp1_ZP,0); sl@0: TEST(ret==KErrNone); sl@0: TEST(bmp1.IsRomBitmap()); sl@0: sl@0: //Loading a ROM bitmap from other private data cage \private\00999999 sl@0: //This test works if PlatSecEnforcement is ON otherwise it will return KErrNone sl@0: CFbsBitmap bmp2; sl@0: ret=bmp2.Load(KBmp1_ZOP,0); sl@0: if (PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement) && PlatSec::IsCapabilityEnforced(ECapabilityAllFiles)) sl@0: TEST(ret==KErrPermissionDenied); sl@0: else sl@0: TEST(ret==KErrNone); sl@0: sl@0: //Loading a ROM bitmap from a public data cage \system\data sl@0: CFbsBitmap bmp3; sl@0: ret=bmp3.Load(KBmp1_Z,0); sl@0: TEST(ret==KErrNone); sl@0: } sl@0: sl@0: //Loading a File Store bitmap from its own private data cage \private\00099999 sl@0: CFbsBitmap bmp4; sl@0: ret=bmp4.Load(KBmp2_ZP,0); sl@0: TEST(ret==KErrNone); sl@0: TEST(!bmp4.IsRomBitmap()); sl@0: sl@0: //Loading a File Store bitmap from other own private data cage \private\00099999 sl@0: CFbsBitmap bmp5; sl@0: ret=bmp5.Load(KBmp2_ZOP,0); sl@0: if (PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement) && PlatSec::IsCapabilityEnforced(ECapabilityAllFiles)) sl@0: TEST(ret==KErrPermissionDenied); sl@0: else sl@0: TEST(ret==KErrNone); sl@0: sl@0: //Loading a File Store bitmap from a public data cage \system\data sl@0: CFbsBitmap bmp6; sl@0: ret=bmp6.Load(KBmp2_Z,0); sl@0: TEST(ret==KErrNone); sl@0: sl@0: //Loading a bitmap file from an rsc file inside the private data path sl@0: CFbsBitmap bmp7; sl@0: TInt fileoffset=0; sl@0: //Getting the file offset for the mbm file embedded inside the rsc sl@0: TRAP(ret,fileoffset=FileSizeL(KRscHeader_ZP)+FileSizeL(KDummyRsc_ZP)); sl@0: TEST(ret==KErrNone); sl@0: ret=bmp7.Load(KTbsRsc_ZP,0,EFalse,fileoffset); sl@0: TEST(ret==KErrNone); sl@0: sl@0: //Loading a File Store bitmap from own private data cage in C: sl@0: CFbsBitmap bmp8; sl@0: ret=bmp8.Load(KBmp2_CP,0); sl@0: TEST(ret==KErrNone); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID sl@0: GRAPHICS-FBSERV-0586 sl@0: sl@0: @SYMTestCaseDesc sl@0: TestCase2 for testing of invalid arguments such as file name,id, file offset sl@0: sl@0: @SYMTestActions sl@0: Test focus on File Store bitmap sl@0: Loading an invalid bitmap file name expect KErrNotFound sl@0: Loading a bitmap with invalid id sl@0: Loading a bitmap with invalid file offset sl@0: sl@0: @SYMTestExpectedResults sl@0: Test should pass sl@0: */ sl@0: void CTFbsSecure::TestCase2() sl@0: { sl@0: INFO_PRINTF1(_L("Test Case 2")); sl@0: TInt ret; sl@0: //Loading an invalid bitmap KInvalid_Bitmap sl@0: CFbsBitmap bmp1; sl@0: ret=bmp1.Load(KInvalid_Bitmap,0); sl@0: TEST(ret==KErrNotFound); sl@0: sl@0: //Loading a bitmap with invalid id,KBmp1_ZP only has one bitmap sl@0: CFbsBitmap bmp2; sl@0: ret=bmp2.Load(KBmp2_ZP,1); sl@0: TEST(ret==KErrEof); sl@0: sl@0: //Loading a bitmap with invalid File offset sl@0: CFbsBitmap bmp3; sl@0: ret=bmp3.Load(KTbsRsc_ZP,0,EFalse,0); sl@0: TEST(ret==KErrNotSupported); sl@0: } sl@0: sl@0: /** sl@0: sl@0: sl@0: */ sl@0: /** sl@0: @SYMTestCaseID sl@0: GRAPHICS-FBSERV-0587 sl@0: sl@0: @SYMTestCaseDesc sl@0: TestCase3 for testing of the sharing of bitmaps using iShareIfLoaded sl@0: this indirectly test the removal of the FileInfo and yet preserver sl@0: preserve the same functionality in 9.0 without any regression sl@0: sl@0: @SYMTestActions sl@0: bmp1 load with iShareIfLoaded=ETrue and bmp2 load same file with ETrue sl@0: Expect the Handle() and DataAddress() to be the same as there will be sl@0: only one raw memory data stored in the global heap for these 2 instances of sl@0: the same bitmap sl@0: sl@0: bmp3 load with iShareIfLoaded=EFalse and bmp4 load same file with ETrue sl@0: Expect the Handle() and DataAddress() to be different as bmp1 does not want sl@0: to share the bitmap,so bmp2 will have its own Handle() and a completely pointer sl@0: to the bitmap raw data sl@0: sl@0: @SYMTestExpectedResults sl@0: Test should pass sl@0: */ sl@0: void CTFbsSecure::TestCase3() sl@0: { sl@0: INFO_PRINTF1(_L("Test Case 3")); sl@0: TInt ret; sl@0: sl@0: //Loading first bitmap with ShareIfLoaded sl@0: CFbsBitmap* bmp1=new (ELeave) CFbsBitmap; sl@0: ret=bmp1->Load(KBmp2_ZP,0,ETrue); sl@0: TEST(ret==KErrNone); sl@0: TEST(!bmp1->IsRomBitmap()); sl@0: sl@0: //Loading second bitmap with ShareIfLoaded sl@0: CFbsBitmap* bmp2=new (ELeave) CFbsBitmap; sl@0: ret-bmp2->Load(KBmp2_ZP,0,ETrue); sl@0: TEST(ret==KErrNone); sl@0: TEST(!bmp2->IsRomBitmap()); sl@0: sl@0: //Test the file sharing properties do exist here sl@0: TEST(bmp1->Handle()==bmp2->Handle()); sl@0: TEST(bmp1->DataAddress()==bmp2->DataAddress()); sl@0: sl@0: TInt fileoffset=0; sl@0: TRAP(ret,fileoffset=FileSizeL(KRscHeader_ZP)+FileSizeL(KDummyRsc_ZP)); sl@0: TEST(ret==KErrNone); sl@0: //Loading third bitmap with NO ShareIfLoaded sl@0: CFbsBitmap* bmp3=new (ELeave) CFbsBitmap; sl@0: ret=bmp3->Load(KTbsRsc_ZP,1,EFalse,fileoffset); sl@0: TEST(ret==KErrNone); sl@0: TEST(!bmp3->IsRomBitmap()); sl@0: sl@0: //Loading fourth bitmap(similar to 3) with ShareIfLoaded sl@0: CFbsBitmap* bmp4=new (ELeave) CFbsBitmap; sl@0: ret=bmp4->Load(KTbsRsc_ZP,1,ETrue,fileoffset); sl@0: TEST(ret==KErrNone); sl@0: TEST(!bmp4->IsRomBitmap()); sl@0: sl@0: //Test the file sharing properties does not exist here sl@0: TEST(bmp3->Handle()!=bmp4->Handle()); sl@0: TEST(bmp3->DataAddress()!=bmp4->DataAddress()); sl@0: sl@0: delete bmp1; sl@0: delete bmp2; sl@0: delete bmp3; sl@0: delete bmp4; sl@0: sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-SYSLIB-FBSERV-CT-0002 sl@0: @SYMTestCaseDesc Testing for the secure bitmap loading in FBSERV sl@0: @SYMTestPriority High sl@0: @SYMTestActions Testing the loading of a bitmap from its own data cage sl@0: Testing for permission denied when loading from other private data sl@0: Testing for invalid arguments sl@0: Testing for bitmap sharing sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMPREQ 280 General Datacaging sl@0: */ sl@0: sl@0: void CTFbsSecure::RunTestCaseL(TInt aCurTestCase) sl@0: { sl@0: ((CTFbsSecureStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName); sl@0: switch(aCurTestCase) sl@0: { sl@0: case 1: sl@0: ((CTFbsSecureStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0585")); sl@0: RDebug::Print(KPlatsecBegin); sl@0: TestCase1(); sl@0: RDebug::Print(KPlatsecEnd); sl@0: break; sl@0: case 2: sl@0: ((CTFbsSecureStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0586")); sl@0: TestCase2(); sl@0: case 3: sl@0: ((CTFbsSecureStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0587")); sl@0: TestCase3(); sl@0: break; sl@0: case 4: sl@0: ((CTFbsSecureStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName); sl@0: ((CTFbsSecureStep*)iStep)->CloseTMSGraphicsStep(); sl@0: TestComplete(); sl@0: break; sl@0: } sl@0: ((CTFbsSecureStep*)iStep)->RecordTestResultL(); sl@0: } sl@0: sl@0: //-------------- sl@0: __CONSTRUCT_STEP__(FbsSecure) sl@0: sl@0: sl@0: void CTFbsSecureStep::TestSetupL() sl@0: { sl@0: User::LeaveIfError(fs.Connect()); sl@0: sl@0: //Creating secure private path for testing purpose sl@0: //This should create the private\10099999 directory sl@0: User::LeaveIfError(fs.CreatePrivatePath(EDriveC)); sl@0: sl@0: //copying files to the secure path sl@0: BaflUtils::CopyFile(fs,KBmp2_Z,KBmp2_CP); sl@0: } sl@0: sl@0: void CTFbsSecureStep::TestClose() sl@0: { sl@0: //Deleting any bitmaps copied to C: sl@0: DeleteDataFile(KBmp2_CP); sl@0: fs.Close(); sl@0: } sl@0: sl@0: //This function is here to delete the bitmaps in C after finished with it sl@0: void CTFbsSecureStep::DeleteDataFile(const TDesC& aFullName) sl@0: { sl@0: TEntry entry; sl@0: if(fs.Entry(aFullName, entry) == KErrNone) sl@0: { sl@0: RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName); sl@0: TInt err = fs.SetAtt(aFullName, 0, KEntryAttReadOnly); sl@0: if(err != KErrNone) sl@0: { sl@0: RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName); sl@0: } sl@0: err = fs.Delete(aFullName); sl@0: if(err != KErrNone) sl@0: { sl@0: RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName); sl@0: } sl@0: } sl@0: }