]> git.saurik.com Git - apple/icu.git/blame - icuSources/test/cintltst/ccolltst.c
ICU-461.16.tar.gz
[apple/icu.git] / icuSources / test / cintltst / ccolltst.c
CommitLineData
b75a7d8f
A
1/********************************************************************
2 * COPYRIGHT:
729e4ab9 3 * Copyright (c) 1997-2009, 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
27void addCollTest(TestNode** root);
28
29void addCollTest(TestNode** root)
30{
31 addCollAPITest(root);
73c04bcf 32 addCurrencyCollTest(root);
b75a7d8f 33 addNormTest(root);
b75a7d8f
A
34 addGermanCollTest(root);
35 addSpanishCollTest(root);
36 addFrenchCollTest(root);
37 addKannaCollTest(root);
38 addTurkishCollTest(root);
39 addEnglishCollTest(root);
40 addFinnishCollTest(root);
41
42 /* WEIVTODO: return tests here */
43 addRuleBasedCollTest(root);
44 addCollIterTest(root);
45 addAllCollTest(root);
46 addMiscCollTest(root);
729e4ab9 47#if !UCONFIG_NO_BREAK_ITERATION && !UCONFIG_NO_FILE_IO
b75a7d8f 48 addSearchTest(root);
46f4442e 49#endif
b75a7d8f
A
50}
51
52
53
54/*Internal functions used*/
55static char* dumpSk(uint8_t *sourceKey, char *sk) {
56 uint32_t kLen = (uint32_t)strlen((const char *)sourceKey);
57 uint32_t i = 0;
58
59 *sk = 0;
60
61 for(i = 0; i<kLen; i++) {
62 sprintf(sk+2*i, "%02X", sourceKey[i]);
63 }
64 return sk;
65}
66
46f4442e
A
67static const char *getCompareResult(UCollationResult result)
68{
69 if (result == UCOL_LESS)
70 {
71 return "LESS";
72 }
73 else if (result == UCOL_EQUAL)
74 {
75 return "EQUAL";
76 }
77 else if (result == UCOL_GREATER)
78 {
79 return "GREATER";
80 }
81 return "invalid UCollationResult?";
82}
83
b75a7d8f
A
84void reportCResult( const UChar source[], const UChar target[],
85 uint8_t *sourceKey, uint8_t *targetKey,
86 UCollationResult compareResult,
87 UCollationResult keyResult,
88 UCollationResult incResult,
89 UCollationResult expectedResult )
90{
b75a7d8f
A
91 if (expectedResult < -1 || expectedResult > 1)
92 {
93 log_err("***** invalid call to reportCResult ****\n");
94 return;
95 }
96
97 if (compareResult != expectedResult)
98 {
b75a7d8f 99 log_err("Compare(%s , %s) returned: %s expected: %s\n", aescstrdup(source,-1), aescstrdup(target,-1),
46f4442e 100 getCompareResult(compareResult), getCompareResult(expectedResult) );
b75a7d8f
A
101 }
102
103 if (incResult != expectedResult)
104 {
b75a7d8f 105 log_err("incCompare(%s , %s) returned: %s expected: %s\n", aescstrdup(source,-1), aescstrdup(target,-1),
46f4442e 106 getCompareResult(incResult), getCompareResult(expectedResult) );
b75a7d8f
A
107 }
108
109 if (keyResult != expectedResult)
110 {
b75a7d8f 111 log_err("KeyCompare(%s , %s) returned: %s expected: %s\n", aescstrdup(source,-1), aescstrdup(target,-1),
46f4442e 112 getCompareResult(keyResult), getCompareResult(expectedResult) );
b75a7d8f
A
113 }
114
115 if (keyResult != compareResult)
116 {
b75a7d8f 117 log_err("difference between sortkey and compare result for (%s , %s) Keys: %s compare %s\n", aescstrdup(source,-1), aescstrdup(target,-1),
46f4442e 118 getCompareResult(keyResult), getCompareResult(compareResult));
b75a7d8f
A
119 }
120
121 if(keyResult != expectedResult || keyResult != compareResult)
122 {
46f4442e
A
123 char sk[10000];
124 log_verbose("SortKey1: %s\n", dumpSk(sourceKey, sk));
125 log_verbose("SortKey2: %s\n", dumpSk(targetKey, sk));
b75a7d8f
A
126 }
127}
128
129#endif /* #if !UCONFIG_NO_COLLATION */