1/******************************************************************** 2 * COPYRIGHT: 3 * Copyright (c) 1997-2009, International Business Machines Corporation and 4 * others. All Rights Reserved. 5 ********************************************************************/ 6 7#include "unicode/utypes.h" 8 9#if !UCONFIG_NO_COLLATION 10 11#include "unicode/coll.h" 12#include "unicode/tblcoll.h" 13#include "unicode/unistr.h" 14#include "unicode/sortkey.h" 15#include "jacoll.h" 16 17#include "sfwdchit.h" 18 19CollationKanaTest::CollationKanaTest() 20: myCollation(0) 21{ 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: */ 27 delete myCollation; 28 myCollation = NULL; 29 return; 30 } 31} 32 33CollationKanaTest::~CollationKanaTest() 34{ 35 delete myCollation; 36} 37 38const UChar CollationKanaTest::testSourceCases[][CollationKanaTest::MAX_TOKEN_LEN] = { 39 {0xff9E, 0x0000}, 40 {0x3042, 0x0000}, 41 {0x30A2, 0x0000}, 42 {0x3042, 0x3042, 0x0000}, 43 {0x30A2, 0x30FC, 0x0000}, 44 {0x30A2, 0x30FC, 0x30C8, 0x0000} /* 6 */ 45}; 46 47const UChar CollationKanaTest::testTargetCases[][CollationKanaTest::MAX_TOKEN_LEN] = { 48 {0xFF9F, 0x0000}, 49 {0x30A2, 0x0000}, 50 {0x3042, 0x3042, 0x0000}, 51 {0x30A2, 0x30FC, 0x0000}, 52 {0x30A2, 0x30FC, 0x30C8, 0x0000}, 53 {0x3042, 0x3042, 0x3068, 0x0000} /* 6 */ 54}; 55 56const Collator::EComparisonResult CollationKanaTest::results[] = { 57 Collator::LESS, 58 Collator::EQUAL, //Collator::LESS, /* Katakanas and Hiraganas are equal on tertiary level(ICU 2.0)*/ 59 Collator::LESS, 60 Collator::GREATER, // Collator::LESS, /* Prolonged sound mark sorts BEFORE equivalent vowel (ICU 2.0)*/ 61 Collator::LESS, 62 Collator::LESS, //Collator::GREATER /* Prolonged sound mark sorts BEFORE equivalent vowel (ICU 2.0)*//* 6 */ 63}; 64 65const UChar CollationKanaTest::testBaseCases[][CollationKanaTest::MAX_TOKEN_LEN] = { 66 {0x30AB, 0x0000}, 67 {0x30AB, 0x30AD, 0x0000}, 68 {0x30AD, 0x0000}, 69 {0x30AD, 0x30AD, 0x0000} 70}; 71 72const UChar CollationKanaTest::testPlainDakutenHandakutenCases[][CollationKanaTest::MAX_TOKEN_LEN] = { 73 {0x30CF, 0x30AB, 0x0000}, 74 {0x30D0, 0x30AB, 0x0000}, 75 {0x30CF, 0x30AD, 0x0000}, 76 {0x30D0, 0x30AD, 0x0000} 77}; 78 79const UChar CollationKanaTest::testSmallLargeCases[][CollationKanaTest::MAX_TOKEN_LEN] = { 80 {0x30C3, 0x30CF, 0x0000}, 81 {0x30C4, 0x30CF, 0x0000}, 82 {0x30C3, 0x30D0, 0x0000}, 83 {0x30C4, 0x30D0, 0x0000} 84}; 85 86const UChar CollationKanaTest::testKatakanaHiraganaCases[][CollationKanaTest::MAX_TOKEN_LEN] = { 87 {0x3042, 0x30C3, 0x0000}, 88 {0x30A2, 0x30C3, 0x0000}, 89 {0x3042, 0x30C4, 0x0000}, 90 {0x30A2, 0x30C4, 0x0000} 91}; 92 93const 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}, 102}; 103 104void CollationKanaTest::TestTertiary(/* char* par */) 105{ 106 int32_t i = 0; 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]); 115 } 116} 117 118/* Testing base letters */ 119void CollationKanaTest::TestBase() 120{ 121 int32_t i; 122 myCollation->setStrength(Collator::PRIMARY); 123 for (i = 0; i < 3 ; i++) 124 doTest(myCollation, testBaseCases[i], testBaseCases[i + 1], Collator::LESS); 125} 126 127/* Testing plain, Daku-ten, Handaku-ten letters */ 128void CollationKanaTest::TestPlainDakutenHandakuten(void) 129{ 130 int32_t i; 131 myCollation->setStrength(Collator::SECONDARY); 132 for (i = 0; i < 3 ; i++) 133 doTest(myCollation, testPlainDakutenHandakutenCases[i], testPlainDakutenHandakutenCases[i + 1], 134 Collator::LESS); 135} 136 137/* 138* Test Small, Large letters 139*/ 140void CollationKanaTest::TestSmallLarge(void) 141{ 142 int32_t i; 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); 148} 149 150/* 151* Test Katakana, Hiragana letters 152*/ 153void CollationKanaTest::TestKatakanaHiragana(void) 154{ 155 int32_t i; 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], 161 Collator::LESS); 162 } 163} 164 165/* 166* Test Choo-on kigoo 167*/ 168void CollationKanaTest::TestChooonKigoo(void) 169{ 170 int32_t i; 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); 176 } 177} 178 179 180void CollationKanaTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ ) 181{ 182 if (exec) logln("TestSuite CollationKanaTest: "); 183 if(myCollation) { 184 switch (index) { 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; 192 } 193 } else { 194 dataerrln("Collator couldn't be instantiated!"); 195 name = ""; 196 } 197} 198 199#endif /* #if !UCONFIG_NO_COLLATION */ 200