|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <f32file.h> |
|
17 #include <fbs.h> |
|
18 #include <bitmap.h> |
|
19 #include <bautils.h> |
|
20 #include "../sfbs/UTILS.H" |
|
21 #include "TSecureFBS.h" |
|
22 |
|
23 |
|
24 |
|
25 LOCAL_C RFs fs; |
|
26 |
|
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"); |
|
34 |
|
35 //Private path in C: |
|
36 _LIT(KBmp2_CP,"c:\\private\\10273364\\RC_RAM16.mbm"); |
|
37 //Private path in Z: |
|
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"); |
|
44 |
|
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"); |
|
48 |
|
49 _LIT(KPlatsecBegin,"*PlatSec* ERROR - BEGIN NEGATIVE PLATSEC TESTING"); |
|
50 _LIT(KPlatsecEnd,"*PlatSec* ERROR - END NEGATIVE PLATSEC TESTING"); |
|
51 //--------------------------------------------------------------------- |
|
52 |
|
53 CTFbsSecure::CTFbsSecure(CTestStep* aStep) : |
|
54 CTGraphicsBase(aStep) |
|
55 { |
|
56 |
|
57 } |
|
58 |
|
59 //--------------------UTILITY Function--------------------------------- |
|
60 //This function is here to measure the offset in the rsc file |
|
61 TInt CTFbsSecure::FileSizeL(const TDesC& aFileName) |
|
62 { |
|
63 RFile file; |
|
64 User::LeaveIfError(file.Open(fs, aFileName, EFileRead)); |
|
65 CleanupClosePushL(file); |
|
66 TInt size = 0; |
|
67 User::LeaveIfError(file.Size(size)); |
|
68 CleanupStack::PopAndDestroy(&file); |
|
69 return size; |
|
70 } |
|
71 |
|
72 //--------------------TEST CASE Function------------------------------- |
|
73 /** |
|
74 |
|
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 |
|
81 */ |
|
82 /** |
|
83 @SYMTestCaseID |
|
84 GRAPHICS-FBSERV-0585 |
|
85 |
|
86 @SYMTestCaseDesc |
|
87 TestCase1 for testing data caging properties. |
|
88 |
|
89 @SYMTestActions |
|
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. |
|
96 |
|
97 @SYMTestExpectedResults |
|
98 Test should pass |
|
99 */ |
|
100 void CTFbsSecure::TestCase1() |
|
101 { |
|
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 |
|
106 { |
|
107 INFO_PRINTF2(_L("Skipping ROM bitmap tests since file \"%S\" is reported to not be a ROM bitmap."), |
|
108 &KBmp1_ZP); |
|
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; |
|
111 } |
|
112 |
|
113 TInt ret; |
|
114 if(!skipRomBitmapTests) |
|
115 { |
|
116 //Loading a ROM bitmap from its own private data cage \private\00099999 |
|
117 CFbsBitmap bmp1; |
|
118 ret=bmp1.Load(KBmp1_ZP,0); |
|
119 TEST(ret==KErrNone); |
|
120 TEST(bmp1.IsRomBitmap()); |
|
121 |
|
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 |
|
124 CFbsBitmap bmp2; |
|
125 ret=bmp2.Load(KBmp1_ZOP,0); |
|
126 if (PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement) && PlatSec::IsCapabilityEnforced(ECapabilityAllFiles)) |
|
127 TEST(ret==KErrPermissionDenied); |
|
128 else |
|
129 TEST(ret==KErrNone); |
|
130 |
|
131 //Loading a ROM bitmap from a public data cage \system\data |
|
132 CFbsBitmap bmp3; |
|
133 ret=bmp3.Load(KBmp1_Z,0); |
|
134 TEST(ret==KErrNone); |
|
135 } |
|
136 |
|
137 //Loading a File Store bitmap from its own private data cage \private\00099999 |
|
138 CFbsBitmap bmp4; |
|
139 ret=bmp4.Load(KBmp2_ZP,0); |
|
140 TEST(ret==KErrNone); |
|
141 TEST(!bmp4.IsRomBitmap()); |
|
142 |
|
143 //Loading a File Store bitmap from other own private data cage \private\00099999 |
|
144 CFbsBitmap bmp5; |
|
145 ret=bmp5.Load(KBmp2_ZOP,0); |
|
146 if (PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement) && PlatSec::IsCapabilityEnforced(ECapabilityAllFiles)) |
|
147 TEST(ret==KErrPermissionDenied); |
|
148 else |
|
149 TEST(ret==KErrNone); |
|
150 |
|
151 //Loading a File Store bitmap from a public data cage \system\data |
|
152 CFbsBitmap bmp6; |
|
153 ret=bmp6.Load(KBmp2_Z,0); |
|
154 TEST(ret==KErrNone); |
|
155 |
|
156 //Loading a bitmap file from an rsc file inside the private data path |
|
157 CFbsBitmap bmp7; |
|
158 TInt fileoffset=0; |
|
159 //Getting the file offset for the mbm file embedded inside the rsc |
|
160 TRAP(ret,fileoffset=FileSizeL(KRscHeader_ZP)+FileSizeL(KDummyRsc_ZP)); |
|
161 TEST(ret==KErrNone); |
|
162 ret=bmp7.Load(KTbsRsc_ZP,0,EFalse,fileoffset); |
|
163 TEST(ret==KErrNone); |
|
164 |
|
165 //Loading a File Store bitmap from own private data cage in C: |
|
166 CFbsBitmap bmp8; |
|
167 ret=bmp8.Load(KBmp2_CP,0); |
|
168 TEST(ret==KErrNone); |
|
169 } |
|
170 |
|
171 /** |
|
172 @SYMTestCaseID |
|
173 GRAPHICS-FBSERV-0586 |
|
174 |
|
175 @SYMTestCaseDesc |
|
176 TestCase2 for testing of invalid arguments such as file name,id, file offset |
|
177 |
|
178 @SYMTestActions |
|
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 |
|
183 |
|
184 @SYMTestExpectedResults |
|
185 Test should pass |
|
186 */ |
|
187 void CTFbsSecure::TestCase2() |
|
188 { |
|
189 INFO_PRINTF1(_L("Test Case 2")); |
|
190 TInt ret; |
|
191 //Loading an invalid bitmap KInvalid_Bitmap |
|
192 CFbsBitmap bmp1; |
|
193 ret=bmp1.Load(KInvalid_Bitmap,0); |
|
194 TEST(ret==KErrNotFound); |
|
195 |
|
196 //Loading a bitmap with invalid id,KBmp1_ZP only has one bitmap |
|
197 CFbsBitmap bmp2; |
|
198 ret=bmp2.Load(KBmp2_ZP,1); |
|
199 TEST(ret==KErrEof); |
|
200 |
|
201 //Loading a bitmap with invalid File offset |
|
202 CFbsBitmap bmp3; |
|
203 ret=bmp3.Load(KTbsRsc_ZP,0,EFalse,0); |
|
204 TEST(ret==KErrNotSupported); |
|
205 } |
|
206 |
|
207 /** |
|
208 |
|
209 |
|
210 */ |
|
211 /** |
|
212 @SYMTestCaseID |
|
213 GRAPHICS-FBSERV-0587 |
|
214 |
|
215 @SYMTestCaseDesc |
|
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 |
|
219 |
|
220 @SYMTestActions |
|
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 |
|
224 the same bitmap |
|
225 |
|
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 |
|
230 |
|
231 @SYMTestExpectedResults |
|
232 Test should pass |
|
233 */ |
|
234 void CTFbsSecure::TestCase3() |
|
235 { |
|
236 INFO_PRINTF1(_L("Test Case 3")); |
|
237 TInt ret; |
|
238 |
|
239 //Loading first bitmap with ShareIfLoaded |
|
240 CFbsBitmap* bmp1=new (ELeave) CFbsBitmap; |
|
241 ret=bmp1->Load(KBmp2_ZP,0,ETrue); |
|
242 TEST(ret==KErrNone); |
|
243 TEST(!bmp1->IsRomBitmap()); |
|
244 |
|
245 //Loading second bitmap with ShareIfLoaded |
|
246 CFbsBitmap* bmp2=new (ELeave) CFbsBitmap; |
|
247 ret-bmp2->Load(KBmp2_ZP,0,ETrue); |
|
248 TEST(ret==KErrNone); |
|
249 TEST(!bmp2->IsRomBitmap()); |
|
250 |
|
251 //Test the file sharing properties do exist here |
|
252 TEST(bmp1->Handle()==bmp2->Handle()); |
|
253 TEST(bmp1->DataAddress()==bmp2->DataAddress()); |
|
254 |
|
255 TInt fileoffset=0; |
|
256 TRAP(ret,fileoffset=FileSizeL(KRscHeader_ZP)+FileSizeL(KDummyRsc_ZP)); |
|
257 TEST(ret==KErrNone); |
|
258 //Loading third bitmap with NO ShareIfLoaded |
|
259 CFbsBitmap* bmp3=new (ELeave) CFbsBitmap; |
|
260 ret=bmp3->Load(KTbsRsc_ZP,1,EFalse,fileoffset); |
|
261 TEST(ret==KErrNone); |
|
262 TEST(!bmp3->IsRomBitmap()); |
|
263 |
|
264 //Loading fourth bitmap(similar to 3) with ShareIfLoaded |
|
265 CFbsBitmap* bmp4=new (ELeave) CFbsBitmap; |
|
266 ret=bmp4->Load(KTbsRsc_ZP,1,ETrue,fileoffset); |
|
267 TEST(ret==KErrNone); |
|
268 TEST(!bmp4->IsRomBitmap()); |
|
269 |
|
270 //Test the file sharing properties does not exist here |
|
271 TEST(bmp3->Handle()!=bmp4->Handle()); |
|
272 TEST(bmp3->DataAddress()!=bmp4->DataAddress()); |
|
273 |
|
274 delete bmp1; |
|
275 delete bmp2; |
|
276 delete bmp3; |
|
277 delete bmp4; |
|
278 |
|
279 } |
|
280 |
|
281 /** |
|
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 |
|
291 */ |
|
292 |
|
293 void CTFbsSecure::RunTestCaseL(TInt aCurTestCase) |
|
294 { |
|
295 ((CTFbsSecureStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName); |
|
296 switch(aCurTestCase) |
|
297 { |
|
298 case 1: |
|
299 ((CTFbsSecureStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0585")); |
|
300 RDebug::Print(KPlatsecBegin); |
|
301 TestCase1(); |
|
302 RDebug::Print(KPlatsecEnd); |
|
303 break; |
|
304 case 2: |
|
305 ((CTFbsSecureStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0586")); |
|
306 TestCase2(); |
|
307 case 3: |
|
308 ((CTFbsSecureStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0587")); |
|
309 TestCase3(); |
|
310 break; |
|
311 case 4: |
|
312 ((CTFbsSecureStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName); |
|
313 ((CTFbsSecureStep*)iStep)->CloseTMSGraphicsStep(); |
|
314 TestComplete(); |
|
315 break; |
|
316 } |
|
317 ((CTFbsSecureStep*)iStep)->RecordTestResultL(); |
|
318 } |
|
319 |
|
320 //-------------- |
|
321 __CONSTRUCT_STEP__(FbsSecure) |
|
322 |
|
323 |
|
324 void CTFbsSecureStep::TestSetupL() |
|
325 { |
|
326 User::LeaveIfError(fs.Connect()); |
|
327 |
|
328 //Creating secure private path for testing purpose |
|
329 //This should create the private\10099999 directory |
|
330 User::LeaveIfError(fs.CreatePrivatePath(EDriveC)); |
|
331 |
|
332 //copying files to the secure path |
|
333 BaflUtils::CopyFile(fs,KBmp2_Z,KBmp2_CP); |
|
334 } |
|
335 |
|
336 void CTFbsSecureStep::TestClose() |
|
337 { |
|
338 //Deleting any bitmaps copied to C: |
|
339 DeleteDataFile(KBmp2_CP); |
|
340 fs.Close(); |
|
341 } |
|
342 |
|
343 //This function is here to delete the bitmaps in C after finished with it |
|
344 void CTFbsSecureStep::DeleteDataFile(const TDesC& aFullName) |
|
345 { |
|
346 TEntry entry; |
|
347 if(fs.Entry(aFullName, entry) == KErrNone) |
|
348 { |
|
349 RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName); |
|
350 TInt err = fs.SetAtt(aFullName, 0, KEntryAttReadOnly); |
|
351 if(err != KErrNone) |
|
352 { |
|
353 RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName); |
|
354 } |
|
355 err = fs.Delete(aFullName); |
|
356 if(err != KErrNone) |
|
357 { |
|
358 RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName); |
|
359 } |
|
360 } |
|
361 } |