+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/*
*******************************************************************************
*
- * Copyright (C) 1999-2008, International Business Machines
+ * Copyright (C) 1999-2013, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
#include "unicode/unistr.h"
#include "unicode/uscript.h"
#include "unicode/ubidi.h"
+#include "unicode/ustring.h"
#include "layout/LETypes.h"
#include "layout/LEScripts.h"
U_NAMESPACE_USE
+static LEErrorCode overallStatus = LE_NO_ERROR;
struct TestInput
{
const char *fontName;
le_bool rightToLeft;
};
+/* Returns the path to icu/source/test/testdata/ */
+const char *getSourceTestData() {
+ const char *srcDataDir = NULL;
+#ifdef U_TOPSRCDIR
+ srcDataDir = U_TOPSRCDIR U_FILE_SEP_STRING "test" U_FILE_SEP_STRING "testdata" U_FILE_SEP_STRING;
+#else
+ srcDataDir = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING;
+ FILE *f = fopen(".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING"rbbitst.txt", "r");
+
+ if (f != NULL) {
+ /* We're in icu/source/test/letest/ */
+ fclose(f);
+ } else {
+ /* We're in icu/source/test/letest/(Debug|Release) */
+ srcDataDir = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING;
+ }
+#endif
+
+ return srcDataDir;
+}
+
+const char *getPath(char buffer[2048], const char *filename) {
+ const char *testDataDirectory = getSourceTestData();
+
+ strcpy(buffer, testDataDirectory);
+ strcat(buffer, filename);
+
+ return buffer;
+}
+
/*
* FIXME: should use the output file name and the current date.
*/
fprintf(file, " </%s>\n", tag);
}
-int main(int /*argc*/, char *argv[])
+int main(int argc, char *argv[])
{
UErrorCode status = U_ZERO_ERROR;
+ const char *gendataFile = "gendata.xml";
FILE *outputFile = fopen(argv[1], "w");
+ if(argc>2) {
+ gendataFile = argv[2];
+ }
time_t now = time(NULL);
struct tm *local = localtime(&now);
const char *tmFormat = "%m/%d/%Y %I:%M:%S %p %Z";
char tmString[64];
-
+ le_uint32 count = 0;
strftime(tmString, 64, tmFormat, local);
fprintf(outputFile, header, local->tm_year + 1900, tmString);
UXMLParser *parser = UXMLParser::createParser(status);
- UXMLElement *root = parser->parseFile("gendata.xml", status);
+ UXMLElement *root = parser->parseFile(gendataFile, status);
if (root == NULL) {
- printf("Error: Could not open gendata.xml\n");
+ printf("Error: Could not open %s\n", gendataFile);
delete parser;
return -1;
+ } else if(U_FAILURE(status)) {
+ printf("Error reading %s: %s\n", gendataFile, u_errorName(status));
+ return -2;
+ } else {
+ printf("Reading %s\n", gendataFile);
}
UnicodeString test_case = UNICODE_STRING_SIMPLE("test-case");
char *id = getCString(testCase->getAttribute(id_attr));
char *script = getCString(testCase->getAttribute(script_attr));
char *lang = getCString(testCase->getAttribute(lang_attr));
+ ++count;
+ printf("\n ID %s\n", id);
LEFontInstance *font = NULL;
const UXMLElement *element;
int32_t ec = 0;
int32_t charCount = 0;
- int32_t typoFlags = 3; // kerning + ligatures...
+ int32_t typoFlags = LayoutEngine::kTypoFlagKern | LayoutEngine::kTypoFlagLiga; // kerning + ligatures...
UScriptCode scriptCode;
le_int32 languageCode = -1;
UnicodeString text;
if (tag.compare(test_font) == 0) {
char *fontName = getCString(element->getAttribute(name_attr));
const char *version = NULL;
- PortableFontInstance *pfi = new PortableFontInstance(fontName, 12, leStatus);
+ char buf[2048];
+ PortableFontInstance *pfi = new PortableFontInstance(getPath(buf,fontName), 12, leStatus);
if (LE_FAILURE(leStatus)) {
- printf("Error: could not open font: %s\n", fontName);
+ printf("Error: could not open font: %s (path: %s)\n", fontName, buf);
freeCString(fontName);
goto free_c_strings;
}
+ printf(" Generating: %s, %s, %s, %s\n", id, script, lang, fontName);
+
version = pfi->getNameString(NAME_VERSION_STRING, PLATFORM_MACINTOSH, MACINTOSH_ROMAN, MACINTOSH_ENGLISH);
// The standard recommends that the Macintosh Roman/English name string be present, but
const LEUnicode16 *uversion = pfi->getUnicodeNameString(NAME_VERSION_STRING, PLATFORM_MICROSOFT, MICROSOFT_UNICODE_BMP, MICROSOFT_ENGLISH);
if (uversion != NULL) {
- fprintf(outputFile, " <test-font name=\"%s\" version=\"%S\" checksum=\"0x%8.8X\"/>\n\n",
- fontName, uversion, pfi->getFontChecksum());
+ char uversion_utf8[300];
+ UErrorCode status2 = U_ZERO_ERROR;
+ u_strToUTF8(uversion_utf8, 300, NULL, uversion, -1, &status2);
+ if(U_FAILURE(status2)) {
+ uversion_utf8[0]=0;
+ }
+ fprintf(outputFile, " <test-font name=\"%s\" version=\"%s\" checksum=\"0x%8.8X\" rchecksum=\"0x%8.8X\"/>\n\n",
+ fontName, uversion_utf8, pfi->getFontChecksum(), pfi->getRawChecksum());
pfi->deleteNameString(uversion);
+ } else {
+ fprintf(outputFile, " <test-font name=\"%s\" version=\"unknown-0x%8.8X\" checksum=\"0x%8.8X\" rchecksum=\"0x%8.8X\"/>\n\n",
+ fontName, pfi->getFontChecksum(), pfi->getFontChecksum(), pfi->getRawChecksum());
}
} else {
- fprintf(outputFile, " <test-font name=\"%s\" version=\"%s\" checksum=\"0x%8.8X\"/>\n\n",
- fontName, version, pfi->getFontChecksum());
+ fprintf(outputFile, " <test-font name=\"%s\" version=\"%s\" checksum=\"0x%8.8X\" rchecksum=\"0x%8.8X\"/>\n\n",
+ fontName, version, pfi->getFontChecksum(), pfi->getRawChecksum());
pfi->deleteNameString(version);
}
+ fflush(outputFile);
freeCString(fontName);
utf8 = getUTF8String(&text);
fprintf(outputFile, " <test-text>%s</test-text>\n\n", utf8);
+ fflush(outputFile);
freeCString(utf8);
} else {
// an unknown tag...
engine->getCharIndices(indices, leStatus);
engine->getGlyphPositions(positions, leStatus);
- dumpLongs(outputFile, "result-glyphs", (le_int32 *) glyphs, glyphCount);
-
- dumpLongs(outputFile, "result-indices", indices, glyphCount);
-
- dumpFloats(outputFile, "result-positions", positions, glyphCount * 2 + 2);
+ if(LE_FAILURE(leStatus)) {
+ fprintf(stderr,"ERROR: LO returned error: %s\n", u_errorName((UErrorCode)leStatus));
+ overallStatus = leStatus;
+ fprintf(outputFile, "<!-- ERROR: %d -->\n", leStatus);
+ fflush(outputFile);
+ leStatus = LE_NO_ERROR;
+ } else {
+ dumpLongs(outputFile, "result-glyphs", (le_int32 *) glyphs, glyphCount);
+
+ dumpLongs(outputFile, "result-indices", indices, glyphCount);
+
+ dumpFloats(outputFile, "result-positions", positions, glyphCount * 2 + 2);
+ fflush(outputFile);
- fprintf(outputFile, " </test-case>\n\n");
+ }
DELETE_ARRAY(positions);
DELETE_ARRAY(indices);
delete engine;
delete_font:
+ fprintf(outputFile, " </test-case>\n\n");
+ fflush(outputFile);
+
delete font;
free_c_strings:
fprintf(outputFile, "</layout-tests>\n");
- fclose(outputFile);
+ if(count==0) {
+ fprintf(stderr, "No cases processed!\n");
+ return 1;
+ }
+
+
+ if(LE_FAILURE(overallStatus)) {
+ fprintf(outputFile, "<!-- !!! FAILED. %d -->\n", overallStatus);
+ fprintf(stderr, "!!! FAILED. %d\n", overallStatus);
+ fclose(outputFile);
+ return 0;
+ // return 1;
+ } else {
+ printf("Generated.\n");
+ fclose(outputFile);
+ return 0;
+ }
}