1 /********************************************************************
3 * Copyright (c) 1997-2009, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
7 #include "unicode/utypes.h"
9 #if !UCONFIG_NO_COLLATION
11 #include "unicode/coll.h"
12 #include "unicode/tblcoll.h"
13 #include "unicode/unistr.h"
14 #include "unicode/sortkey.h"
19 CollationKanaTest::CollationKanaTest()
22 UErrorCode status
= U_ZERO_ERROR
;
23 myCollation
= Collator::createInstance(Locale::getJapan(), status
);
24 if(!myCollation
|| U_FAILURE(status
)) {
25 errcheckln(status
, __FILE__
"failed to create! err " + UnicodeString(u_errorName(status
)));
26 /* if it wasn't already: */
33 CollationKanaTest::~CollationKanaTest()
38 const UChar
CollationKanaTest::testSourceCases
[][CollationKanaTest::MAX_TOKEN_LEN
] = {
42 {0x3042, 0x3042, 0x0000},
43 {0x30A2, 0x30FC, 0x0000},
44 {0x30A2, 0x30FC, 0x30C8, 0x0000} /* 6 */
47 const UChar
CollationKanaTest::testTargetCases
[][CollationKanaTest::MAX_TOKEN_LEN
] = {
50 {0x3042, 0x3042, 0x0000},
51 {0x30A2, 0x30FC, 0x0000},
52 {0x30A2, 0x30FC, 0x30C8, 0x0000},
53 {0x3042, 0x3042, 0x3068, 0x0000} /* 6 */
56 const Collator::EComparisonResult
CollationKanaTest::results
[] = {
58 Collator::EQUAL
, //Collator::LESS, /* Katakanas and Hiraganas are equal on tertiary level(ICU 2.0)*/
60 Collator::GREATER
, // Collator::LESS, /* Prolonged sound mark sorts BEFORE equivalent vowel (ICU 2.0)*/
62 Collator::LESS
, //Collator::GREATER /* Prolonged sound mark sorts BEFORE equivalent vowel (ICU 2.0)*//* 6 */
65 const UChar
CollationKanaTest::testBaseCases
[][CollationKanaTest::MAX_TOKEN_LEN
] = {
67 {0x30AB, 0x30AD, 0x0000},
69 {0x30AD, 0x30AD, 0x0000}
72 const UChar
CollationKanaTest::testPlainDakutenHandakutenCases
[][CollationKanaTest::MAX_TOKEN_LEN
] = {
73 {0x30CF, 0x30AB, 0x0000},
74 {0x30D0, 0x30AB, 0x0000},
75 {0x30CF, 0x30AD, 0x0000},
76 {0x30D0, 0x30AD, 0x0000}
79 const UChar
CollationKanaTest::testSmallLargeCases
[][CollationKanaTest::MAX_TOKEN_LEN
] = {
80 {0x30C3, 0x30CF, 0x0000},
81 {0x30C4, 0x30CF, 0x0000},
82 {0x30C3, 0x30D0, 0x0000},
83 {0x30C4, 0x30D0, 0x0000}
86 const UChar
CollationKanaTest::testKatakanaHiraganaCases
[][CollationKanaTest::MAX_TOKEN_LEN
] = {
87 {0x3042, 0x30C3, 0x0000},
88 {0x30A2, 0x30C3, 0x0000},
89 {0x3042, 0x30C4, 0x0000},
90 {0x30A2, 0x30C4, 0x0000}
93 const UChar
CollationKanaTest::testChooonKigooCases
[][CollationKanaTest::MAX_TOKEN_LEN
] = {
94 /*0*/ {0x30AB, 0x30FC, 0x3042, 0x0000},
95 /*1*/ {0x30AB, 0x30FC, 0x30A2, 0x0000},
96 /*2*/ {0x30AB, 0x30A4, 0x3042, 0x0000},
97 /*3*/ {0x30AB, 0x30A4, 0x30A2, 0x0000},
98 /*6*/ {0x30AD, 0x30FC, 0x3042, 0x0000}, /* Prolonged sound mark sorts BEFORE equivalent vowel (ICU 2.0)*/
99 /*7*/ {0x30AD, 0x30FC, 0x30A2, 0x0000}, /* Prolonged sound mark sorts BEFORE equivalent vowel (ICU 2.0)*/
100 /*4*/ {0x30AD, 0x30A4, 0x3042, 0x0000},
101 /*5*/ {0x30AD, 0x30A4, 0x30A2, 0x0000},
104 void CollationKanaTest::TestTertiary(/* char* par */)
107 UErrorCode status
= U_ZERO_ERROR
;
108 myCollation
->setStrength(Collator::TERTIARY
);
109 /* for one case, strcollinc fails, since it doesn't have good handling of contractions*/
110 /* normalization is turned off to stop strcollinc from executing */
111 myCollation
->setAttribute(UCOL_NORMALIZATION_MODE
, UCOL_ON
, status
);
112 myCollation
->setAttribute(UCOL_CASE_LEVEL
, UCOL_ON
, status
);
113 for (i
= 0; i
< 6; i
++) {
114 doTest(myCollation
, testSourceCases
[i
], testTargetCases
[i
], results
[i
]);
118 /* Testing base letters */
119 void CollationKanaTest::TestBase()
122 myCollation
->setStrength(Collator::PRIMARY
);
123 for (i
= 0; i
< 3 ; i
++)
124 doTest(myCollation
, testBaseCases
[i
], testBaseCases
[i
+ 1], Collator::LESS
);
127 /* Testing plain, Daku-ten, Handaku-ten letters */
128 void CollationKanaTest::TestPlainDakutenHandakuten(void)
131 myCollation
->setStrength(Collator::SECONDARY
);
132 for (i
= 0; i
< 3 ; i
++)
133 doTest(myCollation
, testPlainDakutenHandakutenCases
[i
], testPlainDakutenHandakutenCases
[i
+ 1],
138 * Test Small, Large letters
140 void CollationKanaTest::TestSmallLarge(void)
143 UErrorCode status
= U_ZERO_ERROR
;
144 myCollation
->setStrength(Collator::TERTIARY
);
145 myCollation
->setAttribute(UCOL_CASE_LEVEL
, UCOL_ON
, status
);
146 for (i
= 0; i
< 3 ; i
++)
147 doTest(myCollation
, testSmallLargeCases
[i
], testSmallLargeCases
[i
+ 1], Collator::LESS
);
151 * Test Katakana, Hiragana letters
153 void CollationKanaTest::TestKatakanaHiragana(void)
156 UErrorCode status
= U_ZERO_ERROR
;
157 myCollation
->setStrength(Collator::QUATERNARY
);
158 myCollation
->setAttribute(UCOL_CASE_LEVEL
, UCOL_ON
, status
);
159 for (i
= 0; i
< 3 ; i
++) {
160 doTest(myCollation
, testKatakanaHiraganaCases
[i
], testKatakanaHiraganaCases
[i
+ 1],
168 void CollationKanaTest::TestChooonKigoo(void)
171 UErrorCode status
= U_ZERO_ERROR
;
172 myCollation
->setStrength(Collator::QUATERNARY
);
173 myCollation
->setAttribute(UCOL_CASE_LEVEL
, UCOL_ON
, status
);
174 for (i
= 0; i
< 7 ; i
++) {
175 doTest(myCollation
, testChooonKigooCases
[i
], testChooonKigooCases
[i
+ 1], Collator::LESS
);
180 void CollationKanaTest::runIndexedTest( int32_t index
, UBool exec
, const char* &name
, char* /*par*/ )
182 if (exec
) logln("TestSuite CollationKanaTest: ");
185 case 0: name
= "TestTertiary"; if (exec
) TestTertiary(/* par */); break;
186 case 1: name
= "TestBase"; if (exec
) TestBase(/* par */); break;
187 case 2: name
= "TestSmallLarge"; if (exec
) TestSmallLarge(/* par */); break;
188 case 3: name
= "TestTestPlainDakutenHandakuten"; if (exec
) TestPlainDakutenHandakuten(/* par */); break;
189 case 4: name
= "TestKatakanaHiragana"; if (exec
) TestKatakanaHiragana(/* par */); break;
190 case 5: name
= "TestChooonKigoo"; if (exec
) TestChooonKigoo(/* par */); break;
191 default: name
= ""; break;
194 dataerrln("Collator couldn't be instantiated!");
199 #endif /* #if !UCONFIG_NO_COLLATION */