1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /********************************************************************
5 * Copyright (c) 1997-2009, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 ********************************************************************/
9 #include "unicode/utypes.h"
11 #if !UCONFIG_NO_COLLATION
13 #include "unicode/coll.h"
14 #include "unicode/tblcoll.h"
15 #include "unicode/unistr.h"
16 #include "unicode/sortkey.h"
21 CollationKanaTest::CollationKanaTest()
24 UErrorCode status = U_ZERO_ERROR;
25 myCollation = Collator::createInstance(Locale::getJapan(), status);
26 if(!myCollation || U_FAILURE(status)) {
27 errcheckln(status, __FILE__ "failed to create! err " + UnicodeString(u_errorName(status)));
28 /* if it wasn't already: */
35 CollationKanaTest::~CollationKanaTest()
40 const UChar CollationKanaTest::testSourceCases[][CollationKanaTest::MAX_TOKEN_LEN] = {
44 {0x3042, 0x3042, 0x0000},
45 {0x30A2, 0x30FC, 0x0000},
46 {0x30A2, 0x30FC, 0x30C8, 0x0000} /* 6 */
49 const UChar CollationKanaTest::testTargetCases[][CollationKanaTest::MAX_TOKEN_LEN] = {
52 {0x3042, 0x3042, 0x0000},
53 {0x30A2, 0x30FC, 0x0000},
54 {0x30A2, 0x30FC, 0x30C8, 0x0000},
55 {0x3042, 0x3042, 0x3068, 0x0000} /* 6 */
58 const Collator::EComparisonResult CollationKanaTest::results[] = {
60 Collator::EQUAL, //Collator::LESS, /* Katakanas and Hiraganas are equal on tertiary level(ICU 2.0)*/
62 Collator::GREATER, // Collator::LESS, /* Prolonged sound mark sorts BEFORE equivalent vowel (ICU 2.0)*/
64 Collator::LESS, //Collator::GREATER /* Prolonged sound mark sorts BEFORE equivalent vowel (ICU 2.0)*//* 6 */
67 const UChar CollationKanaTest::testBaseCases[][CollationKanaTest::MAX_TOKEN_LEN] = {
69 {0x30AB, 0x30AD, 0x0000},
71 {0x30AD, 0x30AD, 0x0000}
74 const UChar CollationKanaTest::testPlainDakutenHandakutenCases[][CollationKanaTest::MAX_TOKEN_LEN] = {
75 {0x30CF, 0x30AB, 0x0000},
76 {0x30D0, 0x30AB, 0x0000},
77 {0x30CF, 0x30AD, 0x0000},
78 {0x30D0, 0x30AD, 0x0000}
81 const UChar CollationKanaTest::testSmallLargeCases[][CollationKanaTest::MAX_TOKEN_LEN] = {
82 {0x30C3, 0x30CF, 0x0000},
83 {0x30C4, 0x30CF, 0x0000},
84 {0x30C3, 0x30D0, 0x0000},
85 {0x30C4, 0x30D0, 0x0000}
88 const UChar CollationKanaTest::testKatakanaHiraganaCases[][CollationKanaTest::MAX_TOKEN_LEN] = {
89 {0x3042, 0x30C3, 0x0000},
90 {0x30A2, 0x30C3, 0x0000},
91 {0x3042, 0x30C4, 0x0000},
92 {0x30A2, 0x30C4, 0x0000}
95 const UChar CollationKanaTest::testChooonKigooCases[][CollationKanaTest::MAX_TOKEN_LEN] = {
96 /*0*/ {0x30AB, 0x30FC, 0x3042, 0x0000},
97 /*1*/ {0x30AB, 0x30FC, 0x30A2, 0x0000},
98 /*2*/ {0x30AB, 0x30A4, 0x3042, 0x0000},
99 /*3*/ {0x30AB, 0x30A4, 0x30A2, 0x0000},
100 /*6*/ {0x30AD, 0x30FC, 0x3042, 0x0000}, /* Prolonged sound mark sorts BEFORE equivalent vowel (ICU 2.0)*/
101 /*7*/ {0x30AD, 0x30FC, 0x30A2, 0x0000}, /* Prolonged sound mark sorts BEFORE equivalent vowel (ICU 2.0)*/
102 /*4*/ {0x30AD, 0x30A4, 0x3042, 0x0000},
103 /*5*/ {0x30AD, 0x30A4, 0x30A2, 0x0000},
106 void CollationKanaTest::TestTertiary(/* char* par */)
109 UErrorCode status = U_ZERO_ERROR;
110 myCollation->setStrength(Collator::TERTIARY);
111 /* for one case, strcollinc fails, since it doesn't have good handling of contractions*/
112 /* normalization is turned off to stop strcollinc from executing */
113 myCollation->setAttribute(UCOL_NORMALIZATION_MODE, UCOL_ON, status);
114 myCollation->setAttribute(UCOL_CASE_LEVEL, UCOL_ON, status);
115 for (i = 0; i < 6; i++) {
116 doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]);
120 /* Testing base letters */
121 void CollationKanaTest::TestBase()
124 myCollation->setStrength(Collator::PRIMARY);
125 for (i = 0; i < 3 ; i++)
126 doTest(myCollation, testBaseCases[i], testBaseCases[i + 1], Collator::LESS);
129 /* Testing plain, Daku-ten, Handaku-ten letters */
130 void CollationKanaTest::TestPlainDakutenHandakuten(void)
133 myCollation->setStrength(Collator::SECONDARY);
134 for (i = 0; i < 3 ; i++)
135 doTest(myCollation, testPlainDakutenHandakutenCases[i], testPlainDakutenHandakutenCases[i + 1],
140 * Test Small, Large letters
142 void CollationKanaTest::TestSmallLarge(void)
145 UErrorCode status = U_ZERO_ERROR;
146 myCollation->setStrength(Collator::TERTIARY);
147 myCollation->setAttribute(UCOL_CASE_LEVEL, UCOL_ON, status);
148 for (i = 0; i < 3 ; i++)
149 doTest(myCollation, testSmallLargeCases[i], testSmallLargeCases[i + 1], Collator::LESS);
153 * Test Katakana, Hiragana letters
155 void CollationKanaTest::TestKatakanaHiragana(void)
158 UErrorCode status = U_ZERO_ERROR;
159 myCollation->setStrength(Collator::QUATERNARY);
160 myCollation->setAttribute(UCOL_CASE_LEVEL, UCOL_ON, status);
161 for (i = 0; i < 3 ; i++) {
162 doTest(myCollation, testKatakanaHiraganaCases[i], testKatakanaHiraganaCases[i + 1],
170 void CollationKanaTest::TestChooonKigoo(void)
173 UErrorCode status = U_ZERO_ERROR;
174 myCollation->setStrength(Collator::QUATERNARY);
175 myCollation->setAttribute(UCOL_CASE_LEVEL, UCOL_ON, status);
176 for (i = 0; i < 7 ; i++) {
177 doTest(myCollation, testChooonKigooCases[i], testChooonKigooCases[i + 1], Collator::LESS);
182 void CollationKanaTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ )
184 if (exec) logln("TestSuite CollationKanaTest: ");
187 case 0: name = "TestTertiary"; if (exec) TestTertiary(/* par */); break;
188 case 1: name = "TestBase"; if (exec) TestBase(/* par */); break;
189 case 2: name = "TestSmallLarge"; if (exec) TestSmallLarge(/* par */); break;
190 case 3: name = "TestTestPlainDakutenHandakuten"; if (exec) TestPlainDakutenHandakuten(/* par */); break;
191 case 4: name = "TestKatakanaHiragana"; if (exec) TestKatakanaHiragana(/* par */); break;
192 case 5: name = "TestChooonKigoo"; if (exec) TestChooonKigoo(/* par */); break;
193 default: name = ""; break;
196 dataerrln("Collator couldn't be instantiated!");
201 #endif /* #if !UCONFIG_NO_COLLATION */