1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/********************************************************************
2b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho * Copyright (c) 1997-2011 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
4285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* next two function is modified from "i18n/ucol.cpp" to avoid include "ucol_imp.h" */
45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void uprv_appendByteToHexString(char *dst, uint8_t val) {
46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  uint32_t len = (uint32_t)strlen(dst);
47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  sprintf(dst+len, "%02X", val);
48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic char* U_EXPORT2 ucol_sortKeyToString(const UCollator *coll, const uint8_t *sortkey, char *buffer, uint32_t *len) {
51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  int32_t strength = UCOL_PRIMARY;
52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  uint32_t res_size = 0;
53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  UBool doneCase = FALSE;
54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  char *current = buffer;
56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  const uint8_t *currentSk = sortkey;
57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  UErrorCode error_code = U_ZERO_ERROR;
59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  strcpy(current, "[");
61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  while(strength <= UCOL_QUATERNARY && strength <= ucol_getAttribute(coll,UCOL_STRENGTH, &error_code)) {
63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(error_code)) {
64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      log_err("ucol_getAttribute returned error: %s\n", u_errorName(error_code));
65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(strength > UCOL_PRIMARY) {
67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      strcat(current, " . ");
68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    while(*currentSk != 0x01 && *currentSk != 0x00) { /* print a level */
70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      uprv_appendByteToHexString(current, *currentSk++);
71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      strcat(current, " ");
72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(ucol_getAttribute(coll,UCOL_CASE_LEVEL, &error_code) == UCOL_ON && strength == UCOL_SECONDARY && doneCase == FALSE) {
74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        doneCase = TRUE;
75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else if(ucol_getAttribute(coll,UCOL_CASE_LEVEL, &error_code) == UCOL_OFF || doneCase == TRUE || strength != UCOL_SECONDARY) {
76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      strength ++;
77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(error_code)) {
79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      log_err("ucol_getAttribute returned error: %s\n", u_errorName(error_code));
80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uprv_appendByteToHexString(current, *currentSk++); /* This should print '01' */
82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(strength == UCOL_QUATERNARY && ucol_getAttribute(coll,UCOL_ALTERNATE_HANDLING, &error_code) == UCOL_NON_IGNORABLE) {
83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      break;
84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  }
86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  if(ucol_getAttribute(coll,UCOL_STRENGTH, &error_code) == UCOL_IDENTICAL) {
88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    strcat(current, " . ");
89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    while(*currentSk != 0) {
90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      uprv_appendByteToHexString(current, *currentSk++);
91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      strcat(current, " ");
92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uprv_appendByteToHexString(current, *currentSk++);
95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  }
96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  if(U_FAILURE(error_code)) {
97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_err("ucol_getAttribute returned error: %s\n", u_errorName(error_code));
98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  }
99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  strcat(current, "]");
100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  if(res_size > *len) {
102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return NULL;
103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  }
104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  return buffer;
106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* end of  avoid include "ucol_imp.h" */
108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid addCollAPITest(TestNode** root)
111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* WEIVTODO: return tests here */
113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestProperty,      "tscoll/capitst/TestProperty");
114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestRuleBasedColl, "tscoll/capitst/TestRuleBasedColl");
115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestCompare,       "tscoll/capitst/TestCompare");
116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestSortKey,       "tscoll/capitst/TestSortKey");
117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestHashCode,      "tscoll/capitst/TestHashCode");
118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestElemIter,      "tscoll/capitst/TestElemIter");
119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestGetAll,        "tscoll/capitst/TestGetAll");
120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*addTest(root, &TestGetDefaultRules, "tscoll/capitst/TestGetDefaultRules");*/
121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestDecomposition, "tscoll/capitst/TestDecomposition");
122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestSafeClone, "tscoll/capitst/TestSafeClone");
123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestCloneBinary, "tscoll/capitst/TestCloneBinary");
124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestGetSetAttr, "tscoll/capitst/TestGetSetAttr");
125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestBounds, "tscoll/capitst/TestBounds");
126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestGetLocale, "tscoll/capitst/TestGetLocale");
127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestSortKeyBufferOverrun, "tscoll/capitst/TestSortKeyBufferOverrun");
128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestAttribute, "tscoll/capitst/TestAttribute");
129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestGetTailoredSet, "tscoll/capitst/TestGetTailoredSet");
130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestMergeSortKeys, "tscoll/capitst/TestMergeSortKeys");
131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestShortString, "tscoll/capitst/TestShortString");
132ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho    /* BEGIN android-removed
133ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho       To save space, Android does not include the collation tailoring rules.
134ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho       We skip the tailing tests for collations. */
135ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho    /* addTest(root, &TestGetContractionsAndUnsafes, "tscoll/capitst/TestGetContractionsAndUnsafes"); */
136ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho    /* END android-removed */
137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestOpenBinary, "tscoll/capitst/TestOpenBinary");
138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestDefault, "tscoll/capitst/TestDefault");
13985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    addTest(root, &TestDefaultKeyword, "tscoll/capitst/TestDefaultKeyword");
140ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho    /* BEGIN android-removed
141ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho       To save space, Android does not build full collation tables and tailing rules.
142ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho       We skip the related tests. */
143ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho    /* addTest(root, &TestOpenVsOpenRules, "tscoll/capitst/TestOpenVsOpenRules"); */
144ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho    /* addTest(root, &TestGetKeywordValuesForLocale, "tscoll/capitst/TestGetKeywordValuesForLocale"); */
145ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho    /* END android-removed */
146b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    addTest(root, &TestBengaliSortKey, "tscoll/capitst/TestBengaliSortKey");
147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestGetSetAttr(void) {
150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  UErrorCode status = U_ZERO_ERROR;
151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  UCollator *coll = ucol_open(NULL, &status);
152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  struct attrTest {
153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UColAttribute att;
154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UColAttributeValue val[5];
155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint32_t valueSize;
156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UColAttributeValue nonValue;
157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  } attrs[] = {
158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {UCOL_FRENCH_COLLATION, {UCOL_ON, UCOL_OFF}, 2, UCOL_SHIFTED},
159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {UCOL_ALTERNATE_HANDLING, {UCOL_NON_IGNORABLE, UCOL_SHIFTED}, 2, UCOL_OFF},/* attribute for handling variable elements*/
160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {UCOL_CASE_FIRST, {UCOL_OFF, UCOL_LOWER_FIRST, UCOL_UPPER_FIRST}, 3, UCOL_SHIFTED},/* who goes first, lower case or uppercase */
161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {UCOL_CASE_LEVEL, {UCOL_ON, UCOL_OFF}, 2, UCOL_SHIFTED},/* do we have an extra case level */
162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {UCOL_NORMALIZATION_MODE, {UCOL_ON, UCOL_OFF}, 2, UCOL_SHIFTED},/* attribute for normalization */
163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {UCOL_DECOMPOSITION_MODE, {UCOL_ON, UCOL_OFF}, 2, UCOL_SHIFTED},
164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {UCOL_STRENGTH,         {UCOL_PRIMARY, UCOL_SECONDARY, UCOL_TERTIARY, UCOL_QUATERNARY, UCOL_IDENTICAL}, 5, UCOL_SHIFTED},/* attribute for strength */
165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {UCOL_HIRAGANA_QUATERNARY_MODE, {UCOL_ON, UCOL_OFF}, 2, UCOL_SHIFTED},/* when turned on, this attribute */
166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  };
167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  UColAttribute currAttr;
16885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho  UColAttributeValue value;
169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  uint32_t i = 0, j = 0;
170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
17185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho  if (coll == NULL) {
17285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    log_err_status(status, "Unable to open collator. %s\n", u_errorName(status));
17385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    return;
17485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho  }
175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  for(i = 0; i<sizeof(attrs)/sizeof(attrs[0]); i++) {
176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    currAttr = attrs[i].att;
177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setAttribute(coll, currAttr, UCOL_DEFAULT, &status);
178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)) {
17985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho      log_err_status(status, "ucol_setAttribute with the default value returned error: %s\n", u_errorName(status));
180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      break;
181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    value = ucol_getAttribute(coll, currAttr, &status);
183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)) {
184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      log_err("ucol_getAttribute returned error: %s\n", u_errorName(status));
185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      break;
186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for(j = 0; j<attrs[i].valueSize; j++) {
188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      ucol_setAttribute(coll, currAttr, attrs[i].val[j], &status);
189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      if(U_FAILURE(status)) {
190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("ucol_setAttribute with the value %i returned error: %s\n", attrs[i].val[j], u_errorName(status));
191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        break;
192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      }
193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    status = U_ZERO_ERROR;
195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setAttribute(coll, currAttr, attrs[i].nonValue, &status);
196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_SUCCESS(status)) {
197ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      log_err("ucol_setAttribute with the bad value didn't return an error\n");
198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      break;
199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    status = U_ZERO_ERROR;
201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setAttribute(coll, currAttr, value, &status);
203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)) {
204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      log_err("ucol_setAttribute with the default valuereturned error: %s\n", u_errorName(status));
205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      break;
206ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  }
208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  status = U_ZERO_ERROR;
209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  value = ucol_getAttribute(coll, UCOL_ATTRIBUTE_COUNT, &status);
210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  if(U_SUCCESS(status)) {
211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_err("ucol_getAttribute for UCOL_ATTRIBUTE_COUNT didn't return an error\n");
212ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  }
213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  status = U_ZERO_ERROR;
214ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  ucol_setAttribute(coll, UCOL_ATTRIBUTE_COUNT, UCOL_DEFAULT, &status);
215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  if(U_SUCCESS(status)) {
216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_err("ucol_setAttribute for UCOL_ATTRIBUTE_COUNT didn't return an error\n");
217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  }
218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  status = U_ZERO_ERROR;
219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  ucol_close(coll);
220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void doAssert(int condition, const char *message)
224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (condition==0) {
226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("ERROR :  %s\n", message);
227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if 0
231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* We don't have default rules, at least not in the previous sense */
232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestGetDefaultRules(){
233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint32_t size=0;
234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status=U_ZERO_ERROR;
235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator *coll=NULL;
236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t len1 = 0, len2=0;
237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t *binColData = NULL;
238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UResourceBundle *res = NULL;
240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UResourceBundle *binColl = NULL;
241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t *binResult = NULL;
24285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
24385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const UChar * defaultRulesArray=ucol_getDefaultRulesArray(&size);
245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Test the function ucol_getDefaultRulesArray()\n");
246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    coll = ucol_openRules(defaultRulesArray, size, UCOL_ON, UCOL_PRIMARY, &status);
248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_SUCCESS(status) && coll !=NULL) {
249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        binColData = (uint8_t*)ucol_cloneRuleData(coll, &len1, &status);
25085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
25385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    status=U_ZERO_ERROR;
255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    res=ures_open(NULL, "root", &status);
256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)){
257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("ERROR: Failed to get resource for \"root Locale\" with %s", myErrorName(status));
258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
26085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    binColl=ures_getByKey(res, "%%Collation", binColl, &status);
261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_SUCCESS(status)){
262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        binResult=(uint8_t*)ures_getBinary(binColl,  &len2, &status);
263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(U_FAILURE(status)){
264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("ERROR: ures_getBinary() failed\n");
265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }else{
267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("ERROR: ures_getByKey(locale(default), %%Collation) failed");
268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
269ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
270ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(len1 != len2){
272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Error: ucol_getDefaultRulesArray() failed to return the correct length.\n");
273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
274ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(memcmp(binColData, binResult, len1) != 0){
275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Error: ucol_getDefaultRulesArray() failed\n");
276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
277ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(binColData);
279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ures_close(binColl);
280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ures_close(res);
281ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(coll);
28285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
283ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
286ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* Collator Properties
287ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_open, ucol_strcoll,  getStrength/setStrength
288ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru getDecomposition/setDecomposition, getDisplayName*/
289ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestProperty()
29085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho{
291ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator *col, *ruled;
292ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar *disName;
29327f654740f2a26ad62a5c155af9199af9e69b889claireho    int32_t len = 0;
294ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar *source, *target;
295ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t tempLength;
296ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
29785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    /*
29850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho     * Expected version of the English collator.
29950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho     * Currently, the major/minor version numbers change when the builder code
30050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho     * changes,
30150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho     * number 2 is from the tailoring data version and
30250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho     * number 3 is the UCA version.
30350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho     * This changes with every UCA version change, and the expected value
30450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho     * needs to be adjusted.
30550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho     * Same in intltest/apicoll.cpp.
30650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho     */
30727f654740f2a26ad62a5c155af9199af9e69b889claireho    UVersionInfo currVersionArray = {0x31, 0xC0, 0x05, 0x2A};  /* from ICU 4.4/UCA 5.2 */
308ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UVersionInfo versionArray = {0, 0, 0, 0};
309ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UVersionInfo versionUCAArray = {0, 0, 0, 0};
31027f654740f2a26ad62a5c155af9199af9e69b889claireho    UVersionInfo versionUCDArray = {0, 0, 0, 0};
31185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
312ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("The property tests begin : \n");
313ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Test ucol_strcoll : \n");
314ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    col = ucol_open("en_US", &status);
315ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
31685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(status, "Default Collator creation failed.: %s\n", myErrorName(status));
317ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
318ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
319ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
320ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_getVersion(col, versionArray);
32127f654740f2a26ad62a5c155af9199af9e69b889claireho    /* Check for a version greater than some value rather than equality
32227f654740f2a26ad62a5c155af9199af9e69b889claireho     * so that we need not update the expected version each time. */
32327f654740f2a26ad62a5c155af9199af9e69b889claireho    if (uprv_memcmp(versionArray, currVersionArray, 4)<0) {
32427f654740f2a26ad62a5c155af9199af9e69b889claireho      log_err("Testing ucol_getVersion() - unexpected result: %02x.%02x.%02x.%02x\n",
32527f654740f2a26ad62a5c155af9199af9e69b889claireho              versionArray[0], versionArray[1], versionArray[2], versionArray[3]);
32627f654740f2a26ad62a5c155af9199af9e69b889claireho    } else {
32727f654740f2a26ad62a5c155af9199af9e69b889claireho      log_verbose("ucol_getVersion() result: %02x.%02x.%02x.%02x\n",
32827f654740f2a26ad62a5c155af9199af9e69b889claireho                  versionArray[0], versionArray[1], versionArray[2], versionArray[3]);
329ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
330ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
33127f654740f2a26ad62a5c155af9199af9e69b889claireho    /* Assume that the UCD and UCA versions are the same,
33227f654740f2a26ad62a5c155af9199af9e69b889claireho     * rather than hardcoding (and updating each time) a particular UCA version. */
33327f654740f2a26ad62a5c155af9199af9e69b889claireho    u_getUnicodeVersion(versionUCDArray);
334ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_getUCAVersion(col, versionUCAArray);
33527f654740f2a26ad62a5c155af9199af9e69b889claireho    if (0!=uprv_memcmp(versionUCAArray, versionUCDArray, 4)) {
33627f654740f2a26ad62a5c155af9199af9e69b889claireho      log_err("Testing ucol_getUCAVersion() - unexpected result: %hu.%hu.%hu.%hu\n",
33727f654740f2a26ad62a5c155af9199af9e69b889claireho              versionUCAArray[0], versionUCAArray[1], versionUCAArray[2], versionUCAArray[3]);
338ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
339ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
340ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    source=(UChar*)malloc(sizeof(UChar) * 12);
341ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    target=(UChar*)malloc(sizeof(UChar) * 12);
34285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
343ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
344ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(source, "ab");
345ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(target, "abc");
34685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
347ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert((ucol_strcoll(col, source, u_strlen(source), target, u_strlen(target)) == UCOL_LESS), "ab < abc comparison failed");
348ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
349ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(source, "ab");
350ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(target, "AB");
351ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
352ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert((ucol_strcoll(col, source, u_strlen(source), target, u_strlen(target)) == UCOL_LESS), "ab < AB comparison failed");
353ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*    u_uastrcpy(source, "black-bird");
354ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(target, "blackbird"); */
355ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(target, "black-bird");
356ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(source, "blackbird");
357ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
35885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    doAssert((ucol_strcoll(col, source, u_strlen(source), target, u_strlen(target)) == UCOL_GREATER),
359ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "black-bird > blackbird comparison failed");
360ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(source, "black bird");
361ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(target, "black-bird");
36285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    doAssert((ucol_strcoll(col, source, u_strlen(source), target, u_strlen(target)) == UCOL_LESS),
363ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "black bird < black-bird comparison failed");
364ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(source, "Hello");
365ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(target, "hello");
366ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
36785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    doAssert((ucol_strcoll(col, source, u_strlen(source), target, u_strlen(target)) == UCOL_GREATER),
368ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "Hello > hello comparison failed");
369ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(source);
370ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(target);
371ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Test ucol_strcoll ends.\n");
372ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
373ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("testing ucol_getStrength() method ...\n");
374ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (ucol_getStrength(col) == UCOL_TERTIARY), "collation object has the wrong strength");
375ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (ucol_getStrength(col) != UCOL_PRIMARY), "collation object's strength is primary difference");
37685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
377ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("testing ucol_setStrength() method ...\n");
378ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setStrength(col, UCOL_SECONDARY);
379ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (ucol_getStrength(col) != UCOL_TERTIARY), "collation object's strength is secondary difference");
380ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (ucol_getStrength(col) != UCOL_PRIMARY), "collation object's strength is primary difference");
381ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (ucol_getStrength(col) == UCOL_SECONDARY), "collation object has the wrong strength");
382ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
38385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
384ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Get display name for the default collation in German : \n");
385ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
386ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    len=ucol_getDisplayName("en_US", "de_DE", NULL, 0,  &status);
387ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(status==U_BUFFER_OVERFLOW_ERROR){
388ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        status=U_ZERO_ERROR;
389ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        disName=(UChar*)malloc(sizeof(UChar) * (len+1));
390ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_getDisplayName("en_US", "de_DE", disName, len+1,  &status);
391ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("the display name for default collation in german: %s\n", austrdup(disName) );
392ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        free(disName);
393ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
394ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)){
395ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("ERROR: in getDisplayName: %s\n", myErrorName(status));
396ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
397ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
398ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Default collation getDisplayName ended.\n");
399ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
400ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho    /* BEGIN android-removed
401ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho       To save space, Android does not include the collation tailoring rules.
402ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho       Skip the related tests.
403b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
404ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ruled = ucol_open("da_DK", &status);
405ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("ucol_getRules() testing ...\n");
406ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_getRules(ruled, &tempLength);
407ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( tempLength != 0, "getRules() result incorrect" );
408ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("getRules tests end.\n");
409ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
410ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        UChar *buffer = (UChar *)malloc(200000*sizeof(UChar));
411ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        int32_t bufLen = 200000;
412ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        buffer[0] = '\0';
413ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("ucol_getRulesEx() testing ...\n");
414ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        tempLength = ucol_getRulesEx(col,UCOL_TAILORING_ONLY,buffer,bufLen );
415b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        doAssert( tempLength == 0x00, "getRulesEx() result incorrect" );
416ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("getRules tests end.\n");
41785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
418ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("ucol_getRulesEx() testing ...\n");
419ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        tempLength=ucol_getRulesEx(col,UCOL_FULL_RULES,buffer,bufLen );
420ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        doAssert( tempLength != 0, "getRulesEx() result incorrect" );
421ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("getRules tests end.\n");
422ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        free(buffer);
423ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
424ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(ruled);
425b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    ucol_close(col);
42685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
427ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho    END android-removed */
428ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho
429ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("open an collator for french locale");
430ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    col = ucol_open("fr_FR", &status);
431ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
432ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       log_err("ERROR: Creating French collation failed.: %s\n", myErrorName(status));
433ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
434ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
435ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setStrength(col, UCOL_PRIMARY);
436ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("testing ucol_getStrength() method again ...\n");
437ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (ucol_getStrength(col) != UCOL_TERTIARY), "collation object has the wrong strength");
438ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (ucol_getStrength(col) == UCOL_PRIMARY), "collation object's strength is not primary difference");
43985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
440ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("testing French ucol_setStrength() method ...\n");
441ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setStrength(col, UCOL_TERTIARY);
442ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (ucol_getStrength(col) == UCOL_TERTIARY), "collation object's strength is not tertiary difference");
443ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (ucol_getStrength(col) != UCOL_PRIMARY), "collation object's strength is primary difference");
444ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (ucol_getStrength(col) != UCOL_SECONDARY), "collation object's strength is secondary difference");
445ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(col);
44685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
447ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Get display name for the french collation in english : \n");
448ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    len=ucol_getDisplayName("fr_FR", "en_US", NULL, 0,  &status);
449ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(status==U_BUFFER_OVERFLOW_ERROR){
450ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        status=U_ZERO_ERROR;
451ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        disName=(UChar*)malloc(sizeof(UChar) * (len+1));
452ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_getDisplayName("fr_FR", "en_US", disName, len+1,  &status);
453ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("the display name for french collation in english: %s\n", austrdup(disName) );
454ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        free(disName);
455ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
456ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)){
457ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("ERROR: in getDisplayName: %s\n", myErrorName(status));
458ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
459ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
460ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Default collation getDisplayName ended.\n");
461ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
462ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
463ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
464ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* Test RuleBasedCollator and getRules*/
465ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestRuleBasedColl()
466ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
467ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator *col1, *col2, *col3, *col4;
468ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollationElements *iter1, *iter2;
469ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar ruleset1[60];
470ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar ruleset2[50];
471ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar teststr[10];
472ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar teststr2[10];
473ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const UChar *rule1, *rule2, *rule3, *rule4;
474ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t tempLength;
475ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
476ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(ruleset1, "&9 < a, A < b, B < c, C; ch, cH, Ch, CH < d, D, e, E");
477ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(ruleset2, "&9 < a, A < b, B < c, C < d, D, e, E");
47885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
479ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
480ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    col1 = ucol_openRules(ruleset1, u_strlen(ruleset1), UCOL_DEFAULT, UCOL_DEFAULT_STRENGTH, NULL,&status);
481ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
48285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(status, "RuleBased Collator creation failed.: %s\n", myErrorName(status));
483ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
484ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
485ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    else
486ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("PASS: RuleBased Collator creation passed\n");
48785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
488ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    status = U_ZERO_ERROR;
489ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    col2 = ucol_openRules(ruleset2, u_strlen(ruleset2),  UCOL_DEFAULT, UCOL_DEFAULT_STRENGTH, NULL, &status);
490ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
491ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("RuleBased Collator creation failed.: %s\n", myErrorName(status));
492ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
493ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
494ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    else
495ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("PASS: RuleBased Collator creation passed\n");
49685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
49785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
498ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    status = U_ZERO_ERROR;
499ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    col3= ucol_open(NULL, &status);
500ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
501ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Default Collator creation failed.: %s\n", myErrorName(status));
502ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
503ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
504ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    else
505ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("PASS: Default Collator creation passed\n");
50685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
507ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    rule1 = ucol_getRules(col1, &tempLength);
508ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    rule2 = ucol_getRules(col2, &tempLength);
509ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    rule3 = ucol_getRules(col3, &tempLength);
510ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
511ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert((u_strcmp(rule1, rule2) != 0), "Default collator getRules failed");
512ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert((u_strcmp(rule2, rule3) != 0), "Default collator getRules failed");
513ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert((u_strcmp(rule1, rule3) != 0), "Default collator getRules failed");
51485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
515ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    col4=ucol_openRules(rule2, u_strlen(rule2), UCOL_DEFAULT, UCOL_DEFAULT_STRENGTH, NULL, &status);
516ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
517ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("RuleBased Collator creation failed.: %s\n", myErrorName(status));
518ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
519ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
520ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    rule4= ucol_getRules(col4, &tempLength);
521ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert((u_strcmp(rule2, rule4) == 0), "Default collator getRules failed");
522ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
523ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(col1);
524ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(col2);
525ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(col3);
526ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(col4);
52785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
528ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* tests that modifier ! is always ignored */
529ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(ruleset1, "!&a<b");
530ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    teststr[0] = 0x0e40;
531ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    teststr[1] = 0x0e01;
532ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    teststr[2] = 0x0e2d;
533ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    col1 = ucol_openRules(ruleset1, u_strlen(ruleset1), UCOL_DEFAULT, UCOL_DEFAULT_STRENGTH, NULL, &status);
534ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
535ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("RuleBased Collator creation failed.: %s\n", myErrorName(status));
536ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
537ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
538ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    col2 = ucol_open("en_US", &status);
539ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
540ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("en_US Collator creation failed.: %s\n", myErrorName(status));
541ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
542ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
543ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    iter1 = ucol_openElements(col1, teststr, 3, &status);
544ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    iter2 = ucol_openElements(col2, teststr, 3, &status);
545ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)) {
546ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("ERROR: CollationElement iterator creation failed.: %s\n", myErrorName(status));
547ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
548ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
549ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    while (TRUE) {
550ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* testing with en since thai has its own tailoring */
551ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        uint32_t ce = ucol_next(iter1, &status);
552ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        uint32_t ce2 = ucol_next(iter2, &status);
553ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(U_FAILURE(status)) {
554ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("ERROR: CollationElement iterator creation failed.: %s\n", myErrorName(status));
555ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            return;
556ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
557ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (ce2 != ce) {
558ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru             log_err("! modifier test failed");
559ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
560ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (ce == UCOL_NULLORDER) {
561ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            break;
562ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
563ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
564ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_closeElements(iter1);
565ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_closeElements(iter2);
566ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(col1);
567ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(col2);
568ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* test that we can start a rule without a & or < */
569ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(ruleset1, "< z < a");
570ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    col1 = ucol_openRules(ruleset1, u_strlen(ruleset1), UCOL_DEFAULT, UCOL_DEFAULT_STRENGTH, NULL, &status);
571ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
572ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("RuleBased Collator creation failed.: %s\n", myErrorName(status));
573ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
574ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
575ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(teststr, "z");
576ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(teststr2, "a");
577ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_greaterOrEqual(col1, teststr, 1, teststr2, 1)) {
578ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Rule \"z < a\" fails");
57985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    }
580ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(col1);
581ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
582ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
583ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestCompare()
584ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
585ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
586ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator *col;
587ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar* test1;
588ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar* test2;
58985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
590ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("The compare tests begin : \n");
591ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    status=U_ZERO_ERROR;
592ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    col = ucol_open("en_US", &status);
593ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)) {
59485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(status, "ucal_open() collation creation failed.: %s\n", myErrorName(status));
595ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
596ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
597ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    test1=(UChar*)malloc(sizeof(UChar) * 6);
598ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    test2=(UChar*)malloc(sizeof(UChar) * 6);
599ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(test1, "Abcda");
600ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(test2, "abcda");
60185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
602ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Use tertiary comparison level testing ....\n");
60385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
604ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (!ucol_equal(col, test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"Abcda\" != \"abcda\" ");
605ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (ucol_greater(col, test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"Abcda\" >>> \"abcda\" ");
60685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    doAssert( (ucol_greaterOrEqual(col, test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"Abcda\" >>> \"abcda\"");
607ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
608ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setStrength(col, UCOL_SECONDARY);
609ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Use secondary comparison level testing ....\n");
61085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
611ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (ucol_equal(col, test1, u_strlen(test1), test2, u_strlen(test2) )), "Result should be \"Abcda\" == \"abcda\"");
612ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (!ucol_greater(col, test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"Abcda\" == \"abcda\"");
61385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    doAssert( (ucol_greaterOrEqual(col, test1, u_strlen(test1), test2, u_strlen(test2) )), "Result should be \"Abcda\" == \"abcda\"");
614ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
615ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setStrength(col, UCOL_PRIMARY);
616ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Use primary comparison level testing ....\n");
61785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
618ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (ucol_equal(col, test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"Abcda\" == \"abcda\"");
619ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (!ucol_greater(col, test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"Abcda\" == \"abcda\"");
62085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    doAssert( (ucol_greaterOrEqual(col, test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"Abcda\" == \"abcda\"");
62185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
622ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
623ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("The compare tests end.\n");
624ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(col);
625ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(test1);
626ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(test2);
62785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
628ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
629ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*
630ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru---------------------------------------------
631ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tests decomposition setting
632ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/
633ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestDecomposition() {
634ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
635ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator *en_US, *el_GR, *vi_VN;
636ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    en_US = ucol_open("en_US", &status);
637ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    el_GR = ucol_open("el_GR", &status);
638ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    vi_VN = ucol_open("vi_VN", &status);
639ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
640ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
64185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(status, "ERROR: collation creation failed.: %s\n", myErrorName(status));
642ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
643ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
644ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
645ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getAttribute(vi_VN, UCOL_NORMALIZATION_MODE, &status) != UCOL_ON ||
646ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        U_FAILURE(status))
647ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
648ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("ERROR: vi_VN collation did not have cannonical decomposition for normalization!\n");
649ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
650ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
651ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    status = U_ZERO_ERROR;
652ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getAttribute(el_GR, UCOL_NORMALIZATION_MODE, &status) != UCOL_ON ||
653ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        U_FAILURE(status))
654ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
655ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("ERROR: el_GR collation did not have cannonical decomposition for normalization!\n");
656ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
657ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
658ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    status = U_ZERO_ERROR;
659ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getAttribute(en_US, UCOL_NORMALIZATION_MODE, &status) != UCOL_OFF ||
660ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        U_FAILURE(status))
661ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
662ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("ERROR: en_US collation had cannonical decomposition for normalization!\n");
663ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
664ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
665ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(en_US);
666ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(el_GR);
667ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(vi_VN);
668ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
669ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
670ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define CLONETEST_COLLATOR_COUNT 4
671ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
672ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestSafeClone() {
67385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    UChar test1[6];
67485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    UChar test2[6];
675ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const UChar umlautUStr[] = {0x00DC, 0};
676ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const UChar oeStr[] = {0x0055, 0x0045, 0};
677ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator * someCollators [CLONETEST_COLLATOR_COUNT];
678ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator * someClonedCollators [CLONETEST_COLLATOR_COUNT];
679ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator * col;
680ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode err = U_ZERO_ERROR;
68185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    int8_t index = 6;    /* Leave this here to test buffer alingment in memory*/
682ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t buffer [CLONETEST_COLLATOR_COUNT] [U_COL_SAFECLONE_BUFFERSIZE];
683ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t bufferSize = U_COL_SAFECLONE_BUFFERSIZE;
684ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char sampleRuleChars[] = "&Z < CH";
685ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar sampleRule[sizeof(sampleRuleChars)];
686ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
687ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (TestBufferSize()) {
688ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("U_COL_SAFECLONE_BUFFERSIZE should be larger than sizeof(UCollator)\n");
689ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
690ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
691ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
692ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(test1, "abCda");
693ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(test2, "abcda");
694ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(sampleRule, sampleRuleChars);
69585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
696ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* one default collator & two complex ones */
697ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    someCollators[0] = ucol_open("en_US", &err);
698ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    someCollators[1] = ucol_open("ko", &err);
699ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    someCollators[2] = ucol_open("ja_JP", &err);
700ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    someCollators[3] = ucol_openRules(sampleRule, -1, UCOL_ON, UCOL_TERTIARY, NULL, &err);
701ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(err)) {
70285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        for (index = 0; index < CLONETEST_COLLATOR_COUNT; index++) {
70385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            ucol_close(someCollators[index]);
70485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        }
705ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_data_err("Couldn't open one or more collators\n");
706ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
707ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
708ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
709ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Check the various error & informational states: */
710ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
711ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Null status - just returns NULL */
712ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (0 != ucol_safeClone(someCollators[0], buffer[0], &bufferSize, 0))
713ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
714ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: Cloned Collator failed to deal correctly with null status\n");
715ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
716ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* error status - should return 0 & keep error the same */
717ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    err = U_MEMORY_ALLOCATION_ERROR;
718ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (0 != ucol_safeClone(someCollators[0], buffer[0], &bufferSize, &err) || err != U_MEMORY_ALLOCATION_ERROR)
719ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
720ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: Cloned Collator failed to deal correctly with incoming error status\n");
721ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
722ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    err = U_ZERO_ERROR;
723ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
724ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Null buffer size pointer - just returns NULL & set error to U_ILLEGAL_ARGUMENT_ERROR*/
725ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (0 != ucol_safeClone(someCollators[0], buffer[0], 0, &err) || err != U_ILLEGAL_ARGUMENT_ERROR)
726ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
727ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: Cloned Collator failed to deal correctly with null bufferSize pointer\n");
728ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
729ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    err = U_ZERO_ERROR;
73085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
731ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* buffer size pointer is 0 - fill in pbufferSize with a size */
732ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    bufferSize = 0;
733ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (0 != ucol_safeClone(someCollators[0], buffer[0], &bufferSize, &err) || U_FAILURE(err) || bufferSize <= 0)
734ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
735ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: Cloned Collator failed a sizing request ('preflighting')\n");
736ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
737ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Verify our define is large enough  */
738ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_COL_SAFECLONE_BUFFERSIZE < bufferSize)
739ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
740ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: Pre-calculated buffer size is too small\n");
741ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
742ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Verify we can use this run-time calculated size */
743ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (0 == (col = ucol_safeClone(someCollators[0], buffer[0], &bufferSize, &err)) || U_FAILURE(err))
744ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
745ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: Collator can't be cloned with run-time size\n");
746ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
747ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (col) ucol_close(col);
748ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* size one byte too small - should allocate & let us know */
749ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    --bufferSize;
750ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (0 == (col = ucol_safeClone(someCollators[0], 0, &bufferSize, &err)) || err != U_SAFECLONE_ALLOCATED_WARNING)
751ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
752ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: Cloned Collator failed to deal correctly with too-small buffer size\n");
753ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
754ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (col) ucol_close(col);
755ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    err = U_ZERO_ERROR;
756ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    bufferSize = U_COL_SAFECLONE_BUFFERSIZE;
757ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
758ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
759ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Null buffer pointer - return Collator & set error to U_SAFECLONE_ALLOCATED_ERROR */
760ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (0 == (col = ucol_safeClone(someCollators[0], 0, &bufferSize, &err)) || err != U_SAFECLONE_ALLOCATED_WARNING)
761ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
762ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: Cloned Collator failed to deal correctly with null buffer pointer\n");
763ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
764ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (col) ucol_close(col);
765ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    err = U_ZERO_ERROR;
766ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
767ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Null Collator - return NULL & set U_ILLEGAL_ARGUMENT_ERROR */
768ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (0 != ucol_safeClone(0, buffer[0], &bufferSize, &err) || err != U_ILLEGAL_ARGUMENT_ERROR)
769ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
770ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: Cloned Collator failed to deal correctly with null Collator pointer\n");
771ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
772ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
773ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    err = U_ZERO_ERROR;
774ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
775ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Test that a cloned collator doesn't accidentally use UCA. */
776ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    col=ucol_open("de@collation=phonebook", &err);
777ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    bufferSize = U_COL_SAFECLONE_BUFFERSIZE;
778ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    someClonedCollators[0] = ucol_safeClone(col, buffer[0], &bufferSize, &err);
779ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (ucol_greater(col, umlautUStr, u_strlen(umlautUStr), oeStr, u_strlen(oeStr))), "Original German phonebook collation sorts differently than expected");
780ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (ucol_greater(someClonedCollators[0], umlautUStr, u_strlen(umlautUStr), oeStr, u_strlen(oeStr))), "Cloned German phonebook collation sorts differently than expected");
781ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (!ucol_equals(someClonedCollators[0], col)) {
782ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: Cloned German phonebook collator is not equal to original.\n");
783ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
784ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(col);
785ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(someClonedCollators[0]);
786ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
787ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    err = U_ZERO_ERROR;
788ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
789ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* change orig & clone & make sure they are independent */
790ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
791ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for (index = 0; index < CLONETEST_COLLATOR_COUNT; index++)
792ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
793ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_setStrength(someCollators[index], UCOL_IDENTICAL);
794ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        bufferSize = 1;
795ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        err = U_ZERO_ERROR;
796ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_close(ucol_safeClone(someCollators[index], buffer[index], &bufferSize, &err));
797ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (err != U_SAFECLONE_ALLOCATED_WARNING) {
798ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("FAIL: collator number %d was not allocated.\n", index);
79985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            log_err("FAIL: status of Collator[%d] is %d  (hex: %x).\n", index, err, err);
800ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
801ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
802ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        bufferSize = U_COL_SAFECLONE_BUFFERSIZE;
803ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        err = U_ZERO_ERROR;
804ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        someClonedCollators[index] = ucol_safeClone(someCollators[index], buffer[index], &bufferSize, &err);
805ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (someClonedCollators[index] == NULL
806ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            || someClonedCollators[index] < (UCollator *)buffer[index]
807ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            || someClonedCollators[index] > (UCollator *)(buffer[index]+(U_COL_SAFECLONE_BUFFERSIZE-1)))
808ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {
809ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("FAIL: Cloned collator didn't use provided buffer.\n");
810ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            return;
811ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
812ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (!ucol_equals(someClonedCollators[index], someCollators[index])) {
813ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("FAIL: Cloned collator is not equal to original at index = %d.\n", index);
814ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
815ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
816ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* Check the usability */
817ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_setStrength(someCollators[index], UCOL_PRIMARY);
818ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_setAttribute(someCollators[index], UCOL_CASE_LEVEL, UCOL_OFF, &err);
81985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
820ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        doAssert( (ucol_equal(someCollators[index], test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"abcda\" == \"abCda\"");
82185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
822ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* Close the original to make sure that the clone is usable. */
823ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_close(someCollators[index]);
824ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
825ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_setStrength(someClonedCollators[index], UCOL_TERTIARY);
826ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_setAttribute(someClonedCollators[index], UCOL_CASE_LEVEL, UCOL_OFF, &err);
827ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        doAssert( (ucol_greater(someClonedCollators[index], test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"abCda\" >>> \"abcda\" ");
828ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
829ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_close(someClonedCollators[index]);
830ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
831ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
832ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
833ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestCloneBinary(){
834ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode err = U_ZERO_ERROR;
835ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator * col = ucol_open("en_US", &err);
836ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator * c;
837ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t size;
838ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t * buffer;
839ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
840ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(err)) {
841ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_data_err("Couldn't open collator. Error: %s\n", u_errorName(err));
842ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
843ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
844ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
845ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    size = ucol_cloneBinary(col, NULL, 0, &err);
846ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(size==0 || err!=U_BUFFER_OVERFLOW_ERROR) {
847ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("ucol_cloneBinary - couldn't check size. Error: %s\n", u_errorName(err));
848ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
849ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
850ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    err = U_ZERO_ERROR;
851ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
852ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    buffer = (uint8_t *) malloc(size);
853ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_cloneBinary(col, buffer, size, &err);
854ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(err)) {
855ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("ucol_cloneBinary - couldn't clone.. Error: %s\n", u_errorName(err));
856ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        free(buffer);
857ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
858ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
859ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
860ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* how to check binary result ? */
861ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
862ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    c = ucol_openBinary(buffer, size, col, &err);
863ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(err)) {
864ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("ucol_openBinary failed. Error: %s\n", u_errorName(err));
865ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
866ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        UChar t[] = {0x41, 0x42, 0x43, 0};  /* ABC */
867ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        uint8_t  *k1, *k2;
868ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        int l1, l2;
869ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        l1 = ucol_getSortKey(col, t, -1, NULL,0);
870ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        l2 = ucol_getSortKey(c, t, -1, NULL,0);
871ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        k1 = (uint8_t *) malloc(sizeof(uint8_t) * l1);
872ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        k2 = (uint8_t *) malloc(sizeof(uint8_t) * l2);
873ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_getSortKey(col, t, -1, k1, l1);
874ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_getSortKey(col, t, -1, k2, l2);
875ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (strcmp((char *)k1,(char *)k2) != 0){
876ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("ucol_openBinary - new collator should equal to old one\n");
877ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        };
878ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        free(k1);
879ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        free(k2);
880ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
881ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(buffer);
882ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(c);
883ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(col);
884ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
885b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
886b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
887b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2clairehostatic void TestBengaliSortKey(void)
888b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho{
889b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  const char *curLoc = "bn";
890b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  UChar str1[] = { 0x09BE, 0 };
891b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  UChar str2[] = { 0x0B70, 0 };
892b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  UCollator *c2 = NULL;
893b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  const UChar *rules;
894b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  int32_t rulesLength=-1;
895b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  uint8_t *sortKey1;
896b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  int32_t sortKeyLen1 = 0;
897b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  uint8_t *sortKey2;
898b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  int32_t sortKeyLen2 = 0;
899b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  UErrorCode status = U_ZERO_ERROR;
900b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  char sortKeyStr1[2048];
901b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  uint32_t sortKeyStrLen1 = sizeof(sortKeyStr1)/sizeof(sortKeyStr1[0]);
902b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  char sortKeyStr2[2048];
903b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  uint32_t sortKeyStrLen2 = sizeof(sortKeyStr2)/sizeof(sortKeyStr2[0]);
904b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  UCollationResult result;
905b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
906b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  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};
907b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
908b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  rules = preRules;
909b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
910b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  log_verbose("Rules: %s\n", aescstrdup(rules, rulesLength));
911b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
912b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  c2 = ucol_openRules(rules, rulesLength, UCOL_DEFAULT, UCOL_DEFAULT_STRENGTH, NULL, &status);
913b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  if (U_FAILURE(status)) {
914b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    log_data_err("ERROR: Creating collator from rules failed with locale: %s : %s\n", curLoc, myErrorName(status));
915b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    return;
916b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  }
917b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
918b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  sortKeyLen1 = ucol_getSortKey(c2, str1, -1, NULL, 0);
919b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  sortKey1 = (uint8_t*)malloc(sortKeyLen1+1);
920b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  ucol_getSortKey(c2,str1,-1,sortKey1, sortKeyLen1+1);
921b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  ucol_sortKeyToString(c2, sortKey1, sortKeyStr1, &sortKeyStrLen1);
922b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
923b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
924b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  sortKeyLen2 = ucol_getSortKey(c2, str2, -1, NULL, 0);
925b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  sortKey2 = (uint8_t*)malloc(sortKeyLen2+1);
926b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  ucol_getSortKey(c2,str2,-1,sortKey2, sortKeyLen2+1);
927b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
928b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  ucol_sortKeyToString(c2, sortKey2, sortKeyStr2, &sortKeyStrLen2);
929b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
930b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
931b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
932b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  result=ucol_strcoll(c2, str1, -1, str2, -1);
933b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  if(result!=UCOL_LESS) {
934b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    log_err("Error: %s was not less than %s: result=%d.\n", aescstrdup(str1,-1), aescstrdup(str2,-1), result);
935b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    log_info("[%s] -> %s (%d, from rule)\n", aescstrdup(str1,-1), sortKeyStr1, sortKeyLen1);
936b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    log_info("[%s] -> %s (%d, from rule)\n", aescstrdup(str2,-1), sortKeyStr2, sortKeyLen2);
937b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  } else {
938b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    log_verbose("OK: %s was  less than %s: result=%d.\n", aescstrdup(str1,-1), aescstrdup(str2,-1), result);
939b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    log_verbose("[%s] -> %s (%d, from rule)\n", aescstrdup(str1,-1), sortKeyStr1, sortKeyLen1);
940b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    log_verbose("[%s] -> %s (%d, from rule)\n", aescstrdup(str2,-1), sortKeyStr2, sortKeyLen2);
941b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  }
942b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
943b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  free(sortKey1);
944b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  free(sortKey2);
945b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  ucol_close(c2);
946b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
947b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho}
948b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
949ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*
95085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    TestOpenVsOpenRules ensures that collators from ucol_open and ucol_openRules
95185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    will generate identical sort keys
95285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho*/
95385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hovoid TestOpenVsOpenRules(){
95485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
95585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    /* create an array of all the locales */
95685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    int32_t numLocales = uloc_countAvailable();
95785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    int32_t sizeOfStdSet;
95885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    uint32_t adder;
95985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    UChar str[41]; /* create an array of UChar of size maximum strSize + 1 */
96085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    USet *stdSet;
96185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    char* curLoc;
96285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    UCollator * c1;
96385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    UCollator * c2;
96485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    const UChar* rules;
96585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    int32_t rulesLength;
96685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    int32_t sortKeyLen1, sortKeyLen2;
96785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    uint8_t *sortKey1 = NULL, *sortKey2 = NULL;
96885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    ULocaleData *uld;
96950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    int32_t x, y, z;
97085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    USet *eSet;
97185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    int32_t eSize;
97285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    int strSize;
97385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
97485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    UErrorCode err = U_ZERO_ERROR;
97585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
97685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    /* create a set of standard characters that aren't very interesting...
97785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    and then we can find some interesting ones later */
97885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
97985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    stdSet = uset_open(0x61, 0x7A);
98085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    uset_addRange(stdSet, 0x41, 0x5A);
98185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    uset_addRange(stdSet, 0x30, 0x39);
98285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    sizeOfStdSet = uset_size(stdSet);
98385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
98485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    adder = 1;
98527f654740f2a26ad62a5c155af9199af9e69b889claireho    if(getTestOption(QUICK_OPTION))
98685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    {
98785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        adder = 10;
98885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    }
98985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
99085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    for(x = 0; x < numLocales; x+=adder){
99185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        curLoc = (char *)uloc_getAvailable(x);
99285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_verbose("Processing %s\n", curLoc);
99385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
99485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        /* create a collator the normal API way */
99585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        c1 = ucol_open(curLoc, &err);
99685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        if (U_FAILURE(err)) {
99785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            log_err("ERROR: Normal collation creation failed with locale: %s : %s\n", curLoc, myErrorName(err));
99885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            return;
99985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        }
100085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
100185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        /* grab the rules */
100285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        rules = ucol_getRules(c1, &rulesLength);
100385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
100485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        /* use those rules to create a collator from rules */
100585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        c2 = ucol_openRules(rules, rulesLength, UCOL_DEFAULT, UCOL_DEFAULT_STRENGTH, NULL, &err);
100685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        if (U_FAILURE(err)) {
100785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            log_err("ERROR: Creating collator from rules failed with locale: %s : %s\n", curLoc, myErrorName(err));
100885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            return;
100985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        }
101085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
101185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        uld = ulocdata_open(curLoc, &err);
101285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
101385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        /*now that we have some collators, we get several strings */
101485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
101585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        for(y = 0; y < 5; y++){
101685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
101785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            /* get a set of ALL the characters in this locale */
101885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            eSet =  ulocdata_getExemplarSet(uld, NULL, 0, ULOCDATA_ES_STANDARD, &err);
101985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            eSize = uset_size(eSet);
102085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
102185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            /* make a string with these characters in it */
102285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            strSize = (rand()%40) + 1;
102385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
102485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            for(z = 0; z < strSize; z++){
102585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                str[z] = uset_charAt(eSet, rand()%eSize);
102685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            }
102785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
102885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            /* change the set to only include 'abnormal' characters (not A-Z, a-z, 0-9 */
102985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            uset_removeAll(eSet, stdSet);
103085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            eSize = uset_size(eSet);
103185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
103285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            /* if there are some non-normal characters left, put a few into the string, just to make sure we have some */
103385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            if(eSize > 0){
103485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                str[2%strSize] = uset_charAt(eSet, rand()%eSize);
103585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                str[3%strSize] = uset_charAt(eSet, rand()%eSize);
103685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                str[5%strSize] = uset_charAt(eSet, rand()%eSize);
103785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                str[10%strSize] = uset_charAt(eSet, rand()%eSize);
103885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                str[13%strSize] = uset_charAt(eSet, rand()%eSize);
103985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            }
104085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            /* terminate the string */
104185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            str[strSize-1] = '\0';
104285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            log_verbose("String used: %S\n", str);
104385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
104485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            /* get sort keys for both of them, and check that the keys are identicle */
104585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            sortKeyLen1 = ucol_getSortKey(c1, str, u_strlen(str),  NULL, 0);
104685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            sortKey1 = (uint8_t*)malloc(sizeof(uint8_t) * (sortKeyLen1 + 1));
104785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            /*memset(sortKey1, 0xFE, sortKeyLen1);*/
104885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            ucol_getSortKey(c1, str, u_strlen(str), sortKey1, sortKeyLen1 + 1);
104985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
105085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            sortKeyLen2 = ucol_getSortKey(c2, str, u_strlen(str),  NULL, 0);
105185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            sortKey2 = (uint8_t*)malloc(sizeof(uint8_t) * (sortKeyLen2 + 1));
105285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            /*memset(sortKey2, 0xFE, sortKeyLen2);*/
105385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            ucol_getSortKey(c2, str, u_strlen(str), sortKey2, sortKeyLen2 + 1);
105485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
105585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            /* Check that the lengths are the same */
105685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            doAssert((sortKeyLen1 == sortKeyLen2), "Sort key lengths do not match.");
105785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
105885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            /* check that the keys are the same */
105985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            doAssert((memcmp(sortKey1, sortKey2, sortKeyLen1) == 0), "Keys are not equivalent");
106085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
106185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            /* clean up after each string */
106285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            free(sortKey1);
106385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            free(sortKey2);
106485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            uset_close(eSet);
106585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        }
106685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        /* clean up after each locale */
106785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        ulocdata_close(uld);
106885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        ucol_close(c1);
106985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        ucol_close(c2);
107085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    }
107185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    /* final clean up */
107285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    uset_close(stdSet);
107385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho}
107485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho/*
1075ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru----------------------------------------------------------------------------
1076ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ctor -- Tests the getSortKey
1077ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/
1078ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestSortKey()
107985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho{
1080ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t *sortk1 = NULL, *sortk2 = NULL, *sortk3 = NULL, *sortkEmpty = NULL;
1081ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t sortklen, osortklen;
1082ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint32_t toStringLen=0;
1083ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator *col;
1084ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar *test1, *test2, *test3;
1085ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
1086ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char toStringBuffer[256], *resultP;
1087ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1088ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1089ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t s1[] = { 0x9f, 0x00 };
1090ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t s2[] = { 0x61, 0x00 };
1091ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int  strcmpResult;
1092ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1093ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    strcmpResult = strcmp((const char *)s1, (const char *)s2);
1094ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("strcmp(0x9f..., 0x61...) = %d\n", strcmpResult);
109585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1096ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(strcmpResult <= 0) {
1097ac04d0bbe12b3ef54518635711412f178cb4d16Jean-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",
1098ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru              strcmpResult);
1099ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("testing SortKey begins...\n");
110385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    /* this is supposed to open default date format, but later on it treats it like it is "en_US"
1104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       - very bad if you try to run the tests on machine where default locale is NOT "en_US" */
1105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* col = ucol_open(NULL, &status); */
1106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    col = ucol_open("en_US", &status);
1107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
110885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(status, "ERROR: Default collation creation failed.: %s\n", myErrorName(status));
1109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(ucol_getStrength(col) != UCOL_DEFAULT_STRENGTH)
1114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
1115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("ERROR: default collation did not have UCOL_DEFAULT_STRENGTH !\n");
1116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Need to use identical strength */
1118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setAttribute(col, UCOL_STRENGTH, UCOL_IDENTICAL, &status);
1119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    test1=(UChar*)malloc(sizeof(UChar) * 6);
1121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    test2=(UChar*)malloc(sizeof(UChar) * 6);
1122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    test3=(UChar*)malloc(sizeof(UChar) * 6);
112385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    memset(test1,0xFE, sizeof(UChar)*6);
1125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    memset(test2,0xFE, sizeof(UChar)*6);
1126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    memset(test3,0xFE, sizeof(UChar)*6);
1127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(test1, "Abcda");
1130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(test2, "abcda");
1131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(test3, "abcda");
1132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Use tertiary comparison level testing ....\n");
1134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortklen=ucol_getSortKey(col, test1, u_strlen(test1),  NULL, 0);
1136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortk1=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen+1));
1137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    memset(sortk1,0xFE, sortklen);
1138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_getSortKey(col, test1, u_strlen(test1), sortk1, sortklen+1);
1139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortklen=ucol_getSortKey(col, test2, u_strlen(test2),  NULL, 0);
1141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortk2=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen+1));
1142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    memset(sortk2,0xFE, sortklen);
1143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_getSortKey(col, test2, u_strlen(test2), sortk2, sortklen+1);
1144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    osortklen = sortklen;
1146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortklen=ucol_getSortKey(col, test2, u_strlen(test3),  NULL, 0);
1147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortk3=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen+1));
1148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    memset(sortk3,0xFE, sortklen);
1149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_getSortKey(col, test2, u_strlen(test2), sortk3, sortklen+1);
1150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (sortklen == osortklen), "Sortkey length should be the same (abcda, abcda)");
1152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (memcmp(sortk1, sortk2, sortklen) > 0), "Result should be \"Abcda\" > \"abcda\"");
1154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (memcmp(sortk2, sortk1, sortklen) < 0), "Result should be \"abcda\" < \"Abcda\"");
1155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (memcmp(sortk2, sortk3, sortklen) == 0), "Result should be \"abcda\" ==  \"abcda\"");
1156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
115750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    resultP = ucol_sortKeyToString(col, sortk3, toStringBuffer, &toStringLen);
1158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (resultP != 0), "sortKeyToString failed!");
1159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if 1 /* verobse log of sortkeys */
1161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
1162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      char junk2[1000];
1163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      char junk3[1000];
1164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      int i;
1165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      strcpy(junk2, "abcda[2] ");
1167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      strcpy(junk3, " abcda[3] ");
1168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      for(i=0;i<sortklen;i++)
1170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {
1171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru          sprintf(junk2+strlen(junk2), "%02X ",(int)( 0xFF & sortk2[i]));
1172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru          sprintf(junk3+strlen(junk3), "%02X ",(int)( 0xFF & sortk3[i]));
1173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
117485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      log_verbose("%s\n", junk2);
1176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      log_verbose("%s\n", junk3);
1177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
1179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(sortk1);
1181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(sortk2);
1182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(sortk3);
1183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Use secondary comparision level testing ...\n");
1185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setStrength(col, UCOL_SECONDARY);
1186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortklen=ucol_getSortKey(col, test1, u_strlen(test1),  NULL, 0);
1187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortk1=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen+1));
1188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_getSortKey(col, test1, u_strlen(test1), sortk1, sortklen+1);
1189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortklen=ucol_getSortKey(col, test2, u_strlen(test2),  NULL, 0);
1190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortk2=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen+1));
1191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_getSortKey(col, test2, u_strlen(test2), sortk2, sortklen+1);
119285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( !(memcmp(sortk1, sortk2, sortklen) > 0), "Result should be \"Abcda\" == \"abcda\"");
1194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( !(memcmp(sortk2, sortk1, sortklen) < 0), "Result should be \"abcda\" == \"Abcda\"");
1195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (memcmp(sortk1, sortk2, sortklen) == 0), "Result should be \"abcda\" ==  \"abcda\"");
1196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1197ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("getting sortkey for an empty string\n");
1198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setAttribute(col, UCOL_STRENGTH, UCOL_TERTIARY, &status);
1199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortklen = ucol_getSortKey(col, test1, 0, NULL, 0);
1200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortkEmpty = (uint8_t*)malloc(sizeof(uint8_t) * sortklen+1);
1201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortklen = ucol_getSortKey(col, test1, 0, sortkEmpty, sortklen+1);
1202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(sortklen != 3 || sortkEmpty[0] != 1 || sortkEmpty[0] != 1 || sortkEmpty[2] != 0) {
1203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      log_err("Empty string generated wrong sortkey!\n");
1204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(sortkEmpty);
1206ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("testing passing invalid string\n");
1208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortklen = ucol_getSortKey(col, NULL, 0, NULL, 0);
1209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(sortklen != 0) {
1210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      log_err("Invalid string didn't return sortkey size of 0\n");
1211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
121285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
121385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1214ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("testing sortkey ends...\n");
1215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(col);
1216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(test1);
1217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(test2);
1218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(test3);
1219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(sortk1);
1220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(sortk2);
122185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
1223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestHashCode()
1224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
1225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t *sortk1, *sortk2, *sortk3;
1226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t sortk1len, sortk2len, sortk3len;
1227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator *col;
1228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar *test1, *test2, *test3;
1229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
1230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("testing getHashCode begins...\n");
1231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    col = ucol_open("en_US", &status);
1232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
123385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(status, "ERROR: Default collation creation failed.: %s\n", myErrorName(status));
1234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    test1=(UChar*)malloc(sizeof(UChar) * 6);
1237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    test2=(UChar*)malloc(sizeof(UChar) * 6);
1238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    test3=(UChar*)malloc(sizeof(UChar) * 6);
1239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(test1, "Abcda");
1240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(test2, "abcda");
1241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(test3, "abcda");
1242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Use tertiary comparison level testing ....\n");
1244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortk1len=ucol_getSortKey(col, test1, u_strlen(test1),  NULL, 0);
1245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortk1=(uint8_t*)malloc(sizeof(uint8_t) * (sortk1len+1));
1246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_getSortKey(col, test1, u_strlen(test1), sortk1, sortk1len+1);
1247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortk2len=ucol_getSortKey(col, test2, u_strlen(test2),  NULL, 0);
1248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortk2=(uint8_t*)malloc(sizeof(uint8_t) * (sortk2len+1));
1249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_getSortKey(col, test2, u_strlen(test2), sortk2, sortk2len+1);
1250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortk3len=ucol_getSortKey(col, test2, u_strlen(test3),  NULL, 0);
1251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortk3=(uint8_t*)malloc(sizeof(uint8_t) * (sortk3len+1));
1252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_getSortKey(col, test2, u_strlen(test2), sortk3, sortk3len+1);
125385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
125485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("ucol_hashCode() testing ...\n");
125685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
125785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    doAssert( ucol_keyHashCode(sortk1, sortk1len) != ucol_keyHashCode(sortk2, sortk2len), "Hash test1 result incorrect" );
1258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( !(ucol_keyHashCode(sortk1, sortk1len) == ucol_keyHashCode(sortk2, sortk2len)), "Hash test2 result incorrect" );
1259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( ucol_keyHashCode(sortk2, sortk2len) == ucol_keyHashCode(sortk3, sortk3len), "Hash result not equal" );
126085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("hashCode tests end.\n");
1262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(col);
1263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(sortk1);
1264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(sortk2);
1265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(sortk3);
1266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(test1);
1267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(test2);
1268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(test3);
1269ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1270ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
1272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*
1273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *----------------------------------------------------------------------------
1274ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Tests the UCollatorElements API.
127585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho *
127685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho */
1277ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestElemIter()
1278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
1279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t offset;
1280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t order1, order2, order3;
1281ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar *testString1, *testString2;
1282ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator *col;
1283ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollationElements *iterator1, *iterator2, *iterator3;
1284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
1285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("testing UCollatorElements begins...\n");
1286ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    col = ucol_open("en_US", &status);
1287ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setAttribute(col, UCOL_NORMALIZATION_MODE, UCOL_OFF, &status);
1288ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
128985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(status, "ERROR: Default collation creation failed.: %s\n", myErrorName(status));
1290ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1291ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1292ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1293ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    testString1=(UChar*)malloc(sizeof(UChar) * 150);
1294ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    testString2=(UChar*)malloc(sizeof(UChar) * 150);
1295ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(testString1, "XFILE What subset of all possible test cases has the highest probability of detecting the most errors?");
1296ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(testString2, "Xf_ile What subset of all possible test cases has the lowest probability of detecting the least errors?");
129785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1298ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Constructors and comparison testing....\n");
129985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1300ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    iterator1 = ucol_openElements(col, testString1, u_strlen(testString1), &status);
1301ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)) {
1302ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("ERROR: Default collationElement iterator creation failed.: %s\n", myErrorName(status));
1303ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_close(col);
1304ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1305ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1306ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    else{ log_verbose("PASS: Default collationElement iterator1 creation passed\n");}
1307ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1308ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    iterator2 = ucol_openElements(col, testString1, u_strlen(testString1), &status);
1309ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)) {
1310ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("ERROR: Default collationElement iterator creation failed.: %s\n", myErrorName(status));
1311ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_close(col);
1312ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1313ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1314ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    else{ log_verbose("PASS: Default collationElement iterator2 creation passed\n");}
1315ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1316ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    iterator3 = ucol_openElements(col, testString2, u_strlen(testString2), &status);
1317ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)) {
1318ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("ERROR: Default collationElement iterator creation failed.: %s\n", myErrorName(status));
1319ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_close(col);
1320ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1321ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1322ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    else{ log_verbose("PASS: Default collationElement iterator3 creation passed\n");}
1323ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1324ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    offset=ucol_getOffset(iterator1);
1325ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setOffset(iterator1, 6, &status);
1326ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
1327ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Error in setOffset for UCollatorElements iterator.: %s\n", myErrorName(status));
1328ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1329ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1330ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(ucol_getOffset(iterator1)==6)
1331ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("setOffset and getOffset working fine\n");
1332ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    else{
1333ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("error in set and get Offset got %d instead of 6\n", ucol_getOffset(iterator1));
1334ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1335ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1336ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setOffset(iterator1, 0, &status);
1337ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    order1 = ucol_next(iterator1, &status);
1338ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
1339ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Somehow ran out of memory stepping through the iterator1.: %s\n", myErrorName(status));
1340ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1341ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1342ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    order2=ucol_getOffset(iterator2);
1343ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert((order1 != order2), "The first iterator advance failed");
1344ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    order2 = ucol_next(iterator2, &status);
1345ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
1346ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Somehow ran out of memory stepping through the iterator2.: %s\n", myErrorName(status));
1347ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1348ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1349ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    order3 = ucol_next(iterator3, &status);
1350ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
1351ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Somehow ran out of memory stepping through the iterator3.: %s\n", myErrorName(status));
1352ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1353ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
135485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1355ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert((order1 == order2), "The second iterator advance failed should be the same as first one");
135685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1357ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerudoAssert( (ucol_primaryOrder(order1) == ucol_primaryOrder(order3)), "The primary orders should be identical");
1358ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerudoAssert( (ucol_secondaryOrder(order1) == ucol_secondaryOrder(order3)), "The secondary orders should be identical");
1359ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerudoAssert( (ucol_tertiaryOrder(order1) == ucol_tertiaryOrder(order3)), "The tertiary orders should be identical");
136085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1361ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    order1=ucol_next(iterator1, &status);
1362ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
1363ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Somehow ran out of memory stepping through the iterator2.: %s\n", myErrorName(status));
1364ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1365ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1366ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    order3=ucol_next(iterator3, &status);
1367ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
1368ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Somehow ran out of memory stepping through the iterator2.: %s\n", myErrorName(status));
1369ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1370ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1371ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerudoAssert( (ucol_primaryOrder(order1) == ucol_primaryOrder(order3)), "The primary orders should be identical");
1372ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerudoAssert( (ucol_tertiaryOrder(order1) != ucol_tertiaryOrder(order3)), "The tertiary orders should be different");
137385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1374ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    order1=ucol_next(iterator1, &status);
1375ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
1376ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Somehow ran out of memory stepping through the iterator2.: %s\n", myErrorName(status));
1377ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1378ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1379ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    order3=ucol_next(iterator3, &status);
1380ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
1381ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Somehow ran out of memory stepping through the iterator2.: %s\n", myErrorName(status));
1382ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1383ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1384ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* this here, my friends, is either pure lunacy or something so obsolete that even it's mother
1385ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * doesn't care about it. Essentialy, this test complains if secondary values for 'I' and '_'
1386ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * are the same. According to the UCA, this is not true. Therefore, remove the test.
1387ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Besides, if primary strengths for two code points are different, it doesn't matter one bit
1388ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * what is the relation between secondary or any other strengths.
1389ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * killed by weiv 06/11/2002.
1390ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
1391ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*
1392ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( ((order1 & UCOL_SECONDARYMASK) != (order3 & UCOL_SECONDARYMASK)), "The secondary orders should be different");
1393ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    */
1394ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (order1 != UCOL_NULLORDER), "Unexpected end of iterator reached");
1395ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1396ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(testString1);
1397ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(testString2);
1398ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_closeElements(iterator1);
1399ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_closeElements(iterator2);
1400ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_closeElements(iterator3);
1401ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(col);
140285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1403ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("testing CollationElementIterator ends...\n");
1404ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
1405ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1406ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestGetLocale() {
1407ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  UErrorCode status = U_ZERO_ERROR;
1408ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  const char *rules = "&a<x<y<z";
1409ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  UChar rlz[256] = {0};
1410ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  uint32_t rlzLen = u_unescape(rules, rlz, 256);
1411ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1412ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  UCollator *coll = NULL;
1413ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  const char *locale = NULL;
1414ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1415ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  int32_t i = 0;
1416ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1417ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  /* Now that the collation tree is separate, actual==valid at all times. [alan] */
1418ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  static const struct {
1419ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char* requestedLocale;
1420ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char* validLocale;
1421ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char* actualLocale;
1422ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  } testStruct[] = {
142327f654740f2a26ad62a5c155af9199af9e69b889claireho    { "sr_RS", "sr_Cyrl_RS", "sr" },
1424ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    { "sh_YU", "sr_Latn_RS", "hr" }, /* this used to be sh, but now sh collation aliases hr */
142527f654740f2a26ad62a5c155af9199af9e69b889claireho    { "en_BE_FOO", "en_BE", "root" },
142627f654740f2a26ad62a5c155af9199af9e69b889claireho    { "de_DE_NONEXISTANT", "de_DE", "de" }
1427ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  };
1428ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1429ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  /* test opening collators for different locales */
1430ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  for(i = 0; i<sizeof(testStruct)/sizeof(testStruct[0]); i++) {
1431ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    status = U_ZERO_ERROR;
1432ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    coll = ucol_open(testStruct[i].requestedLocale, &status);
1433ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)) {
143485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho      log_err_status(status, "Failed to open collator for %s with %s\n", testStruct[i].requestedLocale, u_errorName(status));
1435ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      ucol_close(coll);
1436ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      continue;
1437ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
143885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho   locale = ucol_getLocaleByType(coll, ULOC_REQUESTED_LOCALE, &status);
1439ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(strcmp(locale, testStruct[i].requestedLocale) != 0) {
1440ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      log_err("[Coll %s]: Error in requested locale, expected %s, got %s\n", testStruct[i].requestedLocale, testStruct[i].requestedLocale, locale);
1441ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
144285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    locale = ucol_getLocaleByType(coll, ULOC_VALID_LOCALE, &status);
1443ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(strcmp(locale, testStruct[i].validLocale) != 0) {
1444ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      log_err("[Coll %s]: Error in valid locale, expected %s, got %s\n", testStruct[i].requestedLocale, testStruct[i].validLocale, locale);
1445ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
144685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    locale = ucol_getLocaleByType(coll, ULOC_ACTUAL_LOCALE, &status);
1447ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(strcmp(locale, testStruct[i].actualLocale) != 0) {
1448ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      log_err("[Coll %s]: Error in actual locale, expected %s, got %s\n", testStruct[i].requestedLocale, testStruct[i].actualLocale, locale);
1449ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1450ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(coll);
1451ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  }
1452ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1453ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  /* completely non-existant locale for collator should get a default collator */
1454ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  {
1455ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator *defaultColl = ucol_open(NULL, &status);
1456ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    coll = ucol_open("blahaha", &status);
1457ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_SUCCESS(status)) {
145885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho      if(strcmp(ucol_getLocaleByType(coll, ULOC_REQUESTED_LOCALE, &status), "blahaha")) {
1459ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Nonexisting locale didn't preserve the requested locale\n");
1460ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      }
146185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho      if(strcmp(ucol_getLocaleByType(coll, ULOC_VALID_LOCALE, &status),
146285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        ucol_getLocaleByType(defaultColl, ULOC_VALID_LOCALE, &status))) {
1463ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Valid locale for nonexisting locale locale collator differs "
1464ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru          "from valid locale for default collator\n");
1465ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      }
146685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho      if(strcmp(ucol_getLocaleByType(coll, ULOC_ACTUAL_LOCALE, &status),
146785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        ucol_getLocaleByType(defaultColl, ULOC_ACTUAL_LOCALE, &status))) {
1468ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Actual locale for nonexisting locale locale collator differs "
1469ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru          "from actual locale for default collator\n");
1470ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      }
1471ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      ucol_close(coll);
1472ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      ucol_close(defaultColl);
1473ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
1474ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      log_data_err("Couldn't open collators\n");
1475ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1476ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  }
1477ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
147885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1479ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1480ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  /* collator instantiated from rules should have all three locales NULL */
1481ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  coll = ucol_openRules(rlz, rlzLen, UCOL_DEFAULT, UCOL_DEFAULT, NULL, &status);
148285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho  locale = ucol_getLocaleByType(coll, ULOC_REQUESTED_LOCALE, &status);
1483ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  if(locale != NULL) {
1484ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_err("For collator instantiated from rules, requested locale returned %s instead of NULL\n", locale);
1485ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  }
148685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho  locale = ucol_getLocaleByType(coll, ULOC_VALID_LOCALE, &status);
1487ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  if(locale != NULL) {
1488ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_err("For collator instantiated from rules,  valid locale returned %s instead of NULL\n", locale);
1489ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  }
149085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho  locale = ucol_getLocaleByType(coll, ULOC_ACTUAL_LOCALE, &status);
1491ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  if(locale != NULL) {
1492ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_err("For collator instantiated from rules, actual locale returned %s instead of NULL\n", locale);
1493ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  }
1494ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  ucol_close(coll);
1495ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1496ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
1497ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1498ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1499ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestGetAll()
1500ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
1501ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t i, count;
1502ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    count=ucol_countAvailable();
1503ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* use something sensible w/o hardcoding the count */
1504ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(count < 0){
1505ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Error in countAvailable(), it returned %d\n", count);
1506ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1507ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    else{
1508ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("PASS: countAvailable() successful, it returned %d\n", count);
1509ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1510ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for(i=0;i<count;i++)
1511ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("%s\n", ucol_getAvailable(i));
1512ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1513ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1514ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
1515ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1516ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1517ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustruct teststruct {
1518ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char *original;
1519ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t key[256];
1520ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} ;
1521ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1522ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic int compare_teststruct(const void *string1, const void *string2) {
1523ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return(strcmp((const char *)((struct teststruct *)string1)->key, (const char *)((struct teststruct *)string2)->key));
1524ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
1525ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1526ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestBounds() {
1527ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
1528ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1529ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator *coll = ucol_open("sh", &status);
1530ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1531ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t sortkey[512], lower[512], upper[512];
1532ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar buffer[512];
1533ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1534ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const char * const test[] = {
1535ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "John Smith",
1536ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "JOHN SMITH",
1537ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "john SMITH",
1538ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "j\\u00F6hn sm\\u00EFth",
1539ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "J\\u00F6hn Sm\\u00EFth",
1540ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "J\\u00D6HN SM\\u00CFTH",
1541ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "john smithsonian",
1542ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "John Smithsonian",
1543ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
1544ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
154585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    struct teststruct tests[] = {
1546ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKI MIHALJ" } ,
1547ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKI MIHALJ" } ,
1548ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKI PIRO\\u0160KA" },
1549ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABAI ANDRIJA" } ,
1550ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABAI LAJO\\u0160" } ,
1551ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABAI MARIJA" } ,
1552ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABAI STEVAN" } ,
1553ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABAI STEVAN" } ,
1554ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABARKAPA BRANKO" } ,
1555ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABARKAPA MILENKO" } ,
1556ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABARKAPA MIROSLAV" } ,
1557ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABARKAPA SIMO" } ,
1558ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABARKAPA STANKO" } ,
1559ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABARKAPA TAMARA" } ,
1560ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABARKAPA TOMA\\u0160" } ,
1561ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABDARI\\u0106 NIKOLA" } ,
1562ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABDARI\\u0106 ZORICA" } ,
1563ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABI NANDOR" } ,
1564ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABOVI\\u0106 MILAN" } ,
1565ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABRADI AGNEZIJA" } ,
1566ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABRADI IVAN" } ,
1567ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABRADI JELENA" } ,
1568ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABRADI LJUBICA" } ,
1569ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABRADI STEVAN" } ,
1570ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABRDA MARTIN" } ,
1571ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABRILO BOGDAN" } ,
1572ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABRILO BRANISLAV" } ,
1573ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABRILO LAZAR" } ,
1574ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABRILO LJUBICA" } ,
1575ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABRILO SPASOJA" } ,
1576ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CADE\\u0160 ZDENKA" } ,
1577ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CADESKI BLAGOJE" } ,
1578ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CADOVSKI VLADIMIR" } ,
1579ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAGLJEVI\\u0106 TOMA" } ,
1580ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAGOROVI\\u0106 VLADIMIR" } ,
1581ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAJA VANKA" } ,
1582ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAJI\\u0106 BOGOLJUB" } ,
1583ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAJI\\u0106 BORISLAV" } ,
1584ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAJI\\u0106 RADOSLAV" } ,
1585ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAK\\u0160IRAN MILADIN" } ,
1586ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKAN EUGEN" } ,
1587ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKAN EVGENIJE" } ,
1588ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKAN IVAN" } ,
1589ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKAN JULIJAN" } ,
1590ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKAN MIHAJLO" } ,
1591ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKAN STEVAN" } ,
1592ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKAN VLADIMIR" } ,
1593ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKAN VLADIMIR" } ,
1594ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKAN VLADIMIR" } ,
1595ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKARA ANA" } ,
1596ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKAREVI\\u0106 MOMIR" } ,
1597ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKAREVI\\u0106 NEDELJKO" } ,
1598ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKI \\u0160ANDOR" } ,
1599ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKI AMALIJA" } ,
1600ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKI ANDRA\\u0160" } ,
1601ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKI LADISLAV" } ,
1602ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKI LAJO\\u0160" } ,
1603ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKI LASLO" } ,
1604ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
1605ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1606ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1607ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1608ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t i = 0, j = 0, k = 0, buffSize = 0, skSize = 0, lowerSize = 0, upperSize = 0;
1609ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t arraySize = sizeof(tests)/sizeof(tests[0]);
1610ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1611ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_SUCCESS(status) && coll) {
1612ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        for(i = 0; i<arraySize; i++) {
1613ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            buffSize = u_unescape(tests[i].original, buffer, 512);
1614ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            skSize = ucol_getSortKey(coll, buffer, buffSize, tests[i].key, 512);
1615ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
1616ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1617ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        qsort(tests, arraySize, sizeof(struct teststruct), compare_teststruct);
1618ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1619ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        for(i = 0; i < arraySize-1; i++) {
1620ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            for(j = i+1; j < arraySize; j++) {
1621ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                lowerSize = ucol_getBound(tests[i].key, -1, UCOL_BOUND_LOWER, 1, lower, 512, &status);
1622ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                upperSize = ucol_getBound(tests[j].key, -1, UCOL_BOUND_UPPER, 1, upper, 512, &status);
1623ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                for(k = i; k <= j; k++) {
1624ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    if(strcmp((const char *)lower, (const char *)tests[k].key) > 0) {
1625ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                        log_err("Problem with lower! j = %i (%s vs %s)\n", k, tests[k].original, tests[i].original);
1626ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    }
1627ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    if(strcmp((const char *)upper, (const char *)tests[k].key) <= 0) {
1628ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                        log_err("Problem with upper! j = %i (%s vs %s)\n", k, tests[k].original, tests[j].original);
1629ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    }
1630ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
1631ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
1632ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
1633ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1634ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1635ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if 0
1636ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        for(i = 0; i < 1000; i++) {
1637ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            lowerRND = (rand()/(RAND_MAX/arraySize));
1638ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            upperRND = lowerRND + (rand()/(RAND_MAX/(arraySize-lowerRND)));
1639ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1640ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            lowerSize = ucol_getBound(tests[lowerRND].key, -1, UCOL_BOUND_LOWER, 1, lower, 512, &status);
1641ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            upperSize = ucol_getBound(tests[upperRND].key, -1, UCOL_BOUND_UPPER_LONG, 1, upper, 512, &status);
1642ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1643ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            for(j = lowerRND; j<=upperRND; j++) {
1644ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                if(strcmp(lower, tests[j].key) > 0) {
1645ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    log_err("Problem with lower! j = %i (%s vs %s)\n", j, tests[j].original, tests[lowerRND].original);
1646ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
1647ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                if(strcmp(upper, tests[j].key) <= 0) {
1648ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    log_err("Problem with upper! j = %i (%s vs %s)\n", j, tests[j].original, tests[upperRND].original);
1649ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
1650ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
1651ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
1652ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
1653ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1654ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1655ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1656ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1657ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1658ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        for(i = 0; i<sizeof(test)/sizeof(test[0]); i++) {
1659ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            buffSize = u_unescape(test[i], buffer, 512);
1660ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            skSize = ucol_getSortKey(coll, buffer, buffSize, sortkey, 512);
1661ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            lowerSize = ucol_getBound(sortkey, skSize, UCOL_BOUND_LOWER, 1, lower, 512, &status);
1662ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            upperSize = ucol_getBound(sortkey, skSize, UCOL_BOUND_UPPER_LONG, 1, upper, 512, &status);
1663ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            for(j = i+1; j<sizeof(test)/sizeof(test[0]); j++) {
1664ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                buffSize = u_unescape(test[j], buffer, 512);
1665ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                skSize = ucol_getSortKey(coll, buffer, buffSize, sortkey, 512);
1666ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                if(strcmp((const char *)lower, (const char *)sortkey) > 0) {
1667ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    log_err("Problem with lower! i = %i, j = %i (%s vs %s)\n", i, j, test[i], test[j]);
1668ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
1669ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                if(strcmp((const char *)upper, (const char *)sortkey) <= 0) {
1670ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    log_err("Problem with upper! i = %i, j = %i (%s vs %s)\n", i, j, test[i], test[j]);
1671ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
1672ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
1673ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
1674ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_close(coll);
1675ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
1676ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_data_err("Couldn't open collator\n");
1677ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1678ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1679ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
1680ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1681ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void doOverrunTest(UCollator *coll, const UChar *uString, int32_t strLen) {
1682ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t skLen = 0, skLen2 = 0;
1683ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t sortKey[256];
1684ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t i, j;
1685ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t filler = 0xFF;
1686ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1687ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    skLen = ucol_getSortKey(coll, uString, strLen, NULL, 0);
1688ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1689ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for(i = 0; i < skLen; i++) {
1690ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        memset(sortKey, filler, 256);
1691ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        skLen2 = ucol_getSortKey(coll, uString, strLen, sortKey, i);
1692ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(skLen != skLen2) {
1693ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("For buffer size %i, got different sortkey length. Expected %i got %i\n", i, skLen, skLen2);
1694ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
1695ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        for(j = i; j < 256; j++) {
1696ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if(sortKey[j] != filler) {
1697ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                log_err("Something run over index %i\n", j);
1698ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                break;
1699ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
1700ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
1701ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1702ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
1703ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1704ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* j1865 reports that if a shorter buffer is passed to
170585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho* to get sort key, a buffer overrun happens in some
1706ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* cases. This test tries to check this.
1707ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/
1708ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestSortKeyBufferOverrun(void) {
1709ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
1710ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char* cString = "A very Merry liTTle-lamB..";
1711ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar uString[256];
1712ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t strLen = 0;
1713ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator *coll = ucol_open("root", &status);
1714ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    strLen = u_unescape(cString, uString, 256);
1715ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1716ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_SUCCESS(status)) {
1717ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("testing non ignorable\n");
1718ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_setAttribute(coll, UCOL_ALTERNATE_HANDLING, UCOL_NON_IGNORABLE, &status);
1719ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        doOverrunTest(coll, uString, strLen);
1720ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1721ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("testing shifted\n");
1722ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_setAttribute(coll, UCOL_ALTERNATE_HANDLING, UCOL_SHIFTED, &status);
1723ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        doOverrunTest(coll, uString, strLen);
1724ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1725ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("testing shifted quaternary\n");
1726ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_setAttribute(coll, UCOL_STRENGTH, UCOL_QUATERNARY, &status);
1727ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        doOverrunTest(coll, uString, strLen);
1728ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1729ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("testing with french secondaries\n");
1730ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_setAttribute(coll, UCOL_FRENCH_COLLATION, UCOL_ON, &status);
1731ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_setAttribute(coll, UCOL_STRENGTH, UCOL_TERTIARY, &status);
1732ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_setAttribute(coll, UCOL_ALTERNATE_HANDLING, UCOL_NON_IGNORABLE, &status);
1733ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        doOverrunTest(coll, uString, strLen);
1734ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1735ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1736ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(coll);
1737ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
1738ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1739ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestAttribute()
1740ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
1741ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode error = U_ZERO_ERROR;
1742ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator *coll = ucol_open(NULL, &error);
1743ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1744ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(error)) {
174585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(error, "Creation of default collator failed\n");
1746ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1747ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1748ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1749ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setAttribute(coll, UCOL_FRENCH_COLLATION, UCOL_OFF, &error);
1750ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getAttribute(coll, UCOL_FRENCH_COLLATION, &error) != UCOL_OFF ||
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_FRENCH_COLLATION, UCOL_ON, &error);
1756ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getAttribute(coll, UCOL_FRENCH_COLLATION, &error) != UCOL_ON ||
1757ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        U_FAILURE(error)) {
175885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(error, "Setting and retrieving of the french collation failed\n");
1759ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1760ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1761ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setAttribute(coll, UCOL_ALTERNATE_HANDLING, UCOL_SHIFTED, &error);
1762ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getAttribute(coll, UCOL_ALTERNATE_HANDLING, &error) != UCOL_SHIFTED ||
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_ALTERNATE_HANDLING, UCOL_NON_IGNORABLE, &error);
1768ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getAttribute(coll, UCOL_ALTERNATE_HANDLING, &error) != UCOL_NON_IGNORABLE ||
1769ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        U_FAILURE(error)) {
177085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(error, "Setting and retrieving of the alternate handling failed\n");
1771ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1772ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1773ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setAttribute(coll, UCOL_CASE_FIRST, UCOL_LOWER_FIRST, &error);
1774ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getAttribute(coll, UCOL_CASE_FIRST, &error) != UCOL_LOWER_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_FIRST, UCOL_UPPER_FIRST, &error);
1780ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getAttribute(coll, UCOL_CASE_FIRST, &error) != UCOL_UPPER_FIRST ||
1781ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        U_FAILURE(error)) {
178285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(error, "Setting and retrieving of the case first attribute failed\n");
1783ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1784ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1785ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setAttribute(coll, UCOL_CASE_LEVEL, UCOL_ON, &error);
1786ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getAttribute(coll, UCOL_CASE_LEVEL, &error) != UCOL_ON ||
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_CASE_LEVEL, UCOL_OFF, &error);
1792ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getAttribute(coll, UCOL_CASE_LEVEL, &error) != UCOL_OFF ||
1793ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        U_FAILURE(error)) {
179485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(error, "Setting and retrieving of the case level attribute failed\n");
1795ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1796ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1797ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setAttribute(coll, UCOL_NORMALIZATION_MODE, UCOL_ON, &error);
1798ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getAttribute(coll, UCOL_NORMALIZATION_MODE, &error) != UCOL_ON ||
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_NORMALIZATION_MODE, UCOL_OFF, &error);
1804ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getAttribute(coll, UCOL_NORMALIZATION_MODE, &error) != UCOL_OFF ||
1805ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        U_FAILURE(error)) {
180685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(error, "Setting and retrieving of the normalization on/off attribute failed\n");
1807ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1808ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1809ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setAttribute(coll, UCOL_STRENGTH, UCOL_PRIMARY, &error);
1810ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getAttribute(coll, UCOL_STRENGTH, &error) != UCOL_PRIMARY ||
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_SECONDARY, &error);
1816ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getAttribute(coll, UCOL_STRENGTH, &error) != UCOL_SECONDARY ||
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_TERTIARY, &error);
1822ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getAttribute(coll, UCOL_STRENGTH, &error) != UCOL_TERTIARY ||
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_QUATERNARY, &error);
1828ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getAttribute(coll, UCOL_STRENGTH, &error) != UCOL_QUATERNARY ||
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_setAttribute(coll, UCOL_STRENGTH, UCOL_IDENTICAL, &error);
1834ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getAttribute(coll, UCOL_STRENGTH, &error) != UCOL_IDENTICAL ||
1835ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        U_FAILURE(error)) {
183685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(error, "Setting and retrieving of the collation strength failed\n");
1837ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1838ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1839ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(coll);
1840ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
1841ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1842ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestGetTailoredSet() {
1843ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  struct {
1844ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char *rules;
1845ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char *tests[20];
1846ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t testsize;
1847ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  } setTest[] = {
1848ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    { "&a < \\u212b", { "\\u212b", "A\\u030a", "\\u00c5" }, 3},
1849ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    { "& S < \\u0161 <<< \\u0160", { "\\u0161", "s\\u030C", "\\u0160", "S\\u030C" }, 4}
1850ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  };
1851ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1852ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  int32_t i = 0, j = 0;
1853ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  UErrorCode status = U_ZERO_ERROR;
1854ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  UParseError pError;
1855ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1856ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  UCollator *coll = NULL;
1857ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  UChar buff[1024];
1858ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  int32_t buffLen = 0;
1859ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  USet *set = NULL;
1860ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1861ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  for(i = 0; i < sizeof(setTest)/sizeof(setTest[0]); i++) {
1862ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    buffLen = u_unescape(setTest[i].rules, buff, 1024);
1863ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    coll = ucol_openRules(buff, buffLen, UCOL_DEFAULT, UCOL_DEFAULT, &pError, &status);
1864ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_SUCCESS(status)) {
1865ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      set = ucol_getTailoredSet(coll, &status);
1866ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      if(uset_size(set) != setTest[i].testsize) {
1867ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Tailored set size different (%d) than expected (%d)\n", uset_size(set), setTest[i].testsize);
1868ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      }
1869ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      for(j = 0; j < setTest[i].testsize; j++) {
1870ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        buffLen = u_unescape(setTest[i].tests[j], buff, 1024);
1871ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(!uset_containsString(set, buff, buffLen)) {
1872ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru          log_err("Tailored set doesn't contain %s... It should\n", setTest[i].tests[j]);
1873ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
1874ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      }
1875ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      uset_close(set);
1876ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
187785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho      log_err_status(status, "Couldn't open collator with rules %s\n", setTest[i].rules);
1878ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1879ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(coll);
1880ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  }
1881ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
1882ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1883ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic int tMemCmp(const uint8_t *first, const uint8_t *second) {
1884ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   int32_t firstLen = (int32_t)strlen((const char *)first);
1885ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   int32_t secondLen = (int32_t)strlen((const char *)second);
1886ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   return memcmp(first, second, uprv_min(firstLen, secondLen));
1887ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
1888ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic const char * strengthsC[] = {
1889ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     "UCOL_PRIMARY",
1890ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     "UCOL_SECONDARY",
1891ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     "UCOL_TERTIARY",
1892ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     "UCOL_QUATERNARY",
1893ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     "UCOL_IDENTICAL"
1894ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru};
189585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1896ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestMergeSortKeys(void) {
1897ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   UErrorCode status = U_ZERO_ERROR;
1898ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   UCollator *coll = ucol_open("en", &status);
1899ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   if(U_SUCCESS(status)) {
190085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1901ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     const char* cases[] = {
1902ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       "abc",
1903ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         "abcd",
1904ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         "abcde"
1905ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     };
1906ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     uint32_t casesSize = sizeof(cases)/sizeof(cases[0]);
1907ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     const char* prefix = "foo";
1908ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     const char* suffix = "egg";
1909ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     char outBuff1[256], outBuff2[256];
191085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1911ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     uint8_t **sortkeys = (uint8_t **)malloc(casesSize*sizeof(uint8_t *));
1912ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     uint8_t **mergedPrefixkeys = (uint8_t **)malloc(casesSize*sizeof(uint8_t *));
1913ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     uint8_t **mergedSuffixkeys = (uint8_t **)malloc(casesSize*sizeof(uint8_t *));
1914ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     uint32_t *sortKeysLen = (uint32_t *)malloc(casesSize*sizeof(uint32_t));
1915ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     uint8_t prefixKey[256], suffixKey[256];
1916ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     uint32_t prefixKeyLen = 0, suffixKeyLen = 0, i = 0;
1917ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     UChar buffer[256];
1918ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     uint32_t unescapedLen = 0, l1 = 0, l2 = 0;
1919ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     UColAttributeValue strength;
192085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1921ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     log_verbose("ucol_mergeSortkeys test\n");
1922ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     log_verbose("Testing order of the test cases\n");
1923ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     genericLocaleStarter("en", cases, casesSize);
192485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1925ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     for(i = 0; i<casesSize; i++) {
1926ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       sortkeys[i] = (uint8_t *)malloc(256*sizeof(uint8_t));
1927ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       mergedPrefixkeys[i] = (uint8_t *)malloc(256*sizeof(uint8_t));
1928ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       mergedSuffixkeys[i] = (uint8_t *)malloc(256*sizeof(uint8_t));
1929ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     }
193085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1931ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     unescapedLen = u_unescape(prefix, buffer, 256);
1932ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     prefixKeyLen = ucol_getSortKey(coll, buffer, unescapedLen, prefixKey, 256);
193385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1934ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     unescapedLen = u_unescape(suffix, buffer, 256);
1935ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     suffixKeyLen = ucol_getSortKey(coll, buffer, unescapedLen, suffixKey, 256);
193685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1937ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     log_verbose("Massaging data with prefixes and different strengths\n");
1938ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     strength = UCOL_PRIMARY;
1939ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     while(strength <= UCOL_IDENTICAL) {
1940ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       log_verbose("Strength %s\n", strengthsC[strength<=UCOL_QUATERNARY?strength:4]);
1941ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       ucol_setAttribute(coll, UCOL_STRENGTH, strength, &status);
1942ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       for(i = 0; i<casesSize; i++) {
1943ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         unescapedLen = u_unescape(cases[i], buffer, 256);
1944ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         sortKeysLen[i] = ucol_getSortKey(coll, buffer, unescapedLen, sortkeys[i], 256);
1945ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         ucol_mergeSortkeys(prefixKey, prefixKeyLen, sortkeys[i], sortKeysLen[i], mergedPrefixkeys[i], 256);
1946ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         ucol_mergeSortkeys(sortkeys[i], sortKeysLen[i], suffixKey, suffixKeyLen, mergedSuffixkeys[i], 256);
1947ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         if(i>0) {
1948ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           if(tMemCmp(mergedPrefixkeys[i-1], mergedPrefixkeys[i]) >= 0) {
1949ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru             log_err("Error while comparing prefixed keys @ strength %s:\n", strengthsC[strength<=UCOL_QUATERNARY?strength:4]);
195085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho             log_err("%s\n%s\n",
1951ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                         ucol_sortKeyToString(coll, mergedPrefixkeys[i-1], outBuff1, &l1),
1952ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                         ucol_sortKeyToString(coll, mergedPrefixkeys[i], outBuff2, &l2));
1953ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           }
1954ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           if(tMemCmp(mergedSuffixkeys[i-1], mergedSuffixkeys[i]) >= 0) {
1955ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru             log_err("Error while comparing suffixed keys @ strength %s:\n", strengthsC[strength<=UCOL_QUATERNARY?strength:4]);
195685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho             log_err("%s\n%s\n",
1957ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                         ucol_sortKeyToString(coll, mergedSuffixkeys[i-1], outBuff1, &l1),
1958ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                         ucol_sortKeyToString(coll, mergedSuffixkeys[i], outBuff2, &l2));
1959ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           }
1960ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         }
1961ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       }
1962ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       if(strength == UCOL_QUATERNARY) {
1963ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         strength = UCOL_IDENTICAL;
1964ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       } else {
1965ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         strength++;
1966ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       }
1967ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     }
196885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1969ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     {
1970ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       uint8_t smallBuf[3];
1971ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       uint32_t reqLen = 0;
1972ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       log_verbose("testing buffer overflow\n");
1973ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       reqLen = ucol_mergeSortkeys(prefixKey, prefixKeyLen, suffixKey, suffixKeyLen, smallBuf, 3);
1974ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       if(reqLen != (prefixKeyLen+suffixKeyLen-1)) {
1975ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         log_err("Wrong preflight size for merged sortkey\n");
1976ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       }
1977ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     }
197885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1979ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     {
1980ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       UChar empty = 0;
1981ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       uint8_t emptyKey[20], abcKey[50], mergedKey[100];
1982ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       int32_t emptyKeyLen = 0, abcKeyLen = 0, mergedKeyLen = 0;
198385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1984ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       log_verbose("testing merging with sortkeys generated for empty strings\n");
1985ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       emptyKeyLen = ucol_getSortKey(coll, &empty, 0, emptyKey, 20);
1986ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       unescapedLen = u_unescape(cases[0], buffer, 256);
1987ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       abcKeyLen = ucol_getSortKey(coll, buffer, unescapedLen, abcKey, 50);
1988ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       mergedKeyLen = ucol_mergeSortkeys(emptyKey, emptyKeyLen, abcKey, abcKeyLen, mergedKey, 100);
1989ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       if(mergedKey[0] != 2) {
1990ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         log_err("Empty sortkey didn't produce a level separator\n");
1991ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       }
1992ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       /* try with zeros */
1993ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       mergedKeyLen = ucol_mergeSortkeys(emptyKey, 0, abcKey, abcKeyLen, mergedKey, 100);
1994ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       if(mergedKeyLen != 0 || mergedKey[0] != 0) {
1995ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         log_err("Empty key didn't produce null mergedKey\n");
1996ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       }
1997ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       mergedKeyLen = ucol_mergeSortkeys(abcKey, abcKeyLen, emptyKey, 0, mergedKey, 100);
1998ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       if(mergedKeyLen != 0 || mergedKey[0] != 0) {
1999ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         log_err("Empty key didn't produce null mergedKey\n");
2000ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       }
200185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
2002ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     }
200385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
2004ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     for(i = 0; i<casesSize; i++) {
2005ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       free(sortkeys[i]);
2006ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       free(mergedPrefixkeys[i]);
2007ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       free(mergedSuffixkeys[i]);
2008ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     }
2009ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     free(sortkeys);
2010ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     free(mergedPrefixkeys);
2011ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     free(mergedSuffixkeys);
2012ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     free(sortKeysLen);
2013ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     ucol_close(coll);
2014ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     /* need to finish this up */
2015ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   } else {
2016ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     log_data_err("Couldn't open collator");
2017ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   }
2018ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
201985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic void TestShortString(void)
2020ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
2021ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    struct {
2022ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        const char *input;
2023ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        const char *expectedOutput;
2024ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        const char *locale;
2025ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        UErrorCode expectedStatus;
2026ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        int32_t    expectedOffset;
2027ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        uint32_t   expectedIdentifier;
2028ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } testCases[] = {
202950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho        /*
203027f654740f2a26ad62a5c155af9199af9e69b889claireho         * The following expectedOutput contains a collation weight (2700 from UCA 6.0)
203150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho         * which is the primary weight for the T character (U+0041) in the input.
203250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho         * When that character gets a different weight in FractionalUCA.txt,
203350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho         * the expectedOutput needs to be adjusted.
203450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho         * That is, when we upgrade to a new UCA version or change collation
203550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho         * in such a way that the absolute weight for 'A' changes,
203650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho         * we will get a test failure here and need to adjust the test case.
203750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho         */
203827f654740f2a26ad62a5c155af9199af9e69b889claireho        {"LDE_RDE_KPHONEBOOK_T0041_ZLATN","B2700_KPHONEBOOK_LDE", "de@collation=phonebook", U_USING_FALLBACK_WARNING, 0, 0 },
203950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
204027f654740f2a26ad62a5c155af9199af9e69b889claireho        {"LEN_RUS_NO_AS_S4","AS_LROOT_NO_S4", NULL, U_USING_DEFAULT_WARNING, 0, 0 },
2041ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"LDE_VPHONEBOOK_EO_SI","EO_KPHONEBOOK_LDE_SI", "de@collation=phonebook", U_ZERO_ERROR, 0, 0 },
2042ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"LDE_Kphonebook","KPHONEBOOK_LDE", "de@collation=phonebook", U_ZERO_ERROR, 0, 0 },
2043ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"Xqde_DE@collation=phonebookq_S3_EX","KPHONEBOOK_LDE", "de@collation=phonebook", U_USING_FALLBACK_WARNING, 0, 0 },
204427f654740f2a26ad62a5c155af9199af9e69b889claireho        {"LFR_FO", "FO_LROOT", NULL, U_USING_DEFAULT_WARNING, 0, 0 },
2045ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"SO_LX_AS", "", NULL, U_ILLEGAL_ARGUMENT_ERROR, 8, 0 },
2046ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"S3_ASS_MMM", "", NULL, U_ILLEGAL_ARGUMENT_ERROR, 5, 0 }
2047ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
2048ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
204985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    int32_t i = 0;
205085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    UCollator *coll = NULL, *fromNormalized = NULL;
2051ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UParseError parseError;
2052ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
205385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    char fromShortBuffer[256], normalizedBuffer[256], fromNormalizedBuffer[256];
2054ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char* locale = NULL;
2055ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2056ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2057ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for(i = 0; i < sizeof(testCases)/sizeof(testCases[0]); i++) {
2058ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        status = U_ZERO_ERROR;
2059ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(testCases[i].locale) {
2060ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            locale = testCases[i].locale;
2061ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        } else {
2062ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            locale = NULL;
2063ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
2064ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2065ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        coll = ucol_openFromShortString(testCases[i].input, FALSE, &parseError, &status);
2066ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(status != testCases[i].expectedStatus) {
206785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            log_err_status(status, "Got status '%s' that is different from expected '%s' for '%s'\n",
2068ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                u_errorName(status), u_errorName(testCases[i].expectedStatus), testCases[i].input);
206985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            continue;
2070ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
207185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
2072ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(U_SUCCESS(status)) {
2073ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            ucol_getShortDefinitionString(coll, locale, fromShortBuffer, 256, &status);
2074ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2075ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if(strcmp(fromShortBuffer, testCases[i].expectedOutput)) {
2076ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                log_err("Got short string '%s' from the collator. Expected '%s' for input '%s'\n",
2077ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    fromShortBuffer, testCases[i].expectedOutput, testCases[i].input);
2078ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
2079ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2080ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            ucol_normalizeShortDefinitionString(testCases[i].input, normalizedBuffer, 256, &parseError, &status);
2081ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            fromNormalized = ucol_openFromShortString(normalizedBuffer, FALSE, &parseError, &status);
2082ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            ucol_getShortDefinitionString(fromNormalized, locale, fromNormalizedBuffer, 256, &status);
2083ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2084ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if(strcmp(fromShortBuffer, fromNormalizedBuffer)) {
208585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                log_err("Strings obtained from collators instantiated by short string ('%s') and from normalized string ('%s') differ\n",
2086ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    fromShortBuffer, fromNormalizedBuffer);
2087ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
2088ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2089ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2090ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if(!ucol_equals(coll, fromNormalized)) {
209185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                log_err("Collator from short string ('%s') differs from one obtained through a normalized version ('%s')\n",
2092ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    testCases[i].input, normalizedBuffer);
2093ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
2094ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2095ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            ucol_close(fromNormalized);
2096ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            ucol_close(coll);
2097ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2098ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        } else {
2099ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if(parseError.offset != testCases[i].expectedOffset) {
2100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                log_err("Got parse error offset %i, but expected %i instead for '%s'\n",
2101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    parseError.offset, testCases[i].expectedOffset, testCases[i].input);
2102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
2103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
2104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
2105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
2107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void
2109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerudoSetsTest(const char *locale, const USet *ref, USet *set, const char* inSet, const char* outSet, UErrorCode *status) {
2110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar buffer[512];
2111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t bufLen;
2112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uset_clear(set);
211485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    bufLen = u_unescape(inSet, buffer, 512);
2115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uset_applyPattern(set, buffer, bufLen, 0, status);
2116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(*status)) {
2117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("%s: Failure setting pattern %s\n", locale, u_errorName(*status));
2118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
2119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(!uset_containsAll(ref, set)) {
2121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("%s: Some stuff from %s is not present in the set\n", locale, inSet);
2122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
2123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uset_clear(set);
212585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    bufLen = u_unescape(outSet, buffer, 512);
2126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uset_applyPattern(set, buffer, bufLen, 0, status);
2127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(*status)) {
2128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("%s: Failure setting pattern %s\n", locale, u_errorName(*status));
2129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
2130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(!uset_containsNone(ref, set)) {
2132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("%s: Some stuff from %s is present in the set\n", locale, outSet);
2133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
2134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
2135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
213985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic void
214085bf2e2fbc60a9f938064abc8127d61da7d19882Claire HoTestGetContractionsAndUnsafes(void)
2141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
2142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static struct {
2143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        const char* locale;
2144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        const char* inConts;
2145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        const char* outConts;
2146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        const char* inExp;
2147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        const char* outExp;
2148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        const char* unsafeCodeUnits;
2149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        const char* safeCodeUnits;
2150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } tests[] = {
215185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        { "ru",
215227f654740f2a26ad62a5c155af9199af9e69b889claireho            "[{\\u0418\\u0306}{\\u0438\\u0306}]",
215327f654740f2a26ad62a5c155af9199af9e69b889claireho            "[\\u0439\\u0457]",
2154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            "[\\u00e6]",
215527f654740f2a26ad62a5c155af9199af9e69b889claireho            "[ae]",
215627f654740f2a26ad62a5c155af9199af9e69b889claireho            "[\\u0418\\u0438]",
2157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            "[aAbB\\u0430\\u0410\\u0433\\u0413]"
2158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        },
2159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        { "uk",
216027f654740f2a26ad62a5c155af9199af9e69b889claireho            "[{\\u0406\\u0308}{\\u0456\\u0308}{\\u0418\\u0306}{\\u0438\\u0306}]",
216127f654740f2a26ad62a5c155af9199af9e69b889claireho            "[\\u0407\\u0419\\u0439\\u0457]",
2162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            "[\\u00e6]",
216327f654740f2a26ad62a5c155af9199af9e69b889claireho            "[ae]",
216427f654740f2a26ad62a5c155af9199af9e69b889claireho            "[\\u0406\\u0456\\u0418\\u0438]",
2165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            "[aAbBxv]",
2166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        },
2167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        { "sh",
2168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            "[{C\\u0301}{C\\u030C}{C\\u0341}{DZ\\u030C}{Dz\\u030C}{D\\u017D}{D\\u017E}{lj}{nj}]",
2169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            "[{\\u309d\\u3099}{\\u30fd\\u3099}]",
2170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            "[\\u00e6]",
2171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            "[a]",
2172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            "[nlcdzNLCDZ]",
2173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            "[jabv]"
2174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        },
2175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        { "ja",
2176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-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}]",
2177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru          "[{\\u30FD\\u3099}{\\u309D\\u3099}{\\u3053\\u3099}{\\u30B3\\u3099}{lj}{nj}]",
2178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            "[\\u30FE\\u00e6]",
2179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            "[a]",
2180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            "[\\u3099]",
2181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            "[]"
2182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
2183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
2184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
2189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator *coll = NULL;
2190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t i = 0;
2191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t noConts = 0;
2192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    USet *conts = uset_open(0,0);
2193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    USet *exp = uset_open(0, 0);
2194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    USet *set  = uset_open(0,0);
2195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t setBufferLen = 65536;
2196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar buffer[65536];
2197ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t setLen = 0;
2198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for(i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) {
2200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("Testing locale: %s\n", tests[i].locale);
2201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        coll = ucol_open(tests[i].locale, &status);
220285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        if (coll == NULL || U_FAILURE(status)) {
220385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            log_err_status(status, "Unable to open collator for locale %s ==> %s\n", tests[i].locale, u_errorName(status));
220485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            continue;
220585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        }
2206ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_getContractionsAndExpansions(coll, conts, exp, TRUE, &status);
2207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        doSetsTest(tests[i].locale, conts, set, tests[i].inConts, tests[i].outConts, &status);
2208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        setLen = uset_toPattern(conts, buffer, setBufferLen, TRUE, &status);
2209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(U_SUCCESS(status)) {
2210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            /*log_verbose("Contractions %i: %s\n", uset_getItemCount(conts), aescstrdup(buffer, setLen));*/
2211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        } else {
2212ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("error %s. %i\n", u_errorName(status), setLen);
2213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            status = U_ZERO_ERROR;
2214ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
2215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        doSetsTest(tests[i].locale, exp, set, tests[i].inExp, tests[i].outExp, &status);
2216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        setLen = uset_toPattern(exp, buffer, setBufferLen, TRUE, &status);
2217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(U_SUCCESS(status)) {
2218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            /*log_verbose("Expansions %i: %s\n", uset_getItemCount(exp), aescstrdup(buffer, setLen));*/
2219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        } else {
2220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("error %s. %i\n", u_errorName(status), setLen);
2221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            status = U_ZERO_ERROR;
2222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
2223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        noConts = ucol_getUnsafeSet(coll, conts, &status);
2225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        doSetsTest(tests[i].locale, conts, set, tests[i].unsafeCodeUnits, tests[i].safeCodeUnits, &status);
2226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        setLen = uset_toPattern(conts, buffer, setBufferLen, TRUE, &status);
2227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(U_SUCCESS(status)) {
2228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_verbose("Unsafe %i: %s\n", uset_getItemCount(exp), aescstrdup(buffer, setLen));
2229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        } else {
2230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("error %s. %i\n", u_errorName(status), setLen);
2231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            status = U_ZERO_ERROR;
2232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
2233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_close(coll);
2235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
2236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uset_close(conts);
2239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uset_close(exp);
2240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uset_close(set);
2241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
2242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
224385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic void
224485bf2e2fbc60a9f938064abc8127d61da7d19882Claire HoTestOpenBinary(void)
2245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
2246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
2247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*
2248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char rule[] = "&h < d < c < b";
2249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char *wUCA[] = { "a", "h", "d", "c", "b", "i" };
2250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char *noUCA[] = {"d", "c", "b", "a", "h", "i" };
2251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    */
2252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* we have to use Cyrillic letters because latin-1 always gets copied */
2253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char rule[] = "&\\u0452 < \\u0434 < \\u0433 < \\u0432"; /* &dje < d < g < v */
2254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char *wUCA[] = { "\\u0430", "\\u0452", "\\u0434", "\\u0433", "\\u0432", "\\u0435" }; /* a, dje, d, g, v, e */
2255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char *noUCA[] = {"\\u0434", "\\u0433", "\\u0432", "\\u0430", "\\u0435", "\\u0452" }; /* d, g, v, a, e, dje */
2256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar uRules[256];
2258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t uRulesLen = u_unescape(rule, uRules, 256);
2259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator *coll = ucol_openRules(uRules, uRulesLen, UCOL_DEFAULT, UCOL_DEFAULT, NULL, &status);
226185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    UCollator *UCA = NULL;
2262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator *cloneNOUCA = NULL, *cloneWUCA = NULL;
2263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t imageBuffer[32768];
2265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t *image = imageBuffer;
2266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t imageBufferCapacity = 32768;
2267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t imageSize;
2269ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
227085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    if((coll==NULL)||(U_FAILURE(status))) {
2271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_data_err("could not load collators or error occured: %s\n",
2272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            u_errorName(status));
2273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
227485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    }
227585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    UCA = ucol_open("root", &status);
227685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    if((UCA==NULL)||(U_FAILURE(status))) {
227785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_data_err("could not load UCA collator or error occured: %s\n",
227885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            u_errorName(status));
227985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        return;
228085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    }
2281ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    imageSize = ucol_cloneBinary(coll, image, imageBufferCapacity, &status);
2282ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)) {
2283ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        image = (uint8_t *)malloc(imageSize*sizeof(uint8_t));
2284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        status = U_ZERO_ERROR;
2285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        imageSize = ucol_cloneBinary(coll, imageBuffer, imageSize, &status);
2286ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
2287ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2288ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2289ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    cloneWUCA = ucol_openBinary(image, imageSize, UCA, &status);
2290ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    cloneNOUCA = ucol_openBinary(image, imageSize, NULL, &status);
2291ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2292ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    genericOrderingTest(coll, wUCA, sizeof(wUCA)/sizeof(wUCA[0]));
2293ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2294ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    genericOrderingTest(cloneWUCA, wUCA, sizeof(wUCA)/sizeof(wUCA[0]));
2295ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    genericOrderingTest(cloneNOUCA, noUCA, sizeof(noUCA)/sizeof(noUCA[0]));
2296ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2297ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(image != imageBuffer) {
2298ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        free(image);
2299ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
2300ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(coll);
2301ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(cloneNOUCA);
2302ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(cloneWUCA);
2303ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(UCA);
2304ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
2305ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2306ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestDefault(void) {
2307ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Tests for code coverage. */
2308ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
2309ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator *coll = ucol_open("es@collation=pinyin", &status);
231085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    if (coll == NULL || status == U_FILE_ACCESS_ERROR) {
231185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_data_err("Unable to open collator es@collation=pinyin\n");
231285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        return;
231385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    }
2314ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (status != U_USING_DEFAULT_WARNING) {
2315ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* What do you mean that you know about using pinyin collation in Spanish!? This should be in the zh locale. */
2316ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("es@collation=pinyin should return U_USING_DEFAULT_WARNING, but returned %s\n", u_errorName(status));
2317ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
2318ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(coll);
2319ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getKeywordValues("funky", &status) != NULL) {
2320ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Collators should not know about the funky keyword.\n");
2321ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
2322ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (status != U_ILLEGAL_ARGUMENT_ERROR) {
2323ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("funky keyword didn't fail as expected %s\n", u_errorName(status));
2324ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
2325ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getKeywordValues("collation", &status) != NULL) {
2326ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("ucol_getKeywordValues should not work when given a bad status.\n");
2327ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
2328ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
2329ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
233085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic void TestDefaultKeyword(void) {
233185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    /* Tests for code coverage. */
233285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    UErrorCode status = U_ZERO_ERROR;
233385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    const char *loc = "zh_TW@collation=default";
233485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    UCollator *coll = ucol_open(loc, &status);
233585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    if(U_FAILURE(status)) {
233685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_info("Warning: ucol_open(%s, ...) returned %s, at least it didn't crash.\n", loc, u_errorName(status));
233785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    } else if (status != U_USING_FALLBACK_WARNING) {
233827f654740f2a26ad62a5c155af9199af9e69b889claireho        /* Hmm, skip the following test for CLDR 1.9 data and/or ICU 4.6, no longer seems to apply */
233927f654740f2a26ad62a5c155af9199af9e69b889claireho        #if 0
234085bf2e2fbc60a9f938064abc8127d61da7d19882Claire 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));
234127f654740f2a26ad62a5c155af9199af9e69b889claireho        #endif
234285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    }
234385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    ucol_close(coll);
234485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho}
234585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
234685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic void TestGetKeywordValuesForLocale(void) {
234727f654740f2a26ad62a5c155af9199af9e69b889claireho#define INCLUDE_UNIHAN_COLLATION 0
234885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho#define PREFERRED_SIZE 16
234927f654740f2a26ad62a5c155af9199af9e69b889claireho#define MAX_NUMBER_OF_KEYWORDS 8
235085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    const char *PREFERRED[PREFERRED_SIZE][MAX_NUMBER_OF_KEYWORDS+1] = {
235127f654740f2a26ad62a5c155af9199af9e69b889claireho            { "und",            "standard", "ducet", "search", NULL, NULL, NULL, NULL, NULL },
235227f654740f2a26ad62a5c155af9199af9e69b889claireho            { "en_US",          "standard", "ducet", "search", NULL, NULL, NULL, NULL, NULL },
235327f654740f2a26ad62a5c155af9199af9e69b889claireho            { "en_029",         "standard", "ducet", "search", NULL, NULL, NULL, NULL, NULL },
235427f654740f2a26ad62a5c155af9199af9e69b889claireho            { "de_DE",          "standard", "phonebook", "search", "ducet", NULL, NULL, NULL, NULL },
235527f654740f2a26ad62a5c155af9199af9e69b889claireho            { "de_Latn_DE",     "standard", "phonebook", "search", "ducet", NULL, NULL, NULL, NULL },
235627f654740f2a26ad62a5c155af9199af9e69b889claireho#if INCLUDE_UNIHAN_COLLATION
235727f654740f2a26ad62a5c155af9199af9e69b889claireho            { "zh",             "pinyin", "big5han", "gb2312han", "standard", "stroke", "unihan", "ducet", "search" },
235827f654740f2a26ad62a5c155af9199af9e69b889claireho            { "zh_Hans",        "pinyin", "big5han", "gb2312han", "standard", "stroke", "unihan", "ducet", "search" },
235927f654740f2a26ad62a5c155af9199af9e69b889claireho            { "zh_CN",          "pinyin", "big5han", "gb2312han", "standard", "stroke", "unihan", "ducet", "search" },
236027f654740f2a26ad62a5c155af9199af9e69b889claireho            { "zh_Hant",        "stroke", "big5han", "gb2312han", "pinyin", "standard", "unihan", "ducet", "search" },
236127f654740f2a26ad62a5c155af9199af9e69b889claireho            { "zh_TW",          "stroke", "big5han", "gb2312han", "pinyin", "standard", "unihan", "ducet", "search" },
236227f654740f2a26ad62a5c155af9199af9e69b889claireho            { "zh__PINYIN",     "pinyin", "big5han", "gb2312han", "standard", "stroke", "unihan", "ducet", "search" },
236327f654740f2a26ad62a5c155af9199af9e69b889claireho#else
236427f654740f2a26ad62a5c155af9199af9e69b889claireho            { "zh",             "pinyin", "big5han", "gb2312han", "standard", "stroke", "ducet", "search", NULL },
236527f654740f2a26ad62a5c155af9199af9e69b889claireho            { "zh_Hans",        "pinyin", "big5han", "gb2312han", "standard", "stroke", "ducet", "search", NULL },
236627f654740f2a26ad62a5c155af9199af9e69b889claireho            { "zh_CN",          "pinyin", "big5han", "gb2312han", "standard", "stroke", "ducet", "search", NULL },
236727f654740f2a26ad62a5c155af9199af9e69b889claireho            { "zh_Hant",        "stroke", "big5han", "gb2312han", "pinyin", "standard", "ducet", "search", NULL },
236827f654740f2a26ad62a5c155af9199af9e69b889claireho            { "zh_TW",          "stroke", "big5han", "gb2312han", "pinyin", "standard", "ducet", "search", NULL },
236927f654740f2a26ad62a5c155af9199af9e69b889claireho            { "zh__PINYIN",     "pinyin", "big5han", "gb2312han", "standard", "stroke", "ducet", "search", NULL },
237027f654740f2a26ad62a5c155af9199af9e69b889claireho#endif
237127f654740f2a26ad62a5c155af9199af9e69b889claireho            { "es_ES",          "standard", "search", "traditional", "ducet", NULL, NULL, NULL, NULL },
237227f654740f2a26ad62a5c155af9199af9e69b889claireho            { "es__TRADITIONAL","traditional", "search", "standard", "ducet", NULL, NULL, NULL, NULL },
237327f654740f2a26ad62a5c155af9199af9e69b889claireho            { "und@collation=phonebook",    "standard", "ducet", "search", NULL, NULL, NULL, NULL, NULL },
237427f654740f2a26ad62a5c155af9199af9e69b889claireho            { "de_DE@collation=big5han",    "standard", "phonebook", "search", "ducet", NULL, NULL, NULL, NULL },
237527f654740f2a26ad62a5c155af9199af9e69b889claireho            { "zzz@collation=xxx",          "standard", "ducet", "search", NULL, NULL, NULL, NULL, NULL }
237685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    };
237727f654740f2a26ad62a5c155af9199af9e69b889claireho#if INCLUDE_UNIHAN_COLLATION
237827f654740f2a26ad62a5c155af9199af9e69b889claireho    const int32_t expectedLength[PREFERRED_SIZE] = { 3, 3, 3, 4, 4, 8, 8, 8, 8, 8, 8, 4, 4, 3, 4, 3 };
237927f654740f2a26ad62a5c155af9199af9e69b889claireho#else
238027f654740f2a26ad62a5c155af9199af9e69b889claireho    const int32_t expectedLength[PREFERRED_SIZE] = { 3, 3, 3, 4, 4, 7, 7, 7, 7, 7, 7, 4, 4, 3, 4, 3 };
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