10596faeddefbf198de137d5e893708495ab1584cFredrik Roubert// © 2016 and later: Unicode, Inc. and others.
264339d36f8bd4db5025fe2988eda22b491a9219cFredrik Roubert// License & terms of use: http://www.unicode.org/copyright.html
3ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*
4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *******************************************************************************
5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *
6f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius *   Copyright (C) 1999-2014, International Business Machines
7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *   Corporation and others.  All Rights Reserved.
8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *
9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *******************************************************************************
10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h"
13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/uclean.h"
14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/uchar.h"
15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/unistr.h"
16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/uscript.h"
17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/putil.h"
18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/ctest.h"
19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "layout/LETypes.h"
21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "layout/LEScripts.h"
22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "letsutil.h"
24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "letest.h"
25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "xmlreader.h"
27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "xmlparser.h"
29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <stdlib.h>
31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <stdio.h>
32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <string.h>
33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru//U_NAMESPACE_USE
35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define CH_COMMA 0x002C
37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic le_uint32 *getHexArray(const UnicodeString &numbers, int32_t &arraySize)
39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t offset = -1;
41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    arraySize = 1;
43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    while((offset = numbers.indexOf(CH_COMMA, offset + 1)) >= 0) {
44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        arraySize += 1;
45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    le_uint32 *array = NEW_ARRAY(le_uint32, arraySize);
48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char number[16];
49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    le_int32 count = 0;
50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    le_int32 start = 0, end = 0;
51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    le_int32 len = 0;
52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // trim leading whitespace
54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    while(u_isUWhiteSpace(numbers[start])) {
55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        start += 1;
56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    while((end = numbers.indexOf(CH_COMMA, start)) >= 0) {
59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        len = numbers.extract(start, end - start, number, ARRAY_SIZE(number), US_INV);
60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        number[len] = '\0';
61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        start = end + 1;
62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        sscanf(number, "%x", &array[count++]);
64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        // trim whitespace following the comma
66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        while(u_isUWhiteSpace(numbers[start])) {
67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            start += 1;
68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // trim trailing whitespace
72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    end = numbers.length();
73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    while(u_isUWhiteSpace(numbers[end - 1])) {
74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        end -= 1;
75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    len = numbers.extract(start, end - start, number, ARRAY_SIZE(number), US_INV);
78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    number[len] = '\0';
79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sscanf(number, "%x", &array[count]);
80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return array;
82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic float *getFloatArray(const UnicodeString &numbers, int32_t &arraySize)
85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t offset = -1;
87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    arraySize = 1;
89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    while((offset = numbers.indexOf(CH_COMMA, offset + 1)) >= 0) {
90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        arraySize += 1;
91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    float *array = NEW_ARRAY(float, arraySize);
94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char number[32];
95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    le_int32 count = 0;
96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    le_int32 start = 0, end = 0;
97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    le_int32 len = 0;
98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // trim leading whitespace
100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    while(u_isUWhiteSpace(numbers[start])) {
101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        start += 1;
102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    while((end = numbers.indexOf(CH_COMMA, start)) >= 0) {
105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        len = numbers.extract(start, end - start, number, ARRAY_SIZE(number), US_INV);
106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        number[len] = '\0';
107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        start = end + 1;
108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        sscanf(number, "%f", &array[count++]);
110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        // trim whiteapce following the comma
112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        while(u_isUWhiteSpace(numbers[start])) {
113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            start += 1;
114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    while(u_isUWhiteSpace(numbers[start])) {
118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        start += 1;
119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // trim trailing whitespace
122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    end = numbers.length();
123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    while(u_isUWhiteSpace(numbers[end - 1])) {
124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        end -= 1;
125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    len = numbers.extract(start, end - start, number, ARRAY_SIZE(number), US_INV);
128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    number[len] = '\0';
129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sscanf(number, "%f", &array[count]);
130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return array;
132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_CDECL_BEGIN
135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid readTestFile(const char *testFilePath, TestCaseCallback callback)
136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_REGULAR_EXPRESSIONS
138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UXMLParser  *parser = UXMLParser::createParser(status);
140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UXMLElement *root   = parser->parseFile(testFilePath, status);
141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (root == NULL) {
143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Could not open the test data file: %s\n", testFilePath);
144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        delete parser;
145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString test_case        = UNICODE_STRING_SIMPLE("test-case");
149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString test_text        = UNICODE_STRING_SIMPLE("test-text");
150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString test_font        = UNICODE_STRING_SIMPLE("test-font");
151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString result_glyphs    = UNICODE_STRING_SIMPLE("result-glyphs");
152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString result_indices   = UNICODE_STRING_SIMPLE("result-indices");
153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString result_positions = UNICODE_STRING_SIMPLE("result-positions");
154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // test-case attributes
156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString id_attr     = UNICODE_STRING_SIMPLE("id");
157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString script_attr = UNICODE_STRING_SIMPLE("script");
158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString lang_attr   = UNICODE_STRING_SIMPLE("lang");
159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // test-font attributes
161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString name_attr   = UNICODE_STRING_SIMPLE("name");
162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString ver_attr    = UNICODE_STRING_SIMPLE("version");
163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString cksum_attr  = UNICODE_STRING_SIMPLE("checksum");
164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const UXMLElement *testCase;
166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t tc = 0;
167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    while((testCase = root->nextChildElement(tc)) != NULL) {
169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (testCase->getTagName().compare(test_case) == 0) {
170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            char *id = getCString(testCase->getAttribute(id_attr));
171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            char *script    = getCString(testCase->getAttribute(script_attr));
172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            char *lang      = getCString(testCase->getAttribute(lang_attr));
173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            char *fontName  = NULL;
174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru			char *fontVer   = NULL;
175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru			char *fontCksum = NULL;
176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            const UXMLElement *element;
177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            int32_t ec = 0;
178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            int32_t charCount = 0;
179f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius            // int32_t typoFlags = 3; // kerning + ligatures...
180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            UScriptCode scriptCode;
181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            le_int32 languageCode = -1;
182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            UnicodeString text, glyphs, indices, positions;
183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            int32_t glyphCount = 0, indexCount = 0, positionCount = 0;
184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            TestResult expected = {0, NULL, NULL, NULL};
185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            uscript_getCode(script, &scriptCode, 1, &status);
187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if (LE_FAILURE(status)) {
188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                log_err("invalid script name: %s.\n", script);
189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                goto free_c_strings;
190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if (lang != NULL) {
193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                languageCode = getLanguageCode(lang);
194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                if (languageCode < 0) {
196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    log_err("invalid language name: %s.\n", lang);
197ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    goto free_c_strings;
198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            while((element = testCase->nextChildElement(ec)) != NULL) {
202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                UnicodeString tag = element->getTagName();
203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                // TODO: make sure that each element is only used once.
205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                if (tag.compare(test_font) == 0) {
206ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    fontName  = getCString(element->getAttribute(name_attr));
207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    fontVer   = getCString(element->getAttribute(ver_attr));
208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    fontCksum = getCString(element->getAttribute(cksum_attr));
209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                } else if (tag.compare(test_text) == 0) {
211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    text = element->getText(TRUE);
212ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    charCount = text.length();
213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                } else if (tag.compare(result_glyphs) == 0) {
214ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    glyphs = element->getText(TRUE);
215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                } else if (tag.compare(result_indices) == 0) {
216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    indices = element->getText(TRUE);
217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                } else if (tag.compare(result_positions) == 0) {
218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    positions = element->getText(TRUE);
219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                } else {
220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    // an unknown tag...
221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    char *cTag = getCString(&tag);
222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    log_info("Test %s: unknown element with tag \"%s\"\n", id, cTag);
224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    freeCString(cTag);
225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            expected.glyphs    = (LEGlyphID *) getHexArray(glyphs, glyphCount);
229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            expected.indices   = (le_int32 *)  getHexArray(indices, indexCount);
230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            expected.positions = getFloatArray(positions, positionCount);
231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            expected.glyphCount = glyphCount;
233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if (glyphCount < charCount || indexCount != glyphCount || positionCount < glyphCount * 2 + 2) {
235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                log_err("Test %s: inconsistent input data: charCount = %d, glyphCount = %d, indexCount = %d, positionCount = %d\n",
236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    id, charCount, glyphCount, indexCount, positionCount);
237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                goto free_expected;
238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            };
239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru			(*callback)(id, fontName, fontVer, fontCksum, scriptCode, languageCode, text.getBuffer(), charCount, &expected);
241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querufree_expected:
243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            DELETE_ARRAY(expected.positions);
244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            DELETE_ARRAY(expected.indices);
245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            DELETE_ARRAY(expected.glyphs);
246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querufree_c_strings:
248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru			freeCString(fontCksum);
249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru			freeCString(fontVer);
250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru			freeCString(fontName);
251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            freeCString(lang);
252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            freeCString(script);
253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            freeCString(id);
254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    delete root;
258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    delete parser;
259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_CDECL_END
262