]> git.saurik.com Git - apple/icu.git/blob - icuSources/test/cintltst/cturtst.c
ICU-3.13.tar.gz
[apple/icu.git] / icuSources / test / cintltst / cturtst.c
1 /********************************************************************
2 * COPYRIGHT:
3 * Copyright (c) 1997-2001, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
6 /********************************************************************************
7 *
8 * File CTURTST.C
9 *
10 * Modification History:
11 * Name Description
12 * Madhu Katragadda Ported for C API
13 *********************************************************************************/
14 /**
15 * CollationTurkishTest 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 "ccolltst.h"
31 #include "callcoll.h"
32 #include "cturtst.h"
33 #include "unicode/ustring.h"
34 #include "string.h"
35
36 static UCollator *myCollation;
37 const static UChar testSourceCases[][MAX_TOKEN_LEN] = {
38 {0x0073/*'s'*/, 0x0327, 0x0000},
39 {0x0076/*'v'*/, 0x00E4, 0x0074/*'t'*/, 0x0000},
40 {0x006f/*'o'*/, 0x006c/*'l'*/, 0x0064/*'d'*/, 0x0000},
41 {0x00FC, 0x006f/*'o'*/, 0x0069/*'i'*/, 0x0064/*'d'*/, 0x0000},
42 {0x0068/*'h'*/, 0x011E, 0x0061/*'a'*/, 0x006c/*'l'*/, 0x0074/*'t'*/, 0x0000},
43 {0x0073/*'s'*/, 0x0074/*'t'*/, 0x0072/*'r'*/, 0x0065/*'e'*/, 0x0073/*'s'*/, 0x015E, 0x0000},
44 {0x0076/*'v'*/, 0x006f/*'o'*/, 0x0131, 0x0064/*'d'*/, 0x0000},
45 {0x0069/*'i'*/, 0x0064/*'d'*/, 0x0065/*'e'*/, 0x0061/*'a'*/, 0x0000},
46 {0x00FC, 0x006f/*'o'*/, 0x0069/*'i'*/, 0x0064 /*d'*/, 0x0000},
47 {0x0076/*'v'*/, 0x006f/*'o'*/, 0x0131, 0x0064 /*d'*/, 0x0000},
48 {0x0069/*'i'*/, 0x0064/*'d'*/, 0x0065/*'e'*/, 0x0061/*'a'*/, 0x0000},
49 };
50
51 const static UChar testTargetCases[][MAX_TOKEN_LEN] = {
52 {0x0075/*'u'*/, 0x0308, 0x0000},
53 {0x0076/*'v'*/, 0x0062/*'b'*/, 0x0074/*'t'*/, 0x0000},
54 {0x00D6, 0x0061/*'a'*/, 0x0079/*'y'*/, 0x0000},
55 {0x0076/*'v'*/, 0x006f/*'o'*/, 0x0069/*'i'*/, 0x0064 /*d'*/, 0x0000},
56 {0x0068/*'h'*/, 0x0061/*'a'*/, 0x006c/*'l'*/, 0x0074/*'t'*/, 0x0000},
57 {0x015E, 0x0074/*'t'*/, 0x0072/*'r'*/, 0x0065/*'e'*/, 0x015E, 0x0073/*'s'*/, 0x0000},
58 {0x0076/*'v'*/, 0x006f/*'o'*/, 0x0069/*'i'*/, 0x0064 /*d'*/, 0x0000},
59 {0x0049/*'I'*/, 0x0064/*'d'*/, 0x0065/*'e'*/, 0x0061/*'a'*/, 0x0000},
60 {0x0076/*'v'*/, 0x006f/*'o'*/, 0x0069/*'i'*/, 0x0064 /*d'*/, 0x0000},
61 {0x0076/*'v'*/, 0x006f/*'o'*/, 0x0069/*'i'*/, 0x0064 /*d'*/, 0x0000},
62 {0x0049/*'I'*/, 0x0064/*'d'*/, 0x0065/*'e'*/, 0x0061/*'a'*/, 0x0000},
63 };
64
65 const static UCollationResult results[] = {
66 UCOL_LESS,
67 UCOL_LESS,
68 UCOL_LESS,
69 UCOL_LESS,
70 UCOL_GREATER,
71 UCOL_LESS,
72 UCOL_LESS,
73 UCOL_GREATER,
74 /* test priamry > 8 */
75 UCOL_LESS,
76 UCOL_LESS, /*Turkish translator made a primary differnce between dotted and dotless I */
77 UCOL_GREATER
78 };
79
80
81
82 void addTurkishCollTest(TestNode** root)
83 {
84
85 addTest(root, &TestPrimary, "tscoll/cturtst/TestPrimary");
86 addTest(root, &TestTertiary, "tscoll/cturtst/TestTertiary");
87
88
89 }
90
91 static void TestTertiary( )
92 {
93
94 int32_t i;
95
96 UErrorCode status = U_ZERO_ERROR;
97 myCollation = ucol_open("tr", &status);
98 if(U_FAILURE(status)){
99 log_err("ERROR: in creation of rule based collator: %s\n", myErrorName(status));
100 return;
101 }
102 log_verbose("Testing Turkish Collation with Tertiary strength\n");
103 ucol_setStrength(myCollation, UCOL_TERTIARY);
104 for (i = 0; i < 8 ; i++)
105 {
106 doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]);
107 }
108 ucol_close(myCollation);
109 }
110
111 static void TestPrimary()
112 {
113
114 int32_t i;
115
116 UErrorCode status = U_ZERO_ERROR;
117 myCollation = ucol_open("tr", &status);
118 if(U_FAILURE(status)){
119 log_err("ERROR: in creation of rule based collator: %s\n", myErrorName(status));
120 return;
121 }
122 log_verbose("Testing Turkish Collation with Primary strength\n");
123 ucol_setStrength(myCollation, UCOL_PRIMARY);
124 for (i = 8; i < 11; i++)
125 {
126 doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]);
127 }
128 ucol_close(myCollation);
129 }
130
131 #endif /* #if !UCONFIG_NO_COLLATION */