X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/b75a7d8f3b4adbae880cab104ce2c6a50eee4db2..2be6500137966bba13903b24204a44804f9e133a:/icuSources/test/intltest/canittst.cpp?ds=inline diff --git a/icuSources/test/intltest/canittst.cpp b/icuSources/test/intltest/canittst.cpp index 28920172..5fe7c174 100644 --- a/icuSources/test/intltest/canittst.cpp +++ b/icuSources/test/intltest/canittst.cpp @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 2002-2003, International Business Machines Corporation and + * Copyright (c) 2002-2012, International Business Machines Corporation and * others. All Rights Reserved. ******************************************************************** * @@ -16,7 +16,9 @@ #include "cstring.h" #include "canittst.h" #include "unicode/caniter.h" +#include "unicode/normlzr.h" #include "unicode/uchar.h" +#include "hash.h" #define ARRAY_LENGTH(array) ((int32_t)(sizeof (array) / sizeof (*array))) @@ -69,12 +71,16 @@ CanonicalIteratorTest::~CanonicalIteratorTest() void CanonicalIteratorTest::TestExhaustive() { UErrorCode status = U_ZERO_ERROR; CanonicalIterator it("", status); + if (U_FAILURE(status)) { + dataerrln("Error creating CanonicalIterator: %s", u_errorName(status)); + return; + } UChar32 i = 0; - UnicodeString s, decomp, comp; - // Test static and dynamic class IDs + UnicodeString s; + // Test static and dynamic class IDs if(it.getDynamicClassID() != CanonicalIterator::getStaticClassID()){ - errln("CanonicalIterator::getStaticClassId ! = CanonicalIterator.getDynamicClassID"); - } + errln("CanonicalIterator::getStaticClassId ! = CanonicalIterator.getDynamicClassID"); + } for (i = 0; i < 0x10FFFF; quick?i+=0x10:++i) { //for (i = 0xae00; i < 0xaf00; ++i) { @@ -88,33 +94,10 @@ void CanonicalIteratorTest::TestExhaustive() { || type == U_SURROGATE) continue; s = i; + characterTest(s, i, it); + s += (UChar32)0x0345; //"\\u0345"; - - Normalizer::decompose(s, FALSE, 0, decomp, status); - Normalizer::compose(s, FALSE, 0, comp, status); - - // skip characters that don't have either decomp. - // need quick test for this! - if (s == decomp && s == comp) { - continue; - } - - it.setSource(s, status); - UBool gotDecomp = FALSE; - UBool gotComp = FALSE; - UBool gotSource = FALSE; - - while (TRUE) { - UnicodeString item = it.next(); - if (item.isBogus()) break; - if (item == s) gotSource = TRUE; - if (item == decomp) gotDecomp = TRUE; - if (item == comp) gotComp = TRUE; - } - - if (!gotSource || !gotDecomp || !gotComp) { - errln("FAIL CanonicalIterator: " + s + (int)i); - } + characterTest(s, i, it); } } @@ -147,7 +130,7 @@ void CanonicalIteratorTest::TestBasic() { // NOTE: we use a TreeSet below to sort the output, which is not guaranteed to be sorted! Hashtable *permutations = new Hashtable(FALSE, status); - permutations->setValueDeleter(uhash_deleteUnicodeString); + permutations->setValueDeleter(uprv_deleteUObject); UnicodeString toPermute("ABC"); CanonicalIterator::permute(toPermute, FALSE, permutations, status); @@ -161,7 +144,7 @@ void CanonicalIteratorTest::TestBasic() { // try samples logln("testing samples"); Hashtable *set = new Hashtable(FALSE, status); - set->setValueDeleter(uhash_deleteUnicodeString); + set->setValueDeleter(uprv_deleteUObject); int32_t i = 0; CanonicalIterator it("", status); if(U_SUCCESS(status)) { @@ -170,7 +153,7 @@ void CanonicalIteratorTest::TestBasic() { UnicodeString testStr = CharsToUnicodeString(testArray[i][0]); it.setSource(testStr, status); set->removeAll(); - while (TRUE) { + for (;;) { //UnicodeString *result = new UnicodeString(it.next()); UnicodeString result(it.next()); if (result.isBogus()) { @@ -180,15 +163,47 @@ void CanonicalIteratorTest::TestBasic() { //logln(++counter + ": " + hex.transliterate(result)); //logln(" = " + name.transliterate(result)); } - expectEqual(i + ": ", testStr, collectionToString(set), CharsToUnicodeString(testArray[i][1])); + expectEqual(i + UnicodeString(": "), testStr, collectionToString(set), CharsToUnicodeString(testArray[i][1])); } } else { - errln("Couldn't instantiate canonical iterator. Error: %s", u_errorName(status)); + dataerrln("Couldn't instantiate canonical iterator. Error: %s", u_errorName(status)); } delete set; } +void CanonicalIteratorTest::characterTest(UnicodeString &s, UChar32 ch, CanonicalIterator &it) +{ + UErrorCode status = U_ZERO_ERROR; + UnicodeString decomp, comp; + UBool gotDecomp = FALSE; + UBool gotComp = FALSE; + UBool gotSource = FALSE; + + Normalizer::decompose(s, FALSE, 0, decomp, status); + Normalizer::compose(s, FALSE, 0, comp, status); + + // skip characters that don't have either decomp. + // need quick test for this! + if (s == decomp && s == comp) { + return; + } + + it.setSource(s, status); + + for (;;) { + UnicodeString item = it.next(); + if (item.isBogus()) break; + if (item == s) gotSource = TRUE; + if (item == decomp) gotDecomp = TRUE; + if (item == comp) gotComp = TRUE; + } + + if (!gotSource || !gotDecomp || !gotComp) { + errln("FAIL CanonicalIterator: " + s + (int)ch); + } +} + void CanonicalIteratorTest::expectEqual(const UnicodeString &message, const UnicodeString &item, const UnicodeString &a, const UnicodeString &b) { if (!(a==b)) { errln("FAIL: " + message + getReadable(item)); @@ -230,7 +245,8 @@ UnicodeString CanonicalIteratorTest::getReadable(const UnicodeString &s) { //return "[" + (verbose ? name->transliterate(s) + "; " : "") + hex->transliterate(s) + "]"; } -U_CAPI int compareUnicodeStrings(const void *s1, const void *s2) { +U_CFUNC int U_CALLCONV +compareUnicodeStrings(const void *s1, const void *s2) { UnicodeString **st1 = (UnicodeString **)s1; UnicodeString **st2 = (UnicodeString **)s2; @@ -291,6 +307,10 @@ void CanonicalIteratorTest::TestAPI() { logln("Testing CanonicalIterator::getSource"); logln("Instantiating canonical iterator with string "+start); CanonicalIterator can(start, status); + if (U_FAILURE(status)) { + dataerrln("Error creating CanonicalIterator: %s", u_errorName(status)); + return; + } UnicodeString source = can.getSource(); logln("CanonicalIterator::getSource returned "+source); if(start != source) {