ICU-114 Test for Transliterator
X-SVN-Rev: 1008
This commit is contained in:
parent
89fd22e69c
commit
2e88c2a06b
358
icu4c/source/test/intltest/cpdtrtst.cpp
Normal file
358
icu4c/source/test/intltest/cpdtrtst.cpp
Normal file
@ -0,0 +1,358 @@
|
||||
/*
|
||||
*****************************************************************************************
|
||||
* *
|
||||
* COPYRIGHT: *
|
||||
* (C) Copyright International Business Machines Corporation, 2000 *
|
||||
* Licensed Material - Program-Property of IBM - All Rights Reserved. *
|
||||
* US Government Users Restricted Rights - Use, duplication, or disclosure *
|
||||
* restricted by GSA ADP Schedule Contract with IBM Corp. *
|
||||
* *
|
||||
*****************************************************************************************
|
||||
************************************************************************
|
||||
* Date Name Description
|
||||
* 03/09/2000 Madhu Creation.
|
||||
************************************************************************/
|
||||
|
||||
#include "ittrans.h"
|
||||
#include "cpdtrtst.h"
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/translit.h"
|
||||
#include "unicode/cpdtrans.h"
|
||||
#include "intltest.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
//---------------------------------------------
|
||||
// runIndexedTest
|
||||
//---------------------------------------------
|
||||
|
||||
void CompoundTransliteratorTest::runIndexedTest( int32_t index, bool_t exec, char* &name, char* par )
|
||||
{
|
||||
if (exec) logln((UnicodeString)"TestSuite CompoundTransliterator API ");
|
||||
switch (index) {
|
||||
|
||||
case 0: name = "TestConstruction"; if (exec) TestConstruction(); break;
|
||||
case 1: name = "TestCloneEqual"; if (exec) TestCloneEqual(); break;
|
||||
case 2: name = "TestGetCount"; if (exec) TestGetCount(); break;
|
||||
case 3: name = "TestGetSetAdoptTransliterator"; if (exec) TestGetSetAdoptTransliterator(); break;
|
||||
case 4: name = "TestTransliterate"; if (exec) TestTransliterate(); break;
|
||||
|
||||
default: name = ""; break; /*needed to end loop*/
|
||||
}
|
||||
}
|
||||
void CompoundTransliteratorTest::TestConstruction(){
|
||||
logln("Testing the construction of the compound Transliterator");
|
||||
UnicodeString names[]={"Greek-Latin", "Latin-Devanagari", "Devanagari-Latin", "Latin-Greek"};
|
||||
Transliterator* t1=Transliterator::createInstance(names[0]);
|
||||
Transliterator* t2=Transliterator::createInstance(names[1]);
|
||||
Transliterator* t3=Transliterator::createInstance(names[2]);
|
||||
Transliterator* t4=Transliterator::createInstance(names[3]);
|
||||
if(t1 == 0 || t2 == 0 || t3 == 0 || t4 == 0){
|
||||
errln("Transliterator construction failed");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Transliterator* transarray1[]={t1};
|
||||
Transliterator* transarray2[]={t1, t4};
|
||||
Transliterator* transarray3[]={t4, t1, t2};
|
||||
Transliterator* transarray4[]={t1, t2, t3, t4};
|
||||
|
||||
Transliterator** transarray[]={transarray1, transarray2, transarray3, transarray4};
|
||||
const UnicodeString IDs[]={
|
||||
names[0],
|
||||
names[0]+";"+names[3],
|
||||
names[3]+";"+names[1]+";"+names[2],
|
||||
names[0]+";"+names[1]+";"+names[2]+";"+names[3]
|
||||
};
|
||||
|
||||
uint16_t i=0;
|
||||
for(i=0; i<4; i++){
|
||||
|
||||
CompoundTransliterator *cpdtrans=new CompoundTransliterator(IDs[i]);
|
||||
if(cpdtrans == 0){
|
||||
errln("Construction using CompoundTransliterator(UnicodeString&, Direction, UnicodeFilter*) failed");
|
||||
}
|
||||
else{
|
||||
delete cpdtrans;
|
||||
}
|
||||
|
||||
CompoundTransliterator *cpdtrans2=new CompoundTransliterator(transarray[i], i+1);
|
||||
if(cpdtrans2 == 0){
|
||||
errln("Construction using CompoundTransliterator(Transliterator* const transliterators[], "
|
||||
"int32_t count, UnicodeFilter* adoptedFilter = 0) failed");
|
||||
continue;
|
||||
}
|
||||
CompoundTransliterator *copycpd=new CompoundTransliterator(*cpdtrans2);
|
||||
if(copycpd->getCount() != cpdtrans2->getCount() || copycpd->getID() != cpdtrans2->getID()) {
|
||||
errln("Copy construction failed");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
delete copycpd;
|
||||
delete cpdtrans2;
|
||||
|
||||
}
|
||||
delete t1;
|
||||
delete t2;
|
||||
delete t3;
|
||||
delete t4;
|
||||
|
||||
}
|
||||
|
||||
void CompoundTransliteratorTest::TestCloneEqual(){
|
||||
logln("Testing the clone() and equality operator functions of Compound Transliterator");
|
||||
CompoundTransliterator *ct1=new CompoundTransliterator("Greek-Latin;Latin-Devanagari");
|
||||
if(ct1 == 0){
|
||||
errln("construction failed");
|
||||
return;
|
||||
}
|
||||
CompoundTransliterator *ct2=new CompoundTransliterator("Greek-Latin");
|
||||
if(ct2 == 0){
|
||||
errln("construction failed");
|
||||
return;
|
||||
}
|
||||
CompoundTransliterator *copyct1=new CompoundTransliterator(*ct1);
|
||||
if(copyct1 == 0){
|
||||
errln("copy construction failed");
|
||||
return;
|
||||
}
|
||||
CompoundTransliterator *copyct2=new CompoundTransliterator(*ct2);
|
||||
if(copyct2 == 0){
|
||||
errln("copy construction failed");
|
||||
return;
|
||||
}
|
||||
CompoundTransliterator equalct1=*copyct1;
|
||||
CompoundTransliterator equalct2=*copyct2;
|
||||
|
||||
if(copyct1->getID() != ct1->getID() || copyct2->getID() != ct2->getID() ||
|
||||
copyct1->getCount() != ct1->getCount() || copyct2->getCount() != ct2->getCount() ||
|
||||
copyct2->getID() == ct1->getID() || copyct1->getID() == ct2->getID() ||
|
||||
copyct2->getCount() == ct1->getCount() || copyct1->getCount() == ct2->getCount() ){
|
||||
errln("Error: copy constructors failed");
|
||||
}
|
||||
|
||||
if(equalct1.getID() != ct1->getID() || equalct2.getID() != ct2->getID() ||
|
||||
equalct1.getID() != copyct1->getID() || equalct2.getID() != copyct2->getID() ||
|
||||
equalct1.getCount() != ct1->getCount() || equalct2.getCount() != ct2->getCount() ||
|
||||
copyct2->getID() == ct1->getID() || copyct1->getID() == ct2->getID() ||
|
||||
equalct1.getCount() != copyct1->getCount() || equalct2.getCount() != copyct2->getCount() ||
|
||||
equalct2.getCount() == ct1->getCount() || equalct1.getCount() == ct2->getCount() ) {
|
||||
errln("Error: =operator or copy constructor failed");
|
||||
}
|
||||
|
||||
CompoundTransliterator *clonect1a=(CompoundTransliterator*)ct1->clone();
|
||||
CompoundTransliterator *clonect1b=(CompoundTransliterator*)equalct1.clone();
|
||||
CompoundTransliterator *clonect2a=(CompoundTransliterator*)ct2->clone();
|
||||
CompoundTransliterator *clonect2b=(CompoundTransliterator*)copyct2->clone();
|
||||
|
||||
|
||||
if(clonect1a->getID() != ct1->getID() || clonect1a->getCount() != ct1->getCount() ||
|
||||
clonect1a->getID() != clonect1b->getID() || clonect1a->getCount() != clonect1b->getCount() ||
|
||||
clonect1a->getID() != equalct1.getID() || clonect1a->getCount() != equalct1.getCount() ||
|
||||
clonect1a->getID() != copyct1->getID() || clonect1a->getCount() != copyct1->getCount() ||
|
||||
|
||||
clonect2b->getID() != ct2->getID() || clonect2a->getCount() != ct2->getCount() ||
|
||||
clonect2a->getID() != clonect2b->getID() || clonect2a->getCount() != clonect2b->getCount() ||
|
||||
clonect2a->getID() != equalct2.getID() || clonect2a->getCount() != equalct2.getCount() ||
|
||||
clonect2b->getID() != copyct2->getID() || clonect2b->getCount() != copyct2->getCount() ) {
|
||||
errln("Error: clone() failed");
|
||||
}
|
||||
|
||||
delete ct1;
|
||||
delete ct2;
|
||||
delete copyct1;
|
||||
delete copyct2;
|
||||
|
||||
}
|
||||
|
||||
void CompoundTransliteratorTest::TestGetCount(){
|
||||
logln("Testing the getCount() API of CompoundTransliterator");
|
||||
CompoundTransliterator *ct1=new CompoundTransliterator("Halfwidth-Fullwidth;Fullwidth-Halfwidth");
|
||||
CompoundTransliterator *ct2=new CompoundTransliterator("Unicode-Hex;Hex-Unicode;Cyrillic-Latin;Latin-Cyrillic");
|
||||
CompoundTransliterator *ct3=(CompoundTransliterator*)ct1;
|
||||
CompoundTransliterator *ct4=new CompoundTransliterator("Latin-Devanagari");
|
||||
CompoundTransliterator *ct5=new CompoundTransliterator(*ct4);
|
||||
|
||||
|
||||
if(ct1->getCount() == ct2->getCount() || ct1->getCount() != ct3->getCount() ||
|
||||
ct2->getCount() == ct3->getCount() ||
|
||||
ct4->getCount() != ct5->getCount() || ct4->getCount() == ct1->getCount() ||
|
||||
ct4->getCount() == ct2->getCount() || ct4->getCount() == ct3->getCount() ||
|
||||
ct5->getCount() == ct2->getCount() || ct5->getCount() == ct3->getCount() ) {
|
||||
errln("Error: getCount() failed");
|
||||
}
|
||||
delete ct1;
|
||||
delete ct2;
|
||||
delete ct4;
|
||||
delete ct5;
|
||||
}
|
||||
|
||||
void CompoundTransliteratorTest::TestGetSetAdoptTransliterator(){
|
||||
logln("Testing the getTransliterator() API of CompoundTransliterator");
|
||||
UnicodeString ID("Latin-Greek;Greek-Latin;Latin-Devanagari;Devanagari-Latin;Latin-Cyrillic;Cyrillic-Latin;Unicode-Hex;Hex-Unicode");
|
||||
CompoundTransliterator *ct1=new CompoundTransliterator(ID);
|
||||
if(ct1 == 0){
|
||||
errln("CompoundTransliterator construction failed");
|
||||
return;
|
||||
}
|
||||
int32_t count=ct1->getCount();
|
||||
UnicodeString *array=split(ID, ';', count);
|
||||
int i;
|
||||
for(i=0; i < count; i++){
|
||||
UnicodeString child= ct1->getTransliterator(i).getID();
|
||||
if(child != *(array+i)){
|
||||
errln("Error getTransliterator() failed: Expected->" + *(array+i) + " Got->" + child);
|
||||
}else {
|
||||
logln("OK: getTransliterator() passed: Expected->" + *(array+i) + " Got->" + child);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
logln("Testing setTransliterator() API of CompoundTransliterator");
|
||||
UnicodeString ID2("Hex-Unicode;Unicode-Hex;Latin-Cyrillic;Cyrillic-Latin;Halfwidth-Fullwidth;Fullwidth-Halfwidth");
|
||||
array=split(ID2, ';', count);
|
||||
Transliterator** transarray=new Transliterator*[count];
|
||||
for(i=0;i<count;i++){
|
||||
transarray[i]=Transliterator::createInstance(*(array+i));
|
||||
logln("The ID for the transltierator created is " + transarray[i]->getID());
|
||||
}
|
||||
/*setTransliterator and adoptTransliterator */
|
||||
|
||||
ct1->setTransliterators(transarray, count);
|
||||
if(ct1->getCount() != count || ct1->getID() != "Latin-kana"){
|
||||
errln((UnicodeString)"Error: setTransliterators) failed.\n\t Count:- expected->" + count + (UnicodeString)". got->" + ct1->getCount() +
|
||||
(UnicodeString)"\n\tID :- expected->" + ID2 + (UnicodeString)". got->" + ct1->getID());
|
||||
}
|
||||
else{
|
||||
logln("OK: setTransliterators() passed");
|
||||
}
|
||||
/*UnicodeString temp;
|
||||
for(i=0;i<count-1;i++){
|
||||
temp.append(ct1->getTransliterator(i).getID());
|
||||
temp.append(";");
|
||||
}
|
||||
temp.append(ct1->getTransliterator(i).getID());
|
||||
if(temp != ID2){
|
||||
errln("Error: setTransliterator() failed. Expected->" + ID2 + "\nGot->" + temp);
|
||||
}
|
||||
else{
|
||||
logln("OK: setTransliterator() passed");
|
||||
}*/
|
||||
logln("Testing adoptTransliterator() API of CompoundTransliterator");
|
||||
Transliterator *transarray2[]={Transliterator::createInstance("Latin-Kana")};
|
||||
ct1->adoptTransliterators(transarray2, 1);
|
||||
if(ct1->getCount() != 1 || ct1->getID() != "Latin-kana"){
|
||||
errln((UnicodeString)"Error: adoptTransliterators) failed.\n\t Count:- expected->1" + (UnicodeString)". got->" + ct1->getCount() +
|
||||
(UnicodeString)"\n\tID :- expected->Latin-Kana" + (UnicodeString)". got->" + ct1->getID());
|
||||
}
|
||||
else{
|
||||
logln("OK: adoptTranslterator() passed");
|
||||
}
|
||||
// delete ct1;
|
||||
|
||||
}
|
||||
/**
|
||||
* Splits a UnicodeString
|
||||
*/
|
||||
UnicodeString* CompoundTransliteratorTest::split(const UnicodeString& str, UChar seperator, int32_t& count) {
|
||||
|
||||
//get the count
|
||||
int32_t i;
|
||||
count =1;
|
||||
for(i=0; i<str.length(); i++){
|
||||
if(str.charAt(i) == seperator)
|
||||
count++;
|
||||
}
|
||||
// make an array
|
||||
UnicodeString* result = new UnicodeString[count];
|
||||
int32_t last = 0;
|
||||
int32_t current = 0;
|
||||
for (i = 0; i < str.length(); ++i) {
|
||||
if (str.charAt(i) == seperator) {
|
||||
str.extractBetween(last, i, result[current]);
|
||||
last = i+1;
|
||||
current++;
|
||||
}
|
||||
}
|
||||
str.extractBetween(last, i, result[current]);
|
||||
return result;
|
||||
}
|
||||
void CompoundTransliteratorTest::TestTransliterate(){
|
||||
logln("Testing the handleTransliterate() API of CompoundTransliterator");
|
||||
CompoundTransliterator *ct1=new CompoundTransliterator("Unicode-Hex;Hex-Unicode");
|
||||
if(ct1 == 0){
|
||||
errln("CompoundTransliterator construction failed");
|
||||
}else {
|
||||
UnicodeString s("abcabc");
|
||||
expect(*ct1, s, s);
|
||||
Transliterator::Position index(0, 0);
|
||||
UnicodeString rsource2(s);
|
||||
UnicodeString expectedResult=s;
|
||||
ct1->handleTransliterate(rsource2, index, FALSE);
|
||||
expectAux(ct1->getID() + ":String, index(0,0,0), incremental=FALSE", rsource2 + "->" + rsource2, rsource2==expectedResult, expectedResult);
|
||||
index=Transliterator::Position(1,3,2);
|
||||
UnicodeString rsource3(s);
|
||||
ct1->handleTransliterate(rsource3, index, TRUE);
|
||||
expectAux(ct1->getID() + ":String, index(1,2,3), incremental=TRUE", rsource3 + "->" + rsource3, rsource3==expectedResult, expectedResult);
|
||||
|
||||
delete ct1;
|
||||
}
|
||||
UnicodeString Data[]={
|
||||
//ID, input string, transliterated string
|
||||
"Unicode-Hex;Hex-Unicode;Unicode-Hex", "hello", "\\u0068\\u0065\\u006C\\u006C\\u006F",
|
||||
"Unicode-Hex;Hex-Unicode", "hello! How are you?", "hello! How are you?",
|
||||
"Devanagari-Latin;Latin-Devanagari", CharsToUnicodeString("\\u092D\\u0948'\\u0930'\\u0935"), CharsToUnicodeString("\\u092D\\u093E\\u0907\\u0930\\u0935"),
|
||||
"Latin-Cyrillic;Cyrillic-Latin", "a'b'k'd'e'f'g'h'i'j'Shch'shch'zh'h", "abkdefghijShchshchzhh",
|
||||
"Latin-Greek;Greek-Latin", "ABGabgAKLMN", "ABGabgAKLMN",
|
||||
"Latin-Arabic;Arabic-Latin", "Ad'r'a'b'i'k'dh'dd'gh", "Adrabikdhddgh"
|
||||
|
||||
|
||||
};
|
||||
int i;
|
||||
for(i=0; i<sizeof(Data)/sizeof(Data[0]); i=i+3){
|
||||
CompoundTransliterator *ct2=new CompoundTransliterator(Data[i+0]);
|
||||
if(ct1 == 0){
|
||||
errln("CompoundTransliterator construction failed for " + Data[i+0]);
|
||||
continue;
|
||||
}
|
||||
expect(*ct2, Data[i+1], Data[i+2]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//======================================================================
|
||||
// Support methods
|
||||
//======================================================================
|
||||
void CompoundTransliteratorTest::expect(const CompoundTransliterator& t,
|
||||
const UnicodeString& source,
|
||||
const UnicodeString& expectedResult) {
|
||||
|
||||
UnicodeString rsource(source);
|
||||
t.transliterate(rsource);
|
||||
expectAux(t.getID() + ":Replaceable", source + "->" + rsource, rsource==expectedResult, expectedResult);
|
||||
|
||||
// Test handleTransliterate (incremental) transliteration --
|
||||
rsource.remove();
|
||||
rsource.append(source);
|
||||
Transliterator::Position index(0,source.length(),0);
|
||||
t.handleTransliterate(rsource, index, TRUE);
|
||||
expectAux(t.getID() + ":handleTransliterate ", source + "->" + rsource, rsource==expectedResult, expectedResult);
|
||||
|
||||
}
|
||||
|
||||
void CompoundTransliteratorTest::expectAux(const UnicodeString& tag,
|
||||
const UnicodeString& summary, bool_t pass,
|
||||
const UnicodeString& expectedResult) {
|
||||
if (pass) {
|
||||
logln(UnicodeString("(")+tag+") " + prettify(summary));
|
||||
} else {
|
||||
errln(UnicodeString("FAIL: (")+tag+") "
|
||||
+ prettify(summary)
|
||||
+ ", expected " + prettify(expectedResult));
|
||||
}
|
||||
}
|
||||
|
69
icu4c/source/test/intltest/cpdtrtst.h
Normal file
69
icu4c/source/test/intltest/cpdtrtst.h
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
*****************************************************************************************
|
||||
* *
|
||||
* COPYRIGHT: *
|
||||
* (C) Copyright International Business Machines Corporation, 2000 *
|
||||
* Licensed Material - Program-Property of IBM - All Rights Reserved. *
|
||||
* US Government Users Restricted Rights - Use, duplication, or disclosure *
|
||||
* restricted by GSA ADP Schedule Contract with IBM Corp. *
|
||||
* *
|
||||
*****************************************************************************************
|
||||
************************************************************************
|
||||
* Date Name Description
|
||||
* 03/09/2000 Madhu Creation.
|
||||
************************************************************************/
|
||||
|
||||
#ifndef CPDTRTST_H
|
||||
#define CPDTRTST_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/translit.h"
|
||||
#include "unicode/cpdtrans.h"
|
||||
#include "intltest.h"
|
||||
|
||||
class CompoundTransliterator;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @summary General test of Compound Transliterator
|
||||
*/
|
||||
class CompoundTransliteratorTest : public IntlTest {
|
||||
public:
|
||||
void runIndexedTest(int32_t index, bool_t exec, char* &name, char* par=NULL);
|
||||
|
||||
/*Tests the constructors */
|
||||
void TestConstruction(void);
|
||||
/*Tests the function clone, and operator==()*/
|
||||
void TestCloneEqual(void);
|
||||
/*Tests the function getCount()*/
|
||||
void TestGetCount(void);
|
||||
/*Tests the function getTransliterator() and setTransliterators() and adoptTransliterators()*/
|
||||
void TestGetSetAdoptTransliterator(void);
|
||||
/*Tests the function handleTransliterate()*/
|
||||
void TestTransliterate(void);
|
||||
|
||||
//======================================================================
|
||||
// Support methods
|
||||
//======================================================================
|
||||
|
||||
/**
|
||||
* Splits a UnicodeString
|
||||
*/
|
||||
UnicodeString* CompoundTransliteratorTest::split(const UnicodeString& str, UChar seperator, int32_t& count);
|
||||
|
||||
void expect(const CompoundTransliterator& t,
|
||||
const UnicodeString& source,
|
||||
const UnicodeString& expectedResult);
|
||||
|
||||
void expectAux(const UnicodeString& tag,
|
||||
const UnicodeString& summary, bool_t pass,
|
||||
const UnicodeString& expectedResult);
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
330
icu4c/source/test/intltest/hajatrts.cpp
Normal file
330
icu4c/source/test/intltest/hajatrts.cpp
Normal file
@ -0,0 +1,330 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* COPYRIGHT: *
|
||||
* (C) Copyright International Business Machines Corporation, 2000 *
|
||||
* Licensed Material - Program-Property of IBM - All Rights Reserved. *
|
||||
* US Government Users Restricted Rights - Use, duplication, or disclosure *
|
||||
* restricted by GSA ADP Schedule Contract with IBM Corp. *
|
||||
* *
|
||||
*****************************************************************************************
|
||||
************************************************************************
|
||||
* Date Name Description
|
||||
* 03/20/2000 Madhu Creation.
|
||||
************************************************************************/
|
||||
|
||||
#include "ittrans.h"
|
||||
#include "hajatrts.h"
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/translit.h"
|
||||
#include "unicode/hangjamo.h"
|
||||
#include "unicode/unifilt.h"
|
||||
#include "intltest.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
/*converts a Unicodestring to integer*/
|
||||
static int32_t getInt(UnicodeString str)
|
||||
{
|
||||
int len=str.length();
|
||||
char *alias;
|
||||
char *buffer=new char[len+1];
|
||||
alias=buffer;
|
||||
for(int i=0; i< len; i++){
|
||||
*alias=(char)str.charAt(i);
|
||||
alias++;
|
||||
}
|
||||
*alias='\0';
|
||||
return atoi(buffer);
|
||||
}
|
||||
//---------------------------------------------
|
||||
// runIndexedTest
|
||||
//---------------------------------------------
|
||||
|
||||
void HangToJamoTransliteratorTest::runIndexedTest( int32_t index, bool_t exec, char* &name, char* par )
|
||||
{
|
||||
if (exec) logln((UnicodeString)"TestSuite HangToJamoul Transliterator API ");
|
||||
switch (index) {
|
||||
|
||||
case 0: name = "TestConstruction"; if (exec) TestConstruction(); break;
|
||||
case 1: name = "TestCloneEqual"; if (exec) TestCloneEqual(); break;
|
||||
case 2: name = "TestSimpleTransliterate"; if (exec) TestSimpleTransliterate(); break;
|
||||
case 3: name = "TestTransliterate"; if (exec) TestTransliterate(); break;
|
||||
case 4: name = "TestTransliterate2"; if (exec) TestTransliterate2(); break;
|
||||
|
||||
default: name = ""; break; /*needed to end loop*/
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Used by TestConstruction() and TestTransliterate.
|
||||
*/
|
||||
class TestHangulFilter : public UnicodeFilter {
|
||||
virtual UnicodeFilter* clone() const {
|
||||
return new TestHangulFilter(*this);
|
||||
}
|
||||
virtual bool_t contains(UChar c) const {
|
||||
if(c == 0xae4c )
|
||||
return FALSE;
|
||||
else
|
||||
return TRUE;
|
||||
}
|
||||
};
|
||||
void HangToJamoTransliteratorTest::TestConstruction(){
|
||||
logln("Testing the construction HangulJamoTransliterator()");
|
||||
HangulJamoTransliterator *trans1=new HangulJamoTransliterator();
|
||||
if(trans1 == 0){
|
||||
errln("HangulJamoTransliterator() construction failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
HangulJamoTransliterator *trans2=new HangulJamoTransliterator(new TestHangulFilter);
|
||||
if(trans2 == 0){
|
||||
errln("HangulJamoTransliterator(UnicodeFilter) construction failed.");
|
||||
return;
|
||||
}
|
||||
logln("Testing copy construction");
|
||||
HangulJamoTransliterator *trans2copy=new HangulJamoTransliterator(*trans2);
|
||||
if(trans2copy == 0){
|
||||
errln("HangulJamoTransliterator copy construction failed");
|
||||
delete trans2;
|
||||
}
|
||||
|
||||
if(trans2copy->getID() != trans2->getID() ||
|
||||
trans2copy->getFilter() == NULL ||
|
||||
trans2copy->getFilter()->contains(0xae4c) != trans2->getFilter()->contains(0xae4c) ) {
|
||||
errln("Copy construction failed");
|
||||
}
|
||||
|
||||
|
||||
delete trans1;
|
||||
delete trans2copy;
|
||||
delete trans2;
|
||||
|
||||
}
|
||||
void HangToJamoTransliteratorTest::TestCloneEqual(){
|
||||
logln("Testing the clone and =operator of HangulJamoTransliterator");
|
||||
HangulJamoTransliterator *trans1=new HangulJamoTransliterator();
|
||||
if(trans1 == 0){
|
||||
errln("HangulJamoTransliterator() construction failed.");
|
||||
return;
|
||||
}
|
||||
HangulJamoTransliterator *trans2=new HangulJamoTransliterator(new TestHangulFilter);
|
||||
if(trans2 == 0){
|
||||
errln("HangulJamoTransliterator(UnicodeFilter) construction failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
HangulJamoTransliterator *trans1equal=trans1;
|
||||
HangulJamoTransliterator *trans2equal=trans2;
|
||||
if(trans1equal == 0 || trans2equal==0 ){
|
||||
errln("=Operator failed");
|
||||
delete trans1;
|
||||
delete trans2;
|
||||
return;
|
||||
}
|
||||
if(trans1->getID() != trans1equal->getID() ||
|
||||
trans1equal->getFilter() != NULL ||
|
||||
trans2->getID() != trans2equal->getID() ||
|
||||
trans2equal->getFilter() == NULL ||
|
||||
trans2equal->getFilter()->contains(0xae4c) != trans2->getFilter()->contains(0xae4c) ) {
|
||||
errln("=Operator failed");
|
||||
}
|
||||
|
||||
|
||||
HangulJamoTransliterator *trans1clone=(HangulJamoTransliterator*)trans1->clone();
|
||||
HangulJamoTransliterator *trans2clone=(HangulJamoTransliterator*)trans2->clone();
|
||||
if(trans1clone == 0 || trans2clone==0 ){
|
||||
errln("clone() failed");
|
||||
delete trans1;
|
||||
delete trans2;
|
||||
return;
|
||||
}
|
||||
if(trans1->getID() != trans1clone->getID() ||
|
||||
trans1clone->getFilter() != NULL ||
|
||||
trans2->getID() != trans2clone->getID() ||
|
||||
trans2clone->getFilter() == NULL ||
|
||||
trans2clone->getFilter()->contains(0x1101) != trans2->getFilter()->contains(0x1101) ) {
|
||||
errln("=Operator failed");
|
||||
}
|
||||
|
||||
delete trans1;
|
||||
delete trans2;
|
||||
}
|
||||
|
||||
void HangToJamoTransliteratorTest::TestSimpleTransliterate(){
|
||||
logln("Testing the handleTransliterate() API of HangulJamoTransliterator()");
|
||||
HangulJamoTransliterator *trans1=new HangulJamoTransliterator();
|
||||
if(trans1==0){
|
||||
errln("HangulJamoTransliterator construction failed");
|
||||
return;
|
||||
}
|
||||
UChar src[]={ 0xae4c, 0xc139, 0xc54a, 0xc694, 0};
|
||||
UnicodeString source(src);
|
||||
UnicodeString expected(CharsToUnicodeString("\\u1101\\u1161\\u1109\\u1166\\u11a8\\u110b\\u1161\\u11ad\\u110b\\u116d"));
|
||||
expect(*trans1, "", source, expected);
|
||||
|
||||
HangulJamoTransliterator *trans2=new HangulJamoTransliterator(new TestHangulFilter);
|
||||
if(trans2==0){
|
||||
errln("HangulJamoTransliterator(UnicodeFilter) construction failed");
|
||||
return;
|
||||
}
|
||||
expect(*trans2, " with Filter(0xae4c) ", source, CharsToUnicodeString("\\uae4c\\u1109\\u1166\\u11a8\\u110b\\u1161\\u11ad\\u110b\\u116d"));
|
||||
|
||||
|
||||
|
||||
}
|
||||
void HangToJamoTransliteratorTest::TestTransliterate2(){
|
||||
logln("Testing the handleTransliterate() API HangulJamoTransliterator()");
|
||||
HangulJamoTransliterator *trans1=new HangulJamoTransliterator();
|
||||
if(trans1==0){
|
||||
errln("HangulJamoTransliterator construction failed");
|
||||
return;
|
||||
}
|
||||
UnicodeString source, expected, temp;
|
||||
UChar choseong=0x1100;
|
||||
UChar jungseong=0x1161;
|
||||
UChar jongseong=0x11a8;
|
||||
for(UChar c=0xac01;c<0xacff;++c){
|
||||
source.append(c);
|
||||
expected.append(choseong);
|
||||
if(jongseong > 0x11c2){
|
||||
jongseong=0x11a8;
|
||||
jungseong++;
|
||||
expected.append(jungseong);
|
||||
}
|
||||
else {
|
||||
expected.append(jungseong);
|
||||
expected.append(jongseong++);
|
||||
}
|
||||
expect(*trans1, "", source, expected);
|
||||
source.remove();
|
||||
expected.remove();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
void HangToJamoTransliteratorTest::TestTransliterate(){
|
||||
UnicodeString Data[]={
|
||||
// source, index.start, index.limit, index.cursor, expectedResult, expectedResult using Filter(TestHangulFilter)
|
||||
CharsToUnicodeString("\\u1100\\uae4c\\ub098"), "1", "3", "1",
|
||||
CharsToUnicodeString("\\u1100\\u1101\\u1161\\u1102\\u1161"), CharsToUnicodeString("\\u1100\\uae4c\\u1102\\u1161"),
|
||||
CharsToUnicodeString("\\uc5ec\\u1101"), "0", "1", "0",
|
||||
CharsToUnicodeString("\\u110b\\u1167\\u1101"), CharsToUnicodeString("\\u110b\\u1167\\u1101"),
|
||||
CharsToUnicodeString("\\uc5ec\\uae4c"), "0", "2", "0",
|
||||
CharsToUnicodeString("\\u110b\\u1167\\u1101\\u1161"), CharsToUnicodeString("\\u110b\\u1167\\uae4c"),
|
||||
|
||||
|
||||
|
||||
};
|
||||
int i;
|
||||
HangulJamoTransliterator *trans1=new HangulJamoTransliterator();
|
||||
if(trans1 == 0){
|
||||
errln("HangulJamoTransliterator construction failed");
|
||||
return;
|
||||
}
|
||||
HangulJamoTransliterator *trans2=new HangulJamoTransliterator(new TestHangulFilter);
|
||||
if(trans2 == 0){
|
||||
errln("HangulJamoTransliterator(UnicodeFilter) construction failed");
|
||||
return;
|
||||
}
|
||||
for(i=0;i<sizeof(Data)/sizeof(Data[0]);i=i+6){
|
||||
expectTranslit(*trans1, ":", Data[i+0], getInt(Data[i+1]), getInt(Data[i+2]), getInt(Data[i+3]), Data[i+4] );
|
||||
expectTranslit(*trans2, " with Filter(0xae4c):", Data[i+0], getInt(Data[i+1]), getInt(Data[i+2]), getInt(Data[i+3]), Data[i+5] );
|
||||
|
||||
}
|
||||
delete trans1;
|
||||
delete trans2;
|
||||
|
||||
}
|
||||
//======================================================================
|
||||
// Support methods
|
||||
//======================================================================
|
||||
|
||||
void HangToJamoTransliteratorTest::expectTranslit(const HangulJamoTransliterator& t,
|
||||
const UnicodeString& message,
|
||||
const UnicodeString& source,
|
||||
int32_t start, int32_t limit, int32_t cursor,
|
||||
const UnicodeString& expectedResult){
|
||||
|
||||
|
||||
Transliterator::Position index(start, limit, cursor);
|
||||
UnicodeString rsource(source);
|
||||
t.handleTransliterate(rsource, index, FALSE);
|
||||
expectAux(t.getID() + ":handleTransliterator(increment=FALSE) " + message, source + "-->" + rsource, rsource==expectedResult, expectedResult);
|
||||
|
||||
UnicodeString rsource2(source);
|
||||
index=Transliterator::Position(start, limit, cursor);
|
||||
t.handleTransliterate(rsource2, index, TRUE);
|
||||
expectAux(t.getID() + ":handleTransliterator(increment=TRUE) " + message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
|
||||
|
||||
/*ceates a copy constructor and checks the transliteration*/
|
||||
HangulJamoTransliterator *copy=new HangulJamoTransliterator(t);
|
||||
rsource2.remove();
|
||||
rsource2.append(source);
|
||||
index=Transliterator::Position(start, limit, cursor);
|
||||
copy->handleTransliterate(rsource2, index, FALSE);
|
||||
expectAux(t.getID() + "COPY:handleTransliterator(increment=FALSE) "+ message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
|
||||
|
||||
rsource2.remove();
|
||||
rsource2.append(source);
|
||||
index=Transliterator::Position(start, limit, cursor);
|
||||
copy->handleTransliterate(rsource2, index, TRUE);
|
||||
expectAux(t.getID() + "COPY:handleTransliterator(increment=TRUE) "+ message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
|
||||
delete copy;
|
||||
|
||||
/*creates a clone and tests transliteration*/
|
||||
HangulJamoTransliterator *clone=(HangulJamoTransliterator*)t.clone();
|
||||
rsource2.remove();
|
||||
rsource2.append(source);
|
||||
index=Transliterator::Position(start, limit, cursor);
|
||||
clone->handleTransliterate(rsource2, index, FALSE);
|
||||
expectAux(t.getID() + "CLONE:handleTransliterator(increment=FALSE) "+ message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
|
||||
|
||||
rsource2.remove();
|
||||
rsource2.append(source);
|
||||
index=Transliterator::Position(start, limit, cursor);
|
||||
clone->handleTransliterate(rsource2, index, TRUE);
|
||||
expectAux(t.getID() + "CLONE:handleTransliterator(increment=TRUE) "+ message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
|
||||
|
||||
/*Uses the assignment operator to create a transliterator and tests transliteration*/
|
||||
HangulJamoTransliterator equal=t;
|
||||
rsource2.remove();
|
||||
rsource2.append(source);
|
||||
index=Transliterator::Position(start, limit, cursor);
|
||||
equal.handleTransliterate(rsource2, index, FALSE);
|
||||
expectAux(t.getID() + "=OPERATOR:handleTransliterator(increment=FALSE) "+ message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
|
||||
|
||||
rsource2.remove();
|
||||
rsource2.append(source);
|
||||
index=Transliterator::Position(start, limit, cursor);
|
||||
equal.handleTransliterate(rsource2, index, TRUE);
|
||||
expectAux(t.getID() + "=OPERATOR:handleTransliterator(increment=TRUE) "+ message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
|
||||
|
||||
}
|
||||
void HangToJamoTransliteratorTest::expect(const HangulJamoTransliterator& t,
|
||||
const UnicodeString& message,
|
||||
const UnicodeString& source,
|
||||
const UnicodeString& expectedResult) {
|
||||
|
||||
UnicodeString rsource(source);
|
||||
t.transliterate(rsource);
|
||||
expectAux(t.getID() + ":Replaceable " + message, source + "->" + rsource, rsource==expectedResult, expectedResult);
|
||||
|
||||
// Test handleTransliterate (incremental) transliteration --
|
||||
rsource.remove();
|
||||
rsource.append(source);
|
||||
Transliterator::Position index(0,source.length(),0);
|
||||
t.handleTransliterate(rsource, index, TRUE);
|
||||
expectAux(t.getID() + ":handleTransliterate " + message, source + "->" + rsource, rsource==expectedResult, expectedResult);
|
||||
|
||||
}
|
||||
void HangToJamoTransliteratorTest::expectAux(const UnicodeString& tag,
|
||||
const UnicodeString& summary, bool_t pass,
|
||||
const UnicodeString& expectedResult) {
|
||||
if (pass) {
|
||||
logln(UnicodeString("(")+tag+") " + prettify(summary));
|
||||
} else {
|
||||
errln(UnicodeString("FAIL: (")+tag+") "
|
||||
+ prettify(summary)
|
||||
+ ", expected " + prettify(expectedResult));
|
||||
}
|
||||
}
|
71
icu4c/source/test/intltest/hajatrts.h
Normal file
71
icu4c/source/test/intltest/hajatrts.h
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
*****************************************************************************************
|
||||
* *
|
||||
* COPYRIGHT: *
|
||||
* (C) Copyright International Business Machines Corporation, 2000 *
|
||||
* Licensed Material - Program-Property of IBM - All Rights Reserved. *
|
||||
* US Government Users Restricted Rights - Use, duplication, or disclosure *
|
||||
* restricted by GSA ADP Schedule Contract with IBM Corp. *
|
||||
* *
|
||||
*****************************************************************************************
|
||||
************************************************************************
|
||||
* Date Name Description
|
||||
* 03/20/2000 Madhu Creation.
|
||||
************************************************************************/
|
||||
|
||||
#ifndef HANGTOJAMOTRTST_H
|
||||
#define HANGTOJAMOTRTST_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/translit.h"
|
||||
#include "unicode/hangjamo.h"
|
||||
#include "intltest.h"
|
||||
|
||||
class HangulJamoTransliterator;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @summary General test of HangulToJamo Transliterator
|
||||
*/
|
||||
class HangToJamoTransliteratorTest : public IntlTest {
|
||||
public:
|
||||
void runIndexedTest(int32_t index, bool_t exec, char* &name, char* par=NULL);
|
||||
|
||||
/*Tests the constructors */
|
||||
void TestConstruction(void);
|
||||
/*Tests the function clone, and operator==()*/
|
||||
void TestCloneEqual(void);
|
||||
/*Tests the function handleTransliterate()*/
|
||||
void TestSimpleTransliterate(void);
|
||||
/*Tests the function handleTransliterate()*/
|
||||
void TestTransliterate(void);
|
||||
|
||||
void TestTransliterate2(void);
|
||||
//======================================================================
|
||||
// Support methods
|
||||
//======================================================================
|
||||
void expectTranslit(const HangulJamoTransliterator& t,
|
||||
const UnicodeString& message,
|
||||
const UnicodeString& source,
|
||||
int32_t start,
|
||||
int32_t limit,
|
||||
int32_t cursor,
|
||||
const UnicodeString& expectedResult);
|
||||
|
||||
void expect(const HangulJamoTransliterator& t,
|
||||
const UnicodeString& message,
|
||||
const UnicodeString& source,
|
||||
const UnicodeString& expectedResult);
|
||||
|
||||
void expectAux(const UnicodeString& tag,
|
||||
const UnicodeString& summary, bool_t pass,
|
||||
const UnicodeString& expectedResult);
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
412
icu4c/source/test/intltest/hxuntrts.cpp
Normal file
412
icu4c/source/test/intltest/hxuntrts.cpp
Normal file
@ -0,0 +1,412 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* COPYRIGHT: *
|
||||
* (C) Copyright International Business Machines Corporation, 2000 *
|
||||
* Licensed Material - Program-Property of IBM - All Rights Reserved. *
|
||||
* US Government Users Restricted Rights - Use, duplication, or disclosure *
|
||||
* restricted by GSA ADP Schedule Contract with IBM Corp. *
|
||||
* *
|
||||
*****************************************************************************************
|
||||
************************************************************************
|
||||
* Date Name Description
|
||||
* 03/17/2000 Madhu Creation.
|
||||
************************************************************************/
|
||||
|
||||
#include "ittrans.h"
|
||||
#include "hxuntrts.h"
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/translit.h"
|
||||
#include "unicode/hextouni.h"
|
||||
#include "unicode/unifilt.h"
|
||||
#include "intltest.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
/*converts a Unicodestring to integer*/
|
||||
static int32_t getInt(UnicodeString str)
|
||||
{
|
||||
int len=str.length();
|
||||
char *alias;
|
||||
char *buffer=new char[len+1];
|
||||
alias=buffer;
|
||||
for(int i=0; i< len; i++){
|
||||
*alias=(char)str.charAt(i);
|
||||
alias++;
|
||||
}
|
||||
*alias='\0';
|
||||
return atoi(buffer);
|
||||
}
|
||||
|
||||
//---------------------------------------------
|
||||
// runIndexedTest
|
||||
//---------------------------------------------
|
||||
|
||||
void HexToUniTransliteratorTest::runIndexedTest( int32_t index, bool_t exec, char* &name, char* par )
|
||||
{
|
||||
if (exec) logln((UnicodeString)"TestSuite HexadecimalToUnicode Transliterator API ");
|
||||
switch (index) {
|
||||
|
||||
case 0: name = "TestConstruction"; if (exec) TestConstruction(); break;
|
||||
case 1: name = "TestCloneEqual"; if (exec) TestCloneEqual(); break;
|
||||
case 2: name = "TestPattern"; if (exec) TestPattern(); break;
|
||||
case 3: name = "TestSimpleTransliterate"; if (exec) TestSimpleTransliterate(); break;
|
||||
case 4: name = "TestTransliterate"; if (exec) TestTransliterate(); break;
|
||||
default: name = ""; break; /*needed to end loop*/
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Used by TestConstruction() and TestTransliterate.
|
||||
*/
|
||||
class TestHexFilter : public UnicodeFilter {
|
||||
virtual UnicodeFilter* clone() const {
|
||||
return new TestHexFilter(*this);
|
||||
}
|
||||
virtual bool_t contains(UChar c) const {
|
||||
if(c == 0x0061 || c == 0x0063 )
|
||||
return FALSE;
|
||||
else
|
||||
return TRUE;
|
||||
}
|
||||
};
|
||||
void HexToUniTransliteratorTest::TestConstruction(){
|
||||
UErrorCode status=U_ZERO_ERROR;
|
||||
logln("Testing the construction HexToUnicodeTransliterator()");
|
||||
HexToUnicodeTransliterator *trans1=new HexToUnicodeTransliterator();
|
||||
if(trans1==0){
|
||||
errln("HexToUnicodeTransliterator construction failed Error=" + (UnicodeString)u_errorName(status));
|
||||
return;
|
||||
}
|
||||
delete trans1;
|
||||
|
||||
logln("Testing the cosntruction HexToUnicodeTransliterator(pattern, status)");
|
||||
UnicodeString pattern("\\\\U+0000abc");
|
||||
trans1=new HexToUnicodeTransliterator(pattern, status);
|
||||
if(U_FAILURE(status)){
|
||||
errln("HexToUnicodeTransliterator construction failed with pattern =" + pattern + " Error=" + (UnicodeString)u_errorName(status));
|
||||
status=U_ZERO_ERROR;
|
||||
return;
|
||||
}
|
||||
delete trans1;
|
||||
|
||||
logln("Testing the construction HexToUnicodeTransliterator(pattern, status) with illegal pattern");
|
||||
UnicodeString pattern2("\\X+");
|
||||
trans1=new HexToUnicodeTransliterator(pattern2, status);
|
||||
if(U_FAILURE(status)){
|
||||
logln("OK: HexToUnicodeTransliterator construction for illegal pattern failed, as expected");
|
||||
status=U_ZERO_ERROR;
|
||||
} else {
|
||||
errln("Error: calling the HexToUnicodeTransliterator constructor with illegal pattern should fail");
|
||||
delete trans1;
|
||||
}
|
||||
|
||||
logln("Testing the construction HexToUnicodeTransliterator(pattern, adoptedFilter, status)");
|
||||
trans1=new HexToUnicodeTransliterator(pattern, NULL, status);
|
||||
if(U_FAILURE(status)){
|
||||
errln("HexToUnicodeTransliterator construction failed. Error=" + (UnicodeString)u_errorName(status));
|
||||
status=U_ZERO_ERROR;
|
||||
return;
|
||||
}
|
||||
logln("Testing the copy construction");
|
||||
HexToUnicodeTransliterator *trans1copy=new HexToUnicodeTransliterator(*trans1);
|
||||
if(trans1->toPattern() != trans1copy->toPattern() ||
|
||||
trans1->getID() != trans1copy->getID() ){
|
||||
errln("Copy construction failed");
|
||||
}
|
||||
delete trans1copy;
|
||||
delete trans1;
|
||||
|
||||
logln("Testing the construction HexToUnicodeTransliterator(adoptedFilter)");
|
||||
|
||||
trans1=new HexToUnicodeTransliterator(new TestHexFilter);
|
||||
if(trans1 == 0){
|
||||
errln("HexToUnicodeTransliterator construction failed. Error=" + (UnicodeString)u_errorName(status));
|
||||
return;
|
||||
}
|
||||
logln("Testing the copy construction");
|
||||
trans1copy=new HexToUnicodeTransliterator(*trans1);
|
||||
if(trans1->getFilter() == NULL || trans1copy->getFilter() == NULL ||
|
||||
trans1->toPattern() != trans1copy->toPattern() ||
|
||||
trans1->getID() != trans1copy->getID() ){
|
||||
errln("Copy construction failed");
|
||||
}
|
||||
|
||||
delete trans1copy;
|
||||
delete trans1;
|
||||
|
||||
}
|
||||
|
||||
void HexToUniTransliteratorTest::TestCloneEqual(){
|
||||
UErrorCode status=U_ZERO_ERROR;
|
||||
HexToUnicodeTransliterator *transdefault=new HexToUnicodeTransliterator();
|
||||
UnicodeString pattern1("\\U##00");
|
||||
UnicodeString pattern2("\\\\uni0000");
|
||||
HexToUnicodeTransliterator *trans1=new HexToUnicodeTransliterator(pattern1, status);
|
||||
if(U_FAILURE(status) && status==U_ILLEGAL_ARGUMENT_ERROR){
|
||||
errln("HexToUnicodeTransliterator construction failed");
|
||||
status=U_ZERO_ERROR;
|
||||
return;
|
||||
}
|
||||
HexToUnicodeTransliterator *trans2=new HexToUnicodeTransliterator(pattern2, status);
|
||||
if(U_FAILURE(status) && status==U_ILLEGAL_ARGUMENT_ERROR){
|
||||
errln("HexToUnicodeTransliterator construction failed");
|
||||
status=U_ZERO_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
logln("Testing the clone() API of the HexToUnicodeTransliterator");
|
||||
HexToUnicodeTransliterator *transdefaultclone=(HexToUnicodeTransliterator*)transdefault->clone();
|
||||
HexToUnicodeTransliterator *trans1clone=(HexToUnicodeTransliterator*)trans1->clone();
|
||||
HexToUnicodeTransliterator *trans2clone=(HexToUnicodeTransliterator*)trans2->clone();
|
||||
if(transdefault->toPattern() != transdefaultclone->toPattern() ||
|
||||
trans1->toPattern() != trans1clone->toPattern() ||
|
||||
trans2->toPattern() != trans2clone->toPattern() ||
|
||||
transdefault->toPattern() == trans1->toPattern() ||
|
||||
trans1->toPattern() == trans2clone->toPattern() ||
|
||||
trans2->toPattern() == transdefault->toPattern() ) {
|
||||
errln("Error: clone() failed");
|
||||
}
|
||||
|
||||
logln("Testing the =operator of the HexToUnicodeTransliterator");
|
||||
HexToUnicodeTransliterator *transdefaultequal=transdefault;
|
||||
HexToUnicodeTransliterator *trans1equal=trans1;
|
||||
HexToUnicodeTransliterator *trans2equal=trans2;
|
||||
if(transdefault->toPattern() != transdefaultequal->toPattern() ||
|
||||
trans1->toPattern() != trans1equal->toPattern() ||
|
||||
trans2->toPattern() != trans2equal->toPattern() ||
|
||||
transdefault->toPattern() == trans1->toPattern() ||
|
||||
trans1->toPattern() == trans2equal->toPattern() ||
|
||||
trans2->toPattern() == transdefault->toPattern() ) {
|
||||
errln("Error: equal() failed");
|
||||
}
|
||||
if(transdefaultclone->toPattern() != transdefaultequal->toPattern() ||
|
||||
trans1equal->toPattern() != trans1clone->toPattern() ||
|
||||
trans2clone->toPattern() != trans2equal->toPattern() ){
|
||||
errln("Error: equal() or clone() failed");
|
||||
}
|
||||
|
||||
delete transdefault;
|
||||
delete trans1;
|
||||
delete trans2;
|
||||
}
|
||||
|
||||
void HexToUniTransliteratorTest::TestPattern(){
|
||||
logln("Testing the applyPattern() and toPattern() API of HexToUnicodeTransliterator");
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
/*default transliterator has pattern \\u0000*/
|
||||
HexToUnicodeTransliterator *transdefault=new HexToUnicodeTransliterator();
|
||||
if(transdefault == 0){
|
||||
errln("HexToUnicodeTransliterator construction failed. Error=" + (UnicodeString)u_errorName(status));
|
||||
return;
|
||||
}
|
||||
UnicodeString defaultpattern=transdefault->toPattern();
|
||||
|
||||
UnicodeString pattern1("\\\\U+0000");
|
||||
HexToUnicodeTransliterator *trans1=new HexToUnicodeTransliterator(pattern1, NULL, status);
|
||||
if(U_FAILURE(status) ){
|
||||
errln("HexToUnicodeTransliterator construction failed with pattern =" + pattern1);
|
||||
status=U_ZERO_ERROR;
|
||||
return;
|
||||
}
|
||||
/*test toPattern() */
|
||||
if(transdefault->toPattern() == trans1->toPattern() ||
|
||||
transdefault->toPattern() != UnicodeString("\\\\u0000;\\\\U0000;u+0000;U+0000") ||
|
||||
trans1->toPattern() != pattern1 ){
|
||||
errln("Error: toPattern() failed "+ transdefault->toPattern());
|
||||
}
|
||||
|
||||
/*apply patterns for transdefault*/
|
||||
UnicodeString str("abKf");
|
||||
expectPattern(*transdefault, pattern1, "\\U+0061\\U+0062\\U+004B\\U+0066", str);
|
||||
expectPattern(*transdefault, "\\U##00,", "U61,U62,U4B,U66,", str);
|
||||
expectPattern(*transdefault, defaultpattern, "\\u0061\\u0062\\u004B\\u0066", str);
|
||||
expectPattern(*trans1, "\\uni0000", "uni0061uni0062uni004Buni0066", str);
|
||||
expectPattern(*trans1, "\\\\S-0000-E", "\\S-0061-E\\S-0062-E\\S-004B-E\\S-0066-E", str);
|
||||
expectPattern(*trans1, "\\u##0000", "\\u##0061\\u##0062", "FAIL");
|
||||
expectPattern(*trans1, "\\*0000", "*0061*0062*004B*0066", str);
|
||||
expectPattern(*trans1, "\\u####", "\\u##0061\\u##0062", "FAIL");
|
||||
|
||||
delete trans1;
|
||||
delete transdefault;
|
||||
|
||||
}
|
||||
void HexToUniTransliteratorTest::TestSimpleTransliterate(){
|
||||
logln("Testing the handleTransliterate() API of HexToUnicodeTransliterator");
|
||||
UErrorCode status=U_ZERO_ERROR;
|
||||
UnicodeString pattern1("\\\\U+0000");
|
||||
HexToUnicodeTransliterator *trans1=new HexToUnicodeTransliterator(pattern1, NULL, status);
|
||||
if(U_FAILURE(status)){
|
||||
errln("HexToUnicodeTransliterator construction failed with pattern =" + pattern1 + "Error: " + (UnicodeString)u_errorName(status));
|
||||
status=U_ZERO_ERROR;
|
||||
return;
|
||||
}
|
||||
UnicodeString source("He\\U+006C\\U+006C\\U+006F");
|
||||
UnicodeString rsource(source);
|
||||
Transliterator::Position index(1, source.length(),2);
|
||||
UnicodeString expected("Hello");
|
||||
trans1->handleTransliterate(rsource, index, FALSE);
|
||||
expectAux(trans1->getID() + ":handleTransliterator ", source + "-->" + rsource, rsource==expected, expected);
|
||||
expect(*trans1, "", "\\U+0048\\U+0065\\U+006C\\U+006C\\U+006F", expected);
|
||||
delete trans1;
|
||||
|
||||
HexToUnicodeTransliterator *trans2=new HexToUnicodeTransliterator(new TestHexFilter);
|
||||
expect(*trans2, "with Filter(0x0061, 0x0063) ", CharsToUnicodeString("\\u0061\\u0062\\u0063"),
|
||||
CharsToUnicodeString("\\u0061b\\u0063") );
|
||||
delete trans2;
|
||||
|
||||
}
|
||||
void HexToUniTransliteratorTest::TestTransliterate(){
|
||||
UErrorCode status=U_ZERO_ERROR;
|
||||
UnicodeString Data[]={
|
||||
//pattern, source, index.start, index.limit, index.cursor, expectedResult,
|
||||
"U+##00", "abU+63", "1", "7", "2", "abc",
|
||||
"\\\\u0000", "a\\u0062c", "1", "7", "1", "abc",
|
||||
"Uni0000", "abUni0063", "1", "9", "2", "abc",
|
||||
"U[0000]", "heU[006C]U[006C]o", "0", "16", "2", "hello",
|
||||
"prefix-0000-suffix", "aprefix-0062-suffixprefix-0063-suffix", "1", "39", "1", "abc",
|
||||
"*##00*", "hell*6F**74**68**65*re", "1", "20", "4", "hellothere",
|
||||
|
||||
};
|
||||
int i;
|
||||
for(i=0;i<sizeof(Data)/sizeof(Data[0]);i=i+6){
|
||||
HexToUnicodeTransliterator *trans1=new HexToUnicodeTransliterator(Data[i+0], NULL, status);
|
||||
if(U_FAILURE(status)){
|
||||
errln("HexToUnicodeTransliterator construction failed with pattern =" + Data[i+0]);
|
||||
status=U_ZERO_ERROR;
|
||||
continue;
|
||||
}
|
||||
expectTranslit(*trans1, "", Data[i+1], getInt(Data[i+2]), getInt(Data[i+3]), getInt(Data[i+4]), Data[i+5] );
|
||||
delete trans1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//======================================================================
|
||||
// Support methods
|
||||
//======================================================================
|
||||
|
||||
void HexToUniTransliteratorTest::expectTranslit(const HexToUnicodeTransliterator& t,
|
||||
const UnicodeString& message,
|
||||
const UnicodeString& source,
|
||||
int32_t start, int32_t limit, int32_t cursor,
|
||||
const UnicodeString& expectedResult){
|
||||
|
||||
|
||||
Transliterator::Position index(start, limit, cursor);
|
||||
UnicodeString rsource(source);
|
||||
t.handleTransliterate(rsource, index, FALSE);
|
||||
expectAux(t.getID() + ":handleTransliterator(increment=FALSE) "+ message, source + "-->" + rsource, rsource==expectedResult, expectedResult);
|
||||
|
||||
UnicodeString rsource2(source);
|
||||
index=Transliterator::Position(start, limit, cursor);
|
||||
t.handleTransliterate(rsource2, index, TRUE);
|
||||
expectAux(t.getID() + ":handleTransliterator(increment=TRUE) "+ message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
|
||||
|
||||
/*ceates a copy constructor and checks the transliteration*/
|
||||
HexToUnicodeTransliterator *copy=new HexToUnicodeTransliterator(t);
|
||||
rsource2.remove();
|
||||
rsource2.append(source);
|
||||
index=Transliterator::Position(start, limit, cursor);
|
||||
copy->handleTransliterate(rsource2, index, FALSE);
|
||||
expectAux(t.getID() + "COPY:handleTransliterator(increment=FALSE) "+ message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
|
||||
|
||||
rsource2.remove();
|
||||
rsource2.append(source);
|
||||
index=Transliterator::Position(start, limit, cursor);
|
||||
copy->handleTransliterate(rsource2, index, TRUE);
|
||||
expectAux(t.getID() + "COPY:handleTransliterator(increment=TRUE) "+ message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
|
||||
delete copy;
|
||||
|
||||
/*creates a clone and tests transliteration*/
|
||||
HexToUnicodeTransliterator *clone=(HexToUnicodeTransliterator*)t.clone();
|
||||
rsource2.remove();
|
||||
rsource2.append(source);
|
||||
index=Transliterator::Position(start, limit, cursor);
|
||||
clone->handleTransliterate(rsource2, index, FALSE);
|
||||
expectAux(t.getID() + "CLONE:handleTransliterator(increment=FALSE) "+ message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
|
||||
|
||||
rsource2.remove();
|
||||
rsource2.append(source);
|
||||
index=Transliterator::Position(start, limit, cursor);
|
||||
clone->handleTransliterate(rsource2, index, TRUE);
|
||||
expectAux(t.getID() + "CLONE:handleTransliterator(increment=TRUE) "+ message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
|
||||
|
||||
/*Uses the assignment operator to create a transliterator and tests transliteration*/
|
||||
HexToUnicodeTransliterator equal=t;
|
||||
rsource2.remove();
|
||||
rsource2.append(source);
|
||||
index=Transliterator::Position(start, limit, cursor);
|
||||
equal.handleTransliterate(rsource2, index, FALSE);
|
||||
expectAux(t.getID() + "=OPERATOR:handleTransliterator(increment=FALSE) "+ message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
|
||||
|
||||
rsource2.remove();
|
||||
rsource2.append(source);
|
||||
index=Transliterator::Position(start, limit, cursor);
|
||||
equal.handleTransliterate(rsource2, index, TRUE);
|
||||
expectAux(t.getID() + "=OPERATOR:handleTransliterator(increment=TRUE) "+ message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void HexToUniTransliteratorTest::expectPattern(HexToUnicodeTransliterator& t,
|
||||
const UnicodeString& pattern,
|
||||
const UnicodeString& source,
|
||||
const UnicodeString& expectedResult){
|
||||
UErrorCode status=U_ZERO_ERROR;
|
||||
t.applyPattern(pattern, status);
|
||||
if(expectedResult == "FAIL"){
|
||||
if(U_FAILURE(status)){
|
||||
logln("OK: calling applyPattern() with illegal pattern failed as expected. Error=" + (UnicodeString)u_errorName(status));
|
||||
status=U_ZERO_ERROR;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(U_FAILURE(status)){
|
||||
errln("Error: applyPattern() failed with pattern =" + pattern + "--->" + (UnicodeString)u_errorName(status));
|
||||
return;
|
||||
}else {
|
||||
if(t.toPattern() != pattern) {
|
||||
errln("Error: applyPattern or toPatten failed. Expected: " + pattern + "Got: " + t.toPattern());
|
||||
}
|
||||
else{
|
||||
logln("OK: applyPattern passed. Testing transliteration");
|
||||
expect(t, " with pattern "+pattern, source, expectedResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
void HexToUniTransliteratorTest::expect(const HexToUnicodeTransliterator& t,
|
||||
const UnicodeString& message,
|
||||
const UnicodeString& source,
|
||||
const UnicodeString& expectedResult) {
|
||||
|
||||
UnicodeString rsource(source);
|
||||
t.transliterate(rsource);
|
||||
expectAux(t.getID() + ":Replaceable " + message, source + "->" + rsource, rsource==expectedResult, expectedResult);
|
||||
|
||||
// Test handleTransliterate (incremental) transliteration --
|
||||
rsource.remove();
|
||||
rsource.append(source);
|
||||
Transliterator::Position index(0,source.length(),0);
|
||||
t.handleTransliterate(rsource, index, TRUE);
|
||||
expectAux(t.getID() + ":handleTransliterate " + message, source + "->" + rsource, rsource==expectedResult, expectedResult);
|
||||
|
||||
|
||||
}
|
||||
void HexToUniTransliteratorTest::expectAux(const UnicodeString& tag,
|
||||
const UnicodeString& summary, bool_t pass,
|
||||
const UnicodeString& expectedResult) {
|
||||
if (pass) {
|
||||
logln(UnicodeString("(")+tag+") " + prettify(summary));
|
||||
} else {
|
||||
errln(UnicodeString("FAIL: (")+tag+") "
|
||||
+ prettify(summary)
|
||||
+ ", expected " + prettify(expectedResult));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
73
icu4c/source/test/intltest/hxuntrts.h
Normal file
73
icu4c/source/test/intltest/hxuntrts.h
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
*****************************************************************************************
|
||||
* *
|
||||
* COPYRIGHT: *
|
||||
* (C) Copyright International Business Machines Corporation, 2000 *
|
||||
* Licensed Material - Program-Property of IBM - All Rights Reserved. *
|
||||
* US Government Users Restricted Rights - Use, duplication, or disclosure *
|
||||
* restricted by GSA ADP Schedule Contract with IBM Corp. *
|
||||
* *
|
||||
*****************************************************************************************
|
||||
************************************************************************
|
||||
* Date Name Description
|
||||
* 03/17/2000 Madhu Creation.
|
||||
************************************************************************/
|
||||
|
||||
#ifndef HEXTOUNITRTST_H
|
||||
#define HEXTOUNITRTST_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/translit.h"
|
||||
#include "unicode/hextouni.h"
|
||||
#include "intltest.h"
|
||||
|
||||
class HexToUnicodeTransliterator;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @summary General test of HexadecimalToUnicodeTransliterator
|
||||
*/
|
||||
class HexToUniTransliteratorTest : public IntlTest {
|
||||
public:
|
||||
void runIndexedTest(int32_t index, bool_t exec, char* &name, char* par=NULL);
|
||||
|
||||
/*Tests the constructors */
|
||||
void TestConstruction(void);
|
||||
/*Tests the function clone, and operator==()*/
|
||||
void TestCloneEqual(void);
|
||||
/*Tests the function getTransliterator() and setTransliterators() and adoptTransliterators()*/
|
||||
void TestPattern(void);
|
||||
/*Tests the function handleTransliterate()*/
|
||||
void TestSimpleTransliterate(void);
|
||||
/*Tests the function handleTransliterate()*/
|
||||
void TestTransliterate(void);
|
||||
|
||||
//======================================================================
|
||||
// Support methods
|
||||
//======================================================================
|
||||
void expectTranslit(const HexToUnicodeTransliterator& t,
|
||||
const UnicodeString& message,
|
||||
const UnicodeString& source,
|
||||
int32_t start, int32_t limit, int32_t cursor,
|
||||
const UnicodeString& expectedResult);
|
||||
|
||||
void expectPattern(HexToUnicodeTransliterator& t,
|
||||
const UnicodeString& pattern,
|
||||
const UnicodeString& source,
|
||||
const UnicodeString& expectedResult);
|
||||
|
||||
void expect(const HexToUnicodeTransliterator& t,
|
||||
const UnicodeString& message,
|
||||
const UnicodeString& source,
|
||||
const UnicodeString& expectedResult);
|
||||
|
||||
void expectAux(const UnicodeString& tag,
|
||||
const UnicodeString& summary, bool_t pass,
|
||||
const UnicodeString& expectedResult);
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
323
icu4c/source/test/intltest/jahatrts.cpp
Normal file
323
icu4c/source/test/intltest/jahatrts.cpp
Normal file
@ -0,0 +1,323 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* COPYRIGHT: *
|
||||
* (C) Copyright International Business Machines Corporation, 2000 *
|
||||
* Licensed Material - Program-Property of IBM - All Rights Reserved. *
|
||||
* US Government Users Restricted Rights - Use, duplication, or disclosure *
|
||||
* restricted by GSA ADP Schedule Contract with IBM Corp. *
|
||||
* *
|
||||
*****************************************************************************************
|
||||
************************************************************************
|
||||
* Date Name Description
|
||||
* 03/20/2000 Madhu Creation.
|
||||
************************************************************************/
|
||||
|
||||
#include "ittrans.h"
|
||||
#include "jahatrts.h"
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/translit.h"
|
||||
#include "unicode/jamohang.h"
|
||||
#include "unicode/unifilt.h"
|
||||
#include "intltest.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
/*converts a Unicodestring to integer*/
|
||||
static int32_t getInt(UnicodeString str)
|
||||
{
|
||||
int len=str.length();
|
||||
char *alias;
|
||||
char *buffer=new char[len+1];
|
||||
alias=buffer;
|
||||
for(int i=0; i< len; i++){
|
||||
*alias=(char)str.charAt(i);
|
||||
alias++;
|
||||
}
|
||||
*alias='\0';
|
||||
return atoi(buffer);
|
||||
}
|
||||
//---------------------------------------------
|
||||
// runIndexedTest
|
||||
//---------------------------------------------
|
||||
|
||||
void JamoToHangTransliteratorTest::runIndexedTest( int32_t index, bool_t exec, char* &name, char* par )
|
||||
{
|
||||
if (exec) logln((UnicodeString)"TestSuite JamoToHangul Transliterator API ");
|
||||
switch (index) {
|
||||
|
||||
case 0: name = "TestConstruction"; if (exec) TestConstruction(); break;
|
||||
case 1: name = "TestCloneEqual"; if (exec) TestCloneEqual(); break;
|
||||
case 2: name = "TestSimpleTransliterate"; if (exec) TestSimpleTransliterate(); break;
|
||||
case 3: name = "TestTransliterate"; if (exec) TestTransliterate(); break;
|
||||
case 4: name = "TestTransliterate2"; if (exec) TestTransliterate2(); break;
|
||||
default: name = ""; break; /*needed to end loop*/
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Used by TestConstruction() and TestTransliterate.
|
||||
*/
|
||||
class TestJamoFilter : public UnicodeFilter {
|
||||
virtual UnicodeFilter* clone() const {
|
||||
return new TestJamoFilter(*this);
|
||||
}
|
||||
virtual bool_t contains(UChar c) const {
|
||||
if(c == 0x1101 )
|
||||
return FALSE;
|
||||
else
|
||||
return TRUE;
|
||||
}
|
||||
};
|
||||
void JamoToHangTransliteratorTest::TestConstruction(){
|
||||
logln("Testing the construction JamoHangulTransliterator()");
|
||||
JamoHangulTransliterator *trans1=new JamoHangulTransliterator();
|
||||
if(trans1 == 0){
|
||||
errln("JamoHangulTransliterator() construction failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
JamoHangulTransliterator *trans2=new JamoHangulTransliterator(new TestJamoFilter);
|
||||
if(trans2 == 0){
|
||||
errln("JamoHangulTransliterator(UnicodeFilter) construction failed.");
|
||||
return;
|
||||
}
|
||||
logln("Testing copy construction");
|
||||
JamoHangulTransliterator *trans2copy=new JamoHangulTransliterator(*trans2);
|
||||
if(trans2copy == 0){
|
||||
errln("JamoHangulTransliterator copy construction failed");
|
||||
delete trans2;
|
||||
}
|
||||
|
||||
if(trans2copy->getID() != trans2->getID() ||
|
||||
trans2copy->getFilter() == NULL ||
|
||||
trans2copy->getFilter()->contains(0x1101) != trans2->getFilter()->contains(0x1101) ) {
|
||||
errln("Copy construction failed");
|
||||
}
|
||||
|
||||
|
||||
delete trans1;
|
||||
delete trans2copy;
|
||||
delete trans2;
|
||||
|
||||
}
|
||||
void JamoToHangTransliteratorTest::TestCloneEqual(){
|
||||
logln("Testing the clone and =operator of JamoHangulTransliterator");
|
||||
JamoHangulTransliterator *trans1=new JamoHangulTransliterator();
|
||||
if(trans1 == 0){
|
||||
errln("JamoHangulTransliterator() construction failed.");
|
||||
return;
|
||||
}
|
||||
JamoHangulTransliterator *trans2=new JamoHangulTransliterator(new TestJamoFilter);
|
||||
if(trans2 == 0){
|
||||
errln("JamoHangulTransliterator(UnicodeFilter) construction failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
JamoHangulTransliterator *trans1equal=trans1;
|
||||
JamoHangulTransliterator *trans2equal=trans2;
|
||||
if(trans1equal == 0 || trans2equal==0 ){
|
||||
errln("=Operator failed");
|
||||
delete trans1;
|
||||
delete trans2;
|
||||
return;
|
||||
}
|
||||
if(trans1->getID() != trans1equal->getID() ||
|
||||
trans1equal->getFilter() != NULL ||
|
||||
trans2->getID() != trans2equal->getID() ||
|
||||
trans2equal->getFilter() == NULL ||
|
||||
trans2equal->getFilter()->contains(0x1101) != trans2->getFilter()->contains(0x1101) ) {
|
||||
errln("=Operator failed");
|
||||
}
|
||||
|
||||
|
||||
JamoHangulTransliterator *trans1clone=(JamoHangulTransliterator*)trans1->clone();
|
||||
JamoHangulTransliterator *trans2clone=(JamoHangulTransliterator*)trans2->clone();
|
||||
if(trans1clone == 0 || trans2clone==0 ){
|
||||
errln("clone() failed");
|
||||
delete trans1;
|
||||
delete trans2;
|
||||
return;
|
||||
}
|
||||
if(trans1->getID() != trans1clone->getID() ||
|
||||
trans1clone->getFilter() != NULL ||
|
||||
trans2->getID() != trans2clone->getID() ||
|
||||
trans2clone->getFilter() == NULL ||
|
||||
trans2clone->getFilter()->contains(0x1101) != trans2->getFilter()->contains(0x1101) ) {
|
||||
errln("=Operator failed");
|
||||
}
|
||||
|
||||
delete trans1;
|
||||
delete trans2;
|
||||
}
|
||||
|
||||
void JamoToHangTransliteratorTest::TestSimpleTransliterate(){
|
||||
logln("Testing the handleTransliterate() of JamoHangulTransliterator");
|
||||
JamoHangulTransliterator *trans1=new JamoHangulTransliterator();
|
||||
if(trans1==0){
|
||||
errln("JamoHangulTransliterator construction failed");
|
||||
return;
|
||||
}
|
||||
UChar src[]={ 0x1101, 0x1109, 0x1166, 0x11A8, 0x11AD, 0x116D, 0};
|
||||
UnicodeString source(src);
|
||||
UnicodeString expected(CharsToUnicodeString("\\uAE4C\\uC139\\uC54A\\uC694"));
|
||||
expect(*trans1, "", source, expected);
|
||||
|
||||
JamoHangulTransliterator *trans2=new JamoHangulTransliterator(new TestJamoFilter);
|
||||
if(trans2==0){
|
||||
errln("JamoHangulTransliterator(UnicodeFilter) construction failed");
|
||||
return;
|
||||
}
|
||||
expect(*trans2, " with Filter(0x1101) ", source, CharsToUnicodeString("\\u1101\\uC139\\uC54A\\uC694"));
|
||||
|
||||
|
||||
}
|
||||
void JamoToHangTransliteratorTest::TestTransliterate2(){
|
||||
logln("Testing the handleTransliterate() of JamoHangulTransliterator");
|
||||
JamoHangulTransliterator *trans1=new JamoHangulTransliterator();
|
||||
if(trans1==0){
|
||||
errln("JamoHangulTransliterator construction failed");
|
||||
return;
|
||||
}
|
||||
UnicodeString source, expected, temp;
|
||||
UChar choseong=0x1100;
|
||||
UChar jungseong=0x1161;
|
||||
UChar jongseong=0x11a8;
|
||||
for(UChar c=0xac01;c<0xacff;++c){
|
||||
source.append(choseong);
|
||||
if(jongseong > 0x11c2){
|
||||
jongseong=0x11a8;
|
||||
jungseong++;
|
||||
source.append(jungseong);
|
||||
}
|
||||
else {
|
||||
source.append(jungseong);
|
||||
source.append(jongseong++);
|
||||
}
|
||||
expected.append(c);
|
||||
|
||||
expect(*trans1, "", source, expected);
|
||||
source.remove();
|
||||
expected.remove();
|
||||
|
||||
}
|
||||
}
|
||||
void JamoToHangTransliteratorTest::TestTransliterate(){
|
||||
UnicodeString Data[]={
|
||||
// source, index.start, index.limit, index.cursor, expectedResult, expectedResult using Filter(TestJamoFilter)
|
||||
CharsToUnicodeString("\\u1100\\u1101\\u1102"), "1", "3", "1", CharsToUnicodeString("\\u1100\\uAE4C\\uB098"), CharsToUnicodeString("\\u1100\\u1101\\uB098"),
|
||||
CharsToUnicodeString("\\u1167\\u1101"), "0", "1", "0", CharsToUnicodeString("\\uc5ec\\u1101"), CharsToUnicodeString("\\uc5ec\\u1101"),
|
||||
CharsToUnicodeString("\\u1167\\u1101"), "0", "2", "0", CharsToUnicodeString("\\uc5ec\\uae4c"), CharsToUnicodeString("\\uc5ec\\u1101"),
|
||||
|
||||
|
||||
};
|
||||
int i;
|
||||
JamoHangulTransliterator *trans1=new JamoHangulTransliterator();
|
||||
if(trans1 == 0){
|
||||
errln("JamoHangulTransliterator construction failed");
|
||||
return;
|
||||
}
|
||||
JamoHangulTransliterator *trans2=new JamoHangulTransliterator(new TestJamoFilter);
|
||||
if(trans2 == 0){
|
||||
errln("JamoHangulTransliterator(UnicodeFilter) construction failed");
|
||||
return;
|
||||
}
|
||||
for(i=0;i<sizeof(Data)/sizeof(Data[0]);i=i+6){
|
||||
expectTranslit(*trans1, ":", Data[i+0], getInt(Data[i+1]), getInt(Data[i+2]), getInt(Data[i+3]), Data[i+4] );
|
||||
expectTranslit(*trans2, " with Filter(0x1101):", Data[i+0], getInt(Data[i+1]), getInt(Data[i+2]), getInt(Data[i+3]), Data[i+5] );
|
||||
|
||||
}
|
||||
delete trans1;
|
||||
delete trans2;
|
||||
|
||||
}
|
||||
//======================================================================
|
||||
// Support methods
|
||||
//======================================================================
|
||||
|
||||
void JamoToHangTransliteratorTest::expectTranslit(const JamoHangulTransliterator& t,
|
||||
const UnicodeString& message,
|
||||
const UnicodeString& source,
|
||||
int32_t start, int32_t limit, int32_t cursor,
|
||||
const UnicodeString& expectedResult){
|
||||
|
||||
|
||||
Transliterator::Position index(start, limit, cursor);
|
||||
UnicodeString rsource(source);
|
||||
t.handleTransliterate(rsource, index, FALSE);
|
||||
expectAux(t.getID() + ":handleTransliterator(increment=FALSE) " + message, source + "-->" + rsource, rsource==expectedResult, expectedResult);
|
||||
|
||||
UnicodeString rsource2(source);
|
||||
index=Transliterator::Position(start, limit, cursor);
|
||||
t.handleTransliterate(rsource2, index, TRUE);
|
||||
expectAux(t.getID() + ":handleTransliterator(increment=TRUE) " + message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
|
||||
|
||||
/*ceates a copy constructor and checks the transliteration*/
|
||||
JamoHangulTransliterator *copy=new JamoHangulTransliterator(t);
|
||||
rsource2.remove();
|
||||
rsource2.append(source);
|
||||
index=Transliterator::Position(start, limit, cursor);
|
||||
copy->handleTransliterate(rsource2, index, FALSE);
|
||||
expectAux(t.getID() + "COPY:handleTransliterator(increment=FALSE) "+ message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
|
||||
|
||||
rsource2.remove();
|
||||
rsource2.append(source);
|
||||
index=Transliterator::Position(start, limit, cursor);
|
||||
copy->handleTransliterate(rsource2, index, TRUE);
|
||||
expectAux(t.getID() + "COPY:handleTransliterator(increment=TRUE) "+ message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
|
||||
delete copy;
|
||||
|
||||
/*creates a clone and tests transliteration*/
|
||||
JamoHangulTransliterator *clone=(JamoHangulTransliterator*)t.clone();
|
||||
rsource2.remove();
|
||||
rsource2.append(source);
|
||||
index=Transliterator::Position(start, limit, cursor);
|
||||
clone->handleTransliterate(rsource2, index, FALSE);
|
||||
expectAux(t.getID() + "CLONE:handleTransliterator(increment=FALSE) "+ message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
|
||||
|
||||
rsource2.remove();
|
||||
rsource2.append(source);
|
||||
index=Transliterator::Position(start, limit, cursor);
|
||||
clone->handleTransliterate(rsource2, index, TRUE);
|
||||
expectAux(t.getID() + "CLONE:handleTransliterator(increment=TRUE) "+ message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
|
||||
|
||||
/*Uses the assignment operator to create a transliterator and tests transliteration*/
|
||||
JamoHangulTransliterator equal=t;
|
||||
rsource2.remove();
|
||||
rsource2.append(source);
|
||||
index=Transliterator::Position(start, limit, cursor);
|
||||
equal.handleTransliterate(rsource2, index, FALSE);
|
||||
expectAux(t.getID() + "=OPERATOR:handleTransliterator(increment=FALSE) "+ message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
|
||||
|
||||
rsource2.remove();
|
||||
rsource2.append(source);
|
||||
index=Transliterator::Position(start, limit, cursor);
|
||||
equal.handleTransliterate(rsource2, index, TRUE);
|
||||
expectAux(t.getID() + "=OPERATOR:handleTransliterator(increment=TRUE) "+ message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
|
||||
|
||||
}
|
||||
void JamoToHangTransliteratorTest::expect(const JamoHangulTransliterator& t,
|
||||
const UnicodeString& message,
|
||||
const UnicodeString& source,
|
||||
const UnicodeString& expectedResult) {
|
||||
|
||||
UnicodeString rsource(source);
|
||||
t.transliterate(rsource);
|
||||
expectAux(t.getID() + ":Replaceable " + message, source + "->" + rsource, rsource==expectedResult, expectedResult);
|
||||
|
||||
// Test handleTransliterate (incremental) transliteration --
|
||||
rsource.remove();
|
||||
rsource.append(source);
|
||||
Transliterator::Position index(0,source.length(),0);
|
||||
t.handleTransliterate(rsource, index, TRUE);
|
||||
expectAux(t.getID() + ":handleTransliterate " + message, source + "->" + rsource, rsource==expectedResult, expectedResult);
|
||||
|
||||
}
|
||||
void JamoToHangTransliteratorTest::expectAux(const UnicodeString& tag,
|
||||
const UnicodeString& summary, bool_t pass,
|
||||
const UnicodeString& expectedResult) {
|
||||
if (pass) {
|
||||
logln(UnicodeString("(")+tag+") " + prettify(summary));
|
||||
} else {
|
||||
errln(UnicodeString("FAIL: (")+tag+") "
|
||||
+ prettify(summary)
|
||||
+ ", expected " + prettify(expectedResult));
|
||||
}
|
||||
}
|
72
icu4c/source/test/intltest/jahatrts.h
Normal file
72
icu4c/source/test/intltest/jahatrts.h
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
*****************************************************************************************
|
||||
* *
|
||||
* COPYRIGHT: *
|
||||
* (C) Copyright International Business Machines Corporation, 2000 *
|
||||
* Licensed Material - Program-Property of IBM - All Rights Reserved. *
|
||||
* US Government Users Restricted Rights - Use, duplication, or disclosure *
|
||||
* restricted by GSA ADP Schedule Contract with IBM Corp. *
|
||||
* *
|
||||
*****************************************************************************************
|
||||
************************************************************************
|
||||
* Date Name Description
|
||||
* 03/20/2000 Madhu Creation.
|
||||
************************************************************************/
|
||||
|
||||
#ifndef JAMOTOHANGTRTST_H
|
||||
#define JAMOTOHANGTRTST_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/translit.h"
|
||||
#include "unicode/jamohang.h"
|
||||
#include "intltest.h"
|
||||
|
||||
class JamoHangulTransliterator;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @summary General test of JamoToHangul Transliterator
|
||||
*/
|
||||
class JamoToHangTransliteratorTest : public IntlTest {
|
||||
public:
|
||||
void runIndexedTest(int32_t index, bool_t exec, char* &name, char* par=NULL);
|
||||
|
||||
/*Tests the constructors */
|
||||
void TestConstruction(void);
|
||||
/*Tests the function clone, and operator==()*/
|
||||
void TestCloneEqual(void);
|
||||
/*Tests the function handleTransliterate()*/
|
||||
void TestSimpleTransliterate(void);
|
||||
/*Tests the function handleTransliterate()*/
|
||||
void TestTransliterate(void);
|
||||
void TestTransliterate2(void);
|
||||
|
||||
|
||||
//======================================================================
|
||||
// Support methods
|
||||
//======================================================================
|
||||
void expectTranslit(const JamoHangulTransliterator& t,
|
||||
const UnicodeString& message,
|
||||
const UnicodeString& source,
|
||||
int32_t start,
|
||||
int32_t limit,
|
||||
int32_t cursor,
|
||||
const UnicodeString& expectedResult);
|
||||
|
||||
void expect(const JamoHangulTransliterator& t,
|
||||
const UnicodeString& message,
|
||||
const UnicodeString& source,
|
||||
const UnicodeString& expectedResult);
|
||||
|
||||
void expectAux(const UnicodeString& tag,
|
||||
const UnicodeString& summary, bool_t pass,
|
||||
const UnicodeString& expectedResult);
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
224
icu4c/source/test/intltest/ufltlgts.cpp
Normal file
224
icu4c/source/test/intltest/ufltlgts.cpp
Normal file
@ -0,0 +1,224 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* COPYRIGHT: *
|
||||
* (C) Copyright International Business Machines Corporation, 2000 *
|
||||
* Licensed Material - Program-Property of IBM - All Rights Reserved. *
|
||||
* US Government Users Restricted Rights - Use, duplication, or disclosure *
|
||||
* restricted by GSA ADP Schedule Contract with IBM Corp. *
|
||||
* *
|
||||
*****************************************************************************************
|
||||
************************************************************************
|
||||
* Date Name Description
|
||||
* 03/22/2000 Madhu Creation.
|
||||
************************************************************************/
|
||||
|
||||
#include "ittrans.h"
|
||||
#include "ufltlgts.h"
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/translit.h"
|
||||
#include "unicode/unifilt.h"
|
||||
#include "unicode/unifltlg.h"
|
||||
#include "intltest.h"
|
||||
|
||||
//---------------------------------------------
|
||||
// runIndexedTest
|
||||
//---------------------------------------------
|
||||
|
||||
void UnicodeFilterLogicTest::runIndexedTest( int32_t index, bool_t exec, char* &name, char* par )
|
||||
{
|
||||
if (exec) logln((UnicodeString)"TestSuite UnicodeFilterLogic API ");
|
||||
switch (index) {
|
||||
|
||||
case 0: name = "TestAll"; if (exec) TestAll(); break;
|
||||
|
||||
default: name = ""; break; /*needed to end loop*/
|
||||
}
|
||||
}
|
||||
|
||||
class Filter1: public UnicodeFilter{
|
||||
virtual UnicodeFilter* clone() const{
|
||||
return new Filter1(*this);
|
||||
}
|
||||
virtual bool_t contains(UChar c) const {
|
||||
if(c == 'a' || c == 'A' || c == 'c' || c == 'C')
|
||||
return FALSE;
|
||||
else
|
||||
return TRUE;
|
||||
}
|
||||
};
|
||||
class Filter2: public UnicodeFilter{
|
||||
virtual UnicodeFilter* clone() const{
|
||||
return new Filter2(*this);
|
||||
}
|
||||
virtual bool_t contains(UChar c) const {
|
||||
if(c == 'y' || c == 'Y' || c == 'z' || c == 'Z' || c =='a' || c == 'c')
|
||||
return FALSE;
|
||||
else
|
||||
return TRUE;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void UnicodeFilterLogicTest::TestAll(){
|
||||
|
||||
Transliterator *t1=Transliterator::createInstance("Unicode-Hex");
|
||||
if(t1 == 0){
|
||||
errln("FAIL: Error in instantiation.");
|
||||
return;
|
||||
}
|
||||
UnicodeString source("abcdABCDyzYZ");
|
||||
|
||||
//sanity testing wihtout any filter
|
||||
expect(*t1, "without any Filter", source, "\\u0061\\u0062\\u0063\\u0064\\u0041\\u0042\\u0043\\u0044\\u0079\\u007A\\u0059\\u005A");
|
||||
//sanity testing using the Filter1(acAC) and Filter2(acyzYZ)
|
||||
t1->adoptFilter(new Filter1);
|
||||
expect(*t1, "with Filter(acAC)", source, "a\\u0062c\\u0064A\\u0042C\\u0044\\u0079\\u007A\\u0059\\u005A");
|
||||
t1->adoptFilter(new Filter2);
|
||||
expect(*t1, "with Filter2(acyzYZ)", source, "a\\u0062c\\u0064\\u0041\\u0042\\u0043\\u0044yzYZ");
|
||||
|
||||
|
||||
UnicodeFilter *filterNOT=UnicodeFilterLogic::createNot(new Filter1);
|
||||
UnicodeFilter *filterAND=UnicodeFilterLogic::createAnd(new Filter1, new Filter2);
|
||||
UnicodeFilter *filterOR=UnicodeFilterLogic::createOr(new Filter1, new Filter2);
|
||||
|
||||
TestNOT(*t1, new Filter1, "Filter(acAC)",
|
||||
source, "\\u0061b\\u0063d\\u0041B\\u0043DyzYZ");
|
||||
TestNOT(*t1, new Filter2, "Filter(acyzYZ)",
|
||||
source, "\\u0061b\\u0063dABCD\\u0079\\u007A\\u0059\\u005A");
|
||||
TestNOT(*t1, NULL, "NULL",
|
||||
source, "abcdABCDyzYZ");
|
||||
TestNOT(*t1, filterNOT, "FilterNOT(Fitler1(acAC))",
|
||||
source, "a\\u0062c\\u0064A\\u0042C\\u0044\\u0079\\u007A\\u0059\\u005A");
|
||||
TestNOT(*t1, filterAND, "FilterAND(Fitler1(acAC), Filter2(acyzYZ))",
|
||||
source, "\\u0061b\\u0063d\\u0041B\\u0043D\\u0079\\u007A\\u0059\\u005A");
|
||||
TestNOT(*t1, filterOR, "FilterOR(Fitler1(acAC), Filter2(acyzYZ))",
|
||||
source, "\\u0061b\\u0063dABCDyzYZ");
|
||||
|
||||
TestAND(*t1, new Filter1, new Filter2, "Filter1(a,c,A,C), Filter2(acyzYZ)",
|
||||
source, "a\\u0062c\\u0064A\\u0042C\\u0044yzYZ");
|
||||
TestAND(*t1, new Filter2, new Filter1, "Filter2(acyzYZ), Filter1(a,c,A,C), ",
|
||||
source, "a\\u0062c\\u0064A\\u0042C\\u0044yzYZ");
|
||||
TestAND(*t1, new Filter1, NULL, "Filter1(a,c,A,C), NULL",
|
||||
source, "a\\u0062c\\u0064A\\u0042C\\u0044\\u0079\\u007A\\u0059\\u005A");
|
||||
TestAND(*t1, NULL, new Filter2, "NULL, Filter2(acyzYZ)",
|
||||
source, "a\\u0062c\\u0064\\u0041\\u0042\\u0043\\u0044yzYZ");
|
||||
TestAND(*t1, NULL, NULL, "NULL, NULL",
|
||||
source, "\\u0061\\u0062\\u0063\\u0064\\u0041\\u0042\\u0043\\u0044\\u0079\\u007A\\u0059\\u005A");
|
||||
TestAND(*t1, filterAND, NULL, "FilterAND(Fitler1(acAC), Filter2(acyzYZ)), NULL",
|
||||
source, "a\\u0062c\\u0064A\\u0042C\\u0044yzYZ");
|
||||
TestAND(*t1, filterAND, new Filter1, "FilterAND(Fitler1(acAC), Filter2(acyzYZ)), Filter1(acAC)",
|
||||
source, "a\\u0062c\\u0064A\\u0042C\\u0044yzYZ");
|
||||
TestAND(*t1, filterAND, new Filter2, "FilterAND(Fitler1(acAC), Filter2(acyzYZ)), Filter2(acyzYZ)",
|
||||
source, "a\\u0062c\\u0064A\\u0042C\\u0044yzYZ");
|
||||
TestAND(*t1, new Filter1, filterAND, "Filter1(acAC), FilterAND(Filter1(acAC), Fitler1(acAC))",
|
||||
source, "a\\u0062c\\u0064A\\u0042C\\u0044yzYZ");
|
||||
TestAND(*t1, new Filter2, filterAND, "Filter2(acyzYZ), FilterAND(Filter1(acAC), Fitler1(acAC))",
|
||||
source, "a\\u0062c\\u0064A\\u0042C\\u0044yzYZ");
|
||||
TestAND(*t1, filterOR, NULL, "FilterOR(Fitler1(acAC), Filter2(acyzYZ)), NULL",
|
||||
source, "a\\u0062c\\u0064\\u0041\\u0042\\u0043\\u0044\\u0079\\u007A\\u0059\\u005A");
|
||||
TestAND(*t1, filterOR, new Filter1, "FilterOR(Fitler1(acAC), Filter2(acyzYZ)), Fitler1(acAC)",
|
||||
source, "a\\u0062c\\u0064A\\u0042C\\u0044\\u0079\\u007A\\u0059\\u005A");
|
||||
TestAND(*t1, filterOR, new Filter2, "FilterOR(Fitler1(acAC), Filter2(acyzYZ)), Fitler2(acyzYZ)",
|
||||
source, "a\\u0062c\\u0064\\u0041\\u0042\\u0043\\u0044yzYZ");
|
||||
TestAND(*t1, filterNOT, new Filter1, "FilterNOT(Fitler1(acAC)), Fitler1(acAC)",
|
||||
source, "abcdABCDyzYZ");
|
||||
TestAND(*t1, new Filter1, filterNOT, "Fitler1(acAC), FilterNOT(Fitler1(acAC))",
|
||||
source, "abcdABCDyzYZ");
|
||||
TestAND(*t1, filterNOT, new Filter2, "FilterNOT(Fitler1(acAC)), Fitler2(acyzYZ)",
|
||||
source, "abcd\\u0041B\\u0043DyzYZ");
|
||||
TestAND(*t1, new Filter2, filterNOT, "Fitler2(acyzYZ), FilterNOT(Fitler1(acAC))",
|
||||
source, "abcd\\u0041B\\u0043DyzYZ");
|
||||
|
||||
TestOR(*t1, new Filter1, new Filter2, "Filter1(a,c,A,C), Filter2(acyzYZ)",
|
||||
source, "a\\u0062c\\u0064\\u0041\\u0042\\u0043\\u0044\\u0079\\u007A\\u0059\\u005A");
|
||||
TestOR(*t1, new Filter2, new Filter1, "Filter2(acyzYZ), Filter1(a,c,A,C)",
|
||||
source, "a\\u0062c\\u0064\\u0041\\u0042\\u0043\\u0044\\u0079\\u007A\\u0059\\u005A");
|
||||
TestOR(*t1, new Filter1, NULL, "Filter1(a,c,A,C), NULL",
|
||||
source, "a\\u0062c\\u0064A\\u0042C\\u0044\\u0079\\u007A\\u0059\\u005A");
|
||||
TestOR(*t1, NULL, new Filter2, "NULL, Filter2(acyzYZ)",
|
||||
source, "a\\u0062c\\u0064\\u0041\\u0042\\u0043\\u0044yzYZ");
|
||||
TestOR(*t1, NULL, NULL, "NULL, NULL",
|
||||
source, "\\u0061\\u0062\\u0063\\u0064\\u0041\\u0042\\u0043\\u0044\\u0079\\u007A\\u0059\\u005A");
|
||||
TestOR(*t1, filterAND, NULL, "FilterAND(Fitler1(acAC), Filter2(acyzYZ)), NULL",
|
||||
source, "a\\u0062c\\u0064A\\u0042C\\u0044yzYZ");
|
||||
TestOR(*t1, filterAND, new Filter1, "FilterAND(Fitler1(acAC), Filter2(acyzYZ)), Filter1(acAC)",
|
||||
source, "a\\u0062c\\u0064A\\u0042C\\u0044\\u0079\\u007A\\u0059\\u005A");
|
||||
TestOR(*t1, filterAND, new Filter2, "FilterAND(Fitler1(acAC), Filter2(acyzYZ)), Filter2(acyzYZ)",
|
||||
source, "a\\u0062c\\u0064\\u0041\\u0042\\u0043\\u0044yzYZ");
|
||||
TestOR(*t1, new Filter1, filterAND, "Filter1(acAC), FilterAND(Filter1(acAC), Fitler1(acAC))",
|
||||
source, "a\\u0062c\\u0064A\\u0042C\\u0044\\u0079\\u007A\\u0059\\u005A");
|
||||
TestOR(*t1, new Filter2, filterAND, "Filter2(acyzYZ), FilterAND(Filter1(acAC), Fitler1(acAC))",
|
||||
source, "a\\u0062c\\u0064\\u0041\\u0042\\u0043\\u0044yzYZ");
|
||||
TestOR(*t1, filterNOT, new Filter1, "FilterNOT(Fitler1(acAC)), Fitler1(acAC)",
|
||||
source, "\\u0061\\u0062\\u0063\\u0064\\u0041\\u0042\\u0043\\u0044\\u0079\\u007A\\u0059\\u005A");
|
||||
TestOR(*t1, new Filter1, filterNOT, "Fitler1(acAC), FilterNOT(Fitler1(acAC))",
|
||||
source, "\\u0061\\u0062\\u0063\\u0064\\u0041\\u0042\\u0043\\u0044\\u0079\\u007A\\u0059\\u005A");
|
||||
TestOR(*t1, filterNOT, new Filter2, "FilterNOT(Fitler1(acAC)), Fitler1(acyzYZ)",
|
||||
source, "\\u0061\\u0062\\u0063\\u0064\\u0041\\u0042\\u0043\\u0044yzYZ");
|
||||
TestOR(*t1, new Filter2, filterNOT, "Fitler2(acyzYZ), FilterNOT(Fitler1(acAC))",
|
||||
source, "\\u0061\\u0062\\u0063\\u0064\\u0041\\u0042\\u0043\\u0044yzYZ");
|
||||
|
||||
|
||||
delete filterNOT;
|
||||
delete filterAND;
|
||||
delete filterOR;
|
||||
delete t1;
|
||||
|
||||
}
|
||||
void UnicodeFilterLogicTest::TestNOT(Transliterator& t,
|
||||
const UnicodeFilter* f1,
|
||||
const UnicodeString& message,
|
||||
const UnicodeString& source,
|
||||
const UnicodeString& expected){
|
||||
UnicodeFilter *filter=UnicodeFilterLogic::createNot(f1);
|
||||
t.adoptFilter(filter);
|
||||
expect(t, "with FilterNOT(" + message + ")", source, expected);
|
||||
|
||||
}
|
||||
void UnicodeFilterLogicTest::TestAND(Transliterator& t,
|
||||
const UnicodeFilter* f1,
|
||||
const UnicodeFilter* f2,
|
||||
const UnicodeString& message,
|
||||
const UnicodeString& source,
|
||||
const UnicodeString& expected){
|
||||
UnicodeFilter *filter=UnicodeFilterLogic::createAnd(f1, f2);
|
||||
t.adoptFilter(filter);
|
||||
expect(t, "with FilterAND(" + message + ")", source, expected);
|
||||
|
||||
}
|
||||
void UnicodeFilterLogicTest::TestOR(Transliterator& t,
|
||||
const UnicodeFilter* f1,
|
||||
const UnicodeFilter* f2,
|
||||
const UnicodeString& message,
|
||||
const UnicodeString& source,
|
||||
const UnicodeString& expected){
|
||||
UnicodeFilter *filter=UnicodeFilterLogic::createOr(f1, f2);
|
||||
t.adoptFilter(filter);
|
||||
expect(t, "with FilterOR(" + message + ")", source, expected);
|
||||
|
||||
}
|
||||
|
||||
void UnicodeFilterLogicTest::expect(const Transliterator& t,
|
||||
const UnicodeString& message,
|
||||
const UnicodeString& source,
|
||||
const UnicodeString& expectedResult) {
|
||||
|
||||
|
||||
UnicodeString rsource(source);
|
||||
t.transliterate(rsource);
|
||||
expectAux(t.getID() + ":Replaceable " + message, source + "->" + rsource, rsource==expectedResult, expectedResult);
|
||||
|
||||
}
|
||||
void UnicodeFilterLogicTest::expectAux(const UnicodeString& tag,
|
||||
const UnicodeString& summary, bool_t pass,
|
||||
const UnicodeString& expectedResult) {
|
||||
if (pass) {
|
||||
logln(UnicodeString("(")+tag+") " + prettify(summary));
|
||||
} else {
|
||||
errln(UnicodeString("FAIL: (")+tag+") "
|
||||
+ prettify(summary)
|
||||
+ ", expected " + prettify(expectedResult));
|
||||
}
|
||||
}
|
||||
|
||||
|
69
icu4c/source/test/intltest/ufltlgts.h
Normal file
69
icu4c/source/test/intltest/ufltlgts.h
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
*****************************************************************************************
|
||||
* *
|
||||
* COPYRIGHT: *
|
||||
* (C) Copyright International Business Machines Corporation, 2000 *
|
||||
* Licensed Material - Program-Property of IBM - All Rights Reserved. *
|
||||
* US Government Users Restricted Rights - Use, duplication, or disclosure *
|
||||
* restricted by GSA ADP Schedule Contract with IBM Corp. *
|
||||
* *
|
||||
*****************************************************************************************
|
||||
************************************************************************
|
||||
* Date Name Description
|
||||
* 03/22/2000 Madhu Creation.
|
||||
************************************************************************/
|
||||
|
||||
#ifndef UNIFLTLOGICTST_H
|
||||
#define UNIFLTLOGICTST_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/translit.h"
|
||||
#include "unicode/unifltlg.h"
|
||||
#include "intltest.h"
|
||||
|
||||
class UnicodeFilterLogic;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @summary General test of UnicodeFilterLogic API
|
||||
*/
|
||||
class UnicodeFilterLogicTest : public IntlTest {
|
||||
public:
|
||||
void runIndexedTest(int32_t index, bool_t exec, char* &name, char* par=NULL);
|
||||
|
||||
/*Tests all the NOT, OR and AND filters */
|
||||
void TestAll(void);
|
||||
|
||||
void TestNOT(Transliterator& t,
|
||||
const UnicodeFilter* f1,
|
||||
const UnicodeString& message,
|
||||
const UnicodeString& source,
|
||||
const UnicodeString& expected);
|
||||
|
||||
void TestAND(Transliterator& t,
|
||||
const UnicodeFilter* f1,
|
||||
const UnicodeFilter* f2,
|
||||
const UnicodeString& message,
|
||||
const UnicodeString& source,
|
||||
const UnicodeString& expected);
|
||||
|
||||
void TestOR(Transliterator& t,
|
||||
const UnicodeFilter* f1,
|
||||
const UnicodeFilter* f2,
|
||||
const UnicodeString& message,
|
||||
const UnicodeString& source,
|
||||
const UnicodeString& expected);
|
||||
|
||||
//support functions
|
||||
void expect(const Transliterator& t,
|
||||
const UnicodeString& message,
|
||||
const UnicodeString& source,
|
||||
const UnicodeString& expectedResult);
|
||||
|
||||
void UnicodeFilterLogicTest::expectAux(const UnicodeString& tag,
|
||||
const UnicodeString& summary, bool_t pass,
|
||||
const UnicodeString& expectedResult);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
467
icu4c/source/test/intltest/unhxtrts.cpp
Normal file
467
icu4c/source/test/intltest/unhxtrts.cpp
Normal file
@ -0,0 +1,467 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* COPYRIGHT: *
|
||||
* (C) Copyright International Business Machines Corporation, 2000 *
|
||||
* Licensed Material - Program-Property of IBM - All Rights Reserved. *
|
||||
* US Government Users Restricted Rights - Use, duplication, or disclosure *
|
||||
* restricted by GSA ADP Schedule Contract with IBM Corp. *
|
||||
* *
|
||||
*****************************************************************************************
|
||||
************************************************************************
|
||||
* Date Name Description
|
||||
* 03/15/2000 Madhu Creation.
|
||||
************************************************************************/
|
||||
|
||||
#include "ittrans.h"
|
||||
#include "unhxtrts.h"
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/translit.h"
|
||||
#include "unicode/unitohex.h"
|
||||
#include "unicode/unifilt.h"
|
||||
#include "intltest.h"
|
||||
/*converts a Unicodestring to integer*/
|
||||
static int32_t getInt(UnicodeString str)
|
||||
{
|
||||
int len=str.length();
|
||||
char *alias;
|
||||
char *buffer=new char[len+1];
|
||||
alias=buffer;
|
||||
for(int i=0; i< len; i++){
|
||||
*alias=(char)str.charAt(i);
|
||||
alias++;
|
||||
}
|
||||
*alias='\0';
|
||||
return atoi(buffer);
|
||||
}
|
||||
//---------------------------------------------
|
||||
// runIndexedTest
|
||||
//---------------------------------------------
|
||||
|
||||
void UniToHexTransliteratorTest::runIndexedTest( int32_t index, bool_t exec, char* &name, char* par )
|
||||
{
|
||||
if (exec) logln((UnicodeString)"TestSuite UnicodeToHexadecimal Transliterator API ");
|
||||
switch (index) {
|
||||
|
||||
case 0: name = "TestConstruction"; if (exec) TestConstruction(); break;
|
||||
case 1: name = "TestCloneEqual"; if (exec) TestCloneEqual(); break;
|
||||
case 2: name = "TestUpperCase"; if (exec) TestUpperCase(); break;
|
||||
case 3: name = "TestPattern"; if (exec) TestPattern(); break;
|
||||
case 4: name = "TestSimpleTransliterate"; if (exec) TestSimpleTransliterate(); break;
|
||||
case 5: name = "TestTransliterate"; if (exec) TestTransliterate(); break;
|
||||
default: name = ""; break; /*needed to end loop*/
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Used by TestConstruction() and TestTransliterate.
|
||||
*/
|
||||
class TestUniFilter : public UnicodeFilter {
|
||||
virtual UnicodeFilter* clone() const {
|
||||
return new TestUniFilter(*this);
|
||||
}
|
||||
virtual bool_t contains(UChar c) const {
|
||||
if(c=='c' || c=='a' || c=='C' || c=='A')
|
||||
return FALSE;
|
||||
else
|
||||
return TRUE;
|
||||
}
|
||||
};
|
||||
void UniToHexTransliteratorTest::TestConstruction(){
|
||||
UErrorCode status=U_ZERO_ERROR;
|
||||
logln("Testing the construction UnicodeToHexTransliterator()");
|
||||
UnicodeToHexTransliterator *trans1=new UnicodeToHexTransliterator();
|
||||
if(trans1==0){
|
||||
errln("UnicodeToHexTransliterator construction failed Error=" + (UnicodeString)u_errorName(status));
|
||||
return;
|
||||
}
|
||||
delete trans1;
|
||||
|
||||
logln("Testing the cosntruction UnicodeToHexTransliterator(pattern, status)");
|
||||
UnicodeString pattern("\\\\U+0000abc");
|
||||
trans1=new UnicodeToHexTransliterator(pattern, status);
|
||||
if(U_FAILURE(status)){
|
||||
errln("UnicodeToHexTransliterator construction failed with pattern =" + pattern + " Error=" + (UnicodeString)u_errorName(status));
|
||||
status=U_ZERO_ERROR;
|
||||
return;
|
||||
}
|
||||
delete trans1;
|
||||
|
||||
logln("Testing the cosntruction UnicodeToHexTransliterator(pattern, status) with illegal pattern");
|
||||
UnicodeString pattern2("\\X+");
|
||||
trans1=new UnicodeToHexTransliterator(pattern2, status);
|
||||
if(U_FAILURE(status)){
|
||||
logln("OK: UnicodeToHexTransliterator construction for illegal pattern failed, as expected");
|
||||
status=U_ZERO_ERROR;
|
||||
} else {
|
||||
errln("Error: calling the UnicodeToHexTransliterator constructor with illegal pattern should fail");
|
||||
delete trans1;
|
||||
}
|
||||
|
||||
logln("Testing the construction UnicodeToHexTransliterator(pattern, isUppercase, adoptedFilter, status)");
|
||||
trans1=new UnicodeToHexTransliterator(pattern, FALSE, NULL, status);
|
||||
if(U_FAILURE(status)){
|
||||
errln("UnicodeToHexTransliterator construction failed. Error=" + (UnicodeString)u_errorName(status));
|
||||
status=U_ZERO_ERROR;
|
||||
return;
|
||||
}
|
||||
logln("Testing the copy construction");
|
||||
UnicodeToHexTransliterator *trans1copy=new UnicodeToHexTransliterator(*trans1);
|
||||
if(trans1->toPattern() != trans1copy->toPattern() || trans1->isUppercase() != trans1copy->isUppercase() ||
|
||||
trans1->getID() != trans1copy->getID()){
|
||||
errln("Copy construction failed");
|
||||
}
|
||||
delete trans1copy;
|
||||
delete trans1;
|
||||
|
||||
logln("Testing the construction UnicodeToHexTransliterator(pattern, isUppercase, adoptedFilter, status)");
|
||||
trans1=new UnicodeToHexTransliterator(pattern, TRUE, new TestUniFilter, status);
|
||||
if(U_FAILURE(status)){
|
||||
errln("UnicodeToHexTransliterator construction failed Error=" + (UnicodeString)u_errorName(status));
|
||||
status=U_ZERO_ERROR;
|
||||
return;
|
||||
}
|
||||
logln("Testing the copy construction");
|
||||
trans1copy=new UnicodeToHexTransliterator(*trans1);
|
||||
if(trans1->toPattern() != trans1copy->toPattern() || trans1->isUppercase() != trans1copy->isUppercase() ||
|
||||
trans1->getID() != trans1copy->getID() ||
|
||||
trans1->getFilter() == NULL || trans1copy->getFilter() == NULL ){
|
||||
errln("Copy construction failed");
|
||||
}
|
||||
delete trans1copy;
|
||||
delete trans1;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void UniToHexTransliteratorTest::TestCloneEqual(){
|
||||
UErrorCode status=U_ZERO_ERROR;
|
||||
UnicodeToHexTransliterator *transdefault=new UnicodeToHexTransliterator();
|
||||
UnicodeString pattern1("\\U##00");
|
||||
UnicodeString pattern2("\\\\uni0000");
|
||||
UnicodeToHexTransliterator *trans1=new UnicodeToHexTransliterator(pattern1, status);
|
||||
if(U_FAILURE(status) && status==U_ILLEGAL_ARGUMENT_ERROR){
|
||||
errln("UnicodeToHexTransliterator construction failed");
|
||||
status=U_ZERO_ERROR;
|
||||
return;
|
||||
}
|
||||
UnicodeToHexTransliterator *trans2=new UnicodeToHexTransliterator(pattern2, status);
|
||||
if(U_FAILURE(status) && status==U_ILLEGAL_ARGUMENT_ERROR){
|
||||
errln("UnicodeToHexTransliterator construction failed");
|
||||
status=U_ZERO_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
logln("Testing the clone() API of the UnicodeToHexTransliterator");
|
||||
UnicodeToHexTransliterator *transdefaultclone=(UnicodeToHexTransliterator*)transdefault->clone();
|
||||
UnicodeToHexTransliterator *trans1clone=(UnicodeToHexTransliterator*)trans1->clone();
|
||||
UnicodeToHexTransliterator *trans2clone=(UnicodeToHexTransliterator*)trans2->clone();
|
||||
if(transdefault->toPattern() != transdefaultclone->toPattern() ||
|
||||
transdefault->isUppercase() != transdefaultclone->isUppercase() ||
|
||||
trans1->toPattern() != trans1clone->toPattern() ||
|
||||
trans1->isUppercase() != trans1clone->isUppercase() ||
|
||||
trans2->toPattern() != trans2clone->toPattern() ||
|
||||
trans2->isUppercase() != trans2clone->isUppercase() ||
|
||||
transdefault->toPattern() == trans1->toPattern() ||
|
||||
trans1->toPattern() == trans2clone->toPattern() ||
|
||||
trans2->toPattern() == transdefault->toPattern() ) {
|
||||
errln("Error: clone() failed");
|
||||
}
|
||||
|
||||
|
||||
logln("Testing the =operator of the UnicodeToHexTransliterator");
|
||||
UnicodeToHexTransliterator *transdefaultequal=transdefault;
|
||||
UnicodeToHexTransliterator *trans1equal=trans1;
|
||||
UnicodeToHexTransliterator *trans2equal=trans2;
|
||||
if(transdefault->toPattern() != transdefaultequal->toPattern() ||
|
||||
transdefault->isUppercase() != transdefaultequal->isUppercase() ||
|
||||
trans1->toPattern() != trans1equal->toPattern() ||
|
||||
trans1->isUppercase() != trans1equal->isUppercase() ||
|
||||
trans2->toPattern() != trans2equal->toPattern() ||
|
||||
trans2->isUppercase() != trans2equal->isUppercase() ||
|
||||
transdefault->toPattern() == trans1->toPattern() ||
|
||||
trans1->toPattern() == trans2equal->toPattern() ||
|
||||
trans2->toPattern() == transdefault->toPattern() ) {
|
||||
errln("Error: equal() failed");
|
||||
}
|
||||
if(transdefaultclone->toPattern() != transdefaultequal->toPattern() ||
|
||||
transdefaultclone->isUppercase() != transdefaultequal->isUppercase() ||
|
||||
trans1equal->toPattern() != trans1clone->toPattern() ||
|
||||
trans1equal->isUppercase() != trans1clone->isUppercase() ||
|
||||
trans2clone->toPattern() != trans2equal->toPattern() ||
|
||||
trans2clone->isUppercase() != trans2equal->isUppercase() ) {
|
||||
errln("Error: equal() or clone() failed");
|
||||
}
|
||||
|
||||
delete transdefault;
|
||||
delete trans1;
|
||||
delete trans2;
|
||||
}
|
||||
|
||||
void UniToHexTransliteratorTest::TestUpperCase(){
|
||||
logln("Testing the isUppercase() and setUppercase() API of UnicodeToHexTransliterator");
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
UnicodeString str("abk");
|
||||
/*default transliterator has upper case TRUE*/
|
||||
UnicodeToHexTransliterator *transdefault=new UnicodeToHexTransliterator();
|
||||
if(transdefault == 0){
|
||||
errln("UnicodeToHexTransliterator construction failed");
|
||||
return;
|
||||
}
|
||||
expect(*transdefault, "where uppercase=default", str, UnicodeString("\\u0061\\u0062\\u006B"));
|
||||
|
||||
UnicodeString pattern("\\\\u0000");
|
||||
/*transliterator with Uppercase FALSE*/
|
||||
UnicodeToHexTransliterator *trans1=new UnicodeToHexTransliterator(pattern, FALSE, NULL, status);
|
||||
if(U_FAILURE(status) && status==U_ILLEGAL_ARGUMENT_ERROR){
|
||||
errln("UnicodeToHexTransliterator construction failed with pattern =" + pattern);
|
||||
status=U_ZERO_ERROR;
|
||||
return;
|
||||
}
|
||||
expect(*trans1, "where uppercase=FALSE", str, UnicodeString("\\u0061\\u0062\\u006b")); /*doesn't display uppercase*/
|
||||
|
||||
if(transdefault->isUppercase() != TRUE || trans1->isUppercase() != FALSE ){
|
||||
errln("isUpperCase() failed");
|
||||
}
|
||||
/*changing the outputhexdigits to lower case for the default transliterator*/
|
||||
transdefault->setUppercase(trans1->isUppercase());
|
||||
if(transdefault->isUppercase() != trans1->isUppercase() || transdefault->isUppercase() != FALSE){
|
||||
errln("setUppercase() failed");
|
||||
}
|
||||
/*doesn't ouput uppercase hex, since transdefault's uppercase is set to FALSE using setUppercase*/
|
||||
expect(*transdefault, "where uppercase=FALSE", str, UnicodeString("\\u0061\\u0062\\u006b"));
|
||||
|
||||
/*trying round trip*/
|
||||
transdefault->setUppercase(TRUE);
|
||||
if(transdefault->isUppercase() != TRUE || transdefault->isUppercase() == trans1->isUppercase() ){
|
||||
errln("setUppercase() failed");
|
||||
}
|
||||
/*displays upper case since it is set to TRUE*/
|
||||
expect(*transdefault, "where uppercase=TRUE", str, UnicodeString("\\u0061\\u0062\\u006B"));
|
||||
|
||||
delete transdefault;
|
||||
delete trans1;
|
||||
|
||||
}
|
||||
void UniToHexTransliteratorTest::TestPattern(){
|
||||
logln("Testing the applyPattern() and toPattern() API of UnicodeToHexTransliterator");
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
/*default transliterator has pattern \\u0000*/
|
||||
UnicodeToHexTransliterator *transdefault=new UnicodeToHexTransliterator();
|
||||
if(transdefault == 0){
|
||||
errln("UnicodeToHexTransliterator construction failed");
|
||||
return;
|
||||
}
|
||||
UnicodeString defaultpattern=transdefault->toPattern();
|
||||
|
||||
UnicodeString pattern1("\\\\U+0000");
|
||||
UnicodeToHexTransliterator *trans1=new UnicodeToHexTransliterator(pattern1, TRUE, NULL, status);
|
||||
if(U_FAILURE(status) && status==U_ILLEGAL_ARGUMENT_ERROR){
|
||||
errln("UnicodeToHexTransliterator construction failed with pattern =" + pattern1);
|
||||
status=U_ZERO_ERROR;
|
||||
return;
|
||||
}
|
||||
/*test toPattern() */
|
||||
if(transdefault->toPattern() == trans1->toPattern() ||
|
||||
transdefault->toPattern() != UnicodeString("\\\\u0000") ||
|
||||
trans1->toPattern() != pattern1 ){
|
||||
errln("Error: toPattern() failed");
|
||||
}
|
||||
|
||||
/*apply patterns for transdefault*/
|
||||
UnicodeString str("abKf");
|
||||
expectPattern(*transdefault, pattern1, str, "\\U+0061\\U+0062\\U+004B\\U+0066");
|
||||
expectPattern(*transdefault, "\\U##00,", str, "U61,U62,U4B,U66,");
|
||||
expectPattern(*transdefault, defaultpattern, str, "\\u0061\\u0062\\u004B\\u0066");
|
||||
expectPattern(*trans1, "\\uni0000", str, "uni0061uni0062uni004Buni0066");
|
||||
expectPattern(*trans1, "\\\\S-0000-E", str, "\\S-0061-E\\S-0062-E\\S-004B-E\\S-0066-E");
|
||||
expectPattern(*trans1, "\\u##0000", str, "FAIL");
|
||||
expectPattern(*trans1, "\\*0000", str, "*0061*0062*004B*0066");
|
||||
expectPattern(*trans1, "\\u####", str, "FAIL");
|
||||
|
||||
delete trans1;
|
||||
delete transdefault;
|
||||
|
||||
}
|
||||
void UniToHexTransliteratorTest::TestSimpleTransliterate(){
|
||||
UErrorCode status=U_ZERO_ERROR;
|
||||
UnicodeString pattern1("\\\\U+0000");
|
||||
UnicodeToHexTransliterator *trans1=new UnicodeToHexTransliterator(pattern1, TRUE, NULL, status);
|
||||
if(U_FAILURE(status) && status==U_ILLEGAL_ARGUMENT_ERROR){
|
||||
errln("UnicodeToHexTransliterator construction failed with pattern =" + pattern1);
|
||||
status=U_ZERO_ERROR;
|
||||
return;
|
||||
}
|
||||
Transliterator::Position index(1,5,2);
|
||||
UnicodeString source("Hello");
|
||||
UnicodeString rsource(source);
|
||||
UnicodeString expected("He\\U+006C\\U+006C\\U+006F");
|
||||
trans1->handleTransliterate(rsource, index, FALSE);
|
||||
expectAux(trans1->getID() + ":handleTransliterator ", source + "-->" + rsource, rsource==expected, expected);
|
||||
delete trans1;
|
||||
}
|
||||
|
||||
void UniToHexTransliteratorTest::TestTransliterate(){
|
||||
UErrorCode status=U_ZERO_ERROR;
|
||||
UnicodeString Data[]={
|
||||
//pattern, source, index.start, index.limit, index.cursor, expectedResult, expectedResult using filter(a, b)
|
||||
"U+##00", "abc", "1", "3", "2", "abU+63", "abc",
|
||||
"\\\\u0000", "abc", "1", "2", "1", "a\\u0062c", "a\\u0062c",
|
||||
"Uni0000", "abc", "1", "3", "2", "abUni0063", "abc",
|
||||
"U[0000]", "hello", "0", "4", "2", "heU[006C]U[006C]o", "heU[006C]U[006C]o",
|
||||
"prefix-0000-suffix", "abc", "1", "3", "1", "aprefix-0062-suffixprefix-0063-suffix", "aprefix-0062-suffixc",
|
||||
"*##00*", "hellothere", "1", "8", "4", "hell*6F**74**68**65*re", "hell*6F**74**68**65*re",
|
||||
|
||||
};
|
||||
int i;
|
||||
for(i=0;i<sizeof(Data)/sizeof(Data[0]);i=i+7){
|
||||
UnicodeToHexTransliterator *trans1=new UnicodeToHexTransliterator(Data[i+0], TRUE, NULL, status);
|
||||
if(U_FAILURE(status)){
|
||||
errln("UnicodeToHexTransliterator construction failed with pattern =" + Data[i+0]);
|
||||
status=U_ZERO_ERROR;
|
||||
continue;
|
||||
}
|
||||
expectTranslit(*trans1, "", Data[i+1], getInt(Data[i+2]), getInt(Data[i+3]), getInt(Data[i+4]), Data[i+5] );
|
||||
delete trans1;
|
||||
UnicodeToHexTransliterator *trans2=new UnicodeToHexTransliterator(Data[i+0], TRUE, new TestUniFilter, status);
|
||||
if(U_FAILURE(status)){
|
||||
errln("UnicodeToHexTransliterator construction failed with pattern=" + Data[i+0] + "with filter(a,c)" );
|
||||
status=U_ZERO_ERROR;
|
||||
continue;
|
||||
}
|
||||
expectTranslit(*trans2, " with filter(a,A,c,C)", Data[i+1], getInt(Data[i+2]), getInt(Data[i+3]), getInt(Data[i+4]), Data[i+6] );
|
||||
delete trans2;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
//======================================================================
|
||||
// Support methods
|
||||
//======================================================================
|
||||
|
||||
void UniToHexTransliteratorTest::expectTranslit(const UnicodeToHexTransliterator& t,
|
||||
const UnicodeString& message,
|
||||
const UnicodeString& source,
|
||||
int32_t start, int32_t limit, int32_t cursor,
|
||||
const UnicodeString& expectedResult){
|
||||
|
||||
|
||||
Transliterator::Position index(start, limit, cursor);
|
||||
UnicodeString rsource(source);
|
||||
t.handleTransliterate(rsource, index, FALSE);
|
||||
expectAux(t.getID() + ":handleTransliterator(increment=FALSE) " + message, source + "-->" + rsource, rsource==expectedResult, expectedResult);
|
||||
|
||||
UnicodeString rsource2(source);
|
||||
index=Transliterator::Position(start, limit, cursor);
|
||||
t.handleTransliterate(rsource2, index, TRUE);
|
||||
expectAux(t.getID() + ":handleTransliterator(increment=TRUE) "+ message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
|
||||
|
||||
/*ceates a copy constructor and checks the transliteration*/
|
||||
UnicodeToHexTransliterator *copy=new UnicodeToHexTransliterator(t);
|
||||
rsource2.remove();
|
||||
rsource2.append(source);
|
||||
index=Transliterator::Position(start, limit, cursor);
|
||||
copy->handleTransliterate(rsource2, index, FALSE);
|
||||
expectAux(t.getID() + "COPY:handleTransliterator(increment=FALSE) " + message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
|
||||
|
||||
rsource2.remove();
|
||||
rsource2.append(source);
|
||||
index=Transliterator::Position(start, limit, cursor);
|
||||
copy->handleTransliterate(rsource2, index, TRUE);
|
||||
expectAux(t.getID() + "COPY:handleTransliterator(increment=TRUE) " + message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
|
||||
delete copy;
|
||||
|
||||
/*creates a clone and tests transliteration*/
|
||||
UnicodeToHexTransliterator *clone=(UnicodeToHexTransliterator*)t.clone();
|
||||
rsource2.remove();
|
||||
rsource2.append(source);
|
||||
index=Transliterator::Position(start, limit, cursor);
|
||||
clone->handleTransliterate(rsource2, index, FALSE);
|
||||
expectAux(t.getID() + "CLONE:handleTransliterator(increment=FALSE) "+ message,source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
|
||||
|
||||
rsource2.remove();
|
||||
rsource2.append(source);
|
||||
index=Transliterator::Position(start, limit, cursor);
|
||||
clone->handleTransliterate(rsource2, index, TRUE);
|
||||
expectAux(t.getID() + "CLONE:handleTransliterator(increment=TRUE) "+ message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
|
||||
|
||||
/*Uses the assignment operator to create a transliterator and tests transliteration*/
|
||||
UnicodeToHexTransliterator equal=t;
|
||||
rsource2.remove();
|
||||
rsource2.append(source);
|
||||
index=Transliterator::Position(start, limit, cursor);
|
||||
equal.handleTransliterate(rsource2, index, FALSE);
|
||||
expectAux(t.getID() + "=OPERATOR:handleTransliterator(increment=FALSE) "+ message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
|
||||
|
||||
rsource2.remove();
|
||||
rsource2.append(source);
|
||||
index=Transliterator::Position(start, limit, cursor);
|
||||
equal.handleTransliterate(rsource2, index, TRUE);
|
||||
expectAux(t.getID() + "=OPERATOR:handleTransliterator(increment=TRUE) "+ message, source + "-->" + rsource2, rsource2==expectedResult, expectedResult);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
void UniToHexTransliteratorTest::expectPattern(UnicodeToHexTransliterator& t,
|
||||
const UnicodeString& pattern,
|
||||
const UnicodeString& source,
|
||||
const UnicodeString& expectedResult){
|
||||
UErrorCode status=U_ZERO_ERROR;
|
||||
t.applyPattern(pattern, status);
|
||||
if(expectedResult == "FAIL"){
|
||||
if(U_FAILURE(status)){
|
||||
logln("OK: calling applyPattern() with illegal pattern failed as expected. Error=" + (UnicodeString)u_errorName(status));
|
||||
status=U_ZERO_ERROR;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(U_FAILURE(status)){
|
||||
errln("Error: applyPattern() failed with pattern =" + pattern + "--->" + (UnicodeString)u_errorName(status));
|
||||
return;
|
||||
}else {
|
||||
if(t.toPattern() != pattern) {
|
||||
errln("Error: applyPattern or toPatten failed. Expected: " + pattern + "Got: " + t.toPattern());
|
||||
}
|
||||
else{
|
||||
logln("OK: applyPattern passed. Testing transliteration");
|
||||
expect(t, (UnicodeString)" with pattern "+pattern, source, expectedResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
void UniToHexTransliteratorTest::expect(const UnicodeToHexTransliterator& t,
|
||||
const UnicodeString& message,
|
||||
const UnicodeString& source,
|
||||
const UnicodeString& expectedResult) {
|
||||
|
||||
UnicodeString rsource(source);
|
||||
t.transliterate(rsource);
|
||||
expectAux(t.getID() + ":Replaceable " + message, source + "->" + rsource, rsource==expectedResult, expectedResult);
|
||||
|
||||
// Test handleTransliterate (incremental) transliteration --
|
||||
rsource.remove();
|
||||
rsource.append(source);
|
||||
Transliterator::Position index(0,source.length(),0);
|
||||
t.handleTransliterate(rsource, index, TRUE);
|
||||
expectAux(t.getID() + ":handleTransliterate " + message, source + "->" + rsource, rsource==expectedResult, expectedResult);
|
||||
|
||||
}
|
||||
void UniToHexTransliteratorTest::expectAux(const UnicodeString& tag,
|
||||
const UnicodeString& summary, bool_t pass,
|
||||
const UnicodeString& expectedResult) {
|
||||
if (pass) {
|
||||
logln(UnicodeString("(")+tag+") " + prettify(summary));
|
||||
} else {
|
||||
errln(UnicodeString("FAIL: (")+tag+") "
|
||||
+ prettify(summary)
|
||||
+ ", expected " + prettify(expectedResult));
|
||||
}
|
||||
}
|
||||
|
||||
|
77
icu4c/source/test/intltest/unhxtrts.h
Normal file
77
icu4c/source/test/intltest/unhxtrts.h
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
*****************************************************************************************
|
||||
* *
|
||||
* COPYRIGHT: *
|
||||
* (C) Copyright International Business Machines Corporation, 2000 *
|
||||
* Licensed Material - Program-Property of IBM - All Rights Reserved. *
|
||||
* US Government Users Restricted Rights - Use, duplication, or disclosure *
|
||||
* restricted by GSA ADP Schedule Contract with IBM Corp. *
|
||||
* *
|
||||
*****************************************************************************************
|
||||
************************************************************************
|
||||
* Date Name Description
|
||||
* 03/15/2000 Madhu Creation.
|
||||
************************************************************************/
|
||||
|
||||
#ifndef UNITOHEXTRTST_H
|
||||
#define UNITOHEXTRTST_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/translit.h"
|
||||
#include "unicode/unitohex.h"
|
||||
#include "intltest.h"
|
||||
|
||||
class UnicodeToHexTransliterator;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @summary General test of UnicodeToHexadecimal Transliterator
|
||||
*/
|
||||
class UniToHexTransliteratorTest : public IntlTest {
|
||||
public:
|
||||
void runIndexedTest(int32_t index, bool_t exec, char* &name, char* par=NULL);
|
||||
|
||||
/*Tests the constructors */
|
||||
void TestConstruction(void);
|
||||
/*Tests the function clone, and operator==()*/
|
||||
void TestCloneEqual(void);
|
||||
/*Tests the function isUppercase and setUppercase()*/
|
||||
void TestUpperCase(void);
|
||||
/*Tests the function getTransliterator() and setTransliterators() and adoptTransliterators()*/
|
||||
void TestPattern(void);
|
||||
/*Tests the function handleTransliterate()*/
|
||||
void TestSimpleTransliterate();
|
||||
/*Tests the function handleTransliterate()*/
|
||||
void TestTransliterate();
|
||||
|
||||
//======================================================================
|
||||
// Support methods
|
||||
//======================================================================
|
||||
void expectTranslit(const UnicodeToHexTransliterator& t,
|
||||
const UnicodeString& message,
|
||||
const UnicodeString& source,
|
||||
int32_t start, int32_t limit, int32_t cursor,
|
||||
const UnicodeString& expectedResult);
|
||||
|
||||
void expectPattern(UnicodeToHexTransliterator& t,
|
||||
const UnicodeString& pattern,
|
||||
const UnicodeString& source,
|
||||
const UnicodeString& expectedResult);
|
||||
|
||||
void expect(const UnicodeToHexTransliterator& t,
|
||||
const UnicodeString& message,
|
||||
const UnicodeString& source,
|
||||
const UnicodeString& expectedResult);
|
||||
|
||||
void expectAux(const UnicodeString& tag,
|
||||
const UnicodeString& summary, bool_t pass,
|
||||
const UnicodeString& expectedResult);
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user