1/******************************************************************** 2 * COPYRIGHT: 3 * Copyright (c) 1997-2009, International Business Machines Corporation and 4 * others. All Rights Reserved. 5 ********************************************************************/ 6/******************************************************************************** 7* 8* File CJAPTST.C 9* 10* Modification History: 11* Name Description 12* Madhu Katragadda Ported for C API 13* synwee Added TestBase, TestPlainDakutenHandakuten, 14* TestSmallLarge, TestKatakanaHiragana, 15* TestChooonKigoo 16*********************************************************************************/ 17/** 18 * CollationKannaTest is a third level test class. This tests the locale 19 * specific primary, secondary and tertiary rules. For example, the ignorable 20 * character '-' in string "black-bird". The en_US locale uses the default 21 * collation rules as its sorting sequence. 22 */ 23 24#include <stdlib.h> 25 26#include "unicode/utypes.h" 27 28#if !UCONFIG_NO_COLLATION 29 30#include "unicode/ucol.h" 31#include "unicode/uloc.h" 32#include "cintltst.h" 33#include "ccolltst.h" 34#include "callcoll.h" 35#include "cjaptst.h" 36#include "unicode/ustring.h" 37#include "string.h" 38 39static UCollator *myCollation; 40const static UChar testSourceCases[][MAX_TOKEN_LEN] = { 41 {0xff9E, 0x0000}, 42 {0x3042, 0x0000}, 43 {0x30A2, 0x0000}, 44 {0x3042, 0x3042, 0x0000}, 45 {0x30A2, 0x30FC, 0x0000}, 46 {0x30A2, 0x30FC, 0x30C8, 0x0000} /* 6 */ 47}; 48 49const static UChar testTargetCases[][MAX_TOKEN_LEN] = { 50 {0xFF9F, 0x0000}, 51 {0x30A2, 0x0000}, 52 {0x3042, 0x3042, 0x0000}, 53 {0x30A2, 0x30FC, 0x0000}, 54 {0x30A2, 0x30FC, 0x30C8, 0x0000}, 55 {0x3042, 0x3042, 0x3068, 0x0000} /* 6 */ 56}; 57 58const static UCollationResult results[] = { 59 UCOL_LESS, 60 UCOL_EQUAL, /*UCOL_LESS*/ /* Katakanas and Hiraganas are equal on tertiary level(ICU 2.0)*/ 61 UCOL_LESS, 62 UCOL_GREATER, /*UCOL_LESS*/ /* Prolonged sound mark sorts BEFORE equivalent vowel (ICU 2.0)*/ 63 UCOL_LESS, 64 UCOL_LESS, /*UCOL_GREATER*/ /* Prolonged sound mark sorts BEFORE equivalent vowel (ICU 2.0)*//* 6 */ 65}; 66 67const static UChar testBaseCases[][MAX_TOKEN_LEN] = { 68 {0x30AB, 0x0000}, 69 {0x30AB, 0x30AD, 0x0000}, 70 {0x30AD, 0x0000}, 71 {0x30AD, 0x30AD, 0x0000} 72}; 73 74const static UChar testPlainDakutenHandakutenCases[][MAX_TOKEN_LEN] = { 75 {0x30CF, 0x30AB, 0x0000}, 76 {0x30D0, 0x30AB, 0x0000}, 77 {0x30CF, 0x30AD, 0x0000}, 78 {0x30D0, 0x30AD, 0x0000} 79}; 80 81const static UChar testSmallLargeCases[][MAX_TOKEN_LEN] = { 82 {0x30C3, 0x30CF, 0x0000}, 83 {0x30C4, 0x30CF, 0x0000}, 84 {0x30C3, 0x30D0, 0x0000}, 85 {0x30C4, 0x30D0, 0x0000} 86}; 87 88const static UChar testKatakanaHiraganaCases[][MAX_TOKEN_LEN] = { 89 {0x3042, 0x30C3, 0x0000}, 90 {0x30A2, 0x30C3, 0x0000}, 91 {0x3042, 0x30C4, 0x0000}, 92 {0x30A2, 0x30C4, 0x0000} 93}; 94 95const static UChar testChooonKigooCases[][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}, 104}; 105 106void addKannaCollTest(TestNode** root) 107{ 108 addTest(root, &TestTertiary, "tscoll/cjacoll/TestTertiary"); 109 addTest(root, &TestBase, "tscoll/cjacoll/TestBase"); 110 addTest(root, &TestPlainDakutenHandakuten, "tscoll/cjacoll/TestPlainDakutenHandakuten"); 111 addTest(root, &TestSmallLarge, "tscoll/cjacoll/TestSmallLarge"); 112 addTest(root, &TestKatakanaHiragana, "tscoll/cjacoll/TestKatakanaHiragana"); 113 addTest(root, &TestChooonKigoo, "tscoll/cjacoll/TestChooonKigoo"); 114} 115 116static void TestTertiary( ) 117{ 118 int32_t i; 119 UErrorCode status = U_ZERO_ERROR; 120 myCollation = ucol_open("ja_JP", &status); 121 if(U_FAILURE(status)){ 122 log_err_status(status, "ERROR: in creation of rule based collator: %s\n", myErrorName(status)); 123 return; 124 } 125 log_verbose("Testing Kanna(Japan) Collation with Tertiary strength\n"); 126 ucol_setStrength(myCollation, UCOL_TERTIARY); 127 ucol_setAttribute(myCollation, UCOL_CASE_LEVEL, UCOL_ON, &status); 128 for (i = 0; i < 6 ; i++) 129 { 130 doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]); 131 } 132 ucol_close(myCollation); 133} 134 135/* Testing base letters */ 136static void TestBase() 137{ 138 int32_t i; 139 UErrorCode status = U_ZERO_ERROR; 140 myCollation = ucol_open("ja_JP", &status); 141 if (U_FAILURE(status)) 142 { 143 log_err_status(status, "ERROR: in creation of rule based collator: %s\n", 144 myErrorName(status)); 145 return; 146 } 147 148 log_verbose("Testing Japanese Base Characters Collation\n"); 149 ucol_setStrength(myCollation, UCOL_PRIMARY); 150 for (i = 0; i < 3 ; i++) 151 doTest(myCollation, testBaseCases[i], testBaseCases[i + 1], UCOL_LESS); 152 153 ucol_close(myCollation); 154} 155 156/* Testing plain, Daku-ten, Handaku-ten letters */ 157static void TestPlainDakutenHandakuten(void) 158{ 159 int32_t i; 160 UErrorCode status = U_ZERO_ERROR; 161 myCollation = ucol_open("ja_JP", &status); 162 if (U_FAILURE(status)) 163 { 164 log_err_status(status, "ERROR: in creation of rule based collator: %s\n", 165 myErrorName(status)); 166 return; 167 } 168 169 log_verbose("Testing plain, Daku-ten, Handaku-ten letters Japanese Characters Collation\n"); 170 ucol_setStrength(myCollation, UCOL_SECONDARY); 171 for (i = 0; i < 3 ; i++) 172 doTest(myCollation, testPlainDakutenHandakutenCases[i], 173 testPlainDakutenHandakutenCases[i + 1], UCOL_LESS); 174 175 ucol_close(myCollation); 176} 177 178/* 179* Test Small, Large letters 180*/ 181static void TestSmallLarge(void) 182{ 183 int32_t i; 184 UErrorCode status = U_ZERO_ERROR; 185 myCollation = ucol_open("ja_JP", &status); 186 if (U_FAILURE(status)) 187 { 188 log_err_status(status, "ERROR: in creation of rule based collator: %s\n", 189 myErrorName(status)); 190 return; 191 } 192 193 log_verbose("Testing Japanese Small and Large Characters Collation\n"); 194 ucol_setStrength(myCollation, UCOL_TERTIARY); 195 ucol_setAttribute(myCollation, UCOL_CASE_LEVEL, UCOL_ON, &status); 196 for (i = 0; i < 3 ; i++) 197 doTest(myCollation, testSmallLargeCases[i], testSmallLargeCases[i + 1], 198 UCOL_LESS); 199 200 ucol_close(myCollation); 201} 202 203/* 204* Test Katakana, Hiragana letters 205*/ 206static void TestKatakanaHiragana(void) 207{ 208 int32_t i; 209 UErrorCode status = U_ZERO_ERROR; 210 myCollation = ucol_open("ja_JP", &status); 211 if (U_FAILURE(status)) 212 { 213 log_err_status(status, "ERROR: in creation of rule based collator: %s\n", 214 myErrorName(status)); 215 return; 216 } 217 218 log_verbose("Testing Japanese Katakana, Hiragana Characters Collation\n"); 219 ucol_setStrength(myCollation, UCOL_QUATERNARY); 220 ucol_setAttribute(myCollation, UCOL_CASE_LEVEL, UCOL_ON, &status); 221 for (i = 0; i < 3 ; i++) { 222 doTest(myCollation, testKatakanaHiraganaCases[i], 223 testKatakanaHiraganaCases[i + 1], UCOL_LESS); 224 } 225 226 ucol_close(myCollation); 227} 228 229/* 230* Test Choo-on kigoo 231*/ 232static void TestChooonKigoo(void) 233{ 234 int32_t i; 235 UErrorCode status = U_ZERO_ERROR; 236 myCollation = ucol_open("ja_JP", &status); 237 if (U_FAILURE(status)) 238 { 239 log_err_status(status, "ERROR: in creation of rule based collator: %s\n", 240 myErrorName(status)); 241 return; 242 } 243 244 log_verbose("Testing Japanese Choo-on Kigoo Characters Collation\n"); 245 ucol_setAttribute(myCollation, UCOL_STRENGTH, UCOL_QUATERNARY, &status); 246 ucol_setAttribute(myCollation, UCOL_CASE_LEVEL, UCOL_ON, &status); 247 for (i = 0; i < 7 ; i++) { 248 doTest(myCollation, testChooonKigooCases[i], testChooonKigooCases[i + 1], 249 UCOL_LESS); 250 } 251 252 ucol_close(myCollation); 253} 254 255#endif /* #if !UCONFIG_NO_COLLATION */ 256