X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/73c04bcfe1096173b00431f0cdc742894b15eef0..151279e3792e85d0417b499c229886b3af724f55:/icuSources/test/intltest/transtst.cpp diff --git a/icuSources/test/intltest/transtst.cpp b/icuSources/test/intltest/transtst.cpp index 38be8a2a..508da51d 100644 --- a/icuSources/test/intltest/transtst.cpp +++ b/icuSources/test/intltest/transtst.cpp @@ -1,6 +1,6 @@ /* ********************************************************************** -* Copyright (C) 1999-2006, International Business Machines +* Copyright (C) 1999-2011, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************** * Date Name Description @@ -23,9 +23,11 @@ #include "unicode/ustring.h" #include "unicode/usetiter.h" #include "unicode/uscript.h" +#include "unicode/utf16.h" #include "cpdtrans.h" #include "nultrans.h" #include "rbt.h" +#include "rbt_pars.h" #include "anytrans.h" #include "esctrn.h" #include "name2uni.h" @@ -170,7 +172,9 @@ TransliteratorTest::runIndexedTest(int32_t index, UBool exec, TESTCASE(62,TestAnchorMasking); TESTCASE(63,TestDisplayName); TESTCASE(64,TestSpecialCases); +#if !UCONFIG_NO_FILE_IO TESTCASE(65,TestIncrementalProgress); +#endif TESTCASE(66,TestSurrogateCasing); TESTCASE(67,TestFunction); TESTCASE(68,TestInvalidBackRef); @@ -179,18 +183,22 @@ TransliteratorTest::runIndexedTest(int32_t index, UBool exec, TESTCASE(71,TestAnyX); TESTCASE(72,TestSourceTargetSet); TESTCASE(73,TestGurmukhiDevanagari); - TESTCASE(74,TestRuleWhitespace); + TESTCASE(74,TestPatternWhiteSpace); TESTCASE(75,TestAllCodepoints); TESTCASE(76,TestBoilerplate); TESTCASE(77,TestAlternateSyntax); TESTCASE(78,TestBeginEnd); TESTCASE(79,TestBeginEndToRules); TESTCASE(80,TestRegisterAlias); + TESTCASE(81,TestRuleStripping); + TESTCASE(82,TestHalfwidthFullwidth); + TESTCASE(83,TestThai); + TESTCASE(84,TestAny); default: name = ""; break; } } -static const UVersionInfo ICU_37 = {3,7,0,0}; +static const UVersionInfo ICU_39 = {3,9,4,0}; /** * Make sure every system transliterator can be instantiated. * @@ -225,10 +233,6 @@ void TransliteratorTest::TestInstantiation() { i + ") != getAvailableIDs().snext()"); continue; } - if(id2.indexOf("Thai")>-1 && !isICUVersionAtLeast(ICU_37)){ - /* The Thai-Latin transliterator doesn't exist in ICU4C yet */ - continue; - } UParseError parseError; UErrorCode status = U_ZERO_ERROR; Transliterator* t = Transliterator::createInstance(id, @@ -236,16 +240,20 @@ void TransliteratorTest::TestInstantiation() { name.truncate(0); Transliterator::getDisplayName(id, name); if (t == 0) { - errln(UnicodeString("FAIL: Couldn't create ") + id + - /*", parse error " + parseError.code +*/ - ", line " + parseError.line + - ", offset " + parseError.offset + - ", pre-context " + prettify(parseError.preContext, TRUE) + - ", post-context " +prettify(parseError.postContext,TRUE) + - ", Error: " + u_errorName(status)); - // When createInstance fails, it deletes the failing - // entry from the available ID list. We detect this - // here by looking for a change in countAvailableIDs. +#if UCONFIG_NO_BREAK_ITERATION + // If UCONFIG_NO_BREAK_ITERATION is on, then only Thai should fail. + if (id.compare((UnicodeString)"Thai-Latin") != 0) +#endif + dataerrln(UnicodeString("FAIL: Couldn't create ") + id + + /*", parse error " + parseError.code +*/ + ", line " + parseError.line + + ", offset " + parseError.offset + + ", pre-context " + prettify(parseError.preContext, TRUE) + + ", post-context " +prettify(parseError.postContext,TRUE) + + ", Error: " + u_errorName(status)); + // When createInstance fails, it deletes the failing + // entry from the available ID list. We detect this + // here by looking for a change in countAvailableIDs. int32_t nn = Transliterator::countAvailableIDs(); if (nn == (n - 1)) { n = nn; @@ -325,7 +333,8 @@ void TransliteratorTest::TestSimpleRules(void) { /* Test categories */ UErrorCode status = U_ZERO_ERROR; - RuleBasedTransliterator t( + UParseError parseError; + Transliterator *t = Transliterator::createFromRules( "", UnicodeString("$dummy=").append((UChar)0xE100) + UnicodeString(";" @@ -336,12 +345,14 @@ void TransliteratorTest::TestSimpleRules(void) { "'!' { $lu > '^';" "$lu > '*';" "a > ERROR", ""), + UTRANS_FORWARD, parseError, status); if (U_FAILURE(status)) { - errln("FAIL: RBT constructor failed"); + dataerrln("FAIL: RBT constructor failed - %s", u_errorName(status)); return; } - expect(t, "abcdefgABCDEFGU", "&bcd&fg!^**!^*&"); + expect(*t, "abcdefgABCDEFGU", "&bcd&fg!^**!^*&"); + delete t; } /** @@ -402,29 +413,35 @@ void TransliteratorTest::TestRuleBasedInverse(void) { int32_t DATA_length = (int32_t)(sizeof(DATA) / sizeof(DATA[0])); UErrorCode status = U_ZERO_ERROR; - RuleBasedTransliterator fwd("", RULES, status); - RuleBasedTransliterator rev("", RULES, - UTRANS_REVERSE, status); + UParseError parseError; + Transliterator *fwd = Transliterator::createFromRules("", RULES, + UTRANS_FORWARD, parseError, status); + Transliterator *rev = Transliterator::createFromRules("", RULES, + UTRANS_REVERSE, parseError, status); if (U_FAILURE(status)) { errln("FAIL: RBT constructor failed"); return; } for (int32_t i=0; i", + Transliterator *t = Transliterator::createFromRules("", UnicodeString("psch>Y;") +"ps>y;" +"ch>x;" +"a>A;", + UTRANS_FORWARD, parseError, status); if (U_FAILURE(status)) { errln("FAIL: RBT constructor failed"); @@ -441,19 +458,22 @@ void TransliteratorTest::TestKeyboard(void) { 0, "AycAY", // null means finishKeyboardTransliteration }; - keyboardAux(t, DATA, (int32_t)(sizeof(DATA)/sizeof(DATA[0]))); + keyboardAux(*t, DATA, (int32_t)(sizeof(DATA)/sizeof(DATA[0]))); + delete t; } /** * Basic test of keyboard with cursor. */ void TransliteratorTest::TestKeyboard2(void) { + UParseError parseError; UErrorCode status = U_ZERO_ERROR; - RuleBasedTransliterator t("", + Transliterator *t = Transliterator::createFromRules("", UnicodeString("ych>Y;") +"ps>|y;" +"ch>x;" +"a>A;", + UTRANS_FORWARD, parseError, status); if (U_FAILURE(status)) { errln("FAIL: RBT constructor failed"); @@ -473,7 +493,8 @@ void TransliteratorTest::TestKeyboard2(void) { 0, "AycAY", // null means finishKeyboardTransliteration }; - keyboardAux(t, DATA, (int32_t)(sizeof(DATA)/sizeof(DATA[0]))); + keyboardAux(*t, DATA, (int32_t)(sizeof(DATA)/sizeof(DATA[0]))); + delete t; } /** @@ -499,13 +520,15 @@ void TransliteratorTest::TestKeyboard3(void) { 0, "abycz", // null means finishKeyboardTransliteration }; + UParseError parseError; UErrorCode status = U_ZERO_ERROR; - RuleBasedTransliterator t("", RULES, status); + Transliterator *t = Transliterator::createFromRules("", RULES, UTRANS_FORWARD, parseError, status); if (U_FAILURE(status)) { errln("FAIL: RBT constructor failed"); return; } - keyboardAux(t, DATA, (int32_t)(sizeof(DATA)/sizeof(DATA[0]))); + keyboardAux(*t, DATA, (int32_t)(sizeof(DATA)/sizeof(DATA[0]))); + delete t; } void TransliteratorTest::keyboardAux(const Transliterator& t, @@ -584,7 +607,7 @@ void TransliteratorTest::TestCompoundKana(void) { UErrorCode status = U_ZERO_ERROR; Transliterator* t = Transliterator::createInstance("Latin-Hiragana;Hiragana-Latin", UTRANS_FORWARD, parseError, status); if (t == 0) { - errln("FAIL: construction of Latin-Hiragana;Hiragana-Latin failed"); + dataerrln("FAIL: construction of Latin-Hiragana;Hiragana-Latin failed - %s", u_errorName(status)); } else { expect(*t, "aaaaa", "aaaaa"); delete t; @@ -725,13 +748,15 @@ void TransliteratorTest::TestPatternQuoting(void) { for (int32_t i=0; i<3; i+=3) { logln(UnicodeString("Pattern: ") + prettify(DATA[i])); + UParseError parseError; UErrorCode status = U_ZERO_ERROR; - RuleBasedTransliterator t("", DATA[i], status); + Transliterator *t = Transliterator::createFromRules("", DATA[i], UTRANS_FORWARD, parseError, status); if (U_FAILURE(status)) { errln("RBT constructor failed"); } else { - expect(t, DATA[i+1], DATA[i+2]); + expect(*t, DATA[i+1], DATA[i+2]); } + delete t; } } @@ -743,7 +768,7 @@ void TransliteratorTest::TestJ277(void) { UParseError parseError; Transliterator *gl = Transliterator::createInstance("Greek-Latin; NFD; [:M:]Remove; NFC", UTRANS_FORWARD, parseError, status); if (gl == NULL) { - errln("FAIL: createInstance(Greek-Latin) returned NULL"); + dataerrln("FAIL: createInstance(Greek-Latin) returned NULL - %s", u_errorName(status)); return; } @@ -779,10 +804,12 @@ void TransliteratorTest::TestJ277(void) { "y <> $ypsilon;" "n <> $nu;", ""); - RuleBasedTransliterator mini("mini", rules, UTRANS_REVERSE, status); + Transliterator *mini = Transliterator::createFromRules("mini", rules, UTRANS_REVERSE, parseError, status); if (U_FAILURE(status)) { errln("FAIL: Transliterator constructor failed"); return; } - expect(mini, syn, "syn"); - expect(mini, sayn, "saun"); + expect(*mini, syn, "syn"); + expect(*mini, sayn, "saun"); + delete mini; + mini = NULL; #if !UCONFIG_NO_FORMATTING // Transliterate the Greek locale data @@ -856,10 +883,9 @@ void TransliteratorTest::TestJ329(void) { for (int32_t i=0; i", + Transliterator *rbt = Transliterator::createFromRules("", DATA[i].rule, UTRANS_FORWARD, - 0, parseError, status); UBool gotError = U_FAILURE(status); @@ -876,6 +902,7 @@ void TransliteratorTest::TestJ329(void) { } else { errln(UnicodeString("FAIL: ") + desc); } + delete rbt; } } @@ -899,13 +926,15 @@ void TransliteratorTest::TestSegments(void) { for (int32_t i=0; i", DATA[i], status); + Transliterator *t = Transliterator::createFromRules("", DATA[i], UTRANS_FORWARD, parseError, status); if (U_FAILURE(status)) { errln("FAIL: RBT constructor"); } else { - expect(t, DATA[i+1], DATA[i+2]); + expect(*t, DATA[i+1], DATA[i+2]); } + delete t; } } @@ -968,13 +999,15 @@ void TransliteratorTest::TestArbitraryVariableValues(void) { for (int32_t i=0; i", DATA[i], status); + Transliterator *t = Transliterator::createFromRules("", DATA[i], UTRANS_FORWARD, parseError, status); if (U_FAILURE(status)) { errln("FAIL: RBT constructor"); } else { - expect(t, DATA[i+1], DATA[i+2]); + expect(*t, DATA[i+1], DATA[i+2]); } + delete t; } } @@ -1010,8 +1043,9 @@ void TransliteratorTest::TestPositionHandling(void) { int32_t n = (int32_t)(sizeof(DATA) / sizeof(DATA[0])) / 3; for (int32_t i=0; i", - DATA[3*i], status); + UParseError parseError; + Transliterator *t = Transliterator::createFromRules("", + DATA[3*i], UTRANS_FORWARD, parseError, status); if (U_FAILURE(status)) { delete t; errln("FAIL: RBT constructor"); @@ -1047,7 +1081,7 @@ void TransliteratorTest::TestHiraganaKatakana(void) { Transliterator* hk = Transliterator::createInstance("Hiragana-Katakana", UTRANS_FORWARD, parseError, status); Transliterator* kh = Transliterator::createInstance("Katakana-Hiragana", UTRANS_FORWARD, parseError, status); if (hk == 0 || kh == 0) { - errln("FAIL: createInstance failed"); + dataerrln("FAIL: createInstance failed - %s", u_errorName(status)); delete hk; delete kh; return; @@ -1093,18 +1127,21 @@ void TransliteratorTest::TestCopyJ476(void) { // The real test here is what happens when the destructors are // called. So we let one object get destructed, and check to // see that its copy still works. - RuleBasedTransliterator *t2 = 0; + Transliterator *t2 = 0; { + UParseError parseError; UErrorCode status = U_ZERO_ERROR; - RuleBasedTransliterator t1("t1", "a>A;b>B;", status); + Transliterator *t1 = Transliterator::createFromRules("t1", + "a>A;b>B;'foo'+>'bar'", UTRANS_FORWARD, parseError, status); if (U_FAILURE(status)) { errln("FAIL: RBT constructor"); return; } - t2 = new RuleBasedTransliterator(t1); - expect(t1, "abc", "ABc"); + t2 = t1->clone(); // Call copy constructor under the covers. + expect(*t1, "abcfoofoo", "ABcbar"); + delete t1; } - expect(*t2, "abc", "ABc"); + expect(*t2, "abcfoofoo", "ABcbar"); delete t2; } @@ -1118,7 +1155,7 @@ void TransliteratorTest::TestInterIndic(void) { UParseError parseError; Transliterator* dg = Transliterator::createInstance(ID, UTRANS_FORWARD, parseError, status); if (dg == 0) { - errln("FAIL: createInstance(" + ID + ") returned NULL"); + dataerrln("FAIL: createInstance(" + ID + ") returned NULL - " + u_errorName(status)); return; } UnicodeString id = dg->getID(); @@ -1240,8 +1277,8 @@ void TransliteratorTest::TestNameMap(void) { // Careful: CharsToUS will convert "\\N" => "N"; use "\\\\N" for \N expect(*uni2name, CharsToUnicodeString("\\u00A0abc\\u4E01\\u00B5\\u0A81\\uFFFD\\u0004\\u0009\\u0081\\uFFFF"), - CharsToUnicodeString("\\\\N{NO-BREAK SPACE}abc\\\\N{CJK UNIFIED IDEOGRAPH-4E01}\\\\N{MICRO SIGN}\\\\N{GUJARATI SIGN CANDRABINDU}\\\\N{REPLACEMENT CHARACTER}\\\\N{END OF TRANSMISSION}\\\\N{CHARACTER TABULATION}\\\\N{}\\\\N{}")); - expect(*name2uni, "{\\N { NO-BREAK SPACE}abc\\N{ CJK UNIFIED IDEOGRAPH-4E01 }\\N{x\\N{MICRO SIGN}\\N{GUJARATI SIGN CANDRABINDU}\\N{REPLACEMENT CHARACTER}\\N{END OF TRANSMISSION}\\N{CHARACTER TABULATION}\\N{}\\N{}\\N{}\\N{", + CharsToUnicodeString("\\\\N{NO-BREAK SPACE}abc\\\\N{CJK UNIFIED IDEOGRAPH-4E01}\\\\N{MICRO SIGN}\\\\N{GUJARATI SIGN CANDRABINDU}\\\\N{REPLACEMENT CHARACTER}\\\\N{}\\\\N{}\\\\N{}\\\\N{}")); + expect(*name2uni, UNICODE_STRING_SIMPLE("{\\N { NO-BREAK SPACE}abc\\N{ CJK UNIFIED IDEOGRAPH-4E01 }\\N{x\\N{MICRO SIGN}\\N{GUJARATI SIGN CANDRABINDU}\\N{REPLACEMENT CHARACTER}\\N{}\\N{}\\N{}\\N{}\\N{}\\N{"), CharsToUnicodeString("{\\u00A0abc\\u4E01\\\\N{x\\u00B5\\u0A81\\uFFFD\\u0004\\u0009\\u0081\\uFFFF\\u0004\\\\N{")); delete uni2name; @@ -1283,8 +1320,8 @@ void TransliteratorTest::TestLiberalizedID(void) { for (int32_t i=0; i " + newID); } else { - errln((UnicodeString)"FAIL: createInstance(" + + dataerrln((UnicodeString)"FAIL: createInstance(" + id + "," + DATA[i+1] + ") => " + newID + ", expected " + expID); } @@ -1423,7 +1460,7 @@ void TransliteratorTest::TestNormalizationTransliterator() { Transliterator* NFD = Transliterator::createInstance("NFD", UTRANS_FORWARD, parseError, status); Transliterator* NFC = Transliterator::createInstance("NFC", UTRANS_FORWARD, parseError, status); if (!NFD || !NFC) { - errln("FAIL: createInstance failed"); + dataerrln("FAIL: createInstance failed: %s", u_errorName(status)); delete NFD; delete NFC; return; @@ -1488,7 +1525,7 @@ void TransliteratorTest::TestCompoundRBT(void) { errln("FAIL: createFromRules failed"); return; } - expect(*t, "\\u0043at in the hat, bat on the mat", + expect(*t, UNICODE_STRING_SIMPLE("\\u0043at in the hat, bat on the mat"), "C.A.t IN tHE H.A.t, .B..A.t ON tHE M.A.t"); UnicodeString r; t->toRules(r, TRUE); @@ -1503,7 +1540,7 @@ void TransliteratorTest::TestCompoundRBT(void) { // Now test toRules t = Transliterator::createInstance("Greek-Latin; Latin-Cyrillic", UTRANS_FORWARD, parseError, status); if (t == 0) { - errln("FAIL: createInstance failed"); + dataerrln("FAIL: createInstance failed - %s", u_errorName(status)); return; } UnicodeString exp("::Greek-Latin;\n::Latin-Cyrillic;"); @@ -1591,7 +1628,7 @@ void TransliteratorTest::TestCompoundFilter(void) { Transliterator *t = Transliterator::createInstance ("Greek-Latin; Latin-Greek; Lower", UTRANS_FORWARD, parseError, status); if (t == 0) { - errln("FAIL: createInstance failed"); + dataerrln("FAIL: createInstance failed - %s", u_errorName(status)); return; } t->adoptFilter(new UnicodeSet("[^A]", status)); @@ -1700,28 +1737,28 @@ void TransliteratorTest::TestToRules(void) { UParseError parseError; UErrorCode status = U_ZERO_ERROR; Transliterator *t = Transliterator::createFromRules("ID", - DATA[d+1], UTRANS_FORWARD, parseError, status); + UnicodeString(DATA[d+1], -1, US_INV), UTRANS_FORWARD, parseError, status); if (t == 0) { - errln("FAIL: createFromRules failed"); + dataerrln("FAIL: createFromRules failed - %s", u_errorName(status)); return; } UnicodeString rules, escapedRules; t->toRules(rules, FALSE); t->toRules(escapedRules, TRUE); UnicodeString expRules = CharsToUnicodeString(DATA[d+2]); - UnicodeString expEscapedRules(DATA[d+2]); + UnicodeString expEscapedRules(DATA[d+2], -1, US_INV); if (rules == expRules) { - logln((UnicodeString)"Ok: " + DATA[d+1] + + logln((UnicodeString)"Ok: " + UnicodeString(DATA[d+1], -1, US_INV) + " => " + rules); } else { - errln((UnicodeString)"FAIL: " + DATA[d+1] + + errln((UnicodeString)"FAIL: " + UnicodeString(DATA[d+1], -1, US_INV) + " => " + rules + ", exp " + expRules); } if (escapedRules == expEscapedRules) { - logln((UnicodeString)"Ok: " + DATA[d+1] + + logln((UnicodeString)"Ok: " + UnicodeString(DATA[d+1], -1, US_INV) + " => " + escapedRules); } else { - errln((UnicodeString)"FAIL: " + DATA[d+1] + + errln((UnicodeString)"FAIL: " + UnicodeString(DATA[d+1], -1, US_INV) + " => " + escapedRules + ", exp " + expEscapedRules); } delete t; @@ -1729,8 +1766,8 @@ void TransliteratorTest::TestToRules(void) { } else { // UnicodeSet test UErrorCode status = U_ZERO_ERROR; - UnicodeString pat(DATA[d+1]); - UnicodeString expToPat(DATA[d+2]); + UnicodeString pat(DATA[d+1], -1, US_INV); + UnicodeString expToPat(DATA[d+2], -1, US_INV); UnicodeSet set(pat, status); if (U_FAILURE(status)) { errln("FAIL: UnicodeSet ct failed"); @@ -1792,23 +1829,23 @@ void TransliteratorTest::TestSupplemental() { expectT("Any-Name", CharsToUnicodeString("\\U00010330\\U000E0061\\u00A0"), - "\\N{GOTHIC LETTER AHSA}\\N{TAG LATIN SMALL LETTER A}\\N{NO-BREAK SPACE}"); + UNICODE_STRING_SIMPLE("\\N{GOTHIC LETTER AHSA}\\N{TAG LATIN SMALL LETTER A}\\N{NO-BREAK SPACE}")); expectT("Any-Hex/Unicode", CharsToUnicodeString("\\U00010330\\U0010FF00\\U000E0061\\u00A0"), - "U+10330U+10FF00U+E0061U+00A0"); + UNICODE_STRING_SIMPLE("U+10330U+10FF00U+E0061U+00A0")); expectT("Any-Hex/C", CharsToUnicodeString("\\U00010330\\U0010FF00\\U000E0061\\u00A0"), - "\\U00010330\\U0010FF00\\U000E0061\\u00A0"); + UNICODE_STRING_SIMPLE("\\U00010330\\U0010FF00\\U000E0061\\u00A0")); expectT("Any-Hex/Perl", CharsToUnicodeString("\\U00010330\\U0010FF00\\U000E0061\\u00A0"), - "\\x{10330}\\x{10FF00}\\x{E0061}\\x{A0}"); + UNICODE_STRING_SIMPLE("\\x{10330}\\x{10FF00}\\x{E0061}\\x{A0}")); expectT("Any-Hex/Java", CharsToUnicodeString("\\U00010330\\U0010FF00\\U000E0061\\u00A0"), - "\\uD800\\uDF30\\uDBFF\\uDF00\\uDB40\\uDC61\\u00A0"); + UNICODE_STRING_SIMPLE("\\uD800\\uDF30\\uDBFF\\uDF00\\uDB40\\uDC61\\u00A0")); expectT("Any-Hex/XML", CharsToUnicodeString("\\U00010330\\U0010FF00\\U000E0061\\u00A0"), @@ -1818,7 +1855,7 @@ void TransliteratorTest::TestSupplemental() { CharsToUnicodeString("\\U00010330\\U0010FF00\\U000E0061\\u00A0"), "𐌰􏼀󠁡 "); - expectT("[\\U000E0000-\\U000E0FFF] Remove", + expectT(UNICODE_STRING_SIMPLE("[\\U000E0000-\\U000E0FFF] Remove"), CharsToUnicodeString("\\U00010330\\U0010FF00\\U000E0061\\u00A0"), CharsToUnicodeString("\\U00010330\\U0010FF00\\u00A0")); } @@ -1904,12 +1941,22 @@ void TransliteratorTest::TestQuantifier() { "bb x xb"); } -class TestTrans : public NullTransliterator { +class TestTrans : public Transliterator { public: - TestTrans(const UnicodeString& id) { - setID(id); + TestTrans(const UnicodeString& id) : Transliterator(id, 0) { } + virtual Transliterator* clone(void) const { + return new TestTrans(getID()); + } + virtual void handleTransliterate(Replaceable& /*text*/, UTransPosition& offsets, + UBool /*isIncremental*/) const + { + offsets.start = offsets.limit; + } + virtual UClassID getDynamicClassID() const; + static UClassID U_EXPORT2 getStaticClassID(); }; +UOBJECT_DEFINE_RTTI_IMPLEMENTATION(TestTrans) /** * Test Source-Target/Variant. @@ -2034,7 +2081,7 @@ void TransliteratorTest::TestCompoundInverse(void) { Transliterator *t = Transliterator::createInstance ("Greek-Latin; Title()", UTRANS_REVERSE,parseError, status); if (t == 0) { - errln("FAIL: createInstance"); + dataerrln("FAIL: createInstance - %s", u_errorName(status)); return; } UnicodeString exp("(Title);Latin-Greek"); @@ -2058,7 +2105,7 @@ void TransliteratorTest::TestNFDChainRBT() { "TEST", "::NFD; aa > Q; a > q;", UTRANS_FORWARD, pe, ec); if (t == NULL || U_FAILURE(ec)) { - errln("FAIL: Transliterator::createFromRules failed with %s", u_errorName(ec)); + dataerrln("FAIL: Transliterator::createFromRules failed with %s", u_errorName(ec)); return; } expect(*t, "aa", "Q"); @@ -2185,7 +2232,7 @@ void TransliteratorTest::TestAliasInverseID() { UErrorCode ec = U_ZERO_ERROR; Transliterator *t = Transliterator::createInstance(ID, UTRANS_FORWARD, pe, ec); if (t == 0 || U_FAILURE(ec)) { - errln("FAIL: createInstance"); + dataerrln("FAIL: createInstance - %s", u_errorName(ec)); return; } Transliterator *u = t->createInverse(ec); @@ -2213,7 +2260,7 @@ void TransliteratorTest::TestCompoundInverseID() { UErrorCode ec = U_ZERO_ERROR; Transliterator *t = Transliterator::createInstance(ID, UTRANS_FORWARD, pe, ec); if (t == 0 || U_FAILURE(ec)) { - errln("FAIL: createInstance"); + dataerrln("FAIL: createInstance - %s", u_errorName(ec)); return; } Transliterator *u = t->createInverse(ec); @@ -2240,7 +2287,7 @@ void TransliteratorTest::TestUndefinedVariable() { UnicodeString rule = "$initial } a <> \\u1161;"; UParseError pe; UErrorCode ec = U_ZERO_ERROR; - Transliterator *t = new RuleBasedTransliterator("", rule, UTRANS_FORWARD, 0, pe, ec); + Transliterator *t = Transliterator::createFromRules("", rule, UTRANS_FORWARD, pe, ec); delete t; if (U_FAILURE(ec)) { logln((UnicodeString)"OK: Got exception for " + rule + ", as expected: " + @@ -2315,7 +2362,7 @@ void TransliteratorTest::TestCompoundFilterID(void) { } delete t; } else { - errln((UnicodeString)"FAIL: " + id + " => " + transID + ", " + + dataerrln((UnicodeString)"FAIL: " + id + " => " + transID + ", " + u_errorName(ec)); } } @@ -2325,7 +2372,7 @@ void TransliteratorTest::TestCompoundFilterID(void) { * Test new property set syntax */ void TransliteratorTest::TestPropertySet() { - expect("a>A; \\p{Lu}>x; \\p{ANY}>y;", "abcDEF", "Ayyxxx"); + expect(UNICODE_STRING_SIMPLE("a>A; \\p{Lu}>x; \\p{ANY}>y;"), "abcDEF", "Ayyxxx"); expect("(.+)>'[' $1 ']';", " a stitch \n in time \r saves 9", "[ a stitch ]\n[ in time ]\r[ saves 9]"); } @@ -2338,7 +2385,7 @@ void TransliteratorTest::TestNewEngine() { UErrorCode ec = U_ZERO_ERROR; Transliterator *t = Transliterator::createInstance("Latin-Hiragana", UTRANS_FORWARD, pe, ec); if (t == 0 || U_FAILURE(ec)) { - errln("FAIL: createInstance Latin-Hiragana"); + dataerrln("FAIL: createInstance Latin-Hiragana - %s", u_errorName(ec)); return; } // Katakana should be untouched @@ -2597,8 +2644,8 @@ void TransliteratorTest::TestDevanagariLatinRT(){ Transliterator* latinToDev=Transliterator::createInstance("Latin-Devanagari", UTRANS_FORWARD, parseError, status); Transliterator* devToLatin=Transliterator::createInstance("Devanagari-Latin", UTRANS_FORWARD, parseError, status); if(U_FAILURE(status)){ - errln("FAIL: construction " + UnicodeString(" Error: ") + u_errorName(status)); - errln("PreContext: " + prettify(parseError.preContext) + " PostContext: " + prettify( parseError.postContext) ); + dataerrln("FAIL: construction " + UnicodeString(" Error: ") + u_errorName(status)); + dataerrln("PreContext: " + prettify(parseError.preContext) + " PostContext: " + prettify( parseError.postContext) ); return; } UnicodeString gotResult; @@ -2645,8 +2692,8 @@ void TransliteratorTest::TestTeluguLatinRT(){ Transliterator* latinToDev=Transliterator::createInstance("Latin-Telugu", UTRANS_FORWARD, parseError, status); Transliterator* devToLatin=Transliterator::createInstance("Telugu-Latin", UTRANS_FORWARD, parseError, status); if(U_FAILURE(status)){ - errln("FAIL: construction " + UnicodeString(" Error: ") + u_errorName(status)); - errln("PreContext: " + prettify(parseError.preContext) + " PostContext: " + prettify( parseError.postContext) ); + dataerrln("FAIL: construction " + UnicodeString(" Error: ") + u_errorName(status)); + dataerrln("PreContext: " + prettify(parseError.preContext) + " PostContext: " + prettify( parseError.postContext) ); return; } UnicodeString gotResult; @@ -2705,8 +2752,8 @@ void TransliteratorTest::TestSanskritLatinRT(){ Transliterator* latinToDev=Transliterator::createInstance("Latin-Devanagari", UTRANS_FORWARD, parseError, status); Transliterator* devToLatin=Transliterator::createInstance("Devanagari-Latin", UTRANS_FORWARD, parseError, status); if(U_FAILURE(status)){ - errln("FAIL: construction " + UnicodeString(" Error: ") + u_errorName(status)); - errln("PreContext: " + prettify(parseError.preContext) + " PostContext: " + prettify( parseError.postContext) ); + dataerrln("FAIL: construction " + UnicodeString(" Error: ") + u_errorName(status)); + dataerrln("PreContext: " + prettify(parseError.preContext) + " PostContext: " + prettify( parseError.postContext) ); return; } UnicodeString gotResult; @@ -2774,8 +2821,8 @@ void TransliteratorTest::TestCompoundLatinRT(){ Transliterator* latinToTelToLatin=Transliterator::createInstance("Latin-Telugu;Telugu-Latin", UTRANS_FORWARD, parseError, status); if(U_FAILURE(status)){ - errln("FAIL: construction " + UnicodeString(" Error: ") + u_errorName(status)); - errln("PreContext: " + prettify(parseError.preContext) + " PostContext: " + prettify( parseError.postContext) ); + dataerrln("FAIL: construction " + UnicodeString(" Error: ") + u_errorName(status)); + dataerrln("PreContext: " + prettify(parseError.preContext) + " PostContext: " + prettify( parseError.postContext) ); return; } UnicodeString gotResult; @@ -2800,20 +2847,20 @@ void TransliteratorTest::TestGurmukhiDevanagari(){ // (\u0902) (when preceded by vowel) ---> (\u0A02) // (\u0902) (when preceded by consonant) ---> (\u0A70) UErrorCode status = U_ZERO_ERROR; - UnicodeSet vowel(UnicodeString("[\\u0905-\\u090A \\u090F\\u0910\\u0913\\u0914 \\u093e-\\u0942\\u0947\\u0948\\u094B\\u094C\\u094D]").unescape(), status); - UnicodeSet non_vowel(UnicodeString("[\\u0915-\\u0928\\u092A-\\u0930]").unescape(), status); + UnicodeSet vowel(UnicodeString("[\\u0905-\\u090A \\u090F\\u0910\\u0913\\u0914 \\u093e-\\u0942\\u0947\\u0948\\u094B\\u094C\\u094D]", -1, US_INV).unescape(), status); + UnicodeSet non_vowel(UnicodeString("[\\u0915-\\u0928\\u092A-\\u0930]", -1, US_INV).unescape(), status); UParseError parseError; UnicodeSetIterator vIter(vowel); UnicodeSetIterator nvIter(non_vowel); Transliterator* trans = Transliterator::createInstance("Devanagari-Gurmukhi",UTRANS_FORWARD, parseError, status); if(U_FAILURE(status)) { - errln("Error creating transliterator %s", u_errorName(status)); + dataerrln("Error creating transliterator %s", u_errorName(status)); delete trans; return; } - UnicodeString src (" \\u0902"); - UnicodeString expected(" \\u0A02"); + UnicodeString src (" \\u0902", -1, US_INV); + UnicodeString expected(" \\u0A02", -1, US_INV); src = src.unescape(); expected= expected.unescape(); @@ -2840,7 +2887,7 @@ void TransliteratorTest::TestLocaleInstantiation(void) { UErrorCode ec = U_ZERO_ERROR; Transliterator *t = Transliterator::createInstance("ru_RU-Latin", UTRANS_FORWARD, pe, ec); if (U_FAILURE(ec)) { - errln("FAIL: createInstance(ru_RU-Latin)"); + dataerrln("FAIL: createInstance(ru_RU-Latin) - %s", u_errorName(ec)); delete t; return; } @@ -2892,7 +2939,7 @@ void TransliteratorTest::TestLocaleResource() { UErrorCode ec = U_ZERO_ERROR; Transliterator *t = Transliterator::createInstance(DATA[i], UTRANS_FORWARD, pe, ec); if (U_FAILURE(ec)) { - errln((UnicodeString)"FAIL: createInstance(" + DATA[i] + ")"); + dataerrln((UnicodeString)"FAIL: createInstance(" + DATA[i] + ") - " + u_errorName(ec)); delete t; continue; } @@ -2906,7 +2953,7 @@ void TransliteratorTest::TestLocaleResource() { * Make sure parse errors reference the right line. */ void TransliteratorTest::TestParseError() { - const char* rule = + static const char* rule = "a > b;\n" "# more stuff\n" "d << b;"; @@ -2922,9 +2969,25 @@ void TransliteratorTest::TestParseError() { } else { errln("FAIL: " + err); } - return; } - errln("FAIL: no syntax error"); + else { + errln("FAIL: no syntax error"); + } + static const char* maskingRule = + "a>x;\n" + "# more stuff\n" + "ab>y;"; + ec = U_ZERO_ERROR; + delete Transliterator::createFromRules("ID", maskingRule, UTRANS_FORWARD, pe, ec); + if (ec != U_RULE_MASK_ERROR) { + errln("FAIL: returned %s instead of U_RULE_MASK_ERROR", u_errorName(ec)); + } + else if (UnicodeString("a > x;") != UnicodeString(pe.preContext)) { + errln("FAIL: did not get expected precontext"); + } + else if (UnicodeString("ab > y;") != UnicodeString(pe.postContext)) { + errln("FAIL: did not get expected postcontext"); + } } /** @@ -3028,7 +3091,7 @@ void TransliteratorTest::TestIDForms() { if (!expValid) { logln((UnicodeString)"Ok: getInstance(" + ID +") => " + u_errorName(ec)); } else { - errln((UnicodeString)"FAIL: Couldn't create " + ID); + dataerrln((UnicodeString)"FAIL: Couldn't create " + ID + " - " + u_errorName(ec)); } delete t; continue; @@ -3111,21 +3174,21 @@ void TransliteratorTest::TestToRulesMark() { UParseError pe; UErrorCode ec = U_ZERO_ERROR; - Transliterator *t2 = Transliterator::createFromRules("source-target", testRules, UTRANS_FORWARD, pe, ec); - Transliterator *t3 = Transliterator::createFromRules("target-source", testRules, UTRANS_REVERSE, pe, ec); + Transliterator *t2 = Transliterator::createFromRules("source-target", UnicodeString(testRules, -1, US_INV), UTRANS_FORWARD, pe, ec); + Transliterator *t3 = Transliterator::createFromRules("target-source", UnicodeString(testRules, -1, US_INV), UTRANS_REVERSE, pe, ec); if (U_FAILURE(ec)) { delete t2; delete t3; - errln((UnicodeString)"FAIL: createFromRules => " + u_errorName(ec)); + dataerrln((UnicodeString)"FAIL: createFromRules => " + u_errorName(ec)); return; } expect(*t2, source, target); expect(*t3, target, source); - checkRules("Failed toRules FORWARD", *t2, testRulesForward); - checkRules("Failed toRules BACKWARD", *t3, testRulesBackward); + checkRules("Failed toRules FORWARD", *t2, UnicodeString(testRulesForward, -1, US_INV)); + checkRules("Failed toRules BACKWARD", *t3, UnicodeString(testRulesBackward, -1, US_INV)); delete t2; delete t3; @@ -3145,7 +3208,7 @@ void TransliteratorTest::TestEscape() { errln((UnicodeString)"FAIL: createInstance"); } else { expect(*t, - "\\x{40}\\U000000312Q", + UNICODE_STRING_SIMPLE("\\x{40}\\U000000312Q"), "@12Q"); } delete t; @@ -3157,7 +3220,7 @@ void TransliteratorTest::TestEscape() { } else { expect(*t, CharsToUnicodeString("A\\U0010BEEF\\uFEED"), - "\\u0041\\U0010BEEF\\uFEED"); + UNICODE_STRING_SIMPLE("\\u0041\\U0010BEEF\\uFEED")); } delete t; @@ -3168,7 +3231,7 @@ void TransliteratorTest::TestEscape() { } else { expect(*t, CharsToUnicodeString("A\\U0010BEEF\\uFEED"), - "\\u0041\\uDBEF\\uDEEF\\uFEED"); + UNICODE_STRING_SIMPLE("\\u0041\\uDBEF\\uDEEF\\uFEED")); } delete t; @@ -3179,7 +3242,7 @@ void TransliteratorTest::TestEscape() { } else { expect(*t, CharsToUnicodeString("A\\U0010BEEF\\uFEED"), - "\\x{41}\\x{10BEEF}\\x{FEED}"); + UNICODE_STRING_SIMPLE("\\x{41}\\x{10BEEF}\\x{FEED}")); } delete t; } @@ -3234,7 +3297,7 @@ void TransliteratorTest::TestDisplayName() { UnicodeString name; Transliterator::getDisplayName(DATA[i], US, name); if (name != DATA[i+1]) { - errln((UnicodeString)"FAIL: " + DATA[i] + ".getDisplayName() => " + + dataerrln((UnicodeString)"FAIL: " + DATA[i] + ".getDisplayName() => " + name + ", expected " + DATA[i+1]); } else { logln((UnicodeString)"Ok: " + DATA[i] + ".getDisplayName() => " + name); @@ -3244,12 +3307,12 @@ void TransliteratorTest::TestDisplayName() { Transliterator *t = Transliterator::createInstance(DATA[i], UTRANS_REVERSE, pe, ec); if (U_FAILURE(ec)) { delete t; - errln("FAIL: createInstance failed"); + dataerrln("FAIL: createInstance failed - %s", u_errorName(ec)); continue; } name = Transliterator::getDisplayName(t->getID(), US, name); if (name != DATA[i+2]) { - errln((UnicodeString)"FAIL: " + t->getID() + ".getDisplayName() => " + + dataerrln((UnicodeString)"FAIL: " + t->getID() + ".getDisplayName() => " + name + ", expected " + DATA[i+2]); } else { logln((UnicodeString)"Ok: " + t->getID() + ".getDisplayName() => " + name); @@ -3332,7 +3395,7 @@ void TransliteratorTest::TestSpecialCases(void) { Transliterator *t = Transliterator::createFromRules(registerRules[0+i], registerRules[i+1], UTRANS_FORWARD, pos, status); if (U_FAILURE(status)) { - errln("Fails: Unable to create the transliterator from rules."); + dataerrln("Fails: Unable to create the transliterator from rules. - %s", u_errorName(status)); } else { Transliterator::registerInstance(t); } @@ -3343,7 +3406,7 @@ void TransliteratorTest::TestSpecialCases(void) { const UnicodeString& name = testCases[i]; Transliterator *t = Transliterator::createInstance(name, UTRANS_FORWARD, pe, ec); if (U_FAILURE(ec)) { - errln((UnicodeString)"FAIL: Couldn't create " + name); + dataerrln((UnicodeString)"FAIL: Couldn't create " + name + " - " + u_errorName(ec)); delete t; continue; } @@ -3398,7 +3461,7 @@ void TransliteratorTest::TestSurrogateCasing (void) { char buffer[20]; UChar buffer2[20]; UChar32 dee; - UTF_GET_CHAR(DESERET_dee,0, 0, DESERET_dee.length(), dee); + U16_GET(DESERET_dee,0, 0, DESERET_dee.length(), dee); UnicodeString DEE(u_totitle(dee)); if (DEE != DESERET_DEE) { err("Fails titlecase of surrogates"); @@ -3497,13 +3560,9 @@ void TransliteratorTest::TestIncrementalProgress(void) { Transliterator::getAvailableVariant(k, source, target, variant); UnicodeString id = source + "-" + target + "/" + variant; - if(id.indexOf("Thai")>-1 && !isICUVersionAtLeast(ICU_37)){ - /* The Thai-Latin transliterator doesn't exist in ICU4C yet */ - continue; - } Transliterator *t = Transliterator::createInstance(id, UTRANS_FORWARD, err, status); if (U_FAILURE(status)) { - errln((UnicodeString)"FAIL: Could not create " + id); + dataerrln((UnicodeString)"FAIL: Could not create " + id); delete t; continue; } @@ -3514,7 +3573,12 @@ void TransliteratorTest::TestIncrementalProgress(void) { _trans(*t, test, rev); Transliterator *inv = t->createInverse(status); if (U_FAILURE(status)) { - errln((UnicodeString)"FAIL: Could not create inverse of " + id); +#if UCONFIG_NO_BREAK_ITERATION + // If UCONFIG_NO_BREAK_ITERATION is on, then only Thai should fail. + if (id.compare((UnicodeString)"Latin-Thai/") != 0) +#endif + errln((UnicodeString)"FAIL: Could not create inverse of " + id); + delete t; delete inv; continue; @@ -3574,7 +3638,7 @@ void TransliteratorTest::TestFunction() { UErrorCode ec = U_ZERO_ERROR; Transliterator *t = Transliterator::createFromRules("Test", rule, UTRANS_FORWARD, pe, ec); if (t == NULL) { - errln("FAIL: createFromRules failed"); + dataerrln("FAIL: createFromRules failed - %s", u_errorName(ec)); return; } @@ -3588,7 +3652,7 @@ void TransliteratorTest::TestFunction() { } expect(*t, "The Quick Brown Fox", - "T(t=\\u0074)he Q(q=\\u0071)uick B(b=\\u0062)rown F(f=\\u0066)ox"); + UNICODE_STRING_SIMPLE("T(t=\\u0074)he Q(q=\\u0071)uick B(b=\\u0062)rown F(f=\\u0066)ox")); delete t; } @@ -3706,22 +3770,22 @@ void TransliteratorTest::TestUserFunction() { // There's no need to register inverses if we don't use them t = Transliterator::createFromRules("gif", - "'\\'u(..)(..) > '';", + UNICODE_STRING_SIMPLE("'\\'u(..)(..) > '';"), UTRANS_FORWARD, pe, ec); if (t == NULL || U_FAILURE(ec)) { - errln((UnicodeString)"FAIL: createFromRules gif " + u_errorName(ec)); + dataerrln((UnicodeString)"FAIL: createFromRules gif " + u_errorName(ec)); return; } _TUFReg("Any-gif", t, 0); t = Transliterator::createFromRules("RemoveCurly", - "[\\{\\}] > ; '\\N' > ;", + UNICODE_STRING_SIMPLE("[\\{\\}] > ; '\\N' > ;"), UTRANS_FORWARD, pe, ec); if (t == NULL || U_FAILURE(ec)) { errln((UnicodeString)"FAIL: createFromRules RemoveCurly " + u_errorName(ec)); goto FAIL; } - expect(*t, "\\N{name}", "name"); + expect(*t, UNICODE_STRING_SIMPLE("\\N{name}"), "name"); _TUFReg("Any-RemoveCurly", t, 1); logln("Trying &hex"); @@ -3739,7 +3803,7 @@ void TransliteratorTest::TestUserFunction() { errln((UnicodeString)"FAIL: createInstance Any-hex2 " + u_errorName(ec)); goto FAIL; } - expect(*t, "abc", "\\u0061\\u0062\\u0063"); + expect(*t, "abc", UNICODE_STRING_SIMPLE("\\u0061\\u0062\\u0063")); delete t; logln("Trying &gif"); @@ -3770,7 +3834,7 @@ void TransliteratorTest::TestUserFunction() { goto FAIL; } expect(*t, "abc", - "\\u0061 LATIN SMALL LETTER A \\u0062 LATIN SMALL LETTER B \\u0063 LATIN SMALL LETTER C "); + UNICODE_STRING_SIMPLE("\\u0061 LATIN SMALL LETTER A \\u0062 LATIN SMALL LETTER B \\u0063 LATIN SMALL LETTER C ")); delete t; FAIL: @@ -3788,7 +3852,7 @@ void TransliteratorTest::TestAnyX(void) { Transliterator* anyLatin = Transliterator::createInstance("Any-Latin", UTRANS_FORWARD, parseError, status); if (anyLatin==0) { - errln("FAIL: createInstance returned NULL"); + dataerrln("FAIL: createInstance returned NULL - %s", u_errorName(status)); delete anyLatin; return; } @@ -3800,6 +3864,59 @@ void TransliteratorTest::TestAnyX(void) { delete anyLatin; } +/** + * Test Any-X transliterators with sample letters from all scripts. + */ +void TransliteratorTest::TestAny(void) { + UErrorCode status = U_ZERO_ERROR; + // Note: there is a lot of implict construction of UnicodeStrings from (char *) in + // function call parameters going on in this test. + UnicodeSet alphabetic("[:alphabetic:]", status); + if (U_FAILURE(status)) { + dataerrln("Failure: file %s, line %d, status = %s", __FILE__, __LINE__, u_errorName(status)); + return; + } + alphabetic.freeze(); + + UnicodeString testString; + for (int32_t i = 0; i < USCRIPT_CODE_LIMIT; i++) { + const char *scriptName = uscript_getShortName((UScriptCode)i); + if (scriptName == NULL) { + errln("Failure: file %s, line %d: Script Code %d is invalid, ", __FILE__, __LINE__, i); + return; + } + + UnicodeSet sample; + sample.applyPropertyAlias("script", scriptName, status); + if (U_FAILURE(status)) { + errln("Failure: file %s, line %d, status = %s", __FILE__, __LINE__, u_errorName(status)); + return; + } + sample.retainAll(alphabetic); + for (int32_t count=0; count<5; count++) { + UChar32 c = sample.charAt(count); + if (c == -1) { + break; + } + testString.append(c); + } + } + + UParseError parseError; + Transliterator* anyLatin = + Transliterator::createInstance("Any-Latin", UTRANS_FORWARD, parseError, status); + if (U_FAILURE(status)) { + dataerrln("Failure: file %s, line %d, status = %s", __FILE__, __LINE__, u_errorName(status)); + return; + } + + logln(UnicodeString("Sample set for Any-Latin: ") + testString); + anyLatin->transliterate(testString); + logln(UnicodeString("Sample result for Any-Latin: ") + testString); + delete anyLatin; +} + + /** * Test the source and target set API. These are only implemented * for RBT and CompoundTransliterator at this time. @@ -3848,9 +3965,9 @@ void TransliteratorTest::TestSourceTargetSet() { } /** - * Test handling of rule whitespace, for both RBT and UnicodeSet. + * Test handling of Pattern_White_Space, for both RBT and UnicodeSet. */ -void TransliteratorTest::TestRuleWhitespace() { +void TransliteratorTest::TestPatternWhiteSpace() { // Rules const char* r = "a > \\u200E b;"; @@ -3895,11 +4012,11 @@ void TransliteratorTest::TestAllCodepoints(){ for(uint32_t i = 0; i<=0x10ffff; i++){ code = uscript_getScript(i,&status); if(code == USCRIPT_INVALID_CODE){ - errln("uscript_getScript for codepoint \\U%08X failed.\n", i); + dataerrln("uscript_getScript for codepoint \\U%08X failed.", i); } const char* myId = uscript_getName(code); if(!myId) { - errln("Valid script code returned NULL name. Check your data!"); + dataerrln("Valid script code returned NULL name. Check your data!"); return; } uprv_strcpy(id,myId); @@ -3916,14 +4033,14 @@ void TransliteratorTest::TestAllCodepoints(){ if(uprv_strcmp(newId,oldId)!=0){ Transliterator* t = Transliterator::createInstance(newId,UTRANS_FORWARD,pe,status); if(t==NULL || U_FAILURE(status)){ - errln((UnicodeString)"FAIL: Could not create " + id); + dataerrln((UnicodeString)"FAIL: Could not create " + id + " - " + u_errorName(status)); } delete t; } if(uprv_strcmp(newAbbrId,oldAbbrId)!=0){ Transliterator* t = Transliterator::createInstance(newAbbrId,UTRANS_FORWARD,pe,status); if(t==NULL || U_FAILURE(status)){ - errln((UnicodeString)"FAIL: Could not create " + id); + dataerrln((UnicodeString)"FAIL: Could not create " + id + " - " + u_errorName(status)); } delete t; } @@ -3938,7 +4055,7 @@ void TransliteratorTest::TestAllCodepoints(){ UErrorCode ec = U_ZERO_ERROR; \ Transliterator* t = Transliterator::createInstance(id, UTRANS_FORWARD, ec); \ if (U_FAILURE(ec)) { \ - errln("FAIL: Couldn't create " id); \ + dataerrln("FAIL: Couldn't create %s - %s", id, u_errorName(ec)); \ } else { \ if (t->getDynamicClassID() != cls::getStaticClassID()) { \ errln("FAIL: " #cls " dynamic and static class ID mismatch"); \ @@ -3989,7 +4106,7 @@ void TransliteratorTest::TestAlternateSyntax() { "xbz"); expect(CharsToUnicodeString("([:^ASCII:]) \\u2192 \\u2206Name($1);"), CharsToUnicodeString("<=\\u2190; >=\\u2192; <>=\\u2194; &=\\u2206"), - "<=\\N{LEFTWARDS ARROW}; >=\\N{RIGHTWARDS ARROW}; <>=\\N{LEFT RIGHT ARROW}; &=\\N{INCREMENT}"); + UNICODE_STRING_SIMPLE("<=\\N{LEFTWARDS ARROW}; >=\\N{RIGHTWARDS ARROW}; <>=\\N{LEFT RIGHT ARROW}; &=\\N{INCREMENT}")); } static const char* BEGIN_END_RULES[] = { @@ -4226,9 +4343,9 @@ void TransliteratorTest::TestBeginEnd() { int32_t i = 0; for (i = 0; i < BEGIN_END_TEST_CASES_length; i += 3) { expect((UnicodeString)"Test case #" + (i / 3), - UnicodeString(BEGIN_END_TEST_CASES[i]), - UnicodeString(BEGIN_END_TEST_CASES[i + 1]), - UnicodeString(BEGIN_END_TEST_CASES[i + 2])); + UnicodeString(BEGIN_END_TEST_CASES[i], -1, US_INV), + UnicodeString(BEGIN_END_TEST_CASES[i + 1], -1, US_INV), + UnicodeString(BEGIN_END_TEST_CASES[i + 2], -1, US_INV)); } // instantiate the one reversible rule set in the reverse direction and make sure it does the right thing @@ -4269,7 +4386,7 @@ void TransliteratorTest::TestBeginEndToRules() { for (int32_t i = 0; i < BEGIN_END_TEST_CASES_length; i += 3) { UParseError parseError; UErrorCode status = U_ZERO_ERROR; - Transliterator* t = Transliterator::createFromRules("--", UnicodeString(BEGIN_END_TEST_CASES[i]), + Transliterator* t = Transliterator::createFromRules("--", UnicodeString(BEGIN_END_TEST_CASES[i], -1, US_INV), UTRANS_FORWARD, parseError, status); if (U_FAILURE(status)) { reportParseError(UnicodeString("FAIL: Couldn't create transliterator"), parseError, status); @@ -4284,8 +4401,8 @@ void TransliteratorTest::TestBeginEndToRules() { delete t; } else { expect(*t2, - UnicodeString(BEGIN_END_TEST_CASES[i + 1]), - UnicodeString(BEGIN_END_TEST_CASES[i + 2])); + UnicodeString(BEGIN_END_TEST_CASES[i + 1], -1, US_INV), + UnicodeString(BEGIN_END_TEST_CASES[i + 2], -1, US_INV)); delete t; delete t2; } @@ -4372,7 +4489,7 @@ void TransliteratorTest::TestRegisterAlias() { err = U_ZERO_ERROR; t1 = Transliterator::createInstance(realID, UTRANS_FORWARD, err); if (U_FAILURE(err)) { - errln("Failed to instantiate transliterator with real ID"); + dataerrln("Failed to instantiate transliterator with real ID - %s", u_errorName(err)); Transliterator::unregister(realID); return; } @@ -4394,6 +4511,161 @@ void TransliteratorTest::TestRegisterAlias() { Transliterator::unregister(fakeID); } +void TransliteratorTest::TestRuleStripping() { + /* +# +\uE001>\u0C01; # SIGN + */ + static const UChar rule[] = { + 0x0023,0x0020,0x000D,0x000A, + 0xE001,0x003E,0x0C01,0x003B,0x0020,0x0023,0x0020,0x0053,0x0049,0x0047,0x004E,0 + }; + static const UChar expectedRule[] = { + 0xE001,0x003E,0x0C01,0x003B,0 + }; + UChar result[sizeof(rule)/sizeof(rule[0])]; + UErrorCode status = U_ZERO_ERROR; + int32_t len = utrans_stripRules(rule, (int32_t)(sizeof(rule)/sizeof(rule[0])), result, &status); + if (len != u_strlen(expectedRule)) { + errln("utrans_stripRules return len = %d", len); + } + if (u_strncmp(expectedRule, result, len) != 0) { + errln("utrans_stripRules did not return expected string"); + } +} + +/** + * Test the Halfwidth-Fullwidth transliterator (ticket 6281). + */ +void TransliteratorTest::TestHalfwidthFullwidth(void) { + UParseError parseError; + UErrorCode status = U_ZERO_ERROR; + Transliterator* hf = Transliterator::createInstance("Halfwidth-Fullwidth", UTRANS_FORWARD, parseError, status); + Transliterator* fh = Transliterator::createInstance("Fullwidth-Halfwidth", UTRANS_FORWARD, parseError, status); + if (hf == 0 || fh == 0) { + dataerrln("FAIL: createInstance failed - %s", u_errorName(status)); + delete hf; + delete fh; + return; + } + + // Array of 2n items + // Each item is + // "hf"|"fh"|"both", + // , + // + const char* DATA[] = { + "both", + "\\uFFE9\\uFFEA\\uFFEB\\uFFEC\\u0061\\uFF71\\u00AF\\u0020", + "\\u2190\\u2191\\u2192\\u2193\\uFF41\\u30A2\\uFFE3\\u3000", + }; + int32_t DATA_length = (int32_t)(sizeof(DATA) / sizeof(DATA[0])); + + for (int32_t i=0; itransliterate(xlitText); + + UnicodeString expectedText(latinText); + expectedText = expectedText.unescape(); + expect(*tr, xlitText, expectedText); + + delete tr; +#endif +} + + //====================================================================== // Support methods //====================================================================== @@ -4404,7 +4676,7 @@ void TransliteratorTest::expectT(const UnicodeString& id, UParseError pe; Transliterator *t = Transliterator::createInstance(id, UTRANS_FORWARD, pe, ec); if (U_FAILURE(ec)) { - errln((UnicodeString)"FAIL: Could not create " + id); + errln((UnicodeString)"FAIL: Could not create " + id + " - " + u_errorName(ec)); delete t; return; } @@ -4415,7 +4687,7 @@ void TransliteratorTest::expectT(const UnicodeString& id, void TransliteratorTest::reportParseError(const UnicodeString& message, const UParseError& parseError, const UErrorCode& status) { - errln(message + + dataerrln(message + /*", parse error " + parseError.code +*/ ", line " + parseError.line + ", offset " + parseError.offset + @@ -4563,7 +4835,7 @@ void TransliteratorTest::expectAux(const UnicodeString& tag, if (pass) { logln(UnicodeString("(")+tag+") " + prettify(summary)); } else { - errln(UnicodeString("FAIL: (")+tag+") " + dataerrln(UnicodeString("FAIL: (")+tag+") " + prettify(summary) + ", expected " + prettify(expectedResult)); }