First public contribution.
2 * Copyright (c) 2006-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.
23 @internalComponent Internal Symbian test code
26 #include "T_GetNearestFont.h"
29 _LIT( KFontNotAvailable, "NotAvailableOnSystem" );
30 _LIT( KTypefaceName, "DejaVu Sans Condensed" );
31 _LIT( KFontAlias, "Alias");
33 class CTGetNearestFont : public CTGraphicsBase
36 CTGetNearestFont(CTestStep* aStep);
37 virtual ~CTGetNearestFont();
41 virtual void RunTestCaseL(TInt aCurTestCase);
42 virtual void ConstructL();
45 void AliasedFontCreationL();
46 void TestFontStoreL();
47 void TestSystemDefaultFont();
49 CFbsTypefaceStore* iTfs;
52 CTGetNearestFont::CTGetNearestFont(CTestStep* aStep) :
58 void CTGetNearestFont::ConstructL()
60 iTfs = CFbsTypefaceStore::NewL(NULL);
63 CTGetNearestFont::~CTGetNearestFont()
68 void CTGetNearestFont::RunTestCaseL( TInt aCurTestCase )
70 ((CTGetNearestFontStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
71 switch ( aCurTestCase )
74 ((CTGetNearestFontStep*)iStep)->SetTestStepID(_L("GRAPHICS-INC064346-0001"));
75 INFO_PRINTF1(_L("TestINC064346 Started"));
77 INFO_PRINTF1(_L("TestINC064346 Finished"));
81 ((CTGetNearestFontStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0005"));
82 INFO_PRINTF1(_L("TestFontStore Started"));
84 INFO_PRINTF1(_L("TestFontStore Finished"));
88 ((CTGetNearestFontStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0006"));
89 INFO_PRINTF1(_L("Test System default font Started"));
90 TestSystemDefaultFont();
91 INFO_PRINTF1(_L("Test System default font Finished"));
95 ((CTGetNearestFontStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0051"));
96 INFO_PRINTF1(_L("AliasedFontCreationL Started"));
97 AliasedFontCreationL();
98 INFO_PRINTF1(_L("AliasedFontCreationL Finished"));
102 ((CTGetNearestFontStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
103 ((CTGetNearestFontStep*)iStep)->CloseTMSGraphicsStep();
107 ((CTGetNearestFontStep*)iStep)->RecordTestResultL();
110 void CTGetNearestFont::TestINC064346()
113 @SYMTestCaseID GRAPHICS-INC064346-0001
115 @SYMTestPriority Medium
117 @SYMTestCaseDesc Tests that the correct font height is returned when matching with a superscript font.
118 @SYMTestActions Get nearest font to design height for a font with the following parameters:
119 Font name must be specified that is a font that does not exist on the system.
120 Font must be superscript, proportional and serif.
121 @SYMTestExpectedResults The correct height must be returned for the nearest font found which is checked with the expected value.
123 TInt ret = KErrGeneral;
125 TFontSpec spec(KFontNotAvailable, 15);
127 spec.iFontStyle = TFontStyle(EPostureUpright, EStrokeWeightNormal, EPrintPosSuperscript);
128 spec.iTypeface.SetIsProportional(ETrue);
129 spec.iTypeface.SetIsSerif(ETrue);
130 ret = iTfs->GetNearestFontToDesignHeightInPixels(font, spec);
131 TEST(ret == KErrNone);
132 INFO_PRINTF2(_L("Font height = %d"), font->HeightInPixels());
133 TEST(10 == font->HeightInPixels());
136 void CTGetNearestFont::TestFontStoreL()
139 @SYMTestCaseID GRAPHICS-FNTSTORE-0005
142 @SYMTestCaseDesc Tests the font store optimisation changes for reduce the font load time
143 @SYMTestPriority High
144 @SYMTestStatus Implemented
145 @SYMTestActions Get the nearest font to the design height for a font which exists and one which does not exists
146 @SYMTestExpectedResults Time taken for fetching an existing font should be less then time take for fetching a non existent font.
147 In addition fetching a non existent font should take almost the same time in principle, as taken by fetching
148 n existing with old method (as old search method checks all existing fonts even if it finds one in between
149 during search procedure).
152 TFontSpec spec(KFontNotAvailable, 15);
155 spec.iTypeface.iName = KFontNotAvailable;
156 spec.iFontStyle = TFontStyle(EPostureUpright, EStrokeWeightNormal, EPrintPosSuperscript);
157 spec.iTypeface.SetIsProportional(ETrue);
159 //Set the Bold and Italic attribute for the font
160 TOpenFontSpec openFontSpec(spec);
161 openFontSpec.SetBold(ETrue);
162 openFontSpec.SetItalic(ETrue);
163 openFontSpec.GetTFontSpec(spec);
167 //Run it twice with same font specifications except different typeface name
168 //First iteration for Non Existent font and second iteration for Existent font
169 for (TInt cntr = 0; cntr < 2; cntr++)
173 TUint32 starttime = User::FastCounter();
174 TInt ret = iTfs->GetNearestFontToDesignHeightInPixels(font, spec);
175 TUint32 endtime = User::FastCounter();
176 TEST(ret == KErrNone);
178 User::LeaveIfError(HAL::Get(HALData::EFastCounterFrequency, freq));
179 TUint32 diff = endtime - starttime;
180 diffTime[cntr] = (1000000 * TInt64(diff)) / (TInt64)freq;
182 TFontSpec returnedSpecs = font->FontSpecInTwips();
183 INFO_PRINTF3(_L("Font Desired : Name = %S Height = %d "), &spec.iTypeface.iName, spec.iHeight);
184 INFO_PRINTF4(_L("Font Returned : Name = %S Height = %d Time = %d Microseconds"), &returnedSpecs.iTypeface.iName, font->HeightInPixels(),TUint32(diffTime[cntr]));
186 //Change the font spec to specify available typeface
187 spec.iTypeface.iName = KTypefaceName;
189 iTfs->ReleaseFont(font);
192 TEST(diffTime[1] < diffTime[0]);
193 INFO_PRINTF2(_L("OPTIMISATION Factor %f"), (TReal(1)-(TReal(diffTime[1])/TReal(diffTime[0]))));
197 @SYMTestCaseID GRAPHICS-FNTSTORE-0006
198 @SYMTestPriority Critical
205 1 - Test without setting system default font
206 2 - Set the system default font to typeface 1
207 3 - Set the system default font to typeface 2
208 4 - Set the system default font to an empty descriptor
209 5 - Set the system default font to large descriptor
210 6 - Set the system default font to a font that does not exist
211 7 - Set system font to an alias font
213 @SYMTestExpectedResults
214 The following applies when the typeface name is empty when requesting a font:
215 If a default system typeface is not set then the nearest font to the specified font will be returned.
216 If a default system typeface name is set then this will be the returned font.
217 If the character length of the system typeface is greater than KMaxTypefaceNameLength then a KErrTooBig leave will occur.
219 void CTGetNearestFont::TestSystemDefaultFont()
221 const TInt numTypefaces = iTfs->NumTypefaces();
222 TEST(numTypefaces >= 2); // Must have at least 2 typefaces
224 // Get the first typeface
225 TTypefaceSupport tfSupport1;
226 iTfs->TypefaceSupport(tfSupport1, 0);
227 TPtrC typeface1 = tfSupport1.iTypeface.iName;
229 // Get the second typeface
230 TTypefaceSupport tfSupport2;
231 iTfs->TypefaceSupport(tfSupport2, 1);
232 TPtrC typeface2 = tfSupport2.iTypeface.iName;
234 // Test without setting system default font and the returned font should not be typeface1 or typeface2
236 TFontSpec spec(KNullDesC, 15);
237 spec.iTypeface.SetIsProportional(ETrue);
238 spec.iTypeface.SetIsSerif(ETrue);
239 TInt ret = iTfs->GetNearestFontToDesignHeightInPixels(font, spec);
240 TEST(ret == KErrNone);
241 TFontSpec returnedSpecs = font->FontSpecInTwips();
242 TEST(returnedSpecs.iTypeface.iName != typeface1 && returnedSpecs.iTypeface.iName != typeface2);
243 iTfs->ReleaseFont(font);
245 // Now set the system default font and the returned font should be typeface1
246 iTfs->SetSystemDefaultTypefaceNameL(typeface1);
247 ret = iTfs->GetNearestFontToDesignHeightInPixels(font, spec);
248 TEST(ret == KErrNone);
249 returnedSpecs = font->FontSpecInTwips();
250 TEST(returnedSpecs.iTypeface.iName == typeface1);
251 iTfs->ReleaseFont(font);
253 // Now set the system default font and the returned font should be typeface2
254 iTfs->SetSystemDefaultTypefaceNameL(typeface2);
255 ret = iTfs->GetNearestFontToDesignHeightInPixels(font, spec);
256 TEST(ret == KErrNone);
257 returnedSpecs = font->FontSpecInTwips();
258 TEST(returnedSpecs.iTypeface.iName == typeface2);
259 iTfs->ReleaseFont(font);
261 // Now set the system default font to an empty descriptor and the font returned should not be typeface1 or typeface2
262 iTfs->SetSystemDefaultTypefaceNameL(KNullDesC);
263 ret = iTfs->GetNearestFontToDesignHeightInPixels(font, spec);
264 TEST(ret == KErrNone);
265 returnedSpecs = font->FontSpecInTwips();
266 TEST(returnedSpecs.iTypeface.iName != typeface1 && returnedSpecs.iTypeface.iName != typeface2);
267 iTfs->ReleaseFont(font);
269 // Set the system default font to large descriptor and we should get an error
270 TRAP(ret, iTfs->SetSystemDefaultTypefaceNameL(_L("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")));
271 TEST(ret == KErrTooBig);
273 // Now set the system default font to a font that does not exist and the font returned should not be typeface 1 or typeface2
274 _LIT( KFontNotExisting, "FontDoesNotExist" );
275 iTfs->SetSystemDefaultTypefaceNameL(KFontNotExisting);
276 ret = iTfs->GetNearestFontToDesignHeightInPixels(font, spec);
277 TEST(ret == KErrNone);
278 returnedSpecs = font->FontSpecInTwips();
279 TEST(returnedSpecs.iTypeface.iName != typeface1 && returnedSpecs.iTypeface.iName != typeface2);
280 iTfs->ReleaseFont(font);
282 // Now set the system default font and set an alias on typeface1 - the returned font should still be typeface1
283 iTfs->SetSystemDefaultTypefaceNameL(typeface1);
284 iTfs->SetFontNameAliasL(typeface1, typeface2);
285 ret = iTfs->GetNearestFontToDesignHeightInPixels(font, spec);
286 TEST(ret == KErrNone);
287 returnedSpecs = font->FontSpecInTwips();
288 TEST(returnedSpecs.iTypeface.iName == typeface1);
289 iTfs->ReleaseFont(font);
291 // Now set the system default font to an aliased font - the returned font should still be typeface1
292 iTfs->SetSystemDefaultTypefaceNameL(KFontAlias);
293 iTfs->SetFontNameAliasL(KFontAlias, typeface1);
294 ret = iTfs->GetNearestFontToDesignHeightInPixels(font, spec);
295 TEST(ret == KErrNone);
296 returnedSpecs = font->FontSpecInTwips();
297 TEST(returnedSpecs.iTypeface.iName == typeface1);
298 iTfs->ReleaseFont(font);
300 // tear down the default font
301 iTfs->SetSystemDefaultTypefaceNameL(KNullDesC);
305 @SYMTestCaseID GRAPHICS-FNTSTORE-0051
307 @SYMTestPriority Medium
309 @SYMTestCaseDesc Tests that an alias does not prevent a real font from being loaded.
310 @SYMTestActions Create an alias using the name of a real font. Get the real font.
311 @SYMTestExpectedResults Ensure the real font, not the aliased font is returned.
313 void CTGetNearestFont::AliasedFontCreationL()
315 TInt numTypefaces = iTfs->NumTypefaces();
319 TTypefaceSupport tfSupport1;
321 iTfs->TypefaceSupport(tfSupport1, 0);
322 INFO_PRINTF1(tfSupport1.iTypeface.iName);
323 // Get the first different typeface
324 TTypefaceSupport tfSupport2;
325 while (--numTypefaces)
327 iTfs->TypefaceSupport(tfSupport2, numTypefaces);
328 INFO_PRINTF1(tfSupport2.iTypeface.iName);
329 if (tfSupport2.iTypeface.iName != tfSupport1.iTypeface.iName)
335 // Make sure we aren't at the end of the list
337 // Alias the other font with the same name as the original
338 iTfs->SetFontNameAliasL(tfSupport1.iTypeface.iName, tfSupport2.iTypeface.iName);
340 // Request the original font (making sure we don't get the aliased font back)
342 TFontSpec spec(tfSupport1.iTypeface.iName, 0);
343 TInt ret = iTfs->GetNearestFontToDesignHeightInPixels(font, spec);
344 TEST(ret == KErrNone);
345 TFontSpec returnedSpecs = font->FontSpecInTwips();
346 INFO_PRINTF1(returnedSpecs.iTypeface.iName);
347 TEST(returnedSpecs.iTypeface.iName == tfSupport1.iTypeface.iName);
348 iTfs->ReleaseFont(font);
352 __CONSTRUCT_STEP__(GetNearestFont)