1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/********************************************************************
254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius * Copyright (c) 1997-2012, International Business Machines
385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * Corporation and others. All Rights Reserved.
4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ********************************************************************/
585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho/*****************************************************************************
6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*
7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* File CAPITEST.C
8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*
9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* Modification History:
1085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho*        Name                     Description
11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*     Madhu Katragadda             Ported for C API
1285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho*     Brian Rower                  Added TestOpenVsOpenRules
1385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho******************************************************************************
14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*//* C API TEST For COLLATOR */
15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h"
17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_COLLATION
19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <stdio.h>
21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <stdlib.h>
22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <string.h>
23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/uloc.h"
2485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho#include "unicode/ulocdata.h"
25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/ustring.h"
26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/ures.h"
27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/ucoleitr.h"
28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cintltst.h"
29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "capitst.h"
30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "ccolltst.h"
31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "putilimp.h"
3227f654740f2a26ad62a5c155af9199af9e69b889claireho#include "cmemory.h"
3385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho#include "cstring.h"
34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestAttribute(void);
36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestDefault(void);
3785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic void TestDefaultKeyword(void);
38b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2clairehostatic void TestBengaliSortKey(void);
39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        int TestBufferSize();    /* defined in "colutil.c" */
40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
42103e9ffba2cba345d0078eb8b8db33249f81840aCraig Corneliusstatic char* U_EXPORT2 ucol_sortKeyToString(const UCollator *coll, const uint8_t *sortkey, char *buffer, uint32_t len) {
43103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius    uint32_t position = 0;
44103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius    uint8_t b;
4585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
46103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius    if (position + 1 < len)
47103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        position += sprintf(buffer + position, "[");
48103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius    while ((b = *sortkey++) != 0) {
49103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        if (b == 1 && position + 5 < len) {
50103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius            position += sprintf(buffer + position, "%02X . ", b);
51103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        } else if (b != 1 && position + 3 < len) {
52103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius            position += sprintf(buffer + position, "%02X ", b);
53103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        }
54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
55103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius    if (position + 3 < len)
56103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        position += sprintf(buffer + position, "%02X]", b);
57103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius    return buffer;
58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid addCollAPITest(TestNode** root)
61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* WEIVTODO: return tests here */
63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestProperty,      "tscoll/capitst/TestProperty");
64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestRuleBasedColl, "tscoll/capitst/TestRuleBasedColl");
65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestCompare,       "tscoll/capitst/TestCompare");
66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestSortKey,       "tscoll/capitst/TestSortKey");
67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestHashCode,      "tscoll/capitst/TestHashCode");
68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestElemIter,      "tscoll/capitst/TestElemIter");
69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestGetAll,        "tscoll/capitst/TestGetAll");
70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*addTest(root, &TestGetDefaultRules, "tscoll/capitst/TestGetDefaultRules");*/
71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestDecomposition, "tscoll/capitst/TestDecomposition");
72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestSafeClone, "tscoll/capitst/TestSafeClone");
73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestCloneBinary, "tscoll/capitst/TestCloneBinary");
74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestGetSetAttr, "tscoll/capitst/TestGetSetAttr");
75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestBounds, "tscoll/capitst/TestBounds");
76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestGetLocale, "tscoll/capitst/TestGetLocale");
77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestSortKeyBufferOverrun, "tscoll/capitst/TestSortKeyBufferOverrun");
78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestAttribute, "tscoll/capitst/TestAttribute");
79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestGetTailoredSet, "tscoll/capitst/TestGetTailoredSet");
80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestMergeSortKeys, "tscoll/capitst/TestMergeSortKeys");
81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestShortString, "tscoll/capitst/TestShortString");
82ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho    /* BEGIN android-removed
83ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho       To save space, Android does not include the collation tailoring rules.
84ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho       We skip the tailing tests for collations. */
85ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho    /* addTest(root, &TestGetContractionsAndUnsafes, "tscoll/capitst/TestGetContractionsAndUnsafes"); */
86ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho    /* END android-removed */
87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestOpenBinary, "tscoll/capitst/TestOpenBinary");
88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addTest(root, &TestDefault, "tscoll/capitst/TestDefault");
8985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    addTest(root, &TestDefaultKeyword, "tscoll/capitst/TestDefaultKeyword");
90ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho    /* BEGIN android-removed
91ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho       To save space, Android does not build full collation tables and tailing rules.
92ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho       We skip the related tests. */
93ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho    /* addTest(root, &TestOpenVsOpenRules, "tscoll/capitst/TestOpenVsOpenRules"); */
94ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho    /* addTest(root, &TestGetKeywordValuesForLocale, "tscoll/capitst/TestGetKeywordValuesForLocale"); */
95ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho    /* END android-removed */
96b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    addTest(root, &TestBengaliSortKey, "tscoll/capitst/TestBengaliSortKey");
97103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius    addTest(root, &TestGetKeywordValuesForLocale, "tscoll/capitst/TestGetKeywordValuesForLocale");
98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestGetSetAttr(void) {
101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  UErrorCode status = U_ZERO_ERROR;
102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  UCollator *coll = ucol_open(NULL, &status);
103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  struct attrTest {
104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UColAttribute att;
105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UColAttributeValue val[5];
106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint32_t valueSize;
107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UColAttributeValue nonValue;
108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  } attrs[] = {
109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {UCOL_FRENCH_COLLATION, {UCOL_ON, UCOL_OFF}, 2, UCOL_SHIFTED},
110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {UCOL_ALTERNATE_HANDLING, {UCOL_NON_IGNORABLE, UCOL_SHIFTED}, 2, UCOL_OFF},/* attribute for handling variable elements*/
111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {UCOL_CASE_FIRST, {UCOL_OFF, UCOL_LOWER_FIRST, UCOL_UPPER_FIRST}, 3, UCOL_SHIFTED},/* who goes first, lower case or uppercase */
112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {UCOL_CASE_LEVEL, {UCOL_ON, UCOL_OFF}, 2, UCOL_SHIFTED},/* do we have an extra case level */
113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {UCOL_NORMALIZATION_MODE, {UCOL_ON, UCOL_OFF}, 2, UCOL_SHIFTED},/* attribute for normalization */
114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {UCOL_DECOMPOSITION_MODE, {UCOL_ON, UCOL_OFF}, 2, UCOL_SHIFTED},
115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {UCOL_STRENGTH,         {UCOL_PRIMARY, UCOL_SECONDARY, UCOL_TERTIARY, UCOL_QUATERNARY, UCOL_IDENTICAL}, 5, UCOL_SHIFTED},/* attribute for strength */
116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {UCOL_HIRAGANA_QUATERNARY_MODE, {UCOL_ON, UCOL_OFF}, 2, UCOL_SHIFTED},/* when turned on, this attribute */
117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  };
118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  UColAttribute currAttr;
11985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho  UColAttributeValue value;
120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  uint32_t i = 0, j = 0;
121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
12285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho  if (coll == NULL) {
12385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    log_err_status(status, "Unable to open collator. %s\n", u_errorName(status));
12485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    return;
12585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho  }
126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  for(i = 0; i<sizeof(attrs)/sizeof(attrs[0]); i++) {
127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    currAttr = attrs[i].att;
128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setAttribute(coll, currAttr, UCOL_DEFAULT, &status);
129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)) {
13085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho      log_err_status(status, "ucol_setAttribute with the default value returned error: %s\n", u_errorName(status));
131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      break;
132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    value = ucol_getAttribute(coll, currAttr, &status);
134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)) {
135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      log_err("ucol_getAttribute returned error: %s\n", u_errorName(status));
136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      break;
137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for(j = 0; j<attrs[i].valueSize; j++) {
139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      ucol_setAttribute(coll, currAttr, attrs[i].val[j], &status);
140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      if(U_FAILURE(status)) {
141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("ucol_setAttribute with the value %i returned error: %s\n", attrs[i].val[j], u_errorName(status));
142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        break;
143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      }
144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    status = U_ZERO_ERROR;
146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setAttribute(coll, currAttr, attrs[i].nonValue, &status);
147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_SUCCESS(status)) {
148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      log_err("ucol_setAttribute with the bad value didn't return an error\n");
149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      break;
150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    status = U_ZERO_ERROR;
152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setAttribute(coll, currAttr, value, &status);
154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)) {
155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      log_err("ucol_setAttribute with the default valuereturned error: %s\n", u_errorName(status));
156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      break;
157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  }
159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  status = U_ZERO_ERROR;
160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  value = ucol_getAttribute(coll, UCOL_ATTRIBUTE_COUNT, &status);
161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  if(U_SUCCESS(status)) {
162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_err("ucol_getAttribute for UCOL_ATTRIBUTE_COUNT didn't return an error\n");
163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  }
164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  status = U_ZERO_ERROR;
165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  ucol_setAttribute(coll, UCOL_ATTRIBUTE_COUNT, UCOL_DEFAULT, &status);
166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  if(U_SUCCESS(status)) {
167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_err("ucol_setAttribute for UCOL_ATTRIBUTE_COUNT didn't return an error\n");
168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  }
169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  status = U_ZERO_ERROR;
170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  ucol_close(coll);
171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void doAssert(int condition, const char *message)
175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (condition==0) {
177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("ERROR :  %s\n", message);
178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
18154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius#define UTF8_BUF_SIZE 128
18254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius
18354dcd9b6a06071f647dac967e9e267abb9410720Craig Corneliusstatic void doStrcoll(const UCollator* coll, const UChar* src, int32_t srcLen, const UChar* tgt, int32_t tgtLen,
18454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius                    UCollationResult expected, const char *message) {
18554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius    UErrorCode err = U_ZERO_ERROR;
18654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius    char srcU8[UTF8_BUF_SIZE], tgtU8[UTF8_BUF_SIZE];
18754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius    int32_t srcU8Len = -1, tgtU8Len = -1;
18854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius    int32_t len = 0;
18954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius
19054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius    if (ucol_strcoll(coll, src, srcLen, tgt, tgtLen) != expected) {
19154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius        log_err("ERROR :  %s\n", message);
19254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius    }
19354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius
19454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius    u_strToUTF8(srcU8, UTF8_BUF_SIZE, &len, src, srcLen, &err);
19554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius    if (U_FAILURE(err) || len >= UTF8_BUF_SIZE) {
19654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius        log_err("ERROR : UTF-8 conversion error\n");
19754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius        return;
19854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius    }
19954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius    if (srcLen >= 0) {
20054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius        srcU8Len = len;
20154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius    }
20254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius    u_strToUTF8(tgtU8, UTF8_BUF_SIZE, &len, tgt, tgtLen, &err);
20354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius    if (U_FAILURE(err) || len >= UTF8_BUF_SIZE) {
20454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius        log_err("ERROR : UTF-8 conversion error\n");
20554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius        return;
20654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius    }
20754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius    if (tgtLen >= 0) {
20854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius        tgtU8Len = len;
20954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius    }
21054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius
21154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius    if (ucol_strcollUTF8(coll, srcU8, srcU8Len, tgtU8, tgtU8Len, &err) != expected
21254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius        || U_FAILURE(err)) {
21354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius        log_err("ERROR: %s (strcollUTF8)\n", message);
21454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius    }
21554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius}
21654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius
217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if 0
218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* We don't have default rules, at least not in the previous sense */
219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestGetDefaultRules(){
220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint32_t size=0;
221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status=U_ZERO_ERROR;
222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator *coll=NULL;
223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t len1 = 0, len2=0;
224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t *binColData = NULL;
225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UResourceBundle *res = NULL;
227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UResourceBundle *binColl = NULL;
228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t *binResult = NULL;
22985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
23085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const UChar * defaultRulesArray=ucol_getDefaultRulesArray(&size);
232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Test the function ucol_getDefaultRulesArray()\n");
233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    coll = ucol_openRules(defaultRulesArray, size, UCOL_ON, UCOL_PRIMARY, &status);
235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_SUCCESS(status) && coll !=NULL) {
236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        binColData = (uint8_t*)ucol_cloneRuleData(coll, &len1, &status);
23785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
24085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    status=U_ZERO_ERROR;
242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    res=ures_open(NULL, "root", &status);
243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)){
244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("ERROR: Failed to get resource for \"root Locale\" with %s", myErrorName(status));
245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
24785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    binColl=ures_getByKey(res, "%%Collation", binColl, &status);
248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_SUCCESS(status)){
249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        binResult=(uint8_t*)ures_getBinary(binColl,  &len2, &status);
250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(U_FAILURE(status)){
251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("ERROR: ures_getBinary() failed\n");
252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }else{
254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("ERROR: ures_getByKey(locale(default), %%Collation) failed");
255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(len1 != len2){
259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Error: ucol_getDefaultRulesArray() failed to return the correct length.\n");
260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(memcmp(binColData, binResult, len1) != 0){
262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Error: ucol_getDefaultRulesArray() failed\n");
263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(binColData);
266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ures_close(binColl);
267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ures_close(res);
268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(coll);
26985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
270ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* Collator Properties
274ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucol_open, ucol_strcoll,  getStrength/setStrength
275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru getDecomposition/setDecomposition, getDisplayName*/
276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestProperty()
27785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho{
278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator *col, *ruled;
279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar *disName;
28027f654740f2a26ad62a5c155af9199af9e69b889claireho    int32_t len = 0;
28154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius    UChar source[12], target[12];
28254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius    char sourceU8[36], targetU8[36];
283ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t tempLength;
284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
28585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    /*
28650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho     * Expected version of the English collator.
28750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho     * Currently, the major/minor version numbers change when the builder code
28850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho     * changes,
28950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho     * number 2 is from the tailoring data version and
29050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho     * number 3 is the UCA version.
29150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho     * This changes with every UCA version change, and the expected value
29250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho     * needs to be adjusted.
29350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho     * Same in intltest/apicoll.cpp.
29450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho     */
29527f654740f2a26ad62a5c155af9199af9e69b889claireho    UVersionInfo currVersionArray = {0x31, 0xC0, 0x05, 0x2A};  /* from ICU 4.4/UCA 5.2 */
296ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UVersionInfo versionArray = {0, 0, 0, 0};
297ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UVersionInfo versionUCAArray = {0, 0, 0, 0};
29827f654740f2a26ad62a5c155af9199af9e69b889claireho    UVersionInfo versionUCDArray = {0, 0, 0, 0};
29985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
300ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("The property tests begin : \n");
301ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Test ucol_strcoll : \n");
302ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    col = ucol_open("en_US", &status);
303ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
30485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(status, "Default Collator creation failed.: %s\n", myErrorName(status));
305ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
306ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
307ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
308ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_getVersion(col, versionArray);
30927f654740f2a26ad62a5c155af9199af9e69b889claireho    /* Check for a version greater than some value rather than equality
31027f654740f2a26ad62a5c155af9199af9e69b889claireho     * so that we need not update the expected version each time. */
31127f654740f2a26ad62a5c155af9199af9e69b889claireho    if (uprv_memcmp(versionArray, currVersionArray, 4)<0) {
31227f654740f2a26ad62a5c155af9199af9e69b889claireho      log_err("Testing ucol_getVersion() - unexpected result: %02x.%02x.%02x.%02x\n",
31327f654740f2a26ad62a5c155af9199af9e69b889claireho              versionArray[0], versionArray[1], versionArray[2], versionArray[3]);
31427f654740f2a26ad62a5c155af9199af9e69b889claireho    } else {
31527f654740f2a26ad62a5c155af9199af9e69b889claireho      log_verbose("ucol_getVersion() result: %02x.%02x.%02x.%02x\n",
31627f654740f2a26ad62a5c155af9199af9e69b889claireho                  versionArray[0], versionArray[1], versionArray[2], versionArray[3]);
317ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
318ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
31927f654740f2a26ad62a5c155af9199af9e69b889claireho    /* Assume that the UCD and UCA versions are the same,
32027f654740f2a26ad62a5c155af9199af9e69b889claireho     * rather than hardcoding (and updating each time) a particular UCA version. */
32127f654740f2a26ad62a5c155af9199af9e69b889claireho    u_getUnicodeVersion(versionUCDArray);
322ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_getUCAVersion(col, versionUCAArray);
32327f654740f2a26ad62a5c155af9199af9e69b889claireho    if (0!=uprv_memcmp(versionUCAArray, versionUCDArray, 4)) {
32427f654740f2a26ad62a5c155af9199af9e69b889claireho      log_err("Testing ucol_getUCAVersion() - unexpected result: %hu.%hu.%hu.%hu\n",
32527f654740f2a26ad62a5c155af9199af9e69b889claireho              versionUCAArray[0], versionUCAArray[1], versionUCAArray[2], versionUCAArray[3]);
326ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
327ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
328ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(source, "ab");
329ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(target, "abc");
33085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
33154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius    doStrcoll(col, source, u_strlen(source), target, u_strlen(target), UCOL_LESS, "ab < abc comparison failed");
332ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
333ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(source, "ab");
334ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(target, "AB");
335ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
33654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius    doStrcoll(col, source, u_strlen(source), target, u_strlen(target), UCOL_LESS, "ab < AB comparison failed");
33754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius
338ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(source, "blackbird");
33954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius    u_uastrcpy(target, "black-bird");
34054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius
34154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius    doStrcoll(col, source, u_strlen(source), target, u_strlen(target), UCOL_GREATER, "black-bird > blackbird comparison failed");
342ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
343ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(source, "black bird");
344ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(target, "black-bird");
34554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius
34654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius    doStrcoll(col, source, u_strlen(source), target, u_strlen(target), UCOL_LESS, "black bird < black-bird comparison failed");
34754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius
348ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(source, "Hello");
349ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(target, "hello");
350ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
35154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius    doStrcoll(col, source, u_strlen(source), target, u_strlen(target), UCOL_GREATER, "Hello > hello comparison failed");
35254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius
353ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Test ucol_strcoll ends.\n");
354ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
355ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("testing ucol_getStrength() method ...\n");
356ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (ucol_getStrength(col) == UCOL_TERTIARY), "collation object has the wrong strength");
357ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (ucol_getStrength(col) != UCOL_PRIMARY), "collation object's strength is primary difference");
35885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
359ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("testing ucol_setStrength() method ...\n");
360ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setStrength(col, UCOL_SECONDARY);
361ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (ucol_getStrength(col) != UCOL_TERTIARY), "collation object's strength is secondary difference");
362ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (ucol_getStrength(col) != UCOL_PRIMARY), "collation object's strength is primary difference");
363ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (ucol_getStrength(col) == UCOL_SECONDARY), "collation object has the wrong strength");
364ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
36585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
366ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Get display name for the default collation in German : \n");
367ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
368ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    len=ucol_getDisplayName("en_US", "de_DE", NULL, 0,  &status);
369ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(status==U_BUFFER_OVERFLOW_ERROR){
370ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        status=U_ZERO_ERROR;
371ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        disName=(UChar*)malloc(sizeof(UChar) * (len+1));
372ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_getDisplayName("en_US", "de_DE", disName, len+1,  &status);
373ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("the display name for default collation in german: %s\n", austrdup(disName) );
374ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        free(disName);
375ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
376ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)){
377ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("ERROR: in getDisplayName: %s\n", myErrorName(status));
378ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
379ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
380ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Default collation getDisplayName ended.\n");
381ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
382ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho    /* BEGIN android-removed
383ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho       To save space, Android does not include the collation tailoring rules.
384ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho       Skip the related tests.
385b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
386ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ruled = ucol_open("da_DK", &status);
387ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("ucol_getRules() testing ...\n");
388ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_getRules(ruled, &tempLength);
389ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( tempLength != 0, "getRules() result incorrect" );
390ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("getRules tests end.\n");
391ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
392ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        UChar *buffer = (UChar *)malloc(200000*sizeof(UChar));
393ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        int32_t bufLen = 200000;
394ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        buffer[0] = '\0';
395ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("ucol_getRulesEx() testing ...\n");
396ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        tempLength = ucol_getRulesEx(col,UCOL_TAILORING_ONLY,buffer,bufLen );
397b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        doAssert( tempLength == 0x00, "getRulesEx() result incorrect" );
398ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("getRules tests end.\n");
39985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
400ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("ucol_getRulesEx() testing ...\n");
401ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        tempLength=ucol_getRulesEx(col,UCOL_FULL_RULES,buffer,bufLen );
402ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        doAssert( tempLength != 0, "getRulesEx() result incorrect" );
403ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("getRules tests end.\n");
404ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        free(buffer);
405ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
406ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(ruled);
407103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius    ucol_close(col);
40885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
409ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho    END android-removed */
410ea1f1813c8b13a850b13f256aeb5152bb0942e81claireho
411ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("open an collator for french locale");
412ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    col = ucol_open("fr_FR", &status);
413ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
414ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       log_err("ERROR: Creating French collation failed.: %s\n", myErrorName(status));
415ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
416ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
417ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setStrength(col, UCOL_PRIMARY);
418ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("testing ucol_getStrength() method again ...\n");
419ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (ucol_getStrength(col) != UCOL_TERTIARY), "collation object has the wrong strength");
420ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (ucol_getStrength(col) == UCOL_PRIMARY), "collation object's strength is not primary difference");
42185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
422ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("testing French ucol_setStrength() method ...\n");
423ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setStrength(col, UCOL_TERTIARY);
424ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (ucol_getStrength(col) == UCOL_TERTIARY), "collation object's strength is not tertiary difference");
425ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (ucol_getStrength(col) != UCOL_PRIMARY), "collation object's strength is primary difference");
426ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (ucol_getStrength(col) != UCOL_SECONDARY), "collation object's strength is secondary difference");
427ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(col);
42885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
429ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Get display name for the french collation in english : \n");
430ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    len=ucol_getDisplayName("fr_FR", "en_US", NULL, 0,  &status);
431ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(status==U_BUFFER_OVERFLOW_ERROR){
432ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        status=U_ZERO_ERROR;
433ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        disName=(UChar*)malloc(sizeof(UChar) * (len+1));
434ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_getDisplayName("fr_FR", "en_US", disName, len+1,  &status);
435ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("the display name for french collation in english: %s\n", austrdup(disName) );
436ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        free(disName);
437ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
438ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)){
439ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("ERROR: in getDisplayName: %s\n", myErrorName(status));
440ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
441ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
442ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Default collation getDisplayName ended.\n");
443ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
444ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
445ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
446ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* Test RuleBasedCollator and getRules*/
447ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestRuleBasedColl()
448ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
449ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator *col1, *col2, *col3, *col4;
450ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollationElements *iter1, *iter2;
451ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar ruleset1[60];
452ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar ruleset2[50];
453ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar teststr[10];
454ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar teststr2[10];
455ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const UChar *rule1, *rule2, *rule3, *rule4;
456ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t tempLength;
457ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
458ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(ruleset1, "&9 < a, A < b, B < c, C; ch, cH, Ch, CH < d, D, e, E");
459ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(ruleset2, "&9 < a, A < b, B < c, C < d, D, e, E");
46085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
461ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
462ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    col1 = ucol_openRules(ruleset1, u_strlen(ruleset1), UCOL_DEFAULT, UCOL_DEFAULT_STRENGTH, NULL,&status);
463ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
46485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(status, "RuleBased Collator creation failed.: %s\n", myErrorName(status));
465ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
466ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
467ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    else
468ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("PASS: RuleBased Collator creation passed\n");
46985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
470ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    status = U_ZERO_ERROR;
471ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    col2 = ucol_openRules(ruleset2, u_strlen(ruleset2),  UCOL_DEFAULT, UCOL_DEFAULT_STRENGTH, NULL, &status);
472ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
473ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("RuleBased Collator creation failed.: %s\n", myErrorName(status));
474ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
475ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
476ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    else
477ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("PASS: RuleBased Collator creation passed\n");
47885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
47985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
480ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    status = U_ZERO_ERROR;
481ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    col3= ucol_open(NULL, &status);
482ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
483ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Default Collator creation failed.: %s\n", myErrorName(status));
484ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
485ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
486ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    else
487ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("PASS: Default Collator creation passed\n");
48885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
489ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    rule1 = ucol_getRules(col1, &tempLength);
490ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    rule2 = ucol_getRules(col2, &tempLength);
491ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    rule3 = ucol_getRules(col3, &tempLength);
492ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
493ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert((u_strcmp(rule1, rule2) != 0), "Default collator getRules failed");
494ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert((u_strcmp(rule2, rule3) != 0), "Default collator getRules failed");
495ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert((u_strcmp(rule1, rule3) != 0), "Default collator getRules failed");
49685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
497ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    col4=ucol_openRules(rule2, u_strlen(rule2), UCOL_DEFAULT, UCOL_DEFAULT_STRENGTH, NULL, &status);
498ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
499ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("RuleBased Collator creation failed.: %s\n", myErrorName(status));
500ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
501ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
502ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    rule4= ucol_getRules(col4, &tempLength);
503ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert((u_strcmp(rule2, rule4) == 0), "Default collator getRules failed");
504ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
505ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(col1);
506ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(col2);
507ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(col3);
508ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(col4);
50985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
510ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* tests that modifier ! is always ignored */
511ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(ruleset1, "!&a<b");
512ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    teststr[0] = 0x0e40;
513ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    teststr[1] = 0x0e01;
514ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    teststr[2] = 0x0e2d;
515ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    col1 = ucol_openRules(ruleset1, u_strlen(ruleset1), 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    col2 = ucol_open("en_US", &status);
521ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
522ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("en_US Collator creation failed.: %s\n", myErrorName(status));
523ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
524ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
525ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    iter1 = ucol_openElements(col1, teststr, 3, &status);
526ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    iter2 = ucol_openElements(col2, teststr, 3, &status);
527ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)) {
528ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("ERROR: CollationElement iterator creation failed.: %s\n", myErrorName(status));
529ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
530ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
531ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    while (TRUE) {
532ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* testing with en since thai has its own tailoring */
533ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        uint32_t ce = ucol_next(iter1, &status);
534ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        uint32_t ce2 = ucol_next(iter2, &status);
535ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(U_FAILURE(status)) {
536ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("ERROR: CollationElement iterator creation failed.: %s\n", myErrorName(status));
537ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            return;
538ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
539ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (ce2 != ce) {
540ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru             log_err("! modifier test failed");
541ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
542ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (ce == UCOL_NULLORDER) {
543ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            break;
544ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
545ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
546ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_closeElements(iter1);
547ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_closeElements(iter2);
548ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(col1);
549ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(col2);
550ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* test that we can start a rule without a & or < */
551ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(ruleset1, "< z < a");
552ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    col1 = ucol_openRules(ruleset1, u_strlen(ruleset1), UCOL_DEFAULT, UCOL_DEFAULT_STRENGTH, NULL, &status);
553ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
554ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("RuleBased Collator creation failed.: %s\n", myErrorName(status));
555ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
556ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
557ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(teststr, "z");
558ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(teststr2, "a");
559ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_greaterOrEqual(col1, teststr, 1, teststr2, 1)) {
560ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Rule \"z < a\" fails");
56185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    }
562ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(col1);
563ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
564ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
565ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestCompare()
566ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
567ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
568ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator *col;
569ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar* test1;
570ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar* test2;
57185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
572ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("The compare tests begin : \n");
573ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    status=U_ZERO_ERROR;
574ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    col = ucol_open("en_US", &status);
575ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)) {
57685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(status, "ucal_open() collation creation failed.: %s\n", myErrorName(status));
577ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
578ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
579ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    test1=(UChar*)malloc(sizeof(UChar) * 6);
580ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    test2=(UChar*)malloc(sizeof(UChar) * 6);
581ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(test1, "Abcda");
582ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(test2, "abcda");
58385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
584ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Use tertiary comparison level testing ....\n");
58585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
586ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (!ucol_equal(col, test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"Abcda\" != \"abcda\" ");
587ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (ucol_greater(col, test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"Abcda\" >>> \"abcda\" ");
58885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    doAssert( (ucol_greaterOrEqual(col, test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"Abcda\" >>> \"abcda\"");
589ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
590ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setStrength(col, UCOL_SECONDARY);
591ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Use secondary comparison level testing ....\n");
59285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
593ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (ucol_equal(col, test1, u_strlen(test1), test2, u_strlen(test2) )), "Result should be \"Abcda\" == \"abcda\"");
594ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (!ucol_greater(col, test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"Abcda\" == \"abcda\"");
59585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    doAssert( (ucol_greaterOrEqual(col, test1, u_strlen(test1), test2, u_strlen(test2) )), "Result should be \"Abcda\" == \"abcda\"");
596ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
597ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setStrength(col, UCOL_PRIMARY);
598ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Use primary comparison level testing ....\n");
59985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
600ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (ucol_equal(col, test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"Abcda\" == \"abcda\"");
601ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (!ucol_greater(col, test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"Abcda\" == \"abcda\"");
60285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    doAssert( (ucol_greaterOrEqual(col, test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"Abcda\" == \"abcda\"");
60385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
604ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
605ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("The compare tests end.\n");
606ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(col);
607ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(test1);
608ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(test2);
60985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
610ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
611ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*
612ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru---------------------------------------------
613ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tests decomposition setting
614ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/
615ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestDecomposition() {
616ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
617ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator *en_US, *el_GR, *vi_VN;
618ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    en_US = ucol_open("en_US", &status);
619ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    el_GR = ucol_open("el_GR", &status);
620ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    vi_VN = ucol_open("vi_VN", &status);
621ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
622ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
62385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(status, "ERROR: collation creation failed.: %s\n", myErrorName(status));
624ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
625ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
626ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
627ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getAttribute(vi_VN, UCOL_NORMALIZATION_MODE, &status) != UCOL_ON ||
628ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        U_FAILURE(status))
629ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
630ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("ERROR: vi_VN collation did not have cannonical decomposition for normalization!\n");
631ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
632ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
633ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    status = U_ZERO_ERROR;
634ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getAttribute(el_GR, UCOL_NORMALIZATION_MODE, &status) != UCOL_ON ||
635ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        U_FAILURE(status))
636ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
637ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("ERROR: el_GR collation did not have cannonical decomposition for normalization!\n");
638ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
639ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
640ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    status = U_ZERO_ERROR;
641ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getAttribute(en_US, UCOL_NORMALIZATION_MODE, &status) != UCOL_OFF ||
642ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        U_FAILURE(status))
643ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
644ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("ERROR: en_US collation had cannonical decomposition for normalization!\n");
645ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
646ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
647ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(en_US);
648ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(el_GR);
649ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(vi_VN);
650ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
651ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
652ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define CLONETEST_COLLATOR_COUNT 4
653ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
654ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestSafeClone() {
65585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    UChar test1[6];
65685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    UChar test2[6];
657ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const UChar umlautUStr[] = {0x00DC, 0};
658ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const UChar oeStr[] = {0x0055, 0x0045, 0};
659ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator * someCollators [CLONETEST_COLLATOR_COUNT];
660ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator * someClonedCollators [CLONETEST_COLLATOR_COUNT];
661ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator * col;
662ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode err = U_ZERO_ERROR;
66354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius    int8_t idx = 6;    /* Leave this here to test buffer alingment in memory*/
664ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t buffer [CLONETEST_COLLATOR_COUNT] [U_COL_SAFECLONE_BUFFERSIZE];
665ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t bufferSize = U_COL_SAFECLONE_BUFFERSIZE;
666ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char sampleRuleChars[] = "&Z < CH";
667ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar sampleRule[sizeof(sampleRuleChars)];
668ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
669ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (TestBufferSize()) {
670ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("U_COL_SAFECLONE_BUFFERSIZE should be larger than sizeof(UCollator)\n");
671ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
672ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
673ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
674ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(test1, "abCda");
675ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(test2, "abcda");
676ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(sampleRule, sampleRuleChars);
67785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
678ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* one default collator & two complex ones */
679ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    someCollators[0] = ucol_open("en_US", &err);
680ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    someCollators[1] = ucol_open("ko", &err);
681ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    someCollators[2] = ucol_open("ja_JP", &err);
682ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    someCollators[3] = ucol_openRules(sampleRule, -1, UCOL_ON, UCOL_TERTIARY, NULL, &err);
683ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(err)) {
68454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius        for (idx = 0; idx < CLONETEST_COLLATOR_COUNT; idx++) {
68554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius            ucol_close(someCollators[idx]);
68685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        }
687ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_data_err("Couldn't open one or more collators\n");
688ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
689ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
690ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
691ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Check the various error & informational states: */
692ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
693ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Null status - just returns NULL */
694ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (0 != ucol_safeClone(someCollators[0], buffer[0], &bufferSize, 0))
695ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
696ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: Cloned Collator failed to deal correctly with null status\n");
697ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
698ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* error status - should return 0 & keep error the same */
699ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    err = U_MEMORY_ALLOCATION_ERROR;
700ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (0 != ucol_safeClone(someCollators[0], buffer[0], &bufferSize, &err) || err != U_MEMORY_ALLOCATION_ERROR)
701ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
702ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: Cloned Collator failed to deal correctly with incoming error status\n");
703ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
704ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    err = U_ZERO_ERROR;
705ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
706ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Null buffer size pointer - just returns NULL & set error to U_ILLEGAL_ARGUMENT_ERROR*/
707ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (0 != ucol_safeClone(someCollators[0], buffer[0], 0, &err) || err != U_ILLEGAL_ARGUMENT_ERROR)
708ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
709ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: Cloned Collator failed to deal correctly with null bufferSize pointer\n");
710ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
711ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    err = U_ZERO_ERROR;
71285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
713ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* buffer size pointer is 0 - fill in pbufferSize with a size */
714ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    bufferSize = 0;
715ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (0 != ucol_safeClone(someCollators[0], buffer[0], &bufferSize, &err) || U_FAILURE(err) || bufferSize <= 0)
716ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
717ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: Cloned Collator failed a sizing request ('preflighting')\n");
718ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
719ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Verify our define is large enough  */
720ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_COL_SAFECLONE_BUFFERSIZE < bufferSize)
721ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
722ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: Pre-calculated buffer size is too small\n");
723ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
724ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Verify we can use this run-time calculated size */
725ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (0 == (col = ucol_safeClone(someCollators[0], buffer[0], &bufferSize, &err)) || U_FAILURE(err))
726ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
727ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: Collator can't be cloned with run-time size\n");
728ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
729ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (col) ucol_close(col);
730ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* size one byte too small - should allocate & let us know */
731ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    --bufferSize;
732ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (0 == (col = ucol_safeClone(someCollators[0], 0, &bufferSize, &err)) || err != U_SAFECLONE_ALLOCATED_WARNING)
733ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
734ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: Cloned Collator failed to deal correctly with too-small buffer size\n");
735ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
736ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (col) ucol_close(col);
737ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    err = U_ZERO_ERROR;
738ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    bufferSize = U_COL_SAFECLONE_BUFFERSIZE;
739ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
740ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
741ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Null buffer pointer - return Collator & set error to U_SAFECLONE_ALLOCATED_ERROR */
742ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (0 == (col = ucol_safeClone(someCollators[0], 0, &bufferSize, &err)) || err != U_SAFECLONE_ALLOCATED_WARNING)
743ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
744ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: Cloned Collator failed to deal correctly with null buffer pointer\n");
745ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
746ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (col) ucol_close(col);
747ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    err = U_ZERO_ERROR;
748ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
749ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Null Collator - return NULL & set U_ILLEGAL_ARGUMENT_ERROR */
750ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (0 != ucol_safeClone(0, buffer[0], &bufferSize, &err) || err != U_ILLEGAL_ARGUMENT_ERROR)
751ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
752ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: Cloned Collator failed to deal correctly with null Collator pointer\n");
753ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
754ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
755ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    err = U_ZERO_ERROR;
756ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
757ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Test that a cloned collator doesn't accidentally use UCA. */
758ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    col=ucol_open("de@collation=phonebook", &err);
759ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    bufferSize = U_COL_SAFECLONE_BUFFERSIZE;
760ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    someClonedCollators[0] = ucol_safeClone(col, buffer[0], &bufferSize, &err);
761ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (ucol_greater(col, umlautUStr, u_strlen(umlautUStr), oeStr, u_strlen(oeStr))), "Original German phonebook collation sorts differently than expected");
762ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (ucol_greater(someClonedCollators[0], umlautUStr, u_strlen(umlautUStr), oeStr, u_strlen(oeStr))), "Cloned German phonebook collation sorts differently than expected");
763ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (!ucol_equals(someClonedCollators[0], col)) {
764ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: Cloned German phonebook collator is not equal to original.\n");
765ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
766ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(col);
767ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(someClonedCollators[0]);
768ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
769ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    err = U_ZERO_ERROR;
770ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
771ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* change orig & clone & make sure they are independent */
772ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
77354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius    for (idx = 0; idx < CLONETEST_COLLATOR_COUNT; idx++)
774ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
77554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius        ucol_setStrength(someCollators[idx], UCOL_IDENTICAL);
776ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        bufferSize = 1;
777ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        err = U_ZERO_ERROR;
77854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius        ucol_close(ucol_safeClone(someCollators[idx], buffer[idx], &bufferSize, &err));
779ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (err != U_SAFECLONE_ALLOCATED_WARNING) {
78054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius            log_err("FAIL: collator number %d was not allocated.\n", idx);
78154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius            log_err("FAIL: status of Collator[%d] is %d  (hex: %x).\n", idx, err, err);
782ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
783ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
784ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        bufferSize = U_COL_SAFECLONE_BUFFERSIZE;
785ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        err = U_ZERO_ERROR;
78654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius        someClonedCollators[idx] = ucol_safeClone(someCollators[idx], buffer[idx], &bufferSize, &err);
78754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius        if (someClonedCollators[idx] == NULL
78854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius            || someClonedCollators[idx] < (UCollator *)buffer[idx]
78954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius            || someClonedCollators[idx] > (UCollator *)(buffer[idx]+(U_COL_SAFECLONE_BUFFERSIZE-1)))
790ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {
791ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("FAIL: Cloned collator didn't use provided buffer.\n");
792ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            return;
793ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
79454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius        if (!ucol_equals(someClonedCollators[idx], someCollators[idx])) {
79554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius            log_err("FAIL: Cloned collator is not equal to original at index = %d.\n", idx);
796ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
797ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
798ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* Check the usability */
79954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius        ucol_setStrength(someCollators[idx], UCOL_PRIMARY);
80054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius        ucol_setAttribute(someCollators[idx], UCOL_CASE_LEVEL, UCOL_OFF, &err);
80185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
80254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius        doAssert( (ucol_equal(someCollators[idx], test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"abcda\" == \"abCda\"");
80385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
804ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* Close the original to make sure that the clone is usable. */
80554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius        ucol_close(someCollators[idx]);
806ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
80754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius        ucol_setStrength(someClonedCollators[idx], UCOL_TERTIARY);
80854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius        ucol_setAttribute(someClonedCollators[idx], UCOL_CASE_LEVEL, UCOL_OFF, &err);
80954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius        doAssert( (ucol_greater(someClonedCollators[idx], test1, u_strlen(test1), test2, u_strlen(test2))), "Result should be \"abCda\" >>> \"abcda\" ");
810ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
81154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius        ucol_close(someClonedCollators[idx]);
812ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
813ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
814ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
815ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestCloneBinary(){
816ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode err = U_ZERO_ERROR;
817ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator * col = ucol_open("en_US", &err);
818ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator * c;
819ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t size;
820ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t * buffer;
821ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
822ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(err)) {
823ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_data_err("Couldn't open collator. Error: %s\n", u_errorName(err));
824ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
825ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
826ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
827ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    size = ucol_cloneBinary(col, NULL, 0, &err);
828ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(size==0 || err!=U_BUFFER_OVERFLOW_ERROR) {
829ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("ucol_cloneBinary - couldn't check size. Error: %s\n", u_errorName(err));
830ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
831ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
832ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    err = U_ZERO_ERROR;
833ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
834ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    buffer = (uint8_t *) malloc(size);
835ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_cloneBinary(col, buffer, size, &err);
836ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(err)) {
837ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("ucol_cloneBinary - couldn't clone.. Error: %s\n", u_errorName(err));
838ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        free(buffer);
839ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
840ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
841ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
842ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* how to check binary result ? */
843ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
844ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    c = ucol_openBinary(buffer, size, col, &err);
845ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(err)) {
846ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("ucol_openBinary failed. Error: %s\n", u_errorName(err));
847ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
848ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        UChar t[] = {0x41, 0x42, 0x43, 0};  /* ABC */
849ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        uint8_t  *k1, *k2;
850ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        int l1, l2;
851ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        l1 = ucol_getSortKey(col, t, -1, NULL,0);
852ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        l2 = ucol_getSortKey(c, t, -1, NULL,0);
853ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        k1 = (uint8_t *) malloc(sizeof(uint8_t) * l1);
854ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        k2 = (uint8_t *) malloc(sizeof(uint8_t) * l2);
855ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_getSortKey(col, t, -1, k1, l1);
856ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_getSortKey(col, t, -1, k2, l2);
857ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (strcmp((char *)k1,(char *)k2) != 0){
858ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("ucol_openBinary - new collator should equal to old one\n");
859ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        };
860ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        free(k1);
861ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        free(k2);
862ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
863ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(buffer);
864ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(c);
865ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(col);
866ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
867b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
868b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
869b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2clairehostatic void TestBengaliSortKey(void)
870b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho{
871b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  const char *curLoc = "bn";
872b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  UChar str1[] = { 0x09BE, 0 };
873b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  UChar str2[] = { 0x0B70, 0 };
874b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  UCollator *c2 = NULL;
875b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  const UChar *rules;
876b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  int32_t rulesLength=-1;
877b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  uint8_t *sortKey1;
878b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  int32_t sortKeyLen1 = 0;
879b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  uint8_t *sortKey2;
880b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  int32_t sortKeyLen2 = 0;
881b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  UErrorCode status = U_ZERO_ERROR;
882b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  char sortKeyStr1[2048];
883b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  uint32_t sortKeyStrLen1 = sizeof(sortKeyStr1)/sizeof(sortKeyStr1[0]);
884b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  char sortKeyStr2[2048];
885b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  uint32_t sortKeyStrLen2 = sizeof(sortKeyStr2)/sizeof(sortKeyStr2[0]);
886b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  UCollationResult result;
887b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
888b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  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};
889b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
890b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  rules = preRules;
891b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
892b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  log_verbose("Rules: %s\n", aescstrdup(rules, rulesLength));
893b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
894b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  c2 = ucol_openRules(rules, rulesLength, UCOL_DEFAULT, UCOL_DEFAULT_STRENGTH, NULL, &status);
895b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  if (U_FAILURE(status)) {
896b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    log_data_err("ERROR: Creating collator from rules failed with locale: %s : %s\n", curLoc, myErrorName(status));
897b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    return;
898b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  }
899b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
900b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  sortKeyLen1 = ucol_getSortKey(c2, str1, -1, NULL, 0);
901b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  sortKey1 = (uint8_t*)malloc(sortKeyLen1+1);
902b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  ucol_getSortKey(c2,str1,-1,sortKey1, sortKeyLen1+1);
903103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius  ucol_sortKeyToString(c2, sortKey1, sortKeyStr1, sortKeyStrLen1);
904b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
905b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
906b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  sortKeyLen2 = ucol_getSortKey(c2, str2, -1, NULL, 0);
907b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  sortKey2 = (uint8_t*)malloc(sortKeyLen2+1);
908b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  ucol_getSortKey(c2,str2,-1,sortKey2, sortKeyLen2+1);
909b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
910103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius  ucol_sortKeyToString(c2, sortKey2, sortKeyStr2, sortKeyStrLen2);
911b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
912b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
913b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
914b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  result=ucol_strcoll(c2, str1, -1, str2, -1);
915b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  if(result!=UCOL_LESS) {
916b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    log_err("Error: %s was not less than %s: result=%d.\n", aescstrdup(str1,-1), aescstrdup(str2,-1), result);
917b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    log_info("[%s] -> %s (%d, from rule)\n", aescstrdup(str1,-1), sortKeyStr1, sortKeyLen1);
918b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    log_info("[%s] -> %s (%d, from rule)\n", aescstrdup(str2,-1), sortKeyStr2, sortKeyLen2);
919b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  } else {
920b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    log_verbose("OK: %s was  less than %s: result=%d.\n", aescstrdup(str1,-1), aescstrdup(str2,-1), result);
921b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    log_verbose("[%s] -> %s (%d, from rule)\n", aescstrdup(str1,-1), sortKeyStr1, sortKeyLen1);
922b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    log_verbose("[%s] -> %s (%d, from rule)\n", aescstrdup(str2,-1), sortKeyStr2, sortKeyLen2);
923b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  }
924b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
925b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  free(sortKey1);
926b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  free(sortKey2);
927b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho  ucol_close(c2);
928b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
929b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho}
930b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
931ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*
93285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    TestOpenVsOpenRules ensures that collators from ucol_open and ucol_openRules
93385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    will generate identical sort keys
93485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho*/
93585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hovoid TestOpenVsOpenRules(){
93685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
93785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    /* create an array of all the locales */
93885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    int32_t numLocales = uloc_countAvailable();
93985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    int32_t sizeOfStdSet;
94085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    uint32_t adder;
94185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    UChar str[41]; /* create an array of UChar of size maximum strSize + 1 */
94285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    USet *stdSet;
94385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    char* curLoc;
94485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    UCollator * c1;
94585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    UCollator * c2;
94685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    const UChar* rules;
94785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    int32_t rulesLength;
94885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    int32_t sortKeyLen1, sortKeyLen2;
94985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    uint8_t *sortKey1 = NULL, *sortKey2 = NULL;
950103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius    char sortKeyStr1[512], sortKeyStr2[512];
951103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius    uint32_t sortKeyStrLen1 = sizeof(sortKeyStr1) / sizeof(sortKeyStr1[0]),
952103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius             sortKeyStrLen2 = sizeof(sortKeyStr2) / sizeof(sortKeyStr2[0]);
95385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    ULocaleData *uld;
95450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    int32_t x, y, z;
95585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    USet *eSet;
95685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    int32_t eSize;
95785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    int strSize;
95885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
95985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    UErrorCode err = U_ZERO_ERROR;
96085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
96185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    /* create a set of standard characters that aren't very interesting...
96285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    and then we can find some interesting ones later */
96385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
96485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    stdSet = uset_open(0x61, 0x7A);
96585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    uset_addRange(stdSet, 0x41, 0x5A);
96685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    uset_addRange(stdSet, 0x30, 0x39);
96785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    sizeOfStdSet = uset_size(stdSet);
96885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
96985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    adder = 1;
97027f654740f2a26ad62a5c155af9199af9e69b889claireho    if(getTestOption(QUICK_OPTION))
97185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    {
97285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        adder = 10;
97385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    }
97485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
97585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    for(x = 0; x < numLocales; x+=adder){
97685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        curLoc = (char *)uloc_getAvailable(x);
97785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_verbose("Processing %s\n", curLoc);
97885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
97985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        /* create a collator the normal API way */
98085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        c1 = ucol_open(curLoc, &err);
98185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        if (U_FAILURE(err)) {
98285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            log_err("ERROR: Normal collation creation failed with locale: %s : %s\n", curLoc, myErrorName(err));
98385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            return;
98485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        }
98585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
98685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        /* grab the rules */
98785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        rules = ucol_getRules(c1, &rulesLength);
98885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
98985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        /* use those rules to create a collator from rules */
99085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        c2 = ucol_openRules(rules, rulesLength, UCOL_DEFAULT, UCOL_DEFAULT_STRENGTH, NULL, &err);
99185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        if (U_FAILURE(err)) {
99285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            log_err("ERROR: Creating collator from rules failed with locale: %s : %s\n", curLoc, myErrorName(err));
99385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            return;
99485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        }
99585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
99685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        uld = ulocdata_open(curLoc, &err);
99785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
99885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        /*now that we have some collators, we get several strings */
99985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
100085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        for(y = 0; y < 5; y++){
100185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
100285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            /* get a set of ALL the characters in this locale */
100385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            eSet =  ulocdata_getExemplarSet(uld, NULL, 0, ULOCDATA_ES_STANDARD, &err);
100485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            eSize = uset_size(eSet);
100585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
100685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            /* make a string with these characters in it */
100785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            strSize = (rand()%40) + 1;
100885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
100985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            for(z = 0; z < strSize; z++){
101085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                str[z] = uset_charAt(eSet, rand()%eSize);
101185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            }
101285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
101385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            /* change the set to only include 'abnormal' characters (not A-Z, a-z, 0-9 */
101485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            uset_removeAll(eSet, stdSet);
101585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            eSize = uset_size(eSet);
101685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
101785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            /* if there are some non-normal characters left, put a few into the string, just to make sure we have some */
101885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            if(eSize > 0){
101985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                str[2%strSize] = uset_charAt(eSet, rand()%eSize);
102085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                str[3%strSize] = uset_charAt(eSet, rand()%eSize);
102185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                str[5%strSize] = uset_charAt(eSet, rand()%eSize);
102285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                str[10%strSize] = uset_charAt(eSet, rand()%eSize);
102385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                str[13%strSize] = uset_charAt(eSet, rand()%eSize);
102485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            }
102585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            /* terminate the string */
102685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            str[strSize-1] = '\0';
102785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            log_verbose("String used: %S\n", str);
102885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
102985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            /* get sort keys for both of them, and check that the keys are identicle */
103085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            sortKeyLen1 = ucol_getSortKey(c1, str, u_strlen(str),  NULL, 0);
103185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            sortKey1 = (uint8_t*)malloc(sizeof(uint8_t) * (sortKeyLen1 + 1));
103285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            /*memset(sortKey1, 0xFE, sortKeyLen1);*/
103385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            ucol_getSortKey(c1, str, u_strlen(str), sortKey1, sortKeyLen1 + 1);
1034103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius            ucol_sortKeyToString(c1, sortKey1, sortKeyStr1, sortKeyStrLen1);
103585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
103685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            sortKeyLen2 = ucol_getSortKey(c2, str, u_strlen(str),  NULL, 0);
103785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            sortKey2 = (uint8_t*)malloc(sizeof(uint8_t) * (sortKeyLen2 + 1));
103885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            /*memset(sortKey2, 0xFE, sortKeyLen2);*/
103985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            ucol_getSortKey(c2, str, u_strlen(str), sortKey2, sortKeyLen2 + 1);
1040103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius            ucol_sortKeyToString(c2, sortKey2, sortKeyStr2, sortKeyStrLen2);
104185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
104285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            /* Check that the lengths are the same */
1043103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius            if (sortKeyLen1 != sortKeyLen2) {
1044103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius                log_err("ERROR : Sort key lengths %d and %d for text '%s' in locale '%s' do not match.\n",
1045103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius                    sortKeyLen1, sortKeyLen2, str, curLoc);
1046103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius            }
104785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
104885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            /* check that the keys are the same */
1049103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius            if (memcmp(sortKey1, sortKey2, sortKeyLen1) != 0) {
1050103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius                log_err("ERROR : Sort keys '%s' and '%s' for text '%s' in locale '%s' are not equivalent.\n",
1051103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius                    sortKeyStr1, sortKeyStr2, str, curLoc);
1052103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius            }
105385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
105485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            /* clean up after each string */
105585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            free(sortKey1);
105685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            free(sortKey2);
105785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            uset_close(eSet);
105885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        }
105985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        /* clean up after each locale */
106085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        ulocdata_close(uld);
106185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        ucol_close(c1);
106285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        ucol_close(c2);
106385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    }
106485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    /* final clean up */
106585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    uset_close(stdSet);
106685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho}
106785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho/*
1068ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru----------------------------------------------------------------------------
1069ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ctor -- Tests the getSortKey
1070ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/
1071ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestSortKey()
107285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho{
1073ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t *sortk1 = NULL, *sortk2 = NULL, *sortk3 = NULL, *sortkEmpty = NULL;
1074ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t sortklen, osortklen;
1075ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator *col;
1076ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar *test1, *test2, *test3;
1077ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
1078ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char toStringBuffer[256], *resultP;
1079103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius    uint32_t toStringLen=sizeof(toStringBuffer)/sizeof(toStringBuffer[0]);
1080ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1081ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1082ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t s1[] = { 0x9f, 0x00 };
1083ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t s2[] = { 0x61, 0x00 };
1084ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int  strcmpResult;
1085ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1086ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    strcmpResult = strcmp((const char *)s1, (const char *)s2);
1087ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("strcmp(0x9f..., 0x61...) = %d\n", strcmpResult);
108885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1089ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(strcmpResult <= 0) {
1090ac04d0bbe12b3ef54518635711412f178cb4d16Jean-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",
1091ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru              strcmpResult);
1092ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1093ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1094ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1095ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("testing SortKey begins...\n");
109685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    /* this is supposed to open default date format, but later on it treats it like it is "en_US"
1097ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       - very bad if you try to run the tests on machine where default locale is NOT "en_US" */
1098ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* col = ucol_open(NULL, &status); */
1099ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    col = ucol_open("en_US", &status);
1100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
110185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(status, "ERROR: Default collation creation failed.: %s\n", myErrorName(status));
1102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(ucol_getStrength(col) != UCOL_DEFAULT_STRENGTH)
1107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
1108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("ERROR: default collation did not have UCOL_DEFAULT_STRENGTH !\n");
1109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Need to use identical strength */
1111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setAttribute(col, UCOL_STRENGTH, UCOL_IDENTICAL, &status);
1112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    test1=(UChar*)malloc(sizeof(UChar) * 6);
1114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    test2=(UChar*)malloc(sizeof(UChar) * 6);
1115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    test3=(UChar*)malloc(sizeof(UChar) * 6);
111685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    memset(test1,0xFE, sizeof(UChar)*6);
1118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    memset(test2,0xFE, sizeof(UChar)*6);
1119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    memset(test3,0xFE, sizeof(UChar)*6);
1120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(test1, "Abcda");
1123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(test2, "abcda");
1124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(test3, "abcda");
1125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Use tertiary comparison level testing ....\n");
1127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortklen=ucol_getSortKey(col, test1, u_strlen(test1),  NULL, 0);
1129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortk1=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen+1));
1130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    memset(sortk1,0xFE, sortklen);
1131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_getSortKey(col, test1, u_strlen(test1), sortk1, sortklen+1);
1132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortklen=ucol_getSortKey(col, test2, u_strlen(test2),  NULL, 0);
1134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortk2=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen+1));
1135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    memset(sortk2,0xFE, sortklen);
1136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_getSortKey(col, test2, u_strlen(test2), sortk2, sortklen+1);
1137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    osortklen = sortklen;
1139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortklen=ucol_getSortKey(col, test2, u_strlen(test3),  NULL, 0);
1140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortk3=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen+1));
1141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    memset(sortk3,0xFE, sortklen);
1142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_getSortKey(col, test2, u_strlen(test2), sortk3, sortklen+1);
1143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (sortklen == osortklen), "Sortkey length should be the same (abcda, abcda)");
1145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (memcmp(sortk1, sortk2, sortklen) > 0), "Result should be \"Abcda\" > \"abcda\"");
1147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (memcmp(sortk2, sortk1, sortklen) < 0), "Result should be \"abcda\" < \"Abcda\"");
1148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (memcmp(sortk2, sortk3, sortklen) == 0), "Result should be \"abcda\" ==  \"abcda\"");
1149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1150103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius    resultP = ucol_sortKeyToString(col, sortk3, toStringBuffer, toStringLen);
1151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (resultP != 0), "sortKeyToString failed!");
1152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if 1 /* verobse log of sortkeys */
1154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    {
1155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      char junk2[1000];
1156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      char junk3[1000];
1157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      int i;
1158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      strcpy(junk2, "abcda[2] ");
1160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      strcpy(junk3, " abcda[3] ");
1161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      for(i=0;i<sortklen;i++)
1163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {
1164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru          sprintf(junk2+strlen(junk2), "%02X ",(int)( 0xFF & sortk2[i]));
1165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru          sprintf(junk3+strlen(junk3), "%02X ",(int)( 0xFF & sortk3[i]));
1166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
116785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      log_verbose("%s\n", junk2);
1169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      log_verbose("%s\n", junk3);
1170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
1172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(sortk1);
1174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(sortk2);
1175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(sortk3);
1176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Use secondary comparision level testing ...\n");
1178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setStrength(col, UCOL_SECONDARY);
1179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortklen=ucol_getSortKey(col, test1, u_strlen(test1),  NULL, 0);
1180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortk1=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen+1));
1181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_getSortKey(col, test1, u_strlen(test1), sortk1, sortklen+1);
1182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortklen=ucol_getSortKey(col, test2, u_strlen(test2),  NULL, 0);
1183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortk2=(uint8_t*)malloc(sizeof(uint8_t) * (sortklen+1));
1184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_getSortKey(col, test2, u_strlen(test2), sortk2, sortklen+1);
118585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( !(memcmp(sortk1, sortk2, sortklen) > 0), "Result should be \"Abcda\" == \"abcda\"");
1187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( !(memcmp(sortk2, sortk1, sortklen) < 0), "Result should be \"abcda\" == \"Abcda\"");
1188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (memcmp(sortk1, sortk2, sortklen) == 0), "Result should be \"abcda\" ==  \"abcda\"");
1189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("getting sortkey for an empty string\n");
1191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setAttribute(col, UCOL_STRENGTH, UCOL_TERTIARY, &status);
1192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortklen = ucol_getSortKey(col, test1, 0, NULL, 0);
1193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortkEmpty = (uint8_t*)malloc(sizeof(uint8_t) * sortklen+1);
1194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortklen = ucol_getSortKey(col, test1, 0, sortkEmpty, sortklen+1);
1195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(sortklen != 3 || sortkEmpty[0] != 1 || sortkEmpty[0] != 1 || sortkEmpty[2] != 0) {
1196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      log_err("Empty string generated wrong sortkey!\n");
1197ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(sortkEmpty);
1199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("testing passing invalid string\n");
1201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortklen = ucol_getSortKey(col, NULL, 0, NULL, 0);
1202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(sortklen != 0) {
1203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      log_err("Invalid string didn't return sortkey size of 0\n");
1204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
120585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
120685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("testing sortkey ends...\n");
1208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(col);
1209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(test1);
1210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(test2);
1211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(test3);
1212ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(sortk1);
1213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(sortk2);
121485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
1216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestHashCode()
1217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
1218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t *sortk1, *sortk2, *sortk3;
1219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t sortk1len, sortk2len, sortk3len;
1220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator *col;
1221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar *test1, *test2, *test3;
1222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
1223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("testing getHashCode begins...\n");
1224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    col = ucol_open("en_US", &status);
1225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
122685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(status, "ERROR: Default collation creation failed.: %s\n", myErrorName(status));
1227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    test1=(UChar*)malloc(sizeof(UChar) * 6);
1230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    test2=(UChar*)malloc(sizeof(UChar) * 6);
1231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    test3=(UChar*)malloc(sizeof(UChar) * 6);
1232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(test1, "Abcda");
1233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(test2, "abcda");
1234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(test3, "abcda");
1235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Use tertiary comparison level testing ....\n");
1237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortk1len=ucol_getSortKey(col, test1, u_strlen(test1),  NULL, 0);
1238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortk1=(uint8_t*)malloc(sizeof(uint8_t) * (sortk1len+1));
1239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_getSortKey(col, test1, u_strlen(test1), sortk1, sortk1len+1);
1240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortk2len=ucol_getSortKey(col, test2, u_strlen(test2),  NULL, 0);
1241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortk2=(uint8_t*)malloc(sizeof(uint8_t) * (sortk2len+1));
1242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_getSortKey(col, test2, u_strlen(test2), sortk2, sortk2len+1);
1243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortk3len=ucol_getSortKey(col, test2, u_strlen(test3),  NULL, 0);
1244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    sortk3=(uint8_t*)malloc(sizeof(uint8_t) * (sortk3len+1));
1245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_getSortKey(col, test2, u_strlen(test2), sortk3, sortk3len+1);
124685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
124785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("ucol_hashCode() testing ...\n");
124985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
125085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    doAssert( ucol_keyHashCode(sortk1, sortk1len) != ucol_keyHashCode(sortk2, sortk2len), "Hash test1 result incorrect" );
1251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( !(ucol_keyHashCode(sortk1, sortk1len) == ucol_keyHashCode(sortk2, sortk2len)), "Hash test2 result incorrect" );
1252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( ucol_keyHashCode(sortk2, sortk2len) == ucol_keyHashCode(sortk3, sortk3len), "Hash result not equal" );
125385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("hashCode tests end.\n");
1255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(col);
1256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(sortk1);
1257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(sortk2);
1258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(sortk3);
1259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(test1);
1260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(test2);
1261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(test3);
1262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
1265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*
1266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *----------------------------------------------------------------------------
1267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Tests the UCollatorElements API.
126885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho *
126985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho */
1270ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestElemIter()
1271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
1272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t offset;
1273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t order1, order2, order3;
1274ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar *testString1, *testString2;
1275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator *col;
1276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollationElements *iterator1, *iterator2, *iterator3;
1277ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
1278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("testing UCollatorElements begins...\n");
1279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    col = ucol_open("en_US", &status);
1280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setAttribute(col, UCOL_NORMALIZATION_MODE, UCOL_OFF, &status);
1281ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
128285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(status, "ERROR: Default collation creation failed.: %s\n", myErrorName(status));
1283ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1286ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    testString1=(UChar*)malloc(sizeof(UChar) * 150);
1287ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    testString2=(UChar*)malloc(sizeof(UChar) * 150);
1288ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(testString1, "XFILE What subset of all possible test cases has the highest probability of detecting the most errors?");
1289ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(testString2, "Xf_ile What subset of all possible test cases has the lowest probability of detecting the least errors?");
129085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1291ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("Constructors and comparison testing....\n");
129285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1293ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    iterator1 = ucol_openElements(col, testString1, u_strlen(testString1), &status);
1294ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)) {
1295ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("ERROR: Default collationElement iterator creation failed.: %s\n", myErrorName(status));
1296ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_close(col);
1297ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1298ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1299ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    else{ log_verbose("PASS: Default collationElement iterator1 creation passed\n");}
1300ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1301ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    iterator2 = ucol_openElements(col, testString1, u_strlen(testString1), &status);
1302ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)) {
1303ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("ERROR: Default collationElement iterator creation failed.: %s\n", myErrorName(status));
1304ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_close(col);
1305ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1306ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1307ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    else{ log_verbose("PASS: Default collationElement iterator2 creation passed\n");}
1308ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1309ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    iterator3 = ucol_openElements(col, testString2, u_strlen(testString2), &status);
1310ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)) {
1311ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("ERROR: Default collationElement iterator creation failed.: %s\n", myErrorName(status));
1312ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_close(col);
1313ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1314ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1315ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    else{ log_verbose("PASS: Default collationElement iterator3 creation passed\n");}
1316ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1317ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    offset=ucol_getOffset(iterator1);
1318ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setOffset(iterator1, 6, &status);
1319ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
1320ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Error in setOffset for UCollatorElements iterator.: %s\n", myErrorName(status));
1321ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1322ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1323ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(ucol_getOffset(iterator1)==6)
1324ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("setOffset and getOffset working fine\n");
1325ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    else{
1326ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("error in set and get Offset got %d instead of 6\n", ucol_getOffset(iterator1));
1327ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1328ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1329ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setOffset(iterator1, 0, &status);
1330ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    order1 = ucol_next(iterator1, &status);
1331ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
1332ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Somehow ran out of memory stepping through the iterator1.: %s\n", myErrorName(status));
1333ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1334ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1335ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    order2=ucol_getOffset(iterator2);
1336ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert((order1 != order2), "The first iterator advance failed");
1337ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    order2 = ucol_next(iterator2, &status);
1338ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
1339ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Somehow ran out of memory stepping through the iterator2.: %s\n", myErrorName(status));
1340ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1341ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1342ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    order3 = ucol_next(iterator3, &status);
1343ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
1344ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Somehow ran out of memory stepping through the iterator3.: %s\n", myErrorName(status));
1345ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1346ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
134785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1348ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert((order1 == order2), "The second iterator advance failed should be the same as first one");
134985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1350ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerudoAssert( (ucol_primaryOrder(order1) == ucol_primaryOrder(order3)), "The primary orders should be identical");
1351ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerudoAssert( (ucol_secondaryOrder(order1) == ucol_secondaryOrder(order3)), "The secondary orders should be identical");
1352ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerudoAssert( (ucol_tertiaryOrder(order1) == ucol_tertiaryOrder(order3)), "The tertiary orders should be identical");
135385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1354ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    order1=ucol_next(iterator1, &status);
1355ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
1356ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Somehow ran out of memory stepping through the iterator2.: %s\n", myErrorName(status));
1357ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1358ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1359ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    order3=ucol_next(iterator3, &status);
1360ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
1361ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Somehow ran out of memory stepping through the iterator2.: %s\n", myErrorName(status));
1362ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1363ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1364ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerudoAssert( (ucol_primaryOrder(order1) == ucol_primaryOrder(order3)), "The primary orders should be identical");
1365ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerudoAssert( (ucol_tertiaryOrder(order1) != ucol_tertiaryOrder(order3)), "The tertiary orders should be different");
136685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1367ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    order1=ucol_next(iterator1, &status);
1368ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
1369ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Somehow ran out of memory stepping through the iterator2.: %s\n", myErrorName(status));
1370ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1371ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1372ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    order3=ucol_next(iterator3, &status);
1373ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
1374ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Somehow ran out of memory stepping through the iterator2.: %s\n", myErrorName(status));
1375ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1376ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1377ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* this here, my friends, is either pure lunacy or something so obsolete that even it's mother
1378ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * doesn't care about it. Essentialy, this test complains if secondary values for 'I' and '_'
1379ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * are the same. According to the UCA, this is not true. Therefore, remove the test.
1380ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Besides, if primary strengths for two code points are different, it doesn't matter one bit
1381ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * what is the relation between secondary or any other strengths.
1382ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * killed by weiv 06/11/2002.
1383ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
1384ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*
1385ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( ((order1 & UCOL_SECONDARYMASK) != (order3 & UCOL_SECONDARYMASK)), "The secondary orders should be different");
1386ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    */
1387ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doAssert( (order1 != UCOL_NULLORDER), "Unexpected end of iterator reached");
1388ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1389ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(testString1);
1390ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(testString2);
1391ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_closeElements(iterator1);
1392ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_closeElements(iterator2);
1393ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_closeElements(iterator3);
1394ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(col);
139585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1396ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_verbose("testing CollationElementIterator ends...\n");
1397ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
1398ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1399ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestGetLocale() {
1400ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  UErrorCode status = U_ZERO_ERROR;
1401ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  const char *rules = "&a<x<y<z";
1402ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  UChar rlz[256] = {0};
1403ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  uint32_t rlzLen = u_unescape(rules, rlz, 256);
1404ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1405ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  UCollator *coll = NULL;
1406ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  const char *locale = NULL;
1407ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1408ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  int32_t i = 0;
1409ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1410ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  /* Now that the collation tree is separate, actual==valid at all times. [alan] */
1411ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  static const struct {
1412ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char* requestedLocale;
1413ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char* validLocale;
1414ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char* actualLocale;
1415ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  } testStruct[] = {
141627f654740f2a26ad62a5c155af9199af9e69b889claireho    { "sr_RS", "sr_Cyrl_RS", "sr" },
1417ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    { "sh_YU", "sr_Latn_RS", "hr" }, /* this used to be sh, but now sh collation aliases hr */
141827f654740f2a26ad62a5c155af9199af9e69b889claireho    { "en_BE_FOO", "en_BE", "root" },
141927f654740f2a26ad62a5c155af9199af9e69b889claireho    { "de_DE_NONEXISTANT", "de_DE", "de" }
1420ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  };
1421ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1422ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  /* test opening collators for different locales */
1423ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  for(i = 0; i<sizeof(testStruct)/sizeof(testStruct[0]); i++) {
1424ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    status = U_ZERO_ERROR;
1425ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    coll = ucol_open(testStruct[i].requestedLocale, &status);
1426ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)) {
142785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho      log_err_status(status, "Failed to open collator for %s with %s\n", testStruct[i].requestedLocale, u_errorName(status));
1428ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      ucol_close(coll);
1429ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      continue;
1430ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
143185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho   locale = ucol_getLocaleByType(coll, ULOC_REQUESTED_LOCALE, &status);
1432ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(strcmp(locale, testStruct[i].requestedLocale) != 0) {
1433ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      log_err("[Coll %s]: Error in requested locale, expected %s, got %s\n", testStruct[i].requestedLocale, testStruct[i].requestedLocale, locale);
1434ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
143585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    locale = ucol_getLocaleByType(coll, ULOC_VALID_LOCALE, &status);
1436ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(strcmp(locale, testStruct[i].validLocale) != 0) {
1437ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      log_err("[Coll %s]: Error in valid locale, expected %s, got %s\n", testStruct[i].requestedLocale, testStruct[i].validLocale, locale);
1438ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
143985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    locale = ucol_getLocaleByType(coll, ULOC_ACTUAL_LOCALE, &status);
1440ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(strcmp(locale, testStruct[i].actualLocale) != 0) {
1441ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      log_err("[Coll %s]: Error in actual locale, expected %s, got %s\n", testStruct[i].requestedLocale, testStruct[i].actualLocale, locale);
1442ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1443ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(coll);
1444ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  }
1445ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1446ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  /* completely non-existant locale for collator should get a default collator */
1447ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  {
1448ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator *defaultColl = ucol_open(NULL, &status);
1449ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    coll = ucol_open("blahaha", &status);
1450ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_SUCCESS(status)) {
145185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho      if(strcmp(ucol_getLocaleByType(coll, ULOC_REQUESTED_LOCALE, &status), "blahaha")) {
1452ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Nonexisting locale didn't preserve the requested locale\n");
1453ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      }
145485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho      if(strcmp(ucol_getLocaleByType(coll, ULOC_VALID_LOCALE, &status),
145585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        ucol_getLocaleByType(defaultColl, ULOC_VALID_LOCALE, &status))) {
1456ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Valid locale for nonexisting locale locale collator differs "
1457ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru          "from valid locale for default collator\n");
1458ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      }
145985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho      if(strcmp(ucol_getLocaleByType(coll, ULOC_ACTUAL_LOCALE, &status),
146085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        ucol_getLocaleByType(defaultColl, ULOC_ACTUAL_LOCALE, &status))) {
1461ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Actual locale for nonexisting locale locale collator differs "
1462ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru          "from actual locale for default collator\n");
1463ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      }
1464ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      ucol_close(coll);
1465ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      ucol_close(defaultColl);
1466ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
1467ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      log_data_err("Couldn't open collators\n");
1468ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1469ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  }
1470ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
147185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1472ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1473ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  /* collator instantiated from rules should have all three locales NULL */
1474ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  coll = ucol_openRules(rlz, rlzLen, UCOL_DEFAULT, UCOL_DEFAULT, NULL, &status);
147585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho  locale = ucol_getLocaleByType(coll, ULOC_REQUESTED_LOCALE, &status);
1476ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  if(locale != NULL) {
1477ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_err("For collator instantiated from rules, requested locale returned %s instead of NULL\n", locale);
1478ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  }
147985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho  locale = ucol_getLocaleByType(coll, ULOC_VALID_LOCALE, &status);
1480ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  if(locale != NULL) {
1481ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_err("For collator instantiated from rules,  valid locale returned %s instead of NULL\n", locale);
1482ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  }
148385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho  locale = ucol_getLocaleByType(coll, ULOC_ACTUAL_LOCALE, &status);
1484ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  if(locale != NULL) {
1485ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log_err("For collator instantiated from rules, actual locale returned %s instead of NULL\n", locale);
1486ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  }
1487ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  ucol_close(coll);
1488ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1489ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
1490ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1491ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1492ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestGetAll()
1493ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
1494ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t i, count;
1495ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    count=ucol_countAvailable();
1496ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* use something sensible w/o hardcoding the count */
1497ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(count < 0){
1498ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Error in countAvailable(), it returned %d\n", count);
1499ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1500ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    else{
1501ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("PASS: countAvailable() successful, it returned %d\n", count);
1502ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1503ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for(i=0;i<count;i++)
1504ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("%s\n", ucol_getAvailable(i));
1505ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1506ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1507ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
1508ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1509ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1510ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustruct teststruct {
1511ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char *original;
1512ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t key[256];
1513ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} ;
1514ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1515ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic int compare_teststruct(const void *string1, const void *string2) {
1516ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return(strcmp((const char *)((struct teststruct *)string1)->key, (const char *)((struct teststruct *)string2)->key));
1517ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
1518ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1519ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestBounds() {
1520ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
1521ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1522ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator *coll = ucol_open("sh", &status);
1523ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1524ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t sortkey[512], lower[512], upper[512];
1525ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar buffer[512];
1526ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1527ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static const char * const test[] = {
1528ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "John Smith",
1529ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "JOHN SMITH",
1530ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "john SMITH",
1531ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "j\\u00F6hn sm\\u00EFth",
1532ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "J\\u00F6hn Sm\\u00EFth",
1533ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "J\\u00D6HN SM\\u00CFTH",
1534ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "john smithsonian",
1535ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "John Smithsonian",
1536ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
1537ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
153885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    struct teststruct tests[] = {
1539ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKI MIHALJ" } ,
1540ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKI MIHALJ" } ,
1541ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKI PIRO\\u0160KA" },
1542ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABAI ANDRIJA" } ,
1543ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABAI LAJO\\u0160" } ,
1544ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABAI MARIJA" } ,
1545ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABAI STEVAN" } ,
1546ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABAI STEVAN" } ,
1547ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABARKAPA BRANKO" } ,
1548ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABARKAPA MILENKO" } ,
1549ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABARKAPA MIROSLAV" } ,
1550ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABARKAPA SIMO" } ,
1551ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABARKAPA STANKO" } ,
1552ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABARKAPA TAMARA" } ,
1553ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABARKAPA TOMA\\u0160" } ,
1554ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABDARI\\u0106 NIKOLA" } ,
1555ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABDARI\\u0106 ZORICA" } ,
1556ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABI NANDOR" } ,
1557ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABOVI\\u0106 MILAN" } ,
1558ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABRADI AGNEZIJA" } ,
1559ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABRADI IVAN" } ,
1560ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABRADI JELENA" } ,
1561ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABRADI LJUBICA" } ,
1562ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABRADI STEVAN" } ,
1563ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABRDA MARTIN" } ,
1564ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABRILO BOGDAN" } ,
1565ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABRILO BRANISLAV" } ,
1566ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABRILO LAZAR" } ,
1567ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABRILO LJUBICA" } ,
1568ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CABRILO SPASOJA" } ,
1569ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CADE\\u0160 ZDENKA" } ,
1570ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CADESKI BLAGOJE" } ,
1571ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CADOVSKI VLADIMIR" } ,
1572ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAGLJEVI\\u0106 TOMA" } ,
1573ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAGOROVI\\u0106 VLADIMIR" } ,
1574ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAJA VANKA" } ,
1575ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAJI\\u0106 BOGOLJUB" } ,
1576ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAJI\\u0106 BORISLAV" } ,
1577ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAJI\\u0106 RADOSLAV" } ,
1578ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAK\\u0160IRAN MILADIN" } ,
1579ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKAN EUGEN" } ,
1580ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKAN EVGENIJE" } ,
1581ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKAN IVAN" } ,
1582ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKAN JULIJAN" } ,
1583ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKAN MIHAJLO" } ,
1584ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKAN STEVAN" } ,
1585ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKAN VLADIMIR" } ,
1586ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKAN VLADIMIR" } ,
1587ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKAN VLADIMIR" } ,
1588ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKARA ANA" } ,
1589ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKAREVI\\u0106 MOMIR" } ,
1590ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKAREVI\\u0106 NEDELJKO" } ,
1591ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKI \\u0160ANDOR" } ,
1592ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKI AMALIJA" } ,
1593ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKI ANDRA\\u0160" } ,
1594ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKI LADISLAV" } ,
1595ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKI LAJO\\u0160" } ,
1596ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"\\u010CAKI LASLO" } ,
1597ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
1598ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1599ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1600ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1601ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t i = 0, j = 0, k = 0, buffSize = 0, skSize = 0, lowerSize = 0, upperSize = 0;
1602ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t arraySize = sizeof(tests)/sizeof(tests[0]);
1603ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1604ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_SUCCESS(status) && coll) {
1605ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        for(i = 0; i<arraySize; i++) {
1606ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            buffSize = u_unescape(tests[i].original, buffer, 512);
1607ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            skSize = ucol_getSortKey(coll, buffer, buffSize, tests[i].key, 512);
1608ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
1609ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1610ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        qsort(tests, arraySize, sizeof(struct teststruct), compare_teststruct);
1611ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1612ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        for(i = 0; i < arraySize-1; i++) {
1613ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            for(j = i+1; j < arraySize; j++) {
1614ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                lowerSize = ucol_getBound(tests[i].key, -1, UCOL_BOUND_LOWER, 1, lower, 512, &status);
1615ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                upperSize = ucol_getBound(tests[j].key, -1, UCOL_BOUND_UPPER, 1, upper, 512, &status);
1616ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                for(k = i; k <= j; k++) {
1617ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    if(strcmp((const char *)lower, (const char *)tests[k].key) > 0) {
1618ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                        log_err("Problem with lower! j = %i (%s vs %s)\n", k, tests[k].original, tests[i].original);
1619ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    }
1620ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    if(strcmp((const char *)upper, (const char *)tests[k].key) <= 0) {
1621ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                        log_err("Problem with upper! j = %i (%s vs %s)\n", k, tests[k].original, tests[j].original);
1622ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    }
1623ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
1624ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
1625ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
1626ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1627ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1628ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if 0
1629ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        for(i = 0; i < 1000; i++) {
1630ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            lowerRND = (rand()/(RAND_MAX/arraySize));
1631ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            upperRND = lowerRND + (rand()/(RAND_MAX/(arraySize-lowerRND)));
1632ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1633ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            lowerSize = ucol_getBound(tests[lowerRND].key, -1, UCOL_BOUND_LOWER, 1, lower, 512, &status);
1634ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            upperSize = ucol_getBound(tests[upperRND].key, -1, UCOL_BOUND_UPPER_LONG, 1, upper, 512, &status);
1635ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1636ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            for(j = lowerRND; j<=upperRND; j++) {
1637ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                if(strcmp(lower, tests[j].key) > 0) {
1638ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    log_err("Problem with lower! j = %i (%s vs %s)\n", j, tests[j].original, tests[lowerRND].original);
1639ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
1640ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                if(strcmp(upper, tests[j].key) <= 0) {
1641ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    log_err("Problem with upper! j = %i (%s vs %s)\n", j, tests[j].original, tests[upperRND].original);
1642ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
1643ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
1644ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
1645ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
1646ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1647ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1648ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1649ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1650ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1651ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        for(i = 0; i<sizeof(test)/sizeof(test[0]); i++) {
1652ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            buffSize = u_unescape(test[i], buffer, 512);
1653ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            skSize = ucol_getSortKey(coll, buffer, buffSize, sortkey, 512);
1654ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            lowerSize = ucol_getBound(sortkey, skSize, UCOL_BOUND_LOWER, 1, lower, 512, &status);
1655ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            upperSize = ucol_getBound(sortkey, skSize, UCOL_BOUND_UPPER_LONG, 1, upper, 512, &status);
1656ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            for(j = i+1; j<sizeof(test)/sizeof(test[0]); j++) {
1657ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                buffSize = u_unescape(test[j], buffer, 512);
1658ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                skSize = ucol_getSortKey(coll, buffer, buffSize, sortkey, 512);
1659ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                if(strcmp((const char *)lower, (const char *)sortkey) > 0) {
1660ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    log_err("Problem with lower! i = %i, j = %i (%s vs %s)\n", i, j, test[i], test[j]);
1661ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
1662ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                if(strcmp((const char *)upper, (const char *)sortkey) <= 0) {
1663ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    log_err("Problem with upper! i = %i, j = %i (%s vs %s)\n", i, j, test[i], test[j]);
1664ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                }
1665ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
1666ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
1667ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_close(coll);
1668ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
1669ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_data_err("Couldn't open collator\n");
1670ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1671ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1672ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
1673ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1674ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void doOverrunTest(UCollator *coll, const UChar *uString, int32_t strLen) {
1675ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t skLen = 0, skLen2 = 0;
1676ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t sortKey[256];
1677ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t i, j;
1678ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t filler = 0xFF;
1679ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1680ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    skLen = ucol_getSortKey(coll, uString, strLen, NULL, 0);
1681ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1682ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for(i = 0; i < skLen; i++) {
1683ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        memset(sortKey, filler, 256);
1684ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        skLen2 = ucol_getSortKey(coll, uString, strLen, sortKey, i);
1685ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(skLen != skLen2) {
1686ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("For buffer size %i, got different sortkey length. Expected %i got %i\n", i, skLen, skLen2);
1687ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
1688ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        for(j = i; j < 256; j++) {
1689ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if(sortKey[j] != filler) {
1690ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                log_err("Something run over index %i\n", j);
1691ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                break;
1692ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
1693ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
1694ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1695ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
1696ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1697ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* j1865 reports that if a shorter buffer is passed to
169885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho* to get sort key, a buffer overrun happens in some
1699ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* cases. This test tries to check this.
1700ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/
1701ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestSortKeyBufferOverrun(void) {
1702ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
1703ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char* cString = "A very Merry liTTle-lamB..";
1704ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar uString[256];
1705ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t strLen = 0;
1706ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator *coll = ucol_open("root", &status);
1707ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    strLen = u_unescape(cString, uString, 256);
1708ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1709ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_SUCCESS(status)) {
1710ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("testing non ignorable\n");
1711ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_setAttribute(coll, UCOL_ALTERNATE_HANDLING, UCOL_NON_IGNORABLE, &status);
1712ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        doOverrunTest(coll, uString, strLen);
1713ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1714ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("testing shifted\n");
1715ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_setAttribute(coll, UCOL_ALTERNATE_HANDLING, UCOL_SHIFTED, &status);
1716ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        doOverrunTest(coll, uString, strLen);
1717ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1718ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("testing shifted quaternary\n");
1719ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_setAttribute(coll, UCOL_STRENGTH, UCOL_QUATERNARY, &status);
1720ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        doOverrunTest(coll, uString, strLen);
1721ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1722ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("testing with french secondaries\n");
1723ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_setAttribute(coll, UCOL_FRENCH_COLLATION, UCOL_ON, &status);
1724ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_setAttribute(coll, UCOL_STRENGTH, UCOL_TERTIARY, &status);
1725ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_setAttribute(coll, UCOL_ALTERNATE_HANDLING, UCOL_NON_IGNORABLE, &status);
1726ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        doOverrunTest(coll, uString, strLen);
1727ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1728ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1729ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(coll);
1730ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
1731ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1732ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestAttribute()
1733ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
1734ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode error = U_ZERO_ERROR;
1735ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator *coll = ucol_open(NULL, &error);
1736ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1737ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(error)) {
173885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(error, "Creation of default collator failed\n");
1739ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
1740ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1741ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1742ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setAttribute(coll, UCOL_FRENCH_COLLATION, UCOL_OFF, &error);
1743ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getAttribute(coll, UCOL_FRENCH_COLLATION, &error) != UCOL_OFF ||
1744ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        U_FAILURE(error)) {
174585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(error, "Setting and retrieving of the french collation failed\n");
1746ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1747ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1748ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setAttribute(coll, UCOL_FRENCH_COLLATION, UCOL_ON, &error);
1749ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getAttribute(coll, UCOL_FRENCH_COLLATION, &error) != UCOL_ON ||
1750ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        U_FAILURE(error)) {
175185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(error, "Setting and retrieving of the french collation failed\n");
1752ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1753ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1754ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setAttribute(coll, UCOL_ALTERNATE_HANDLING, UCOL_SHIFTED, &error);
1755ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getAttribute(coll, UCOL_ALTERNATE_HANDLING, &error) != UCOL_SHIFTED ||
1756ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        U_FAILURE(error)) {
175785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(error, "Setting and retrieving of the alternate handling failed\n");
1758ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1759ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1760ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setAttribute(coll, UCOL_ALTERNATE_HANDLING, UCOL_NON_IGNORABLE, &error);
1761ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getAttribute(coll, UCOL_ALTERNATE_HANDLING, &error) != UCOL_NON_IGNORABLE ||
1762ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        U_FAILURE(error)) {
176385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(error, "Setting and retrieving of the alternate handling failed\n");
1764ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1765ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1766ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setAttribute(coll, UCOL_CASE_FIRST, UCOL_LOWER_FIRST, &error);
1767ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getAttribute(coll, UCOL_CASE_FIRST, &error) != UCOL_LOWER_FIRST ||
1768ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        U_FAILURE(error)) {
176985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(error, "Setting and retrieving of the case first attribute failed\n");
1770ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1771ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1772ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setAttribute(coll, UCOL_CASE_FIRST, UCOL_UPPER_FIRST, &error);
1773ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getAttribute(coll, UCOL_CASE_FIRST, &error) != UCOL_UPPER_FIRST ||
1774ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        U_FAILURE(error)) {
177585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(error, "Setting and retrieving of the case first attribute failed\n");
1776ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1777ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1778ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setAttribute(coll, UCOL_CASE_LEVEL, UCOL_ON, &error);
1779ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getAttribute(coll, UCOL_CASE_LEVEL, &error) != UCOL_ON ||
1780ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        U_FAILURE(error)) {
178185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(error, "Setting and retrieving of the case level attribute failed\n");
1782ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1783ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1784ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setAttribute(coll, UCOL_CASE_LEVEL, UCOL_OFF, &error);
1785ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getAttribute(coll, UCOL_CASE_LEVEL, &error) != UCOL_OFF ||
1786ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        U_FAILURE(error)) {
178785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(error, "Setting and retrieving of the case level attribute failed\n");
1788ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1789ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1790ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setAttribute(coll, UCOL_NORMALIZATION_MODE, UCOL_ON, &error);
1791ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getAttribute(coll, UCOL_NORMALIZATION_MODE, &error) != UCOL_ON ||
1792ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        U_FAILURE(error)) {
179385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(error, "Setting and retrieving of the normalization on/off attribute failed\n");
1794ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1795ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1796ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setAttribute(coll, UCOL_NORMALIZATION_MODE, UCOL_OFF, &error);
1797ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getAttribute(coll, UCOL_NORMALIZATION_MODE, &error) != UCOL_OFF ||
1798ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        U_FAILURE(error)) {
179985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(error, "Setting and retrieving of the normalization on/off attribute failed\n");
1800ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1801ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1802ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setAttribute(coll, UCOL_STRENGTH, UCOL_PRIMARY, &error);
1803ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getAttribute(coll, UCOL_STRENGTH, &error) != UCOL_PRIMARY ||
1804ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        U_FAILURE(error)) {
180585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(error, "Setting and retrieving of the collation strength failed\n");
1806ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1807ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1808ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setAttribute(coll, UCOL_STRENGTH, UCOL_SECONDARY, &error);
1809ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getAttribute(coll, UCOL_STRENGTH, &error) != UCOL_SECONDARY ||
1810ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        U_FAILURE(error)) {
181185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(error, "Setting and retrieving of the collation strength failed\n");
1812ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1813ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1814ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setAttribute(coll, UCOL_STRENGTH, UCOL_TERTIARY, &error);
1815ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getAttribute(coll, UCOL_STRENGTH, &error) != UCOL_TERTIARY ||
1816ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        U_FAILURE(error)) {
181785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(error, "Setting and retrieving of the collation strength failed\n");
1818ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1819ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1820ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setAttribute(coll, UCOL_STRENGTH, UCOL_QUATERNARY, &error);
1821ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getAttribute(coll, UCOL_STRENGTH, &error) != UCOL_QUATERNARY ||
1822ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        U_FAILURE(error)) {
182385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(error, "Setting and retrieving of the collation strength failed\n");
1824ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1825ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1826ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_setAttribute(coll, UCOL_STRENGTH, UCOL_IDENTICAL, &error);
1827ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getAttribute(coll, UCOL_STRENGTH, &error) != UCOL_IDENTICAL ||
1828ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        U_FAILURE(error)) {
182985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_err_status(error, "Setting and retrieving of the collation strength failed\n");
1830ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1831ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1832ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(coll);
1833ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
1834ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1835ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestGetTailoredSet() {
1836ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  struct {
1837ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char *rules;
1838ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char *tests[20];
1839ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t testsize;
1840ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  } setTest[] = {
1841ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    { "&a < \\u212b", { "\\u212b", "A\\u030a", "\\u00c5" }, 3},
1842ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    { "& S < \\u0161 <<< \\u0160", { "\\u0161", "s\\u030C", "\\u0160", "S\\u030C" }, 4}
1843ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  };
1844ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1845ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  int32_t i = 0, j = 0;
1846ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  UErrorCode status = U_ZERO_ERROR;
1847ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  UParseError pError;
1848ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1849ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  UCollator *coll = NULL;
1850ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  UChar buff[1024];
1851ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  int32_t buffLen = 0;
1852ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  USet *set = NULL;
1853ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1854ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  for(i = 0; i < sizeof(setTest)/sizeof(setTest[0]); i++) {
1855ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    buffLen = u_unescape(setTest[i].rules, buff, 1024);
1856ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    coll = ucol_openRules(buff, buffLen, UCOL_DEFAULT, UCOL_DEFAULT, &pError, &status);
1857ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_SUCCESS(status)) {
1858ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      set = ucol_getTailoredSet(coll, &status);
1859ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      if(uset_size(set) != setTest[i].testsize) {
1860ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Tailored set size different (%d) than expected (%d)\n", uset_size(set), setTest[i].testsize);
1861ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      }
1862ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      for(j = 0; j < setTest[i].testsize; j++) {
1863ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        buffLen = u_unescape(setTest[i].tests[j], buff, 1024);
1864ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(!uset_containsString(set, buff, buffLen)) {
1865ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru          log_err("Tailored set doesn't contain %s... It should\n", setTest[i].tests[j]);
1866ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
1867ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      }
1868ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      uset_close(set);
1869ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
187085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho      log_err_status(status, "Couldn't open collator with rules %s\n", setTest[i].rules);
1871ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
1872ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(coll);
1873ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  }
1874ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
1875ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
1876ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic int tMemCmp(const uint8_t *first, const uint8_t *second) {
1877ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   int32_t firstLen = (int32_t)strlen((const char *)first);
1878ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   int32_t secondLen = (int32_t)strlen((const char *)second);
1879ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   return memcmp(first, second, uprv_min(firstLen, secondLen));
1880ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
1881ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic const char * strengthsC[] = {
1882ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     "UCOL_PRIMARY",
1883ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     "UCOL_SECONDARY",
1884ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     "UCOL_TERTIARY",
1885ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     "UCOL_QUATERNARY",
1886ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     "UCOL_IDENTICAL"
1887ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru};
188885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1889ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestMergeSortKeys(void) {
1890ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   UErrorCode status = U_ZERO_ERROR;
1891ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   UCollator *coll = ucol_open("en", &status);
1892ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   if(U_SUCCESS(status)) {
189385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1894ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     const char* cases[] = {
1895ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       "abc",
1896ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         "abcd",
1897ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         "abcde"
1898ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     };
1899ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     uint32_t casesSize = sizeof(cases)/sizeof(cases[0]);
1900ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     const char* prefix = "foo";
1901ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     const char* suffix = "egg";
1902ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     char outBuff1[256], outBuff2[256];
190385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1904ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     uint8_t **sortkeys = (uint8_t **)malloc(casesSize*sizeof(uint8_t *));
1905ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     uint8_t **mergedPrefixkeys = (uint8_t **)malloc(casesSize*sizeof(uint8_t *));
1906ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     uint8_t **mergedSuffixkeys = (uint8_t **)malloc(casesSize*sizeof(uint8_t *));
1907ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     uint32_t *sortKeysLen = (uint32_t *)malloc(casesSize*sizeof(uint32_t));
1908ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     uint8_t prefixKey[256], suffixKey[256];
1909ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     uint32_t prefixKeyLen = 0, suffixKeyLen = 0, i = 0;
1910ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     UChar buffer[256];
1911ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     uint32_t unescapedLen = 0, l1 = 0, l2 = 0;
1912ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     UColAttributeValue strength;
191385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1914ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     log_verbose("ucol_mergeSortkeys test\n");
1915ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     log_verbose("Testing order of the test cases\n");
1916ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     genericLocaleStarter("en", cases, casesSize);
191785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1918ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     for(i = 0; i<casesSize; i++) {
1919ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       sortkeys[i] = (uint8_t *)malloc(256*sizeof(uint8_t));
1920ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       mergedPrefixkeys[i] = (uint8_t *)malloc(256*sizeof(uint8_t));
1921ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       mergedSuffixkeys[i] = (uint8_t *)malloc(256*sizeof(uint8_t));
1922ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     }
192385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1924ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     unescapedLen = u_unescape(prefix, buffer, 256);
1925ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     prefixKeyLen = ucol_getSortKey(coll, buffer, unescapedLen, prefixKey, 256);
192685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1927ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     unescapedLen = u_unescape(suffix, buffer, 256);
1928ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     suffixKeyLen = ucol_getSortKey(coll, buffer, unescapedLen, suffixKey, 256);
192985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1930ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     log_verbose("Massaging data with prefixes and different strengths\n");
1931ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     strength = UCOL_PRIMARY;
1932ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     while(strength <= UCOL_IDENTICAL) {
1933ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       log_verbose("Strength %s\n", strengthsC[strength<=UCOL_QUATERNARY?strength:4]);
1934ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       ucol_setAttribute(coll, UCOL_STRENGTH, strength, &status);
1935ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       for(i = 0; i<casesSize; i++) {
1936ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         unescapedLen = u_unescape(cases[i], buffer, 256);
1937ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         sortKeysLen[i] = ucol_getSortKey(coll, buffer, unescapedLen, sortkeys[i], 256);
1938ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         ucol_mergeSortkeys(prefixKey, prefixKeyLen, sortkeys[i], sortKeysLen[i], mergedPrefixkeys[i], 256);
1939ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         ucol_mergeSortkeys(sortkeys[i], sortKeysLen[i], suffixKey, suffixKeyLen, mergedSuffixkeys[i], 256);
1940ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         if(i>0) {
1941ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           if(tMemCmp(mergedPrefixkeys[i-1], mergedPrefixkeys[i]) >= 0) {
1942ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru             log_err("Error while comparing prefixed keys @ strength %s:\n", strengthsC[strength<=UCOL_QUATERNARY?strength:4]);
194385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho             log_err("%s\n%s\n",
1944103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius                         ucol_sortKeyToString(coll, mergedPrefixkeys[i-1], outBuff1, l1),
1945103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius                         ucol_sortKeyToString(coll, mergedPrefixkeys[i], outBuff2, l2));
1946ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           }
1947ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           if(tMemCmp(mergedSuffixkeys[i-1], mergedSuffixkeys[i]) >= 0) {
1948ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru             log_err("Error while comparing suffixed keys @ strength %s:\n", strengthsC[strength<=UCOL_QUATERNARY?strength:4]);
194985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho             log_err("%s\n%s\n",
1950103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius                         ucol_sortKeyToString(coll, mergedSuffixkeys[i-1], outBuff1, l1),
1951103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius                         ucol_sortKeyToString(coll, mergedSuffixkeys[i], outBuff2, l2));
1952ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           }
1953ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         }
1954ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       }
1955ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       if(strength == UCOL_QUATERNARY) {
1956ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         strength = UCOL_IDENTICAL;
1957ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       } else {
1958ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         strength++;
1959ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       }
1960ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     }
196185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1962ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     {
1963ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       uint8_t smallBuf[3];
1964ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       uint32_t reqLen = 0;
1965ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       log_verbose("testing buffer overflow\n");
1966ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       reqLen = ucol_mergeSortkeys(prefixKey, prefixKeyLen, suffixKey, suffixKeyLen, smallBuf, 3);
1967ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       if(reqLen != (prefixKeyLen+suffixKeyLen-1)) {
1968ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         log_err("Wrong preflight size for merged sortkey\n");
1969ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       }
1970ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     }
197185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1972ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     {
1973ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       UChar empty = 0;
1974ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       uint8_t emptyKey[20], abcKey[50], mergedKey[100];
1975ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       int32_t emptyKeyLen = 0, abcKeyLen = 0, mergedKeyLen = 0;
197685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1977ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       log_verbose("testing merging with sortkeys generated for empty strings\n");
1978ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       emptyKeyLen = ucol_getSortKey(coll, &empty, 0, emptyKey, 20);
1979ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       unescapedLen = u_unescape(cases[0], buffer, 256);
1980ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       abcKeyLen = ucol_getSortKey(coll, buffer, unescapedLen, abcKey, 50);
1981ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       mergedKeyLen = ucol_mergeSortkeys(emptyKey, emptyKeyLen, abcKey, abcKeyLen, mergedKey, 100);
1982ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       if(mergedKey[0] != 2) {
1983ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         log_err("Empty sortkey didn't produce a level separator\n");
1984ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       }
1985ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       /* try with zeros */
1986ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       mergedKeyLen = ucol_mergeSortkeys(emptyKey, 0, abcKey, abcKeyLen, mergedKey, 100);
1987ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       if(mergedKeyLen != 0 || mergedKey[0] != 0) {
1988ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         log_err("Empty key didn't produce null mergedKey\n");
1989ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       }
1990ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       mergedKeyLen = ucol_mergeSortkeys(abcKey, abcKeyLen, emptyKey, 0, mergedKey, 100);
1991ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       if(mergedKeyLen != 0 || mergedKey[0] != 0) {
1992ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         log_err("Empty key didn't produce null mergedKey\n");
1993ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       }
199485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1995ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     }
199685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
1997ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     for(i = 0; i<casesSize; i++) {
1998ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       free(sortkeys[i]);
1999ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       free(mergedPrefixkeys[i]);
2000ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       free(mergedSuffixkeys[i]);
2001ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     }
2002ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     free(sortkeys);
2003ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     free(mergedPrefixkeys);
2004ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     free(mergedSuffixkeys);
2005ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     free(sortKeysLen);
2006ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     ucol_close(coll);
2007ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     /* need to finish this up */
2008ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   } else {
2009ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     log_data_err("Couldn't open collator");
2010ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   }
2011ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
201285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic void TestShortString(void)
2013ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
2014ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    struct {
2015ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        const char *input;
2016ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        const char *expectedOutput;
2017ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        const char *locale;
2018ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        UErrorCode expectedStatus;
2019ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        int32_t    expectedOffset;
2020ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        uint32_t   expectedIdentifier;
2021ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } testCases[] = {
202250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho        /*
202327f654740f2a26ad62a5c155af9199af9e69b889claireho         * The following expectedOutput contains a collation weight (2700 from UCA 6.0)
202450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho         * which is the primary weight for the T character (U+0041) in the input.
202550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho         * When that character gets a different weight in FractionalUCA.txt,
202650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho         * the expectedOutput needs to be adjusted.
202750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho         * That is, when we upgrade to a new UCA version or change collation
202850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho         * in such a way that the absolute weight for 'A' changes,
202950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho         * we will get a test failure here and need to adjust the test case.
203050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho         */
203127f654740f2a26ad62a5c155af9199af9e69b889claireho        {"LDE_RDE_KPHONEBOOK_T0041_ZLATN","B2700_KPHONEBOOK_LDE", "de@collation=phonebook", U_USING_FALLBACK_WARNING, 0, 0 },
203250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
203327f654740f2a26ad62a5c155af9199af9e69b889claireho        {"LEN_RUS_NO_AS_S4","AS_LROOT_NO_S4", NULL, U_USING_DEFAULT_WARNING, 0, 0 },
2034ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"LDE_VPHONEBOOK_EO_SI","EO_KPHONEBOOK_LDE_SI", "de@collation=phonebook", U_ZERO_ERROR, 0, 0 },
2035ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"LDE_Kphonebook","KPHONEBOOK_LDE", "de@collation=phonebook", U_ZERO_ERROR, 0, 0 },
2036ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"Xqde_DE@collation=phonebookq_S3_EX","KPHONEBOOK_LDE", "de@collation=phonebook", U_USING_FALLBACK_WARNING, 0, 0 },
203727f654740f2a26ad62a5c155af9199af9e69b889claireho        {"LFR_FO", "FO_LROOT", NULL, U_USING_DEFAULT_WARNING, 0, 0 },
2038ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"SO_LX_AS", "", NULL, U_ILLEGAL_ARGUMENT_ERROR, 8, 0 },
2039ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {"S3_ASS_MMM", "", NULL, U_ILLEGAL_ARGUMENT_ERROR, 5, 0 }
2040ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
2041ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
204285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    int32_t i = 0;
204385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    UCollator *coll = NULL, *fromNormalized = NULL;
2044ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UParseError parseError;
2045ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
204685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    char fromShortBuffer[256], normalizedBuffer[256], fromNormalizedBuffer[256];
2047ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char* locale = NULL;
2048ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2049ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2050ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for(i = 0; i < sizeof(testCases)/sizeof(testCases[0]); i++) {
2051ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        status = U_ZERO_ERROR;
2052ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(testCases[i].locale) {
2053ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            locale = testCases[i].locale;
2054ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        } else {
2055ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            locale = NULL;
2056ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
2057ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2058ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        coll = ucol_openFromShortString(testCases[i].input, FALSE, &parseError, &status);
2059ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(status != testCases[i].expectedStatus) {
206085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            log_err_status(status, "Got status '%s' that is different from expected '%s' for '%s'\n",
2061ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                u_errorName(status), u_errorName(testCases[i].expectedStatus), testCases[i].input);
206285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            continue;
2063ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
206485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
2065ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(U_SUCCESS(status)) {
2066ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            ucol_getShortDefinitionString(coll, locale, fromShortBuffer, 256, &status);
2067ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2068ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if(strcmp(fromShortBuffer, testCases[i].expectedOutput)) {
2069ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                log_err("Got short string '%s' from the collator. Expected '%s' for input '%s'\n",
2070ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    fromShortBuffer, testCases[i].expectedOutput, testCases[i].input);
2071ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
2072ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2073ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            ucol_normalizeShortDefinitionString(testCases[i].input, normalizedBuffer, 256, &parseError, &status);
2074ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            fromNormalized = ucol_openFromShortString(normalizedBuffer, FALSE, &parseError, &status);
2075ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            ucol_getShortDefinitionString(fromNormalized, locale, fromNormalizedBuffer, 256, &status);
2076ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2077ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if(strcmp(fromShortBuffer, fromNormalizedBuffer)) {
207885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                log_err("Strings obtained from collators instantiated by short string ('%s') and from normalized string ('%s') differ\n",
2079ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    fromShortBuffer, fromNormalizedBuffer);
2080ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
2081ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2082ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2083ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if(!ucol_equals(coll, fromNormalized)) {
208485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                log_err("Collator from short string ('%s') differs from one obtained through a normalized version ('%s')\n",
2085ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    testCases[i].input, normalizedBuffer);
2086ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
2087ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2088ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            ucol_close(fromNormalized);
2089ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            ucol_close(coll);
2090ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2091ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        } else {
2092ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if(parseError.offset != testCases[i].expectedOffset) {
2093ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                log_err("Got parse error offset %i, but expected %i instead for '%s'\n",
2094ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    parseError.offset, testCases[i].expectedOffset, testCases[i].input);
2095ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
2096ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
2097ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
2098ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2099ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
2100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void
2102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QuerudoSetsTest(const char *locale, const USet *ref, USet *set, const char* inSet, const char* outSet, UErrorCode *status) {
2103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar buffer[512];
2104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t bufLen;
2105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uset_clear(set);
210785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    bufLen = u_unescape(inSet, buffer, 512);
2108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uset_applyPattern(set, buffer, bufLen, 0, status);
2109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(*status)) {
2110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("%s: Failure setting pattern %s\n", locale, u_errorName(*status));
2111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
2112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(!uset_containsAll(ref, set)) {
2114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("%s: Some stuff from %s is not present in the set\n", locale, inSet);
2115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
2116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uset_clear(set);
211885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    bufLen = u_unescape(outSet, buffer, 512);
2119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uset_applyPattern(set, buffer, bufLen, 0, status);
2120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(*status)) {
2121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("%s: Failure setting pattern %s\n", locale, u_errorName(*status));
2122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
2123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(!uset_containsNone(ref, set)) {
2125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("%s: Some stuff from %s is present in the set\n", locale, outSet);
2126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
2127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
2128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
213285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic void
213385bf2e2fbc60a9f938064abc8127d61da7d19882Claire HoTestGetContractionsAndUnsafes(void)
2134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
2135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static struct {
2136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        const char* locale;
2137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        const char* inConts;
2138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        const char* outConts;
2139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        const char* inExp;
2140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        const char* outExp;
2141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        const char* unsafeCodeUnits;
2142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        const char* safeCodeUnits;
2143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } tests[] = {
214485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        { "ru",
214527f654740f2a26ad62a5c155af9199af9e69b889claireho            "[{\\u0418\\u0306}{\\u0438\\u0306}]",
214627f654740f2a26ad62a5c155af9199af9e69b889claireho            "[\\u0439\\u0457]",
2147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            "[\\u00e6]",
214827f654740f2a26ad62a5c155af9199af9e69b889claireho            "[ae]",
214927f654740f2a26ad62a5c155af9199af9e69b889claireho            "[\\u0418\\u0438]",
2150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            "[aAbB\\u0430\\u0410\\u0433\\u0413]"
2151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        },
2152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        { "uk",
215327f654740f2a26ad62a5c155af9199af9e69b889claireho            "[{\\u0406\\u0308}{\\u0456\\u0308}{\\u0418\\u0306}{\\u0438\\u0306}]",
215427f654740f2a26ad62a5c155af9199af9e69b889claireho            "[\\u0407\\u0419\\u0439\\u0457]",
2155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            "[\\u00e6]",
215627f654740f2a26ad62a5c155af9199af9e69b889claireho            "[ae]",
215727f654740f2a26ad62a5c155af9199af9e69b889claireho            "[\\u0406\\u0456\\u0418\\u0438]",
2158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            "[aAbBxv]",
2159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        },
2160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        { "sh",
2161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            "[{C\\u0301}{C\\u030C}{C\\u0341}{DZ\\u030C}{Dz\\u030C}{D\\u017D}{D\\u017E}{lj}{nj}]",
2162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            "[{\\u309d\\u3099}{\\u30fd\\u3099}]",
2163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            "[\\u00e6]",
2164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            "[a]",
2165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            "[nlcdzNLCDZ]",
2166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            "[jabv]"
2167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        },
2168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        { "ja",
2169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-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}]",
2170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru          "[{\\u30FD\\u3099}{\\u309D\\u3099}{\\u3053\\u3099}{\\u30B3\\u3099}{lj}{nj}]",
2171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            "[\\u30FE\\u00e6]",
2172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            "[a]",
2173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            "[\\u3099]",
2174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            "[]"
2175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
2176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
2177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
2182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator *coll = NULL;
2183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t i = 0;
2184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t noConts = 0;
2185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    USet *conts = uset_open(0,0);
2186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    USet *exp = uset_open(0, 0);
2187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    USet *set  = uset_open(0,0);
2188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t setBufferLen = 65536;
2189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar buffer[65536];
2190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t setLen = 0;
2191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for(i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) {
2193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("Testing locale: %s\n", tests[i].locale);
2194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        coll = ucol_open(tests[i].locale, &status);
219585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        if (coll == NULL || U_FAILURE(status)) {
219685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            log_err_status(status, "Unable to open collator for locale %s ==> %s\n", tests[i].locale, u_errorName(status));
219785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            continue;
219885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        }
2199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_getContractionsAndExpansions(coll, conts, exp, TRUE, &status);
2200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        doSetsTest(tests[i].locale, conts, set, tests[i].inConts, tests[i].outConts, &status);
2201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        setLen = uset_toPattern(conts, buffer, setBufferLen, TRUE, &status);
2202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(U_SUCCESS(status)) {
2203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            /*log_verbose("Contractions %i: %s\n", uset_getItemCount(conts), aescstrdup(buffer, setLen));*/
2204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        } else {
2205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("error %s. %i\n", u_errorName(status), setLen);
2206ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            status = U_ZERO_ERROR;
2207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
2208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        doSetsTest(tests[i].locale, exp, set, tests[i].inExp, tests[i].outExp, &status);
2209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        setLen = uset_toPattern(exp, buffer, setBufferLen, TRUE, &status);
2210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(U_SUCCESS(status)) {
2211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            /*log_verbose("Expansions %i: %s\n", uset_getItemCount(exp), aescstrdup(buffer, setLen));*/
2212ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        } else {
2213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("error %s. %i\n", u_errorName(status), setLen);
2214ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            status = U_ZERO_ERROR;
2215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
2216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        noConts = ucol_getUnsafeSet(coll, conts, &status);
2218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        doSetsTest(tests[i].locale, conts, set, tests[i].unsafeCodeUnits, tests[i].safeCodeUnits, &status);
2219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        setLen = uset_toPattern(conts, buffer, setBufferLen, TRUE, &status);
2220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(U_SUCCESS(status)) {
2221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_verbose("Unsafe %i: %s\n", uset_getItemCount(exp), aescstrdup(buffer, setLen));
2222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        } else {
2223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("error %s. %i\n", u_errorName(status), setLen);
2224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            status = U_ZERO_ERROR;
2225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
2226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ucol_close(coll);
2228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
2229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uset_close(conts);
2232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uset_close(exp);
2233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uset_close(set);
2234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
2235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
223685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic void
223785bf2e2fbc60a9f938064abc8127d61da7d19882Claire HoTestOpenBinary(void)
2238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
2239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
2240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*
2241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char rule[] = "&h < d < c < b";
2242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char *wUCA[] = { "a", "h", "d", "c", "b", "i" };
2243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char *noUCA[] = {"d", "c", "b", "a", "h", "i" };
2244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    */
2245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* we have to use Cyrillic letters because latin-1 always gets copied */
2246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char rule[] = "&\\u0452 < \\u0434 < \\u0433 < \\u0432"; /* &dje < d < g < v */
2247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char *wUCA[] = { "\\u0430", "\\u0452", "\\u0434", "\\u0433", "\\u0432", "\\u0435" }; /* a, dje, d, g, v, e */
2248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char *noUCA[] = {"\\u0434", "\\u0433", "\\u0432", "\\u0430", "\\u0435", "\\u0452" }; /* d, g, v, a, e, dje */
2249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar uRules[256];
2251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t uRulesLen = u_unescape(rule, uRules, 256);
2252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator *coll = ucol_openRules(uRules, uRulesLen, UCOL_DEFAULT, UCOL_DEFAULT, NULL, &status);
225485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    UCollator *UCA = NULL;
2255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator *cloneNOUCA = NULL, *cloneWUCA = NULL;
2256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t imageBuffer[32768];
2258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint8_t *image = imageBuffer;
2259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t imageBufferCapacity = 32768;
2260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t imageSize;
2262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
226385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    if((coll==NULL)||(U_FAILURE(status))) {
2264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_data_err("could not load collators or error occured: %s\n",
2265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            u_errorName(status));
2266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
226785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    }
226885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    UCA = ucol_open("root", &status);
226985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    if((UCA==NULL)||(U_FAILURE(status))) {
227085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_data_err("could not load UCA collator or error occured: %s\n",
227185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            u_errorName(status));
227285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        return;
227385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    }
2274ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    imageSize = ucol_cloneBinary(coll, image, imageBufferCapacity, &status);
2275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)) {
2276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        image = (uint8_t *)malloc(imageSize*sizeof(uint8_t));
2277ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        status = U_ZERO_ERROR;
2278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        imageSize = ucol_cloneBinary(coll, imageBuffer, imageSize, &status);
2279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
2280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2281ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2282ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    cloneWUCA = ucol_openBinary(image, imageSize, UCA, &status);
2283ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    cloneNOUCA = ucol_openBinary(image, imageSize, NULL, &status);
2284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    genericOrderingTest(coll, wUCA, sizeof(wUCA)/sizeof(wUCA[0]));
2286ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2287ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    genericOrderingTest(cloneWUCA, wUCA, sizeof(wUCA)/sizeof(wUCA[0]));
2288ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    genericOrderingTest(cloneNOUCA, noUCA, sizeof(noUCA)/sizeof(noUCA[0]));
2289ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2290ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(image != imageBuffer) {
2291ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        free(image);
2292ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
2293ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(coll);
2294ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(cloneNOUCA);
2295ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(cloneWUCA);
2296ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(UCA);
2297ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
2298ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2299ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestDefault(void) {
2300ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Tests for code coverage. */
2301ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
2302ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UCollator *coll = ucol_open("es@collation=pinyin", &status);
230385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    if (coll == NULL || status == U_FILE_ACCESS_ERROR) {
230485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_data_err("Unable to open collator es@collation=pinyin\n");
230585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        return;
230685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    }
2307ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (status != U_USING_DEFAULT_WARNING) {
2308ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* What do you mean that you know about using pinyin collation in Spanish!? This should be in the zh locale. */
2309ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("es@collation=pinyin should return U_USING_DEFAULT_WARNING, but returned %s\n", u_errorName(status));
2310ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
2311ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ucol_close(coll);
2312ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getKeywordValues("funky", &status) != NULL) {
2313ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("Collators should not know about the funky keyword.\n");
2314ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
2315ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (status != U_ILLEGAL_ARGUMENT_ERROR) {
2316ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("funky keyword didn't fail as expected %s\n", u_errorName(status));
2317ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
2318ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ucol_getKeywordValues("collation", &status) != NULL) {
2319ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("ucol_getKeywordValues should not work when given a bad status.\n");
2320ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
2321ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
2322ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
232385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic void TestDefaultKeyword(void) {
232485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    /* Tests for code coverage. */
232585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    UErrorCode status = U_ZERO_ERROR;
232685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    const char *loc = "zh_TW@collation=default";
232785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    UCollator *coll = ucol_open(loc, &status);
232885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    if(U_FAILURE(status)) {
232985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_info("Warning: ucol_open(%s, ...) returned %s, at least it didn't crash.\n", loc, u_errorName(status));
233085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    } else if (status != U_USING_FALLBACK_WARNING) {
233127f654740f2a26ad62a5c155af9199af9e69b889claireho        /* Hmm, skip the following test for CLDR 1.9 data and/or ICU 4.6, no longer seems to apply */
233227f654740f2a26ad62a5c155af9199af9e69b889claireho        #if 0
233385bf2e2fbc60a9f938064abc8127d61da7d19882Claire 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));
233427f654740f2a26ad62a5c155af9199af9e69b889claireho        #endif
233585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    }
233685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    ucol_close(coll);
233785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho}
233885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
233985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Hostatic void TestGetKeywordValuesForLocale(void) {
234027f654740f2a26ad62a5c155af9199af9e69b889claireho#define INCLUDE_UNIHAN_COLLATION 0
234185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho#define PREFERRED_SIZE 16
2342103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius#define MAX_NUMBER_OF_KEYWORDS 9
234385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    const char *PREFERRED[PREFERRED_SIZE][MAX_NUMBER_OF_KEYWORDS+1] = {
234427f654740f2a26ad62a5c155af9199af9e69b889claireho            { "und",            "standard", "ducet", "search", NULL, NULL, NULL, NULL, NULL },
234527f654740f2a26ad62a5c155af9199af9e69b889claireho            { "en_US",          "standard", "ducet", "search", NULL, NULL, NULL, NULL, NULL },
234627f654740f2a26ad62a5c155af9199af9e69b889claireho            { "en_029",         "standard", "ducet", "search", NULL, NULL, NULL, NULL, NULL },
234727f654740f2a26ad62a5c155af9199af9e69b889claireho            { "de_DE",          "standard", "phonebook", "search", "ducet", NULL, NULL, NULL, NULL },
234827f654740f2a26ad62a5c155af9199af9e69b889claireho            { "de_Latn_DE",     "standard", "phonebook", "search", "ducet", NULL, NULL, NULL, NULL },
234927f654740f2a26ad62a5c155af9199af9e69b889claireho#if INCLUDE_UNIHAN_COLLATION
235054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius            { "zh",             "pinyin", "big5han", "gb2312han", "standard", "stroke", "zhuyin", "unihan", "ducet", "search" },
235154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius            { "zh_Hans",        "pinyin", "big5han", "gb2312han", "standard", "stroke", "zhuyin", "unihan", "ducet", "search" },
235254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius            { "zh_CN",          "pinyin", "big5han", "gb2312han", "standard", "stroke", "zhuyin", "unihan", "ducet", "search" },
235354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius            { "zh_Hant",        "stroke", "big5han", "gb2312han", "pinyin", "standard", "zhuyin", "unihan", "ducet", "search" },
235454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius            { "zh_TW",          "stroke", "big5han", "gb2312han", "pinyin", "standard", "zhuyin", "unihan", "ducet", "search" },
235554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius            { "zh__PINYIN",     "pinyin", "big5han", "gb2312han", "standard", "stroke", "zhuyin", "unihan", "ducet", "search" },
235627f654740f2a26ad62a5c155af9199af9e69b889claireho#else
235754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius            { "zh",             "pinyin", "big5han", "gb2312han", "standard", "stroke", "zhuyin", "ducet", "search", NULL },
235854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius            { "zh_Hans",        "pinyin", "big5han", "gb2312han", "standard", "stroke", "zhuyin", "ducet", "search", NULL },
235954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius            { "zh_CN",          "pinyin", "big5han", "gb2312han", "standard", "stroke", "zhuyin", "ducet", "search", NULL },
236054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius            { "zh_Hant",        "stroke", "big5han", "gb2312han", "pinyin", "standard", "zhuyin", "ducet", "search", NULL },
236154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius            { "zh_TW",          "stroke", "big5han", "gb2312han", "pinyin", "standard", "zhuyin", "ducet", "search", NULL },
236254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius            { "zh__PINYIN",     "pinyin", "big5han", "gb2312han", "standard", "stroke", "zhuyin", "ducet", "search", NULL },
236327f654740f2a26ad62a5c155af9199af9e69b889claireho#endif
236427f654740f2a26ad62a5c155af9199af9e69b889claireho            { "es_ES",          "standard", "search", "traditional", "ducet", NULL, NULL, NULL, NULL },
236527f654740f2a26ad62a5c155af9199af9e69b889claireho            { "es__TRADITIONAL","traditional", "search", "standard", "ducet", NULL, NULL, NULL, NULL },
236627f654740f2a26ad62a5c155af9199af9e69b889claireho            { "und@collation=phonebook",    "standard", "ducet", "search", NULL, NULL, NULL, NULL, NULL },
236727f654740f2a26ad62a5c155af9199af9e69b889claireho            { "de_DE@collation=big5han",    "standard", "phonebook", "search", "ducet", NULL, NULL, NULL, NULL },
236827f654740f2a26ad62a5c155af9199af9e69b889claireho            { "zzz@collation=xxx",          "standard", "ducet", "search", NULL, NULL, NULL, NULL, NULL }
236985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    };
237027f654740f2a26ad62a5c155af9199af9e69b889claireho#if INCLUDE_UNIHAN_COLLATION
237154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius    const int32_t expectedLength[PREFERRED_SIZE] = { 3, 3, 3, 4, 4, 9, 9, 9, 9, 9, 9, 4, 4, 3, 4, 3 };
237227f654740f2a26ad62a5c155af9199af9e69b889claireho#else
237354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius    const int32_t expectedLength[PREFERRED_SIZE] = { 3, 3, 3, 4, 4, 8, 8, 8, 8, 8, 8, 4, 4, 3, 4, 3 };
237427f654740f2a26ad62a5c155af9199af9e69b889claireho#endif
237585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
237685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    UErrorCode status = U_ZERO_ERROR;
237785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    UEnumeration *keywordValues = NULL;
237885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    int32_t i, n, size, valueLength;
237985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    const char *locale = NULL, *value = NULL;
238085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    UBool errorOccurred = FALSE;
238185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
238285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    for (i = 0; i < PREFERRED_SIZE; i++) {
238385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        locale = PREFERRED[i][0];
238485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        value = NULL;
238585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        valueLength = 0;
238685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        size = 0;
238785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
238885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        keywordValues = ucol_getKeywordValuesForLocale("collation", locale, TRUE, &status);
238985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        if (keywordValues == NULL || U_FAILURE(status)) {
239085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            log_err_status(status, "Error getting keyword values: %s\n", u_errorName(status));
239185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            break;
239285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        }
239385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        size = uenum_count(keywordValues, &status);
239485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
239585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        if (size == expectedLength[i]) {
239685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            for (n = 0; n < expectedLength[i]; n++) {
239785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                if ((value = uenum_next(keywordValues, &valueLength, &status)) != NULL && U_SUCCESS(status)) {
239885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                    if (uprv_strcmp(value, PREFERRED[i][n+1]) != 0) {
239985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                        log_err("Keyword values differ: Got [%s] Expected [%s] for locale: %s\n", value, PREFERRED[i][n+1], locale);
240085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                        errorOccurred = TRUE;
240185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                        break;
240285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                    }
240385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
240485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                } else {
240585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                    log_err("While getting keyword value from locale: %s got this error: %s\n", locale, u_errorName(status));
240685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                    errorOccurred = TRUE;
240785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                    break;
240885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                }
240985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            }
241085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            if (errorOccurred) {
241185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                break;
241285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            }
241385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        } else {
241485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            log_err("Number of keywords (%d) does not match expected size (%d) for locale: %s\n", size, expectedLength[i], locale);
241585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            break;
241685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        }
241785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        uenum_close(keywordValues);
241885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        keywordValues = NULL;
241985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    }
242085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    if (keywordValues != NULL) {
242185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        uenum_close(keywordValues);
242285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    }
242385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho}
242485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
242585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
2426ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif /* #if !UCONFIG_NO_COLLATION */
2427