os/textandloc/fontservices/fontstore/tfs/T_FNTMEM.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/textandloc/fontservices/fontstore/tfs/T_FNTMEM.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,636 @@
     1.4 +/*
     1.5 +* Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include "T_FNTMEM.H"
    1.23 +#include "T_FSOPEN.H"
    1.24 +#include <graphics/openfontrasterizer.h>
    1.25 +
    1.26 +#ifdef __WINS__
    1.27 +	_LIT(KEonFontFileName,"z:\\resource\\fonts\\eon14.gdr");
    1.28 +#else
    1.29 +	_LIT(KEonFontFileName,"z:\\resource\\fonts\\eon.gdr");
    1.30 +#endif
    1.31 +
    1.32 +// 'dummy' open fonts, as used by T_FSOPEN
    1.33 +_LIT(KFontDummy,"z:\\PlatTest\\Graphics\\TestData\\dummy_fonts\\dummy");
    1.34 +//_LIT(KFontDummy_b,"z:\\PlatTest\\Graphics\\TestData\\dummy_fonts\\dummy_b");
    1.35 +//_LIT(KFontDummy_i,"z:\\PlatTest\\Graphics\\TestData\\dummy_fonts\\dummy_i");
    1.36 +//_LIT(KFontDummy_bi,"z:\\PlatTest\\Graphics\\TestData\\dummy_fonts\\dummy_bi");
    1.37 +
    1.38 +
    1.39 +
    1.40 +CTFntMem::CTFntMem(CTestStep* aStep):
    1.41 +	CTGraphicsBase(aStep),
    1.42 +	iHeap(NULL)
    1.43 +	{
    1.44 +	iHeap = UserHeap::ChunkHeap(NULL,0x80000,0x80000);
    1.45 +	INFO_PRINTF1(_L("FontStore"));
    1.46 +	}
    1.47 +
    1.48 +void CTFntMem::RunTestCaseL(TInt aCurTestCase)
    1.49 +	{
    1.50 +	((CTFntMemStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
    1.51 +	switch(aCurTestCase)
    1.52 +		{
    1.53 +	case 1:
    1.54 +		((CTFntMemStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0024"));
    1.55 +		TRAPD(err,TestNewL());
    1.56 +		TEST(err == KErrNone);
    1.57 +		break;
    1.58 +	case 2: // OOM handling for bitmap fonts
    1.59 +		((CTFntMemStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0025"));
    1.60 +		TRAP(err,TestAddFileL(KEonFontFileName));
    1.61 +		TEST(err == KErrNone);
    1.62 +		break;
    1.63 +	case 3: // OOM handling for open fonts
    1.64 +		((CTFntMemStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0025"));
    1.65 +		TRAP(err,TestAddFileL(KFontDummy));
    1.66 +		TEST(err == KErrNone);
    1.67 +		break;
    1.68 +	case 5: // OOM handling for second reference to a bitmap font
    1.69 +		((CTFntMemStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0026"));
    1.70 +		TRAP(err,TestAddFileTwiceL(KEonFontFileName));
    1.71 +		TEST(err == KErrNone);
    1.72 +		break;
    1.73 +	case 6: // OOM handling for second reference to an open font
    1.74 +		((CTFntMemStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0026"));
    1.75 +		TRAP(err,TestAddFileTwiceL(KFontDummy));
    1.76 +		TEST(err == KErrNone);
    1.77 +		break;
    1.78 +	case 7:
    1.79 +		((CTFntMemStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0027"));
    1.80 +		TRAP(err,TestGetNearestFontToDesignHeightInTwipsL());
    1.81 +		TEST(err == KErrNone);
    1.82 +		break;
    1.83 +	case 8:
    1.84 +		((CTFntMemStep*)iStep)->SetTestStepID(_L("GRAPHICS-NearestOpenFontLeaksDEF095184-0001"));
    1.85 +		TRAP(err,TestGetNearestOpenFontLeaksL());
    1.86 +		TEST(err == KErrNone);
    1.87 +		break;
    1.88 +	case 9:
    1.89 +		((CTFntMemStep*)iStep)->SetTestStepID(_L("GRAPHICS-CTFbs-TestDuplicateFontFileEntries-0002"));
    1.90 +		TRAP(err,TestDuplicateBitmapFontFileEntriesL());
    1.91 +		TEST(err == KErrNone);
    1.92 +		break;
    1.93 +	case 10:
    1.94 +		((CTFntMemStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
    1.95 +		((CTFntMemStep*)iStep)->CloseTMSGraphicsStep();
    1.96 +		TestComplete();				
    1.97 +		break;
    1.98 +	default:
    1.99 +		((CTFntMemStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
   1.100 +		break;
   1.101 +	}
   1.102 +	((CTFntMemStep*)iStep)->RecordTestResultL();
   1.103 +	}
   1.104 +
   1.105 +/**
   1.106 +	@SYMTestCaseID
   1.107 +	GRAPHICS-FNTSTORE-0024
   1.108 +
   1.109 +	@SYMTestCaseDesc
   1.110 +	Simulates out of memory errors of the heap when trying to allocate
   1.111 +	memory for a CFontStore object.
   1.112 +
   1.113 +	@SYMTestActions
   1.114 +	1. Cancels simulated heap allocation failure for the current thread's heap.
   1.115 +	2. Simulates heap allocation failure for the current thread's heap.
   1.116 +	3. Marks the start of checking the current thread's heap. 
   1.117 +	4. In a loop, tries to create a new CFontStore object with a pointer to 
   1.118 +	   the heap class used for memory allocation.
   1.119 +	5. Checking is done to see if the CFontStore was allocated or
   1.120 +	   if out of memory. The loop is broken when an object is created correctly.  	
   1.121 +	
   1.122 +	@SYMTestExpectedResults
   1.123 +	Test should pass
   1.124 +*/
   1.125 +void CTFntMem::TestNewL()
   1.126 +	{
   1.127 +	INFO_PRINTF1(_L("NewL"));
   1.128 +
   1.129 +	TInt ret=KErrGeneral;
   1.130 +	CFontStore *fs=NULL;
   1.131 +	TInt failRate=1;
   1.132 +
   1.133 +	while (ret!=KErrNone)
   1.134 +		{
   1.135 +		__UHEAP_RESET;
   1.136 +		__UHEAP_SETFAIL(RHeap::EDeterministic,failRate);
   1.137 +		__UHEAP_MARK;
   1.138 +		TRAP(ret,fs=CFontStore::NewL(iHeap));
   1.139 +		RDebug::Print(_L("fs %d failrate %d, error %d\n"),fs,failRate, ret);
   1.140 +		if (ret==KErrNoMemory)
   1.141 +			{
   1.142 +			__UHEAP_MARKEND;
   1.143 +			__UHEAP_RESET;
   1.144 +			TEST(fs==NULL);
   1.145 +			}
   1.146 +		else if(ret==KErrNone)
   1.147 +			{
   1.148 +			delete fs;
   1.149 +			__UHEAP_MARKEND;
   1.150 +			__UHEAP_RESET;
   1.151 +			__UHEAP_SETFAIL(RHeap::ENone,failRate);
   1.152 +			}
   1.153 +		else
   1.154 +			User::Panic(_L("Unknown error"),ret);
   1.155 +		failRate++;
   1.156 +		}
   1.157 +	}
   1.158 +
   1.159 +/**
   1.160 +	@SYMTestCaseID
   1.161 +	GRAPHICS-FNTSTORE-0025
   1.162 +
   1.163 +	@SYMTestCaseDesc
   1.164 +	Tests the Out Of Memory handling for bitmap- and open fonts.
   1.165 +
   1.166 +	@SYMTestActions
   1.167 +	1. Finds or creates a font file object to support a font file.
   1.168 +	   If an appropriate font file object exists then no new open font file is created. 
   1.169 +	   In this case the reference count of the font file object is incremented.
   1.170 +	2. Allocates the object from the heap and then initialises its contents
   1.171 +	   to binary zeroes.
   1.172 +	3. Installs and takes ownership of an Open Font rasterizer
   1.173 +	4. Releases a hold on one or all font file objects (COpenFontFiles or CFontStoreFiles)
   1.174 +	   If aFileUid identifies a font file object, then the reference count for this 
   1.175 +       object is decremented. If this brings the reference count down to zero then 
   1.176 +       the font file object is removed from the font store, as well as the fonts 
   1.177 +       and typefaces associated with this file.
   1.178 +       If, on the other hand, aFileUid's value is NULL, then all font file objects 
   1.179 +	   are removed, along with all fonts and typefaces in the font store.
   1.180 +	5. Simulates heap allocation failure for the current thread's heap.
   1.181 +	6. Tries to add a font file to the font store and checks for memory allocation errors.
   1.182 +		
   1.183 +	@SYMTestExpectedResults
   1.184 +	Test should pass
   1.185 +*/
   1.186 +void CTFntMem::TestAddFileL(const TDesC& aFileName)
   1.187 +	{
   1.188 +	INFO_PRINTF2(_L("AddFileL(\"%S\")"), &aFileName);
   1.189 +	TInt failRate=1;
   1.190 +	CFontStore *fs=CFontStore::NewL(iHeap);
   1.191 +
   1.192 +	// Install the dummy rasterizer - used for 'Open Font's
   1.193 +	COpenFontRasterizer* r = CDummyRasterizer::NewL();
   1.194 +	CleanupStack::PushL(r);
   1.195 +	fs->InstallRasterizerL(r);
   1.196 +	CleanupStack::Pop();
   1.197 +
   1.198 +	(void)fs->AddFileL(aFileName);
   1.199 +	fs->RemoveFile(KNullUid);
   1.200 +	TInt ret=KErrGeneral;
   1.201 +
   1.202 +	while (ret!=KErrNone)
   1.203 +		{
   1.204 +		__UHEAP_RESET;
   1.205 +		__UHEAP_MARK;
   1.206 +		__UHEAP_SETFAIL(RHeap::EDeterministic,failRate);
   1.207 +		TRAP(ret, (void)fs->AddFileL(aFileName));
   1.208 +		RDebug::Print(_L("NumTypefaces %d failrate %d, error %d\n"),fs->NumTypefaces(), failRate, ret);
   1.209 +		if (ret==KErrNoMemory)
   1.210 +			{
   1.211 +			fs->RemoveFile(KNullUid);
   1.212 +			__UHEAP_MARKEND;
   1.213 +			__UHEAP_RESET;
   1.214 +			TEST(fs->NumTypefaces()==0);
   1.215 +			}
   1.216 +		else if(ret==KErrNone)
   1.217 +			{
   1.218 +			fs->RemoveFile(KNullUid);
   1.219 +			delete fs;
   1.220 +			__UHEAP_MARKEND;
   1.221 +			__UHEAP_RESET;
   1.222 +			__UHEAP_SETFAIL(RHeap::ENone,failRate);
   1.223 +			}
   1.224 +		else
   1.225 +			User::Panic(_L("Unknown error"),ret);
   1.226 +		failRate++;
   1.227 +		}
   1.228 +	}
   1.229 +		
   1.230 +/**
   1.231 +	@SYMTestCaseID
   1.232 +	GRAPHICS-FNTSTORE-0026
   1.233 +
   1.234 +	@SYMTestCaseDesc
   1.235 +	Tests the Out Of Memory handling for second reference to a bitmap font and open fonts.
   1.236 +
   1.237 +	@SYMTestActions
   1.238 +	1. Finds or creates a font file object to support a font file.
   1.239 +	   If an appropriate font file object exists then no new open font file is created. 
   1.240 +	   In this case the reference count of the font file object is incremented.
   1.241 +	2. Allocates the object from the heap and then initialises its contents.
   1.242 +	   to binary zeroes.
   1.243 +	3. Installs and takes ownership of an Open Font rasterizer.
   1.244 +	4. Loads a font file.
   1.245 +	5. Simulates heap allocation failure for the current thread's heap.
   1.246 +	6. Tries to add a font file a second time to the font store and checks for memory allocation errors.
   1.247 +	7. Removes all font file objects.
   1.248 +	
   1.249 +	@SYMTestExpectedResults
   1.250 +	Test should pass
   1.251 +*/
   1.252 +void CTFntMem::TestAddFileTwiceL(const TDesC& aFileName)
   1.253 +	{
   1.254 +	INFO_PRINTF2(_L("AddFileTwiceL(\"%S\")"), &aFileName);
   1.255 +	TInt failRate=1;
   1.256 +	CFontStore *fs=CFontStore::NewL(iHeap);
   1.257 +
   1.258 +	// Install the dummy rasterizer - used for 'Open Font's
   1.259 +	COpenFontRasterizer* r = CDummyRasterizer::NewL();
   1.260 +	CleanupStack::PushL(r);
   1.261 +	fs->InstallRasterizerL(r);
   1.262 +	CleanupStack::Pop();
   1.263 +
   1.264 +	// load the font file
   1.265 +	(void)fs->AddFileL(aFileName);
   1.266 +	TInt ret=KErrGeneral;
   1.267 +
   1.268 +	while (ret!=KErrNone)
   1.269 +		{
   1.270 +		__UHEAP_SETFAIL(RHeap::EDeterministic,failRate);
   1.271 +		__UHEAP_MARK;
   1.272 +		TRAP(ret, (void)fs->AddFileL(aFileName));
   1.273 +		RDebug::Print(_L("NumTypefaces %d failrate %d, error %d\n"),fs->NumTypefaces(), failRate, ret);
   1.274 +
   1.275 +		// neither success or failure should use more memory
   1.276 +		__UHEAP_MARKEND;
   1.277 +		__UHEAP_RESET;
   1.278 +
   1.279 +		if ( (ret != KErrNoMemory) && (ret != KErrNone) )
   1.280 +			{
   1.281 +			User::Panic(_L("Unknown error"),ret);
   1.282 +			}
   1.283 +		failRate++;
   1.284 +		}
   1.285 +
   1.286 +	fs->RemoveFile(KNullUid);
   1.287 +	delete fs;
   1.288 +	}
   1.289 +	
   1.290 +/**
   1.291 +	@SYMTestCaseID
   1.292 +	GRAPHICS-FNTSTORE-0027
   1.293 +
   1.294 +	@SYMTestCaseDesc
   1.295 +	Tests the function GetNearestFontToDesignHeightInTwips in Out Of Memory 
   1.296 +	error conditions.
   1.297 +
   1.298 +	@SYMTestActions
   1.299 +	1. Creates a new CFontStore object.
   1.300 +	2. Adds a font file to the font store.
   1.301 +	3. Creates a bitmap font object.
   1.302 +	4. Gets the nearest font to design height in twips of the DejaVu Sans Condensed font.
   1.303 +	5. Releases a hold on one or all font file objects (COpenFontFiles or CFontStoreFiles)
   1.304 +	   If aFileUid identifies a font file object, then the reference count for this 
   1.305 +       object is decremented. If this brings the reference count down to zero then 
   1.306 +       the font file object is removed from the font store, as well as the fonts 
   1.307 +       and typefaces associated with this file.
   1.308 +       If, on the other hand, aFileUid's value is NULL, then all font file objects 
   1.309 +	   are removed, along with all fonts and typefaces in the font store.
   1.310 +	6. Simulates heap allocation failure for the current thread's heap.
   1.311 +	7. Tries to get the nearest font to design height in twips for the font and 
   1.312 +	   checks for memory allocation errors.
   1.313 +	8. Deallocates the CFontStore object.
   1.314 +	
   1.315 +	@SYMTestExpectedResults
   1.316 +	Test should pass
   1.317 +*/
   1.318 +void CTFntMem::TestGetNearestFontToDesignHeightInTwipsL()
   1.319 +	{
   1.320 +	INFO_PRINTF1(_L("GetNearestFontToDesignHeightInTwips"));
   1.321 +	CFontStore *fs=CFontStore::NewL(iHeap);
   1.322 +	(void)fs->AddFileL(KEonFontFileName);
   1.323 +	TInt failRate=1;
   1.324 +	CBitmapFont *font;
   1.325 +	TFontSpec spec(_L("DejaVu Sans Condensed"),200);
   1.326 +	TInt ret;
   1.327 +	ret=fs->GetNearestFontToDesignHeightInTwips((CFont *&) font,spec);
   1.328 +	TEST(ret==KErrNone);
   1.329 +	if (ret!=KErrNone || font==NULL)
   1.330 +		return;	//otherwise the memory faulting test loop will deadlock!
   1.331 +	fs->ReleaseFont(font);
   1.332 +	ret=KErrNoMemory;
   1.333 +	while(ret!=KErrNone)
   1.334 +		{
   1.335 +		__UHEAP_RESET;
   1.336 +		__UHEAP_SETFAIL(RHeap::EDeterministic,failRate);
   1.337 +		__UHEAP_MARK;
   1.338 +		__RHEAP_MARK(iHeap);
   1.339 +		font=NULL;
   1.340 +		ret=fs->GetNearestFontToDesignHeightInTwips((CFont *&) font,spec);
   1.341 +		RDebug::Print(_L("Font %d failrate %d\n"),font,failRate);
   1.342 +		if (ret==KErrNoMemory)
   1.343 +			{
   1.344 +			TEST(font==NULL);
   1.345 +			__RHEAP_MARKEND(iHeap);
   1.346 +			__UHEAP_MARKEND;
   1.347 +			}
   1.348 +		else if(ret==KErrNone)
   1.349 +			{
   1.350 +			fs->ReleaseFont(font);
   1.351 +			font=NULL;
   1.352 +			__RHEAP_MARKEND(iHeap);
   1.353 +			__UHEAP_MARKEND;
   1.354 +			__UHEAP_SETFAIL(RHeap::ENone,failRate);
   1.355 +			}
   1.356 +		else
   1.357 +			User::Panic(_L("Unknown error"),ret);
   1.358 +		failRate++;
   1.359 +		}
   1.360 +				 
   1.361 +	delete fs;
   1.362 +	}
   1.363 +//----------------
   1.364 +/**
   1.365 +@SYMTestCaseID GRAPHICS-NearestOpenFontLeaksDEF095184-0001
   1.366 +@SYMTestPriority Med
   1.367 +@SYMREQ DEF095184
   1.368 +
   1.369 +@SYMTestCaseDesc
   1.370 +Leak in font finder
   1.371 +
   1.372 +@SYMTestActions
   1.373 +Tests for leak case loading both nearest open and bitmap font.
   1.374 +The first call to GetNearestFontToDesignHeightInTwips loads the bitmap font.
   1.375 +The looped calls change the memory fault frequency until this succeeds, 
   1.376 +but the open font is returned instead, and then until the bitmap font is again returned.
   1.377 +The test fontspec is specially chosen to cause these different results,
   1.378 + and the test code is not working if the differing results are not fetched.
   1.379 +
   1.380 +@SYMTestExpectedResults
   1.381 +failrate 1: KErrNoMemory
   1.382 +failrate 2: Same font returned
   1.383 +failrate 3: Different font returned
   1.384 +failrate 4: Same font returned
   1.385 +No leaks.
   1.386 +Note that the exact results may change fail rates 
   1.387 +if underlying changes are made to the font store.
   1.388 +
   1.389 +**/
   1.390 +void CTFntMem::TestGetNearestOpenFontLeaksL()
   1.391 +	{
   1.392 +	INFO_PRINTF1(_L("TestGetNearestOpenFontLeaksL"));
   1.393 +	CFontStore *fs=CFontStore::NewL(iHeap);
   1.394 +	CleanupStack::PushL(fs);
   1.395 +	// Install the dummy rasterizer - used for 'Open Font's
   1.396 +	COpenFontRasterizer* r = CDummyRasterizer::NewL();
   1.397 +	CleanupStack::PushL(r);
   1.398 +	fs->InstallRasterizerL(r);
   1.399 +	//Need one of each font flavour
   1.400 +	(void)fs->AddFileL(KFontDummy);
   1.401 +	(void)fs->AddFileL(KEonFontFileName);
   1.402 +	CleanupStack::Pop(r);
   1.403 +	CleanupStack::Pop(fs);
   1.404 +	bool differentResultFetched=false;	
   1.405 +	CBitmapFont *firstFont;
   1.406 +
   1.407 +	//Manufacture this font so that the bitmap font is favoured
   1.408 +	//Note that the best I could do was get them equal, but that is enough to get bitmap chosen!
   1.409 +	//Blank name is required to allow the dummy open font to be selected by similarity
   1.410 +	TFontSpec reqSpec(_L(""),190);
   1.411 +	reqSpec.iFontStyle.SetBitmapType(EMonochromeGlyphBitmap);
   1.412 +	TFontSpec firstSpec;
   1.413 +	TInt ret;	
   1.414 +	//first run - tests that the code actually works before faulting the memory 
   1.415 +	ret=fs->GetNearestFontToDesignHeightInTwips((CFont *&) firstFont,reqSpec);
   1.416 +	TEST(ret==KErrNone);
   1.417 +	TEST(firstFont!=NULL);
   1.418 +	if (ret!=KErrNone || firstFont==NULL)
   1.419 +		{
   1.420 +		return;	//otherwise the memory faulting test loop will deadlock!
   1.421 +		}
   1.422 +	if (firstFont)
   1.423 +		{
   1.424 +		firstSpec=firstFont->FontSpecInTwips();
   1.425 +		fs->ReleaseFont(firstFont);
   1.426 +		}
   1.427 +	ret=KErrNoMemory;
   1.428 +	TInt failRate=1;
   1.429 +	while(ret!=KErrNone || (failRate<30 && !differentResultFetched))
   1.430 +		{
   1.431 +		CBitmapFont *font=NULL;
   1.432 +		__UHEAP_RESET;
   1.433 +		__RHEAP_SETFAIL(iHeap,RHeap::EDeterministic,failRate);
   1.434 +		__UHEAP_MARK;
   1.435 +		__RHEAP_MARK(iHeap);
   1.436 +		TFontSpec spec(reqSpec);
   1.437 +		ret=fs->GetNearestFontToDesignHeightInTwips((CFont *&) font,reqSpec);
   1.438 +		if (ret==KErrNoMemory)
   1.439 +			{
   1.440 +			RDebug::Print(_L("failrate %d: KErrNoMemory\n"),failRate);
   1.441 +			TEST(font==NULL);
   1.442 +			}
   1.443 +		else if(ret==KErrNone)
   1.444 +			{
   1.445 +			TEST(font!=NULL);
   1.446 +			if (font)
   1.447 +				{
   1.448 +				TFontSpec spec=font->FontSpecInTwips();
   1.449 +				if (!(spec==firstSpec))
   1.450 +					{
   1.451 +					differentResultFetched=true;
   1.452 +					ret=KErrNoMemory;			//actually there was a handled memory fault
   1.453 +					RDebug::Print(_L("failrate %d: Different font returned\n"),failRate);
   1.454 +					}
   1.455 +				else
   1.456 +					{
   1.457 +					RDebug::Print(_L("failrate %d: Same font returned\n"),failRate);
   1.458 +					}
   1.459 +				}
   1.460 +			else
   1.461 +				{
   1.462 +				RDebug::Print(_L("failrate %d: Error: NULL font returned\n"),failRate);
   1.463 +				}
   1.464 +			fs->ReleaseFont(font);
   1.465 +			font=NULL;
   1.466 +			}
   1.467 +		else
   1.468 +			{
   1.469 +			User::Panic(_L("Unexpected error"),ret);
   1.470 +			}
   1.471 +		__RHEAP_CHECK(iHeap,0);
   1.472 +		__RHEAP_MARKEND(iHeap);
   1.473 +		__UHEAP_MARKEND;
   1.474 +		__RHEAP_SETFAIL(iHeap,RHeap::ENone,failRate);
   1.475 +		failRate++;
   1.476 +		}
   1.477 +	if (!differentResultFetched)
   1.478 +		{
   1.479 +		INFO_PRINTF1(_L("Test did not return different results under memory stress (unexpected)"));
   1.480 +		}
   1.481 +	delete fs;
   1.482 +	}
   1.483 +
   1.484 +
   1.485 +//The "bad" versions of these standard fonts have been hacked to give specific results
   1.486 +_LIT(KFBSERVFontFileBitmap, 	"Z:\\resource\\fonts\\ceurope.GDR");
   1.487 +//This file has the master GUID nobbled, but all the guid and typeface entries are duplicates.
   1.488 +_LIT(KFBSERVFontFileBadBitmap1, 	"Z:\\PlatTest\\Graphics\\TestData\\uniquified_fonts\\XXeuro.GDR");
   1.489 +//This file has the master GUID nobbled, one of the 8 fonts, and one of the typefaces has also been nobbled.
   1.490 +_LIT(KFBSERVFontFileBadBitmap2, 	"Z:\\PlatTest\\Graphics\\TestData\\uniquified_fonts\\YYeuro.GDR");
   1.491 +enum	{KNobbledFontEnum=0x10ff5912};		//official code for LatinBold17 is 0x10005912
   1.492 +_LIT(NobbledTypefaceName, 	"XatinBold17");
   1.493 +
   1.494 +
   1.495 + /**
   1.496 +   @SYMTestCaseID GRAPHICS-CTFbs-TestDuplicateFontFileEntries-0002
   1.497 +  
   1.498 +   @SYMDEF  DEF094692
   1.499 +  
   1.500 +   @SYMTestCaseDesc  If Bitmap fonts are loaded that are marginally unique compared to the 
   1.501 +   					 existing fonts then they are not actually added to the typeface system, and may even be discarded.
   1.502 +   
   1.503 +   @SYMTestPriority Med 
   1.504 +  
   1.505 +   @SYMTestStatus Implemented
   1.506 +   
   1.507 +   @SYMTestActions \n
   1.508 +   		The original versions of the Bitmapfonts are first loaded to ensure that they have actually been loaded.
   1.509 +   		A version of the bitmap font which is identical except for the file UID should be rejected
   1.510 +   		Verify that the unique data for the next test does not already exist
   1.511 +   		A version of the bitmap font which has just 1 unique bitmap will be loaded, but only 1 typeface entry will be added.
   1.512 +   		Verify that the unique data for the previous test now does exist
   1.513 +   	    The memory allocations through these steps should be deterministic
   1.514 +   			
   1.515 +   API Calls:	AddFile\n	
   1.516 +      
   1.517 +   @SYMTestExpectedResults The test expects:
   1.518 +   		The original versions should load without changing the number of typefaces
   1.519 +   		The second load should return the same UID for the font
   1.520 +   		The identical fonts should return captured fail codes, and not change the typeface counts
   1.521 +   		The semi-identical font should perform a single increase to UIDs and typefaces
   1.522 +  */
   1.523 +void CTFntMem::TestDuplicateBitmapFontFileEntriesL()
   1.524 +	{
   1.525 +	
   1.526 +	INFO_PRINTF1(_L("Test Load semi-duplicate bitmap font files"));
   1.527 +	__RHEAP_MARK(iHeap);
   1.528 +	__UHEAP_MARK;
   1.529 +	CFontStore *fs=CFontStore::NewL(iHeap);
   1.530 +	CleanupStack::PushL(fs);
   1.531 +	
   1.532 +	TInt numFacesBefore=fs->NumTypefaces();
   1.533 +	TUid aIdBitMap1=TUid::Null();
   1.534 +	TUint numAllocsBefore=iHeap->Count();
   1.535 +	TUid aIdBitMap2=TUid::Null();
   1.536 +	TUid aIdBitMap3=TUid::Null();
   1.537 +	//make sure the originals of these fonts were safely opened
   1.538 +	//both should simply cause a reference-count increase on the originator files.
   1.539 +	TRAPD(err1,aIdBitMap1=fs->AddFileL(KFBSERVFontFileBitmap));
   1.540 +	TEST(err1==KErrNone);
   1.541 +	if (err1)
   1.542 +		{
   1.543 +		INFO_PRINTF1(_L("One of the expected fonts was missing. Test abandoned."));
   1.544 +		}
   1.545 +	else
   1.546 +		{
   1.547 +		TInt numFacesAfterLoadOriginals=fs->NumTypefaces();
   1.548 +		TEST(numFacesBefore<numFacesAfterLoadOriginals);
   1.549 +		TUint numAllocsAfterLoadOriginals=iHeap->Count();
   1.550 +		
   1.551 +		
   1.552 +		//This bitmap font file contains no new fonts, so will ultimately be discarded
   1.553 +		//The master UID has been nobbled so the file is not considered identical to its originator
   1.554 +		TRAPD(err3,aIdBitMap2=fs->AddFileL(KFBSERVFontFileBadBitmap1));
   1.555 +		TEST(err3==KErrAlreadyExists && aIdBitMap2==TUid::Null());
   1.556 +		if (err3!=KErrAlreadyExists)
   1.557 +				INFO_PRINTF2(_L("Unexpected error code was %d"),err3);	 
   1.558 +		TInt numFacesAfterLoadBadFile3=fs->NumTypefaces();
   1.559 +		TEST(numFacesAfterLoadOriginals==numFacesAfterLoadBadFile3);
   1.560 +		TUint numAllocsAfterLoadBadFile3=iHeap->Count();
   1.561 +		TEST(numAllocsAfterLoadBadFile3==numAllocsAfterLoadOriginals);
   1.562 +		
   1.563 +		//Before loading the next test check that the new data about to be added does not already exist
   1.564 +		CFont *font=NULL;
   1.565 +		TAlgStyle algStyle;
   1.566 +		TFontSpec fontSpec(NobbledTypefaceName,10);
   1.567 +		
   1.568 +		TInt err5a1=fs->GetFontById(font,TUid::Uid(KNobbledFontEnum),algStyle);
   1.569 +		TEST(font==NULL);	//the nobbled UID should not already exist
   1.570 +
   1.571 +		font=NULL;
   1.572 +		
   1.573 +		TInt err5a2=fs->GetNearestFontInPixels(font, fontSpec);
   1.574 +		if (font)
   1.575 +			{
   1.576 +			TFontSpec specNoMatch=font->FontSpecInTwips();
   1.577 +			TEST(specNoMatch.iTypeface.iName!=NobbledTypefaceName);	 //Nobbled font name should not be known yet
   1.578 +			fs->ReleaseFont(font);
   1.579 +			}
   1.580 +		
   1.581 +		//This bitmap font file contains one new typeface and font
   1.582 +		//Actually, they are bit file edited versions of existing ones!
   1.583 +		TInt numAllocsBeforeLoadBadFile5 = iHeap->Count();
   1.584 +		TRAPD(err5,aIdBitMap3=fs->AddFileL(KFBSERVFontFileBadBitmap2));
   1.585 +		TEST(err5==KErrNone); 
   1.586 +		if (err5!=KErrNone)
   1.587 +				INFO_PRINTF2(_L("Unexpected error code was %d"),err5);	 
   1.588 +		
   1.589 +		//The number of typefaces has now increased
   1.590 +		TInt numFacesAfterLoadBadFile5=fs->NumTypefaces();
   1.591 +		TEST(numFacesAfterLoadOriginals+1==numFacesAfterLoadBadFile5);
   1.592 +		TUint numAllocsAfterLoadBadFile5=iHeap->Count();
   1.593 +		TEST(numAllocsAfterLoadBadFile5==numAllocsBeforeLoadBadFile5+2);
   1.594 +		
   1.595 +
   1.596 +		TInt err5b1=fs->GetFontById(font,TUid::Uid(KNobbledFontEnum),algStyle);
   1.597 +		TEST(err5b1==KErrNone && font!=NULL);	//the nobbled UID should now exist
   1.598 +		if (err5b1!=KErrNone)
   1.599 +				INFO_PRINTF2(_L("Unexpected error code was %d"),err5b1);	 
   1.600 +		
   1.601 +		CFont *font2=NULL;
   1.602 +		TInt err5b2=fs->GetNearestFontInPixels(font2, fontSpec);
   1.603 +		TEST(err5b2==KErrNone && font2!=NULL);	
   1.604 +		if (err5b2!=KErrNone)
   1.605 +				INFO_PRINTF2(_L("Unexpected error code was %d"),err5b2);	 
   1.606 +		if (font2!=NULL)
   1.607 +			{
   1.608 +			TFontSpec specMatches=font->FontSpecInTwips();
   1.609 +			TEST(specMatches.iTypeface.iName==NobbledTypefaceName);	   //the nobbled typeface should now exist
   1.610 +			}
   1.611 +		TEST(font==font2);
   1.612 +		if (font)
   1.613 +			fs->ReleaseFont(font);
   1.614 +		if (font2)
   1.615 +			fs->ReleaseFont(font2);
   1.616 +		}
   1.617 +	
   1.618 +	if (aIdBitMap1!=TUid::Null())	fs->RemoveFile(aIdBitMap1);
   1.619 +	if (aIdBitMap2!=TUid::Null())	fs->RemoveFile(aIdBitMap2);
   1.620 +	if (aIdBitMap3!=TUid::Null())	fs->RemoveFile(aIdBitMap3);
   1.621 +	
   1.622 +	//The added typeface should have been uninstalled
   1.623 +	TInt numFacesAfterUninstall=fs->NumTypefaces();
   1.624 +	TEST(numFacesAfterUninstall==numFacesBefore);
   1.625 +	TUint numAllocsAfterUninstall=iHeap->Count();
   1.626 +	
   1.627 +	CleanupStack::PopAndDestroy(fs);
   1.628 +	__UHEAP_CHECK(0);
   1.629 +	__UHEAP_MARKEND;
   1.630 +	__RHEAP_CHECK(iHeap,0);
   1.631 +	__RHEAP_MARKEND(iHeap);
   1.632 +	
   1.633 +	}
   1.634 +
   1.635 +
   1.636 +//--------------
   1.637 +__CONSTRUCT_STEP__(FntMem)
   1.638 +
   1.639 +