os/graphics/fbs/fontandbitmapserver/tfbs/TFBS.CPP
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 1995-2010 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 /**
    17  @file
    18  @internalComponent - Internal Symbian test code
    19 */
    20 
    21 #include "TFBS.H"
    22 #include "../sfbs/UTILS.H"
    23 #include "../sfbs/fbshelper.h"
    24 #include <shapeinfo.h>
    25 #include <graphics/openfontrasterizer.h>
    26 #include <graphics/openfontconstants.h>
    27 #include "fbsdefs.h"
    28 #include "fbsmessage.h"
    29 
    30 TInt buffer[2];
    31 
    32 _LIT(KFBSERVFontFileDir, "\\resource\\fonts\\");
    33 _LIT(KTypefaceName, "DejaVu Sans Condensed");
    34 
    35 // TLS Handle for TestFlushCallback test, from tfbsserver.mmp
    36 const TInt KTlsHandle = 0x10273364;
    37 
    38 
    39 #ifdef __WINS__
    40 template<class C> XTCallCounter<C>::XTCallCounter(CTGraphicsBase& aTestBase)
    41 	: iTestBase(aTestBase), iVFCallsOutsideFBServ(0)
    42 	{}
    43 
    44 template<class C> void XTCallCounter<C>::ExecuteShellcode(TInt aFromFunction)
    45 	{
    46 	const TUint32 KFBServId = 0x10003A16;
    47 	const TUint32 KTFbsServerId = 0x10273364;
    48 	TSecureId id = RProcess().SecureId();
    49 	if (id != KFBServId)
    50 		{
    51 		User::LockedInc(iVFCallsOutsideFBServ);
    52 		if (id == KTFbsServerId)
    53 			{
    54 			TBuf<128> name;
    55 			XVtableInjector<C>::GetVirtualFunctionName(aFromFunction, name);
    56 			iTestBase.INFO_PRINTF2(_L("Virtual function call to %S from outside FBServ"), &name);
    57 			}
    58 		}
    59 	}
    60 #endif
    61 
    62 
    63 void CTFbs::DeleteScanLineBuffer()
    64 	{
    65 	delete iFbs->iScanLineBuffer;
    66 	iFbs->iScanLineBuffer = 0;
    67 	};
    68 
    69 CTFbs::CTFbs(CTestStep* aStep):
    70 	CTGraphicsBase(aStep),
    71 	iHandle(0),
    72 	iFbs(NULL),
    73 	iTs(NULL),
    74 	iHeap(NULL),
    75 	iFs(NULL),
    76 	iResourceCount(0),
    77 	iAllocs(0)
    78 #ifdef __WINS__
    79 	, iFontCallCounter(*this), iOpenFontCallCounter(*this)
    80 #endif
    81 	{
    82 	}
    83 
    84 void CTFbs::ConstructL()
    85 	{
    86 	ExpandCleanupStackL();
    87 	User::LeaveIfError(Logger().ShareAuto());
    88 	TestConstruction();
    89 	AllocScanLineBuf();
    90 	
    91 	INFO_PRINTF1(_L("FBSERV testing"));
    92 	}
    93 	
    94 CTFbs::~CTFbs()
    95 	{
    96 	delete iTs;
    97 	}
    98 
    99 void CTFbs::RunTestCaseL(TInt aCurTestCase)
   100 	{
   101 	((CTFbsStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
   102 	switch(aCurTestCase)
   103 		{
   104 	case 1:
   105 		((CTFbsStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0555"));
   106 		TestConnection();
   107 		break;
   108 	case 2:
   109 		((CTFbsStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0558"));
   110 		TestInvalidFiles();
   111 		break;
   112 	case 3:
   113 		((CTFbsStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0556"));
   114 		TestFlushCallBack();
   115 		break;
   116 	case 4:
   117 		((CTFbsStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0568"));
   118 		TestMultiThread();
   119 		break;
   120 	case 5:
   121 		((CTFbsStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0559"));
   122 		TestGetFont();
   123 		break;
   124 	case 6:
   125 		((CTFbsStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0560"));
   126 		TestFontStore();
   127 		break;
   128 	case 7:
   129 		((CTFbsStep*)iStep)->SetTestStepID(_L("GRAPHICS-PREQ807_1_Load_all_fonts-0001"));
   130 		TestAllFontsLoaded();
   131 		break;
   132 	case 8:
   133 		((CTFbsStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0561"));
   134 		TestFontNameAlias();
   135 		break;
   136 	case 9:
   137 		((CTFbsStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0557"));
   138 		TestAddFontFile();
   139 		break;
   140 	case 10:
   141 		((CTFbsStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0562"));
   142 		TestBufferedFont();
   143 		break;
   144 	case 11:
   145 		((CTFbsStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0563"));
   146 		TestMultipleFont();
   147 		break;
   148 	case 12:
   149 		((CTFbsStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0564"));
   150 		TestCreateBitmap();
   151 		break;
   152 	case 13:
   153 		((CTFbsStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0565"));
   154 		TestLoadBitmap();
   155 		break;
   156 	case 14:
   157 		((CTFbsStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0566"));
   158 		TestQueryBitmap();
   159 		TRAPD(errCode, TestRomBitmapL());
   160 		if(errCode==KErrNone)
   161 			{
   162 			TestHeapCompression();
   163 			}
   164 		break;
   165 	case 15:
   166 		((CTFbsStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0570"));
   167 		TestDefaultLanguageForMetrics();		
   168 		break;
   169 	case 16:
   170 		((CTFbsStep*)iStep)->SetTestStepID(_L("GRAPHICS-CTFbs-TestDuplicateFontFileEntries-0001"));
   171 		TestDuplicateFontFileEntries();
   172 		break;
   173 	//COMMENTED OUT FOR NOW BECAUSE DEF084095 FIX MAKES THIS TEST REDUNDANT
   174 	/*case 17:
   175 		TestShapeHeaderMemoryLeakAtClientDeath();
   176 		break;*/
   177 	case 17:
   178 		((CTFbsStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0506"));
   179 		TestBitmapHandleImmutable();
   180 		break;
   181 	case 18:
   182 		((CTFbsStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0507"));
   183 		TestBitmapBeginEnd();
   184 		break;
   185 	case 19:
   186 		((CTFbsStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0508"));
   187 		TestSingletonServer();
   188 		break;
   189 	case 21:
   190 		((CTFbsStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0623"));
   191 		TestFontSessionCacheLookupL();
   192 		break;
   193 	case 22:
   194 		((CTFbsStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0650"));
   195 		TestInvalidHandlesInIpcCallsL();
   196 		break;
   197 	case 23:
   198 		// this one should always be the last test, since it checks the final virtual function call count
   199 		((CTFbsStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0619"));
   200 		TestNoVFCallsToGlobalObjects();
   201 		break;
   202 	case 24:
   203 		((CTFbsStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
   204 		((CTFbsStep*)iStep)->CloseTMSGraphicsStep();
   205 		TestComplete();		
   206 		break;
   207 		}
   208 	((CTFbsStep*)iStep)->RecordTestResultL();
   209 	}
   210 
   211 CFbsFontEx* CTFbs::SelectFont()
   212 	{
   213 	CFbsFontEx* font=NULL;
   214 	TInt ret=iTs->GetNearestFontToDesignHeightInPixels((CFont*&)font, TFontSpec(KTypefaceName, 15));
   215 	TEST(ret==KErrNone);
   216 #ifdef __WINS__
   217 	CBitmapFont* bitmapFont = font->Address();
   218 	iFontCallCounter.iInjector.InjectShellcode(bitmapFont, &iFontCallCounter);
   219 	if (bitmapFont->IsOpenFont())
   220 		{
   221 		iOpenFontCallCounter.iInjector.InjectShellcode(bitmapFont->OpenFont(), &iOpenFontCallCounter);
   222 		}
   223 #endif
   224 	TEST(font->MaxCharWidthInPixels()>0);
   225 	TEST(font->MaxNormalCharWidthInPixels()>0);
   226 	return(font);
   227 	}
   228 
   229 CFbsFontEx* CTFbs::SelectOpenTypeFont()
   230 	{
   231 	CFbsFontEx* font=NULL;
   232 	TFontSpec fsp;
   233 	fsp.iTypeface.iName=_L("Series 60 Sans");
   234 	fsp.iHeight=15;
   235 	TInt ret=iTs->GetNearestFontToDesignHeightInPixels((CFont*&)font,fsp);
   236 	TEST(ret==KErrNone);
   237 #ifdef __WINS__
   238 	CBitmapFont* bitmapFont = font->Address();
   239 	iFontCallCounter.iInjector.InjectShellcode(bitmapFont, &iFontCallCounter);
   240 	if (bitmapFont->IsOpenFont())
   241 		{
   242 		iOpenFontCallCounter.iInjector.InjectShellcode(bitmapFont->OpenFont(), &iOpenFontCallCounter);
   243 		}
   244 #endif
   245 	TEST(font->MaxCharWidthInPixels()>0);
   246 	TEST(font->MaxNormalCharWidthInPixels()>0);
   247 	return(font);
   248 	}
   249 
   250 void CTFbs::TestConstruction()
   251 	{
   252 	CFbsBitmap bmp;
   253 	iTestBitmapName = KTestBitmapOnZ;
   254 	TInt ret=bmp.Load(iTestBitmapName,ETfbs,NULL);
   255 	if (ret != KErrNone)
   256 		User::Panic(_L("Could not load bitmap"),ret);
   257 	bmp.Reset();
   258 
   259 	iFbs = RFbsSession::GetSession();
   260 	TRAP(ret,iTs = (CFbsTypefaceStore*)CFbsTypefaceStore::NewL(NULL));
   261 	TEST(iTs != NULL);
   262 	CFbsFontEx* font = SelectFont();
   263 	iTs->ReleaseFont(font);
   264 	}
   265 	
   266 /**
   267 	@SYMTestCaseID
   268 	GRAPHICS-FBSERV-0555
   269 
   270 	@SYMTestCaseDesc
   271 	Tests the connections to the FbsSession
   272 
   273 	@SYMTestActions
   274 	Allocates a 100 RFbsSession objects and
   275 	connects to the server and checks if
   276 	all connections succeeded. Frees the memory
   277 	and checks the heap memory.
   278 	
   279 	@SYMTestExpectedResults
   280 	Test should pass
   281 */
   282 void CTFbs::TestConnection()
   283 	{
   284 	INFO_PRINTF1(_L("class RFbsSession"));
   285 	__UHEAP_MARK;
   286 	const TInt numconnects=100;
   287 	RFbsSession* connections=(RFbsSession*)User::Alloc(sizeof(RFbsSession)*numconnects);
   288 	TEST(connections!=NULL);
   289 	TInt count=0;
   290 	for(;count<numconnects;count++)
   291 		new(&connections[count]) RFbsSession;
   292 	TEST(iFbs->ResourceCount()==0);
   293 	for(count=0;count<numconnects;count++)
   294 		{
   295 		TInt ret=connections[count].Connect();
   296 		if(ret!=KErrNone)
   297 			break;
   298 		}
   299 	INFO_PRINTF2(_L("    %d connections created.\n"),count);
   300 	TEST(iFbs->ResourceCount()==0);
   301 	for(TInt count2=0;count2<count;count2++)
   302 		connections[count2].Disconnect();
   303 	TEST(iFbs->ResourceCount()==0);
   304 	User::Free(connections);
   305 	User::Heap().Check();
   306 	__UHEAP_MARKEND;
   307 	}
   308 
   309 /**
   310 	@SYMTestCaseID
   311 	GRAPHICS-FBSERV-0556
   312 
   313 	@SYMTestCaseDesc
   314 	Tests if the flush callback function
   315 	is called properly.
   316 
   317 	@SYMTestActions
   318 	Sets the flush callback, fills the cache with different
   319 	fonts until the cache is full.
   320 	Create one more font which forces an eviction of a font
   321 	in the cache.
   322 	Check call back is called.
   323 	Reset the flush callback, create another new font,
   324 	check that the callback was not called.
   325 	Check for memory and resource leaks.
   326 	
   327 	@SYMTestExpectedResults
   328 	Callback function should be called once at end of loop.
   329 */
   330 void CTFbs::TestFlushCallBack()
   331 	{
   332 	INFO_PRINTF1(_L("Test Flush CallBack"));
   333 
   334 	__UHEAP_MARK;
   335 	CFbsTypefaceStore* tfs=NULL;
   336 	TRAPD(ret,tfs=CFbsTypefaceStore::NewL(NULL));
   337 	TEST(ret==KErrNone);
   338 	TEST(tfs!=NULL);
   339 
   340 	UserSvr::DllSetTls(KTlsHandle, this);
   341 	INFO_PRINTF1(_L("Testing Flush CallBack mechanism..."));
   342 	iFbs->SetCallBack(TCallBack(FlushCallBack, NULL));
   343 	CFbsFontEx* font=NULL;
   344 
   345 	// Fill up the fontcache so that on the final iteration, the first 
   346 	// font is evicted, thereby destroying it server-side and executing the 
   347 	// callback.
   348 	iFlushCallbackReceived = EFalse;
   349 	TInt fontSize = 10;
   350 	for (TInt fontEntries = 0; fontEntries < KMaxFontCacheEntries+1; fontEntries++)
   351 		{
   352 		ret=tfs->GetNearestFontToDesignHeightInTwips((CFont*&)font, TFontSpec(KTypefaceName, fontSize));
   353 		TEST(ret==KErrNone);
   354 		iResourceCount++;
   355 		CheckResourceCount();
   356 		tfs->ReleaseFont(font);
   357 		fontSize += 15;
   358 		}
   359 	TEST(iFlushCallbackReceived);
   360 
   361 	// Now check callback is correctly reset and callback function is not executed
   362 	// when another font is evicted from the cache.
   363 	// Resource count wont increase as although a new font is being created, another
   364 	// will be evicted from the cache.
   365 	iFlushCallbackReceived = EFalse;
   366 	iFbs->ResetCallBack();
   367 	ret=tfs->GetNearestFontToDesignHeightInTwips((CFont*&)font, TFontSpec(KTypefaceName, fontSize));
   368 	TEST(ret==KErrNone);
   369 	tfs->ReleaseFont(font);
   370 	TEST(!iFlushCallbackReceived);
   371 	CheckResourceCount();
   372 
   373 	UserSvr::DllFreeTls(KTlsHandle);
   374 	delete tfs;
   375 	iResourceCount = 0;
   376 	CheckResourceCount();
   377 	__UHEAP_MARKEND;
   378 	}
   379 
   380 TInt CTFbs::FlushCallBack(TAny* /*aPtr*/)
   381 	{
   382 	CTFbs* tfbs = static_cast<CTFbs*>(UserSvr::DllTls(KTlsHandle));
   383 	tfbs->INFO_PRINTF1(_L("    ...Flush CallBack called successfully"));
   384 	tfbs->iFlushCallbackReceived = ETrue;
   385 	--tfbs->iResourceCount;
   386 	return(0);
   387 	}
   388 
   389 
   390 #ifdef __WINS__
   391 _LIT(KCTFbsTestFont,"z:\\resource\\fonts\\eon14.gdr");
   392 #else
   393 _LIT(KCTFbsTestFont,"z:\\resource\\fonts\\eon.gdr");
   394 #endif
   395 
   396 /**
   397 	@SYMTestCaseID
   398 	GRAPHICS-FBSERV-0557
   399 
   400 	@SYMTestCaseDesc
   401 	Tests adding of a font file
   402 	to the font store
   403 
   404 	@SYMTestActions
   405 	Creates a type face store and adds
   406 	font files to it. Checks if adding
   407 	the files succeeded. Removes the files
   408 	from the store. Checks if succeeded.
   409 	
   410 	@SYMTestExpectedResults
   411 	Test should pass
   412 */
   413 void CTFbs::TestAddFontFile()
   414 	{
   415 	INFO_PRINTF1(_L("Test Add File"));
   416 	__UHEAP_MARK;
   417 	CFbsTypefaceStore* tfs=NULL;
   418 	TRAPD(ret,tfs=CFbsTypefaceStore::NewL(NULL));
   419 	TEST(ret==KErrNone);
   420 	TEST(tfs!=NULL);
   421 	TInt id1=0;
   422 	TInt id2=0;
   423 	TInt id3=0;
   424 	TInt id4=0;
   425 	ret=tfs->AddFile(KCTFbsTestFont,id1);
   426 	TEST(ret==KErrNone);
   427 	TEST(id1!=0);
   428 	ret=tfs->AddFile(KCTFbsTestFont,id2);
   429 	TEST(ret==KErrNone);
   430 	TEST(id2==id1);
   431 	ret=tfs->AddFile(KCTFbsTestFont,id3);
   432 	TEST(ret==KErrNone);
   433 	TEST(id3==id2);
   434 	tfs->RemoveFile(id1);
   435 	tfs->RemoveFile(id2);
   436 	tfs->RemoveFile(id3);
   437 	ret=tfs->AddFile(KCTFbsTestFont,id4);
   438 	TEST(ret==KErrNone);
   439 	TEST(id4==id1);
   440 	tfs->RemoveFile(id4);
   441 	delete tfs;
   442 	__UHEAP_MARKEND;
   443 	
   444 	//test the sequence AddFile, GetNearestFont, ReleaseFont, RemoveFile
   445 	CFbsTypefaceStore* tfs1=NULL;
   446     TRAPD(ret1,tfs1=CFbsTypefaceStore::NewL(NULL));
   447     TEST(ret1==KErrNone);
   448     TEST(tfs1!=NULL);
   449     TInt id5=0;
   450     ret1=tfs1->AddFile(_L("z:\\resource\\fonts\\DejaVuSerifCondensed.ttf"),id5);
   451     TEST(ret1==KErrNone);
   452     TEST(id5!=0);
   453     
   454     TInt id6=0;
   455     ret1=tfs1->AddFile(_L("z:\\resource\\fonts\\DejaVuSansCondensed.ttf"), id6);
   456     TEST(ret1==KErrNone);
   457     TEST(id6!=0);    
   458     
   459     TFontSpec fsp1;
   460     fsp1.iTypeface.iName=_L("DejaVu Serif Condensed");
   461     fsp1.iHeight=15;
   462     CFont* font1;
   463     ret1=tfs1->GetNearestFontToDesignHeightInTwips((CFont*&)font1,fsp1);
   464     TEST(ret1==KErrNone);
   465     
   466     TFontSpec fsp2;
   467     fsp2.iTypeface.iName=_L("DejaVu Serif Condensed");
   468     fsp2.iHeight=30;
   469     CFont *font2;
   470     ret1=tfs1->GetNearestFontToDesignHeightInTwips((CFont*&)font2,fsp2);
   471     TEST(ret1==KErrNone);
   472 
   473     TFontSpec fsp3;
   474     fsp3.iTypeface.iName=_L("DejaVu Sans Condensed");
   475     fsp3.iHeight=20;
   476     CFont *font3;
   477     ret1=tfs1->GetNearestFontToDesignHeightInTwips((CFont*&)font3,fsp3);
   478     TEST(ret1==KErrNone);
   479 
   480     TFontSpec fsp4;
   481     fsp4.iTypeface.iName=_L("DejaVu Serif Condensed");
   482     fsp4.iHeight=35;
   483     CFont *font4;
   484     ret1=tfs1->GetNearestFontToDesignHeightInTwips((CFont*&)font4,fsp4);
   485     TEST(ret1==KErrNone);
   486     
   487     if (font1)
   488         tfs1->ReleaseFont(font1);
   489     if (font2)
   490         tfs1->ReleaseFont(font2);
   491     if (font4)
   492         tfs1->ReleaseFont(font4);
   493  
   494     if (id6)
   495         tfs1->RemoveFile(id6);
   496     if (id5)
   497         tfs1->RemoveFile(id5);
   498     delete tfs1;
   499 	}
   500 
   501 /**
   502 	@SYMTestCaseID
   503 	GRAPHICS-FBSERV-0558
   504 
   505 	@SYMTestCaseDesc
   506 	Tries to add and load a nonexisting 
   507 	file to the FbsTypeFaceStore and checks
   508 	if it fails.
   509 	
   510 	@SYMTestActions
   511 	
   512 	@SYMTestExpectedResults
   513 	Test should pass
   514 */
   515 void CTFbs::TestInvalidFiles()
   516 	{
   517 	INFO_PRINTF1(_L("Test Invalid Files"));
   518 	__UHEAP_MARK;
   519 	CFbsTypefaceStore* tfs=NULL;
   520 	TRAPD(ret,tfs=CFbsTypefaceStore::NewL(NULL));
   521 	TEST(ret==KErrNone);
   522 	TEST(tfs!=NULL);
   523 	TInt id=0;
   524 	ret=tfs->AddFile(_L("\\nonexist.gdr"),id);
   525 	TEST(ret!=KErrNone);
   526 	delete tfs;
   527 	CFbsBitmapEx bmp;
   528 	ret=bmp.Load(_L("\\nonexist.mbm"),0);
   529 	TEST(ret!=KErrNone);
   530 	User::Heap().Check();
   531 	__UHEAP_MARKEND;
   532 	}
   533 
   534 /**
   535 	@SYMTestCaseID
   536 	GRAPHICS-FBSERV-0559
   537 
   538 	@SYMTestCaseDesc
   539 	Gets a font and tests all its properties. 
   540 
   541 	@SYMTestActions
   542 	Tests the char width, text width, handles, verifies
   543 	the resource count and the heap for memory leaks
   544 	CharWidthInPixels() and TextWidthInPixels() may return 
   545 	different values depending on the hardware used.
   546 	Therefore, when comparing these values for the same character,
   547 	allow a margin of 1 pixel difference.
   548 	
   549 	@SYMTestExpectedResults
   550 	Test should pass
   551 */
   552 void CTFbs::TestGetFont()
   553 	{
   554 	INFO_PRINTF1(_L("Test Get Font"));
   555 	CFbsFontEx* font=SelectFont();
   556 	iResourceCount++;
   557 	TEST(font->Handle()!=0);
   558 	CheckResourceCount();
   559 	TUid uid;
   560 	uid=KCFbsFontUid;
   561 	TEST(font->TypeUid()==uid);
   562 	TInt w=font->TextWidthInPixels(_L(" "));
   563 	TEST(w>0);
   564 	// Now test the same use case with context
   565 	CFont::TMeasureTextInput param;
   566 	param.iStartInputChar = 34;
   567 	TInt wContext=font->TextWidthInPixels(_L("->This text will not be measured<- "),&param);
   568 	TEST(wContext==w);
   569 	// End of first use case with context
   570 		
   571 	TInt x=font->TextCount(_L("          "),10);
   572 	TEST(10/w==x);
   573 	TInt y,z;
   574 	y=font->TextCount(_L("   "),10,z);
   575 	TEST(y==x);
   576 	TInt cwidth=font->CharWidthInPixels('i');
   577 	TInt twidth=font->TextWidthInPixels(_L("i"));
   578 	TInt charTextdiff = cwidth - twidth;
   579 	TEST(1>=charTextdiff && -1<=charTextdiff);
   580 	TInt twidthContext=font->TextWidthInPixels(_L("->This text will not be measured<-i"),&param);
   581 	TEST(twidth==twidthContext);
   582 	cwidth=font->CharWidthInPixels('p');
   583 	twidth=font->TextWidthInPixels(_L("p"));
   584 	charTextdiff = cwidth - twidth;
   585 	TEST(1>=charTextdiff && -1<=charTextdiff);
   586 	twidthContext=font->TextWidthInPixels(_L("->This text will not be measured<-p"),&param);
   587 	TEST(twidth==twidthContext);
   588 	cwidth=font->CharWidthInPixels('W');
   589 	twidth=font->TextWidthInPixels(_L("W"));
   590 	charTextdiff = cwidth - twidth;
   591 	TEST(1>=charTextdiff && -1<=charTextdiff);
   592 	twidthContext=font->TextWidthInPixels(_L("->This text will not be measured<-W"),&param);
   593 	TEST(twidth==twidthContext);
   594 	cwidth=font->CharWidthInPixels(' ');
   595 	twidth=font->TextWidthInPixels(_L(" "));
   596 	charTextdiff = cwidth - twidth;
   597 	TEST(1>=charTextdiff && -1<=charTextdiff);
   598 	SCharWidth chwid;
   599 	font->TextWidthInPixels(_L(" "),chwid);
   600 	TEST(chwid.iMove==w);
   601 	TEST(chwid.iWidth+chwid.iLeftAdjust+chwid.iRightAdjust==chwid.iMove);
   602 	font->TextWidthInPixels(_L("->This text will not be measured<- "),&param,chwid);
   603 	TEST(chwid.iMove==w);
   604 	TEST(chwid.iWidth+chwid.iLeftAdjust+chwid.iRightAdjust==chwid.iMove);
   605 
   606 	// Now do all these tests with an OpenType font where the width with context is different from the
   607 	// width without context
   608 	// NOTE:	These tests are performed for WINS and WINSCW only because we are using a TrueType font, and the bounds of 
   609 	// 			the text returned is different for different hardware devices, including different h4's	and hence 
   610 	//			cannot be measured.
   611 	#if defined __WINS__ || defined __WINSCW__
   612 	CFbsFontEx* openFont = SelectOpenTypeFont();
   613 	iResourceCount++;
   614 	TEST(font->Handle()!=0);
   615 	CheckResourceCount();
   616 	uid=KCFbsFontUid;
   617 	TEST(font->TypeUid()==uid);
   618 	cwidth=openFont->CharWidthInPixels('.');
   619 	twidth=openFont->TextWidthInPixels(_L("."));
   620 	charTextdiff = cwidth - twidth;
   621 	TEST(1>=charTextdiff && -1<=charTextdiff);
   622 	param.iStartInputChar = 1;
   623 	twidthContext=openFont->TextWidthInPixels(_L("\x0915."),&param);
   624 	TEST(twidth!=twidthContext);
   625 	cwidth=openFont->CharWidthInPixels(',');
   626 	twidth=openFont->TextWidthInPixels(_L(","));
   627 	charTextdiff = cwidth - twidth;
   628 	TEST(1>=charTextdiff && -1<=charTextdiff);
   629 	twidthContext=openFont->TextWidthInPixels(_L("\x0915,"),&param);
   630 	TEST(cwidth!=twidthContext);
   631 	TEST(twidth!=twidthContext);
   632 	openFont->TextWidthInPixels(_L("\x0915."),&param,chwid);
   633 	TEST(chwid.iMove!=cwidth);
   634 	#endif
   635 
   636 	CFbsFontEx* font2=SelectFont(); // Don't increment iResourceCount as the font is already in the cache
   637 	CheckResourceCount();
   638 	iTs->ReleaseFont(font2);
   639 	RFbsSession* fbsalt=RFbsSession::GetSession();
   640 	CFbsFontEx* font3=new CFbsFontEx;
   641 	font3->Duplicate(font->Handle());
   642 	iResourceCount++;
   643 	TEST(font3->Handle());
   644 	CheckResourceCount();
   645 	TEST(fbsalt->ResourceCount()==iResourceCount);
   646 	iTs->ReleaseFont(font);
   647 	iResourceCount--;
   648 	TEST(w==font3->TextWidthInPixels(_L(" ")));
   649 	CheckResourceCount();
   650 	TEST(fbsalt->ResourceCount()==iResourceCount);
   651 	font3->Reset();
   652 	delete font3;
   653 	iResourceCount--;
   654 	CheckResourceCount();
   655 	TEST(fbsalt->ResourceCount()==iResourceCount);
   656 	User::Heap().Check();
   657 	}
   658 
   659 /**
   660 	@SYMTestCaseID
   661 	GRAPHICS-FBSERV-0560
   662 
   663 	@SYMTestCaseDesc
   664 	Tests the font store.
   665 
   666 	@SYMTestActions
   667 	Allocates an array of pointers which is
   668 	used to store the font height. It tests
   669 	the font height and gets the nearest font
   670 	available. The heap is checked for 
   671 	memory leaks.	
   672 	
   673 	@SYMTestExpectedResults
   674 	Test should pass
   675 */
   676 void CTFbs::TestFontStore()
   677 	{
   678 	INFO_PRINTF1(_L("Test Font Store"));
   679 	CFbsFontEx* font=NULL;
   680 	TFontSpec fs;
   681 	TInt typefaces=iTs->NumTypefaces();
   682 	TTypefaceSupport info;
   683 	for(TInt count=0;count<typefaces;count++)
   684 		{
   685 		iTs->TypefaceSupport(info,count);
   686 		INFO_PRINTF1(_L("    "));
   687 	    TBuf<KMaxTypefaceNameLength> tname;
   688 		tname.Copy(info.iTypeface.iName);
   689 		INFO_PRINTF1(tname);
   690 		INFO_PRINTF1(_L("\n"));
   691 		TInt* heightarray=(TInt*)User::Alloc(info.iNumHeights*sizeof(TInt));
   692 		TInt index=0;
   693 		for(;index<info.iNumHeights;index++)
   694 			heightarray[index]=iTs->FontHeightInTwips(count,index);
   695 		for(index=1;index<info.iNumHeights;index++)
   696 			TEST(heightarray[index]>heightarray[index-1]);
   697 		for(index=0;index<info.iNumHeights;index++)
   698 			heightarray[index]=iTs->FontHeightInPixels(count,index);
   699 		for(index=1;index<info.iNumHeights;index++)
   700 			TEST(heightarray[index]>=heightarray[index-1]);
   701 		delete [] heightarray;
   702 		for(index=0;index<info.iNumHeights;index++)
   703 			{
   704 			TInt height=iTs->FontHeightInTwips(count,index);
   705 			fs.iTypeface=info.iTypeface;
   706 			fs.iHeight=height;
   707 			TInt ret=iTs->GetNearestFontToDesignHeightInTwips((CFont*&)font,fs);
   708 			TEST(ret==KErrNone);
   709 			TEST(font->Handle());
   710 			iTs->ReleaseFont(font);
   711 
   712 			height=iTs->FontHeightInPixels(count,index);
   713 			fs.iTypeface=info.iTypeface;
   714 			fs.iHeight=height;
   715 			ret=iTs->GetNearestFontToDesignHeightInPixels((CFont*&)font,fs);
   716 			TEST(ret==KErrNone);
   717 			TEST(font->Handle());
   718 			iTs->ReleaseFont(font);
   719 			}
   720 		}
   721 	iResourceCount = iFbs->ResourceCount(); // Allow for fonts left in the typeface store cache
   722 	User::Heap().Check();
   723 	}
   724 
   725 /**
   726 	@SYMTestCaseID
   727 	GRAPHICS-FBSERV-0561
   728 
   729 	@SYMTestCaseDesc
   730 	Tests the font name alias
   731 
   732 	@SYMTestActions
   733 	Creates three different font name alias with a 
   734 	mixture of caps and small letters. Checks the font
   735 	name aliases using the different names.
   736 	
   737 	@SYMTestExpectedResults
   738 	Test should pass
   739 */
   740 void CTFbs::TestFontNameAlias()
   741 	{
   742 	INFO_PRINTF1(_L("Test Font Name Alias"));
   743 
   744 	TInt size = 20;
   745 	_LIT(KFontAlias0,"Font alias 0");
   746 	_LIT(KFontAlias1,"Font alias 1");
   747 	_LIT(KFontAlias2,"FOnT AlIaS 0");//Alias name in mixture of caps & small letters for KFontAlias0
   748 
   749     TBuf<KMaxTypefaceNameLength> defaultName;
   750     TBuf<KMaxTypefaceNameLength> fontName[3];
   751 
   752 	CFbsFontEx* font = NULL;
   753 	TFontSpec fs(KNullDesC,200);
   754 	TInt ret = iTs->GetNearestFontToDesignHeightInTwips((CFont*&)font,fs);
   755 	TEST(ret == KErrNone);
   756 	TEST(font->Handle());
   757 	fs = font->FontSpecInTwips();
   758 	defaultName = fs.iTypeface.iName;
   759 	iTs->ReleaseFont(font);
   760 
   761 	TTypefaceSupport info;
   762 	for (TInt index = 0, nameIndex = 0; nameIndex < 3; index++)
   763 		{
   764 		iTs->TypefaceSupport(info,index);
   765 		if (info.iTypeface.iName != defaultName)
   766 			fontName[nameIndex++] = info.iTypeface.iName;
   767 		}
   768 
   769 	TRAP(ret,iTs->SetFontNameAliasL(KFontAlias0,fontName[0]));
   770 	TEST(ret == KErrNone);
   771 	CheckFontNameAlias(KFontAlias0,fontName[0],size);
   772 	//Testing if it works even if the alias name passed differs in case
   773 	CheckFontNameAlias(KFontAlias2,fontName[0],size);
   774 
   775 	TRAP(ret,iTs->SetFontNameAliasL(KFontAlias1,fontName[1]));
   776 	TEST(ret == KErrNone);
   777 	CheckFontNameAlias(KFontAlias0,fontName[0],size);
   778 	CheckFontNameAlias(KFontAlias1,fontName[1],size);
   779 
   780 	TRAP(ret,iTs->SetFontNameAliasL(KFontAlias0,fontName[2]));
   781 	TEST(ret == KErrNone);
   782 	CheckFontNameAlias(KFontAlias0,fontName[2],size);
   783 	CheckFontNameAlias(KFontAlias1,fontName[1],size);
   784 
   785 	TRAP(ret,iTs->SetFontNameAliasL(KFontAlias1,KNullDesC));
   786 	TEST(ret == KErrNone);
   787 	CheckFontNameAlias(KFontAlias0,fontName[2],size);
   788 	CheckFontNameAlias(KFontAlias1,defaultName,size);
   789 
   790 	TRAP(ret,iTs->SetFontNameAliasL(KFontAlias0,KNullDesC));
   791 	TEST(ret == KErrNone);
   792 	CheckFontNameAlias(KFontAlias0,defaultName,size);
   793 	CheckFontNameAlias(KFontAlias1,defaultName,size);
   794 	iResourceCount--; // Allow for a cache eviction because the last check fills the cache
   795 
   796 	CheckResourceCount();
   797 	User::Heap().Check();
   798 	}
   799 
   800 void CTFbs::CheckFontNameAlias(const TDesC& aFontAlias, const TDesC& aFontName, TInt& aSize)
   801 	{
   802 	CFbsFontEx* font = NULL;
   803 	TFontSpec fs(aFontAlias,aSize);
   804 	aSize += 20;
   805 
   806 	TInt ret = iTs->GetNearestFontToDesignHeightInTwips((CFont*&)font,fs);
   807 	TEST(ret == KErrNone);
   808 	TEST(font->Handle());
   809 
   810 	TFontSpec checkFS = font->FontSpecInTwips();
   811 	TEST(checkFS.iTypeface.iName == aFontName);
   812 
   813 	iTs->ReleaseFont(font);
   814 	}
   815 
   816 /**
   817 	@SYMTestCaseID
   818 	GRAPHICS-FBSERV-0562
   819 
   820 	@SYMTestCaseDesc
   821 	Tests the width of a font stored in a buffer
   822 	
   823 	@SYMTestActions
   824 	Gets how much of the specified descriptor can be 
   825 	displayed for a specified font without 
   826 	exceeding the specified width.
   827 	
   828 	@SYMTestExpectedResults
   829 	Test should pass
   830 */
   831 void CTFbs::TestBufferedFont()
   832 	{
   833 	INFO_PRINTF1(_L("Test Buffered Font"));
   834 	CFbsFontEx* font=SelectFont();
   835 	TBuf<1280> largebuf;
   836 	TInt count=0;
   837 	for(;count<1280;count++)
   838 		largebuf.Append(32);
   839 	TInt width,lcount,rcount,lwidth,rwidth;
   840 	width=font->TextWidthInPixels(largebuf);
   841 	for(count=0;count<1280;count+=500)
   842 		{
   843 		lcount=font->TextCount(largebuf.Left(count),100000);
   844 		TEST(lcount==count);
   845 		rcount=font->TextCount(largebuf.Right(1280-count),100000);
   846 		TEST(rcount==1280-count);
   847 		lwidth=font->TextWidthInPixels(largebuf.Left(count));
   848 		rwidth=font->TextWidthInPixels(largebuf.Right(1280-count));
   849 		TEST(rwidth+lwidth==width);
   850 		}
   851 	iTs->ReleaseFont(font);
   852 	CheckResourceCount();
   853 	User::Heap().Check();
   854 	}
   855 
   856 /**
   857 	@SYMTestCaseID
   858 	GRAPHICS-FBSERV-0563
   859 
   860 	@SYMTestCaseDesc
   861 	Tests having multiple fonts allocated
   862 	and deallocated
   863 
   864 	@SYMTestActions
   865 	Gets multiple font. Releases the hold of a 
   866 	typeface store client on a specified font.
   867 	Decrements the access-count for the specified 
   868 	font by one. If this reduces the access-count 
   869 	to zero then the font is no longer needed by any 
   870 	client, and is deleted from the typeface store list.
   871 	
   872 	@SYMTestExpectedResults
   873 	Test should pass
   874 */
   875 void CTFbs::TestMultipleFont()
   876 	{
   877 	INFO_PRINTF1(_L("Test Multiple Font"));
   878 	const TInt numfonts=100;
   879 	CFbsFontEx* fonts[numfonts];
   880 	TInt count=0;
   881 	for(;count<numfonts;count++)
   882 		fonts[count]=SelectFont();
   883 	for(count=0;count<numfonts;count++)
   884 		iTs->ReleaseFont(fonts[count]);
   885 	INFO_PRINTF2(_L("    %d font handles created.\n"),numfonts);
   886 	CheckResourceCount();
   887 	User::Heap().Check();
   888 	}
   889 
   890 /**
   891 	@SYMTestCaseID
   892 	GRAPHICS-FBSERV-0564
   893 
   894 	@SYMTestCaseDesc
   895 	Tests creation of unique bitmaps with
   896 	no handles already to them. Also tests
   897 	and verifies defects DEF069571 and DEF076347.
   898 	
   899 	@SYMDEF DEF069571 DEF076347
   900 	
   901 	@SYMTestActions
   902 	Test creation of original bitmaps. Destroys 
   903 	existing bitmap and creates a new one. Tests
   904 	creation of bitmap by duplicating an already
   905 	existing bitmap. Tests creation of different 
   906 	sized bitmaps and resizes them.
   907 	
   908 	@SYMTestExpectedResults
   909 	Test should pass
   910 */
   911 void CTFbs::TestCreateBitmap()
   912 	{
   913 	INFO_PRINTF1(_L("Test Create Bitmap"));
   914 	__UHEAP_MARK;
   915 
   916 	CFbsBitmapEx bmp1;
   917 	CFbsBitmapEx bmp2;
   918 
   919 	// Test creation of original bitmaps (ie handles are unique)
   920 	TInt ret=bmp1.Create(TSize(0,0),EGray2);
   921 	TEST(ret==KErrNone);
   922 	iResourceCount++;
   923 	CheckResourceCount();
   924 
   925 	ret=bmp2.Load(iTestBitmapName,ETfbs);
   926 	TEST(ret==KErrNone);
   927 	iResourceCount++;
   928 	TEST(bmp2.Handle()!=bmp1.Handle());
   929 	CheckResourceCount();
   930 
   931 	ret=bmp2.Create(TSize(0,0),EGray2); // Destroys existing and creates new
   932 	TEST(ret==KErrNone);
   933 	TEST(bmp2.Handle()!=bmp1.Handle());
   934 	CheckResourceCount();
   935 	bmp2.Reset();
   936 	iResourceCount--;
   937 	CheckResourceCount();
   938 
   939 	// Test creation by duplication
   940 	RFbsSession* fbsalt=RFbsSession::GetSession();
   941 	CFbsBitmapEx bmp3;
   942 
   943 	ret=bmp3.Duplicate(bmp1.Handle());
   944 	TEST(ret==KErrNone);
   945 	iResourceCount++;
   946 	CheckResourceCount();
   947 	TEST(fbsalt->ResourceCount()==iResourceCount);
   948 	TEST((TInt)bmp1.BitmapAddress());
   949 	CBitwiseBitmap* bmp3add=bmp3.BitmapAddress();
   950 	CBitwiseBitmap* bmp1add=bmp1.BitmapAddress();
   951 	TEST(bmp3add==bmp1add);
   952 	TEST(bmp3.Handle()==bmp1.Handle());
   953 	bmp3.Reset();
   954 	iResourceCount--;
   955 	CheckResourceCount();
   956 	TEST(fbsalt->ResourceCount()==iResourceCount);
   957 	bmp1.Reset();
   958 	iResourceCount--;
   959 	CheckResourceCount();
   960 	TEST(fbsalt->ResourceCount()==iResourceCount);
   961 	
   962 	//Testing the DEF069571
   963 	
   964 	CFbsBitmapEx bmp0;
   965 	//Test creation of large bitmaps (>65536)
   966 	TInt ret0=bmp0.Create(TSize(65536,1),EGray256);
   967 	bmp0.Reset();
   968 	
   969 	//Testcode for DEF076347
   970 	CFbsBitmapEx bmp01;
   971 	TInt ret01=bmp01.Create(TSize(65536,1),EColor16MU);
   972 	TInt ret02=bmp01.SetDisplayMode(EColor16MA);
   973 	bmp01.Reset();
   974 	
   975 	
   976 
   977 	// Test creation of different sizes and resizing them
   978 	DoResizeBitmap(EGray2);
   979 	DoResizeBitmap(EGray4);
   980 	DoResizeBitmap(EGray16);
   981 	DoResizeBitmap(EGray256);
   982 	DoResizeBitmap(EColor16);
   983 	DoResizeBitmap(EColor256);
   984 	DoResizeBitmap(EColor4K);
   985 	DoResizeBitmap(EColor64K);
   986 	DoResizeBitmap(EColor16M);
   987 
   988 	User::Heap().Check();
   989 	__UHEAP_MARKEND;
   990 	}
   991 
   992 void CTFbs::DoResizeBitmap(TDisplayMode aDispMode)
   993 	{
   994 	const TInt numNewSizes = 5;
   995 	const TSize newSizes[numNewSizes] = { TSize(0,0), TSize(1,1), TSize(17,20), TSize(32,32), TSize(32,1025) };
   996 	const TInt numTwipsSizes = 4;
   997 	const TSize twipsSizes[numTwipsSizes] = { TSize(100,100), TSize(1440,1440), TSize(1000000,1000000), TSize(0,0) };
   998 
   999 	__UHEAP_MARK;
  1000 
  1001 	CFbsBitmapEx bmp;
  1002 
  1003 	TInt count;
  1004 	for(count = 0; count < numNewSizes; count++)
  1005 		{
  1006 		TSize size = newSizes[count];
  1007 		TInt ret = bmp.Create(size,aDispMode);
  1008 		TEST(ret == KErrNone);
  1009 		TEST(bmp.Handle() != 0);
  1010 		TEST(bmp.SizeInPixels() == size);
  1011 		TEST(bmp.DisplayMode() == aDispMode);
  1012 		}
  1013 
  1014 	for(count = 0; count < numNewSizes; count++)
  1015 		{
  1016 		TInt ret = bmp.Create(TSize(0,0),aDispMode);
  1017 		TSize size = newSizes[count];
  1018 		ret = bmp.Resize(size);
  1019 		TEST(ret == KErrNone);
  1020 		TEST(bmp.SizeInPixels() == size);
  1021 		}
  1022 
  1023 	for(count = 0; count < numTwipsSizes; count++)
  1024 		{
  1025 		TSize size = twipsSizes[count];
  1026 		bmp.SetSizeInTwips(size);
  1027 		TEST(bmp.SizeInTwips() == size);
  1028 		}
  1029 
  1030 	bmp.Reset();
  1031 	CheckResourceCount();
  1032 
  1033 	User::Heap().Check();
  1034 	DeleteScanLineBuffer();
  1035 	__UHEAP_MARKEND;
  1036 	}
  1037 
  1038 /**
  1039 	@SYMTestCaseID
  1040 	GRAPHICS-FBSERV-0565
  1041 
  1042 	@SYMTestCaseDesc
  1043 	Tests loading of bitmaps
  1044 
  1045 	@SYMTestActions
  1046 	Loads a specific bitmap from a multi-bitmap 
  1047 	file. Retrieves the bitmap addresses for the
  1048 	bitmap and check if they are valid.
  1049 	
  1050 	@SYMTestExpectedResults
  1051 	Test should pass
  1052 */
  1053 void CTFbs::TestLoadBitmap()
  1054 	{
  1055 	INFO_PRINTF1(_L("Test Load Bitmap"));
  1056 	__UHEAP_MARK;
  1057 	CFbsBitmapEx bmp1;
  1058 	CFbsBitmapEx bmp2;
  1059 	CFbsBitmapEx bmp3;
  1060 	CFbsBitmapEx bmp4;
  1061 	CFbsBitmapEx bmp5;
  1062 	TInt ret=bmp1.Load(iTestBitmapName,ETfbs);
  1063 	TEST(ret==KErrNone);
  1064 	iResourceCount++;
  1065 	TEST(bmp1.Handle()!=0);
  1066 	ret=bmp2.Load(iTestBitmapName,ETfbs);
  1067 	TEST(ret==KErrNone);
  1068 	iResourceCount++;
  1069 	CBitwiseBitmap* bmp1add=bmp1.BitmapAddress();
  1070 	TEST((TInt)bmp1add);
  1071 	CBitwiseBitmap* bmp2add=bmp2.BitmapAddress();
  1072 	TEST(bmp1add==bmp2add);
  1073 	TEST(bmp1.Handle()==bmp2.Handle());
  1074 	ret=bmp3.Load(iTestBitmapName,ETblank);
  1075 	TEST(ret==KErrNone);
  1076 	iResourceCount++;
  1077 	TEST(bmp1.Handle()!=bmp3.Handle());
  1078 	bmp2.Reset();
  1079 	iResourceCount--;
  1080 	ret=bmp4.Load(iTestBitmapName,ETfbs);
  1081 	TEST(ret==KErrNone);
  1082 	iResourceCount++;
  1083 	CBitwiseBitmap* bmp4add=bmp4.BitmapAddress();
  1084 	TEST(bmp1add==bmp4add);
  1085 	TEST(bmp4.Handle()==bmp1.Handle());
  1086 	ret=bmp5.Load(iTestBitmapName,ETblank);
  1087 	TEST(ret==KErrNone);
  1088 	iResourceCount++;
  1089 	CBitwiseBitmap* bmp3add=bmp3.BitmapAddress();
  1090 	CBitwiseBitmap* bmp5add=bmp5.BitmapAddress();
  1091 	TEST((TInt)bmp3add);
  1092 	TEST(bmp3add==bmp5add);
  1093 	TEST(bmp5.Handle()==bmp3.Handle());
  1094 	CheckResourceCount();
  1095 	bmp3.Reset();
  1096 	iResourceCount--;
  1097 	bmp4.Reset();
  1098 	iResourceCount--;
  1099 	bmp5.Reset();
  1100 	iResourceCount--;
  1101 	ret=bmp2.Load(iTestBitmapName,ETfbs);
  1102 	TEST(ret==KErrNone);
  1103 	iResourceCount++;
  1104 	bmp2add=bmp2.BitmapAddress();
  1105 	TEST(bmp1add==bmp2add);
  1106 	TEST(bmp1.Handle()==bmp2.Handle());
  1107 	CheckResourceCount();
  1108 	bmp1.Reset();
  1109 	iResourceCount--;
  1110 	bmp2.Reset();
  1111 	iResourceCount--;
  1112 	CheckResourceCount();
  1113 
  1114 	ret=bmp1.Load(iTestBitmapName,ETfbs,EFalse);
  1115 	TEST(ret==KErrNone);
  1116 	ret=bmp2.Load(iTestBitmapName,ETfbs,ETrue);
  1117 	TEST(ret==KErrNone);
  1118 	ret=bmp3.Load(iTestBitmapName,ETfbs,ETrue);
  1119 	TEST(ret==KErrNone);
  1120 	ret=bmp4.Load(iTestBitmapName,ETfbs,EFalse);
  1121 	TEST(ret==KErrNone);
  1122 	ret=bmp5.Load(iTestBitmapName,ETfbs,ETrue);
  1123 	TEST(ret==KErrNone);
  1124 	bmp1add=bmp1.BitmapAddress();
  1125 	bmp2add=bmp2.BitmapAddress();
  1126 	bmp3add=bmp3.BitmapAddress();
  1127 	bmp4add=bmp4.BitmapAddress();
  1128 	bmp5add=bmp5.BitmapAddress();
  1129 	TEST(bmp1add!=bmp2add);
  1130 	TEST(bmp1add!=bmp3add);
  1131 	TEST(bmp1add!=bmp4add);
  1132 	TEST(bmp1add!=bmp5add);
  1133 	TEST(bmp2add==bmp3add);
  1134 	TEST(bmp2add!=bmp4add);
  1135 	TEST(bmp2add==bmp5add);
  1136 	TEST(bmp3add!=bmp4add);
  1137 	TEST(bmp3add==bmp5add);
  1138 	TEST(bmp4add!=bmp5add);
  1139 	bmp1.Reset();
  1140 	bmp2.Reset();
  1141 	bmp3.Reset();
  1142 	bmp4.Reset();
  1143 	bmp5.Reset();
  1144 	User::Heap().Check();
  1145 	DeleteScanLineBuffer();
  1146 	__UHEAP_MARKEND;
  1147 	}
  1148 
  1149 /**
  1150 	@SYMTestCaseID
  1151 	GRAPHICS-FBSERV-0566
  1152 
  1153 	@SYMTestCaseDesc
  1154 	Checks the properties of a created bitmap.
  1155 	
  1156 	@SYMTestActions
  1157 	Creates a bitmap. Checks the resource count.
  1158 	Checks the handle, size, display mode and 
  1159 	conversion methods for twips to pixels. Checks
  1160 	the heap for memory leaks.
  1161 	
  1162 	@SYMTestExpectedResults
  1163 	Test should pass
  1164 */
  1165 void CTFbs::TestQueryBitmap()
  1166 	{
  1167 	INFO_PRINTF1(_L("Test Query Bitmap"));
  1168 	__UHEAP_MARK;
  1169 	CheckResourceCount();
  1170 	CFbsBitmapEx bmp;
  1171 	TInt ret=bmp.Create(TSize(100,100),EGray16);
  1172 	TEST(ret==KErrNone);
  1173 	iResourceCount++;
  1174 	CheckResourceCount();
  1175 	TEST(bmp.Handle()!=0);
  1176 	TEST(bmp.SizeInPixels()==TSize(100,100));
  1177 	TEST(bmp.DisplayMode()==EGray16);
  1178 	bmp.SetSizeInTwips(TSize(1000,1000));
  1179 	TEST(bmp.SizeInTwips()==TSize(1000,1000));
  1180 	TEST(bmp.HorizontalPixelsToTwips(10)==100);
  1181 	TEST(bmp.VerticalPixelsToTwips(10)==100);
  1182 	TEST(bmp.HorizontalTwipsToPixels(100)==10);
  1183 	TEST(bmp.VerticalTwipsToPixels(100)==10);
  1184 	TEST(bmp.ScanLineLength(100,EGray16)==52);
  1185 	bmp.Reset();
  1186 	iResourceCount--;
  1187 	CheckResourceCount();
  1188 	User::Heap().Check();
  1189 	DeleteScanLineBuffer();
  1190 	__UHEAP_MARKEND;
  1191 	}
  1192 
  1193 /**
  1194 	@SYMTestCaseID
  1195 	GRAPHICS-FBSERV-0567
  1196 
  1197 	@SYMTestCaseDesc
  1198 	Extended test to check scan line buffer in 
  1199 	session allocated correctly for SetRomBitmapL	
  1200 
  1201 	@SYMTestActions
  1202 	Loads a specific bitmap from a multi-bitmap 
  1203 	file. Reset the bitmap and checks the resource 
  1204 	count. Loads new bitmaps, checks the handle
  1205 	the bitmap address and data address.
  1206 
  1207 	@SYMTestExpectedResults
  1208 	Test should pass
  1209 */
  1210 void CTFbs::TestRomBitmapL()
  1211 	{
  1212 	_LIT(KBmpFile, "z:\\system\\data\\tfbs.rbm");
  1213 	INFO_PRINTF1(_L("Test Rom Bitmap"));
  1214 	CheckResourceCount();
  1215 	CFbsBitmapEx bmpx;
  1216 	TInt ret=bmpx.Load(KBmpFile,ETfbs);
  1217 	if (ret != KErrNone)
  1218 		{
  1219 		INFO_PRINTF2(_L("Rom bitmap tfbs.mbm not loaded %d\r\n"),ret);
  1220 		return;
  1221 		}
  1222 	bmpx.Reset();
  1223 	CheckResourceCount();
  1224 	__UHEAP_MARK;
  1225 	CFbsBitmapEx bmp1;
  1226 	CFbsBitmapEx bmp2;
  1227 	CFbsBitmapEx bmp3;
  1228 	CFbsBitmapEx bmp4;
  1229 	CFbsBitmapEx bmp5;
  1230 	ret=bmp1.Load(KBmpFile,ETfbs);
  1231 	TEST(ret==KErrNone);
  1232 	TEST(bmp1.Handle()!=0);
  1233 	ret=bmp2.Load(KBmpFile,ETfbs);
  1234 	TEST(ret==KErrNone);
  1235 	CBitwiseBitmap* bmp1add=bmp1.BitmapAddress();
  1236 	TEST((TInt)bmp1add);
  1237 	CBitwiseBitmap* bmp2add=bmp2.BitmapAddress();
  1238 	TEST(bmp1add==bmp2add);
  1239 	TEST(bmp1.Handle()==bmp2.Handle());
  1240 	CheckResourceCount();
  1241 
  1242 	ret=bmp3.Load(KBmpFile,ETblank);
  1243 	TEST(ret==KErrNone);
  1244 	TEST(bmp1.Handle()!=bmp3.Handle());
  1245 	bmp2.Reset();
  1246 	ret=bmp4.Load(KBmpFile,ETfbs);
  1247 	TEST(ret==KErrNone);
  1248 	CBitwiseBitmap* bmp4add=bmp4.BitmapAddress();
  1249 	TEST(bmp1add==bmp4add);
  1250 	TEST(bmp4.Handle()==bmp1.Handle());
  1251 
  1252 	ret=bmp5.Load(KBmpFile,ETblank);
  1253 	TEST(ret==KErrNone);
  1254 	CBitwiseBitmap* bmp3add=bmp3.BitmapAddress();
  1255 	CBitwiseBitmap* bmp5add=bmp5.BitmapAddress();
  1256 	TEST((TInt)bmp3add);
  1257 	TEST(bmp3add==bmp5add);
  1258 	TEST(bmp5.Handle()==bmp3.Handle());
  1259 
  1260 	CheckResourceCount();
  1261 	bmp3.Reset();
  1262 	bmp4.Reset();
  1263 	bmp5.Reset();
  1264 	ret=bmp2.Load(KBmpFile,ETfbs);
  1265 	TEST(ret==KErrNone);
  1266 	bmp2add=bmp2.BitmapAddress();
  1267 	TEST(bmp1add==bmp2add);
  1268 	TEST(bmp1.Handle()==bmp2.Handle());
  1269 
  1270 	CheckResourceCount();
  1271 	bmp2.Reset();
  1272 	ret=bmp2.Load(iTestBitmapName,ETfbs);
  1273 	TEST(ret==KErrNone);
  1274 	bmp2add=bmp2.BitmapAddress();
  1275 	TSize bmpsize=bmp1.SizeInPixels();
  1276 	TInt sllen=CFbsBitmap::ScanLineLength(bmpsize.iWidth,bmp1.DisplayMode());
  1277 	sllen*=bmpsize.iHeight;
  1278 	bmp1.LockHeap();
  1279 	TUint32* bmp1bits=bmp1.DataAddress();
  1280 	bmp1.UnlockHeap();
  1281 	bmp2.LockHeap();
  1282 	TUint32* bmp2bits=bmp2.DataAddress();
  1283 	bmp2.UnlockHeap();
  1284 	TEST(Mem::Compare((TUint8*)bmp1bits,sllen,(TUint8*)bmp2bits,sllen)==0);
  1285 	bmp1.Reset();
  1286 	bmp2.Reset();
  1287 
  1288 	ret=bmp1.Load(KBmpFile,ETfbs);
  1289 	TEST(ret==KErrNone);
  1290 	// Extended test to check scan line buffer in session allocated 
  1291 	// correctly for SetRomBitmapL()
  1292 	DeleteScanLineBuffer();
  1293 	TInt size = 0;
  1294 	bmp2.SetRomBitmapL(bmp1.BitmapAddress(),size);
  1295 	TEST(iFbs->iScanLineBuffer != 0);
  1296 	TEST(Mem::Compare((TUint8*)bmp1.BitmapAddress(),size,(TUint8*)bmp2.BitmapAddress(),size)==0);
  1297 	bmp1.Reset();
  1298 	bmp2.Reset();
  1299 
  1300 	User::Heap().Check();
  1301 	DeleteScanLineBuffer();
  1302 	__UHEAP_MARKEND;
  1303 	}
  1304 
  1305 TInt AlternateThreadTest(TAny* aAny)
  1306 	{
  1307 	CTFbs* alt = static_cast<CTFbs*> (aAny);
  1308 	__UHEAP_MARK;
  1309 
  1310 	TInt ret=RFbsSession::Connect();
  1311 	alt->TEST(ret==KErrNone);
  1312 	RFbsSession* fbs=RFbsSession::GetSession();
  1313 	alt->TEST(fbs!=NULL);
  1314 	alt->TEST(fbs->ResourceCount()==0);
  1315 
  1316 	CFbsFontEx* font=new CFbsFontEx;
  1317 	ret=font->Duplicate(buffer[0]);
  1318 	alt->TEST(ret==KErrNone);
  1319 	alt->TEST(fbs->ResourceCount()==1);
  1320 	
  1321 	CFbsBitmapEx bmp;
  1322 	ret=bmp.Duplicate(buffer[1]);
  1323 	alt->TEST(ret==KErrNone);
  1324 #if defined(__WINS__)
  1325 	alt->TEST(fbs->ResourceCount()==2);
  1326 #endif
  1327 	
  1328 	CFbsFontEx* font2=new CFbsFontEx;
  1329 	ret=font2->Duplicate(buffer[0]);
  1330 	alt->TEST(ret==KErrNone);
  1331 	font->Reset();
  1332 	User::Free(font);
  1333 	font2->Reset();
  1334 	User::Free(font2);
  1335 #if defined(__WINS__)
  1336 	alt->TEST(fbs->ResourceCount()==1);
  1337 #endif
  1338 	CFbsBitmapEx bmp2;
  1339 	ret=bmp2.Duplicate(buffer[1]);
  1340 	alt->TEST(ret==KErrNone);
  1341 	bmp.Reset();
  1342 	bmp2.Reset();
  1343 	alt->TEST(fbs->ResourceCount()==0);
  1344 	RFbsSession::Disconnect();
  1345 	__UHEAP_MARKEND;
  1346 	return(KErrNone);
  1347 	}
  1348 
  1349 /**
  1350 	@SYMTestCaseID
  1351 	GRAPHICS-FBSERV-0568
  1352 
  1353 	@SYMTestCaseDesc
  1354 	Tests the resource counting of font objects
  1355 	during multi threading
  1356 	
  1357 	@SYMTestActions
  1358 	
  1359 	@SYMTestExpectedResults
  1360 	Test should pass
  1361 */
  1362 void CTFbs::TestMultiThread()
  1363 	{
  1364 	INFO_PRINTF1(_L("Test Multiple Threads"));
  1365 	CFbsFontEx* font=SelectFont();
  1366 	TEST(font->Handle()!=0);
  1367 	iResourceCount++;
  1368 	CheckResourceCount();
  1369 	
  1370 	CFbsBitmapEx bmp;
  1371 	TInt ret=bmp.Load(iTestBitmapName,ETfbs);
  1372 	TEST(ret==KErrNone);
  1373 	iResourceCount++;
  1374 	CheckResourceCount();
  1375 
  1376 	buffer[0]=font->Handle();
  1377 	buffer[1]=bmp.Handle();
  1378 	RThread thrd;
  1379 	TRequestStatus stat;
  1380 	thrd.Create(_L("AlternateThreadTest"),AlternateThreadTest,KDefaultStackSize,0x2000,0x2000,this);
  1381 	thrd.SetPriority(EPriorityMuchMore);
  1382 	thrd.Logon(stat);
  1383 	thrd.Resume();
  1384 	User::WaitForRequest(stat);
  1385 	thrd.Close();
  1386 	bmp.Reset();
  1387 	iResourceCount--;
  1388 	iTs->ReleaseFont(font);
  1389 	iResourceCount--;
  1390 	CheckResourceCount();
  1391 	User::Heap().Check();
  1392 	}
  1393 
  1394 /**
  1395 	@SYMTestCaseID
  1396 	GRAPHICS-FBSERV-0569
  1397 
  1398 	@SYMTestCaseDesc
  1399 	Tests compression of bitmaps on the heap.
  1400 
  1401 	@SYMTestActions
  1402 	Creates a bitmap. Checks the resource count.
  1403 	Allocates memory on the heap. Locks the heap and
  1404 	stores the bitmaps data address. The heap is unlocked.
  1405 	Copies data from the stored data address and compares
  1406 	the copied data with the original data. The heap is
  1407 	checked for memory leaks.
  1408 	
  1409 	@SYMTestExpectedResults
  1410 	Test should pass
  1411 */
  1412 void CTFbs::TestHeapCompression()
  1413 	{
  1414 	INFO_PRINTF1(_L("Test Heap Compression"));
  1415 	__UHEAP_MARK;
  1416 	CheckResourceCount();
  1417 	CFbsBitmapEx bmp1;
  1418 	TInt ret=bmp1.Create(TSize(100,100),EGray16);
  1419 	TEST(ret==KErrNone);
  1420 	iResourceCount++;
  1421 	CheckResourceCount();
  1422 	CFbsBitmapEx bmp2;
  1423 	ret=bmp2.Create(TSize(100,100),EGray16);
  1424 	TEST(ret==KErrNone);
  1425 	iResourceCount++;
  1426 	CheckResourceCount();
  1427 	TUint32* data=(TUint32*)User::Alloc(5200);
  1428 	TEST(data!=NULL);
  1429 	bmp2.LockHeap();
  1430 	TUint32* sladd=bmp2.DataAddress();
  1431 	bmp2.UnlockHeap();
  1432 	TUint32* slptr=sladd;
  1433 	for(TInt count=0;count<1300;count++)
  1434 		*slptr++=count;
  1435 	Mem::Copy(data,sladd,5200);
  1436 	bmp1.Reset();
  1437 	iResourceCount--;
  1438 	CheckResourceCount();
  1439 	bmp2.LockHeap();
  1440 	TUint32* newdata=bmp2.DataAddress();
  1441 	bmp2.UnlockHeap();
  1442 	TEST(Mem::Compare((TUint8*)data,5200,(TUint8*)newdata,5200)==0);
  1443 	bmp2.Reset();
  1444 	iResourceCount--;
  1445 	CheckResourceCount();
  1446 	delete data;
  1447 	User::Heap().Check();
  1448 	DeleteScanLineBuffer();
  1449 	__UHEAP_MARKEND;
  1450 	}
  1451 
  1452 void CTFbs::ExpandCleanupStackL()
  1453 	{
  1454 	TInt count=0;
  1455 	for(;count<10;count++)
  1456 		CleanupStack::PushL((TUint32*)0x1);
  1457 	CleanupStack::Pop(count);
  1458 	}
  1459 
  1460 void CTFbs::CheckResourceCount()
  1461 	{
  1462 	const TInt serverResourceCount = iFbs->ResourceCount();
  1463 	TEST(serverResourceCount == iResourceCount);
  1464 	}
  1465 
  1466 //
  1467 // DoCreateBitmap(), CreateBitmap(), DoAllocScanLineBufL(), CTFbs::AllocScanLineBuf() are 
  1468 // used to show "INC044388  SymbianOS week 12 Fbserv crashes (on HW only)" defect
  1469 // (problem with NULL scanline buffer) and to prove its fix.
  1470 // The idea of the test:
  1471 // A second thread ("CreateBitmap" is the thread name) is created and when resumed it
  1472 // creates a bitmap and initializes ComprBitmap pointer to point to it.
  1473 // The "CreateBitmap" thread signals the main thread, that the bitmap has been created,
  1474 // and waits until receiving "Die" signal and then dies.
  1475 // The main thread waits for a signal from the second thread and then duplicates the bitmap and 
  1476 // calls GetScanLine() on duplicated bitmap object. If the call fails, the defect is not fixed!
  1477 
  1478 CFbsBitmap* ComprBitmap = NULL;//Shared between threads bitmap pointer.
  1479 _LIT(KRamComprBitmap, "z:\\system\\data\\16bit20col.mbm");
  1480 RSemaphore  BitmapCreatedSyncObj;//It is used to signal when the bitmap, created by the thread, 
  1481 								 //is ready for use
  1482 RSemaphore  DieSyncObj;//It is used to signal that "CreateBitmapThread" can die.
  1483 
  1484 //Thread function. It is used by AllocScanLineBuf() test to create a test bitmap and share
  1485 //it with the main thread. This function is called from CreateBitmap().
  1486 static TInt DoCreateBitmapL(CTFbs* aTest)
  1487 	{
  1488 	aTest->TEST(::ComprBitmap == NULL);
  1489 
  1490 	ComprBitmap = new (ELeave) CFbsBitmap;
  1491 
  1492 	CleanupStack::PushL(::ComprBitmap);
  1493 	User::LeaveIfError(::ComprBitmap->Load(KRamComprBitmap, 0));
  1494 	CleanupStack::Pop(::ComprBitmap);
  1495 
  1496 	return KErrNone;
  1497 	}
  1498 
  1499 //Thread function. It prepares the cleanup stack and traps the call to DoCreateBitmap().
  1500 static TInt CreateBitmap(TAny* aTest)
  1501 	{
  1502 	CTFbs* test = static_cast <CTFbs*> (aTest);
  1503 
  1504 	CTrapCleanup* trapCleanup = CTrapCleanup::New();
  1505 	test->TEST(trapCleanup != NULL);
  1506 	TInt err = RFbsSession::Connect();
  1507 	test->TEST(err == KErrNone);
  1508 
  1509 	TRAP(err, DoCreateBitmapL(test));
  1510 
  1511 	::BitmapCreatedSyncObj.Signal();//Signal the main thread, that the bitmap has been created
  1512 	::DieSyncObj.Wait();//Wait "Die" command from the main thread
  1513 
  1514 	delete ::ComprBitmap;
  1515 	::ComprBitmap = NULL;
  1516 	RFbsSession::Disconnect();
  1517 	delete trapCleanup;
  1518 	return err;
  1519 	}
  1520 
  1521 static void DoAllocScanLineBufL(CTFbs& aTest)
  1522 	{
  1523 	aTest.TEST(::ComprBitmap == NULL);
  1524 	//Create semaphores
  1525 	::CleanupClosePushL(::BitmapCreatedSyncObj);
  1526 	::CleanupClosePushL(::DieSyncObj);
  1527 	User::LeaveIfError(::BitmapCreatedSyncObj.CreateLocal(0));
  1528 	User::LeaveIfError(::DieSyncObj.CreateLocal(0));
  1529 	//Create "CreateBitmap" thread. The tread will create "ComprBitmap" bitmap.
  1530 	RThread createBitmapThread;
  1531 	_LIT(KName, "CreateBitmap");
  1532 	User::LeaveIfError(createBitmapThread.Create(KName, 
  1533 		(TThreadFunction)CreateBitmap, KDefaultStackSize, KMinHeapSize, 0x00100000, &aTest));
  1534 	RDebug::Print(_L("CreateBitmap thread started\r\n"));	
  1535 	//Request notification when the tread dies.
  1536 	TRequestStatus status;
  1537 	createBitmapThread.Logon(status);
  1538 	//Resume the thread
  1539 	createBitmapThread.Resume();
  1540 	::BitmapCreatedSyncObj.Wait();//Wait "bitmap created" signal
  1541 	//The bitmap "ComprBitmap" should be already created
  1542 	aTest.TEST(::ComprBitmap != NULL);
  1543 	//Duplicate the bitmap
  1544 	CFbsBitmap* bmp = new (ELeave) CFbsBitmap;
  1545 	CleanupStack::PushL(bmp);
  1546 	TInt err = bmp->Duplicate(::ComprBitmap->Handle());
  1547 	aTest.TEST(err == KErrNone);
  1548 	//Call GetScanLine(). It will fail if the defect is not fixed.
  1549 	TBuf8<100> buf;
  1550 	bmp->GetScanLine(buf, TPoint(0, 0), 10, EColor256);
  1551 	//Cleanup
  1552 	CleanupStack::PopAndDestroy(bmp);
  1553 	//Signal & Wait until "CreateBitmap" thread dies.
  1554 	::DieSyncObj.Signal();
  1555 	User::WaitForRequest(status);
  1556 	aTest.TEST(::ComprBitmap == NULL);
  1557 	CleanupStack::PopAndDestroy(&::DieSyncObj);
  1558 	CleanupStack::PopAndDestroy(&::BitmapCreatedSyncObj);
  1559 	}
  1560 
  1561 //INC044388 - SymbianOS week 12 Fbserv crashes (on HW only)
  1562 void CTFbs::AllocScanLineBuf()
  1563 	{
  1564 	TRAPD(err, ::DoAllocScanLineBufL(*this));
  1565 	TEST(err == KErrNone);
  1566 	}
  1567 // End of INC044388 test.
  1568 
  1569 
  1570 int CTFbs::LoadOpenFontLibraries()
  1571 	{
  1572 	RImplInfoPtrArray implementationArray;
  1573 	TInt error = KErrNone;
  1574 	TUid uid = {KUidOpenFontRasterizerPlunginInterface};
  1575 
  1576 	TRAPD(ecomerror,REComSession::ListImplementationsL(uid,implementationArray));
  1577 	TEST(ecomerror==KErrNone);
  1578 
  1579 	const TInt availCount = implementationArray.Count();
  1580 	for (TInt count=0;count<availCount;++count)
  1581 		{
  1582 		const CImplementationInformation* info = implementationArray[count];
  1583 		TUid rasterizerUid = info->ImplementationUid();
  1584 		// Create a rasterizer
  1585 		COpenFontRasterizer* rasterizer=0;
  1586 		TRAP(error,rasterizer = COpenFontRasterizer::NewL(rasterizerUid));
  1587 		if (!error)
  1588 			{
  1589 			// Install it in the font store.
  1590 			TRAP(error,iFs->InstallRasterizerL(rasterizer));
  1591 			if (error)
  1592 				delete rasterizer;
  1593 			}
  1594 		}
  1595 	implementationArray.ResetAndDestroy();
  1596 	return error;
  1597 	}
  1598 	
  1599 TBool CTFbs::CheckTypefacesSupport(const TTypefaceSupport& aInfo1, const TTypefaceSupport& aInfo2)
  1600 	{
  1601 	if ((aInfo1.iTypeface == aInfo2.iTypeface) &&
  1602 		(aInfo1.iIsScalable == aInfo2.iIsScalable) &&
  1603 		(aInfo1.iMaxHeightInTwips == aInfo2.iMaxHeightInTwips) &&
  1604 		(aInfo1.iMinHeightInTwips == aInfo2.iMinHeightInTwips) &&
  1605 		(aInfo1.iNumHeights == aInfo2.iNumHeights))
  1606 		{
  1607 		return ETrue;	
  1608 		}
  1609 	return EFalse;
  1610 	}
  1611 
  1612 void CTFbs::LoadFontsL(const TDesC& aFontsDir)
  1613 	{
  1614 	TUid id1 = TUid::Uid(0);
  1615 
  1616 	RFs fileSys;
  1617 	User::LeaveIfError(fileSys.Connect());
  1618 
  1619 	TFindFile fileFinder(fileSys);
  1620 	CDir* foundFileList = NULL;
  1621 	
  1622 	_LIT(KFBSERVFontFilePattern, "*");
  1623 	TInt findFileComplete = fileFinder.FindWildByDir(KFBSERVFontFilePattern,aFontsDir,foundFileList);
  1624 
  1625 	while (!findFileComplete)
  1626 		{
  1627 		CleanupStack::PushL(foundFileList);
  1628 
  1629 		const TInt foundFileCount = foundFileList->Count();
  1630 		for (TInt i = 0; i < foundFileCount; i++)
  1631 			{			
  1632 			TParse parse;
  1633 			if (parse.Set((*foundFileList)[i].iName,&fileFinder.File(),NULL) == KErrNone)
  1634 				{
  1635 				// Get filename and extension of font proposing to be loaded
  1636 				TPtrC fontFilename = parse.NameAndExt();
  1637 				INFO_PRINTF2(_L("CTFbs::LoadFontsL to load font filename: %S\r\n"), &fontFilename);
  1638 				TRAPD(addFileError,id1=iFs->AddFileL(parse.FullName()));
  1639 				if (addFileError != KErrNone)
  1640 					{
  1641 					// Log error in the "corrupt font" file
  1642 					User::Panic(_L("Wrong font file"), addFileError);
  1643 					}
  1644 				}
  1645 			}
  1646 		CleanupStack::PopAndDestroy(foundFileList); 
  1647 		findFileComplete = fileFinder.FindWild(foundFileList);
  1648 		}		
  1649 	fileSys.Close();
  1650 	}
  1651 
  1652  /**
  1653    @SYMTestCaseID GRAPHICS-PREQ807_1_Load_all_fonts-0001
  1654   
  1655    @SYMPREQ REQ4723
  1656   
  1657    @SYMTestCaseDesc The test manually scans the font folders and loads all font files available.
  1658    Once all the fonts have been loaded and stored in a CFontStore, the TTypefaces stored in this
  1659    CFontStore object are compared to the TTypefaces stored in an existing CFbsTypefaceStore. 
  1660    
  1661    @SYMTestPriority High 
  1662   
  1663    @SYMTestStatus Implemented
  1664    
  1665    @SYMTestActions \n
  1666    API Calls:\n	
  1667       
  1668    @SYMTestExpectedResults The test expects that all the font files loaded by the test matches the ones 
  1669    that FBserv loaded during the startup initialisation.    
  1670   */
  1671 void CTFbs::TestAllFontsLoaded()
  1672 	{
  1673 	INFO_PRINTF1(_L("Test Load all fonts files"));
  1674 	__UHEAP_MARK;
  1675 
  1676 	iHeap=UserHeap::ChunkHeap(NULL,0x10000,0x10000);
  1677 	TRAPD(ret,iFs=CFontStore::NewL(iHeap));
  1678 	TEST(ret==KErrNone);
  1679 	TEST(iFs != NULL);
  1680 
  1681 	ret = LoadOpenFontLibraries();
  1682 	TEST(ret==KErrNone);
  1683 
  1684 	TRAP(ret, LoadFontsL(KFBSERVFontFileDir));
  1685 	TEST(ret==KErrNone);
  1686 
  1687 	// Check the Typefaces are the same both in the newly CFontStore and existing CFbsTypefaceStore
  1688 	TInt fsTypefaceNum = iFs->NumTypefaces();
  1689 	TInt tsTypefaceNum = iTs->NumTypefaces();
  1690 	TEST(fsTypefaceNum == tsTypefaceNum);	
  1691 
  1692 	TBool equal = EFalse;
  1693 	for (TInt i = 0; i < fsTypefaceNum; i++)
  1694 		{
  1695 		TTypefaceSupport infoFs;
  1696 		iFs->TypefaceSupport(infoFs,i);
  1697 		for (TInt j = 0; j < tsTypefaceNum; j++)
  1698 			{
  1699 			TTypefaceSupport infoTs;
  1700 			iTs->TypefaceSupport(infoTs,j);
  1701 			
  1702 			equal = CheckTypefacesSupport(infoFs, infoTs);
  1703 			if (equal)
  1704 				{
  1705 				break;
  1706 				}
  1707 			}
  1708 		// Check if the CFontStore typeface has been found in the CFbsTypefaceStore
  1709 		TEST(equal);
  1710 		}
  1711 		
  1712 	delete iFs;
  1713 	iHeap->Close();
  1714 
  1715 	REComSession::FinalClose();
  1716 	
  1717 	User::Heap().Check();
  1718 	__UHEAP_MARKEND;
  1719 	}
  1720 
  1721 /**
  1722 	@SYMTestCaseID
  1723 	GRAPHICS-FBSERV-0570
  1724 
  1725 	@SYMTestCaseDesc
  1726 	Tests default language for metrics.
  1727 
  1728 	@SYMTestActions
  1729 	Constructs a TFontSpec object with the specified 
  1730 	typeface and height. Gets the font which is the 
  1731 	nearest to the given font specification. Checks
  1732 	that the maximum font height is correct for a 
  1733 	specified language.
  1734 	
  1735 	@SYMTestExpectedResults
  1736 	Test should pass
  1737 */
  1738 void CTFbs::TestDefaultLanguageForMetrics()
  1739 	{
  1740 	static const TInt KRequiredHeight = 24;
  1741 	static const TInt KReturnedMaxHeight = 36;
  1742 	TInt rc = KErrGeneral;
  1743 
  1744 	// Case 00
  1745 	// No languages are set on font spec and typeface store
  1746 	//
  1747 	TFontSpec fontSpec0(KTypefaceName, KRequiredHeight);
  1748 	CFont* font0 = NULL;
  1749 	rc = iTs->GetNearestFontToDesignHeightInPixels(font0, fontSpec0);
  1750 	TEST(KErrNone == rc);
  1751 	TEST(NULL != font0);
  1752 	TEST(KReturnedMaxHeight == font0->FontMaxHeight());
  1753 	INFO_PRINTF2(_L("FontMaxHeight returns %d"), font0->FontMaxHeight());
  1754 
  1755 	// Case 01
  1756 	// Set language on font spec will suppress that on typeface store
  1757 	//
  1758 	fontSpec0.SetScriptTypeForMetrics(ELangGreek);
  1759 	CFont* font1 = NULL;
  1760 	rc = iTs->GetNearestFontToDesignHeightInPixels(font1, fontSpec0);
  1761 	TEST(KErrNone == rc);
  1762 	TEST(NULL != font1);
  1763 	TEST(KReturnedMaxHeight == font1->FontMaxHeight());
  1764 	INFO_PRINTF2(_L("FontMaxHeight returns %d"), font1->FontMaxHeight());
  1765 
  1766 	// Set language on typeface store
  1767 	iTs->SetDefaultLanguageForMetrics(ELangEnglish);
  1768 
  1769 	// Case 10
  1770 	// Language on typeface store will suppress that on font spec
  1771 	// _if_ its not specified
  1772 	//
  1773 	TFontSpec fontSpec1(KTypefaceName, KRequiredHeight);
  1774 	CFont* font2 = NULL;
  1775 	rc = iTs->GetNearestFontToDesignHeightInPixels(font2, fontSpec1);
  1776 	TEST(KErrNone == rc);
  1777 	TEST(NULL != font2);
  1778 	TEST(KReturnedMaxHeight == font2->FontMaxHeight());
  1779 	INFO_PRINTF2(_L("FontMaxHeight returns %d"), font2->FontMaxHeight());
  1780 
  1781 	// Case 11 - Negative test of case 10
  1782 	//
  1783 	fontSpec1.SetScriptTypeForMetrics(ELangRussian);
  1784 	CFont* font3 = NULL;
  1785 	rc = iTs->GetNearestFontToDesignHeightInPixels(font3, fontSpec1);
  1786 	TEST(KErrNone == rc);
  1787 	TEST(NULL != font3);
  1788 	TEST(KReturnedMaxHeight == font3->FontMaxHeight());
  1789 	INFO_PRINTF2(_L("FontMaxHeight returns %d"), font3->FontMaxHeight());
  1790 
  1791 	iTs->ReleaseFont(font0);
  1792 	iTs->ReleaseFont(font1);
  1793 	iTs->ReleaseFont(font2);
  1794 	iTs->ReleaseFont(font3);
  1795 
  1796 	CheckResourceCount();
  1797 	User::Heap().Check();
  1798 	}
  1799 	
  1800 
  1801 //The "bad" versions of these standard fonts have been hacked to give specific results
  1802 _LIT(KFBSERVFontFileOpen, 		"Z:\\resource\\fonts\\DejaVuSansCondensed.ttf");
  1803 
  1804 //This file is identical to DejaVuSansCondensed.ttf
  1805 _LIT(KFBSERVFontFileBadOpen, 	"Z:\\PlatTest\\Graphics\\TestData\\uniquified_fonts\\xx_dejavusanscondensed.ttf");
  1806 
  1807  /**
  1808    @SYMTestCaseID GRAPHICS-CTFbs-TestDuplicateFontFileEntries-0001
  1809   
  1810    @SYMDEF  DEF094692
  1811   
  1812    @SYMTestCaseDesc  If Open fonts are loaded that are marginally unique compared to the 
  1813    					 existing fonts then they are not actually added to the typeface system, and may even be discarded.
  1814    					 The fix is actually in FNTSTORE, but I need to test in an environment with full Open font support,
  1815    					 which is not provided in the fontstore test code.
  1816    					 Bi9tmap fon ts are tested in fntstore\tfs\t_fntmem.cpp
  1817    
  1818    @SYMTestPriority Med 
  1819   
  1820    @SYMTestStatus Implemented
  1821    
  1822    @SYMTestActions \n
  1823    		The original versions of the Open fonts are first loaded to ensure that they have actually been loaded.
  1824    		The original versions of the Open fonts are loaded again to demobnstrate they have the same IDs.
  1825    		A version of the open font which is identical except for a different filename should be rejected
  1826    	
  1827    			
  1828    API Calls:	AddFile\n	
  1829       
  1830    @SYMTestExpectedResults The test expects:
  1831    		The original versions should load without changing the number of typefaces
  1832    		The second load should return the same UID for the font
  1833    		The identical fonts should return captured fail codes, and not change the typeface counts
  1834    		The semi-identical font should perform a single increase to UIDs and typefaces
  1835   */
  1836 void CTFbs::TestDuplicateFontFileEntries()
  1837 	{
  1838 	
  1839 	INFO_PRINTF1(_L("Test Load semi-duplicate fonts files"));
  1840 	TInt numFacesBefore=iTs->NumTypefaces();
  1841 	TInt aIdOpen1=0;
  1842 	TInt aIdOpen1b=0;
  1843 	TInt aIdOpen2=0;
  1844 	//make sure the originals of these fonts were safely opened
  1845 	//both should simply cause a reference-count increase on the originator files.
  1846 	TInt err2=iTs->AddFile(KFBSERVFontFileOpen,aIdOpen1);
  1847 	TEST(err2==KErrNone);
  1848 	if (err2)
  1849 		{
  1850 		INFO_PRINTF1(_L("One of the expected fonts was missing. Test abandoned."));
  1851 		}
  1852 	else
  1853 		{
  1854 		TInt numFacesAfterLoadOriginals=iTs->NumTypefaces();
  1855 		//TEST(numFacesBefore==numFacesAfterLoadOriginals);
  1856 		if (numFacesBefore!=numFacesAfterLoadOriginals)
  1857 			INFO_PRINTF2(_L("Warning: reinstalling the system fonts added %d typefaces!"), numFacesAfterLoadOriginals-numFacesBefore);
  1858 		
  1859 		//load the originals again just to prove the UIDs are re-used - only makes sense for open font where UID is generated!
  1860 		TInt err2=iTs->AddFile(KFBSERVFontFileOpen,aIdOpen1b);
  1861 		TEST(err2==KErrNone);
  1862 		TEST(aIdOpen1==aIdOpen1b);
  1863 		
  1864 		TInt numFacesAfterLoadBadFile3=iTs->NumTypefaces();
  1865 		TEST(numFacesBefore==numFacesAfterLoadBadFile3);
  1866 		
  1867 		//This open font file contains no new fonts, so will ultimately be discarded
  1868 		//The pathname is different so it won't be considered identical to its originator
  1869 		TInt err4=iTs->AddFile(KFBSERVFontFileBadOpen,aIdOpen2);
  1870 		TEST(err4==KErrAlreadyExists && aIdOpen2==0); 
  1871 		if (err4!=KErrAlreadyExists)
  1872 				INFO_PRINTF2(_L("Unexpected error code was %d"),err4);	 
  1873 		
  1874 		TInt numFacesAfterLoadBadFile4=iTs->NumTypefaces();
  1875 		TEST(numFacesBefore==numFacesAfterLoadBadFile4);
  1876 		
  1877 		}
  1878 	
  1879 	if (aIdOpen1)	iTs->RemoveFile(aIdOpen1);
  1880 	if (aIdOpen1b)	iTs->RemoveFile(aIdOpen1b);
  1881 	if (aIdOpen2)	iTs->RemoveFile(aIdOpen2);
  1882 	
  1883 	//The added typeface should have been uninstalled
  1884 	TInt numFacesAfterUninstall=iTs->NumTypefaces();
  1885 	TEST(numFacesAfterUninstall==numFacesBefore);
  1886 	
  1887 	
  1888 	}
  1889 
  1890 
  1891 /*
  1892 COMMENTED OUT FOR NOW BECAUSE DEF084095 FIX MAKES THIS TEST REDUNDANT
  1893 //DEF078039: Workwer function: Hindi - Risk of memory leak (RShapeInfo) if client thread dies
  1894 TInt TShapeHeaderMemoryLeakTest(TAny* aTest)
  1895 	{
  1896 	_LIT16(KHindi1,"\x0915\x094D\x0937\x0924\x094D\x0930\x093F\x092F\x0020\x0909\x0926\x094D\x0926\x0947\x0936\x094D\x0020\x0915\x094D\x0937\x093F\x092A\x094D\x0930");
  1897 	_LIT(KDevFontFace, "Devanagari OT Eval");
  1898 	
  1899 	CTFbs* test = static_cast<CTFbs*> (aTest);
  1900 	
  1901 	__UHEAP_MARK;
  1902 	
  1903 	const TDesC16& Hindi1 = KHindi1;
  1904 	RShapeInfo shapeInfo;
  1905 	TBool isOpen = EFalse;
  1906 	
  1907 	// Create a cleanup stack for this thread
  1908 	CTrapCleanup* trapCleanup = CTrapCleanup::New();
  1909 	test->TEST(trapCleanup != NULL);
  1910 
  1911 	// Create a new session with FBSERV
  1912 	TInt ret=RFbsSession::Connect();
  1913 	test->TEST(ret==KErrNone);
  1914 	RFbsSession* fbs=RFbsSession::GetSession();
  1915 	test->TEST(fbs!=NULL);
  1916 
  1917 	// Create a FbsFont to use for shaping
  1918 	TFontSpec testFontSpec(KDevFontFace,200); 
  1919 	CFbsBitmap* bmp = new(ELeave) CFbsBitmap;
  1920 	ret = bmp->Create(TSize(100,100),EGray2);
  1921 	if (ret == KErrNotSupported)
  1922 		return ret;
  1923 	else
  1924 		User::LeaveIfError(ret);
  1925 
  1926 	CFbsBitmapDevice* device = NULL;
  1927 	TRAPD(err,device = CFbsBitmapDevice::NewL(bmp));
  1928 	User::LeaveIfError(err);
  1929 
  1930 	CFbsBitGc* gc = NULL;
  1931 	User::LeaveIfError(device->CreateContext(gc));
  1932 
  1933 	CFbsFont* font = NULL;
  1934 	User::LeaveIfError(device->GetNearestFontToDesignHeightInTwips(font,testFontSpec));
  1935 	gc->UseFont(font);
  1936 	
  1937 	// Open shapeInfo by calling GetCharacterPosition2. This makes an IPC call to the 
  1938 	// server and shapes Hindi, resulting in memory being allocated for a TShapeHeader object
  1939 	CFont::TPositionParam param;
  1940 	param.iDirection = CFont::EHorizontal;
  1941 	param.iFlags = CFont::TPositionParam::EFLogicalOrder;
  1942 	param.iText.Set(Hindi1);
  1943 	param.iPosInText = 0;
  1944 	param.iPen.iX = param.iPen.iY = 0;
  1945 	TBool r = font->GetCharacterPosition2(param, shapeInfo);
  1946 	
  1947 	// Test is memory was allocated to a TShapeHeader object
  1948 	isOpen = shapeInfo.IsOpen();
  1949 	test->TEST(isOpen == 1);
  1950 	
  1951 	// Tidy up and close
  1952 	delete bmp;
  1953 	delete device;
  1954 	delete gc;
  1955 
  1956 	// Disconnect from the server. i.e. end ther session, without calling 
  1957 	// RShapeInfo::Close(), to simulate a client death
  1958 	RFbsSession::Disconnect();
  1959 	
  1960 	// Check to see is TShapeHeader has been freed.
  1961 	// Since a pointer the the TShapeHeader object is stored with the 
  1962 	// COpenFontSessionCache, when the client disconnects, the TShapeHeader 
  1963 	// object is freed along with the session cache.
  1964 	isOpen = shapeInfo.IsOpen();
  1965 	test->TEST(isOpen == 0);
  1966 	
  1967 	delete trapCleanup;
  1968 
  1969 	__UHEAP_MARKEND;
  1970 	return(KErrNone);
  1971 	}
  1972 */
  1973 /*
  1974 COMMENTED OUT FOR NOW BECAUSE DEF084095 FIX MAKES THIS TEST REDUNDANT
  1975 
  1976 //DEF078039: Hindi - Risk of memory leak (RShapeInfo) if client thread dies
  1977 void CTFbs::TestShapeHeaderMemoryLeakAtClientDeath()
  1978 	{
  1979 	INFO_PRINTF1(_L("Test Shape Header Memory Leak At Client Death"));
  1980 	RThread shaperThread;
  1981 	TRequestStatus stat;
  1982 	shaperThread.Create(_L("Shaper Thread"),TShapeHeaderMemoryLeakTest,KDefaultStackSize, KMinHeapSize, 0x00100000,this);
  1983 	shaperThread.SetPriority(EPriorityMuchMore);
  1984 	shaperThread.Logon(stat);
  1985 	shaperThread.Resume();
  1986 	User::WaitForRequest(stat);
  1987 	shaperThread.Close();
  1988 	User::Heap().Check();
  1989 	}
  1990 // End of DEF078039 test.
  1991 */
  1992 
  1993 /**
  1994 @SYMTestCaseID			GRAPHICS-FBSERV-0506
  1995 
  1996 @SYMDEF					INC103815
  1997 
  1998 @SYMTestCaseDesc		Tests that the value returned by CFbsBitmap::Handle()
  1999 						does not change after resizing or compression
  2000 
  2001 @SYMTestPriority		High
  2002 
  2003 @SYMTestType			UT
  2004 
  2005 @SYMTestStatus			Implemented
  2006 
  2007 @SYMTestActions			1. Create a bitmap and store its handle number
  2008 						2. Resize the bitmap and compare its handle number with the stored value
  2009 						3. Compress the bitmap and compare its handle number with the stored value
  2010 
  2011 @SYMTestExpectedResults	All the handle numbers returned should be the same
  2012 */
  2013 void CTFbs::TestBitmapHandleImmutable()
  2014 	{
  2015 	INFO_PRINTF1(_L("Test fix for INC103815"));
  2016 	CFbsBitmap *bmp = new CFbsBitmap;
  2017 	TEST(bmp != NULL);
  2018 	if (bmp == NULL)
  2019 		return;
  2020 	TEST(bmp->Create(TSize(200, 200), EColor256) == KErrNone);
  2021 	TInt handle = bmp->Handle();
  2022 	TEST(bmp->Resize(TSize(400, 400)) == KErrNone);
  2023 	TEST(handle == bmp->Handle());
  2024 	TEST(bmp->Compress() == KErrNone);
  2025 	TEST(handle == bmp->Handle());
  2026 	delete bmp;
  2027 	}
  2028 
  2029 
  2030 /**
  2031 @SYMTestCaseID		GRAPHICS-FBSERV-0507
  2032 @SYMTestPriority	High
  2033 @SYMTestType		UT
  2034 @SYMTestStatus		Implemented
  2035 @SYMDEF				PDEF102570
  2036 
  2037 @SYMTestCaseDesc
  2038 	Tests that the attributes and the data address of a bitmap do not change between
  2039 	calls to CFbsBitmap::BeginDataAccess() and CFbsBitmap::EndDataAccess() due to resizing
  2040 	or compression by other clients
  2041 
  2042 @SYMTestActions
  2043 	1: Create a bitmap and a second CFbsBitmap object that refers to the same bitmap.
  2044 	2: Call BeginDataAccess() on the first CFbsBitmap object.
  2045 	3: Call Resize() on the second CFbsBitmap object.
  2046 	4: Call EndDataAccess() on the first CFbsBitmap object checking its state before and after.
  2047 	5: Call BeginDataAccess() on the first CFbsBitmap object.
  2048 	6: Call Compress() on the second CFbsBitmap object.
  2049 	7: Call EndDataAccess() on the first CFbsBitmap object checking its state before and after.
  2050 
  2051 @SYMTestExpectedResults
  2052 	The affected attributes and the data address of the bitmap should change only
  2053 	after the calls to EndDataAccess()
  2054 */
  2055 void CTFbs::TestBitmapBeginEnd()
  2056 	{
  2057 	INFO_PRINTF1(_L("Test CFbsBitmap::BeginDataAccess()-EndDataAccess()"));
  2058 	CFbsBitmap *bmp1 = new CFbsBitmap;
  2059 	CFbsBitmap *bmp2 = new CFbsBitmap;
  2060 	TEST(bmp1 != NULL && bmp2 != NULL);
  2061 	if (bmp1 == NULL || bmp2 == NULL)
  2062 		return;
  2063 	TEST(bmp1->Create(TSize(200, 200), EColor256) == KErrNone);
  2064 	TEST(bmp2->Duplicate(bmp1->Handle()) == KErrNone);
  2065 	TUint32* dataAddress1 = bmp1->DataAddress();
  2066 	TUint32* dataAddress2 = bmp2->DataAddress();
  2067 	TEST(dataAddress1 == dataAddress2);
  2068 	bmp1->BeginDataAccess();
  2069 	TEST(bmp2->Resize(TSize(400, 400)) == KErrNone);
  2070 	dataAddress2 = bmp2->DataAddress();
  2071 	TEST(bmp1->SizeInPixels() == TSize(200, 200));
  2072 	TEST(bmp1->DataAddress() == dataAddress1);
  2073 	bmp1->EndDataAccess();
  2074 	TEST(bmp1->SizeInPixels() == TSize(400, 400));
  2075 	dataAddress1 = bmp1->DataAddress();
  2076 	TEST(dataAddress1 == dataAddress2);
  2077 	bmp1->BeginDataAccess();
  2078 	TEST(bmp2->Compress() == KErrNone);
  2079 	dataAddress2 = bmp2->DataAddress();
  2080 	TEST(bmp1->Header().iCompression == ENoBitmapCompression);
  2081 	TEST(bmp1->DataAddress() == dataAddress1);
  2082 	bmp1->EndDataAccess();
  2083 	TEST(bmp1->Header().iCompression != ENoBitmapCompression);
  2084 	dataAddress1 = bmp1->DataAddress();
  2085 	TEST(dataAddress1 == dataAddress2);
  2086 	delete bmp1;
  2087 	delete bmp2;
  2088 	}
  2089 
  2090 
  2091 /**
  2092 @SYMTestCaseID		GRAPHICS-FBSERV-0508
  2093 @SYMTestPriority	High
  2094 @SYMTestType		UT
  2095 @SYMTestStatus		Implemented
  2096 @SYMDEF				DEF104752
  2097 
  2098 @SYMTestCaseDesc
  2099 	Tests that trying to launch a second instance of FBServ fails gracefully
  2100 
  2101 @SYMTestActions
  2102 	Start a new instance of FBSERV.EXE. Since the Font and Bitmap Server should
  2103 	already be running, the created process should panic immediately.
  2104 
  2105 @SYMTestExpectedResults
  2106 	Panic FBSERV 5
  2107 */
  2108 void CTFbs::TestSingletonServer()
  2109 	{
  2110 	INFO_PRINTF1(_L("Test singleton FBServ process"));
  2111 	_LIT(KFBSERVServerExe, "z:\\sys\\bin\\fbserv.exe");
  2112 	RProcess fbs;
  2113 	TInt ret = fbs.Create(KFBSERVServerExe, KNullDesC);
  2114 #ifdef __WINS__
  2115 	// On the emulator it's not possible to load the same EXEXP twice
  2116 	// DWin32CodeSeg::DoCreate() returns KErrAlreadyExists in that case
  2117 	if (ret == KErrAlreadyExists)
  2118 		return;
  2119 #endif
  2120 	TEST(ret == KErrNone);
  2121 	TRequestStatus status;
  2122 	fbs.Logon(status);
  2123 	TEST(status == KRequestPending);
  2124 	fbs.Resume();
  2125 	User::WaitForRequest(status);
  2126 	TExitType exitType = fbs.ExitType();
  2127 	TExitCategoryName exitCategory = fbs.ExitCategory();
  2128 	TInt exitReason = fbs.ExitReason();
  2129 	TEST(exitType == EExitPanic);
  2130 	TEST(exitCategory == KFBSERVPanicCategory);
  2131 	TEST(exitReason == EFbsPanicStartupFailed);
  2132 	fbs.Close();
  2133 	}
  2134 
  2135 /**
  2136 @SYMTestCaseID      GRAPHICS-FBSERV-0623
  2137 @SYMTestPriority    High
  2138 @SYMTestStatus      Implemented
  2139 @SYMDEF             DEF140138
  2140 
  2141 @SYMTestCaseDesc
  2142 	A positive test that shows in cases where the font glyph cache is full and the 
  2143 	session cache becomes used, client-side CFbsFont calls that query the session cache 
  2144 	successfully find the glyph, proving that the session handles used client-side and server-side
  2145 	are the same, thereby avoiding any unneccessary IPC calls.
  2146 
  2147 @SYMTestActions
  2148 	Try to open a global semaphore called "FBSSessionCacheSemaphore" (this is a temporary measure to
  2149 		ensure successful propagation of ou1cimx1#250526).
  2150 	Create a large font which consumes a lot of memory.
  2151 	Create a CFbsBitGc and a CFbsBitmap target.
  2152 	Use the CFbsBitGc to render some text, thereby filling the font glyph cache. 
  2153 		Renders enough glyphs to fill up the font glyph cache, so that the session cache is used
  2154 		for later characters.
  2155 	Call CBitmapFont::CharacterNeedsToBeRasterized() with a NULL session handle.
  2156 	Call CBitmapFont::CharacterNeedsToBeRasterized() with the RFbsSession handle.
  2157 	Call CFbsFont::GetCharacterData() to retrieve a pointer to the bitmap data. Compare this with the data 
  2158 		returned from CBitmapFont::GetCharacterData().
  2159 
  2160 @SYMTestExpectedResults
  2161 	No global semaphore called "FBSSessionCacheSemaphore" should exist.
  2162 	When using KNullHandle, CharacterNeedsToBeRasterized() with the first character, is expected to pass
  2163 		proving that the font cache is working as expected when glyphs can fit into it.
  2164 	When using KNullHandle, CharacterNeedsToBeRasterized() with the last character, it expected to fail, 
  2165 		proving that the glyph has not been cached in the font glyph cache. (If it had, it would find a 
  2166 		match regardless of the	session handle as it looks in the font cache before the session cache).
  2167 	When using the correct session handle with CharacterNeedsToBeRasterized() with the last character, 
  2168 		should return ETrue, proving that the glyph has been cached, and was found because the correct 
  2169 		session handle was supplied, therefore must be in the session cache.    
  2170 	The bitmap pointers returned by CFbsFont::GetCharacterData() and CBitmapFont::GetCharacterData() should match, 
  2171 		proving the public API CFbsFont::GetCharacterData() is correctly using the data stored in the session cache,
  2172 		and not returning the data of a separately-rasterized glyph.
  2173 */
  2174 void CTFbs::TestFontSessionCacheLookupL()
  2175 	{
  2176 	INFO_PRINTF1(_L("Test Font Session-cache Lookup"));
  2177 
  2178 	// Make sure the global semaphore is gone for good
  2179 	_LIT(KSessionCacheSemaphoreName, "FBSSessionCacheSemaphore");
  2180 	RSemaphore sem;
  2181 	TEST(sem.OpenGlobal(KSessionCacheSemaphoreName) == KErrNotFound);
  2182 
  2183 	User::LeaveIfError(RFbsSession::Connect());    
  2184 	RFbsSession* fbsSession = RFbsSession::GetSession();
  2185 	CFbsTypefaceStore* ts = CFbsTypefaceStore::NewL(NULL);
  2186 	CleanupStack::PushL(ts);
  2187 
  2188 	TFontSpec fs(_L("DejaVu Sans Mono"), 80);
  2189 	fs.iFontStyle.SetBitmapType(EAntiAliasedGlyphBitmap);
  2190 	CFbsFont* font = NULL;
  2191 	TEST(KErrNone == ts->GetNearestFontToDesignHeightInPixels((CFont*&)font, fs));
  2192 
  2193 	CFbsBitmap* target = new (ELeave) CFbsBitmap;
  2194 	CleanupStack::PushL(target);
  2195 	User::LeaveIfError(target->Create(TSize(100, 100), EColor16MU));
  2196 	CFbsBitmapDevice* bgDevice = CFbsBitmapDevice::NewL(target);
  2197 	CleanupStack::PushL(bgDevice);
  2198 	CFbsBitGc* bgGc = NULL;
  2199 	User::LeaveIfError(bgDevice->CreateContext(bgGc));
  2200 	bgGc->UseFont(font);
  2201 	CleanupStack::PushL(bgGc);
  2202 	_LIT(KTestText, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJLKMNOPQRSTUVWXYZ");
  2203 
  2204 	// Draw the text, forcing the glyphs into the font and session caches.
  2205 	bgGc->DrawText(KTestText, TPoint(0, 10));
  2206 
  2207 	CBitmapFont* bmFont = CTFbsFont::FontAddress(font);
  2208 	
  2209 	// Check that the first character in KTestText has been rasterized, and is in the font cache. 
  2210 	TBool glyphIsInFontCache = !bmFont->CharacterNeedsToBeRasterized(KNullHandle, KTestText()[0]);
  2211 	TEST(glyphIsInFontCache);
  2212 	
  2213 	// Check that the last character in KTestText has been rasterized, and is not in the font cache
  2214 	// because it did not fit, therefore it should be in the session cache.
  2215 	const TChar KTestChar = KTestText()[KTestText().Length() - 1];
  2216 	glyphIsInFontCache = !bmFont->CharacterNeedsToBeRasterized(KNullHandle, KTestChar);
  2217 	TEST(!glyphIsInFontCache);
  2218 	TBool glyphIsInSessionCache = !bmFont->CharacterNeedsToBeRasterized(fbsSession->iHelper->iServerSessionHandle, KTestChar);
  2219 	TEST(glyphIsInSessionCache);
  2220 
  2221 	// Test that when calling GetCharacterData() on CFbsFont, it returns the same rasterized data as 
  2222 	// the bitmap in the session cache, proving that the client API is using the session cache handle correctly.
  2223 	TSize bitmapSize;
  2224 	const TUint8* bitmapDataClient;
  2225 	const TUint8* bitmapDataSessionCache;
  2226 	TOpenFontCharMetrics metrics;
  2227 	font->GetCharacterData(KTestChar,metrics,bitmapDataClient,bitmapSize);
  2228 	bmFont->GetCharacterData(fbsSession->iHelper->iServerSessionHandle, KTestChar, metrics, bitmapDataSessionCache);
  2229 	TEST(bitmapDataClient != NULL && bitmapDataClient == bitmapDataSessionCache);
  2230 
  2231 	bgGc->DiscardFont();
  2232 	CleanupStack::PopAndDestroy(4); // bgGc, bgDevice, target, ts
  2233 	RFbsSession::Disconnect();
  2234 	}
  2235 	
  2236 /**
  2237 @SYMTestCaseID      GRAPHICS-FBSERV-0650
  2238 @SYMTestPriority    High
  2239 @SYMTestStatus      Implemented
  2240 @SYMDEF             DEF141816
  2241 
  2242 @SYMTestCaseDesc
  2243 	A negative test that shows that IPC calls from CFbsBitmap which uses a 
  2244 	CFbsFont handle fail and that IPC calls from CFbsFont which use a 
  2245 	CFbsBitmap handle fail.
  2246 
  2247 @SYMTestActions
  2248 	i. Create a bitmap.
  2249 	ii. Create a font.
  2250 	iii. Send a bitmap-related IPC message to server with bitmap handle.
  2251 	iv. Send a bitmap-related IPC message to server with font handle.
  2252 	v. Send a font-related IPC message to server with font handle.
  2253 	vi. In a separate thread, send a font-related IPC message to server with
  2254 		bitmap handle.
  2255 	
  2256 @SYMTestExpectedResults
  2257 	Steps iii. and v. should return KErrNone.
  2258 	Step iv. should return KErrUnknown.
  2259 	Step vi. should panic with FBSERV -6.
  2260 */
  2261 void CTFbs::TestInvalidHandlesInIpcCallsL()
  2262 	{
  2263 	INFO_PRINTF1(_L("Test Bitmap and Font IPC calls with invalid handles"));
  2264 	CFbsFontEx* font = SelectFont();
  2265 
  2266 	CFbsBitmapEx* bmp = new(ELeave) CFbsBitmapEx();
  2267 	TEST(KErrNone == bmp->Create(TSize(1,1),EGray2));
  2268 
  2269 	TInt fontHandle = font->FontHandle();
  2270 	TInt bitmapHandle = bmp->BitmapHandle();
  2271 
  2272 	// Send a IPC command to resize a bitmap with a font handle
  2273 	TPckgBuf<TBmpHandles> handlebuf;
  2274 	TIpcArgs args1(fontHandle, 2, 2, &handlebuf);
  2275 	// Send a IPC command to resize a bitmap with the bitmap's handle
  2276 	TEST(KErrNone == iFbs->SendCommand(EFbsMessBitmapBgCompress, bitmapHandle));
  2277 	// Send a IPC command to resize a bitmap with the font's handle
  2278 	TEST(KErrUnknown == iFbs->SendCommand(EFbsMessBitmapBgCompress, fontHandle));
  2279 
  2280 	// Send a IPC command to set the font's height with the font's handle
  2281 	TEST(KErrNone == iFbs->SendCommand(EFbsMessSetTwipsHeight, fontHandle, 49));
  2282 	// In a second thread, send a IPC command to set the font's height with the 
  2283 	// bitmap's handle.  Should panic with FBServ -6.
  2284 	_LIT(KTestName, "TestInvalidHandlesInIpcCall");
  2285  	CreateSecondThreadAndCheckPanicL(SecondThreadPanicInvalidHandleInIpcCallL, KErrArgument, KFbsPanicCategory, KTestName);
  2286 
  2287 	iTs->ReleaseFont(font);
  2288 	delete bmp;
  2289 	}
  2290 
  2291 /**
  2292 Second thread function for test GRAPHICS-FBSERV-0650. It should panic with FBSERV -6 if the test is successful.
  2293  */
  2294 void CTFbs::SecondThreadPanicInvalidHandleInIpcCallL()
  2295 	{
  2296 	User::LeaveIfError(RFbsSession::Connect());
  2297 	RFbsSession* fbs = RFbsSession::GetSession();
  2298 	CFbsBitmapEx* bmp = new(ELeave) CFbsBitmapEx();
  2299 	CleanupStack::PushL(bmp);
  2300 	User::LeaveIfError(bmp->Create(TSize(1,1), EGray2));
  2301 	CFbsTypefaceStore* ts = CFbsTypefaceStore::NewL(NULL);
  2302 	CleanupStack::PushL(ts);
  2303 	CFbsFont* font=NULL;
  2304 	User::LeaveIfError(ts->GetNearestFontToDesignHeightInPixels((CFont*&)font, TFontSpec(KTypefaceName, 15)));
  2305 	TInt bitmapHandle = bmp->BitmapHandle();
  2306 
  2307 	// Send a IPC command to set twips height of font with a bitmap handle
  2308 	(void)fbs->SendCommand(EFbsMessSetTwipsHeight, bitmapHandle, 49);
  2309 
  2310 	ts->ReleaseFont(font);
  2311 	CleanupStack::PopAndDestroy(2);
  2312 	RFbsSession::Disconnect();
  2313 	}
  2314 
  2315 
  2316 struct TFbsTestDelegator
  2317 	{
  2318 	CTFbs* iTestBase;
  2319 	void (CTFbs::*iMethodPtr)();
  2320 	};
  2321 
  2322 /**
  2323 Creates a second thread and checks that it panics.
  2324 @param aMethodL The leaving method of CTFbs that the second thread is going to execute.
  2325 @param aPanicCode The expected panic code.
  2326 @param aPanicCategory The expected panic category.
  2327 @param aThreadName The name of the new thread.
  2328 */
  2329 void CTFbs::CreateSecondThreadAndCheckPanicL(void (CTFbs::*aMethodL)(), TInt aPanicCode, const TDesC& aPanicCategory, const TDesC& aThreadName)
  2330 	{
  2331 	RThread secondThread;
  2332 	TFbsTestDelegator delegator;
  2333 	delegator.iTestBase = this;
  2334 	delegator.iMethodPtr = aMethodL;
  2335 	User::LeaveIfError(secondThread.Create(aThreadName, MethodDelegatorThreadFunction, KDefaultStackSize, 0x1000, 0x1000, &delegator));
  2336 	// Launch second thread
  2337 	TRequestStatus statusSecondThread;
  2338 	secondThread.Logon(statusSecondThread);
  2339 	secondThread.Resume();
  2340 	// Wait until second thread is finished
  2341 	User::WaitForRequest(statusSecondThread);
  2342 	// Check results
  2343 	if (EExitPanic != secondThread.ExitType())
  2344 		{
  2345 		ERR_PRINTF2(_L("Expected exit type: EExitPanic, actual exit type: %d"), secondThread.ExitType());
  2346 		TEST(EFalse);
  2347 		}
  2348 	if (aPanicCode != secondThread.ExitReason())
  2349 		{
  2350 		ERR_PRINTF3(_L("Expected exit reason: %d, actual exit reason: %d"), aPanicCode, secondThread.ExitReason());
  2351         TEST(EFalse);
  2352 		}
  2353 	TExitCategoryName secondThreadExitCategory = secondThread.ExitCategory();
  2354 	if (aPanicCategory != secondThreadExitCategory)
  2355 		{
  2356 		ERR_PRINTF3(_L("Expected exit category: %S, actual exit category: %S"), &aPanicCategory, &secondThreadExitCategory);
  2357         TEST(EFalse);
  2358 		}
  2359 	// Dispose of the remains of the second thread
  2360 	secondThread.Close();
  2361 	}
  2362 
  2363 TInt CTFbs::MethodDelegatorThreadFunction(TAny* aDelegator)
  2364 	{
  2365 	CTrapCleanup* cleanupStack = CTrapCleanup::New();
  2366 	if (!cleanupStack)
  2367 	    {
  2368 	    return KErrNoMemory;
  2369 	    }
  2370 	TFbsTestDelegator* delegator = static_cast<TFbsTestDelegator*>(aDelegator);
  2371 	TRAPD(err, (delegator->iTestBase->*delegator->iMethodPtr)());
  2372 	delete cleanupStack;
  2373 	return err;
  2374 	}
  2375 
  2376 /**
  2377 @SYMTestCaseID		GRAPHICS-FBSERV-0619
  2378 @SYMTestPriority	High
  2379 @SYMTestType		UT
  2380 @SYMTestStatus		Implemented
  2381 @SYMDEF				EI0014
  2382 
  2383 @SYMTestCaseDesc
  2384 	Tests that there are no virtual function calls to objects in FBServ's shared heap from outside
  2385 	the FBServ process. Such function calls only work if DLLs are guaranteed to be mapped at the
  2386 	same logical address in every process. This is not necessarily true for all memory models.
  2387 
  2388 @SYMTestActions
  2389 	Selects a font, intercepts the VF table in the corresponding CBitmapFont and COpenFont objects
  2390 	to record virtual function calls from outside the FBServ process, calls the vulnerable functions
  2391 	on the created CFbsFont object and releases the font.
  2392 
  2393 @SYMTestExpectedResults
  2394 	Number of virtual function calls to CBitmapFont and COpenFont from outside FBServ is 0
  2395 */
  2396 void CTFbs::TestNoVFCallsToGlobalObjects()
  2397 	{
  2398 #ifdef __WINS__
  2399 	INFO_PRINTF1(_L("Test no virtual function calls to objects in FBServ's shared heap from outside FBServ process"));
  2400 	CFbsFontEx* font = SelectFont();
  2401 	(void)font->TypeUid();
  2402 	(void)font->HeightInPixels();
  2403 	(void)font->AscentInPixels();
  2404 	(void)font->DescentInPixels();
  2405 	(void)font->CharWidthInPixels('A');
  2406 	(void)font->TextWidthInPixels(_L("A"));
  2407 	(void)font->BaselineOffsetInPixels();
  2408 	(void)font->TextCount(_L("A"), 10);
  2409 	TInt excess;
  2410 	(void)font->TextCount(_L("A"), 10, excess);
  2411 	(void)font->MaxCharWidthInPixels();
  2412 	(void)font->MaxNormalCharWidthInPixels();
  2413 	(void)font->FontSpecInTwips();
  2414 	TOpenFontCharMetrics metrics;
  2415 	const TUint8* bitmap;
  2416 	TSize size;
  2417 	(void)font->GetCharacterData('A', metrics, bitmap, size);
  2418 	CFont::TPositionParam param;
  2419 	param.iText.Set(_L("A"));
  2420 	(void)font->GetCharacterPosition(param);
  2421 	(void)font->FontCapitalAscent();
  2422 	(void)font->FontMaxAscent();
  2423 	(void)font->FontStandardDescent();
  2424 	(void)font->FontMaxDescent();
  2425 	(void)font->FontLineGap();
  2426 	iTs->ReleaseFont(font);
  2427 	TEST(iFontCallCounter.iVFCallsOutsideFBServ == 0);
  2428 	TEST(iOpenFontCallCounter.iVFCallsOutsideFBServ == 0);
  2429 #else
  2430 	INFO_PRINTF1(_L("Test no virtual function calls to objects in FBServ's shared heap from outside FBServ process - skipped on target"));
  2431 #endif
  2432 	}
  2433 
  2434 //--------------
  2435 __CONSTRUCT_STEP__(Fbs)