Update contrib.
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
21 #include "t_linkedfontscapability.h"
23 #include <linkedfonts.h>
28 @SYMPurpose This file is used for tests to check the security capabilities
29 of the the calls to the font and bitmap server regarding linked fonts
31 Registering a linked font requires write device data. Fetching a linked
32 font requires read device data.
34 The function uses an ini file to indicate to this file what tests should be run.
35 There are 3 tests, read and write, read, write. It is important to register a
36 the linked font test first so that it can be fetched. The test script does this by
37 calling tests which do not panic, initially.
40 _LIT(KLinkedFontsCapabilityFont,"CapabilityTestFnt");
41 _LIT(KLinkedFontsCaseNumber,"CaseNumber");
45 void CTLinkedFontsCapability::TestRegisterL()
47 CFbsTypefaceStore* store = CFbsTypefaceStore::NewL(iBitmapDevice);
48 CleanupStack::PushL(store);
50 // Create typeface to be linked
51 CLinkedTypefaceSpecification *typefaceSpec;
52 typefaceSpec = CLinkedTypefaceSpecification::NewLC(KLinkedFontsCapabilityFont);
54 CLinkedTypefaceGroup* group1 = CLinkedTypefaceGroup::NewLC(1);
55 typefaceSpec->AddLinkedTypefaceGroupL(*group1);
59 CLinkedTypefaceElementSpec *elementSpec1;
60 _LIT(KLinkedTypefaceTT, "DejaVu Sans Condensed");
61 elementSpec1 = CLinkedTypefaceElementSpec::NewLC(KLinkedTypefaceTT, 1);
62 elementSpec1->SetCanonical(ETrue);
64 typefaceSpec->AddTypefaceAtBackL(*elementSpec1);
65 CleanupStack::Pop(1, elementSpec1);
67 // Now try regstering the linked typeface
68 TRAPD(ret, typefaceSpec->RegisterLinkedTypefaceL(*store));
69 CleanupStack::PopAndDestroy(2, store);
71 if (ret!=KErrAlreadyExists)
73 User::LeaveIfError(ret);
77 void CTLinkedFontsCapability::CheckLinkedFontsRasterizerInstalledL()
79 CFbsTypefaceStore* store = CFbsTypefaceStore::NewL(iBitmapDevice);
80 CleanupStack::PushL(store);
82 // Create typeface to be linked
83 CLinkedTypefaceSpecification *typefaceSpec;
84 typefaceSpec = CLinkedTypefaceSpecification::NewLC(KLinkedFontsCapabilityFont);
86 CLinkedTypefaceGroup* group1 = CLinkedTypefaceGroup::NewLC(1);
87 typefaceSpec->AddLinkedTypefaceGroupL(*group1);
91 CLinkedTypefaceElementSpec *elementSpec1;
92 _LIT(KLinkedTypefaceTT, "DejaVu Sans Condensed");
93 elementSpec1 = CLinkedTypefaceElementSpec::NewLC(KLinkedTypefaceTT, 1);
94 elementSpec1->SetCanonical(ETrue);
96 typefaceSpec->AddTypefaceAtBackL(*elementSpec1);
97 CleanupStack::Pop(1, elementSpec1);
99 // Now try regstering the linked typeface
100 TRAPD(ret, typefaceSpec->RegisterLinkedTypefaceL(*store));
101 CleanupStack::PopAndDestroy(2, store);
105 case KErrAlreadyExists:
107 iHaveRasterizer = ETrue;
112 if (!iHaveRasterizer)
114 INFO_PRINTF1(_L("Linked fonts capability: no linked fonts rasterizer found"));
118 TBool CTLinkedFontsCapability::LinkedFontsRasterizerPresent()
120 return iHaveRasterizer;
124 void CTLinkedFontsCapability::TestFetchL()
126 CFbsTypefaceStore* store = CFbsTypefaceStore::NewL(iBitmapDevice);
127 CleanupStack::PushL(store);
129 CLinkedTypefaceSpecification *typefaceSpec;
130 typefaceSpec = CLinkedTypefaceSpecification::NewLC(KLinkedFontsCapabilityFont);
132 typefaceSpec->FetchLinkedTypefaceSpecificationL(*store);
134 CleanupStack::PopAndDestroy(2, store);
137 CTLinkedFontsCapability::~CTLinkedFontsCapability()
140 delete iBitmapDevice;
144 CTLinkedFontsCapability::CTLinkedFontsCapability(CTestStep *aStep):
145 CTGraphicsBase(aStep),
146 iHaveRasterizer(EFalse)
150 /** Create the screen device.
151 @param aMode display mode for which device has to be created
153 void CTLinkedFontsCapability::CreateBitmapDeviceL(TDisplayMode aMode)
155 iBitmap = new(ELeave) CFbsBitmap;
156 //Considering the intersection of the screen size for both hw and emulator so that same
157 //baselined hash can be used to test for both
158 iBitmap->Create(TSize(40, 40), aMode); //small, bitmap not used
159 iBitmapDevice = CFbsBitmapDevice::NewL(iBitmap);
160 User::LeaveIfError(iBitmapDevice->CreateContext((CGraphicsContext*&)iGc));
164 @SYMTestCaseID GRAPHICS-FNTSTORE-LINKEDFONTS-0110
166 @SYMTestPriority Critical
170 @SYMREQ REQ10924, REQ10925, REQ10926
173 Checks security capabilities for linked fonts
176 1 - Run the test case with read device data and write device data
177 2 - Run the test case with write device data
178 3 - Run the test case with read device data
179 4 - Run the test case with no capabilities
181 @SYMTestExpectedResults
182 1- A linked font can be registered or returns KErrAlreadyExists and linked fonts can be fetched.
183 2- Registering a linked font fails with panic E32USER-CBase panic 47, and linked fonts can be fetched.
184 3- Registering a linked font succeeds or returns KErrAlreadyExists and fetching a linked font fail with panic E32USER-CBase panic 47.
185 4- Registering a linked font fails with panic E32USER-CBase panic 47. Fetching a linked font fails with panic E32USER-CBase panic 47.
188 void CTLinkedFontsCapability::RunTestCaseL(TInt /*aCurTestCase*/)
190 INFO_PRINTF1(_L("Linked fonts capability tests" ));
192 //Read the case number from the ini file
193 TBool res = iStep->GetIntFromConfig(iStep->ConfigSection(), KLinkedFontsCaseNumber, curTestCase);
200 CreateBitmapDeviceL(EColor16MU);
204 ((CTLinkedFontsCapabilityStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
209 ((CTLinkedFontsCapabilityStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-LINKEDFONTS-0110"));
210 CheckLinkedFontsRasterizerInstalledL();
213 ((CTLinkedFontsCapabilityStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-LINKEDFONTS-0110"));
214 if (LinkedFontsRasterizerPresent())
221 ((CTLinkedFontsCapabilityStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-LINKEDFONTS-0110"));
222 if (LinkedFontsRasterizerPresent())
224 TestRegisterL();//write only
228 ((CTLinkedFontsCapabilityStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-LINKEDFONTS-0110"));
229 if (LinkedFontsRasterizerPresent())
231 TestFetchL();//read only
235 //following are similar to tests 2-4, but leaves if no permission to access the capabilities
237 ((CTLinkedFontsCapabilityStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-LINKEDFONTS-0110"));
238 if(LinkedFontsRasterizerPresent())
240 TRAP(err,TestRegisterL());
241 TRAP(err2, TestFetchL());
242 TEST((err == KErrPermissionDenied)&&(err2 == KErrPermissionDenied));
246 ((CTLinkedFontsCapabilityStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-LINKEDFONTS-0110"));
247 if(LinkedFontsRasterizerPresent())
249 TRAP(err,TestRegisterL());//write only
250 TEST(err == KErrPermissionDenied);
254 ((CTLinkedFontsCapabilityStep*)iStep)->SetTestStepID(_L("GRAPHICS-FNTSTORE-LINKEDFONTS-0110"));
255 if(LinkedFontsRasterizerPresent())
257 TRAP(err, TestFetchL());//read only
258 TEST(err == KErrPermissionDenied);
263 ((CTLinkedFontsCapabilityStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
264 ((CTLinkedFontsCapabilityStep*)iStep)->CloseTMSGraphicsStep();
265 TEST(EFalse); //nothing should have the default value
269 ((CTLinkedFontsCapabilityStep*)iStep)->RecordTestResultL();
271 ((CTLinkedFontsCapabilityStep*)iStep)->CloseTMSGraphicsStep();
275 __CONSTRUCT_STEP__(LinkedFontsCapability)