Update contrib.
2 * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
22 #include <graphics/fbsdefs.h>
23 #include "T_GlyphTreeDel.h"
25 const TDisplayMode testDisplayModes[] =
41 // This test is based on code from the TTAGMA test in form
44 CTGlyphTreeDel::CTGlyphTreeDel(CTestStep* aStep):
49 CTGlyphTreeDel::~CTGlyphTreeDel()
53 RFbsSession::Disconnect();
56 CTGlyphTreeDel* CTGlyphTreeDel::NewL(CTestStep* aStep)
58 CTGlyphTreeDel *theTest = new (ELeave) CTGlyphTreeDel(aStep);
60 CleanupStack::PushL(theTest);
61 theTest->ConstructL();
66 void CTGlyphTreeDel::ConstructL()
68 iStep -> INFO_PRINTF1(_L("DEF047283"));
69 RFbsSession::Connect();
70 iFbs = RFbsSession::GetSession();
72 User::Leave(KErrGeneral);
73 User::LeaveIfError(CreateScreenDevice());
74 iDev->ChangeScreenDevice(NULL);
75 iDev->SetAutoUpdate(ETrue);
76 iDev->CreateContext(iGc);
79 TInt CTGlyphTreeDel::CreateScreenDevice()
82 TInt sizeOfDisplayMode = sizeof (testDisplayModes) / sizeof(testDisplayModes[0]);
84 for(TInt theScreenModeIndex = sizeOfDisplayMode - 1; theScreenModeIndex ; theScreenModeIndex--)
86 TDisplayMode disp = testDisplayModes[theScreenModeIndex];
87 TRAP(err, iDev = CFbsScreenDevice::NewL(_L(""), disp)); //scdv
90 iStep->INFO_PRINTF2(_L("Device %d has been created"), disp);
97 // Get System free Ram
99 TInt CTGlyphTreeDel::GetRam()
101 TMemoryInfoV1Buf memory;
102 UserHal::MemoryInfo(memory);
103 return(TInt)(memory().iFreeRamInBytes);
106 void CTGlyphTreeDel::CheckRam( TInt beforeFreeRam)
108 TInt freeRam=GetRam();
109 if( beforeFreeRam < freeRam)
111 iStep -> INFO_PRINTF2( _L("Freed %08d bytes of RAM\n"), freeRam-beforeFreeRam);
113 else if( beforeFreeRam > freeRam)
115 iStep -> INFO_PRINTF2( _L("Leaked %08d bytes of RAM\n"), beforeFreeRam-freeRam);
121 GRAPHICS-FNTSTORE-0034
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
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.
144 @SYMTestExpectedResults
147 void CTGlyphTreeDel::TestGlyphTreeDeleteL()
149 iGc->SetPenStyle(CGraphicsContext::ENullPen);
150 iGc->SetBrushColor(KRgbGray);
151 iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
153 TInt typefaces = iDev->NumTypefaces();
154 TTypefaceSupport info;
157 TInt beforeFreeRam = GetRam(); // Initialise here because of WINS warning
159 for(TInt loop=0;loop<100;++loop)
161 if (loop&1) //if it is odd
169 for (count=0;count < typefaces; count++)
171 iDev->TypefaceSupport(info, count);
173 fs.iTypeface = info.iTypeface;
174 fs.iHeight = fontSize;
175 CFbsFont* font = NULL;
176 TInt err = iDev->GetNearestFontToDesignHeightInPixels((CFont*&)font, fs);
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);
185 iGc->DrawText(_L("ABCDEFG123456789\n"), TPoint(10+loop, 200-(fontSize*2)+count));
186 iDev->ReleaseFont(font);
191 for (count=typefaces-1;count>=0;--count)
193 iDev->TypefaceSupport(info, count);
196 fs.iTypeface = info.iTypeface;
197 fs.iHeight = fontSize;
198 CFbsFont* font = NULL;
199 TInt err = iDev->GetNearestFontToDesignHeightInPixels((CFont*&)font, fs);
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);
208 iGc->DrawText(_L("ABCDEFG123456789\n"), TPoint(10+loop, 200-(fontSize*2)+count));
209 iDev->ReleaseFont(font);
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.
221 // Wait to ensure font memory grabs are complete
222 User::After(3000000);
224 // save initial free RAM figure
225 beforeFreeRam = GetRam();
229 // Wait for all requests to complete
230 User::After(2000000);
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;
240 // Any extra RAM grabbed for the glyph trees should be released by
241 // the calls to DiscardFont
243 iStep-> testBooleanTrue((afterFreeRam>=beforeFreeRam), (TText8*)__FILE__, __LINE__);
248 CTGlyphTreeDelStep::CTGlyphTreeDelStep()
250 SetTestStepName(KTGlyphTreeDelStep);
253 TVerdict CTGlyphTreeDelStep::doTestStepL()
255 #if defined(__SUPPORT_CPP_EXCEPTIONS__)
256 SetTestStepID(_L("GRAPHICS-FNTSTORE-0034"));
258 CTrapCleanup* TrapCleanup = CTrapCleanup::New();
259 TInt error = KErrNone;
261 TTrapHandler* trapHandler = User::MarkCleanupStack();
264 User::After(10000000);
265 CTGlyphTreeDel* test_harness = CTGlyphTreeDel::NewL(this);
266 test_harness->TestGlyphTreeDeleteL();
270 User::UnMarkCleanupStack(trapHandler);
272 catch (XLeaveException& leave)
274 error = leave.GetReason();
284 SetTestStepResult(EFail);
287 #endif //__SUPPORT_CPP_EXCEPTIONS__
288 return TestStepResult();