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