1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/fbs/fontandbitmapserver/tfbs/TStreamIdCache.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,906 @@
1.4 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +// Epoc includes
1.20 +#include "../inc/FBSMBMC.H"
1.21 +#include "../sfbs/UTILS.H"
1.22 +#include "TStreamIdCache.h"
1.23 +#include "fbsmessage.h"
1.24 +#include "fbsdefs.h"
1.25 +
1.26 +//Eikon has 78 bitmaps inside the mbm file(id 0-77)
1.27 +_LIT(KMbmFileEikon, "z:\\System\\Data\\tfbs_file4.mbm");
1.28 +_LIT(KMbmFileEikon2, "z:\\System\\Data\\tfbs_file4a.mbm");
1.29 +_LIT(KMbmFileEikon3, "z:\\System\\Data\\tfbs_file4b.mbm");
1.30 +_LIT(KMbmFileEikon4, "z:\\System\\Data\\tfbs_file4c.mbm");
1.31 +_LIT(KMbmFileEikon5, "z:\\System\\Data\\tfbs_file4d.mbm");
1.32 +//Lafcurs has 28 bitmaps inside the mbm file(id 0-27)
1.33 +_LIT(KMbmFileLafcurs, "z:\\System\\Data\\tfbs_file2.mbm");
1.34 +//Resource file containing mbm file
1.35 +_LIT(KMbmFileTFBSRSC, "z:\\System\\Data\\tfbs_rsc.rsc");
1.36 +_LIT(KRscFileHeader, "z:\\system\\data\\RscHeader3.bin");
1.37 +_LIT(KRscFileData, "z:\\system\\data\\DummyRscFile3.rsc");
1.38 +
1.39 +// File with two 1x1 px mbm files: first is black, second is white. white mbm at 72 bytes into file
1.40 +#define WHITE_OFFSET 72
1.41 +_LIT(KBlackAndWhite, "z:\\system\\data\\blackandwhite.mbm");
1.42 +
1.43 +// ============================================================================
1.44 +
1.45 +//Default Constructor
1.46 +CTStreamIdCache::CTStreamIdCache(CTestStep* aStep):
1.47 + CTGraphicsBase(aStep),
1.48 + iFbs(NULL)
1.49 + {
1.50 + }
1.51 +
1.52 +CTStreamIdCache::~CTStreamIdCache()
1.53 + {
1.54 + if(iShutdownFbs)
1.55 + RFbsSession::GetSession()->SendCommand(EFbsMessShutdown);
1.56 + RFbsSession::Disconnect();
1.57 + iFs.Close();
1.58 + }
1.59 +
1.60 +void CTStreamIdCache::ConstructL()
1.61 + {
1.62 + if(RFbsSession::Connect()==KErrNone)
1.63 + {
1.64 + iShutdownFbs = EFalse;
1.65 + }
1.66 + else
1.67 + {
1.68 + FbsStartup();
1.69 + RFbsSession::Connect();
1.70 + iShutdownFbs = ETrue;
1.71 + }
1.72 +
1.73 + iFs.Connect();
1.74 +
1.75 + iFbs = RFbsSession::GetSession();
1.76 + iSessionHandle = iFbs->SessionHandle();
1.77 + ExpandCleanupStackL();
1.78 +
1.79 + INFO_PRINTF1(_L("FBS Bitmap StreamId cache testing"));
1.80 + }
1.81 +
1.82 +void CTStreamIdCache::RunTestCaseL(TInt aCurTestCase)
1.83 + {
1.84 + ((CTStreamIdCacheStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
1.85 + switch(aCurTestCase)
1.86 + {
1.87 + case 1:
1.88 + ((CTStreamIdCacheStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0577"));
1.89 + TestStreamIdCacheEntry();
1.90 + break;
1.91 + case 2:
1.92 + ((CTStreamIdCacheStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0578"));
1.93 + TestProcessingBitmapStream();
1.94 + break;
1.95 + case 3:
1.96 + ((CTStreamIdCacheStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0580"));
1.97 + TestReplacingFile();
1.98 + break;
1.99 + case 4:
1.100 + ((CTStreamIdCacheStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0579"));
1.101 + TestComparingStreams();
1.102 + break;
1.103 + case 5:
1.104 + ((CTStreamIdCacheStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0581"));
1.105 + TestInvalidArgument();
1.106 + break;
1.107 + case 6:
1.108 + ((CTStreamIdCacheStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0582"));
1.109 + TestOOMCondition();
1.110 + break;
1.111 + case 7:
1.112 + ((CTStreamIdCacheStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0583"));
1.113 + TestPerformance();
1.114 + break;
1.115 + case 8:
1.116 + ((CTStreamIdCacheStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0584"));
1.117 + TestLoadAtOffset();
1.118 + break;
1.119 + case 9:
1.120 + ((CTStreamIdCacheStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0509"));
1.121 + TestSessionClose();
1.122 + break;
1.123 + case 10:
1.124 + ((CTStreamIdCacheStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
1.125 + ((CTStreamIdCacheStep*)iStep)->CloseTMSGraphicsStep();
1.126 + TestComplete();
1.127 + break;
1.128 + }
1.129 + ((CTStreamIdCacheStep*)iStep)->RecordTestResultL();
1.130 + }
1.131 +
1.132 +//This function is here to measure the offset in the rsc file
1.133 +TInt CTStreamIdCache::FileSizeL(const TDesC& aFileName)
1.134 + {
1.135 + RFile file;
1.136 + User::LeaveIfError(file.Open(iFs, aFileName, EFileRead));
1.137 + CleanupClosePushL(file);
1.138 + TInt size = 0;
1.139 + User::LeaveIfError(file.Size(size));
1.140 + CleanupStack::PopAndDestroy(&file);
1.141 + return size;
1.142 + }
1.143 +
1.144 +void CTStreamIdCache::ExpandCleanupStackL()
1.145 + {
1.146 + TInt count=0;
1.147 + for(;count<10;count++)
1.148 + CleanupStack::PushL((TUint32*)0x1);
1.149 + CleanupStack::Pop(count);
1.150 + }
1.151 +
1.152 +/**
1.153 + @SYMTestCaseID
1.154 + GRAPHICS-FBSERV-0577
1.155 +
1.156 + @SYMTestCaseDesc
1.157 + Tests the API functionality of the class ensuring
1.158 + the internal states are correct during the construction
1.159 + and other operation.
1.160 +
1.161 + @SYMTestActions
1.162 + Tests the API on a defaultly built element object.
1.163 +
1.164 + @SYMTestExpectedResults
1.165 + Test should pass
1.166 +*/
1.167 +void CTStreamIdCache::TestStreamIdCacheEntry()
1.168 + {
1.169 + INFO_PRINTF1(_L("Test of CFbTopStreamIdCache API"));
1.170 +
1.171 + // Test the API on a defaultly built element object
1.172 +
1.173 + CFbTopStreamIdCache* mbmcache=new CFbTopStreamIdCache(20,30,1);
1.174 + TEST(mbmcache->iEntries.Count() == 0);
1.175 + TEST(mbmcache->iMaxCacheFilestores == 1);
1.176 + TEST(mbmcache->iBackwardCacheSize ==30);
1.177 + TEST(mbmcache->iForwardCacheSize ==20);
1.178 +
1.179 + delete mbmcache;
1.180 +
1.181 + }
1.182 +
1.183 +/**
1.184 + @SYMTestCaseID
1.185 + GRAPHICS-FBSERV-0578
1.186 +
1.187 + @SYMTestCaseDesc
1.188 + Tests the loading of a bitmap from an mbm file using
1.189 + the cache and the content of the cache after the loading
1.190 + i.e. how many stream ids are stored, the last bitmap file
1.191 + name, the last id, the cache forward and backward size.
1.192 +
1.193 + @SYMTestActions
1.194 + Tests the GetStreamIdL method. Loads eikon.mbm with 78
1.195 + bitmap files. Tests loading some rsc file which contains offset.
1.196 + Tests the flushing.
1.197 +
1.198 + @SYMTestExpectedResults
1.199 + Test should pass
1.200 +*/
1.201 +void CTStreamIdCache::TestProcessingBitmapStream()
1.202 + {
1.203 + TInt ret;
1.204 +
1.205 + INFO_PRINTF1(_L("Test loading a bitmap file and processing the stream id"));
1.206 +
1.207 + //Testing the GetStreamIdL method
1.208 + CFbTopStreamIdCache* mbmcacheptr = new CFbTopStreamIdCache(30,30,1);
1.209 + CFbTopStreamIdCache& mbmcache = *mbmcacheptr;
1.210 + INFO_PRINTF1(_L("Loading eikon.mbm with 78 bitmap files"));
1.211 + //Loading eikon.mbm with 78 bitmap files
1.212 + RFile file;
1.213 + ret=file.Open(iFs,KMbmFileEikon,EFileShareReadersOnly);
1.214 + TEST(ret==KErrNone);
1.215 + TRAP(ret,mbmcache.GetStreamIdL(file,KMbmFileEikon,50,0,iSessionHandle));
1.216 + TEST(ret==KErrNone);
1.217 + //the cache only stores 30 ids before 50 + max of 30 after(including 50)
1.218 + //but in this case the bitmap only has 78 bitmaps so it only stores 28 after
1.219 + TEST(mbmcache.iEntries.Count() == 1);
1.220 + TEST(mbmcache.iEntries[0]->iStreamIdCount==58);
1.221 + TEST(mbmcache.iEntries[0]->iLastId==50);
1.222 + TEST(mbmcache.iForwardCacheSize==30);
1.223 + TEST(mbmcache.iBackwardCacheSize==30);
1.224 + TEST(mbmcache.iEntries[0]->iFilename.CompareF(KMbmFileEikon)==0);
1.225 + TEST(mbmcache.iEntries[0]->iFilestore!=NULL);
1.226 +
1.227 + //Test loading some rsc file which contains offset
1.228 + TInt mbm_offset = FileSizeL(KRscFileHeader) + FileSizeL(KRscFileData);
1.229 + ret=file.Open(iFs,KMbmFileTFBSRSC,EFileShareReadersOnly);
1.230 + TEST(ret==KErrNone);
1.231 + TRAP(ret,mbmcache.GetStreamIdL(file,KMbmFileTFBSRSC,0,mbm_offset,iSessionHandle));
1.232 + TEST(ret==KErrNone);
1.233 + TEST(mbmcache.iEntries.Count() == 1);
1.234 + TEST(mbmcache.iEntries[0]->iLastId==0);
1.235 + TEST(mbmcache.iEntries[0]->iStreamIdCount==2);
1.236 + TEST(mbmcache.iEntries[0]->iFilename.CompareF(KMbmFileTFBSRSC)==0);
1.237 +
1.238 + // Test the flushing
1.239 + mbmcache.FlushCache();
1.240 + TEST(mbmcache.iEntries.Count() == 0);
1.241 + TEST(mbmcache.iMaxCacheFilestores == 1);
1.242 + TEST(mbmcache.iBackwardCacheSize == 30);
1.243 + TEST(mbmcache.iForwardCacheSize == 30);
1.244 +
1.245 + delete mbmcacheptr;
1.246 + }
1.247 +
1.248 +/**
1.249 + @SYMTestCaseID
1.250 + GRAPHICS-FBSERV-0579
1.251 +
1.252 + @SYMTestCaseDesc
1.253 + Tests the correct functionality of the cache storing the stream ids.
1.254 + Three different caches are used to load the same mbm file but the
1.255 + bitmap id to be loaded are different however the bitmap ids are chosen in
1.256 + such a way that these three caches will store some common bitmap id.
1.257 + We then accessed the cache content and check that these three caches
1.258 + will give the same stream id values for that common bitmap id.
1.259 +
1.260 + @SYMTestActions
1.261 +
1.262 + @SYMTestExpectedResults
1.263 + Test should pass
1.264 +*/
1.265 +void CTStreamIdCache::TestComparingStreams()
1.266 + {
1.267 + TInt ret;
1.268 +
1.269 + INFO_PRINTF1(_L("Test comparing the stream ids from three different caches"));
1.270 +
1.271 + CFbTopStreamIdCache* cache1=new CFbTopStreamIdCache(30,30,1);
1.272 + CFbTopStreamIdCache* cache2=new CFbTopStreamIdCache(10,30,1);
1.273 + CFbTopStreamIdCache* cache3=new CFbTopStreamIdCache(25,5,1);
1.274 +
1.275 + //CACHE1 Loading this will fill up the streams with ids from 0-55
1.276 + RFile file;
1.277 + ret=file.Open(iFs,KMbmFileEikon,EFileShareReadersOnly);
1.278 + TEST(ret==KErrNone);
1.279 + TRAP(ret,cache1->GetStreamIdL(file,KMbmFileEikon,25,0,iSessionHandle));
1.280 + TEST(ret==KErrNone);
1.281 + TEST(cache1->iEntries.Count() == 1);
1.282 + TEST(cache1->iEntries[0]->iStreamIdCount==55);
1.283 + TEST(cache1->iEntries[0]->iLastId==25);
1.284 + //now storing the actual TStreamId for bitmap id 26 for future comparison
1.285 + //stream id for bitmapid=26 will be @ the 26th position inside the array
1.286 + TStreamId id25_26=cache1->iEntries[0]->iStreamIdCache[26];
1.287 +
1.288 + delete cache1;
1.289 +
1.290 +
1.291 + //CACHE2 Loading this will fill up the streams with ids from 36-65
1.292 + ret=file.Open(iFs,KMbmFileEikon,EFileShareReadersOnly);
1.293 + TEST(ret==KErrNone);
1.294 + TRAP(ret,cache2->GetStreamIdL(file,KMbmFileEikon,56,0,iSessionHandle));
1.295 + TEST(ret==KErrNone);
1.296 + TEST(cache2->iEntries.Count() == 1);
1.297 + TEST(cache2->iEntries[0]->iStreamIdCount==40);
1.298 + TEST(cache2->iEntries[0]->iLastId==56);
1.299 + //stream id for bitmapid=26 will be @ the 0th position inside the array
1.300 + TStreamId id56_26=cache2->iEntries[0]->iStreamIdCache[0];
1.301 + TEST(id25_26.Value()==id56_26.Value());
1.302 +
1.303 + delete cache2;
1.304 +
1.305 + //CACHE3 Loading this will fill up the streams with ids from 1-30
1.306 + ret=file.Open(iFs,KMbmFileEikon,EFileShareReadersOnly);
1.307 + TEST(ret==KErrNone);
1.308 + TRAP(ret,cache3->GetStreamIdL(file,KMbmFileEikon,6,0,iSessionHandle));
1.309 + TEST(ret==KErrNone);
1.310 + TEST(cache3->iEntries.Count() == 1);
1.311 + TEST(cache3->iEntries[0]->iStreamIdCount==30);
1.312 + TEST(cache3->iEntries[0]->iLastId==6);
1.313 + TStreamId id6_26=cache3->iEntries[0]->iStreamIdCache[25];
1.314 + TEST(id25_26.Value()==id6_26.Value());
1.315 +
1.316 + delete cache3;
1.317 + }
1.318 +
1.319 +/**
1.320 + @SYMTestCaseID
1.321 + GRAPHICS-FBSERV-0580
1.322 +
1.323 + @SYMTestCaseDesc
1.324 + Tests the functionality of the cache when it has already
1.325 + stored some existing bitmap ids The cache is loaded with a
1.326 + different mbm file and the cache content is examined to make
1.327 + sure it has the correct new data.
1.328 +
1.329 + @SYMTestActions
1.330 +
1.331 + @SYMTestExpectedResults
1.332 + Test should pass
1.333 +*/
1.334 +void CTStreamIdCache::TestReplacingFile()
1.335 + {
1.336 + TInt ret;
1.337 +
1.338 + INFO_PRINTF1(_L("Test loading a file different from previous stored in cache"));
1.339 +
1.340 + CFbTopStreamIdCache* cache1ptr = new CFbTopStreamIdCache(30,30,1);
1.341 + CFbTopStreamIdCache& cache1 = *cache1ptr;
1.342 + RFile file;
1.343 + ret=file.Open(iFs,KMbmFileEikon,EFileShareReadersOnly);
1.344 + TEST(ret==KErrNone);
1.345 + TRAP(ret,cache1.GetStreamIdL(file,KMbmFileEikon,25,0,iSessionHandle));
1.346 + TEST(ret==KErrNone);
1.347 + TEST(cache1.iEntries.Count() == 1);
1.348 + TEST(cache1.iEntries[0]->iStreamIdCount==55);
1.349 + TEST(cache1.iEntries[0]->iLastId==25);
1.350 + TEST(cache1.iEntries[0]->iFilename.Compare(KMbmFileEikon)==0);
1.351 +
1.352 + //Now trying to load an entirely different bitmap file
1.353 + //and check to ensure the cache has reflushed itself
1.354 + //and load itself with new stuff
1.355 + ret=file.Open(iFs,KMbmFileLafcurs,EFileShareReadersOnly);
1.356 + TEST(ret==KErrNone);
1.357 + TRAP(ret,cache1.GetStreamIdL(file,KMbmFileLafcurs,12,0,iSessionHandle));
1.358 + TEST(ret==KErrNone);
1.359 + TEST(cache1.iEntries.Count() == 1);
1.360 + TEST(cache1.iEntries[0]->iStreamIdCount==28);
1.361 + TEST(cache1.iEntries[0]->iLastId==12);
1.362 + TEST(cache1.iEntries[0]->iFilename.Compare(KMbmFileLafcurs)==0);
1.363 +
1.364 + delete cache1ptr;
1.365 + }
1.366 +
1.367 +/**
1.368 + @SYMTestCaseID
1.369 + GRAPHICS-FBSERV-0581
1.370 +
1.371 + @SYMTestCaseDesc
1.372 + Tests the error values that would be returned by
1.373 + the cache when supplied with invalid arguments such
1.374 + as bad file name negative bitmap ids, out of range
1.375 + bitmap ids, and invalid file offset.
1.376 +
1.377 + @SYMDEF INC047122 INC046632
1.378 +
1.379 + @SYMTestActions
1.380 + Creates an FbTopStreamIdCache object. Tests to ensure the cache
1.381 + can deal with non error cases immediately after error cases.
1.382 + Passing an in bound bitmap id. Passing an out of bound bitmap id.
1.383 + Passing an in bound bitmap id. Passing an out of bound bitmap id.
1.384 + Passing an in bound bitmap id. Passing negative bitmap id.
1.385 + Passing an invalid file name. Passing an invalid file offset.
1.386 +
1.387 + @SYMTestExpectedResults
1.388 + Test should pass
1.389 +*/
1.390 +void CTStreamIdCache::TestInvalidArgument()
1.391 + {
1.392 +
1.393 + TInt ret;
1.394 +
1.395 + INFO_PRINTF1(_L("Test loading a file bitmap with invalid argument"));
1.396 +
1.397 + CFbTopStreamIdCache* cache1ptr = new CFbTopStreamIdCache(30,30,1);
1.398 + CFbTopStreamIdCache& cache1 = *cache1ptr;
1.399 + //Eikon mbm only can accept ids from 0-77
1.400 +
1.401 + //The following sequence of 4 tests ensures the cache can deal with
1.402 + //non error cases immediately after error cases.
1.403 +
1.404 + //Passing an in bound bitmap id
1.405 + RFile file;
1.406 + ret=file.Open(iFs,KMbmFileEikon,EFileShareReadersOnly);
1.407 + TEST(ret==KErrNone);
1.408 + TRAP(ret,cache1.GetStreamIdL(file,KMbmFileEikon,0,0,iSessionHandle));
1.409 + TEST(ret==KErrNone);
1.410 +
1.411 + //Passing an out of bound bitmap id
1.412 + ret=file.Open(iFs,KMbmFileEikon,EFileShareReadersOnly);
1.413 + TEST(ret==KErrNone);
1.414 + TRAP(ret,cache1.GetStreamIdL(file,KMbmFileEikon,78,0,iSessionHandle));
1.415 + TEST(ret==KErrEof);
1.416 +
1.417 + //Passing an in bound bitmap id
1.418 + ret=file.Open(iFs,KMbmFileEikon,EFileShareReadersOnly);
1.419 + TEST(ret==KErrNone);
1.420 + TRAP(ret,cache1.GetStreamIdL(file,KMbmFileEikon,74,0,iSessionHandle));
1.421 + TEST(ret==KErrNone);
1.422 +
1.423 + //Passing an out of bound bitmap id
1.424 + ret=file.Open(iFs,KMbmFileEikon,EFileShareReadersOnly);
1.425 + TEST(ret==KErrNone);
1.426 + TRAP(ret,cache1.GetStreamIdL(file,KMbmFileEikon,78,0,iSessionHandle));
1.427 + TEST(ret==KErrEof);
1.428 +
1.429 + //Passing an in bound bitmap id
1.430 + ret=file.Open(iFs,KMbmFileEikon,EFileShareReadersOnly);
1.431 + TEST(ret==KErrNone);
1.432 + TRAP(ret,cache1.GetStreamIdL(file,KMbmFileEikon,77,0,iSessionHandle));
1.433 + TEST(ret==KErrNone);
1.434 +
1.435 +
1.436 + //Passing negative bitmap id
1.437 + ret=file.Open(iFs,KMbmFileEikon,EFileShareReadersOnly);
1.438 + TEST(ret==KErrNone);
1.439 + TRAP(ret,cache1.GetStreamIdL(file,KMbmFileEikon,-1,0,iSessionHandle));
1.440 + TEST(ret==KErrEof);
1.441 +
1.442 + //Passing an invalid file name
1.443 + ret=file.Open(iFs,_L("invalid.mbm"),EFileShareReadersOnly);
1.444 + cache1.FlushCache();
1.445 + TEST((ret==KErrNotFound)||(ret==KErrPathNotFound));
1.446 +
1.447 + //Passing an invalid file offset
1.448 + ret=file.Open(iFs,KMbmFileEikon,EFileShareReadersOnly);
1.449 + TEST(ret==KErrNone);
1.450 + TRAP(ret,cache1.GetStreamIdL(file,KMbmFileEikon,12,10,iSessionHandle));
1.451 + TEST(ret==KErrNotSupported);
1.452 +
1.453 + //Tests for INC047122 and INC046632
1.454 + TInt err(KErrNone);
1.455 + TInt id(0);
1.456 + for (; id<100; id++)
1.457 + {
1.458 + err=file.Open(iFs,KMbmFileEikon,EFileShareReadersOnly);
1.459 + TEST(err==KErrNone);
1.460 + TRAP(err,cache1.GetStreamIdL(file,KMbmFileEikon,id,0,iSessionHandle));
1.461 + if(err != KErrNone)
1.462 + break;
1.463 + }
1.464 + TEST(id==78);
1.465 + INFO_PRINTF2(_L("Starting from 0 the number of bitmaps in KMbmFileEikon is calculated to be %d\n\n"), id);
1.466 +
1.467 + delete cache1ptr;
1.468 +
1.469 + // New cache, start from Id 50
1.470 + CFbTopStreamIdCache* cache2ptr = new CFbTopStreamIdCache(30,30,1);
1.471 + CFbTopStreamIdCache& cache2 = *cache2ptr;
1.472 + for (id=50, err=KErrNone; id<100; id++)
1.473 + {
1.474 + err=file.Open(iFs,KMbmFileEikon,EFileShareReadersOnly);
1.475 + TEST(err==KErrNone);
1.476 + TRAP(err,cache2.GetStreamIdL(file,KMbmFileEikon,id,0,iSessionHandle));
1.477 + if(err != KErrNone)
1.478 + break;
1.479 + }
1.480 + TEST(id==78);
1.481 + INFO_PRINTF2(_L("Starting from 50 the number of bitmaps in KMbmFileEikon is calculated to be %d\n\n"), id);
1.482 +
1.483 + delete cache2ptr;
1.484 + }
1.485 +
1.486 +/**
1.487 + @SYMTestCaseID
1.488 + GRAPHICS-FBSERV-0582
1.489 +
1.490 + @SYMTestCaseDesc
1.491 + Tests the out of memory condition during memory
1.492 + allocation inside the test function GetStreamIdL
1.493 + to ensure that there is no memory leaks.
1.494 +
1.495 + @SYMTestActions
1.496 + Tests the cache by opening a file and calls GetStreamIdL
1.497 + and checks the heap for memory leaks. Tests the cache
1.498 + for a cache hit. Test the cache for a cache miss.
1.499 +
1.500 + @SYMTestExpectedResults
1.501 + Test should pass
1.502 +*/
1.503 +void CTStreamIdCache::TestOOMCondition()
1.504 + {
1.505 + INFO_PRINTF1(_L("Test of CFbTopStreamIdCache OOM"));
1.506 +
1.507 + // Test a cache for the first time
1.508 + for (TInt count = 1; ; count++)
1.509 + {
1.510 + __UHEAP_MARK;
1.511 + CFbTopStreamIdCache* cache=new CFbTopStreamIdCache(30,30,1);
1.512 +
1.513 + __UHEAP_SETFAIL(RHeap::EDeterministic,count);
1.514 + RFile file;
1.515 + TInt ret=file.Open(iFs,KMbmFileEikon,EFileShareReadersOnly);
1.516 + TEST(ret==KErrNone);
1.517 + TRAP(ret,cache->GetStreamIdL(file,KMbmFileEikon,30,0,iSessionHandle));
1.518 + __UHEAP_RESET;
1.519 +
1.520 + delete cache;
1.521 + __UHEAP_MARKEND;
1.522 +
1.523 + if (ret==KErrNone)
1.524 + break;
1.525 + TEST(ret==KErrNoMemory);
1.526 + }
1.527 +
1.528 + // Test a cache hit
1.529 + for (TInt count = 1; ; count++)
1.530 + {
1.531 + __UHEAP_MARK;
1.532 + CFbTopStreamIdCache* cache=new CFbTopStreamIdCache(30,30,1);
1.533 +
1.534 + RFile file1;
1.535 + TInt ret=file1.Open(iFs,KMbmFileEikon,EFileShareReadersOnly);
1.536 + TEST(ret==KErrNone);
1.537 + TRAP(ret,cache->GetStreamIdL(file1,KMbmFileEikon,30,0,iSessionHandle));
1.538 + TEST(ret==KErrNone);
1.539 +
1.540 + __UHEAP_SETFAIL(RHeap::EDeterministic,count);
1.541 + RFile file;
1.542 + ret=file.Open(iFs,KMbmFileEikon,EFileShareReadersOnly);
1.543 + TEST(ret==KErrNone);
1.544 + TRAP(ret,cache->GetStreamIdL(file,KMbmFileEikon,30,0,iSessionHandle));
1.545 + __UHEAP_RESET;
1.546 +
1.547 + delete cache;
1.548 + __UHEAP_MARKEND;
1.549 +
1.550 + if (ret==KErrNone)
1.551 + break;
1.552 + TEST(ret==KErrNoMemory);
1.553 + }
1.554 +
1.555 + // Test a cache miss
1.556 + for (TInt count = 1; ; count++)
1.557 + {
1.558 + __UHEAP_MARK;
1.559 + CFbTopStreamIdCache* cache=new CFbTopStreamIdCache(30,30,1);
1.560 +
1.561 + RFile file1;
1.562 + TInt ret=file1.Open(iFs,KMbmFileLafcurs,EFileShareReadersOnly);
1.563 + TEST(ret==KErrNone);
1.564 + TRAP(ret,cache->GetStreamIdL(file1,KMbmFileLafcurs,0,0,iSessionHandle));
1.565 + TEST(ret==KErrNone);
1.566 +
1.567 + __UHEAP_SETFAIL(RHeap::EDeterministic,count);
1.568 + RFile file;
1.569 + ret=file.Open(iFs,KMbmFileEikon,EFileShareReadersOnly);
1.570 + TEST(ret==KErrNone);
1.571 + TRAP(ret,cache->GetStreamIdL(file,KMbmFileEikon,30,0,iSessionHandle));
1.572 + __UHEAP_RESET;
1.573 +
1.574 + delete cache;
1.575 + __UHEAP_MARKEND;
1.576 +
1.577 + if (ret==KErrNone)
1.578 + {
1.579 + __UHEAP_SETFAIL(RHeap::ENone,count);
1.580 + break;
1.581 + }
1.582 + TEST(ret==KErrNoMemory);
1.583 + }
1.584 + }
1.585 +
1.586 +/**
1.587 + @SYMTestCaseID
1.588 + GRAPHICS-FBSERV-0583
1.589 +
1.590 + @SYMTestCaseDesc
1.591 + This test is used to measure the performance improvement
1.592 + when the font bitmap server is using a cache to store the
1.593 + stream ids.
1.594 +
1.595 + @SYMTestActions
1.596 + Starts the timing. Gets the current time. Creates a FbsBitmap
1.597 + on the heap. Simulates loading during boot time by loading
1.598 + bitmaps from ROM. Does forward testing before optimised duration.
1.599 + Retreives the current time and calculates the time taken by the tests.
1.600 + Does forward testing after optimised duration. Does backward testing
1.601 + before optimised duration. Does backward testing after optimised duration.
1.602 +
1.603 + @SYMTestExpectedResults
1.604 + Test should pass
1.605 +*/
1.606 +void CTStreamIdCache::TestPerformance()
1.607 + {
1.608 + //Start the timing
1.609 + TTime starttime;
1.610 + starttime.UniversalTime();
1.611 +
1.612 + CFbsBitmap* bitmap=new (ELeave) CFbsBitmap;
1.613 + TInt ret;
1.614 + //simulating loading during boottime
1.615 + TInt i,j;
1.616 + for (i=0;i<30;i++)
1.617 + {
1.618 + for (j=0;j<10;j++)
1.619 + {
1.620 + ret=bitmap->Load(KMbmFileEikon,j,EFalse);
1.621 + TEST(ret==KErrNone);
1.622 + }
1.623 + for (j=0;j<2;j++)
1.624 + {
1.625 + ret=bitmap->Load(_L("z:\\system\\data\\tfbs.mbm"),j,EFalse);
1.626 + TEST(ret==KErrNone);
1.627 + }
1.628 + for (j=0;j<28;j++)
1.629 + {
1.630 + ret=bitmap->Load(KMbmFileLafcurs,j,EFalse);
1.631 + TEST(ret==KErrNone);
1.632 + }
1.633 + for (j=71;j<73;j++)
1.634 + {
1.635 + ret=bitmap->Load(KMbmFileEikon,j,EFalse);
1.636 + TEST(ret==KErrNone);
1.637 + }
1.638 + for (j=0;j<2;j++)
1.639 + {
1.640 + ret=bitmap->Load(_L("z:\\system\\data\\tfbs.mbm"),j,EFalse);
1.641 + TEST(ret==KErrNone);
1.642 + }
1.643 + for (j=20;j<22;j++)
1.644 + {
1.645 + ret=bitmap->Load(KMbmFileLafcurs,j,EFalse);
1.646 + TEST(ret==KErrNone);
1.647 + }
1.648 + }
1.649 +
1.650 + TTime endtime;
1.651 + endtime.UniversalTime();
1.652 + INFO_PRINTF1(_L("Forward Testing Before optimised duration= 3515625 microseconds \n"));
1.653 + TTimeIntervalMicroSeconds difftime=endtime.MicroSecondsFrom(starttime);
1.654 + INFO_PRINTF2(_L("Forward Testing After optimised duration=%Ld microseconds\n\n"),difftime.Int64());
1.655 +
1.656 + starttime.UniversalTime();
1.657 + for (i=0;i<30;i++)
1.658 + {
1.659 + for (j=10;j>=0;j--)
1.660 + {
1.661 + ret=bitmap->Load(KMbmFileEikon,j,EFalse);
1.662 + TEST(ret==KErrNone);
1.663 + }
1.664 + for (j=1;j>=0;j--)
1.665 + {
1.666 + ret=bitmap->Load(_L("z:\\system\\data\\tfbs.mbm"),j,EFalse);
1.667 + TEST(ret==KErrNone);
1.668 + }
1.669 + for (j=27;j>=0;j--)
1.670 + {
1.671 + ret=bitmap->Load(KMbmFileLafcurs,j,EFalse);
1.672 + TEST(ret==KErrNone);
1.673 + }
1.674 + for (j=73;j>=72;j--)
1.675 + {
1.676 + ret=bitmap->Load(KMbmFileEikon,j,EFalse);
1.677 + TEST(ret==KErrNone);
1.678 + }
1.679 + for (j=1;j>=0;j--)
1.680 + {
1.681 + ret=bitmap->Load(_L("z:\\system\\data\\tfbs.mbm"),j,EFalse);
1.682 + TEST(ret==KErrNone);
1.683 + }
1.684 + for (j=22;j>=20;j--)
1.685 + {
1.686 + ret=bitmap->Load(KMbmFileLafcurs,j,EFalse);
1.687 + TEST(ret==KErrNone);
1.688 + }
1.689 + }
1.690 + endtime.UniversalTime();
1.691 + difftime=endtime.MicroSecondsFrom(starttime);
1.692 + INFO_PRINTF1(_L("Backward Testing Before optimised duration= 3515625 microseconds \n"));
1.693 + INFO_PRINTF2(_L("Backward Testing After optimised duration=%Ld microseconds\n\n"),difftime.Int64());
1.694 +
1.695 + starttime.UniversalTime();
1.696 + for (i=0;i<30;i++)
1.697 + {
1.698 + for (j=40;j<70;j++)
1.699 + {
1.700 + ret=bitmap->Load(KMbmFileEikon,j,EFalse);
1.701 + TEST(ret==KErrNone);
1.702 + ret=bitmap->Load(KMbmFileEikon2,j,EFalse);
1.703 + TEST(ret==KErrNone);
1.704 + ret=bitmap->Load(KMbmFileEikon3,j,EFalse);
1.705 + TEST(ret==KErrNone);
1.706 + ret=bitmap->Load(KMbmFileEikon4,j,EFalse);
1.707 + TEST(ret==KErrNone);
1.708 + ret=bitmap->Load(KMbmFileEikon5,j,EFalse);
1.709 + TEST(ret==KErrNone);
1.710 + }
1.711 + }
1.712 + endtime.UniversalTime();
1.713 + difftime=endtime.MicroSecondsFrom(starttime);
1.714 + INFO_PRINTF1(_L("Multiple File Testing Before optimised duration= ? microseconds \n"));
1.715 + INFO_PRINTF2(_L("Multiple File Testing After optimised duration=%Ld microseconds\n\n"),difftime.Int64());
1.716 +
1.717 + starttime.UniversalTime();
1.718 + for (i=0;i<30;i++)
1.719 + {
1.720 + for (j=0;j<30;j++)
1.721 + {
1.722 + ret=bitmap->Load(KMbmFileEikon,j,EFalse);
1.723 + TEST(ret==KErrNone);
1.724 + }
1.725 + for (j=40;j<70;j++)
1.726 + {
1.727 + ret=bitmap->Load(KMbmFileEikon,j,EFalse);
1.728 + TEST(ret==KErrNone);
1.729 + }
1.730 + }
1.731 + endtime.UniversalTime();
1.732 + difftime=endtime.MicroSecondsFrom(starttime);
1.733 + INFO_PRINTF1(_L("Single File Testing Before optimised duration= ? microseconds \n"));
1.734 + INFO_PRINTF2(_L("Single File Testing After optimised duration=%Ld microseconds\n\n"),difftime.Int64());
1.735 +
1.736 + bitmap->Reset();
1.737 + delete bitmap;
1.738 +
1.739 + }
1.740 +
1.741 +/**
1.742 + @SYMTestCaseID
1.743 + GRAPHICS-FBSERV-0584
1.744 +
1.745 + @SYMTestCaseDesc
1.746 + Tests loading of bitmaps at an offset
1.747 + (Bitmap file section offset within the file).
1.748 +
1.749 + @SYMTestActions
1.750 + Creates an FbsBitmap object on the heap. Loads
1.751 + a monochrone bitmap with zero offset. Checks if
1.752 + loading completed successfully. Checks the pixel
1.753 + size. Gets a pixel. Checks if pixel is KRgbBlack.
1.754 +
1.755 + @SYMTestExpectedResults
1.756 + Test should pass
1.757 +*/
1.758 +void CTStreamIdCache::TestLoadAtOffset()
1.759 + {
1.760 + CFbsBitmap* bitmap = NULL;
1.761 + TRAPD(ret, bitmap = new (ELeave) CFbsBitmap);
1.762 + TEST(ret==KErrNone);
1.763 + if(iStep->TestStepResult() != EPass)
1.764 + {
1.765 + return;
1.766 + }
1.767 + INFO_PRINTF1(_L("Testing repeated CFbsBitmap Load with different offsets"));
1.768 +
1.769 + do // use a do{}while(false) so we can break out of the test code and fall back to the cleanup code
1.770 + {
1.771 + ret = bitmap->Load(KBlackAndWhite, 0, EFalse, 0);
1.772 + TEST(ret==KErrNone);
1.773 + if(iStep->TestStepResult() != EPass)
1.774 + {
1.775 + INFO_PRINTF1(_L("TestLoadAtOffset: Failed to load first mbm"));
1.776 + break;
1.777 + }
1.778 +
1.779 + TEST( bitmap->SizeInPixels() == TSize(1,1) && bitmap->IsMonochrome() );
1.780 + if(iStep->TestStepResult() == EPass)
1.781 + {
1.782 + TRgb colour;
1.783 + bitmap->GetPixel(colour, TPoint(0,0));
1.784 + TEST( colour == KRgbBlack );
1.785 + }
1.786 +
1.787 + if(iStep->TestStepResult() != EPass)
1.788 + {
1.789 + INFO_PRINTF1(_L("TestLoadAtOffset: First mbm loaded incorrectly"));
1.790 + break;
1.791 + }
1.792 +
1.793 + ret = bitmap->Load(KBlackAndWhite, 0, EFalse, WHITE_OFFSET);
1.794 + TEST(ret==KErrNone);
1.795 + if(iStep->TestStepResult() != EPass)
1.796 + {
1.797 + INFO_PRINTF1(_L("TestLoadAtOffset: Failed to load second mbm"));
1.798 + break;
1.799 + }
1.800 +
1.801 + TEST( bitmap->SizeInPixels() == TSize(1,1) && bitmap->IsMonochrome() );
1.802 + if(iStep->TestStepResult() == EPass)
1.803 + {
1.804 + TRgb colour;
1.805 + bitmap->GetPixel(colour, TPoint(0,0));
1.806 + TEST( colour == KRgbWhite );
1.807 + }
1.808 +
1.809 + if(iStep->TestStepResult() != EPass)
1.810 + {
1.811 + INFO_PRINTF1(_L("TestLoadAtOffset: Second mbm loaded incorrectly"));
1.812 + break;
1.813 + }
1.814 + } while( EFalse );
1.815 +
1.816 + bitmap->Reset();
1.817 + delete bitmap;
1.818 + }
1.819 +
1.820 +/**
1.821 +@SYMTestCaseID GRAPHICS-FBSERV-0509
1.822 +
1.823 +@SYMDEF DEF104261
1.824 +
1.825 +@SYMTestCaseDesc Tests file store cleanup for corresponding fbs session
1.826 +
1.827 +@SYMTestPriority Medium
1.828 +
1.829 +@SYMTestStatus Implemented
1.830 +
1.831 +@SYMTestActions 1. Create a file store object from file stream cache using current session handle
1.832 + 2. Create new file store object using some dummy session handle
1.833 + 3. Check two file store object belongs to the corresponding dummy session handle.
1.834 + 4. Close file store and check
1.835 + - if corresponing session's handle file store used to close.
1.836 + - if we send wrong session handle none of the file store should close
1.837 + - if we haven't send any session handle close all the file store object irrespective of the session handle
1.838 +
1.839 +@SYMTestExpectedResults 1. File store should close only for the corresponding session, while disconnecting the session
1.840 + 2. By flushing cache should close all file stores and reset cache entries, irrespective of the session
1.841 +*/
1.842 +void CTStreamIdCache::TestSessionClose()
1.843 + {
1.844 + TInt ret;
1.845 +
1.846 + INFO_PRINTF1(_L("Test file store clean up"));
1.847 +
1.848 + CFbTopStreamIdCache* mbmcacheptr = new CFbTopStreamIdCache(30,30,2);
1.849 + CFbTopStreamIdCache& mbmcache = *mbmcacheptr;
1.850 + RFile file1;
1.851 + ret=file1.Open(iFs,KMbmFileEikon,EFileShareReadersOnly);
1.852 + TEST(ret==KErrNone);
1.853 + RFile file2;
1.854 + ret=file2.Open(iFs,KMbmFileLafcurs,EFileShareReadersOnly);
1.855 + TEST(ret==KErrNone);
1.856 +
1.857 + //Create a file store with dummy session handle 1
1.858 + TRAP(ret,mbmcache.GetStreamIdL(file1,KMbmFileEikon,50,0,1));
1.859 + TEST(ret==KErrNone);
1.860 + //Create a file store with dummy session handle 2
1.861 + TRAP(ret,mbmcache.GetStreamIdL(file2,KMbmFileLafcurs,12,0,2));
1.862 + TEST(ret==KErrNone);
1.863 + TEST(mbmcache.iEntries.Count() == 2);
1.864 +
1.865 + TEST(2==mbmcache.iEntries[0]->SessionHandle());
1.866 + TEST(1==mbmcache.iEntries[1]->SessionHandle());
1.867 + TEST(mbmcache.iEntries[0]->iFilestore!=NULL);
1.868 + TEST(mbmcache.iEntries[1]->iFilestore!=NULL);
1.869 +
1.870 + mbmcache.CloseFileStores(1);
1.871 + TEST(mbmcache.iEntries.Count() == 2);
1.872 + TEST(mbmcache.iEntries[0]->iFilestore!=NULL);
1.873 + TEST(mbmcache.iEntries[1]->iFilestore==NULL);
1.874 + TEST(2==mbmcache.iEntries[0]->SessionHandle());
1.875 + TEST(0==mbmcache.iEntries[1]->SessionHandle());
1.876 +
1.877 + //All File stores should deleted
1.878 + mbmcache.CloseFileStores(0);
1.879 + TEST(mbmcache.iEntries.Count() == 2);
1.880 + TEST(mbmcache.iEntries[0]->iFilestore==NULL);
1.881 + TEST(mbmcache.iEntries[1]->iFilestore==NULL);
1.882 + TEST(0==mbmcache.iEntries[0]->SessionHandle());
1.883 + TEST(0==mbmcache.iEntries[1]->SessionHandle());
1.884 +
1.885 + // Should remove all the file store objects and reset the cache entries.
1.886 + mbmcache.FlushCache();
1.887 + TEST(mbmcache.iEntries.Count() == 0);
1.888 +
1.889 + delete mbmcacheptr;
1.890 + }
1.891 +
1.892 +
1.893 +//--------------
1.894 +__CONSTRUCT_STEP__(StreamIdCache)
1.895 +
1.896 +
1.897 +void CTStreamIdCacheStep::TestSetupL()
1.898 + {
1.899 + // Leaking thread handles
1.900 + iThread.HandleCount(iStartProcessHandleCount, iStartThreadHandleCount);
1.901 + }
1.902 +
1.903 +void CTStreamIdCacheStep::TestClose()
1.904 + {
1.905 + // Check for open handles
1.906 + iThread.HandleCount(iEndProcessHandleCount, iEndThreadHandleCount);
1.907 + if(iStartThreadHandleCount != iEndThreadHandleCount)
1.908 + {__DEBUGGER()} // Oops leaked some handles
1.909 + }