First public contribution.
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
20 #include "../sfbs/UTILS.H"
21 #include "TSecureFBS.h"
27 //----------------------TEST DATA-------------------------------------
28 //RC_ROM12 is a ROM type mbm
29 //RC_RAM16 is a File Store type mbm
30 //TFBS inside TFBS_RSC is a File Store type mbm
31 //Bitmap for testing purposes
32 _LIT(KBmp1_Z,"z:\\system\\data\\RC_ROM12.mbm");
33 _LIT(KBmp2_Z,"z:\\system\\data\\RC_RAM16.mbm");
36 _LIT(KBmp2_CP,"c:\\private\\10273364\\RC_RAM16.mbm");
38 _LIT(KBmp1_ZP,"z:\\private\\10273364\\RC_ROM12.mbm");
39 _LIT(KBmp2_ZP,"z:\\private\\10273364\\RC_RAM16.mbm");
40 _LIT(KRscHeader_ZP,"z:\\private\\10273364\\RscHeader3.bin");
41 _LIT(KDummyRsc_ZP,"z:\\private\\10273364\\DummyRscFile3.rsc");
42 _LIT(KTbsRsc_ZP,"z:\\private\\10273364\\TFBS_RSC.rsc");
43 _LIT(KInvalid_Bitmap,"z:\\private\\10273364\\invalid.mbm");
45 //Other private path 00999999 used for data caging test
46 _LIT(KBmp1_ZOP,"z:\\private\\00999999\\RC_ROM12.mbm");
47 _LIT(KBmp2_ZOP,"z:\\private\\00999999\\RC_RAM16.mbm");
49 _LIT(KPlatsecBegin,"*PlatSec* ERROR - BEGIN NEGATIVE PLATSEC TESTING");
50 _LIT(KPlatsecEnd,"*PlatSec* ERROR - END NEGATIVE PLATSEC TESTING");
51 //---------------------------------------------------------------------
53 CTFbsSecure::CTFbsSecure(CTestStep* aStep) :
59 //--------------------UTILITY Function---------------------------------
60 //This function is here to measure the offset in the rsc file
61 TInt CTFbsSecure::FileSizeL(const TDesC& aFileName)
64 User::LeaveIfError(file.Open(fs, aFileName, EFileRead));
65 CleanupClosePushL(file);
67 User::LeaveIfError(file.Size(size));
68 CleanupStack::PopAndDestroy(&file);
72 //--------------------TEST CASE Function-------------------------------
75 -Using two type of bitmaps Rom and File Store Bitmap
76 -Testing will focus on File Store type bitmap only
77 -Loading a bitmap in private data cage, expect KErrNone
78 -Loading a bitmap in other private data cage, expect KErrPermissionDenied(-46)
79 -Loading a bitmap from a public path, expect KErrNone
80 -Loading a bitmap from an rsc file inside the private data path
87 TestCase1 for testing data caging properties.
90 Using two type of bitmaps Rom and File Store Bitmap.
91 Testing will focus on File Store type bitmap only.
92 Loading a bitmap in private data cage, expect KErrNone.
93 Loading a bitmap in other private data cage, expect KErrPermissionDenied(-46).
94 Loading a bitmap from a public path, expect KErrNone.
95 Loading a bitmap from an rsc file inside the private data path.
97 @SYMTestExpectedResults
100 void CTFbsSecure::TestCase1()
102 INFO_PRINTF1(_L("Test Case 1"));
103 TInt skipRomBitmapTests = EFalse;
104 TUint32* romAddress = NULL;
105 if(!CFbsBitmap::IsFileInRom(KBmp1_ZP, romAddress)) //any ROM bitmap
107 INFO_PRINTF2(_L("Skipping ROM bitmap tests since file \"%S\" is reported to not be a ROM bitmap."),
109 INFO_PRINTF1(_L("This should only occur on non-XIP ROMs, e.g. NAND ROMs, where ROM bitmaps aren't supported."));
110 skipRomBitmapTests = ETrue;
114 if(!skipRomBitmapTests)
116 //Loading a ROM bitmap from its own private data cage \private\00099999
118 ret=bmp1.Load(KBmp1_ZP,0);
120 TEST(bmp1.IsRomBitmap());
122 //Loading a ROM bitmap from other private data cage \private\00999999
123 //This test works if PlatSecEnforcement is ON otherwise it will return KErrNone
125 ret=bmp2.Load(KBmp1_ZOP,0);
126 if (PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement) && PlatSec::IsCapabilityEnforced(ECapabilityAllFiles))
127 TEST(ret==KErrPermissionDenied);
131 //Loading a ROM bitmap from a public data cage \system\data
133 ret=bmp3.Load(KBmp1_Z,0);
137 //Loading a File Store bitmap from its own private data cage \private\00099999
139 ret=bmp4.Load(KBmp2_ZP,0);
141 TEST(!bmp4.IsRomBitmap());
143 //Loading a File Store bitmap from other own private data cage \private\00099999
145 ret=bmp5.Load(KBmp2_ZOP,0);
146 if (PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement) && PlatSec::IsCapabilityEnforced(ECapabilityAllFiles))
147 TEST(ret==KErrPermissionDenied);
151 //Loading a File Store bitmap from a public data cage \system\data
153 ret=bmp6.Load(KBmp2_Z,0);
156 //Loading a bitmap file from an rsc file inside the private data path
159 //Getting the file offset for the mbm file embedded inside the rsc
160 TRAP(ret,fileoffset=FileSizeL(KRscHeader_ZP)+FileSizeL(KDummyRsc_ZP));
162 ret=bmp7.Load(KTbsRsc_ZP,0,EFalse,fileoffset);
165 //Loading a File Store bitmap from own private data cage in C:
167 ret=bmp8.Load(KBmp2_CP,0);
176 TestCase2 for testing of invalid arguments such as file name,id, file offset
179 Test focus on File Store bitmap
180 Loading an invalid bitmap file name expect KErrNotFound
181 Loading a bitmap with invalid id
182 Loading a bitmap with invalid file offset
184 @SYMTestExpectedResults
187 void CTFbsSecure::TestCase2()
189 INFO_PRINTF1(_L("Test Case 2"));
191 //Loading an invalid bitmap KInvalid_Bitmap
193 ret=bmp1.Load(KInvalid_Bitmap,0);
194 TEST(ret==KErrNotFound);
196 //Loading a bitmap with invalid id,KBmp1_ZP only has one bitmap
198 ret=bmp2.Load(KBmp2_ZP,1);
201 //Loading a bitmap with invalid File offset
203 ret=bmp3.Load(KTbsRsc_ZP,0,EFalse,0);
204 TEST(ret==KErrNotSupported);
216 TestCase3 for testing of the sharing of bitmaps using iShareIfLoaded
217 this indirectly test the removal of the FileInfo and yet preserver
218 preserve the same functionality in 9.0 without any regression
221 bmp1 load with iShareIfLoaded=ETrue and bmp2 load same file with ETrue
222 Expect the Handle() and DataAddress() to be the same as there will be
223 only one raw memory data stored in the global heap for these 2 instances of
226 bmp3 load with iShareIfLoaded=EFalse and bmp4 load same file with ETrue
227 Expect the Handle() and DataAddress() to be different as bmp1 does not want
228 to share the bitmap,so bmp2 will have its own Handle() and a completely pointer
229 to the bitmap raw data
231 @SYMTestExpectedResults
234 void CTFbsSecure::TestCase3()
236 INFO_PRINTF1(_L("Test Case 3"));
239 //Loading first bitmap with ShareIfLoaded
240 CFbsBitmap* bmp1=new (ELeave) CFbsBitmap;
241 ret=bmp1->Load(KBmp2_ZP,0,ETrue);
243 TEST(!bmp1->IsRomBitmap());
245 //Loading second bitmap with ShareIfLoaded
246 CFbsBitmap* bmp2=new (ELeave) CFbsBitmap;
247 ret-bmp2->Load(KBmp2_ZP,0,ETrue);
249 TEST(!bmp2->IsRomBitmap());
251 //Test the file sharing properties do exist here
252 TEST(bmp1->Handle()==bmp2->Handle());
253 TEST(bmp1->DataAddress()==bmp2->DataAddress());
256 TRAP(ret,fileoffset=FileSizeL(KRscHeader_ZP)+FileSizeL(KDummyRsc_ZP));
258 //Loading third bitmap with NO ShareIfLoaded
259 CFbsBitmap* bmp3=new (ELeave) CFbsBitmap;
260 ret=bmp3->Load(KTbsRsc_ZP,1,EFalse,fileoffset);
262 TEST(!bmp3->IsRomBitmap());
264 //Loading fourth bitmap(similar to 3) with ShareIfLoaded
265 CFbsBitmap* bmp4=new (ELeave) CFbsBitmap;
266 ret=bmp4->Load(KTbsRsc_ZP,1,ETrue,fileoffset);
268 TEST(!bmp4->IsRomBitmap());
270 //Test the file sharing properties does not exist here
271 TEST(bmp3->Handle()!=bmp4->Handle());
272 TEST(bmp3->DataAddress()!=bmp4->DataAddress());
282 @SYMTestCaseID GRAPHICS-SYSLIB-FBSERV-CT-0002
283 @SYMTestCaseDesc Testing for the secure bitmap loading in FBSERV
284 @SYMTestPriority High
285 @SYMTestActions Testing the loading of a bitmap from its own data cage
286 Testing for permission denied when loading from other private data
287 Testing for invalid arguments
288 Testing for bitmap sharing
289 @SYMTestExpectedResults The test must not fail.
290 @SYMPREQ 280 General Datacaging
293 void CTFbsSecure::RunTestCaseL(TInt aCurTestCase)
295 ((CTFbsSecureStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
299 ((CTFbsSecureStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0585"));
300 RDebug::Print(KPlatsecBegin);
302 RDebug::Print(KPlatsecEnd);
305 ((CTFbsSecureStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0586"));
308 ((CTFbsSecureStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0587"));
312 ((CTFbsSecureStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
313 ((CTFbsSecureStep*)iStep)->CloseTMSGraphicsStep();
317 ((CTFbsSecureStep*)iStep)->RecordTestResultL();
321 __CONSTRUCT_STEP__(FbsSecure)
324 void CTFbsSecureStep::TestSetupL()
326 User::LeaveIfError(fs.Connect());
328 //Creating secure private path for testing purpose
329 //This should create the private\10099999 directory
330 User::LeaveIfError(fs.CreatePrivatePath(EDriveC));
332 //copying files to the secure path
333 BaflUtils::CopyFile(fs,KBmp2_Z,KBmp2_CP);
336 void CTFbsSecureStep::TestClose()
338 //Deleting any bitmaps copied to C:
339 DeleteDataFile(KBmp2_CP);
343 //This function is here to delete the bitmaps in C after finished with it
344 void CTFbsSecureStep::DeleteDataFile(const TDesC& aFullName)
347 if(fs.Entry(aFullName, entry) == KErrNone)
349 RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
350 TInt err = fs.SetAtt(aFullName, 0, KEntryAttReadOnly);
353 RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
355 err = fs.Delete(aFullName);
358 RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);