|
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 #include "testharness.h" |
|
20 #include <bitdev.h> |
|
21 #include <fntstore.h> |
|
22 #include <fbs.h> |
|
23 #include <test/testexecutestepbase.h> |
|
24 #include <graphics/fbsdefs.h> |
|
25 |
|
26 CTestHarness::CTestHarness(CTestStep* aStep) : |
|
27 iStep(aStep) |
|
28 { |
|
29 iStep -> INFO_PRINTF1(iStep -> TestStepName()); |
|
30 } |
|
31 |
|
32 CTestHarness* CTestHarness::NewL(CTestStep* aStep) |
|
33 { |
|
34 CTestHarness* t = new (ELeave)CTestHarness (aStep); |
|
35 CleanupStack::PushL(t); |
|
36 t->ConstructL(); |
|
37 CleanupStack::Pop(); |
|
38 return t; |
|
39 } |
|
40 |
|
41 void CTestHarness::ConstructL() |
|
42 { |
|
43 User::LeaveIfError(FbsStartup()); |
|
44 |
|
45 RFbsSession::Connect(); |
|
46 iFbs = RFbsSession::GetSession(); |
|
47 if (iFbs == NULL) |
|
48 User::Leave(KErrGeneral); |
|
49 |
|
50 TRAPD(error, iDev = CFbsScreenDevice::NewL(_L("scdv"),EColor16M)); |
|
51 if (error == KErrNotSupported) |
|
52 TRAP(error, iDev = CFbsScreenDevice::NewL(_L("scdv"),EColor16MA)); |
|
53 if (error == KErrNotSupported) |
|
54 TRAP(error, iDev = CFbsScreenDevice::NewL(_L("scdv"),EColor16MU)); |
|
55 if (error == KErrNotSupported) |
|
56 TRAP(error, iDev = CFbsScreenDevice::NewL(_L("scdv"),EColor64K)); |
|
57 if (error == KErrNotSupported) |
|
58 TRAP(error, iDev = CFbsScreenDevice::NewL(_L("scdv"),EColor4K)); |
|
59 if (error == KErrNotSupported) |
|
60 TRAP(error, iDev = CFbsScreenDevice::NewL(_L("scdv"),EColor256)); |
|
61 if (error == KErrNotSupported) |
|
62 TRAP(error, iDev = CFbsScreenDevice::NewL(_L("scdv"),EColor16)); |
|
63 if (error == KErrNotSupported) |
|
64 TRAP(error, iDev = CFbsScreenDevice::NewL(_L("scdv"),EGray256)); |
|
65 if (error == KErrNotSupported) |
|
66 TRAP(error, iDev = CFbsScreenDevice::NewL(_L("scdv"),EGray16)); |
|
67 if (error == KErrNotSupported) |
|
68 TRAP(error, iDev = CFbsScreenDevice::NewL(_L("scdv"),EGray4)); |
|
69 if (error == KErrNotSupported) |
|
70 TRAP(error, iDev = CFbsScreenDevice::NewL(_L("scdv"),EGray2)); |
|
71 if (error == KErrNotSupported) |
|
72 TRAP(error, iDev = CFbsScreenDevice::NewL(_L("scdv"),EColor16MAP)); |
|
73 |
|
74 if(error == KErrNone) |
|
75 { |
|
76 iDev->ChangeScreenDevice(NULL); |
|
77 iDev->SetAutoUpdate(ETrue); |
|
78 iDev->CreateContext(iGc); |
|
79 |
|
80 TFontSpec fs(_L("DejaVu Sans Condensed"),16); |
|
81 error = iDev->GetNearestFontToDesignHeightInPixels((CFont*&)iStandardFont,fs); |
|
82 if (error) |
|
83 User::Panic(_L("Could not create 16-pixel DejaVu Sans Condensed"),error); |
|
84 } |
|
85 } |
|
86 |
|
87 CTestHarness::~CTestHarness() |
|
88 { |
|
89 if (iStandardFont) |
|
90 iDev->ReleaseFont(iStandardFont); |
|
91 delete iGc; |
|
92 delete iDev; |
|
93 RFbsSession::Disconnect(); |
|
94 } |
|
95 |
|
96 void CTestHarness::PerformTests() |
|
97 { |
|
98 iStep->INFO_PRINTF1(_L("Test started")); |
|
99 |
|
100 TInt typefaces = iDev->NumTypefaces(); |
|
101 for (int typeface = 0; typeface < typefaces; typeface++) |
|
102 { |
|
103 TestFont(typeface); |
|
104 } |
|
105 |
|
106 iStep->INFO_PRINTF1(_L("Test ended")); |
|
107 } |
|
108 |
|
109 void CTestHarness::TestFont(TInt aTypeface) |
|
110 { |
|
111 TTypefaceSupport support; |
|
112 iDev->TypefaceSupport(support,aTypeface); |
|
113 |
|
114 TBuf<50> testInfo; |
|
115 testInfo.Append(_L("Testing typeface: ")); |
|
116 testInfo.Append(support.iTypeface.iName); |
|
117 iStep->INFO_PRINTF1(testInfo); |
|
118 |
|
119 const TInt pointsizes = 9; |
|
120 static TInt pointsize[pointsizes] = { 8, 10, 12, 14, 16, 20, 24, 48, 200 }; |
|
121 TInt i = 0; |
|
122 for (i = 0; i < (pointsizes-2); i++) |
|
123 { |
|
124 TestFontDisplayAtSize(support, pointsize[i], i & 1); |
|
125 } |
|
126 |
|
127 TestFontMetricsDiagram(support, pointsize[i], i & 1); |
|
128 i++; |
|
129 |
|
130 TestFontHugeCharacters(support, pointsize[i], i & 1); |
|
131 } |
|
132 |
|
133 void CTestHarness::TestFontDisplayAtSize(TTypefaceSupport& aSupport, TInt aPointSize, TBool aItalic) |
|
134 { |
|
135 TBuf<50> testInfo; |
|
136 testInfo.Append(_L("Testing font size: ")); |
|
137 TBuf<10> num; |
|
138 num.Num(aPointSize); |
|
139 testInfo.Append(num); |
|
140 iStep->INFO_PRINTF1(testInfo); |
|
141 |
|
142 TFontSpec fs; |
|
143 |
|
144 fs.iTypeface = aSupport.iTypeface; |
|
145 fs.iHeight = aPointSize * 20; |
|
146 if (aItalic) |
|
147 { |
|
148 fs.iFontStyle.SetPosture(EPostureItalic); |
|
149 } |
|
150 iTestFont = NULL; |
|
151 TInt error = iDev->GetNearestFontToDesignHeightInTwips((CFont*&)iTestFont,fs); |
|
152 if (error) |
|
153 User::Panic(_L("Could not create font"),error); |
|
154 if (!iTestFont->IsOpenFont()) |
|
155 { |
|
156 iDev->ReleaseFont(iTestFont); |
|
157 iTestFont = NULL; |
|
158 return; |
|
159 } |
|
160 PrintMetrics(); |
|
161 DisplayFont(); |
|
162 iDev->ReleaseFont(iTestFont); |
|
163 } |
|
164 |
|
165 void CTestHarness::TestFontMetricsDiagram(TTypefaceSupport& aSupport, TInt aPointSize, TBool aItalic) |
|
166 { |
|
167 TBuf<50> testInfo; |
|
168 testInfo.Append(_L("Testing font metrics: ")); |
|
169 TBuf<10> num; |
|
170 num.Num(aPointSize); |
|
171 testInfo.Append(num); |
|
172 iStep->INFO_PRINTF1(testInfo); |
|
173 |
|
174 TFontSpec fs; |
|
175 fs.iTypeface = aSupport.iTypeface; |
|
176 fs.iHeight = aPointSize * 20; |
|
177 if (aItalic) |
|
178 { |
|
179 fs.iFontStyle.SetPosture(EPostureItalic); |
|
180 } |
|
181 iTestFont = NULL; |
|
182 TInt error = iDev->GetNearestFontToDesignHeightInTwips((CFont*&)iTestFont,fs); |
|
183 if (error) |
|
184 User::Panic(_L("Could not create font"),error); |
|
185 if (!iTestFont->IsOpenFont()) |
|
186 { |
|
187 iDev->ReleaseFont(iTestFont); |
|
188 iTestFont = NULL; |
|
189 return; |
|
190 } |
|
191 PrintMetrics(); |
|
192 DrawMetricsDiagram(); |
|
193 iDev->ReleaseFont(iTestFont); |
|
194 } |
|
195 |
|
196 void CTestHarness::TestFontHugeCharacters(TTypefaceSupport& aSupport, TInt aPointSize, TBool aItalic) |
|
197 { |
|
198 TBuf<50> testInfo; |
|
199 testInfo.Append(_L("Testing huge characters: ")); |
|
200 TBuf<10> num; |
|
201 num.Num(aPointSize); |
|
202 testInfo.Append(num); |
|
203 iStep->INFO_PRINTF1(testInfo); |
|
204 |
|
205 TFontSpec fs; |
|
206 fs.iTypeface = aSupport.iTypeface; |
|
207 fs.iHeight = aPointSize * 20; |
|
208 if (aItalic) |
|
209 fs.iFontStyle.SetPosture(EPostureItalic); |
|
210 iTestFont = NULL; |
|
211 TInt error = iDev->GetNearestFontToDesignHeightInTwips((CFont*&)iTestFont,fs); |
|
212 if (error) |
|
213 User::Panic(_L("Could not create font"),error); |
|
214 if (!iTestFont->IsOpenFont()) |
|
215 { |
|
216 iDev->ReleaseFont(iTestFont); |
|
217 iTestFont = NULL; |
|
218 return; |
|
219 } |
|
220 PrintMetrics(); |
|
221 DrawHugeCharacters(); |
|
222 iDev->ReleaseFont(iTestFont); |
|
223 } |
|
224 |
|
225 static void Hellenize(TDes16& text) |
|
226 { |
|
227 static const TUint16* roman = (TUint16*)(L"ABGDEZJQIKLMNXOPRVSTUFHCW"); |
|
228 |
|
229 for (int i = 0; i < text.Length(); i++) |
|
230 for (int j = 0; j < 25; j++) |
|
231 if (roman[j] == text[i]) |
|
232 { |
|
233 text[i] = (TUint16)(0x391 + j); |
|
234 break; |
|
235 } |
|
236 else if (roman[j] + 32 == text[i]) |
|
237 { |
|
238 text[i] = (TUint16)(0x3B1 + j); |
|
239 break; |
|
240 } |
|
241 } |
|
242 |
|
243 void CTestHarness::PrintMetrics(TBool isClear) |
|
244 { |
|
245 if(isClear) |
|
246 { |
|
247 Clear(); |
|
248 } |
|
249 |
|
250 UseFont(iStandardFont); |
|
251 TFontSpec fs = iTestFont->FontSpecInTwips(); |
|
252 TOpenFontMetrics metrics; |
|
253 iTestFont->GetFontMetrics(metrics); |
|
254 TOpenFontFaceAttrib attrib; |
|
255 iTestFont->GetFaceAttrib(attrib); |
|
256 TPtrC name = attrib.LocalFullName(); |
|
257 iBuffer.Format(_L("%S %dpt size=%d ascent=%d descent=%d maxheight=%d maxdepth=%d maxwidth=%d"), |
|
258 &name,(fs.iHeight + 10) / 20,metrics.Size(),metrics.Ascent(),metrics.Descent(), |
|
259 metrics.MaxHeight(),metrics.MaxDepth(),metrics.MaxWidth()); |
|
260 Print(iBuffer); |
|
261 } |
|
262 |
|
263 void CTestHarness::DisplayFont() |
|
264 { |
|
265 UseFont(iStandardFont); |
|
266 TOpenFontFaceAttrib attrib; |
|
267 iTestFont->GetFaceAttrib(attrib); |
|
268 iBuffer.SetLength(0); |
|
269 if (attrib.HasLatin()) |
|
270 iBuffer.Append(_L("Latin, ")); |
|
271 if (attrib.HasGreek()) |
|
272 iBuffer.Append(_L("Greek, ")); |
|
273 if (attrib.HasCyrillic()) |
|
274 iBuffer.Append(_L("Cyrillic, ")); |
|
275 if (attrib.HasKana()) |
|
276 iBuffer.Append(_L("Kana (Japanese syllabaries), ")); |
|
277 if (attrib.HasHangul()) |
|
278 iBuffer.Append(_L("Hangul (Korean writing system), ")); |
|
279 if (attrib.HasCJK()) |
|
280 iBuffer.Append(_L("CJK (Chinese, Japanese & Korean ideographs), ")); |
|
281 if (iBuffer.Length() == 0) |
|
282 iBuffer.Append(_L("(character sets unknown)")); |
|
283 else |
|
284 iBuffer.SetLength(iBuffer.Length() - 2); |
|
285 Print(iBuffer); |
|
286 |
|
287 UseFont(iTestFont); |
|
288 |
|
289 // Benchmark the rasterization of Ascii printable characters. |
|
290 const int count = 126 - 33 + 1; |
|
291 iBuffer.SetLength(count); |
|
292 int i; |
|
293 for (i = 0; i < count; i++) |
|
294 iBuffer[i] = (TText)(i + 33); |
|
295 TTime start, end; |
|
296 start.HomeTime(); |
|
297 iTestFont->RawTextWidthInPixels(iBuffer); |
|
298 end.HomeTime(); |
|
299 TTimeIntervalMicroSeconds time64 = end.MicroSecondsFrom(start); |
|
300 int time = I64INT(time64.Int64()); |
|
301 |
|
302 start.HomeTime(); |
|
303 for (i = 0; i < 100; i++) |
|
304 iTestFont->RawTextWidthInPixels(iBuffer); |
|
305 end.HomeTime(); |
|
306 time64 = end.MicroSecondsFrom(start); |
|
307 int overhead = I64INT(time64.Int64()) / 100; |
|
308 time -= overhead; |
|
309 if (time <= 0) |
|
310 time = 1; |
|
311 |
|
312 iBuffer.Format(_L("%d characters rasterized per second"), |
|
313 count * 1000000 / time); |
|
314 Print(iBuffer); |
|
315 iBuffer.UpperCase(); |
|
316 Print(iBuffer); |
|
317 iBuffer = _L("sm\xf6rg\xe5sbord soup\xe7on na\xefvet\xe9"); |
|
318 Print(iBuffer); |
|
319 iBuffer.UpperCase(); |
|
320 Print(iBuffer); |
|
321 |
|
322 if (attrib.HasGreek()) |
|
323 { |
|
324 iBuffer = _L("agjwmetrjsewv mjdeiv eisitw"); |
|
325 Hellenize(iBuffer); |
|
326 Print(iBuffer); |
|
327 iBuffer.UpperCase(); |
|
328 Print(iBuffer); |
|
329 } |
|
330 if (attrib.HasCyrillic()) |
|
331 { |
|
332 iBuffer.SetLength(32); |
|
333 for (int i = 0; i < 32; i++) |
|
334 iBuffer[i] = (TText)(0x430 + i); |
|
335 Print(iBuffer); |
|
336 iBuffer.UpperCase(); |
|
337 Print(iBuffer); |
|
338 } |
|
339 if (attrib.HasKana()) |
|
340 { |
|
341 iBuffer.SetLength(32); |
|
342 int i; |
|
343 for (i = 0; i < 32; i++) |
|
344 iBuffer[i] = (TText)(0x3041 + i); |
|
345 Print(iBuffer); |
|
346 for (i = 0; i < iBuffer.Length(); i++) |
|
347 iBuffer[i] = (TText)User::Fold(iBuffer[i],TChar::EFoldKana); // fold to katakana |
|
348 Print(iBuffer); |
|
349 } |
|
350 if (attrib.HasHangul()) |
|
351 { |
|
352 iBuffer.SetLength(32); |
|
353 for (int i = 0; i < 32; i++) |
|
354 iBuffer[i] = (TText)(0x3131 + i); |
|
355 Print(iBuffer); |
|
356 } |
|
357 |
|
358 // Display characters from 4e00 that are found in all 6 encodings given in the Unicode table. |
|
359 if (attrib.HasCJK()) |
|
360 { |
|
361 iBuffer.SetLength(15); |
|
362 iBuffer[0] = 0x4e00; |
|
363 iBuffer[1] = 0x4e01; |
|
364 iBuffer[2] = 0x4e03; |
|
365 iBuffer[3] = 0x4e07; |
|
366 iBuffer[4] = 0x4e08; |
|
367 iBuffer[5] = 0x4e09; |
|
368 iBuffer[6] = 0x4e0a; |
|
369 iBuffer[7] = 0x4e0b; |
|
370 iBuffer[8] = 0x4e0d; |
|
371 iBuffer[9] = 0x4e11; |
|
372 iBuffer[10] = 0x4e14; |
|
373 iBuffer[11] = 0x4e15; |
|
374 iBuffer[12] = 0x4e16; |
|
375 iBuffer[13] = 0x4e18; |
|
376 iBuffer[14] = 0x4e19; |
|
377 Print(iBuffer); |
|
378 } |
|
379 |
|
380 iGc->DiscardFont(); |
|
381 } |
|
382 |
|
383 void CTestHarness::DrawCharMetrics(TPoint& aPos,TInt aCode) |
|
384 { |
|
385 TOpenFontCharMetrics metrics; |
|
386 const TUint8* bytes; |
|
387 TSize size; |
|
388 iTestFont->GetCharacterData(aCode,metrics,bytes,size); |
|
389 TRect r; |
|
390 r.iTl = aPos; |
|
391 r.iTl.iX += metrics.HorizBearingX(); |
|
392 r.iTl.iY += iBaseLine; |
|
393 r.iTl.iY -= metrics.HorizBearingY(); |
|
394 r.iBr = r.iTl + TSize(metrics.Width(),metrics.Height()); |
|
395 iGc->DrawRect(r); |
|
396 aPos.iX += metrics.HorizAdvance(); |
|
397 } |
|
398 |
|
399 void CTestHarness::DrawMetricsDiagram() |
|
400 { |
|
401 UseFont(iTestFont); |
|
402 iBuffer = _L("Dig my crazy metrics!"); |
|
403 iPrintPos.iX += 8; |
|
404 TPoint pos = iPrintPos; |
|
405 Print(iBuffer); |
|
406 TPoint baseline_start = pos; |
|
407 baseline_start.iY += iBaseLine; |
|
408 for (int i = 0; i < iBuffer.Length(); i++) |
|
409 DrawCharMetrics(pos,iBuffer[i]); |
|
410 TPoint baseline_end = pos; |
|
411 baseline_end.iY += iBaseLine; |
|
412 iGc->DrawLine(baseline_start,baseline_end); |
|
413 iGc->DiscardFont(); |
|
414 //iTest.Getch(); |
|
415 } |
|
416 |
|
417 void CTestHarness::DrawHugeCharacters() |
|
418 { |
|
419 UseFont(iTestFont); |
|
420 iBuffer = _L("ABC123"); |
|
421 TOpenFontCharMetrics metrics; |
|
422 const TUint8* bytes; |
|
423 TSize size; |
|
424 iTestFont->GetCharacterData('A',metrics,bytes,size); |
|
425 iBaseLine = metrics.HorizBearingY();; |
|
426 Print(iBuffer); |
|
427 iGc->DiscardFont(); |
|
428 //iTest.Getch(); |
|
429 } |
|
430 |
|
431 void CTestHarness::Clear() |
|
432 { |
|
433 TRect r(iDev->SizeInPixels()); |
|
434 iGc->Clear(r); |
|
435 iPrintPos = TPoint(0,0); |
|
436 } |
|
437 |
|
438 void CTestHarness::Print(const TDesC& aText) |
|
439 { |
|
440 TPoint p = iPrintPos; |
|
441 p.iY += iBaseLine; |
|
442 iGc->DrawText(aText,p); |
|
443 iPrintPos.iX = 0; |
|
444 iPrintPos.iY += iLineHeight; |
|
445 } |
|
446 |
|
447 void CTestHarness::UseFont(CFbsFont* aFont) |
|
448 { |
|
449 iGc->UseFont(aFont); |
|
450 TOpenFontMetrics metrics; |
|
451 aFont->GetFontMetrics(metrics); |
|
452 iBaseLine = metrics.MaxHeight(); |
|
453 iLineHeight = metrics.MaxHeight() + metrics.MaxDepth(); |
|
454 } |
|
455 |
|
456 /* |
|
457 @SYMTestCaseID GRAPHICS-FREETYPE-0001 |
|
458 @SYMTestCaseDesc Supplementary characters rasterization Test |
|
459 @SYMTestPriority High |
|
460 @SYMTestActions This test checks that the free type rasterizer rasterizes supplementary characters |
|
461 properly. |
|
462 It prints the descriptor containing supplementary characters with 2 Fonts. One font does not support |
|
463 supplementary characters and the other does. |
|
464 @SYMTestExpectedResults This step should be executed without error and the user should be able to see the |
|
465 above descriptor is displayed as a square with the first font and in the correct shape with the other font. |
|
466 @SYMDEF DEF120018 Security issue in FreeType rasterizer! Supplementary characters rendered as BMP |
|
467 */ |
|
468 void CTestHarness::SurrogateRasterizedTestsL() |
|
469 { |
|
470 // The literal descriptor consisting of common letter 'A' and Supplementary character 0x20000 |
|
471 // which is represented by surrogate pair 0xD840 0xDC00 |
|
472 _LIT16(KSurrogatePairCode, "A\xD840\xDC00"); |
|
473 |
|
474 // Testing Fonts: DejaVu Sans Condensed does not support Supplementary character. |
|
475 // Test2 only supports letter "A" and Supplementary character 0x20000 |
|
476 TFontSpec fsDejaVuSans(_L("DejaVu Sans Condensed"), 16 * 20); |
|
477 TFontSpec fsTest2(_L("Test2"), 16 * 20); |
|
478 |
|
479 Clear(); |
|
480 |
|
481 // Prints test descriptor with font SwissA |
|
482 iTestFont = NULL; |
|
483 TInt error = iDev->GetNearestFontToDesignHeightInTwips((CFont*&)iTestFont,fsDejaVuSans); |
|
484 iStep->TESTL(KErrNone == error); |
|
485 |
|
486 if (!iTestFont->IsOpenFont()) |
|
487 { |
|
488 iDev->ReleaseFont(iTestFont); |
|
489 iTestFont = NULL; |
|
490 User::Leave(KErrGeneral); |
|
491 } |
|
492 PrintMetrics(EFalse); |
|
493 |
|
494 UseFont(iTestFont); |
|
495 Print(KSurrogatePairCode); |
|
496 iDev->ReleaseFont(iTestFont); |
|
497 |
|
498 // Prints test descriptor with font Test2 |
|
499 iTestFont = NULL; |
|
500 error = iDev->GetNearestFontToDesignHeightInTwips((CFont*&)iTestFont,fsTest2); |
|
501 iStep->TESTL(KErrNone == error); |
|
502 |
|
503 if (!iTestFont->IsOpenFont()) |
|
504 { |
|
505 iDev->ReleaseFont(iTestFont); |
|
506 iTestFont = NULL; |
|
507 User::Leave(KErrGeneral); |
|
508 } |
|
509 PrintMetrics(EFalse); |
|
510 |
|
511 UseFont(iTestFont); |
|
512 Print(KSurrogatePairCode); |
|
513 iDev->ReleaseFont(iTestFont); |
|
514 iTestFont = NULL; |
|
515 |
|
516 // User::After(10000000); |
|
517 } |
|
518 |