capitst.c revision 85bf2e2fbc60a9f938064abc8127d61da7d19882
1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/******************************************************************** 285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * Copyright (c) 1997-2009 International Business Machines 385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * Corporation and others. All Rights Reserved. 4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ********************************************************************/ 585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho/***************************************************************************** 6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* 7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* File CAPITEST.C 8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* 9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* Modification History: 1085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho* Name Description 11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* Madhu Katragadda Ported for C API 1285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho* Brian Rower Added TestOpenVsOpenRules 1385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho****************************************************************************** 14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*//* C API TEST For COLLATOR */ 15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h" 17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_COLLATION 19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <stdio.h> 21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <stdlib.h> 22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <string.h> 23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/uloc.h" 2485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho#include "unicode/ulocdata.h" 25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/ustring.h" 26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/ures.h" 27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/ucoleitr.h" 28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cintltst.h" 29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "capitst.h" 30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "ccolltst.h" 31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "putilimp.h" 3285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho#include "cstring.h" 33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestAttribute(void); 35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestDefault(void); 3685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic void TestDefaultKeyword(void); 37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int TestBufferSize(); /* defined in "colutil.c" */ 38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 4085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* next two function is modified from "i18n/ucol.cpp" to avoid include "ucol_imp.h" */ 43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void uprv_appendByteToHexString(char *dst, uint8_t val) { 44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t len = (uint32_t)strlen(dst); 45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sprintf(dst+len, "%02X", val); 46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic char* U_EXPORT2 ucol_sortKeyToString(const UCollator *coll, const uint8_t *sortkey, char *buffer, uint32_t *len) { 49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t strength = UCOL_PRIMARY; 50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t res_size = 0; 51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UBool doneCase = FALSE; 52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char *current = buffer; 54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const uint8_t *currentSk = sortkey; 55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode error_code = U_ZERO_ERROR; 57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(current, "["); 59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru while(strength <= UCOL_QUATERNARY && strength <= ucol_getAttribute(coll,UCOL_STRENGTH, &error_code)) { 61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(error_code)) { 62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ucol_getAttribute returned error: %s\n", u_errorName(error_code)); 63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strength > UCOL_PRIMARY) { 65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcat(current, " . "); 66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru while(*currentSk != 0x01 && *currentSk != 0x00) { /* print a level */ 68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uprv_appendByteToHexString(current, *currentSk++); 69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcat(current, " "); 70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(ucol_getAttribute(coll,UCOL_CASE_LEVEL, &error_code) == UCOL_ON && strength == UCOL_SECONDARY && doneCase == FALSE) { 72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doneCase = TRUE; 73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else if(ucol_getAttribute(coll,UCOL_CASE_LEVEL, &error_code) == UCOL_OFF || doneCase == TRUE || strength != UCOL_SECONDARY) { 74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strength ++; 75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(error_code)) { 77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ucol_getAttribute returned error: %s\n", u_errorName(error_code)); 78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uprv_appendByteToHexString(current, *currentSk++); /* This should print '01' */ 80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strength == UCOL_QUATERNARY && ucol_getAttribute(coll,UCOL_ALTERNATE_HANDLING, &error_code) == UCOL_NON_IGNORABLE) { 81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru break; 82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(ucol_getAttribute(coll,UCOL_STRENGTH, &error_code) == UCOL_IDENTICAL) { 86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcat(current, " . "); 87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru while(*currentSk != 0) { 88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uprv_appendByteToHexString(current, *currentSk++); 89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcat(current, " "); 90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uprv_appendByteToHexString(current, *currentSk++); 93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(error_code)) { 95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ucol_getAttribute returned error: %s\n", u_errorName(error_code)); 96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcat(current, "]"); 98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(res_size > *len) { 100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return NULL; 101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return buffer; 104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* end of avoid include "ucol_imp.h" */ 106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid addCollAPITest(TestNode** root) 109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* WEIVTODO: return tests here */ 111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestProperty, "tscoll/capitst/TestProperty"); 112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestRuleBasedColl, "tscoll/capitst/TestRuleBasedColl"); 113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestCompare, "tscoll/capitst/TestCompare"); 114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestSortKey, "tscoll/capitst/TestSortKey"); 115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestHashCode, "tscoll/capitst/TestHashCode"); 116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestElemIter, "tscoll/capitst/TestElemIter"); 117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestGetAll, "tscoll/capitst/TestGetAll"); 118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*addTest(root, &TestGetDefaultRules, "tscoll/capitst/TestGetDefaultRules");*/ 119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestDecomposition, "tscoll/capitst/TestDecomposition"); 120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestSafeClone, "tscoll/capitst/TestSafeClone"); 121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestCloneBinary, "tscoll/capitst/TestCloneBinary"); 122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestGetSetAttr, "tscoll/capitst/TestGetSetAttr"); 123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestBounds, "tscoll/capitst/TestBounds"); 124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestGetLocale, "tscoll/capitst/TestGetLocale"); 125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestSortKeyBufferOverrun, "tscoll/capitst/TestSortKeyBufferOverrun"); 126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestAttribute, "tscoll/capitst/TestAttribute"); 127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestGetTailoredSet, "tscoll/capitst/TestGetTailoredSet"); 128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestMergeSortKeys, "tscoll/capitst/TestMergeSortKeys"); 129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestShortString, "tscoll/capitst/TestShortString"); 130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestGetContractionsAndUnsafes, "tscoll/capitst/TestGetContractionsAndUnsafes"); 131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestOpenBinary, "tscoll/capitst/TestOpenBinary"); 132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestDefault, "tscoll/capitst/TestDefault"); 13385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho addTest(root, &TestDefaultKeyword, "tscoll/capitst/TestDefaultKeyword"); 13485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho addTest(root, &TestOpenVsOpenRules, "tscoll/capitst/TestOpenVsOpenRules"); 13585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho addTest(root, &TestGetKeywordValuesForLocale, "tscoll/capitst/TestGetKeywordValuesForLocale"); 136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestGetSetAttr(void) { 139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *coll = ucol_open(NULL, &status); 141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru struct attrTest { 142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UColAttribute att; 143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UColAttributeValue val[5]; 144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t valueSize; 145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UColAttributeValue nonValue; 146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } attrs[] = { 147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {UCOL_FRENCH_COLLATION, {UCOL_ON, UCOL_OFF}, 2, UCOL_SHIFTED}, 148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {UCOL_ALTERNATE_HANDLING, {UCOL_NON_IGNORABLE, UCOL_SHIFTED}, 2, UCOL_OFF},/* attribute for handling variable elements*/ 149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {UCOL_CASE_FIRST, {UCOL_OFF, UCOL_LOWER_FIRST, UCOL_UPPER_FIRST}, 3, UCOL_SHIFTED},/* who goes first, lower case or uppercase */ 150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {UCOL_CASE_LEVEL, {UCOL_ON, UCOL_OFF}, 2, UCOL_SHIFTED},/* do we have an extra case level */ 151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {UCOL_NORMALIZATION_MODE, {UCOL_ON, UCOL_OFF}, 2, UCOL_SHIFTED},/* attribute for normalization */ 152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {UCOL_DECOMPOSITION_MODE, {UCOL_ON, UCOL_OFF}, 2, UCOL_SHIFTED}, 153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {UCOL_STRENGTH, {UCOL_PRIMARY, UCOL_SECONDARY, UCOL_TERTIARY, UCOL_QUATERNARY, UCOL_IDENTICAL}, 5, UCOL_SHIFTED},/* attribute for strength */ 154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {UCOL_HIRAGANA_QUATERNARY_MODE, {UCOL_ON, UCOL_OFF}, 2, UCOL_SHIFTED},/* when turned on, this attribute */ 155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }; 156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UColAttribute currAttr; 15785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UColAttributeValue value; 158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t i = 0, j = 0; 159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 16085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if (coll == NULL) { 16185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "Unable to open collator. %s\n", u_errorName(status)); 16285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho return; 16385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i = 0; i<sizeof(attrs)/sizeof(attrs[0]); i++) { 165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru currAttr = attrs[i].att; 166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, currAttr, UCOL_DEFAULT, &status); 167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 16885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "ucol_setAttribute with the default value returned error: %s\n", u_errorName(status)); 169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru break; 170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru value = ucol_getAttribute(coll, currAttr, &status); 172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ucol_getAttribute returned error: %s\n", u_errorName(status)); 174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru break; 175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(j = 0; j<attrs[i].valueSize; j++) { 177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, currAttr, attrs[i].val[j], &status); 178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ucol_setAttribute with the value %i returned error: %s\n", attrs[i].val[j], u_errorName(status)); 180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru break; 181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, currAttr, attrs[i].nonValue, &status); 185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)) { 186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ucol_setAttribute with the bad value didn't return an error\n"); 187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru break; 188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, currAttr, value, &status); 192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ucol_setAttribute with the default valuereturned error: %s\n", u_errorName(status)); 194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru break; 195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 197ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru value = ucol_getAttribute(coll, UCOL_ATTRIBUTE_COUNT, &status); 199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)) { 200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ucol_getAttribute for UCOL_ATTRIBUTE_COUNT didn't return an error\n"); 201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_ATTRIBUTE_COUNT, UCOL_DEFAULT, &status); 204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)) { 205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ucol_setAttribute for UCOL_ATTRIBUTE_COUNT didn't return an error\n"); 206ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(coll); 209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 212ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void doAssert(int condition, const char *message) 213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 214ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (condition==0) { 215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR : %s\n", message); 216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if 0 220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* We don't have default rules, at least not in the previous sense */ 221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestGetDefaultRules(){ 222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t size=0; 223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status=U_ZERO_ERROR; 224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *coll=NULL; 225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t len1 = 0, len2=0; 226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t *binColData = NULL; 227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *res = NULL; 229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *binColl = NULL; 230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t *binResult = NULL; 23185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 23285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UChar * defaultRulesArray=ucol_getDefaultRulesArray(&size); 234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Test the function ucol_getDefaultRulesArray()\n"); 235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru coll = ucol_openRules(defaultRulesArray, size, UCOL_ON, UCOL_PRIMARY, &status); 237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status) && coll !=NULL) { 238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru binColData = (uint8_t*)ucol_cloneRuleData(coll, &len1, &status); 23985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 24285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru res=ures_open(NULL, "root", &status); 245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)){ 246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: Failed to get resource for \"root Locale\" with %s", myErrorName(status)); 247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 24985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho binColl=ures_getByKey(res, "%%Collation", binColl, &status); 250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)){ 251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru binResult=(uint8_t*)ures_getBinary(binColl, &len2, &status); 252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)){ 253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_getBinary() failed\n"); 254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_getByKey(locale(default), %%Collation) failed"); 257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(len1 != len2){ 261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Error: ucol_getDefaultRulesArray() failed to return the correct length.\n"); 262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(memcmp(binColData, binResult, len1) != 0){ 264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Error: ucol_getDefaultRulesArray() failed\n"); 265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(binColData); 268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(binColl); 269ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(res); 270ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(coll); 27185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 274ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* Collator Properties 276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_open, ucol_strcoll, getStrength/setStrength 277ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru getDecomposition/setDecomposition, getDisplayName*/ 278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestProperty() 27985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho{ 280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *col, *ruled; 281ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar *disName; 282ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t len = 0, i = 0; 283ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar *source, *target; 284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t tempLength; 285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 28685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* 287ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru All the collations have the same version in an ICU 288ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru version. 289ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ICU 2.0 currVersionArray = {0x18, 0xC0, 0x02, 0x02}; 290ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ICU 2.1 currVersionArray = {0x19, 0x00, 0x03, 0x03}; 291ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ICU 2.2 currVersionArray = {0x21, 0x40, 0x04, 0x04}; 292ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ICU 2.4 currVersionArray = {0x21, 0x40, 0x04, 0x04}; 293ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ICU 2.6 currVersionArray = {0x21, 0x40, 0x03, 0x03}; 294ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ICU 2.8 currVersionArray = {0x29, 0x80, 0x00, 0x04}; 295ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ICU 3.4 currVersionArray = {0x31, 0xC0, 0x00, 0x04}; 296ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 29785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UVersionInfo currVersionArray = {0x31, 0xC0, 0x00, 0x29}; 298ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* ICU 3.4 had UCA 4.1 */ 299ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*UVersionInfo currUCAVersionArray = {4, 1, 0, 0};*/ 30085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UVersionInfo currUCAVersionArray = {5, 1, 0, 0}; 301ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UVersionInfo versionArray = {0, 0, 0, 0}; 302ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UVersionInfo versionUCAArray = {0, 0, 0, 0}; 30385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 304ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("The property tests begin : \n"); 305ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Test ucol_strcoll : \n"); 306ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru col = ucol_open("en_US", &status); 307ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 30885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "Default Collator creation failed.: %s\n", myErrorName(status)); 309ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 310ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 311ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 312ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_getVersion(col, versionArray); 313ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (i=0; i<4; ++i) { 314ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (versionArray[i] != currVersionArray[i]) { 31585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("Testing ucol_getVersion() - unexpected result: %hu.%hu.%hu.%hu\n", 316ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru versionArray[0], versionArray[1], versionArray[2], versionArray[3]); 317ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru break; 318ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 319ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 320ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 321ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_getUCAVersion(col, versionUCAArray); 322ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (i=0; i<4; ++i) { 323ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (versionUCAArray[i] != currUCAVersionArray[i]) { 32485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("Testing ucol_getUCAVersion() - unexpected result: %hu.%hu.%hu.%hu\n", 325ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru versionUCAArray[0], versionUCAArray[1], versionUCAArray[2], versionUCAArray[3]); 326ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru break; 327ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 328ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 329ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 330ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru source=(UChar*)malloc(sizeof(UChar) * 12); 331ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru target=(UChar*)malloc(sizeof(UChar) * 12); 33285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 333ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 334ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(source, "ab"); 335ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(target, "abc"); 33685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 337ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert((ucol_strcoll(col, source, u_strlen(source), target, u_strlen(target)) == UCOL_LESS), "ab < abc comparison failed"); 338ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 339ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(source, "ab"); 340ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(target, "AB"); 341ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 342ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert((ucol_strcoll(col, source, u_strlen(source), target, u_strlen(target)) == UCOL_LESS), "ab < AB comparison failed"); 343ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* u_uastrcpy(source, "black-bird"); 344ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(target, "blackbird"); */ 345ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(target, "black-bird"); 346ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(source, "blackbird"); 347ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 34885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho doAssert((ucol_strcoll(col, source, u_strlen(source), target, u_strlen(target)) == UCOL_GREATER), 349ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "black-bird > blackbird comparison failed"); 350ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(source, "black bird"); 351ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(target, "black-bird"); 35285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho doAssert((ucol_strcoll(col, source, u_strlen(source), target, u_strlen(target)) == UCOL_LESS), 353ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "black bird < black-bird comparison failed"); 354ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(source, "Hello"); 355ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(target, "hello"); 356ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 35785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho doAssert((ucol_strcoll(col, source, u_strlen(source), target, u_strlen(target)) == UCOL_GREATER), 358ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "Hello > hello comparison failed"); 359ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(source); 360ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(target); 361ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Test ucol_strcoll ends.\n"); 362ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 363ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("testing ucol_getStrength() method ...\n"); 364ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (ucol_getStrength(col) == UCOL_TERTIARY), "collation object has the wrong strength"); 365ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (ucol_getStrength(col) != UCOL_PRIMARY), "collation object's strength is primary difference"); 36685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 367ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("testing ucol_setStrength() method ...\n"); 368ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setStrength(col, UCOL_SECONDARY); 369ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (ucol_getStrength(col) != UCOL_TERTIARY), "collation object's strength is secondary difference"); 370ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (ucol_getStrength(col) != UCOL_PRIMARY), "collation object's strength is primary difference"); 371ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (ucol_getStrength(col) == UCOL_SECONDARY), "collation object has the wrong strength"); 372ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 37385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 374ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Get display name for the default collation in German : \n"); 375ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 376ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru len=ucol_getDisplayName("en_US", "de_DE", NULL, 0, &status); 377ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status==U_BUFFER_OVERFLOW_ERROR){ 378ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 379ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru disName=(UChar*)malloc(sizeof(UChar) * (len+1)); 380ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_getDisplayName("en_US", "de_DE", disName, len+1, &status); 381ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("the display name for default collation in german: %s\n", austrdup(disName) ); 382ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(disName); 383ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 384ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)){ 385ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: in getDisplayName: %s\n", myErrorName(status)); 386ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 387ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 388ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Default collation getDisplayName ended.\n"); 389ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 390ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ruled = ucol_open("da_DK", &status); 391ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("ucol_getRules() testing ...\n"); 392ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_getRules(ruled, &tempLength); 393ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( tempLength != 0, "getRules() result incorrect" ); 394ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("getRules tests end.\n"); 395ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 396ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar *buffer = (UChar *)malloc(200000*sizeof(UChar)); 397ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t bufLen = 200000; 398ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru buffer[0] = '\0'; 399ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("ucol_getRulesEx() testing ...\n"); 400ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tempLength = ucol_getRulesEx(col,UCOL_TAILORING_ONLY,buffer,bufLen ); 401ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( tempLength == 0x0a, "getRulesEx() result incorrect" ); 402ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("getRules tests end.\n"); 40385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 404ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("ucol_getRulesEx() testing ...\n"); 405ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tempLength=ucol_getRulesEx(col,UCOL_FULL_RULES,buffer,bufLen ); 406ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( tempLength != 0, "getRulesEx() result incorrect" ); 407ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("getRules tests end.\n"); 408ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(buffer); 409ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 410ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(ruled); 411ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(col); 41285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 413ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("open an collator for french locale"); 414ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru col = ucol_open("fr_FR", &status); 415ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 416ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: Creating French collation failed.: %s\n", myErrorName(status)); 417ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 418ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 419ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setStrength(col, UCOL_PRIMARY); 420ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("testing ucol_getStrength() method again ...\n"); 421ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (ucol_getStrength(col) != UCOL_TERTIARY), "collation object has the wrong strength"); 422ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (ucol_getStrength(col) == UCOL_PRIMARY), "collation object's strength is not primary difference"); 42385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 424ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("testing French ucol_setStrength() method ...\n"); 425ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setStrength(col, UCOL_TERTIARY); 426ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (ucol_getStrength(col) == UCOL_TERTIARY), "collation object's strength is not tertiary difference"); 427ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (ucol_getStrength(col) != UCOL_PRIMARY), "collation object's strength is primary difference"); 428ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (ucol_getStrength(col) != UCOL_SECONDARY), "collation object's strength is secondary difference"); 429ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(col); 43085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 431ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Get display name for the french collation in english : \n"); 432ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru len=ucol_getDisplayName("fr_FR", "en_US", NULL, 0, &status); 433ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status==U_BUFFER_OVERFLOW_ERROR){ 434ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 435ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru disName=(UChar*)malloc(sizeof(UChar) * (len+1)); 436ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_getDisplayName("fr_FR", "en_US", disName, len+1, &status); 437ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("the display name for french collation in english: %s\n", austrdup(disName) ); 438ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(disName); 439ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 440ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)){ 441ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: in getDisplayName: %s\n", myErrorName(status)); 442ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 443ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 444ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Default collation getDisplayName ended.\n"); 445ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 446ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 447ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 448ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* Test RuleBasedCollator and getRules*/ 449ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestRuleBasedColl() 450ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 451ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *col1, *col2, *col3, *col4; 452ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollationElements *iter1, *iter2; 453ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar ruleset1[60]; 454ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar ruleset2[50]; 455ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar teststr[10]; 456ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar teststr2[10]; 457ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UChar *rule1, *rule2, *rule3, *rule4; 458ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t tempLength; 459ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 460ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(ruleset1, "&9 < a, A < b, B < c, C; ch, cH, Ch, CH < d, D, e, E"); 461ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(ruleset2, "&9 < a, A < b, B < c, C < d, D, e, E"); 46285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 463ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 464ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru col1 = ucol_openRules(ruleset1, u_strlen(ruleset1), UCOL_DEFAULT, UCOL_DEFAULT_STRENGTH, NULL,&status); 465ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 46685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "RuleBased Collator creation failed.: %s\n", myErrorName(status)); 467ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 468ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 469ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else 470ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("PASS: RuleBased Collator creation passed\n"); 47185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 472ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 473ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru col2 = ucol_openRules(ruleset2, u_strlen(ruleset2), UCOL_DEFAULT, UCOL_DEFAULT_STRENGTH, NULL, &status); 474ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 475ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("RuleBased Collator creation failed.: %s\n", myErrorName(status)); 476ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 477ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 478ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else 479ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("PASS: RuleBased Collator creation passed\n"); 48085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 48185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 482ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 483ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru col3= ucol_open(NULL, &status); 484ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 485ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Default Collator creation failed.: %s\n", myErrorName(status)); 486ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 487ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 488ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else 489ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("PASS: Default Collator creation passed\n"); 49085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 491ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru rule1 = ucol_getRules(col1, &tempLength); 492ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru rule2 = ucol_getRules(col2, &tempLength); 493ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru rule3 = ucol_getRules(col3, &tempLength); 494ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 495ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert((u_strcmp(rule1, rule2) != 0), "Default collator getRules failed"); 496ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert((u_strcmp(rule2, rule3) != 0), "Default collator getRules failed"); 497ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert((u_strcmp(rule1, rule3) != 0), "Default collator getRules failed"); 49885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 499ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru col4=ucol_openRules(rule2, u_strlen(rule2), UCOL_DEFAULT, UCOL_DEFAULT_STRENGTH, NULL, &status); 500ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 501ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("RuleBased Collator creation failed.: %s\n", myErrorName(status)); 502ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 503ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 504ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru rule4= ucol_getRules(col4, &tempLength); 505ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert((u_strcmp(rule2, rule4) == 0), "Default collator getRules failed"); 506ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 507ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(col1); 508ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(col2); 509ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(col3); 510ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(col4); 51185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 512ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* tests that modifier ! is always ignored */ 513ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(ruleset1, "!&a<b"); 514ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru teststr[0] = 0x0e40; 515ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru teststr[1] = 0x0e01; 516ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru teststr[2] = 0x0e2d; 517ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru col1 = ucol_openRules(ruleset1, u_strlen(ruleset1), UCOL_DEFAULT, UCOL_DEFAULT_STRENGTH, NULL, &status); 518ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 519ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("RuleBased Collator creation failed.: %s\n", myErrorName(status)); 520ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 521ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 522ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru col2 = ucol_open("en_US", &status); 523ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 524ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("en_US Collator creation failed.: %s\n", myErrorName(status)); 525ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 526ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 527ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru iter1 = ucol_openElements(col1, teststr, 3, &status); 528ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru iter2 = ucol_openElements(col2, teststr, 3, &status); 529ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 530ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: CollationElement iterator creation failed.: %s\n", myErrorName(status)); 531ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 532ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 533ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru while (TRUE) { 534ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* testing with en since thai has its own tailoring */ 535ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t ce = ucol_next(iter1, &status); 536ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t ce2 = ucol_next(iter2, &status); 537ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 538ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: CollationElement iterator creation failed.: %s\n", myErrorName(status)); 539ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 540ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 541ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ce2 != ce) { 542ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("! modifier test failed"); 543ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 544ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ce == UCOL_NULLORDER) { 545ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru break; 546ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 547ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 548ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_closeElements(iter1); 549ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_closeElements(iter2); 550ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(col1); 551ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(col2); 552ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* test that we can start a rule without a & or < */ 553ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(ruleset1, "< z < a"); 554ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru col1 = ucol_openRules(ruleset1, u_strlen(ruleset1), UCOL_DEFAULT, UCOL_DEFAULT_STRENGTH, NULL, &status); 555ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 556ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("RuleBased Collator creation failed.: %s\n", myErrorName(status)); 557ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 558ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 559ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(teststr, "z"); 560ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(teststr2, "a"); 561ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_greaterOrEqual(col1, teststr, 1, teststr2, 1)) { 562ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Rule \"z < a\" fails"); 56385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 564ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(col1); 565ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 566ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 567ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestCompare() 568ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 569ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 570ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *col; 571ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar* test1; 572ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar* test2; 57385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 574ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("The compare tests begin : \n"); 575ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 576ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru col = ucol_open("en_US", &status); 577ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 57885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "ucal_open() collation creation failed.: %s\n", myErrorName(status)); 579ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 580ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 581ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru test1=(UChar*)malloc(sizeof(UChar) * 6); 582ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru test2=(UChar*)malloc(sizeof(UChar) * 6); 583ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(test1, "Abcda"); 584ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(test2, "abcda"); 58585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 586ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Use tertiary comparison level testing ....\n"); 58785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 588ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (!ucol_equal(col, test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"Abcda\" != \"abcda\" "); 589ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (ucol_greater(col, test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"Abcda\" >>> \"abcda\" "); 59085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho doAssert( (ucol_greaterOrEqual(col, test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"Abcda\" >>> \"abcda\""); 591ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 592ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setStrength(col, UCOL_SECONDARY); 593ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Use secondary comparison level testing ....\n"); 59485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 595ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (ucol_equal(col, test1, u_strlen(test1), test2, u_strlen(test2) )), "Result should be \"Abcda\" == \"abcda\""); 596ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (!ucol_greater(col, test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"Abcda\" == \"abcda\""); 59785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho doAssert( (ucol_greaterOrEqual(col, test1, u_strlen(test1), test2, u_strlen(test2) )), "Result should be \"Abcda\" == \"abcda\""); 598ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 599ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setStrength(col, UCOL_PRIMARY); 600ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Use primary comparison level testing ....\n"); 60185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 602ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (ucol_equal(col, test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"Abcda\" == \"abcda\""); 603ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (!ucol_greater(col, test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"Abcda\" == \"abcda\""); 60485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho doAssert( (ucol_greaterOrEqual(col, test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"Abcda\" == \"abcda\""); 60585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 606ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 607ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("The compare tests end.\n"); 608ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(col); 609ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(test1); 610ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(test2); 61185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 612ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 613ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* 614ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru--------------------------------------------- 615ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tests decomposition setting 616ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/ 617ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestDecomposition() { 618ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 619ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *en_US, *el_GR, *vi_VN; 620ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru en_US = ucol_open("en_US", &status); 621ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru el_GR = ucol_open("el_GR", &status); 622ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru vi_VN = ucol_open("vi_VN", &status); 623ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 624ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 62585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "ERROR: collation creation failed.: %s\n", myErrorName(status)); 626ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 627ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 628ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 629ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getAttribute(vi_VN, UCOL_NORMALIZATION_MODE, &status) != UCOL_ON || 630ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_FAILURE(status)) 631ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 632ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: vi_VN collation did not have cannonical decomposition for normalization!\n"); 633ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 634ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 635ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 636ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getAttribute(el_GR, UCOL_NORMALIZATION_MODE, &status) != UCOL_ON || 637ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_FAILURE(status)) 638ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 639ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: el_GR collation did not have cannonical decomposition for normalization!\n"); 640ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 641ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 642ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 643ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getAttribute(en_US, UCOL_NORMALIZATION_MODE, &status) != UCOL_OFF || 644ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_FAILURE(status)) 645ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 646ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: en_US collation had cannonical decomposition for normalization!\n"); 647ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 648ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 649ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(en_US); 650ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(el_GR); 651ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(vi_VN); 652ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 653ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 654ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define CLONETEST_COLLATOR_COUNT 4 655ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 656ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestSafeClone() { 65785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UChar test1[6]; 65885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UChar test2[6]; 659ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static const UChar umlautUStr[] = {0x00DC, 0}; 660ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static const UChar oeStr[] = {0x0055, 0x0045, 0}; 661ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator * someCollators [CLONETEST_COLLATOR_COUNT]; 662ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator * someClonedCollators [CLONETEST_COLLATOR_COUNT]; 663ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator * col; 664ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode err = U_ZERO_ERROR; 66585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho int8_t index = 6; /* Leave this here to test buffer alingment in memory*/ 666ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t buffer [CLONETEST_COLLATOR_COUNT] [U_COL_SAFECLONE_BUFFERSIZE]; 667ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t bufferSize = U_COL_SAFECLONE_BUFFERSIZE; 668ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char sampleRuleChars[] = "&Z < CH"; 669ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar sampleRule[sizeof(sampleRuleChars)]; 670ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 671ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (TestBufferSize()) { 672ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("U_COL_SAFECLONE_BUFFERSIZE should be larger than sizeof(UCollator)\n"); 673ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 674ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 675ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 676ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(test1, "abCda"); 677ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(test2, "abcda"); 678ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(sampleRule, sampleRuleChars); 67985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 680ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* one default collator & two complex ones */ 681ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru someCollators[0] = ucol_open("en_US", &err); 682ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru someCollators[1] = ucol_open("ko", &err); 683ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru someCollators[2] = ucol_open("ja_JP", &err); 684ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru someCollators[3] = ucol_openRules(sampleRule, -1, UCOL_ON, UCOL_TERTIARY, NULL, &err); 685ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(err)) { 68685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho for (index = 0; index < CLONETEST_COLLATOR_COUNT; index++) { 68785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho ucol_close(someCollators[index]); 68885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 689ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_data_err("Couldn't open one or more collators\n"); 690ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 691ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 692ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 693ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Check the various error & informational states: */ 694ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 695ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Null status - just returns NULL */ 696ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (0 != ucol_safeClone(someCollators[0], buffer[0], &bufferSize, 0)) 697ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 698ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: Cloned Collator failed to deal correctly with null status\n"); 699ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 700ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* error status - should return 0 & keep error the same */ 701ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru err = U_MEMORY_ALLOCATION_ERROR; 702ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (0 != ucol_safeClone(someCollators[0], buffer[0], &bufferSize, &err) || err != U_MEMORY_ALLOCATION_ERROR) 703ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 704ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: Cloned Collator failed to deal correctly with incoming error status\n"); 705ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 706ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru err = U_ZERO_ERROR; 707ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 708ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Null buffer size pointer - just returns NULL & set error to U_ILLEGAL_ARGUMENT_ERROR*/ 709ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (0 != ucol_safeClone(someCollators[0], buffer[0], 0, &err) || err != U_ILLEGAL_ARGUMENT_ERROR) 710ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 711ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: Cloned Collator failed to deal correctly with null bufferSize pointer\n"); 712ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 713ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru err = U_ZERO_ERROR; 71485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 715ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* buffer size pointer is 0 - fill in pbufferSize with a size */ 716ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru bufferSize = 0; 717ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (0 != ucol_safeClone(someCollators[0], buffer[0], &bufferSize, &err) || U_FAILURE(err) || bufferSize <= 0) 718ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 719ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: Cloned Collator failed a sizing request ('preflighting')\n"); 720ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 721ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Verify our define is large enough */ 722ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_COL_SAFECLONE_BUFFERSIZE < bufferSize) 723ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 724ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: Pre-calculated buffer size is too small\n"); 725ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 726ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Verify we can use this run-time calculated size */ 727ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (0 == (col = ucol_safeClone(someCollators[0], buffer[0], &bufferSize, &err)) || U_FAILURE(err)) 728ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 729ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: Collator can't be cloned with run-time size\n"); 730ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 731ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (col) ucol_close(col); 732ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* size one byte too small - should allocate & let us know */ 733ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru --bufferSize; 734ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (0 == (col = ucol_safeClone(someCollators[0], 0, &bufferSize, &err)) || err != U_SAFECLONE_ALLOCATED_WARNING) 735ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 736ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: Cloned Collator failed to deal correctly with too-small buffer size\n"); 737ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 738ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (col) ucol_close(col); 739ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru err = U_ZERO_ERROR; 740ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru bufferSize = U_COL_SAFECLONE_BUFFERSIZE; 741ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 742ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 743ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Null buffer pointer - return Collator & set error to U_SAFECLONE_ALLOCATED_ERROR */ 744ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (0 == (col = ucol_safeClone(someCollators[0], 0, &bufferSize, &err)) || err != U_SAFECLONE_ALLOCATED_WARNING) 745ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 746ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: Cloned Collator failed to deal correctly with null buffer pointer\n"); 747ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 748ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (col) ucol_close(col); 749ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru err = U_ZERO_ERROR; 750ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 751ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Null Collator - return NULL & set U_ILLEGAL_ARGUMENT_ERROR */ 752ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (0 != ucol_safeClone(0, buffer[0], &bufferSize, &err) || err != U_ILLEGAL_ARGUMENT_ERROR) 753ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 754ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: Cloned Collator failed to deal correctly with null Collator pointer\n"); 755ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 756ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 757ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru err = U_ZERO_ERROR; 758ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 759ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Test that a cloned collator doesn't accidentally use UCA. */ 760ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru col=ucol_open("de@collation=phonebook", &err); 761ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru bufferSize = U_COL_SAFECLONE_BUFFERSIZE; 762ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru someClonedCollators[0] = ucol_safeClone(col, buffer[0], &bufferSize, &err); 763ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (ucol_greater(col, umlautUStr, u_strlen(umlautUStr), oeStr, u_strlen(oeStr))), "Original German phonebook collation sorts differently than expected"); 764ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (ucol_greater(someClonedCollators[0], umlautUStr, u_strlen(umlautUStr), oeStr, u_strlen(oeStr))), "Cloned German phonebook collation sorts differently than expected"); 765ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (!ucol_equals(someClonedCollators[0], col)) { 766ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: Cloned German phonebook collator is not equal to original.\n"); 767ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 768ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(col); 769ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(someClonedCollators[0]); 770ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 771ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru err = U_ZERO_ERROR; 772ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 773ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* change orig & clone & make sure they are independent */ 774ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 775ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (index = 0; index < CLONETEST_COLLATOR_COUNT; index++) 776ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 777ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setStrength(someCollators[index], UCOL_IDENTICAL); 778ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru bufferSize = 1; 779ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru err = U_ZERO_ERROR; 780ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(ucol_safeClone(someCollators[index], buffer[index], &bufferSize, &err)); 781ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (err != U_SAFECLONE_ALLOCATED_WARNING) { 782ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: collator number %d was not allocated.\n", index); 78385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("FAIL: status of Collator[%d] is %d (hex: %x).\n", index, err, err); 784ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 785ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 786ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru bufferSize = U_COL_SAFECLONE_BUFFERSIZE; 787ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru err = U_ZERO_ERROR; 788ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru someClonedCollators[index] = ucol_safeClone(someCollators[index], buffer[index], &bufferSize, &err); 789ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (someClonedCollators[index] == NULL 790ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru || someClonedCollators[index] < (UCollator *)buffer[index] 791ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru || someClonedCollators[index] > (UCollator *)(buffer[index]+(U_COL_SAFECLONE_BUFFERSIZE-1))) 792ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 793ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: Cloned collator didn't use provided buffer.\n"); 794ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 795ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 796ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (!ucol_equals(someClonedCollators[index], someCollators[index])) { 797ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: Cloned collator is not equal to original at index = %d.\n", index); 798ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 799ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 800ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Check the usability */ 801ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setStrength(someCollators[index], UCOL_PRIMARY); 802ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(someCollators[index], UCOL_CASE_LEVEL, UCOL_OFF, &err); 80385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 804ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (ucol_equal(someCollators[index], test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"abcda\" == \"abCda\""); 80585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 806ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Close the original to make sure that the clone is usable. */ 807ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(someCollators[index]); 808ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 809ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setStrength(someClonedCollators[index], UCOL_TERTIARY); 810ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(someClonedCollators[index], UCOL_CASE_LEVEL, UCOL_OFF, &err); 811ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (ucol_greater(someClonedCollators[index], test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"abCda\" >>> \"abcda\" "); 812ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 813ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(someClonedCollators[index]); 814ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 815ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 816ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 817ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestCloneBinary(){ 818ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode err = U_ZERO_ERROR; 819ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator * col = ucol_open("en_US", &err); 820ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator * c; 821ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t size; 822ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t * buffer; 823ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 824ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(err)) { 825ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_data_err("Couldn't open collator. Error: %s\n", u_errorName(err)); 826ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 827ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 828ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 829ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru size = ucol_cloneBinary(col, NULL, 0, &err); 830ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(size==0 || err!=U_BUFFER_OVERFLOW_ERROR) { 831ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ucol_cloneBinary - couldn't check size. Error: %s\n", u_errorName(err)); 832ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 833ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 834ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru err = U_ZERO_ERROR; 835ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 836ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru buffer = (uint8_t *) malloc(size); 837ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_cloneBinary(col, buffer, size, &err); 838ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(err)) { 839ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ucol_cloneBinary - couldn't clone.. Error: %s\n", u_errorName(err)); 840ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(buffer); 841ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 842ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 843ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 844ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* how to check binary result ? */ 845ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 846ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru c = ucol_openBinary(buffer, size, col, &err); 847ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(err)) { 848ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ucol_openBinary failed. Error: %s\n", u_errorName(err)); 849ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 850ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar t[] = {0x41, 0x42, 0x43, 0}; /* ABC */ 851ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t *k1, *k2; 852ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int l1, l2; 853ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru l1 = ucol_getSortKey(col, t, -1, NULL,0); 854ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru l2 = ucol_getSortKey(c, t, -1, NULL,0); 855ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru k1 = (uint8_t *) malloc(sizeof(uint8_t) * l1); 856ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru k2 = (uint8_t *) malloc(sizeof(uint8_t) * l2); 857ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_getSortKey(col, t, -1, k1, l1); 858ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_getSortKey(col, t, -1, k2, l2); 859ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (strcmp((char *)k1,(char *)k2) != 0){ 860ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ucol_openBinary - new collator should equal to old one\n"); 861ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }; 862ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(k1); 863ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(k2); 864ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 865ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(buffer); 866ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(c); 867ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(col); 868ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 869ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* 87085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho TestOpenVsOpenRules ensures that collators from ucol_open and ucol_openRules 87185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho will generate identical sort keys 87285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho*/ 87385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hovoid TestOpenVsOpenRules(){ 87485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 87585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* create an array of all the locales */ 87685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho int32_t numLocales = uloc_countAvailable(); 87785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho int32_t sizeOfStdSet; 87885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho uint32_t adder; 87985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UChar str[41]; /* create an array of UChar of size maximum strSize + 1 */ 88085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho USet *stdSet; 88185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho char* curLoc; 88285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UCollator * c1; 88385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UCollator * c2; 88485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho const UChar* rules; 88585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho int32_t rulesLength; 88685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho int32_t sortKeyLen1, sortKeyLen2; 88785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho uint8_t *sortKey1 = NULL, *sortKey2 = NULL; 88885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho ULocaleData *uld; 88985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho uint32_t x, y, z; 89085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho USet *eSet; 89185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho int32_t eSize; 89285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho int strSize; 89385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 89485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UErrorCode err = U_ZERO_ERROR; 89585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 89685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* create a set of standard characters that aren't very interesting... 89785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho and then we can find some interesting ones later */ 89885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 89985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho stdSet = uset_open(0x61, 0x7A); 90085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho uset_addRange(stdSet, 0x41, 0x5A); 90185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho uset_addRange(stdSet, 0x30, 0x39); 90285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho sizeOfStdSet = uset_size(stdSet); 90385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 90485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho adder = 1; 90585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if(QUICK) 90685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho { 90785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho adder = 10; 90885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 90985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 91085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho for(x = 0; x < numLocales; x+=adder){ 91185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho curLoc = (char *)uloc_getAvailable(x); 91285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_verbose("Processing %s\n", curLoc); 91385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 91485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* create a collator the normal API way */ 91585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho c1 = ucol_open(curLoc, &err); 91685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if (U_FAILURE(err)) { 91785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("ERROR: Normal collation creation failed with locale: %s : %s\n", curLoc, myErrorName(err)); 91885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho return; 91985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 92085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 92185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* grab the rules */ 92285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho rules = ucol_getRules(c1, &rulesLength); 92385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 92485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* use those rules to create a collator from rules */ 92585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho c2 = ucol_openRules(rules, rulesLength, UCOL_DEFAULT, UCOL_DEFAULT_STRENGTH, NULL, &err); 92685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if (U_FAILURE(err)) { 92785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("ERROR: Creating collator from rules failed with locale: %s : %s\n", curLoc, myErrorName(err)); 92885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho return; 92985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 93085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 93185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho uld = ulocdata_open(curLoc, &err); 93285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 93385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /*now that we have some collators, we get several strings */ 93485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 93585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho for(y = 0; y < 5; y++){ 93685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 93785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* get a set of ALL the characters in this locale */ 93885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho eSet = ulocdata_getExemplarSet(uld, NULL, 0, ULOCDATA_ES_STANDARD, &err); 93985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho eSize = uset_size(eSet); 94085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 94185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* make a string with these characters in it */ 94285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho strSize = (rand()%40) + 1; 94385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 94485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho for(z = 0; z < strSize; z++){ 94585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho str[z] = uset_charAt(eSet, rand()%eSize); 94685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 94785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 94885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* change the set to only include 'abnormal' characters (not A-Z, a-z, 0-9 */ 94985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho uset_removeAll(eSet, stdSet); 95085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho eSize = uset_size(eSet); 95185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 95285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* if there are some non-normal characters left, put a few into the string, just to make sure we have some */ 95385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if(eSize > 0){ 95485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho str[2%strSize] = uset_charAt(eSet, rand()%eSize); 95585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho str[3%strSize] = uset_charAt(eSet, rand()%eSize); 95685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho str[5%strSize] = uset_charAt(eSet, rand()%eSize); 95785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho str[10%strSize] = uset_charAt(eSet, rand()%eSize); 95885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho str[13%strSize] = uset_charAt(eSet, rand()%eSize); 95985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 96085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* terminate the string */ 96185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho str[strSize-1] = '\0'; 96285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_verbose("String used: %S\n", str); 96385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 96485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* get sort keys for both of them, and check that the keys are identicle */ 96585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho sortKeyLen1 = ucol_getSortKey(c1, str, u_strlen(str), NULL, 0); 96685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho sortKey1 = (uint8_t*)malloc(sizeof(uint8_t) * (sortKeyLen1 + 1)); 96785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /*memset(sortKey1, 0xFE, sortKeyLen1);*/ 96885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho ucol_getSortKey(c1, str, u_strlen(str), sortKey1, sortKeyLen1 + 1); 96985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 97085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho sortKeyLen2 = ucol_getSortKey(c2, str, u_strlen(str), NULL, 0); 97185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho sortKey2 = (uint8_t*)malloc(sizeof(uint8_t) * (sortKeyLen2 + 1)); 97285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /*memset(sortKey2, 0xFE, sortKeyLen2);*/ 97385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho ucol_getSortKey(c2, str, u_strlen(str), sortKey2, sortKeyLen2 + 1); 97485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 97585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* Check that the lengths are the same */ 97685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho doAssert((sortKeyLen1 == sortKeyLen2), "Sort key lengths do not match."); 97785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 97885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* check that the keys are the same */ 97985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho doAssert((memcmp(sortKey1, sortKey2, sortKeyLen1) == 0), "Keys are not equivalent"); 98085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 98185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* clean up after each string */ 98285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho free(sortKey1); 98385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho free(sortKey2); 98485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho uset_close(eSet); 98585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 98685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* clean up after each locale */ 98785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho ulocdata_close(uld); 98885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho ucol_close(c1); 98985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho ucol_close(c2); 99085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 99185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* final clean up */ 99285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho uset_close(stdSet); 99385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho} 99485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho/* 995ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru---------------------------------------------------------------------------- 996ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ctor -- Tests the getSortKey 997ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/ 998ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestSortKey() 99985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho{ 1000ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t *sortk1 = NULL, *sortk2 = NULL, *sortk3 = NULL, *sortkEmpty = NULL; 100185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho uint8_t sortk2_compat[] = { 100285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* 3.9 key, from UCA 5.1 */ 100385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 0x2c, 0x2e, 0x30, 0x32, 0x2c, 0x01, 100485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 0x09, 0x01, 0x09, 0x01, 0x2b, 0x01, 100585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 0x92, 0x93, 0x94, 0x95, 0x92, 0x0 100685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1007ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* 3.6 key, from UCA 5.0 */ 100885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* 100985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 0x29, 0x2b, 0x2d, 0x2f, 0x29, 0x01, 101085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 0x09, 0x01, 0x09, 0x01, 0x28, 0x01, 1011ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 0x92, 0x93, 0x94, 0x95, 0x92, 0x00 101285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho */ 1013ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* 3.4 key, from UCA 4.1 */ 1014ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* 0x28, 0x2a, 0x2c, 0x2e, 0x28, 0x01, 0x09, 0x01, 0x09, 0x01, 0x27, 0x01, 0x92, 0x93, 0x94, 0x95, 0x92, 0x00 */ 1015ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* 2.6.1 key */ 1016ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* 0x26, 0x28, 0x2A, 0x2C, 0x26, 0x01, 0x09, 0x01, 0x09, 0x01, 0x25, 0x01, 0x92, 0x93, 0x94, 0x95, 0x92, 0x00 */ 1017ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* 2.2 key */ 1018ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*0x1D, 0x1F, 0x21, 0x23, 0x1D, 0x01, 0x09, 0x01, 0x09, 0x01, 0x1C, 0x01, 0x92, 0x93, 0x94, 0x95, 0x92, 0x00*/ 1019ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* 2.0 key */ 1020ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*0x19, 0x1B, 0x1D, 0x1F, 0x19, 0x01, 0x09, 0x01, 0x09, 0x01, 0x18, 0x01, 0x92, 0x93, 0x94, 0x95, 0x92, 0x00*/ 1021ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* 1.8.1 key.*/ 1022ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*0x19, 0x1B, 0x1D, 0x1F, 0x19, 0x01, 0x0A, 0x01, 0x0A, 0x01, 0x92, 0x93, 0x94, 0x95, 0x92, 0x00*/ 1023ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*this is a 1.8 sortkey */ 1024ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*0x17, 0x19, 0x1B, 0x1D, 0x17, 0x01, 0x08, 0x01, 0x08, 0x00*/ 1025ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*this is a 1.7 sortkey */ 1026ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*0x02, 0x54, 0x02, 0x55, 0x02, 0x56, 0x02, 0x57, 0x02, 0x54, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x00*/ 1027ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* this is a 1.6 sortkey */ 1028ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*0x00, 0x53, 0x00, 0x54, 0x00, 0x55, 0x00, 0x56, 0x00, 0x53, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00*/ 1029ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }; 1030ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1031ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t sortklen, osortklen; 1032ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t toStringLen=0; 1033ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *col; 1034ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar *test1, *test2, *test3; 1035ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 1036ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char toStringBuffer[256], *resultP; 1037ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1038ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1039ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t s1[] = { 0x9f, 0x00 }; 1040ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t s2[] = { 0x61, 0x00 }; 1041ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int strcmpResult; 1042ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1043ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcmpResult = strcmp((const char *)s1, (const char *)s2); 1044ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("strcmp(0x9f..., 0x61...) = %d\n", strcmpResult); 104585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1046ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strcmpResult <= 0) { 1047ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERR: expected strcmp(\"9f 00\", \"61 00\") to be >=0 (GREATER).. got %d. Calling strcmp() for sortkeys may not work! \n", 1048ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcmpResult); 1049ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1050ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1051ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1052ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("testing SortKey begins...\n"); 105385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* this is supposed to open default date format, but later on it treats it like it is "en_US" 1054ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru - very bad if you try to run the tests on machine where default locale is NOT "en_US" */ 1055ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* col = ucol_open(NULL, &status); */ 1056ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru col = ucol_open("en_US", &status); 1057ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 105885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "ERROR: Default collation creation failed.: %s\n", myErrorName(status)); 1059ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1060ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1061ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1062ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1063ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(ucol_getStrength(col) != UCOL_DEFAULT_STRENGTH) 1064ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1065ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: default collation did not have UCOL_DEFAULT_STRENGTH !\n"); 1066ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1067ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Need to use identical strength */ 1068ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(col, UCOL_STRENGTH, UCOL_IDENTICAL, &status); 1069ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1070ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru test1=(UChar*)malloc(sizeof(UChar) * 6); 1071ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru test2=(UChar*)malloc(sizeof(UChar) * 6); 1072ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru test3=(UChar*)malloc(sizeof(UChar) * 6); 107385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1074ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru memset(test1,0xFE, sizeof(UChar)*6); 1075ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru memset(test2,0xFE, sizeof(UChar)*6); 1076ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru memset(test3,0xFE, sizeof(UChar)*6); 1077ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1078ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1079ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(test1, "Abcda"); 1080ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(test2, "abcda"); 1081ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(test3, "abcda"); 1082ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1083ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Use tertiary comparison level testing ....\n"); 1084ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1085ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortklen=ucol_getSortKey(col, test1, u_strlen(test1), NULL, 0); 1086ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortk1=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen+1)); 1087ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru memset(sortk1,0xFE, sortklen); 1088ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_getSortKey(col, test1, u_strlen(test1), sortk1, sortklen+1); 1089ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1090ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortklen=ucol_getSortKey(col, test2, u_strlen(test2), NULL, 0); 1091ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortk2=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen+1)); 1092ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru memset(sortk2,0xFE, sortklen); 1093ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_getSortKey(col, test2, u_strlen(test2), sortk2, sortklen+1); 1094ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1095ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru osortklen = sortklen; 1096ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortklen=ucol_getSortKey(col, test2, u_strlen(test3), NULL, 0); 1097ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortk3=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen+1)); 1098ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru memset(sortk3,0xFE, sortklen); 1099ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_getSortKey(col, test2, u_strlen(test2), sortk3, sortklen+1); 1100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (sortklen == osortklen), "Sortkey length should be the same (abcda, abcda)"); 1102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (memcmp(sortk1, sortk2, sortklen) > 0), "Result should be \"Abcda\" > \"abcda\""); 1104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (memcmp(sortk2, sortk1, sortklen) < 0), "Result should be \"abcda\" < \"Abcda\""); 1105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (memcmp(sortk2, sortk3, sortklen) == 0), "Result should be \"abcda\" == \"abcda\""); 1106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (memcmp(sortk2, sortk2_compat, sortklen) == 0), "Binary format for 'abcda' sortkey different!"); 1108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru resultP = ucol_sortKeyToString(col, sortk2_compat, toStringBuffer, &toStringLen); 1110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (resultP != 0), "sortKeyToString failed!"); 1111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if 1 /* verobse log of sortkeys */ 1113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char junk2[1000]; 1115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char junk3[1000]; 1116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int i; 1117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(junk2, "abcda[2] "); 1119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(junk3, " abcda[3] "); 1120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i=0;i<sortklen;i++) 1122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sprintf(junk2+strlen(junk2), "%02X ",(int)( 0xFF & sortk2[i])); 1124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sprintf(junk3+strlen(junk3), "%02X ",(int)( 0xFF & sortk3[i])); 1125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 112685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("%s\n", junk2); 1128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("%s\n", junk3); 1129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 1131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(sortk1); 1133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(sortk2); 1134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(sortk3); 1135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Use secondary comparision level testing ...\n"); 1137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setStrength(col, UCOL_SECONDARY); 1138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortklen=ucol_getSortKey(col, test1, u_strlen(test1), NULL, 0); 1139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortk1=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen+1)); 1140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_getSortKey(col, test1, u_strlen(test1), sortk1, sortklen+1); 1141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortklen=ucol_getSortKey(col, test2, u_strlen(test2), NULL, 0); 1142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortk2=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen+1)); 1143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_getSortKey(col, test2, u_strlen(test2), sortk2, sortklen+1); 114485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( !(memcmp(sortk1, sortk2, sortklen) > 0), "Result should be \"Abcda\" == \"abcda\""); 1146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( !(memcmp(sortk2, sortk1, sortklen) < 0), "Result should be \"abcda\" == \"Abcda\""); 1147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (memcmp(sortk1, sortk2, sortklen) == 0), "Result should be \"abcda\" == \"abcda\""); 1148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("getting sortkey for an empty string\n"); 1150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(col, UCOL_STRENGTH, UCOL_TERTIARY, &status); 1151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortklen = ucol_getSortKey(col, test1, 0, NULL, 0); 1152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortkEmpty = (uint8_t*)malloc(sizeof(uint8_t) * sortklen+1); 1153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortklen = ucol_getSortKey(col, test1, 0, sortkEmpty, sortklen+1); 1154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(sortklen != 3 || sortkEmpty[0] != 1 || sortkEmpty[0] != 1 || sortkEmpty[2] != 0) { 1155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Empty string generated wrong sortkey!\n"); 1156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(sortkEmpty); 1158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("testing passing invalid string\n"); 1160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortklen = ucol_getSortKey(col, NULL, 0, NULL, 0); 1161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(sortklen != 0) { 1162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Invalid string didn't return sortkey size of 0\n"); 1163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 116485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 116585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("testing sortkey ends...\n"); 1167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(col); 1168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(test1); 1169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(test2); 1170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(test3); 1171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(sortk1); 1172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(sortk2); 117385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestHashCode() 1176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 1177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t *sortk1, *sortk2, *sortk3; 1178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t sortk1len, sortk2len, sortk3len; 1179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *col; 1180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar *test1, *test2, *test3; 1181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 1182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("testing getHashCode begins...\n"); 1183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru col = ucol_open("en_US", &status); 1184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 118585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "ERROR: Default collation creation failed.: %s\n", myErrorName(status)); 1186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru test1=(UChar*)malloc(sizeof(UChar) * 6); 1189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru test2=(UChar*)malloc(sizeof(UChar) * 6); 1190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru test3=(UChar*)malloc(sizeof(UChar) * 6); 1191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(test1, "Abcda"); 1192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(test2, "abcda"); 1193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(test3, "abcda"); 1194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Use tertiary comparison level testing ....\n"); 1196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortk1len=ucol_getSortKey(col, test1, u_strlen(test1), NULL, 0); 1197ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortk1=(uint8_t*)malloc(sizeof(uint8_t) * (sortk1len+1)); 1198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_getSortKey(col, test1, u_strlen(test1), sortk1, sortk1len+1); 1199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortk2len=ucol_getSortKey(col, test2, u_strlen(test2), NULL, 0); 1200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortk2=(uint8_t*)malloc(sizeof(uint8_t) * (sortk2len+1)); 1201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_getSortKey(col, test2, u_strlen(test2), sortk2, sortk2len+1); 1202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortk3len=ucol_getSortKey(col, test2, u_strlen(test3), NULL, 0); 1203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortk3=(uint8_t*)malloc(sizeof(uint8_t) * (sortk3len+1)); 1204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_getSortKey(col, test2, u_strlen(test2), sortk3, sortk3len+1); 120585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 120685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("ucol_hashCode() testing ...\n"); 120885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 120985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho doAssert( ucol_keyHashCode(sortk1, sortk1len) != ucol_keyHashCode(sortk2, sortk2len), "Hash test1 result incorrect" ); 1210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( !(ucol_keyHashCode(sortk1, sortk1len) == ucol_keyHashCode(sortk2, sortk2len)), "Hash test2 result incorrect" ); 1211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( ucol_keyHashCode(sortk2, sortk2len) == ucol_keyHashCode(sortk3, sortk3len), "Hash result not equal" ); 121285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("hashCode tests end.\n"); 1214ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(col); 1215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(sortk1); 1216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(sortk2); 1217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(sortk3); 1218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(test1); 1219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(test2); 1220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(test3); 1221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* 1225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *---------------------------------------------------------------------------- 1226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Tests the UCollatorElements API. 122785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * 122885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho */ 1229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestElemIter() 1230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 1231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t offset; 1232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t order1, order2, order3; 1233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar *testString1, *testString2; 1234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *col; 1235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollationElements *iterator1, *iterator2, *iterator3; 1236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 1237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("testing UCollatorElements begins...\n"); 1238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru col = ucol_open("en_US", &status); 1239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(col, UCOL_NORMALIZATION_MODE, UCOL_OFF, &status); 1240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 124185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "ERROR: Default collation creation failed.: %s\n", myErrorName(status)); 1242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru testString1=(UChar*)malloc(sizeof(UChar) * 150); 1246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru testString2=(UChar*)malloc(sizeof(UChar) * 150); 1247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(testString1, "XFILE What subset of all possible test cases has the highest probability of detecting the most errors?"); 1248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(testString2, "Xf_ile What subset of all possible test cases has the lowest probability of detecting the least errors?"); 124985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Constructors and comparison testing....\n"); 125185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru iterator1 = ucol_openElements(col, testString1, u_strlen(testString1), &status); 1253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 1254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: Default collationElement iterator creation failed.: %s\n", myErrorName(status)); 1255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(col); 1256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else{ log_verbose("PASS: Default collationElement iterator1 creation passed\n");} 1259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru iterator2 = ucol_openElements(col, testString1, u_strlen(testString1), &status); 1261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 1262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: Default collationElement iterator creation failed.: %s\n", myErrorName(status)); 1263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(col); 1264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else{ log_verbose("PASS: Default collationElement iterator2 creation passed\n");} 1267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru iterator3 = ucol_openElements(col, testString2, u_strlen(testString2), &status); 1269ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 1270ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: Default collationElement iterator creation failed.: %s\n", myErrorName(status)); 1271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(col); 1272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1274ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else{ log_verbose("PASS: Default collationElement iterator3 creation passed\n");} 1275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru offset=ucol_getOffset(iterator1); 1277ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setOffset(iterator1, 6, &status); 1278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 1279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Error in setOffset for UCollatorElements iterator.: %s\n", myErrorName(status)); 1280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1281ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1282ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(ucol_getOffset(iterator1)==6) 1283ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("setOffset and getOffset working fine\n"); 1284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else{ 1285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("error in set and get Offset got %d instead of 6\n", ucol_getOffset(iterator1)); 1286ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1287ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1288ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setOffset(iterator1, 0, &status); 1289ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru order1 = ucol_next(iterator1, &status); 1290ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 1291ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Somehow ran out of memory stepping through the iterator1.: %s\n", myErrorName(status)); 1292ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1293ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1294ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru order2=ucol_getOffset(iterator2); 1295ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert((order1 != order2), "The first iterator advance failed"); 1296ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru order2 = ucol_next(iterator2, &status); 1297ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 1298ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Somehow ran out of memory stepping through the iterator2.: %s\n", myErrorName(status)); 1299ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1300ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1301ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru order3 = ucol_next(iterator3, &status); 1302ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 1303ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Somehow ran out of memory stepping through the iterator3.: %s\n", myErrorName(status)); 1304ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1305ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 130685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1307ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert((order1 == order2), "The second iterator advance failed should be the same as first one"); 130885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1309ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerudoAssert( (ucol_primaryOrder(order1) == ucol_primaryOrder(order3)), "The primary orders should be identical"); 1310ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerudoAssert( (ucol_secondaryOrder(order1) == ucol_secondaryOrder(order3)), "The secondary orders should be identical"); 1311ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerudoAssert( (ucol_tertiaryOrder(order1) == ucol_tertiaryOrder(order3)), "The tertiary orders should be identical"); 131285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1313ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru order1=ucol_next(iterator1, &status); 1314ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 1315ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Somehow ran out of memory stepping through the iterator2.: %s\n", myErrorName(status)); 1316ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1317ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1318ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru order3=ucol_next(iterator3, &status); 1319ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 1320ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Somehow ran out of memory stepping through the iterator2.: %s\n", myErrorName(status)); 1321ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1322ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1323ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerudoAssert( (ucol_primaryOrder(order1) == ucol_primaryOrder(order3)), "The primary orders should be identical"); 1324ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerudoAssert( (ucol_tertiaryOrder(order1) != ucol_tertiaryOrder(order3)), "The tertiary orders should be different"); 132585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1326ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru order1=ucol_next(iterator1, &status); 1327ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 1328ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Somehow ran out of memory stepping through the iterator2.: %s\n", myErrorName(status)); 1329ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1330ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1331ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru order3=ucol_next(iterator3, &status); 1332ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 1333ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Somehow ran out of memory stepping through the iterator2.: %s\n", myErrorName(status)); 1334ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1335ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1336ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* this here, my friends, is either pure lunacy or something so obsolete that even it's mother 1337ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * doesn't care about it. Essentialy, this test complains if secondary values for 'I' and '_' 1338ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * are the same. According to the UCA, this is not true. Therefore, remove the test. 1339ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Besides, if primary strengths for two code points are different, it doesn't matter one bit 1340ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * what is the relation between secondary or any other strengths. 1341ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * killed by weiv 06/11/2002. 1342ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 1343ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* 1344ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( ((order1 & UCOL_SECONDARYMASK) != (order3 & UCOL_SECONDARYMASK)), "The secondary orders should be different"); 1345ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 1346ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (order1 != UCOL_NULLORDER), "Unexpected end of iterator reached"); 1347ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1348ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(testString1); 1349ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(testString2); 1350ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_closeElements(iterator1); 1351ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_closeElements(iterator2); 1352ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_closeElements(iterator3); 1353ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(col); 135485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1355ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("testing CollationElementIterator ends...\n"); 1356ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1357ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1358ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestGetLocale() { 1359ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 1360ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *rules = "&a<x<y<z"; 1361ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar rlz[256] = {0}; 1362ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t rlzLen = u_unescape(rules, rlz, 256); 1363ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1364ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *coll = NULL; 1365ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *locale = NULL; 1366ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1367ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t i = 0; 1368ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1369ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Now that the collation tree is separate, actual==valid at all times. [alan] */ 1370ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static const struct { 1371ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* requestedLocale; 1372ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* validLocale; 1373ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* actualLocale; 1374ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } testStruct[] = { 1375ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { "sr_RS", "sr_Cyrl_RS", "ru" }, 1376ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { "sh_YU", "sr_Latn_RS", "hr" }, /* this used to be sh, but now sh collation aliases hr */ 1377ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { "en_BE_FOO", "en_BE", "en_BE" }, 1378ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { "fr_FR_NONEXISTANT", "fr_FR", "fr" } 1379ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }; 1380ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1381ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* test opening collators for different locales */ 1382ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i = 0; i<sizeof(testStruct)/sizeof(testStruct[0]); i++) { 1383ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 1384ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru coll = ucol_open(testStruct[i].requestedLocale, &status); 1385ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 138685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "Failed to open collator for %s with %s\n", testStruct[i].requestedLocale, u_errorName(status)); 1387ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(coll); 1388ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru continue; 1389ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 139085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho locale = ucol_getLocaleByType(coll, ULOC_REQUESTED_LOCALE, &status); 1391ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strcmp(locale, testStruct[i].requestedLocale) != 0) { 1392ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("[Coll %s]: Error in requested locale, expected %s, got %s\n", testStruct[i].requestedLocale, testStruct[i].requestedLocale, locale); 1393ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 139485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho locale = ucol_getLocaleByType(coll, ULOC_VALID_LOCALE, &status); 1395ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strcmp(locale, testStruct[i].validLocale) != 0) { 1396ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("[Coll %s]: Error in valid locale, expected %s, got %s\n", testStruct[i].requestedLocale, testStruct[i].validLocale, locale); 1397ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 139885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho locale = ucol_getLocaleByType(coll, ULOC_ACTUAL_LOCALE, &status); 1399ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strcmp(locale, testStruct[i].actualLocale) != 0) { 1400ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("[Coll %s]: Error in actual locale, expected %s, got %s\n", testStruct[i].requestedLocale, testStruct[i].actualLocale, locale); 1401ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1402ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(coll); 1403ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1404ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1405ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* completely non-existant locale for collator should get a default collator */ 1406ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1407ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *defaultColl = ucol_open(NULL, &status); 1408ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru coll = ucol_open("blahaha", &status); 1409ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)) { 141085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if(strcmp(ucol_getLocaleByType(coll, ULOC_REQUESTED_LOCALE, &status), "blahaha")) { 1411ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Nonexisting locale didn't preserve the requested locale\n"); 1412ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 141385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if(strcmp(ucol_getLocaleByType(coll, ULOC_VALID_LOCALE, &status), 141485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho ucol_getLocaleByType(defaultColl, ULOC_VALID_LOCALE, &status))) { 1415ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Valid locale for nonexisting locale locale collator differs " 1416ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "from valid locale for default collator\n"); 1417ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 141885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if(strcmp(ucol_getLocaleByType(coll, ULOC_ACTUAL_LOCALE, &status), 141985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho ucol_getLocaleByType(defaultColl, ULOC_ACTUAL_LOCALE, &status))) { 1420ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Actual locale for nonexisting locale locale collator differs " 1421ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "from actual locale for default collator\n"); 1422ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1423ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(coll); 1424ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(defaultColl); 1425ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 1426ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_data_err("Couldn't open collators\n"); 1427ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1428ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1429ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 143085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1431ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1432ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* collator instantiated from rules should have all three locales NULL */ 1433ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru coll = ucol_openRules(rlz, rlzLen, UCOL_DEFAULT, UCOL_DEFAULT, NULL, &status); 143485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho locale = ucol_getLocaleByType(coll, ULOC_REQUESTED_LOCALE, &status); 1435ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(locale != NULL) { 1436ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("For collator instantiated from rules, requested locale returned %s instead of NULL\n", locale); 1437ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 143885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho locale = ucol_getLocaleByType(coll, ULOC_VALID_LOCALE, &status); 1439ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(locale != NULL) { 1440ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("For collator instantiated from rules, valid locale returned %s instead of NULL\n", locale); 1441ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 144285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho locale = ucol_getLocaleByType(coll, ULOC_ACTUAL_LOCALE, &status); 1443ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(locale != NULL) { 1444ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("For collator instantiated from rules, actual locale returned %s instead of NULL\n", locale); 1445ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1446ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(coll); 1447ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1448ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1449ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1450ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1451ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestGetAll() 1452ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 1453ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t i, count; 1454ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru count=ucol_countAvailable(); 1455ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* use something sensible w/o hardcoding the count */ 1456ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(count < 0){ 1457ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Error in countAvailable(), it returned %d\n", count); 1458ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1459ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else{ 1460ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("PASS: countAvailable() successful, it returned %d\n", count); 1461ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1462ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i=0;i<count;i++) 1463ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("%s\n", ucol_getAvailable(i)); 1464ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1465ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1466ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1467ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1468ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1469ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustruct teststruct { 1470ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *original; 1471ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t key[256]; 1472ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} ; 1473ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1474ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic int compare_teststruct(const void *string1, const void *string2) { 1475ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return(strcmp((const char *)((struct teststruct *)string1)->key, (const char *)((struct teststruct *)string2)->key)); 1476ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1477ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1478ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestBounds() { 1479ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 1480ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1481ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *coll = ucol_open("sh", &status); 1482ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1483ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t sortkey[512], lower[512], upper[512]; 1484ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar buffer[512]; 1485ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1486ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static const char * const test[] = { 1487ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "John Smith", 1488ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "JOHN SMITH", 1489ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "john SMITH", 1490ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "j\\u00F6hn sm\\u00EFth", 1491ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "J\\u00F6hn Sm\\u00EFth", 1492ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "J\\u00D6HN SM\\u00CFTH", 1493ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "john smithsonian", 1494ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "John Smithsonian", 1495ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }; 1496ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 149785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho struct teststruct tests[] = { 1498ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKI MIHALJ" } , 1499ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKI MIHALJ" } , 1500ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKI PIRO\\u0160KA" }, 1501ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABAI ANDRIJA" } , 1502ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABAI LAJO\\u0160" } , 1503ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABAI MARIJA" } , 1504ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABAI STEVAN" } , 1505ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABAI STEVAN" } , 1506ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABARKAPA BRANKO" } , 1507ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABARKAPA MILENKO" } , 1508ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABARKAPA MIROSLAV" } , 1509ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABARKAPA SIMO" } , 1510ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABARKAPA STANKO" } , 1511ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABARKAPA TAMARA" } , 1512ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABARKAPA TOMA\\u0160" } , 1513ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABDARI\\u0106 NIKOLA" } , 1514ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABDARI\\u0106 ZORICA" } , 1515ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABI NANDOR" } , 1516ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABOVI\\u0106 MILAN" } , 1517ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABRADI AGNEZIJA" } , 1518ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABRADI IVAN" } , 1519ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABRADI JELENA" } , 1520ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABRADI LJUBICA" } , 1521ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABRADI STEVAN" } , 1522ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABRDA MARTIN" } , 1523ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABRILO BOGDAN" } , 1524ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABRILO BRANISLAV" } , 1525ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABRILO LAZAR" } , 1526ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABRILO LJUBICA" } , 1527ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABRILO SPASOJA" } , 1528ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CADE\\u0160 ZDENKA" } , 1529ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CADESKI BLAGOJE" } , 1530ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CADOVSKI VLADIMIR" } , 1531ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAGLJEVI\\u0106 TOMA" } , 1532ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAGOROVI\\u0106 VLADIMIR" } , 1533ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAJA VANKA" } , 1534ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAJI\\u0106 BOGOLJUB" } , 1535ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAJI\\u0106 BORISLAV" } , 1536ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAJI\\u0106 RADOSLAV" } , 1537ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAK\\u0160IRAN MILADIN" } , 1538ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKAN EUGEN" } , 1539ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKAN EVGENIJE" } , 1540ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKAN IVAN" } , 1541ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKAN JULIJAN" } , 1542ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKAN MIHAJLO" } , 1543ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKAN STEVAN" } , 1544ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKAN VLADIMIR" } , 1545ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKAN VLADIMIR" } , 1546ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKAN VLADIMIR" } , 1547ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKARA ANA" } , 1548ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKAREVI\\u0106 MOMIR" } , 1549ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKAREVI\\u0106 NEDELJKO" } , 1550ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKI \\u0160ANDOR" } , 1551ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKI AMALIJA" } , 1552ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKI ANDRA\\u0160" } , 1553ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKI LADISLAV" } , 1554ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKI LAJO\\u0160" } , 1555ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKI LASLO" } , 1556ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }; 1557ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1558ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1559ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1560ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t i = 0, j = 0, k = 0, buffSize = 0, skSize = 0, lowerSize = 0, upperSize = 0; 1561ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t arraySize = sizeof(tests)/sizeof(tests[0]); 1562ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1563ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status) && coll) { 1564ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i = 0; i<arraySize; i++) { 1565ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru buffSize = u_unescape(tests[i].original, buffer, 512); 1566ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru skSize = ucol_getSortKey(coll, buffer, buffSize, tests[i].key, 512); 1567ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1568ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1569ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru qsort(tests, arraySize, sizeof(struct teststruct), compare_teststruct); 1570ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1571ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i = 0; i < arraySize-1; i++) { 1572ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(j = i+1; j < arraySize; j++) { 1573ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru lowerSize = ucol_getBound(tests[i].key, -1, UCOL_BOUND_LOWER, 1, lower, 512, &status); 1574ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru upperSize = ucol_getBound(tests[j].key, -1, UCOL_BOUND_UPPER, 1, upper, 512, &status); 1575ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(k = i; k <= j; k++) { 1576ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strcmp((const char *)lower, (const char *)tests[k].key) > 0) { 1577ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Problem with lower! j = %i (%s vs %s)\n", k, tests[k].original, tests[i].original); 1578ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1579ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strcmp((const char *)upper, (const char *)tests[k].key) <= 0) { 1580ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Problem with upper! j = %i (%s vs %s)\n", k, tests[k].original, tests[j].original); 1581ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1582ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1583ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1584ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1585ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1586ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1587ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if 0 1588ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i = 0; i < 1000; i++) { 1589ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru lowerRND = (rand()/(RAND_MAX/arraySize)); 1590ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru upperRND = lowerRND + (rand()/(RAND_MAX/(arraySize-lowerRND))); 1591ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1592ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru lowerSize = ucol_getBound(tests[lowerRND].key, -1, UCOL_BOUND_LOWER, 1, lower, 512, &status); 1593ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru upperSize = ucol_getBound(tests[upperRND].key, -1, UCOL_BOUND_UPPER_LONG, 1, upper, 512, &status); 1594ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1595ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(j = lowerRND; j<=upperRND; j++) { 1596ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strcmp(lower, tests[j].key) > 0) { 1597ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Problem with lower! j = %i (%s vs %s)\n", j, tests[j].original, tests[lowerRND].original); 1598ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1599ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strcmp(upper, tests[j].key) <= 0) { 1600ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Problem with upper! j = %i (%s vs %s)\n", j, tests[j].original, tests[upperRND].original); 1601ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1602ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1603ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1604ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 1605ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1606ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1607ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1608ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1609ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1610ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i = 0; i<sizeof(test)/sizeof(test[0]); i++) { 1611ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru buffSize = u_unescape(test[i], buffer, 512); 1612ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru skSize = ucol_getSortKey(coll, buffer, buffSize, sortkey, 512); 1613ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru lowerSize = ucol_getBound(sortkey, skSize, UCOL_BOUND_LOWER, 1, lower, 512, &status); 1614ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru upperSize = ucol_getBound(sortkey, skSize, UCOL_BOUND_UPPER_LONG, 1, upper, 512, &status); 1615ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(j = i+1; j<sizeof(test)/sizeof(test[0]); j++) { 1616ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru buffSize = u_unescape(test[j], buffer, 512); 1617ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru skSize = ucol_getSortKey(coll, buffer, buffSize, sortkey, 512); 1618ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strcmp((const char *)lower, (const char *)sortkey) > 0) { 1619ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Problem with lower! i = %i, j = %i (%s vs %s)\n", i, j, test[i], test[j]); 1620ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1621ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strcmp((const char *)upper, (const char *)sortkey) <= 0) { 1622ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Problem with upper! i = %i, j = %i (%s vs %s)\n", i, j, test[i], test[j]); 1623ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1624ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1625ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1626ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(coll); 1627ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 1628ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_data_err("Couldn't open collator\n"); 1629ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1630ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1631ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1632ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1633ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void doOverrunTest(UCollator *coll, const UChar *uString, int32_t strLen) { 1634ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t skLen = 0, skLen2 = 0; 1635ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t sortKey[256]; 1636ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t i, j; 1637ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t filler = 0xFF; 1638ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1639ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru skLen = ucol_getSortKey(coll, uString, strLen, NULL, 0); 1640ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1641ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i = 0; i < skLen; i++) { 1642ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru memset(sortKey, filler, 256); 1643ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru skLen2 = ucol_getSortKey(coll, uString, strLen, sortKey, i); 1644ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(skLen != skLen2) { 1645ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("For buffer size %i, got different sortkey length. Expected %i got %i\n", i, skLen, skLen2); 1646ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1647ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(j = i; j < 256; j++) { 1648ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(sortKey[j] != filler) { 1649ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Something run over index %i\n", j); 1650ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru break; 1651ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1652ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1653ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1654ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1655ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1656ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* j1865 reports that if a shorter buffer is passed to 165785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho* to get sort key, a buffer overrun happens in some 1658ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* cases. This test tries to check this. 1659ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/ 1660ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestSortKeyBufferOverrun(void) { 1661ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 1662ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* cString = "A very Merry liTTle-lamB.."; 1663ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar uString[256]; 1664ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t strLen = 0; 1665ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *coll = ucol_open("root", &status); 1666ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strLen = u_unescape(cString, uString, 256); 1667ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1668ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)) { 1669ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("testing non ignorable\n"); 1670ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_ALTERNATE_HANDLING, UCOL_NON_IGNORABLE, &status); 1671ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doOverrunTest(coll, uString, strLen); 1672ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1673ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("testing shifted\n"); 1674ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_ALTERNATE_HANDLING, UCOL_SHIFTED, &status); 1675ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doOverrunTest(coll, uString, strLen); 1676ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1677ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("testing shifted quaternary\n"); 1678ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_STRENGTH, UCOL_QUATERNARY, &status); 1679ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doOverrunTest(coll, uString, strLen); 1680ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1681ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("testing with french secondaries\n"); 1682ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_FRENCH_COLLATION, UCOL_ON, &status); 1683ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_STRENGTH, UCOL_TERTIARY, &status); 1684ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_ALTERNATE_HANDLING, UCOL_NON_IGNORABLE, &status); 1685ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doOverrunTest(coll, uString, strLen); 1686ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1687ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1688ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(coll); 1689ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1690ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1691ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestAttribute() 1692ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 1693ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode error = U_ZERO_ERROR; 1694ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *coll = ucol_open(NULL, &error); 1695ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1696ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(error)) { 169785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(error, "Creation of default collator failed\n"); 1698ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1699ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1700ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1701ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_FRENCH_COLLATION, UCOL_OFF, &error); 1702ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getAttribute(coll, UCOL_FRENCH_COLLATION, &error) != UCOL_OFF || 1703ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_FAILURE(error)) { 170485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(error, "Setting and retrieving of the french collation failed\n"); 1705ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1706ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1707ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_FRENCH_COLLATION, UCOL_ON, &error); 1708ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getAttribute(coll, UCOL_FRENCH_COLLATION, &error) != UCOL_ON || 1709ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_FAILURE(error)) { 171085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(error, "Setting and retrieving of the french collation failed\n"); 1711ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1712ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1713ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_ALTERNATE_HANDLING, UCOL_SHIFTED, &error); 1714ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getAttribute(coll, UCOL_ALTERNATE_HANDLING, &error) != UCOL_SHIFTED || 1715ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_FAILURE(error)) { 171685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(error, "Setting and retrieving of the alternate handling failed\n"); 1717ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1718ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1719ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_ALTERNATE_HANDLING, UCOL_NON_IGNORABLE, &error); 1720ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getAttribute(coll, UCOL_ALTERNATE_HANDLING, &error) != UCOL_NON_IGNORABLE || 1721ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_FAILURE(error)) { 172285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(error, "Setting and retrieving of the alternate handling failed\n"); 1723ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1724ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1725ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_CASE_FIRST, UCOL_LOWER_FIRST, &error); 1726ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getAttribute(coll, UCOL_CASE_FIRST, &error) != UCOL_LOWER_FIRST || 1727ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_FAILURE(error)) { 172885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(error, "Setting and retrieving of the case first attribute failed\n"); 1729ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1730ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1731ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_CASE_FIRST, UCOL_UPPER_FIRST, &error); 1732ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getAttribute(coll, UCOL_CASE_FIRST, &error) != UCOL_UPPER_FIRST || 1733ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_FAILURE(error)) { 173485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(error, "Setting and retrieving of the case first attribute failed\n"); 1735ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1736ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1737ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_CASE_LEVEL, UCOL_ON, &error); 1738ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getAttribute(coll, UCOL_CASE_LEVEL, &error) != UCOL_ON || 1739ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_FAILURE(error)) { 174085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(error, "Setting and retrieving of the case level attribute failed\n"); 1741ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1742ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1743ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_CASE_LEVEL, UCOL_OFF, &error); 1744ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getAttribute(coll, UCOL_CASE_LEVEL, &error) != UCOL_OFF || 1745ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_FAILURE(error)) { 174685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(error, "Setting and retrieving of the case level attribute failed\n"); 1747ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1748ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1749ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_NORMALIZATION_MODE, UCOL_ON, &error); 1750ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getAttribute(coll, UCOL_NORMALIZATION_MODE, &error) != UCOL_ON || 1751ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_FAILURE(error)) { 175285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(error, "Setting and retrieving of the normalization on/off attribute failed\n"); 1753ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1754ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1755ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_NORMALIZATION_MODE, UCOL_OFF, &error); 1756ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getAttribute(coll, UCOL_NORMALIZATION_MODE, &error) != UCOL_OFF || 1757ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_FAILURE(error)) { 175885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(error, "Setting and retrieving of the normalization on/off attribute failed\n"); 1759ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1760ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1761ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_STRENGTH, UCOL_PRIMARY, &error); 1762ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getAttribute(coll, UCOL_STRENGTH, &error) != UCOL_PRIMARY || 1763ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_FAILURE(error)) { 176485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(error, "Setting and retrieving of the collation strength failed\n"); 1765ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1766ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1767ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_STRENGTH, UCOL_SECONDARY, &error); 1768ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getAttribute(coll, UCOL_STRENGTH, &error) != UCOL_SECONDARY || 1769ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_FAILURE(error)) { 177085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(error, "Setting and retrieving of the collation strength failed\n"); 1771ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1772ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1773ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_STRENGTH, UCOL_TERTIARY, &error); 1774ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getAttribute(coll, UCOL_STRENGTH, &error) != UCOL_TERTIARY || 1775ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_FAILURE(error)) { 177685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(error, "Setting and retrieving of the collation strength failed\n"); 1777ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1778ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1779ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_STRENGTH, UCOL_QUATERNARY, &error); 1780ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getAttribute(coll, UCOL_STRENGTH, &error) != UCOL_QUATERNARY || 1781ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_FAILURE(error)) { 178285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(error, "Setting and retrieving of the collation strength failed\n"); 1783ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1784ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1785ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_STRENGTH, UCOL_IDENTICAL, &error); 1786ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getAttribute(coll, UCOL_STRENGTH, &error) != UCOL_IDENTICAL || 1787ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_FAILURE(error)) { 178885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(error, "Setting and retrieving of the collation strength failed\n"); 1789ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1790ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1791ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(coll); 1792ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1793ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1794ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestGetTailoredSet() { 1795ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru struct { 1796ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *rules; 1797ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *tests[20]; 1798ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t testsize; 1799ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } setTest[] = { 1800ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { "&a < \\u212b", { "\\u212b", "A\\u030a", "\\u00c5" }, 3}, 1801ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { "& S < \\u0161 <<< \\u0160", { "\\u0161", "s\\u030C", "\\u0160", "S\\u030C" }, 4} 1802ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }; 1803ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1804ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t i = 0, j = 0; 1805ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 1806ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UParseError pError; 1807ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1808ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *coll = NULL; 1809ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar buff[1024]; 1810ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t buffLen = 0; 1811ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru USet *set = NULL; 1812ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1813ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i = 0; i < sizeof(setTest)/sizeof(setTest[0]); i++) { 1814ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru buffLen = u_unescape(setTest[i].rules, buff, 1024); 1815ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru coll = ucol_openRules(buff, buffLen, UCOL_DEFAULT, UCOL_DEFAULT, &pError, &status); 1816ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)) { 1817ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru set = ucol_getTailoredSet(coll, &status); 1818ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(uset_size(set) != setTest[i].testsize) { 1819ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Tailored set size different (%d) than expected (%d)\n", uset_size(set), setTest[i].testsize); 1820ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1821ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(j = 0; j < setTest[i].testsize; j++) { 1822ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru buffLen = u_unescape(setTest[i].tests[j], buff, 1024); 1823ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(!uset_containsString(set, buff, buffLen)) { 1824ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Tailored set doesn't contain %s... It should\n", setTest[i].tests[j]); 1825ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1826ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1827ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uset_close(set); 1828ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 182985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "Couldn't open collator with rules %s\n", setTest[i].rules); 1830ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1831ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(coll); 1832ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1833ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1834ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1835ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic int tMemCmp(const uint8_t *first, const uint8_t *second) { 1836ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t firstLen = (int32_t)strlen((const char *)first); 1837ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t secondLen = (int32_t)strlen((const char *)second); 1838ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return memcmp(first, second, uprv_min(firstLen, secondLen)); 1839ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1840ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic const char * strengthsC[] = { 1841ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "UCOL_PRIMARY", 1842ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "UCOL_SECONDARY", 1843ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "UCOL_TERTIARY", 1844ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "UCOL_QUATERNARY", 1845ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "UCOL_IDENTICAL" 1846ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 184785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1848ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestMergeSortKeys(void) { 1849ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 1850ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *coll = ucol_open("en", &status); 1851ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)) { 185285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1853ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* cases[] = { 1854ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "abc", 1855ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "abcd", 1856ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "abcde" 1857ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }; 1858ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t casesSize = sizeof(cases)/sizeof(cases[0]); 1859ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* prefix = "foo"; 1860ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* suffix = "egg"; 1861ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char outBuff1[256], outBuff2[256]; 186285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1863ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t **sortkeys = (uint8_t **)malloc(casesSize*sizeof(uint8_t *)); 1864ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t **mergedPrefixkeys = (uint8_t **)malloc(casesSize*sizeof(uint8_t *)); 1865ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t **mergedSuffixkeys = (uint8_t **)malloc(casesSize*sizeof(uint8_t *)); 1866ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t *sortKeysLen = (uint32_t *)malloc(casesSize*sizeof(uint32_t)); 1867ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t prefixKey[256], suffixKey[256]; 1868ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t prefixKeyLen = 0, suffixKeyLen = 0, i = 0; 1869ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar buffer[256]; 1870ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t unescapedLen = 0, l1 = 0, l2 = 0; 1871ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UColAttributeValue strength; 187285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1873ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("ucol_mergeSortkeys test\n"); 1874ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Testing order of the test cases\n"); 1875ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru genericLocaleStarter("en", cases, casesSize); 187685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1877ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i = 0; i<casesSize; i++) { 1878ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortkeys[i] = (uint8_t *)malloc(256*sizeof(uint8_t)); 1879ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru mergedPrefixkeys[i] = (uint8_t *)malloc(256*sizeof(uint8_t)); 1880ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru mergedSuffixkeys[i] = (uint8_t *)malloc(256*sizeof(uint8_t)); 1881ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 188285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1883ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru unescapedLen = u_unescape(prefix, buffer, 256); 1884ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru prefixKeyLen = ucol_getSortKey(coll, buffer, unescapedLen, prefixKey, 256); 188585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1886ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru unescapedLen = u_unescape(suffix, buffer, 256); 1887ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru suffixKeyLen = ucol_getSortKey(coll, buffer, unescapedLen, suffixKey, 256); 188885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1889ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Massaging data with prefixes and different strengths\n"); 1890ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strength = UCOL_PRIMARY; 1891ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru while(strength <= UCOL_IDENTICAL) { 1892ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Strength %s\n", strengthsC[strength<=UCOL_QUATERNARY?strength:4]); 1893ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_STRENGTH, strength, &status); 1894ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i = 0; i<casesSize; i++) { 1895ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru unescapedLen = u_unescape(cases[i], buffer, 256); 1896ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortKeysLen[i] = ucol_getSortKey(coll, buffer, unescapedLen, sortkeys[i], 256); 1897ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_mergeSortkeys(prefixKey, prefixKeyLen, sortkeys[i], sortKeysLen[i], mergedPrefixkeys[i], 256); 1898ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_mergeSortkeys(sortkeys[i], sortKeysLen[i], suffixKey, suffixKeyLen, mergedSuffixkeys[i], 256); 1899ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(i>0) { 1900ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(tMemCmp(mergedPrefixkeys[i-1], mergedPrefixkeys[i]) >= 0) { 1901ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Error while comparing prefixed keys @ strength %s:\n", strengthsC[strength<=UCOL_QUATERNARY?strength:4]); 190285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("%s\n%s\n", 1903ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_sortKeyToString(coll, mergedPrefixkeys[i-1], outBuff1, &l1), 1904ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_sortKeyToString(coll, mergedPrefixkeys[i], outBuff2, &l2)); 1905ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1906ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(tMemCmp(mergedSuffixkeys[i-1], mergedSuffixkeys[i]) >= 0) { 1907ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Error while comparing suffixed keys @ strength %s:\n", strengthsC[strength<=UCOL_QUATERNARY?strength:4]); 190885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("%s\n%s\n", 1909ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_sortKeyToString(coll, mergedSuffixkeys[i-1], outBuff1, &l1), 1910ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_sortKeyToString(coll, mergedSuffixkeys[i], outBuff2, &l2)); 1911ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1912ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1913ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1914ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strength == UCOL_QUATERNARY) { 1915ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strength = UCOL_IDENTICAL; 1916ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 1917ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strength++; 1918ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1919ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 192085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1921ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1922ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t smallBuf[3]; 1923ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t reqLen = 0; 1924ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("testing buffer overflow\n"); 1925ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru reqLen = ucol_mergeSortkeys(prefixKey, prefixKeyLen, suffixKey, suffixKeyLen, smallBuf, 3); 1926ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(reqLen != (prefixKeyLen+suffixKeyLen-1)) { 1927ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Wrong preflight size for merged sortkey\n"); 1928ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1929ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 193085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1931ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1932ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar empty = 0; 1933ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t emptyKey[20], abcKey[50], mergedKey[100]; 1934ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t emptyKeyLen = 0, abcKeyLen = 0, mergedKeyLen = 0; 193585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1936ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("testing merging with sortkeys generated for empty strings\n"); 1937ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru emptyKeyLen = ucol_getSortKey(coll, &empty, 0, emptyKey, 20); 1938ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru unescapedLen = u_unescape(cases[0], buffer, 256); 1939ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru abcKeyLen = ucol_getSortKey(coll, buffer, unescapedLen, abcKey, 50); 1940ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru mergedKeyLen = ucol_mergeSortkeys(emptyKey, emptyKeyLen, abcKey, abcKeyLen, mergedKey, 100); 1941ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(mergedKey[0] != 2) { 1942ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Empty sortkey didn't produce a level separator\n"); 1943ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1944ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* try with zeros */ 1945ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru mergedKeyLen = ucol_mergeSortkeys(emptyKey, 0, abcKey, abcKeyLen, mergedKey, 100); 1946ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(mergedKeyLen != 0 || mergedKey[0] != 0) { 1947ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Empty key didn't produce null mergedKey\n"); 1948ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1949ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru mergedKeyLen = ucol_mergeSortkeys(abcKey, abcKeyLen, emptyKey, 0, mergedKey, 100); 1950ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(mergedKeyLen != 0 || mergedKey[0] != 0) { 1951ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Empty key didn't produce null mergedKey\n"); 1952ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 195385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1954ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 195585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1956ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i = 0; i<casesSize; i++) { 1957ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(sortkeys[i]); 1958ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(mergedPrefixkeys[i]); 1959ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(mergedSuffixkeys[i]); 1960ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1961ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(sortkeys); 1962ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(mergedPrefixkeys); 1963ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(mergedSuffixkeys); 1964ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(sortKeysLen); 1965ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(coll); 1966ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* need to finish this up */ 1967ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 1968ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_data_err("Couldn't open collator"); 1969ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1970ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 197185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic void TestShortString(void) 1972ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 1973ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru struct { 1974ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *input; 1975ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *expectedOutput; 1976ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *locale; 1977ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode expectedStatus; 1978ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t expectedOffset; 1979ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t expectedIdentifier; 1980ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } testCases[] = { 198185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho {"LDE_RDE_KPHONEBOOK_T0041_ZLATN","B2C00_KPHONEBOOK_LDE", "de@collation=phonebook", U_USING_FALLBACK_WARNING, 0, 0 }, 1982ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"LEN_RUS_NO_AS_S4","AS_LEN_NO_S4", NULL, U_USING_FALLBACK_WARNING, 0, 0 }, 1983ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"LDE_VPHONEBOOK_EO_SI","EO_KPHONEBOOK_LDE_SI", "de@collation=phonebook", U_ZERO_ERROR, 0, 0 }, 1984ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"LDE_Kphonebook","KPHONEBOOK_LDE", "de@collation=phonebook", U_ZERO_ERROR, 0, 0 }, 1985ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"Xqde_DE@collation=phonebookq_S3_EX","KPHONEBOOK_LDE", "de@collation=phonebook", U_USING_FALLBACK_WARNING, 0, 0 }, 1986ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"LFR_FO", "LFR", NULL, U_ZERO_ERROR, 0, 0 }, 1987ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"SO_LX_AS", "", NULL, U_ILLEGAL_ARGUMENT_ERROR, 8, 0 }, 1988ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"S3_ASS_MMM", "", NULL, U_ILLEGAL_ARGUMENT_ERROR, 5, 0 } 1989ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }; 1990ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 199185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho int32_t i = 0; 199285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UCollator *coll = NULL, *fromNormalized = NULL; 1993ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UParseError parseError; 1994ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 199585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho char fromShortBuffer[256], normalizedBuffer[256], fromNormalizedBuffer[256]; 1996ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* locale = NULL; 1997ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1998ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1999ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i = 0; i < sizeof(testCases)/sizeof(testCases[0]); i++) { 2000ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 2001ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(testCases[i].locale) { 2002ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru locale = testCases[i].locale; 2003ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 2004ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru locale = NULL; 2005ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2006ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2007ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru coll = ucol_openFromShortString(testCases[i].input, FALSE, &parseError, &status); 2008ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status != testCases[i].expectedStatus) { 200985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "Got status '%s' that is different from expected '%s' for '%s'\n", 2010ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_errorName(status), u_errorName(testCases[i].expectedStatus), testCases[i].input); 201185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho continue; 2012ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 201385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 2014ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)) { 2015ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_getShortDefinitionString(coll, locale, fromShortBuffer, 256, &status); 2016ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2017ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strcmp(fromShortBuffer, testCases[i].expectedOutput)) { 2018ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Got short string '%s' from the collator. Expected '%s' for input '%s'\n", 2019ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fromShortBuffer, testCases[i].expectedOutput, testCases[i].input); 2020ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2021ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2022ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_normalizeShortDefinitionString(testCases[i].input, normalizedBuffer, 256, &parseError, &status); 2023ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fromNormalized = ucol_openFromShortString(normalizedBuffer, FALSE, &parseError, &status); 2024ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_getShortDefinitionString(fromNormalized, locale, fromNormalizedBuffer, 256, &status); 2025ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2026ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strcmp(fromShortBuffer, fromNormalizedBuffer)) { 202785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("Strings obtained from collators instantiated by short string ('%s') and from normalized string ('%s') differ\n", 2028ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fromShortBuffer, fromNormalizedBuffer); 2029ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2030ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2031ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2032ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(!ucol_equals(coll, fromNormalized)) { 203385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("Collator from short string ('%s') differs from one obtained through a normalized version ('%s')\n", 2034ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru testCases[i].input, normalizedBuffer); 2035ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2036ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2037ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(fromNormalized); 2038ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(coll); 2039ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2040ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 2041ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(parseError.offset != testCases[i].expectedOffset) { 2042ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Got parse error offset %i, but expected %i instead for '%s'\n", 2043ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru parseError.offset, testCases[i].expectedOffset, testCases[i].input); 2044ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2045ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2046ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2047ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2048ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 2049ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2050ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void 2051ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerudoSetsTest(const char *locale, const USet *ref, USet *set, const char* inSet, const char* outSet, UErrorCode *status) { 2052ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar buffer[512]; 2053ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t bufLen; 2054ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2055ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uset_clear(set); 205685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho bufLen = u_unescape(inSet, buffer, 512); 2057ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uset_applyPattern(set, buffer, bufLen, 0, status); 2058ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(*status)) { 2059ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("%s: Failure setting pattern %s\n", locale, u_errorName(*status)); 2060ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2061ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2062ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(!uset_containsAll(ref, set)) { 2063ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("%s: Some stuff from %s is not present in the set\n", locale, inSet); 2064ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2065ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2066ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uset_clear(set); 206785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho bufLen = u_unescape(outSet, buffer, 512); 2068ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uset_applyPattern(set, buffer, bufLen, 0, status); 2069ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(*status)) { 2070ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("%s: Failure setting pattern %s\n", locale, u_errorName(*status)); 2071ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2072ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2073ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(!uset_containsNone(ref, set)) { 2074ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("%s: Some stuff from %s is present in the set\n", locale, outSet); 2075ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2076ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 2077ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2078ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2079ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2080ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 208185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic void 208285bf2e2fbc60a9f938064abc8127d61da7d19882Claire HoTestGetContractionsAndUnsafes(void) 2083ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 2084ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static struct { 2085ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* locale; 2086ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* inConts; 2087ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* outConts; 2088ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* inExp; 2089ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* outExp; 2090ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* unsafeCodeUnits; 2091ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* safeCodeUnits; 2092ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } tests[] = { 209385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho { "ru", 209485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho "[{\\u0474\\u030F}{\\u0475\\u030F}{\\u04D8\\u0308}{\\u04D9\\u0308}{\\u04E8\\u0308}{\\u04E9\\u0308}]", 2095ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[{\\u0430\\u0306}{\\u0410\\u0306}{\\u0430\\u0308}{\\u0410\\u0306}{\\u0433\\u0301}{\\u0413\\u0301}]", 2096ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[\\u00e6]", 2097ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[a]", 2098ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[\\u0474\\u0475\\u04d8\\u04d9\\u04e8\\u04e9]", 2099ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[aAbB\\u0430\\u0410\\u0433\\u0413]" 2100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }, 2101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { "uk", 210285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho "[{\\u0474\\u030F}{\\u0475\\u030F}{\\u04D8\\u0308}{\\u04D9\\u0308}{\\u04E8\\u0308}{\\u04E9\\u0308}" 2103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "{\\u0430\\u0306}{\\u0410\\u0306}{\\u0430\\u0308}{\\u0410\\u0306}{\\u0433\\u0301}{\\u0413\\u0301}]", 2104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[]", 2105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[\\u00e6]", 2106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[a]", 2107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[\\u0474\\u0475\\u04D8\\u04D9\\u04E8\\u04E9\\u0430\\u0410\\u0433\\u0413]", 2108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[aAbBxv]", 2109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }, 2110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { "sh", 2111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[{C\\u0301}{C\\u030C}{C\\u0341}{DZ\\u030C}{Dz\\u030C}{D\\u017D}{D\\u017E}{lj}{nj}]", 2112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[{\\u309d\\u3099}{\\u30fd\\u3099}]", 2113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[\\u00e6]", 2114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[a]", 2115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[nlcdzNLCDZ]", 2116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[jabv]" 2117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }, 2118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { "ja", 2119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[{\\u3053\\u3099\\u309D}{\\u3053\\u3099\\u309D\\u3099}{\\u3053\\u3099\\u309E}{\\u3053\\u3099\\u30FC}{\\u3053\\u309D}{\\u3053\\u309D\\u3099}{\\u3053\\u309E}{\\u3053\\u30FC}{\\u30B3\\u3099\\u30FC}{\\u30B3\\u3099\\u30FD}{\\u30B3\\u3099\\u30FD\\u3099}{\\u30B3\\u3099\\u30FE}{\\u30B3\\u30FC}{\\u30B3\\u30FD}{\\u30B3\\u30FD\\u3099}{\\u30B3\\u30FE}]", 2120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[{\\u30FD\\u3099}{\\u309D\\u3099}{\\u3053\\u3099}{\\u30B3\\u3099}{lj}{nj}]", 2121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[\\u30FE\\u00e6]", 2122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[a]", 2123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[\\u3099]", 2124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[]" 2125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }; 2127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 2132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *coll = NULL; 2133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t i = 0; 2134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t noConts = 0; 2135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru USet *conts = uset_open(0,0); 2136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru USet *exp = uset_open(0, 0); 2137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru USet *set = uset_open(0,0); 2138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t setBufferLen = 65536; 2139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar buffer[65536]; 2140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t setLen = 0; 2141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) { 2143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Testing locale: %s\n", tests[i].locale); 2144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru coll = ucol_open(tests[i].locale, &status); 214585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if (coll == NULL || U_FAILURE(status)) { 214685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "Unable to open collator for locale %s ==> %s\n", tests[i].locale, u_errorName(status)); 214785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho continue; 214885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 2149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_getContractionsAndExpansions(coll, conts, exp, TRUE, &status); 2150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doSetsTest(tests[i].locale, conts, set, tests[i].inConts, tests[i].outConts, &status); 2151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru setLen = uset_toPattern(conts, buffer, setBufferLen, TRUE, &status); 2152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)) { 2153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*log_verbose("Contractions %i: %s\n", uset_getItemCount(conts), aescstrdup(buffer, setLen));*/ 2154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 2155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("error %s. %i\n", u_errorName(status), setLen); 2156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 2157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doSetsTest(tests[i].locale, exp, set, tests[i].inExp, tests[i].outExp, &status); 2159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru setLen = uset_toPattern(exp, buffer, setBufferLen, TRUE, &status); 2160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)) { 2161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*log_verbose("Expansions %i: %s\n", uset_getItemCount(exp), aescstrdup(buffer, setLen));*/ 2162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 2163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("error %s. %i\n", u_errorName(status), setLen); 2164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 2165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru noConts = ucol_getUnsafeSet(coll, conts, &status); 2168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doSetsTest(tests[i].locale, conts, set, tests[i].unsafeCodeUnits, tests[i].safeCodeUnits, &status); 2169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru setLen = uset_toPattern(conts, buffer, setBufferLen, TRUE, &status); 2170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)) { 2171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Unsafe %i: %s\n", uset_getItemCount(exp), aescstrdup(buffer, setLen)); 2172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 2173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("error %s. %i\n", u_errorName(status), setLen); 2174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 2175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(coll); 2178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uset_close(conts); 2182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uset_close(exp); 2183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uset_close(set); 2184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 2185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 218685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic void 218785bf2e2fbc60a9f938064abc8127d61da7d19882Claire HoTestOpenBinary(void) 2188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 2189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 2190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* 2191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char rule[] = "&h < d < c < b"; 2192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char *wUCA[] = { "a", "h", "d", "c", "b", "i" }; 2193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char *noUCA[] = {"d", "c", "b", "a", "h", "i" }; 2194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 2195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* we have to use Cyrillic letters because latin-1 always gets copied */ 2196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char rule[] = "&\\u0452 < \\u0434 < \\u0433 < \\u0432"; /* &dje < d < g < v */ 2197ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *wUCA[] = { "\\u0430", "\\u0452", "\\u0434", "\\u0433", "\\u0432", "\\u0435" }; /* a, dje, d, g, v, e */ 2198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *noUCA[] = {"\\u0434", "\\u0433", "\\u0432", "\\u0430", "\\u0435", "\\u0452" }; /* d, g, v, a, e, dje */ 2199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar uRules[256]; 2201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t uRulesLen = u_unescape(rule, uRules, 256); 2202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *coll = ucol_openRules(uRules, uRulesLen, UCOL_DEFAULT, UCOL_DEFAULT, NULL, &status); 220485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UCollator *UCA = NULL; 2205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *cloneNOUCA = NULL, *cloneWUCA = NULL; 2206ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t imageBuffer[32768]; 2208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t *image = imageBuffer; 2209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t imageBufferCapacity = 32768; 2210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t imageSize; 2212ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 221385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if((coll==NULL)||(U_FAILURE(status))) { 2214ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_data_err("could not load collators or error occured: %s\n", 2215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_errorName(status)); 2216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 221785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 221885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UCA = ucol_open("root", &status); 221985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if((UCA==NULL)||(U_FAILURE(status))) { 222085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_data_err("could not load UCA collator or error occured: %s\n", 222185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho u_errorName(status)); 222285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho return; 222385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 2224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru imageSize = ucol_cloneBinary(coll, image, imageBufferCapacity, &status); 2225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 2226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru image = (uint8_t *)malloc(imageSize*sizeof(uint8_t)); 2227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 2228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru imageSize = ucol_cloneBinary(coll, imageBuffer, imageSize, &status); 2229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru cloneWUCA = ucol_openBinary(image, imageSize, UCA, &status); 2233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru cloneNOUCA = ucol_openBinary(image, imageSize, NULL, &status); 2234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru genericOrderingTest(coll, wUCA, sizeof(wUCA)/sizeof(wUCA[0])); 2236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru genericOrderingTest(cloneWUCA, wUCA, sizeof(wUCA)/sizeof(wUCA[0])); 2238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru genericOrderingTest(cloneNOUCA, noUCA, sizeof(noUCA)/sizeof(noUCA[0])); 2239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(image != imageBuffer) { 2241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(image); 2242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(coll); 2244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(cloneNOUCA); 2245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(cloneWUCA); 2246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(UCA); 2247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 2248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestDefault(void) { 2250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Tests for code coverage. */ 2251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 2252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *coll = ucol_open("es@collation=pinyin", &status); 225385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if (coll == NULL || status == U_FILE_ACCESS_ERROR) { 225485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_data_err("Unable to open collator es@collation=pinyin\n"); 225585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho return; 225685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 2257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (status != U_USING_DEFAULT_WARNING) { 2258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* What do you mean that you know about using pinyin collation in Spanish!? This should be in the zh locale. */ 2259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("es@collation=pinyin should return U_USING_DEFAULT_WARNING, but returned %s\n", u_errorName(status)); 2260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(coll); 2262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getKeywordValues("funky", &status) != NULL) { 2263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Collators should not know about the funky keyword.\n"); 2264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (status != U_ILLEGAL_ARGUMENT_ERROR) { 2266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("funky keyword didn't fail as expected %s\n", u_errorName(status)); 2267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getKeywordValues("collation", &status) != NULL) { 2269ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ucol_getKeywordValues should not work when given a bad status.\n"); 2270ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 2272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 227385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic void TestDefaultKeyword(void) { 227485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* Tests for code coverage. */ 227585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UErrorCode status = U_ZERO_ERROR; 227685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho const char *loc = "zh_TW@collation=default"; 227785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UCollator *coll = ucol_open(loc, &status); 227885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if(U_FAILURE(status)) { 227985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_info("Warning: ucol_open(%s, ...) returned %s, at least it didn't crash.\n", loc, u_errorName(status)); 228085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } else if (status != U_USING_FALLBACK_WARNING) { 228185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("ucol_open(%s, ...) should return an error or some sort of U_USING_FALLBACK_WARNING, but returned %s\n", loc, u_errorName(status)); 228285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 228385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho ucol_close(coll); 228485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho} 228585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 228685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic void TestGetKeywordValuesForLocale(void) { 228785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho#define PREFERRED_SIZE 16 228885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho#define MAX_NUMBER_OF_KEYWORDS 6 228985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho const char *PREFERRED[PREFERRED_SIZE][MAX_NUMBER_OF_KEYWORDS+1] = { 229085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho { "und", "standard", NULL, NULL, NULL, NULL, NULL }, 229185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho { "en_US", "standard", NULL, NULL, NULL, NULL, NULL }, 229285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho { "en_029", "standard", NULL, NULL, NULL, NULL, NULL }, 229385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho { "de_DE", "standard", "phonebook", NULL, NULL, NULL, NULL }, 229485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho { "de_Latn_DE", "standard", "phonebook", NULL, NULL, NULL, NULL }, 229585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho { "zh", "pinyin", "big5han", "gb2312han", "standard", "stroke", "unihan" }, 229685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho { "zh_Hans", "pinyin", "big5han", "gb2312han", "standard", "stroke", "unihan" }, 229785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho { "zh_CN", "pinyin", "big5han", "gb2312han", "standard", "stroke", "unihan" }, 229885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho { "zh_Hant", "stroke", "big5han", "gb2312han", "pinyin", "standard", "unihan" }, 229985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho { "zh_TW", "stroke", "big5han", "gb2312han", "pinyin", "standard", "unihan" }, 230085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho { "zh__PINYIN", "pinyin", "big5han", "gb2312han", "standard", "stroke", "unihan" }, 230185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho { "es_ES", "standard", "traditional", NULL, NULL, NULL, NULL }, 230285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho { "es__TRADITIONAL","traditional", "standard", NULL, NULL, NULL, NULL }, 230385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho { "und@collation=phonebook", "standard", NULL, NULL, NULL, NULL, NULL }, 230485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho { "de_DE@collation=big5han", "standard", "phonebook", NULL, NULL, NULL, NULL }, 230585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho { "zzz@collation=xxx", "standard", NULL, NULL, NULL, NULL, NULL } 230685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho }; 230785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho const int32_t expectedLength[PREFERRED_SIZE] = { 1, 1, 1, 2, 2, 6, 6, 6, 6, 6, 6, 2, 2, 1, 2, 1 }; 230885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 230985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UErrorCode status = U_ZERO_ERROR; 231085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UEnumeration *keywordValues = NULL; 231185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho int32_t i, n, size, valueLength; 231285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho const char *locale = NULL, *value = NULL; 231385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UBool errorOccurred = FALSE; 231485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 231585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho for (i = 0; i < PREFERRED_SIZE; i++) { 231685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho locale = PREFERRED[i][0]; 231785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho value = NULL; 231885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho valueLength = 0; 231985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho size = 0; 232085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 232185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho keywordValues = ucol_getKeywordValuesForLocale("collation", locale, TRUE, &status); 232285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if (keywordValues == NULL || U_FAILURE(status)) { 232385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "Error getting keyword values: %s\n", u_errorName(status)); 232485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho break; 232585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 232685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho size = uenum_count(keywordValues, &status); 232785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 232885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if (size == expectedLength[i]) { 232985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho for (n = 0; n < expectedLength[i]; n++) { 233085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if ((value = uenum_next(keywordValues, &valueLength, &status)) != NULL && U_SUCCESS(status)) { 233185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if (uprv_strcmp(value, PREFERRED[i][n+1]) != 0) { 233285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("Keyword values differ: Got [%s] Expected [%s] for locale: %s\n", value, PREFERRED[i][n+1], locale); 233385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho errorOccurred = TRUE; 233485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho break; 233585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 233685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 233785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } else { 233885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("While getting keyword value from locale: %s got this error: %s\n", locale, u_errorName(status)); 233985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho errorOccurred = TRUE; 234085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho break; 234185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 234285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 234385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if (errorOccurred) { 234485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho break; 234585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 234685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } else { 234785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("Number of keywords (%d) does not match expected size (%d) for locale: %s\n", size, expectedLength[i], locale); 234885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho break; 234985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 235085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho uenum_close(keywordValues); 235185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho keywordValues = NULL; 235285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 235385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if (keywordValues != NULL) { 235485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho uenum_close(keywordValues); 235585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 235685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho} 235785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 235885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 2359ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif /* #if !UCONFIG_NO_COLLATION */ 2360