]>
Commit | Line | Data |
---|---|---|
f3c0d7a5 A |
1 | // © 2016 and later: Unicode, Inc. and others. |
2 | // License & terms of use: http://www.unicode.org/copyright.html | |
b75a7d8f A |
3 | /******************************************************************** |
4 | * COPYRIGHT: | |
51004dcb | 5 | * Copyright (c) 1997-2012, International Business Machines Corporation and |
b75a7d8f A |
6 | * others. All Rights Reserved. |
7 | ********************************************************************/ | |
8 | /******************************************************************************** | |
9 | * | |
10 | * File CCOLLTST.C | |
11 | * | |
12 | * Modification History: | |
13 | * Name Description | |
14 | * Madhu Katragadda Creation | |
15 | ********************************************************************************* | |
16 | */ | |
17 | #include <stdio.h> | |
18 | ||
19 | #include "unicode/utypes.h" | |
20 | ||
21 | #if !UCONFIG_NO_COLLATION | |
22 | ||
23 | #include "cintltst.h" | |
24 | #include "ccolltst.h" | |
25 | #include "unicode/ucol.h" | |
26 | #include "unicode/ustring.h" | |
27 | #include "cmemory.h" | |
28 | ||
b75a7d8f A |
29 | void addCollTest(TestNode** root); |
30 | ||
31 | void addCollTest(TestNode** root) | |
32 | { | |
33 | addCollAPITest(root); | |
73c04bcf | 34 | addCurrencyCollTest(root); |
51004dcb | 35 | #if !UCONFIG_NO_NORMALIZATION |
b75a7d8f | 36 | addNormTest(root); |
51004dcb | 37 | #endif |
b75a7d8f A |
38 | addGermanCollTest(root); |
39 | addSpanishCollTest(root); | |
40 | addFrenchCollTest(root); | |
41 | addKannaCollTest(root); | |
42 | addTurkishCollTest(root); | |
43 | addEnglishCollTest(root); | |
44 | addFinnishCollTest(root); | |
45 | ||
46 | /* WEIVTODO: return tests here */ | |
47 | addRuleBasedCollTest(root); | |
48 | addCollIterTest(root); | |
49 | addAllCollTest(root); | |
50 | addMiscCollTest(root); | |
729e4ab9 | 51 | #if !UCONFIG_NO_BREAK_ITERATION && !UCONFIG_NO_FILE_IO |
b75a7d8f | 52 | addSearchTest(root); |
46f4442e | 53 | #endif |
b75a7d8f A |
54 | } |
55 | ||
56 | ||
57 | ||
58 | /*Internal functions used*/ | |
59 | static char* dumpSk(uint8_t *sourceKey, char *sk) { | |
60 | uint32_t kLen = (uint32_t)strlen((const char *)sourceKey); | |
61 | uint32_t i = 0; | |
62 | ||
63 | *sk = 0; | |
64 | ||
65 | for(i = 0; i<kLen; i++) { | |
66 | sprintf(sk+2*i, "%02X", sourceKey[i]); | |
67 | } | |
68 | return sk; | |
69 | } | |
70 | ||
46f4442e A |
71 | static const char *getCompareResult(UCollationResult result) |
72 | { | |
73 | if (result == UCOL_LESS) | |
74 | { | |
75 | return "LESS"; | |
76 | } | |
77 | else if (result == UCOL_EQUAL) | |
78 | { | |
79 | return "EQUAL"; | |
80 | } | |
81 | else if (result == UCOL_GREATER) | |
82 | { | |
83 | return "GREATER"; | |
84 | } | |
85 | return "invalid UCollationResult?"; | |
86 | } | |
87 | ||
b75a7d8f A |
88 | void reportCResult( const UChar source[], const UChar target[], |
89 | uint8_t *sourceKey, uint8_t *targetKey, | |
90 | UCollationResult compareResult, | |
91 | UCollationResult keyResult, | |
92 | UCollationResult incResult, | |
93 | UCollationResult expectedResult ) | |
94 | { | |
b75a7d8f A |
95 | if (expectedResult < -1 || expectedResult > 1) |
96 | { | |
97 | log_err("***** invalid call to reportCResult ****\n"); | |
98 | return; | |
99 | } | |
100 | ||
101 | if (compareResult != expectedResult) | |
102 | { | |
b75a7d8f | 103 | log_err("Compare(%s , %s) returned: %s expected: %s\n", aescstrdup(source,-1), aescstrdup(target,-1), |
46f4442e | 104 | getCompareResult(compareResult), getCompareResult(expectedResult) ); |
b75a7d8f A |
105 | } |
106 | ||
107 | if (incResult != expectedResult) | |
108 | { | |
b75a7d8f | 109 | log_err("incCompare(%s , %s) returned: %s expected: %s\n", aescstrdup(source,-1), aescstrdup(target,-1), |
46f4442e | 110 | getCompareResult(incResult), getCompareResult(expectedResult) ); |
b75a7d8f A |
111 | } |
112 | ||
113 | if (keyResult != expectedResult) | |
114 | { | |
b75a7d8f | 115 | log_err("KeyCompare(%s , %s) returned: %s expected: %s\n", aescstrdup(source,-1), aescstrdup(target,-1), |
46f4442e | 116 | getCompareResult(keyResult), getCompareResult(expectedResult) ); |
b75a7d8f A |
117 | } |
118 | ||
119 | if (keyResult != compareResult) | |
120 | { | |
b75a7d8f | 121 | log_err("difference between sortkey and compare result for (%s , %s) Keys: %s compare %s\n", aescstrdup(source,-1), aescstrdup(target,-1), |
46f4442e | 122 | getCompareResult(keyResult), getCompareResult(compareResult)); |
b75a7d8f A |
123 | } |
124 | ||
125 | if(keyResult != expectedResult || keyResult != compareResult) | |
126 | { | |
46f4442e A |
127 | char sk[10000]; |
128 | log_verbose("SortKey1: %s\n", dumpSk(sourceKey, sk)); | |
129 | log_verbose("SortKey2: %s\n", dumpSk(targetKey, sk)); | |
b75a7d8f A |
130 | } |
131 | } | |
132 | ||
133 | #endif /* #if !UCONFIG_NO_COLLATION */ |