1 /********************************************************************
2  * COPYRIGHT:
3  * Copyright (c) 1997-2012, 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 void addCollTest(TestNode** root);
28 
addCollTest(TestNode ** root)29 void addCollTest(TestNode** root)
30 {
31     addCollAPITest(root);
32     addCurrencyCollTest(root);
33 #if !UCONFIG_NO_NORMALIZATION
34     addNormTest(root);
35 #endif
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 #if !UCONFIG_NO_BREAK_ITERATION && !UCONFIG_NO_FILE_IO
50     addSearchTest(root);
51 #endif
52 }
53 
54 
55 
56 /*Internal functions used*/
dumpSk(uint8_t * sourceKey,char * sk)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 
getCompareResult(UCollationResult result)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 
reportCResult(const UChar source[],const UChar target[],uint8_t * sourceKey,uint8_t * targetKey,UCollationResult compareResult,UCollationResult keyResult,UCollationResult incResult,UCollationResult expectedResult)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 {
93     if (expectedResult < -1 || expectedResult > 1)
94     {
95         log_err("***** invalid call to reportCResult ****\n");
96         return;
97     }
98 
99     if (compareResult != expectedResult)
100     {
101         log_err("Compare(%s , %s) returned: %s expected: %s\n", aescstrdup(source,-1), aescstrdup(target,-1),
102             getCompareResult(compareResult), getCompareResult(expectedResult) );
103     }
104 
105     if (incResult != expectedResult)
106     {
107         log_err("incCompare(%s , %s) returned: %s expected: %s\n", aescstrdup(source,-1), aescstrdup(target,-1),
108             getCompareResult(incResult), getCompareResult(expectedResult) );
109     }
110 
111     if (keyResult != expectedResult)
112     {
113         log_err("KeyCompare(%s , %s) returned: %s expected: %s\n", aescstrdup(source,-1), aescstrdup(target,-1),
114             getCompareResult(keyResult), getCompareResult(expectedResult) );
115     }
116 
117     if (keyResult != compareResult)
118     {
119         log_err("difference between sortkey and compare result for (%s , %s) Keys: %s compare %s\n", aescstrdup(source,-1), aescstrdup(target,-1),
120             getCompareResult(keyResult), getCompareResult(compareResult));
121     }
122 
123     if(keyResult != expectedResult || keyResult != compareResult)
124     {
125         char sk[10000];
126         log_verbose("SortKey1: %s\n", dumpSk(sourceKey, sk));
127         log_verbose("SortKey2: %s\n", dumpSk(targetKey, sk));
128     }
129 }
130 
131 #endif /* #if !UCONFIG_NO_COLLATION */
132