]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/cintltst/cdetst.c
1 /********************************************************************
3 * Copyright (c) 1997-2001, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
6 /********************************************************************************
10 * Modification History:
12 * Madhu Katragadda Ported for C API
13 *********************************************************************************/
15 * CollationGermanTest 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
] =
39 {0x0047/*'G'*/, 0x0072/*'r'*/, 0x00F6, 0x00DF, 0x0065/*'e'*/, 0x0000},
40 {0x0061/*'a'*/, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000},
41 {0x0054/*'T'*/, 0x00F6, 0x006e/*'n'*/, 0x0065/*'e'*/, 0x0000},
42 {0x0054/*'T'*/, 0x00F6, 0x006e/*'n'*/, 0x0065/*'e'*/, 0x0000},
43 {0x0054/*'T'*/, 0x00F6, 0x006e/*'n'*/, 0x0065/*'e'*/, 0x0000},
44 {0x0061/*'a'*/, 0x0308, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000},
45 {0x00E4, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000}, /*doubt in primary here */
46 {0x00E4, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000}, /*doubt in primary here*/
47 {0x0053/*'S'*/, 0x0074/*'t'*/, 0x0072/*'r'*/, 0x0061/*'a'*/, 0x00DF, 0x0065/*'e'*/, 0x0000},
48 {0x0065/*'e'*/, 0x0066/*'f'*/, 0x0067/*'g'*/, 0x0000},
49 {0x00E4, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000}, /*doubt in primary here*/
50 {0x0053/*'S'*/, 0x0074/*'t'*/, 0x0072/*'r'*/, 0x0061/*'a'*/, 0x00DF, 0x0065/*'e'*/, 0x0000}
53 const static UChar testTargetCases
[][MAX_TOKEN_LEN
] =
55 {0x0047/*'G'*/, 0x0072/*'r'*/, 0x006f/*'o'*/, 0x0073/*'s'*/, 0x0073/*'s'*/, 0x0069/*'i'*/, 0x0073/*'s'*/, 0x0074/*'t'*/, 0x0000},
56 {0x0061/*'a'*/, 0x0308, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000},
57 {0x0054/*'T'*/, 0x006f/*'o'*/, 0x006e/*'n'*/, 0x0000},
58 {0x0054/*'T'*/, 0x006f/*'o'*/, 0x0064/*'d'*/, 0x0000},
59 {0x0054/*'T'*/, 0x006f/*'o'*/, 0x0066/*'f'*/, 0x0075/*'u'*/, 0x0000},
60 {0x0041/*'A'*/, 0x0308, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000},
61 {0x0061/*'a'*/, 0x0308, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000}, /*doubt in primary here*/
62 {0x0061/*'a'*/, 0x0065/*'e'*/, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000}, /*doubt in primary here*/
63 {0x0053/*'S'*/, 0x0074/*'t'*/, 0x0072/*'r'*/, 0x0061/*'a'*/, 0x0073/*'s'*/, 0x0073/*'s'*/, 0x0065/*'e'*/, 0x0000},
64 {0x0065/*'e'*/, 0x0066/*'f'*/, 0x0067/*'g'*/, 0x0000},
65 {0x0061/*'a'*/, 0x0065/*'e'*/, 0x0062/*'b'*/, 0x0063/*'c'*/, 0x0000}, /*doubt in primary here*/
66 {0x0053/*'S'*/, 0x0074/*'t'*/, 0x0072/*'r'*/, 0x0061/*'a'*/, 0x0073/*'s'*/, 0x0073/*'s'*/, 0x0065/*'e'*/, 0x0000}
69 const static UCollationResult results
[][2] =
71 /* Primary*/ /* Tertiary*/
72 { UCOL_LESS
, UCOL_LESS
}, /*should be UCOL_GREATER for primary*/
73 { UCOL_EQUAL
, UCOL_LESS
},
74 { UCOL_GREATER
, UCOL_GREATER
},
75 { UCOL_GREATER
, UCOL_GREATER
},
76 { UCOL_GREATER
, UCOL_GREATER
},
77 { UCOL_EQUAL
, UCOL_LESS
},
78 { UCOL_EQUAL
, UCOL_EQUAL
}, /*should be UCOL_GREATER for primary*/
79 { UCOL_LESS
, UCOL_LESS
}, /*should be UCOL_GREATER for primary*/
80 { UCOL_EQUAL
, UCOL_GREATER
},
81 { UCOL_EQUAL
, UCOL_EQUAL
},
82 { UCOL_LESS
, UCOL_LESS
}, /*should be UCOL_GREATER for primary*/
83 { UCOL_EQUAL
, UCOL_GREATER
}
89 void addGermanCollTest(TestNode
** root
)
93 addTest(root
, &TestTertiary
, "tscoll/cdetst/TestTertiary");
94 addTest(root
, &TestPrimary
, "tscoll/cdetst/TestPrimary");
100 static void TestTertiary( )
104 UErrorCode status
= U_ZERO_ERROR
;
105 myCollation
= ucol_open("de_DE", &status
);
106 if(U_FAILURE(status
)){
107 log_err("ERROR: in creation of rule based collator: %s\n", myErrorName(status
));
110 log_verbose("Testing German Collation with Tertiary strength\n");
111 ucol_setAttribute(myCollation
, UCOL_NORMALIZATION_MODE
, UCOL_ON
, &status
);
112 ucol_setStrength(myCollation
, UCOL_TERTIARY
);
113 for (i
= 0; i
< 12 ; i
++)
115 doTest(myCollation
, testSourceCases
[i
], testTargetCases
[i
], results
[i
][1]);
117 ucol_close(myCollation
);
120 static void TestPrimary()
124 UErrorCode status
= U_ZERO_ERROR
;
125 myCollation
= ucol_open("de_DE", &status
);
126 if(U_FAILURE(status
)){
127 log_err("ERROR: %s: in creation of rule based collator: %s\n", __FILE__
, myErrorName(status
));
130 log_verbose("Testing German Collation with primary strength\n");
131 ucol_setStrength(myCollation
, UCOL_PRIMARY
);
132 for (i
= 0; i
< 12 ; i
++)
134 doTest(myCollation
, testSourceCases
[i
], testTargetCases
[i
], results
[i
][0]);
136 ucol_close(myCollation
);
139 #endif /* #if !UCONFIG_NO_COLLATION */