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