os/textandloc/fontservices/fontstore/tfs/T_FNTMEM.CPP
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 #include "T_FNTMEM.H"
    20 #include "T_FSOPEN.H"
    21 #include <graphics/openfontrasterizer.h>
    22 
    23 #ifdef __WINS__
    24 	_LIT(KEonFontFileName,"z:\\resource\\fonts\\eon14.gdr");
    25 #else
    26 	_LIT(KEonFontFileName,"z:\\resource\\fonts\\eon.gdr");
    27 #endif
    28 
    29 // 'dummy' open fonts, as used by T_FSOPEN
    30 _LIT(KFontDummy,"z:\\PlatTest\\Graphics\\TestData\\dummy_fonts\\dummy");
    31 //_LIT(KFontDummy_b,"z:\\PlatTest\\Graphics\\TestData\\dummy_fonts\\dummy_b");
    32 //_LIT(KFontDummy_i,"z:\\PlatTest\\Graphics\\TestData\\dummy_fonts\\dummy_i");
    33 //_LIT(KFontDummy_bi,"z:\\PlatTest\\Graphics\\TestData\\dummy_fonts\\dummy_bi");
    34 
    35 
    36 
    37 CTFntMem::CTFntMem(CTestStep* aStep):
    38 	CTGraphicsBase(aStep),
    39 	iHeap(NULL)
    40 	{
    41 	iHeap = UserHeap::ChunkHeap(NULL,0x80000,0x80000);
    42 	INFO_PRINTF1(_L("FontStore"));
    43 	}
    44 
    45 void CTFntMem::RunTestCaseL(TInt aCurTestCase)
    46 	{
    47 	((CTFntMemStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
    48 	switch(aCurTestCase)
    49 		{
    50 	case 1:
    51 		((CTFntMemStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0024"));
    52 		TRAPD(err,TestNewL());
    53 		TEST(err == KErrNone);
    54 		break;
    55 	case 2: // OOM handling for bitmap fonts
    56 		((CTFntMemStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0025"));
    57 		TRAP(err,TestAddFileL(KEonFontFileName));
    58 		TEST(err == KErrNone);
    59 		break;
    60 	case 3: // OOM handling for open fonts
    61 		((CTFntMemStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0025"));
    62 		TRAP(err,TestAddFileL(KFontDummy));
    63 		TEST(err == KErrNone);
    64 		break;
    65 	case 5: // OOM handling for second reference to a bitmap font
    66 		((CTFntMemStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0026"));
    67 		TRAP(err,TestAddFileTwiceL(KEonFontFileName));
    68 		TEST(err == KErrNone);
    69 		break;
    70 	case 6: // OOM handling for second reference to an open font
    71 		((CTFntMemStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0026"));
    72 		TRAP(err,TestAddFileTwiceL(KFontDummy));
    73 		TEST(err == KErrNone);
    74 		break;
    75 	case 7:
    76 		((CTFntMemStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0027"));
    77 		TRAP(err,TestGetNearestFontToDesignHeightInTwipsL());
    78 		TEST(err == KErrNone);
    79 		break;
    80 	case 8:
    81 		((CTFntMemStep*)iStep)->SetTestStepID(_L("GRAPHICS-NearestOpenFontLeaksDEF095184-0001"));
    82 		TRAP(err,TestGetNearestOpenFontLeaksL());
    83 		TEST(err == KErrNone);
    84 		break;
    85 	case 9:
    86 		((CTFntMemStep*)iStep)->SetTestStepID(_L("GRAPHICS-CTFbs-TestDuplicateFontFileEntries-0002"));
    87 		TRAP(err,TestDuplicateBitmapFontFileEntriesL());
    88 		TEST(err == KErrNone);
    89 		break;
    90 	case 10:
    91 		((CTFntMemStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
    92 		((CTFntMemStep*)iStep)->CloseTMSGraphicsStep();
    93 		TestComplete();				
    94 		break;
    95 	default:
    96 		((CTFntMemStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
    97 		break;
    98 	}
    99 	((CTFntMemStep*)iStep)->RecordTestResultL();
   100 	}
   101 
   102 /**
   103 	@SYMTestCaseID
   104 	GRAPHICS-FNTSTORE-0024
   105 
   106 	@SYMTestCaseDesc
   107 	Simulates out of memory errors of the heap when trying to allocate
   108 	memory for a CFontStore object.
   109 
   110 	@SYMTestActions
   111 	1. Cancels simulated heap allocation failure for the current thread's heap.
   112 	2. Simulates heap allocation failure for the current thread's heap.
   113 	3. Marks the start of checking the current thread's heap. 
   114 	4. In a loop, tries to create a new CFontStore object with a pointer to 
   115 	   the heap class used for memory allocation.
   116 	5. Checking is done to see if the CFontStore was allocated or
   117 	   if out of memory. The loop is broken when an object is created correctly.  	
   118 	
   119 	@SYMTestExpectedResults
   120 	Test should pass
   121 */
   122 void CTFntMem::TestNewL()
   123 	{
   124 	INFO_PRINTF1(_L("NewL"));
   125 
   126 	TInt ret=KErrGeneral;
   127 	CFontStore *fs=NULL;
   128 	TInt failRate=1;
   129 
   130 	while (ret!=KErrNone)
   131 		{
   132 		__UHEAP_RESET;
   133 		__UHEAP_SETFAIL(RHeap::EDeterministic,failRate);
   134 		__UHEAP_MARK;
   135 		TRAP(ret,fs=CFontStore::NewL(iHeap));
   136 		RDebug::Print(_L("fs %d failrate %d, error %d\n"),fs,failRate, ret);
   137 		if (ret==KErrNoMemory)
   138 			{
   139 			__UHEAP_MARKEND;
   140 			__UHEAP_RESET;
   141 			TEST(fs==NULL);
   142 			}
   143 		else if(ret==KErrNone)
   144 			{
   145 			delete fs;
   146 			__UHEAP_MARKEND;
   147 			__UHEAP_RESET;
   148 			__UHEAP_SETFAIL(RHeap::ENone,failRate);
   149 			}
   150 		else
   151 			User::Panic(_L("Unknown error"),ret);
   152 		failRate++;
   153 		}
   154 	}
   155 
   156 /**
   157 	@SYMTestCaseID
   158 	GRAPHICS-FNTSTORE-0025
   159 
   160 	@SYMTestCaseDesc
   161 	Tests the Out Of Memory handling for bitmap- and open fonts.
   162 
   163 	@SYMTestActions
   164 	1. Finds or creates a font file object to support a font file.
   165 	   If an appropriate font file object exists then no new open font file is created. 
   166 	   In this case the reference count of the font file object is incremented.
   167 	2. Allocates the object from the heap and then initialises its contents
   168 	   to binary zeroes.
   169 	3. Installs and takes ownership of an Open Font rasterizer
   170 	4. Releases a hold on one or all font file objects (COpenFontFiles or CFontStoreFiles)
   171 	   If aFileUid identifies a font file object, then the reference count for this 
   172        object is decremented. If this brings the reference count down to zero then 
   173        the font file object is removed from the font store, as well as the fonts 
   174        and typefaces associated with this file.
   175        If, on the other hand, aFileUid's value is NULL, then all font file objects 
   176 	   are removed, along with all fonts and typefaces in the font store.
   177 	5. Simulates heap allocation failure for the current thread's heap.
   178 	6. Tries to add a font file to the font store and checks for memory allocation errors.
   179 		
   180 	@SYMTestExpectedResults
   181 	Test should pass
   182 */
   183 void CTFntMem::TestAddFileL(const TDesC& aFileName)
   184 	{
   185 	INFO_PRINTF2(_L("AddFileL(\"%S\")"), &aFileName);
   186 	TInt failRate=1;
   187 	CFontStore *fs=CFontStore::NewL(iHeap);
   188 
   189 	// Install the dummy rasterizer - used for 'Open Font's
   190 	COpenFontRasterizer* r = CDummyRasterizer::NewL();
   191 	CleanupStack::PushL(r);
   192 	fs->InstallRasterizerL(r);
   193 	CleanupStack::Pop();
   194 
   195 	(void)fs->AddFileL(aFileName);
   196 	fs->RemoveFile(KNullUid);
   197 	TInt ret=KErrGeneral;
   198 
   199 	while (ret!=KErrNone)
   200 		{
   201 		__UHEAP_RESET;
   202 		__UHEAP_MARK;
   203 		__UHEAP_SETFAIL(RHeap::EDeterministic,failRate);
   204 		TRAP(ret, (void)fs->AddFileL(aFileName));
   205 		RDebug::Print(_L("NumTypefaces %d failrate %d, error %d\n"),fs->NumTypefaces(), failRate, ret);
   206 		if (ret==KErrNoMemory)
   207 			{
   208 			fs->RemoveFile(KNullUid);
   209 			__UHEAP_MARKEND;
   210 			__UHEAP_RESET;
   211 			TEST(fs->NumTypefaces()==0);
   212 			}
   213 		else if(ret==KErrNone)
   214 			{
   215 			fs->RemoveFile(KNullUid);
   216 			delete fs;
   217 			__UHEAP_MARKEND;
   218 			__UHEAP_RESET;
   219 			__UHEAP_SETFAIL(RHeap::ENone,failRate);
   220 			}
   221 		else
   222 			User::Panic(_L("Unknown error"),ret);
   223 		failRate++;
   224 		}
   225 	}
   226 		
   227 /**
   228 	@SYMTestCaseID
   229 	GRAPHICS-FNTSTORE-0026
   230 
   231 	@SYMTestCaseDesc
   232 	Tests the Out Of Memory handling for second reference to a bitmap font and open fonts.
   233 
   234 	@SYMTestActions
   235 	1. Finds or creates a font file object to support a font file.
   236 	   If an appropriate font file object exists then no new open font file is created. 
   237 	   In this case the reference count of the font file object is incremented.
   238 	2. Allocates the object from the heap and then initialises its contents.
   239 	   to binary zeroes.
   240 	3. Installs and takes ownership of an Open Font rasterizer.
   241 	4. Loads a font file.
   242 	5. Simulates heap allocation failure for the current thread's heap.
   243 	6. Tries to add a font file a second time to the font store and checks for memory allocation errors.
   244 	7. Removes all font file objects.
   245 	
   246 	@SYMTestExpectedResults
   247 	Test should pass
   248 */
   249 void CTFntMem::TestAddFileTwiceL(const TDesC& aFileName)
   250 	{
   251 	INFO_PRINTF2(_L("AddFileTwiceL(\"%S\")"), &aFileName);
   252 	TInt failRate=1;
   253 	CFontStore *fs=CFontStore::NewL(iHeap);
   254 
   255 	// Install the dummy rasterizer - used for 'Open Font's
   256 	COpenFontRasterizer* r = CDummyRasterizer::NewL();
   257 	CleanupStack::PushL(r);
   258 	fs->InstallRasterizerL(r);
   259 	CleanupStack::Pop();
   260 
   261 	// load the font file
   262 	(void)fs->AddFileL(aFileName);
   263 	TInt ret=KErrGeneral;
   264 
   265 	while (ret!=KErrNone)
   266 		{
   267 		__UHEAP_SETFAIL(RHeap::EDeterministic,failRate);
   268 		__UHEAP_MARK;
   269 		TRAP(ret, (void)fs->AddFileL(aFileName));
   270 		RDebug::Print(_L("NumTypefaces %d failrate %d, error %d\n"),fs->NumTypefaces(), failRate, ret);
   271 
   272 		// neither success or failure should use more memory
   273 		__UHEAP_MARKEND;
   274 		__UHEAP_RESET;
   275 
   276 		if ( (ret != KErrNoMemory) && (ret != KErrNone) )
   277 			{
   278 			User::Panic(_L("Unknown error"),ret);
   279 			}
   280 		failRate++;
   281 		}
   282 
   283 	fs->RemoveFile(KNullUid);
   284 	delete fs;
   285 	}
   286 	
   287 /**
   288 	@SYMTestCaseID
   289 	GRAPHICS-FNTSTORE-0027
   290 
   291 	@SYMTestCaseDesc
   292 	Tests the function GetNearestFontToDesignHeightInTwips in Out Of Memory 
   293 	error conditions.
   294 
   295 	@SYMTestActions
   296 	1. Creates a new CFontStore object.
   297 	2. Adds a font file to the font store.
   298 	3. Creates a bitmap font object.
   299 	4. Gets the nearest font to design height in twips of the DejaVu Sans Condensed font.
   300 	5. Releases a hold on one or all font file objects (COpenFontFiles or CFontStoreFiles)
   301 	   If aFileUid identifies a font file object, then the reference count for this 
   302        object is decremented. If this brings the reference count down to zero then 
   303        the font file object is removed from the font store, as well as the fonts 
   304        and typefaces associated with this file.
   305        If, on the other hand, aFileUid's value is NULL, then all font file objects 
   306 	   are removed, along with all fonts and typefaces in the font store.
   307 	6. Simulates heap allocation failure for the current thread's heap.
   308 	7. Tries to get the nearest font to design height in twips for the font and 
   309 	   checks for memory allocation errors.
   310 	8. Deallocates the CFontStore object.
   311 	
   312 	@SYMTestExpectedResults
   313 	Test should pass
   314 */
   315 void CTFntMem::TestGetNearestFontToDesignHeightInTwipsL()
   316 	{
   317 	INFO_PRINTF1(_L("GetNearestFontToDesignHeightInTwips"));
   318 	CFontStore *fs=CFontStore::NewL(iHeap);
   319 	(void)fs->AddFileL(KEonFontFileName);
   320 	TInt failRate=1;
   321 	CBitmapFont *font;
   322 	TFontSpec spec(_L("DejaVu Sans Condensed"),200);
   323 	TInt ret;
   324 	ret=fs->GetNearestFontToDesignHeightInTwips((CFont *&) font,spec);
   325 	TEST(ret==KErrNone);
   326 	if (ret!=KErrNone || font==NULL)
   327 		return;	//otherwise the memory faulting test loop will deadlock!
   328 	fs->ReleaseFont(font);
   329 	ret=KErrNoMemory;
   330 	while(ret!=KErrNone)
   331 		{
   332 		__UHEAP_RESET;
   333 		__UHEAP_SETFAIL(RHeap::EDeterministic,failRate);
   334 		__UHEAP_MARK;
   335 		__RHEAP_MARK(iHeap);
   336 		font=NULL;
   337 		ret=fs->GetNearestFontToDesignHeightInTwips((CFont *&) font,spec);
   338 		RDebug::Print(_L("Font %d failrate %d\n"),font,failRate);
   339 		if (ret==KErrNoMemory)
   340 			{
   341 			TEST(font==NULL);
   342 			__RHEAP_MARKEND(iHeap);
   343 			__UHEAP_MARKEND;
   344 			}
   345 		else if(ret==KErrNone)
   346 			{
   347 			fs->ReleaseFont(font);
   348 			font=NULL;
   349 			__RHEAP_MARKEND(iHeap);
   350 			__UHEAP_MARKEND;
   351 			__UHEAP_SETFAIL(RHeap::ENone,failRate);
   352 			}
   353 		else
   354 			User::Panic(_L("Unknown error"),ret);
   355 		failRate++;
   356 		}
   357 				 
   358 	delete fs;
   359 	}
   360 //----------------
   361 /**
   362 @SYMTestCaseID GRAPHICS-NearestOpenFontLeaksDEF095184-0001
   363 @SYMTestPriority Med
   364 @SYMREQ DEF095184
   365 
   366 @SYMTestCaseDesc
   367 Leak in font finder
   368 
   369 @SYMTestActions
   370 Tests for leak case loading both nearest open and bitmap font.
   371 The first call to GetNearestFontToDesignHeightInTwips loads the bitmap font.
   372 The looped calls change the memory fault frequency until this succeeds, 
   373 but the open font is returned instead, and then until the bitmap font is again returned.
   374 The test fontspec is specially chosen to cause these different results,
   375  and the test code is not working if the differing results are not fetched.
   376 
   377 @SYMTestExpectedResults
   378 failrate 1: KErrNoMemory
   379 failrate 2: Same font returned
   380 failrate 3: Different font returned
   381 failrate 4: Same font returned
   382 No leaks.
   383 Note that the exact results may change fail rates 
   384 if underlying changes are made to the font store.
   385 
   386 **/
   387 void CTFntMem::TestGetNearestOpenFontLeaksL()
   388 	{
   389 	INFO_PRINTF1(_L("TestGetNearestOpenFontLeaksL"));
   390 	CFontStore *fs=CFontStore::NewL(iHeap);
   391 	CleanupStack::PushL(fs);
   392 	// Install the dummy rasterizer - used for 'Open Font's
   393 	COpenFontRasterizer* r = CDummyRasterizer::NewL();
   394 	CleanupStack::PushL(r);
   395 	fs->InstallRasterizerL(r);
   396 	//Need one of each font flavour
   397 	(void)fs->AddFileL(KFontDummy);
   398 	(void)fs->AddFileL(KEonFontFileName);
   399 	CleanupStack::Pop(r);
   400 	CleanupStack::Pop(fs);
   401 	bool differentResultFetched=false;	
   402 	CBitmapFont *firstFont;
   403 
   404 	//Manufacture this font so that the bitmap font is favoured
   405 	//Note that the best I could do was get them equal, but that is enough to get bitmap chosen!
   406 	//Blank name is required to allow the dummy open font to be selected by similarity
   407 	TFontSpec reqSpec(_L(""),190);
   408 	reqSpec.iFontStyle.SetBitmapType(EMonochromeGlyphBitmap);
   409 	TFontSpec firstSpec;
   410 	TInt ret;	
   411 	//first run - tests that the code actually works before faulting the memory 
   412 	ret=fs->GetNearestFontToDesignHeightInTwips((CFont *&) firstFont,reqSpec);
   413 	TEST(ret==KErrNone);
   414 	TEST(firstFont!=NULL);
   415 	if (ret!=KErrNone || firstFont==NULL)
   416 		{
   417 		return;	//otherwise the memory faulting test loop will deadlock!
   418 		}
   419 	if (firstFont)
   420 		{
   421 		firstSpec=firstFont->FontSpecInTwips();
   422 		fs->ReleaseFont(firstFont);
   423 		}
   424 	ret=KErrNoMemory;
   425 	TInt failRate=1;
   426 	while(ret!=KErrNone || (failRate<30 && !differentResultFetched))
   427 		{
   428 		CBitmapFont *font=NULL;
   429 		__UHEAP_RESET;
   430 		__RHEAP_SETFAIL(iHeap,RHeap::EDeterministic,failRate);
   431 		__UHEAP_MARK;
   432 		__RHEAP_MARK(iHeap);
   433 		TFontSpec spec(reqSpec);
   434 		ret=fs->GetNearestFontToDesignHeightInTwips((CFont *&) font,reqSpec);
   435 		if (ret==KErrNoMemory)
   436 			{
   437 			RDebug::Print(_L("failrate %d: KErrNoMemory\n"),failRate);
   438 			TEST(font==NULL);
   439 			}
   440 		else if(ret==KErrNone)
   441 			{
   442 			TEST(font!=NULL);
   443 			if (font)
   444 				{
   445 				TFontSpec spec=font->FontSpecInTwips();
   446 				if (!(spec==firstSpec))
   447 					{
   448 					differentResultFetched=true;
   449 					ret=KErrNoMemory;			//actually there was a handled memory fault
   450 					RDebug::Print(_L("failrate %d: Different font returned\n"),failRate);
   451 					}
   452 				else
   453 					{
   454 					RDebug::Print(_L("failrate %d: Same font returned\n"),failRate);
   455 					}
   456 				}
   457 			else
   458 				{
   459 				RDebug::Print(_L("failrate %d: Error: NULL font returned\n"),failRate);
   460 				}
   461 			fs->ReleaseFont(font);
   462 			font=NULL;
   463 			}
   464 		else
   465 			{
   466 			User::Panic(_L("Unexpected error"),ret);
   467 			}
   468 		__RHEAP_CHECK(iHeap,0);
   469 		__RHEAP_MARKEND(iHeap);
   470 		__UHEAP_MARKEND;
   471 		__RHEAP_SETFAIL(iHeap,RHeap::ENone,failRate);
   472 		failRate++;
   473 		}
   474 	if (!differentResultFetched)
   475 		{
   476 		INFO_PRINTF1(_L("Test did not return different results under memory stress (unexpected)"));
   477 		}
   478 	delete fs;
   479 	}
   480 
   481 
   482 //The "bad" versions of these standard fonts have been hacked to give specific results
   483 _LIT(KFBSERVFontFileBitmap, 	"Z:\\resource\\fonts\\ceurope.GDR");
   484 //This file has the master GUID nobbled, but all the guid and typeface entries are duplicates.
   485 _LIT(KFBSERVFontFileBadBitmap1, 	"Z:\\PlatTest\\Graphics\\TestData\\uniquified_fonts\\XXeuro.GDR");
   486 //This file has the master GUID nobbled, one of the 8 fonts, and one of the typefaces has also been nobbled.
   487 _LIT(KFBSERVFontFileBadBitmap2, 	"Z:\\PlatTest\\Graphics\\TestData\\uniquified_fonts\\YYeuro.GDR");
   488 enum	{KNobbledFontEnum=0x10ff5912};		//official code for LatinBold17 is 0x10005912
   489 _LIT(NobbledTypefaceName, 	"XatinBold17");
   490 
   491 
   492  /**
   493    @SYMTestCaseID GRAPHICS-CTFbs-TestDuplicateFontFileEntries-0002
   494   
   495    @SYMDEF  DEF094692
   496   
   497    @SYMTestCaseDesc  If Bitmap fonts are loaded that are marginally unique compared to the 
   498    					 existing fonts then they are not actually added to the typeface system, and may even be discarded.
   499    
   500    @SYMTestPriority Med 
   501   
   502    @SYMTestStatus Implemented
   503    
   504    @SYMTestActions \n
   505    		The original versions of the Bitmapfonts are first loaded to ensure that they have actually been loaded.
   506    		A version of the bitmap font which is identical except for the file UID should be rejected
   507    		Verify that the unique data for the next test does not already exist
   508    		A version of the bitmap font which has just 1 unique bitmap will be loaded, but only 1 typeface entry will be added.
   509    		Verify that the unique data for the previous test now does exist
   510    	    The memory allocations through these steps should be deterministic
   511    			
   512    API Calls:	AddFile\n	
   513       
   514    @SYMTestExpectedResults The test expects:
   515    		The original versions should load without changing the number of typefaces
   516    		The second load should return the same UID for the font
   517    		The identical fonts should return captured fail codes, and not change the typeface counts
   518    		The semi-identical font should perform a single increase to UIDs and typefaces
   519   */
   520 void CTFntMem::TestDuplicateBitmapFontFileEntriesL()
   521 	{
   522 	
   523 	INFO_PRINTF1(_L("Test Load semi-duplicate bitmap font files"));
   524 	__RHEAP_MARK(iHeap);
   525 	__UHEAP_MARK;
   526 	CFontStore *fs=CFontStore::NewL(iHeap);
   527 	CleanupStack::PushL(fs);
   528 	
   529 	TInt numFacesBefore=fs->NumTypefaces();
   530 	TUid aIdBitMap1=TUid::Null();
   531 	TUint numAllocsBefore=iHeap->Count();
   532 	TUid aIdBitMap2=TUid::Null();
   533 	TUid aIdBitMap3=TUid::Null();
   534 	//make sure the originals of these fonts were safely opened
   535 	//both should simply cause a reference-count increase on the originator files.
   536 	TRAPD(err1,aIdBitMap1=fs->AddFileL(KFBSERVFontFileBitmap));
   537 	TEST(err1==KErrNone);
   538 	if (err1)
   539 		{
   540 		INFO_PRINTF1(_L("One of the expected fonts was missing. Test abandoned."));
   541 		}
   542 	else
   543 		{
   544 		TInt numFacesAfterLoadOriginals=fs->NumTypefaces();
   545 		TEST(numFacesBefore<numFacesAfterLoadOriginals);
   546 		TUint numAllocsAfterLoadOriginals=iHeap->Count();
   547 		
   548 		
   549 		//This bitmap font file contains no new fonts, so will ultimately be discarded
   550 		//The master UID has been nobbled so the file is not considered identical to its originator
   551 		TRAPD(err3,aIdBitMap2=fs->AddFileL(KFBSERVFontFileBadBitmap1));
   552 		TEST(err3==KErrAlreadyExists && aIdBitMap2==TUid::Null());
   553 		if (err3!=KErrAlreadyExists)
   554 				INFO_PRINTF2(_L("Unexpected error code was %d"),err3);	 
   555 		TInt numFacesAfterLoadBadFile3=fs->NumTypefaces();
   556 		TEST(numFacesAfterLoadOriginals==numFacesAfterLoadBadFile3);
   557 		TUint numAllocsAfterLoadBadFile3=iHeap->Count();
   558 		TEST(numAllocsAfterLoadBadFile3==numAllocsAfterLoadOriginals);
   559 		
   560 		//Before loading the next test check that the new data about to be added does not already exist
   561 		CFont *font=NULL;
   562 		TAlgStyle algStyle;
   563 		TFontSpec fontSpec(NobbledTypefaceName,10);
   564 		
   565 		TInt err5a1=fs->GetFontById(font,TUid::Uid(KNobbledFontEnum),algStyle);
   566 		TEST(font==NULL);	//the nobbled UID should not already exist
   567 
   568 		font=NULL;
   569 		
   570 		TInt err5a2=fs->GetNearestFontInPixels(font, fontSpec);
   571 		if (font)
   572 			{
   573 			TFontSpec specNoMatch=font->FontSpecInTwips();
   574 			TEST(specNoMatch.iTypeface.iName!=NobbledTypefaceName);	 //Nobbled font name should not be known yet
   575 			fs->ReleaseFont(font);
   576 			}
   577 		
   578 		//This bitmap font file contains one new typeface and font
   579 		//Actually, they are bit file edited versions of existing ones!
   580 		TInt numAllocsBeforeLoadBadFile5 = iHeap->Count();
   581 		TRAPD(err5,aIdBitMap3=fs->AddFileL(KFBSERVFontFileBadBitmap2));
   582 		TEST(err5==KErrNone); 
   583 		if (err5!=KErrNone)
   584 				INFO_PRINTF2(_L("Unexpected error code was %d"),err5);	 
   585 		
   586 		//The number of typefaces has now increased
   587 		TInt numFacesAfterLoadBadFile5=fs->NumTypefaces();
   588 		TEST(numFacesAfterLoadOriginals+1==numFacesAfterLoadBadFile5);
   589 		TUint numAllocsAfterLoadBadFile5=iHeap->Count();
   590 		TEST(numAllocsAfterLoadBadFile5==numAllocsBeforeLoadBadFile5+2);
   591 		
   592 
   593 		TInt err5b1=fs->GetFontById(font,TUid::Uid(KNobbledFontEnum),algStyle);
   594 		TEST(err5b1==KErrNone && font!=NULL);	//the nobbled UID should now exist
   595 		if (err5b1!=KErrNone)
   596 				INFO_PRINTF2(_L("Unexpected error code was %d"),err5b1);	 
   597 		
   598 		CFont *font2=NULL;
   599 		TInt err5b2=fs->GetNearestFontInPixels(font2, fontSpec);
   600 		TEST(err5b2==KErrNone && font2!=NULL);	
   601 		if (err5b2!=KErrNone)
   602 				INFO_PRINTF2(_L("Unexpected error code was %d"),err5b2);	 
   603 		if (font2!=NULL)
   604 			{
   605 			TFontSpec specMatches=font->FontSpecInTwips();
   606 			TEST(specMatches.iTypeface.iName==NobbledTypefaceName);	   //the nobbled typeface should now exist
   607 			}
   608 		TEST(font==font2);
   609 		if (font)
   610 			fs->ReleaseFont(font);
   611 		if (font2)
   612 			fs->ReleaseFont(font2);
   613 		}
   614 	
   615 	if (aIdBitMap1!=TUid::Null())	fs->RemoveFile(aIdBitMap1);
   616 	if (aIdBitMap2!=TUid::Null())	fs->RemoveFile(aIdBitMap2);
   617 	if (aIdBitMap3!=TUid::Null())	fs->RemoveFile(aIdBitMap3);
   618 	
   619 	//The added typeface should have been uninstalled
   620 	TInt numFacesAfterUninstall=fs->NumTypefaces();
   621 	TEST(numFacesAfterUninstall==numFacesBefore);
   622 	TUint numAllocsAfterUninstall=iHeap->Count();
   623 	
   624 	CleanupStack::PopAndDestroy(fs);
   625 	__UHEAP_CHECK(0);
   626 	__UHEAP_MARKEND;
   627 	__RHEAP_CHECK(iHeap,0);
   628 	__RHEAP_MARKEND(iHeap);
   629 	
   630 	}
   631 
   632 
   633 //--------------
   634 __CONSTRUCT_STEP__(FntMem)
   635 
   636