]> git.saurik.com Git - apple/icu.git/blob - icuSources/test/cintltst/cestst.c
ICU-551.51.4.tar.gz
[apple/icu.git] / icuSources / test / cintltst / cestst.c
1 /********************************************************************
2 * COPYRIGHT:
3 * Copyright (c) 1997-2009, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
6 /********************************************************************************
7 *
8 * File CESTST.C
9 *
10 * Modification History:
11 * Name Description
12 * Madhu Katragadda Ported for C API
13 *********************************************************************************/
14 /**
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.
19 */
20
21 #include <stdlib.h>
22
23 #include "unicode/utypes.h"
24
25 #if !UCONFIG_NO_COLLATION
26
27 #include "unicode/ucol.h"
28 #include "unicode/uloc.h"
29 #include "cintltst.h"
30 #include "cestst.h"
31 #include "ccolltst.h"
32 #include "callcoll.h"
33 #include "unicode/ustring.h"
34 #include "string.h"
35
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},
47 };
48
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},
59 };
60
61 const static UCollationResult results[] = {
62 UCOL_LESS,
63 UCOL_LESS,
64 UCOL_GREATER,
65 UCOL_LESS,
66 UCOL_LESS,
67 /* test primary > 5*/
68 UCOL_LESS,
69 UCOL_EQUAL,
70 UCOL_LESS,
71 UCOL_EQUAL
72 };
73
74
75 void addSpanishCollTest(TestNode** root)
76 {
77
78
79 addTest(root, &TestPrimary, "tscoll/cestst/TestPrimary");
80 addTest(root, &TestTertiary, "tscoll/cestst/TestTertiary");
81
82 }
83
84
85 static void TestTertiary( )
86 {
87
88 int32_t i;
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));
93 return;
94 }
95 log_verbose("Testing Spanish Collation with Tertiary strength\n");
96 ucol_setStrength(myCollation, UCOL_TERTIARY);
97 for (i = 0; i < 5 ; i++)
98 {
99 doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]);
100 }
101 ucol_close(myCollation);
102 }
103
104 static void TestPrimary()
105 {
106
107 int32_t i;
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));
112 return;
113 }
114 log_verbose("Testing Spanish Collation with Primary strength\n");
115 ucol_setStrength(myCollation, UCOL_PRIMARY);
116 for (i = 5; i < 9; i++)
117 {
118 doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]);
119 }
120 ucol_close(myCollation);
121 }
122
123 #endif /* #if !UCONFIG_NO_COLLATION */