]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/cintltst/cestst.c
1 /********************************************************************
3 * Copyright (c) 1997-2009, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
6 /********************************************************************************
10 * Modification History:
12 * Madhu Katragadda Ported for C API
13 *********************************************************************************/
15 * CollationSpanishTest is a third level test class. This tests the locale
16 * specific primary, secondary and tertiary rules. For example, the ignorable
17 * character '-' in string "black-bird". The en_US locale uses the default
18 * collation rules as its sorting sequence.
23 #include "unicode/utypes.h"
25 #if !UCONFIG_NO_COLLATION
27 #include "unicode/ucol.h"
28 #include "unicode/uloc.h"
33 #include "unicode/ustring.h"
36 static UCollator
*myCollation
;
37 const static UChar testSourceCases
[][MAX_TOKEN_LEN
] = {
38 {0x0062/*'a'*/, 0x006c/*'l'*/, 0x0069/*'i'*/, 0x0061/*'a'*/, 0x0073/*'s'*/, 0x0000},
39 {0x0045/*'E'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x0069/*'i'*/, 0x006f/*'o'*/, 0x0074/*'t'*/, 0x0000},
40 {0x0048/*'H'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x006f/*'o'*/, 0x0000},
41 {0x0061/*'a'*/, 0x0063/*'c'*/, 0x0048/*'H'*/, 0x0063/*'c'*/, 0x0000},
42 {0x0061/*'a'*/, 0x0063/*'c'*/, 0x0063/*'c'*/, 0x0000},
43 {0x0061/*'a'*/, 0x006c/*'l'*/, 0x0069/*'i'*/, 0x0061/*'a'*/, 0x0073/*'s'*/, 0x0000},
44 {0x0061/*'a'*/, 0x0063/*'c'*/, 0x0048/*'H'*/, 0x0063/*'c'*/, 0x0000},
45 {0x0061/*'a'*/, 0x0063/*'c'*/, 0x0063/*'c'*/, 0x0000},
46 {0x0048/*'H'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x006f/*'o'*/, 0x0000},
49 const static UChar testTargetCases
[][MAX_TOKEN_LEN
] = {
50 {0x0062/*'a'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x0069/*'i'*/, 0x0061/*'a'*/, 0x0073/*'s'*/, 0x0000},
51 {0x0045/*'E'*/, 0x006d/*'m'*/, 0x0069/*'i'*/, 0x006f/*'o'*/, 0x0074/*'t'*/, 0x0000},
52 {0x0068/*'h'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x006f/*'O'*/, 0x0000},
53 {0x0061/*'a'*/, 0x0043/*'C'*/, 0x0048/*'H'*/, 0x0063/*'c'*/, 0x0000},
54 {0x0061/*'a'*/, 0x0043/*'C'*/, 0x0048/*'H'*/, 0x0063/*'c'*/, 0x0000},
55 {0x0062/*'a'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x0069/*'i'*/, 0x0061/*'a'*/, 0x0073/*'s'*/, 0x0000},
56 {0x0061/*'a'*/, 0x0043/*'C'*/, 0x0048/*'H'*/, 0x0063/*'c'*/, 0x0000},
57 {0x0061/*'a'*/, 0x0043/*'C'*/, 0x0048/*'H'*/, 0x0063/*'c'*/, 0x0000},
58 {0x0068/*'h'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x006f/*'O'*/, 0x0000},
61 const static UCollationResult results
[] = {
75 void addSpanishCollTest(TestNode
** root
)
79 addTest(root
, &TestPrimary
, "tscoll/cestst/TestPrimary");
80 addTest(root
, &TestTertiary
, "tscoll/cestst/TestTertiary");
85 static void TestTertiary( )
89 UErrorCode status
= U_ZERO_ERROR
;
90 myCollation
= ucol_open("es_ES", &status
);
91 if(U_FAILURE(status
)){
92 log_err_status(status
, "ERROR: %s: in creation of rule based collator: %s\n", __FILE__
, myErrorName(status
));
95 log_verbose("Testing Spanish Collation with Tertiary strength\n");
96 ucol_setStrength(myCollation
, UCOL_TERTIARY
);
97 for (i
= 0; i
< 5 ; i
++)
99 doTest(myCollation
, testSourceCases
[i
], testTargetCases
[i
], results
[i
]);
101 ucol_close(myCollation
);
104 static void TestPrimary()
108 UErrorCode status
= U_ZERO_ERROR
;
109 myCollation
= ucol_open("es_ES", &status
);
110 if(U_FAILURE(status
)){
111 log_err_status(status
, "ERROR: %s: in creation of rule based collator: %s\n", __FILE__
, myErrorName(status
));
114 log_verbose("Testing Spanish Collation with Primary strength\n");
115 ucol_setStrength(myCollation
, UCOL_PRIMARY
);
116 for (i
= 5; i
< 9; i
++)
118 doTest(myCollation
, testSourceCases
[i
], testTargetCases
[i
], results
[i
]);
120 ucol_close(myCollation
);
123 #endif /* #if !UCONFIG_NO_COLLATION */