fontservices/fontstore/tfs/T_GlyphTreeDel.cpp
changeset 0 1fb32624e06b
equal deleted inserted replaced
-1:000000000000 0:1fb32624e06b
       
     1 /*
       
     2 * Copyright (c) 2003-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 <bitdev.h>
       
    20 #include <fntstore.h>
       
    21 #include <fbs.h>
       
    22 #include <graphics/fbsdefs.h>
       
    23 #include "T_GlyphTreeDel.h"
       
    24 
       
    25 const TDisplayMode testDisplayModes[] =	
       
    26 	{
       
    27 	EGray2,
       
    28 	EGray4,
       
    29 	EGray16,
       
    30 	EGray256,
       
    31 	EColor16,
       
    32 	EColor256,
       
    33 	EColor64K,
       
    34 	EColor16M,
       
    35 	EColor4K,
       
    36 	EColor16MU,
       
    37 	EColor16MA,
       
    38 	EColor16MAP,
       
    39 	};
       
    40 
       
    41 // This test is based on code from the TTAGMA test in form
       
    42 
       
    43 
       
    44 CTGlyphTreeDel::CTGlyphTreeDel(CTestStep* aStep):
       
    45 	iStep(aStep)
       
    46 	{
       
    47 	}
       
    48 
       
    49 CTGlyphTreeDel::~CTGlyphTreeDel()
       
    50 	{
       
    51 	delete iGc;
       
    52 	delete iDev;
       
    53 	RFbsSession::Disconnect();
       
    54 	}
       
    55 
       
    56 CTGlyphTreeDel* CTGlyphTreeDel::NewL(CTestStep* aStep)
       
    57 	{
       
    58 	CTGlyphTreeDel *theTest = new (ELeave) CTGlyphTreeDel(aStep);
       
    59 	
       
    60 	CleanupStack::PushL(theTest);
       
    61 	theTest->ConstructL();
       
    62 	CleanupStack::Pop();
       
    63 	return theTest;
       
    64 	}
       
    65 	
       
    66 void CTGlyphTreeDel::ConstructL()
       
    67 	{
       
    68 	iStep -> INFO_PRINTF1(_L("DEF047283"));
       
    69 	RFbsSession::Connect();
       
    70 	iFbs = RFbsSession::GetSession();
       
    71 	if (iFbs == NULL)
       
    72 		User::Leave(KErrGeneral);
       
    73 	User::LeaveIfError(CreateScreenDevice());
       
    74 	iDev->ChangeScreenDevice(NULL);
       
    75 	iDev->SetAutoUpdate(ETrue);
       
    76 	iDev->CreateContext(iGc);
       
    77 	}
       
    78 
       
    79 TInt CTGlyphTreeDel::CreateScreenDevice()
       
    80 	{
       
    81 	TInt err = KErrNone;
       
    82 	TInt sizeOfDisplayMode = sizeof (testDisplayModes) / sizeof(testDisplayModes[0]);
       
    83 	 
       
    84 	for(TInt theScreenModeIndex = sizeOfDisplayMode - 1; theScreenModeIndex ; theScreenModeIndex--)
       
    85 		{
       
    86 		TDisplayMode disp = testDisplayModes[theScreenModeIndex];
       
    87 		TRAP(err, iDev = CFbsScreenDevice::NewL(_L(""), disp)); //scdv
       
    88 		if(err == KErrNone)
       
    89 			{
       
    90 			iStep->INFO_PRINTF2(_L("Device %d has been created"), disp);
       
    91 			return KErrNone;
       
    92 			}
       
    93 		}
       
    94 	return err;	
       
    95 	}
       
    96 
       
    97 // Get System free Ram
       
    98 
       
    99 TInt CTGlyphTreeDel::GetRam()
       
   100 	{
       
   101 	TMemoryInfoV1Buf memory;
       
   102 	UserHal::MemoryInfo(memory);
       
   103 	return(TInt)(memory().iFreeRamInBytes);	
       
   104 	}
       
   105 	
       
   106 void CTGlyphTreeDel::CheckRam( TInt beforeFreeRam)
       
   107 	{
       
   108 	TInt freeRam=GetRam();
       
   109 	if( beforeFreeRam < freeRam)
       
   110 		{
       
   111 		iStep -> INFO_PRINTF2( _L("Freed  %08d bytes of RAM\n"), freeRam-beforeFreeRam);
       
   112 		}
       
   113 	else if( beforeFreeRam > freeRam)
       
   114 		{
       
   115 		iStep -> INFO_PRINTF2( _L("Leaked %08d bytes of RAM\n"), beforeFreeRam-freeRam);
       
   116 		}
       
   117 	}
       
   118 
       
   119 /**
       
   120 	@SYMTestCaseID
       
   121 	GRAPHICS-FNTSTORE-0034
       
   122 
       
   123 	@SYMTestCaseDesc
       
   124 	Tests glyph cache. 
       
   125 		
       
   126 	@SYMTestActions
       
   127 	1. Sets pen style to null pen.
       
   128 	2. Sets brush color to gray.
       
   129 	3. Sets brush style to solid.
       
   130 	4. Retrieves number of typefaces.
       
   131 	5. Retrieves the details of the typeface family.
       
   132 	6. Gets the font which is the nearest to the given font specification.
       
   133 	7. Sets the retrieved font to be used into the graphic context.
       
   134 	8. Draws a string to the display.
       
   135 	9. Releases the font.
       
   136 	10. Discards the font.
       
   137 	11. Glyph cache is filled by looping. The glyph cache heap should be large enough
       
   138 		for all subsequent loops, if the glyph tree is successfully deleted after the font is
       
   139 		discarded. 
       
   140 	12. Waits three seconds after the loops complete for the first time. Then records the free RAM. 
       
   141 	    No extra RAM should be required to be allocated after this point.
       
   142 	13. Check if there is any RAM loss.
       
   143 	
       
   144 	@SYMTestExpectedResults
       
   145 	Test should pass
       
   146 */
       
   147 void CTGlyphTreeDel::TestGlyphTreeDeleteL()
       
   148 	{
       
   149     iGc->SetPenStyle(CGraphicsContext::ENullPen);
       
   150     iGc->SetBrushColor(KRgbGray);
       
   151     iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   152 
       
   153 	TInt typefaces = iDev->NumTypefaces();
       
   154 	TTypefaceSupport info;	
       
   155 	TInt fontSize = 24;
       
   156 			
       
   157 	TInt beforeFreeRam = GetRam(); 		// Initialise here because of WINS warning
       
   158 	
       
   159 	for(TInt loop=0;loop<100;++loop)
       
   160 		{		
       
   161 		if (loop&1) //if it is odd
       
   162 			fontSize+=12;
       
   163 		else
       
   164 			fontSize-=12;
       
   165 
       
   166 		TInt count=0;
       
   167 		TInt forLoop = 0;
       
   168 		
       
   169 		for (count=0;count < typefaces; count++)
       
   170 			{
       
   171 			iDev->TypefaceSupport(info, count); 
       
   172 			TFontSpec fs;
       
   173 			fs.iTypeface = info.iTypeface;
       
   174 			fs.iHeight = fontSize;
       
   175 			CFbsFont* font = NULL;
       
   176 			TInt err = iDev->GetNearestFontToDesignHeightInPixels((CFont*&)font, fs);
       
   177 
       
   178 			if( font == NULL)
       
   179 				{
       
   180 				iStep -> INFO_PRINTF6(_L("[Couldn't get font Loop  % 2d, Iteration % 2d Font \"%S\", Size %d, err %d]\n"), forLoop, count, &fs.iTypeface.iName, fontSize, err);
       
   181 				continue;
       
   182 				}
       
   183 
       
   184 			iGc->UseFont(font);			
       
   185 			iGc->DrawText(_L("ABCDEFG123456789\n"), TPoint(10+loop, 200-(fontSize*2)+count));
       
   186 			iDev->ReleaseFont(font);
       
   187 			iGc->DiscardFont();	
       
   188 			}
       
   189 		
       
   190 		forLoop=1;
       
   191 		for (count=typefaces-1;count>=0;--count)
       
   192 			{
       
   193 			iDev->TypefaceSupport(info, count); 
       
   194 
       
   195 			TFontSpec fs;
       
   196 			fs.iTypeface = info.iTypeface;
       
   197 			fs.iHeight = fontSize;
       
   198 			CFbsFont* font = NULL;
       
   199 			TInt err = iDev->GetNearestFontToDesignHeightInPixels((CFont*&)font, fs);
       
   200 
       
   201 			if( font == NULL)
       
   202 				{
       
   203 				iStep -> INFO_PRINTF6(_L("[Couldn't get font Loop  % 2d, Iteration % 2d Font \"%S\", Size %d, err %d]\n"), forLoop, count, &fs.iTypeface.iName, fontSize, err);
       
   204 				continue;
       
   205 				}
       
   206 
       
   207 			iGc->UseFont(font);
       
   208 			iGc->DrawText(_L("ABCDEFG123456789\n"), TPoint(10+loop, 200-(fontSize*2)+count));
       
   209 			iDev->ReleaseFont(font);
       
   210 			iGc->DiscardFont();
       
   211 			}
       
   212 
       
   213 		// When the 2 loops above have completed once, the glyph cache heap should be large enough
       
   214 		// for all subsequent loops, if the glyph tree is successfully deleted after the font is
       
   215 		// discarded. So we wait 3 seconds after the 2 loops complete for the 1st time and then
       
   216 		// record the free RAM. No extra RAM should be required to be allocated after this point.			
       
   217 			
       
   218 		if( loop==0)
       
   219 			{
       
   220 		
       
   221 			// Wait to ensure font memory grabs are complete
       
   222 			User::After(3000000);	
       
   223 	
       
   224 			// save initial free RAM figure
       
   225 			beforeFreeRam = GetRam();
       
   226 			}
       
   227 
       
   228 		}
       
   229 		// Wait for all requests to complete
       
   230 		User::After(2000000);
       
   231 
       
   232 		// If there is any RAM loss print it out before call to iTest 
       
   233 		CheckRam(beforeFreeRam);		
       
   234 		TInt afterFreeRam = GetRam();
       
   235 		// Add a safety buffer to accouunt for miscellaneous system changes
       
   236 		// affect the total ram. The defect this was set to catch was leaking
       
   237 		// of the order of a megabyte so this will still catch that.
       
   238 		afterFreeRam += 65536;
       
   239 		
       
   240 		// Any extra RAM grabbed for the glyph trees should be released by 
       
   241 		// the calls to DiscardFont
       
   242 		
       
   243 		iStep-> testBooleanTrue((afterFreeRam>=beforeFreeRam), (TText8*)__FILE__, __LINE__);
       
   244 	}
       
   245 
       
   246 
       
   247 //--------------
       
   248 CTGlyphTreeDelStep::CTGlyphTreeDelStep()
       
   249 	{
       
   250 	SetTestStepName(KTGlyphTreeDelStep);
       
   251 	}
       
   252 
       
   253 TVerdict CTGlyphTreeDelStep::doTestStepL()
       
   254 	{
       
   255 #if defined(__SUPPORT_CPP_EXCEPTIONS__)
       
   256 	SetTestStepID(_L("GRAPHICS-FNTSTORE-0034"));
       
   257 	FbsStartup();
       
   258 	CTrapCleanup* TrapCleanup = CTrapCleanup::New();
       
   259 	TInt error = KErrNone;
       
   260 	try	{
       
   261 		TTrapHandler* trapHandler = User::MarkCleanupStack();
       
   262 		__UHEAP_MARK;
       
   263 
       
   264 		User::After(10000000);	
       
   265 		CTGlyphTreeDel* test_harness = CTGlyphTreeDel::NewL(this);
       
   266 		test_harness->TestGlyphTreeDeleteL();
       
   267 		delete test_harness;
       
   268 
       
   269 		__UHEAP_MARKEND;
       
   270 		User::UnMarkCleanupStack(trapHandler);
       
   271 		}
       
   272 	catch (XLeaveException& leave)
       
   273 		{
       
   274 		error = leave.GetReason();
       
   275 		}
       
   276 	catch (...)
       
   277 		{
       
   278 		User::Invariant();
       
   279 		}
       
   280 	delete TrapCleanup;
       
   281 
       
   282 	if (error)
       
   283 		{
       
   284 		SetTestStepResult(EFail);
       
   285 		}
       
   286 	RecordTestResultL();
       
   287 #endif	//__SUPPORT_CPP_EXCEPTIONS__
       
   288 	return TestStepResult();
       
   289 	}