sl@0: /*
sl@0: * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: * All rights reserved.
sl@0: * This component and the accompanying materials are made available
sl@0: * under the terms of "Eclipse Public License v1.0"
sl@0: * which accompanies this distribution, and is available
sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: *
sl@0: * Initial Contributors:
sl@0: * Nokia Corporation - initial contribution.
sl@0: *
sl@0: * Contributors:
sl@0: *
sl@0: * Description: 
sl@0: *
sl@0: */
sl@0: 
sl@0: 
sl@0: 
sl@0: #include "FNTSTD.H"
sl@0: #include "t_linkedfontscapability.h"
sl@0: #include <hal.h>
sl@0: #include <linkedfonts.h>
sl@0: 
sl@0: /**
sl@0: @file 
sl@0: 
sl@0: @SYMPurpose This file is used for tests to check the security capabilities
sl@0: of the the calls to the font and bitmap server regarding linked fonts
sl@0: 
sl@0: Registering a linked font requires write device data.  Fetching a linked
sl@0: font requires read device data.
sl@0: 
sl@0: The function uses an ini file to indicate to this file what tests should be run.
sl@0: There are 3 tests, read and write, read, write.  It is important to register a
sl@0: the linked font test first so that it can be fetched.  The test script does this by 
sl@0: calling tests which do not panic, initially.
sl@0: 
sl@0: */
sl@0: _LIT(KLinkedFontsCapabilityFont,"CapabilityTestFnt");
sl@0: _LIT(KLinkedFontsCaseNumber,"CaseNumber");
sl@0: 
sl@0: 
sl@0: 
sl@0: void CTLinkedFontsCapability::TestRegisterL()
sl@0: 	{
sl@0: 	CFbsTypefaceStore* store = CFbsTypefaceStore::NewL(iBitmapDevice);
sl@0: 	CleanupStack::PushL(store);
sl@0: 	
sl@0: 	// Create typeface to be linked
sl@0: 	CLinkedTypefaceSpecification *typefaceSpec;
sl@0: 	typefaceSpec = CLinkedTypefaceSpecification::NewLC(KLinkedFontsCapabilityFont);
sl@0: 	
sl@0: 	CLinkedTypefaceGroup* group1 = CLinkedTypefaceGroup::NewLC(1);
sl@0: 	typefaceSpec->AddLinkedTypefaceGroupL(*group1);
sl@0: 	CleanupStack::Pop();
sl@0: 	
sl@0: 	// Add first typeface
sl@0: 	CLinkedTypefaceElementSpec *elementSpec1;
sl@0: 	_LIT(KLinkedTypefaceTT, "DejaVu Sans Condensed");
sl@0: 	elementSpec1 = CLinkedTypefaceElementSpec::NewLC(KLinkedTypefaceTT, 1);
sl@0: 	elementSpec1->SetCanonical(ETrue);
sl@0: 		
sl@0: 	typefaceSpec->AddTypefaceAtBackL(*elementSpec1);
sl@0: 	CleanupStack::Pop(1, elementSpec1);
sl@0: 	
sl@0: 	// Now try regstering the linked typeface
sl@0: 	TRAPD(ret, typefaceSpec->RegisterLinkedTypefaceL(*store));
sl@0: 	CleanupStack::PopAndDestroy(2, store);
sl@0: 	
sl@0: 	if (ret!=KErrAlreadyExists)
sl@0: 		{
sl@0: 		User::LeaveIfError(ret);
sl@0: 		}
sl@0: 	}
sl@0: 
sl@0: void CTLinkedFontsCapability::CheckLinkedFontsRasterizerInstalledL()
sl@0: 	{
sl@0: 	CFbsTypefaceStore* store = CFbsTypefaceStore::NewL(iBitmapDevice);
sl@0: 	CleanupStack::PushL(store);
sl@0: 	
sl@0: 	// Create typeface to be linked
sl@0: 	CLinkedTypefaceSpecification *typefaceSpec;
sl@0: 	typefaceSpec = CLinkedTypefaceSpecification::NewLC(KLinkedFontsCapabilityFont);
sl@0: 	
sl@0: 	CLinkedTypefaceGroup* group1 = CLinkedTypefaceGroup::NewLC(1);
sl@0: 	typefaceSpec->AddLinkedTypefaceGroupL(*group1);
sl@0: 	CleanupStack::Pop();
sl@0: 	
sl@0: 	// Add first typeface
sl@0: 	CLinkedTypefaceElementSpec *elementSpec1;
sl@0: 	_LIT(KLinkedTypefaceTT, "DejaVu Sans Condensed");
sl@0: 	elementSpec1 = CLinkedTypefaceElementSpec::NewLC(KLinkedTypefaceTT, 1);
sl@0: 	elementSpec1->SetCanonical(ETrue);
sl@0: 		
sl@0: 	typefaceSpec->AddTypefaceAtBackL(*elementSpec1);
sl@0: 	CleanupStack::Pop(1, elementSpec1);
sl@0: 	
sl@0: 	// Now try regstering the linked typeface
sl@0: 	TRAPD(ret, typefaceSpec->RegisterLinkedTypefaceL(*store));
sl@0: 	CleanupStack::PopAndDestroy(2, store);
sl@0: 
sl@0: 	switch (ret)
sl@0: 		{
sl@0: 		case KErrAlreadyExists:
sl@0: 		case KErrNone:
sl@0: 			iHaveRasterizer = ETrue;
sl@0: 		default:
sl@0: 			break;			
sl@0: 		}
sl@0: 	
sl@0: 	if (!iHaveRasterizer)
sl@0: 		{
sl@0: 		INFO_PRINTF1(_L("Linked fonts capability: no linked fonts rasterizer found"));
sl@0: 		}
sl@0: 	}
sl@0: 
sl@0: TBool CTLinkedFontsCapability::LinkedFontsRasterizerPresent()
sl@0: 	{
sl@0: 	return iHaveRasterizer;
sl@0: 	}
sl@0: 
sl@0: 
sl@0: void CTLinkedFontsCapability::TestFetchL()
sl@0: 	{
sl@0: 	CFbsTypefaceStore* store = CFbsTypefaceStore::NewL(iBitmapDevice);
sl@0: 	CleanupStack::PushL(store);
sl@0: 	
sl@0: 	CLinkedTypefaceSpecification *typefaceSpec;
sl@0: 	typefaceSpec = CLinkedTypefaceSpecification::NewLC(KLinkedFontsCapabilityFont);
sl@0: 	
sl@0: 	typefaceSpec->FetchLinkedTypefaceSpecificationL(*store);
sl@0: 	
sl@0: 	CleanupStack::PopAndDestroy(2, store);
sl@0: 	}
sl@0: 
sl@0: CTLinkedFontsCapability::~CTLinkedFontsCapability()
sl@0: 	{
sl@0: 	delete iGc;
sl@0: 	delete iBitmapDevice;
sl@0: 	delete iBitmap;
sl@0: 	}
sl@0: 
sl@0: CTLinkedFontsCapability::CTLinkedFontsCapability(CTestStep *aStep):
sl@0: 	CTGraphicsBase(aStep),
sl@0: 	iHaveRasterizer(EFalse)
sl@0: 	{	
sl@0: 	}
sl@0: 
sl@0: /** Create the screen device.
sl@0: @param aMode display mode for which device has to be created
sl@0: */
sl@0: void CTLinkedFontsCapability::CreateBitmapDeviceL(TDisplayMode aMode)
sl@0: 	{
sl@0: 	iBitmap = new(ELeave) CFbsBitmap;
sl@0: 	//Considering the intersection of the screen size for both hw and emulator so that same
sl@0: 	//baselined hash can be used to test for both
sl@0: 	iBitmap->Create(TSize(40, 40), aMode); //small, bitmap not used
sl@0: 	iBitmapDevice = CFbsBitmapDevice::NewL(iBitmap);
sl@0: 	User::LeaveIfError(iBitmapDevice->CreateContext((CGraphicsContext*&)iGc));
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID GRAPHICS-FNTSTORE-LINKEDFONTS-0110
sl@0: 
sl@0: @SYMTestPriority Critical
sl@0: 
sl@0: @SYMPREQ				PREQ2146
sl@0: 
sl@0: @SYMREQ					REQ10924, REQ10925, REQ10926
sl@0: 
sl@0: @SYMTestCaseDesc 
sl@0: Checks security capabilities for linked fonts
sl@0: 
sl@0: @SYMTestActions 
sl@0: 1 - Run the test case with read device data and write device data
sl@0: 2 - Run the test case with write device data
sl@0: 3 - Run the test case with read device data
sl@0: 4 - Run the test case with no capabilities
sl@0: 
sl@0: @SYMTestExpectedResults 
sl@0: 1- A linked font can be registered or returns KErrAlreadyExists and linked fonts can be fetched.
sl@0: 2- Registering a linked font fails with panic E32USER-CBase panic 47, and linked fonts can be fetched.
sl@0: 3- Registering a linked font succeeds or returns KErrAlreadyExists and fetching a linked font fail with panic E32USER-CBase panic 47.
sl@0: 4- Registering a linked font fails with panic E32USER-CBase panic 47. Fetching a linked font fails with panic E32USER-CBase panic 47.
sl@0: 
sl@0: */
sl@0: void CTLinkedFontsCapability::RunTestCaseL(TInt /*aCurTestCase*/)
sl@0: 	{
sl@0: 	INFO_PRINTF1(_L("Linked fonts capability  tests" ));
sl@0: 	TInt curTestCase;
sl@0: 		//Read the case number from the ini file
sl@0: 	TBool res = iStep->GetIntFromConfig(iStep->ConfigSection(), KLinkedFontsCaseNumber, curTestCase);		
sl@0: 	if(!res)
sl@0: 		{
sl@0: 		TEST(EFalse);
sl@0: 		return ;
sl@0: 		}	
sl@0: 	
sl@0: 	CreateBitmapDeviceL(EColor16MU);
sl@0: 	TInt err=KErrNone;
sl@0: 	TInt err2=KErrNone;
sl@0: 
sl@0: 	((CTLinkedFontsCapabilityStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
sl@0: 
sl@0: 	switch (curTestCase)
sl@0: 		{
sl@0: 		case 1:
sl@0: 			((CTLinkedFontsCapabilityStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-LINKEDFONTS-0110"));
sl@0: 			CheckLinkedFontsRasterizerInstalledL();
sl@0: 			break;		
sl@0: 		case 2:
sl@0: 			((CTLinkedFontsCapabilityStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-LINKEDFONTS-0110"));
sl@0: 			if (LinkedFontsRasterizerPresent())
sl@0: 				{
sl@0: 				TestRegisterL();
sl@0: 				TestFetchL();
sl@0: 				}
sl@0: 			break;
sl@0: 		case 3:
sl@0: 			((CTLinkedFontsCapabilityStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-LINKEDFONTS-0110"));
sl@0: 			if (LinkedFontsRasterizerPresent())
sl@0: 				{
sl@0: 				TestRegisterL();//write only
sl@0: 				}
sl@0: 			break;
sl@0: 		case 4:
sl@0: 			((CTLinkedFontsCapabilityStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-LINKEDFONTS-0110"));
sl@0: 			if (LinkedFontsRasterizerPresent())
sl@0: 				{
sl@0: 				TestFetchL();//read only
sl@0: 				}
sl@0: 			break;
sl@0: 			
sl@0: 		//following are similar to tests 2-4, but leaves if no permission to access the capabilities
sl@0: 		case 5:
sl@0: 			((CTLinkedFontsCapabilityStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-LINKEDFONTS-0110"));
sl@0: 			if(LinkedFontsRasterizerPresent())
sl@0: 				{
sl@0: 				TRAP(err,TestRegisterL());
sl@0: 				TRAP(err2, TestFetchL());
sl@0: 				TEST((err == KErrPermissionDenied)&&(err2 == KErrPermissionDenied));
sl@0: 				}
sl@0: 			break;
sl@0: 		case 6:
sl@0: 			((CTLinkedFontsCapabilityStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-LINKEDFONTS-0110"));
sl@0: 			if(LinkedFontsRasterizerPresent())
sl@0: 				{
sl@0: 				TRAP(err,TestRegisterL());//write only
sl@0: 				TEST(err == KErrPermissionDenied);
sl@0: 				}
sl@0: 			break;
sl@0: 		case 7:
sl@0: 			((CTLinkedFontsCapabilityStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-LINKEDFONTS-0110"));
sl@0: 			if(LinkedFontsRasterizerPresent())
sl@0: 				{
sl@0: 				TRAP(err, TestFetchL());//read only
sl@0: 				TEST(err == KErrPermissionDenied);
sl@0: 				}
sl@0: 			break;			
sl@0: 		default:
sl@0: 			{
sl@0: 			((CTLinkedFontsCapabilityStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
sl@0: 			((CTLinkedFontsCapabilityStep*)iStep)->CloseTMSGraphicsStep();
sl@0: 			TEST(EFalse); //nothing should have the default value
sl@0: 			break;
sl@0: 			}
sl@0: 		}
sl@0: 	((CTLinkedFontsCapabilityStep*)iStep)->RecordTestResultL();
sl@0: 	TEST(ETrue);
sl@0: 	((CTLinkedFontsCapabilityStep*)iStep)->CloseTMSGraphicsStep();
sl@0: 	TestComplete();
sl@0: 	}
sl@0: 
sl@0: __CONSTRUCT_STEP__(LinkedFontsCapability)
sl@0: