]> git.saurik.com Git - apple/icu.git/blob - icuSources/test/cintltst/ccolltst.c
ICU-8.11.tar.gz
[apple/icu.git] / icuSources / test / cintltst / ccolltst.c
1 /********************************************************************
2 * COPYRIGHT:
3 * Copyright (c) 1997-2005, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
6 /********************************************************************************
7 *
8 * File CCOLLTST.C
9 *
10 * Modification History:
11 * Name Description
12 * Madhu Katragadda Creation
13 *********************************************************************************
14 */
15 #include <stdio.h>
16
17 #include "unicode/utypes.h"
18
19 #if !UCONFIG_NO_COLLATION
20
21 #include "cintltst.h"
22 #include "ccolltst.h"
23 #include "unicode/ucol.h"
24 #include "unicode/ustring.h"
25 #include "cmemory.h"
26
27 UChar U_CALLCONV testInc(void *context);
28
29 void addCollTest(TestNode** root);
30
31 void addCollTest(TestNode** root)
32 {
33 addCollAPITest(root);
34 addCurrencyCollTest(root);
35 addNormTest(root);
36 addGermanCollTest(root);
37 addSpanishCollTest(root);
38 addFrenchCollTest(root);
39 addKannaCollTest(root);
40 addTurkishCollTest(root);
41 addEnglishCollTest(root);
42 addFinnishCollTest(root);
43
44 /* WEIVTODO: return tests here */
45 addRuleBasedCollTest(root);
46 addCollIterTest(root);
47 addAllCollTest(root);
48 addMiscCollTest(root);
49
50 addSearchTest(root);
51 }
52
53
54
55 /*Internal functions used*/
56 static char* dumpSk(uint8_t *sourceKey, char *sk) {
57 uint32_t kLen = (uint32_t)strlen((const char *)sourceKey);
58 uint32_t i = 0;
59
60 *sk = 0;
61
62 for(i = 0; i<kLen; i++) {
63 sprintf(sk+2*i, "%02X", sourceKey[i]);
64 }
65 return sk;
66 }
67
68 void reportCResult( const UChar source[], const UChar target[],
69 uint8_t *sourceKey, uint8_t *targetKey,
70 UCollationResult compareResult,
71 UCollationResult keyResult,
72 UCollationResult incResult,
73 UCollationResult expectedResult )
74 {
75 UChar *sResult, *sExpect;
76 sResult=(UChar*)malloc(sizeof(UChar) * 10);
77 sExpect=(UChar*)malloc(sizeof(UChar) * 10);
78 if (expectedResult < -1 || expectedResult > 1)
79 {
80 log_err("***** invalid call to reportCResult ****\n");
81 return;
82 }
83
84 if (compareResult != expectedResult)
85 {
86
87 appendCompareResult(compareResult, sResult);
88 appendCompareResult(expectedResult, sExpect);
89 log_err("Compare(%s , %s) returned: %s expected: %s\n", aescstrdup(source,-1), aescstrdup(target,-1),
90 austrdup(sResult), austrdup(sExpect) );
91 }
92
93 if (incResult != expectedResult)
94 {
95
96 appendCompareResult(incResult, sResult);
97 appendCompareResult(expectedResult, sExpect);
98 log_err("incCompare(%s , %s) returned: %s expected: %s\n", aescstrdup(source,-1), aescstrdup(target,-1),
99 austrdup(sResult), austrdup(sExpect) );
100 }
101
102 if (keyResult != expectedResult)
103 {
104
105 appendCompareResult(keyResult, sResult);
106 appendCompareResult(expectedResult, sExpect);
107
108 log_err("KeyCompare(%s , %s) returned: %s expected: %s\n", aescstrdup(source,-1), aescstrdup(target,-1),
109 austrdup(sResult), austrdup(sExpect) );
110
111
112 }
113
114 if (keyResult != compareResult)
115 {
116
117 appendCompareResult(keyResult, sResult);
118 appendCompareResult(compareResult, sExpect);
119
120 log_err("difference between sortkey and compare result for (%s , %s) Keys: %s compare %s\n", aescstrdup(source,-1), aescstrdup(target,-1),
121 austrdup(sResult), austrdup(sExpect) );
122
123
124 }
125
126 if(keyResult != expectedResult || keyResult != compareResult)
127 {
128 char sk[10000];
129 log_verbose("SortKey1: %s\n", dumpSk(sourceKey, sk));
130 log_verbose("SortKey2: %s\n", dumpSk(targetKey, sk));
131 }
132
133 free(sExpect);
134 free(sResult);
135 }
136
137 UChar* appendCompareResult(UCollationResult result, UChar* target)
138 {
139 if (result == UCOL_LESS)
140 {
141 u_uastrcpy(target, "LESS");
142 }
143 else if (result == UCOL_EQUAL)
144 {
145 u_uastrcpy(target, "EQUAL");
146 }
147 else if (result == UCOL_GREATER)
148 {
149 u_uastrcpy(target, "GREATER");
150 }
151 else
152 {
153 u_uastrcpy(target, "huh???");
154 }
155
156 return target;
157 }
158
159 /* Support for testing incremental strcoll */
160 typedef struct {
161 const UChar *start;
162 const UChar *end;
163 } testContext;
164
165 UChar U_CALLCONV testInc(void *context) {
166 testContext *s = (testContext *)context;
167 if(s->start == s->end) {
168 return 0xFFFF;
169 } else {
170 return *(s->start++);
171 }
172 }
173
174 #endif /* #if !UCONFIG_NO_COLLATION */