]>
Commit | Line | Data |
---|---|---|
b75a7d8f A |
1 | /******************************************************************** |
2 | * COPYRIGHT: | |
3 | * Copyright (c) 1997-2001, 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 | addCurrencyTest(root); | |
35 | addNormTest(root); | |
36 | addDanishCollTest(root); | |
37 | addGermanCollTest(root); | |
38 | addSpanishCollTest(root); | |
39 | addFrenchCollTest(root); | |
40 | addKannaCollTest(root); | |
41 | addTurkishCollTest(root); | |
42 | addEnglishCollTest(root); | |
43 | addFinnishCollTest(root); | |
44 | ||
45 | /* WEIVTODO: return tests here */ | |
46 | addRuleBasedCollTest(root); | |
47 | addCollIterTest(root); | |
48 | addAllCollTest(root); | |
49 | addMiscCollTest(root); | |
50 | ||
51 | addSearchTest(root); | |
52 | } | |
53 | ||
54 | ||
55 | ||
56 | /*Internal functions used*/ | |
57 | static char* dumpSk(uint8_t *sourceKey, char *sk) { | |
58 | uint32_t kLen = (uint32_t)strlen((const char *)sourceKey); | |
59 | uint32_t i = 0; | |
60 | ||
61 | *sk = 0; | |
62 | ||
63 | for(i = 0; i<kLen; i++) { | |
64 | sprintf(sk+2*i, "%02X", sourceKey[i]); | |
65 | } | |
66 | return sk; | |
67 | } | |
68 | ||
69 | void reportCResult( const UChar source[], const UChar target[], | |
70 | uint8_t *sourceKey, uint8_t *targetKey, | |
71 | UCollationResult compareResult, | |
72 | UCollationResult keyResult, | |
73 | UCollationResult incResult, | |
74 | UCollationResult expectedResult ) | |
75 | { | |
76 | UChar *sResult, *sExpect; | |
77 | sResult=(UChar*)malloc(sizeof(UChar) * 10); | |
78 | sExpect=(UChar*)malloc(sizeof(UChar) * 10); | |
79 | if (expectedResult < -1 || expectedResult > 1) | |
80 | { | |
81 | log_err("***** invalid call to reportCResult ****\n"); | |
82 | return; | |
83 | } | |
84 | ||
85 | if (compareResult != expectedResult) | |
86 | { | |
87 | ||
88 | appendCompareResult(compareResult, sResult); | |
89 | appendCompareResult(expectedResult, sExpect); | |
90 | log_err("Compare(%s , %s) returned: %s expected: %s\n", aescstrdup(source,-1), aescstrdup(target,-1), | |
91 | austrdup(sResult), austrdup(sExpect) ); | |
92 | } | |
93 | ||
94 | if (incResult != expectedResult) | |
95 | { | |
96 | ||
97 | appendCompareResult(incResult, sResult); | |
98 | appendCompareResult(expectedResult, sExpect); | |
99 | log_err("incCompare(%s , %s) returned: %s expected: %s\n", aescstrdup(source,-1), aescstrdup(target,-1), | |
100 | austrdup(sResult), austrdup(sExpect) ); | |
101 | } | |
102 | ||
103 | if (keyResult != expectedResult) | |
104 | { | |
105 | ||
106 | appendCompareResult(keyResult, sResult); | |
107 | appendCompareResult(expectedResult, sExpect); | |
108 | ||
109 | log_err("KeyCompare(%s , %s) returned: %s expected: %s\n", aescstrdup(source,-1), aescstrdup(target,-1), | |
110 | austrdup(sResult), austrdup(sExpect) ); | |
111 | ||
112 | ||
113 | } | |
114 | ||
115 | if (keyResult != compareResult) | |
116 | { | |
117 | ||
118 | appendCompareResult(keyResult, sResult); | |
119 | appendCompareResult(compareResult, sExpect); | |
120 | ||
121 | log_err("difference between sortkey and compare result for (%s , %s) Keys: %s compare %s\n", aescstrdup(source,-1), aescstrdup(target,-1), | |
122 | austrdup(sResult), austrdup(sExpect) ); | |
123 | ||
124 | ||
125 | } | |
126 | ||
127 | if(keyResult != expectedResult || keyResult != compareResult) | |
128 | { | |
129 | char sk[10000]; | |
130 | log_verbose("SortKey1: %s\n", dumpSk(sourceKey, sk)); | |
131 | log_verbose("SortKey2: %s\n", dumpSk(targetKey, sk)); | |
132 | } | |
133 | ||
134 | free(sExpect); | |
135 | free(sResult); | |
136 | } | |
137 | ||
138 | UChar* appendCompareResult(UCollationResult result, UChar* target) | |
139 | { | |
140 | if (result == UCOL_LESS) | |
141 | { | |
142 | u_uastrcpy(target, "LESS"); | |
143 | } | |
144 | else if (result == UCOL_EQUAL) | |
145 | { | |
146 | u_uastrcpy(target, "EQUAL"); | |
147 | } | |
148 | else if (result == UCOL_GREATER) | |
149 | { | |
150 | u_uastrcpy(target, "GREATER"); | |
151 | } | |
152 | else | |
153 | { | |
154 | u_uastrcpy(target, "huh???"); | |
155 | } | |
156 | ||
157 | return target; | |
158 | } | |
159 | ||
160 | /* Support for testing incremental strcoll */ | |
161 | typedef struct { | |
162 | const UChar *start; | |
163 | const UChar *end; | |
164 | } testContext; | |
165 | ||
166 | UChar U_CALLCONV testInc(void *context) { | |
167 | testContext *s = (testContext *)context; | |
168 | if(s->start == s->end) { | |
169 | return 0xFFFF; | |
170 | } else { | |
171 | return *(s->start++); | |
172 | } | |
173 | } | |
174 | ||
175 | #endif /* #if !UCONFIG_NO_COLLATION */ |