]>
Commit | Line | Data |
---|---|---|
b75a7d8f A |
1 | /******************************************************************** |
2 | * COPYRIGHT: | |
51004dcb | 3 | * Copyright (c) 1997-2012, International Business Machines Corporation and |
b75a7d8f A |
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 | ||
b75a7d8f A |
27 | void addCollTest(TestNode** root); |
28 | ||
29 | void addCollTest(TestNode** root) | |
30 | { | |
31 | addCollAPITest(root); | |
73c04bcf | 32 | addCurrencyCollTest(root); |
51004dcb | 33 | #if !UCONFIG_NO_NORMALIZATION |
b75a7d8f | 34 | addNormTest(root); |
51004dcb | 35 | #endif |
b75a7d8f A |
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); | |
729e4ab9 | 49 | #if !UCONFIG_NO_BREAK_ITERATION && !UCONFIG_NO_FILE_IO |
b75a7d8f | 50 | addSearchTest(root); |
46f4442e | 51 | #endif |
b75a7d8f A |
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 | ||
46f4442e A |
69 | static const char *getCompareResult(UCollationResult result) |
70 | { | |
71 | if (result == UCOL_LESS) | |
72 | { | |
73 | return "LESS"; | |
74 | } | |
75 | else if (result == UCOL_EQUAL) | |
76 | { | |
77 | return "EQUAL"; | |
78 | } | |
79 | else if (result == UCOL_GREATER) | |
80 | { | |
81 | return "GREATER"; | |
82 | } | |
83 | return "invalid UCollationResult?"; | |
84 | } | |
85 | ||
b75a7d8f A |
86 | void reportCResult( const UChar source[], const UChar target[], |
87 | uint8_t *sourceKey, uint8_t *targetKey, | |
88 | UCollationResult compareResult, | |
89 | UCollationResult keyResult, | |
90 | UCollationResult incResult, | |
91 | UCollationResult expectedResult ) | |
92 | { | |
b75a7d8f A |
93 | if (expectedResult < -1 || expectedResult > 1) |
94 | { | |
95 | log_err("***** invalid call to reportCResult ****\n"); | |
96 | return; | |
97 | } | |
98 | ||
99 | if (compareResult != expectedResult) | |
100 | { | |
b75a7d8f | 101 | log_err("Compare(%s , %s) returned: %s expected: %s\n", aescstrdup(source,-1), aescstrdup(target,-1), |
46f4442e | 102 | getCompareResult(compareResult), getCompareResult(expectedResult) ); |
b75a7d8f A |
103 | } |
104 | ||
105 | if (incResult != expectedResult) | |
106 | { | |
b75a7d8f | 107 | log_err("incCompare(%s , %s) returned: %s expected: %s\n", aescstrdup(source,-1), aescstrdup(target,-1), |
46f4442e | 108 | getCompareResult(incResult), getCompareResult(expectedResult) ); |
b75a7d8f A |
109 | } |
110 | ||
111 | if (keyResult != expectedResult) | |
112 | { | |
b75a7d8f | 113 | log_err("KeyCompare(%s , %s) returned: %s expected: %s\n", aescstrdup(source,-1), aescstrdup(target,-1), |
46f4442e | 114 | getCompareResult(keyResult), getCompareResult(expectedResult) ); |
b75a7d8f A |
115 | } |
116 | ||
117 | if (keyResult != compareResult) | |
118 | { | |
b75a7d8f | 119 | log_err("difference between sortkey and compare result for (%s , %s) Keys: %s compare %s\n", aescstrdup(source,-1), aescstrdup(target,-1), |
46f4442e | 120 | getCompareResult(keyResult), getCompareResult(compareResult)); |
b75a7d8f A |
121 | } |
122 | ||
123 | if(keyResult != expectedResult || keyResult != compareResult) | |
124 | { | |
46f4442e A |
125 | char sk[10000]; |
126 | log_verbose("SortKey1: %s\n", dumpSk(sourceKey, sk)); | |
127 | log_verbose("SortKey2: %s\n", dumpSk(targetKey, sk)); | |
b75a7d8f A |
128 | } |
129 | } | |
130 | ||
131 | #endif /* #if !UCONFIG_NO_COLLATION */ |