]>
git.saurik.com Git - apple/icu.git/blob - 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 /********************************************************************
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 * 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.
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
] =
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}
55 const static UChar testTargetCases
[][MAX_TOKEN_LEN
] =
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}
71 const static UCollationResult results
[][2] =
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
}
91 void addGermanCollTest(TestNode
** root
)
95 addTest(root
, &TestTertiary
, "tscoll/cdetst/TestTertiary");
96 addTest(root
, &TestPrimary
, "tscoll/cdetst/TestPrimary");
102 static void TestTertiary( )
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
));
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
++)
117 doTest(myCollation
, testSourceCases
[i
], testTargetCases
[i
], results
[i
][1]);
119 ucol_close(myCollation
);
122 static void TestPrimary()
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
));
132 log_verbose("Testing German Collation with primary strength\n");
133 ucol_setStrength(myCollation
, UCOL_PRIMARY
);
134 for (i
= 0; i
< 12 ; i
++)
136 doTest(myCollation
, testSourceCases
[i
], testTargetCases
[i
], results
[i
][0]);
138 ucol_close(myCollation
);
141 #endif /* #if !UCONFIG_NO_COLLATION */