]> git.saurik.com Git - apple/icu.git/blob - icuSources/test/cintltst/cdetst.c
ICU-62107.0.1.tar.gz
[apple/icu.git] / icuSources / test / cintltst / cdetst.c
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /********************************************************************
4 * COPYRIGHT:
5 * Copyright (c) 1997-2009, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 ********************************************************************/
8 /********************************************************************************
9 *
10 * File CDETST.C
11 *
12 * Modification History:
13 * Name Description
14 * Madhu Katragadda Ported for C API
15 *********************************************************************************/
16 /**
17 * CollationGermanTest 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.
21 */
22
23 #include <stdlib.h>
24
25 #include "unicode/utypes.h"
26
27 #if !UCONFIG_NO_COLLATION
28
29 #include "unicode/ucol.h"
30 #include "unicode/uloc.h"
31 #include "cintltst.h"
32 #include "cdetst.h"
33 #include "ccolltst.h"
34 #include "callcoll.h"
35 #include "unicode/ustring.h"
36 #include "string.h"
37
38 static UCollator *myCollation;
39 const static UChar testSourceCases[][MAX_TOKEN_LEN] =
40 {
41 {0x0047/*'G'*/, 0x0072/*'r'*/, 0x00F6, 0x00DF, 0x0065/*'e'*/, 0x0000},
42 {0x0061/*'a'*/, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000},
43 {0x0054/*'T'*/, 0x00F6, 0x006e/*'n'*/, 0x0065/*'e'*/, 0x0000},
44 {0x0054/*'T'*/, 0x00F6, 0x006e/*'n'*/, 0x0065/*'e'*/, 0x0000},
45 {0x0054/*'T'*/, 0x00F6, 0x006e/*'n'*/, 0x0065/*'e'*/, 0x0000},
46 {0x0061/*'a'*/, 0x0308, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000},
47 {0x00E4, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000}, /*doubt in primary here */
48 {0x00E4, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000}, /*doubt in primary here*/
49 {0x0053/*'S'*/, 0x0074/*'t'*/, 0x0072/*'r'*/, 0x0061/*'a'*/, 0x00DF, 0x0065/*'e'*/, 0x0000},
50 {0x0065/*'e'*/, 0x0066/*'f'*/, 0x0067/*'g'*/, 0x0000},
51 {0x00E4, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000}, /*doubt in primary here*/
52 {0x0053/*'S'*/, 0x0074/*'t'*/, 0x0072/*'r'*/, 0x0061/*'a'*/, 0x00DF, 0x0065/*'e'*/, 0x0000}
53 };
54
55 const static UChar testTargetCases[][MAX_TOKEN_LEN] =
56 {
57 {0x0047/*'G'*/, 0x0072/*'r'*/, 0x006f/*'o'*/, 0x0073/*'s'*/, 0x0073/*'s'*/, 0x0069/*'i'*/, 0x0073/*'s'*/, 0x0074/*'t'*/, 0x0000},
58 {0x0061/*'a'*/, 0x0308, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000},
59 {0x0054/*'T'*/, 0x006f/*'o'*/, 0x006e/*'n'*/, 0x0000},
60 {0x0054/*'T'*/, 0x006f/*'o'*/, 0x0064/*'d'*/, 0x0000},
61 {0x0054/*'T'*/, 0x006f/*'o'*/, 0x0066/*'f'*/, 0x0075/*'u'*/, 0x0000},
62 {0x0041/*'A'*/, 0x0308, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000},
63 {0x0061/*'a'*/, 0x0308, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000}, /*doubt in primary here*/
64 {0x0061/*'a'*/, 0x0065/*'e'*/, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000}, /*doubt in primary here*/
65 {0x0053/*'S'*/, 0x0074/*'t'*/, 0x0072/*'r'*/, 0x0061/*'a'*/, 0x0073/*'s'*/, 0x0073/*'s'*/, 0x0065/*'e'*/, 0x0000},
66 {0x0065/*'e'*/, 0x0066/*'f'*/, 0x0067/*'g'*/, 0x0000},
67 {0x0061/*'a'*/, 0x0065/*'e'*/, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000}, /*doubt in primary here*/
68 {0x0053/*'S'*/, 0x0074/*'t'*/, 0x0072/*'r'*/, 0x0061/*'a'*/, 0x0073/*'s'*/, 0x0073/*'s'*/, 0x0065/*'e'*/, 0x0000}
69 };
70
71 const static UCollationResult results[][2] =
72 {
73 /* Primary*/ /* Tertiary*/
74 { UCOL_LESS, UCOL_LESS }, /*should be UCOL_GREATER for primary*/
75 { UCOL_EQUAL, UCOL_LESS },
76 { UCOL_GREATER, UCOL_GREATER },
77 { UCOL_GREATER, UCOL_GREATER },
78 { UCOL_GREATER, UCOL_GREATER },
79 { UCOL_EQUAL, UCOL_LESS },
80 { UCOL_EQUAL, UCOL_EQUAL }, /*should be UCOL_GREATER for primary*/
81 { UCOL_LESS, UCOL_LESS }, /*should be UCOL_GREATER for primary*/
82 { UCOL_EQUAL, UCOL_GREATER },
83 { UCOL_EQUAL, UCOL_EQUAL },
84 { UCOL_LESS, UCOL_LESS }, /*should be UCOL_GREATER for primary*/
85 { UCOL_EQUAL, UCOL_GREATER }
86 };
87
88
89
90
91 void addGermanCollTest(TestNode** root)
92 {
93
94
95 addTest(root, &TestTertiary, "tscoll/cdetst/TestTertiary");
96 addTest(root, &TestPrimary, "tscoll/cdetst/TestPrimary");
97
98
99
100 }
101
102 static void TestTertiary( )
103 {
104
105 int32_t i;
106 UErrorCode status = U_ZERO_ERROR;
107 myCollation = ucol_open("de_DE", &status);
108 if(U_FAILURE(status)){
109 log_err_status(status, "ERROR: in creation of rule based collator: %s\n", myErrorName(status));
110 return;
111 }
112 log_verbose("Testing German Collation with Tertiary strength\n");
113 ucol_setAttribute(myCollation, UCOL_NORMALIZATION_MODE, UCOL_ON, &status);
114 ucol_setStrength(myCollation, UCOL_TERTIARY);
115 for (i = 0; i < 12 ; i++)
116 {
117 doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i][1]);
118 }
119 ucol_close(myCollation);
120 }
121
122 static void TestPrimary()
123 {
124
125 int32_t i;
126 UErrorCode status = U_ZERO_ERROR;
127 myCollation = ucol_open("de_DE", &status);
128 if(U_FAILURE(status)){
129 log_err_status(status, "ERROR: %s: in creation of rule based collator: %s\n", __FILE__, myErrorName(status));
130 return;
131 }
132 log_verbose("Testing German Collation with primary strength\n");
133 ucol_setStrength(myCollation, UCOL_PRIMARY);
134 for (i = 0; i < 12 ; i++)
135 {
136 doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i][0]);
137 }
138 ucol_close(myCollation);
139 }
140
141 #endif /* #if !UCONFIG_NO_COLLATION */