os/textandloc/fontservices/fontstore/tfs/T_LinkedFontUpdateTests.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 1995-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 #include "T_LinkedFontUpdateTests.h"
    19 
    20 CTLinkedFontsUpdateStage1::CTLinkedFontsUpdateStage1(CTestStep* aStep)
    21 :	CTGraphicsBase(aStep)
    22 	{
    23 	iFontLinkingSupported = EFalse;
    24 	}
    25 
    26 CTLinkedFontsUpdateStage1::~CTLinkedFontsUpdateStage1()
    27 	{
    28 	}
    29 
    30 void CTLinkedFontsUpdateStage1::TestPanic(TInt aPanic)
    31 	{
    32 	_LIT(KFntTestStorePanicCategory,"TestFntStore");
    33 	User::Panic(KFntTestStorePanicCategory,aPanic);
    34 	}
    35 
    36 void CTLinkedFontsUpdateStage1::RunTestCaseL(TInt aCurTestCase)
    37 	{
    38 	((CTLinkedFontsUpdateStage1Step*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
    39 	switch (aCurTestCase)
    40 		{
    41 		case 1:
    42 			((CTLinkedFontsUpdateStage1Step*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
    43 			SetupTestsL();
    44 			break;
    45 		case 2:
    46 			((CTLinkedFontsUpdateStage1Step*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-LINKEDFONTS-0200"));
    47 			RegisterThenUpdateTestL();
    48 			break;
    49 		case 3:
    50 			((CTLinkedFontsUpdateStage1Step*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-LINKEDFONTS-0201"));
    51 			NegativeUpdateTestsL();
    52 			break;
    53 		case 4:
    54 			((CTLinkedFontsUpdateStage1Step*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
    55 			CloseTestsL();
    56 			break;
    57 		default:
    58 			((CTLinkedFontsUpdateStage1Step*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
    59 			((CTLinkedFontsUpdateStage1Step*)iStep)->CloseTMSGraphicsStep();
    60 			TestComplete();
    61 			break;
    62 		}
    63 	((CTLinkedFontsUpdateStage1Step*)iStep)->RecordTestResultL();
    64 	}
    65 
    66 /**
    67 Connect to the Font Bitmap Server and construct a CFbsTypeface store to access the fontstore.
    68 */
    69 void CTLinkedFontsUpdateStage1::SetupTestsL()
    70 	{
    71 	TInt ret = RFbsSession::Connect();
    72 	TEST2(ret, KErrNone);
    73 	
    74 	iFbs = RFbsSession::GetSession();
    75 	
    76 	iTfStore = CFbsTypefaceStore::NewL(NULL);
    77 	}
    78 
    79 void CTLinkedFontsUpdateStage1::CloseTestsL()
    80 	{
    81 	delete iTfStore;
    82 	RFbsSession::Disconnect();
    83 	}
    84 /**
    85 @SYMTestCaseID
    86 GRAPHICS-FNTSTORE-LINKEDFONTS-0200
    87 
    88 @SYMPREQ
    89 PREQ2147
    90 
    91 @SYMREQ
    92 REQ11859
    93 
    94 @SYMTestCaseDesc
    95 Creates three brand new linked typefaces, then updates each. The first typeface has an
    96 element added to it, the second has one removed and the third is replaced with a different
    97 specification.
    98 
    99 The outcome of the update process is checked after a reboot by test case 202.
   100 
   101 @SYMTestPriority
   102 Critical
   103 
   104 @SYMTestStatus
   105 Implemented
   106 
   107 @SYMTestActions
   108 Checks the update process has completed succesfully.
   109 
   110 @SYMTestExpectedResults
   111 Linked fonts are created and updated successfully. Validation of the new file is performed after a reboot.
   112 */
   113 
   114 void CTLinkedFontsUpdateStage1::RegisterThenUpdateTestL()
   115 	{
   116 	CLinkedTypefaceSpecification* addSpec = CreateAddTypefaceLC(EFalse);
   117 	CLinkedTypefaceSpecification* removeSpec = CreateRemoveTypefaceLC(EFalse);
   118 	CLinkedTypefaceSpecification* updateSpec = CreateUpdateTypefaceLC(EFalse);
   119 	
   120 	//Create three new linked fonts
   121 	TRAPD(ret, addSpec->RegisterLinkedTypefaceL(*iTfStore));
   122 	
   123 	//Ensure that a supporting rasterizer is present.
   124 	if (ret == KErrNotSupported)
   125 		{
   126 		WARN_PRINTF1(_L("There is not a font rasterizer present supporting font linking installed, skipping test."));
   127 		CleanupStack::PopAndDestroy(3, addSpec);
   128 		return;
   129 		}
   130 	else
   131 		{
   132 		iFontLinkingSupported = ETrue;
   133 		}
   134 	
   135 	TEST(ret == KErrNone);
   136 	TRAP(ret, removeSpec->RegisterLinkedTypefaceL(*iTfStore));
   137 	TEST(ret == KErrNone);
   138 	TRAP(ret, updateSpec->RegisterLinkedTypefaceL(*iTfStore));
   139 	TEST(ret == KErrNone);
   140 	
   141 	CleanupStack::PopAndDestroy(3);
   142 	
   143 	//Update the three linked fonts with their new specifications
   144 	addSpec = CreateAddTypefaceLC(ETrue);
   145 	TRAP(ret, addSpec->UpdateLinkedTypefaceL(*iTfStore));
   146 	TEST(ret == KErrNone);
   147 	
   148 	removeSpec = CreateRemoveTypefaceLC(ETrue);
   149 	TRAP(ret, removeSpec->UpdateLinkedTypefaceL(*iTfStore));
   150 	TEST(ret == KErrNone);
   151 	
   152 	updateSpec = CreateUpdateTypefaceLC(ETrue);
   153 	TRAP(ret, updateSpec->UpdateLinkedTypefaceL(*iTfStore));
   154 	TEST(ret == KErrNone);
   155 	
   156 	CleanupStack::PopAndDestroy(3, addSpec);
   157 	}
   158 
   159 /**
   160 @SYMTestCaseID
   161 GRAPHICS-FNTSTORE-LINKEDFONTS-0201
   162 
   163 @SYMPREQ
   164 PREQ2147
   165 
   166 @SYMREQ
   167 REQ11859
   168 
   169 @SYMTestCaseDesc
   170 Attempt to update a linked font with Invalid or Non-Existent Elements.
   171 Attempt to update a non-linked font.
   172 
   173 @SYMTestPriority
   174 Critical
   175 
   176 @SYMTestStatus
   177 Implemented
   178 
   179 @SYMTestActions
   180 Ensures the correct error codes are returned showing that no updates were made to the relevant typefaces.
   181 
   182 @SYMTestExpectedResults
   183 All invalid updates will return KErrNotFound or KErrAccessDenied
   184 */
   185 void CTLinkedFontsUpdateStage1::NegativeUpdateTestsL()
   186 	{
   187 	if (!iFontLinkingSupported)
   188 		{
   189 		WARN_PRINTF1(_L("There is not a font rasterizer present supporting font linking installed, skipping test."));
   190 		return;
   191 		}
   192 	//Update with invalid element
   193 	CLinkedTypefaceSpecification* invalidSpec =  CreateUpdateTypefaceLC(EFalse);
   194 	
   195 	CLinkedTypefaceElementSpec* invalidElement = CLinkedTypefaceElementSpec::NewLC(_L("SomeThingInValid"), 1);
   196 	invalidSpec->AddTypefaceAtBackL(*invalidElement);
   197 	CleanupStack::Pop(invalidElement);
   198 	
   199 	TRAPD(ret, invalidSpec->UpdateLinkedTypefaceL(*iTfStore));
   200 	TEST(ret == KErrNotFound);
   201 	
   202 	CleanupStack::PopAndDestroy(invalidSpec);
   203 	
   204 	//Update a typeface that doesn't exist.
   205 	_LIT(KNonExistantTypeface, "DoesNotExist");
   206 	CLinkedTypefaceSpecification* nonExistentTypeface = CreateNegativeTestTypefaceLC(KNonExistantTypeface);
   207 	TRAP(ret, nonExistentTypeface->UpdateLinkedTypefaceL(*iTfStore));
   208 	TEST(ret == KErrNotFound);
   209 	
   210 	CleanupStack::PopAndDestroy(nonExistentTypeface);
   211 	
   212 	//Update the default techview font (that is not a linked font).
   213 	_LIT(KNonLinkedFontName, "DejaVu Sans Condensed");
   214 	CLinkedTypefaceSpecification* nonLinkedTypeface = CreateNegativeTestTypefaceLC(KNonLinkedFontName);
   215 	TRAP(ret, nonLinkedTypeface->UpdateLinkedTypefaceL(*iTfStore));
   216 	TEST(ret == KErrAccessDenied);
   217 	
   218 	CleanupStack::PopAndDestroy(nonLinkedTypeface);
   219 
   220 	}
   221 
   222 /**
   223 Create a typeface to test adding a new element to a linked font.
   224  @param TBool EFalse for Original, ETrue for Update version
   225  */ 
   226 CLinkedTypefaceSpecification* CTLinkedFontsUpdateStage1::CreateAddTypefaceLC(TBool aUpdate)
   227 	{
   228 	CLinkedTypefaceSpecification* spec = CLinkedTypefaceSpecification::NewLC(KAddElementFontName);
   229 	
   230 	AddGroups(spec);
   231 	
   232 	CLinkedTypefaceElementSpec* element = CLinkedTypefaceElementSpec::NewLC(KElement1Name, 1);
   233 	element->SetCanonical(ETrue);
   234 	spec->AddTypefaceAtBackL(*element);
   235 	CleanupStack::Pop(element);
   236 	
   237 	element = CLinkedTypefaceElementSpec::NewLC(KElement2Name, 2);
   238 	spec->AddTypefaceAtBackL(*element);
   239 	CleanupStack::Pop(element);
   240 	
   241 	if (aUpdate)
   242 		{
   243 		element = CLinkedTypefaceElementSpec::NewLC(KElement3Name, 2);
   244 		spec->AddTypefaceAtBackL(*element);
   245 		CleanupStack::Pop(element);
   246 		}
   247 	
   248 	return spec;
   249 	}
   250 
   251 /**
   252 Create a typeface to test removing an element from a linked font.
   253  @param TBool EFalse for Original, ETrue for Update version
   254  */ 
   255 CLinkedTypefaceSpecification* CTLinkedFontsUpdateStage1::CreateRemoveTypefaceLC(TBool aUpdate)
   256 	{
   257 	CLinkedTypefaceSpecification* spec = CLinkedTypefaceSpecification::NewLC(KRemoveElementFontName);
   258 	AddGroups(spec);
   259 	
   260 	CLinkedTypefaceElementSpec* element = CLinkedTypefaceElementSpec::NewLC(KElement1Name, 1);
   261 	element->SetCanonical(ETrue);
   262 	spec->AddTypefaceAtBackL(*element);
   263 	CleanupStack::Pop(element);
   264 	
   265 	element = CLinkedTypefaceElementSpec::NewLC(KElement2Name, 2);
   266 	spec->AddTypefaceAtBackL(*element);
   267 	CleanupStack::Pop(element);
   268 	
   269 	if (!aUpdate)
   270 		{
   271 		element = CLinkedTypefaceElementSpec::NewLC(KElement3Name, 2);
   272 		spec->AddTypefaceAtBackL(*element);
   273 		CleanupStack::Pop(element);
   274 		}
   275 	
   276 	return spec;
   277 	}
   278 
   279 /**
   280 Create a typeface to test completely changing a linked font.
   281  @param TBool EFalse for Original, ETrue for Update version
   282  */ 
   283 CLinkedTypefaceSpecification* CTLinkedFontsUpdateStage1::CreateUpdateTypefaceLC(TBool aUpdate)
   284 	{
   285 	CLinkedTypefaceSpecification* spec = CLinkedTypefaceSpecification::NewLC(KUpdateFontName);
   286 	AddGroups(spec);
   287 	
   288 	CLinkedTypefaceElementSpec* element;
   289 	
   290 	if (!aUpdate)
   291 		{
   292 		element = CLinkedTypefaceElementSpec::NewLC(KElement1Name, 1);
   293 		element->SetCanonical(ETrue);
   294 		spec->AddTypefaceAtBackL(*element);
   295 		CleanupStack::Pop(element);
   296 		}
   297 	
   298 	element = CLinkedTypefaceElementSpec::NewLC(KElement2Name, 2);
   299 	spec->AddTypefaceAtBackL(*element);
   300 	CleanupStack::Pop(element);
   301 	
   302 	if (aUpdate)
   303 		{
   304 		CLinkedTypefaceElementSpec* element = CLinkedTypefaceElementSpec::NewLC(KElement3Name, 1);
   305 		element->SetCanonical(ETrue);
   306 		spec->AddTypefaceAtBackL(*element);
   307 		CleanupStack::Pop(element);
   308 		}
   309 	
   310 	return spec;
   311 	}
   312 
   313 /**
   314 Create a typeface for use in the negative test cases.
   315 
   316 This has a number of typeface groups already added to it.
   317 
   318 @see CTLinkedFontsUpdate1::AddGroups()
   319 @param aName The name of the typeface.
   320 */
   321 CLinkedTypefaceSpecification* CTLinkedFontsUpdateStage1::CreateNegativeTestTypefaceLC(const TDesC& aName)
   322 	{
   323 	CLinkedTypefaceSpecification* spec = CLinkedTypefaceSpecification::NewLC(aName);
   324 	
   325 	AddGroups(spec);
   326 	
   327 	CLinkedTypefaceElementSpec* element = CLinkedTypefaceElementSpec::NewLC(_L("DejaVu Sans Condensed"), 1);
   328 	element->SetCanonical(ETrue);
   329 	spec->AddTypefaceAtBackL(*element);
   330 	CleanupStack::Pop(element);	
   331 	
   332 	return spec;
   333 	}
   334 
   335 /**
   336 Adds two simple linked typeface groups to the linked typeface group.
   337 
   338 @param aSpec The specification to have groups added to
   339 */
   340 void CTLinkedFontsUpdateStage1::AddGroups(CLinkedTypefaceSpecification* aSpec)
   341 	{
   342 	CLinkedTypefaceGroup* grp = CLinkedTypefaceGroup::NewLC(1);
   343 	grp->SetBaselineShift(CLinkedTypefaceGroup::EBaselineShift);
   344 	aSpec->AddLinkedTypefaceGroupL(*grp);
   345 	CleanupStack::Pop(grp);
   346 	
   347 	grp = CLinkedTypefaceGroup::NewLC(2);
   348 	grp->SetBaselineShift(CLinkedTypefaceGroup::ENoBaselineShift);
   349 	aSpec->AddLinkedTypefaceGroupL(*grp);
   350 	CleanupStack::Pop(grp);
   351 	}
   352 
   353 __CONSTRUCT_STEP__(LinkedFontsUpdateStage1)
   354 
   355 
   356 //CTLinkedFontsUpdate2
   357 CTLinkedFontsUpdateStage2::CTLinkedFontsUpdateStage2(CTestStep* aStep)
   358 :	CTGraphicsBase(aStep)
   359 	{
   360 	}
   361 
   362 CTLinkedFontsUpdateStage2::~CTLinkedFontsUpdateStage2()
   363 	{
   364 	}
   365 
   366 void CTLinkedFontsUpdateStage2::TestPanic(TInt aPanic)
   367 	{
   368 	_LIT(KFntTestStorePanicCategory,"TestFntStore");
   369 	User::Panic(KFntTestStorePanicCategory,aPanic);
   370 	}
   371 
   372 void CTLinkedFontsUpdateStage2::RunTestCaseL(TInt aCurTestCase)
   373 	{
   374 	((CTLinkedFontsUpdateStage2Step*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
   375 	switch (aCurTestCase)
   376 		{
   377 		case 1:
   378 			((CTLinkedFontsUpdateStage2Step*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
   379 			SetupTestsL();
   380 			break;
   381 		case 2:
   382 			((CTLinkedFontsUpdateStage1Step*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-LINKEDFONTS-0202"));
   383 			ValidateLinkedFontsL();
   384 			break;
   385 		case 3:
   386 			((CTLinkedFontsUpdateStage2Step*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
   387 			CloseTestsL();
   388 		default:
   389 			((CTLinkedFontsUpdateStage2Step*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
   390 			((CTLinkedFontsUpdateStage2Step*)iStep)->CloseTMSGraphicsStep();
   391 			TestComplete();
   392 			break;
   393 		}
   394 		((CTLinkedFontsUpdateStage2Step*)iStep)->RecordTestResultL();
   395 	}
   396 
   397 /**
   398 Connect to the Font Bitmap Server and construct a CFbsTypeface store to access the fontstore.
   399 */
   400 void CTLinkedFontsUpdateStage2::SetupTestsL()
   401 	{
   402 	TInt ret = RFbsSession::Connect();
   403 	TEST2(ret, KErrNone);
   404 	
   405 	iFbs = RFbsSession::GetSession();
   406 	
   407 	iTfStore = CFbsTypefaceStore::NewL(NULL);
   408 	}
   409 
   410 void CTLinkedFontsUpdateStage2::CloseTestsL()
   411 	{
   412 	delete iTfStore;
   413 	RFbsSession::Disconnect();
   414 	}
   415 /**
   416 @SYMTestCaseID
   417 GRAPHICS-FNTSTORE-LINKEDFONTS-0202
   418 
   419 @SYMPREQ
   420 PREQ2147
   421 
   422 @SYMREQ
   423 REQ11859
   424 
   425 @SYMTestCaseDesc
   426 Tests the updates made to three linked typefaces created by test case 200; this checks the linked fonts
   427 have been correctly updated to the latest specification. 
   428 
   429 @SYMTestPriority
   430 Critical
   431 
   432 @SYMTestStatus
   433 Implemented
   434 
   435 @SYMTestActions
   436 Checks the update process has completed succesfully.
   437 
   438 @SYMTestExpectedResults
   439 The linked fonts match the specification they were updated to. 
   440 Failures may be due to other failures in test case xxx as this is the second stage of these tests.
   441 */
   442 void CTLinkedFontsUpdateStage2::ValidateLinkedFontsL()
   443 	{
   444 	CLinkedTypefaceSpecification* addSpec = CLinkedTypefaceSpecification::NewLC(KAddElementFontName);
   445 	TRAPD(ret, addSpec->FetchLinkedTypefaceSpecificationL(*iTfStore));
   446 	TEST(ret == KErrNone);
   447 	
   448 	CLinkedTypefaceSpecification* removeSpec = CLinkedTypefaceSpecification::NewLC(KRemoveElementFontName);
   449 	TRAP(ret, removeSpec->FetchLinkedTypefaceSpecificationL(*iTfStore));
   450 	TEST(ret == KErrNone);
   451 	
   452 	CLinkedTypefaceSpecification* updateSpec = CLinkedTypefaceSpecification::NewLC(KUpdateFontName);
   453 	TRAP(ret, updateSpec->FetchLinkedTypefaceSpecificationL(*iTfStore));
   454 	TEST(ret == KErrNone);
   455 	
   456 	//Test Elements are in correct order
   457 	TEST(addSpec->TypefaceCount() == 3);
   458 	
   459 	if (addSpec->Typeface(0))
   460 		TEST(addSpec->Typeface(0)->ElementName() == KElement1Name);
   461 	else
   462 		TEST(EFalse);
   463 	
   464 	if (addSpec->Typeface(1))
   465 		TEST(addSpec->Typeface(1)->ElementName() == KElement2Name);
   466 	else
   467 		TEST(EFalse);
   468 	
   469 	if (addSpec->Typeface(2))
   470 		TEST(addSpec->Typeface(2)->ElementName() == KElement3Name);
   471 	else
   472 		TEST(EFalse);
   473 	
   474 	TEST(removeSpec->TypefaceCount() == 2);
   475 	if (addSpec->Typeface(0))
   476 		TEST(removeSpec->Typeface(0)->ElementName() == KElement1Name);
   477 	else
   478 		TEST(EFalse);
   479 	
   480 	if (addSpec->Typeface(1))
   481 		TEST(removeSpec->Typeface(1)->ElementName() == KElement2Name);
   482 	else
   483 		TEST(EFalse);
   484 	
   485 	TEST(updateSpec->TypefaceCount() == 2);
   486 	if (addSpec->Typeface(1))
   487 		TEST(updateSpec->Typeface(0)->ElementName() == KElement2Name);
   488 	else
   489 		TEST(EFalse);
   490 	
   491 	if (addSpec->Typeface(1))
   492 		TEST(updateSpec->Typeface(1)->ElementName() == KElement3Name);
   493 	else
   494 		TEST(EFalse);
   495 	
   496 	CleanupStack::PopAndDestroy(3, addSpec);
   497 	}
   498 
   499 __CONSTRUCT_STEP__(LinkedFontsUpdateStage2)