ICU-3517 remove HexToUnicode and UnicodeToHex transliterators; add countElements / getElement

X-SVN-Rev: 14590
This commit is contained in:
Alan Liu 2004-02-25 23:03:03 +00:00
parent 56f27d5462
commit cebda468da
3 changed files with 76 additions and 68 deletions

View file

@ -20,11 +20,9 @@
#include "unicode/uchar.h"
#include "unicode/unifilt.h"
#include "unicode/uniset.h"
#include "unitohex.h"
#include "unicode/ustring.h"
#include "unicode/usetiter.h"
#include "unicode/uscript.h"
#include "hextouni.h"
#include "cpdtrans.h"
#include "nultrans.h"
#include "rbt.h"
@ -802,22 +800,27 @@ void TransliteratorTest::TestJ277(void) {
* Prefix, suffix support in hex transliterators
*/
void TransliteratorTest::TestJ243(void) {
UErrorCode status = U_ZERO_ERROR;
UErrorCode ec = U_ZERO_ERROR;
// Test default Hex-Any, which should handle
// \u, \U, u+, and U+
HexToUnicodeTransliterator hex;
expect(hex, UnicodeString("\\u0041+\\U0042,u+0043uu+0044z", ""), "A+B,CuDz");
// Try a custom Hex-Unicode
// \uXXXX and &#xXXXX;
status = U_ZERO_ERROR;
HexToUnicodeTransliterator hex2(UnicodeString("\\\\u###0;&\\#x###0\\;", ""), status);
expect(hex2, UnicodeString("\\u61\\u062\\u0063\\u00645\\u66x0123", ""),
"abcd5fx0123");
// Try custom Any-Hex (default is tested elsewhere)
status = U_ZERO_ERROR;
UnicodeToHexTransliterator hex3(UnicodeString("&\\#x###0;", ""), status);
expect(hex3, "012", "012");
Transliterator *hex =
Transliterator::createInstance("Hex-Any", UTRANS_FORWARD, ec);
if (assertSuccess("getInstance", ec)) {
expect(*hex, UnicodeString("\\u0041+\\U00000042,U+0043uU+0044z", ""), "A+B,CuDz");
}
delete hex;
// // Try a custom Hex-Unicode
// // \uXXXX and &#xXXXX;
// ec = U_ZERO_ERROR;
// HexToUnicodeTransliterator hex2(UnicodeString("\\\\u###0;&\\#x###0\\;", ""), ec);
// expect(hex2, UnicodeString("\\u61\\u062\\u0063\\u00645\\u66x0123", ""),
// "abcd5fx0123");
// // Try custom Any-Hex (default is tested elsewhere)
// ec = U_ZERO_ERROR;
// UnicodeToHexTransliterator hex3(UnicodeString("&\\#x###0;", ""), ec);
// expect(hex3, "012", "012");
}
/**
@ -2323,9 +2326,9 @@ void TransliteratorTest::TestNewEngine() {
// true. Otherwise, this test will fail, revealing a
// limitation of global filters in incremental mode.
Transliterator *a =
Transliterator::createFromRules("a", "a > A;", UTRANS_FORWARD, pe, ec);
Transliterator::createFromRules("a_to_A", "a > A;", UTRANS_FORWARD, pe, ec);
Transliterator *A =
Transliterator::createFromRules("A", "A > b;", UTRANS_FORWARD, pe, ec);
Transliterator::createFromRules("A_to_b", "A > b;", UTRANS_FORWARD, pe, ec);
if (U_FAILURE(ec)) {
delete a;
delete A;
@ -2355,6 +2358,13 @@ void TransliteratorTest::TestNewEngine() {
}
expect(*t, "aAaA", "bAbA");
assertTrue("countElements", t->countElements() == 3);
assertEquals("getElement(0)", t->getElement(0, ec).getID(), "a_to_A");
assertEquals("getElement(1)", t->getElement(1, ec).getID(), "NFD");
assertEquals("getElement(2)", t->getElement(2, ec).getID(), "A_to_b");
assertSuccess("getElement", ec);
delete a;
delete A;
delete array[1];

View file

@ -23,8 +23,6 @@
#include "unicode/translit.h"
#include "unicode/uniset.h"
#include "rbt.h"
#include "unitohex.h"
#include "hextouni.h"
#include "unicode/unifilt.h"
#include "cpdtrans.h"
#include "nultrans.h"
@ -44,9 +42,9 @@ TransliteratorErrorTest::runIndexedTest(int32_t index, UBool exec,
switch (index) {
TESTCASE(0,TestTransliteratorErrors);
TESTCASE(1, TestUnicodeSetErrors);
TESTCASE(2, TestUniToHexErrors);
TESTCASE(3, TestRBTErrors);
TESTCASE(4, TestHexToUniErrors);
TESTCASE(2, TestRBTErrors);
//TESTCASE(3, TestUniToHexErrors);
//TESTCASE(4, TestHexToUniErrors);
// TODO: Add a subclass to test clone().
default: name = ""; break;
}
@ -192,29 +190,29 @@ void TransliteratorErrorTest::TestUnicodeSetErrors() {
delete set1;
}
void TransliteratorErrorTest::TestUniToHexErrors() {
UErrorCode status = U_ZERO_ERROR;
Transliterator *t = new UnicodeToHexTransliterator("", TRUE, NULL, status);
if (U_SUCCESS(status)) {
errln("FAIL: Created a UnicodeToHexTransliterator with an empty pattern.");
}
delete t;
status = U_ZERO_ERROR;
t = new UnicodeToHexTransliterator("\\x", TRUE, NULL, status);
if (U_SUCCESS(status)) {
errln("FAIL: Created a UnicodeToHexTransliterator with a bad pattern.");
}
delete t;
status = U_ZERO_ERROR;
t = new UnicodeToHexTransliterator();
((UnicodeToHexTransliterator*)t)->applyPattern("\\x", status);
if (U_SUCCESS(status)) {
errln("FAIL: UnicodeToHexTransliterator::applyPattern succeeded with a bad pattern.");
}
delete t;
}
//void TransliteratorErrorTest::TestUniToHexErrors() {
// UErrorCode status = U_ZERO_ERROR;
// Transliterator *t = new UnicodeToHexTransliterator("", TRUE, NULL, status);
// if (U_SUCCESS(status)) {
// errln("FAIL: Created a UnicodeToHexTransliterator with an empty pattern.");
// }
// delete t;
//
// status = U_ZERO_ERROR;
// t = new UnicodeToHexTransliterator("\\x", TRUE, NULL, status);
// if (U_SUCCESS(status)) {
// errln("FAIL: Created a UnicodeToHexTransliterator with a bad pattern.");
// }
// delete t;
//
// status = U_ZERO_ERROR;
// t = new UnicodeToHexTransliterator();
// ((UnicodeToHexTransliterator*)t)->applyPattern("\\x", status);
// if (U_SUCCESS(status)) {
// errln("FAIL: UnicodeToHexTransliterator::applyPattern succeeded with a bad pattern.");
// }
// delete t;
//}
void TransliteratorErrorTest::TestRBTErrors() {
@ -244,26 +242,26 @@ void TransliteratorErrorTest::TestRBTErrors() {
}
}
void TransliteratorErrorTest::TestHexToUniErrors() {
UErrorCode status = U_ZERO_ERROR;
Transliterator *t = new HexToUnicodeTransliterator("", NULL, status);
if (U_FAILURE(status)) {
errln("FAIL: Could not create a HexToUnicodeTransliterator with an empty pattern.");
}
delete t;
status = U_ZERO_ERROR;
t = new HexToUnicodeTransliterator("\\x", NULL, status);
if (U_SUCCESS(status)) {
errln("FAIL: Created a HexToUnicodeTransliterator with a bad pattern.");
}
delete t;
status = U_ZERO_ERROR;
t = new HexToUnicodeTransliterator();
((HexToUnicodeTransliterator*)t)->applyPattern("\\x", status);
if (U_SUCCESS(status)) {
errln("FAIL: HexToUnicodeTransliterator::applyPattern succeeded with a bad pattern.");
}
delete t;
}
//void TransliteratorErrorTest::TestHexToUniErrors() {
// UErrorCode status = U_ZERO_ERROR;
// Transliterator *t = new HexToUnicodeTransliterator("", NULL, status);
// if (U_FAILURE(status)) {
// errln("FAIL: Could not create a HexToUnicodeTransliterator with an empty pattern.");
// }
// delete t;
// status = U_ZERO_ERROR;
// t = new HexToUnicodeTransliterator("\\x", NULL, status);
// if (U_SUCCESS(status)) {
// errln("FAIL: Created a HexToUnicodeTransliterator with a bad pattern.");
// }
// delete t;
// status = U_ZERO_ERROR;
// t = new HexToUnicodeTransliterator();
// ((HexToUnicodeTransliterator*)t)->applyPattern("\\x", status);
// if (U_SUCCESS(status)) {
// errln("FAIL: HexToUnicodeTransliterator::applyPattern succeeded with a bad pattern.");
// }
// delete t;
//}
#endif /* #if !UCONFIG_NO_TRANSLITERATION */

View file

@ -37,11 +37,11 @@ public:
void TestUnicodeSetErrors(void);
void TestUniToHexErrors(void);
//void TestUniToHexErrors(void);
void TestRBTErrors(void);
void TestHexToUniErrors(void);
//void TestHexToUniErrors(void);
};