|
1 // Copyright (c) 1997-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 // Epoc includes |
|
17 #include "../inc/FBSMBMC.H" |
|
18 #include "../sfbs/UTILS.H" |
|
19 #include "TStreamIdCache.h" |
|
20 #include "fbsmessage.h" |
|
21 #include "fbsdefs.h" |
|
22 |
|
23 //Eikon has 78 bitmaps inside the mbm file(id 0-77) |
|
24 _LIT(KMbmFileEikon, "z:\\System\\Data\\tfbs_file4.mbm"); |
|
25 _LIT(KMbmFileEikon2, "z:\\System\\Data\\tfbs_file4a.mbm"); |
|
26 _LIT(KMbmFileEikon3, "z:\\System\\Data\\tfbs_file4b.mbm"); |
|
27 _LIT(KMbmFileEikon4, "z:\\System\\Data\\tfbs_file4c.mbm"); |
|
28 _LIT(KMbmFileEikon5, "z:\\System\\Data\\tfbs_file4d.mbm"); |
|
29 //Lafcurs has 28 bitmaps inside the mbm file(id 0-27) |
|
30 _LIT(KMbmFileLafcurs, "z:\\System\\Data\\tfbs_file2.mbm"); |
|
31 //Resource file containing mbm file |
|
32 _LIT(KMbmFileTFBSRSC, "z:\\System\\Data\\tfbs_rsc.rsc"); |
|
33 _LIT(KRscFileHeader, "z:\\system\\data\\RscHeader3.bin"); |
|
34 _LIT(KRscFileData, "z:\\system\\data\\DummyRscFile3.rsc"); |
|
35 |
|
36 // File with two 1x1 px mbm files: first is black, second is white. white mbm at 72 bytes into file |
|
37 #define WHITE_OFFSET 72 |
|
38 _LIT(KBlackAndWhite, "z:\\system\\data\\blackandwhite.mbm"); |
|
39 |
|
40 // ============================================================================ |
|
41 |
|
42 //Default Constructor |
|
43 CTStreamIdCache::CTStreamIdCache(CTestStep* aStep): |
|
44 CTGraphicsBase(aStep), |
|
45 iFbs(NULL) |
|
46 { |
|
47 } |
|
48 |
|
49 CTStreamIdCache::~CTStreamIdCache() |
|
50 { |
|
51 if(iShutdownFbs) |
|
52 RFbsSession::GetSession()->SendCommand(EFbsMessShutdown); |
|
53 RFbsSession::Disconnect(); |
|
54 iFs.Close(); |
|
55 } |
|
56 |
|
57 void CTStreamIdCache::ConstructL() |
|
58 { |
|
59 if(RFbsSession::Connect()==KErrNone) |
|
60 { |
|
61 iShutdownFbs = EFalse; |
|
62 } |
|
63 else |
|
64 { |
|
65 FbsStartup(); |
|
66 RFbsSession::Connect(); |
|
67 iShutdownFbs = ETrue; |
|
68 } |
|
69 |
|
70 iFs.Connect(); |
|
71 |
|
72 iFbs = RFbsSession::GetSession(); |
|
73 iSessionHandle = iFbs->SessionHandle(); |
|
74 ExpandCleanupStackL(); |
|
75 |
|
76 INFO_PRINTF1(_L("FBS Bitmap StreamId cache testing")); |
|
77 } |
|
78 |
|
79 void CTStreamIdCache::RunTestCaseL(TInt aCurTestCase) |
|
80 { |
|
81 ((CTStreamIdCacheStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName); |
|
82 switch(aCurTestCase) |
|
83 { |
|
84 case 1: |
|
85 ((CTStreamIdCacheStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0577")); |
|
86 TestStreamIdCacheEntry(); |
|
87 break; |
|
88 case 2: |
|
89 ((CTStreamIdCacheStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0578")); |
|
90 TestProcessingBitmapStream(); |
|
91 break; |
|
92 case 3: |
|
93 ((CTStreamIdCacheStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0580")); |
|
94 TestReplacingFile(); |
|
95 break; |
|
96 case 4: |
|
97 ((CTStreamIdCacheStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0579")); |
|
98 TestComparingStreams(); |
|
99 break; |
|
100 case 5: |
|
101 ((CTStreamIdCacheStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0581")); |
|
102 TestInvalidArgument(); |
|
103 break; |
|
104 case 6: |
|
105 ((CTStreamIdCacheStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0582")); |
|
106 TestOOMCondition(); |
|
107 break; |
|
108 case 7: |
|
109 ((CTStreamIdCacheStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0583")); |
|
110 TestPerformance(); |
|
111 break; |
|
112 case 8: |
|
113 ((CTStreamIdCacheStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0584")); |
|
114 TestLoadAtOffset(); |
|
115 break; |
|
116 case 9: |
|
117 ((CTStreamIdCacheStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0509")); |
|
118 TestSessionClose(); |
|
119 break; |
|
120 case 10: |
|
121 ((CTStreamIdCacheStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName); |
|
122 ((CTStreamIdCacheStep*)iStep)->CloseTMSGraphicsStep(); |
|
123 TestComplete(); |
|
124 break; |
|
125 } |
|
126 ((CTStreamIdCacheStep*)iStep)->RecordTestResultL(); |
|
127 } |
|
128 |
|
129 //This function is here to measure the offset in the rsc file |
|
130 TInt CTStreamIdCache::FileSizeL(const TDesC& aFileName) |
|
131 { |
|
132 RFile file; |
|
133 User::LeaveIfError(file.Open(iFs, aFileName, EFileRead)); |
|
134 CleanupClosePushL(file); |
|
135 TInt size = 0; |
|
136 User::LeaveIfError(file.Size(size)); |
|
137 CleanupStack::PopAndDestroy(&file); |
|
138 return size; |
|
139 } |
|
140 |
|
141 void CTStreamIdCache::ExpandCleanupStackL() |
|
142 { |
|
143 TInt count=0; |
|
144 for(;count<10;count++) |
|
145 CleanupStack::PushL((TUint32*)0x1); |
|
146 CleanupStack::Pop(count); |
|
147 } |
|
148 |
|
149 /** |
|
150 @SYMTestCaseID |
|
151 GRAPHICS-FBSERV-0577 |
|
152 |
|
153 @SYMTestCaseDesc |
|
154 Tests the API functionality of the class ensuring |
|
155 the internal states are correct during the construction |
|
156 and other operation. |
|
157 |
|
158 @SYMTestActions |
|
159 Tests the API on a defaultly built element object. |
|
160 |
|
161 @SYMTestExpectedResults |
|
162 Test should pass |
|
163 */ |
|
164 void CTStreamIdCache::TestStreamIdCacheEntry() |
|
165 { |
|
166 INFO_PRINTF1(_L("Test of CFbTopStreamIdCache API")); |
|
167 |
|
168 // Test the API on a defaultly built element object |
|
169 |
|
170 CFbTopStreamIdCache* mbmcache=new CFbTopStreamIdCache(20,30,1); |
|
171 TEST(mbmcache->iEntries.Count() == 0); |
|
172 TEST(mbmcache->iMaxCacheFilestores == 1); |
|
173 TEST(mbmcache->iBackwardCacheSize ==30); |
|
174 TEST(mbmcache->iForwardCacheSize ==20); |
|
175 |
|
176 delete mbmcache; |
|
177 |
|
178 } |
|
179 |
|
180 /** |
|
181 @SYMTestCaseID |
|
182 GRAPHICS-FBSERV-0578 |
|
183 |
|
184 @SYMTestCaseDesc |
|
185 Tests the loading of a bitmap from an mbm file using |
|
186 the cache and the content of the cache after the loading |
|
187 i.e. how many stream ids are stored, the last bitmap file |
|
188 name, the last id, the cache forward and backward size. |
|
189 |
|
190 @SYMTestActions |
|
191 Tests the GetStreamIdL method. Loads eikon.mbm with 78 |
|
192 bitmap files. Tests loading some rsc file which contains offset. |
|
193 Tests the flushing. |
|
194 |
|
195 @SYMTestExpectedResults |
|
196 Test should pass |
|
197 */ |
|
198 void CTStreamIdCache::TestProcessingBitmapStream() |
|
199 { |
|
200 TInt ret; |
|
201 |
|
202 INFO_PRINTF1(_L("Test loading a bitmap file and processing the stream id")); |
|
203 |
|
204 //Testing the GetStreamIdL method |
|
205 CFbTopStreamIdCache* mbmcacheptr = new CFbTopStreamIdCache(30,30,1); |
|
206 CFbTopStreamIdCache& mbmcache = *mbmcacheptr; |
|
207 INFO_PRINTF1(_L("Loading eikon.mbm with 78 bitmap files")); |
|
208 //Loading eikon.mbm with 78 bitmap files |
|
209 RFile file; |
|
210 ret=file.Open(iFs,KMbmFileEikon,EFileShareReadersOnly); |
|
211 TEST(ret==KErrNone); |
|
212 TRAP(ret,mbmcache.GetStreamIdL(file,KMbmFileEikon,50,0,iSessionHandle)); |
|
213 TEST(ret==KErrNone); |
|
214 //the cache only stores 30 ids before 50 + max of 30 after(including 50) |
|
215 //but in this case the bitmap only has 78 bitmaps so it only stores 28 after |
|
216 TEST(mbmcache.iEntries.Count() == 1); |
|
217 TEST(mbmcache.iEntries[0]->iStreamIdCount==58); |
|
218 TEST(mbmcache.iEntries[0]->iLastId==50); |
|
219 TEST(mbmcache.iForwardCacheSize==30); |
|
220 TEST(mbmcache.iBackwardCacheSize==30); |
|
221 TEST(mbmcache.iEntries[0]->iFilename.CompareF(KMbmFileEikon)==0); |
|
222 TEST(mbmcache.iEntries[0]->iFilestore!=NULL); |
|
223 |
|
224 //Test loading some rsc file which contains offset |
|
225 TInt mbm_offset = FileSizeL(KRscFileHeader) + FileSizeL(KRscFileData); |
|
226 ret=file.Open(iFs,KMbmFileTFBSRSC,EFileShareReadersOnly); |
|
227 TEST(ret==KErrNone); |
|
228 TRAP(ret,mbmcache.GetStreamIdL(file,KMbmFileTFBSRSC,0,mbm_offset,iSessionHandle)); |
|
229 TEST(ret==KErrNone); |
|
230 TEST(mbmcache.iEntries.Count() == 1); |
|
231 TEST(mbmcache.iEntries[0]->iLastId==0); |
|
232 TEST(mbmcache.iEntries[0]->iStreamIdCount==2); |
|
233 TEST(mbmcache.iEntries[0]->iFilename.CompareF(KMbmFileTFBSRSC)==0); |
|
234 |
|
235 // Test the flushing |
|
236 mbmcache.FlushCache(); |
|
237 TEST(mbmcache.iEntries.Count() == 0); |
|
238 TEST(mbmcache.iMaxCacheFilestores == 1); |
|
239 TEST(mbmcache.iBackwardCacheSize == 30); |
|
240 TEST(mbmcache.iForwardCacheSize == 30); |
|
241 |
|
242 delete mbmcacheptr; |
|
243 } |
|
244 |
|
245 /** |
|
246 @SYMTestCaseID |
|
247 GRAPHICS-FBSERV-0579 |
|
248 |
|
249 @SYMTestCaseDesc |
|
250 Tests the correct functionality of the cache storing the stream ids. |
|
251 Three different caches are used to load the same mbm file but the |
|
252 bitmap id to be loaded are different however the bitmap ids are chosen in |
|
253 such a way that these three caches will store some common bitmap id. |
|
254 We then accessed the cache content and check that these three caches |
|
255 will give the same stream id values for that common bitmap id. |
|
256 |
|
257 @SYMTestActions |
|
258 |
|
259 @SYMTestExpectedResults |
|
260 Test should pass |
|
261 */ |
|
262 void CTStreamIdCache::TestComparingStreams() |
|
263 { |
|
264 TInt ret; |
|
265 |
|
266 INFO_PRINTF1(_L("Test comparing the stream ids from three different caches")); |
|
267 |
|
268 CFbTopStreamIdCache* cache1=new CFbTopStreamIdCache(30,30,1); |
|
269 CFbTopStreamIdCache* cache2=new CFbTopStreamIdCache(10,30,1); |
|
270 CFbTopStreamIdCache* cache3=new CFbTopStreamIdCache(25,5,1); |
|
271 |
|
272 //CACHE1 Loading this will fill up the streams with ids from 0-55 |
|
273 RFile file; |
|
274 ret=file.Open(iFs,KMbmFileEikon,EFileShareReadersOnly); |
|
275 TEST(ret==KErrNone); |
|
276 TRAP(ret,cache1->GetStreamIdL(file,KMbmFileEikon,25,0,iSessionHandle)); |
|
277 TEST(ret==KErrNone); |
|
278 TEST(cache1->iEntries.Count() == 1); |
|
279 TEST(cache1->iEntries[0]->iStreamIdCount==55); |
|
280 TEST(cache1->iEntries[0]->iLastId==25); |
|
281 //now storing the actual TStreamId for bitmap id 26 for future comparison |
|
282 //stream id for bitmapid=26 will be @ the 26th position inside the array |
|
283 TStreamId id25_26=cache1->iEntries[0]->iStreamIdCache[26]; |
|
284 |
|
285 delete cache1; |
|
286 |
|
287 |
|
288 //CACHE2 Loading this will fill up the streams with ids from 36-65 |
|
289 ret=file.Open(iFs,KMbmFileEikon,EFileShareReadersOnly); |
|
290 TEST(ret==KErrNone); |
|
291 TRAP(ret,cache2->GetStreamIdL(file,KMbmFileEikon,56,0,iSessionHandle)); |
|
292 TEST(ret==KErrNone); |
|
293 TEST(cache2->iEntries.Count() == 1); |
|
294 TEST(cache2->iEntries[0]->iStreamIdCount==40); |
|
295 TEST(cache2->iEntries[0]->iLastId==56); |
|
296 //stream id for bitmapid=26 will be @ the 0th position inside the array |
|
297 TStreamId id56_26=cache2->iEntries[0]->iStreamIdCache[0]; |
|
298 TEST(id25_26.Value()==id56_26.Value()); |
|
299 |
|
300 delete cache2; |
|
301 |
|
302 //CACHE3 Loading this will fill up the streams with ids from 1-30 |
|
303 ret=file.Open(iFs,KMbmFileEikon,EFileShareReadersOnly); |
|
304 TEST(ret==KErrNone); |
|
305 TRAP(ret,cache3->GetStreamIdL(file,KMbmFileEikon,6,0,iSessionHandle)); |
|
306 TEST(ret==KErrNone); |
|
307 TEST(cache3->iEntries.Count() == 1); |
|
308 TEST(cache3->iEntries[0]->iStreamIdCount==30); |
|
309 TEST(cache3->iEntries[0]->iLastId==6); |
|
310 TStreamId id6_26=cache3->iEntries[0]->iStreamIdCache[25]; |
|
311 TEST(id25_26.Value()==id6_26.Value()); |
|
312 |
|
313 delete cache3; |
|
314 } |
|
315 |
|
316 /** |
|
317 @SYMTestCaseID |
|
318 GRAPHICS-FBSERV-0580 |
|
319 |
|
320 @SYMTestCaseDesc |
|
321 Tests the functionality of the cache when it has already |
|
322 stored some existing bitmap ids The cache is loaded with a |
|
323 different mbm file and the cache content is examined to make |
|
324 sure it has the correct new data. |
|
325 |
|
326 @SYMTestActions |
|
327 |
|
328 @SYMTestExpectedResults |
|
329 Test should pass |
|
330 */ |
|
331 void CTStreamIdCache::TestReplacingFile() |
|
332 { |
|
333 TInt ret; |
|
334 |
|
335 INFO_PRINTF1(_L("Test loading a file different from previous stored in cache")); |
|
336 |
|
337 CFbTopStreamIdCache* cache1ptr = new CFbTopStreamIdCache(30,30,1); |
|
338 CFbTopStreamIdCache& cache1 = *cache1ptr; |
|
339 RFile file; |
|
340 ret=file.Open(iFs,KMbmFileEikon,EFileShareReadersOnly); |
|
341 TEST(ret==KErrNone); |
|
342 TRAP(ret,cache1.GetStreamIdL(file,KMbmFileEikon,25,0,iSessionHandle)); |
|
343 TEST(ret==KErrNone); |
|
344 TEST(cache1.iEntries.Count() == 1); |
|
345 TEST(cache1.iEntries[0]->iStreamIdCount==55); |
|
346 TEST(cache1.iEntries[0]->iLastId==25); |
|
347 TEST(cache1.iEntries[0]->iFilename.Compare(KMbmFileEikon)==0); |
|
348 |
|
349 //Now trying to load an entirely different bitmap file |
|
350 //and check to ensure the cache has reflushed itself |
|
351 //and load itself with new stuff |
|
352 ret=file.Open(iFs,KMbmFileLafcurs,EFileShareReadersOnly); |
|
353 TEST(ret==KErrNone); |
|
354 TRAP(ret,cache1.GetStreamIdL(file,KMbmFileLafcurs,12,0,iSessionHandle)); |
|
355 TEST(ret==KErrNone); |
|
356 TEST(cache1.iEntries.Count() == 1); |
|
357 TEST(cache1.iEntries[0]->iStreamIdCount==28); |
|
358 TEST(cache1.iEntries[0]->iLastId==12); |
|
359 TEST(cache1.iEntries[0]->iFilename.Compare(KMbmFileLafcurs)==0); |
|
360 |
|
361 delete cache1ptr; |
|
362 } |
|
363 |
|
364 /** |
|
365 @SYMTestCaseID |
|
366 GRAPHICS-FBSERV-0581 |
|
367 |
|
368 @SYMTestCaseDesc |
|
369 Tests the error values that would be returned by |
|
370 the cache when supplied with invalid arguments such |
|
371 as bad file name negative bitmap ids, out of range |
|
372 bitmap ids, and invalid file offset. |
|
373 |
|
374 @SYMDEF INC047122 INC046632 |
|
375 |
|
376 @SYMTestActions |
|
377 Creates an FbTopStreamIdCache object. Tests to ensure the cache |
|
378 can deal with non error cases immediately after error cases. |
|
379 Passing an in bound bitmap id. Passing an out of bound bitmap id. |
|
380 Passing an in bound bitmap id. Passing an out of bound bitmap id. |
|
381 Passing an in bound bitmap id. Passing negative bitmap id. |
|
382 Passing an invalid file name. Passing an invalid file offset. |
|
383 |
|
384 @SYMTestExpectedResults |
|
385 Test should pass |
|
386 */ |
|
387 void CTStreamIdCache::TestInvalidArgument() |
|
388 { |
|
389 |
|
390 TInt ret; |
|
391 |
|
392 INFO_PRINTF1(_L("Test loading a file bitmap with invalid argument")); |
|
393 |
|
394 CFbTopStreamIdCache* cache1ptr = new CFbTopStreamIdCache(30,30,1); |
|
395 CFbTopStreamIdCache& cache1 = *cache1ptr; |
|
396 //Eikon mbm only can accept ids from 0-77 |
|
397 |
|
398 //The following sequence of 4 tests ensures the cache can deal with |
|
399 //non error cases immediately after error cases. |
|
400 |
|
401 //Passing an in bound bitmap id |
|
402 RFile file; |
|
403 ret=file.Open(iFs,KMbmFileEikon,EFileShareReadersOnly); |
|
404 TEST(ret==KErrNone); |
|
405 TRAP(ret,cache1.GetStreamIdL(file,KMbmFileEikon,0,0,iSessionHandle)); |
|
406 TEST(ret==KErrNone); |
|
407 |
|
408 //Passing an out of bound bitmap id |
|
409 ret=file.Open(iFs,KMbmFileEikon,EFileShareReadersOnly); |
|
410 TEST(ret==KErrNone); |
|
411 TRAP(ret,cache1.GetStreamIdL(file,KMbmFileEikon,78,0,iSessionHandle)); |
|
412 TEST(ret==KErrEof); |
|
413 |
|
414 //Passing an in bound bitmap id |
|
415 ret=file.Open(iFs,KMbmFileEikon,EFileShareReadersOnly); |
|
416 TEST(ret==KErrNone); |
|
417 TRAP(ret,cache1.GetStreamIdL(file,KMbmFileEikon,74,0,iSessionHandle)); |
|
418 TEST(ret==KErrNone); |
|
419 |
|
420 //Passing an out of bound bitmap id |
|
421 ret=file.Open(iFs,KMbmFileEikon,EFileShareReadersOnly); |
|
422 TEST(ret==KErrNone); |
|
423 TRAP(ret,cache1.GetStreamIdL(file,KMbmFileEikon,78,0,iSessionHandle)); |
|
424 TEST(ret==KErrEof); |
|
425 |
|
426 //Passing an in bound bitmap id |
|
427 ret=file.Open(iFs,KMbmFileEikon,EFileShareReadersOnly); |
|
428 TEST(ret==KErrNone); |
|
429 TRAP(ret,cache1.GetStreamIdL(file,KMbmFileEikon,77,0,iSessionHandle)); |
|
430 TEST(ret==KErrNone); |
|
431 |
|
432 |
|
433 //Passing negative bitmap id |
|
434 ret=file.Open(iFs,KMbmFileEikon,EFileShareReadersOnly); |
|
435 TEST(ret==KErrNone); |
|
436 TRAP(ret,cache1.GetStreamIdL(file,KMbmFileEikon,-1,0,iSessionHandle)); |
|
437 TEST(ret==KErrEof); |
|
438 |
|
439 //Passing an invalid file name |
|
440 ret=file.Open(iFs,_L("invalid.mbm"),EFileShareReadersOnly); |
|
441 cache1.FlushCache(); |
|
442 TEST((ret==KErrNotFound)||(ret==KErrPathNotFound)); |
|
443 |
|
444 //Passing an invalid file offset |
|
445 ret=file.Open(iFs,KMbmFileEikon,EFileShareReadersOnly); |
|
446 TEST(ret==KErrNone); |
|
447 TRAP(ret,cache1.GetStreamIdL(file,KMbmFileEikon,12,10,iSessionHandle)); |
|
448 TEST(ret==KErrNotSupported); |
|
449 |
|
450 //Tests for INC047122 and INC046632 |
|
451 TInt err(KErrNone); |
|
452 TInt id(0); |
|
453 for (; id<100; id++) |
|
454 { |
|
455 err=file.Open(iFs,KMbmFileEikon,EFileShareReadersOnly); |
|
456 TEST(err==KErrNone); |
|
457 TRAP(err,cache1.GetStreamIdL(file,KMbmFileEikon,id,0,iSessionHandle)); |
|
458 if(err != KErrNone) |
|
459 break; |
|
460 } |
|
461 TEST(id==78); |
|
462 INFO_PRINTF2(_L("Starting from 0 the number of bitmaps in KMbmFileEikon is calculated to be %d\n\n"), id); |
|
463 |
|
464 delete cache1ptr; |
|
465 |
|
466 // New cache, start from Id 50 |
|
467 CFbTopStreamIdCache* cache2ptr = new CFbTopStreamIdCache(30,30,1); |
|
468 CFbTopStreamIdCache& cache2 = *cache2ptr; |
|
469 for (id=50, err=KErrNone; id<100; id++) |
|
470 { |
|
471 err=file.Open(iFs,KMbmFileEikon,EFileShareReadersOnly); |
|
472 TEST(err==KErrNone); |
|
473 TRAP(err,cache2.GetStreamIdL(file,KMbmFileEikon,id,0,iSessionHandle)); |
|
474 if(err != KErrNone) |
|
475 break; |
|
476 } |
|
477 TEST(id==78); |
|
478 INFO_PRINTF2(_L("Starting from 50 the number of bitmaps in KMbmFileEikon is calculated to be %d\n\n"), id); |
|
479 |
|
480 delete cache2ptr; |
|
481 } |
|
482 |
|
483 /** |
|
484 @SYMTestCaseID |
|
485 GRAPHICS-FBSERV-0582 |
|
486 |
|
487 @SYMTestCaseDesc |
|
488 Tests the out of memory condition during memory |
|
489 allocation inside the test function GetStreamIdL |
|
490 to ensure that there is no memory leaks. |
|
491 |
|
492 @SYMTestActions |
|
493 Tests the cache by opening a file and calls GetStreamIdL |
|
494 and checks the heap for memory leaks. Tests the cache |
|
495 for a cache hit. Test the cache for a cache miss. |
|
496 |
|
497 @SYMTestExpectedResults |
|
498 Test should pass |
|
499 */ |
|
500 void CTStreamIdCache::TestOOMCondition() |
|
501 { |
|
502 INFO_PRINTF1(_L("Test of CFbTopStreamIdCache OOM")); |
|
503 |
|
504 // Test a cache for the first time |
|
505 for (TInt count = 1; ; count++) |
|
506 { |
|
507 __UHEAP_MARK; |
|
508 CFbTopStreamIdCache* cache=new CFbTopStreamIdCache(30,30,1); |
|
509 |
|
510 __UHEAP_SETFAIL(RHeap::EDeterministic,count); |
|
511 RFile file; |
|
512 TInt ret=file.Open(iFs,KMbmFileEikon,EFileShareReadersOnly); |
|
513 TEST(ret==KErrNone); |
|
514 TRAP(ret,cache->GetStreamIdL(file,KMbmFileEikon,30,0,iSessionHandle)); |
|
515 __UHEAP_RESET; |
|
516 |
|
517 delete cache; |
|
518 __UHEAP_MARKEND; |
|
519 |
|
520 if (ret==KErrNone) |
|
521 break; |
|
522 TEST(ret==KErrNoMemory); |
|
523 } |
|
524 |
|
525 // Test a cache hit |
|
526 for (TInt count = 1; ; count++) |
|
527 { |
|
528 __UHEAP_MARK; |
|
529 CFbTopStreamIdCache* cache=new CFbTopStreamIdCache(30,30,1); |
|
530 |
|
531 RFile file1; |
|
532 TInt ret=file1.Open(iFs,KMbmFileEikon,EFileShareReadersOnly); |
|
533 TEST(ret==KErrNone); |
|
534 TRAP(ret,cache->GetStreamIdL(file1,KMbmFileEikon,30,0,iSessionHandle)); |
|
535 TEST(ret==KErrNone); |
|
536 |
|
537 __UHEAP_SETFAIL(RHeap::EDeterministic,count); |
|
538 RFile file; |
|
539 ret=file.Open(iFs,KMbmFileEikon,EFileShareReadersOnly); |
|
540 TEST(ret==KErrNone); |
|
541 TRAP(ret,cache->GetStreamIdL(file,KMbmFileEikon,30,0,iSessionHandle)); |
|
542 __UHEAP_RESET; |
|
543 |
|
544 delete cache; |
|
545 __UHEAP_MARKEND; |
|
546 |
|
547 if (ret==KErrNone) |
|
548 break; |
|
549 TEST(ret==KErrNoMemory); |
|
550 } |
|
551 |
|
552 // Test a cache miss |
|
553 for (TInt count = 1; ; count++) |
|
554 { |
|
555 __UHEAP_MARK; |
|
556 CFbTopStreamIdCache* cache=new CFbTopStreamIdCache(30,30,1); |
|
557 |
|
558 RFile file1; |
|
559 TInt ret=file1.Open(iFs,KMbmFileLafcurs,EFileShareReadersOnly); |
|
560 TEST(ret==KErrNone); |
|
561 TRAP(ret,cache->GetStreamIdL(file1,KMbmFileLafcurs,0,0,iSessionHandle)); |
|
562 TEST(ret==KErrNone); |
|
563 |
|
564 __UHEAP_SETFAIL(RHeap::EDeterministic,count); |
|
565 RFile file; |
|
566 ret=file.Open(iFs,KMbmFileEikon,EFileShareReadersOnly); |
|
567 TEST(ret==KErrNone); |
|
568 TRAP(ret,cache->GetStreamIdL(file,KMbmFileEikon,30,0,iSessionHandle)); |
|
569 __UHEAP_RESET; |
|
570 |
|
571 delete cache; |
|
572 __UHEAP_MARKEND; |
|
573 |
|
574 if (ret==KErrNone) |
|
575 { |
|
576 __UHEAP_SETFAIL(RHeap::ENone,count); |
|
577 break; |
|
578 } |
|
579 TEST(ret==KErrNoMemory); |
|
580 } |
|
581 } |
|
582 |
|
583 /** |
|
584 @SYMTestCaseID |
|
585 GRAPHICS-FBSERV-0583 |
|
586 |
|
587 @SYMTestCaseDesc |
|
588 This test is used to measure the performance improvement |
|
589 when the font bitmap server is using a cache to store the |
|
590 stream ids. |
|
591 |
|
592 @SYMTestActions |
|
593 Starts the timing. Gets the current time. Creates a FbsBitmap |
|
594 on the heap. Simulates loading during boot time by loading |
|
595 bitmaps from ROM. Does forward testing before optimised duration. |
|
596 Retreives the current time and calculates the time taken by the tests. |
|
597 Does forward testing after optimised duration. Does backward testing |
|
598 before optimised duration. Does backward testing after optimised duration. |
|
599 |
|
600 @SYMTestExpectedResults |
|
601 Test should pass |
|
602 */ |
|
603 void CTStreamIdCache::TestPerformance() |
|
604 { |
|
605 //Start the timing |
|
606 TTime starttime; |
|
607 starttime.UniversalTime(); |
|
608 |
|
609 CFbsBitmap* bitmap=new (ELeave) CFbsBitmap; |
|
610 TInt ret; |
|
611 //simulating loading during boottime |
|
612 TInt i,j; |
|
613 for (i=0;i<30;i++) |
|
614 { |
|
615 for (j=0;j<10;j++) |
|
616 { |
|
617 ret=bitmap->Load(KMbmFileEikon,j,EFalse); |
|
618 TEST(ret==KErrNone); |
|
619 } |
|
620 for (j=0;j<2;j++) |
|
621 { |
|
622 ret=bitmap->Load(_L("z:\\system\\data\\tfbs.mbm"),j,EFalse); |
|
623 TEST(ret==KErrNone); |
|
624 } |
|
625 for (j=0;j<28;j++) |
|
626 { |
|
627 ret=bitmap->Load(KMbmFileLafcurs,j,EFalse); |
|
628 TEST(ret==KErrNone); |
|
629 } |
|
630 for (j=71;j<73;j++) |
|
631 { |
|
632 ret=bitmap->Load(KMbmFileEikon,j,EFalse); |
|
633 TEST(ret==KErrNone); |
|
634 } |
|
635 for (j=0;j<2;j++) |
|
636 { |
|
637 ret=bitmap->Load(_L("z:\\system\\data\\tfbs.mbm"),j,EFalse); |
|
638 TEST(ret==KErrNone); |
|
639 } |
|
640 for (j=20;j<22;j++) |
|
641 { |
|
642 ret=bitmap->Load(KMbmFileLafcurs,j,EFalse); |
|
643 TEST(ret==KErrNone); |
|
644 } |
|
645 } |
|
646 |
|
647 TTime endtime; |
|
648 endtime.UniversalTime(); |
|
649 INFO_PRINTF1(_L("Forward Testing Before optimised duration= 3515625 microseconds \n")); |
|
650 TTimeIntervalMicroSeconds difftime=endtime.MicroSecondsFrom(starttime); |
|
651 INFO_PRINTF2(_L("Forward Testing After optimised duration=%Ld microseconds\n\n"),difftime.Int64()); |
|
652 |
|
653 starttime.UniversalTime(); |
|
654 for (i=0;i<30;i++) |
|
655 { |
|
656 for (j=10;j>=0;j--) |
|
657 { |
|
658 ret=bitmap->Load(KMbmFileEikon,j,EFalse); |
|
659 TEST(ret==KErrNone); |
|
660 } |
|
661 for (j=1;j>=0;j--) |
|
662 { |
|
663 ret=bitmap->Load(_L("z:\\system\\data\\tfbs.mbm"),j,EFalse); |
|
664 TEST(ret==KErrNone); |
|
665 } |
|
666 for (j=27;j>=0;j--) |
|
667 { |
|
668 ret=bitmap->Load(KMbmFileLafcurs,j,EFalse); |
|
669 TEST(ret==KErrNone); |
|
670 } |
|
671 for (j=73;j>=72;j--) |
|
672 { |
|
673 ret=bitmap->Load(KMbmFileEikon,j,EFalse); |
|
674 TEST(ret==KErrNone); |
|
675 } |
|
676 for (j=1;j>=0;j--) |
|
677 { |
|
678 ret=bitmap->Load(_L("z:\\system\\data\\tfbs.mbm"),j,EFalse); |
|
679 TEST(ret==KErrNone); |
|
680 } |
|
681 for (j=22;j>=20;j--) |
|
682 { |
|
683 ret=bitmap->Load(KMbmFileLafcurs,j,EFalse); |
|
684 TEST(ret==KErrNone); |
|
685 } |
|
686 } |
|
687 endtime.UniversalTime(); |
|
688 difftime=endtime.MicroSecondsFrom(starttime); |
|
689 INFO_PRINTF1(_L("Backward Testing Before optimised duration= 3515625 microseconds \n")); |
|
690 INFO_PRINTF2(_L("Backward Testing After optimised duration=%Ld microseconds\n\n"),difftime.Int64()); |
|
691 |
|
692 starttime.UniversalTime(); |
|
693 for (i=0;i<30;i++) |
|
694 { |
|
695 for (j=40;j<70;j++) |
|
696 { |
|
697 ret=bitmap->Load(KMbmFileEikon,j,EFalse); |
|
698 TEST(ret==KErrNone); |
|
699 ret=bitmap->Load(KMbmFileEikon2,j,EFalse); |
|
700 TEST(ret==KErrNone); |
|
701 ret=bitmap->Load(KMbmFileEikon3,j,EFalse); |
|
702 TEST(ret==KErrNone); |
|
703 ret=bitmap->Load(KMbmFileEikon4,j,EFalse); |
|
704 TEST(ret==KErrNone); |
|
705 ret=bitmap->Load(KMbmFileEikon5,j,EFalse); |
|
706 TEST(ret==KErrNone); |
|
707 } |
|
708 } |
|
709 endtime.UniversalTime(); |
|
710 difftime=endtime.MicroSecondsFrom(starttime); |
|
711 INFO_PRINTF1(_L("Multiple File Testing Before optimised duration= ? microseconds \n")); |
|
712 INFO_PRINTF2(_L("Multiple File Testing After optimised duration=%Ld microseconds\n\n"),difftime.Int64()); |
|
713 |
|
714 starttime.UniversalTime(); |
|
715 for (i=0;i<30;i++) |
|
716 { |
|
717 for (j=0;j<30;j++) |
|
718 { |
|
719 ret=bitmap->Load(KMbmFileEikon,j,EFalse); |
|
720 TEST(ret==KErrNone); |
|
721 } |
|
722 for (j=40;j<70;j++) |
|
723 { |
|
724 ret=bitmap->Load(KMbmFileEikon,j,EFalse); |
|
725 TEST(ret==KErrNone); |
|
726 } |
|
727 } |
|
728 endtime.UniversalTime(); |
|
729 difftime=endtime.MicroSecondsFrom(starttime); |
|
730 INFO_PRINTF1(_L("Single File Testing Before optimised duration= ? microseconds \n")); |
|
731 INFO_PRINTF2(_L("Single File Testing After optimised duration=%Ld microseconds\n\n"),difftime.Int64()); |
|
732 |
|
733 bitmap->Reset(); |
|
734 delete bitmap; |
|
735 |
|
736 } |
|
737 |
|
738 /** |
|
739 @SYMTestCaseID |
|
740 GRAPHICS-FBSERV-0584 |
|
741 |
|
742 @SYMTestCaseDesc |
|
743 Tests loading of bitmaps at an offset |
|
744 (Bitmap file section offset within the file). |
|
745 |
|
746 @SYMTestActions |
|
747 Creates an FbsBitmap object on the heap. Loads |
|
748 a monochrone bitmap with zero offset. Checks if |
|
749 loading completed successfully. Checks the pixel |
|
750 size. Gets a pixel. Checks if pixel is KRgbBlack. |
|
751 |
|
752 @SYMTestExpectedResults |
|
753 Test should pass |
|
754 */ |
|
755 void CTStreamIdCache::TestLoadAtOffset() |
|
756 { |
|
757 CFbsBitmap* bitmap = NULL; |
|
758 TRAPD(ret, bitmap = new (ELeave) CFbsBitmap); |
|
759 TEST(ret==KErrNone); |
|
760 if(iStep->TestStepResult() != EPass) |
|
761 { |
|
762 return; |
|
763 } |
|
764 INFO_PRINTF1(_L("Testing repeated CFbsBitmap Load with different offsets")); |
|
765 |
|
766 do // use a do{}while(false) so we can break out of the test code and fall back to the cleanup code |
|
767 { |
|
768 ret = bitmap->Load(KBlackAndWhite, 0, EFalse, 0); |
|
769 TEST(ret==KErrNone); |
|
770 if(iStep->TestStepResult() != EPass) |
|
771 { |
|
772 INFO_PRINTF1(_L("TestLoadAtOffset: Failed to load first mbm")); |
|
773 break; |
|
774 } |
|
775 |
|
776 TEST( bitmap->SizeInPixels() == TSize(1,1) && bitmap->IsMonochrome() ); |
|
777 if(iStep->TestStepResult() == EPass) |
|
778 { |
|
779 TRgb colour; |
|
780 bitmap->GetPixel(colour, TPoint(0,0)); |
|
781 TEST( colour == KRgbBlack ); |
|
782 } |
|
783 |
|
784 if(iStep->TestStepResult() != EPass) |
|
785 { |
|
786 INFO_PRINTF1(_L("TestLoadAtOffset: First mbm loaded incorrectly")); |
|
787 break; |
|
788 } |
|
789 |
|
790 ret = bitmap->Load(KBlackAndWhite, 0, EFalse, WHITE_OFFSET); |
|
791 TEST(ret==KErrNone); |
|
792 if(iStep->TestStepResult() != EPass) |
|
793 { |
|
794 INFO_PRINTF1(_L("TestLoadAtOffset: Failed to load second mbm")); |
|
795 break; |
|
796 } |
|
797 |
|
798 TEST( bitmap->SizeInPixels() == TSize(1,1) && bitmap->IsMonochrome() ); |
|
799 if(iStep->TestStepResult() == EPass) |
|
800 { |
|
801 TRgb colour; |
|
802 bitmap->GetPixel(colour, TPoint(0,0)); |
|
803 TEST( colour == KRgbWhite ); |
|
804 } |
|
805 |
|
806 if(iStep->TestStepResult() != EPass) |
|
807 { |
|
808 INFO_PRINTF1(_L("TestLoadAtOffset: Second mbm loaded incorrectly")); |
|
809 break; |
|
810 } |
|
811 } while( EFalse ); |
|
812 |
|
813 bitmap->Reset(); |
|
814 delete bitmap; |
|
815 } |
|
816 |
|
817 /** |
|
818 @SYMTestCaseID GRAPHICS-FBSERV-0509 |
|
819 |
|
820 @SYMDEF DEF104261 |
|
821 |
|
822 @SYMTestCaseDesc Tests file store cleanup for corresponding fbs session |
|
823 |
|
824 @SYMTestPriority Medium |
|
825 |
|
826 @SYMTestStatus Implemented |
|
827 |
|
828 @SYMTestActions 1. Create a file store object from file stream cache using current session handle |
|
829 2. Create new file store object using some dummy session handle |
|
830 3. Check two file store object belongs to the corresponding dummy session handle. |
|
831 4. Close file store and check |
|
832 - if corresponing session's handle file store used to close. |
|
833 - if we send wrong session handle none of the file store should close |
|
834 - if we haven't send any session handle close all the file store object irrespective of the session handle |
|
835 |
|
836 @SYMTestExpectedResults 1. File store should close only for the corresponding session, while disconnecting the session |
|
837 2. By flushing cache should close all file stores and reset cache entries, irrespective of the session |
|
838 */ |
|
839 void CTStreamIdCache::TestSessionClose() |
|
840 { |
|
841 TInt ret; |
|
842 |
|
843 INFO_PRINTF1(_L("Test file store clean up")); |
|
844 |
|
845 CFbTopStreamIdCache* mbmcacheptr = new CFbTopStreamIdCache(30,30,2); |
|
846 CFbTopStreamIdCache& mbmcache = *mbmcacheptr; |
|
847 RFile file1; |
|
848 ret=file1.Open(iFs,KMbmFileEikon,EFileShareReadersOnly); |
|
849 TEST(ret==KErrNone); |
|
850 RFile file2; |
|
851 ret=file2.Open(iFs,KMbmFileLafcurs,EFileShareReadersOnly); |
|
852 TEST(ret==KErrNone); |
|
853 |
|
854 //Create a file store with dummy session handle 1 |
|
855 TRAP(ret,mbmcache.GetStreamIdL(file1,KMbmFileEikon,50,0,1)); |
|
856 TEST(ret==KErrNone); |
|
857 //Create a file store with dummy session handle 2 |
|
858 TRAP(ret,mbmcache.GetStreamIdL(file2,KMbmFileLafcurs,12,0,2)); |
|
859 TEST(ret==KErrNone); |
|
860 TEST(mbmcache.iEntries.Count() == 2); |
|
861 |
|
862 TEST(2==mbmcache.iEntries[0]->SessionHandle()); |
|
863 TEST(1==mbmcache.iEntries[1]->SessionHandle()); |
|
864 TEST(mbmcache.iEntries[0]->iFilestore!=NULL); |
|
865 TEST(mbmcache.iEntries[1]->iFilestore!=NULL); |
|
866 |
|
867 mbmcache.CloseFileStores(1); |
|
868 TEST(mbmcache.iEntries.Count() == 2); |
|
869 TEST(mbmcache.iEntries[0]->iFilestore!=NULL); |
|
870 TEST(mbmcache.iEntries[1]->iFilestore==NULL); |
|
871 TEST(2==mbmcache.iEntries[0]->SessionHandle()); |
|
872 TEST(0==mbmcache.iEntries[1]->SessionHandle()); |
|
873 |
|
874 //All File stores should deleted |
|
875 mbmcache.CloseFileStores(0); |
|
876 TEST(mbmcache.iEntries.Count() == 2); |
|
877 TEST(mbmcache.iEntries[0]->iFilestore==NULL); |
|
878 TEST(mbmcache.iEntries[1]->iFilestore==NULL); |
|
879 TEST(0==mbmcache.iEntries[0]->SessionHandle()); |
|
880 TEST(0==mbmcache.iEntries[1]->SessionHandle()); |
|
881 |
|
882 // Should remove all the file store objects and reset the cache entries. |
|
883 mbmcache.FlushCache(); |
|
884 TEST(mbmcache.iEntries.Count() == 0); |
|
885 |
|
886 delete mbmcacheptr; |
|
887 } |
|
888 |
|
889 |
|
890 //-------------- |
|
891 __CONSTRUCT_STEP__(StreamIdCache) |
|
892 |
|
893 |
|
894 void CTStreamIdCacheStep::TestSetupL() |
|
895 { |
|
896 // Leaking thread handles |
|
897 iThread.HandleCount(iStartProcessHandleCount, iStartThreadHandleCount); |
|
898 } |
|
899 |
|
900 void CTStreamIdCacheStep::TestClose() |
|
901 { |
|
902 // Check for open handles |
|
903 iThread.HandleCount(iEndProcessHandleCount, iEndThreadHandleCount); |
|
904 if(iStartThreadHandleCount != iEndThreadHandleCount) |
|
905 {__DEBUGGER()} // Oops leaked some handles |
|
906 } |