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