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#include "unicode/utypes.h" 102e5b6d6dSopenharmony_ci 112e5b6d6dSopenharmony_ci#if !UCONFIG_NO_COLLATION 122e5b6d6dSopenharmony_ci 132e5b6d6dSopenharmony_ci#include "unicode/coll.h" 142e5b6d6dSopenharmony_ci#include "unicode/tblcoll.h" 152e5b6d6dSopenharmony_ci#include "unicode/unistr.h" 162e5b6d6dSopenharmony_ci#include "unicode/sortkey.h" 172e5b6d6dSopenharmony_ci#include "jacoll.h" 182e5b6d6dSopenharmony_ci 192e5b6d6dSopenharmony_ci#include "sfwdchit.h" 202e5b6d6dSopenharmony_ci 212e5b6d6dSopenharmony_ciCollationKanaTest::CollationKanaTest() 222e5b6d6dSopenharmony_ci: myCollation(0) 232e5b6d6dSopenharmony_ci{ 242e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 252e5b6d6dSopenharmony_ci myCollation = Collator::createInstance(Locale::getJapan(), status); 262e5b6d6dSopenharmony_ci if(!myCollation || U_FAILURE(status)) { 272e5b6d6dSopenharmony_ci errcheckln(status, __FILE__ "failed to create! err " + UnicodeString(u_errorName(status))); 282e5b6d6dSopenharmony_ci /* if it wasn't already: */ 292e5b6d6dSopenharmony_ci delete myCollation; 302e5b6d6dSopenharmony_ci myCollation = NULL; 312e5b6d6dSopenharmony_ci return; 322e5b6d6dSopenharmony_ci } 332e5b6d6dSopenharmony_ci} 342e5b6d6dSopenharmony_ci 352e5b6d6dSopenharmony_ciCollationKanaTest::~CollationKanaTest() 362e5b6d6dSopenharmony_ci{ 372e5b6d6dSopenharmony_ci delete myCollation; 382e5b6d6dSopenharmony_ci} 392e5b6d6dSopenharmony_ci 402e5b6d6dSopenharmony_ciconst UChar CollationKanaTest::testSourceCases[][CollationKanaTest::MAX_TOKEN_LEN] = { 412e5b6d6dSopenharmony_ci {0xff9E, 0x0000}, 422e5b6d6dSopenharmony_ci {0x3042, 0x0000}, 432e5b6d6dSopenharmony_ci {0x30A2, 0x0000}, 442e5b6d6dSopenharmony_ci {0x3042, 0x3042, 0x0000}, 452e5b6d6dSopenharmony_ci {0x30A2, 0x30FC, 0x0000}, 462e5b6d6dSopenharmony_ci {0x30A2, 0x30FC, 0x30C8, 0x0000} /* 6 */ 472e5b6d6dSopenharmony_ci}; 482e5b6d6dSopenharmony_ci 492e5b6d6dSopenharmony_ciconst UChar CollationKanaTest::testTargetCases[][CollationKanaTest::MAX_TOKEN_LEN] = { 502e5b6d6dSopenharmony_ci {0xFF9F, 0x0000}, 512e5b6d6dSopenharmony_ci {0x30A2, 0x0000}, 522e5b6d6dSopenharmony_ci {0x3042, 0x3042, 0x0000}, 532e5b6d6dSopenharmony_ci {0x30A2, 0x30FC, 0x0000}, 542e5b6d6dSopenharmony_ci {0x30A2, 0x30FC, 0x30C8, 0x0000}, 552e5b6d6dSopenharmony_ci {0x3042, 0x3042, 0x3068, 0x0000} /* 6 */ 562e5b6d6dSopenharmony_ci}; 572e5b6d6dSopenharmony_ci 582e5b6d6dSopenharmony_ciconst Collator::EComparisonResult CollationKanaTest::results[] = { 592e5b6d6dSopenharmony_ci Collator::LESS, 602e5b6d6dSopenharmony_ci Collator::EQUAL, //Collator::LESS, /* Katakanas and Hiraganas are equal on tertiary level(ICU 2.0)*/ 612e5b6d6dSopenharmony_ci Collator::LESS, 622e5b6d6dSopenharmony_ci Collator::GREATER, // Collator::LESS, /* Prolonged sound mark sorts BEFORE equivalent vowel (ICU 2.0)*/ 632e5b6d6dSopenharmony_ci Collator::LESS, 642e5b6d6dSopenharmony_ci Collator::LESS, //Collator::GREATER /* Prolonged sound mark sorts BEFORE equivalent vowel (ICU 2.0)*//* 6 */ 652e5b6d6dSopenharmony_ci}; 662e5b6d6dSopenharmony_ci 672e5b6d6dSopenharmony_ciconst UChar CollationKanaTest::testBaseCases[][CollationKanaTest::MAX_TOKEN_LEN] = { 682e5b6d6dSopenharmony_ci {0x30AB, 0x0000}, 692e5b6d6dSopenharmony_ci {0x30AB, 0x30AD, 0x0000}, 702e5b6d6dSopenharmony_ci {0x30AD, 0x0000}, 712e5b6d6dSopenharmony_ci {0x30AD, 0x30AD, 0x0000} 722e5b6d6dSopenharmony_ci}; 732e5b6d6dSopenharmony_ci 742e5b6d6dSopenharmony_ciconst UChar CollationKanaTest::testPlainDakutenHandakutenCases[][CollationKanaTest::MAX_TOKEN_LEN] = { 752e5b6d6dSopenharmony_ci {0x30CF, 0x30AB, 0x0000}, 762e5b6d6dSopenharmony_ci {0x30D0, 0x30AB, 0x0000}, 772e5b6d6dSopenharmony_ci {0x30CF, 0x30AD, 0x0000}, 782e5b6d6dSopenharmony_ci {0x30D0, 0x30AD, 0x0000} 792e5b6d6dSopenharmony_ci}; 802e5b6d6dSopenharmony_ci 812e5b6d6dSopenharmony_ciconst UChar CollationKanaTest::testSmallLargeCases[][CollationKanaTest::MAX_TOKEN_LEN] = { 822e5b6d6dSopenharmony_ci {0x30C3, 0x30CF, 0x0000}, 832e5b6d6dSopenharmony_ci {0x30C4, 0x30CF, 0x0000}, 842e5b6d6dSopenharmony_ci {0x30C3, 0x30D0, 0x0000}, 852e5b6d6dSopenharmony_ci {0x30C4, 0x30D0, 0x0000} 862e5b6d6dSopenharmony_ci}; 872e5b6d6dSopenharmony_ci 882e5b6d6dSopenharmony_ciconst UChar CollationKanaTest::testKatakanaHiraganaCases[][CollationKanaTest::MAX_TOKEN_LEN] = { 892e5b6d6dSopenharmony_ci {0x3042, 0x30C3, 0x0000}, 902e5b6d6dSopenharmony_ci {0x30A2, 0x30C3, 0x0000}, 912e5b6d6dSopenharmony_ci {0x3042, 0x30C4, 0x0000}, 922e5b6d6dSopenharmony_ci {0x30A2, 0x30C4, 0x0000} 932e5b6d6dSopenharmony_ci}; 942e5b6d6dSopenharmony_ci 952e5b6d6dSopenharmony_ciconst UChar CollationKanaTest::testChooonKigooCases[][CollationKanaTest::MAX_TOKEN_LEN] = { 962e5b6d6dSopenharmony_ci /*0*/ {0x30AB, 0x30FC, 0x3042, 0x0000}, 972e5b6d6dSopenharmony_ci /*1*/ {0x30AB, 0x30FC, 0x30A2, 0x0000}, 982e5b6d6dSopenharmony_ci /*2*/ {0x30AB, 0x30A4, 0x3042, 0x0000}, 992e5b6d6dSopenharmony_ci /*3*/ {0x30AB, 0x30A4, 0x30A2, 0x0000}, 1002e5b6d6dSopenharmony_ci /*6*/ {0x30AD, 0x30FC, 0x3042, 0x0000}, /* Prolonged sound mark sorts BEFORE equivalent vowel (ICU 2.0)*/ 1012e5b6d6dSopenharmony_ci /*7*/ {0x30AD, 0x30FC, 0x30A2, 0x0000}, /* Prolonged sound mark sorts BEFORE equivalent vowel (ICU 2.0)*/ 1022e5b6d6dSopenharmony_ci /*4*/ {0x30AD, 0x30A4, 0x3042, 0x0000}, 1032e5b6d6dSopenharmony_ci /*5*/ {0x30AD, 0x30A4, 0x30A2, 0x0000}, 1042e5b6d6dSopenharmony_ci}; 1052e5b6d6dSopenharmony_ci 1062e5b6d6dSopenharmony_civoid CollationKanaTest::TestTertiary(/* char* par */) 1072e5b6d6dSopenharmony_ci{ 1082e5b6d6dSopenharmony_ci int32_t i = 0; 1092e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 1102e5b6d6dSopenharmony_ci myCollation->setStrength(Collator::TERTIARY); 1112e5b6d6dSopenharmony_ci /* for one case, strcollinc fails, since it doesn't have good handling of contractions*/ 1122e5b6d6dSopenharmony_ci /* normalization is turned off to stop strcollinc from executing */ 1132e5b6d6dSopenharmony_ci myCollation->setAttribute(UCOL_NORMALIZATION_MODE, UCOL_ON, status); 1142e5b6d6dSopenharmony_ci myCollation->setAttribute(UCOL_CASE_LEVEL, UCOL_ON, status); 1152e5b6d6dSopenharmony_ci for (i = 0; i < 6; i++) { 1162e5b6d6dSopenharmony_ci doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]); 1172e5b6d6dSopenharmony_ci } 1182e5b6d6dSopenharmony_ci} 1192e5b6d6dSopenharmony_ci 1202e5b6d6dSopenharmony_ci/* Testing base letters */ 1212e5b6d6dSopenharmony_civoid CollationKanaTest::TestBase() 1222e5b6d6dSopenharmony_ci{ 1232e5b6d6dSopenharmony_ci int32_t i; 1242e5b6d6dSopenharmony_ci myCollation->setStrength(Collator::PRIMARY); 1252e5b6d6dSopenharmony_ci for (i = 0; i < 3 ; i++) 1262e5b6d6dSopenharmony_ci doTest(myCollation, testBaseCases[i], testBaseCases[i + 1], Collator::LESS); 1272e5b6d6dSopenharmony_ci} 1282e5b6d6dSopenharmony_ci 1292e5b6d6dSopenharmony_ci/* Testing plain, Daku-ten, Handaku-ten letters */ 1302e5b6d6dSopenharmony_civoid CollationKanaTest::TestPlainDakutenHandakuten(void) 1312e5b6d6dSopenharmony_ci{ 1322e5b6d6dSopenharmony_ci int32_t i; 1332e5b6d6dSopenharmony_ci myCollation->setStrength(Collator::SECONDARY); 1342e5b6d6dSopenharmony_ci for (i = 0; i < 3 ; i++) 1352e5b6d6dSopenharmony_ci doTest(myCollation, testPlainDakutenHandakutenCases[i], testPlainDakutenHandakutenCases[i + 1], 1362e5b6d6dSopenharmony_ci Collator::LESS); 1372e5b6d6dSopenharmony_ci} 1382e5b6d6dSopenharmony_ci 1392e5b6d6dSopenharmony_ci/* 1402e5b6d6dSopenharmony_ci* Test Small, Large letters 1412e5b6d6dSopenharmony_ci*/ 1422e5b6d6dSopenharmony_civoid CollationKanaTest::TestSmallLarge(void) 1432e5b6d6dSopenharmony_ci{ 1442e5b6d6dSopenharmony_ci int32_t i; 1452e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 1462e5b6d6dSopenharmony_ci myCollation->setStrength(Collator::TERTIARY); 1472e5b6d6dSopenharmony_ci myCollation->setAttribute(UCOL_CASE_LEVEL, UCOL_ON, status); 1482e5b6d6dSopenharmony_ci for (i = 0; i < 3 ; i++) 1492e5b6d6dSopenharmony_ci doTest(myCollation, testSmallLargeCases[i], testSmallLargeCases[i + 1], Collator::LESS); 1502e5b6d6dSopenharmony_ci} 1512e5b6d6dSopenharmony_ci 1522e5b6d6dSopenharmony_ci/* 1532e5b6d6dSopenharmony_ci* Test Katakana, Hiragana letters 1542e5b6d6dSopenharmony_ci*/ 1552e5b6d6dSopenharmony_civoid CollationKanaTest::TestKatakanaHiragana(void) 1562e5b6d6dSopenharmony_ci{ 1572e5b6d6dSopenharmony_ci int32_t i; 1582e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 1592e5b6d6dSopenharmony_ci myCollation->setStrength(Collator::QUATERNARY); 1602e5b6d6dSopenharmony_ci myCollation->setAttribute(UCOL_CASE_LEVEL, UCOL_ON, status); 1612e5b6d6dSopenharmony_ci for (i = 0; i < 3 ; i++) { 1622e5b6d6dSopenharmony_ci doTest(myCollation, testKatakanaHiraganaCases[i], testKatakanaHiraganaCases[i + 1], 1632e5b6d6dSopenharmony_ci Collator::LESS); 1642e5b6d6dSopenharmony_ci } 1652e5b6d6dSopenharmony_ci} 1662e5b6d6dSopenharmony_ci 1672e5b6d6dSopenharmony_ci/* 1682e5b6d6dSopenharmony_ci* Test Choo-on kigoo 1692e5b6d6dSopenharmony_ci*/ 1702e5b6d6dSopenharmony_civoid CollationKanaTest::TestChooonKigoo(void) 1712e5b6d6dSopenharmony_ci{ 1722e5b6d6dSopenharmony_ci int32_t i; 1732e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 1742e5b6d6dSopenharmony_ci myCollation->setStrength(Collator::QUATERNARY); 1752e5b6d6dSopenharmony_ci myCollation->setAttribute(UCOL_CASE_LEVEL, UCOL_ON, status); 1762e5b6d6dSopenharmony_ci for (i = 0; i < 7 ; i++) { 1772e5b6d6dSopenharmony_ci doTest(myCollation, testChooonKigooCases[i], testChooonKigooCases[i + 1], Collator::LESS); 1782e5b6d6dSopenharmony_ci } 1792e5b6d6dSopenharmony_ci} 1802e5b6d6dSopenharmony_ci 1812e5b6d6dSopenharmony_ci 1822e5b6d6dSopenharmony_civoid CollationKanaTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ ) 1832e5b6d6dSopenharmony_ci{ 1842e5b6d6dSopenharmony_ci if (exec) logln("TestSuite CollationKanaTest: "); 1852e5b6d6dSopenharmony_ci if(myCollation) { 1862e5b6d6dSopenharmony_ci switch (index) { 1872e5b6d6dSopenharmony_ci case 0: name = "TestTertiary"; if (exec) TestTertiary(/* par */); break; 1882e5b6d6dSopenharmony_ci case 1: name = "TestBase"; if (exec) TestBase(/* par */); break; 1892e5b6d6dSopenharmony_ci case 2: name = "TestSmallLarge"; if (exec) TestSmallLarge(/* par */); break; 1902e5b6d6dSopenharmony_ci case 3: name = "TestTestPlainDakutenHandakuten"; if (exec) TestPlainDakutenHandakuten(/* par */); break; 1912e5b6d6dSopenharmony_ci case 4: name = "TestKatakanaHiragana"; if (exec) TestKatakanaHiragana(/* par */); break; 1922e5b6d6dSopenharmony_ci case 5: name = "TestChooonKigoo"; if (exec) TestChooonKigoo(/* par */); break; 1932e5b6d6dSopenharmony_ci default: name = ""; break; 1942e5b6d6dSopenharmony_ci } 1952e5b6d6dSopenharmony_ci } else { 1962e5b6d6dSopenharmony_ci dataerrln("Collator couldn't be instantiated!"); 1972e5b6d6dSopenharmony_ci name = ""; 1982e5b6d6dSopenharmony_ci } 1992e5b6d6dSopenharmony_ci} 2002e5b6d6dSopenharmony_ci 2012e5b6d6dSopenharmony_ci#endif /* #if !UCONFIG_NO_COLLATION */ 202