os/textandloc/fontservices/fontstore/tfs/T_LinkedFonts2.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 /**
    20  @file
    21  @test
    22  @internalComponent
    23 */
    24 
    25 #include "T_LinkedFonts2.h"
    26 #include "linkedfontsprivate.h"
    27 #include <graphics/openfontlinkedtypefacespecification.h>
    28 #include <openfontlinkedtypefaceelementspec.h>
    29 
    30 CTLinkedFonts2::CTLinkedFonts2(CTestStep* aStep)
    31 :	CTGraphicsBase(aStep)
    32 	{
    33 	
    34 	}
    35 
    36 CTLinkedFonts2::~CTLinkedFonts2()
    37 	{
    38 	delete iGc;
    39 	delete iDev;
    40 	if (iFbs)
    41 		iFbs->Disconnect();
    42 	}
    43 
    44 void CTLinkedFonts2::TestPanic(TInt aPanic)
    45 	{
    46 	_LIT(KFntTestStorePanicCategory,"TestFntStore");
    47 	User::Panic(KFntTestStorePanicCategory,aPanic);
    48 	}
    49 
    50 void CTLinkedFonts2::RunTestCaseL(TInt aCurTestCase)
    51 	{
    52 	((CTLinkedFonts2Step*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
    53 	switch (aCurTestCase)
    54 		{
    55 		case 1:
    56 			((CTLinkedFonts2Step*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-LINKEDFONTS-0046"));
    57 			InitializeTestHarnessL();
    58 			break;
    59 		case 2:
    60 			((CTLinkedFonts2Step*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-LINKEDFONTS-0001"));
    61 			TestLinkedClientGettersAndSettersL();
    62 			break;
    63 		case 3:
    64 			((CTLinkedFonts2Step*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-LINKEDFONTS-0002"));
    65 			TestLinkedClientAddAndRemoveL();
    66 			break;
    67 		case 4:
    68 			((CTLinkedFonts2Step*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-LINKEDFONTS-0003"));
    69 			TestOpenClientAddAndRemoveL();
    70 			break;
    71 		case 5:
    72 /**
    73 @SYMTestCaseID GRAPHICS-FNTSTORE-LINKEDFONTS-0004
    74 */
    75 			((CTLinkedFonts2Step*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-LINKEDFONTS-0004"));
    76 			TestLinkedRegistrationAndFetchL();
    77 			break;
    78 		case 6:
    79 			((CTLinkedFonts2Step*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-LINKEDFONTS-0100"));
    80 			TestComplexLinkedFontsBasicL();
    81 			break;
    82 		case 7:
    83 			((CTLinkedFonts2Step*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
    84 			//((CTLinkedFonts2Step*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-LINKEDFONTS-0101"));
    85 			//TestBitmapFontsL();
    86 			break;
    87 		default:
    88 			CloseTestHarnessL();
    89 			TestComplete();
    90 			((CTLinkedFonts2Step*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
    91 			((CTLinkedFonts2Step*)iStep)->CloseTMSGraphicsStep();
    92 			break;
    93 		}
    94 	((CTLinkedFonts2Step*)iStep)->RecordTestResultL();
    95 	}
    96 
    97 /**
    98 	@SYMTestCaseID
    99 	GRAPHICS-FNTSTORE-LINKEDFONTS-0046
   100 
   101 	@SYMTestCaseDesc
   102 	Starts a server session with the font and bitmap server.
   103 
   104 	@SYMTestActions
   105 	1. Creates a session with the Font and Bitmap server.
   106 	2. Gets the current Font and Bitmap server session.
   107 	3. Creates a CFbsScreenDevice object.
   108 	4. Sets screen device to null.
   109 	5. Sets auto update to true.
   110 	6. Creates a font and bitmap server graphics context for the 
   111 	   device and activates it.
   112 	
   113 	@SYMTestExpectedResults
   114 	All steps 1-6 above succeed.  
   115 */
   116 void CTLinkedFonts2::StartServer()
   117 	{
   118 	TInt ret = RFbsSession::Connect();
   119 	TEST2(ret, KErrNone);
   120 	iFbs = RFbsSession::GetSession();
   121 	TEST(iFbs != NULL);
   122 	
   123 	if (iFbs==NULL)
   124 		{
   125 		//cannot continue
   126 		TestComplete();
   127 		return;
   128 		}
   129 
   130 	TInt err;
   131 	TDisplayMode mode[4] = {EColor16MA,EColor16MU,EColor64K,EColor16MAP};
   132 
   133 	TInt count;
   134 	for (count=0; count < (sizeof(mode)/sizeof(mode[0])) ;count++)
   135 		{
   136 		TRAP(err, iDev = CFbsScreenDevice::NewL(KNullDesC, mode[count]));
   137 		if (err!=KErrNotSupported)
   138 			{
   139 			break;
   140 			}
   141 		}
   142 
   143 	if(err == KErrNone)
   144 		{
   145 		INFO_PRINTF2(_L("%d screen mode created"),mode[count]);
   146 		iDev->ChangeScreenDevice(NULL);
   147 		iDev->SetAutoUpdate(ETrue);
   148 		iDev->CreateContext(iGc);
   149 		
   150 		//use and create a font
   151 		//otherwise for memory tests there is a leak reported since the first AllocL
   152 		//creates the space for the array (e.g. CTypefaceStore::AddFontL()) and 
   153 		//although the array is emptied the array element storage is not deleted
   154 		//until everything is closed
   155 		_LIT(KSansSerif, "DejaVu Sans Condensed");
   156 		TTypeface typeface;
   157 		typeface.iName = KSansSerif;
   158 		TFontSpec fs;
   159 		fs.iTypeface = typeface;
   160 		fs.iHeight = 20;
   161 		CFbsFont* font = NULL;
   162 		TInt err1 = iDev->GetNearestFontToDesignHeightInPixels(font, fs);
   163 		TEST(err1==KErrNone);
   164 		if (err1 == KErrNone)
   165 			{
   166 			TSize scrSize = iDev->SizeInPixels();
   167 			iGc->UseFont(font);
   168 			_LIT(KTestText,"TEST");
   169 			iGc->DrawText(KTestText, TPoint((scrSize.iWidth / 2) + 50, 50));
   170 			iGc->DiscardFont();
   171 			iDev->ReleaseFont(font);
   172 			}	
   173 		}
   174 	else
   175 		{
   176 		INFO_PRINTF2(_L("Could not create screen mode error %d"),err);
   177 		}
   178 	}
   179 
   180 
   181 void CTLinkedFonts2::InitializeTestHarnessL()
   182 	{
   183 	INFO_PRINTF1(_L("Initialising the test harness T_LinkedFonts2 (PREQ2146)"));
   184 	StartServer();
   185 	}
   186 
   187 void CTLinkedFonts2::CloseTestHarnessL()
   188 	{
   189 	}
   190 /**
   191 @SYMTestCaseID
   192 GRAPHICS-FNTSTORE-LINKEDFONTS-0001
   193 
   194 @SYMPREQ
   195 PREQ2146
   196 
   197 @SYMREQ
   198 PREQ2146
   199 
   200 @SYMTestCaseDesc
   201 Create a linked typeface element & group. Set the parameters they provide.
   202 
   203 @SYMTestPriority
   204 Critical
   205 
   206 @SYMTestStatus
   207 Implemented
   208 
   209 @SYMTestActions
   210 Tests that the values set are stored correctly by the linked typeface element & group.
   211 
   212 @SYMTestExpectedResults
   213 Values are set correctly
   214 */
   215 void CTLinkedFonts2::TestLinkedClientGettersAndSettersL()
   216 	{
   217 	INFO_PRINTF1(_L("CTLinkedFonts2::TestLinkedClientGettersAndSettersL"));
   218 	CLinkedTypefaceElementSpec *elementSpec;
   219 	_LIT(KLinkedTypefaceName, "TypefaceNumberOne");
   220 	elementSpec = CLinkedTypefaceElementSpec::NewLC(KLinkedTypefaceName, 10);
   221 	
   222 	elementSpec->SetCanonical(ETrue);
   223 	TEST(elementSpec->Canonical());
   224 	
   225 	//Test Remaining Getters & Setters
   226 	elementSpec->SetCanonical(EFalse);
   227 
   228 	CleanupStack::PopAndDestroy(elementSpec);
   229 	
   230 	CLinkedTypefaceGroup* grp = CLinkedTypefaceGroup::NewLC(10);
   231 	const TInt KPercentageValue = 50;
   232 	TInt ret;
   233 	
   234 	grp->SetBoldnessPercentage(KPercentageValue);
   235 	ret = grp->BoldnessPercentage();
   236 	TEST2(ret, KPercentageValue);
   237 	
   238 	grp->SetItalicAngle(KPercentageValue);
   239 	ret = grp->ItalicAngle();
   240 	TEST2(ret, KPercentageValue);
   241 	
   242 	grp->SetBaselineShift(CLinkedTypefaceGroup::ENoBaselineShift);
   243 	CLinkedTypefaceGroup::TBaselineShift ret2 = grp->BaselineShift();
   244 	TEST2(ret2, CLinkedTypefaceGroup::ENoBaselineShift);
   245 	
   246 	CleanupStack::PopAndDestroy(grp);
   247 	}
   248 
   249 /**
   250 @SYMTestCaseID
   251 GRAPHICS-FNTSTORE-LINKEDFONTS-0002
   252 
   253 @SYMPREQ
   254 PREQ2146
   255 
   256 @SYMREQ
   257 PREQ2146
   258 
   259 @SYMTestCaseDesc
   260 Tests construction of a Linked Typeface specification with both valid & invalid data.
   261 
   262 @SYMTestPriority
   263 Critical
   264 
   265 @SYMTestStatus
   266 Implemented
   267 
   268 @SYMTestActions
   269 Tests a number of different combinations (listed) of adding, removing and updating groups and
   270 elements from a linked typeface specification.
   271 
   272 Tests applicable to CLinkedTypefaceGroup / CLinkedTypefaceSpecification
   273 
   274 1. Adding a valid group
   275 2. Adding a duplicate group
   276 3. Adding a group with the same Id as an existing one
   277 4. Removal of group
   278 12. Remove invalid GroupId
   279 13. Adding more than KMaxLinkedTypefaceGroups groups
   280 14. Retrieve Group with index out of bounds
   281 
   282 
   283 Tests applicable to CLinkedTypefaceElementSpec / CLinkedTypefaceSpecification
   284 
   285 5. Adding a valid element
   286 6. Adding a duplicate element
   287 7. Ensuring ordering of elements is as specified
   288 8. Ensure canonical index is correct when element moved/removed
   289 9. Ensuring correct error if extra canonical added
   290 10. Ensuring correct error if canonical activated "in-place"
   291 11. Removal of element
   292 15. Create Specification & Element with too short (0)/long (KMaxTypefaceNameLength) names.
   293 16. Adding more than KMaxLinkedTypefaces Elements
   294 17. Retrieve Typeface with index out of bounds
   295 
   296 @SYMTestExpectedResults
   297 The canonical index is expected to be set to the values provided through the test after the 
   298 various operations performed. Addition & removal should provide success or fail error codes
   299 as indicated throughout the test. Actions are referenced within the code with expected results.
   300 */
   301 void CTLinkedFonts2::TestLinkedClientAddAndRemoveL()
   302 	{
   303 	INFO_PRINTF1(_L("TestLinkedClientAddAndRemoveL"));
   304 	
   305 	CFbsTypefaceStore* store = CFbsTypefaceStore::NewL(NULL);
   306 	CleanupStack::PushL(store);
   307 	
   308 	_LIT(KTestLinkedFont, "TestLinkedFont");
   309 	CLinkedTypefaceSpecification* typefaceSpec = 
   310 		CLinkedTypefaceSpecification::NewLC(KTestLinkedFont);
   311 	
   312 	TInt canIndex = typefaceSpec->CanonicalIndex();
   313 	TEST(canIndex == KErrNotFound);
   314 	TRAPD(ret, typefaceSpec->RegisterLinkedTypefaceL(*store));
   315 	TEST(ret == KErrNotFound);
   316 
   317 	
   318 	const TInt KGroup1Id = 1;
   319 	CLinkedTypefaceGroup* group1 = CLinkedTypefaceGroup::NewLC(KGroup1Id);
   320 	//Action 1 : Valid group
   321 	TRAP(ret, typefaceSpec->AddLinkedTypefaceGroupL(*group1));
   322 	TEST(ret == KErrNone);
   323 	CleanupStack::Pop(group1);
   324 	
   325 	//Action 2 : Same group again
   326 	TRAP(ret, typefaceSpec->AddLinkedTypefaceGroupL(*group1));
   327 	TEST(ret == KErrAlreadyExists);
   328 	
   329 	//Action 3 : Group with existing Id
   330 	CLinkedTypefaceGroup* duplicateGroup = CLinkedTypefaceGroup::NewLC(KGroup1Id);
   331 	TRAP(ret, typefaceSpec->AddLinkedTypefaceGroupL(*duplicateGroup));
   332 	TEST(ret == KErrAlreadyExists);
   333 	CleanupStack::PopAndDestroy(duplicateGroup);
   334 	
   335 	//Action 1 : Valid group
   336 	const TInt KGroup2Id = 2;
   337 	CLinkedTypefaceGroup* group2 = CLinkedTypefaceGroup::NewLC(KGroup2Id);
   338 	group2->SetBaselineShift(CLinkedTypefaceGroup::EBaselineShift);
   339 	group2->SetScalingOption(CLinkedTypefaceGroup::EScalingUpOrDown);
   340 	TRAP(ret, typefaceSpec->AddLinkedTypefaceGroupL(*group2));
   341 	TEST(ret == KErrNone);
   342 	CleanupStack::Pop(group2);
   343 	
   344 	const TInt KGroup3Id = 4;
   345 	CLinkedTypefaceGroup* group3 = CLinkedTypefaceGroup::NewLC(KGroup3Id);
   346 	TRAP(ret, typefaceSpec->AddLinkedTypefaceGroupL(*group3));
   347 	TEST(ret == KErrNone);
   348 	CleanupStack::Pop(group3);
   349 	
   350 	//Action 5 : Japanese typefaces
   351 	_LIT(KJapaneseElement, "Japanese");
   352 	CLinkedTypefaceElementSpec* element1 = CLinkedTypefaceElementSpec::NewLC(KJapaneseElement, KGroup2Id);
   353 	TRAP(ret, typefaceSpec->AddTypefaceAtBackL(*element1));
   354 	CleanupStack::Pop(element1);
   355 	
   356 	//Action 5: Add the canonical element (Latin)
   357 	_LIT(KLatinElement, "DejaVu Sans Mono Bold");
   358 	CLinkedTypefaceElementSpec* element2 = CLinkedTypefaceElementSpec::NewLC(KLatinElement, KGroup1Id);
   359 	element2->SetCanonical(ETrue);
   360 	
   361 	TRAP(ret, typefaceSpec->AddTypefaceAtIndexL(*element2,0));
   362 	TEST(ret == KErrNone);
   363 	CleanupStack::Pop(element2);
   364 	
   365 	//Action 8 : Check Canonical Index is correct
   366 	canIndex = typefaceSpec->CanonicalIndex();
   367 	TEST(canIndex == 0);
   368 	
   369 	//Action 5 : Hindi typefaces
   370 	_LIT(KHindiElement, "Chandas");
   371 	CLinkedTypefaceElementSpec* element3 = CLinkedTypefaceElementSpec::NewLC(KHindiElement, KGroup3Id);
   372 	TRAP(ret, typefaceSpec->AddTypefaceAtBackL(*element3));
   373 	TEST(ret == KErrNone);
   374 	CleanupStack::Pop(element3);
   375 	
   376 	//Action 6 : Same element again
   377 	TRAP(ret, typefaceSpec->AddTypefaceAtBackL(*element3));
   378 	TEST(ret == KErrAlreadyExists);
   379 	
   380 	//Action 7 : Check ordering is correct
   381 	TEST2(element1, typefaceSpec->Typeface(1));
   382 	TEST2(element2, typefaceSpec->Typeface(0));
   383 	TEST2(element3, typefaceSpec->Typeface(2));
   384 	
   385 	_LIT(KDummyTypeface, "DummyTypeface");
   386 	CLinkedTypefaceElementSpec* dummyElement1 = CLinkedTypefaceElementSpec::NewLC(KDummyTypeface, KGroup2Id);
   387 	
   388 	//Action 9 : Add second canonical
   389 	dummyElement1->SetCanonical(ETrue);
   390 	TRAP(ret, typefaceSpec->AddTypefaceAtBackL(*dummyElement1));
   391 	TEST(ret == KErrArgument);
   392 
   393 	//Add at front of typeface to check canonical index is updated.
   394 	dummyElement1->SetCanonical(EFalse);
   395 	TRAP(ret, typefaceSpec->AddTypefaceAtIndexL(*dummyElement1, 0));
   396 	TEST(ret == KErrNone);
   397 	CleanupStack::Pop(dummyElement1);
   398 	
   399 	canIndex = typefaceSpec->CanonicalIndex();
   400 	TEST(canIndex == 1);
   401 	
   402 	dummyElement1 = CLinkedTypefaceElementSpec::NewLC(KDummyTypeface, 180);
   403 	TRAP(ret, typefaceSpec->AddTypefaceAtIndexL(*dummyElement1, 0));
   404 	TEST(ret == KErrArgument);
   405 	CleanupStack::PopAndDestroy(dummyElement1);
   406 	
   407 	//Action 11 : Remove Element
   408 	typefaceSpec->RemoveTypeface(0);
   409 	TEST2(element2, typefaceSpec->Typeface(0));
   410 	
   411 	//Action 8 : Check canonical index is correct
   412 	canIndex = typefaceSpec->CanonicalIndex();
   413 	TEST(canIndex == 0);
   414 	
   415 	//Action 10 : Check error if extra canonical activated "in place"
   416 	typefaceSpec->Typeface(1)->SetCanonical(ETrue);
   417 	canIndex = typefaceSpec->CanonicalIndex();
   418 	TEST(canIndex == KErrOverflow);
   419 	TRAP(ret, typefaceSpec->RegisterLinkedTypefaceL(*store));
   420 	TEST(ret == KErrOverflow);
   421 	//Reset back to be non-canonical
   422 	typefaceSpec->Typeface(1)->SetCanonical(EFalse);
   423 	
   424 	//Action 8 : Check canonical index is correct
   425 	typefaceSpec->RemoveTypeface(0);
   426 	TEST2(element1, typefaceSpec->Typeface(0));
   427 	
   428 	//Action 8 : Check canonical index is correct
   429 	canIndex = typefaceSpec->CanonicalIndex();
   430 	TEST(canIndex == -1);
   431 
   432 	//Action 4 : Remove the group
   433 	TRAP(ret, typefaceSpec->RemoveLinkedTypefaceGroup(KGroup3Id));
   434 	TEST(ret == KErrNone);
   435 	CLinkedTypefaceGroup* groupRet = typefaceSpec->GroupById(KGroup3Id);
   436 	TEST(groupRet == NULL);
   437 	
   438 	TEST2(element1, typefaceSpec->Typeface(0));
   439 
   440 	//Action 12 : Remove invalid group
   441 	ret = typefaceSpec->RemoveLinkedTypefaceGroup(180);
   442 	TEST(ret == KErrNotFound);
   443 	//Action 4 : Remove group
   444 	ret = typefaceSpec->RemoveLinkedTypefaceGroup(KGroup1Id);
   445 	TEST(ret == KErrNone);
   446 	groupRet = typefaceSpec->GroupById(KGroup1Id);
   447 	TEST(groupRet == NULL);
   448 	
   449 	CleanupStack::PopAndDestroy(typefaceSpec);
   450 	
   451 	//Negative Name length tests
   452 	_LIT(KEmptyTypefaceName, "");
   453 	//Action 15 : Create Specification & Element with 0 length names
   454 	TRAP(ret, typefaceSpec = CLinkedTypefaceSpecification::NewLC(KEmptyTypefaceName));
   455 	TEST(ret == KErrArgument);
   456 	TRAP(ret, dummyElement1 = CLinkedTypefaceElementSpec::NewLC(KEmptyTypefaceName,1));
   457 	TEST(ret < KErrNone);
   458 	//Action 15: Create Specification & Element with name longer than KMaxTypefaceNameLength
   459 	_LIT(KLongTypefaceName, "KErrArgumentKErrArgumentKErrArgument");
   460 	TRAP(ret, typefaceSpec = CLinkedTypefaceSpecification::NewLC(KLongTypefaceName));
   461 	TEST(ret == KErrArgument);
   462 	TRAP(ret, dummyElement1 = CLinkedTypefaceElementSpec::NewLC(KLongTypefaceName,1));
   463 	TEST(ret < KErrNone);
   464 	
   465 	typefaceSpec = CLinkedTypefaceSpecification::NewLC(KTestLinkedFont);
   466 	TInt i;
   467 	for (i = 0 ; i <= KMaxLinkedTypefaceGroups+1 ; i++)
   468 		{
   469 		CLinkedTypefaceGroup* group = CLinkedTypefaceGroup::NewLC(i);
   470 		
   471 		if (i < KMaxLinkedTypefaceGroups)
   472 			{
   473 			//Add Groups 1-KMaxLinkedTypefaceGroups
   474 			TRAP(ret, typefaceSpec->AddLinkedTypefaceGroupL(*group));
   475 			CleanupStack::Pop(group);
   476 			}
   477 		else
   478 			{
   479 			//Action 13 : Add group at KMaxLinkedTypefaceGroups+1
   480 			TRAP(ret, typefaceSpec->AddLinkedTypefaceGroupL(*group));
   481 			TEST(ret == KErrOverflow);
   482 			CleanupStack::PopAndDestroy(group);
   483 			}
   484 		}
   485 
   486 	_LIT(KFormatElementName, "Element%d");
   487 	for (i = 0 ; i <= KMaxLinkedTypefaces ; i++)
   488 		{
   489 		TBuf<18> elementName;
   490 		elementName.Format(KFormatElementName,i);
   491 		CLinkedTypefaceElementSpec* element = CLinkedTypefaceElementSpec::NewLC(elementName,i);
   492 		if (i < KMaxLinkedTypefaces)
   493 			{
   494 			//Add Elements 1-KMaxLinkedTypefaces
   495 			TRAP(ret,typefaceSpec->AddTypefaceAtBackL(*element));
   496 			CleanupStack::Pop(element);
   497 			}
   498 		else
   499 			{
   500 			//Action 16 : Add element KMaxLinkedTypefaces+1
   501 			TRAP(ret,typefaceSpec->AddTypefaceAtBackL(*element));
   502 			TEST(ret == KErrOverflow);
   503 			CleanupStack::PopAndDestroy(element);
   504 			}
   505 		}
   506 	
   507 	//Action 14 : Retrieve out of bounds groups
   508 	TEST2(typefaceSpec->Group(-1), NULL);
   509 	TEST2(typefaceSpec->Group(typefaceSpec->GroupCount()+1), NULL);
   510 	//Action 17 : Retrieve typeface with index out of bounds
   511 	TEST2(typefaceSpec->Typeface(-1), NULL);
   512 	TEST2(typefaceSpec->Typeface(typefaceSpec->TypefaceCount()+1), NULL);
   513 	//Action 11 : Remove typeface with index out of bounds
   514 	TEST2(typefaceSpec->RemoveTypeface(-1), KErrNotFound);
   515 	TEST2(typefaceSpec->RemoveTypeface(typefaceSpec->TypefaceCount()+1), KErrNotFound);
   516 	
   517 	CleanupStack::PopAndDestroy(2, store);
   518 	}
   519 
   520 /**
   521 @SYMTestCaseID
   522 GRAPHICS-FNTSTORE-LINKEDFONTS-0003
   523 
   524 @SYMPREQ
   525 PREQ2146
   526 
   527 @SYMREQ
   528 PREQ2146
   529 
   530 @SYMTestCaseDesc
   531 Tests the Add & RemoveTypeface functions provided by COpenFontLinkedTypefaceSpecification
   532 
   533 @SYMTestPriority
   534 Critical
   535 
   536 @SYMTestStatus
   537 Implemented
   538 
   539 @SYMTestActions
   540 Tests applicable to CLinkedTypefaceGroup / COpenFontLinkedTypefaceSpecification
   541 
   542 1. Adding a valid group
   543 2. Adding a duplicate group (same object)
   544 3. Adding a group with the same Id as an existing one
   545 4. Removal of group
   546 12. Remove invalid GroupId
   547 13. Adding more than KMaxLinkedTypefaceGroups groups
   548 14. Retrieve Group with index out of bounds
   549 
   550 Tests applicable to COpenFontLinkedTypefaceElementSpec / COpenFontLinkedTypefaceSpecification
   551 
   552 5. Adding a valid element
   553 6. Adding a duplicate element (same object)
   554 7. Ensuring ordering of elements is as specified
   555 8. Ensure canonical index is correct when element moved/removed
   556 9. Ensuring correct error if extra canonical added
   557 10. Ensuring correct error if canonical activated "in-place"
   558 11. Removal of element
   559 15. Create Specification & Element with too short (0)/long (KMaxTypefaceNameLength) names.
   560 16. Adding more than KMaxLinkedTypefaces Elements
   561 17. Retrieve Typeface with index out of bounds
   562 
   563 @SYMTestExpectedResults
   564 The canonical index is expected to be set to the values provided through the test after the 
   565 various operations performed. Addition & removal should provide success or fail error codes
   566 as indicated throughout the test. Actions are referenced within the code with expected results.
   567 */
   568 void CTLinkedFonts2::TestOpenClientAddAndRemoveL()
   569 	{
   570 	INFO_PRINTF1(_L("TestOpenClientAddAndRemoveL"));
   571 	
   572 	_LIT(KTestLinkedFont, "TestLinkedFont");
   573 	COpenFontLinkedTypefaceSpecification* typefaceSpec = 
   574 		COpenFontLinkedTypefaceSpecification::NewLC(KTestLinkedFont);
   575 	
   576 	TInt canIndex = typefaceSpec->CanonicalIndex();
   577 	TEST(canIndex == -1);
   578 	
   579 	TInt ret;
   580 	
   581 	//Action 1 : Add a valid group
   582 	const TInt KGroup1Id = 1;
   583 	CLinkedTypefaceGroup* group1 = CLinkedTypefaceGroup::NewLC(KGroup1Id);
   584 	TRAP(ret, typefaceSpec->AddLinkedTypefaceGroupL(*group1));
   585 	TEST(ret == KErrNone);
   586 	CleanupStack::Pop(group1);
   587 	
   588 	//Action 2 : Add a duplicate group
   589 	TRAP(ret, typefaceSpec->AddLinkedTypefaceGroupL(*group1));
   590 	TEST(ret == KErrAlreadyExists);
   591 	
   592 	//Action 3 : Add a group with the same id
   593 	CLinkedTypefaceGroup* duplicateGroup = CLinkedTypefaceGroup::NewLC(KGroup1Id);
   594 	TRAP(ret, typefaceSpec->AddLinkedTypefaceGroupL(*duplicateGroup));
   595 	TEST(ret == KErrAlreadyExists);
   596 	CleanupStack::PopAndDestroy(duplicateGroup);
   597 	
   598 	//Action 5 : Add a valid element
   599 	const TInt KGroup2Id = 2;
   600 	CLinkedTypefaceGroup* group2 = CLinkedTypefaceGroup::NewLC(KGroup2Id);
   601 	group2->SetBaselineShift(CLinkedTypefaceGroup::EBaselineShift);
   602 	group2->SetScalingOption(CLinkedTypefaceGroup::EScalingUpOrDown);
   603 	TRAP(ret, typefaceSpec->AddLinkedTypefaceGroupL(*group2));
   604 	TEST(ret == KErrNone);
   605 	CleanupStack::Pop(group2);
   606 	
   607 	const TInt KGroup3Id = 4;
   608 	CLinkedTypefaceGroup* group3 = CLinkedTypefaceGroup::NewLC(KGroup3Id);
   609 	TRAP(ret, typefaceSpec->AddLinkedTypefaceGroupL(*group3));
   610 	TEST(ret == KErrNone);
   611 	CleanupStack::Pop(group3);
   612 	
   613 	//Action 5 : Add a valid element
   614 	_LIT(KJapaneseElement, "Japanese");
   615 	COpenFontLinkedTypefaceElementSpec* element1 = COpenFontLinkedTypefaceElementSpec::NewLC(KJapaneseElement, KGroup2Id);
   616 	TRAP(ret, typefaceSpec->AddTypefaceAtBackL(*element1));
   617 	CleanupStack::Pop(element1);
   618 	
   619 	//Action 5 : Add a valid element
   620 	_LIT(KLatinElement, "DejaVu Sans Mono Bold");
   621 	COpenFontLinkedTypefaceElementSpec* element2 = COpenFontLinkedTypefaceElementSpec::NewLC(KLatinElement, KGroup1Id);
   622 	element2->SetCanonical(ETrue);
   623 	
   624 	TRAP(ret, typefaceSpec->AddTypefaceAtIndexL(*element2,0));
   625 	TEST(ret == KErrNone);
   626 	CleanupStack::Pop(element2);
   627 	
   628 	//Action 8 : Ensure canonical index correct
   629 	canIndex = typefaceSpec->CanonicalIndex();
   630 	TEST(canIndex == 0);
   631 	
   632 	_LIT(KHindiElement, "Chandas");
   633 	COpenFontLinkedTypefaceElementSpec* element3 = COpenFontLinkedTypefaceElementSpec::NewLC(KHindiElement, KGroup3Id);
   634 	TRAP(ret, typefaceSpec->AddTypefaceAtBackL(*element3));
   635 	TEST(ret == KErrNone);
   636 	CleanupStack::Pop(element3);
   637 	
   638 	//Action 6 : Duplicate element
   639 	TRAP(ret, typefaceSpec->AddTypefaceAtBackL(*element3));
   640 	TEST(ret == KErrAlreadyExists);
   641 	
   642 	//Action 7 : Ensure ordering correct
   643 	TEST2(element1, typefaceSpec->Typeface(1));
   644 	TEST2(element2, typefaceSpec->Typeface(0));
   645 	TEST2(element3, typefaceSpec->Typeface(2));
   646 	
   647 	_LIT(KDummyTypeface, "DummyTypeface");
   648 	COpenFontLinkedTypefaceElementSpec* dummyElement1 = COpenFontLinkedTypefaceElementSpec::NewLC(KDummyTypeface, KGroup2Id);
   649 	
   650 	//Action 9 : Add 2nd canonical
   651 	dummyElement1->SetCanonical(ETrue);
   652 	TRAP(ret, typefaceSpec->AddTypefaceAtBackL(*dummyElement1));
   653 	TEST(ret == KErrArgument);
   654 	
   655 	//Add at front of typeface to check canonical index is updated.
   656 	dummyElement1->SetCanonical(EFalse);
   657 	TRAP(ret, typefaceSpec->AddTypefaceAtIndexL(*dummyElement1, 0));
   658 	TEST(ret == KErrNone);
   659 	CleanupStack::Pop(dummyElement1);
   660 	
   661 	//Action 8 : Check canonical updated
   662 	canIndex = typefaceSpec->CanonicalIndex();
   663 	TEST(canIndex == 1);
   664 	
   665 	//Action 11 : Remove element
   666 	typefaceSpec->RemoveTypeface(0);
   667 	TEST2(element2, typefaceSpec->Typeface(0));
   668 	
   669 	//Action 8 : Check canonical updated
   670 	canIndex = typefaceSpec->CanonicalIndex();
   671 	TEST(canIndex == 0);
   672 	
   673 	//Action 10 : Additional canonical set in-place
   674 	typefaceSpec->Typeface(1)->SetCanonical(ETrue);
   675 	canIndex = typefaceSpec->CanonicalIndex();
   676 	TEST(canIndex == KErrOverflow);
   677 	typefaceSpec->Typeface(1)->SetCanonical(EFalse);
   678 	
   679 	//Action 11 : Remove element
   680 	typefaceSpec->RemoveTypeface(0);
   681 	TEST2(element1, typefaceSpec->Typeface(0));
   682 	
   683 	//Action 8 : Canonical updated
   684 	canIndex = typefaceSpec->CanonicalIndex();
   685 	TEST(canIndex == -1);
   686 
   687 	//Action 4 : Remove group
   688 	TRAP(ret, typefaceSpec->RemoveLinkedTypefaceGroup(KGroup3Id));
   689 	TEST(ret == KErrNone);
   690 	CLinkedTypefaceGroup* groupRet = typefaceSpec->GroupById(KGroup3Id);
   691 	TEST(groupRet == NULL);
   692 	
   693 	TEST2(element1, typefaceSpec->Typeface(0));
   694 	
   695 	//Action 12 : Remove invalid group Id
   696 	ret = typefaceSpec->RemoveLinkedTypefaceGroup(180);
   697 	TEST(ret == KErrNotFound);
   698 	ret = typefaceSpec->RemoveLinkedTypefaceGroup(KGroup1Id);
   699 	TEST(ret == KErrNone);
   700 		
   701 	CleanupStack::PopAndDestroy(typefaceSpec);	
   702 	
   703 	//Negative Name length tests
   704 	_LIT(KEmptyTypefaceName, "");
   705 	//Action 15 : Create Specifications 
   706 	TRAP(ret, typefaceSpec = COpenFontLinkedTypefaceSpecification::NewLC(KEmptyTypefaceName));
   707 	TEST(ret == KErrArgument);
   708 	TRAP(ret, dummyElement1 = COpenFontLinkedTypefaceElementSpec::NewLC(KEmptyTypefaceName,1));
   709 	TEST(ret < KErrNone);
   710 	_LIT(KLongTypefaceName, "KErrArgumentKErrArgumentKErrArgument");
   711 	TRAP(ret, typefaceSpec = COpenFontLinkedTypefaceSpecification::NewLC(KLongTypefaceName));
   712 	TEST(ret == KErrArgument);
   713 	TRAP(ret, dummyElement1 = COpenFontLinkedTypefaceElementSpec::NewLC(KLongTypefaceName,1));
   714 	TEST(ret < KErrNone);
   715 	
   716 	typefaceSpec = COpenFontLinkedTypefaceSpecification::NewLC(KTestLinkedFont);
   717 	TInt i;
   718 	for (i = 0 ; i <= KMaxLinkedTypefaceGroups+1 ; i++)
   719 		{
   720 		CLinkedTypefaceGroup* group = CLinkedTypefaceGroup::NewLC(i);
   721 		
   722 		if (i < KMaxLinkedTypefaceGroups)
   723 			{
   724 			TRAP(ret, typefaceSpec->AddLinkedTypefaceGroupL(*group));
   725 			CleanupStack::Pop(group);
   726 			}
   727 		else
   728 			{
   729 			TRAP(ret, typefaceSpec->AddLinkedTypefaceGroupL(*group));
   730 			TEST(ret == KErrOverflow);
   731 			CleanupStack::PopAndDestroy(group);
   732 			}
   733 		}
   734 
   735 	_LIT(KFormatElementName, "Element%d");
   736 	for (i = 0 ; i <= KMaxLinkedTypefaces ; i++)
   737 		{
   738 		TBuf<18> elementName;
   739 		elementName.Format(KFormatElementName,i);
   740 		COpenFontLinkedTypefaceElementSpec* element = COpenFontLinkedTypefaceElementSpec::NewLC(elementName,i);
   741 		if (i < KMaxLinkedTypefaces)
   742 			{
   743 			TRAP(ret,typefaceSpec->AddTypefaceAtBackL(*element));
   744 			CleanupStack::Pop(element);
   745 			}
   746 		else
   747 			{
   748 			TRAP(ret,typefaceSpec->AddTypefaceAtBackL(*element));
   749 			TEST(ret == KErrOverflow);
   750 			CleanupStack::PopAndDestroy(element);
   751 			}
   752 		}
   753 	
   754 	TEST2(typefaceSpec->Group(-1), NULL);
   755 	TEST2(typefaceSpec->Group(typefaceSpec->GroupCount()+1), NULL);
   756 	TEST2(typefaceSpec->Typeface(-1), NULL);
   757 	TEST2(typefaceSpec->Typeface(typefaceSpec->TypefaceCount()+1), NULL);
   758 	TEST2(typefaceSpec->RemoveTypeface(-1), KErrNotFound);
   759 	TEST2(typefaceSpec->RemoveTypeface(typefaceSpec->TypefaceCount()+1), KErrNotFound);
   760 	CleanupStack::PopAndDestroy(typefaceSpec);
   761 	}
   762 
   763 /* Function is used to determine if complex fonts are available.  It looks for a 
   764 test Devanagari font
   765 */
   766 TBool CTLinkedFonts2::ComplexFontAvailable()
   767 	{
   768 	_LIT(KTypefaceOT, "Chandas");
   769 
   770 	// Create the linked font
   771 	TTypeface typeface;
   772 	typeface.iName = KTypefaceOT;
   773 	TFontSpec fs1;
   774 	fs1.iTypeface = typeface;
   775 	fs1.iHeight = 4;
   776 	CFbsFont* font = NULL;
   777 	TInt err = iDev->GetNearestFontToDesignHeightInPixels(font, fs1);
   778 	if (font)
   779 		{
   780 		TFontSpec fs2 = font->FontSpecInTwips();
   781 		iDev->ReleaseFont(font);
   782 		if (fs2.iTypeface.iName.Compare(KTypefaceOT) == 0)
   783 			{
   784 			return ETrue;
   785 			}
   786 		}
   787 	INFO_PRINTF1(_L("(N.B. Complex font not available so complex parts of test skipped)"));
   788 	return EFalse;
   789 	}
   790 
   791 /**
   792    @SYMTestCaseID			GRAPHICS-FNTSTORE-LINKEDFONTS-0100
   793 
   794    @SYMPREQ					PREQ2146
   795 
   796    @SYMREQ					REQ10924, REQ10925, REQ10926
   797 
   798    @SYMTestCaseDesc			To ensure that a linked typeface including a complex font can be created
   799 							and used.  Test access to characters in a complex linked font.
   800 
   801    @SYMTestPriority			Critical
   802 
   803    @SYMTestStatus			Implemented
   804 
   805    @SYMTestActions			(1) Create a linked font with a complex typeface. Draw text, 
   806    								and compare	against text drawn using a non-linked font.
   807 
   808    @SYMTestExpectedResults	(1) - test allows a linked font with a complex typeface to be created
   809 */
   810 void CTLinkedFonts2::TestComplexLinkedFontsBasicL()
   811 	{
   812 	INFO_PRINTF1(_L("LinkedFonts2::TestComplexLinkedFontsBasicL"));
   813 
   814 	CFbsTypefaceStore* store = CFbsTypefaceStore::NewL(iDev);
   815 	CleanupStack::PushL(store);
   816 
   817 	TBool testComplex = ComplexFontAvailable();
   818 	if (testComplex)
   819 		{
   820 		// Create typeface to be linked
   821 		_LIT(KLinkedTypefaceTT, "DejaVu Sans Condensed");
   822 		_LIT(KLinkedTypefaceOT, "Chandas");
   823 
   824 		CLinkedTypefaceSpecification *typefaceSpec;
   825 		_LIT(KLinkedTypefaceTTOT, "LinkedTypefaceComp");
   826 		
   827 		typefaceSpec = CLinkedTypefaceSpecification::NewLC(KLinkedTypefaceTTOT);
   828 		
   829 		CLinkedTypefaceGroup* group1 = CLinkedTypefaceGroup::NewLC(1);
   830 		typefaceSpec->AddLinkedTypefaceGroupL(*group1);
   831 		CleanupStack::Pop();
   832 		
   833 		CLinkedTypefaceGroup* group2 = CLinkedTypefaceGroup::NewLC(2);
   834 		typefaceSpec->AddLinkedTypefaceGroupL(*group2);
   835 		CleanupStack::Pop();
   836 		
   837 		// Add first typeface
   838 		CLinkedTypefaceElementSpec *elementSpec1;
   839 		elementSpec1 = CLinkedTypefaceElementSpec::NewLC(KLinkedTypefaceTT, 1);
   840 		
   841 		CLinkedTypefaceElementSpec *elementSpec2;
   842 		elementSpec2 = CLinkedTypefaceElementSpec::NewLC(KLinkedTypefaceOT, 2);
   843 		elementSpec2->SetCanonical(ETrue);
   844 		
   845 		typefaceSpec->AddTypefaceAtBackL(*elementSpec1);
   846 		typefaceSpec->AddTypefaceAtBackL(*elementSpec2);
   847 		CleanupStack::Pop(2, elementSpec1);
   848 		
   849 		TEST(typefaceSpec->TypefaceCount() == 2);
   850 		TEST(typefaceSpec->Name() == KLinkedTypefaceTTOT);
   851 
   852 		// Now try registering the linked typeface
   853 		TRAPD(ret, typefaceSpec->RegisterLinkedTypefaceL(*store));
   854 
   855 		if (ret == KErrNotSupported)
   856 			{
   857 			INFO_PRINTF1(_L("No Rasterizer is present that supports the extended Font Linking interface. This test case has been skipped."));
   858 			CleanupStack::PopAndDestroy(2,store);
   859 			}
   860 		else
   861 			{
   862 			TEST(ret == KErrNone);
   863 			
   864 			// Create the linked font
   865 			TTypeface typeface;
   866 			typeface.iName = KLinkedTypefaceTTOT;
   867 			TFontSpec fs;
   868 			fs.iTypeface = typeface;
   869 			fs.iHeight = 35;
   870 			CFbsFont* font = NULL;
   871 			TInt err = iDev->GetNearestFontToDesignHeightInPixels(font, fs);
   872 			
   873 			//check the font is the one requested
   874 			TFontSpec fontSpec = font->FontSpecInTwips();
   875 			TEST(fontSpec.iTypeface.iName == KLinkedTypefaceTTOT);
   876 	
   877 			_LIT16(KEnglish1,"ABCD12345 ");
   878 			_LIT16(KHindi1,"\x0915\x094D\x0937\x0924\x094D\x0930\x093F\x092F\x0020");
   879 			TEST(font != NULL);
   880 			const TPoint englishLinked(10,75);
   881 			const TPoint hindiLinked(10,150);
   882 			if (font)
   883 				{
   884 				// Use the font
   885 				iGc->UseFont(font);
   886 				iGc->Clear();
   887 				iGc->DrawText(KEnglish1, englishLinked);
   888 				iGc->DrawText(KHindi1, hindiLinked);
   889 				iGc->DiscardFont();
   890 				iDev->Update();
   891 				User::After(1000*1000*5);
   892 				}
   893 	
   894 			// All the CFont functions can use a linked font and a non-linked
   895 			// font - with the same base font, results should be the same.
   896 			// Compare with the test function.
   897 			
   898 			//output the Hindi text
   899 			TTypeface typeface2;
   900 			typeface2.iName = KLinkedTypefaceOT;
   901 			TFontSpec fs2;
   902 			fs2.iTypeface = typeface2;
   903 			fs2.iHeight = 35;
   904 			CFbsFont* font2 = NULL;
   905 			err = iDev->GetNearestFontToDesignHeightInPixels(font2, fs2);
   906 			TEST(font2 != NULL);
   907 			
   908 			//check the font is the one requested
   909 			fontSpec = font2->FontSpecInTwips();
   910 			TEST(fontSpec.iTypeface.iName == KLinkedTypefaceOT);
   911 	
   912 			const TPoint englishHindiFont(240, 75);
   913 			const TPoint hindiHindiFont(240, 150);
   914 			if (font2)
   915 				{
   916 				// Use the font
   917 				iGc->UseFont(font2);
   918 				iGc->DrawText(KEnglish1, englishHindiFont);
   919 				iGc->DrawText(KHindi1, hindiHindiFont);
   920 				iGc->DiscardFont();
   921 				iDev->Update();
   922 				User::After(1000*1000);
   923 				iDev->ReleaseFont(font2);
   924 				}
   925 			
   926 			//output the English text
   927 			TTypeface typeface3;
   928 			typeface3.iName = KLinkedTypefaceTT;
   929 			TFontSpec fs3;
   930 			fs3.iTypeface = typeface3;
   931 			fs3.iHeight = 35;
   932 			CFbsFont* font3 = NULL;
   933 			err = iDev->GetNearestFontToDesignHeightInPixels(font3, fs3);
   934 			TEST(font3 != NULL);
   935 	
   936 			//check the font is the one requested
   937 			fontSpec = font3->FontSpecInTwips();
   938 			TEST(fontSpec.iTypeface.iName == KLinkedTypefaceTT);
   939 	
   940 			const TPoint englishSansSerifFont(440, 75);
   941 			const TPoint hindiSansSerifFont(440, 150);
   942 			if (font3)
   943 				{
   944 				// Use the font
   945 				iGc->UseFont(font3);
   946 				iGc->DrawText(KEnglish1, englishSansSerifFont);
   947 				iGc->DrawText(KHindi1, hindiSansSerifFont);
   948 				iGc->DiscardFont();
   949 				iDev->Update();
   950 				User::After(1000*1000);
   951 				iDev->ReleaseFont(font3);
   952 				}
   953 			
   954 			//compare rects.
   955 			if (font)
   956 				{
   957 				CFont::TMeasureTextOutput compareEnglish;
   958 				CFont::TMeasureTextOutput compareHindi;
   959 				//get the size of a text box to do the comparison
   960 				font->MeasureText(KEnglish1, NULL, &compareEnglish);
   961 				font->MeasureText(KHindi1, NULL, &compareHindi);
   962 				
   963 				//compare English
   964 				TRect englishLinkedRect (englishLinked.iX,englishLinked.iY,
   965 							englishLinked.iX+compareEnglish.iBounds.Width(),
   966 							englishLinked.iY+compareEnglish.iBounds.Height());
   967 				TRect englishSansSerifRect  (englishSansSerifFont.iX,englishSansSerifFont.iY,
   968 						englishSansSerifFont.iX+compareEnglish.iBounds.Width(),
   969 						englishSansSerifFont.iY+compareEnglish.iBounds.Height());
   970 				
   971 				TBool val = iDev->RectCompare(englishLinkedRect, *iDev,englishSansSerifRect);
   972 				//this value is not compared since the rasterizer may resize/reposition fonts
   973 				
   974 				//compare Hindi
   975 				TRect hindiLinkedRect  (hindiLinked.iX,hindiLinked.iY,
   976 						hindiLinked.iX+compareHindi.iBounds.Width(),
   977 						hindiLinked.iY+compareHindi.iBounds.Height());
   978 				TRect hindiHindiRect  (hindiHindiFont.iX,hindiHindiFont.iY,
   979 						hindiHindiFont.iX+compareHindi.iBounds.Width(),
   980 						hindiHindiFont.iY+compareHindi.iBounds.Height());
   981 				val=iDev->RectCompare(hindiLinkedRect, *iDev,hindiHindiRect);
   982 				//do not call TEST(val) since size/position may be slightly different
   983 				iDev->ReleaseFont(font);
   984 				}
   985 			CleanupStack::PopAndDestroy(2, store);
   986 			}
   987 		}
   988 	}
   989 
   990 /**
   991    @SYMTestCaseID			GRAPHICS-FNTSTORE-LINKEDFONTS-0101
   992 
   993    @SYMPREQ					PREQ2146
   994 
   995    @SYMREQ					REQ10924, REQ10925, REQ10926
   996 
   997    @SYMTestCaseDesc			To test PREQ2146 linked fonts with bitmap fonts.  Bitmap fonts are not  
   998    							supported so an error needs to be returned on registration.
   999 
  1000    @SYMTestPriority			Critical
  1001 
  1002    @SYMTestStatus			Implemented
  1003 
  1004    @SYMTestActions			(1) Create a linked typeface elements, with one of them from a bitmap font
  1005    								try registering, and KErrNotSupported error should be returned
  1006 
  1007    @SYMTestExpectedResults	(1) - registering a bitmap font returns KErrNotSupported.
  1008 */
  1009 void CTLinkedFonts2::TestBitmapFontsL()
  1010 	{
  1011 	INFO_PRINTF1(_L("LinkedFonts2::TestBitmapFontsL"));
  1012 
  1013 	CFbsTypefaceStore* store = CFbsTypefaceStore::NewL(iDev);
  1014 	CleanupStack::PushL(store);
  1015 	
  1016 	// Create typeface to be linked
  1017 	_LIT(KLinkedTypefaceTT, "DejaVu Sans Condensed");
  1018 	_LIT(KLinkedTypeFace1, "LinkedFont1"); //this is a bitmap font
  1019 
  1020 	CLinkedTypefaceSpecification *typefaceSpec;
  1021 	_LIT(KLinkedTypefaceBitmap, "LinkedTypefaceBitmap");
  1022 		
  1023 	typefaceSpec = CLinkedTypefaceSpecification::NewLC(KLinkedTypefaceBitmap);
  1024 	
  1025 	CLinkedTypefaceGroup* group1 = CLinkedTypefaceGroup::NewLC(1);
  1026 	typefaceSpec->AddLinkedTypefaceGroupL(*group1);
  1027 	CleanupStack::Pop();
  1028 	
  1029 	CLinkedTypefaceGroup* group2 = CLinkedTypefaceGroup::NewLC(2);
  1030 	typefaceSpec->AddLinkedTypefaceGroupL(*group2);
  1031 	CleanupStack::Pop();
  1032 	
  1033 	// Add first typeface
  1034 	CLinkedTypefaceElementSpec *elementSpec1;
  1035 	elementSpec1 = CLinkedTypefaceElementSpec::NewLC(KLinkedTypefaceTT, 2);
  1036 		
  1037 	CLinkedTypefaceElementSpec *elementSpec2;
  1038 	elementSpec2 = CLinkedTypefaceElementSpec::NewLC(KLinkedTypeFace1, 1);
  1039 	elementSpec2->SetCanonical(ETrue);
  1040 		
  1041 	typefaceSpec->AddTypefaceAtBackL(*elementSpec1);
  1042 	typefaceSpec->AddTypefaceAtBackL(*elementSpec2);
  1043 	CleanupStack::Pop(2, elementSpec1);
  1044 		
  1045 	TEST(typefaceSpec->TypefaceCount() == 2);
  1046 	TEST(typefaceSpec->Name() == KLinkedTypefaceBitmap);
  1047 
  1048 	// Now try regstering the linked typeface
  1049 	TRAPD(ret, typefaceSpec->RegisterLinkedTypefaceL(*store));
  1050 	TEST(ret == KErrNotSupported);
  1051 	CleanupStack::PopAndDestroy(2, store);
  1052 	}
  1053 
  1054 /**
  1055    @SYMTestCaseID			GRAPHICS-FNTSTORE-LINKEDFONTS-0109
  1056 
  1057    @SYMPREQ					PREQ2146
  1058 
  1059    @SYMREQ					REQ10924, REQ10925, REQ10926
  1060 
  1061    @SYMTestCaseDesc			To test PREQ2146 linked fonts updates to the TOpenFontCharMetrics class.  
  1062    
  1063    @SYMTestPriority			Critical
  1064 
  1065    @SYMTestStatus			Implemented
  1066 
  1067    @SYMTestActions			(1) Create a TOpenFontCharMetrics object.
  1068    							(2) Check that nothing is set
  1069    							(3) Set a small positive baseline
  1070    							(4) Check that the baseline is as set and the glyph type is still not set
  1071    							(5) Set a large positive baseline
  1072    							(6)	Check that the baseline is as set and the glyph type is still not set
  1073 							(7) Set a large negative baseline
  1074 							(8) Check that the baseline is as set and the glyph type is still not set
  1075 							(9) Set the glyph type.
  1076 							(10) Check that the baseline is as set and the glyph type is as set
  1077 							(11) Set the baseline to a again to various values
  1078 							(12) Check that the baseline is as set and the glyph type has not changed
  1079 
  1080    	@SYMTestExpectedResults	(2) the default values are 0 for baseline and EGlyphBitmapTypeNotDefined for glyph type
  1081    							(4)(6)(8)(10)(12) The values are are set, and setting the baseline does 
  1082    							not alter the glyph type and vice-versa.
  1083 */
  1084 void CTLinkedFonts2::TestTOpenFontMetrics()
  1085 	{
  1086 	TOpenFontMetrics metrics;
  1087 	
  1088 	TInt len = metrics.BaselineCorrection();
  1089 	TEST(len==0);
  1090 	
  1091 	metrics.SetBaselineCorrection(22);
  1092 	len = metrics.BaselineCorrection();
  1093 	TEST(len==22);
  1094 	
  1095 	metrics.SetBaselineCorrection(444);
  1096 	len = metrics.BaselineCorrection();
  1097 	TEST(len==444);
  1098 	
  1099 	metrics.SetBaselineCorrection(-333);
  1100 	len = metrics.BaselineCorrection();
  1101 	TEST(len==-333);
  1102 	
  1103 	metrics.SetBaselineCorrection(444);
  1104 	len = metrics.BaselineCorrection();
  1105 	TEST(len==444);
  1106 	
  1107 	metrics.SetBaselineCorrection(-1);
  1108 	len = metrics.BaselineCorrection();
  1109 	TEST(len==-1);
  1110 
  1111 	}
  1112 
  1113 void CTLinkedFonts2::TestLinkedRegistrationAndFetchL()
  1114 	{
  1115 	INFO_PRINTF1(_L("CTLinkedFonts2::TestLinkedRegistrationAndFetchL"));
  1116 	CFbsTypefaceStore* store = CFbsTypefaceStore::NewL(iDev);
  1117 	CleanupStack::PushL(store);
  1118 	
  1119 	//Create and register a dummy linked typeface to register.
  1120 	_LIT(KFetchTypefaceName, "FetchFont");
  1121 	CLinkedTypefaceSpecification* typefaceSpec = CLinkedTypefaceSpecification::NewLC(KFetchTypefaceName);
  1122 
  1123 	CLinkedTypefaceGroup* group1 = CLinkedTypefaceGroup::NewLC(1);
  1124 	group1->SetBoldnessPercentage(20);
  1125 	group1->SetItalicAngle(10);
  1126 	group1->SetBaselineShift(CLinkedTypefaceGroup::EBaselineShift);
  1127 	group1->SetScalingOption(CLinkedTypefaceGroup::EScalingDown);
  1128 	
  1129 	typefaceSpec->AddLinkedTypefaceGroupL(*group1);
  1130 	CleanupStack::Pop(group1);
  1131 	
  1132 	CLinkedTypefaceGroup* group2 = CLinkedTypefaceGroup::NewLC(2);
  1133 	group2->SetBoldnessPercentage(21);
  1134 	group2->SetItalicAngle(11);
  1135 	group2->SetBaselineShift(CLinkedTypefaceGroup::ENoBaselineShift);
  1136 	group2->SetScalingOption(CLinkedTypefaceGroup::EScalingUp);
  1137 	
  1138 	typefaceSpec->AddLinkedTypefaceGroupL(*group2);
  1139 	CleanupStack::Pop(group2);
  1140 	
  1141 	_LIT(KElement1Name, "DejaVu Sans Condensed");
  1142 	CLinkedTypefaceElementSpec* element1 = CLinkedTypefaceElementSpec::NewLC(KElement1Name, 1);
  1143 	element1->SetCanonical(ETrue);
  1144 	typefaceSpec->AddTypefaceAtBackL(*element1);
  1145 	CleanupStack::Pop(element1);
  1146 	
  1147 	_LIT(KElement2Name, "Chandas");
  1148 	CLinkedTypefaceElementSpec* element2 = CLinkedTypefaceElementSpec::NewLC(KElement2Name, 2);
  1149 	typefaceSpec->AddTypefaceAtBackL(*element2);
  1150 	CleanupStack::Pop(element2);
  1151 	
  1152 	TRAPD(ret, typefaceSpec->RegisterLinkedTypefaceL(*store));
  1153 	if (ret == KErrNotSupported)
  1154 		{
  1155 		INFO_PRINTF1(_L("No Rasterizer is present that supports the extended Font Linking interface. This test case has been skipped."));
  1156 		CleanupStack::PopAndDestroy(2,store);
  1157 		}
  1158 	else
  1159 		{
  1160 		TEST(ret == KErrNone);
  1161 		
  1162 		CLinkedTypefaceSpecification* fetchSpec = CLinkedTypefaceSpecification::NewLC(KFetchTypefaceName);
  1163 		TRAP(ret, fetchSpec->FetchLinkedTypefaceSpecificationL(*store));
  1164 		TEST(ret == KErrNone);
  1165 		
  1166 		//Compare Groups. Ordering isn't important so can get group by id rather than index.
  1167 		TEST(typefaceSpec->GroupCount() == fetchSpec->GroupCount());
  1168 		CLinkedTypefaceGroup* groupf = fetchSpec->GroupById(1);
  1169 		TEST(CompareGroups(group1,groupf));
  1170 		
  1171 		groupf = fetchSpec->GroupById(2);
  1172 		TEST(CompareGroups(group2,groupf));
  1173 			
  1174 		//Check elements match 
  1175 		TEST(typefaceSpec->TypefaceCount() == fetchSpec->TypefaceCount());
  1176 		
  1177 		CLinkedTypefaceElementSpec* elementf = fetchSpec->Typeface(0);
  1178 		TEST(CompareElementSpecs(elementf, element1));
  1179 		elementf = fetchSpec->Typeface(1);
  1180 		TEST(CompareElementSpecs(elementf, element2));
  1181 			
  1182 		CleanupStack::PopAndDestroy(3,store);
  1183 		}
  1184 	}
  1185 
  1186 /**
  1187    @SYMTestCaseID			GRAPHICS-FNTSTORE-LINKEDFONTS-0110
  1188 
  1189    @SYMDEF					DEF137360
  1190 
  1191    @SYMTestCaseDesc			Ensure that font full names are used to build a linked font  
  1192    
  1193    @SYMTestPriority			Critical
  1194 
  1195    @SYMTestStatus			Implemented
  1196 
  1197    @SYMTestActions			Attempt to register a linked font using a font full name rather than a family
  1198 						    name. DejaVu Sans Condensed is both a family name and a full name. DejaVu Sans Mono Bold is full name only.
  1199 
  1200    	@SYMTestExpectedResults	Registration of the linked font will be sucessful.
  1201 							Failing with KErrNotFound means either the test font is not available or there is a regression.
  1202 */
  1203 void CTLinkedFonts2::TestFontNameUsage()
  1204 	{
  1205 	CFbsTypefaceStore* store = CFbsTypefaceStore::NewL(NULL);
  1206 	CleanupStack::PushL(store);
  1207 	
  1208 	CLinkedTypefaceSpecification* nameSpec = CLinkedTypefaceSpecification::NewLC(_L("FullNameTest"));
  1209 	
  1210 	CLinkedTypefaceGroup* group = CLinkedTypefaceGroup::NewLC(1);
  1211 	nameSpec->AddLinkedTypefaceGroupL(*group);
  1212 	CleanupStack::Pop(group);
  1213 	
  1214 	//Use a font whose name doesn't match a family name
  1215 	CLinkedTypefaceElementSpec* element1 = CLinkedTypefaceElementSpec::NewLC(_L("DejaVu Sans Mono Bold"), 1);
  1216 	element1->SetCanonical(ETrue);
  1217 	nameSpec->AddTypefaceAtBackL(*element1);
  1218 	CleanupStack::Pop(element1);
  1219 	
  1220 	CLinkedTypefaceElementSpec* element2 = CLinkedTypefaceElementSpec::NewLC(_L("Chandas"), 1);
  1221 	nameSpec->AddTypefaceAtBackL(*element2);
  1222 	CleanupStack::Pop(element2);
  1223 	
  1224 	TRAPD(ret, store->RegisterLinkedTypeface(*nameSpec));
  1225 	
  1226 	TEST(ret == KErrNone);
  1227 	
  1228 	CleanupStack::PopAndDestroy(2, store);
  1229 	}
  1230 
  1231 TBool CTLinkedFonts2::CompareElementSpecs(CLinkedTypefaceElementSpec* aSpec1, CLinkedTypefaceElementSpec* aSpec2)
  1232 	{
  1233 	if ( (aSpec1 == NULL ) && (aSpec2 == NULL) )
  1234 		return ETrue;
  1235 	if ( (aSpec1 == NULL) || (aSpec2 == NULL) )
  1236 		return EFalse;
  1237 	if (aSpec1->ElementName().Compare(aSpec2->ElementName()) != 0)
  1238 		return EFalse;
  1239 	if (aSpec1->Canonical() != aSpec2->Canonical())
  1240 		return EFalse;
  1241 	if (aSpec1->GroupId() != aSpec2->GroupId())
  1242 		return EFalse;
  1243 	
  1244 	return ETrue;
  1245 	}
  1246 
  1247 TBool CTLinkedFonts2::CompareElementSpecs(COpenFontLinkedTypefaceElementSpec* aSpec1, COpenFontLinkedTypefaceElementSpec* aSpec2)
  1248 	{
  1249 	if ( (aSpec1 == NULL ) && (aSpec2 == NULL) )
  1250 		return ETrue;
  1251 	if ( (aSpec1 == NULL) || (aSpec2 == NULL) )
  1252 		return EFalse;
  1253 	if (aSpec1->ElementName().Compare(aSpec2->ElementName()) != 0)
  1254 		return EFalse;
  1255 	if (aSpec1->Canonical() != aSpec2->Canonical())
  1256 		return EFalse;
  1257 	if (aSpec1->GroupId() != aSpec2->GroupId())
  1258 		return EFalse;
  1259 	
  1260 	return ETrue;
  1261 	}
  1262 /**
  1263 Compare two linked typeface groups; the first varable should be a locally created group and the second one fetched from the
  1264 rasterizer. If the local group has thresholds / metrics set to -1 ("best guess by rasterizer") then the differences between the
  1265 values are ignored.
  1266  */
  1267 TBool CTLinkedFonts2::CompareGroups(CLinkedTypefaceGroup* aLocalGroup, CLinkedTypefaceGroup* aFetchedGroup)
  1268 	{
  1269 	if ( (aLocalGroup == NULL) && (aFetchedGroup == NULL) )
  1270 		return ETrue;
  1271 	if ( (aLocalGroup == NULL) || (aFetchedGroup == NULL) )
  1272 		{
  1273 		INFO_PRINTF1(_L("One of the specified groups is NULL"));
  1274 		return EFalse;
  1275 		}
  1276 	
  1277 	if (aLocalGroup->BaselineShift() != aFetchedGroup->BaselineShift())
  1278 		return EFalse;
  1279 	
  1280 	/*if (aLocalGroup->BoldnessPercentage() != -1)
  1281 		{
  1282 		if (aLocalGroup->BoldnessPercentage() != aFetchedGroup->BoldnessPercentage())
  1283 			{
  1284 			INFO_PRINTF1(_L("Fail below caused by non-matching boldness percentages"));
  1285 			return EFalse;
  1286 			}
  1287 		}
  1288 	
  1289 	if (aLocalGroup->ItalicAngle() != -1)
  1290 		{
  1291 		if (aLocalGroup->ItalicAngle() != aFetchedGroup->ItalicAngle())
  1292 			{
  1293 			INFO_PRINTF1(_L("Fail below caused by non-matching italic angles"));
  1294 			return EFalse;
  1295 			}
  1296 		}
  1297 	*/
  1298 	if (aLocalGroup->ScalingOption() != aFetchedGroup->ScalingOption())
  1299 		return EFalse;
  1300 	if (aLocalGroup->GroupId() != aFetchedGroup->GroupId())
  1301 		return EFalse;
  1302 	
  1303 	return ETrue;
  1304 	}
  1305 
  1306 __CONSTRUCT_STEP__(LinkedFonts2)