12e5b6d6dSopenharmony_ci// © 2016 and later: Unicode, Inc. and others.
22e5b6d6dSopenharmony_ci// License & terms of use: http://www.unicode.org/copyright.html
32e5b6d6dSopenharmony_ci/********************************************************************
42e5b6d6dSopenharmony_ci * COPYRIGHT:
52e5b6d6dSopenharmony_ci * Copyright (c) 1997-2009, International Business Machines Corporation and
62e5b6d6dSopenharmony_ci * others. All Rights Reserved.
72e5b6d6dSopenharmony_ci ********************************************************************/
82e5b6d6dSopenharmony_ci/********************************************************************************
92e5b6d6dSopenharmony_ci*
102e5b6d6dSopenharmony_ci* File CJAPTST.C
112e5b6d6dSopenharmony_ci*
122e5b6d6dSopenharmony_ci* Modification History:
132e5b6d6dSopenharmony_ci*        Name                     Description
142e5b6d6dSopenharmony_ci*     Madhu Katragadda            Ported for C API
152e5b6d6dSopenharmony_ci* synwee                          Added TestBase, TestPlainDakutenHandakuten,
162e5b6d6dSopenharmony_ci*                                 TestSmallLarge, TestKatakanaHiragana,
172e5b6d6dSopenharmony_ci*                                 TestChooonKigoo
182e5b6d6dSopenharmony_ci*********************************************************************************/
192e5b6d6dSopenharmony_ci/**
202e5b6d6dSopenharmony_ci * CollationKannaTest is a third level test class.  This tests the locale
212e5b6d6dSopenharmony_ci * specific primary, secondary and tertiary rules.  For example, the ignorable
222e5b6d6dSopenharmony_ci * character '-' in string "black-bird".  The en_US locale uses the default
232e5b6d6dSopenharmony_ci * collation rules as its sorting sequence.
242e5b6d6dSopenharmony_ci */
252e5b6d6dSopenharmony_ci
262e5b6d6dSopenharmony_ci#include <stdlib.h>
272e5b6d6dSopenharmony_ci
282e5b6d6dSopenharmony_ci#include "unicode/utypes.h"
292e5b6d6dSopenharmony_ci
302e5b6d6dSopenharmony_ci#if !UCONFIG_NO_COLLATION
312e5b6d6dSopenharmony_ci
322e5b6d6dSopenharmony_ci#include "unicode/ucol.h"
332e5b6d6dSopenharmony_ci#include "unicode/uloc.h"
342e5b6d6dSopenharmony_ci#include "cintltst.h"
352e5b6d6dSopenharmony_ci#include "ccolltst.h"
362e5b6d6dSopenharmony_ci#include "callcoll.h"
372e5b6d6dSopenharmony_ci#include "cjaptst.h"
382e5b6d6dSopenharmony_ci#include "unicode/ustring.h"
392e5b6d6dSopenharmony_ci#include "string.h"
402e5b6d6dSopenharmony_ci
412e5b6d6dSopenharmony_cistatic UCollator *myCollation;
422e5b6d6dSopenharmony_ciconst static UChar testSourceCases[][MAX_TOKEN_LEN] = {
432e5b6d6dSopenharmony_ci    {0xff9E, 0x0000},
442e5b6d6dSopenharmony_ci    {0x3042, 0x0000},
452e5b6d6dSopenharmony_ci    {0x30A2, 0x0000},
462e5b6d6dSopenharmony_ci    {0x3042, 0x3042, 0x0000},
472e5b6d6dSopenharmony_ci    {0x30A2, 0x30FC, 0x0000},
482e5b6d6dSopenharmony_ci    {0x30A2, 0x30FC, 0x30C8, 0x0000}                               /*  6 */
492e5b6d6dSopenharmony_ci};
502e5b6d6dSopenharmony_ci
512e5b6d6dSopenharmony_ciconst static UChar testTargetCases[][MAX_TOKEN_LEN] = {
522e5b6d6dSopenharmony_ci    {0xFF9F, 0x0000},
532e5b6d6dSopenharmony_ci    {0x30A2, 0x0000},
542e5b6d6dSopenharmony_ci    {0x3042, 0x3042, 0x0000},
552e5b6d6dSopenharmony_ci    {0x30A2, 0x30FC, 0x0000},
562e5b6d6dSopenharmony_ci    {0x30A2, 0x30FC, 0x30C8, 0x0000},
572e5b6d6dSopenharmony_ci    {0x3042, 0x3042, 0x3068, 0x0000}                              /*  6 */
582e5b6d6dSopenharmony_ci};
592e5b6d6dSopenharmony_ci
602e5b6d6dSopenharmony_ciconst static UCollationResult results[] = {
612e5b6d6dSopenharmony_ci    UCOL_LESS,
622e5b6d6dSopenharmony_ci    UCOL_EQUAL, /*UCOL_LESS*/   /* Katakanas and Hiraganas are equal on tertiary level(ICU 2.0)*/
632e5b6d6dSopenharmony_ci    UCOL_LESS,
642e5b6d6dSopenharmony_ci    UCOL_GREATER, /*UCOL_LESS*/ /* Prolonged sound mark sorts BEFORE equivalent vowel (ICU 2.0)*/
652e5b6d6dSopenharmony_ci    UCOL_LESS,
662e5b6d6dSopenharmony_ci    UCOL_LESS, /*UCOL_GREATER*/ /* Prolonged sound mark sorts BEFORE equivalent vowel (ICU 2.0)*//*  6 */
672e5b6d6dSopenharmony_ci};
682e5b6d6dSopenharmony_ci
692e5b6d6dSopenharmony_ciconst static UChar testBaseCases[][MAX_TOKEN_LEN] = {
702e5b6d6dSopenharmony_ci  {0x30AB, 0x0000},
712e5b6d6dSopenharmony_ci  {0x30AB, 0x30AD, 0x0000},
722e5b6d6dSopenharmony_ci  {0x30AD, 0x0000},
732e5b6d6dSopenharmony_ci  {0x30AD, 0x30AD, 0x0000}
742e5b6d6dSopenharmony_ci};
752e5b6d6dSopenharmony_ci
762e5b6d6dSopenharmony_ciconst static UChar testPlainDakutenHandakutenCases[][MAX_TOKEN_LEN] = {
772e5b6d6dSopenharmony_ci  {0x30CF, 0x30AB, 0x0000},
782e5b6d6dSopenharmony_ci  {0x30D0, 0x30AB, 0x0000},
792e5b6d6dSopenharmony_ci  {0x30CF, 0x30AD, 0x0000},
802e5b6d6dSopenharmony_ci  {0x30D0, 0x30AD, 0x0000}
812e5b6d6dSopenharmony_ci};
822e5b6d6dSopenharmony_ci
832e5b6d6dSopenharmony_ciconst static UChar testSmallLargeCases[][MAX_TOKEN_LEN] = {
842e5b6d6dSopenharmony_ci  {0x30C3, 0x30CF, 0x0000},
852e5b6d6dSopenharmony_ci  {0x30C4, 0x30CF, 0x0000},
862e5b6d6dSopenharmony_ci  {0x30C3, 0x30D0, 0x0000},
872e5b6d6dSopenharmony_ci  {0x30C4, 0x30D0, 0x0000}
882e5b6d6dSopenharmony_ci};
892e5b6d6dSopenharmony_ci
902e5b6d6dSopenharmony_ciconst static UChar testKatakanaHiraganaCases[][MAX_TOKEN_LEN] = {
912e5b6d6dSopenharmony_ci  {0x3042, 0x30C3, 0x0000},
922e5b6d6dSopenharmony_ci  {0x30A2, 0x30C3, 0x0000},
932e5b6d6dSopenharmony_ci  {0x3042, 0x30C4, 0x0000},
942e5b6d6dSopenharmony_ci  {0x30A2, 0x30C4, 0x0000}
952e5b6d6dSopenharmony_ci};
962e5b6d6dSopenharmony_ci
972e5b6d6dSopenharmony_ciconst static UChar testChooonKigooCases[][MAX_TOKEN_LEN] = {
982e5b6d6dSopenharmony_ci  /*0*/ {0x30AB, 0x30FC, 0x3042, 0x0000},
992e5b6d6dSopenharmony_ci  /*1*/ {0x30AB, 0x30FC, 0x30A2, 0x0000},
1002e5b6d6dSopenharmony_ci  /*2*/ {0x30AB, 0x30A4, 0x3042, 0x0000},
1012e5b6d6dSopenharmony_ci  /*3*/ {0x30AB, 0x30A4, 0x30A2, 0x0000},
1022e5b6d6dSopenharmony_ci  /*6*/ {0x30AD, 0x30FC, 0x3042, 0x0000}, /* Prolonged sound mark sorts BEFORE equivalent vowel (ICU 2.0)*/
1032e5b6d6dSopenharmony_ci  /*7*/ {0x30AD, 0x30FC, 0x30A2, 0x0000}, /* Prolonged sound mark sorts BEFORE equivalent vowel (ICU 2.0)*/
1042e5b6d6dSopenharmony_ci  /*4*/ {0x30AD, 0x30A4, 0x3042, 0x0000},
1052e5b6d6dSopenharmony_ci  /*5*/ {0x30AD, 0x30A4, 0x30A2, 0x0000},
1062e5b6d6dSopenharmony_ci};
1072e5b6d6dSopenharmony_ci
1082e5b6d6dSopenharmony_civoid addKannaCollTest(TestNode** root)
1092e5b6d6dSopenharmony_ci{
1102e5b6d6dSopenharmony_ci    addTest(root, &TestTertiary, "tscoll/cjacoll/TestTertiary");
1112e5b6d6dSopenharmony_ci    addTest(root, &TestBase, "tscoll/cjacoll/TestBase");
1122e5b6d6dSopenharmony_ci    addTest(root, &TestPlainDakutenHandakuten, "tscoll/cjacoll/TestPlainDakutenHandakuten");
1132e5b6d6dSopenharmony_ci    addTest(root, &TestSmallLarge, "tscoll/cjacoll/TestSmallLarge");
1142e5b6d6dSopenharmony_ci    addTest(root, &TestKatakanaHiragana, "tscoll/cjacoll/TestKatakanaHiragana");
1152e5b6d6dSopenharmony_ci    addTest(root, &TestChooonKigoo, "tscoll/cjacoll/TestChooonKigoo");
1162e5b6d6dSopenharmony_ci}
1172e5b6d6dSopenharmony_ci
1182e5b6d6dSopenharmony_cistatic void TestTertiary( )
1192e5b6d6dSopenharmony_ci{
1202e5b6d6dSopenharmony_ci    int32_t i;
1212e5b6d6dSopenharmony_ci    UErrorCode status = U_ZERO_ERROR;
1222e5b6d6dSopenharmony_ci    myCollation = ucol_open("ja_JP", &status);
1232e5b6d6dSopenharmony_ci    if(U_FAILURE(status)){
1242e5b6d6dSopenharmony_ci        log_err_status(status, "ERROR: in creation of rule based collator: %s\n", myErrorName(status));
1252e5b6d6dSopenharmony_ci        return;
1262e5b6d6dSopenharmony_ci    }
1272e5b6d6dSopenharmony_ci    log_verbose("Testing Kanna(Japan) Collation with Tertiary strength\n");
1282e5b6d6dSopenharmony_ci    ucol_setStrength(myCollation, UCOL_TERTIARY);
1292e5b6d6dSopenharmony_ci    ucol_setAttribute(myCollation, UCOL_CASE_LEVEL, UCOL_ON, &status);
1302e5b6d6dSopenharmony_ci    for (i = 0; i < 6 ; i++)
1312e5b6d6dSopenharmony_ci    {
1322e5b6d6dSopenharmony_ci        doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]);
1332e5b6d6dSopenharmony_ci    }
1342e5b6d6dSopenharmony_ci    ucol_close(myCollation);
1352e5b6d6dSopenharmony_ci}
1362e5b6d6dSopenharmony_ci
1372e5b6d6dSopenharmony_ci/* Testing base letters */
1382e5b6d6dSopenharmony_cistatic void TestBase()
1392e5b6d6dSopenharmony_ci{
1402e5b6d6dSopenharmony_ci    int32_t i;
1412e5b6d6dSopenharmony_ci    UErrorCode status = U_ZERO_ERROR;
1422e5b6d6dSopenharmony_ci    myCollation = ucol_open("ja_JP", &status);
1432e5b6d6dSopenharmony_ci    if (U_FAILURE(status))
1442e5b6d6dSopenharmony_ci    {
1452e5b6d6dSopenharmony_ci        log_err_status(status, "ERROR: in creation of rule based collator: %s\n",
1462e5b6d6dSopenharmony_ci            myErrorName(status));
1472e5b6d6dSopenharmony_ci        return;
1482e5b6d6dSopenharmony_ci    }
1492e5b6d6dSopenharmony_ci
1502e5b6d6dSopenharmony_ci    log_verbose("Testing Japanese Base Characters Collation\n");
1512e5b6d6dSopenharmony_ci    ucol_setStrength(myCollation, UCOL_PRIMARY);
1522e5b6d6dSopenharmony_ci    for (i = 0; i < 3 ; i++)
1532e5b6d6dSopenharmony_ci        doTest(myCollation, testBaseCases[i], testBaseCases[i + 1], UCOL_LESS);
1542e5b6d6dSopenharmony_ci
1552e5b6d6dSopenharmony_ci    ucol_close(myCollation);
1562e5b6d6dSopenharmony_ci}
1572e5b6d6dSopenharmony_ci
1582e5b6d6dSopenharmony_ci/* Testing plain, Daku-ten, Handaku-ten letters */
1592e5b6d6dSopenharmony_cistatic void TestPlainDakutenHandakuten(void)
1602e5b6d6dSopenharmony_ci{
1612e5b6d6dSopenharmony_ci    int32_t i;
1622e5b6d6dSopenharmony_ci    UErrorCode status = U_ZERO_ERROR;
1632e5b6d6dSopenharmony_ci    myCollation = ucol_open("ja_JP", &status);
1642e5b6d6dSopenharmony_ci    if (U_FAILURE(status))
1652e5b6d6dSopenharmony_ci    {
1662e5b6d6dSopenharmony_ci        log_err_status(status, "ERROR: in creation of rule based collator: %s\n",
1672e5b6d6dSopenharmony_ci            myErrorName(status));
1682e5b6d6dSopenharmony_ci        return;
1692e5b6d6dSopenharmony_ci    }
1702e5b6d6dSopenharmony_ci
1712e5b6d6dSopenharmony_ci    log_verbose("Testing plain, Daku-ten, Handaku-ten letters Japanese Characters Collation\n");
1722e5b6d6dSopenharmony_ci    ucol_setStrength(myCollation, UCOL_SECONDARY);
1732e5b6d6dSopenharmony_ci    for (i = 0; i < 3 ; i++)
1742e5b6d6dSopenharmony_ci        doTest(myCollation, testPlainDakutenHandakutenCases[i],
1752e5b6d6dSopenharmony_ci        testPlainDakutenHandakutenCases[i + 1], UCOL_LESS);
1762e5b6d6dSopenharmony_ci
1772e5b6d6dSopenharmony_ci    ucol_close(myCollation);
1782e5b6d6dSopenharmony_ci}
1792e5b6d6dSopenharmony_ci
1802e5b6d6dSopenharmony_ci/*
1812e5b6d6dSopenharmony_ci* Test Small, Large letters
1822e5b6d6dSopenharmony_ci*/
1832e5b6d6dSopenharmony_cistatic void TestSmallLarge(void)
1842e5b6d6dSopenharmony_ci{
1852e5b6d6dSopenharmony_ci    int32_t i;
1862e5b6d6dSopenharmony_ci    UErrorCode status = U_ZERO_ERROR;
1872e5b6d6dSopenharmony_ci    myCollation = ucol_open("ja_JP", &status);
1882e5b6d6dSopenharmony_ci    if (U_FAILURE(status))
1892e5b6d6dSopenharmony_ci    {
1902e5b6d6dSopenharmony_ci        log_err_status(status, "ERROR: in creation of rule based collator: %s\n",
1912e5b6d6dSopenharmony_ci            myErrorName(status));
1922e5b6d6dSopenharmony_ci        return;
1932e5b6d6dSopenharmony_ci    }
1942e5b6d6dSopenharmony_ci
1952e5b6d6dSopenharmony_ci    log_verbose("Testing Japanese Small and Large Characters Collation\n");
1962e5b6d6dSopenharmony_ci    ucol_setStrength(myCollation, UCOL_TERTIARY);
1972e5b6d6dSopenharmony_ci    ucol_setAttribute(myCollation, UCOL_CASE_LEVEL, UCOL_ON, &status);
1982e5b6d6dSopenharmony_ci    for (i = 0; i < 3 ; i++)
1992e5b6d6dSopenharmony_ci        doTest(myCollation, testSmallLargeCases[i], testSmallLargeCases[i + 1],
2002e5b6d6dSopenharmony_ci        UCOL_LESS);
2012e5b6d6dSopenharmony_ci
2022e5b6d6dSopenharmony_ci    ucol_close(myCollation);
2032e5b6d6dSopenharmony_ci}
2042e5b6d6dSopenharmony_ci
2052e5b6d6dSopenharmony_ci/*
2062e5b6d6dSopenharmony_ci* Test Katakana, Hiragana letters
2072e5b6d6dSopenharmony_ci*/
2082e5b6d6dSopenharmony_cistatic void TestKatakanaHiragana(void)
2092e5b6d6dSopenharmony_ci{
2102e5b6d6dSopenharmony_ci    int32_t i;
2112e5b6d6dSopenharmony_ci    UErrorCode status = U_ZERO_ERROR;
2122e5b6d6dSopenharmony_ci    myCollation = ucol_open("ja_JP", &status);
2132e5b6d6dSopenharmony_ci    if (U_FAILURE(status))
2142e5b6d6dSopenharmony_ci    {
2152e5b6d6dSopenharmony_ci        log_err_status(status, "ERROR: in creation of rule based collator: %s\n",
2162e5b6d6dSopenharmony_ci            myErrorName(status));
2172e5b6d6dSopenharmony_ci        return;
2182e5b6d6dSopenharmony_ci    }
2192e5b6d6dSopenharmony_ci
2202e5b6d6dSopenharmony_ci    log_verbose("Testing Japanese Katakana, Hiragana Characters Collation\n");
2212e5b6d6dSopenharmony_ci    ucol_setStrength(myCollation, UCOL_QUATERNARY);
2222e5b6d6dSopenharmony_ci    ucol_setAttribute(myCollation, UCOL_CASE_LEVEL, UCOL_ON, &status);
2232e5b6d6dSopenharmony_ci    for (i = 0; i < 3 ; i++) {
2242e5b6d6dSopenharmony_ci        doTest(myCollation, testKatakanaHiraganaCases[i],
2252e5b6d6dSopenharmony_ci            testKatakanaHiraganaCases[i + 1], UCOL_LESS);
2262e5b6d6dSopenharmony_ci    }
2272e5b6d6dSopenharmony_ci
2282e5b6d6dSopenharmony_ci    ucol_close(myCollation);
2292e5b6d6dSopenharmony_ci}
2302e5b6d6dSopenharmony_ci
2312e5b6d6dSopenharmony_ci/*
2322e5b6d6dSopenharmony_ci* Test Choo-on kigoo
2332e5b6d6dSopenharmony_ci*/
2342e5b6d6dSopenharmony_cistatic void TestChooonKigoo(void)
2352e5b6d6dSopenharmony_ci{
2362e5b6d6dSopenharmony_ci    int32_t i;
2372e5b6d6dSopenharmony_ci    UErrorCode status = U_ZERO_ERROR;
2382e5b6d6dSopenharmony_ci    myCollation = ucol_open("ja_JP", &status);
2392e5b6d6dSopenharmony_ci    if (U_FAILURE(status))
2402e5b6d6dSopenharmony_ci    {
2412e5b6d6dSopenharmony_ci        log_err_status(status, "ERROR: in creation of rule based collator: %s\n",
2422e5b6d6dSopenharmony_ci            myErrorName(status));
2432e5b6d6dSopenharmony_ci        return;
2442e5b6d6dSopenharmony_ci    }
2452e5b6d6dSopenharmony_ci
2462e5b6d6dSopenharmony_ci    log_verbose("Testing Japanese Choo-on Kigoo Characters Collation\n");
2472e5b6d6dSopenharmony_ci    ucol_setAttribute(myCollation, UCOL_STRENGTH, UCOL_QUATERNARY, &status);
2482e5b6d6dSopenharmony_ci    ucol_setAttribute(myCollation, UCOL_CASE_LEVEL, UCOL_ON, &status);
2492e5b6d6dSopenharmony_ci    for (i = 0; i < 7 ; i++) {
2502e5b6d6dSopenharmony_ci        doTest(myCollation, testChooonKigooCases[i], testChooonKigooCases[i + 1],
2512e5b6d6dSopenharmony_ci            UCOL_LESS);
2522e5b6d6dSopenharmony_ci    }
2532e5b6d6dSopenharmony_ci
2542e5b6d6dSopenharmony_ci    ucol_close(myCollation);
2552e5b6d6dSopenharmony_ci}
2562e5b6d6dSopenharmony_ci
2572e5b6d6dSopenharmony_ci#endif /* #if !UCONFIG_NO_COLLATION */
258