1 /********************************************************************
3 * Copyright (c) 1997-2001, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
6 /********************************************************************************
10 * Modification History:
12 * Madhu Katragadda Creation
13 *********************************************************************************
17 #include "unicode/utypes.h"
19 #if !UCONFIG_NO_COLLATION
23 #include "unicode/ucol.h"
24 #include "unicode/ustring.h"
27 UChar U_CALLCONV
testInc(void *context
);
29 void addCollTest(TestNode
** root
);
31 void addCollTest(TestNode
** root
)
34 addCurrencyTest(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
);
45 /* WEIVTODO: return tests here */
46 addRuleBasedCollTest(root
);
47 addCollIterTest(root
);
49 addMiscCollTest(root
);
56 /*Internal functions used*/
57 static char* dumpSk(uint8_t *sourceKey
, char *sk
) {
58 uint32_t kLen
= (uint32_t)strlen((const char *)sourceKey
);
63 for(i
= 0; i
<kLen
; i
++) {
64 sprintf(sk
+2*i
, "%02X", sourceKey
[i
]);
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
)
76 UChar
*sResult
, *sExpect
;
77 sResult
=(UChar
*)malloc(sizeof(UChar
) * 10);
78 sExpect
=(UChar
*)malloc(sizeof(UChar
) * 10);
79 if (expectedResult
< -1 || expectedResult
> 1)
81 log_err("***** invalid call to reportCResult ****\n");
85 if (compareResult
!= expectedResult
)
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
) );
94 if (incResult
!= expectedResult
)
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
) );
103 if (keyResult
!= expectedResult
)
106 appendCompareResult(keyResult
, sResult
);
107 appendCompareResult(expectedResult
, sExpect
);
109 log_err("KeyCompare(%s , %s) returned: %s expected: %s\n", aescstrdup(source
,-1), aescstrdup(target
,-1),
110 austrdup(sResult
), austrdup(sExpect
) );
115 if (keyResult
!= compareResult
)
118 appendCompareResult(keyResult
, sResult
);
119 appendCompareResult(compareResult
, sExpect
);
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
) );
127 if(keyResult
!= expectedResult
|| keyResult
!= compareResult
)
130 log_verbose("SortKey1: %s\n", dumpSk(sourceKey
, sk
));
131 log_verbose("SortKey2: %s\n", dumpSk(targetKey
, sk
));
138 UChar
* appendCompareResult(UCollationResult result
, UChar
* target
)
140 if (result
== UCOL_LESS
)
142 u_uastrcpy(target
, "LESS");
144 else if (result
== UCOL_EQUAL
)
146 u_uastrcpy(target
, "EQUAL");
148 else if (result
== UCOL_GREATER
)
150 u_uastrcpy(target
, "GREATER");
154 u_uastrcpy(target
, "huh???");
160 /* Support for testing incremental strcoll */
166 UChar U_CALLCONV
testInc(void *context
) {
167 testContext
*s
= (testContext
*)context
;
168 if(s
->start
== s
->end
) {
171 return *(s
->start
++);
175 #endif /* #if !UCONFIG_NO_COLLATION */