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 CJAPTST.C
11*
12* Modification History:
13*        Name                     Description
14*     Madhu Katragadda            Ported for C API
15* synwee                          Added TestBase, TestPlainDakutenHandakuten,
16*                                 TestSmallLarge, TestKatakanaHiragana,
17*                                 TestChooonKigoo
18*********************************************************************************/
19/**
20 * CollationKannaTest is a third level test class.  This tests the locale
21 * specific primary, secondary and tertiary rules.  For example, the ignorable
22 * character '-' in string "black-bird".  The en_US locale uses the default
23 * collation rules as its sorting sequence.
24 */
25
26#include <stdlib.h>
27
28#include "unicode/utypes.h"
29
30#if !UCONFIG_NO_COLLATION
31
32#include "unicode/ucol.h"
33#include "unicode/uloc.h"
34#include "cintltst.h"
35#include "ccolltst.h"
36#include "callcoll.h"
37#include "cjaptst.h"
38#include "unicode/ustring.h"
39#include "string.h"
40
41static UCollator *myCollation;
42const static UChar testSourceCases[][MAX_TOKEN_LEN] = {
43    {0xff9E, 0x0000},
44    {0x3042, 0x0000},
45    {0x30A2, 0x0000},
46    {0x3042, 0x3042, 0x0000},
47    {0x30A2, 0x30FC, 0x0000},
48    {0x30A2, 0x30FC, 0x30C8, 0x0000}                               /*  6 */
49};
50
51const static UChar testTargetCases[][MAX_TOKEN_LEN] = {
52    {0xFF9F, 0x0000},
53    {0x30A2, 0x0000},
54    {0x3042, 0x3042, 0x0000},
55    {0x30A2, 0x30FC, 0x0000},
56    {0x30A2, 0x30FC, 0x30C8, 0x0000},
57    {0x3042, 0x3042, 0x3068, 0x0000}                              /*  6 */
58};
59
60const static UCollationResult results[] = {
61    UCOL_LESS,
62    UCOL_EQUAL, /*UCOL_LESS*/   /* Katakanas and Hiraganas are equal on tertiary level(ICU 2.0)*/
63    UCOL_LESS,
64    UCOL_GREATER, /*UCOL_LESS*/ /* Prolonged sound mark sorts BEFORE equivalent vowel (ICU 2.0)*/
65    UCOL_LESS,
66    UCOL_LESS, /*UCOL_GREATER*/ /* Prolonged sound mark sorts BEFORE equivalent vowel (ICU 2.0)*//*  6 */
67};
68
69const static UChar testBaseCases[][MAX_TOKEN_LEN] = {
70  {0x30AB, 0x0000},
71  {0x30AB, 0x30AD, 0x0000},
72  {0x30AD, 0x0000},
73  {0x30AD, 0x30AD, 0x0000}
74};
75
76const static UChar testPlainDakutenHandakutenCases[][MAX_TOKEN_LEN] = {
77  {0x30CF, 0x30AB, 0x0000},
78  {0x30D0, 0x30AB, 0x0000},
79  {0x30CF, 0x30AD, 0x0000},
80  {0x30D0, 0x30AD, 0x0000}
81};
82
83const static UChar testSmallLargeCases[][MAX_TOKEN_LEN] = {
84  {0x30C3, 0x30CF, 0x0000},
85  {0x30C4, 0x30CF, 0x0000},
86  {0x30C3, 0x30D0, 0x0000},
87  {0x30C4, 0x30D0, 0x0000}
88};
89
90const static UChar testKatakanaHiraganaCases[][MAX_TOKEN_LEN] = {
91  {0x3042, 0x30C3, 0x0000},
92  {0x30A2, 0x30C3, 0x0000},
93  {0x3042, 0x30C4, 0x0000},
94  {0x30A2, 0x30C4, 0x0000}
95};
96
97const static UChar testChooonKigooCases[][MAX_TOKEN_LEN] = {
98  /*0*/ {0x30AB, 0x30FC, 0x3042, 0x0000},
99  /*1*/ {0x30AB, 0x30FC, 0x30A2, 0x0000},
100  /*2*/ {0x30AB, 0x30A4, 0x3042, 0x0000},
101  /*3*/ {0x30AB, 0x30A4, 0x30A2, 0x0000},
102  /*6*/ {0x30AD, 0x30FC, 0x3042, 0x0000}, /* Prolonged sound mark sorts BEFORE equivalent vowel (ICU 2.0)*/
103  /*7*/ {0x30AD, 0x30FC, 0x30A2, 0x0000}, /* Prolonged sound mark sorts BEFORE equivalent vowel (ICU 2.0)*/
104  /*4*/ {0x30AD, 0x30A4, 0x3042, 0x0000},
105  /*5*/ {0x30AD, 0x30A4, 0x30A2, 0x0000},
106};
107
108void addKannaCollTest(TestNode** root)
109{
110    addTest(root, &TestTertiary, "tscoll/cjacoll/TestTertiary");
111    addTest(root, &TestBase, "tscoll/cjacoll/TestBase");
112    addTest(root, &TestPlainDakutenHandakuten, "tscoll/cjacoll/TestPlainDakutenHandakuten");
113    addTest(root, &TestSmallLarge, "tscoll/cjacoll/TestSmallLarge");
114    addTest(root, &TestKatakanaHiragana, "tscoll/cjacoll/TestKatakanaHiragana");
115    addTest(root, &TestChooonKigoo, "tscoll/cjacoll/TestChooonKigoo");
116}
117
118static void TestTertiary( )
119{
120    int32_t i;
121    UErrorCode status = U_ZERO_ERROR;
122    myCollation = ucol_open("ja_JP", &status);
123    if(U_FAILURE(status)){
124        log_err_status(status, "ERROR: in creation of rule based collator: %s\n", myErrorName(status));
125        return;
126    }
127    log_verbose("Testing Kanna(Japan) Collation with Tertiary strength\n");
128    ucol_setStrength(myCollation, UCOL_TERTIARY);
129    ucol_setAttribute(myCollation, UCOL_CASE_LEVEL, UCOL_ON, &status);
130    for (i = 0; i < 6 ; i++)
131    {
132        doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]);
133    }
134    ucol_close(myCollation);
135}
136
137/* Testing base letters */
138static void TestBase()
139{
140    int32_t i;
141    UErrorCode status = U_ZERO_ERROR;
142    myCollation = ucol_open("ja_JP", &status);
143    if (U_FAILURE(status))
144    {
145        log_err_status(status, "ERROR: in creation of rule based collator: %s\n",
146            myErrorName(status));
147        return;
148    }
149
150    log_verbose("Testing Japanese Base Characters Collation\n");
151    ucol_setStrength(myCollation, UCOL_PRIMARY);
152    for (i = 0; i < 3 ; i++)
153        doTest(myCollation, testBaseCases[i], testBaseCases[i + 1], UCOL_LESS);
154
155    ucol_close(myCollation);
156}
157
158/* Testing plain, Daku-ten, Handaku-ten letters */
159static void TestPlainDakutenHandakuten(void)
160{
161    int32_t i;
162    UErrorCode status = U_ZERO_ERROR;
163    myCollation = ucol_open("ja_JP", &status);
164    if (U_FAILURE(status))
165    {
166        log_err_status(status, "ERROR: in creation of rule based collator: %s\n",
167            myErrorName(status));
168        return;
169    }
170
171    log_verbose("Testing plain, Daku-ten, Handaku-ten letters Japanese Characters Collation\n");
172    ucol_setStrength(myCollation, UCOL_SECONDARY);
173    for (i = 0; i < 3 ; i++)
174        doTest(myCollation, testPlainDakutenHandakutenCases[i],
175        testPlainDakutenHandakutenCases[i + 1], UCOL_LESS);
176
177    ucol_close(myCollation);
178}
179
180/*
181* Test Small, Large letters
182*/
183static void TestSmallLarge(void)
184{
185    int32_t i;
186    UErrorCode status = U_ZERO_ERROR;
187    myCollation = ucol_open("ja_JP", &status);
188    if (U_FAILURE(status))
189    {
190        log_err_status(status, "ERROR: in creation of rule based collator: %s\n",
191            myErrorName(status));
192        return;
193    }
194
195    log_verbose("Testing Japanese Small and Large Characters Collation\n");
196    ucol_setStrength(myCollation, UCOL_TERTIARY);
197    ucol_setAttribute(myCollation, UCOL_CASE_LEVEL, UCOL_ON, &status);
198    for (i = 0; i < 3 ; i++)
199        doTest(myCollation, testSmallLargeCases[i], testSmallLargeCases[i + 1],
200        UCOL_LESS);
201
202    ucol_close(myCollation);
203}
204
205/*
206* Test Katakana, Hiragana letters
207*/
208static void TestKatakanaHiragana(void)
209{
210    int32_t i;
211    UErrorCode status = U_ZERO_ERROR;
212    myCollation = ucol_open("ja_JP", &status);
213    if (U_FAILURE(status))
214    {
215        log_err_status(status, "ERROR: in creation of rule based collator: %s\n",
216            myErrorName(status));
217        return;
218    }
219
220    log_verbose("Testing Japanese Katakana, Hiragana Characters Collation\n");
221    ucol_setStrength(myCollation, UCOL_QUATERNARY);
222    ucol_setAttribute(myCollation, UCOL_CASE_LEVEL, UCOL_ON, &status);
223    for (i = 0; i < 3 ; i++) {
224        doTest(myCollation, testKatakanaHiraganaCases[i],
225            testKatakanaHiraganaCases[i + 1], UCOL_LESS);
226    }
227
228    ucol_close(myCollation);
229}
230
231/*
232* Test Choo-on kigoo
233*/
234static void TestChooonKigoo(void)
235{
236    int32_t i;
237    UErrorCode status = U_ZERO_ERROR;
238    myCollation = ucol_open("ja_JP", &status);
239    if (U_FAILURE(status))
240    {
241        log_err_status(status, "ERROR: in creation of rule based collator: %s\n",
242            myErrorName(status));
243        return;
244    }
245
246    log_verbose("Testing Japanese Choo-on Kigoo Characters Collation\n");
247    ucol_setAttribute(myCollation, UCOL_STRENGTH, UCOL_QUATERNARY, &status);
248    ucol_setAttribute(myCollation, UCOL_CASE_LEVEL, UCOL_ON, &status);
249    for (i = 0; i < 7 ; i++) {
250        doTest(myCollation, testChooonKigooCases[i], testChooonKigooCases[i + 1],
251            UCOL_LESS);
252    }
253
254    ucol_close(myCollation);
255}
256
257#endif /* #if !UCONFIG_NO_COLLATION */
258