X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/b75a7d8f3b4adbae880cab104ce2c6a50eee4db2..efa1e6592fb03ce23b15276b2b91d885a3ee7da5:/icuSources/test/cintltst/cmsccoll.c diff --git a/icuSources/test/cintltst/cmsccoll.c b/icuSources/test/cintltst/cmsccoll.c index 46bc9391..d6b1a13c 100644 --- a/icuSources/test/cintltst/cmsccoll.c +++ b/icuSources/test/cintltst/cmsccoll.c @@ -1,6 +1,7 @@ + /******************************************************************** * COPYRIGHT: - * Copyright (c) 2001-2003, International Business Machines Corporation and + * Copyright (c) 2001-2013, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ /******************************************************************************* @@ -31,125 +32,25 @@ #include "ucol_tok.h" #include "cmemory.h" #include "cstring.h" +#include "uassert.h" #include "unicode/parseerr.h" #include "unicode/ucnv.h" +#include "unicode/ures.h" +#include "unicode/uscript.h" +#include "unicode/utf16.h" #include "uparse.h" +#include "putilimp.h" -#define MAX_TOKEN_LEN 16 -#define RULE_BUFFER_LEN 8192 -void genericLocaleStarter(const char *locale, const char *s[], uint32_t size); /* keep gcc happy */ +#define LEN(a) (sizeof(a)/sizeof(a[0])) + +#define MAX_TOKEN_LEN 16 -typedef int tst_strcoll(void *collator, const int object, +typedef UCollationResult tst_strcoll(void *collator, const int object, const UChar *source, const int sLen, const UChar *target, const int tLen); -/** - * Return an integer array containing all of the collation orders - * returned by calls to next on the specified iterator - */ -static int32_t* getOrders(UCollationElements *iter, int32_t *orderLength) -{ - UErrorCode status; - int32_t order; - int32_t maxSize = 100; - int32_t size = 0; - int32_t *temp; - int32_t *orders =(int32_t*)malloc(sizeof(int32_t) * maxSize); - status= U_ZERO_ERROR; - - - while ((order=ucol_next(iter, &status)) != UCOL_NULLORDER) - { - if (size == maxSize) - { - maxSize *= 2; - temp = (int32_t*)malloc(sizeof(int32_t) * maxSize); - - memcpy(temp, orders, size * sizeof(int32_t)); - free(orders); - orders = temp; - - } - - orders[size++] = order; - } - - if (maxSize > size && size > 0) - { - temp = (int32_t*)malloc(sizeof(int32_t) * size); - - memcpy(temp, orders, size * sizeof(int32_t)); - free(orders); - orders = temp; - - - } - - *orderLength = size; - return orders; -} - -static void backAndForth(UCollationElements *iter) -{ - /* Run through the iterator forwards and stick it into an array */ - int32_t index, o; - UErrorCode status = U_ZERO_ERROR; - int32_t orderLength = 0; - int32_t *orders; - orders= getOrders(iter, &orderLength); - - - /* Now go through it backwards and make sure we get the same values */ - index = orderLength; - ucol_reset(iter); - - /* synwee : changed */ - while ((o = ucol_previous(iter, &status)) != UCOL_NULLORDER) - { - if (o != orders[-- index]) - { - if (o == 0) - index ++; - else - { - while (index > 0 && orders[-- index] == 0) - { - } - if (o != orders[index]) - { - log_err("Mismatch at index : %d\n", index); - break; - } - } - } - } - - while (index != 0 && orders[index - 1] == 0) { - index --; - } - - if (index != 0) - { - log_err("Didn't get back to beginning - index is %d\n", index); - - ucol_reset(iter); - log_err("\nnext: "); - while ((o = ucol_next(iter, &status)) != UCOL_NULLORDER) - { - log_err("Error at %d\n", o); - } - log_err("\nprev: "); - while ((o = ucol_previous(iter, &status)) != UCOL_NULLORDER) - { - log_err("Error at %d\n", o); - } - log_verbose("\n"); - } - - free(orders); -} const static char cnt1[][10] = { @@ -258,7 +159,7 @@ const static char shifted[][20] = { }; const static UCollationResult shiftedTert[] = { - 0, + UCOL_EQUAL, UCOL_EQUAL, UCOL_EQUAL, UCOL_LESS, @@ -365,7 +266,7 @@ static void FunkyATest(void) UCollator *myCollation; myCollation = ucol_open("en_US", &status); if(U_FAILURE(status)){ - log_err("ERROR: in creation of rule based collator: %s\n", myErrorName(status)); + log_err_status(status, "ERROR: in creation of rule based collator: %s\n", myErrorName(status)); return; } log_verbose("Testing some A letters, for some reason\n"); @@ -496,9 +397,9 @@ static void BillFairmanTest(void) { lr = ures_open(NULL,lp,&lec); if (lr) { - cr = ures_getByKey(lr,"CollationElements",0,&lec); + cr = ures_getByKey(lr,"collations",0,&lec); if (cr) { - lp = ures_getLocale(cr,&lec); + lp = ures_getLocaleByType(cr, ULOC_ACTUAL_LOCALE, &lec); if (lp) { if (U_SUCCESS(lec)) { if(strcmp(lp, "fr") != 0) { @@ -642,6 +543,7 @@ static void testCollator(UCollator *coll, UErrorCode *status) { UBool startOfRules = TRUE; UBool lastReset = FALSE; UBool before = FALSE; + uint32_t beforeStrength = 0; UColTokenParser src; UColOptionSet opts; @@ -651,11 +553,14 @@ static void testCollator(UCollator *coll, UErrorCode *status) { uint32_t tempLen; UChar *rulesCopy = NULL; UParseError parseError; + + uprv_memset(&src, 0, sizeof(UColTokenParser)); + src.opts = &opts; rules = ucol_getRules(coll, &ruleLen); if(U_SUCCESS(*status) && ruleLen > 0) { - rulesCopy = (UChar *)malloc((ruleLen+UCOL_TOK_EXTRA_RULE_SPACE_SIZE)*sizeof(UChar)); + rulesCopy = (UChar *)uprv_malloc((ruleLen+UCOL_TOK_EXTRA_RULE_SPACE_SIZE)*sizeof(UChar)); uprv_memcpy(rulesCopy, rules, ruleLen*sizeof(UChar)); src.current = src.source = rulesCopy; src.end = rulesCopy+ruleLen; @@ -663,6 +568,8 @@ static void testCollator(UCollator *coll, UErrorCode *status) { src.extraEnd = src.end+UCOL_TOK_EXTRA_RULE_SPACE_SIZE; *first = *second = 0; + /* Note that as a result of tickets 7015 or 6912, ucol_tok_parseNextToken can cause the pointer to + the rules copy in src.source to get reallocated, freeing the original pointer in rulesCopy */ while ((current = ucol_tok_parseNextToken(&src, startOfRules,&parseError, status)) != NULL) { strength = src.parsedToken.strength; chOffset = src.parsedToken.charsOffset; @@ -676,38 +583,41 @@ static void testCollator(UCollator *coll, UErrorCode *status) { startOfRules = FALSE; varT = (UBool)((specs & UCOL_TOK_VARIABLE_TOP) != 0); top_ = (UBool)((specs & UCOL_TOK_TOP) != 0); - if(top_) { /* if reset is on top, we should just continue */ - continue; - } - u_strncpy(second,rulesCopy+chOffset, chLen); - second[chLen] = 0; + if(top_) { /* if reset is on top, the sequence is broken. We should have an empty string */ + second[0] = 0; + } else { + u_strncpy(second,src.source+chOffset, chLen); + second[chLen] = 0; - if(exLen > 0 && firstEx == 0) { - u_strncat(first, rulesCopy+exOffset, exLen); - first[firstLen+exLen] = 0; - } + if(exLen > 0 && firstEx == 0) { + u_strncat(first, src.source+exOffset, exLen); + first[firstLen+exLen] = 0; + } - if(lastReset == TRUE && prefixLen != 0) { - u_strncpy(first+prefixLen, first, firstLen); - u_strncpy(first, rulesCopy+prefixOffset, prefixLen); - first[firstLen+prefixLen] = 0; - firstLen = firstLen+prefixLen; - } + if(lastReset == TRUE && prefixLen != 0) { + u_strncpy(first+prefixLen, first, firstLen); + u_strncpy(first, src.source+prefixOffset, prefixLen); + first[firstLen+prefixLen] = 0; + firstLen = firstLen+prefixLen; + } - if(before == TRUE) { /* swap first and second */ - u_strcpy(tempB, first); - u_strcpy(first, second); - u_strcpy(second, tempB); + if(before == TRUE) { /* swap first and second */ + u_strcpy(tempB, first); + u_strcpy(first, second); + u_strcpy(second, tempB); - tempLen = firstLen; - firstLen = chLen; - chLen = tempLen; + tempLen = firstLen; + firstLen = chLen; + chLen = tempLen; - tempLen = firstEx; - firstEx = exLen; - exLen = tempLen; + tempLen = firstEx; + firstEx = exLen; + exLen = tempLen; + if(beforeStrength < strength) { + strength = beforeStrength; + } + } } - lastReset = FALSE; switch(strength){ @@ -726,33 +636,37 @@ static void testCollator(UCollator *coll, UErrorCode *status) { case UCOL_TOK_RESET: lastReset = TRUE; before = (UBool)((specs & UCOL_TOK_BEFORE) != 0); + if(before) { + beforeStrength = (specs & UCOL_TOK_BEFORE)-1; + } break; default: break; } if(before == TRUE && strength != UCOL_TOK_RESET) { /* first and second were swapped */ - before = FALSE; + before = FALSE; } else { firstLen = chLen; firstEx = exLen; u_strcpy(first, second); } } - free(rulesCopy); + uprv_free(src.source); + uprv_free(src.reorderCodes); } } -static int ucaTest(void *collator, const int object, const UChar *source, const int sLen, const UChar *target, const int tLen) { +static UCollationResult ucaTest(void *collator, const int object, const UChar *source, const int sLen, const UChar *target, const int tLen) { UCollator *UCA = (UCollator *)collator; return ucol_strcoll(UCA, source, sLen, target, tLen); } /* -static int winTest(void *collator, const int object, const UChar *source, const int sLen, const UChar *target, const int tLen) { -#ifdef WIN32 +static UCollationResult winTest(void *collator, const int object, const UChar *source, const int sLen, const UChar *target, const int tLen) { +#if U_PLATFORM_HAS_WIN32_API LCID lcid = (LCID)collator; - return CompareString(lcid, 0, source, sLen, target, tLen); + return (UCollationResult)CompareString(lcid, 0, source, sLen, target, tLen); #else return 0; #endif @@ -857,11 +771,15 @@ static void logFailure (const char *platform, const char *test, uint32_t i = 0; - char sEsc[256], s[256], tEsc[256], t[256], b[256], output[256], relation[256]; + char sEsc[256], s[256], tEsc[256], t[256], b[256], output[512], relation[256]; + static int32_t maxOutputLength = 0; + int32_t outputLength; *sEsc = *tEsc = *s = *t = 0; if(error == TRUE) { log_err("Difference between expected and generated order. Run test with -v for more info\n"); + } else if(getTestOption(VERBOSITY_OPTION) == 0) { + return; } for(i = 0; i maxOutputLength) { + maxOutputLength = outputLength; + U_ASSERT(outputLength < sizeof(output)); + } + log_verbose("%s\n", output); } @@ -979,7 +903,7 @@ static uint32_t testSwitch(tst_strcoll* func, void *collator, int opts, uint32_t realResult = func(collator, opts, first, sLen, second, tLen); realStrength = probeStrength(func, collator, opts, first, sLen, second, tLen, realResult); - if(strength == UCOL_IDENTICAL && realResult != UCOL_IDENTICAL) { + if(strength == UCOL_IDENTICAL && realResult != UCOL_EQUAL) { logFailure(msg, "tailoring", first, sLen, second, tLen, realResult, realStrength, UCOL_EQUAL, strength, error); diffs++; } else if(realResult != UCOL_LESS || realStrength != strength) { @@ -1013,6 +937,7 @@ static void testAgainstUCA(UCollator *coll, UCollator *UCA, const char *refName, uint32_t Windiff = 1; UParseError parseError; + uprv_memset(&src, 0, sizeof(UColTokenParser)); src.opts = &opts; rules = ucol_getRules(coll, &ruleLen); @@ -1020,7 +945,7 @@ static void testAgainstUCA(UCollator *coll, UCollator *UCA, const char *refName, /*printOutRules(rules);*/ if(U_SUCCESS(*status) && ruleLen > 0) { - rulesCopy = (UChar *)malloc((ruleLen+UCOL_TOK_EXTRA_RULE_SPACE_SIZE)*sizeof(UChar)); + rulesCopy = (UChar *)uprv_malloc((ruleLen+UCOL_TOK_EXTRA_RULE_SPACE_SIZE)*sizeof(UChar)); uprv_memcpy(rulesCopy, rules, ruleLen*sizeof(UChar)); src.current = src.source = rulesCopy; src.end = rulesCopy+ruleLen; @@ -1028,6 +953,8 @@ static void testAgainstUCA(UCollator *coll, UCollator *UCA, const char *refName, src.extraEnd = src.end+UCOL_TOK_EXTRA_RULE_SPACE_SIZE; *first = *second = 0; + /* Note that as a result of tickets 7015 or 6912, ucol_tok_parseNextToken can cause the pointer to + the rules copy in src.source to get reallocated, freeing the original pointer in rulesCopy */ while ((current = ucol_tok_parseNextToken(&src, startOfRules, &parseError,status)) != NULL) { strength = src.parsedToken.strength; chOffset = src.parsedToken.charsOffset; @@ -1042,12 +969,12 @@ static void testAgainstUCA(UCollator *coll, UCollator *UCA, const char *refName, varT = (UBool)((specs & UCOL_TOK_VARIABLE_TOP) != 0); top_ = (UBool)((specs & UCOL_TOK_TOP) != 0); - u_strncpy(second,rulesCopy+chOffset, chLen); + u_strncpy(second,src.source+chOffset, chLen); second[chLen] = 0; secondLen = chLen; if(exLen > 0) { - u_strncat(first, rulesCopy+exOffset, exLen); + u_strncat(first, src.source+exOffset, exLen); first[firstLen+exLen] = 0; firstLen += exLen; } @@ -1073,12 +1000,13 @@ static void testAgainstUCA(UCollator *coll, UCollator *UCA, const char *refName, if(Windiff == 0) { log_verbose("No immediate difference with Win32!\n"); } - free(rulesCopy); + uprv_free(src.source); + uprv_free(src.reorderCodes); } } -/* - * Takes two CEs (lead and continuation) and +/* + * Takes two CEs (lead and continuation) and * compares them as CEs should be compared: * primary vs. primary, secondary vs. secondary * tertiary vs. tertiary @@ -1089,8 +1017,8 @@ static int32_t compareCEs(uint32_t s1, uint32_t s2, if(s1 == t1 && s2 == t2) { return 0; } - s = (s1 & 0xFFFF0000)|((s2 & 0xFFFF0000)>>16); - t = (t1 & 0xFFFF0000)|((t2 & 0xFFFF0000)>>16); + s = (s1 & 0xFFFF0000)|((s2 & 0xFFFF0000)>>16); + t = (t1 & 0xFFFF0000)|((t2 & 0xFFFF0000)>>16); if(s < t) { return -1; } else if(s > t) { @@ -1114,147 +1042,257 @@ static int32_t compareCEs(uint32_t s1, uint32_t s2, } } -static void testCEs(UCollator *coll, UErrorCode *status) { - - const UChar *rules = NULL, *current = NULL; - int32_t ruleLen = 0; - - uint32_t strength = 0; - uint32_t maxStrength = UCOL_IDENTICAL; - uint32_t baseCE, baseContCE, nextCE, nextContCE, currCE, currContCE; - uint32_t lastCE; - uint32_t lastContCE; - - int32_t result = 0; - uint32_t chOffset = 0; uint32_t chLen = 0; - uint32_t exOffset = 0; uint32_t exLen = 0; - uint32_t prefixOffset = 0; uint32_t prefixLen = 0; - uint32_t oldOffset = 0; +typedef struct { + uint32_t startCE; + uint32_t startContCE; + uint32_t limitCE; + uint32_t limitContCE; +} indirectBoundaries; + +/* these values are used for finding CE values for indirect positioning. */ +/* Indirect positioning is a mechanism for allowing resets on symbolic */ +/* values. It only works for resets and you cannot tailor indirect names */ +/* An indirect name can define either an anchor point or a range. An */ +/* anchor point behaves in exactly the same way as a code point in reset */ +/* would, except that it cannot be tailored. A range (we currently only */ +/* know for the [top] range will explicitly set the upper bound for */ +/* generated CEs, thus allowing for better control over how many CEs can */ +/* be squeezed between in the range without performance penalty. */ +/* In that respect, we use [top] for tailoring of locales that use CJK */ +/* characters. Other indirect values are currently a pure convenience, */ +/* they can be used to assure that the CEs will be always positioned in */ +/* the same place relative to a point with known properties (e.g. first */ +/* primary ignorable). */ +static indirectBoundaries ucolIndirectBoundaries[15]; +static UBool indirectBoundariesSet = FALSE; +static void setIndirectBoundaries(uint32_t indexR, uint32_t *start, uint32_t *end) { + /* Set values for the top - TODO: once we have values for all the indirects, we are going */ + /* to initalize here. */ + ucolIndirectBoundaries[indexR].startCE = start[0]; + ucolIndirectBoundaries[indexR].startContCE = start[1]; + if(end) { + ucolIndirectBoundaries[indexR].limitCE = end[0]; + ucolIndirectBoundaries[indexR].limitContCE = end[1]; + } else { + ucolIndirectBoundaries[indexR].limitCE = 0; + ucolIndirectBoundaries[indexR].limitContCE = 0; + } +} - /* uint32_t rExpsLen = 0; */ - /* uint32_t firstLen = 0; */ - uint16_t specs = 0; - UBool varT = FALSE; UBool top_ = TRUE; - UBool startOfRules = TRUE; - UColTokenParser src; - UColOptionSet opts; - UParseError parseError; - UChar *rulesCopy = NULL; - collIterate c; - UCollator *UCA = ucol_open("root", status); - UCAConstants *consts = (UCAConstants *)((uint8_t *)UCA->image + UCA->image->UCAConsts); - uint32_t UCOL_RESET_TOP_VALUE = consts->UCA_LAST_NON_VARIABLE[0], UCOL_RESET_TOP_CONT = consts->UCA_LAST_NON_VARIABLE[1], - UCOL_NEXT_TOP_VALUE = consts->UCA_FIRST_IMPLICIT[0], UCOL_NEXT_TOP_CONT = consts->UCA_FIRST_IMPLICIT[1]; - - baseCE=baseContCE=nextCE=nextContCE=currCE=currContCE=lastCE=lastContCE = UCOL_NOT_FOUND; +static void testCEs(UCollator *coll, UErrorCode *status) { + const UChar *rules = NULL, *current = NULL; + int32_t ruleLen = 0; + + uint32_t strength = 0; + uint32_t maxStrength = UCOL_IDENTICAL; + uint32_t baseCE, baseContCE, nextCE, nextContCE, currCE, currContCE; + uint32_t lastCE; + uint32_t lastContCE; + + int32_t result = 0; + uint32_t chOffset = 0; uint32_t chLen = 0; + uint32_t exOffset = 0; uint32_t exLen = 0; + uint32_t prefixOffset = 0; uint32_t prefixLen = 0; + uint32_t oldOffset = 0; + + /* uint32_t rExpsLen = 0; */ + /* uint32_t firstLen = 0; */ + uint16_t specs = 0; + UBool varT = FALSE; UBool top_ = TRUE; + UBool startOfRules = TRUE; + UBool before = FALSE; + UColTokenParser src; + UColOptionSet opts; + UParseError parseError; + UChar *rulesCopy = NULL; + collIterate *c = uprv_new_collIterate(status); + UCAConstants *consts = NULL; + uint32_t UCOL_RESET_TOP_VALUE, /*UCOL_RESET_TOP_CONT, */ + UCOL_NEXT_TOP_VALUE, UCOL_NEXT_TOP_CONT; + const char *colLoc; + UCollator *UCA = ucol_open("root", status); + + if (U_FAILURE(*status)) { + log_err("Could not open root collator %s\n", u_errorName(*status)); + uprv_delete_collIterate(c); + return; + } - src.opts = &opts; + colLoc = ucol_getLocaleByType(coll, ULOC_ACTUAL_LOCALE, status); + if (U_FAILURE(*status)) { + log_err("Could not get collator name: %s\n", u_errorName(*status)); + ucol_close(UCA); + uprv_delete_collIterate(c); + return; + } - rules = ucol_getRules(coll, &ruleLen); + uprv_memset(&src, 0, sizeof(UColTokenParser)); + + consts = (UCAConstants *)((uint8_t *)UCA->image + UCA->image->UCAConsts); + UCOL_RESET_TOP_VALUE = consts->UCA_LAST_NON_VARIABLE[0]; + /*UCOL_RESET_TOP_CONT = consts->UCA_LAST_NON_VARIABLE[1]; */ + UCOL_NEXT_TOP_VALUE = consts->UCA_FIRST_IMPLICIT[0]; + UCOL_NEXT_TOP_CONT = consts->UCA_FIRST_IMPLICIT[1]; + + baseCE=baseContCE=nextCE=nextContCE=currCE=currContCE=lastCE=lastContCE = UCOL_NOT_FOUND; + + src.opts = &opts; + + rules = ucol_getRules(coll, &ruleLen); + + src.invUCA = ucol_initInverseUCA(status); + + if(indirectBoundariesSet == FALSE) { + /* UCOL_RESET_TOP_VALUE */ + setIndirectBoundaries(0, consts->UCA_LAST_NON_VARIABLE, consts->UCA_FIRST_IMPLICIT); + /* UCOL_FIRST_PRIMARY_IGNORABLE */ + setIndirectBoundaries(1, consts->UCA_FIRST_PRIMARY_IGNORABLE, 0); + /* UCOL_LAST_PRIMARY_IGNORABLE */ + setIndirectBoundaries(2, consts->UCA_LAST_PRIMARY_IGNORABLE, 0); + /* UCOL_FIRST_SECONDARY_IGNORABLE */ + setIndirectBoundaries(3, consts->UCA_FIRST_SECONDARY_IGNORABLE, 0); + /* UCOL_LAST_SECONDARY_IGNORABLE */ + setIndirectBoundaries(4, consts->UCA_LAST_SECONDARY_IGNORABLE, 0); + /* UCOL_FIRST_TERTIARY_IGNORABLE */ + setIndirectBoundaries(5, consts->UCA_FIRST_TERTIARY_IGNORABLE, 0); + /* UCOL_LAST_TERTIARY_IGNORABLE */ + setIndirectBoundaries(6, consts->UCA_LAST_TERTIARY_IGNORABLE, 0); + /* UCOL_FIRST_VARIABLE */ + setIndirectBoundaries(7, consts->UCA_FIRST_VARIABLE, 0); + /* UCOL_LAST_VARIABLE */ + setIndirectBoundaries(8, consts->UCA_LAST_VARIABLE, 0); + /* UCOL_FIRST_NON_VARIABLE */ + setIndirectBoundaries(9, consts->UCA_FIRST_NON_VARIABLE, 0); + /* UCOL_LAST_NON_VARIABLE */ + setIndirectBoundaries(10, consts->UCA_LAST_NON_VARIABLE, consts->UCA_FIRST_IMPLICIT); + /* UCOL_FIRST_IMPLICIT */ + setIndirectBoundaries(11, consts->UCA_FIRST_IMPLICIT, 0); + /* UCOL_LAST_IMPLICIT */ + setIndirectBoundaries(12, consts->UCA_LAST_IMPLICIT, consts->UCA_FIRST_TRAILING); + /* UCOL_FIRST_TRAILING */ + setIndirectBoundaries(13, consts->UCA_FIRST_TRAILING, 0); + /* UCOL_LAST_TRAILING */ + setIndirectBoundaries(14, consts->UCA_LAST_TRAILING, 0); + ucolIndirectBoundaries[14].limitCE = (consts->UCA_PRIMARY_SPECIAL_MIN<<24); + indirectBoundariesSet = TRUE; + } - ucol_initInverseUCA(status); - if(U_SUCCESS(*status) && ruleLen > 0) { - rulesCopy = (UChar *)malloc((ruleLen+UCOL_TOK_EXTRA_RULE_SPACE_SIZE)*sizeof(UChar)); - uprv_memcpy(rulesCopy, rules, ruleLen*sizeof(UChar)); - src.current = src.source = rulesCopy; - src.end = rulesCopy+ruleLen; - src.extraCurrent = src.end; - src.extraEnd = src.end+UCOL_TOK_EXTRA_RULE_SPACE_SIZE; + if(U_SUCCESS(*status) && ruleLen > 0) { + rulesCopy = (UChar *)uprv_malloc((ruleLen+UCOL_TOK_EXTRA_RULE_SPACE_SIZE)*sizeof(UChar)); + uprv_memcpy(rulesCopy, rules, ruleLen*sizeof(UChar)); + src.current = src.source = rulesCopy; + src.end = rulesCopy+ruleLen; + src.extraCurrent = src.end; + src.extraEnd = src.end+UCOL_TOK_EXTRA_RULE_SPACE_SIZE; + + /* Note that as a result of tickets 7015 or 6912, ucol_tok_parseNextToken can cause the pointer to + the rules copy in src.source to get reallocated, freeing the original pointer in rulesCopy */ + while ((current = ucol_tok_parseNextToken(&src, startOfRules, &parseError,status)) != NULL) { + strength = src.parsedToken.strength; + chOffset = src.parsedToken.charsOffset; + chLen = src.parsedToken.charsLen; + exOffset = src.parsedToken.extensionOffset; + exLen = src.parsedToken.extensionLen; + prefixOffset = src.parsedToken.prefixOffset; + prefixLen = src.parsedToken.prefixLen; + specs = src.parsedToken.flags; + + startOfRules = FALSE; + varT = (UBool)((specs & UCOL_TOK_VARIABLE_TOP) != 0); + top_ = (UBool)((specs & UCOL_TOK_TOP) != 0); + + uprv_init_collIterate(coll, src.source+chOffset, chLen, c, status); + + currCE = ucol_getNextCE(coll, c, status); + if(currCE == 0 && UCOL_ISTHAIPREVOWEL(*(src.source+chOffset))) { + log_verbose("Thai prevowel detected. Will pick next CE\n"); + currCE = ucol_getNextCE(coll, c, status); + } - while ((current = ucol_tok_parseNextToken(&src, startOfRules, &parseError,status)) != NULL) { - strength = src.parsedToken.strength; - chOffset = src.parsedToken.charsOffset; - chLen = src.parsedToken.charsLen; - exOffset = src.parsedToken.extensionOffset; - exLen = src.parsedToken.extensionLen; - prefixOffset = src.parsedToken.prefixOffset; - prefixLen = src.parsedToken.prefixLen; - specs = src.parsedToken.flags; + currContCE = ucol_getNextCE(coll, c, status); + if(!isContinuation(currContCE)) { + currContCE = 0; + } - startOfRules = FALSE; - varT = (UBool)((specs & UCOL_TOK_VARIABLE_TOP) != 0); - top_ = (UBool)((specs & UCOL_TOK_TOP) != 0); + /* we need to repack CEs here */ - uprv_init_collIterate(coll, rulesCopy+chOffset, chLen, &c); + if(strength == UCOL_TOK_RESET) { + before = (UBool)((specs & UCOL_TOK_BEFORE) != 0); + if(top_ == TRUE) { + int32_t tokenIndex = src.parsedToken.indirectIndex; - currCE = ucol_getNextCE(coll, &c, status); - if(currCE == 0 && UCOL_ISTHAIPREVOWEL(*(rulesCopy+chOffset))) { - log_verbose("Thai prevowel detected. Will pick next CE\n"); - currCE = ucol_getNextCE(coll, &c, status); - } + nextCE = baseCE = currCE = ucolIndirectBoundaries[tokenIndex].startCE; + nextContCE = baseContCE = currContCE = ucolIndirectBoundaries[tokenIndex].startContCE; + } else { + nextCE = baseCE = currCE; + nextContCE = baseContCE = currContCE; + } + maxStrength = UCOL_IDENTICAL; + } else { + if(strength < maxStrength) { + maxStrength = strength; + if(baseCE == UCOL_RESET_TOP_VALUE) { + log_verbose("Resetting to [top]\n"); + nextCE = UCOL_NEXT_TOP_VALUE; + nextContCE = UCOL_NEXT_TOP_CONT; + } else { + result = ucol_inv_getNextCE(&src, baseCE & 0xFFFFFF3F, baseContCE, &nextCE, &nextContCE, maxStrength); + } + if(result < 0) { + if(ucol_isTailored(coll, *(src.source+oldOffset), status)) { + log_verbose("Reset is tailored codepoint %04X, don't know how to continue, taking next test\n", *(src.source+oldOffset)); + return; + } else { + log_err("%s: couldn't find the CE\n", colLoc); + return; + } + } + } - currContCE = ucol_getNextCE(coll, &c, status); - if(!isContinuation(currContCE)) { - currContCE = 0; - } + currCE &= 0xFFFFFF3F; + currContCE &= 0xFFFFFFBF; - /* we need to repack CEs here */ + if(maxStrength == UCOL_IDENTICAL) { + if(baseCE != currCE || baseContCE != currContCE) { + log_err("%s: current CE (initial strength UCOL_EQUAL)\n", colLoc); + } + } else { + if(strength == UCOL_IDENTICAL) { + if(lastCE != currCE || lastContCE != currContCE) { + log_err("%s: current CE (initial strength UCOL_EQUAL)\n", colLoc); + } + } else { + if(compareCEs(currCE, currContCE, nextCE, nextContCE) > 0) { + /*if(currCE > nextCE || (currCE == nextCE && currContCE >= nextContCE)) {*/ + log_err("%s: current CE is not less than base CE\n", colLoc); + } + if(!before) { + if(compareCEs(currCE, currContCE, lastCE, lastContCE) < 0) { + /*if(currCE < lastCE || (currCE == lastCE && currContCE <= lastContCE)) {*/ + log_err("%s: sequence of generated CEs is broken\n", colLoc); + } + } else { + before = FALSE; + if(compareCEs(currCE, currContCE, lastCE, lastContCE) > 0) { + /*if(currCE < lastCE || (currCE == lastCE && currContCE <= lastContCE)) {*/ + log_err("%s: sequence of generated CEs is broken\n", colLoc); + } + } + } + } - if(strength == UCOL_TOK_RESET) { - if(top_ == TRUE) { - - nextCE = baseCE = currCE = UCOL_RESET_TOP_VALUE; - nextContCE = baseContCE = currContCE = UCOL_RESET_TOP_CONT; - } else { - nextCE = baseCE = currCE; - nextContCE = baseContCE = currContCE; - } - maxStrength = UCOL_IDENTICAL; - } else { - if(strength < maxStrength) { - maxStrength = strength; - if(baseCE == UCOL_RESET_TOP_VALUE) { - log_verbose("Resetting to [top]\n"); - nextCE = UCOL_NEXT_TOP_VALUE; - nextContCE = UCOL_NEXT_TOP_CONT; - } else { - result = ucol_inv_getNextCE(baseCE & 0xFFFFFF3F, baseContCE, &nextCE, &nextContCE, maxStrength); - } - if(result < 0) { - if(ucol_isTailored(coll, *(rulesCopy+oldOffset), status)) { - log_verbose("Reset is tailored codepoint %04X, don't know how to continue, taking next test\n", *(rulesCopy+oldOffset)); - return; - } else { - log_err("couldn't find the CE\n"); - return; } - } - } - - currCE &= 0xFFFFFF3F; - currContCE &= 0xFFFFFFBF; - if(maxStrength == UCOL_IDENTICAL) { - if(baseCE != currCE || baseContCE != currContCE) { - log_err("current CE (initial strength UCOL_EQUAL)\n"); - } - } else { - if(strength == UCOL_IDENTICAL) { - if(lastCE != currCE || lastContCE != currContCE) { - log_err("current CE (initial strength UCOL_EQUAL)\n"); - } - } else { - if(compareCEs(currCE, currContCE, nextCE, nextContCE) > 0) { - /*if(currCE > nextCE || (currCE == nextCE && currContCE >= nextContCE)) {*/ - log_err("current CE is not less than base CE\n"); - } - if(compareCEs(currCE, currContCE, lastCE, lastContCE) < 0) { - /*if(currCE < lastCE || (currCE == lastCE && currContCE <= lastContCE)) {*/ - log_err("sequence of generated CEs is broken\n"); - } - } + oldOffset = chOffset; + lastCE = currCE & 0xFFFFFF3F; + lastContCE = currContCE & 0xFFFFFFBF; } - - } - - oldOffset = chOffset; - lastCE = currCE & 0xFFFFFF3F; - lastContCE = currContCE & 0xFFFFFFBF; + uprv_free(src.source); + uprv_free(src.reorderCodes); } - free(rulesCopy); - } - ucol_close(UCA); + ucol_close(UCA); + uprv_delete_collIterate(c); } #if 0 @@ -1286,271 +1324,187 @@ static const char* rulesToTest[] = { "&[top]<'?';Qum<3<4<5image->jamoSpecial == TRUE) { - log_err("%s has special JAMOs\n", locName); + if (uprv_strcmp("km", uloc_getDefault())==0 || uprv_strcmp("km_KH", uloc_getDefault())==0) { + /* This test will fail if the default locale is "km" or "km_KH". Enable after trac#6040. */ + return; + } + + for(i = 0; iimage->jamoSpecial == TRUE) { + log_err("%s has special JAMOs\n", locName); + } + ucol_setAttribute(coll, UCOL_CASE_FIRST, UCOL_OFF, &status); + testCollator(coll, &status); + testCEs(coll, &status); + } else { + log_verbose("Skipping %s: %s\n", locName, u_errorName(status)); + } + ucol_close(coll); + } else { + log_err("Could not open %s: %s\n", locName, u_errorName(status)); + } } - ucol_setAttribute(coll, UCOL_CASE_FIRST, UCOL_OFF, &status); - testCollator(coll, &status); - testCEs(coll, &status); - ucol_close(coll); - } } - } - for(i = 0; i %s (Are you missing data?)\n", u_errorName(status)); + return; } + charsToTestSize = uset_size(charsToTest); + if (charsToTestSize <= 0) { + log_err("Set was zero. Missing data?\n"); + return; + } + t = (tester **)malloc(charsToTestSize * sizeof(tester *)); + t[0] = (tester *)malloc(sizeof(tester)); + log_verbose("Testing UCA extensively for %d characters\n", charsToTestSize); - - for(u = 0; u < 0x30000; u++) { - len = 0; - UTF_APPEND_CHAR_UNSAFE(comp, len, u); + for(u = 0; u < charsToTestSize; u++) { + UChar32 ch = uset_charAt(charsToTest, u); + len = 0; + U16_APPEND_UNSAFE(comp, len, ch); nfcSize = unorm_normalize(comp, len, UNORM_NFC, 0, t[noCases]->NFC, NORM_BUFFER_TEST_LEN, &status); nfdSize = unorm_normalize(comp, len, UNORM_NFD, 0, t[noCases]->NFD, NORM_BUFFER_TEST_LEN, &status); - if(nfcSize != nfdSize || (uprv_memcmp(t[noCases]->NFC, t[noCases]->NFD, nfcSize * sizeof(UChar)) != 0) + if(nfcSize != nfdSize || (uprv_memcmp(t[noCases]->NFC, t[noCases]->NFD, nfcSize * sizeof(UChar)) != 0) || (len != nfdSize || (uprv_memcmp(comp, t[noCases]->NFD, nfdSize * sizeof(UChar)) != 0))) { - t[noCases]->u = u; + t[noCases]->u = ch; if(len != nfdSize || (uprv_memcmp(comp, t[noCases]->NFD, nfdSize * sizeof(UChar)) != 0)) { - u_strncpy(t[noCases]->NFC, comp, len); - t[noCases]->NFC[len] = 0; + u_strncpy(t[noCases]->NFC, comp, len); + t[noCases]->NFC[len] = 0; } noCases++; t[noCases] = (tester *)malloc(sizeof(tester)); uprv_memset(t[noCases], 0, sizeof(tester)); - } + } } + log_verbose("Testing %d/%d of possible test cases\n", noCases, charsToTestSize); + uset_close(charsToTest); + charsToTest = NULL; for(u=0; u<(UChar32)noCases; u++) { - if(!ucol_equal(coll, t[u]->NFC, -1, t[u]->NFD, -1)) { - log_err("Failure: codePoint %05X fails TestComposeDecompose in the UCA\n", t[u]->u); - doTest(coll, t[u]->NFC, t[u]->NFD, UCOL_EQUAL); - } + if(!ucol_equal(coll, t[u]->NFC, -1, t[u]->NFD, -1)) { + log_err("Failure: codePoint %05X fails TestComposeDecompose in the UCA\n", t[u]->u); + doTest(coll, t[u]->NFC, t[u]->NFD, UCOL_EQUAL); + } } /* - for(u = 0; u < 0x30000; u++) { + for(u = 0; u < charsToTestSize; u++) { if(!(u&0xFFFF)) { log_verbose("%08X ", u); } uprv_memset(t[noCases], 0, sizeof(tester)); t[noCases]->u = u; len = 0; - UTF_APPEND_CHAR_UNSAFE(comp, len, u); + U16_APPEND_UNSAFE(comp, len, u); comp[len] = 0; nfcSize = unorm_normalize(comp, len, UNORM_NFC, 0, t[noCases]->NFC, NORM_BUFFER_TEST_LEN, &status); nfdSize = unorm_normalize(comp, len, UNORM_NFD, 0, t[noCases]->NFD, NORM_BUFFER_TEST_LEN, &status); @@ -1760,13 +1752,21 @@ static void TestComposeDecompose(void) { coll = ucol_open(locName, &status); ucol_setStrength(coll, UCOL_IDENTICAL); + iter = ucol_openElements(coll, t[u]->NFD, u_strlen(t[u]->NFD), &status); for(u=0; u<(UChar32)noCases; u++) { - if(!ucol_equal(coll, t[u]->NFC, -1, t[u]->NFD, -1)) { - log_err("Failure: codePoint %05X fails TestComposeDecompose for locale %s\n", t[u]->u, cName); - doTest(coll, t[u]->NFC, t[u]->NFD, UCOL_EQUAL); - } + if(!ucol_equal(coll, t[u]->NFC, -1, t[u]->NFD, -1)) { + log_err("Failure: codePoint %05X fails TestComposeDecompose for locale %s\n", t[u]->u, cName); + doTest(coll, t[u]->NFC, t[u]->NFD, UCOL_EQUAL); + log_verbose("Testing NFC\n"); + ucol_setText(iter, t[u]->NFC, u_strlen(t[u]->NFC), &status); + backAndForth(iter); + log_verbose("Testing NFD\n"); + ucol_setText(iter, t[u]->NFD, u_strlen(t[u]->NFD), &status); + backAndForth(iter); + } } + ucol_closeElements(iter); ucol_close(coll); } } @@ -1865,6 +1865,8 @@ static void TestBefore(void) { data, sizeof(data)/sizeof(data[0])); } +#if 0 +/* superceded by TestBeforePinyin */ static void TestJ784(void) { const static char *data[] = { "A", "\\u0101", "\\u00e1", "\\u01ce", "\\u00e0", @@ -1877,8 +1879,10 @@ static void TestJ784(void) { }; genericLocaleStarter("zh", data, sizeof(data)/sizeof(data[0])); } +#endif - +#if 0 +/* superceded by the changes to the lv locale */ static void TestJ831(void) { const static char *data[] = { "I", @@ -1888,6 +1892,7 @@ static void TestJ831(void) { }; genericLocaleStarter("lv", data, sizeof(data)/sizeof(data[0])); } +#endif static void TestJ815(void) { const static char *data[] = { @@ -1925,87 +1930,103 @@ static void TestJ815(void) { static void TestRedundantRules(void) { int32_t i; - const static char *rules[] = { - "& a <<< b <<< c << d <<< e& [before 1] e <<< x", - "& a < b <<< c << d <<< e& [before 1] e <<< x", - "& a < b < c < d& [before 1] c < m", - "& a < b <<< c << d <<< e& [before 3] e <<< x", - "& a < b <<< c << d <<< e& [before 2] e <<< x", - "& a < b <<< c << d <<< e <<< f < g& [before 1] g < x", - "& a <<< b << c < d& a < m", - "&a %s\n", u_errorName(status)); return; } while (count < 149) { @@ -2622,7 +2644,7 @@ static void TestCyrillicTailoring(void) { }; /* Russian overrides contractions, so this test is not valid anymore */ - /*genericLocaleStarter("ru", test, 3);*/ + /*genericLocaleStarter("ru", test, 3);*/ genericLocaleStarter("root", test, 3); genericRulesStarter("&\\u0410 = \\u0410", test, 3); @@ -2638,14 +2660,14 @@ static void TestSuppressContractions(void) { static const char *testNoCont2[] = { "\\u0410\\u0302a", "\\u0410\\u0306b", - "\\u0410c" + "\\u0410c" }; static const char *testNoCont[] = { - "a\\u0410", + "a\\u0410", "A\\u0410\\u0306", "\\uFF21\\u0410\\u0302" }; - + genericRulesStarter("[suppressContractions [\\u0400-\\u047f]]", testNoCont, 3); genericRulesStarter("[suppressContractions [\\u0400-\\u047f]]", testNoCont2, 3); } @@ -2690,7 +2712,7 @@ static void TestContraction(void) { rlen = u_unescape(testrules[i], rule, 32); coll = ucol_openRules(rule, rlen, UCOL_ON, UCOL_TERTIARY,NULL, &status); if (U_FAILURE(status)) { - log_err("Collator creation failed %s\n", testrules[i]); + log_err_status(status, "Collator creation failed %s -> %s\n", testrules[i], u_errorName(status)); return; } iter1 = ucol_openElements(coll, testdata[i], 2, &status); @@ -2816,7 +2838,7 @@ static void TestExpansion(void) { rlen = u_unescape(testrules[i], rule, 32); coll = ucol_openRules(rule, rlen, UCOL_ON, UCOL_TERTIARY,NULL, &status); if (U_FAILURE(status)) { - log_err("Collator creation failed %s\n", testrules[i]); + log_err_status(status, "Collator creation failed %s -> %s\n", testrules[i], u_errorName(status)); return; } @@ -2827,128 +2849,6 @@ static void TestExpansion(void) { } } -/** - * Test for CollationElementIterator previous and next for the whole set of - * unicode characters with normalization on. - */ -static void TestNumericCollation(void) -{ - UCollationElements *iter; - UErrorCode status = U_ZERO_ERROR; - - int i = 0, j = 0, size = 0; - /*UCollationResult collResult;*/ - UChar t1[100], t2[100]; - - const static char *basicTestStrings[]={ - "hello1", - "hello2", - "hello123456" - }; - - const static char *preZeroTestStrings[]={ - "avery1", - "avery01", - "avery001", - "avery0001" - }; - - const static char *thirtyTwoBitNumericStrings[]={ - "avery42949672960", - "avery42949672961", - "avery42949672962", - "avery429496729610" - }; - - const static char *arabicNumericStrings[]={ - "avery""\\u0660", /*avery followed by the arabic digit 0*/ - "avery""\\u0661", /*avery followed by the arabic digit 1*/ - "avery""\\u0662", /*avery followed by the arabic digit 1*/ - "avery""\\u0661\\u0662" /*avery followed by the arabic digits 1 and 2*/ - }; - - - /* Open our collator. */ - UCollator* coll = ucol_open(NULL, &status); - if (U_FAILURE(status)){ - log_err("ERROR: in using ucol_open()\n %s\n", - myErrorName(status)); - return; - } - - /* Setting up our collator to do digits.*/ - ucol_setAttribute(coll, UCOL_NUMERIC_COLLATION, UCOL_ON, &status); - if (U_FAILURE(status)){ - log_err("ERROR: in setting UCOL_NUMERIC_COLLATION as an attribute\n %s\n", - myErrorName(status)); - return; - } - - /* - Testing basic numeric collation behavior. We expect that every element in our - strings array is less than it's predecessor. This shows that numeric collation - works (on a superficial level). - */ - size = sizeof(basicTestStrings)/sizeof(basicTestStrings[0]); - for(i = 0; i < size-1; i++) { - for(j = i+1; j < size; j++) { - u_uastrcpy(t1, basicTestStrings[i]); - u_uastrcpy(t2, basicTestStrings[j]); - doTest(coll, t1, t2, UCOL_LESS); - } - } - /* - Testing that prepended zeroes still yield the correct collation behavior. - We expect that every element in our strings array will be equal. - */ - size = sizeof(preZeroTestStrings)/sizeof(preZeroTestStrings[0]); - for(i = 0; i < size-1; i++) { - for(j = i+1; j < size; j++) { - u_uastrcpy(t1, preZeroTestStrings[i]); - u_uastrcpy(t2, preZeroTestStrings[j]); - doTest(coll, t1, t2, UCOL_EQUAL); - } - } - - /* - Testing that numeric collation can handle numbers greater than 32-bits. - We expect that every element in our strings array is less than it's successor. - */ - size = sizeof(thirtyTwoBitNumericStrings)/sizeof(thirtyTwoBitNumericStrings[0]); - for(i = 0; i < size-1; i++) { - for(j = i+1; j < size; j++) { - u_uastrcpy(t1, thirtyTwoBitNumericStrings[i]); - u_uastrcpy(t2, thirtyTwoBitNumericStrings[j]); - doTest(coll, t1, t2, UCOL_LESS); - } - } - - /* - Testing that numeric collation for arabic numbers. This case is interesting because - it ensures that non-Roman characters that have the numeric property still get processed - correctly. We expect every element to be less than it's successor. - */ - - size = sizeof(arabicNumericStrings)/sizeof(arabicNumericStrings[0]); - for(i = 0; i < size-1; i++) { - for(j = i+1; j < size; j++) { - u_unescape(arabicNumericStrings[i], t1,100); - u_unescape(arabicNumericStrings[j], t2,100); - doTest(coll, t1, t2, UCOL_LESS); - } - } - /* - Testing collation element iterator. Running backAndForth on - a string with numbers in it should be sufficient. - */ - u_uastrcpy(t1, basicTestStrings[2]); - iter=ucol_openElements(coll, t1, u_strlen(t1), &status); - backAndForth(iter); - ucol_closeElements(iter); - - ucol_close(coll); -} - #if 0 /* this test tests the current limitations of the engine */ /* it always fail, so it is disabled by default */ @@ -3093,20 +2993,22 @@ static void TestVariableTopSetting(void) { UChar first[256] = { 0 }; UChar second[256] = { 0 }; UParseError parseError; - int32_t myQ = QUICK; + int32_t myQ = getTestOption(QUICK_OPTION); + + uprv_memset(&src, 0, sizeof(UColTokenParser)); src.opts = &opts; - if(QUICK <= 0) { - QUICK = 1; + if(getTestOption(QUICK_OPTION) <= 0) { + setTestOption(QUICK_OPTION, 1); } /* this test will fail when normalization is turned on */ /* therefore we always turn off exhaustive mode for it */ - if(1) { /* QUICK > 0*/ + { /* QUICK > 0*/ log_verbose("Slide variable top over UCARules\n"); rulesLen = ucol_getRulesEx(coll, UCOL_FULL_RULES, rulesCopy, 0); - rulesCopy = (UChar *)malloc((rulesLen+UCOL_TOK_EXTRA_RULE_SPACE_SIZE)*sizeof(UChar)); + rulesCopy = (UChar *)uprv_malloc((rulesLen+UCOL_TOK_EXTRA_RULE_SPACE_SIZE)*sizeof(UChar)); rulesLen = ucol_getRulesEx(coll, UCOL_FULL_RULES, rulesCopy, rulesLen+UCOL_TOK_EXTRA_RULE_SPACE_SIZE); if(U_SUCCESS(status) && rulesLen > 0) { @@ -3114,8 +3016,10 @@ static void TestVariableTopSetting(void) { src.current = src.source = rulesCopy; src.end = rulesCopy+rulesLen; src.extraCurrent = src.end; - src.extraEnd = src.end+UCOL_TOK_EXTRA_RULE_SPACE_SIZE; + src.extraEnd = src.end+UCOL_TOK_EXTRA_RULE_SPACE_SIZE; + /* Note that as a result of tickets 7015 or 6912, ucol_tok_parseNextToken can cause the pointer to + the rules copy in src.source to get reallocated, freeing the original pointer in rulesCopy */ while ((current = ucol_tok_parseNextToken(&src, startOfRules, &parseError,&status)) != NULL) { strength = src.parsedToken.strength; chOffset = src.parsedToken.charsOffset; @@ -3127,13 +3031,13 @@ static void TestVariableTopSetting(void) { specs = src.parsedToken.flags; startOfRules = FALSE; - if(0) { - log_verbose("%04X %d ", *(rulesCopy+chOffset), chLen); + { + log_verbose("%04X %d ", *(src.source+chOffset), chLen); } if(strength == UCOL_PRIMARY) { status = U_ZERO_ERROR; varTopOriginal = ucol_getVariableTop(coll, &status); - varTop1 = ucol_setVariableTop(coll, rulesCopy+oldChOffset, oldChLen, &status); + varTop1 = ucol_setVariableTop(coll, src.source+oldChOffset, oldChLen, &status); if(U_FAILURE(status)) { char buffer[256]; char *buf = buffer; @@ -3141,26 +3045,28 @@ static void TestVariableTopSetting(void) { uint32_t CE = UCOL_NO_MORE_CES; /* before we start screaming, let's see if there is a problem with the rules */ - collIterate s; - uprv_init_collIterate(coll, rulesCopy+oldChOffset, oldChLen, &s); + UErrorCode collIterateStatus = U_ZERO_ERROR; + collIterate *s = uprv_new_collIterate(&collIterateStatus); + uprv_init_collIterate(coll, src.source+oldChOffset, oldChLen, s, &collIterateStatus); - CE = ucol_getNextCE(coll, &s, &status); + CE = ucol_getNextCE(coll, s, &status); for(i = 0; i < oldChLen; i++) { - j = sprintf(buf, "%04X ", *(rulesCopy+oldChOffset+i)); + j = sprintf(buf, "%04X ", *(src.source+oldChOffset+i)); buf += j; } if(status == U_PRIMARY_TOO_LONG_ERROR) { log_verbose("= Expected failure for %s =", buffer); } else { - if(s.pos == s.endp) { - log_err("Unexpected failure setting variable top at offset %d. Error %s. Codepoints: %s\n", + if(uprv_collIterateAtEnd(s)) { + log_err("Unexpected failure setting variable top at offset %d. Error %s. Codepoints: %s\n", oldChOffset, u_errorName(status), buffer); } else { - log_verbose("There is a goofy contraction in UCA rules that does not appear in the fractional UCA. Codepoints: %s\n", + log_verbose("There is a goofy contraction in UCA rules that does not appear in the fractional UCA. Codepoints: %s\n", buffer); } } + uprv_delete_collIterate(s); } varTop2 = ucol_getVariableTop(coll, &status); if((varTop1 & 0xFFFF0000) != (varTop2 & 0xFFFF0000)) { @@ -3170,25 +3076,25 @@ static void TestVariableTopSetting(void) { if((varTop1 & 0xFFFF0000) > 0 && oldExLen == 0) { - u_strncpy(first, rulesCopy+oldChOffset, oldChLen); - u_strncpy(first+oldChLen, rulesCopy+chOffset, chLen); - u_strncpy(first+oldChLen+chLen, rulesCopy+oldChOffset, oldChLen); + u_strncpy(first, src.source+oldChOffset, oldChLen); + u_strncpy(first+oldChLen, src.source+chOffset, chLen); + u_strncpy(first+oldChLen+chLen, src.source+oldChOffset, oldChLen); first[2*oldChLen+chLen] = 0; if(oldExLen == 0) { - u_strncpy(second, rulesCopy+chOffset, chLen); + u_strncpy(second, src.source+chOffset, chLen); second[chLen] = 0; } else { /* This is skipped momentarily, but should work once UCARules are fully UCA conformant */ - u_strncpy(second, rulesCopy+oldExOffset, oldExLen); - u_strncpy(second+oldChLen, rulesCopy+chOffset, chLen); - u_strncpy(second+oldChLen+chLen, rulesCopy+oldExOffset, oldExLen); + u_strncpy(second, src.source+oldExOffset, oldExLen); + u_strncpy(second+oldChLen, src.source+chOffset, chLen); + u_strncpy(second+oldChLen+chLen, src.source+oldExOffset, oldExLen); second[2*oldExLen+chLen] = 0; } result = ucol_strcoll(coll, first, -1, second, -1); if(result == UCOL_EQUAL) { doTest(coll, first, second, UCOL_EQUAL); } else { - log_verbose("Suspicious strcoll result for %04X and %04X\n", *(rulesCopy+oldChOffset), *(rulesCopy+chOffset)); + log_verbose("Suspicious strcoll result for %04X and %04X\n", *(src.source+oldChOffset), *(src.source+chOffset)); } } } @@ -3212,25 +3118,39 @@ static void TestVariableTopSetting(void) { status = U_ZERO_ERROR; } - QUICK = myQ; + setTestOption(QUICK_OPTION, myQ); log_verbose("Testing setting variable top to contractions\n"); { - /* uint32_t tailoredCE = UCOL_NOT_FOUND; */ - /*UChar *conts = (UChar *)((uint8_t *)coll->image + coll->image->UCAConsts+sizeof(UCAConstants));*/ UChar *conts = (UChar *)((uint8_t *)coll->image + coll->image->contractionUCACombos); + int32_t maxUCAContractionLength = coll->image->contractionUCACombosWidth; while(*conts != 0) { - if(*(conts+2) == 0) { - varTop1 = ucol_setVariableTop(coll, conts, -1, &status); + /* + * A continuation is NUL-terminated and NUL-padded + * except if it has the maximum length. + */ + int32_t contractionLength = maxUCAContractionLength; + while(contractionLength > 0 && conts[contractionLength - 1] == 0) { + --contractionLength; + } + if(*(conts+1)==0) { /* pre-context */ + varTop1 = ucol_setVariableTop(coll, conts, 1, &status); } else { - varTop1 = ucol_setVariableTop(coll, conts, 3, &status); + varTop1 = ucol_setVariableTop(coll, conts, contractionLength, &status); } if(U_FAILURE(status)) { - log_err("Couldn't set variable top to a contraction %04X %04X %04X\n", - *conts, *(conts+1), *(conts+2)); + if(status == U_PRIMARY_TOO_LONG_ERROR) { + /* ucol_setVariableTop() is documented to not accept 3-byte primaries, + * therefore it is not an error when it complains about them. */ + log_verbose("Couldn't set variable top to a contraction %04X %04X %04X - U_PRIMARY_TOO_LONG_ERROR\n", + *conts, *(conts+1), *(conts+2)); + } else { + log_err("Couldn't set variable top to a contraction %04X %04X %04X - %s\n", + *conts, *(conts+1), *(conts+2), u_errorName(status)); + } status = U_ZERO_ERROR; } - conts+=3; + conts+=maxUCAContractionLength; } status = U_ZERO_ERROR; @@ -3267,7 +3187,7 @@ static void TestVariableTopSetting(void) { if(status != U_INTERNAL_PROGRAM_ERROR) { log_err("Bad reaction to passed error!\n"); } - free(rulesCopy); + uprv_free(src.source); ucol_close(coll); } else { log_data_err("Couldn't open UCA collator\n"); @@ -3277,10 +3197,11 @@ static void TestVariableTopSetting(void) { static void TestNonChars(void) { static const char *test[] = { - "\\u0000", - "\\uFFFE", "\\uFFFF", - "\\U0001FFFE", "\\U0001FFFF", - "\\U0002FFFE", "\\U0002FFFF", + "\\u0000", /* ignorable */ + "\\uFFFE", /* special merge-sort character with minimum non-ignorable weights */ + "\\uFDD0", "\\uFDEF", + "\\U0001FFFE", "\\U0001FFFF", /* UCA 6.0: noncharacters are treated like unassigned, */ + "\\U0002FFFE", "\\U0002FFFF", /* not like ignorable. */ "\\U0003FFFE", "\\U0003FFFF", "\\U0004FFFE", "\\U0004FFFF", "\\U0005FFFE", "\\U0005FFFF", @@ -3294,7 +3215,8 @@ static void TestNonChars(void) { "\\U000DFFFE", "\\U000DFFFF", "\\U000EFFFE", "\\U000EFFFF", "\\U000FFFFE", "\\U000FFFFF", - "\\U0010FFFE", "\\U0010FFFF" + "\\U0010FFFE", "\\U0010FFFF", + "\\uFFFF" /* special character with maximum primary weight */ }; UErrorCode status = U_ZERO_ERROR; UCollator *coll = ucol_open("en_US", &status); @@ -3302,9 +3224,9 @@ static void TestNonChars(void) { log_verbose("Test non characters\n"); if(U_SUCCESS(status)) { - genericOrderingTestWithResult(coll, test, 35, UCOL_EQUAL); + genericOrderingTestWithResult(coll, test, 35, UCOL_LESS); } else { - log_err("Unable to open collator\n"); + log_err_status(status, "Unable to open collator\n"); } ucol_close(coll); @@ -3388,19 +3310,19 @@ static void TestSurrogates(void) { static void TestPrefix(void) { uint32_t i; - static struct { + static const struct { const char *rules; const char *data[50]; const uint32_t len; - } tests[] = { - { "&z <<< z|a", + } tests[] = { + { "&z <<< z|a", {"zz", "za"}, 2 }, - { "&z <<< z| a", + { "&z <<< z| a", {"zz", "za"}, 2 }, { "[strength I]" "&a=\\ud900\\udc25" - "&z<<<\\ud900\\udc25|a", + "&z<<<\\ud900\\udc25|a", {"aa", "az", "\\ud900\\udc25z", "\\ud900\\udc25a", "zz"}, 4 }, }; @@ -3414,7 +3336,7 @@ static void TestPrefix(void) { /* JIS X 4061 collation order implementation */ static void TestNewJapanese(void) { - static const char *test1[] = { + static const char * const test1[] = { "\\u30b7\\u30e3\\u30fc\\u30ec", "\\u30b7\\u30e3\\u30a4", "\\u30b7\\u30e4\\u30a3", @@ -3426,7 +3348,7 @@ static void TestNewJapanese(void) { "\\u30c6\\u30fc\\u30bf", "\\u30c6\\u30a7\\u30bf", "\\u3066\\u3048\\u305f", - "\\u3067\\u30fc\\u305f", + "\\u3067\\u30fc\\u305f", "\\u30c7\\u30fc\\u30bf", "\\u30c7\\u30a7\\u30bf", "\\u3067\\u3048\\u305f", @@ -3450,7 +3372,7 @@ static void TestNewJapanese(void) { "\\u30d2\\u30e5\\u30a6", "\\u30d2\\u30e6\\u30a6", "\\u30d4\\u30e5\\u30a6\\u30a2", - "\\u3073\\u3085\\u30fc\\u3042\\u30fc", + "\\u3073\\u3085\\u30fc\\u3042\\u30fc", "\\u30d3\\u30e5\\u30fc\\u30a2\\u30fc", "\\u30d3\\u30e5\\u30a6\\u30a2\\u30fc", "\\u3072\\u3085\\u3093", @@ -3495,7 +3417,7 @@ static void TestNewJapanese(void) { static const char *test2[] = { "\\u306f\\u309d", /* H\\u309d */ - /*"\\u30cf\\u30fd",*/ /* K\\u30fd */ + "\\u30cf\\u30fd", /* K\\u30fd */ "\\u306f\\u306f", /* HH */ "\\u306f\\u30cf", /* HK */ "\\u30cf\\u30cf", /* KK */ @@ -3578,16 +3500,16 @@ static void TestStrCollIdenticalPrefix(void) { "ab\\ud9b0\\udc70", "ab\\ud9b0\\udc71" }; - genericRulesTestWithResult(rule, test, sizeof(test)/sizeof(test[0]), UCOL_EQUAL); + genericRulesStarterWithResult(rule, test, sizeof(test)/sizeof(test[0]), UCOL_EQUAL); } /* Contractions should have all their canonically equivalent */ /* strings included */ static void TestContractionClosure(void) { - static struct { + static const struct { const char *rules; - const char *data[50]; + const char *data[10]; const uint32_t len; - } tests[] = { + } tests[] = { { "&b=\\u00e4\\u00e4", { "b", "\\u00e4\\u00e4", "a\\u0308a\\u0308", "\\u00e4a\\u0308", "a\\u0308\\u00e4" }, 5}, { "&b=\\u00C5", @@ -3597,23 +3519,23 @@ static void TestContractionClosure(void) { for(i = 0; i<(sizeof(tests)/sizeof(tests[0])); i++) { - genericRulesTestWithResult(tests[i].rules, tests[i].data, tests[i].len, UCOL_EQUAL); + genericRulesStarterWithResult(tests[i].rules, tests[i].data, tests[i].len, UCOL_EQUAL); } } /* This tests also fails*/ static void TestBeforePrefixFailure(void) { - static struct { + static const struct { const char *rules; - const char *data[50]; + const char *data[10]; const uint32_t len; - } tests[] = { + } tests[] = { { "&g <<< a" "&[before 3]\\uff41 <<< x", {"x", "\\uff41"}, 2 }, { "&\\u30A7=\\u30A7=\\u3047=\\uff6a" "&\\u30A8=\\u30A8=\\u3048=\\uff74" - "&[before 3]\\u30a7<<<\\u30a9", + "&[before 3]\\u30a7<<<\\u30a9", {"\\u30a9", "\\u30a7"}, 2 }, { "&[before 3]\\u30a7<<<\\u30a9" "&\\u30A7=\\u30A7=\\u3047=\\uff6a" @@ -3628,16 +3550,16 @@ static void TestBeforePrefixFailure(void) { } #if 0 - const char* rule1 = + const char* rule1 = "&\\u30A7=\\u30A7=\\u3047=\\uff6a" "&\\u30A8=\\u30A8=\\u3048=\\uff74" "&[before 3]\\u30a7<<<\\u30c6|\\u30fc"; - const char* rule2 = + const char* rule2 = "&[before 3]\\u30a7<<<\\u30c6|\\u30fc" "&\\u30A7=\\u30A7=\\u3047=\\uff6a" "&\\u30A8=\\u30A8=\\u3048=\\uff74"; const char* test[] = { - "\\u30c6\\u30fc\\u30bf", + "\\u30c6\\u30fc\\u30bf", "\\u30c6\\u30a7\\u30bf", }; genericRulesStarter(rule1, test, sizeof(test)/sizeof(test[0])); @@ -3645,7 +3567,7 @@ static void TestBeforePrefixFailure(void) { /* this piece of code should be in some sort of verbose mode */ /* it gets the collation elements for elements and prints them */ /* This is useful when trying to see whether the problem is */ - { + { UErrorCode status = U_ZERO_ERROR; uint32_t i = 0; UCollationElements *it = NULL; @@ -3680,15 +3602,15 @@ static void TestBeforePrefixFailure(void) { } static void TestPrefixCompose(void) { - const char* rule1 = + const char* rule1 = "&\\u30a7<<<\\u30ab|\\u30fc=\\u30ac|\\u30fc"; /* const char* test[] = { - "\\u30c6\\u30fc\\u30bf", + "\\u30c6\\u30fc\\u30bf", "\\u30c6\\u30a7\\u30bf", }; */ - { + { UErrorCode status = U_ZERO_ERROR; /*uint32_t i = 0;*/ /*UCollationElements *it = NULL;*/ @@ -3707,80 +3629,123 @@ static void TestPrefixCompose(void) { } /* -[last variable] last variable value -[last primary ignorable] largest CE for primary ignorable -[last secondary ignorable] largest CE for secondary ignorable -[last tertiary ignorable] largest CE for tertiary ignorable -[top] guaranteed to be above all implicit CEs, for now and in the future (in 1.8) +[last variable] last variable value +[last primary ignorable] largest CE for primary ignorable +[last secondary ignorable] largest CE for secondary ignorable +[last tertiary ignorable] largest CE for tertiary ignorable +[top] guaranteed to be above all implicit CEs, for now and in the future (in 1.8) */ static void TestRuleOptions(void) { - /* values here are hardcoded and are correct for the current UCA - * when the UCA changes, one might be forced to change these - * values. (\\u02d0, \\U00010FFFC etc...) + /* values here are hardcoded and are correct for the current UCA + * when the UCA changes, one might be forced to change these + * values. + */ + + /* + * These strings contain the last character before [variable top] + * and the first and second characters (by primary weights) after it. + * See FractionalUCA.txt. For example: + [last variable [0C FE, 05, 05]] # U+10A7F OLD SOUTH ARABIAN NUMERIC INDICATOR + [variable top = 0C FE] + [first regular [0D 0A, 05, 05]] # U+0060 GRAVE ACCENT + and + 00B4; [0D 0C, 05, 05] + * + * Note: Starting with UCA 6.0, the [variable top] collation element + * is not the weight of any character or string, + * which means that LAST_VARIABLE_CHAR_STRING sorts before [last variable]. + */ +#define LAST_VARIABLE_CHAR_STRING "\\U00010A7F" +#define FIRST_REGULAR_CHAR_STRING "\\u0060" +#define SECOND_REGULAR_CHAR_STRING "\\u00B4" + + /* + * This string has to match the character that has the [last regular] weight + * which changes with each UCA version. + * See the bottom of FractionalUCA.txt which says something like + [last regular [7A FE, 05, 05]] # U+1342E EGYPTIAN HIEROGLYPH AA032 + * + * Note: Starting with UCA 6.0, the [last regular] collation element + * is not the weight of any character or string, + * which means that LAST_REGULAR_CHAR_STRING sorts before [last regular]. */ - static struct { +#define LAST_REGULAR_CHAR_STRING "\\U0001342E" + + static const struct { const char *rules; - const char *data[50]; + const char *data[10]; const uint32_t len; - } tests[] = { + } tests[] = { /* - all befores here amount to zero */ - { "&[before 1][first tertiary ignorable]<< s2 -weiv will check - could be a problem with utf-8 iterator -cycheng@ca.ibm.c... but if we use the utf-8 iterator, i.e. s1 = efbfbc62 and s2 = eda08021, we have s1 < s2 -weiv hmmm -cycheng@ca.ibm.c... note that we have a standalone high surrogate -weiv that doesn't sound right -cycheng@ca.ibm.c... we got the same inconsistent results on AIX and Win2000 -weiv so you have two strings, you convert them to utf-8 and to utf-16BE -cycheng@ca.ibm.c... yes -weiv and then do the comparison -cycheng@ca.ibm.c... in one case, the input strings are in utf8, and in the other case the input strings are in utf-16be -weiv utf-16 strings look like a little endian ones in the example you sent me -weiv It could be a bug - let me try to test it out -cycheng@ca.ibm.c... ok -cycheng@ca.ibm.c... we can wait till the conf. call -cycheng@ca.ibm.c... next weke -weiv that would be great -weiv hmmm -weiv I might be wrong -weiv let me play with it some more -cycheng@ca.ibm.c... ok -cycheng@ca.ibm.c... also please check s3 = 0x0e3a0062 and s4 = 0x0e400021. both are in utf-16be -cycheng@ca.ibm.c... seems with icu 2.2 we have s3 > s4, but not in icu 2.4 that's built for db2 -cycheng@ca.ibm.c... also s1 & s2 that I sent you earlier are also in utf-16be -weiv ok -cycheng@ca.ibm.c... i ask sherman to send you more inconsistent data -weiv thanks -cycheng@ca.ibm.c... the 4 strings we sent are just samples +cycheng@ca.ibm.c... we got inconsistent results when using the UTF-16BE iterator and the UTF-8 iterator. +weiv ucol_strcollIter? +cycheng@ca.ibm.c... e.g. s1 = 0xfffc0062, and s2 = d8000021 +weiv these are the input strings? +cycheng@ca.ibm.c... yes, using the utf-16 iterator and UCA with normalization on, we have s1 > s2 +weiv will check - could be a problem with utf-8 iterator +cycheng@ca.ibm.c... but if we use the utf-8 iterator, i.e. s1 = efbfbc62 and s2 = eda08021, we have s1 < s2 +weiv hmmm +cycheng@ca.ibm.c... note that we have a standalone high surrogate +weiv that doesn't sound right +cycheng@ca.ibm.c... we got the same inconsistent results on AIX and Win2000 +weiv so you have two strings, you convert them to utf-8 and to utf-16BE +cycheng@ca.ibm.c... yes +weiv and then do the comparison +cycheng@ca.ibm.c... in one case, the input strings are in utf8, and in the other case the input strings are in utf-16be +weiv utf-16 strings look like a little endian ones in the example you sent me +weiv It could be a bug - let me try to test it out +cycheng@ca.ibm.c... ok +cycheng@ca.ibm.c... we can wait till the conf. call +cycheng@ca.ibm.c... next weke +weiv that would be great +weiv hmmm +weiv I might be wrong +weiv let me play with it some more +cycheng@ca.ibm.c... ok +cycheng@ca.ibm.c... also please check s3 = 0x0e3a0062 and s4 = 0x0e400021. both are in utf-16be +cycheng@ca.ibm.c... seems with icu 2.2 we have s3 > s4, but not in icu 2.4 that's built for db2 +cycheng@ca.ibm.c... also s1 & s2 that I sent you earlier are also in utf-16be +weiv ok +cycheng@ca.ibm.c... i ask sherman to send you more inconsistent data +weiv thanks +cycheng@ca.ibm.c... the 4 strings we sent are just samples */ #if 0 static void Alexis(void) { @@ -3889,7 +3854,7 @@ static void Alexis2(void) { UErrorCode status = U_ZERO_ERROR; UChar U16Source[CMSCOLL_ALEXIS2_BUFFER_SIZE], U16Target[CMSCOLL_ALEXIS2_BUFFER_SIZE]; char U16BESource[CMSCOLL_ALEXIS2_BUFFER_SIZE], U16BETarget[CMSCOLL_ALEXIS2_BUFFER_SIZE]; - char U8Source[CMSCOLL_ALEXIS2_BUFFER_SIZE], U8Target[CMSCOLL_ALEXIS2_BUFFER_SIZE]; + char U8Source[CMSCOLL_ALEXIS2_BUFFER_SIZE], U8Target[CMSCOLL_ALEXIS2_BUFFER_SIZE]; int32_t U16LenS = 0, U16LenT = 0, U16BELenS = 0, U16BELenT = 0, U8LenS = 0, U8LenT = 0; UConverter *conv = NULL; @@ -3899,7 +3864,7 @@ static void Alexis2(void) { UCollationResult resU16, resU16BE, resU8; - const char* pairs[][2] = { + static const char* const pairs[][2] = { { "\\ud800\\u0021", "\\uFFFC\\u0062"}, { "\\u0435\\u0308\\u0334", "\\u0415\\u0334\\u0340" }, { "\\u0E40\\u0021", "\\u00A1\\u0021"}, @@ -3969,7 +3934,7 @@ static void Alexis2(void) { static void TestHebrewUCA(void) { UErrorCode status = U_ZERO_ERROR; - const char *first[] = { + static const char *first[] = { "d790d6b8d79cd795d6bcd7a9", "d790d79cd79ed7a7d799d799d7a1", "d790d6b4d79ed795d6bcd7a9", @@ -3983,6 +3948,10 @@ static void TestHebrewUCA(void) { int32_t sizeUTF16[3]; UCollator *coll = ucol_open("", &status); + if (U_FAILURE(status)) { + log_err_status(status, "Could not open UCA collation %s\n", u_errorName(status)); + return; + } /*ucol_setAttribute(coll, UCOL_NORMALIZATION_MODE, UCOL_ON, &status);*/ for(i = 0; i < sizeof(first)/sizeof(first[0]); i++) { @@ -4006,9 +3975,9 @@ static void TestHebrewUCA(void) { } static void TestPartialSortKeyTermination(void) { - const char* cases[] = { + static const char* cases[] = { "\\u1234\\u1234\\udc00", - "\\udc00\\ud800\\ud800" + "\\udc00\\ud800\\ud800" }; int32_t i = sizeof(UCollator); @@ -4038,12 +4007,12 @@ static void TestPartialSortKeyTermination(void) { } static void TestSettings(void) { - const char* cases[] = { + static const char* cases[] = { "apple", "Apple" }; - const char* locales[] = { + static const char* locales[] = { "", "en" }; @@ -4072,161 +4041,3026 @@ static void TestSettings(void) { } static int32_t TestEqualsForCollator(const char* locName, UCollator *source, UCollator *target) { - UErrorCode status = U_ZERO_ERROR; - int32_t errorNo = 0; - /*const UChar *sourceRules = NULL;*/ - /*int32_t sourceRulesLen = 0;*/ - UColAttributeValue french = UCOL_OFF; - int32_t cloneSize = 0; - - if(!ucol_equals(source, target)) { - log_err("Same collators, different address not equal\n"); - errorNo++; - } - ucol_close(target); - if(uprv_strcmp(ucol_getLocale(source, ULOC_REQUESTED_LOCALE, &status), ucol_getLocale(source, ULOC_ACTUAL_LOCALE, &status)) == 0) { - /* currently, safeClone is implemented through getRules/openRules - * so it is the same as the test below - I will comment that test out. - */ - /* real thing */ - target = ucol_safeClone(source, NULL, &cloneSize, &status); - if(U_FAILURE(status)) { - log_err("Error creating clone\n"); - errorNo++; - return errorNo; - } + UErrorCode status = U_ZERO_ERROR; + int32_t errorNo = 0; + /*const UChar *sourceRules = NULL;*/ + /*int32_t sourceRulesLen = 0;*/ + UColAttributeValue french = UCOL_OFF; + int32_t cloneSize = 0; + if(!ucol_equals(source, target)) { - log_err("Collator different from it's clone\n"); - errorNo++; - } - french = ucol_getAttribute(source, UCOL_FRENCH_COLLATION, &status); - if(french == UCOL_ON) { - ucol_setAttribute(target, UCOL_FRENCH_COLLATION, UCOL_OFF, &status); - } else { - ucol_setAttribute(target, UCOL_FRENCH_COLLATION, UCOL_ON, &status); - } - if(U_FAILURE(status)) { - log_err("Error setting attributes\n"); - errorNo++; - return errorNo; - } - if(ucol_equals(source, target)) { - log_err("Collators same even when options changed\n"); - errorNo++; + log_err("Same collators, different address not equal\n"); + errorNo++; } ucol_close(target); - /* commented out since safeClone uses exactly the same technique */ - /* - sourceRules = ucol_getRules(source, &sourceRulesLen); - target = ucol_openRules(sourceRules, sourceRulesLen, UCOL_DEFAULT, UCOL_DEFAULT, &parseError, &status); - if(U_FAILURE(status)) { - log_err("Error instantiating target from rules\n"); - errorNo++; - return errorNo; - } - if(!ucol_equals(source, target)) { - log_err("Collator different from collator that was created from the same rules\n"); - errorNo++; + if(uprv_strcmp(ucol_getLocaleByType(source, ULOC_REQUESTED_LOCALE, &status), ucol_getLocaleByType(source, ULOC_ACTUAL_LOCALE, &status)) == 0) { + /* currently, safeClone is implemented through getRules/openRules + * so it is the same as the test below - I will comment that test out. + */ + /* real thing */ + target = ucol_safeClone(source, NULL, &cloneSize, &status); + if(U_FAILURE(status)) { + log_err("Error creating clone\n"); + errorNo++; + return errorNo; + } + if(!ucol_equals(source, target)) { + log_err("Collator different from it's clone\n"); + errorNo++; + } + french = ucol_getAttribute(source, UCOL_FRENCH_COLLATION, &status); + if(french == UCOL_ON) { + ucol_setAttribute(target, UCOL_FRENCH_COLLATION, UCOL_OFF, &status); + } else { + ucol_setAttribute(target, UCOL_FRENCH_COLLATION, UCOL_ON, &status); + } + if(U_FAILURE(status)) { + log_err("Error setting attributes\n"); + errorNo++; + return errorNo; + } + if(ucol_equals(source, target)) { + log_err("Collators same even when options changed\n"); + errorNo++; + } + ucol_close(target); + /* commented out since safeClone uses exactly the same technique */ + /* + sourceRules = ucol_getRules(source, &sourceRulesLen); + target = ucol_openRules(sourceRules, sourceRulesLen, UCOL_DEFAULT, UCOL_DEFAULT, &parseError, &status); + if(U_FAILURE(status)) { + log_err("Error instantiating target from rules\n"); + errorNo++; + return errorNo; + } + if(!ucol_equals(source, target)) { + log_err("Collator different from collator that was created from the same rules\n"); + errorNo++; + } + ucol_close(target); + */ } - ucol_close(target); - */ - } - return errorNo; + return errorNo; } static void TestEquals(void) { - /* ucol_equals is not currently a public API. There is a chance that it will become - * something like this, but currently it is only used by RuleBasedCollator::operator== - */ - /* test whether the two collators instantiated from the same locale are equal */ - UErrorCode status = U_ZERO_ERROR; - UParseError parseError; - int32_t noOfLoc = uloc_countAvailable(); - const char *locName = NULL; - UCollator *source = NULL, *target = NULL; - int32_t i = 0; + /* ucol_equals is not currently a public API. There is a chance that it will become + * something like this, but currently it is only used by RuleBasedCollator::operator== + */ + /* test whether the two collators instantiated from the same locale are equal */ + UErrorCode status = U_ZERO_ERROR; + UParseError parseError; + int32_t noOfLoc = uloc_countAvailable(); + const char *locName = NULL; + UCollator *source = NULL, *target = NULL; + int32_t i = 0; + + const char* rules[] = { + "&l < lj <<< Lj <<< LJ", + "&n < nj <<< Nj <<< NJ", + "&ae <<< \\u00e4", + "&AE <<< \\u00c4" + }; + /* + const char* badRules[] = { + "&l <<< Lj", + "&n < nj <<< nJ <<< NJ", + "&a <<< \\u00e4", + "&AE <<< \\u00c4 <<< x" + }; + */ + + UChar sourceRules[1024], targetRules[1024]; + int32_t sourceRulesSize = 0, targetRulesSize = 0; + int32_t rulesSize = sizeof(rules)/sizeof(rules[0]); + + for(i = 0; i < rulesSize; i++) { + sourceRulesSize += u_unescape(rules[i], sourceRules+sourceRulesSize, 1024 - sourceRulesSize); + targetRulesSize += u_unescape(rules[rulesSize-i-1], targetRules+targetRulesSize, 1024 - targetRulesSize); + } + + source = ucol_openRules(sourceRules, sourceRulesSize, UCOL_DEFAULT, UCOL_DEFAULT, &parseError, &status); + if(status == U_FILE_ACCESS_ERROR) { + log_data_err("Is your data around?\n"); + return; + } else if(U_FAILURE(status)) { + log_err("Error opening collator\n"); + return; + } + target = ucol_openRules(targetRules, targetRulesSize, UCOL_DEFAULT, UCOL_DEFAULT, &parseError, &status); + if(!ucol_equals(source, target)) { + log_err("Equivalent collators not equal!\n"); + } + ucol_close(source); + ucol_close(target); + + source = ucol_open("root", &status); + target = ucol_open("root", &status); + log_verbose("Testing root\n"); + if(!ucol_equals(source, source)) { + log_err("Same collator not equal\n"); + } + if(TestEqualsForCollator(locName, source, target)) { + log_err("Errors for root\n", locName); + } + ucol_close(source); + + for(i = 0; i %s\n", u_errorName(status)); + } else { + ucol_close(coll); + } +} + +/** + * Test for CollationElementIterator previous and next for the whole set of + * unicode characters with normalization on. + */ +static void TestNumericCollation(void) +{ + UErrorCode status = U_ZERO_ERROR; + + const static char *basicTestStrings[]={ + "hello1", + "hello2", + "hello2002", + "hello2003", + "hello123456", + "hello1234567", + "hello10000000", + "hello100000000", + "hello1000000000", + "hello10000000000", + }; + + const static char *preZeroTestStrings[]={ + "avery10000", + "avery010000", + "avery0010000", + "avery00010000", + "avery000010000", + "avery0000010000", + "avery00000010000", + "avery000000010000", + }; + + const static char *thirtyTwoBitNumericStrings[]={ + "avery42949672960", + "avery42949672961", + "avery42949672962", + "avery429496729610" + }; + + const static char *longNumericStrings[]={ + /* Some of these sort out of the order that would expected if digits-as-numbers handled arbitrarily-long digit strings. + In fact, a single collation element can represent a maximum of 254 digits as a number. Digit strings longer than that + are treated as multiple collation elements. */ + "num9234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123z", /*253digits, num + 9.23E252 + z */ + "num10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", /*254digits, num + 1.00E253 */ + "num100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", /*255digits, num + 1.00E253 + 0, out of numeric order but expected */ + "num12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234", /*254digits, num + 1.23E253 */ + "num123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345", /*255digits, num + 1.23E253 + 5 */ + "num1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456", /*256digits, num + 1.23E253 + 56 */ + "num12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567", /*257digits, num + 1.23E253 + 567 */ + "num12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234a", /*254digits, num + 1.23E253 + a, out of numeric order but expected */ + "num92345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234", /*254digits, num + 9.23E253, out of numeric order but expected */ + "num92345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234a", /*254digits, num + 9.23E253 + a, out of numeric order but expected */ + }; + + const static char *supplementaryDigits[] = { + "\\uD835\\uDFCE", /* 0 */ + "\\uD835\\uDFCF", /* 1 */ + "\\uD835\\uDFD0", /* 2 */ + "\\uD835\\uDFD1", /* 3 */ + "\\uD835\\uDFCF\\uD835\\uDFCE", /* 10 */ + "\\uD835\\uDFCF\\uD835\\uDFCF", /* 11 */ + "\\uD835\\uDFCF\\uD835\\uDFD0", /* 12 */ + "\\uD835\\uDFD0\\uD835\\uDFCE", /* 20 */ + "\\uD835\\uDFD0\\uD835\\uDFCF", /* 21 */ + "\\uD835\\uDFD0\\uD835\\uDFD0" /* 22 */ + }; + + const static char *foreignDigits[] = { + "\\u0661", + "\\u0662", + "\\u0663", + "\\u0661\\u0660", + "\\u0661\\u0662", + "\\u0661\\u0663", + "\\u0662\\u0660", + "\\u0662\\u0662", + "\\u0662\\u0663", + "\\u0663\\u0660", + "\\u0663\\u0662", + "\\u0663\\u0663" + }; + + const static char *evenZeroes[] = { + "2000", + "2001", + "2002", + "2003" + }; + + UColAttribute att = UCOL_NUMERIC_COLLATION; + UColAttributeValue val = UCOL_ON; + + /* Open our collator. */ + UCollator* coll = ucol_open("root", &status); + if (U_FAILURE(status)){ + log_err_status(status, "ERROR: in using ucol_open() -> %s\n", + myErrorName(status)); + return; + } + genericLocaleStarterWithOptions("root", basicTestStrings, sizeof(basicTestStrings)/sizeof(basicTestStrings[0]), &att, &val, 1); + genericLocaleStarterWithOptions("root", thirtyTwoBitNumericStrings, sizeof(thirtyTwoBitNumericStrings)/sizeof(thirtyTwoBitNumericStrings[0]), &att, &val, 1); + genericLocaleStarterWithOptions("root", longNumericStrings, sizeof(longNumericStrings)/sizeof(longNumericStrings[0]), &att, &val, 1); + genericLocaleStarterWithOptions("en_US", foreignDigits, sizeof(foreignDigits)/sizeof(foreignDigits[0]), &att, &val, 1); + genericLocaleStarterWithOptions("root", supplementaryDigits, sizeof(supplementaryDigits)/sizeof(supplementaryDigits[0]), &att, &val, 1); + genericLocaleStarterWithOptions("root", evenZeroes, sizeof(evenZeroes)/sizeof(evenZeroes[0]), &att, &val, 1); + + /* Setting up our collator to do digits. */ + ucol_setAttribute(coll, UCOL_NUMERIC_COLLATION, UCOL_ON, &status); + if (U_FAILURE(status)){ + log_err("ERROR: in setting UCOL_NUMERIC_COLLATION as an attribute\n %s\n", + myErrorName(status)); + return; + } + + /* + Testing that prepended zeroes still yield the correct collation behavior. + We expect that every element in our strings array will be equal. + */ + genericOrderingTestWithResult(coll, preZeroTestStrings, sizeof(preZeroTestStrings)/sizeof(preZeroTestStrings[0]), UCOL_EQUAL); + + ucol_close(coll); +} + +static void TestTibetanConformance(void) +{ + const char* test[] = { + "\\u0FB2\\u0591\\u0F71\\u0061", + "\\u0FB2\\u0F71\\u0061" + }; + + UErrorCode status = U_ZERO_ERROR; + UCollator *coll = ucol_open("", &status); + UChar source[100]; + UChar target[100]; + int result; + ucol_setAttribute(coll, UCOL_NORMALIZATION_MODE, UCOL_ON, &status); + if (U_SUCCESS(status)) { + u_unescape(test[0], source, 100); + u_unescape(test[1], target, 100); + doTest(coll, source, target, UCOL_EQUAL); + result = ucol_strcoll(coll, source, -1, target, -1); + log_verbose("result %d\n", result); + if (UCOL_EQUAL != result) { + log_err("Tibetan comparison error\n"); + } + } + ucol_close(coll); + + genericLocaleStarterWithResult("", test, 2, UCOL_EQUAL); +} + +static void TestPinyinProblem(void) { + static const char *test[] = { "\\u4E56\\u4E56\\u7761", "\\u4E56\\u5B69\\u5B50" }; + genericLocaleStarter("zh__PINYIN", test, sizeof(test)/sizeof(test[0])); +} + +#define TST_UCOL_MAX_INPUT 0x220001 +#define topByte 0xFF000000; +#define bottomByte 0xFF; +#define fourBytes 0xFFFFFFFF; + + +static void showImplicit(UChar32 i) { + if (i >= 0 && i <= TST_UCOL_MAX_INPUT) { + log_verbose("%08X\t%08X\n", i, uprv_uca_getImplicitFromRaw(i)); + } +} + +static void TestImplicitGeneration(void) { + UErrorCode status = U_ZERO_ERROR; + UChar32 last = 0; + UChar32 current; + UChar32 i = 0, j = 0; + UChar32 roundtrip = 0; + UChar32 lastBottom = 0; + UChar32 currentBottom = 0; + UChar32 lastTop = 0; + UChar32 currentTop = 0; + + UCollator *coll = ucol_open("root", &status); + if(U_FAILURE(status)) { + log_err_status(status, "Couldn't open UCA -> %s\n", u_errorName(status)); + return; + } + + uprv_uca_getRawFromImplicit(0xE20303E7); + + for (i = 0; i <= TST_UCOL_MAX_INPUT; ++i) { + current = uprv_uca_getImplicitFromRaw(i) & fourBytes; + + /* check that it round-trips AND that all intervening ones are illegal*/ + roundtrip = uprv_uca_getRawFromImplicit(current); + if (roundtrip != i) { + log_err("No roundtrip %08X\n", i); + } + if (last != 0) { + for (j = last + 1; j < current; ++j) { + roundtrip = uprv_uca_getRawFromImplicit(j); + /* raise an error if it *doesn't* find an error*/ + if (roundtrip != -1) { + log_err("Fails to recognize illegal %08X\n", j); + } + } + } + /* now do other consistency checks*/ + lastBottom = last & bottomByte; + currentBottom = current & bottomByte; + lastTop = last & topByte; + currentTop = current & topByte; + + /* print out some values for spot-checking*/ + if (lastTop != currentTop || i == 0x10000 || i == 0x110000) { + showImplicit(i-3); + showImplicit(i-2); + showImplicit(i-1); + showImplicit(i); + showImplicit(i+1); + showImplicit(i+2); + } + last = current; + + if(uprv_uca_getCodePointFromRaw(uprv_uca_getRawFromCodePoint(i)) != i) { + log_err("No raw <-> code point roundtrip for 0x%08X\n", i); + } + } + showImplicit(TST_UCOL_MAX_INPUT-2); + showImplicit(TST_UCOL_MAX_INPUT-1); + showImplicit(TST_UCOL_MAX_INPUT); + ucol_close(coll); +} + +/** + * Iterate through the given iterator, checking to see that all the strings + * in the expected array are present. + * @param expected array of strings we expect to see, or NULL + * @param expectedCount number of elements of expected, or 0 + */ +static int32_t checkUEnumeration(const char* msg, + UEnumeration* iter, + const char** expected, + int32_t expectedCount) { + UErrorCode ec = U_ZERO_ERROR; + int32_t i = 0, n, j, bit; + int32_t seenMask = 0; + + U_ASSERT(expectedCount >= 0 && expectedCount < 31); /* [sic] 31 not 32 */ + n = uenum_count(iter, &ec); + if (!assertSuccess("count", &ec)) return -1; + log_verbose("%s = [", msg); + for (;; ++i) { + const char* s = uenum_next(iter, NULL, &ec); + if (!assertSuccess("snext", &ec) || s == NULL) break; + if (i != 0) log_verbose(","); + log_verbose("%s", s); + /* check expected list */ + for (j=0, bit=1; j %s (Are you missing data?)\n", u_errorName(ec)); + } +#endif + + e = ucol_getKeywords(&ec); + if (e != NULL) { + assertSuccess("ucol_getKeywords", &ec); + assertTrue("ucol_getKeywords!=0", e!=0); + n = checkUEnumeration("ucol_getKeywords", e, KW, LEN(KW)); + /* Don't need to check n because we check list */ + uenum_close(e); + } else { + log_data_err("Error calling ucol_getKeywords() -> %s (Are you missing data?)\n", u_errorName(ec)); + } + + e = ucol_getKeywordValues(KW[0], &ec); + if (e != NULL) { + assertSuccess("ucol_getKeywordValues", &ec); + assertTrue("ucol_getKeywordValues!=0", e!=0); + n = checkUEnumeration("ucol_getKeywordValues", e, KWVAL, LEN(KWVAL)); + /* Don't need to check n because we check list */ + uenum_close(e); + } else { + log_data_err("Error calling ucol_getKeywordValues() -> %s (Are you missing data?)\n", u_errorName(ec)); + } + + /* Try setting a warning before calling ucol_getKeywordValues */ + ec = U_USING_FALLBACK_WARNING; + e = ucol_getKeywordValues(KW[0], &ec); + if (assertSuccess("ucol_getKeywordValues [with warning code set]", &ec)) { + assertTrue("ucol_getKeywordValues!=0 [with warning code set]", e!=0); + n = checkUEnumeration("ucol_getKeywordValues [with warning code set]", e, KWVAL, LEN(KWVAL)); + /* Don't need to check n because we check list */ + uenum_close(e); + } + + /* +U_DRAFT int32_t U_EXPORT2 +ucol_getFunctionalEquivalent(char* result, int32_t resultCapacity, + const char* locale, UBool* isAvailable, + UErrorCode* status); +} +*/ + n = ucol_getFunctionalEquivalent(loc, sizeof(loc), "collation", "de", + &isAvailable, &ec); + if (assertSuccess("getFunctionalEquivalent", &ec)) { + assertEquals("getFunctionalEquivalent(de)", "de", loc); + assertTrue("getFunctionalEquivalent(de).isAvailable==TRUE", + isAvailable == TRUE); + } + + n = ucol_getFunctionalEquivalent(loc, sizeof(loc), "collation", "de_DE", + &isAvailable, &ec); + if (assertSuccess("getFunctionalEquivalent", &ec)) { + assertEquals("getFunctionalEquivalent(de_DE)", "de", loc); + assertTrue("getFunctionalEquivalent(de_DE).isAvailable==TRUE", + isAvailable == TRUE); + } +} + +/* supercedes TestJ784 */ +static void TestBeforePinyin(void) { + const static char rules[] = { + "&[before 2]A<<\\u0101<<<\\u0100<<\\u00E1<<<\\u00C1<<\\u01CE<<<\\u01CD<<\\u00E0<<<\\u00C0" + "&[before 2]e<<\\u0113<<<\\u0112<<\\u00E9<<<\\u00C9<<\\u011B<<<\\u011A<<\\u00E8<<<\\u00C8" + "&[before 2]i<<\\u012B<<<\\u012A<<\\u00ED<<<\\u00CD<<\\u01D0<<<\\u01CF<<\\u00EC<<<\\u00CC" + "&[before 2]o<<\\u014D<<<\\u014C<<\\u00F3<<<\\u00D3<<\\u01D2<<<\\u01D1<<\\u00F2<<<\\u00D2" + "&[before 2]u<<\\u016B<<<\\u016A<<\\u00FA<<<\\u00DA<<\\u01D4<<<\\u01D3<<\\u00F9<<<\\u00D9" + "&U<<\\u01D6<<<\\u01D5<<\\u01D8<<<\\u01D7<<\\u01DA<<<\\u01D9<<\\u01DC<<<\\u01DB<<\\u00FC" + }; + + const static char *test[] = { + "l\\u0101", + "la", + "l\\u0101n", + "lan ", + "l\\u0113", + "le", + "l\\u0113n", + "len" + }; + + const static char *test2[] = { + "x\\u0101", + "x\\u0100", + "X\\u0101", + "X\\u0100", + "x\\u00E1", + "x\\u00C1", + "X\\u00E1", + "X\\u00C1", + "x\\u01CE", + "x\\u01CD", + "X\\u01CE", + "X\\u01CD", + "x\\u00E0", + "x\\u00C0", + "X\\u00E0", + "X\\u00C0", + "xa", + "xA", + "Xa", + "XA", + "x\\u0101x", + "x\\u0100x", + "x\\u00E1x", + "x\\u00C1x", + "x\\u01CEx", + "x\\u01CDx", + "x\\u00E0x", + "x\\u00C0x", + "xax", + "xAx" + }; + + genericRulesStarter(rules, test, sizeof(test)/sizeof(test[0])); + genericLocaleStarter("zh", test, sizeof(test)/sizeof(test[0])); + genericRulesStarter(rules, test2, sizeof(test2)/sizeof(test2[0])); + genericLocaleStarter("zh", test2, sizeof(test2)/sizeof(test2[0])); +} + +static void TestBeforeTightening(void) { + static const struct { + const char *rules; + UErrorCode expectedStatus; + } tests[] = { + { "&[before 1]a %s\n", u_errorName(status)); + } else { + res = ucol_strcoll(coll, &a, 1, &null, 1); + + if(res != UCOL_LESS) { + log_err("NULL was not tailored properly!\n"); + } + } + + ucol_close(coll); +} + +static void +TestUpperFirstQuaternary(void) +{ + const char* tests[] = { "B", "b", "Bb", "bB" }; + UColAttribute att[] = { UCOL_STRENGTH, UCOL_CASE_FIRST }; + UColAttributeValue attVals[] = { UCOL_QUATERNARY, UCOL_UPPER_FIRST }; + genericLocaleStarterWithOptions("root", tests, sizeof(tests)/sizeof(tests[0]), att, attVals, sizeof(att)/sizeof(att[0])); +} + +static void +TestJ4960(void) +{ + const char* tests[] = { "\\u00e2T", "aT" }; + UColAttribute att[] = { UCOL_STRENGTH, UCOL_CASE_LEVEL }; + UColAttributeValue attVals[] = { UCOL_PRIMARY, UCOL_ON }; + const char* tests2[] = { "a", "A" }; + const char* rule = "&[first tertiary ignorable]=A=a"; + UColAttribute att2[] = { UCOL_CASE_LEVEL }; + UColAttributeValue attVals2[] = { UCOL_ON }; + /* Test whether we correctly ignore primary ignorables on case level when */ + /* we have only primary & case level */ + genericLocaleStarterWithOptionsAndResult("root", tests, sizeof(tests)/sizeof(tests[0]), att, attVals, sizeof(att)/sizeof(att[0]), UCOL_EQUAL); + /* Test whether ICU4J will make case level for sortkeys that have primary strength */ + /* and case level */ + genericLocaleStarterWithOptions("root", tests2, sizeof(tests2)/sizeof(tests2[0]), att, attVals, sizeof(att)/sizeof(att[0])); + /* Test whether completely ignorable letters have case level info (they shouldn't) */ + genericRulesStarterWithOptionsAndResult(rule, tests2, sizeof(tests2)/sizeof(tests2[0]), att2, attVals2, sizeof(att2)/sizeof(att2[0]), UCOL_EQUAL); +} + +static void +TestJ5223(void) +{ + static const char *test = "this is a test string"; + UChar ustr[256]; + int32_t ustr_length = u_unescape(test, ustr, 256); + unsigned char sortkey[256]; + int32_t sortkey_length; + UErrorCode status = U_ZERO_ERROR; + static UCollator *coll = NULL; + coll = ucol_open("root", &status); + if(U_FAILURE(status)) { + log_err_status(status, "Couldn't open UCA -> %s\n", u_errorName(status)); + return; + } + ucol_setStrength(coll, UCOL_PRIMARY); + ucol_setAttribute(coll, UCOL_STRENGTH, UCOL_PRIMARY, &status); + ucol_setAttribute(coll, UCOL_NORMALIZATION_MODE, UCOL_ON, &status); + if (U_FAILURE(status)) { + log_err("Failed setting atributes\n"); + return; + } + sortkey_length = ucol_getSortKey(coll, ustr, ustr_length, NULL, 0); + if (sortkey_length > 256) return; + + /* we mark the position where the null byte should be written in advance */ + sortkey[sortkey_length-1] = 0xAA; + + /* we set the buffer size one byte higher than needed */ + sortkey_length = ucol_getSortKey(coll, ustr, ustr_length, sortkey, + sortkey_length+1); + + /* no error occurs (for me) */ + if (sortkey[sortkey_length-1] == 0xAA) { + log_err("Hit bug at first try\n"); + } + + /* we mark the position where the null byte should be written again */ + sortkey[sortkey_length-1] = 0xAA; + + /* this time we set the buffer size to the exact amount needed */ + sortkey_length = ucol_getSortKey(coll, ustr, ustr_length, sortkey, + sortkey_length); + + /* now the trailing null byte is not written */ + if (sortkey[sortkey_length-1] == 0xAA) { + log_err("Hit bug at second try\n"); + } + + ucol_close(coll); +} + +/* Regression test for Thai partial sort key problem */ +static void +TestJ5232(void) +{ + const static char *test[] = { + "\\u0e40\\u0e01\\u0e47\\u0e1a\\u0e40\\u0e25\\u0e47\\u0e21", + "\\u0e40\\u0e01\\u0e47\\u0e1a\\u0e40\\u0e25\\u0e48\\u0e21" + }; + + genericLocaleStarter("th", test, sizeof(test)/sizeof(test[0])); +} + +static void +TestJ5367(void) +{ + const static char *test[] = { "a", "y" }; + const char* rules = "&Ny << Y &[first secondary ignorable] <<< a"; + genericRulesStarter(rules, test, sizeof(test)/sizeof(test[0])); +} + +static void +TestVI5913(void) +{ + UErrorCode status = U_ZERO_ERROR; + int32_t i, j; + UCollator *coll =NULL; + uint8_t resColl[100], expColl[100]; + int32_t rLen, tLen, ruleLen, sLen, kLen; + UChar rule[256]={0x26, 0x62, 0x3c, 0x1FF3, 0}; /* &a<0x1FF3-omega with Ypogegrammeni*/ + UChar rule2[256]={0x26, 0x7a, 0x3c, 0x0161, 0}; /* &z %s\n", u_errorName(status)); + return; + } + log_verbose("\n\nVI collation:"); + if ( !ucol_equal(coll, tData[0], u_strlen(tData[0]), tData[2], u_strlen(tData[2])) ) { + log_err("\\u1EAC not equals to \\u1EA0+\\u0302\n"); + } + if ( !ucol_equal(coll, tData[0], u_strlen(tData[0]), tData[3], u_strlen(tData[3])) ) { + log_err("\\u1EAC not equals to \\u00c2+\\u0323\n"); + } + if ( !ucol_equal(coll, tData[5], u_strlen(tData[5]), tData[4], u_strlen(tData[4])) ) { + log_err("\\u1ED8 not equals to \\u1ECC+\\u0302\n"); + } + if ( !ucol_equal(coll, tData[7], u_strlen(tData[7]), tData[6], u_strlen(tData[6])) ) { + log_err("\\u1EB7 not equals to \\u1EA1+\\u0306\n"); + } + + for (j=0; j<8; j++) { + tLen = u_strlen(tData[j]); + log_verbose("\n Data :%s \tlen: %d key: ", tData[j], tLen); + rLen = ucol_getSortKey(coll, tData[j], tLen, resColl, 100); + for(i = 0; i %s\n", u_errorName(status)); + return; + } + tLen = u_strlen(tData1[0]); + rLen = ucol_getSortKey(coll, tData1[0], tLen, resColl, 100); + if (rLen != LEN(lastPrimaryIgnCE) || uprv_memcmp(resColl, lastPrimaryIgnCE, rLen) != 0) { + log_err("Bad result for &[lpi]< %s\n", u_errorName(status)); + return; + } + tLen = u_strlen(tData2[0]); + rLen = ucol_getSortKey(coll, tData2[0], tLen, resColl, 100); + if (rLen != LEN(lastSecondaryIgnCE) || uprv_memcmp(resColl, lastSecondaryIgnCE, rLen) != 0) { + log_err("Bad result for &[lsi]<< %s\n", u_errorName(status)); + return; + } + for (j=0; j<11; j++) { + tLen = u_strlen(tData1[j]); + rLen = ucol_getSortKey(coll, tData1[j], tLen, resColl, 100); + if ((j>0) && (strcmp((char *)resColl, (char *)prevColl)<0)) { + log_err("\n Expecting greater key than previous test case: Data[%d] :%s.", + j, tData1[j]); + } + log_verbose("\n Data[%d] :%s \tlen: %d key: ", j, tData1[j], rLen); + for(i = 0; i0) && (strcmp((char *)resColl, (char *)prevColl)<0)) { + log_err("\n Expecting greater key than previous test case: Data[%d] :%s.", + j, tData1[j]); + } + log_verbose("\n Data[%d] :%s \tlen: %d key: ", j, tData1[j], rLen); + for(i = 0; i0) && (strcmp((char *)resColl, (char *)prevColl)<0)) { + log_err("\n Expecting greater key than previous test case: Data[%d] :%s.", + j, tData1[j]); + } + log_verbose("\n Data[%d] :%s \tlen: %d key: ", j, tData1[j], rLen); + for(i = 0; i0) && (j!=3) && (strcmp((char *)resColl, (char *)prevColl)<0)) { + log_err("\n Expecting greater key than previous test case: Data[%d] :%s.", + j, tData1[j]); + } + if ((j==3)&&(strcmp((char *)resColl, (char *)prevColl)>0)) { + log_err("\n Expecting smaller key than previous test case: Data[%d] :%s.", + j, tData1[j]); + } + log_verbose("\n Data[%d] :%s \tlen: %d key: ", j, tData1[j], rLen); + for(i = 0; i %s\n", u_errorName(status)); + return; + } + ucol_setStrength(coll, UCOL_PRIMARY); + ucol_setAttribute(coll, UCOL_STRENGTH, UCOL_PRIMARY, &status); + ucol_setAttribute(coll, UCOL_NORMALIZATION_MODE, UCOL_ON, &status); + if (U_FAILURE(status)) { + log_err("Failed setting atributes\n"); + return; + } + + sortkey_length = ucol_getSortKey(coll, ustr, ustr_length, shortKeyBuf, sizeof(shortKeyBuf)); + if (sortkey_length != 4) { + log_err("expecting length of sortKey is 4 got:%d ", sortkey_length); + } + log_verbose("length of sortKey is %d", sortkey_length); + ucol_close(coll); +} + +#define TSKC_DATA_SIZE 5 +#define TSKC_BUF_SIZE 50 +static void +TestSortKeyConsistency(void) +{ + UErrorCode icuRC = U_ZERO_ERROR; + UCollator* ucol; + UChar data[] = { 0xFFFD, 0x0006, 0x0006, 0x0006, 0xFFFD}; + + uint8_t bufFull[TSKC_DATA_SIZE][TSKC_BUF_SIZE]; + uint8_t bufPart[TSKC_DATA_SIZE][TSKC_BUF_SIZE]; + int32_t i, j, i2; + + ucol = ucol_openFromShortString("LEN_S4", FALSE, NULL, &icuRC); + if (U_FAILURE(icuRC)) + { + log_err_status(icuRC, "ucol_openFromShortString failed -> %s\n", u_errorName(icuRC)); + return; + } + + for (i = 0; i < TSKC_DATA_SIZE; i++) + { + UCharIterator uiter; + uint32_t state[2] = { 0, 0 }; + int32_t dataLen = i+1; + for (j=0; j %s\n", u_errorName(status)); + return; + } + + uiter_setString(&iter, text, length); + + actualSortKeyLen = ucol_nextSortKeyPart( + ucol, &iter, (uint32_t*)uStateInfo, + textSortKey, lenSortKey, &status + ); + + if (actualSortKeyLen == lenSortKey) { + log_err("ucol_nextSortKeyPart did not give correct result in Croatian test.\n"); + } + + ucol_close(ucol); +} + +/* ticket: 6140 */ +/* This test ensures that codepoints such as 0x3099 are flagged correctly by the collator since + * they are both Hiragana and Katakana + */ +#define SORTKEYLEN 50 +static void TestHiragana(void) { + UErrorCode status = U_ZERO_ERROR; + UCollator* ucol; + UCollationResult strcollresult; + UChar data1[] = { 0x3058, 0x30B8 }; /* Hiragana and Katakana letter Zi */ + UChar data2[] = { 0x3057, 0x3099, 0x30B7, 0x3099 }; + int32_t data1Len = sizeof(data1)/sizeof(*data1); + int32_t data2Len = sizeof(data2)/sizeof(*data2); + int32_t i, j; + uint8_t sortKey1[SORTKEYLEN]; + uint8_t sortKey2[SORTKEYLEN]; + + UCharIterator uiter1; + UCharIterator uiter2; + uint32_t state1[2] = { 0, 0 }; + uint32_t state2[2] = { 0, 0 }; + int32_t keySize1; + int32_t keySize2; + + ucol = ucol_openFromShortString("LJA_AN_CX_EX_FX_HO_NX_S4", FALSE, NULL, + &status); + if (U_FAILURE(status)) { + log_err_status(status, "Error status: %s; Unable to open collator from short string.\n", u_errorName(status)); + return; + } + + /* Start of full sort keys */ + /* Full sort key1 */ + keySize1 = ucol_getSortKey(ucol, data1, data1Len, sortKey1, SORTKEYLEN); + /* Full sort key2 */ + keySize2 = ucol_getSortKey(ucol, data2, data2Len, sortKey2, SORTKEYLEN); + if (keySize1 == keySize2) { + for (i = 0; i < keySize1; i++) { + if (sortKey1[i] != sortKey2[i]) { + log_err("Full sort keys are different. Should be equal."); + } + } + } else { + log_err("Full sort keys sizes doesn't match: %d %d", keySize1, keySize2); + } + /* End of full sort keys */ + + /* Start of partial sort keys */ + /* Partial sort key1 */ + uiter_setString(&uiter1, data1, data1Len); + keySize1 = ucol_nextSortKeyPart(ucol, &uiter1, state1, sortKey1, SORTKEYLEN, &status); + /* Partial sort key2 */ + uiter_setString(&uiter2, data2, data2Len); + keySize2 = ucol_nextSortKeyPart(ucol, &uiter2, state2, sortKey2, SORTKEYLEN, &status); + if (U_SUCCESS(status) && keySize1 == keySize2) { + for (j = 0; j < keySize1; j++) { + if (sortKey1[j] != sortKey2[j]) { + log_err("Partial sort keys are different. Should be equal"); + } + } + } else { + log_err("Error Status: %s or Partial sort keys sizes doesn't match: %d %d", u_errorName(status), keySize1, keySize2); + } + /* End of partial sort keys */ + + /* Start of strcoll */ + /* Use ucol_strcoll() to determine ordering */ + strcollresult = ucol_strcoll(ucol, data1, data1Len, data2, data2Len); + if (strcollresult != UCOL_EQUAL) { + log_err("Result from ucol_strcoll() should be UCOL_EQUAL."); + } + + ucol_close(ucol); +} + +/* Convenient struct for running collation tests */ +typedef struct { + const UChar source[MAX_TOKEN_LEN]; /* String on left */ + const UChar target[MAX_TOKEN_LEN]; /* String on right */ + UCollationResult result; /* -1, 0 or +1, depending on collation */ +} OneTestCase; + +/* + * Utility function to test one collation test case. + * @param testcases Array of test cases. + * @param n_testcases Size of the array testcases. + * @param str_rules Array of rules. These rules should be specifying the same rule in different formats. + * @param n_rules Size of the array str_rules. + */ +static void doTestOneTestCase(const OneTestCase testcases[], + int n_testcases, + const char* str_rules[], + int n_rules) +{ + int rule_no, testcase_no; + UChar rule[500]; + int32_t length = 0; + UErrorCode status = U_ZERO_ERROR; + UParseError parse_error; + UCollator *myCollation; + + for (rule_no = 0; rule_no < n_rules; ++rule_no) { + + length = u_unescape(str_rules[rule_no], rule, 500); + if (length == 0) { + log_err("ERROR: The rule cannot be unescaped: %s\n"); + return; + } + myCollation = ucol_openRules(rule, length, UCOL_ON, UCOL_TERTIARY, &parse_error, &status); + if(U_FAILURE(status)){ + log_err_status(status, "ERROR: in creation of rule based collator: %s\n", myErrorName(status)); + return; + } + log_verbose("Testing the <<* syntax\n"); + ucol_setAttribute(myCollation, UCOL_NORMALIZATION_MODE, UCOL_ON, &status); + ucol_setStrength(myCollation, UCOL_TERTIARY); + for (testcase_no = 0; testcase_no < n_testcases; ++testcase_no) { + doTest(myCollation, + testcases[testcase_no].source, + testcases[testcase_no].target, + testcases[testcase_no].result + ); + } + ucol_close(myCollation); + } +} + +const static OneTestCase rangeTestcases[] = { + { {0x0061}, {0x0062}, UCOL_LESS }, /* "a" < "b" */ + { {0x0062}, {0x0063}, UCOL_LESS }, /* "b" < "c" */ + { {0x0061}, {0x0063}, UCOL_LESS }, /* "a" < "c" */ + + { {0x0062}, {0x006b}, UCOL_LESS }, /* "b" << "k" */ + { {0x006b}, {0x006c}, UCOL_LESS }, /* "k" << "l" */ + { {0x0062}, {0x006c}, UCOL_LESS }, /* "b" << "l" */ + { {0x0061}, {0x006c}, UCOL_LESS }, /* "a" < "l" */ + { {0x0061}, {0x006d}, UCOL_LESS }, /* "a" < "m" */ + + { {0x0079}, {0x006d}, UCOL_LESS }, /* "y" < "f" */ + { {0x0079}, {0x0067}, UCOL_LESS }, /* "y" < "g" */ + { {0x0061}, {0x0068}, UCOL_LESS }, /* "y" < "h" */ + { {0x0061}, {0x0065}, UCOL_LESS }, /* "g" < "e" */ + + { {0x0061}, {0x0031}, UCOL_EQUAL }, /* "a" = "1" */ + { {0x0061}, {0x0032}, UCOL_EQUAL }, /* "a" = "2" */ + { {0x0061}, {0x0033}, UCOL_EQUAL }, /* "a" = "3" */ + { {0x0061}, {0x0066}, UCOL_LESS }, /* "a" < "f" */ + { {0x006c, 0x0061}, {0x006b, 0x0062}, UCOL_LESS }, /* "la" < "123" */ + { {0x0061, 0x0061, 0x0061}, {0x0031, 0x0032, 0x0033}, UCOL_EQUAL }, /* "aaa" = "123" */ + { {0x0062}, {0x007a}, UCOL_LESS }, /* "b" < "z" */ + { {0x0061, 0x007a, 0x0062}, {0x0032, 0x0079, 0x006d}, UCOL_LESS }, /* "azm" = "2yc" */ +}; + +static int nRangeTestcases = LEN(rangeTestcases); + +const static OneTestCase rangeTestcasesSupplemental[] = { + { {0xfffe}, {0xffff}, UCOL_LESS }, /* U+FFFE < U+FFFF */ + { {0xffff}, {0xd800, 0xdc00}, UCOL_LESS }, /* U+FFFF < U+10000 */ + { {0xd800, 0xdc00}, {0xd800, 0xdc01}, UCOL_LESS }, /* U+10000 < U+10001 */ + { {0xfffe}, {0xd800, 0xdc01}, UCOL_LESS }, /* U+FFFE < U+10001 */ + { {0xd800, 0xdc01}, {0xd800, 0xdc02}, UCOL_LESS }, /* U+10000 < U+10001 */ + { {0xd800, 0xdc01}, {0xd800, 0xdc02}, UCOL_LESS }, /* U+10000 < U+10001 */ + { {0xfffe}, {0xd800, 0xdc02}, UCOL_LESS }, /* U+FFFE < U+10001 */ +}; + +static int nRangeTestcasesSupplemental = LEN(rangeTestcasesSupplemental); + +const static OneTestCase rangeTestcasesQwerty[] = { + { {0x0071}, {0x0077}, UCOL_LESS }, /* "q" < "w" */ + { {0x0077}, {0x0065}, UCOL_LESS }, /* "w" < "e" */ + + { {0x0079}, {0x0075}, UCOL_LESS }, /* "y" < "u" */ + { {0x0071}, {0x0075}, UCOL_LESS }, /* "q" << "u" */ + + { {0x0074}, {0x0069}, UCOL_LESS }, /* "t" << "i" */ + { {0x006f}, {0x0070}, UCOL_LESS }, /* "o" << "p" */ + + { {0x0079}, {0x0065}, UCOL_LESS }, /* "y" < "e" */ + { {0x0069}, {0x0075}, UCOL_LESS }, /* "i" < "u" */ + + { {0x0071, 0x0075, 0x0065, 0x0073, 0x0074}, + {0x0077, 0x0065, 0x0072, 0x0065}, UCOL_LESS }, /* "quest" < "were" */ + { {0x0071, 0x0075, 0x0061, 0x0063, 0x006b}, + {0x0071, 0x0075, 0x0065, 0x0073, 0x0074}, UCOL_LESS }, /* "quack" < "quest" */ +}; + +static int nRangeTestcasesQwerty = LEN(rangeTestcasesQwerty); + +static void TestSameStrengthList(void) +{ + const char* strRules[] = { + /* Normal */ + "&a 128 collation elements */ + 0x42,0xC1,0x43,0xC9,0x44,0xCD,0x46,0xD3,0x47,0xDA,0x48,0xC0,0x4A,0xC8,0x4B,0xCC,0x4C,0xD2,0x4D,0xD9,0x4E,0xC2,0x50,0xCA,0x20, + 0x42,0xC1,0x43,0xC9,0x44,0xCD,0x46,0xD3,0x47,0xDA,0x48,0xC0,0x4A,0xC8,0x4B,0xCC,0x4C,0xD2,0x4D,0xD9,0x4E,0xC2,0x50,0xCA,0x20, + 0x42,0xC1,0x43,0xC9,0x44,0xCD,0x46,0xD3,0x47,0xDA,0x48,0xC0,0x4A,0xC8,0x4B,0xCC,0x4C,0xD2,0x4D,0xD9,0x4E,0xC2,0x50,0xCA,0x20, + 0x42,0xC1,0x43,0xC9,0x44,0xCD,0x46,0xD3,0x47,0xDA,0x48,0xC0,0x4A,0xC8,0x4B,0xCC,0x4C,0xD2,0x4D,0xD9,0x4E,0xC2,0x50,0xCA,0x20, + 0x42,0xC1,0x43,0xC9,0x44,0xCD,0x46,0xD3,0x47,0xDA,0x48,0xC0,0x4A,0xC8,0x4B,0xCC,0x4C,0xD2,0x4D,0xD9,0x4E,0xC2,0x50,0xCA,0x20 +}; + +/* 'ABCDEFGHIJKLMNOPQRSTUVWXYZ ' repeated 12 times */ +static const UChar longUpperStr3[]= { /* 324 chars */ + 0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x20, + 0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x20, + 0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x20, + 0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x20, + 0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x20, + 0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x20, + 0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x20, + 0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x20, + 0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x20, + 0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x20, + 0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x20, + 0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x20 +}; + +#define MY_ARRAY_LEN(array) (sizeof(array)/sizeof(array[0])) + +typedef struct { + const UChar * longUpperStrPtr; + int32_t longUpperStrLen; +} LongUpperStrItem; + +/* String pointers must be in reverse collation order of the corresponding strings */ +static const LongUpperStrItem longUpperStrItems[] = { + { longUpperStr1, MY_ARRAY_LEN(longUpperStr1) }, + { longUpperStr2, MY_ARRAY_LEN(longUpperStr2) }, + { longUpperStr3, MY_ARRAY_LEN(longUpperStr3) }, + { NULL, 0 } +}; + +enum { kCollKeyLenMax = 800 }; /* longest expected is 749, but may change with collation changes */ + +/* Text fix for #8445; without fix, could have crash due to stack or heap corruption */ +static void TestCaseLevelBufferOverflow(void) +{ + UErrorCode status = U_ZERO_ERROR; + UCollator * ucol = ucol_open("root", &status); + if ( U_SUCCESS(status) ) { + ucol_setAttribute(ucol, UCOL_CASE_LEVEL, UCOL_ON, &status); + if ( U_SUCCESS(status) ) { + const LongUpperStrItem * itemPtr; + uint8_t sortKeyA[kCollKeyLenMax], sortKeyB[kCollKeyLenMax]; + for ( itemPtr = longUpperStrItems; itemPtr->longUpperStrPtr != NULL; itemPtr++ ) { + int32_t sortKeyLen; + if (itemPtr > longUpperStrItems) { + uprv_strcpy((char *)sortKeyB, (char *)sortKeyA); + } + sortKeyLen = ucol_getSortKey(ucol, itemPtr->longUpperStrPtr, itemPtr->longUpperStrLen, sortKeyA, kCollKeyLenMax); + if (sortKeyLen <= 0 || sortKeyLen > kCollKeyLenMax) { + log_err("ERROR sort key length from ucol_getSortKey is %d\n", sortKeyLen); + break; + } + if ( itemPtr > longUpperStrItems ) { + int compareResult = uprv_strcmp((char *)sortKeyA, (char *)sortKeyB); + if (compareResult >= 0) { + log_err("ERROR in sort key comparison result, expected -1, got %d\n", compareResult); + } + } + } + } else { + log_err_status(status, "ERROR in ucol_setAttribute UCOL_CASE_LEVEL on: %s\n", myErrorName(status)); + } + ucol_close(ucol); + } else { + log_err_status(status, "ERROR in ucol_open for root: %s\n", myErrorName(status)); + } } @@ -4234,48 +7068,47 @@ static void TestJ2726(void) { void addMiscCollTest(TestNode** root) { - addTest(root, &TestNumericCollation, "tscoll/cmsccoll/TestNumericCollation"); - addTest(root, &TestRuleOptions, "tscoll/cmsccoll/TestRuleOptions"); - addTest(root, &TestBeforePrefixFailure, "tscoll/cmsccoll/TestBeforePrefixFailure"); - addTest(root, &TestContractionClosure, "tscoll/cmsccoll/TestContractionClosure"); - addTest(root, &TestPrefixCompose, "tscoll/cmsccoll/TestPrefixCompose"); - addTest(root, &TestStrCollIdenticalPrefix, "tscoll/cmsccoll/TestStrCollIdenticalPrefix"); - addTest(root, &TestPrefix, "tscoll/cmsccoll/TestPrefix"); - addTest(root, &TestNewJapanese, "tscoll/cmsccoll/TestNewJapanese"); - /*addTest(root, &TestLimitations, "tscoll/cmsccoll/TestLimitations");*/ - addTest(root, &TestNonChars, "tscoll/cmsccoll/TestNonChars"); - addTest(root, &TestExtremeCompression, "tscoll/cmsccoll/TestExtremeCompression"); - addTest(root, &TestSurrogates, "tscoll/cmsccoll/TestSurrogates"); - addTest(root, &TestVariableTopSetting, "tscoll/cmsccoll/TestVariableTopSetting"); - addTest(root, &TestBocsuCoverage, "tscoll/cmsccoll/TestBocsuCoverage"); - addTest(root, &TestCyrillicTailoring, "tscoll/cmsccoll/TestCyrillicTailoring"); - addTest(root, &TestCase, "tscoll/cmsccoll/TestCase"); - addTest(root, &IncompleteCntTest, "tscoll/cmsccoll/IncompleteCntTest"); - addTest(root, &BlackBirdTest, "tscoll/cmsccoll/BlackBirdTest"); - addTest(root, &FunkyATest, "tscoll/cmsccoll/FunkyATest"); - addTest(root, &BillFairmanTest, "tscoll/cmsccoll/BillFairmanTest"); - addTest(root, &RamsRulesTest, "tscoll/cmsccoll/RamsRulesTest"); - addTest(root, &IsTailoredTest, "tscoll/cmsccoll/IsTailoredTest"); - addTest(root, &TestCollations, "tscoll/cmsccoll/TestCollations"); - addTest(root, &TestChMove, "tscoll/cmsccoll/TestChMove"); - addTest(root, &TestImplicitTailoring, "tscoll/cmsccoll/TestImplicitTailoring"); - addTest(root, &TestFCDProblem, "tscoll/cmsccoll/TestFCDProblem"); - addTest(root, &TestEmptyRule, "tscoll/cmsccoll/TestEmptyRule"); - addTest(root, &TestJ784, "tscoll/cmsccoll/TestJ784"); - addTest(root, &TestJ815, "tscoll/cmsccoll/TestJ815"); - addTest(root, &TestJ831, "tscoll/cmsccoll/TestJ831"); - addTest(root, &TestBefore, "tscoll/cmsccoll/TestBefore"); - addTest(root, &TestRedundantRules, "tscoll/cmsccoll/TestRedundantRules"); - addTest(root, &TestExpansionSyntax, "tscoll/cmsccoll/TestExpansionSyntax"); - addTest(root, &TestHangulTailoring, "tscoll/cmsccoll/TestHangulTailoring"); - addTest(root, &TestUCARules, "tscoll/cmsccoll/TestUCARules"); - addTest(root, &TestIncrementalNormalize, "tscoll/cmsccoll/TestIncrementalNormalize"); - addTest(root, &TestComposeDecompose, "tscoll/cmsccoll/TestComposeDecompose"); - addTest(root, &TestCompressOverlap, "tscoll/cmsccoll/TestCompressOverlap"); - addTest(root, &TestContraction, "tscoll/cmsccoll/TestContraction"); - addTest(root, &TestExpansion, "tscoll/cmsccoll/TestExpansion"); - /*addTest(root, &PrintMarkDavis, "tscoll/cmsccoll/PrintMarkDavis");*/ /* this test doesn't test - just prints sortkeys */ - /*addTest(root, &TestGetCaseBit, "tscoll/cmsccoll/TestGetCaseBit");*/ /*this one requires internal things to be exported */ + TEST(TestRuleOptions); + TEST(TestBeforePrefixFailure); + TEST(TestContractionClosure); + TEST(TestPrefixCompose); + TEST(TestStrCollIdenticalPrefix); + TEST(TestPrefix); + TEST(TestNewJapanese); + /*TEST(TestLimitations);*/ + TEST(TestNonChars); + TEST(TestExtremeCompression); + TEST(TestSurrogates); + TEST(TestVariableTopSetting); + TEST(TestBocsuCoverage); + TEST(TestCyrillicTailoring); + TEST(TestCase); + TEST(IncompleteCntTest); + TEST(BlackBirdTest); + TEST(FunkyATest); + TEST(BillFairmanTest); + TEST(RamsRulesTest); + TEST(IsTailoredTest); + TEST(TestCollations); + TEST(TestChMove); + TEST(TestImplicitTailoring); + TEST(TestFCDProblem); + TEST(TestEmptyRule); + /*TEST(TestJ784);*/ /* 'zh' locale has changed - now it is getting tested by TestBeforePinyin */ + TEST(TestJ815); + /*TEST(TestJ831);*/ /* we changed lv locale */ + TEST(TestBefore); + TEST(TestRedundantRules); + TEST(TestExpansionSyntax); + TEST(TestHangulTailoring); + TEST(TestUCARules); + TEST(TestIncrementalNormalize); + TEST(TestComposeDecompose); + TEST(TestCompressOverlap); + TEST(TestContraction); + TEST(TestExpansion); + /*TEST(PrintMarkDavis);*/ /* this test doesn't test - just prints sortkeys */ + /*TEST(TestGetCaseBit);*/ /*this one requires internal things to be exported */ TEST(TestOptimize); TEST(TestSuppressContractions); TEST(Alexis2); @@ -4284,6 +7117,62 @@ void addMiscCollTest(TestNode** root) TEST(TestSettings); TEST(TestEquals); TEST(TestJ2726); + TEST(NullRule); + TEST(TestNumericCollation); + TEST(TestTibetanConformance); + TEST(TestPinyinProblem); + TEST(TestImplicitGeneration); + TEST(TestSeparateTrees); + TEST(TestBeforePinyin); + TEST(TestBeforeTightening); + /*TEST(TestMoreBefore);*/ + TEST(TestTailorNULL); + TEST(TestUpperFirstQuaternary); + TEST(TestJ4960); + TEST(TestJ5223); + TEST(TestJ5232); + TEST(TestJ5367); + TEST(TestHiragana); + TEST(TestSortKeyConsistency); + TEST(TestVI5913); /* VI, RO tailored rules */ + TEST(TestCroatianSortKey); + TEST(TestTailor6179); + TEST(TestUCAPrecontext); + TEST(TestOutOfBuffer5468); + TEST(TestSameStrengthList); + + TEST(TestSameStrengthListQuoted); + TEST(TestSameStrengthListSupplemental); + TEST(TestSameStrengthListQwerty); + TEST(TestSameStrengthListQuotedQwerty); + TEST(TestSameStrengthListRanges); + TEST(TestSameStrengthListSupplementalRanges); + TEST(TestSpecialCharacters); + TEST(TestPrivateUseCharacters); + TEST(TestPrivateUseCharactersInList); + TEST(TestPrivateUseCharactersInRange); + TEST(TestInvalidListsAndRanges); + TEST(TestImportRulesDeWithPhonebook); + /* TEST(TestImportRulesFiWithEor); EOR rules removed from CLDR 21 */ + /* TEST(TestImportRulesCJKWithUnihan); */ + TEST(TestImport); + TEST(TestImportWithType); + + TEST(TestBeforeRuleWithScriptReordering); + TEST(TestNonLeadBytesDuringCollationReordering); + TEST(TestReorderingAPI); + TEST(TestReorderingAPIWithRuleCreatedCollator); + TEST(TestEquivalentReorderingScripts); + TEST(TestGreekFirstReorder); + TEST(TestGreekLastReorder); + TEST(TestNonScriptReorder); + TEST(TestHaniReorder); + TEST(TestHaniReorderWithOtherRules); + TEST(TestMultipleReorder); + TEST(TestReorderingAcrossCloning); + TEST(TestReorderWithNumericCollation); + + TEST(TestCaseLevelBufferOverflow); } #endif /* #if !UCONFIG_NO_COLLATION */