1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/******************************************************************** 28393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius * Copyright (c) 1997-2013, 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" 3227f654740f2a26ad62a5c155af9199af9e69b889claireho#include "cmemory.h" 3385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho#include "cstring.h" 34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestAttribute(void); 36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestDefault(void); 3785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic void TestDefaultKeyword(void); 38b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2clairehostatic void TestBengaliSortKey(void); 39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int TestBufferSize(); /* defined in "colutil.c" */ 40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 42103e9ffba2cba345d0078eb8b8db33249f81840aCraig Corneliusstatic char* U_EXPORT2 ucol_sortKeyToString(const UCollator *coll, const uint8_t *sortkey, char *buffer, uint32_t len) { 43103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius uint32_t position = 0; 44103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius uint8_t b; 4585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 46103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius if (position + 1 < len) 47103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius position += sprintf(buffer + position, "["); 48103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius while ((b = *sortkey++) != 0) { 49103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius if (b == 1 && position + 5 < len) { 50103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius position += sprintf(buffer + position, "%02X . ", b); 51103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius } else if (b != 1 && position + 3 < len) { 52103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius position += sprintf(buffer + position, "%02X ", b); 53103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius } 54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 55103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius if (position + 3 < len) 56103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius position += sprintf(buffer + position, "%02X]", b); 57103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius return buffer; 58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid addCollAPITest(TestNode** root) 61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* WEIVTODO: return tests here */ 63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestProperty, "tscoll/capitst/TestProperty"); 64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestRuleBasedColl, "tscoll/capitst/TestRuleBasedColl"); 65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestCompare, "tscoll/capitst/TestCompare"); 66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestSortKey, "tscoll/capitst/TestSortKey"); 67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestHashCode, "tscoll/capitst/TestHashCode"); 68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestElemIter, "tscoll/capitst/TestElemIter"); 69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestGetAll, "tscoll/capitst/TestGetAll"); 70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*addTest(root, &TestGetDefaultRules, "tscoll/capitst/TestGetDefaultRules");*/ 71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestDecomposition, "tscoll/capitst/TestDecomposition"); 72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestSafeClone, "tscoll/capitst/TestSafeClone"); 73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestCloneBinary, "tscoll/capitst/TestCloneBinary"); 74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestGetSetAttr, "tscoll/capitst/TestGetSetAttr"); 75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestBounds, "tscoll/capitst/TestBounds"); 76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestGetLocale, "tscoll/capitst/TestGetLocale"); 77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestSortKeyBufferOverrun, "tscoll/capitst/TestSortKeyBufferOverrun"); 78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestAttribute, "tscoll/capitst/TestAttribute"); 79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestGetTailoredSet, "tscoll/capitst/TestGetTailoredSet"); 80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestMergeSortKeys, "tscoll/capitst/TestMergeSortKeys"); 81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestShortString, "tscoll/capitst/TestShortString"); 82ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho /* BEGIN android-removed 83ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho To save space, Android does not include the collation tailoring rules. 84ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho We skip the tailing tests for collations. */ 85ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho /* addTest(root, &TestGetContractionsAndUnsafes, "tscoll/capitst/TestGetContractionsAndUnsafes"); */ 86ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho /* END android-removed */ 87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestOpenBinary, "tscoll/capitst/TestOpenBinary"); 88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru addTest(root, &TestDefault, "tscoll/capitst/TestDefault"); 8985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho addTest(root, &TestDefaultKeyword, "tscoll/capitst/TestDefaultKeyword"); 90ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho /* BEGIN android-removed 91ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho To save space, Android does not build full collation tables and tailing rules. 92ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho We skip the related tests. */ 93ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho /* addTest(root, &TestOpenVsOpenRules, "tscoll/capitst/TestOpenVsOpenRules"); */ 94ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho /* addTest(root, &TestGetKeywordValuesForLocale, "tscoll/capitst/TestGetKeywordValuesForLocale"); */ 95ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho /* END android-removed */ 96b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho addTest(root, &TestBengaliSortKey, "tscoll/capitst/TestBengaliSortKey"); 97103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius addTest(root, &TestGetKeywordValuesForLocale, "tscoll/capitst/TestGetKeywordValuesForLocale"); 98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestGetSetAttr(void) { 101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *coll = ucol_open(NULL, &status); 103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru struct attrTest { 104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UColAttribute att; 105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UColAttributeValue val[5]; 106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t valueSize; 107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UColAttributeValue nonValue; 108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } attrs[] = { 109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {UCOL_FRENCH_COLLATION, {UCOL_ON, UCOL_OFF}, 2, UCOL_SHIFTED}, 110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {UCOL_ALTERNATE_HANDLING, {UCOL_NON_IGNORABLE, UCOL_SHIFTED}, 2, UCOL_OFF},/* attribute for handling variable elements*/ 111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {UCOL_CASE_FIRST, {UCOL_OFF, UCOL_LOWER_FIRST, UCOL_UPPER_FIRST}, 3, UCOL_SHIFTED},/* who goes first, lower case or uppercase */ 112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {UCOL_CASE_LEVEL, {UCOL_ON, UCOL_OFF}, 2, UCOL_SHIFTED},/* do we have an extra case level */ 113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {UCOL_NORMALIZATION_MODE, {UCOL_ON, UCOL_OFF}, 2, UCOL_SHIFTED},/* attribute for normalization */ 114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {UCOL_DECOMPOSITION_MODE, {UCOL_ON, UCOL_OFF}, 2, UCOL_SHIFTED}, 115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {UCOL_STRENGTH, {UCOL_PRIMARY, UCOL_SECONDARY, UCOL_TERTIARY, UCOL_QUATERNARY, UCOL_IDENTICAL}, 5, UCOL_SHIFTED},/* attribute for strength */ 116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {UCOL_HIRAGANA_QUATERNARY_MODE, {UCOL_ON, UCOL_OFF}, 2, UCOL_SHIFTED},/* when turned on, this attribute */ 117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }; 118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UColAttribute currAttr; 11985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UColAttributeValue value; 120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t i = 0, j = 0; 121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 12285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if (coll == NULL) { 12385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "Unable to open collator. %s\n", u_errorName(status)); 12485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho return; 12585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i = 0; i<sizeof(attrs)/sizeof(attrs[0]); i++) { 127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru currAttr = attrs[i].att; 128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, currAttr, UCOL_DEFAULT, &status); 129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 13085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "ucol_setAttribute with the default value returned error: %s\n", u_errorName(status)); 131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru break; 132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru value = ucol_getAttribute(coll, currAttr, &status); 134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ucol_getAttribute returned error: %s\n", u_errorName(status)); 136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru break; 137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(j = 0; j<attrs[i].valueSize; j++) { 139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, currAttr, attrs[i].val[j], &status); 140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ucol_setAttribute with the value %i returned error: %s\n", attrs[i].val[j], u_errorName(status)); 142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru break; 143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, currAttr, attrs[i].nonValue, &status); 147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)) { 148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ucol_setAttribute with the bad value didn't return an error\n"); 149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru break; 150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, currAttr, value, &status); 154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ucol_setAttribute with the default valuereturned error: %s\n", u_errorName(status)); 156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru break; 157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru value = ucol_getAttribute(coll, UCOL_ATTRIBUTE_COUNT, &status); 161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)) { 162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ucol_getAttribute for UCOL_ATTRIBUTE_COUNT didn't return an error\n"); 163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_ATTRIBUTE_COUNT, UCOL_DEFAULT, &status); 166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)) { 167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ucol_setAttribute for UCOL_ATTRIBUTE_COUNT didn't return an error\n"); 168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(coll); 171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void doAssert(int condition, const char *message) 175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (condition==0) { 177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR : %s\n", message); 178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 18154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius#define UTF8_BUF_SIZE 128 18254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius 18354dcd9b6a06071f647dac967e9e267abb9410720Craig Corneliusstatic void doStrcoll(const UCollator* coll, const UChar* src, int32_t srcLen, const UChar* tgt, int32_t tgtLen, 18454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UCollationResult expected, const char *message) { 18554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UErrorCode err = U_ZERO_ERROR; 18654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius char srcU8[UTF8_BUF_SIZE], tgtU8[UTF8_BUF_SIZE]; 18754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius int32_t srcU8Len = -1, tgtU8Len = -1; 18854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius int32_t len = 0; 18954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius 19054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if (ucol_strcoll(coll, src, srcLen, tgt, tgtLen) != expected) { 19154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius log_err("ERROR : %s\n", message); 19254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } 19354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius 19454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius u_strToUTF8(srcU8, UTF8_BUF_SIZE, &len, src, srcLen, &err); 19554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if (U_FAILURE(err) || len >= UTF8_BUF_SIZE) { 19654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius log_err("ERROR : UTF-8 conversion error\n"); 19754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius return; 19854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } 19954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if (srcLen >= 0) { 20054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius srcU8Len = len; 20154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } 20254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius u_strToUTF8(tgtU8, UTF8_BUF_SIZE, &len, tgt, tgtLen, &err); 20354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if (U_FAILURE(err) || len >= UTF8_BUF_SIZE) { 20454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius log_err("ERROR : UTF-8 conversion error\n"); 20554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius return; 20654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } 20754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if (tgtLen >= 0) { 20854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius tgtU8Len = len; 20954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } 21054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius 21154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if (ucol_strcollUTF8(coll, srcU8, srcU8Len, tgtU8, tgtU8Len, &err) != expected 21254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius || U_FAILURE(err)) { 21354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius log_err("ERROR: %s (strcollUTF8)\n", message); 21454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius } 21554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius} 21654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius 217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if 0 218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* We don't have default rules, at least not in the previous sense */ 219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestGetDefaultRules(){ 220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t size=0; 221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status=U_ZERO_ERROR; 222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *coll=NULL; 223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t len1 = 0, len2=0; 224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t *binColData = NULL; 225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *res = NULL; 227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UResourceBundle *binColl = NULL; 228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t *binResult = NULL; 22985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 23085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UChar * defaultRulesArray=ucol_getDefaultRulesArray(&size); 232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Test the function ucol_getDefaultRulesArray()\n"); 233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru coll = ucol_openRules(defaultRulesArray, size, UCOL_ON, UCOL_PRIMARY, &status); 235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status) && coll !=NULL) { 236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru binColData = (uint8_t*)ucol_cloneRuleData(coll, &len1, &status); 23785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 24085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru res=ures_open(NULL, "root", &status); 243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)){ 244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: Failed to get resource for \"root Locale\" with %s", myErrorName(status)); 245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 24785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho binColl=ures_getByKey(res, "%%Collation", binColl, &status); 248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)){ 249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru binResult=(uint8_t*)ures_getBinary(binColl, &len2, &status); 250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)){ 251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_getBinary() failed\n"); 252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: ures_getByKey(locale(default), %%Collation) failed"); 255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(len1 != len2){ 259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Error: ucol_getDefaultRulesArray() failed to return the correct length.\n"); 260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(memcmp(binColData, binResult, len1) != 0){ 262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Error: ucol_getDefaultRulesArray() failed\n"); 263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(binColData); 266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(binColl); 267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ures_close(res); 268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(coll); 26985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 270ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* Collator Properties 274ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_open, ucol_strcoll, getStrength/setStrength 275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru getDecomposition/setDecomposition, getDisplayName*/ 276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestProperty() 27785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho{ 278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *col, *ruled; 279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar *disName; 28027f654740f2a26ad62a5c155af9199af9e69b889claireho int32_t len = 0; 28154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius UChar source[12], target[12]; 282ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t tempLength; 283ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 28485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* 28550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * Expected version of the English collator. 28650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * Currently, the major/minor version numbers change when the builder code 28750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * changes, 28850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * number 2 is from the tailoring data version and 28950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * number 3 is the UCA version. 29050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * This changes with every UCA version change, and the expected value 29150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * needs to be adjusted. 29250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * Same in intltest/apicoll.cpp. 29350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho */ 29427f654740f2a26ad62a5c155af9199af9e69b889claireho UVersionInfo currVersionArray = {0x31, 0xC0, 0x05, 0x2A}; /* from ICU 4.4/UCA 5.2 */ 295ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UVersionInfo versionArray = {0, 0, 0, 0}; 296ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UVersionInfo versionUCAArray = {0, 0, 0, 0}; 29727f654740f2a26ad62a5c155af9199af9e69b889claireho UVersionInfo versionUCDArray = {0, 0, 0, 0}; 29885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 299ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("The property tests begin : \n"); 300ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Test ucol_strcoll : \n"); 301ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru col = ucol_open("en_US", &status); 302ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 30385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "Default Collator creation failed.: %s\n", myErrorName(status)); 304ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 305ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 306ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 307ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_getVersion(col, versionArray); 30827f654740f2a26ad62a5c155af9199af9e69b889claireho /* Check for a version greater than some value rather than equality 30927f654740f2a26ad62a5c155af9199af9e69b889claireho * so that we need not update the expected version each time. */ 31027f654740f2a26ad62a5c155af9199af9e69b889claireho if (uprv_memcmp(versionArray, currVersionArray, 4)<0) { 31127f654740f2a26ad62a5c155af9199af9e69b889claireho log_err("Testing ucol_getVersion() - unexpected result: %02x.%02x.%02x.%02x\n", 31227f654740f2a26ad62a5c155af9199af9e69b889claireho versionArray[0], versionArray[1], versionArray[2], versionArray[3]); 31327f654740f2a26ad62a5c155af9199af9e69b889claireho } else { 31427f654740f2a26ad62a5c155af9199af9e69b889claireho log_verbose("ucol_getVersion() result: %02x.%02x.%02x.%02x\n", 31527f654740f2a26ad62a5c155af9199af9e69b889claireho versionArray[0], versionArray[1], versionArray[2], versionArray[3]); 316ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 317ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 31827f654740f2a26ad62a5c155af9199af9e69b889claireho /* Assume that the UCD and UCA versions are the same, 31927f654740f2a26ad62a5c155af9199af9e69b889claireho * rather than hardcoding (and updating each time) a particular UCA version. */ 32027f654740f2a26ad62a5c155af9199af9e69b889claireho u_getUnicodeVersion(versionUCDArray); 321ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_getUCAVersion(col, versionUCAArray); 32227f654740f2a26ad62a5c155af9199af9e69b889claireho if (0!=uprv_memcmp(versionUCAArray, versionUCDArray, 4)) { 32327f654740f2a26ad62a5c155af9199af9e69b889claireho log_err("Testing ucol_getUCAVersion() - unexpected result: %hu.%hu.%hu.%hu\n", 32427f654740f2a26ad62a5c155af9199af9e69b889claireho versionUCAArray[0], versionUCAArray[1], versionUCAArray[2], versionUCAArray[3]); 325ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 326ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 327ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(source, "ab"); 328ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(target, "abc"); 32985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 33054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius doStrcoll(col, source, u_strlen(source), target, u_strlen(target), UCOL_LESS, "ab < abc comparison failed"); 331ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 332ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(source, "ab"); 333ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(target, "AB"); 334ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 33554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius doStrcoll(col, source, u_strlen(source), target, u_strlen(target), UCOL_LESS, "ab < AB comparison failed"); 33654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius 337ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(source, "blackbird"); 33854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius u_uastrcpy(target, "black-bird"); 33954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius 34054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius doStrcoll(col, source, u_strlen(source), target, u_strlen(target), UCOL_GREATER, "black-bird > blackbird comparison failed"); 341ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 342ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(source, "black bird"); 343ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(target, "black-bird"); 34454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius 34554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius doStrcoll(col, source, u_strlen(source), target, u_strlen(target), UCOL_LESS, "black bird < black-bird comparison failed"); 34654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius 347ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(source, "Hello"); 348ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(target, "hello"); 349ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 35054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius doStrcoll(col, source, u_strlen(source), target, u_strlen(target), UCOL_GREATER, "Hello > hello comparison failed"); 35154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius 352ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Test ucol_strcoll ends.\n"); 353ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 354ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("testing ucol_getStrength() method ...\n"); 355ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (ucol_getStrength(col) == UCOL_TERTIARY), "collation object has the wrong strength"); 356ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (ucol_getStrength(col) != UCOL_PRIMARY), "collation object's strength is primary difference"); 35785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 358ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("testing ucol_setStrength() method ...\n"); 359ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setStrength(col, UCOL_SECONDARY); 360ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (ucol_getStrength(col) != UCOL_TERTIARY), "collation object's strength is secondary difference"); 361ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (ucol_getStrength(col) != UCOL_PRIMARY), "collation object's strength is primary difference"); 362ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (ucol_getStrength(col) == UCOL_SECONDARY), "collation object has the wrong strength"); 363ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 36485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 365ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Get display name for the default collation in German : \n"); 366ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 367ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru len=ucol_getDisplayName("en_US", "de_DE", NULL, 0, &status); 368ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status==U_BUFFER_OVERFLOW_ERROR){ 369ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 370ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru disName=(UChar*)malloc(sizeof(UChar) * (len+1)); 371ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_getDisplayName("en_US", "de_DE", disName, len+1, &status); 372ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("the display name for default collation in german: %s\n", austrdup(disName) ); 373ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(disName); 374ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 375ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)){ 376ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: in getDisplayName: %s\n", myErrorName(status)); 377ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 378ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 379ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Default collation getDisplayName ended.\n"); 380ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 381ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho /* BEGIN android-removed 382ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho To save space, Android does not include the collation tailoring rules. 383ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho Skip the related tests. 384b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 385ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ruled = ucol_open("da_DK", &status); 386ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("ucol_getRules() testing ...\n"); 387ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_getRules(ruled, &tempLength); 388ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( tempLength != 0, "getRules() result incorrect" ); 389ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("getRules tests end.\n"); 390ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 391ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar *buffer = (UChar *)malloc(200000*sizeof(UChar)); 392ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t bufLen = 200000; 393ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru buffer[0] = '\0'; 394ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("ucol_getRulesEx() testing ...\n"); 395ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tempLength = ucol_getRulesEx(col,UCOL_TAILORING_ONLY,buffer,bufLen ); 396b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho doAssert( tempLength == 0x00, "getRulesEx() result incorrect" ); 397ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("getRules tests end.\n"); 39885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 399ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("ucol_getRulesEx() testing ...\n"); 400ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tempLength=ucol_getRulesEx(col,UCOL_FULL_RULES,buffer,bufLen ); 401ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( tempLength != 0, "getRulesEx() result incorrect" ); 402ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("getRules tests end.\n"); 403ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(buffer); 404ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 405ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(ruled); 406103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius ucol_close(col); 40785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 408ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho END android-removed */ 409ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho 410ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("open an collator for french locale"); 411ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru col = ucol_open("fr_FR", &status); 412ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 413ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: Creating French collation failed.: %s\n", myErrorName(status)); 414ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 415ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 416ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setStrength(col, UCOL_PRIMARY); 417ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("testing ucol_getStrength() method again ...\n"); 418ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (ucol_getStrength(col) != UCOL_TERTIARY), "collation object has the wrong strength"); 419ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (ucol_getStrength(col) == UCOL_PRIMARY), "collation object's strength is not primary difference"); 42085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 421ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("testing French ucol_setStrength() method ...\n"); 422ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setStrength(col, UCOL_TERTIARY); 423ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (ucol_getStrength(col) == UCOL_TERTIARY), "collation object's strength is not tertiary difference"); 424ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (ucol_getStrength(col) != UCOL_PRIMARY), "collation object's strength is primary difference"); 425ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (ucol_getStrength(col) != UCOL_SECONDARY), "collation object's strength is secondary difference"); 426ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(col); 42785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 428ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Get display name for the french collation in english : \n"); 429ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru len=ucol_getDisplayName("fr_FR", "en_US", NULL, 0, &status); 430ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status==U_BUFFER_OVERFLOW_ERROR){ 431ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 432ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru disName=(UChar*)malloc(sizeof(UChar) * (len+1)); 433ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_getDisplayName("fr_FR", "en_US", disName, len+1, &status); 434ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("the display name for french collation in english: %s\n", austrdup(disName) ); 435ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(disName); 436ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 437ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)){ 438ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: in getDisplayName: %s\n", myErrorName(status)); 439ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 440ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 441ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Default collation getDisplayName ended.\n"); 442ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 443ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 444ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 445ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* Test RuleBasedCollator and getRules*/ 446ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestRuleBasedColl() 447ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 448ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *col1, *col2, *col3, *col4; 449ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollationElements *iter1, *iter2; 450ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar ruleset1[60]; 451ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar ruleset2[50]; 452ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar teststr[10]; 453ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar teststr2[10]; 454ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UChar *rule1, *rule2, *rule3, *rule4; 455ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t tempLength; 456ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 457ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(ruleset1, "&9 < a, A < b, B < c, C; ch, cH, Ch, CH < d, D, e, E"); 458ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(ruleset2, "&9 < a, A < b, B < c, C < d, D, e, E"); 45985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 460ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 461ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru col1 = ucol_openRules(ruleset1, u_strlen(ruleset1), UCOL_DEFAULT, UCOL_DEFAULT_STRENGTH, NULL,&status); 462ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 46385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "RuleBased Collator creation failed.: %s\n", myErrorName(status)); 464ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 465ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 466ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else 467ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("PASS: RuleBased Collator creation passed\n"); 46885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 469ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 470ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru col2 = ucol_openRules(ruleset2, u_strlen(ruleset2), UCOL_DEFAULT, UCOL_DEFAULT_STRENGTH, NULL, &status); 471ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 472ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("RuleBased Collator creation failed.: %s\n", myErrorName(status)); 473ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 474ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 475ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else 476ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("PASS: RuleBased Collator creation passed\n"); 47785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 47885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 479ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 480ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru col3= ucol_open(NULL, &status); 481ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 482ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Default Collator creation failed.: %s\n", myErrorName(status)); 483ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 484ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 485ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else 486ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("PASS: Default Collator creation passed\n"); 48785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 488ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru rule1 = ucol_getRules(col1, &tempLength); 489ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru rule2 = ucol_getRules(col2, &tempLength); 490ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru rule3 = ucol_getRules(col3, &tempLength); 491ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 492ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert((u_strcmp(rule1, rule2) != 0), "Default collator getRules failed"); 493ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert((u_strcmp(rule2, rule3) != 0), "Default collator getRules failed"); 494ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert((u_strcmp(rule1, rule3) != 0), "Default collator getRules failed"); 49585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 496ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru col4=ucol_openRules(rule2, u_strlen(rule2), UCOL_DEFAULT, UCOL_DEFAULT_STRENGTH, NULL, &status); 497ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 498ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("RuleBased Collator creation failed.: %s\n", myErrorName(status)); 499ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 500ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 501ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru rule4= ucol_getRules(col4, &tempLength); 502ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert((u_strcmp(rule2, rule4) == 0), "Default collator getRules failed"); 503ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 504ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(col1); 505ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(col2); 506ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(col3); 507ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(col4); 50885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 509ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* tests that modifier ! is always ignored */ 510ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(ruleset1, "!&a<b"); 511ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru teststr[0] = 0x0e40; 512ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru teststr[1] = 0x0e01; 513ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru teststr[2] = 0x0e2d; 514ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru col1 = ucol_openRules(ruleset1, u_strlen(ruleset1), UCOL_DEFAULT, UCOL_DEFAULT_STRENGTH, NULL, &status); 515ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 516ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("RuleBased Collator creation failed.: %s\n", myErrorName(status)); 517ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 518ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 519ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru col2 = ucol_open("en_US", &status); 520ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 521ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("en_US Collator creation failed.: %s\n", myErrorName(status)); 522ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 523ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 524ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru iter1 = ucol_openElements(col1, teststr, 3, &status); 525ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru iter2 = ucol_openElements(col2, teststr, 3, &status); 526ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 527ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: CollationElement iterator creation failed.: %s\n", myErrorName(status)); 528ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 529ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 530ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru while (TRUE) { 531ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* testing with en since thai has its own tailoring */ 532ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t ce = ucol_next(iter1, &status); 533ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t ce2 = ucol_next(iter2, &status); 534ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 535ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: CollationElement iterator creation failed.: %s\n", myErrorName(status)); 536ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 537ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 538ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ce2 != ce) { 539ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("! modifier test failed"); 540ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 541ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ce == UCOL_NULLORDER) { 542ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru break; 543ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 544ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 545ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_closeElements(iter1); 546ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_closeElements(iter2); 547ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(col1); 548ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(col2); 549ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* test that we can start a rule without a & or < */ 550ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(ruleset1, "< z < a"); 551ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru col1 = ucol_openRules(ruleset1, u_strlen(ruleset1), UCOL_DEFAULT, UCOL_DEFAULT_STRENGTH, NULL, &status); 552ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 553ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("RuleBased Collator creation failed.: %s\n", myErrorName(status)); 554ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 555ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 556ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(teststr, "z"); 557ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(teststr2, "a"); 558ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_greaterOrEqual(col1, teststr, 1, teststr2, 1)) { 559ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Rule \"z < a\" fails"); 56085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 561ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(col1); 562ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 563ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 564ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestCompare() 565ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 566ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 567ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *col; 568ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar* test1; 569ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar* test2; 57085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 571ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("The compare tests begin : \n"); 572ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status=U_ZERO_ERROR; 573ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru col = ucol_open("en_US", &status); 574ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 57585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "ucal_open() collation creation failed.: %s\n", myErrorName(status)); 576ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 577ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 578ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru test1=(UChar*)malloc(sizeof(UChar) * 6); 579ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru test2=(UChar*)malloc(sizeof(UChar) * 6); 580ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(test1, "Abcda"); 581ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(test2, "abcda"); 58285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 583ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Use tertiary comparison level testing ....\n"); 58485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 585ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (!ucol_equal(col, test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"Abcda\" != \"abcda\" "); 586ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (ucol_greater(col, test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"Abcda\" >>> \"abcda\" "); 58785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho doAssert( (ucol_greaterOrEqual(col, test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"Abcda\" >>> \"abcda\""); 588ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 589ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setStrength(col, UCOL_SECONDARY); 590ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Use secondary comparison level testing ....\n"); 59185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 592ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (ucol_equal(col, test1, u_strlen(test1), test2, u_strlen(test2) )), "Result should be \"Abcda\" == \"abcda\""); 593ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (!ucol_greater(col, test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"Abcda\" == \"abcda\""); 59485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho doAssert( (ucol_greaterOrEqual(col, test1, u_strlen(test1), test2, u_strlen(test2) )), "Result should be \"Abcda\" == \"abcda\""); 595ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 596ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setStrength(col, UCOL_PRIMARY); 597ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Use primary comparison level testing ....\n"); 59885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 599ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (ucol_equal(col, test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"Abcda\" == \"abcda\""); 600ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (!ucol_greater(col, test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"Abcda\" == \"abcda\""); 60185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho doAssert( (ucol_greaterOrEqual(col, test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"Abcda\" == \"abcda\""); 60285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 603ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 604ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("The compare tests end.\n"); 605ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(col); 606ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(test1); 607ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(test2); 60885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 609ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 610ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* 611ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru--------------------------------------------- 612ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tests decomposition setting 613ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/ 614ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestDecomposition() { 615ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 616ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *en_US, *el_GR, *vi_VN; 617ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru en_US = ucol_open("en_US", &status); 618ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru el_GR = ucol_open("el_GR", &status); 619ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru vi_VN = ucol_open("vi_VN", &status); 620ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 621ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 62285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "ERROR: collation creation failed.: %s\n", myErrorName(status)); 623ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 624ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 625ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 626ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getAttribute(vi_VN, UCOL_NORMALIZATION_MODE, &status) != UCOL_ON || 627ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_FAILURE(status)) 628ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 6298393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius log_err("ERROR: vi_VN collation did not have canonical decomposition for normalization!\n"); 630ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 631ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 632ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 633ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getAttribute(el_GR, UCOL_NORMALIZATION_MODE, &status) != UCOL_ON || 634ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_FAILURE(status)) 635ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 6368393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius log_err("ERROR: el_GR collation did not have canonical decomposition for normalization!\n"); 637ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 638ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 639ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 640ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getAttribute(en_US, UCOL_NORMALIZATION_MODE, &status) != UCOL_OFF || 641ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_FAILURE(status)) 642ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 6438393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius log_err("ERROR: en_US collation had canonical decomposition for normalization!\n"); 644ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 645ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 646ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(en_US); 647ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(el_GR); 648ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(vi_VN); 649ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 650ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 651ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define CLONETEST_COLLATOR_COUNT 4 652ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 653ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestSafeClone() { 65485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UChar test1[6]; 65585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UChar test2[6]; 656ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static const UChar umlautUStr[] = {0x00DC, 0}; 657ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static const UChar oeStr[] = {0x0055, 0x0045, 0}; 658ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator * someCollators [CLONETEST_COLLATOR_COUNT]; 659ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator * someClonedCollators [CLONETEST_COLLATOR_COUNT]; 660ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator * col; 661ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode err = U_ZERO_ERROR; 66254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius int8_t idx = 6; /* Leave this here to test buffer alingment in memory*/ 663ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t buffer [CLONETEST_COLLATOR_COUNT] [U_COL_SAFECLONE_BUFFERSIZE]; 664ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t bufferSize = U_COL_SAFECLONE_BUFFERSIZE; 665ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char sampleRuleChars[] = "&Z < CH"; 666ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar sampleRule[sizeof(sampleRuleChars)]; 667ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 668ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (TestBufferSize()) { 669ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("U_COL_SAFECLONE_BUFFERSIZE should be larger than sizeof(UCollator)\n"); 670ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 671ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 672ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 673ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(test1, "abCda"); 674ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(test2, "abcda"); 675ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(sampleRule, sampleRuleChars); 67685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 677ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* one default collator & two complex ones */ 678ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru someCollators[0] = ucol_open("en_US", &err); 679ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru someCollators[1] = ucol_open("ko", &err); 680ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru someCollators[2] = ucol_open("ja_JP", &err); 681ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru someCollators[3] = ucol_openRules(sampleRule, -1, UCOL_ON, UCOL_TERTIARY, NULL, &err); 682ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(err)) { 68354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius for (idx = 0; idx < CLONETEST_COLLATOR_COUNT; idx++) { 68454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius ucol_close(someCollators[idx]); 68585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 686ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_data_err("Couldn't open one or more collators\n"); 687ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 688ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 689ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 690ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Check the various error & informational states: */ 691ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 692ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Null status - just returns NULL */ 693ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (0 != ucol_safeClone(someCollators[0], buffer[0], &bufferSize, 0)) 694ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 695ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: Cloned Collator failed to deal correctly with null status\n"); 696ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 697ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* error status - should return 0 & keep error the same */ 698ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru err = U_MEMORY_ALLOCATION_ERROR; 699ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (0 != ucol_safeClone(someCollators[0], buffer[0], &bufferSize, &err) || err != U_MEMORY_ALLOCATION_ERROR) 700ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 701ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: Cloned Collator failed to deal correctly with incoming error status\n"); 702ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 703ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru err = U_ZERO_ERROR; 704ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 705ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Null buffer size pointer - just returns NULL & set error to U_ILLEGAL_ARGUMENT_ERROR*/ 706ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (0 != ucol_safeClone(someCollators[0], buffer[0], 0, &err) || err != U_ILLEGAL_ARGUMENT_ERROR) 707ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 708ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: Cloned Collator failed to deal correctly with null bufferSize pointer\n"); 709ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 710ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru err = U_ZERO_ERROR; 71185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 712ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* buffer size pointer is 0 - fill in pbufferSize with a size */ 713ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru bufferSize = 0; 714ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (0 != ucol_safeClone(someCollators[0], buffer[0], &bufferSize, &err) || U_FAILURE(err) || bufferSize <= 0) 715ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 716ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: Cloned Collator failed a sizing request ('preflighting')\n"); 717ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 718ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Verify our define is large enough */ 719ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_COL_SAFECLONE_BUFFERSIZE < bufferSize) 720ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 721ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: Pre-calculated buffer size is too small\n"); 722ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 723ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Verify we can use this run-time calculated size */ 724ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (0 == (col = ucol_safeClone(someCollators[0], buffer[0], &bufferSize, &err)) || U_FAILURE(err)) 725ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 726ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: Collator can't be cloned with run-time size\n"); 727ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 728ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (col) ucol_close(col); 729ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* size one byte too small - should allocate & let us know */ 730ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru --bufferSize; 731ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (0 == (col = ucol_safeClone(someCollators[0], 0, &bufferSize, &err)) || err != U_SAFECLONE_ALLOCATED_WARNING) 732ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 733ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: Cloned Collator failed to deal correctly with too-small buffer size\n"); 734ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 735ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (col) ucol_close(col); 736ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru err = U_ZERO_ERROR; 737ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru bufferSize = U_COL_SAFECLONE_BUFFERSIZE; 738ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 739ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 740ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Null buffer pointer - return Collator & set error to U_SAFECLONE_ALLOCATED_ERROR */ 741ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (0 == (col = ucol_safeClone(someCollators[0], 0, &bufferSize, &err)) || err != U_SAFECLONE_ALLOCATED_WARNING) 742ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 743ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: Cloned Collator failed to deal correctly with null buffer pointer\n"); 744ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 745ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (col) ucol_close(col); 746ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru err = U_ZERO_ERROR; 747ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 748ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Null Collator - return NULL & set U_ILLEGAL_ARGUMENT_ERROR */ 749ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (0 != ucol_safeClone(0, buffer[0], &bufferSize, &err) || err != U_ILLEGAL_ARGUMENT_ERROR) 750ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 751ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: Cloned Collator failed to deal correctly with null Collator pointer\n"); 752ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 753ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 754ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru err = U_ZERO_ERROR; 755ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 756ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Test that a cloned collator doesn't accidentally use UCA. */ 757ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru col=ucol_open("de@collation=phonebook", &err); 758ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru bufferSize = U_COL_SAFECLONE_BUFFERSIZE; 759ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru someClonedCollators[0] = ucol_safeClone(col, buffer[0], &bufferSize, &err); 760ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (ucol_greater(col, umlautUStr, u_strlen(umlautUStr), oeStr, u_strlen(oeStr))), "Original German phonebook collation sorts differently than expected"); 761ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (ucol_greater(someClonedCollators[0], umlautUStr, u_strlen(umlautUStr), oeStr, u_strlen(oeStr))), "Cloned German phonebook collation sorts differently than expected"); 762ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (!ucol_equals(someClonedCollators[0], col)) { 763ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("FAIL: Cloned German phonebook collator is not equal to original.\n"); 764ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 765ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(col); 766ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(someClonedCollators[0]); 767ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 768ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru err = U_ZERO_ERROR; 769ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 770ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* change orig & clone & make sure they are independent */ 771ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 77254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius for (idx = 0; idx < CLONETEST_COLLATOR_COUNT; idx++) 773ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 77454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius ucol_setStrength(someCollators[idx], UCOL_IDENTICAL); 775ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru bufferSize = 1; 776ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru err = U_ZERO_ERROR; 77754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius ucol_close(ucol_safeClone(someCollators[idx], buffer[idx], &bufferSize, &err)); 778ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (err != U_SAFECLONE_ALLOCATED_WARNING) { 77954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius log_err("FAIL: collator number %d was not allocated.\n", idx); 78054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius log_err("FAIL: status of Collator[%d] is %d (hex: %x).\n", idx, err, err); 781ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 782ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 783ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru bufferSize = U_COL_SAFECLONE_BUFFERSIZE; 784ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru err = U_ZERO_ERROR; 78554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius someClonedCollators[idx] = ucol_safeClone(someCollators[idx], buffer[idx], &bufferSize, &err); 78654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if (someClonedCollators[idx] == NULL 78754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius || someClonedCollators[idx] < (UCollator *)buffer[idx] 78854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius || someClonedCollators[idx] > (UCollator *)(buffer[idx]+(U_COL_SAFECLONE_BUFFERSIZE-1))) 789ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 7908393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius /* TODO: The use of U_COL_SAFECLONE_BUFFERSIZE will be deprecated per #9932. 7918393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius In the meantime, just turn the following former error into a log message. */ 7928393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius log_verbose("NOTE: Cloned collator did not use provided buffer, index %d, status %s, clone NULL? %d\n", 7938393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius idx, myErrorName(err), someClonedCollators[idx] == NULL); 794ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 79554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if (!ucol_equals(someClonedCollators[idx], someCollators[idx])) { 79654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius log_err("FAIL: Cloned collator is not equal to original at index = %d.\n", idx); 797ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 798ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 799ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Check the usability */ 80054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius ucol_setStrength(someCollators[idx], UCOL_PRIMARY); 80154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius ucol_setAttribute(someCollators[idx], UCOL_CASE_LEVEL, UCOL_OFF, &err); 80285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 80354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius doAssert( (ucol_equal(someCollators[idx], test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"abcda\" == \"abCda\""); 80485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 805ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Close the original to make sure that the clone is usable. */ 80654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius ucol_close(someCollators[idx]); 807ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 80854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius ucol_setStrength(someClonedCollators[idx], UCOL_TERTIARY); 80954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius ucol_setAttribute(someClonedCollators[idx], UCOL_CASE_LEVEL, UCOL_OFF, &err); 81054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius doAssert( (ucol_greater(someClonedCollators[idx], test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"abCda\" >>> \"abcda\" "); 811ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 81254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius ucol_close(someClonedCollators[idx]); 813ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 814ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 815ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 816ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestCloneBinary(){ 817ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode err = U_ZERO_ERROR; 818ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator * col = ucol_open("en_US", &err); 819ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator * c; 820ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t size; 821ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t * buffer; 822ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 823ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(err)) { 824ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_data_err("Couldn't open collator. Error: %s\n", u_errorName(err)); 825ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 826ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 827ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 828ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru size = ucol_cloneBinary(col, NULL, 0, &err); 829ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(size==0 || err!=U_BUFFER_OVERFLOW_ERROR) { 830ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ucol_cloneBinary - couldn't check size. Error: %s\n", u_errorName(err)); 831ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 832ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 833ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru err = U_ZERO_ERROR; 834ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 835ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru buffer = (uint8_t *) malloc(size); 836ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_cloneBinary(col, buffer, size, &err); 837ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(err)) { 838ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ucol_cloneBinary - couldn't clone.. Error: %s\n", u_errorName(err)); 839ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(buffer); 840ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 841ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 842ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 843ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* how to check binary result ? */ 844ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 845ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru c = ucol_openBinary(buffer, size, col, &err); 846ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(err)) { 847ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ucol_openBinary failed. Error: %s\n", u_errorName(err)); 848ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 849ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar t[] = {0x41, 0x42, 0x43, 0}; /* ABC */ 850ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t *k1, *k2; 851ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int l1, l2; 852ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru l1 = ucol_getSortKey(col, t, -1, NULL,0); 853ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru l2 = ucol_getSortKey(c, t, -1, NULL,0); 854ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru k1 = (uint8_t *) malloc(sizeof(uint8_t) * l1); 855ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru k2 = (uint8_t *) malloc(sizeof(uint8_t) * l2); 856ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_getSortKey(col, t, -1, k1, l1); 857ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_getSortKey(col, t, -1, k2, l2); 858ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (strcmp((char *)k1,(char *)k2) != 0){ 859ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ucol_openBinary - new collator should equal to old one\n"); 860ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }; 861ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(k1); 862ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(k2); 863ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 864ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(buffer); 865ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(c); 866ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(col); 867ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 868b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 869b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 870b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2clairehostatic void TestBengaliSortKey(void) 871b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho{ 872b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho const char *curLoc = "bn"; 873b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho UChar str1[] = { 0x09BE, 0 }; 874b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho UChar str2[] = { 0x0B70, 0 }; 875b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho UCollator *c2 = NULL; 876b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho const UChar *rules; 877b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho int32_t rulesLength=-1; 878b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho uint8_t *sortKey1; 879b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho int32_t sortKeyLen1 = 0; 880b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho uint8_t *sortKey2; 881b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho int32_t sortKeyLen2 = 0; 882b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho UErrorCode status = U_ZERO_ERROR; 883b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho char sortKeyStr1[2048]; 884b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho uint32_t sortKeyStrLen1 = sizeof(sortKeyStr1)/sizeof(sortKeyStr1[0]); 885b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho char sortKeyStr2[2048]; 886b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho uint32_t sortKeyStrLen2 = sizeof(sortKeyStr2)/sizeof(sortKeyStr2[0]); 887b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho UCollationResult result; 888b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 889b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho static UChar preRules[41] = { 0x26, 0x9fa, 0x3c, 0x98c, 0x3c, 0x9e1, 0x3c, 0x98f, 0x3c, 0x990, 0x3c, 0x993, 0x3c, 0x994, 0x3c, 0x9bc, 0x3c, 0x982, 0x3c, 0x983, 0x3c, 0x981, 0x3c, 0x9b0, 0x3c, 0x9b8, 0x3c, 0x9b9, 0x3c, 0x9bd, 0x3c, 0x9be, 0x3c, 0x9bf, 0x3c, 0x9c8, 0x3c, 0x9cb, 0x3d, 0x9cb , 0}; 890b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 891b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho rules = preRules; 892b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 893b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho log_verbose("Rules: %s\n", aescstrdup(rules, rulesLength)); 894b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 895b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho c2 = ucol_openRules(rules, rulesLength, UCOL_DEFAULT, UCOL_DEFAULT_STRENGTH, NULL, &status); 896b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (U_FAILURE(status)) { 897b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho log_data_err("ERROR: Creating collator from rules failed with locale: %s : %s\n", curLoc, myErrorName(status)); 898b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho return; 899b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 900b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 901b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho sortKeyLen1 = ucol_getSortKey(c2, str1, -1, NULL, 0); 902b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho sortKey1 = (uint8_t*)malloc(sortKeyLen1+1); 903b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho ucol_getSortKey(c2,str1,-1,sortKey1, sortKeyLen1+1); 904103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius ucol_sortKeyToString(c2, sortKey1, sortKeyStr1, sortKeyStrLen1); 905b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 906b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 907b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho sortKeyLen2 = ucol_getSortKey(c2, str2, -1, NULL, 0); 908b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho sortKey2 = (uint8_t*)malloc(sortKeyLen2+1); 909b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho ucol_getSortKey(c2,str2,-1,sortKey2, sortKeyLen2+1); 910b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 911103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius ucol_sortKeyToString(c2, sortKey2, sortKeyStr2, sortKeyStrLen2); 912b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 913b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 914b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 915b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho result=ucol_strcoll(c2, str1, -1, str2, -1); 916b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if(result!=UCOL_LESS) { 917b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho log_err("Error: %s was not less than %s: result=%d.\n", aescstrdup(str1,-1), aescstrdup(str2,-1), result); 918b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho log_info("[%s] -> %s (%d, from rule)\n", aescstrdup(str1,-1), sortKeyStr1, sortKeyLen1); 919b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho log_info("[%s] -> %s (%d, from rule)\n", aescstrdup(str2,-1), sortKeyStr2, sortKeyLen2); 920b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } else { 921b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho log_verbose("OK: %s was less than %s: result=%d.\n", aescstrdup(str1,-1), aescstrdup(str2,-1), result); 922b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho log_verbose("[%s] -> %s (%d, from rule)\n", aescstrdup(str1,-1), sortKeyStr1, sortKeyLen1); 923b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho log_verbose("[%s] -> %s (%d, from rule)\n", aescstrdup(str2,-1), sortKeyStr2, sortKeyLen2); 924b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 925b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 926b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho free(sortKey1); 927b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho free(sortKey2); 928b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho ucol_close(c2); 929b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 930b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho} 931b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 932ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* 93385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho TestOpenVsOpenRules ensures that collators from ucol_open and ucol_openRules 93485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho will generate identical sort keys 93585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho*/ 93685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hovoid TestOpenVsOpenRules(){ 93785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 93885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* create an array of all the locales */ 93985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho int32_t numLocales = uloc_countAvailable(); 94085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho int32_t sizeOfStdSet; 94185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho uint32_t adder; 94285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UChar str[41]; /* create an array of UChar of size maximum strSize + 1 */ 94385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho USet *stdSet; 94485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho char* curLoc; 94585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UCollator * c1; 94685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UCollator * c2; 94785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho const UChar* rules; 94885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho int32_t rulesLength; 94985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho int32_t sortKeyLen1, sortKeyLen2; 95085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho uint8_t *sortKey1 = NULL, *sortKey2 = NULL; 951103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius char sortKeyStr1[512], sortKeyStr2[512]; 952103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius uint32_t sortKeyStrLen1 = sizeof(sortKeyStr1) / sizeof(sortKeyStr1[0]), 953103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius sortKeyStrLen2 = sizeof(sortKeyStr2) / sizeof(sortKeyStr2[0]); 95485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho ULocaleData *uld; 95550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho int32_t x, y, z; 95685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho USet *eSet; 95785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho int32_t eSize; 95885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho int strSize; 95985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 96085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UErrorCode err = U_ZERO_ERROR; 96185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 96285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* create a set of standard characters that aren't very interesting... 96385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho and then we can find some interesting ones later */ 96485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 96585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho stdSet = uset_open(0x61, 0x7A); 96685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho uset_addRange(stdSet, 0x41, 0x5A); 96785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho uset_addRange(stdSet, 0x30, 0x39); 96885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho sizeOfStdSet = uset_size(stdSet); 96985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 97085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho adder = 1; 97127f654740f2a26ad62a5c155af9199af9e69b889claireho if(getTestOption(QUICK_OPTION)) 97285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho { 97385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho adder = 10; 97485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 97585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 97685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho for(x = 0; x < numLocales; x+=adder){ 97785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho curLoc = (char *)uloc_getAvailable(x); 97885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_verbose("Processing %s\n", curLoc); 97985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 98085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* create a collator the normal API way */ 98185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho c1 = ucol_open(curLoc, &err); 98285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if (U_FAILURE(err)) { 98385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("ERROR: Normal collation creation failed with locale: %s : %s\n", curLoc, myErrorName(err)); 98485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho return; 98585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 98685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 98785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* grab the rules */ 98885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho rules = ucol_getRules(c1, &rulesLength); 98985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 99085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* use those rules to create a collator from rules */ 99185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho c2 = ucol_openRules(rules, rulesLength, UCOL_DEFAULT, UCOL_DEFAULT_STRENGTH, NULL, &err); 99285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if (U_FAILURE(err)) { 99385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("ERROR: Creating collator from rules failed with locale: %s : %s\n", curLoc, myErrorName(err)); 99485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho return; 99585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 99685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 99785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho uld = ulocdata_open(curLoc, &err); 99885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 99985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /*now that we have some collators, we get several strings */ 100085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 100185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho for(y = 0; y < 5; y++){ 100285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 100385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* get a set of ALL the characters in this locale */ 100485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho eSet = ulocdata_getExemplarSet(uld, NULL, 0, ULOCDATA_ES_STANDARD, &err); 100585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho eSize = uset_size(eSet); 100685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 100785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* make a string with these characters in it */ 100885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho strSize = (rand()%40) + 1; 100985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 101085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho for(z = 0; z < strSize; z++){ 101185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho str[z] = uset_charAt(eSet, rand()%eSize); 101285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 101385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 101485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* change the set to only include 'abnormal' characters (not A-Z, a-z, 0-9 */ 101585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho uset_removeAll(eSet, stdSet); 101685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho eSize = uset_size(eSet); 101785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 101885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* if there are some non-normal characters left, put a few into the string, just to make sure we have some */ 101985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if(eSize > 0){ 102085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho str[2%strSize] = uset_charAt(eSet, rand()%eSize); 102185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho str[3%strSize] = uset_charAt(eSet, rand()%eSize); 102285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho str[5%strSize] = uset_charAt(eSet, rand()%eSize); 102385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho str[10%strSize] = uset_charAt(eSet, rand()%eSize); 102485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho str[13%strSize] = uset_charAt(eSet, rand()%eSize); 102585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 102685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* terminate the string */ 102785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho str[strSize-1] = '\0'; 102885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_verbose("String used: %S\n", str); 102985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 103085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* get sort keys for both of them, and check that the keys are identicle */ 103185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho sortKeyLen1 = ucol_getSortKey(c1, str, u_strlen(str), NULL, 0); 103285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho sortKey1 = (uint8_t*)malloc(sizeof(uint8_t) * (sortKeyLen1 + 1)); 103385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /*memset(sortKey1, 0xFE, sortKeyLen1);*/ 103485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho ucol_getSortKey(c1, str, u_strlen(str), sortKey1, sortKeyLen1 + 1); 1035103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius ucol_sortKeyToString(c1, sortKey1, sortKeyStr1, sortKeyStrLen1); 103685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 103785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho sortKeyLen2 = ucol_getSortKey(c2, str, u_strlen(str), NULL, 0); 103885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho sortKey2 = (uint8_t*)malloc(sizeof(uint8_t) * (sortKeyLen2 + 1)); 103985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /*memset(sortKey2, 0xFE, sortKeyLen2);*/ 104085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho ucol_getSortKey(c2, str, u_strlen(str), sortKey2, sortKeyLen2 + 1); 1041103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius ucol_sortKeyToString(c2, sortKey2, sortKeyStr2, sortKeyStrLen2); 104285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 104385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* Check that the lengths are the same */ 1044103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius if (sortKeyLen1 != sortKeyLen2) { 1045103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius log_err("ERROR : Sort key lengths %d and %d for text '%s' in locale '%s' do not match.\n", 1046103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius sortKeyLen1, sortKeyLen2, str, curLoc); 1047103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius } 104885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 104985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* check that the keys are the same */ 1050103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius if (memcmp(sortKey1, sortKey2, sortKeyLen1) != 0) { 1051103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius log_err("ERROR : Sort keys '%s' and '%s' for text '%s' in locale '%s' are not equivalent.\n", 1052103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius sortKeyStr1, sortKeyStr2, str, curLoc); 1053103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius } 105485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 105585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* clean up after each string */ 105685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho free(sortKey1); 105785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho free(sortKey2); 105885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho uset_close(eSet); 105985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 106085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* clean up after each locale */ 106185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho ulocdata_close(uld); 106285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho ucol_close(c1); 106385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho ucol_close(c2); 106485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 106585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* final clean up */ 106685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho uset_close(stdSet); 106785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho} 106885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho/* 1069ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru---------------------------------------------------------------------------- 1070ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ctor -- Tests the getSortKey 1071ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/ 1072ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestSortKey() 107385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho{ 1074ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t *sortk1 = NULL, *sortk2 = NULL, *sortk3 = NULL, *sortkEmpty = NULL; 1075ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t sortklen, osortklen; 1076ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *col; 1077ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar *test1, *test2, *test3; 1078ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 1079ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char toStringBuffer[256], *resultP; 1080103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius uint32_t toStringLen=sizeof(toStringBuffer)/sizeof(toStringBuffer[0]); 1081ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1082ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1083ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t s1[] = { 0x9f, 0x00 }; 1084ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t s2[] = { 0x61, 0x00 }; 1085ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int strcmpResult; 1086ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1087ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcmpResult = strcmp((const char *)s1, (const char *)s2); 1088ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("strcmp(0x9f..., 0x61...) = %d\n", strcmpResult); 108985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1090ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strcmpResult <= 0) { 1091ac04d0bbe12b3ef54518635711412f178cb4d16Jean-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", 1092ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcmpResult); 1093ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1094ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1095ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1096ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("testing SortKey begins...\n"); 109785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* this is supposed to open default date format, but later on it treats it like it is "en_US" 1098ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru - very bad if you try to run the tests on machine where default locale is NOT "en_US" */ 1099ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* col = ucol_open(NULL, &status); */ 1100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru col = ucol_open("en_US", &status); 1101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 110285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "ERROR: Default collation creation failed.: %s\n", myErrorName(status)); 1103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(ucol_getStrength(col) != UCOL_DEFAULT_STRENGTH) 1108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: default collation did not have UCOL_DEFAULT_STRENGTH !\n"); 1110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Need to use identical strength */ 1112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(col, UCOL_STRENGTH, UCOL_IDENTICAL, &status); 1113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru test1=(UChar*)malloc(sizeof(UChar) * 6); 1115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru test2=(UChar*)malloc(sizeof(UChar) * 6); 1116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru test3=(UChar*)malloc(sizeof(UChar) * 6); 111785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru memset(test1,0xFE, sizeof(UChar)*6); 1119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru memset(test2,0xFE, sizeof(UChar)*6); 1120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru memset(test3,0xFE, sizeof(UChar)*6); 1121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(test1, "Abcda"); 1124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(test2, "abcda"); 1125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(test3, "abcda"); 1126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Use tertiary comparison level testing ....\n"); 1128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortklen=ucol_getSortKey(col, test1, u_strlen(test1), NULL, 0); 1130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortk1=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen+1)); 1131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru memset(sortk1,0xFE, sortklen); 1132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_getSortKey(col, test1, u_strlen(test1), sortk1, sortklen+1); 1133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortklen=ucol_getSortKey(col, test2, u_strlen(test2), NULL, 0); 1135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortk2=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen+1)); 1136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru memset(sortk2,0xFE, sortklen); 1137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_getSortKey(col, test2, u_strlen(test2), sortk2, sortklen+1); 1138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru osortklen = sortklen; 1140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortklen=ucol_getSortKey(col, test2, u_strlen(test3), NULL, 0); 1141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortk3=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen+1)); 1142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru memset(sortk3,0xFE, sortklen); 1143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_getSortKey(col, test2, u_strlen(test2), sortk3, sortklen+1); 1144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (sortklen == osortklen), "Sortkey length should be the same (abcda, abcda)"); 1146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (memcmp(sortk1, sortk2, sortklen) > 0), "Result should be \"Abcda\" > \"abcda\""); 1148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (memcmp(sortk2, sortk1, sortklen) < 0), "Result should be \"abcda\" < \"Abcda\""); 1149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (memcmp(sortk2, sortk3, sortklen) == 0), "Result should be \"abcda\" == \"abcda\""); 1150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1151103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius resultP = ucol_sortKeyToString(col, sortk3, toStringBuffer, toStringLen); 1152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (resultP != 0), "sortKeyToString failed!"); 1153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if 1 /* verobse log of sortkeys */ 1155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char junk2[1000]; 1157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char junk3[1000]; 1158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int i; 1159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(junk2, "abcda[2] "); 1161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strcpy(junk3, " abcda[3] "); 1162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i=0;i<sortklen;i++) 1164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sprintf(junk2+strlen(junk2), "%02X ",(int)( 0xFF & sortk2[i])); 1166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sprintf(junk3+strlen(junk3), "%02X ",(int)( 0xFF & sortk3[i])); 1167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 116885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("%s\n", junk2); 1170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("%s\n", junk3); 1171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 1173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(sortk1); 1175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(sortk2); 1176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(sortk3); 1177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Use secondary comparision level testing ...\n"); 1179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setStrength(col, UCOL_SECONDARY); 1180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortklen=ucol_getSortKey(col, test1, u_strlen(test1), NULL, 0); 1181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortk1=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen+1)); 1182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_getSortKey(col, test1, u_strlen(test1), sortk1, sortklen+1); 1183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortklen=ucol_getSortKey(col, test2, u_strlen(test2), NULL, 0); 1184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortk2=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen+1)); 1185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_getSortKey(col, test2, u_strlen(test2), sortk2, sortklen+1); 118685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( !(memcmp(sortk1, sortk2, sortklen) > 0), "Result should be \"Abcda\" == \"abcda\""); 1188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( !(memcmp(sortk2, sortk1, sortklen) < 0), "Result should be \"abcda\" == \"Abcda\""); 1189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (memcmp(sortk1, sortk2, sortklen) == 0), "Result should be \"abcda\" == \"abcda\""); 1190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("getting sortkey for an empty string\n"); 1192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(col, UCOL_STRENGTH, UCOL_TERTIARY, &status); 1193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortklen = ucol_getSortKey(col, test1, 0, NULL, 0); 1194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortkEmpty = (uint8_t*)malloc(sizeof(uint8_t) * sortklen+1); 1195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortklen = ucol_getSortKey(col, test1, 0, sortkEmpty, sortklen+1); 1196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(sortklen != 3 || sortkEmpty[0] != 1 || sortkEmpty[0] != 1 || sortkEmpty[2] != 0) { 1197ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Empty string generated wrong sortkey!\n"); 1198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(sortkEmpty); 1200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("testing passing invalid string\n"); 1202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortklen = ucol_getSortKey(col, NULL, 0, NULL, 0); 1203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(sortklen != 0) { 1204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Invalid string didn't return sortkey size of 0\n"); 1205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 120685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 120785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("testing sortkey ends...\n"); 1209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(col); 1210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(test1); 1211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(test2); 1212ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(test3); 1213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(sortk1); 1214ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(sortk2); 121585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestHashCode() 1218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 1219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t *sortk1, *sortk2, *sortk3; 1220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t sortk1len, sortk2len, sortk3len; 1221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *col; 1222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar *test1, *test2, *test3; 1223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 1224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("testing getHashCode begins...\n"); 1225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru col = ucol_open("en_US", &status); 1226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 122785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "ERROR: Default collation creation failed.: %s\n", myErrorName(status)); 1228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru test1=(UChar*)malloc(sizeof(UChar) * 6); 1231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru test2=(UChar*)malloc(sizeof(UChar) * 6); 1232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru test3=(UChar*)malloc(sizeof(UChar) * 6); 1233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(test1, "Abcda"); 1234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(test2, "abcda"); 1235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(test3, "abcda"); 1236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Use tertiary comparison level testing ....\n"); 1238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortk1len=ucol_getSortKey(col, test1, u_strlen(test1), NULL, 0); 1239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortk1=(uint8_t*)malloc(sizeof(uint8_t) * (sortk1len+1)); 1240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_getSortKey(col, test1, u_strlen(test1), sortk1, sortk1len+1); 1241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortk2len=ucol_getSortKey(col, test2, u_strlen(test2), NULL, 0); 1242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortk2=(uint8_t*)malloc(sizeof(uint8_t) * (sortk2len+1)); 1243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_getSortKey(col, test2, u_strlen(test2), sortk2, sortk2len+1); 1244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortk3len=ucol_getSortKey(col, test2, u_strlen(test3), NULL, 0); 1245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortk3=(uint8_t*)malloc(sizeof(uint8_t) * (sortk3len+1)); 1246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_getSortKey(col, test2, u_strlen(test2), sortk3, sortk3len+1); 124785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 124885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("ucol_hashCode() testing ...\n"); 125085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 125185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho doAssert( ucol_keyHashCode(sortk1, sortk1len) != ucol_keyHashCode(sortk2, sortk2len), "Hash test1 result incorrect" ); 1252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( !(ucol_keyHashCode(sortk1, sortk1len) == ucol_keyHashCode(sortk2, sortk2len)), "Hash test2 result incorrect" ); 1253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( ucol_keyHashCode(sortk2, sortk2len) == ucol_keyHashCode(sortk3, sortk3len), "Hash result not equal" ); 125485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("hashCode tests end.\n"); 1256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(col); 1257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(sortk1); 1258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(sortk2); 1259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(sortk3); 1260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(test1); 1261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(test2); 1262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(test3); 1263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* 1267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *---------------------------------------------------------------------------- 1268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Tests the UCollatorElements API. 126985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * 127085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho */ 1271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestElemIter() 1272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 1273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t offset; 1274ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t order1, order2, order3; 1275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar *testString1, *testString2; 1276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *col; 1277ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollationElements *iterator1, *iterator2, *iterator3; 1278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 1279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("testing UCollatorElements begins...\n"); 1280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru col = ucol_open("en_US", &status); 1281ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(col, UCOL_NORMALIZATION_MODE, UCOL_OFF, &status); 1282ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 128385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "ERROR: Default collation creation failed.: %s\n", myErrorName(status)); 1284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1286ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1287ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru testString1=(UChar*)malloc(sizeof(UChar) * 150); 1288ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru testString2=(UChar*)malloc(sizeof(UChar) * 150); 1289ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(testString1, "XFILE What subset of all possible test cases has the highest probability of detecting the most errors?"); 1290ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_uastrcpy(testString2, "Xf_ile What subset of all possible test cases has the lowest probability of detecting the least errors?"); 129185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1292ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Constructors and comparison testing....\n"); 129385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1294ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru iterator1 = ucol_openElements(col, testString1, u_strlen(testString1), &status); 1295ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 1296ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: Default collationElement iterator creation failed.: %s\n", myErrorName(status)); 1297ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(col); 1298ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1299ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1300ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else{ log_verbose("PASS: Default collationElement iterator1 creation passed\n");} 1301ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1302ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru iterator2 = ucol_openElements(col, testString1, u_strlen(testString1), &status); 1303ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 1304ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: Default collationElement iterator creation failed.: %s\n", myErrorName(status)); 1305ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(col); 1306ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1307ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1308ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else{ log_verbose("PASS: Default collationElement iterator2 creation passed\n");} 1309ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1310ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru iterator3 = ucol_openElements(col, testString2, u_strlen(testString2), &status); 1311ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 1312ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ERROR: Default collationElement iterator creation failed.: %s\n", myErrorName(status)); 1313ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(col); 1314ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1315ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1316ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else{ log_verbose("PASS: Default collationElement iterator3 creation passed\n");} 1317ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1318ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru offset=ucol_getOffset(iterator1); 1319ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setOffset(iterator1, 6, &status); 1320ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 1321ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Error in setOffset for UCollatorElements iterator.: %s\n", myErrorName(status)); 1322ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1323ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1324ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(ucol_getOffset(iterator1)==6) 1325ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("setOffset and getOffset working fine\n"); 1326ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else{ 1327ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("error in set and get Offset got %d instead of 6\n", ucol_getOffset(iterator1)); 1328ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1329ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1330ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setOffset(iterator1, 0, &status); 1331ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru order1 = ucol_next(iterator1, &status); 1332ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 1333ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Somehow ran out of memory stepping through the iterator1.: %s\n", myErrorName(status)); 1334ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1335ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1336ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru order2=ucol_getOffset(iterator2); 1337ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert((order1 != order2), "The first iterator advance failed"); 1338ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru order2 = ucol_next(iterator2, &status); 1339ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 1340ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Somehow ran out of memory stepping through the iterator2.: %s\n", myErrorName(status)); 1341ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1342ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1343ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru order3 = ucol_next(iterator3, &status); 1344ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 1345ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Somehow ran out of memory stepping through the iterator3.: %s\n", myErrorName(status)); 1346ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1347ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 134885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1349ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert((order1 == order2), "The second iterator advance failed should be the same as first one"); 135085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1351ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerudoAssert( (ucol_primaryOrder(order1) == ucol_primaryOrder(order3)), "The primary orders should be identical"); 1352ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerudoAssert( (ucol_secondaryOrder(order1) == ucol_secondaryOrder(order3)), "The secondary orders should be identical"); 1353ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerudoAssert( (ucol_tertiaryOrder(order1) == ucol_tertiaryOrder(order3)), "The tertiary orders should be identical"); 135485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1355ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru order1=ucol_next(iterator1, &status); 1356ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 1357ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Somehow ran out of memory stepping through the iterator2.: %s\n", myErrorName(status)); 1358ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1359ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1360ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru order3=ucol_next(iterator3, &status); 1361ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 1362ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Somehow ran out of memory stepping through the iterator2.: %s\n", myErrorName(status)); 1363ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1364ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1365ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerudoAssert( (ucol_primaryOrder(order1) == ucol_primaryOrder(order3)), "The primary orders should be identical"); 1366ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerudoAssert( (ucol_tertiaryOrder(order1) != ucol_tertiaryOrder(order3)), "The tertiary orders should be different"); 136785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1368ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru order1=ucol_next(iterator1, &status); 1369ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 1370ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Somehow ran out of memory stepping through the iterator2.: %s\n", myErrorName(status)); 1371ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1372ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1373ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru order3=ucol_next(iterator3, &status); 1374ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 1375ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Somehow ran out of memory stepping through the iterator2.: %s\n", myErrorName(status)); 1376ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1377ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1378ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* this here, my friends, is either pure lunacy or something so obsolete that even it's mother 1379ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * doesn't care about it. Essentialy, this test complains if secondary values for 'I' and '_' 1380ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * are the same. According to the UCA, this is not true. Therefore, remove the test. 1381ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Besides, if primary strengths for two code points are different, it doesn't matter one bit 1382ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * what is the relation between secondary or any other strengths. 1383ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * killed by weiv 06/11/2002. 1384ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 1385ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* 1386ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( ((order1 & UCOL_SECONDARYMASK) != (order3 & UCOL_SECONDARYMASK)), "The secondary orders should be different"); 1387ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 1388ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doAssert( (order1 != UCOL_NULLORDER), "Unexpected end of iterator reached"); 1389ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1390ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(testString1); 1391ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(testString2); 1392ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_closeElements(iterator1); 1393ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_closeElements(iterator2); 1394ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_closeElements(iterator3); 1395ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(col); 139685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1397ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("testing CollationElementIterator ends...\n"); 1398ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1399ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1400ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestGetLocale() { 1401ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 1402ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *rules = "&a<x<y<z"; 1403ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar rlz[256] = {0}; 1404ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t rlzLen = u_unescape(rules, rlz, 256); 1405ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1406ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *coll = NULL; 1407ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *locale = NULL; 1408ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1409ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t i = 0; 1410ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1411ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Now that the collation tree is separate, actual==valid at all times. [alan] */ 1412ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static const struct { 1413ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* requestedLocale; 1414ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* validLocale; 1415ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* actualLocale; 1416ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } testStruct[] = { 141727f654740f2a26ad62a5c155af9199af9e69b889claireho { "sr_RS", "sr_Cyrl_RS", "sr" }, 14188393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius { "sh_YU", "sr_Latn_RS", "sr_Latn" }, /* was sh, then aliased to hr, now sr_Latn via import per cldrbug 5647: */ 141927f654740f2a26ad62a5c155af9199af9e69b889claireho { "en_BE_FOO", "en_BE", "root" }, 142027f654740f2a26ad62a5c155af9199af9e69b889claireho { "de_DE_NONEXISTANT", "de_DE", "de" } 1421ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }; 1422ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1423ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* test opening collators for different locales */ 1424ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i = 0; i<sizeof(testStruct)/sizeof(testStruct[0]); i++) { 1425ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 1426ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru coll = ucol_open(testStruct[i].requestedLocale, &status); 1427ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 142885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "Failed to open collator for %s with %s\n", testStruct[i].requestedLocale, u_errorName(status)); 1429ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(coll); 1430ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru continue; 1431ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 143285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho locale = ucol_getLocaleByType(coll, ULOC_REQUESTED_LOCALE, &status); 1433ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strcmp(locale, testStruct[i].requestedLocale) != 0) { 1434ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("[Coll %s]: Error in requested locale, expected %s, got %s\n", testStruct[i].requestedLocale, testStruct[i].requestedLocale, locale); 1435ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 143685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho locale = ucol_getLocaleByType(coll, ULOC_VALID_LOCALE, &status); 1437ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strcmp(locale, testStruct[i].validLocale) != 0) { 1438ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("[Coll %s]: Error in valid locale, expected %s, got %s\n", testStruct[i].requestedLocale, testStruct[i].validLocale, locale); 1439ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 144085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho locale = ucol_getLocaleByType(coll, ULOC_ACTUAL_LOCALE, &status); 1441ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strcmp(locale, testStruct[i].actualLocale) != 0) { 1442ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("[Coll %s]: Error in actual locale, expected %s, got %s\n", testStruct[i].requestedLocale, testStruct[i].actualLocale, locale); 1443ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1444ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(coll); 1445ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1446ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1447ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* completely non-existant locale for collator should get a default collator */ 1448ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1449ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *defaultColl = ucol_open(NULL, &status); 1450ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru coll = ucol_open("blahaha", &status); 1451ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)) { 145285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if(strcmp(ucol_getLocaleByType(coll, ULOC_REQUESTED_LOCALE, &status), "blahaha")) { 1453ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Nonexisting locale didn't preserve the requested locale\n"); 1454ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 145585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if(strcmp(ucol_getLocaleByType(coll, ULOC_VALID_LOCALE, &status), 145685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho ucol_getLocaleByType(defaultColl, ULOC_VALID_LOCALE, &status))) { 1457ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Valid locale for nonexisting locale locale collator differs " 1458ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "from valid locale for default collator\n"); 1459ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 146085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if(strcmp(ucol_getLocaleByType(coll, ULOC_ACTUAL_LOCALE, &status), 146185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho ucol_getLocaleByType(defaultColl, ULOC_ACTUAL_LOCALE, &status))) { 1462ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Actual locale for nonexisting locale locale collator differs " 1463ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "from actual locale for default collator\n"); 1464ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1465ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(coll); 1466ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(defaultColl); 1467ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 1468ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_data_err("Couldn't open collators\n"); 1469ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1470ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1471ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 147285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1473ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1474ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* collator instantiated from rules should have all three locales NULL */ 1475ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru coll = ucol_openRules(rlz, rlzLen, UCOL_DEFAULT, UCOL_DEFAULT, NULL, &status); 147685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho locale = ucol_getLocaleByType(coll, ULOC_REQUESTED_LOCALE, &status); 1477ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(locale != NULL) { 1478ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("For collator instantiated from rules, requested locale returned %s instead of NULL\n", locale); 1479ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 148085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho locale = ucol_getLocaleByType(coll, ULOC_VALID_LOCALE, &status); 1481ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(locale != NULL) { 1482ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("For collator instantiated from rules, valid locale returned %s instead of NULL\n", locale); 1483ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 148485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho locale = ucol_getLocaleByType(coll, ULOC_ACTUAL_LOCALE, &status); 1485ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(locale != NULL) { 1486ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("For collator instantiated from rules, actual locale returned %s instead of NULL\n", locale); 1487ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1488ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(coll); 1489ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1490ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1491ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1492ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1493ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestGetAll() 1494ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 1495ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t i, count; 1496ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru count=ucol_countAvailable(); 1497ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* use something sensible w/o hardcoding the count */ 1498ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(count < 0){ 1499ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Error in countAvailable(), it returned %d\n", count); 1500ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1501ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru else{ 1502ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("PASS: countAvailable() successful, it returned %d\n", count); 1503ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1504ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i=0;i<count;i++) 1505ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("%s\n", ucol_getAvailable(i)); 1506ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1507ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1508ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1509ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1510ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1511ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustruct teststruct { 1512ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *original; 1513ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t key[256]; 1514ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} ; 1515ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1516ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic int compare_teststruct(const void *string1, const void *string2) { 1517ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return(strcmp((const char *)((struct teststruct *)string1)->key, (const char *)((struct teststruct *)string2)->key)); 1518ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1519ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1520ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestBounds() { 1521ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 1522ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1523ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *coll = ucol_open("sh", &status); 1524ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1525ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t sortkey[512], lower[512], upper[512]; 1526ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar buffer[512]; 1527ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1528ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static const char * const test[] = { 1529ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "John Smith", 1530ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "JOHN SMITH", 1531ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "john SMITH", 1532ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "j\\u00F6hn sm\\u00EFth", 1533ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "J\\u00F6hn Sm\\u00EFth", 1534ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "J\\u00D6HN SM\\u00CFTH", 1535ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "john smithsonian", 1536ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "John Smithsonian", 1537ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }; 1538ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 153985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho struct teststruct tests[] = { 1540ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKI MIHALJ" } , 1541ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKI MIHALJ" } , 1542ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKI PIRO\\u0160KA" }, 1543ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABAI ANDRIJA" } , 1544ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABAI LAJO\\u0160" } , 1545ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABAI MARIJA" } , 1546ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABAI STEVAN" } , 1547ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABAI STEVAN" } , 1548ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABARKAPA BRANKO" } , 1549ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABARKAPA MILENKO" } , 1550ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABARKAPA MIROSLAV" } , 1551ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABARKAPA SIMO" } , 1552ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABARKAPA STANKO" } , 1553ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABARKAPA TAMARA" } , 1554ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABARKAPA TOMA\\u0160" } , 1555ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABDARI\\u0106 NIKOLA" } , 1556ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABDARI\\u0106 ZORICA" } , 1557ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABI NANDOR" } , 1558ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABOVI\\u0106 MILAN" } , 1559ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABRADI AGNEZIJA" } , 1560ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABRADI IVAN" } , 1561ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABRADI JELENA" } , 1562ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABRADI LJUBICA" } , 1563ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABRADI STEVAN" } , 1564ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABRDA MARTIN" } , 1565ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABRILO BOGDAN" } , 1566ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABRILO BRANISLAV" } , 1567ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABRILO LAZAR" } , 1568ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABRILO LJUBICA" } , 1569ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CABRILO SPASOJA" } , 1570ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CADE\\u0160 ZDENKA" } , 1571ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CADESKI BLAGOJE" } , 1572ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CADOVSKI VLADIMIR" } , 1573ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAGLJEVI\\u0106 TOMA" } , 1574ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAGOROVI\\u0106 VLADIMIR" } , 1575ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAJA VANKA" } , 1576ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAJI\\u0106 BOGOLJUB" } , 1577ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAJI\\u0106 BORISLAV" } , 1578ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAJI\\u0106 RADOSLAV" } , 1579ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAK\\u0160IRAN MILADIN" } , 1580ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKAN EUGEN" } , 1581ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKAN EVGENIJE" } , 1582ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKAN IVAN" } , 1583ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKAN JULIJAN" } , 1584ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKAN MIHAJLO" } , 1585ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKAN STEVAN" } , 1586ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKAN VLADIMIR" } , 1587ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKAN VLADIMIR" } , 1588ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKAN VLADIMIR" } , 1589ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKARA ANA" } , 1590ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKAREVI\\u0106 MOMIR" } , 1591ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKAREVI\\u0106 NEDELJKO" } , 1592ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKI \\u0160ANDOR" } , 1593ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKI AMALIJA" } , 1594ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKI ANDRA\\u0160" } , 1595ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKI LADISLAV" } , 1596ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKI LAJO\\u0160" } , 1597ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"\\u010CAKI LASLO" } , 1598ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }; 1599ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1600ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1601ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1602ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t i = 0, j = 0, k = 0, buffSize = 0, skSize = 0, lowerSize = 0, upperSize = 0; 1603ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t arraySize = sizeof(tests)/sizeof(tests[0]); 1604ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1605ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status) && coll) { 1606ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i = 0; i<arraySize; i++) { 1607ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru buffSize = u_unescape(tests[i].original, buffer, 512); 1608ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru skSize = ucol_getSortKey(coll, buffer, buffSize, tests[i].key, 512); 1609ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1610ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1611ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru qsort(tests, arraySize, sizeof(struct teststruct), compare_teststruct); 1612ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1613ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i = 0; i < arraySize-1; i++) { 1614ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(j = i+1; j < arraySize; j++) { 1615ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru lowerSize = ucol_getBound(tests[i].key, -1, UCOL_BOUND_LOWER, 1, lower, 512, &status); 1616ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru upperSize = ucol_getBound(tests[j].key, -1, UCOL_BOUND_UPPER, 1, upper, 512, &status); 1617ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(k = i; k <= j; k++) { 1618ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strcmp((const char *)lower, (const char *)tests[k].key) > 0) { 1619ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Problem with lower! j = %i (%s vs %s)\n", k, tests[k].original, tests[i].original); 1620ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1621ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strcmp((const char *)upper, (const char *)tests[k].key) <= 0) { 1622ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Problem with upper! j = %i (%s vs %s)\n", k, tests[k].original, tests[j].original); 1623ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1624ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1625ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1626ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1627ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1628ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1629ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if 0 1630ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i = 0; i < 1000; i++) { 1631ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru lowerRND = (rand()/(RAND_MAX/arraySize)); 1632ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru upperRND = lowerRND + (rand()/(RAND_MAX/(arraySize-lowerRND))); 1633ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1634ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru lowerSize = ucol_getBound(tests[lowerRND].key, -1, UCOL_BOUND_LOWER, 1, lower, 512, &status); 1635ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru upperSize = ucol_getBound(tests[upperRND].key, -1, UCOL_BOUND_UPPER_LONG, 1, upper, 512, &status); 1636ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1637ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(j = lowerRND; j<=upperRND; j++) { 1638ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strcmp(lower, tests[j].key) > 0) { 1639ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Problem with lower! j = %i (%s vs %s)\n", j, tests[j].original, tests[lowerRND].original); 1640ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1641ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strcmp(upper, tests[j].key) <= 0) { 1642ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Problem with upper! j = %i (%s vs %s)\n", j, tests[j].original, tests[upperRND].original); 1643ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1644ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1645ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1646ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 1647ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1648ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1649ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1650ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1651ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1652ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i = 0; i<sizeof(test)/sizeof(test[0]); i++) { 1653ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru buffSize = u_unescape(test[i], buffer, 512); 1654ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru skSize = ucol_getSortKey(coll, buffer, buffSize, sortkey, 512); 1655ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru lowerSize = ucol_getBound(sortkey, skSize, UCOL_BOUND_LOWER, 1, lower, 512, &status); 1656ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru upperSize = ucol_getBound(sortkey, skSize, UCOL_BOUND_UPPER_LONG, 1, upper, 512, &status); 1657ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(j = i+1; j<sizeof(test)/sizeof(test[0]); j++) { 1658ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru buffSize = u_unescape(test[j], buffer, 512); 1659ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru skSize = ucol_getSortKey(coll, buffer, buffSize, sortkey, 512); 1660ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strcmp((const char *)lower, (const char *)sortkey) > 0) { 1661ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Problem with lower! i = %i, j = %i (%s vs %s)\n", i, j, test[i], test[j]); 1662ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1663ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strcmp((const char *)upper, (const char *)sortkey) <= 0) { 1664ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Problem with upper! i = %i, j = %i (%s vs %s)\n", i, j, test[i], test[j]); 1665ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1666ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1667ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1668ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(coll); 1669ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 1670ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_data_err("Couldn't open collator\n"); 1671ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1672ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1673ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1674ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1675ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void doOverrunTest(UCollator *coll, const UChar *uString, int32_t strLen) { 1676ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t skLen = 0, skLen2 = 0; 1677ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t sortKey[256]; 1678ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t i, j; 1679ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t filler = 0xFF; 1680ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1681ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru skLen = ucol_getSortKey(coll, uString, strLen, NULL, 0); 1682ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1683ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i = 0; i < skLen; i++) { 1684ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru memset(sortKey, filler, 256); 1685ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru skLen2 = ucol_getSortKey(coll, uString, strLen, sortKey, i); 1686ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(skLen != skLen2) { 1687ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("For buffer size %i, got different sortkey length. Expected %i got %i\n", i, skLen, skLen2); 1688ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1689ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(j = i; j < 256; j++) { 1690ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(sortKey[j] != filler) { 1691ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Something run over index %i\n", j); 1692ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru break; 1693ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1694ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1695ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1696ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1697ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1698ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* j1865 reports that if a shorter buffer is passed to 169985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho* to get sort key, a buffer overrun happens in some 1700ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* cases. This test tries to check this. 1701ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/ 1702ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestSortKeyBufferOverrun(void) { 1703ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 1704ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* cString = "A very Merry liTTle-lamB.."; 1705ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar uString[256]; 1706ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t strLen = 0; 1707ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *coll = ucol_open("root", &status); 1708ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strLen = u_unescape(cString, uString, 256); 1709ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1710ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)) { 1711ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("testing non ignorable\n"); 1712ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_ALTERNATE_HANDLING, UCOL_NON_IGNORABLE, &status); 1713ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doOverrunTest(coll, uString, strLen); 1714ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1715ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("testing shifted\n"); 1716ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_ALTERNATE_HANDLING, UCOL_SHIFTED, &status); 1717ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doOverrunTest(coll, uString, strLen); 1718ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1719ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("testing shifted quaternary\n"); 1720ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_STRENGTH, UCOL_QUATERNARY, &status); 1721ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doOverrunTest(coll, uString, strLen); 1722ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1723ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("testing with french secondaries\n"); 1724ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_FRENCH_COLLATION, UCOL_ON, &status); 1725ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_STRENGTH, UCOL_TERTIARY, &status); 1726ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_ALTERNATE_HANDLING, UCOL_NON_IGNORABLE, &status); 1727ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doOverrunTest(coll, uString, strLen); 1728ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1729ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1730ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(coll); 1731ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1732ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1733ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestAttribute() 1734ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 1735ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode error = U_ZERO_ERROR; 1736ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *coll = ucol_open(NULL, &error); 1737ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1738ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(error)) { 173985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(error, "Creation of default collator failed\n"); 1740ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 1741ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1742ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1743ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_FRENCH_COLLATION, UCOL_OFF, &error); 1744ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getAttribute(coll, UCOL_FRENCH_COLLATION, &error) != UCOL_OFF || 1745ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_FAILURE(error)) { 174685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(error, "Setting and retrieving of the french collation failed\n"); 1747ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1748ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1749ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_FRENCH_COLLATION, UCOL_ON, &error); 1750ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getAttribute(coll, UCOL_FRENCH_COLLATION, &error) != UCOL_ON || 1751ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_FAILURE(error)) { 175285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(error, "Setting and retrieving of the french collation failed\n"); 1753ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1754ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1755ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_ALTERNATE_HANDLING, UCOL_SHIFTED, &error); 1756ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getAttribute(coll, UCOL_ALTERNATE_HANDLING, &error) != UCOL_SHIFTED || 1757ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_FAILURE(error)) { 175885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(error, "Setting and retrieving of the alternate handling failed\n"); 1759ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1760ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1761ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_ALTERNATE_HANDLING, UCOL_NON_IGNORABLE, &error); 1762ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getAttribute(coll, UCOL_ALTERNATE_HANDLING, &error) != UCOL_NON_IGNORABLE || 1763ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_FAILURE(error)) { 176485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(error, "Setting and retrieving of the alternate handling failed\n"); 1765ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1766ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1767ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_CASE_FIRST, UCOL_LOWER_FIRST, &error); 1768ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getAttribute(coll, UCOL_CASE_FIRST, &error) != UCOL_LOWER_FIRST || 1769ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_FAILURE(error)) { 177085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(error, "Setting and retrieving of the case first attribute failed\n"); 1771ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1772ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1773ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_CASE_FIRST, UCOL_UPPER_FIRST, &error); 1774ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getAttribute(coll, UCOL_CASE_FIRST, &error) != UCOL_UPPER_FIRST || 1775ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_FAILURE(error)) { 177685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(error, "Setting and retrieving of the case first attribute failed\n"); 1777ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1778ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1779ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_CASE_LEVEL, UCOL_ON, &error); 1780ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getAttribute(coll, UCOL_CASE_LEVEL, &error) != UCOL_ON || 1781ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_FAILURE(error)) { 178285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(error, "Setting and retrieving of the case level attribute failed\n"); 1783ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1784ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1785ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_CASE_LEVEL, UCOL_OFF, &error); 1786ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getAttribute(coll, UCOL_CASE_LEVEL, &error) != UCOL_OFF || 1787ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_FAILURE(error)) { 178885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(error, "Setting and retrieving of the case level attribute failed\n"); 1789ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1790ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1791ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_NORMALIZATION_MODE, UCOL_ON, &error); 1792ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getAttribute(coll, UCOL_NORMALIZATION_MODE, &error) != UCOL_ON || 1793ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_FAILURE(error)) { 179485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(error, "Setting and retrieving of the normalization on/off attribute failed\n"); 1795ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1796ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1797ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_NORMALIZATION_MODE, UCOL_OFF, &error); 1798ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getAttribute(coll, UCOL_NORMALIZATION_MODE, &error) != UCOL_OFF || 1799ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_FAILURE(error)) { 180085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(error, "Setting and retrieving of the normalization on/off attribute failed\n"); 1801ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1802ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1803ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_STRENGTH, UCOL_PRIMARY, &error); 1804ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getAttribute(coll, UCOL_STRENGTH, &error) != UCOL_PRIMARY || 1805ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_FAILURE(error)) { 180685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(error, "Setting and retrieving of the collation strength failed\n"); 1807ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1808ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1809ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_STRENGTH, UCOL_SECONDARY, &error); 1810ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getAttribute(coll, UCOL_STRENGTH, &error) != UCOL_SECONDARY || 1811ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_FAILURE(error)) { 181285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(error, "Setting and retrieving of the collation strength failed\n"); 1813ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1814ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1815ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_STRENGTH, UCOL_TERTIARY, &error); 1816ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getAttribute(coll, UCOL_STRENGTH, &error) != UCOL_TERTIARY || 1817ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_FAILURE(error)) { 181885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(error, "Setting and retrieving of the collation strength failed\n"); 1819ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1820ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1821ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_STRENGTH, UCOL_QUATERNARY, &error); 1822ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getAttribute(coll, UCOL_STRENGTH, &error) != UCOL_QUATERNARY || 1823ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_FAILURE(error)) { 182485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(error, "Setting and retrieving of the collation strength failed\n"); 1825ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1826ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1827ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_STRENGTH, UCOL_IDENTICAL, &error); 1828ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getAttribute(coll, UCOL_STRENGTH, &error) != UCOL_IDENTICAL || 1829ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru U_FAILURE(error)) { 183085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(error, "Setting and retrieving of the collation strength failed\n"); 1831ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1832ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1833ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(coll); 1834ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1835ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1836ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestGetTailoredSet() { 1837ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru struct { 1838ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *rules; 1839ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *tests[20]; 1840ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t testsize; 1841ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } setTest[] = { 1842ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { "&a < \\u212b", { "\\u212b", "A\\u030a", "\\u00c5" }, 3}, 1843ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { "& S < \\u0161 <<< \\u0160", { "\\u0161", "s\\u030C", "\\u0160", "S\\u030C" }, 4} 1844ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }; 1845ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1846ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t i = 0, j = 0; 1847ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 1848ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UParseError pError; 1849ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1850ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *coll = NULL; 1851ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar buff[1024]; 1852ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t buffLen = 0; 1853ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru USet *set = NULL; 1854ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1855ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i = 0; i < sizeof(setTest)/sizeof(setTest[0]); i++) { 1856ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru buffLen = u_unescape(setTest[i].rules, buff, 1024); 1857ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru coll = ucol_openRules(buff, buffLen, UCOL_DEFAULT, UCOL_DEFAULT, &pError, &status); 1858ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)) { 1859ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru set = ucol_getTailoredSet(coll, &status); 1860ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(uset_size(set) != setTest[i].testsize) { 1861ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Tailored set size different (%d) than expected (%d)\n", uset_size(set), setTest[i].testsize); 1862ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1863ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(j = 0; j < setTest[i].testsize; j++) { 1864ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru buffLen = u_unescape(setTest[i].tests[j], buff, 1024); 1865ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(!uset_containsString(set, buff, buffLen)) { 1866ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Tailored set doesn't contain %s... It should\n", setTest[i].tests[j]); 1867ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1868ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1869ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uset_close(set); 1870ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 187185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "Couldn't open collator with rules %s\n", setTest[i].rules); 1872ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1873ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(coll); 1874ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1875ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1876ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 1877ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic int tMemCmp(const uint8_t *first, const uint8_t *second) { 1878ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t firstLen = (int32_t)strlen((const char *)first); 1879ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t secondLen = (int32_t)strlen((const char *)second); 1880ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return memcmp(first, second, uprv_min(firstLen, secondLen)); 1881ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 1882ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic const char * strengthsC[] = { 1883ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "UCOL_PRIMARY", 1884ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "UCOL_SECONDARY", 1885ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "UCOL_TERTIARY", 1886ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "UCOL_QUATERNARY", 1887ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "UCOL_IDENTICAL" 1888ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 188985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1890ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestMergeSortKeys(void) { 1891ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 1892ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *coll = ucol_open("en", &status); 1893ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)) { 189485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1895ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* cases[] = { 1896ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "abc", 1897ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "abcd", 1898ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "abcde" 1899ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }; 1900ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t casesSize = sizeof(cases)/sizeof(cases[0]); 1901ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* prefix = "foo"; 1902ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* suffix = "egg"; 1903ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char outBuff1[256], outBuff2[256]; 190485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1905ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t **sortkeys = (uint8_t **)malloc(casesSize*sizeof(uint8_t *)); 1906ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t **mergedPrefixkeys = (uint8_t **)malloc(casesSize*sizeof(uint8_t *)); 1907ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t **mergedSuffixkeys = (uint8_t **)malloc(casesSize*sizeof(uint8_t *)); 1908ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t *sortKeysLen = (uint32_t *)malloc(casesSize*sizeof(uint32_t)); 1909ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t prefixKey[256], suffixKey[256]; 1910ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t prefixKeyLen = 0, suffixKeyLen = 0, i = 0; 1911ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar buffer[256]; 1912ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t unescapedLen = 0, l1 = 0, l2 = 0; 1913ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UColAttributeValue strength; 191485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1915ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("ucol_mergeSortkeys test\n"); 1916ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Testing order of the test cases\n"); 1917ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru genericLocaleStarter("en", cases, casesSize); 191885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1919ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i = 0; i<casesSize; i++) { 1920ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortkeys[i] = (uint8_t *)malloc(256*sizeof(uint8_t)); 1921ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru mergedPrefixkeys[i] = (uint8_t *)malloc(256*sizeof(uint8_t)); 1922ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru mergedSuffixkeys[i] = (uint8_t *)malloc(256*sizeof(uint8_t)); 1923ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 192485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1925ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru unescapedLen = u_unescape(prefix, buffer, 256); 1926ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru prefixKeyLen = ucol_getSortKey(coll, buffer, unescapedLen, prefixKey, 256); 192785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1928ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru unescapedLen = u_unescape(suffix, buffer, 256); 1929ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru suffixKeyLen = ucol_getSortKey(coll, buffer, unescapedLen, suffixKey, 256); 193085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1931ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Massaging data with prefixes and different strengths\n"); 1932ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strength = UCOL_PRIMARY; 1933ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru while(strength <= UCOL_IDENTICAL) { 1934ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Strength %s\n", strengthsC[strength<=UCOL_QUATERNARY?strength:4]); 1935ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_setAttribute(coll, UCOL_STRENGTH, strength, &status); 1936ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i = 0; i<casesSize; i++) { 1937ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru unescapedLen = u_unescape(cases[i], buffer, 256); 1938ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru sortKeysLen[i] = ucol_getSortKey(coll, buffer, unescapedLen, sortkeys[i], 256); 1939ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_mergeSortkeys(prefixKey, prefixKeyLen, sortkeys[i], sortKeysLen[i], mergedPrefixkeys[i], 256); 1940ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_mergeSortkeys(sortkeys[i], sortKeysLen[i], suffixKey, suffixKeyLen, mergedSuffixkeys[i], 256); 1941ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(i>0) { 1942ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(tMemCmp(mergedPrefixkeys[i-1], mergedPrefixkeys[i]) >= 0) { 1943ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Error while comparing prefixed keys @ strength %s:\n", strengthsC[strength<=UCOL_QUATERNARY?strength:4]); 194485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("%s\n%s\n", 1945103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius ucol_sortKeyToString(coll, mergedPrefixkeys[i-1], outBuff1, l1), 1946103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius ucol_sortKeyToString(coll, mergedPrefixkeys[i], outBuff2, l2)); 1947ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1948ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(tMemCmp(mergedSuffixkeys[i-1], mergedSuffixkeys[i]) >= 0) { 1949ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Error while comparing suffixed keys @ strength %s:\n", strengthsC[strength<=UCOL_QUATERNARY?strength:4]); 195085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("%s\n%s\n", 1951103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius ucol_sortKeyToString(coll, mergedSuffixkeys[i-1], outBuff1, l1), 1952103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius ucol_sortKeyToString(coll, mergedSuffixkeys[i], outBuff2, l2)); 1953ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1954ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1955ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1956ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strength == UCOL_QUATERNARY) { 1957ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strength = UCOL_IDENTICAL; 1958ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 1959ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru strength++; 1960ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1961ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 196285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1963ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1964ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t smallBuf[3]; 1965ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t reqLen = 0; 1966ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("testing buffer overflow\n"); 1967ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru reqLen = ucol_mergeSortkeys(prefixKey, prefixKeyLen, suffixKey, suffixKeyLen, smallBuf, 3); 19688393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius if(reqLen != (prefixKeyLen+suffixKeyLen)) { 1969ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Wrong preflight size for merged sortkey\n"); 1970ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1971ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 197285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1973ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 1974ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar empty = 0; 1975ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t emptyKey[20], abcKey[50], mergedKey[100]; 1976ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t emptyKeyLen = 0, abcKeyLen = 0, mergedKeyLen = 0; 197785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1978ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("testing merging with sortkeys generated for empty strings\n"); 1979ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru emptyKeyLen = ucol_getSortKey(coll, &empty, 0, emptyKey, 20); 1980ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru unescapedLen = u_unescape(cases[0], buffer, 256); 1981ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru abcKeyLen = ucol_getSortKey(coll, buffer, unescapedLen, abcKey, 50); 1982ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru mergedKeyLen = ucol_mergeSortkeys(emptyKey, emptyKeyLen, abcKey, abcKeyLen, mergedKey, 100); 1983ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(mergedKey[0] != 2) { 1984ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Empty sortkey didn't produce a level separator\n"); 1985ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1986ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* try with zeros */ 1987ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru mergedKeyLen = ucol_mergeSortkeys(emptyKey, 0, abcKey, abcKeyLen, mergedKey, 100); 1988ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(mergedKeyLen != 0 || mergedKey[0] != 0) { 1989ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Empty key didn't produce null mergedKey\n"); 1990ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 1991ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru mergedKeyLen = ucol_mergeSortkeys(abcKey, abcKeyLen, emptyKey, 0, mergedKey, 100); 1992ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(mergedKeyLen != 0 || mergedKey[0] != 0) { 1993ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Empty key didn't produce null mergedKey\n"); 1994ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 199585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1996ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 199785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 1998ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i = 0; i<casesSize; i++) { 1999ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(sortkeys[i]); 2000ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(mergedPrefixkeys[i]); 2001ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(mergedSuffixkeys[i]); 2002ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2003ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(sortkeys); 2004ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(mergedPrefixkeys); 2005ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(mergedSuffixkeys); 2006ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(sortKeysLen); 2007ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(coll); 2008ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* need to finish this up */ 2009ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 2010ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_data_err("Couldn't open collator"); 2011ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2012ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 201385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic void TestShortString(void) 2014ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 2015ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru struct { 2016ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *input; 2017ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *expectedOutput; 2018ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *locale; 2019ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode expectedStatus; 2020ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t expectedOffset; 2021ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint32_t expectedIdentifier; 2022ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } testCases[] = { 202350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* 202427f654740f2a26ad62a5c155af9199af9e69b889claireho * The following expectedOutput contains a collation weight (2700 from UCA 6.0) 202550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * which is the primary weight for the T character (U+0041) in the input. 202650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * When that character gets a different weight in FractionalUCA.txt, 202750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * the expectedOutput needs to be adjusted. 202850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * That is, when we upgrade to a new UCA version or change collation 202950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * in such a way that the absolute weight for 'A' changes, 203050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * we will get a test failure here and need to adjust the test case. 203150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho */ 203227f654740f2a26ad62a5c155af9199af9e69b889claireho {"LDE_RDE_KPHONEBOOK_T0041_ZLATN","B2700_KPHONEBOOK_LDE", "de@collation=phonebook", U_USING_FALLBACK_WARNING, 0, 0 }, 203350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 203427f654740f2a26ad62a5c155af9199af9e69b889claireho {"LEN_RUS_NO_AS_S4","AS_LROOT_NO_S4", NULL, U_USING_DEFAULT_WARNING, 0, 0 }, 2035ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"LDE_VPHONEBOOK_EO_SI","EO_KPHONEBOOK_LDE_SI", "de@collation=phonebook", U_ZERO_ERROR, 0, 0 }, 2036ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"LDE_Kphonebook","KPHONEBOOK_LDE", "de@collation=phonebook", U_ZERO_ERROR, 0, 0 }, 2037ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"Xqde_DE@collation=phonebookq_S3_EX","KPHONEBOOK_LDE", "de@collation=phonebook", U_USING_FALLBACK_WARNING, 0, 0 }, 203827f654740f2a26ad62a5c155af9199af9e69b889claireho {"LFR_FO", "FO_LROOT", NULL, U_USING_DEFAULT_WARNING, 0, 0 }, 2039ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"SO_LX_AS", "", NULL, U_ILLEGAL_ARGUMENT_ERROR, 8, 0 }, 2040ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru {"S3_ASS_MMM", "", NULL, U_ILLEGAL_ARGUMENT_ERROR, 5, 0 } 2041ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }; 2042ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 204385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho int32_t i = 0; 204485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UCollator *coll = NULL, *fromNormalized = NULL; 2045ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UParseError parseError; 2046ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 204785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho char fromShortBuffer[256], normalizedBuffer[256], fromNormalizedBuffer[256]; 2048ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* locale = NULL; 2049ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2050ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2051ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i = 0; i < sizeof(testCases)/sizeof(testCases[0]); i++) { 2052ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 2053ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(testCases[i].locale) { 2054ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru locale = testCases[i].locale; 2055ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 2056ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru locale = NULL; 2057ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2058ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2059ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru coll = ucol_openFromShortString(testCases[i].input, FALSE, &parseError, &status); 2060ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(status != testCases[i].expectedStatus) { 206185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "Got status '%s' that is different from expected '%s' for '%s'\n", 2062ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_errorName(status), u_errorName(testCases[i].expectedStatus), testCases[i].input); 206385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho continue; 2064ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 206585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 2066ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)) { 2067ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_getShortDefinitionString(coll, locale, fromShortBuffer, 256, &status); 2068ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2069ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strcmp(fromShortBuffer, testCases[i].expectedOutput)) { 2070ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Got short string '%s' from the collator. Expected '%s' for input '%s'\n", 2071ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fromShortBuffer, testCases[i].expectedOutput, testCases[i].input); 2072ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2073ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2074ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_normalizeShortDefinitionString(testCases[i].input, normalizedBuffer, 256, &parseError, &status); 2075ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fromNormalized = ucol_openFromShortString(normalizedBuffer, FALSE, &parseError, &status); 2076ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_getShortDefinitionString(fromNormalized, locale, fromNormalizedBuffer, 256, &status); 2077ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2078ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(strcmp(fromShortBuffer, fromNormalizedBuffer)) { 207985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("Strings obtained from collators instantiated by short string ('%s') and from normalized string ('%s') differ\n", 2080ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fromShortBuffer, fromNormalizedBuffer); 2081ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2082ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2083ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2084ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(!ucol_equals(coll, fromNormalized)) { 208585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("Collator from short string ('%s') differs from one obtained through a normalized version ('%s')\n", 2086ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru testCases[i].input, normalizedBuffer); 2087ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2088ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2089ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(fromNormalized); 2090ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(coll); 2091ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2092ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 2093ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(parseError.offset != testCases[i].expectedOffset) { 2094ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Got parse error offset %i, but expected %i instead for '%s'\n", 2095ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru parseError.offset, testCases[i].expectedOffset, testCases[i].input); 2096ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2097ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2098ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2099ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 2101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void 2103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerudoSetsTest(const char *locale, const USet *ref, USet *set, const char* inSet, const char* outSet, UErrorCode *status) { 2104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar buffer[512]; 2105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t bufLen; 2106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uset_clear(set); 210885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho bufLen = u_unescape(inSet, buffer, 512); 2109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uset_applyPattern(set, buffer, bufLen, 0, status); 2110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(*status)) { 2111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("%s: Failure setting pattern %s\n", locale, u_errorName(*status)); 2112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(!uset_containsAll(ref, set)) { 2115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("%s: Some stuff from %s is not present in the set\n", locale, inSet); 2116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uset_clear(set); 211985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho bufLen = u_unescape(outSet, buffer, 512); 2120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uset_applyPattern(set, buffer, bufLen, 0, status); 2121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(*status)) { 2122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("%s: Failure setting pattern %s\n", locale, u_errorName(*status)); 2123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(!uset_containsNone(ref, set)) { 2126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("%s: Some stuff from %s is present in the set\n", locale, outSet); 2127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 2129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 213385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic void 213485bf2e2fbc60a9f938064abc8127d61da7d19882Claire HoTestGetContractionsAndUnsafes(void) 2135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 2136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru static struct { 2137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* locale; 2138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* inConts; 2139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* outConts; 2140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* inExp; 2141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* outExp; 2142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* unsafeCodeUnits; 2143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char* safeCodeUnits; 2144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } tests[] = { 214585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho { "ru", 214627f654740f2a26ad62a5c155af9199af9e69b889claireho "[{\\u0418\\u0306}{\\u0438\\u0306}]", 214727f654740f2a26ad62a5c155af9199af9e69b889claireho "[\\u0439\\u0457]", 2148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[\\u00e6]", 214927f654740f2a26ad62a5c155af9199af9e69b889claireho "[ae]", 215027f654740f2a26ad62a5c155af9199af9e69b889claireho "[\\u0418\\u0438]", 2151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[aAbB\\u0430\\u0410\\u0433\\u0413]" 2152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }, 2153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { "uk", 215427f654740f2a26ad62a5c155af9199af9e69b889claireho "[{\\u0406\\u0308}{\\u0456\\u0308}{\\u0418\\u0306}{\\u0438\\u0306}]", 215527f654740f2a26ad62a5c155af9199af9e69b889claireho "[\\u0407\\u0419\\u0439\\u0457]", 2156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[\\u00e6]", 215727f654740f2a26ad62a5c155af9199af9e69b889claireho "[ae]", 215827f654740f2a26ad62a5c155af9199af9e69b889claireho "[\\u0406\\u0456\\u0418\\u0438]", 2159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[aAbBxv]", 2160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }, 2161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { "sh", 2162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[{C\\u0301}{C\\u030C}{C\\u0341}{DZ\\u030C}{Dz\\u030C}{D\\u017D}{D\\u017E}{lj}{nj}]", 2163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[{\\u309d\\u3099}{\\u30fd\\u3099}]", 2164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[\\u00e6]", 2165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[a]", 2166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[nlcdzNLCDZ]", 2167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[jabv]" 2168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }, 2169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { "ja", 2170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-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}]", 2171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[{\\u30FD\\u3099}{\\u309D\\u3099}{\\u3053\\u3099}{\\u30B3\\u3099}{lj}{nj}]", 2172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[\\u30FE\\u00e6]", 2173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[a]", 2174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[\\u3099]", 2175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[]" 2176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }; 2178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 2183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *coll = NULL; 2184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t i = 0; 2185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t noConts = 0; 2186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru USet *conts = uset_open(0,0); 2187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru USet *exp = uset_open(0, 0); 2188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru USet *set = uset_open(0,0); 2189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t setBufferLen = 65536; 2190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar buffer[65536]; 2191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t setLen = 0; 2192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) { 2194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Testing locale: %s\n", tests[i].locale); 2195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru coll = ucol_open(tests[i].locale, &status); 219685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if (coll == NULL || U_FAILURE(status)) { 219785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "Unable to open collator for locale %s ==> %s\n", tests[i].locale, u_errorName(status)); 219885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho continue; 219985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 2200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_getContractionsAndExpansions(coll, conts, exp, TRUE, &status); 2201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doSetsTest(tests[i].locale, conts, set, tests[i].inConts, tests[i].outConts, &status); 2202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru setLen = uset_toPattern(conts, buffer, setBufferLen, TRUE, &status); 2203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)) { 2204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*log_verbose("Contractions %i: %s\n", uset_getItemCount(conts), aescstrdup(buffer, setLen));*/ 2205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 2206ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("error %s. %i\n", u_errorName(status), setLen); 2207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 2208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doSetsTest(tests[i].locale, exp, set, tests[i].inExp, tests[i].outExp, &status); 2210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru setLen = uset_toPattern(exp, buffer, setBufferLen, TRUE, &status); 2211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)) { 2212ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /*log_verbose("Expansions %i: %s\n", uset_getItemCount(exp), aescstrdup(buffer, setLen));*/ 2213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 2214ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("error %s. %i\n", u_errorName(status), setLen); 2215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 2216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru noConts = ucol_getUnsafeSet(coll, conts, &status); 2219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru doSetsTest(tests[i].locale, conts, set, tests[i].unsafeCodeUnits, tests[i].safeCodeUnits, &status); 2220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru setLen = uset_toPattern(conts, buffer, setBufferLen, TRUE, &status); 2221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_SUCCESS(status)) { 2222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_verbose("Unsafe %i: %s\n", uset_getItemCount(exp), aescstrdup(buffer, setLen)); 2223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 2224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("error %s. %i\n", u_errorName(status), setLen); 2225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 2226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(coll); 2229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uset_close(conts); 2233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uset_close(exp); 2234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uset_close(set); 2235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 2236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 223785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic void 223885bf2e2fbc60a9f938064abc8127d61da7d19882Claire HoTestOpenBinary(void) 2239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 2240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 2241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* 2242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char rule[] = "&h < d < c < b"; 2243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char *wUCA[] = { "a", "h", "d", "c", "b", "i" }; 2244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char *noUCA[] = {"d", "c", "b", "a", "h", "i" }; 2245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 2246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* we have to use Cyrillic letters because latin-1 always gets copied */ 2247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char rule[] = "&\\u0452 < \\u0434 < \\u0433 < \\u0432"; /* &dje < d < g < v */ 2248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *wUCA[] = { "\\u0430", "\\u0452", "\\u0434", "\\u0433", "\\u0432", "\\u0435" }; /* a, dje, d, g, v, e */ 2249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const char *noUCA[] = {"\\u0434", "\\u0433", "\\u0432", "\\u0430", "\\u0435", "\\u0452" }; /* d, g, v, a, e, dje */ 2250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar uRules[256]; 2252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t uRulesLen = u_unescape(rule, uRules, 256); 2253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *coll = ucol_openRules(uRules, uRulesLen, UCOL_DEFAULT, UCOL_DEFAULT, NULL, &status); 225585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UCollator *UCA = NULL; 2256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *cloneNOUCA = NULL, *cloneWUCA = NULL; 2257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t imageBuffer[32768]; 2259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru uint8_t *image = imageBuffer; 2260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t imageBufferCapacity = 32768; 2261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t imageSize; 2263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 226485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if((coll==NULL)||(U_FAILURE(status))) { 2265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_data_err("could not load collators or error occured: %s\n", 2266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_errorName(status)); 2267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 226885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 226985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UCA = ucol_open("root", &status); 227085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if((UCA==NULL)||(U_FAILURE(status))) { 227185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_data_err("could not load UCA collator or error occured: %s\n", 227285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho u_errorName(status)); 227385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho return; 227485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 2275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru imageSize = ucol_cloneBinary(coll, image, imageBufferCapacity, &status); 2276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(U_FAILURE(status)) { 2277ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru image = (uint8_t *)malloc(imageSize*sizeof(uint8_t)); 2278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 2279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru imageSize = ucol_cloneBinary(coll, imageBuffer, imageSize, &status); 2280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2281ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2282ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2283ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru cloneWUCA = ucol_openBinary(image, imageSize, UCA, &status); 2284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru cloneNOUCA = ucol_openBinary(image, imageSize, NULL, &status); 2285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2286ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru genericOrderingTest(coll, wUCA, sizeof(wUCA)/sizeof(wUCA[0])); 2287ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2288ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru genericOrderingTest(cloneWUCA, wUCA, sizeof(wUCA)/sizeof(wUCA[0])); 2289ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru genericOrderingTest(cloneNOUCA, noUCA, sizeof(noUCA)/sizeof(noUCA[0])); 2290ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2291ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(image != imageBuffer) { 2292ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru free(image); 2293ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2294ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(coll); 2295ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(cloneNOUCA); 2296ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(cloneWUCA); 2297ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(UCA); 2298ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 2299ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2300ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestDefault(void) { 2301ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* Tests for code coverage. */ 2302ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 2303ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UCollator *coll = ucol_open("es@collation=pinyin", &status); 230485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if (coll == NULL || status == U_FILE_ACCESS_ERROR) { 230585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_data_err("Unable to open collator es@collation=pinyin\n"); 230685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho return; 230785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 2308ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (status != U_USING_DEFAULT_WARNING) { 2309ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru /* What do you mean that you know about using pinyin collation in Spanish!? This should be in the zh locale. */ 2310ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("es@collation=pinyin should return U_USING_DEFAULT_WARNING, but returned %s\n", u_errorName(status)); 2311ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2312ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_close(coll); 2313ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getKeywordValues("funky", &status) != NULL) { 2314ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("Collators should not know about the funky keyword.\n"); 2315ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2316ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (status != U_ILLEGAL_ARGUMENT_ERROR) { 2317ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("funky keyword didn't fail as expected %s\n", u_errorName(status)); 2318ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2319ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (ucol_getKeywordValues("collation", &status) != NULL) { 2320ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru log_err("ucol_getKeywordValues should not work when given a bad status.\n"); 2321ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 2322ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 2323ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 232485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic void TestDefaultKeyword(void) { 232585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho /* Tests for code coverage. */ 232685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UErrorCode status = U_ZERO_ERROR; 232785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho const char *loc = "zh_TW@collation=default"; 232885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UCollator *coll = ucol_open(loc, &status); 232985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if(U_FAILURE(status)) { 233085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_info("Warning: ucol_open(%s, ...) returned %s, at least it didn't crash.\n", loc, u_errorName(status)); 233185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } else if (status != U_USING_FALLBACK_WARNING) { 233227f654740f2a26ad62a5c155af9199af9e69b889claireho /* Hmm, skip the following test for CLDR 1.9 data and/or ICU 4.6, no longer seems to apply */ 233327f654740f2a26ad62a5c155af9199af9e69b889claireho #if 0 233485bf2e2fbc60a9f938064abc8127d61da7d19882Claire 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)); 233527f654740f2a26ad62a5c155af9199af9e69b889claireho #endif 233685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 233785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho ucol_close(coll); 233885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho} 233985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 234085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic void TestGetKeywordValuesForLocale(void) { 234127f654740f2a26ad62a5c155af9199af9e69b889claireho#define INCLUDE_UNIHAN_COLLATION 0 234285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho#define PREFERRED_SIZE 16 23438393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius#define MAX_NUMBER_OF_KEYWORDS 8 234485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho const char *PREFERRED[PREFERRED_SIZE][MAX_NUMBER_OF_KEYWORDS+1] = { 23458393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius { "und", "standard", "search", NULL, NULL, NULL, NULL, NULL, NULL }, 23468393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius { "en_US", "standard", "search", NULL, NULL, NULL, NULL, NULL, NULL }, 23478393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius { "en_029", "standard", "search", NULL, NULL, NULL, NULL, NULL, NULL }, 23488393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius { "de_DE", "standard", "phonebook", "search", NULL, NULL, NULL, NULL, NULL }, 23498393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius { "de_Latn_DE", "standard", "phonebook", "search", NULL, NULL, NULL, NULL, NULL }, 235027f654740f2a26ad62a5c155af9199af9e69b889claireho#if INCLUDE_UNIHAN_COLLATION 23518393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius { "zh", "pinyin", "big5han", "gb2312han", "stroke", "zhuyin", "unihan", "search", "standard" }, 23528393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius { "zh_Hans", "pinyin", "big5han", "gb2312han", "stroke", "zhuyin", "unihan", "search", "standard" }, 23538393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius { "zh_CN", "pinyin", "big5han", "gb2312han", "stroke", "zhuyin", "unihan", "search", "standard" }, 23548393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius { "zh_Hant", "stroke", "big5han", "gb2312han", "pinyin", "zhuyin", "unihan", "search", "standard" }, 23558393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius { "zh_TW", "stroke", "big5han", "gb2312han", "pinyin", "zhuyin", "unihan", "search", "standard" }, 23568393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius { "zh__PINYIN", "pinyin", "big5han", "gb2312han", "stroke", "zhuyin", "unihan", "search", "standard" }, 235727f654740f2a26ad62a5c155af9199af9e69b889claireho#else 23588393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius // BEGIN android-changed. No big5han, gb2312han, or zhuyin in Android 23598393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius { "zh", "pinyin", "stroke", "search", "standard", NULL, NULL, NULL, NULL }, 23608393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius { "zh_Hans", "pinyin", "stroke", "search", "standard", NULL, NULL, NULL, NULL }, 23618393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius { "zh_CN", "pinyin", "stroke", "search", "standard", NULL, NULL, NULL, NULL }, 23628393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius { "zh_Hant", "stroke", "pinyin", "search", "standard", NULL, NULL, NULL, NULL }, 23638393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius { "zh_TW", "stroke", "pinyin", "search", "standard", NULL, NULL, NULL, NULL }, 23648393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius { "zh__PINYIN", "pinyin", "stroke", "search", "standard", NULL, NULL, NULL, NULL }, 23658393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius // END android-changed 236627f654740f2a26ad62a5c155af9199af9e69b889claireho#endif 23678393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius { "es_ES", "standard", "search", "traditional", NULL, NULL, NULL, NULL, NULL }, 23688393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius { "es__TRADITIONAL","traditional", "search", "standard", NULL, NULL, NULL, NULL, NULL }, 23698393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius { "und@collation=phonebook", "standard", "search", NULL, NULL, NULL, NULL, NULL, NULL }, 23708393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius { "de_DE@collation=big5han", "standard", "phonebook", "search", NULL, NULL, NULL, NULL, NULL}, 23718393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius 23728393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius { "zzz@collation=xxx", "standard", "search", NULL, NULL, NULL, NULL, NULL, NULL } 237385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho }; 237427f654740f2a26ad62a5c155af9199af9e69b889claireho#if INCLUDE_UNIHAN_COLLATION 23758393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius const int32_t expectedLength[PREFERRED_SIZE] = { 2, 2, 2, 3, 3, 8, 8, 8, 8, 8, 8, 3, 3, 2, 3, 2 }; 237627f654740f2a26ad62a5c155af9199af9e69b889claireho#else 23778393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius // BEGIN android-change 23788393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius // Fewer cases are expected for "zh*" since Android removes collation sequences to save space. 23798393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius const int32_t expectedLength[PREFERRED_SIZE] = { 2, 2, 2, 3, 3, 4, 4, 4, 4, 4, 4, 3, 3, 2, 3, 2 }; 23808393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius // END android-change 238127f654740f2a26ad62a5c155af9199af9e69b889claireho#endif 238285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 238385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UErrorCode status = U_ZERO_ERROR; 238485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UEnumeration *keywordValues = NULL; 238585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho int32_t i, n, size, valueLength; 238685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho const char *locale = NULL, *value = NULL; 238785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho UBool errorOccurred = FALSE; 238885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 238985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho for (i = 0; i < PREFERRED_SIZE; i++) { 239085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho locale = PREFERRED[i][0]; 239185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho value = NULL; 239285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho valueLength = 0; 239385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho size = 0; 239485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 239585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho keywordValues = ucol_getKeywordValuesForLocale("collation", locale, TRUE, &status); 239685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if (keywordValues == NULL || U_FAILURE(status)) { 239785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err_status(status, "Error getting keyword values: %s\n", u_errorName(status)); 239885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho break; 239985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 240085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho size = uenum_count(keywordValues, &status); 240185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 240285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if (size == expectedLength[i]) { 240385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho for (n = 0; n < expectedLength[i]; n++) { 240485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if ((value = uenum_next(keywordValues, &valueLength, &status)) != NULL && U_SUCCESS(status)) { 240585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if (uprv_strcmp(value, PREFERRED[i][n+1]) != 0) { 240685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("Keyword values differ: Got [%s] Expected [%s] for locale: %s\n", value, PREFERRED[i][n+1], locale); 240785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho errorOccurred = TRUE; 240885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho break; 240985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 241085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 241185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } else { 241285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("While getting keyword value from locale: %s got this error: %s\n", locale, u_errorName(status)); 241385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho errorOccurred = TRUE; 241485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho break; 241585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 241685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 241785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if (errorOccurred) { 241885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho break; 241985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 242085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } else { 242185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho log_err("Number of keywords (%d) does not match expected size (%d) for locale: %s\n", size, expectedLength[i], locale); 242285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho break; 242385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 242485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho uenum_close(keywordValues); 242585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho keywordValues = NULL; 242685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 242785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho if (keywordValues != NULL) { 242885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho uenum_close(keywordValues); 242985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho } 243085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho} 243185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 243285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho 2433ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif /* #if !UCONFIG_NO_COLLATION */ 2434