sl@0
|
1 |
/*
|
sl@0
|
2 |
*******************************************************************************
|
sl@0
|
3 |
*
|
sl@0
|
4 |
* Copyright (C) 1999-2003, International Business Machines
|
sl@0
|
5 |
* Corporation and others. All Rights Reserved.
|
sl@0
|
6 |
*
|
sl@0
|
7 |
*******************************************************************************
|
sl@0
|
8 |
* file name: letest.cpp
|
sl@0
|
9 |
*
|
sl@0
|
10 |
* created on: 11/06/2000
|
sl@0
|
11 |
* created by: Eric R. Mader
|
sl@0
|
12 |
*/
|
sl@0
|
13 |
|
sl@0
|
14 |
#include "math.h"
|
sl@0
|
15 |
|
sl@0
|
16 |
#include "LETypes.h"
|
sl@0
|
17 |
#include "LayoutEngine.h"
|
sl@0
|
18 |
#include "PortableFontInstance.h"
|
sl@0
|
19 |
|
sl@0
|
20 |
#include "letest.h"
|
sl@0
|
21 |
|
sl@0
|
22 |
U_NAMESPACE_USE
|
sl@0
|
23 |
|
sl@0
|
24 |
le_bool compareResults(le_int32 testNumber, TestResult *expected, TestResult *actual)
|
sl@0
|
25 |
{
|
sl@0
|
26 |
/* NOTE: we'll stop on the first failure 'cause once there's one error, it may cascade... */
|
sl@0
|
27 |
if (actual->glyphCount != expected->glyphCount) {
|
sl@0
|
28 |
printf("incorrect glyph count: exptected %d, got %d\n", expected->glyphCount, actual->glyphCount);
|
sl@0
|
29 |
return FALSE;
|
sl@0
|
30 |
}
|
sl@0
|
31 |
|
sl@0
|
32 |
le_int32 i;
|
sl@0
|
33 |
|
sl@0
|
34 |
for (i = 0; i < actual->glyphCount; i += 1) {
|
sl@0
|
35 |
if (actual->glyphs[i] != expected->glyphs[i]) {
|
sl@0
|
36 |
printf("incorrect id for glyph %d: expected %4X, got %4X\n", i, expected->glyphs[i], actual->glyphs[i]);
|
sl@0
|
37 |
return FALSE;
|
sl@0
|
38 |
}
|
sl@0
|
39 |
}
|
sl@0
|
40 |
|
sl@0
|
41 |
for (i = 0; i < actual->glyphCount; i += 1) {
|
sl@0
|
42 |
if (actual->indices[i] != expected->indices[i]) {
|
sl@0
|
43 |
printf("incorrect index for glyph %d: expected %8X, got %8X\n", i, expected->indices[i], actual->indices[i]);
|
sl@0
|
44 |
return FALSE;
|
sl@0
|
45 |
}
|
sl@0
|
46 |
}
|
sl@0
|
47 |
|
sl@0
|
48 |
for (i = 0; i <= actual->glyphCount; i += 1) {
|
sl@0
|
49 |
double xError = fabs(actual->positions[i * 2] - expected->positions[i * 2]);
|
sl@0
|
50 |
|
sl@0
|
51 |
if (xError > 0.0001) {
|
sl@0
|
52 |
printf("incorrect x position for glyph %d: expected %f, got %f\n", i, expected->positions[i * 2], actual->positions[i * 2]);
|
sl@0
|
53 |
return FALSE;
|
sl@0
|
54 |
}
|
sl@0
|
55 |
|
sl@0
|
56 |
double yError = fabs(actual->positions[i * 2 + 1] - expected->positions[i * 2 + 1]);
|
sl@0
|
57 |
|
sl@0
|
58 |
if (yError < 0) {
|
sl@0
|
59 |
yError = -yError;
|
sl@0
|
60 |
}
|
sl@0
|
61 |
|
sl@0
|
62 |
if (yError > 0.0001) {
|
sl@0
|
63 |
printf("incorrect y position for glyph %d: expected %f, got %f\n", i, expected->positions[i * 2 + 1], actual->positions[i * 2 + 1]);
|
sl@0
|
64 |
return FALSE;
|
sl@0
|
65 |
}
|
sl@0
|
66 |
}
|
sl@0
|
67 |
|
sl@0
|
68 |
return TRUE;
|
sl@0
|
69 |
}
|
sl@0
|
70 |
|
sl@0
|
71 |
int main_entry()
|
sl@0
|
72 |
{
|
sl@0
|
73 |
le_int32 failures = 0;
|
sl@0
|
74 |
|
sl@0
|
75 |
for (le_int32 test = 0; test < testCount; test += 1) {
|
sl@0
|
76 |
LEErrorCode fontStatus = LE_NO_ERROR;
|
sl@0
|
77 |
|
sl@0
|
78 |
printf("Test %d, font = %s... ", test, testInputs[test].fontName);
|
sl@0
|
79 |
|
sl@0
|
80 |
PortableFontInstance fontInstance(testInputs[test].fontName, 12, fontStatus);
|
sl@0
|
81 |
|
sl@0
|
82 |
if (LE_FAILURE(fontStatus)) {
|
sl@0
|
83 |
printf("could not open font.\n");
|
sl@0
|
84 |
continue;
|
sl@0
|
85 |
}
|
sl@0
|
86 |
|
sl@0
|
87 |
LEErrorCode success = LE_NO_ERROR;
|
sl@0
|
88 |
LayoutEngine *engine = LayoutEngine::layoutEngineFactory(&fontInstance, testInputs[test].scriptCode, -1, success);
|
sl@0
|
89 |
le_int32 textLength = testInputs[test].textLength;
|
sl@0
|
90 |
le_bool result;
|
sl@0
|
91 |
TestResult actual;
|
sl@0
|
92 |
|
sl@0
|
93 |
if (LE_FAILURE(success)) {
|
sl@0
|
94 |
// would be nice to print the script name here, but
|
sl@0
|
95 |
// don't want to maintain a table, and don't want to
|
sl@0
|
96 |
// require ICU just for the script name...
|
sl@0
|
97 |
printf("could not create a LayoutEngine.\n");
|
sl@0
|
98 |
continue;
|
sl@0
|
99 |
}
|
sl@0
|
100 |
|
sl@0
|
101 |
actual.glyphCount = engine->layoutChars(testInputs[test].text, 0, textLength, textLength, testInputs[test].rightToLeft, 0, 0, success);
|
sl@0
|
102 |
|
sl@0
|
103 |
actual.glyphs = new LEGlyphID[actual.glyphCount];
|
sl@0
|
104 |
actual.indices = new le_int32[actual.glyphCount];
|
sl@0
|
105 |
actual.positions = new float[actual.glyphCount * 2 + 2];
|
sl@0
|
106 |
|
sl@0
|
107 |
engine->getGlyphs(actual.glyphs, success);
|
sl@0
|
108 |
engine->getCharIndices(actual.indices, success);
|
sl@0
|
109 |
engine->getGlyphPositions(actual.positions, success);
|
sl@0
|
110 |
|
sl@0
|
111 |
result = compareResults(test, &testResults[test], &actual);
|
sl@0
|
112 |
|
sl@0
|
113 |
if (result) {
|
sl@0
|
114 |
printf("passed.\n");
|
sl@0
|
115 |
} else {
|
sl@0
|
116 |
failures += 1;
|
sl@0
|
117 |
printf("failed.\n");
|
sl@0
|
118 |
}
|
sl@0
|
119 |
|
sl@0
|
120 |
delete[] actual.positions;
|
sl@0
|
121 |
delete[] actual.indices;
|
sl@0
|
122 |
delete[] actual.glyphs;
|
sl@0
|
123 |
delete engine;
|
sl@0
|
124 |
}
|
sl@0
|
125 |
|
sl@0
|
126 |
return failures;
|
sl@0
|
127 |
}
|