1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/textandloc/fontservices/fontstore/tfs/T_GetNearestFont.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,352 @@
1.4 +/*
1.5 +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +* T_NearestFont.cpp
1.19 +*
1.20 +*/
1.21 +
1.22 +
1.23 +/**
1.24 + @file
1.25 + @test
1.26 + @internalComponent Internal Symbian test code
1.27 +*/
1.28 +
1.29 +#include "T_GetNearestFont.h"
1.30 +#include <hal.h>
1.31 +
1.32 +_LIT( KFontNotAvailable, "NotAvailableOnSystem" );
1.33 +_LIT( KTypefaceName, "DejaVu Sans Condensed" );
1.34 +_LIT( KFontAlias, "Alias");
1.35 +
1.36 +class CTGetNearestFont : public CTGraphicsBase
1.37 + {
1.38 +public:
1.39 + CTGetNearestFont(CTestStep* aStep);
1.40 + virtual ~CTGetNearestFont();
1.41 +
1.42 +protected:
1.43 +//from CTGraphicsStep
1.44 + virtual void RunTestCaseL(TInt aCurTestCase);
1.45 + virtual void ConstructL();
1.46 +private:
1.47 + void TestINC064346();
1.48 + void AliasedFontCreationL();
1.49 + void TestFontStoreL();
1.50 + void TestSystemDefaultFont();
1.51 +
1.52 + CFbsTypefaceStore* iTfs;
1.53 + };
1.54 +
1.55 +CTGetNearestFont::CTGetNearestFont(CTestStep* aStep) :
1.56 + CTGraphicsBase(aStep)
1.57 + {
1.58 +
1.59 + }
1.60 +
1.61 +void CTGetNearestFont::ConstructL()
1.62 + {
1.63 + iTfs = CFbsTypefaceStore::NewL(NULL);
1.64 + }
1.65 +
1.66 + CTGetNearestFont::~CTGetNearestFont()
1.67 + {
1.68 + delete iTfs;
1.69 + }
1.70 +
1.71 +void CTGetNearestFont::RunTestCaseL( TInt aCurTestCase )
1.72 + {
1.73 + ((CTGetNearestFontStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
1.74 + switch ( aCurTestCase )
1.75 + {
1.76 + case 1:
1.77 + ((CTGetNearestFontStep*)iStep)->SetTestStepID(_L("GRAPHICS-INC064346-0001"));
1.78 + INFO_PRINTF1(_L("TestINC064346 Started"));
1.79 + TestINC064346();
1.80 + INFO_PRINTF1(_L("TestINC064346 Finished"));
1.81 + break;
1.82 +
1.83 + case 2:
1.84 + ((CTGetNearestFontStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0005"));
1.85 + INFO_PRINTF1(_L("TestFontStore Started"));
1.86 + TestFontStoreL();
1.87 + INFO_PRINTF1(_L("TestFontStore Finished"));
1.88 + break;
1.89 +
1.90 + case 3:
1.91 + ((CTGetNearestFontStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0006"));
1.92 + INFO_PRINTF1(_L("Test System default font Started"));
1.93 + TestSystemDefaultFont();
1.94 + INFO_PRINTF1(_L("Test System default font Finished"));
1.95 + break;
1.96 +
1.97 + case 4:
1.98 + ((CTGetNearestFontStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-0051"));
1.99 + INFO_PRINTF1(_L("AliasedFontCreationL Started"));
1.100 + AliasedFontCreationL();
1.101 + INFO_PRINTF1(_L("AliasedFontCreationL Finished"));
1.102 + break;
1.103 +
1.104 + case 5:
1.105 + ((CTGetNearestFontStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
1.106 + ((CTGetNearestFontStep*)iStep)->CloseTMSGraphicsStep();
1.107 + TestComplete();
1.108 + break;
1.109 + }
1.110 + ((CTGetNearestFontStep*)iStep)->RecordTestResultL();
1.111 + }
1.112 +
1.113 +void CTGetNearestFont::TestINC064346()
1.114 + {
1.115 + /**
1.116 + @SYMTestCaseID GRAPHICS-INC064346-0001
1.117 + @SYMTestType UT
1.118 + @SYMTestPriority Medium
1.119 + @SYMDEF INC064346
1.120 + @SYMTestCaseDesc Tests that the correct font height is returned when matching with a superscript font.
1.121 + @SYMTestActions Get nearest font to design height for a font with the following parameters:
1.122 + Font name must be specified that is a font that does not exist on the system.
1.123 + Font must be superscript, proportional and serif.
1.124 + @SYMTestExpectedResults The correct height must be returned for the nearest font found which is checked with the expected value.
1.125 + */
1.126 + TInt ret = KErrGeneral;
1.127 + CFont* font = NULL;
1.128 + TFontSpec spec(KFontNotAvailable, 15);
1.129 +
1.130 + spec.iFontStyle = TFontStyle(EPostureUpright, EStrokeWeightNormal, EPrintPosSuperscript);
1.131 + spec.iTypeface.SetIsProportional(ETrue);
1.132 + spec.iTypeface.SetIsSerif(ETrue);
1.133 + ret = iTfs->GetNearestFontToDesignHeightInPixels(font, spec);
1.134 + TEST(ret == KErrNone);
1.135 + INFO_PRINTF2(_L("Font height = %d"), font->HeightInPixels());
1.136 + TEST(10 == font->HeightInPixels());
1.137 + }
1.138 +
1.139 +void CTGetNearestFont::TestFontStoreL()
1.140 + {
1.141 + /**
1.142 + @SYMTestCaseID GRAPHICS-FNTSTORE-0005
1.143 + @SYMPREQ PREQ1228
1.144 + @SYMREQ REQ5921
1.145 + @SYMTestCaseDesc Tests the font store optimisation changes for reduce the font load time
1.146 + @SYMTestPriority High
1.147 + @SYMTestStatus Implemented
1.148 + @SYMTestActions Get the nearest font to the design height for a font which exists and one which does not exists
1.149 + @SYMTestExpectedResults Time taken for fetching an existing font should be less then time take for fetching a non existent font.
1.150 + In addition fetching a non existent font should take almost the same time in principle, as taken by fetching
1.151 + n existing with old method (as old search method checks all existing fonts even if it finds one in between
1.152 + during search procedure).
1.153 + */
1.154 + CFont* font = NULL;
1.155 + TFontSpec spec(KFontNotAvailable, 15);
1.156 +
1.157 + spec.iHeight = 15;
1.158 + spec.iTypeface.iName = KFontNotAvailable;
1.159 + spec.iFontStyle = TFontStyle(EPostureUpright, EStrokeWeightNormal, EPrintPosSuperscript);
1.160 + spec.iTypeface.SetIsProportional(ETrue);
1.161 +
1.162 + //Set the Bold and Italic attribute for the font
1.163 + TOpenFontSpec openFontSpec(spec);
1.164 + openFontSpec.SetBold(ETrue);
1.165 + openFontSpec.SetItalic(ETrue);
1.166 + openFontSpec.GetTFontSpec(spec);
1.167 +
1.168 + TInt64 diffTime[2];
1.169 +
1.170 + //Run it twice with same font specifications except different typeface name
1.171 + //First iteration for Non Existent font and second iteration for Existent font
1.172 + for (TInt cntr = 0; cntr < 2; cntr++)
1.173 + {
1.174 + TInt freq = 0;
1.175 +
1.176 + TUint32 starttime = User::FastCounter();
1.177 + TInt ret = iTfs->GetNearestFontToDesignHeightInPixels(font, spec);
1.178 + TUint32 endtime = User::FastCounter();
1.179 + TEST(ret == KErrNone);
1.180 +
1.181 + User::LeaveIfError(HAL::Get(HALData::EFastCounterFrequency, freq));
1.182 + TUint32 diff = endtime - starttime;
1.183 + diffTime[cntr] = (1000000 * TInt64(diff)) / (TInt64)freq;
1.184 +
1.185 + TFontSpec returnedSpecs = font->FontSpecInTwips();
1.186 + INFO_PRINTF3(_L("Font Desired : Name = %S Height = %d "), &spec.iTypeface.iName, spec.iHeight);
1.187 + INFO_PRINTF4(_L("Font Returned : Name = %S Height = %d Time = %d Microseconds"), &returnedSpecs.iTypeface.iName, font->HeightInPixels(),TUint32(diffTime[cntr]));
1.188 +
1.189 + //Change the font spec to specify available typeface
1.190 + spec.iTypeface.iName = KTypefaceName;
1.191 +
1.192 + iTfs->ReleaseFont(font);
1.193 + }
1.194 +
1.195 + TEST(diffTime[1] < diffTime[0]);
1.196 + INFO_PRINTF2(_L("OPTIMISATION Factor %f"), (TReal(1)-(TReal(diffTime[1])/TReal(diffTime[0]))));
1.197 + }
1.198 +
1.199 +/**
1.200 +@SYMTestCaseID GRAPHICS-FNTSTORE-0006
1.201 +@SYMTestPriority Critical
1.202 +@SYMREQ REQ6158
1.203 +
1.204 +@SYMTestCaseDesc
1.205 +Default system font
1.206 +
1.207 +@SYMTestActions
1.208 +1 - Test without setting system default font
1.209 +2 - Set the system default font to typeface 1
1.210 +3 - Set the system default font to typeface 2
1.211 +4 - Set the system default font to an empty descriptor
1.212 +5 - Set the system default font to large descriptor
1.213 +6 - Set the system default font to a font that does not exist
1.214 +7 - Set system font to an alias font
1.215 +
1.216 +@SYMTestExpectedResults
1.217 +The following applies when the typeface name is empty when requesting a font:
1.218 +If a default system typeface is not set then the nearest font to the specified font will be returned.
1.219 +If a default system typeface name is set then this will be the returned font.
1.220 +If the character length of the system typeface is greater than KMaxTypefaceNameLength then a KErrTooBig leave will occur.
1.221 +*/
1.222 +void CTGetNearestFont::TestSystemDefaultFont()
1.223 + {
1.224 + const TInt numTypefaces = iTfs->NumTypefaces();
1.225 + TEST(numTypefaces >= 2); // Must have at least 2 typefaces
1.226 +
1.227 + // Get the first typeface
1.228 + TTypefaceSupport tfSupport1;
1.229 + iTfs->TypefaceSupport(tfSupport1, 0);
1.230 + TPtrC typeface1 = tfSupport1.iTypeface.iName;
1.231 +
1.232 + // Get the second typeface
1.233 + TTypefaceSupport tfSupport2;
1.234 + iTfs->TypefaceSupport(tfSupport2, 1);
1.235 + TPtrC typeface2 = tfSupport2.iTypeface.iName;
1.236 +
1.237 + // Test without setting system default font and the returned font should not be typeface1 or typeface2
1.238 + CFont* font = NULL;
1.239 + TFontSpec spec(KNullDesC, 15);
1.240 + spec.iTypeface.SetIsProportional(ETrue);
1.241 + spec.iTypeface.SetIsSerif(ETrue);
1.242 + TInt ret = iTfs->GetNearestFontToDesignHeightInPixels(font, spec);
1.243 + TEST(ret == KErrNone);
1.244 + TFontSpec returnedSpecs = font->FontSpecInTwips();
1.245 + TEST(returnedSpecs.iTypeface.iName != typeface1 && returnedSpecs.iTypeface.iName != typeface2);
1.246 + iTfs->ReleaseFont(font);
1.247 +
1.248 + // Now set the system default font and the returned font should be typeface1
1.249 + iTfs->SetSystemDefaultTypefaceNameL(typeface1);
1.250 + ret = iTfs->GetNearestFontToDesignHeightInPixels(font, spec);
1.251 + TEST(ret == KErrNone);
1.252 + returnedSpecs = font->FontSpecInTwips();
1.253 + TEST(returnedSpecs.iTypeface.iName == typeface1);
1.254 + iTfs->ReleaseFont(font);
1.255 +
1.256 + // Now set the system default font and the returned font should be typeface2
1.257 + iTfs->SetSystemDefaultTypefaceNameL(typeface2);
1.258 + ret = iTfs->GetNearestFontToDesignHeightInPixels(font, spec);
1.259 + TEST(ret == KErrNone);
1.260 + returnedSpecs = font->FontSpecInTwips();
1.261 + TEST(returnedSpecs.iTypeface.iName == typeface2);
1.262 + iTfs->ReleaseFont(font);
1.263 +
1.264 + // Now set the system default font to an empty descriptor and the font returned should not be typeface1 or typeface2
1.265 + iTfs->SetSystemDefaultTypefaceNameL(KNullDesC);
1.266 + ret = iTfs->GetNearestFontToDesignHeightInPixels(font, spec);
1.267 + TEST(ret == KErrNone);
1.268 + returnedSpecs = font->FontSpecInTwips();
1.269 + TEST(returnedSpecs.iTypeface.iName != typeface1 && returnedSpecs.iTypeface.iName != typeface2);
1.270 + iTfs->ReleaseFont(font);
1.271 +
1.272 + // Set the system default font to large descriptor and we should get an error
1.273 + TRAP(ret, iTfs->SetSystemDefaultTypefaceNameL(_L("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")));
1.274 + TEST(ret == KErrTooBig);
1.275 +
1.276 + // Now set the system default font to a font that does not exist and the font returned should not be typeface 1 or typeface2
1.277 + _LIT( KFontNotExisting, "FontDoesNotExist" );
1.278 + iTfs->SetSystemDefaultTypefaceNameL(KFontNotExisting);
1.279 + ret = iTfs->GetNearestFontToDesignHeightInPixels(font, spec);
1.280 + TEST(ret == KErrNone);
1.281 + returnedSpecs = font->FontSpecInTwips();
1.282 + TEST(returnedSpecs.iTypeface.iName != typeface1 && returnedSpecs.iTypeface.iName != typeface2);
1.283 + iTfs->ReleaseFont(font);
1.284 +
1.285 + // Now set the system default font and set an alias on typeface1 - the returned font should still be typeface1
1.286 + iTfs->SetSystemDefaultTypefaceNameL(typeface1);
1.287 + iTfs->SetFontNameAliasL(typeface1, typeface2);
1.288 + ret = iTfs->GetNearestFontToDesignHeightInPixels(font, spec);
1.289 + TEST(ret == KErrNone);
1.290 + returnedSpecs = font->FontSpecInTwips();
1.291 + TEST(returnedSpecs.iTypeface.iName == typeface1);
1.292 + iTfs->ReleaseFont(font);
1.293 +
1.294 + // Now set the system default font to an aliased font - the returned font should still be typeface1
1.295 + iTfs->SetSystemDefaultTypefaceNameL(KFontAlias);
1.296 + iTfs->SetFontNameAliasL(KFontAlias, typeface1);
1.297 + ret = iTfs->GetNearestFontToDesignHeightInPixels(font, spec);
1.298 + TEST(ret == KErrNone);
1.299 + returnedSpecs = font->FontSpecInTwips();
1.300 + TEST(returnedSpecs.iTypeface.iName == typeface1);
1.301 + iTfs->ReleaseFont(font);
1.302 +
1.303 + // tear down the default font
1.304 + iTfs->SetSystemDefaultTypefaceNameL(KNullDesC);
1.305 + }
1.306 +
1.307 +/**
1.308 +@SYMTestCaseID GRAPHICS-FNTSTORE-0051
1.309 +@SYMTestType UT
1.310 +@SYMTestPriority Medium
1.311 +@SYMDEF INC127988
1.312 +@SYMTestCaseDesc Tests that an alias does not prevent a real font from being loaded.
1.313 +@SYMTestActions Create an alias using the name of a real font. Get the real font.
1.314 +@SYMTestExpectedResults Ensure the real font, not the aliased font is returned.
1.315 +*/
1.316 +void CTGetNearestFont::AliasedFontCreationL()
1.317 + {
1.318 + TInt numTypefaces = iTfs->NumTypefaces();
1.319 + if(numTypefaces <2)
1.320 + return;
1.321 +
1.322 + TTypefaceSupport tfSupport1;
1.323 +
1.324 + iTfs->TypefaceSupport(tfSupport1, 0);
1.325 + INFO_PRINTF1(tfSupport1.iTypeface.iName);
1.326 + // Get the first different typeface
1.327 + TTypefaceSupport tfSupport2;
1.328 + while (--numTypefaces)
1.329 + {
1.330 + iTfs->TypefaceSupport(tfSupport2, numTypefaces);
1.331 + INFO_PRINTF1(tfSupport2.iTypeface.iName);
1.332 + if (tfSupport2.iTypeface.iName != tfSupport1.iTypeface.iName)
1.333 + {
1.334 + break;
1.335 + }
1.336 + }
1.337 +
1.338 + // Make sure we aren't at the end of the list
1.339 + TEST(numTypefaces);
1.340 + // Alias the other font with the same name as the original
1.341 + iTfs->SetFontNameAliasL(tfSupport1.iTypeface.iName, tfSupport2.iTypeface.iName);
1.342 +
1.343 + // Request the original font (making sure we don't get the aliased font back)
1.344 + CFont* font = NULL;
1.345 + TFontSpec spec(tfSupport1.iTypeface.iName, 0);
1.346 + TInt ret = iTfs->GetNearestFontToDesignHeightInPixels(font, spec);
1.347 + TEST(ret == KErrNone);
1.348 + TFontSpec returnedSpecs = font->FontSpecInTwips();
1.349 + INFO_PRINTF1(returnedSpecs.iTypeface.iName);
1.350 + TEST(returnedSpecs.iTypeface.iName == tfSupport1.iTypeface.iName);
1.351 + iTfs->ReleaseFont(font);
1.352 + }
1.353 +
1.354 +//--------------
1.355 +__CONSTRUCT_STEP__(GetNearestFont)