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