scuffed-code/icu4c/source/test/cintltst/cjaptst.c

249 lines
7.7 KiB
C
Raw Normal View History

/********************************************************************
2002-04-02 02:55:31 +00:00
* COPYRIGHT:
* Copyright (c) 1997-2001, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
/********************************************************************************
1999-08-16 21:50:52 +00:00
*
* File CJAPTST.C
*
* Modification History:
2002-04-02 02:55:31 +00:00
* Name Description
* Madhu Katragadda Ported for C API
* synwee Added TestBase, TestPlainDakutenHandakuten,
* TestSmallLarge, TestKatakanaHiragana,
* TestChooonKigoo
*********************************************************************************/
1999-08-16 21:50:52 +00:00
/**
* CollationKannaTest is a third level test class. This tests the locale
* specific primary, secondary and tertiary rules. For example, the ignorable
* character '-' in string "black-bird". The en_US locale uses the default
* collation rules as its sorting sequence.
*/
#include <stdlib.h>
#include "unicode/utypes.h"
#include "unicode/ucol.h"
#include "unicode/uloc.h"
1999-08-16 21:50:52 +00:00
#include "cintltst.h"
#include "ccolltst.h"
#include "callcoll.h"
1999-08-16 21:50:52 +00:00
#include "cjaptst.h"
#include "unicode/ustring.h"
1999-08-16 21:50:52 +00:00
#include "string.h"
1999-08-16 21:50:52 +00:00
static UCollator *myCollation;
const static UChar testSourceCases[][MAX_TOKEN_LEN] = {
{0xff9E, 0x0000},
{0x3042, 0x0000},
{0x30A2, 0x0000},
{0x3042, 0x3042, 0x0000},
{0x30A2, 0x30FC, 0x0000},
{0x30A2, 0x30FC, 0x30C8, 0x0000} /* 6 */
1999-08-16 21:50:52 +00:00
};
const static UChar testTargetCases[][MAX_TOKEN_LEN] = {
{0xFF9F, 0x0000},
{0x30A2, 0x0000},
{0x3042, 0x3042, 0x0000},
{0x30A2, 0x30FC, 0x0000},
{0x30A2, 0x30FC, 0x30C8, 0x0000},
{0x3042, 0x3042, 0x3068, 0x0000} /* 6 */
1999-08-16 21:50:52 +00:00
};
const static UCollationResult results[] = {
UCOL_LESS,
UCOL_EQUAL, /*UCOL_LESS*/ /* Katakanas and Hiraganas are equal on tertiary level(ICU 2.0)*/
UCOL_LESS,
UCOL_GREATER, /*UCOL_LESS*/ /* Prolonged sound mark sorts BEFORE equivalent vowel (ICU 2.0)*/
1999-08-16 21:50:52 +00:00
UCOL_LESS,
UCOL_LESS, /*UCOL_GREATER*/ /* Prolonged sound mark sorts BEFORE equivalent vowel (ICU 2.0)*//* 6 */
1999-08-16 21:50:52 +00:00
};
const static UChar testBaseCases[][MAX_TOKEN_LEN] = {
{0x30AB, 0x0000},
{0x30AB, 0x30AD, 0x0000},
{0x30AD, 0x0000},
{0x30AD, 0x30AD, 0x0000}
};
1999-08-16 21:50:52 +00:00
const static UChar testPlainDakutenHandakutenCases[][MAX_TOKEN_LEN] = {
{0x30CF, 0x30AB, 0x0000},
{0x30D0, 0x30AB, 0x0000},
{0x30CF, 0x30AD, 0x0000},
{0x30D0, 0x30AD, 0x0000}
};
1999-08-16 21:50:52 +00:00
const static UChar testSmallLargeCases[][MAX_TOKEN_LEN] = {
{0x30C3, 0x30CF, 0x0000},
{0x30C4, 0x30CF, 0x0000},
{0x30C3, 0x30D0, 0x0000},
{0x30C4, 0x30D0, 0x0000}
};
const static UChar testKatakanaHiraganaCases[][MAX_TOKEN_LEN] = {
{0x3042, 0x30C3, 0x0000},
{0x30A2, 0x30C3, 0x0000},
{0x3042, 0x30C4, 0x0000},
{0x30A2, 0x30C4, 0x0000}
};
1999-08-16 21:50:52 +00:00
const static UChar testChooonKigooCases[][MAX_TOKEN_LEN] = {
/*0*/ {0x30AB, 0x30FC, 0x3042, 0x0000},
/*1*/ {0x30AB, 0x30FC, 0x30A2, 0x0000},
/*2*/ {0x30AB, 0x30A4, 0x3042, 0x0000},
/*3*/ {0x30AB, 0x30A4, 0x30A2, 0x0000},
/*6*/ {0x30AD, 0x30FC, 0x3042, 0x0000}, /* Prolonged sound mark sorts BEFORE equivalent vowel (ICU 2.0)*/
/*7*/ {0x30AD, 0x30FC, 0x30A2, 0x0000}, /* Prolonged sound mark sorts BEFORE equivalent vowel (ICU 2.0)*/
/*4*/ {0x30AD, 0x30A4, 0x3042, 0x0000},
/*5*/ {0x30AD, 0x30A4, 0x30A2, 0x0000},
};
void addKannaCollTest(TestNode** root)
{
2002-04-02 02:55:31 +00:00
addTest(root, &TestTertiary, "tscoll/cjacoll/TestTertiary");
addTest(root, &TestBase, "tscoll/cjacoll/TestBase");
addTest(root, &TestPlainDakutenHandakuten, "tscoll/cjacoll/TestPlainDakutenHandakuten");
addTest(root, &TestSmallLarge, "tscoll/cjacoll/TestSmallLarge");
addTest(root, &TestKatakanaHiragana, "tscoll/cjacoll/TestKatakanaHiragana");
addTest(root, &TestChooonKigoo, "tscoll/cjacoll/TestChooonKigoo");
1999-08-16 21:50:52 +00:00
}
static void TestTertiary( )
1999-08-16 21:50:52 +00:00
{
int32_t i;
UErrorCode status = U_ZERO_ERROR;
1999-08-16 21:50:52 +00:00
myCollation = ucol_open("ja_JP", &status);
if(U_FAILURE(status)){
1999-08-16 21:50:52 +00:00
log_err("ERROR: in creation of rule based collator: %s\n", myErrorName(status));
2002-04-02 02:55:31 +00:00
return;
1999-08-16 21:50:52 +00:00
}
log_verbose("Testing Kanna(Japan) Collation with Tertiary strength\n");
ucol_setStrength(myCollation, UCOL_TERTIARY);
ucol_setAttribute(myCollation, UCOL_CASE_LEVEL, UCOL_ON, &status);
for (i = 0; i < 6 ; i++)
1999-08-16 21:50:52 +00:00
{
doTest(myCollation, testSourceCases[i], testTargetCases[i], results[i]);
}
ucol_close(myCollation);
}
/* Testing base letters */
static void TestBase()
{
2002-04-02 02:55:31 +00:00
int32_t i;
UErrorCode status = U_ZERO_ERROR;
myCollation = ucol_open("ja_JP", &status);
if (U_FAILURE(status))
{
log_err("ERROR: in creation of rule based collator: %s\n",
myErrorName(status));
2002-04-02 02:55:31 +00:00
return;
}
log_verbose("Testing Japanese Base Characters Collation\n");
ucol_setStrength(myCollation, UCOL_PRIMARY);
for (i = 0; i < 3 ; i++)
doTest(myCollation, testBaseCases[i], testBaseCases[i + 1], UCOL_LESS);
ucol_close(myCollation);
}
/* Testing plain, Daku-ten, Handaku-ten letters */
static void TestPlainDakutenHandakuten(void)
{
2002-04-02 02:55:31 +00:00
int32_t i;
UErrorCode status = U_ZERO_ERROR;
myCollation = ucol_open("ja_JP", &status);
if (U_FAILURE(status))
{
log_err("ERROR: in creation of rule based collator: %s\n",
myErrorName(status));
2002-04-02 02:55:31 +00:00
return;
}
log_verbose("Testing plain, Daku-ten, Handaku-ten letters Japanese Characters Collation\n");
ucol_setStrength(myCollation, UCOL_SECONDARY);
for (i = 0; i < 3 ; i++)
doTest(myCollation, testPlainDakutenHandakutenCases[i],
testPlainDakutenHandakutenCases[i + 1], UCOL_LESS);
ucol_close(myCollation);
}
2002-04-02 02:55:31 +00:00
/*
* Test Small, Large letters
*/
static void TestSmallLarge(void)
{
2002-04-02 02:55:31 +00:00
int32_t i;
UErrorCode status = U_ZERO_ERROR;
myCollation = ucol_open("ja_JP", &status);
if (U_FAILURE(status))
{
log_err("ERROR: in creation of rule based collator: %s\n",
myErrorName(status));
2002-04-02 02:55:31 +00:00
return;
}
log_verbose("Testing Japanese Small and Large Characters Collation\n");
ucol_setStrength(myCollation, UCOL_TERTIARY);
ucol_setAttribute(myCollation, UCOL_CASE_LEVEL, UCOL_ON, &status);
for (i = 0; i < 3 ; i++)
doTest(myCollation, testSmallLargeCases[i], testSmallLargeCases[i + 1],
UCOL_LESS);
ucol_close(myCollation);
}
/*
* Test Katakana, Hiragana letters
*/
static void TestKatakanaHiragana(void)
{
2002-04-02 02:55:31 +00:00
int32_t i;
UErrorCode status = U_ZERO_ERROR;
myCollation = ucol_open("ja_JP", &status);
if (U_FAILURE(status))
{
log_err("ERROR: in creation of rule based collator: %s\n",
myErrorName(status));
2002-04-02 02:55:31 +00:00
return;
}
log_verbose("Testing Japanese Katakana, Hiragana Characters Collation\n");
ucol_setStrength(myCollation, UCOL_QUATERNARY);
ucol_setAttribute(myCollation, UCOL_CASE_LEVEL, UCOL_ON, &status);
for (i = 0; i < 3 ; i++) {
doTest(myCollation, testKatakanaHiraganaCases[i],
testKatakanaHiraganaCases[i + 1], UCOL_LESS);
}
ucol_close(myCollation);
}
/*
* Test Choo-on kigoo
*/
static void TestChooonKigoo(void)
{
2002-04-02 02:55:31 +00:00
int32_t i;
UErrorCode status = U_ZERO_ERROR;
myCollation = ucol_open("ja_JP", &status);
if (U_FAILURE(status))
{
log_err("ERROR: in creation of rule based collator: %s\n",
myErrorName(status));
2002-04-02 02:55:31 +00:00
return;
}
log_verbose("Testing Japanese Choo-on Kigoo Characters Collation\n");
ucol_setAttribute(myCollation, UCOL_CASE_LEVEL, UCOL_ON, &status);
for (i = 0; i < 7 ; i++) {
doTest(myCollation, testChooonKigooCases[i], testChooonKigooCases[i + 1],
UCOL_LESS);
}
ucol_close(myCollation);
}