/********************************************************************
* COPYRIGHT:
- * Copyright (c) 2002-2003, International Business Machines Corporation and
+ * Copyright (c) 2002-2012, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************
*
#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)))
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) {
|| 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);
}
}
// 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);
// 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)) {
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()) {
//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));
//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;
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) {