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