1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/textandloc/fontservices/fontstore/tfs/T_LinkedFonts2.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,1306 @@
1.4 +/*
1.5 +* Copyright (c) 2008-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 +*
1.19 +*/
1.20 +
1.21 +
1.22 +/**
1.23 + @file
1.24 + @test
1.25 + @internalComponent
1.26 +*/
1.27 +
1.28 +#include "T_LinkedFonts2.h"
1.29 +#include "linkedfontsprivate.h"
1.30 +#include <graphics/openfontlinkedtypefacespecification.h>
1.31 +#include <openfontlinkedtypefaceelementspec.h>
1.32 +
1.33 +CTLinkedFonts2::CTLinkedFonts2(CTestStep* aStep)
1.34 +: CTGraphicsBase(aStep)
1.35 + {
1.36 +
1.37 + }
1.38 +
1.39 +CTLinkedFonts2::~CTLinkedFonts2()
1.40 + {
1.41 + delete iGc;
1.42 + delete iDev;
1.43 + if (iFbs)
1.44 + iFbs->Disconnect();
1.45 + }
1.46 +
1.47 +void CTLinkedFonts2::TestPanic(TInt aPanic)
1.48 + {
1.49 + _LIT(KFntTestStorePanicCategory,"TestFntStore");
1.50 + User::Panic(KFntTestStorePanicCategory,aPanic);
1.51 + }
1.52 +
1.53 +void CTLinkedFonts2::RunTestCaseL(TInt aCurTestCase)
1.54 + {
1.55 + ((CTLinkedFonts2Step*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
1.56 + switch (aCurTestCase)
1.57 + {
1.58 + case 1:
1.59 + ((CTLinkedFonts2Step*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-LINKEDFONTS-0046"));
1.60 + InitializeTestHarnessL();
1.61 + break;
1.62 + case 2:
1.63 + ((CTLinkedFonts2Step*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-LINKEDFONTS-0001"));
1.64 + TestLinkedClientGettersAndSettersL();
1.65 + break;
1.66 + case 3:
1.67 + ((CTLinkedFonts2Step*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-LINKEDFONTS-0002"));
1.68 + TestLinkedClientAddAndRemoveL();
1.69 + break;
1.70 + case 4:
1.71 + ((CTLinkedFonts2Step*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-LINKEDFONTS-0003"));
1.72 + TestOpenClientAddAndRemoveL();
1.73 + break;
1.74 + case 5:
1.75 +/**
1.76 +@SYMTestCaseID GRAPHICS-FNTSTORE-LINKEDFONTS-0004
1.77 +*/
1.78 + ((CTLinkedFonts2Step*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-LINKEDFONTS-0004"));
1.79 + TestLinkedRegistrationAndFetchL();
1.80 + break;
1.81 + case 6:
1.82 + ((CTLinkedFonts2Step*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-LINKEDFONTS-0100"));
1.83 + TestComplexLinkedFontsBasicL();
1.84 + break;
1.85 + case 7:
1.86 + ((CTLinkedFonts2Step*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
1.87 + //((CTLinkedFonts2Step*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-LINKEDFONTS-0101"));
1.88 + //TestBitmapFontsL();
1.89 + break;
1.90 + default:
1.91 + CloseTestHarnessL();
1.92 + TestComplete();
1.93 + ((CTLinkedFonts2Step*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
1.94 + ((CTLinkedFonts2Step*)iStep)->CloseTMSGraphicsStep();
1.95 + break;
1.96 + }
1.97 + ((CTLinkedFonts2Step*)iStep)->RecordTestResultL();
1.98 + }
1.99 +
1.100 +/**
1.101 + @SYMTestCaseID
1.102 + GRAPHICS-FNTSTORE-LINKEDFONTS-0046
1.103 +
1.104 + @SYMTestCaseDesc
1.105 + Starts a server session with the font and bitmap server.
1.106 +
1.107 + @SYMTestActions
1.108 + 1. Creates a session with the Font and Bitmap server.
1.109 + 2. Gets the current Font and Bitmap server session.
1.110 + 3. Creates a CFbsScreenDevice object.
1.111 + 4. Sets screen device to null.
1.112 + 5. Sets auto update to true.
1.113 + 6. Creates a font and bitmap server graphics context for the
1.114 + device and activates it.
1.115 +
1.116 + @SYMTestExpectedResults
1.117 + All steps 1-6 above succeed.
1.118 +*/
1.119 +void CTLinkedFonts2::StartServer()
1.120 + {
1.121 + TInt ret = RFbsSession::Connect();
1.122 + TEST2(ret, KErrNone);
1.123 + iFbs = RFbsSession::GetSession();
1.124 + TEST(iFbs != NULL);
1.125 +
1.126 + if (iFbs==NULL)
1.127 + {
1.128 + //cannot continue
1.129 + TestComplete();
1.130 + return;
1.131 + }
1.132 +
1.133 + TInt err;
1.134 + TDisplayMode mode[4] = {EColor16MA,EColor16MU,EColor64K,EColor16MAP};
1.135 +
1.136 + TInt count;
1.137 + for (count=0; count < (sizeof(mode)/sizeof(mode[0])) ;count++)
1.138 + {
1.139 + TRAP(err, iDev = CFbsScreenDevice::NewL(KNullDesC, mode[count]));
1.140 + if (err!=KErrNotSupported)
1.141 + {
1.142 + break;
1.143 + }
1.144 + }
1.145 +
1.146 + if(err == KErrNone)
1.147 + {
1.148 + INFO_PRINTF2(_L("%d screen mode created"),mode[count]);
1.149 + iDev->ChangeScreenDevice(NULL);
1.150 + iDev->SetAutoUpdate(ETrue);
1.151 + iDev->CreateContext(iGc);
1.152 +
1.153 + //use and create a font
1.154 + //otherwise for memory tests there is a leak reported since the first AllocL
1.155 + //creates the space for the array (e.g. CTypefaceStore::AddFontL()) and
1.156 + //although the array is emptied the array element storage is not deleted
1.157 + //until everything is closed
1.158 + _LIT(KSansSerif, "DejaVu Sans Condensed");
1.159 + TTypeface typeface;
1.160 + typeface.iName = KSansSerif;
1.161 + TFontSpec fs;
1.162 + fs.iTypeface = typeface;
1.163 + fs.iHeight = 20;
1.164 + CFbsFont* font = NULL;
1.165 + TInt err1 = iDev->GetNearestFontToDesignHeightInPixels(font, fs);
1.166 + TEST(err1==KErrNone);
1.167 + if (err1 == KErrNone)
1.168 + {
1.169 + TSize scrSize = iDev->SizeInPixels();
1.170 + iGc->UseFont(font);
1.171 + _LIT(KTestText,"TEST");
1.172 + iGc->DrawText(KTestText, TPoint((scrSize.iWidth / 2) + 50, 50));
1.173 + iGc->DiscardFont();
1.174 + iDev->ReleaseFont(font);
1.175 + }
1.176 + }
1.177 + else
1.178 + {
1.179 + INFO_PRINTF2(_L("Could not create screen mode error %d"),err);
1.180 + }
1.181 + }
1.182 +
1.183 +
1.184 +void CTLinkedFonts2::InitializeTestHarnessL()
1.185 + {
1.186 + INFO_PRINTF1(_L("Initialising the test harness T_LinkedFonts2 (PREQ2146)"));
1.187 + StartServer();
1.188 + }
1.189 +
1.190 +void CTLinkedFonts2::CloseTestHarnessL()
1.191 + {
1.192 + }
1.193 +/**
1.194 +@SYMTestCaseID
1.195 +GRAPHICS-FNTSTORE-LINKEDFONTS-0001
1.196 +
1.197 +@SYMPREQ
1.198 +PREQ2146
1.199 +
1.200 +@SYMREQ
1.201 +PREQ2146
1.202 +
1.203 +@SYMTestCaseDesc
1.204 +Create a linked typeface element & group. Set the parameters they provide.
1.205 +
1.206 +@SYMTestPriority
1.207 +Critical
1.208 +
1.209 +@SYMTestStatus
1.210 +Implemented
1.211 +
1.212 +@SYMTestActions
1.213 +Tests that the values set are stored correctly by the linked typeface element & group.
1.214 +
1.215 +@SYMTestExpectedResults
1.216 +Values are set correctly
1.217 +*/
1.218 +void CTLinkedFonts2::TestLinkedClientGettersAndSettersL()
1.219 + {
1.220 + INFO_PRINTF1(_L("CTLinkedFonts2::TestLinkedClientGettersAndSettersL"));
1.221 + CLinkedTypefaceElementSpec *elementSpec;
1.222 + _LIT(KLinkedTypefaceName, "TypefaceNumberOne");
1.223 + elementSpec = CLinkedTypefaceElementSpec::NewLC(KLinkedTypefaceName, 10);
1.224 +
1.225 + elementSpec->SetCanonical(ETrue);
1.226 + TEST(elementSpec->Canonical());
1.227 +
1.228 + //Test Remaining Getters & Setters
1.229 + elementSpec->SetCanonical(EFalse);
1.230 +
1.231 + CleanupStack::PopAndDestroy(elementSpec);
1.232 +
1.233 + CLinkedTypefaceGroup* grp = CLinkedTypefaceGroup::NewLC(10);
1.234 + const TInt KPercentageValue = 50;
1.235 + TInt ret;
1.236 +
1.237 + grp->SetBoldnessPercentage(KPercentageValue);
1.238 + ret = grp->BoldnessPercentage();
1.239 + TEST2(ret, KPercentageValue);
1.240 +
1.241 + grp->SetItalicAngle(KPercentageValue);
1.242 + ret = grp->ItalicAngle();
1.243 + TEST2(ret, KPercentageValue);
1.244 +
1.245 + grp->SetBaselineShift(CLinkedTypefaceGroup::ENoBaselineShift);
1.246 + CLinkedTypefaceGroup::TBaselineShift ret2 = grp->BaselineShift();
1.247 + TEST2(ret2, CLinkedTypefaceGroup::ENoBaselineShift);
1.248 +
1.249 + CleanupStack::PopAndDestroy(grp);
1.250 + }
1.251 +
1.252 +/**
1.253 +@SYMTestCaseID
1.254 +GRAPHICS-FNTSTORE-LINKEDFONTS-0002
1.255 +
1.256 +@SYMPREQ
1.257 +PREQ2146
1.258 +
1.259 +@SYMREQ
1.260 +PREQ2146
1.261 +
1.262 +@SYMTestCaseDesc
1.263 +Tests construction of a Linked Typeface specification with both valid & invalid data.
1.264 +
1.265 +@SYMTestPriority
1.266 +Critical
1.267 +
1.268 +@SYMTestStatus
1.269 +Implemented
1.270 +
1.271 +@SYMTestActions
1.272 +Tests a number of different combinations (listed) of adding, removing and updating groups and
1.273 +elements from a linked typeface specification.
1.274 +
1.275 +Tests applicable to CLinkedTypefaceGroup / CLinkedTypefaceSpecification
1.276 +
1.277 +1. Adding a valid group
1.278 +2. Adding a duplicate group
1.279 +3. Adding a group with the same Id as an existing one
1.280 +4. Removal of group
1.281 +12. Remove invalid GroupId
1.282 +13. Adding more than KMaxLinkedTypefaceGroups groups
1.283 +14. Retrieve Group with index out of bounds
1.284 +
1.285 +
1.286 +Tests applicable to CLinkedTypefaceElementSpec / CLinkedTypefaceSpecification
1.287 +
1.288 +5. Adding a valid element
1.289 +6. Adding a duplicate element
1.290 +7. Ensuring ordering of elements is as specified
1.291 +8. Ensure canonical index is correct when element moved/removed
1.292 +9. Ensuring correct error if extra canonical added
1.293 +10. Ensuring correct error if canonical activated "in-place"
1.294 +11. Removal of element
1.295 +15. Create Specification & Element with too short (0)/long (KMaxTypefaceNameLength) names.
1.296 +16. Adding more than KMaxLinkedTypefaces Elements
1.297 +17. Retrieve Typeface with index out of bounds
1.298 +
1.299 +@SYMTestExpectedResults
1.300 +The canonical index is expected to be set to the values provided through the test after the
1.301 +various operations performed. Addition & removal should provide success or fail error codes
1.302 +as indicated throughout the test. Actions are referenced within the code with expected results.
1.303 +*/
1.304 +void CTLinkedFonts2::TestLinkedClientAddAndRemoveL()
1.305 + {
1.306 + INFO_PRINTF1(_L("TestLinkedClientAddAndRemoveL"));
1.307 +
1.308 + CFbsTypefaceStore* store = CFbsTypefaceStore::NewL(NULL);
1.309 + CleanupStack::PushL(store);
1.310 +
1.311 + _LIT(KTestLinkedFont, "TestLinkedFont");
1.312 + CLinkedTypefaceSpecification* typefaceSpec =
1.313 + CLinkedTypefaceSpecification::NewLC(KTestLinkedFont);
1.314 +
1.315 + TInt canIndex = typefaceSpec->CanonicalIndex();
1.316 + TEST(canIndex == KErrNotFound);
1.317 + TRAPD(ret, typefaceSpec->RegisterLinkedTypefaceL(*store));
1.318 + TEST(ret == KErrNotFound);
1.319 +
1.320 +
1.321 + const TInt KGroup1Id = 1;
1.322 + CLinkedTypefaceGroup* group1 = CLinkedTypefaceGroup::NewLC(KGroup1Id);
1.323 + //Action 1 : Valid group
1.324 + TRAP(ret, typefaceSpec->AddLinkedTypefaceGroupL(*group1));
1.325 + TEST(ret == KErrNone);
1.326 + CleanupStack::Pop(group1);
1.327 +
1.328 + //Action 2 : Same group again
1.329 + TRAP(ret, typefaceSpec->AddLinkedTypefaceGroupL(*group1));
1.330 + TEST(ret == KErrAlreadyExists);
1.331 +
1.332 + //Action 3 : Group with existing Id
1.333 + CLinkedTypefaceGroup* duplicateGroup = CLinkedTypefaceGroup::NewLC(KGroup1Id);
1.334 + TRAP(ret, typefaceSpec->AddLinkedTypefaceGroupL(*duplicateGroup));
1.335 + TEST(ret == KErrAlreadyExists);
1.336 + CleanupStack::PopAndDestroy(duplicateGroup);
1.337 +
1.338 + //Action 1 : Valid group
1.339 + const TInt KGroup2Id = 2;
1.340 + CLinkedTypefaceGroup* group2 = CLinkedTypefaceGroup::NewLC(KGroup2Id);
1.341 + group2->SetBaselineShift(CLinkedTypefaceGroup::EBaselineShift);
1.342 + group2->SetScalingOption(CLinkedTypefaceGroup::EScalingUpOrDown);
1.343 + TRAP(ret, typefaceSpec->AddLinkedTypefaceGroupL(*group2));
1.344 + TEST(ret == KErrNone);
1.345 + CleanupStack::Pop(group2);
1.346 +
1.347 + const TInt KGroup3Id = 4;
1.348 + CLinkedTypefaceGroup* group3 = CLinkedTypefaceGroup::NewLC(KGroup3Id);
1.349 + TRAP(ret, typefaceSpec->AddLinkedTypefaceGroupL(*group3));
1.350 + TEST(ret == KErrNone);
1.351 + CleanupStack::Pop(group3);
1.352 +
1.353 + //Action 5 : Japanese typefaces
1.354 + _LIT(KJapaneseElement, "Japanese");
1.355 + CLinkedTypefaceElementSpec* element1 = CLinkedTypefaceElementSpec::NewLC(KJapaneseElement, KGroup2Id);
1.356 + TRAP(ret, typefaceSpec->AddTypefaceAtBackL(*element1));
1.357 + CleanupStack::Pop(element1);
1.358 +
1.359 + //Action 5: Add the canonical element (Latin)
1.360 + _LIT(KLatinElement, "DejaVu Sans Mono Bold");
1.361 + CLinkedTypefaceElementSpec* element2 = CLinkedTypefaceElementSpec::NewLC(KLatinElement, KGroup1Id);
1.362 + element2->SetCanonical(ETrue);
1.363 +
1.364 + TRAP(ret, typefaceSpec->AddTypefaceAtIndexL(*element2,0));
1.365 + TEST(ret == KErrNone);
1.366 + CleanupStack::Pop(element2);
1.367 +
1.368 + //Action 8 : Check Canonical Index is correct
1.369 + canIndex = typefaceSpec->CanonicalIndex();
1.370 + TEST(canIndex == 0);
1.371 +
1.372 + //Action 5 : Hindi typefaces
1.373 + _LIT(KHindiElement, "Chandas");
1.374 + CLinkedTypefaceElementSpec* element3 = CLinkedTypefaceElementSpec::NewLC(KHindiElement, KGroup3Id);
1.375 + TRAP(ret, typefaceSpec->AddTypefaceAtBackL(*element3));
1.376 + TEST(ret == KErrNone);
1.377 + CleanupStack::Pop(element3);
1.378 +
1.379 + //Action 6 : Same element again
1.380 + TRAP(ret, typefaceSpec->AddTypefaceAtBackL(*element3));
1.381 + TEST(ret == KErrAlreadyExists);
1.382 +
1.383 + //Action 7 : Check ordering is correct
1.384 + TEST2(element1, typefaceSpec->Typeface(1));
1.385 + TEST2(element2, typefaceSpec->Typeface(0));
1.386 + TEST2(element3, typefaceSpec->Typeface(2));
1.387 +
1.388 + _LIT(KDummyTypeface, "DummyTypeface");
1.389 + CLinkedTypefaceElementSpec* dummyElement1 = CLinkedTypefaceElementSpec::NewLC(KDummyTypeface, KGroup2Id);
1.390 +
1.391 + //Action 9 : Add second canonical
1.392 + dummyElement1->SetCanonical(ETrue);
1.393 + TRAP(ret, typefaceSpec->AddTypefaceAtBackL(*dummyElement1));
1.394 + TEST(ret == KErrArgument);
1.395 +
1.396 + //Add at front of typeface to check canonical index is updated.
1.397 + dummyElement1->SetCanonical(EFalse);
1.398 + TRAP(ret, typefaceSpec->AddTypefaceAtIndexL(*dummyElement1, 0));
1.399 + TEST(ret == KErrNone);
1.400 + CleanupStack::Pop(dummyElement1);
1.401 +
1.402 + canIndex = typefaceSpec->CanonicalIndex();
1.403 + TEST(canIndex == 1);
1.404 +
1.405 + dummyElement1 = CLinkedTypefaceElementSpec::NewLC(KDummyTypeface, 180);
1.406 + TRAP(ret, typefaceSpec->AddTypefaceAtIndexL(*dummyElement1, 0));
1.407 + TEST(ret == KErrArgument);
1.408 + CleanupStack::PopAndDestroy(dummyElement1);
1.409 +
1.410 + //Action 11 : Remove Element
1.411 + typefaceSpec->RemoveTypeface(0);
1.412 + TEST2(element2, typefaceSpec->Typeface(0));
1.413 +
1.414 + //Action 8 : Check canonical index is correct
1.415 + canIndex = typefaceSpec->CanonicalIndex();
1.416 + TEST(canIndex == 0);
1.417 +
1.418 + //Action 10 : Check error if extra canonical activated "in place"
1.419 + typefaceSpec->Typeface(1)->SetCanonical(ETrue);
1.420 + canIndex = typefaceSpec->CanonicalIndex();
1.421 + TEST(canIndex == KErrOverflow);
1.422 + TRAP(ret, typefaceSpec->RegisterLinkedTypefaceL(*store));
1.423 + TEST(ret == KErrOverflow);
1.424 + //Reset back to be non-canonical
1.425 + typefaceSpec->Typeface(1)->SetCanonical(EFalse);
1.426 +
1.427 + //Action 8 : Check canonical index is correct
1.428 + typefaceSpec->RemoveTypeface(0);
1.429 + TEST2(element1, typefaceSpec->Typeface(0));
1.430 +
1.431 + //Action 8 : Check canonical index is correct
1.432 + canIndex = typefaceSpec->CanonicalIndex();
1.433 + TEST(canIndex == -1);
1.434 +
1.435 + //Action 4 : Remove the group
1.436 + TRAP(ret, typefaceSpec->RemoveLinkedTypefaceGroup(KGroup3Id));
1.437 + TEST(ret == KErrNone);
1.438 + CLinkedTypefaceGroup* groupRet = typefaceSpec->GroupById(KGroup3Id);
1.439 + TEST(groupRet == NULL);
1.440 +
1.441 + TEST2(element1, typefaceSpec->Typeface(0));
1.442 +
1.443 + //Action 12 : Remove invalid group
1.444 + ret = typefaceSpec->RemoveLinkedTypefaceGroup(180);
1.445 + TEST(ret == KErrNotFound);
1.446 + //Action 4 : Remove group
1.447 + ret = typefaceSpec->RemoveLinkedTypefaceGroup(KGroup1Id);
1.448 + TEST(ret == KErrNone);
1.449 + groupRet = typefaceSpec->GroupById(KGroup1Id);
1.450 + TEST(groupRet == NULL);
1.451 +
1.452 + CleanupStack::PopAndDestroy(typefaceSpec);
1.453 +
1.454 + //Negative Name length tests
1.455 + _LIT(KEmptyTypefaceName, "");
1.456 + //Action 15 : Create Specification & Element with 0 length names
1.457 + TRAP(ret, typefaceSpec = CLinkedTypefaceSpecification::NewLC(KEmptyTypefaceName));
1.458 + TEST(ret == KErrArgument);
1.459 + TRAP(ret, dummyElement1 = CLinkedTypefaceElementSpec::NewLC(KEmptyTypefaceName,1));
1.460 + TEST(ret < KErrNone);
1.461 + //Action 15: Create Specification & Element with name longer than KMaxTypefaceNameLength
1.462 + _LIT(KLongTypefaceName, "KErrArgumentKErrArgumentKErrArgument");
1.463 + TRAP(ret, typefaceSpec = CLinkedTypefaceSpecification::NewLC(KLongTypefaceName));
1.464 + TEST(ret == KErrArgument);
1.465 + TRAP(ret, dummyElement1 = CLinkedTypefaceElementSpec::NewLC(KLongTypefaceName,1));
1.466 + TEST(ret < KErrNone);
1.467 +
1.468 + typefaceSpec = CLinkedTypefaceSpecification::NewLC(KTestLinkedFont);
1.469 + TInt i;
1.470 + for (i = 0 ; i <= KMaxLinkedTypefaceGroups+1 ; i++)
1.471 + {
1.472 + CLinkedTypefaceGroup* group = CLinkedTypefaceGroup::NewLC(i);
1.473 +
1.474 + if (i < KMaxLinkedTypefaceGroups)
1.475 + {
1.476 + //Add Groups 1-KMaxLinkedTypefaceGroups
1.477 + TRAP(ret, typefaceSpec->AddLinkedTypefaceGroupL(*group));
1.478 + CleanupStack::Pop(group);
1.479 + }
1.480 + else
1.481 + {
1.482 + //Action 13 : Add group at KMaxLinkedTypefaceGroups+1
1.483 + TRAP(ret, typefaceSpec->AddLinkedTypefaceGroupL(*group));
1.484 + TEST(ret == KErrOverflow);
1.485 + CleanupStack::PopAndDestroy(group);
1.486 + }
1.487 + }
1.488 +
1.489 + _LIT(KFormatElementName, "Element%d");
1.490 + for (i = 0 ; i <= KMaxLinkedTypefaces ; i++)
1.491 + {
1.492 + TBuf<18> elementName;
1.493 + elementName.Format(KFormatElementName,i);
1.494 + CLinkedTypefaceElementSpec* element = CLinkedTypefaceElementSpec::NewLC(elementName,i);
1.495 + if (i < KMaxLinkedTypefaces)
1.496 + {
1.497 + //Add Elements 1-KMaxLinkedTypefaces
1.498 + TRAP(ret,typefaceSpec->AddTypefaceAtBackL(*element));
1.499 + CleanupStack::Pop(element);
1.500 + }
1.501 + else
1.502 + {
1.503 + //Action 16 : Add element KMaxLinkedTypefaces+1
1.504 + TRAP(ret,typefaceSpec->AddTypefaceAtBackL(*element));
1.505 + TEST(ret == KErrOverflow);
1.506 + CleanupStack::PopAndDestroy(element);
1.507 + }
1.508 + }
1.509 +
1.510 + //Action 14 : Retrieve out of bounds groups
1.511 + TEST2(typefaceSpec->Group(-1), NULL);
1.512 + TEST2(typefaceSpec->Group(typefaceSpec->GroupCount()+1), NULL);
1.513 + //Action 17 : Retrieve typeface with index out of bounds
1.514 + TEST2(typefaceSpec->Typeface(-1), NULL);
1.515 + TEST2(typefaceSpec->Typeface(typefaceSpec->TypefaceCount()+1), NULL);
1.516 + //Action 11 : Remove typeface with index out of bounds
1.517 + TEST2(typefaceSpec->RemoveTypeface(-1), KErrNotFound);
1.518 + TEST2(typefaceSpec->RemoveTypeface(typefaceSpec->TypefaceCount()+1), KErrNotFound);
1.519 +
1.520 + CleanupStack::PopAndDestroy(2, store);
1.521 + }
1.522 +
1.523 +/**
1.524 +@SYMTestCaseID
1.525 +GRAPHICS-FNTSTORE-LINKEDFONTS-0003
1.526 +
1.527 +@SYMPREQ
1.528 +PREQ2146
1.529 +
1.530 +@SYMREQ
1.531 +PREQ2146
1.532 +
1.533 +@SYMTestCaseDesc
1.534 +Tests the Add & RemoveTypeface functions provided by COpenFontLinkedTypefaceSpecification
1.535 +
1.536 +@SYMTestPriority
1.537 +Critical
1.538 +
1.539 +@SYMTestStatus
1.540 +Implemented
1.541 +
1.542 +@SYMTestActions
1.543 +Tests applicable to CLinkedTypefaceGroup / COpenFontLinkedTypefaceSpecification
1.544 +
1.545 +1. Adding a valid group
1.546 +2. Adding a duplicate group (same object)
1.547 +3. Adding a group with the same Id as an existing one
1.548 +4. Removal of group
1.549 +12. Remove invalid GroupId
1.550 +13. Adding more than KMaxLinkedTypefaceGroups groups
1.551 +14. Retrieve Group with index out of bounds
1.552 +
1.553 +Tests applicable to COpenFontLinkedTypefaceElementSpec / COpenFontLinkedTypefaceSpecification
1.554 +
1.555 +5. Adding a valid element
1.556 +6. Adding a duplicate element (same object)
1.557 +7. Ensuring ordering of elements is as specified
1.558 +8. Ensure canonical index is correct when element moved/removed
1.559 +9. Ensuring correct error if extra canonical added
1.560 +10. Ensuring correct error if canonical activated "in-place"
1.561 +11. Removal of element
1.562 +15. Create Specification & Element with too short (0)/long (KMaxTypefaceNameLength) names.
1.563 +16. Adding more than KMaxLinkedTypefaces Elements
1.564 +17. Retrieve Typeface with index out of bounds
1.565 +
1.566 +@SYMTestExpectedResults
1.567 +The canonical index is expected to be set to the values provided through the test after the
1.568 +various operations performed. Addition & removal should provide success or fail error codes
1.569 +as indicated throughout the test. Actions are referenced within the code with expected results.
1.570 +*/
1.571 +void CTLinkedFonts2::TestOpenClientAddAndRemoveL()
1.572 + {
1.573 + INFO_PRINTF1(_L("TestOpenClientAddAndRemoveL"));
1.574 +
1.575 + _LIT(KTestLinkedFont, "TestLinkedFont");
1.576 + COpenFontLinkedTypefaceSpecification* typefaceSpec =
1.577 + COpenFontLinkedTypefaceSpecification::NewLC(KTestLinkedFont);
1.578 +
1.579 + TInt canIndex = typefaceSpec->CanonicalIndex();
1.580 + TEST(canIndex == -1);
1.581 +
1.582 + TInt ret;
1.583 +
1.584 + //Action 1 : Add a valid group
1.585 + const TInt KGroup1Id = 1;
1.586 + CLinkedTypefaceGroup* group1 = CLinkedTypefaceGroup::NewLC(KGroup1Id);
1.587 + TRAP(ret, typefaceSpec->AddLinkedTypefaceGroupL(*group1));
1.588 + TEST(ret == KErrNone);
1.589 + CleanupStack::Pop(group1);
1.590 +
1.591 + //Action 2 : Add a duplicate group
1.592 + TRAP(ret, typefaceSpec->AddLinkedTypefaceGroupL(*group1));
1.593 + TEST(ret == KErrAlreadyExists);
1.594 +
1.595 + //Action 3 : Add a group with the same id
1.596 + CLinkedTypefaceGroup* duplicateGroup = CLinkedTypefaceGroup::NewLC(KGroup1Id);
1.597 + TRAP(ret, typefaceSpec->AddLinkedTypefaceGroupL(*duplicateGroup));
1.598 + TEST(ret == KErrAlreadyExists);
1.599 + CleanupStack::PopAndDestroy(duplicateGroup);
1.600 +
1.601 + //Action 5 : Add a valid element
1.602 + const TInt KGroup2Id = 2;
1.603 + CLinkedTypefaceGroup* group2 = CLinkedTypefaceGroup::NewLC(KGroup2Id);
1.604 + group2->SetBaselineShift(CLinkedTypefaceGroup::EBaselineShift);
1.605 + group2->SetScalingOption(CLinkedTypefaceGroup::EScalingUpOrDown);
1.606 + TRAP(ret, typefaceSpec->AddLinkedTypefaceGroupL(*group2));
1.607 + TEST(ret == KErrNone);
1.608 + CleanupStack::Pop(group2);
1.609 +
1.610 + const TInt KGroup3Id = 4;
1.611 + CLinkedTypefaceGroup* group3 = CLinkedTypefaceGroup::NewLC(KGroup3Id);
1.612 + TRAP(ret, typefaceSpec->AddLinkedTypefaceGroupL(*group3));
1.613 + TEST(ret == KErrNone);
1.614 + CleanupStack::Pop(group3);
1.615 +
1.616 + //Action 5 : Add a valid element
1.617 + _LIT(KJapaneseElement, "Japanese");
1.618 + COpenFontLinkedTypefaceElementSpec* element1 = COpenFontLinkedTypefaceElementSpec::NewLC(KJapaneseElement, KGroup2Id);
1.619 + TRAP(ret, typefaceSpec->AddTypefaceAtBackL(*element1));
1.620 + CleanupStack::Pop(element1);
1.621 +
1.622 + //Action 5 : Add a valid element
1.623 + _LIT(KLatinElement, "DejaVu Sans Mono Bold");
1.624 + COpenFontLinkedTypefaceElementSpec* element2 = COpenFontLinkedTypefaceElementSpec::NewLC(KLatinElement, KGroup1Id);
1.625 + element2->SetCanonical(ETrue);
1.626 +
1.627 + TRAP(ret, typefaceSpec->AddTypefaceAtIndexL(*element2,0));
1.628 + TEST(ret == KErrNone);
1.629 + CleanupStack::Pop(element2);
1.630 +
1.631 + //Action 8 : Ensure canonical index correct
1.632 + canIndex = typefaceSpec->CanonicalIndex();
1.633 + TEST(canIndex == 0);
1.634 +
1.635 + _LIT(KHindiElement, "Chandas");
1.636 + COpenFontLinkedTypefaceElementSpec* element3 = COpenFontLinkedTypefaceElementSpec::NewLC(KHindiElement, KGroup3Id);
1.637 + TRAP(ret, typefaceSpec->AddTypefaceAtBackL(*element3));
1.638 + TEST(ret == KErrNone);
1.639 + CleanupStack::Pop(element3);
1.640 +
1.641 + //Action 6 : Duplicate element
1.642 + TRAP(ret, typefaceSpec->AddTypefaceAtBackL(*element3));
1.643 + TEST(ret == KErrAlreadyExists);
1.644 +
1.645 + //Action 7 : Ensure ordering correct
1.646 + TEST2(element1, typefaceSpec->Typeface(1));
1.647 + TEST2(element2, typefaceSpec->Typeface(0));
1.648 + TEST2(element3, typefaceSpec->Typeface(2));
1.649 +
1.650 + _LIT(KDummyTypeface, "DummyTypeface");
1.651 + COpenFontLinkedTypefaceElementSpec* dummyElement1 = COpenFontLinkedTypefaceElementSpec::NewLC(KDummyTypeface, KGroup2Id);
1.652 +
1.653 + //Action 9 : Add 2nd canonical
1.654 + dummyElement1->SetCanonical(ETrue);
1.655 + TRAP(ret, typefaceSpec->AddTypefaceAtBackL(*dummyElement1));
1.656 + TEST(ret == KErrArgument);
1.657 +
1.658 + //Add at front of typeface to check canonical index is updated.
1.659 + dummyElement1->SetCanonical(EFalse);
1.660 + TRAP(ret, typefaceSpec->AddTypefaceAtIndexL(*dummyElement1, 0));
1.661 + TEST(ret == KErrNone);
1.662 + CleanupStack::Pop(dummyElement1);
1.663 +
1.664 + //Action 8 : Check canonical updated
1.665 + canIndex = typefaceSpec->CanonicalIndex();
1.666 + TEST(canIndex == 1);
1.667 +
1.668 + //Action 11 : Remove element
1.669 + typefaceSpec->RemoveTypeface(0);
1.670 + TEST2(element2, typefaceSpec->Typeface(0));
1.671 +
1.672 + //Action 8 : Check canonical updated
1.673 + canIndex = typefaceSpec->CanonicalIndex();
1.674 + TEST(canIndex == 0);
1.675 +
1.676 + //Action 10 : Additional canonical set in-place
1.677 + typefaceSpec->Typeface(1)->SetCanonical(ETrue);
1.678 + canIndex = typefaceSpec->CanonicalIndex();
1.679 + TEST(canIndex == KErrOverflow);
1.680 + typefaceSpec->Typeface(1)->SetCanonical(EFalse);
1.681 +
1.682 + //Action 11 : Remove element
1.683 + typefaceSpec->RemoveTypeface(0);
1.684 + TEST2(element1, typefaceSpec->Typeface(0));
1.685 +
1.686 + //Action 8 : Canonical updated
1.687 + canIndex = typefaceSpec->CanonicalIndex();
1.688 + TEST(canIndex == -1);
1.689 +
1.690 + //Action 4 : Remove group
1.691 + TRAP(ret, typefaceSpec->RemoveLinkedTypefaceGroup(KGroup3Id));
1.692 + TEST(ret == KErrNone);
1.693 + CLinkedTypefaceGroup* groupRet = typefaceSpec->GroupById(KGroup3Id);
1.694 + TEST(groupRet == NULL);
1.695 +
1.696 + TEST2(element1, typefaceSpec->Typeface(0));
1.697 +
1.698 + //Action 12 : Remove invalid group Id
1.699 + ret = typefaceSpec->RemoveLinkedTypefaceGroup(180);
1.700 + TEST(ret == KErrNotFound);
1.701 + ret = typefaceSpec->RemoveLinkedTypefaceGroup(KGroup1Id);
1.702 + TEST(ret == KErrNone);
1.703 +
1.704 + CleanupStack::PopAndDestroy(typefaceSpec);
1.705 +
1.706 + //Negative Name length tests
1.707 + _LIT(KEmptyTypefaceName, "");
1.708 + //Action 15 : Create Specifications
1.709 + TRAP(ret, typefaceSpec = COpenFontLinkedTypefaceSpecification::NewLC(KEmptyTypefaceName));
1.710 + TEST(ret == KErrArgument);
1.711 + TRAP(ret, dummyElement1 = COpenFontLinkedTypefaceElementSpec::NewLC(KEmptyTypefaceName,1));
1.712 + TEST(ret < KErrNone);
1.713 + _LIT(KLongTypefaceName, "KErrArgumentKErrArgumentKErrArgument");
1.714 + TRAP(ret, typefaceSpec = COpenFontLinkedTypefaceSpecification::NewLC(KLongTypefaceName));
1.715 + TEST(ret == KErrArgument);
1.716 + TRAP(ret, dummyElement1 = COpenFontLinkedTypefaceElementSpec::NewLC(KLongTypefaceName,1));
1.717 + TEST(ret < KErrNone);
1.718 +
1.719 + typefaceSpec = COpenFontLinkedTypefaceSpecification::NewLC(KTestLinkedFont);
1.720 + TInt i;
1.721 + for (i = 0 ; i <= KMaxLinkedTypefaceGroups+1 ; i++)
1.722 + {
1.723 + CLinkedTypefaceGroup* group = CLinkedTypefaceGroup::NewLC(i);
1.724 +
1.725 + if (i < KMaxLinkedTypefaceGroups)
1.726 + {
1.727 + TRAP(ret, typefaceSpec->AddLinkedTypefaceGroupL(*group));
1.728 + CleanupStack::Pop(group);
1.729 + }
1.730 + else
1.731 + {
1.732 + TRAP(ret, typefaceSpec->AddLinkedTypefaceGroupL(*group));
1.733 + TEST(ret == KErrOverflow);
1.734 + CleanupStack::PopAndDestroy(group);
1.735 + }
1.736 + }
1.737 +
1.738 + _LIT(KFormatElementName, "Element%d");
1.739 + for (i = 0 ; i <= KMaxLinkedTypefaces ; i++)
1.740 + {
1.741 + TBuf<18> elementName;
1.742 + elementName.Format(KFormatElementName,i);
1.743 + COpenFontLinkedTypefaceElementSpec* element = COpenFontLinkedTypefaceElementSpec::NewLC(elementName,i);
1.744 + if (i < KMaxLinkedTypefaces)
1.745 + {
1.746 + TRAP(ret,typefaceSpec->AddTypefaceAtBackL(*element));
1.747 + CleanupStack::Pop(element);
1.748 + }
1.749 + else
1.750 + {
1.751 + TRAP(ret,typefaceSpec->AddTypefaceAtBackL(*element));
1.752 + TEST(ret == KErrOverflow);
1.753 + CleanupStack::PopAndDestroy(element);
1.754 + }
1.755 + }
1.756 +
1.757 + TEST2(typefaceSpec->Group(-1), NULL);
1.758 + TEST2(typefaceSpec->Group(typefaceSpec->GroupCount()+1), NULL);
1.759 + TEST2(typefaceSpec->Typeface(-1), NULL);
1.760 + TEST2(typefaceSpec->Typeface(typefaceSpec->TypefaceCount()+1), NULL);
1.761 + TEST2(typefaceSpec->RemoveTypeface(-1), KErrNotFound);
1.762 + TEST2(typefaceSpec->RemoveTypeface(typefaceSpec->TypefaceCount()+1), KErrNotFound);
1.763 + CleanupStack::PopAndDestroy(typefaceSpec);
1.764 + }
1.765 +
1.766 +/* Function is used to determine if complex fonts are available. It looks for a
1.767 +test Devanagari font
1.768 +*/
1.769 +TBool CTLinkedFonts2::ComplexFontAvailable()
1.770 + {
1.771 + _LIT(KTypefaceOT, "Chandas");
1.772 +
1.773 + // Create the linked font
1.774 + TTypeface typeface;
1.775 + typeface.iName = KTypefaceOT;
1.776 + TFontSpec fs1;
1.777 + fs1.iTypeface = typeface;
1.778 + fs1.iHeight = 4;
1.779 + CFbsFont* font = NULL;
1.780 + TInt err = iDev->GetNearestFontToDesignHeightInPixels(font, fs1);
1.781 + if (font)
1.782 + {
1.783 + TFontSpec fs2 = font->FontSpecInTwips();
1.784 + iDev->ReleaseFont(font);
1.785 + if (fs2.iTypeface.iName.Compare(KTypefaceOT) == 0)
1.786 + {
1.787 + return ETrue;
1.788 + }
1.789 + }
1.790 + INFO_PRINTF1(_L("(N.B. Complex font not available so complex parts of test skipped)"));
1.791 + return EFalse;
1.792 + }
1.793 +
1.794 +/**
1.795 + @SYMTestCaseID GRAPHICS-FNTSTORE-LINKEDFONTS-0100
1.796 +
1.797 + @SYMPREQ PREQ2146
1.798 +
1.799 + @SYMREQ REQ10924, REQ10925, REQ10926
1.800 +
1.801 + @SYMTestCaseDesc To ensure that a linked typeface including a complex font can be created
1.802 + and used. Test access to characters in a complex linked font.
1.803 +
1.804 + @SYMTestPriority Critical
1.805 +
1.806 + @SYMTestStatus Implemented
1.807 +
1.808 + @SYMTestActions (1) Create a linked font with a complex typeface. Draw text,
1.809 + and compare against text drawn using a non-linked font.
1.810 +
1.811 + @SYMTestExpectedResults (1) - test allows a linked font with a complex typeface to be created
1.812 +*/
1.813 +void CTLinkedFonts2::TestComplexLinkedFontsBasicL()
1.814 + {
1.815 + INFO_PRINTF1(_L("LinkedFonts2::TestComplexLinkedFontsBasicL"));
1.816 +
1.817 + CFbsTypefaceStore* store = CFbsTypefaceStore::NewL(iDev);
1.818 + CleanupStack::PushL(store);
1.819 +
1.820 + TBool testComplex = ComplexFontAvailable();
1.821 + if (testComplex)
1.822 + {
1.823 + // Create typeface to be linked
1.824 + _LIT(KLinkedTypefaceTT, "DejaVu Sans Condensed");
1.825 + _LIT(KLinkedTypefaceOT, "Chandas");
1.826 +
1.827 + CLinkedTypefaceSpecification *typefaceSpec;
1.828 + _LIT(KLinkedTypefaceTTOT, "LinkedTypefaceComp");
1.829 +
1.830 + typefaceSpec = CLinkedTypefaceSpecification::NewLC(KLinkedTypefaceTTOT);
1.831 +
1.832 + CLinkedTypefaceGroup* group1 = CLinkedTypefaceGroup::NewLC(1);
1.833 + typefaceSpec->AddLinkedTypefaceGroupL(*group1);
1.834 + CleanupStack::Pop();
1.835 +
1.836 + CLinkedTypefaceGroup* group2 = CLinkedTypefaceGroup::NewLC(2);
1.837 + typefaceSpec->AddLinkedTypefaceGroupL(*group2);
1.838 + CleanupStack::Pop();
1.839 +
1.840 + // Add first typeface
1.841 + CLinkedTypefaceElementSpec *elementSpec1;
1.842 + elementSpec1 = CLinkedTypefaceElementSpec::NewLC(KLinkedTypefaceTT, 1);
1.843 +
1.844 + CLinkedTypefaceElementSpec *elementSpec2;
1.845 + elementSpec2 = CLinkedTypefaceElementSpec::NewLC(KLinkedTypefaceOT, 2);
1.846 + elementSpec2->SetCanonical(ETrue);
1.847 +
1.848 + typefaceSpec->AddTypefaceAtBackL(*elementSpec1);
1.849 + typefaceSpec->AddTypefaceAtBackL(*elementSpec2);
1.850 + CleanupStack::Pop(2, elementSpec1);
1.851 +
1.852 + TEST(typefaceSpec->TypefaceCount() == 2);
1.853 + TEST(typefaceSpec->Name() == KLinkedTypefaceTTOT);
1.854 +
1.855 + // Now try registering the linked typeface
1.856 + TRAPD(ret, typefaceSpec->RegisterLinkedTypefaceL(*store));
1.857 +
1.858 + if (ret == KErrNotSupported)
1.859 + {
1.860 + INFO_PRINTF1(_L("No Rasterizer is present that supports the extended Font Linking interface. This test case has been skipped."));
1.861 + CleanupStack::PopAndDestroy(2,store);
1.862 + }
1.863 + else
1.864 + {
1.865 + TEST(ret == KErrNone);
1.866 +
1.867 + // Create the linked font
1.868 + TTypeface typeface;
1.869 + typeface.iName = KLinkedTypefaceTTOT;
1.870 + TFontSpec fs;
1.871 + fs.iTypeface = typeface;
1.872 + fs.iHeight = 35;
1.873 + CFbsFont* font = NULL;
1.874 + TInt err = iDev->GetNearestFontToDesignHeightInPixels(font, fs);
1.875 +
1.876 + //check the font is the one requested
1.877 + TFontSpec fontSpec = font->FontSpecInTwips();
1.878 + TEST(fontSpec.iTypeface.iName == KLinkedTypefaceTTOT);
1.879 +
1.880 + _LIT16(KEnglish1,"ABCD12345 ");
1.881 + _LIT16(KHindi1,"\x0915\x094D\x0937\x0924\x094D\x0930\x093F\x092F\x0020");
1.882 + TEST(font != NULL);
1.883 + const TPoint englishLinked(10,75);
1.884 + const TPoint hindiLinked(10,150);
1.885 + if (font)
1.886 + {
1.887 + // Use the font
1.888 + iGc->UseFont(font);
1.889 + iGc->Clear();
1.890 + iGc->DrawText(KEnglish1, englishLinked);
1.891 + iGc->DrawText(KHindi1, hindiLinked);
1.892 + iGc->DiscardFont();
1.893 + iDev->Update();
1.894 + User::After(1000*1000*5);
1.895 + }
1.896 +
1.897 + // All the CFont functions can use a linked font and a non-linked
1.898 + // font - with the same base font, results should be the same.
1.899 + // Compare with the test function.
1.900 +
1.901 + //output the Hindi text
1.902 + TTypeface typeface2;
1.903 + typeface2.iName = KLinkedTypefaceOT;
1.904 + TFontSpec fs2;
1.905 + fs2.iTypeface = typeface2;
1.906 + fs2.iHeight = 35;
1.907 + CFbsFont* font2 = NULL;
1.908 + err = iDev->GetNearestFontToDesignHeightInPixels(font2, fs2);
1.909 + TEST(font2 != NULL);
1.910 +
1.911 + //check the font is the one requested
1.912 + fontSpec = font2->FontSpecInTwips();
1.913 + TEST(fontSpec.iTypeface.iName == KLinkedTypefaceOT);
1.914 +
1.915 + const TPoint englishHindiFont(240, 75);
1.916 + const TPoint hindiHindiFont(240, 150);
1.917 + if (font2)
1.918 + {
1.919 + // Use the font
1.920 + iGc->UseFont(font2);
1.921 + iGc->DrawText(KEnglish1, englishHindiFont);
1.922 + iGc->DrawText(KHindi1, hindiHindiFont);
1.923 + iGc->DiscardFont();
1.924 + iDev->Update();
1.925 + User::After(1000*1000);
1.926 + iDev->ReleaseFont(font2);
1.927 + }
1.928 +
1.929 + //output the English text
1.930 + TTypeface typeface3;
1.931 + typeface3.iName = KLinkedTypefaceTT;
1.932 + TFontSpec fs3;
1.933 + fs3.iTypeface = typeface3;
1.934 + fs3.iHeight = 35;
1.935 + CFbsFont* font3 = NULL;
1.936 + err = iDev->GetNearestFontToDesignHeightInPixels(font3, fs3);
1.937 + TEST(font3 != NULL);
1.938 +
1.939 + //check the font is the one requested
1.940 + fontSpec = font3->FontSpecInTwips();
1.941 + TEST(fontSpec.iTypeface.iName == KLinkedTypefaceTT);
1.942 +
1.943 + const TPoint englishSansSerifFont(440, 75);
1.944 + const TPoint hindiSansSerifFont(440, 150);
1.945 + if (font3)
1.946 + {
1.947 + // Use the font
1.948 + iGc->UseFont(font3);
1.949 + iGc->DrawText(KEnglish1, englishSansSerifFont);
1.950 + iGc->DrawText(KHindi1, hindiSansSerifFont);
1.951 + iGc->DiscardFont();
1.952 + iDev->Update();
1.953 + User::After(1000*1000);
1.954 + iDev->ReleaseFont(font3);
1.955 + }
1.956 +
1.957 + //compare rects.
1.958 + if (font)
1.959 + {
1.960 + CFont::TMeasureTextOutput compareEnglish;
1.961 + CFont::TMeasureTextOutput compareHindi;
1.962 + //get the size of a text box to do the comparison
1.963 + font->MeasureText(KEnglish1, NULL, &compareEnglish);
1.964 + font->MeasureText(KHindi1, NULL, &compareHindi);
1.965 +
1.966 + //compare English
1.967 + TRect englishLinkedRect (englishLinked.iX,englishLinked.iY,
1.968 + englishLinked.iX+compareEnglish.iBounds.Width(),
1.969 + englishLinked.iY+compareEnglish.iBounds.Height());
1.970 + TRect englishSansSerifRect (englishSansSerifFont.iX,englishSansSerifFont.iY,
1.971 + englishSansSerifFont.iX+compareEnglish.iBounds.Width(),
1.972 + englishSansSerifFont.iY+compareEnglish.iBounds.Height());
1.973 +
1.974 + TBool val = iDev->RectCompare(englishLinkedRect, *iDev,englishSansSerifRect);
1.975 + //this value is not compared since the rasterizer may resize/reposition fonts
1.976 +
1.977 + //compare Hindi
1.978 + TRect hindiLinkedRect (hindiLinked.iX,hindiLinked.iY,
1.979 + hindiLinked.iX+compareHindi.iBounds.Width(),
1.980 + hindiLinked.iY+compareHindi.iBounds.Height());
1.981 + TRect hindiHindiRect (hindiHindiFont.iX,hindiHindiFont.iY,
1.982 + hindiHindiFont.iX+compareHindi.iBounds.Width(),
1.983 + hindiHindiFont.iY+compareHindi.iBounds.Height());
1.984 + val=iDev->RectCompare(hindiLinkedRect, *iDev,hindiHindiRect);
1.985 + //do not call TEST(val) since size/position may be slightly different
1.986 + iDev->ReleaseFont(font);
1.987 + }
1.988 + CleanupStack::PopAndDestroy(2, store);
1.989 + }
1.990 + }
1.991 + }
1.992 +
1.993 +/**
1.994 + @SYMTestCaseID GRAPHICS-FNTSTORE-LINKEDFONTS-0101
1.995 +
1.996 + @SYMPREQ PREQ2146
1.997 +
1.998 + @SYMREQ REQ10924, REQ10925, REQ10926
1.999 +
1.1000 + @SYMTestCaseDesc To test PREQ2146 linked fonts with bitmap fonts. Bitmap fonts are not
1.1001 + supported so an error needs to be returned on registration.
1.1002 +
1.1003 + @SYMTestPriority Critical
1.1004 +
1.1005 + @SYMTestStatus Implemented
1.1006 +
1.1007 + @SYMTestActions (1) Create a linked typeface elements, with one of them from a bitmap font
1.1008 + try registering, and KErrNotSupported error should be returned
1.1009 +
1.1010 + @SYMTestExpectedResults (1) - registering a bitmap font returns KErrNotSupported.
1.1011 +*/
1.1012 +void CTLinkedFonts2::TestBitmapFontsL()
1.1013 + {
1.1014 + INFO_PRINTF1(_L("LinkedFonts2::TestBitmapFontsL"));
1.1015 +
1.1016 + CFbsTypefaceStore* store = CFbsTypefaceStore::NewL(iDev);
1.1017 + CleanupStack::PushL(store);
1.1018 +
1.1019 + // Create typeface to be linked
1.1020 + _LIT(KLinkedTypefaceTT, "DejaVu Sans Condensed");
1.1021 + _LIT(KLinkedTypeFace1, "LinkedFont1"); //this is a bitmap font
1.1022 +
1.1023 + CLinkedTypefaceSpecification *typefaceSpec;
1.1024 + _LIT(KLinkedTypefaceBitmap, "LinkedTypefaceBitmap");
1.1025 +
1.1026 + typefaceSpec = CLinkedTypefaceSpecification::NewLC(KLinkedTypefaceBitmap);
1.1027 +
1.1028 + CLinkedTypefaceGroup* group1 = CLinkedTypefaceGroup::NewLC(1);
1.1029 + typefaceSpec->AddLinkedTypefaceGroupL(*group1);
1.1030 + CleanupStack::Pop();
1.1031 +
1.1032 + CLinkedTypefaceGroup* group2 = CLinkedTypefaceGroup::NewLC(2);
1.1033 + typefaceSpec->AddLinkedTypefaceGroupL(*group2);
1.1034 + CleanupStack::Pop();
1.1035 +
1.1036 + // Add first typeface
1.1037 + CLinkedTypefaceElementSpec *elementSpec1;
1.1038 + elementSpec1 = CLinkedTypefaceElementSpec::NewLC(KLinkedTypefaceTT, 2);
1.1039 +
1.1040 + CLinkedTypefaceElementSpec *elementSpec2;
1.1041 + elementSpec2 = CLinkedTypefaceElementSpec::NewLC(KLinkedTypeFace1, 1);
1.1042 + elementSpec2->SetCanonical(ETrue);
1.1043 +
1.1044 + typefaceSpec->AddTypefaceAtBackL(*elementSpec1);
1.1045 + typefaceSpec->AddTypefaceAtBackL(*elementSpec2);
1.1046 + CleanupStack::Pop(2, elementSpec1);
1.1047 +
1.1048 + TEST(typefaceSpec->TypefaceCount() == 2);
1.1049 + TEST(typefaceSpec->Name() == KLinkedTypefaceBitmap);
1.1050 +
1.1051 + // Now try regstering the linked typeface
1.1052 + TRAPD(ret, typefaceSpec->RegisterLinkedTypefaceL(*store));
1.1053 + TEST(ret == KErrNotSupported);
1.1054 + CleanupStack::PopAndDestroy(2, store);
1.1055 + }
1.1056 +
1.1057 +/**
1.1058 + @SYMTestCaseID GRAPHICS-FNTSTORE-LINKEDFONTS-0109
1.1059 +
1.1060 + @SYMPREQ PREQ2146
1.1061 +
1.1062 + @SYMREQ REQ10924, REQ10925, REQ10926
1.1063 +
1.1064 + @SYMTestCaseDesc To test PREQ2146 linked fonts updates to the TOpenFontCharMetrics class.
1.1065 +
1.1066 + @SYMTestPriority Critical
1.1067 +
1.1068 + @SYMTestStatus Implemented
1.1069 +
1.1070 + @SYMTestActions (1) Create a TOpenFontCharMetrics object.
1.1071 + (2) Check that nothing is set
1.1072 + (3) Set a small positive baseline
1.1073 + (4) Check that the baseline is as set and the glyph type is still not set
1.1074 + (5) Set a large positive baseline
1.1075 + (6) Check that the baseline is as set and the glyph type is still not set
1.1076 + (7) Set a large negative baseline
1.1077 + (8) Check that the baseline is as set and the glyph type is still not set
1.1078 + (9) Set the glyph type.
1.1079 + (10) Check that the baseline is as set and the glyph type is as set
1.1080 + (11) Set the baseline to a again to various values
1.1081 + (12) Check that the baseline is as set and the glyph type has not changed
1.1082 +
1.1083 + @SYMTestExpectedResults (2) the default values are 0 for baseline and EGlyphBitmapTypeNotDefined for glyph type
1.1084 + (4)(6)(8)(10)(12) The values are are set, and setting the baseline does
1.1085 + not alter the glyph type and vice-versa.
1.1086 +*/
1.1087 +void CTLinkedFonts2::TestTOpenFontMetrics()
1.1088 + {
1.1089 + TOpenFontMetrics metrics;
1.1090 +
1.1091 + TInt len = metrics.BaselineCorrection();
1.1092 + TEST(len==0);
1.1093 +
1.1094 + metrics.SetBaselineCorrection(22);
1.1095 + len = metrics.BaselineCorrection();
1.1096 + TEST(len==22);
1.1097 +
1.1098 + metrics.SetBaselineCorrection(444);
1.1099 + len = metrics.BaselineCorrection();
1.1100 + TEST(len==444);
1.1101 +
1.1102 + metrics.SetBaselineCorrection(-333);
1.1103 + len = metrics.BaselineCorrection();
1.1104 + TEST(len==-333);
1.1105 +
1.1106 + metrics.SetBaselineCorrection(444);
1.1107 + len = metrics.BaselineCorrection();
1.1108 + TEST(len==444);
1.1109 +
1.1110 + metrics.SetBaselineCorrection(-1);
1.1111 + len = metrics.BaselineCorrection();
1.1112 + TEST(len==-1);
1.1113 +
1.1114 + }
1.1115 +
1.1116 +void CTLinkedFonts2::TestLinkedRegistrationAndFetchL()
1.1117 + {
1.1118 + INFO_PRINTF1(_L("CTLinkedFonts2::TestLinkedRegistrationAndFetchL"));
1.1119 + CFbsTypefaceStore* store = CFbsTypefaceStore::NewL(iDev);
1.1120 + CleanupStack::PushL(store);
1.1121 +
1.1122 + //Create and register a dummy linked typeface to register.
1.1123 + _LIT(KFetchTypefaceName, "FetchFont");
1.1124 + CLinkedTypefaceSpecification* typefaceSpec = CLinkedTypefaceSpecification::NewLC(KFetchTypefaceName);
1.1125 +
1.1126 + CLinkedTypefaceGroup* group1 = CLinkedTypefaceGroup::NewLC(1);
1.1127 + group1->SetBoldnessPercentage(20);
1.1128 + group1->SetItalicAngle(10);
1.1129 + group1->SetBaselineShift(CLinkedTypefaceGroup::EBaselineShift);
1.1130 + group1->SetScalingOption(CLinkedTypefaceGroup::EScalingDown);
1.1131 +
1.1132 + typefaceSpec->AddLinkedTypefaceGroupL(*group1);
1.1133 + CleanupStack::Pop(group1);
1.1134 +
1.1135 + CLinkedTypefaceGroup* group2 = CLinkedTypefaceGroup::NewLC(2);
1.1136 + group2->SetBoldnessPercentage(21);
1.1137 + group2->SetItalicAngle(11);
1.1138 + group2->SetBaselineShift(CLinkedTypefaceGroup::ENoBaselineShift);
1.1139 + group2->SetScalingOption(CLinkedTypefaceGroup::EScalingUp);
1.1140 +
1.1141 + typefaceSpec->AddLinkedTypefaceGroupL(*group2);
1.1142 + CleanupStack::Pop(group2);
1.1143 +
1.1144 + _LIT(KElement1Name, "DejaVu Sans Condensed");
1.1145 + CLinkedTypefaceElementSpec* element1 = CLinkedTypefaceElementSpec::NewLC(KElement1Name, 1);
1.1146 + element1->SetCanonical(ETrue);
1.1147 + typefaceSpec->AddTypefaceAtBackL(*element1);
1.1148 + CleanupStack::Pop(element1);
1.1149 +
1.1150 + _LIT(KElement2Name, "Chandas");
1.1151 + CLinkedTypefaceElementSpec* element2 = CLinkedTypefaceElementSpec::NewLC(KElement2Name, 2);
1.1152 + typefaceSpec->AddTypefaceAtBackL(*element2);
1.1153 + CleanupStack::Pop(element2);
1.1154 +
1.1155 + TRAPD(ret, typefaceSpec->RegisterLinkedTypefaceL(*store));
1.1156 + if (ret == KErrNotSupported)
1.1157 + {
1.1158 + INFO_PRINTF1(_L("No Rasterizer is present that supports the extended Font Linking interface. This test case has been skipped."));
1.1159 + CleanupStack::PopAndDestroy(2,store);
1.1160 + }
1.1161 + else
1.1162 + {
1.1163 + TEST(ret == KErrNone);
1.1164 +
1.1165 + CLinkedTypefaceSpecification* fetchSpec = CLinkedTypefaceSpecification::NewLC(KFetchTypefaceName);
1.1166 + TRAP(ret, fetchSpec->FetchLinkedTypefaceSpecificationL(*store));
1.1167 + TEST(ret == KErrNone);
1.1168 +
1.1169 + //Compare Groups. Ordering isn't important so can get group by id rather than index.
1.1170 + TEST(typefaceSpec->GroupCount() == fetchSpec->GroupCount());
1.1171 + CLinkedTypefaceGroup* groupf = fetchSpec->GroupById(1);
1.1172 + TEST(CompareGroups(group1,groupf));
1.1173 +
1.1174 + groupf = fetchSpec->GroupById(2);
1.1175 + TEST(CompareGroups(group2,groupf));
1.1176 +
1.1177 + //Check elements match
1.1178 + TEST(typefaceSpec->TypefaceCount() == fetchSpec->TypefaceCount());
1.1179 +
1.1180 + CLinkedTypefaceElementSpec* elementf = fetchSpec->Typeface(0);
1.1181 + TEST(CompareElementSpecs(elementf, element1));
1.1182 + elementf = fetchSpec->Typeface(1);
1.1183 + TEST(CompareElementSpecs(elementf, element2));
1.1184 +
1.1185 + CleanupStack::PopAndDestroy(3,store);
1.1186 + }
1.1187 + }
1.1188 +
1.1189 +/**
1.1190 + @SYMTestCaseID GRAPHICS-FNTSTORE-LINKEDFONTS-0110
1.1191 +
1.1192 + @SYMDEF DEF137360
1.1193 +
1.1194 + @SYMTestCaseDesc Ensure that font full names are used to build a linked font
1.1195 +
1.1196 + @SYMTestPriority Critical
1.1197 +
1.1198 + @SYMTestStatus Implemented
1.1199 +
1.1200 + @SYMTestActions Attempt to register a linked font using a font full name rather than a family
1.1201 + name. DejaVu Sans Condensed is both a family name and a full name. DejaVu Sans Mono Bold is full name only.
1.1202 +
1.1203 + @SYMTestExpectedResults Registration of the linked font will be sucessful.
1.1204 + Failing with KErrNotFound means either the test font is not available or there is a regression.
1.1205 +*/
1.1206 +void CTLinkedFonts2::TestFontNameUsage()
1.1207 + {
1.1208 + CFbsTypefaceStore* store = CFbsTypefaceStore::NewL(NULL);
1.1209 + CleanupStack::PushL(store);
1.1210 +
1.1211 + CLinkedTypefaceSpecification* nameSpec = CLinkedTypefaceSpecification::NewLC(_L("FullNameTest"));
1.1212 +
1.1213 + CLinkedTypefaceGroup* group = CLinkedTypefaceGroup::NewLC(1);
1.1214 + nameSpec->AddLinkedTypefaceGroupL(*group);
1.1215 + CleanupStack::Pop(group);
1.1216 +
1.1217 + //Use a font whose name doesn't match a family name
1.1218 + CLinkedTypefaceElementSpec* element1 = CLinkedTypefaceElementSpec::NewLC(_L("DejaVu Sans Mono Bold"), 1);
1.1219 + element1->SetCanonical(ETrue);
1.1220 + nameSpec->AddTypefaceAtBackL(*element1);
1.1221 + CleanupStack::Pop(element1);
1.1222 +
1.1223 + CLinkedTypefaceElementSpec* element2 = CLinkedTypefaceElementSpec::NewLC(_L("Chandas"), 1);
1.1224 + nameSpec->AddTypefaceAtBackL(*element2);
1.1225 + CleanupStack::Pop(element2);
1.1226 +
1.1227 + TRAPD(ret, store->RegisterLinkedTypeface(*nameSpec));
1.1228 +
1.1229 + TEST(ret == KErrNone);
1.1230 +
1.1231 + CleanupStack::PopAndDestroy(2, store);
1.1232 + }
1.1233 +
1.1234 +TBool CTLinkedFonts2::CompareElementSpecs(CLinkedTypefaceElementSpec* aSpec1, CLinkedTypefaceElementSpec* aSpec2)
1.1235 + {
1.1236 + if ( (aSpec1 == NULL ) && (aSpec2 == NULL) )
1.1237 + return ETrue;
1.1238 + if ( (aSpec1 == NULL) || (aSpec2 == NULL) )
1.1239 + return EFalse;
1.1240 + if (aSpec1->ElementName().Compare(aSpec2->ElementName()) != 0)
1.1241 + return EFalse;
1.1242 + if (aSpec1->Canonical() != aSpec2->Canonical())
1.1243 + return EFalse;
1.1244 + if (aSpec1->GroupId() != aSpec2->GroupId())
1.1245 + return EFalse;
1.1246 +
1.1247 + return ETrue;
1.1248 + }
1.1249 +
1.1250 +TBool CTLinkedFonts2::CompareElementSpecs(COpenFontLinkedTypefaceElementSpec* aSpec1, COpenFontLinkedTypefaceElementSpec* aSpec2)
1.1251 + {
1.1252 + if ( (aSpec1 == NULL ) && (aSpec2 == NULL) )
1.1253 + return ETrue;
1.1254 + if ( (aSpec1 == NULL) || (aSpec2 == NULL) )
1.1255 + return EFalse;
1.1256 + if (aSpec1->ElementName().Compare(aSpec2->ElementName()) != 0)
1.1257 + return EFalse;
1.1258 + if (aSpec1->Canonical() != aSpec2->Canonical())
1.1259 + return EFalse;
1.1260 + if (aSpec1->GroupId() != aSpec2->GroupId())
1.1261 + return EFalse;
1.1262 +
1.1263 + return ETrue;
1.1264 + }
1.1265 +/**
1.1266 +Compare two linked typeface groups; the first varable should be a locally created group and the second one fetched from the
1.1267 +rasterizer. If the local group has thresholds / metrics set to -1 ("best guess by rasterizer") then the differences between the
1.1268 +values are ignored.
1.1269 + */
1.1270 +TBool CTLinkedFonts2::CompareGroups(CLinkedTypefaceGroup* aLocalGroup, CLinkedTypefaceGroup* aFetchedGroup)
1.1271 + {
1.1272 + if ( (aLocalGroup == NULL) && (aFetchedGroup == NULL) )
1.1273 + return ETrue;
1.1274 + if ( (aLocalGroup == NULL) || (aFetchedGroup == NULL) )
1.1275 + {
1.1276 + INFO_PRINTF1(_L("One of the specified groups is NULL"));
1.1277 + return EFalse;
1.1278 + }
1.1279 +
1.1280 + if (aLocalGroup->BaselineShift() != aFetchedGroup->BaselineShift())
1.1281 + return EFalse;
1.1282 +
1.1283 + /*if (aLocalGroup->BoldnessPercentage() != -1)
1.1284 + {
1.1285 + if (aLocalGroup->BoldnessPercentage() != aFetchedGroup->BoldnessPercentage())
1.1286 + {
1.1287 + INFO_PRINTF1(_L("Fail below caused by non-matching boldness percentages"));
1.1288 + return EFalse;
1.1289 + }
1.1290 + }
1.1291 +
1.1292 + if (aLocalGroup->ItalicAngle() != -1)
1.1293 + {
1.1294 + if (aLocalGroup->ItalicAngle() != aFetchedGroup->ItalicAngle())
1.1295 + {
1.1296 + INFO_PRINTF1(_L("Fail below caused by non-matching italic angles"));
1.1297 + return EFalse;
1.1298 + }
1.1299 + }
1.1300 + */
1.1301 + if (aLocalGroup->ScalingOption() != aFetchedGroup->ScalingOption())
1.1302 + return EFalse;
1.1303 + if (aLocalGroup->GroupId() != aFetchedGroup->GroupId())
1.1304 + return EFalse;
1.1305 +
1.1306 + return ETrue;
1.1307 + }
1.1308 +
1.1309 +__CONSTRUCT_STEP__(LinkedFonts2)