1 /********************************************************************
3 * Copyright (c) 1997-2005, 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 addCurrencyCollTest(root
);
36 addGermanCollTest(root
);
37 addSpanishCollTest(root
);
38 addFrenchCollTest(root
);
39 addKannaCollTest(root
);
40 addTurkishCollTest(root
);
41 addEnglishCollTest(root
);
42 addFinnishCollTest(root
);
44 /* WEIVTODO: return tests here */
45 addRuleBasedCollTest(root
);
46 addCollIterTest(root
);
48 addMiscCollTest(root
);
55 /*Internal functions used*/
56 static char* dumpSk(uint8_t *sourceKey
, char *sk
) {
57 uint32_t kLen
= (uint32_t)strlen((const char *)sourceKey
);
62 for(i
= 0; i
<kLen
; i
++) {
63 sprintf(sk
+2*i
, "%02X", sourceKey
[i
]);
68 void reportCResult( const UChar source
[], const UChar target
[],
69 uint8_t *sourceKey
, uint8_t *targetKey
,
70 UCollationResult compareResult
,
71 UCollationResult keyResult
,
72 UCollationResult incResult
,
73 UCollationResult expectedResult
)
75 UChar
*sResult
, *sExpect
;
76 sResult
=(UChar
*)malloc(sizeof(UChar
) * 10);
77 sExpect
=(UChar
*)malloc(sizeof(UChar
) * 10);
78 if (expectedResult
< -1 || expectedResult
> 1)
80 log_err("***** invalid call to reportCResult ****\n");
84 if (compareResult
!= expectedResult
)
87 appendCompareResult(compareResult
, sResult
);
88 appendCompareResult(expectedResult
, sExpect
);
89 log_err("Compare(%s , %s) returned: %s expected: %s\n", aescstrdup(source
,-1), aescstrdup(target
,-1),
90 austrdup(sResult
), austrdup(sExpect
) );
93 if (incResult
!= expectedResult
)
96 appendCompareResult(incResult
, sResult
);
97 appendCompareResult(expectedResult
, sExpect
);
98 log_err("incCompare(%s , %s) returned: %s expected: %s\n", aescstrdup(source
,-1), aescstrdup(target
,-1),
99 austrdup(sResult
), austrdup(sExpect
) );
102 if (keyResult
!= expectedResult
)
105 appendCompareResult(keyResult
, sResult
);
106 appendCompareResult(expectedResult
, sExpect
);
108 log_err("KeyCompare(%s , %s) returned: %s expected: %s\n", aescstrdup(source
,-1), aescstrdup(target
,-1),
109 austrdup(sResult
), austrdup(sExpect
) );
114 if (keyResult
!= compareResult
)
117 appendCompareResult(keyResult
, sResult
);
118 appendCompareResult(compareResult
, sExpect
);
120 log_err("difference between sortkey and compare result for (%s , %s) Keys: %s compare %s\n", aescstrdup(source
,-1), aescstrdup(target
,-1),
121 austrdup(sResult
), austrdup(sExpect
) );
126 if(keyResult
!= expectedResult
|| keyResult
!= compareResult
)
129 log_verbose("SortKey1: %s\n", dumpSk(sourceKey
, sk
));
130 log_verbose("SortKey2: %s\n", dumpSk(targetKey
, sk
));
137 UChar
* appendCompareResult(UCollationResult result
, UChar
* target
)
139 if (result
== UCOL_LESS
)
141 u_uastrcpy(target
, "LESS");
143 else if (result
== UCOL_EQUAL
)
145 u_uastrcpy(target
, "EQUAL");
147 else if (result
== UCOL_GREATER
)
149 u_uastrcpy(target
, "GREATER");
153 u_uastrcpy(target
, "huh???");
159 /* Support for testing incremental strcoll */
165 UChar U_CALLCONV
testInc(void *context
) {
166 testContext
*s
= (testContext
*)context
;
167 if(s
->start
== s
->end
) {
170 return *(s
->start
++);
174 #endif /* #if !UCONFIG_NO_COLLATION */