]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/cintltst/cestst.c
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /********************************************************************
5 * Copyright (c) 1997-2009, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 ********************************************************************/
8 /********************************************************************************
12 * Modification History:
14 * Madhu Katragadda Ported for C API
15 *********************************************************************************/
17 * CollationSpanishTest is a third level test class. This tests the locale
18 * specific primary, secondary and tertiary rules. For example, the ignorable
19 * character '-' in string "black-bird". The en_US locale uses the default
20 * collation rules as its sorting sequence.
25 #include "unicode/utypes.h"
27 #if !UCONFIG_NO_COLLATION
29 #include "unicode/ucol.h"
30 #include "unicode/uloc.h"
35 #include "unicode/ustring.h"
38 static UCollator
*myCollation
;
39 const static UChar testSourceCases
[][MAX_TOKEN_LEN
] = {
40 {0x0062/*'a'*/, 0x006c/*'l'*/, 0x0069/*'i'*/, 0x0061/*'a'*/, 0x0073/*'s'*/, 0x0000},
41 {0x0045/*'E'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x0069/*'i'*/, 0x006f/*'o'*/, 0x0074/*'t'*/, 0x0000},
42 {0x0048/*'H'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x006f/*'o'*/, 0x0000},
43 {0x0061/*'a'*/, 0x0063/*'c'*/, 0x0048/*'H'*/, 0x0063/*'c'*/, 0x0000},
44 {0x0061/*'a'*/, 0x0063/*'c'*/, 0x0063/*'c'*/, 0x0000},
45 {0x0061/*'a'*/, 0x006c/*'l'*/, 0x0069/*'i'*/, 0x0061/*'a'*/, 0x0073/*'s'*/, 0x0000},
46 {0x0061/*'a'*/, 0x0063/*'c'*/, 0x0048/*'H'*/, 0x0063/*'c'*/, 0x0000},
47 {0x0061/*'a'*/, 0x0063/*'c'*/, 0x0063/*'c'*/, 0x0000},
48 {0x0048/*'H'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x006f/*'o'*/, 0x0000},
51 const static UChar testTargetCases
[][MAX_TOKEN_LEN
] = {
52 {0x0062/*'a'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x0069/*'i'*/, 0x0061/*'a'*/, 0x0073/*'s'*/, 0x0000},
53 {0x0045/*'E'*/, 0x006d/*'m'*/, 0x0069/*'i'*/, 0x006f/*'o'*/, 0x0074/*'t'*/, 0x0000},
54 {0x0068/*'h'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x006f/*'O'*/, 0x0000},
55 {0x0061/*'a'*/, 0x0043/*'C'*/, 0x0048/*'H'*/, 0x0063/*'c'*/, 0x0000},
56 {0x0061/*'a'*/, 0x0043/*'C'*/, 0x0048/*'H'*/, 0x0063/*'c'*/, 0x0000},
57 {0x0062/*'a'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x0069/*'i'*/, 0x0061/*'a'*/, 0x0073/*'s'*/, 0x0000},
58 {0x0061/*'a'*/, 0x0043/*'C'*/, 0x0048/*'H'*/, 0x0063/*'c'*/, 0x0000},
59 {0x0061/*'a'*/, 0x0043/*'C'*/, 0x0048/*'H'*/, 0x0063/*'c'*/, 0x0000},
60 {0x0068/*'h'*/, 0x0065/*'e'*/, 0x006c/*'l'*/, 0x006c/*'l'*/, 0x006f/*'O'*/, 0x0000},
63 const static UCollationResult results
[] = {
77 void addSpanishCollTest(TestNode
** root
)
81 addTest(root
, &TestPrimary
, "tscoll/cestst/TestPrimary");
82 addTest(root
, &TestTertiary
, "tscoll/cestst/TestTertiary");
87 static void TestTertiary( )
91 UErrorCode status
= U_ZERO_ERROR
;
92 myCollation
= ucol_open("es_ES", &status
);
93 if(U_FAILURE(status
)){
94 log_err_status(status
, "ERROR: %s: in creation of rule based collator: %s\n", __FILE__
, myErrorName(status
));
97 log_verbose("Testing Spanish Collation with Tertiary strength\n");
98 ucol_setStrength(myCollation
, UCOL_TERTIARY
);
99 for (i
= 0; i
< 5 ; i
++)
101 doTest(myCollation
, testSourceCases
[i
], testTargetCases
[i
], results
[i
]);
103 ucol_close(myCollation
);
106 static void TestPrimary()
110 UErrorCode status
= U_ZERO_ERROR
;
111 myCollation
= ucol_open("es_ES", &status
);
112 if(U_FAILURE(status
)){
113 log_err_status(status
, "ERROR: %s: in creation of rule based collator: %s\n", __FILE__
, myErrorName(status
));
116 log_verbose("Testing Spanish Collation with Primary strength\n");
117 ucol_setStrength(myCollation
, UCOL_PRIMARY
);
118 for (i
= 5; i
< 9; i
++)
120 doTest(myCollation
, testSourceCases
[i
], testTargetCases
[i
], results
[i
]);
122 ucol_close(myCollation
);
125 #endif /* #if !UCONFIG_NO_COLLATION */