2000-03-10 00:42:27 +00:00
/********************************************************************
* COPYRIGHT :
2001-03-21 20:09:56 +00:00
* Copyright ( c ) 2001 , International Business Machines Corporation and
2000-03-10 00:42:27 +00:00
* others . All Rights Reserved .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************************
2000-01-18 02:34:41 +00:00
* Date Name Description
* 1 / 03 / 2000 Madhu Creation .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include "ittrans.h"
# include "transapi.h"
# include "unicode/utypes.h"
# include "unicode/translit.h"
# include "unicode/rbt.h"
# include "unicode/unifilt.h"
# include "unicode/cpdtrans.h"
2000-06-27 18:20:33 +00:00
# include "unicode/nultrans.h"
2000-01-18 02:34:41 +00:00
# include <string.h>
# include <stdio.h>
2000-08-24 01:12:12 +00:00
# include <stdlib.h>
2000-01-18 02:34:41 +00:00
# include "unicode/rep.h"
2001-08-31 18:02:09 +00:00
# include "unicode/locid.h"
2000-01-18 02:34:41 +00:00
int32_t getInt ( UnicodeString str )
{
2000-04-04 16:30:21 +00:00
char buffer [ 20 ] ;
2000-08-10 00:28:31 +00:00
int len = str . length ( ) ;
2000-04-04 16:30:21 +00:00
if ( len > = 20 ) {
len = 19 ;
}
str . extract ( 0 , len , buffer , " " ) ;
buffer [ len ] = 0 ;
2000-08-10 00:28:31 +00:00
return atoi ( buffer ) ;
2000-01-18 02:34:41 +00:00
}
2000-04-04 16:30:21 +00:00
2000-01-18 02:34:41 +00:00
//---------------------------------------------
// runIndexedTest
//---------------------------------------------
2000-08-23 19:11:16 +00:00
void TransliteratorAPITest : : runIndexedTest ( int32_t index , UBool exec , const char * & name , char * /*par*/ )
2000-01-18 02:34:41 +00:00
{
if ( exec ) logln ( ( UnicodeString ) " TestSuite Transliterator API " ) ;
switch ( index ) {
case 0 : name = " TestgetInverse " ; if ( exec ) TestgetInverse ( ) ; break ;
case 1 : name = " TestgetID " ; if ( exec ) TestgetID ( ) ; break ;
2000-08-10 00:28:31 +00:00
case 2 : name = " TestGetDisplayName " ; if ( exec ) TestGetDisplayName ( ) ; break ;
2000-01-18 02:34:41 +00:00
case 3 : name = " TestTransliterate1 " ; if ( exec ) TestTransliterate1 ( ) ; break ;
case 4 : name = " TestTransliterate2 " ; if ( exec ) TestTransliterate2 ( ) ; break ;
case 5 : name = " TestTransliterate3 " ; if ( exec ) TestTransliterate3 ( ) ; break ;
case 6 : name = " TestSimpleKeyboardTransliterator " ; if ( exec ) TestSimpleKeyboardTransliterator ( ) ; break ;
case 7 : name = " TestKeyboardTransliterator1 " ; if ( exec ) TestKeyboardTransliterator1 ( ) ; break ;
case 8 : name = " TestKeyboardTransliterator2 " ; if ( exec ) TestKeyboardTransliterator2 ( ) ; break ;
case 9 : name = " TestKeyboardTransliterator3 " ; if ( exec ) TestKeyboardTransliterator3 ( ) ; break ;
2000-08-10 00:28:31 +00:00
case 10 : name = " TestGetAdoptFilter " ; if ( exec ) TestGetAdoptFilter ( ) ; break ;
case 11 : name = " TestClone " ; if ( exec ) TestClone ( ) ; break ;
2000-06-27 18:20:33 +00:00
case 12 : name = " TestNullTransliterator " ; if ( exec ) TestNullTransliterator ( ) ; break ;
2001-08-31 03:24:28 +00:00
case 13 : name = " TestRegisterUnregister " ; if ( exec ) TestRegisterUnregister ( ) ; break ;
2000-01-18 02:34:41 +00:00
default : name = " " ; break ; /*needed to end loop*/
}
}
void TransliteratorAPITest : : TestgetID ( ) {
2000-08-10 00:28:31 +00:00
UnicodeString trans = " Latin-Greek " ;
UnicodeString ID ;
2001-08-31 03:24:28 +00:00
UParseError parseError ;
UErrorCode status = U_ZERO_ERROR ;
Transliterator * t = Transliterator : : createInstance ( trans , UTRANS_FORWARD , parseError , status ) ;
if ( t = = 0 | | U_FAILURE ( status ) ) {
2000-08-10 00:28:31 +00:00
errln ( " FAIL: construction " ) ;
2001-08-31 03:24:28 +00:00
status = U_ZERO_ERROR ;
} else {
2000-08-10 00:28:31 +00:00
ID = t - > getID ( ) ;
if ( ID ! = trans )
2000-01-18 02:34:41 +00:00
errln ( " FAIL: getID returned " + ID + " instead of Latin-Greek " ) ;
2000-08-10 00:28:31 +00:00
}
int i ;
for ( i = 0 ; i < Transliterator : : countAvailableIDs ( ) ; i + + ) {
ID = ( UnicodeString ) Transliterator : : getAvailableID ( i ) ;
2001-08-31 03:24:28 +00:00
t = Transliterator : : createInstance ( ID , UTRANS_FORWARD , parseError , status ) ;
2000-08-10 00:28:31 +00:00
if ( t = = 0 ) {
errln ( " FAIL: " + ID ) ;
continue ;
}
if ( ID ! = t - > getID ( ) )
errln ( " FAIL: getID() returned " + t - > getID ( ) + " instead of " + ID ) ;
}
ID = ( UnicodeString ) Transliterator : : getAvailableID ( i ) ;
if ( ID ! = ( UnicodeString ) Transliterator : : getAvailableID ( 0 ) ) {
errln ( " FAIL: calling getAvailableID(index > coundAvailableIDs) should make index=0 \n " ) ;
}
2000-01-18 02:34:41 +00:00
2000-08-10 00:28:31 +00:00
delete t ;
2000-01-18 02:34:41 +00:00
2001-08-31 03:24:28 +00:00
Transliterator * t1 = Transliterator : : createInstance ( " Latin-Devanagari " , UTRANS_FORWARD , parseError , status ) ;
Transliterator * t2 = Transliterator : : createInstance ( " Latin-Hebrew " , UTRANS_FORWARD , parseError , status ) ;
2000-08-10 00:28:31 +00:00
if ( t1 = = 0 | | t2 = = 0 ) {
errln ( " FAIL: construction " ) ;
return ;
}
Transliterator * t3 = t1 - > clone ( ) ;
Transliterator * t4 = t2 - > clone ( ) ;
2000-01-18 02:34:41 +00:00
2000-08-10 00:28:31 +00:00
if ( t1 - > getID ( ) ! = t3 - > getID ( ) | | t2 - > getID ( ) ! = t4 - > getID ( ) | |
t1 - > getID ( ) = = t4 - > getID ( ) | | t2 - > getID ( ) = = t3 - > getID ( ) | |
t1 - > getID ( ) = = t4 - > getID ( ) )
errln ( " FAIL: getID or clone failed " ) ;
2000-01-18 02:34:41 +00:00
2001-08-31 03:24:28 +00:00
Transliterator * t5 = Transliterator : : createInstance ( " Latin-Devanagari " , UTRANS_FORWARD , parseError , status ) ;
2000-08-10 00:28:31 +00:00
if ( t5 = = 0 )
errln ( " FAIL: construction " ) ;
if ( t1 - > getID ( ) ! = t5 - > getID ( ) | | t5 - > getID ( ) ! = t3 - > getID ( ) | | t1 - > getID ( ) ! = t3 - > getID ( ) )
errln ( " FAIL: getID or clone failed " ) ;
2000-08-14 21:42:36 +00:00
2000-07-13 01:05:50 +00:00
2000-08-10 00:28:31 +00:00
delete t1 ;
delete t2 ;
delete t3 ;
delete t4 ;
delete t5 ;
}
2000-01-18 02:34:41 +00:00
void TransliteratorAPITest : : TestgetInverse ( ) {
2001-08-31 03:24:28 +00:00
UErrorCode status = U_ZERO_ERROR ;
UParseError parseError ;
Transliterator * t1 = Transliterator : : createInstance ( " Kana-Latin " , UTRANS_FORWARD , parseError , status ) ;
Transliterator * invt1 = Transliterator : : createInstance ( " Latin-Kana " , UTRANS_FORWARD , parseError , status ) ;
Transliterator * t2 = Transliterator : : createInstance ( " Latin-Devanagari " , UTRANS_FORWARD , parseError , status ) ;
Transliterator * invt2 = Transliterator : : createInstance ( " Devanagari-Latin " , UTRANS_FORWARD , parseError , status ) ;
2000-08-14 21:42:36 +00:00
if ( t1 = = 0 | | invt1 = = 0 | | t2 = = 0 | | invt2 = = 0 ) {
errln ( " FAIL: in instantiation " ) ;
return ;
}
2000-01-18 02:34:41 +00:00
2001-08-31 03:24:28 +00:00
Transliterator * inverse1 = t1 - > createInverse ( status ) ;
Transliterator * inverse2 = t2 - > createInverse ( status ) ;
2000-08-14 21:42:36 +00:00
if ( inverse1 - > getID ( ) ! = invt1 - > getID ( ) | | inverse2 - > getID ( ) ! = invt2 - > getID ( )
| | inverse1 - > getID ( ) = = invt2 - > getID ( ) | | inverse2 - > getID ( ) = = invt1 - > getID ( ) )
errln ( " FAIL: getInverse() " ) ;
2000-01-18 02:34:41 +00:00
2000-08-14 21:42:36 +00:00
UnicodeString TransID [ ] = {
" Halfwidth-Fullwidth " ,
" Fullwidth-Halfwidth " ,
" Greek-Latin " ,
" Latin-Greek " ,
" Arabic-Latin " ,
" Latin-Arabic " ,
" Kana-Latin " ,
" Latin-Kana " ,
" Hebrew-Latin " ,
" Latin-Hebrew " ,
" Cyrillic-Latin " ,
" Latin-Cyrillic " ,
" Devanagari-Latin " ,
" Latin-Devanagari " ,
2001-08-01 17:37:08 +00:00
" Any-Hex " ,
" Hex-Any "
2000-08-14 21:42:36 +00:00
} ;
2000-08-29 23:53:37 +00:00
for ( uint32_t i = 0 ; i < sizeof ( TransID ) / sizeof ( TransID [ 0 ] ) ; i = i + 2 ) {
2001-08-31 03:24:28 +00:00
t1 = Transliterator : : createInstance ( TransID [ i ] , UTRANS_FORWARD , parseError , status ) ;
2000-08-14 21:42:36 +00:00
if ( t1 = = 0 ) {
errln ( " FAIL: in instantiation for " + TransID [ i ] ) ;
continue ;
2000-01-18 02:34:41 +00:00
}
2001-08-31 03:24:28 +00:00
inverse1 = t1 - > createInverse ( status ) ;
2000-08-14 21:42:36 +00:00
if ( inverse1 - > getID ( ) ! = TransID [ i + 1 ] )
errln ( " FAIL :getInverse() for " + TransID [ i ] + " returned " + inverse1 - > getID ( ) + " instead of " + TransID [ i + 1 ] ) ;
}
delete t1 ;
delete t2 ;
delete invt1 ;
delete invt2 ;
}
2000-01-18 02:34:41 +00:00
void TransliteratorAPITest : : TestClone ( ) {
Transliterator * t1 , * t2 , * t3 , * t4 ;
2001-08-31 03:24:28 +00:00
UErrorCode status = U_ZERO_ERROR ;
UParseError parseError ;
t1 = Transliterator : : createInstance ( " Latin-Devanagari " , UTRANS_FORWARD , parseError , status ) ;
t2 = Transliterator : : createInstance ( " Latin-Hebrew " , UTRANS_FORWARD , parseError , status ) ;
2000-08-10 00:28:31 +00:00
if ( t1 = = 0 | | t2 = = 0 ) {
errln ( " FAIL: construction " ) ;
return ;
}
t3 = t1 - > clone ( ) ;
t4 = t2 - > clone ( ) ;
if ( t1 - > getID ( ) ! = t3 - > getID ( ) | | t2 - > getID ( ) ! = t4 - > getID ( ) )
errln ( " FAIL: clone or getID failed " ) ;
if ( t1 - > getID ( ) = = t4 - > getID ( ) | | t2 - > getID ( ) = = t3 - > getID ( ) | | t1 - > getID ( ) = = t4 - > getID ( ) )
errln ( " FAIL: clone or getID failed " ) ;
2000-01-18 02:34:41 +00:00
2000-08-10 00:28:31 +00:00
delete t1 ;
delete t2 ;
2000-01-18 02:34:41 +00:00
}
void TransliteratorAPITest : : TestGetDisplayName ( ) {
UnicodeString dispNames [ ] = {
2000-08-10 00:28:31 +00:00
//ID, displayName
" CurlyQuotes-StraightQuotes " , " CurlyQuotes to StraightQuotes " ,
2001-08-01 17:37:08 +00:00
" Any-Hex " , " Any to Hex Escape " ,
2000-08-10 00:28:31 +00:00
" Halfwidth-Fullwidth " , " Halfwidth to Fullwidth " ,
" Latin-Arabic " , " Latin to Arabic " ,
" Latin-Devanagari " , " Latin to Devanagari " ,
" Greek-Latin " , " Greek to Latin " ,
" Arabic-Latin " , " Arabic to Latin " ,
2001-08-01 17:37:08 +00:00
" Hex-Any " , " Hex Escape to Any " ,
2000-08-10 00:28:31 +00:00
" Cyrillic-Latin " , " Cyrillic to Latin " ,
" Latin-Greek " , " Latin to Greek " ,
" Latin-Kana " , " Latin to Kana " ,
" Latin-Hebrew " , " Latin to Hebrew " ,
" Kana-Latin " , " Kana to Latin "
} ;
UnicodeString name = " " ;
2000-08-14 21:42:36 +00:00
Transliterator * t ;
2000-08-10 00:28:31 +00:00
UnicodeString message ;
2001-08-31 03:24:28 +00:00
UErrorCode status = U_ZERO_ERROR ;
UParseError parseError ;
2000-08-29 23:53:37 +00:00
for ( uint32_t i = 0 ; i < sizeof ( dispNames ) / sizeof ( dispNames [ 0 ] ) ; i = i + 2 ) {
2001-08-31 03:24:28 +00:00
t = Transliterator : : createInstance ( dispNames [ i + 0 ] , UTRANS_FORWARD , parseError , status ) ;
2000-08-10 00:28:31 +00:00
if ( t = = 0 ) {
errln ( " FAIL: construction: " + dispNames [ i + 0 ] ) ;
2001-08-31 03:24:28 +00:00
status = U_ZERO_ERROR ;
2000-08-10 00:28:31 +00:00
continue ;
2000-01-18 02:34:41 +00:00
}
2000-08-10 00:28:31 +00:00
t - > getDisplayName ( t - > getID ( ) , name ) ;
message = " Display name for ID: " + t - > getID ( ) ;
// doTest(message, name, dispNames[i+1]); //!!! This will obviously fail for any locale other than english and its children!!!
name = " " ;
t - > getDisplayName ( t - > getID ( ) , Locale : : US , name ) ;
message . remove ( ) ;
message . append ( " Display name for on english locale ID: " ) ;
message . append ( t - > getID ( ) ) ;
// message="Display name for on english locale ID:" + t->getID();
doTest ( message , name , dispNames [ i + 1 ] ) ;
name = " " ;
2000-08-14 21:42:36 +00:00
delete t ;
2000-08-10 00:28:31 +00:00
}
2000-01-18 02:34:41 +00:00
2000-08-10 00:28:31 +00:00
}
2000-01-18 02:34:41 +00:00
void TransliteratorAPITest : : TestTransliterate1 ( ) {
2000-08-10 00:28:31 +00:00
UnicodeString Data [ ] = {
//ID, input string, transliterated string
2001-08-31 03:24:28 +00:00
" Any-Hex " , " hello " , UnicodeString ( " \\ u0068 \\ u0065 \\ u006C \\ u006C \\ u006F " , " " ) ,
2001-08-01 17:37:08 +00:00
" Hex-Any " , UnicodeString ( " \\ u0068 \\ u0065 \\ u006C \\ u006C \\ u006F " , " " ) , " hello " ,
2001-08-31 03:24:28 +00:00
" Latin-Devanagari " , " bhaarata " , CharsToUnicodeString ( " \\ u092D \\ u093E \\ u0930 \\ u0924 " ) ,
" Devanagari-Latin " , CharsToUnicodeString ( " \\ u092D \\ u093E \\ u0930 \\ u0924 " ) , UnicodeString ( " bhaarata " ) ,
2000-08-10 00:28:31 +00:00
// "Contracted-Expanded", CharsToUnicodeString("\\u00C0\\u00C1\\u0042"), CharsToUnicodeString("\\u0041\\u0300\\u0041\\u0301\\u0042") ,
// "Expanded-Contracted", CharsToUnicodeString("\\u0041\\u0300\\u0041\\u0301\\u0042"), CharsToUnicodeString("\\u00C0\\u00C1\\u0042") ,
" Latin-Arabic " , " aap " , CharsToUnicodeString ( " \\ u0627 \\ u06A4 " ) ,
" Arabic-Latin " , CharsToUnicodeString ( " \\ u0627 \\ u06A4 " ) , " aap "
} ;
UnicodeString gotResult ;
UnicodeString temp ;
UnicodeString message ;
2000-08-14 21:42:36 +00:00
Transliterator * t ;
2000-08-10 00:28:31 +00:00
logln ( " Testing transliterate " ) ;
2001-08-31 03:24:28 +00:00
UErrorCode status = U_ZERO_ERROR ;
UParseError parseError ;
2000-08-10 00:28:31 +00:00
2000-08-29 23:53:37 +00:00
for ( uint32_t i = 0 ; i < sizeof ( Data ) / sizeof ( Data [ 0 ] ) ; i = i + 3 ) {
2001-08-31 03:24:28 +00:00
t = Transliterator : : createInstance ( Data [ i + 0 ] , UTRANS_FORWARD , parseError , status ) ;
2000-08-10 00:28:31 +00:00
if ( t = = 0 ) {
2001-08-31 03:24:28 +00:00
errln ( " FAIL: construction: " + Data [ i + 0 ] + " Error: " + u_errorName ( status ) ) ;
errln ( " PreContext: " + prettify ( parseError . preContext ) + " PostContext: " + prettify ( parseError . postContext ) ) ;
status = U_ZERO_ERROR ;
2000-08-10 00:28:31 +00:00
continue ;
}
gotResult = Data [ i + 1 ] ;
t - > transliterate ( gotResult ) ;
2001-08-31 03:24:28 +00:00
message = t - > getID ( ) + " ->transliterate(UnicodeString, UnicodeString) for \n \t Source: " + prettify ( Data [ i + 1 ] ) ;
2000-08-10 00:28:31 +00:00
doTest ( message , gotResult , Data [ i + 2 ] ) ;
//doubt here
temp = Data [ i + 1 ] ;
t - > transliterate ( temp ) ;
message . remove ( ) ;
message . append ( t - > getID ( ) ) ;
message . append ( " ->transliterate(Replaceable) for \n \t Source: " ) ;
message . append ( Data [ i ] [ 1 ] ) ;
doTest ( message , temp , Data [ i + 2 ] ) ;
2000-01-18 02:34:41 +00:00
2000-08-14 21:42:36 +00:00
delete t ;
}
2000-01-18 02:34:41 +00:00
}
2000-08-10 00:28:31 +00:00
2000-01-18 02:34:41 +00:00
void TransliteratorAPITest : : TestTransliterate2 ( ) {
2000-08-10 00:28:31 +00:00
//testing tranliterate(String text, int start, int limit, StringBuffer result)
UnicodeString Data2 [ ] = {
//ID, input string, start, limit, transliterated string
2001-08-01 17:37:08 +00:00
" Any-Hex " , " hello! How are you? " , " 0 " , " 5 " , UnicodeString ( " \\ u0068 \\ u0065 \\ u006C \\ u006C \\ u006F " , " " ) , UnicodeString ( " \\ u0068 \\ u0065 \\ u006C \\ u006C \\ u006F! How are you? " , " " ) ,
" Any-Hex " , " hello! How are you? " , " 7 " , " 12 " , UnicodeString ( " \\ u0048 \\ u006F \\ u0077 \\ u0020 \\ u0061 " , " " ) , UnicodeString ( " hello! \\ u0048 \\ u006F \\ u0077 \\ u0020 \\ u0061re you? " , " " ) ,
" Hex-Any " , CharsToUnicodeString ( " \\ u0068 \\ u0065 \\ u006C \\ u006C \\ u006F \\ u0021 \\ u0020 " ) , " 0 " , " 5 " , " hello " , " hello! " ,
2000-08-10 00:28:31 +00:00
// "Contracted-Expanded", CharsToUnicodeString("\\u00C0\\u00C1\\u0042"), "1", "2", CharsToUnicodeString("\\u0041\\u0301"), CharsToUnicodeString("\\u00C0\\u0041\\u0301\\u0042") ,
" Devanagari-Latin " , CharsToUnicodeString ( " \\ u092D \\ u093E \\ u0930 \\ u0924 " ) , " 0 " , " 1 " , " bha " , CharsToUnicodeString ( " bha \\ u093E \\ u0930 \\ u0924 " ) ,
" Devanagari-Latin " , CharsToUnicodeString ( " \\ u092D \\ u093E \\ u0930 \\ u0924 " ) , " 1 " , " 2 " , " aa " , CharsToUnicodeString ( " \\ u092Daa \\ u0930 \\ u0924 " )
} ;
logln ( " \n Testing transliterate(String, int, int, StringBuffer) " ) ;
Transliterator * t ;
UnicodeString gotResBuf ;
UnicodeString temp ;
int32_t start , limit ;
2001-08-31 03:24:28 +00:00
UErrorCode status = U_ZERO_ERROR ;
UParseError parseError ;
2000-08-29 23:53:37 +00:00
for ( uint32_t i = 0 ; i < sizeof ( Data2 ) / sizeof ( Data2 [ 0 ] ) ; i = i + 6 ) {
2001-08-31 03:24:28 +00:00
t = Transliterator : : createInstance ( Data2 [ i + 0 ] , UTRANS_FORWARD , parseError , status ) ;
2000-08-10 00:28:31 +00:00
if ( t = = 0 ) {
2001-08-31 03:24:28 +00:00
errln ( " FAIL: construction: " + prettify ( Data2 [ i + 0 ] ) ) ;
2000-08-10 00:28:31 +00:00
continue ;
}
start = getInt ( Data2 [ i + 2 ] ) ;
limit = getInt ( Data2 [ i + 3 ] ) ;
Data2 [ i + 1 ] . extractBetween ( start , limit , gotResBuf ) ;
t - > transliterate ( gotResBuf ) ;
// errln("FAIL: calling transliterate on " + t->getID());
2001-08-31 03:24:28 +00:00
doTest ( t - > getID ( ) + " .transliterate(UnicodeString, int32_t, int32_t, UnicodeString):( " + start + " , " + limit + " ) for \n \t source: " + prettify ( Data2 [ i + 1 ] ) , gotResBuf , Data2 [ i + 4 ] ) ;
2000-08-10 00:28:31 +00:00
temp = Data2 [ i + 1 ] ;
t - > transliterate ( temp , start , limit ) ;
2001-08-31 03:24:28 +00:00
doTest ( t - > getID ( ) + " .transliterate(Replaceable, int32_t, int32_t, ):( " + start + " , " + limit + " ) for \n \t source: " + prettify ( Data2 [ i + 1 ] ) , temp , Data2 [ i + 5 ] ) ;
status = U_ZERO_ERROR ;
2000-08-10 00:28:31 +00:00
}
2000-01-18 02:34:41 +00:00
2001-08-31 03:24:28 +00:00
status = U_ZERO_ERROR ;
2000-08-10 00:28:31 +00:00
logln ( " \n Try calling transliterate with illegal start and limit values " ) ;
2001-08-31 03:24:28 +00:00
t = Transliterator : : createInstance ( " Any-Hex " , UTRANS_FORWARD , parseError , status ) ;
2000-08-10 00:28:31 +00:00
gotResBuf = temp = " try start greater than limit " ;
t - > transliterate ( gotResBuf , 10 , 5 ) ;
if ( gotResBuf = = temp )
logln ( " OK: start greater than limit value handled correctly " ) ;
else
errln ( " FAIL: start greater than limit value returned " + gotResBuf ) ;
2000-01-18 02:34:41 +00:00
2000-08-10 00:28:31 +00:00
delete t ;
2000-01-18 02:34:41 +00:00
}
void TransliteratorAPITest : : TestTransliterate3 ( ) {
2000-08-10 00:28:31 +00:00
UnicodeString rs = " This is the replaceable String " ;
UnicodeString Data [ ] = {
" 0 " , " 0 " , " This is the replaceable String " ,
" 2 " , " 3 " , UnicodeString ( " Th \\ u0069s is the replaceable String " , " " ) ,
" 21 " , " 23 " , UnicodeString ( " Th \\ u0069s is the repl \\ u0061 \\ u0063eable String " , " " ) ,
" 14 " , " 17 " , UnicodeString ( " Th \\ u0069s is t \\ u0068 \\ u0065 \\ u0020repl \\ u0061 \\ u0063eable String " , " " ) ,
} ;
int start , limit ;
UnicodeString message ;
2001-08-31 03:24:28 +00:00
UParseError parseError ;
UErrorCode status = U_ZERO_ERROR ;
Transliterator * t = Transliterator : : createInstance ( " Any-Hex " , UTRANS_FORWARD , parseError , status ) ;
2000-08-10 00:28:31 +00:00
if ( t = = 0 )
errln ( " FAIL : construction " ) ;
2000-08-29 23:53:37 +00:00
for ( uint32_t i = 0 ; i < sizeof ( Data ) / sizeof ( Data [ 0 ] ) ; i = i + 3 ) {
2000-08-10 00:28:31 +00:00
start = getInt ( Data [ i + 0 ] ) ;
limit = getInt ( Data [ i + 1 ] ) ;
t - > transliterate ( rs , start , limit ) ;
message = t - > getID ( ) + " .transliterate(ReplaceableString, start, limit):( " + start + " , " + limit + " ): " ;
doTest ( message , rs , Data [ i + 2 ] ) ;
}
2000-01-18 02:34:41 +00:00
}
void TransliteratorAPITest : : TestSimpleKeyboardTransliterator ( ) {
2000-08-10 00:28:31 +00:00
logln ( " simple call to transliterate " ) ;
UErrorCode status = U_ZERO_ERROR ;
2001-08-31 03:24:28 +00:00
UParseError parseError ;
Transliterator * t = Transliterator : : createInstance ( " Any-Hex " , UTRANS_FORWARD , parseError , status ) ;
2001-09-17 20:59:42 +00:00
if ( t = = 0 ) {
errln ( ( UnicodeString ) " FAIL: can't create Any-Hex, " +
2001-09-18 20:31:03 +00:00
( UnicodeString ) u_errorName ( status ) +
2001-09-17 20:59:42 +00:00
( parseError . preContext [ 0 ] ?
( ( UnicodeString ) " at " + parseError . preContext +
( parseError . postContext [ 0 ] ?
2001-09-18 20:31:03 +00:00
( ( UnicodeString ) " | " + parseError . postContext ) : ( UnicodeString ) " " ) ) : ( UnicodeString ) " " ) ) ;
2001-09-17 20:59:42 +00:00
return ;
}
2000-08-10 00:28:31 +00:00
UTransPosition index = { 19 , 20 , 20 , 20 } ;
UnicodeString rs = " Transliterate this-'' " ;
UnicodeString insertion = " abc " ;
UnicodeString expected = UnicodeString ( " Transliterate this-' \\ u0061 \\ u0062 \\ u0063' " , " " ) ;
t - > transliterate ( rs , index , insertion , status ) ;
if ( U_FAILURE ( status ) )
errln ( " FAIL: " + t - > getID ( ) + " .translitere(Replaceable, int[], UnicodeString, UErrorCode)--> " + ( UnicodeString ) u_errorName ( status ) ) ;
t - > finishTransliteration ( rs , index ) ;
UnicodeString message = " transliterate " ;
doTest ( message , rs , expected ) ;
logln ( " try calling transliterate with invalid index values " ) ;
UTransPosition index1 [ ] = {
//START, LIMIT, CURSOR
{ 10 , 10 , 12 , 10 } , //invalid since CURSOR>LIMIT valid:-START <= CURSOR <= LIMIT
{ 17 , 16 , 17 , 17 } , //invalid since START>LIMIT valid:-0<=START<=LIMIT
{ - 1 , 16 , 14 , 16 } , //invalid since START<0
{ 3 , 50 , 2 , 50 } //invalid since LIMIT>text.length()
} ;
2000-08-29 23:53:37 +00:00
for ( uint32_t i = 0 ; i < sizeof ( index1 ) / sizeof ( index1 [ 0 ] ) ; i + + ) {
2000-08-10 00:28:31 +00:00
status = U_ZERO_ERROR ;
t - > transliterate ( rs , index1 [ i ] , insertion , status ) ;
if ( status = = U_ILLEGAL_ARGUMENT_ERROR )
logln ( " OK: invalid index values handled correctly " ) ;
else
errln ( " FAIL: invalid index values didn't throw U_ILLEGAL_ARGUMENT_ERROR throw " + ( UnicodeString ) u_errorName ( status ) ) ;
}
2000-01-18 02:34:41 +00:00
2000-08-10 00:28:31 +00:00
delete t ;
}
2000-01-18 02:34:41 +00:00
void TransliteratorAPITest : : TestKeyboardTransliterator1 ( ) {
2000-08-10 00:28:31 +00:00
UnicodeString Data [ ] = {
//insertion, buffer
" a " , UnicodeString ( " \\ u0061 " , " " ) ,
" bbb " , UnicodeString ( " \\ u0061 \\ u0062 \\ u0062 \\ u0062 " , " " ) ,
" ca " , UnicodeString ( " \\ u0061 \\ u0062 \\ u0062 \\ u0062 \\ u0063 \\ u0061 " , " " ) ,
" " , UnicodeString ( " \\ u0061 \\ u0062 \\ u0062 \\ u0062 \\ u0063 \\ u0061 \\ u0020 " , " " ) ,
" " , UnicodeString ( " \\ u0061 \\ u0062 \\ u0062 \\ u0062 \\ u0063 \\ u0061 \\ u0020 " , " " ) ,
" a " , UnicodeString ( " \\ u0061 " , " " ) ,
" b " , UnicodeString ( " \\ u0061 \\ u0062 " , " " ) ,
" z " , UnicodeString ( " \\ u0061 \\ u0062 \\ u007A " , " " ) ,
" " , UnicodeString ( " \\ u0061 \\ u0062 \\ u007A " , " " )
} ;
2001-08-31 03:24:28 +00:00
UParseError parseError ;
UErrorCode status = U_ZERO_ERROR ;
Transliterator * t = Transliterator : : createInstance ( " Any-Hex " , UTRANS_FORWARD , parseError , status ) ;
2000-08-10 00:28:31 +00:00
//keyboardAux(t, Data);
UTransPosition index = { 0 , 0 , 0 , 0 } ;
UnicodeString s ;
2000-08-29 23:53:37 +00:00
uint32_t i ;
2000-08-10 00:28:31 +00:00
logln ( " Testing transliterate(Replaceable, int32_t, UnicodeString, UErrorCode) " ) ;
for ( i = 0 ; i < 10 ; i = i + 2 ) {
UnicodeString log ;
if ( Data [ i + 0 ] ! = " " ) {
log = s + " + " + Data [ i + 0 ] + " -> " ;
t - > transliterate ( s , index , Data [ i + 0 ] , status ) ;
if ( U_FAILURE ( status ) ) {
errln ( " FAIL: " + t - > getID ( ) + " .transliterate(Replaceable, int32_t[], UnicodeString, UErrorCode)--> " + ( UnicodeString ) u_errorName ( status ) ) ;
continue ;
2000-01-18 02:34:41 +00:00
}
2000-08-10 00:28:31 +00:00
} else {
log = s + " => " ;
t - > finishTransliteration ( s , index ) ;
}
// Show the start index '{' and the cursor '|'
displayOutput ( s , Data [ i + 1 ] , log , index ) ;
}
s = " " ;
status = U_ZERO_ERROR ;
index . contextStart = index . contextLimit = index . start = index . limit = 0 ;
logln ( " Testing transliterate(Replaceable, int32_t, UChar, UErrorCode) " ) ;
for ( i = 10 ; i < sizeof ( Data ) / sizeof ( Data [ 0 ] ) ; i = i + 2 ) {
UnicodeString log ;
if ( Data [ i + 0 ] ! = " " ) {
log = s + " + " + Data [ i + 0 ] + " -> " ;
UChar c = Data [ i + 0 ] . charAt ( 0 ) ;
t - > transliterate ( s , index , c , status ) ;
if ( U_FAILURE ( status ) )
errln ( " FAIL: " + t - > getID ( ) + " .transliterate(Replaceable, int32_t[], UChar, UErrorCode)--> " + ( UnicodeString ) u_errorName ( status ) ) ;
continue ;
} else {
log = s + " => " ;
t - > finishTransliteration ( s , index ) ;
}
// Show the start index '{' and the cursor '|'
displayOutput ( s , Data [ i + 1 ] , log , index ) ;
}
delete t ;
2000-01-18 02:34:41 +00:00
}
2000-08-10 00:28:31 +00:00
2000-01-18 02:34:41 +00:00
void TransliteratorAPITest : : TestKeyboardTransliterator2 ( ) {
2000-08-10 00:28:31 +00:00
UnicodeString Data [ ] = {
//insertion, buffer, index[START], index[LIMIT], index[CURSOR]
2001-08-01 17:37:08 +00:00
//data for Any-Hex
2000-08-10 00:28:31 +00:00
" abc " , UnicodeString ( " Initial String: add- \\ u0061 \\ u0062 \\ u0063- " , " " ) , " 19 " , " 20 " , " 20 " ,
" a " , UnicodeString ( " In \\ u0069 \\ u0061tial String: add- \\ u0061 \\ u0062 \\ u0063- " , " " ) , " 2 " , " 3 " , " 2 " ,
" b " , UnicodeString ( " \\ u0062In \\ u0069 \\ u0061tial String: add- \\ u0061 \\ u0062 \\ u0063- " , " " ) , " 0 " , " 0 " , " 0 " ,
" " , UnicodeString ( " \\ u0062In \\ u0069 \\ u0061tial String: add- \\ u0061 \\ u0062 \\ u0063- " , " " ) , " 0 " , " 0 " , " 0 " ,
//data for Latin-Devanagiri
" aa " , CharsToUnicodeString ( " Hindi - \\ u0906- " ) , " 6 " , " 7 " , " 6 " ,
" maa " , CharsToUnicodeString ( " Hindi - \\ u0906 \\ u092E \\ u093E- " ) , " 7 " , " 8 " , " 7 " ,
" raa " , CharsToUnicodeString ( " Hi \\ u0930 \\ u093Endi - \\ u0906 \\ u092E \\ u093E- " ) , " 1 " , " 2 " , " 2 " ,
" " , CharsToUnicodeString ( " Hi \\ u0930 \\ u093Endi - \\ u0906 \\ u092E \\ u093E- " ) , " 1 " , " 2 " , " 2 "
//data for contracted-Expanded
// CharsToUnicodeString("\\u00C1"), CharsToUnicodeString("Ad\\u0041\\u0301d here:"), "1", "2", "1" ,
// CharsToUnicodeString("\\u00C0"), CharsToUnicodeString("Ad\\u0041\\u0301d here:\\u0041\\u0300"), "11", "11", "11",
// "", CharsToUnicodeString("Ad\\u0041\\u0301d here:\\u0041\\u0300"), "11", "11", "11",
} ;
Transliterator * t ;
UnicodeString rs ;
UnicodeString dataStr ;
logln ( " Testing transliterate(Replaceable, int32_t, UnicodeString, UErrorCode) " ) ;
2001-08-31 03:24:28 +00:00
UErrorCode status = U_ZERO_ERROR ;
UParseError parseError ;
2000-08-10 00:28:31 +00:00
rs = " Initial String: add-- " ;
2001-08-31 03:24:28 +00:00
t = Transliterator : : createInstance ( " Any-Hex " , UTRANS_FORWARD , parseError , status ) ;
2000-08-10 00:28:31 +00:00
if ( t = = 0 )
errln ( " FAIL : construction " ) ;
else {
keyboardAux ( t , Data , rs , 0 , 20 ) ;
delete t ;
}
2000-01-18 02:34:41 +00:00
2000-08-10 00:28:31 +00:00
rs = " Hindi -- " ;
2001-08-31 03:24:28 +00:00
t = Transliterator : : createInstance ( " Latin-Devanagari " , UTRANS_FORWARD , parseError , status ) ;
2000-08-10 00:28:31 +00:00
if ( t = = 0 )
errln ( " FAIL : construction " ) ;
else
keyboardAux ( t , Data , rs , 20 , 40 ) ;
// rs="Add here:";
// t=Transliterator::createInstance("Contracted-Expanded");
// keyboardAux(t, Data, rs, 35, 55);
2000-01-18 02:34:41 +00:00
2000-08-10 00:28:31 +00:00
delete t ;
}
2000-01-18 02:34:41 +00:00
void TransliteratorAPITest : : TestKeyboardTransliterator3 ( ) {
2000-08-10 00:28:31 +00:00
UnicodeString s = " This is the main string " ;
UnicodeString Data [ ] = {
" 0 " , " 0 " , " 0 " , " This is the main string " ,
" 1 " , " 3 " , " 2 " , UnicodeString ( " Th \\ u0069s is the main string " , " " ) ,
" 20 " , " 21 " , " 20 " , UnicodeString ( " Th \\ u0069s is the mai \\ u006E string " , " " )
} ;
UErrorCode status = U_ZERO_ERROR ;
2001-08-31 03:24:28 +00:00
UParseError parseError ;
2000-08-10 00:28:31 +00:00
UTransPosition index = { 0 , 0 , 0 , 0 } ;
logln ( " Testing transliterate(Replaceable, int32_t, UErrorCode) " ) ;
2001-08-31 03:24:28 +00:00
Transliterator * t = Transliterator : : createInstance ( " Any-Hex " , UTRANS_FORWARD , parseError , status ) ;
2000-08-10 00:28:31 +00:00
if ( t = = 0 )
errln ( " FAIL : construction " ) ;
2000-12-21 01:18:01 +00:00
for ( uint32_t i = 0 ; i < sizeof ( Data ) / sizeof ( Data [ 0 ] ) ; i = i + 4 ) {
2000-08-10 00:28:31 +00:00
UnicodeString log ;
index . contextStart = getInt ( Data [ i + 0 ] ) ;
2000-06-27 20:07:59 +00:00
index . contextLimit = index . limit = getInt ( Data [ i + 1 ] ) ;
2000-06-27 19:34:03 +00:00
index . start = getInt ( Data [ i + 2 ] ) ;
2000-01-18 20:24:35 +00:00
t - > transliterate ( s , index , status ) ;
2000-01-18 20:04:30 +00:00
if ( U_FAILURE ( status ) ) {
2000-01-18 20:24:35 +00:00
errln ( " FAIL: " + t - > getID ( ) + " .transliterate(Replaceable, int32_t[], UErrorCode)--> " + ( UnicodeString ) u_errorName ( status ) ) ;
2000-08-10 00:28:31 +00:00
continue ;
}
t - > finishTransliteration ( s , index ) ;
log = s + " => " ;
// Show the start index '{' and the cursor '|'
2000-01-18 02:34:41 +00:00
displayOutput ( s , Data [ i + 3 ] , log , index ) ;
2000-08-10 00:28:31 +00:00
}
2000-01-18 02:34:41 +00:00
2000-08-10 00:28:31 +00:00
delete t ;
2000-01-18 02:34:41 +00:00
}
2000-06-27 18:20:33 +00:00
void TransliteratorAPITest : : TestNullTransliterator ( ) {
UnicodeString s ( " Transliterate using null transliterator " ) ;
NullTransliterator * nullTrans = new NullTransliterator ( ) ;
int32_t transLimit ;
int32_t start = 0 ;
int32_t limit = s . length ( ) ;
UnicodeString replaceable = s ;
transLimit = nullTrans - > transliterate ( replaceable , start , limit ) ;
if ( transLimit ! = limit ) {
errln ( " ERROR: NullTransliterator->transliterate() failed " ) ;
}
doTest ( ( UnicodeString ) " nulTrans->transliterate " , replaceable , s ) ;
replaceable . remove ( ) ;
replaceable . append ( s ) ;
2000-08-12 01:03:01 +00:00
UTransPosition index ;
index . contextStart = start ;
index . contextLimit = limit ;
index . start = 0 ;
index . limit = limit ;
2000-06-27 18:20:33 +00:00
nullTrans - > handleTransliterate ( replaceable , index , TRUE ) ;
2000-06-27 19:34:03 +00:00
if ( index . start ! = limit ) {
2000-06-27 18:20:33 +00:00
errln ( " ERROR: NullTransliterator->handleTransliterate() failed " ) ;
}
doTest ( ( UnicodeString ) " NullTransliterator->handleTransliterate " , replaceable , s ) ;
2000-07-13 01:05:50 +00:00
delete nullTrans ;
2000-06-27 18:20:33 +00:00
}
2000-07-24 17:09:07 +00:00
void TransliteratorAPITest : : TestRegisterUnregister ( ) {
UErrorCode status = U_ZERO_ERROR ;
2001-08-31 03:24:28 +00:00
UParseError parseError ;
2000-07-24 17:09:07 +00:00
/* Make sure it doesn't exist */
2001-08-31 03:24:28 +00:00
if ( Transliterator : : createInstance ( " TestA-TestB " , UTRANS_FORWARD , parseError , status ) ! = NULL ) {
2000-07-24 17:09:07 +00:00
errln ( " FAIL: TestA-TestB already registered \n " ) ;
return ;
}
/* Check inverse too
if ( Transliterator : : createInstance ( " TestA-TestB " ,
( UTransDirection ) UTRANS_REVERSE ) ! = NULL ) {
errln ( " FAIL: TestA-TestB inverse already registered \n " ) ;
return ;
}
*/
2001-08-31 03:24:28 +00:00
status = U_ZERO_ERROR ;
2000-07-24 17:09:07 +00:00
/* Create it */
Transliterator * t = new RuleBasedTransliterator ( " TestA-TestB " ,
" a<>b " ,
status ) ;
/* Register it */
2001-08-15 19:06:40 +00:00
Transliterator : : registerInstance ( t ) ;
2000-07-24 17:09:07 +00:00
/* Now check again -- should exist now*/
2001-08-31 03:24:28 +00:00
Transliterator * s = Transliterator : : createInstance ( " TestA-TestB " , UTRANS_FORWARD , parseError , status ) ;
2000-07-24 17:09:07 +00:00
if ( s = = NULL ) {
errln ( " FAIL: TestA-TestB not registered \n " ) ;
return ;
}
delete s ;
/* Check inverse too
s = Transliterator : : createInstance ( " TestA-TestB " ,
( UTransDirection ) UTRANS_REVERSE ) ;
if ( s = = NULL ) {
errln ( " FAIL: TestA-TestB inverse not registered \n " ) ;
return ;
}
delete s ;
*/
/*unregister the instance*/
Transliterator : : unregister ( " TestA-TestB " ) ;
/* now Make sure it doesn't exist */
2001-08-31 03:24:28 +00:00
if ( Transliterator : : createInstance ( " TestA-TestB " , UTRANS_FORWARD , parseError , status ) ! = NULL ) {
2000-07-24 17:09:07 +00:00
errln ( " FAIL: TestA-TestB isn't unregistered \n " ) ;
return ;
}
}
2000-01-18 02:34:41 +00:00
/**
* Used by TestFiltering ( ) .
*/
class TestFilter1 : public UnicodeFilter {
2001-07-27 00:18:53 +00:00
virtual UnicodeMatcher * clone ( ) const {
2000-01-18 02:34:41 +00:00
return new TestFilter1 ( * this ) ;
}
2001-07-25 19:11:02 +00:00
virtual UBool contains ( UChar32 c ) const {
2000-03-31 21:45:17 +00:00
if ( c = = 0x63 | | c = = 0x61 | | c = = 0x43 | | c = = 0x41 )
2000-01-18 02:34:41 +00:00
return FALSE ;
else
return TRUE ;
}
} ;
class TestFilter2 : public UnicodeFilter {
2001-07-27 00:18:53 +00:00
virtual UnicodeMatcher * clone ( ) const {
2000-01-18 02:34:41 +00:00
return new TestFilter2 ( * this ) ;
}
2001-07-25 19:11:02 +00:00
virtual UBool contains ( UChar32 c ) const {
2000-03-31 21:45:17 +00:00
if ( c = = 0x65 | | c = = 0x6c )
2000-01-18 02:34:41 +00:00
return FALSE ;
else
return TRUE ;
}
} ;
class TestFilter3 : public UnicodeFilter {
2001-07-27 00:18:53 +00:00
virtual UnicodeMatcher * clone ( ) const {
2000-01-18 02:34:41 +00:00
return new TestFilter3 ( * this ) ;
}
2001-07-25 19:11:02 +00:00
virtual UBool contains ( UChar32 c ) const {
2000-03-31 21:45:17 +00:00
if ( c = = 0x6f | | c = = 0x77 )
2000-01-18 02:34:41 +00:00
return FALSE ;
else
return TRUE ;
}
} ;
void TransliteratorAPITest : : TestGetAdoptFilter ( ) {
2001-09-20 01:11:24 +00:00
UErrorCode status = U_ZERO_ERROR ;
2001-08-31 03:24:28 +00:00
UParseError parseError ;
Transliterator * t = Transliterator : : createInstance ( " Any-Hex " , UTRANS_FORWARD , parseError , status ) ;
2000-08-10 00:28:31 +00:00
if ( t = = 0 )
errln ( " FAIL : construction " ) ;
2000-01-18 02:34:41 +00:00
const UnicodeFilter * u = t - > getFilter ( ) ;
if ( u ! = NULL ) {
errln ( " FAIL: getFilter failed. Didn't return null when the transliterator used no filtering " ) ;
}
UnicodeString got , temp , message ;
UnicodeString data = " ABCabcbbCBa " ;
2000-01-19 19:02:10 +00:00
temp = data ;
2000-08-10 00:28:31 +00:00
t - > transliterate ( temp ) ;
t - > adoptFilter ( new TestFilter1 ) ;
2000-01-18 02:34:41 +00:00
2000-01-19 19:02:10 +00:00
got = data ;
2000-08-10 00:28:31 +00:00
t - > transliterate ( got ) ;
2000-08-02 19:06:18 +00:00
UnicodeString exp = UnicodeString ( " A \\ u0042Ca \\ u0062c \\ u0062 \\ u0062C \\ u0042a " , " " ) ;
2000-08-10 00:28:31 +00:00
message = " transliteration after adoptFilter(a,A,c,C) " ;
2000-01-18 02:34:41 +00:00
doTest ( message , got , exp ) ;
logln ( " Testing round trip " ) ;
t - > adoptFilter ( ( UnicodeFilter * ) u ) ;
if ( t - > getFilter ( ) = = NULL )
logln ( " OK: adoptFilter and getFilter round trip worked " ) ;
else
errln ( " FAIL: adoptFilter or getFilter round trip failed " ) ;
2000-01-19 19:02:10 +00:00
got = data ;
t - > transliterate ( got ) ;
2000-08-02 19:06:18 +00:00
exp = UnicodeString ( " \\ u0041 \\ u0042 \\ u0043 \\ u0061 \\ u0062 \\ u0063 \\ u0062 \\ u0062 \\ u0043 \\ u0042 \\ u0061 " , " " ) ;
2000-01-18 02:34:41 +00:00
message = " transliteration after adopting null filter " ;
doTest ( message , got , exp ) ;
message = " adoptFilter round trip " ;
2000-08-10 00:28:31 +00:00
doTest ( " adoptFilter round trip " , got , temp ) ;
2000-01-18 02:34:41 +00:00
t - > adoptFilter ( new TestFilter2 ) ;
data = " heelloe " ;
2000-08-10 00:28:31 +00:00
exp = UnicodeString ( " \\ u0068eell \\ u006Fe " , " " ) ;
2000-01-19 19:02:10 +00:00
got = data ;
2000-08-10 00:28:31 +00:00
t - > transliterate ( got ) ;
message = " transliteration using (e,l) filter " ;
2000-01-18 02:34:41 +00:00
doTest ( " transliteration using (e,l) filter " , got , exp ) ;
2000-08-10 00:28:31 +00:00
data = " are well " ;
exp = UnicodeString ( " \\ u0061 \\ u0072e \\ u0020 \\ u0077ell " , " " ) ;
2000-01-19 19:02:10 +00:00
got = data ;
t - > transliterate ( got ) ;
2000-08-10 00:28:31 +00:00
doTest ( message , got , exp ) ;
2000-01-18 02:34:41 +00:00
t - > adoptFilter ( new TestFilter3 ) ;
2000-08-10 00:28:31 +00:00
data = " ho, wow! " ;
exp = UnicodeString ( " \\ u0068o \\ u002C \\ u0020wow \\ u0021 " , " " ) ;
2000-01-19 19:02:10 +00:00
got = data ;
t - > transliterate ( got ) ;
2000-08-10 00:28:31 +00:00
message = " transliteration using (o,w) filter " ;
2000-01-18 02:34:41 +00:00
doTest ( " transliteration using (o,w) filter " , got , exp ) ;
data = " owl " ;
2000-08-10 00:28:31 +00:00
exp = UnicodeString ( " ow \\ u006C " , " " ) ;
2000-01-19 19:02:10 +00:00
got = data ;
t - > transliterate ( got ) ;
2000-08-10 00:28:31 +00:00
doTest ( " transliteration using (o,w) filter " , got , exp ) ;
delete t ;
2000-01-18 02:34:41 +00:00
}
void TransliteratorAPITest : : keyboardAux ( Transliterator * t , UnicodeString DATA [ ] , UnicodeString & s , int32_t begin , int32_t end ) {
2000-08-10 00:28:31 +00:00
UTransPosition index = { 0 , 0 , 0 , 0 } ;
UErrorCode status = U_ZERO_ERROR ;
for ( int32_t i = begin ; i < end ; i = i + 5 ) {
UnicodeString log ;
if ( DATA [ i + 0 ] ! = " " ) {
log = s + " + " + DATA [ 0 ] + " -> " ;
index . contextStart = getInt ( DATA [ i + 2 ] ) ;
index . contextLimit = index . limit = getInt ( DATA [ i + 3 ] ) ;
index . start = getInt ( DATA [ i + 4 ] ) ;
t - > transliterate ( s , index , DATA [ i + 0 ] , status ) ;
if ( U_FAILURE ( status ) ) {
errln ( " FAIL: " + t - > getID ( ) + " .transliterate(Replaceable, int32_t[], UnicodeString, UErrorCode)--> " + ( UnicodeString ) u_errorName ( status ) ) ;
continue ;
}
} else {
log = s + " => " ;
t - > finishTransliteration ( s , index ) ;
2000-01-18 02:34:41 +00:00
}
2000-08-10 00:28:31 +00:00
// Show the start index '{' and the cursor '|'
displayOutput ( s , DATA [ i + 1 ] , log , index ) ;
}
2000-01-18 02:34:41 +00:00
}
2000-06-27 19:06:15 +00:00
void TransliteratorAPITest : : displayOutput ( const UnicodeString & got , const UnicodeString & expected , UnicodeString & log , UTransPosition & index ) {
2000-08-10 00:28:31 +00:00
// Show the start index '{' and the cursor '|'
UnicodeString a , b , c ;
got . extractBetween ( 0 , index . contextStart , a ) ;
got . extractBetween ( index . contextStart , index . start , b ) ;
got . extractBetween ( index . start , got . length ( ) , c ) ;
log . append ( a ) .
append ( ( UChar ) 0x7b /*{*/ ) .
append ( b ) .
append ( ( UChar ) 0x7c /*|*/ ) .
append ( c ) ;
if ( got = = expected )
logln ( " OK: " + prettify ( log ) ) ;
else
errln ( " FAIL: " + prettify ( log ) + " , expected " + prettify ( expected ) ) ;
2000-01-18 02:34:41 +00:00
}
/*Internal Functions used*/
void TransliteratorAPITest : : doTest ( const UnicodeString & message , const UnicodeString & result , const UnicodeString & expected ) {
2001-08-31 03:24:28 +00:00
if ( prettify ( result ) = = prettify ( expected ) )
2000-08-10 00:28:31 +00:00
logln ( ( UnicodeString ) " Ok: " + prettify ( message ) + " passed \" " + prettify ( expected ) + " \" " ) ;
else
errln ( ( UnicodeString ) " FAIL: " + message + " failed Got--> " + prettify ( result ) + " , Expected--> " + prettify ( expected ) ) ;
}
2000-01-18 02:34:41 +00:00