12e5b6d6dSopenharmony_ci// © 2016 and later: Unicode, Inc. and others. 22e5b6d6dSopenharmony_ci// License & terms of use: http://www.unicode.org/copyright.html 32e5b6d6dSopenharmony_ci/************************************************************************ 42e5b6d6dSopenharmony_ci * COPYRIGHT: 52e5b6d6dSopenharmony_ci * Copyright (c) 2000-2016, International Business Machines Corporation 62e5b6d6dSopenharmony_ci * and others. All Rights Reserved. 72e5b6d6dSopenharmony_ci ************************************************************************/ 82e5b6d6dSopenharmony_ci/************************************************************************ 92e5b6d6dSopenharmony_ci* Date Name Description 102e5b6d6dSopenharmony_ci* 1/03/2000 Madhu Creation. 112e5b6d6dSopenharmony_ci************************************************************************/ 122e5b6d6dSopenharmony_ci 132e5b6d6dSopenharmony_ci#include "unicode/utypes.h" 142e5b6d6dSopenharmony_ci 152e5b6d6dSopenharmony_ci#if !UCONFIG_NO_TRANSLITERATION 162e5b6d6dSopenharmony_ci 172e5b6d6dSopenharmony_ci#include "ittrans.h" 182e5b6d6dSopenharmony_ci#include "transapi.h" 192e5b6d6dSopenharmony_ci#include "unicode/utypes.h" 202e5b6d6dSopenharmony_ci#include "unicode/translit.h" 212e5b6d6dSopenharmony_ci#include "unicode/unifilt.h" 222e5b6d6dSopenharmony_ci#include "cpdtrans.h" 232e5b6d6dSopenharmony_ci#include "cmemory.h" 242e5b6d6dSopenharmony_ci#include <string.h> 252e5b6d6dSopenharmony_ci#include <stdio.h> 262e5b6d6dSopenharmony_ci#include <stdlib.h> 272e5b6d6dSopenharmony_ci#include "unicode/rep.h" 282e5b6d6dSopenharmony_ci#include "unicode/locid.h" 292e5b6d6dSopenharmony_ci#include "unicode/uniset.h" 302e5b6d6dSopenharmony_ci 312e5b6d6dSopenharmony_ciint32_t getInt(UnicodeString str) 322e5b6d6dSopenharmony_ci{ 332e5b6d6dSopenharmony_ci char buffer[20]; 342e5b6d6dSopenharmony_ci int len=str.length(); 352e5b6d6dSopenharmony_ci if(len>=20) { 362e5b6d6dSopenharmony_ci len=19; 372e5b6d6dSopenharmony_ci } 382e5b6d6dSopenharmony_ci str.extract(0, len, buffer, ""); 392e5b6d6dSopenharmony_ci buffer[len]=0; 402e5b6d6dSopenharmony_ci return atoi(buffer); 412e5b6d6dSopenharmony_ci} 422e5b6d6dSopenharmony_ci 432e5b6d6dSopenharmony_ci//--------------------------------------------- 442e5b6d6dSopenharmony_ci// runIndexedTest 452e5b6d6dSopenharmony_ci//--------------------------------------------- 462e5b6d6dSopenharmony_ci 472e5b6d6dSopenharmony_civoid 482e5b6d6dSopenharmony_ciTransliteratorAPITest::runIndexedTest(int32_t index, UBool exec, 492e5b6d6dSopenharmony_ci const char* &name, char* /*par*/) { 502e5b6d6dSopenharmony_ci switch (index) { 512e5b6d6dSopenharmony_ci TESTCASE(0,TestgetInverse); 522e5b6d6dSopenharmony_ci TESTCASE(1,TestgetID); 532e5b6d6dSopenharmony_ci TESTCASE(2,TestGetDisplayName); 542e5b6d6dSopenharmony_ci TESTCASE(3,TestTransliterate1); 552e5b6d6dSopenharmony_ci TESTCASE(4,TestTransliterate2); 562e5b6d6dSopenharmony_ci TESTCASE(5,TestTransliterate3); 572e5b6d6dSopenharmony_ci TESTCASE(6,TestSimpleKeyboardTransliterator); 582e5b6d6dSopenharmony_ci TESTCASE(7,TestKeyboardTransliterator1); 592e5b6d6dSopenharmony_ci TESTCASE(8,TestKeyboardTransliterator2); 602e5b6d6dSopenharmony_ci TESTCASE(9,TestKeyboardTransliterator3); 612e5b6d6dSopenharmony_ci TESTCASE(10,TestGetAdoptFilter); 622e5b6d6dSopenharmony_ci TESTCASE(11,TestClone); 632e5b6d6dSopenharmony_ci TESTCASE(12,TestNullTransliterator); 642e5b6d6dSopenharmony_ci TESTCASE(13,TestRegisterUnregister); 652e5b6d6dSopenharmony_ci TESTCASE(14,TestUnicodeFunctor); 662e5b6d6dSopenharmony_ci default: name = ""; break; 672e5b6d6dSopenharmony_ci } 682e5b6d6dSopenharmony_ci} 692e5b6d6dSopenharmony_ci 702e5b6d6dSopenharmony_ci 712e5b6d6dSopenharmony_civoid TransliteratorAPITest::TestgetID() { 722e5b6d6dSopenharmony_ci UnicodeString trans="Latin-Greek"; 732e5b6d6dSopenharmony_ci UnicodeString ID; 742e5b6d6dSopenharmony_ci UParseError parseError; 752e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 762e5b6d6dSopenharmony_ci Transliterator* t= Transliterator::createInstance(trans, UTRANS_FORWARD, parseError, status); 772e5b6d6dSopenharmony_ci if(t==0 || U_FAILURE(status)){ 782e5b6d6dSopenharmony_ci dataerrln("FAIL: construction of Latin-Greek - %s",u_errorName(status)); 792e5b6d6dSopenharmony_ci return; 802e5b6d6dSopenharmony_ci }else{ 812e5b6d6dSopenharmony_ci ID= t->getID(); 822e5b6d6dSopenharmony_ci if(ID != trans) 832e5b6d6dSopenharmony_ci errln("FAIL: getID returned " + ID + " instead of Latin-Greek"); 842e5b6d6dSopenharmony_ci delete t; 852e5b6d6dSopenharmony_ci } 862e5b6d6dSopenharmony_ci int i; 872e5b6d6dSopenharmony_ci for (i=0; i<Transliterator::countAvailableIDs(); i++){ 882e5b6d6dSopenharmony_ci status = U_ZERO_ERROR; 892e5b6d6dSopenharmony_ci ID = (UnicodeString) Transliterator::getAvailableID(i); 902e5b6d6dSopenharmony_ci if(ID.indexOf("Thai")>-1){ 912e5b6d6dSopenharmony_ci continue; 922e5b6d6dSopenharmony_ci } 932e5b6d6dSopenharmony_ci t = Transliterator::createInstance(ID, UTRANS_FORWARD, parseError, status); 942e5b6d6dSopenharmony_ci if(t == 0){ 952e5b6d6dSopenharmony_ci errln("FAIL: " + ID); 962e5b6d6dSopenharmony_ci continue; 972e5b6d6dSopenharmony_ci } 982e5b6d6dSopenharmony_ci if(ID != t->getID()) 992e5b6d6dSopenharmony_ci errln("FAIL: getID() returned " + t->getID() + " instead of " + ID); 1002e5b6d6dSopenharmony_ci delete t; 1012e5b6d6dSopenharmony_ci } 1022e5b6d6dSopenharmony_ci ID=(UnicodeString)Transliterator::getAvailableID(i); 1032e5b6d6dSopenharmony_ci if(ID != (UnicodeString)Transliterator::getAvailableID(0)){ 1042e5b6d6dSopenharmony_ci errln("FAIL: calling getAvailableID(index > coundAvailableIDs) should make index=0\n"); 1052e5b6d6dSopenharmony_ci } 1062e5b6d6dSopenharmony_ci 1072e5b6d6dSopenharmony_ci Transliterator* t1=Transliterator::createInstance("Latin-Devanagari", UTRANS_FORWARD, parseError, status); 1082e5b6d6dSopenharmony_ci Transliterator* t2=Transliterator::createInstance("Latin-Greek", UTRANS_FORWARD, parseError, status); 1092e5b6d6dSopenharmony_ci if(t1 ==0 || t2 == 0){ 1102e5b6d6dSopenharmony_ci errln("FAIL: construction"); 1112e5b6d6dSopenharmony_ci return; 1122e5b6d6dSopenharmony_ci } 1132e5b6d6dSopenharmony_ci Transliterator* t3=t1->clone(); 1142e5b6d6dSopenharmony_ci Transliterator* t4=t2->clone(); 1152e5b6d6dSopenharmony_ci 1162e5b6d6dSopenharmony_ci if(t1->getID() != t3->getID() || t2->getID() != t4->getID() || 1172e5b6d6dSopenharmony_ci t1->getID() == t4->getID() || t2->getID() == t3->getID() || 1182e5b6d6dSopenharmony_ci t1->getID()== t4->getID() ) 1192e5b6d6dSopenharmony_ci errln("FAIL: getID or clone failed"); 1202e5b6d6dSopenharmony_ci 1212e5b6d6dSopenharmony_ci 1222e5b6d6dSopenharmony_ci Transliterator* t5=Transliterator::createInstance("Latin-Devanagari", UTRANS_FORWARD, parseError, status); 1232e5b6d6dSopenharmony_ci if(t5 == 0) 1242e5b6d6dSopenharmony_ci errln("FAIL: construction"); 1252e5b6d6dSopenharmony_ci else if(t1->getID() != t5->getID() || t5->getID() != t3->getID() || t1->getID() != t3->getID()) 1262e5b6d6dSopenharmony_ci errln("FAIL: getID or clone failed"); 1272e5b6d6dSopenharmony_ci 1282e5b6d6dSopenharmony_ci 1292e5b6d6dSopenharmony_ci delete t1; 1302e5b6d6dSopenharmony_ci delete t2; 1312e5b6d6dSopenharmony_ci delete t3; 1322e5b6d6dSopenharmony_ci delete t4; 1332e5b6d6dSopenharmony_ci delete t5; 1342e5b6d6dSopenharmony_ci} 1352e5b6d6dSopenharmony_ci 1362e5b6d6dSopenharmony_civoid TransliteratorAPITest::TestgetInverse() { 1372e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 1382e5b6d6dSopenharmony_ci UParseError parseError; 1392e5b6d6dSopenharmony_ci Transliterator* t1 = Transliterator::createInstance("Katakana-Latin", UTRANS_FORWARD, parseError, status); 1402e5b6d6dSopenharmony_ci Transliterator* invt1 = Transliterator::createInstance("Latin-Katakana", UTRANS_FORWARD, parseError, status); 1412e5b6d6dSopenharmony_ci Transliterator* t2 = Transliterator::createInstance("Latin-Devanagari", UTRANS_FORWARD, parseError, status); 1422e5b6d6dSopenharmony_ci Transliterator* invt2 = Transliterator::createInstance("Devanagari-Latin", UTRANS_FORWARD, parseError, status); 1432e5b6d6dSopenharmony_ci if(t1 == 0 || invt1 == 0 || t2 == 0 || invt2 == 0) { 1442e5b6d6dSopenharmony_ci dataerrln("FAIL: in instantiation - %s", u_errorName(status)); 1452e5b6d6dSopenharmony_ci return; 1462e5b6d6dSopenharmony_ci } 1472e5b6d6dSopenharmony_ci 1482e5b6d6dSopenharmony_ci Transliterator* inverse1=t1->createInverse(status); 1492e5b6d6dSopenharmony_ci Transliterator* inverse2=t2->createInverse(status); 1502e5b6d6dSopenharmony_ci if(inverse1->getID() != invt1->getID() || inverse2->getID() != invt2->getID() 1512e5b6d6dSopenharmony_ci || inverse1->getID() == invt2->getID() || inverse2->getID() == invt1->getID() ) 1522e5b6d6dSopenharmony_ci errln("FAIL: getInverse() "); 1532e5b6d6dSopenharmony_ci 1542e5b6d6dSopenharmony_ci UnicodeString TransID[]={ 1552e5b6d6dSopenharmony_ci "Halfwidth-Fullwidth", 1562e5b6d6dSopenharmony_ci "Fullwidth-Halfwidth", 1572e5b6d6dSopenharmony_ci "Greek-Latin" , 1582e5b6d6dSopenharmony_ci "Latin-Greek", 1592e5b6d6dSopenharmony_ci //"Arabic-Latin", // removed in 2.0 1602e5b6d6dSopenharmony_ci //"Latin-Arabic", 1612e5b6d6dSopenharmony_ci "Katakana-Latin", 1622e5b6d6dSopenharmony_ci "Latin-Katakana", 1632e5b6d6dSopenharmony_ci //"Hebrew-Latin", // removed in 2.0 1642e5b6d6dSopenharmony_ci //"Latin-Hebrew", 1652e5b6d6dSopenharmony_ci "Cyrillic-Latin", 1662e5b6d6dSopenharmony_ci "Latin-Cyrillic", 1672e5b6d6dSopenharmony_ci "Devanagari-Latin", 1682e5b6d6dSopenharmony_ci "Latin-Devanagari", 1692e5b6d6dSopenharmony_ci "Any-Hex", 1702e5b6d6dSopenharmony_ci "Hex-Any" 1712e5b6d6dSopenharmony_ci }; 1722e5b6d6dSopenharmony_ci for(uint32_t i=0; i<UPRV_LENGTHOF(TransID); i=i+2){ 1732e5b6d6dSopenharmony_ci Transliterator *trans1=Transliterator::createInstance(TransID[i], UTRANS_FORWARD, parseError, status); 1742e5b6d6dSopenharmony_ci if(t1 == 0){ 1752e5b6d6dSopenharmony_ci errln("FAIL: in instantiation for" + TransID[i]); 1762e5b6d6dSopenharmony_ci continue; 1772e5b6d6dSopenharmony_ci } 1782e5b6d6dSopenharmony_ci Transliterator *inver1=trans1->createInverse(status); 1792e5b6d6dSopenharmony_ci if(inver1->getID() != TransID[i+1] ) 1802e5b6d6dSopenharmony_ci errln("FAIL :getInverse() for " + TransID[i] + " returned " + inver1->getID() + " instead of " + TransID[i+1]); 1812e5b6d6dSopenharmony_ci delete inver1; 1822e5b6d6dSopenharmony_ci delete trans1; 1832e5b6d6dSopenharmony_ci } 1842e5b6d6dSopenharmony_ci delete t1; 1852e5b6d6dSopenharmony_ci delete t2; 1862e5b6d6dSopenharmony_ci delete invt1; 1872e5b6d6dSopenharmony_ci delete invt2; 1882e5b6d6dSopenharmony_ci delete inverse1; 1892e5b6d6dSopenharmony_ci delete inverse2; 1902e5b6d6dSopenharmony_ci 1912e5b6d6dSopenharmony_ci} 1922e5b6d6dSopenharmony_ci 1932e5b6d6dSopenharmony_civoid TransliteratorAPITest::TestClone(){ 1942e5b6d6dSopenharmony_ci Transliterator *t1, *t2, *t3, *t4; 1952e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 1962e5b6d6dSopenharmony_ci UParseError parseError; 1972e5b6d6dSopenharmony_ci t1=Transliterator::createInstance("Latin-Devanagari", UTRANS_FORWARD, parseError, status); 1982e5b6d6dSopenharmony_ci t2=Transliterator::createInstance("Latin-Greek", UTRANS_FORWARD, parseError, status); 1992e5b6d6dSopenharmony_ci if(t1 == 0 || t2 == 0){ 2002e5b6d6dSopenharmony_ci dataerrln("FAIL: construction - %s", u_errorName(status)); 2012e5b6d6dSopenharmony_ci return; 2022e5b6d6dSopenharmony_ci } 2032e5b6d6dSopenharmony_ci t3=t1->clone(); 2042e5b6d6dSopenharmony_ci t4=t2->clone(); 2052e5b6d6dSopenharmony_ci 2062e5b6d6dSopenharmony_ci if(t1->getID() != t3->getID() || t2->getID() != t4->getID() ) 2072e5b6d6dSopenharmony_ci errln("FAIL: clone or getID failed"); 2082e5b6d6dSopenharmony_ci if(t1->getID()==t4->getID() || t2->getID()==t3->getID() || t1->getID()==t4->getID()) 2092e5b6d6dSopenharmony_ci errln("FAIL: clone or getID failed"); 2102e5b6d6dSopenharmony_ci 2112e5b6d6dSopenharmony_ci delete t1; 2122e5b6d6dSopenharmony_ci delete t2; 2132e5b6d6dSopenharmony_ci delete t3; 2142e5b6d6dSopenharmony_ci delete t4; 2152e5b6d6dSopenharmony_ci 2162e5b6d6dSopenharmony_ci} 2172e5b6d6dSopenharmony_ci 2182e5b6d6dSopenharmony_civoid TransliteratorAPITest::TestGetDisplayName() { 2192e5b6d6dSopenharmony_ci UnicodeString dispNames[]= { 2202e5b6d6dSopenharmony_ci //ID, displayName 2212e5b6d6dSopenharmony_ci //"CurlyQuotes-StraightQuotes" ,"CurlyQuotes to StraightQuotes", 2222e5b6d6dSopenharmony_ci "Any-Hex" ,"Any to Hex Escape", 2232e5b6d6dSopenharmony_ci "Halfwidth-Fullwidth" ,"Halfwidth to Fullwidth" , 2242e5b6d6dSopenharmony_ci //"Latin-Arabic" ,"Latin to Arabic" , 2252e5b6d6dSopenharmony_ci "Latin-Devanagari" ,"Latin to Devanagari" , 2262e5b6d6dSopenharmony_ci "Greek-Latin" ,"Greek to Latin" , 2272e5b6d6dSopenharmony_ci //"Arabic-Latin" ,"Arabic to Latin" , 2282e5b6d6dSopenharmony_ci "Hex-Any" ,"Hex Escape to Any", 2292e5b6d6dSopenharmony_ci "Cyrillic-Latin" ,"Cyrillic to Latin" , 2302e5b6d6dSopenharmony_ci "Latin-Greek" ,"Latin to Greek" , 2312e5b6d6dSopenharmony_ci "Latin-Katakana" ,"Latin to Katakana" , 2322e5b6d6dSopenharmony_ci //"Latin-Hebrew" ,"Latin to Hebrew" , 2332e5b6d6dSopenharmony_ci "Katakana-Latin" ,"Katakana to Latin" 2342e5b6d6dSopenharmony_ci }; 2352e5b6d6dSopenharmony_ci UnicodeString name=""; 2362e5b6d6dSopenharmony_ci Transliterator* t; 2372e5b6d6dSopenharmony_ci UnicodeString message; 2382e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 2392e5b6d6dSopenharmony_ci UParseError parseError; 2402e5b6d6dSopenharmony_ci 2412e5b6d6dSopenharmony_ci#if UCONFIG_NO_FORMATTING 2422e5b6d6dSopenharmony_ci logln("Skipping, UCONFIG_NO_FORMATTING is set\n"); 2432e5b6d6dSopenharmony_ci return; 2442e5b6d6dSopenharmony_ci#else 2452e5b6d6dSopenharmony_ci 2462e5b6d6dSopenharmony_ci for (uint32_t i=0; i<UPRV_LENGTHOF(dispNames); i=i+2 ) { 2472e5b6d6dSopenharmony_ci t = Transliterator::createInstance(dispNames[i+0], UTRANS_FORWARD, parseError, status); 2482e5b6d6dSopenharmony_ci if(t==0){ 2492e5b6d6dSopenharmony_ci dataerrln("FAIL: construction: " + dispNames[i+0] + " - " + u_errorName(status)); 2502e5b6d6dSopenharmony_ci status = U_ZERO_ERROR; 2512e5b6d6dSopenharmony_ci continue; 2522e5b6d6dSopenharmony_ci } 2532e5b6d6dSopenharmony_ci t->getDisplayName(t->getID(), name); 2542e5b6d6dSopenharmony_ci message="Display name for ID:" + t->getID(); 2552e5b6d6dSopenharmony_ci // doTest(message, name, dispNames[i+1]); //!!! This will obviously fail for any locale other than english and its children!!! 2562e5b6d6dSopenharmony_ci name=""; 2572e5b6d6dSopenharmony_ci t->getDisplayName(t->getID(), Locale::getUS(), name); 2582e5b6d6dSopenharmony_ci message.remove(); 2592e5b6d6dSopenharmony_ci message.append("Display name for on english locale ID:"); 2602e5b6d6dSopenharmony_ci message.append(t->getID()); 2612e5b6d6dSopenharmony_ci // message="Display name for on english locale ID:" + t->getID(); 2622e5b6d6dSopenharmony_ci doTest(message, name, dispNames[i+1]); 2632e5b6d6dSopenharmony_ci name=""; 2642e5b6d6dSopenharmony_ci 2652e5b6d6dSopenharmony_ci delete t; 2662e5b6d6dSopenharmony_ci } 2672e5b6d6dSopenharmony_ci#endif 2682e5b6d6dSopenharmony_ci 2692e5b6d6dSopenharmony_ci} 2702e5b6d6dSopenharmony_ci 2712e5b6d6dSopenharmony_civoid TransliteratorAPITest::TestTransliterate1(){ 2722e5b6d6dSopenharmony_ci 2732e5b6d6dSopenharmony_ci UnicodeString Data[]={ 2742e5b6d6dSopenharmony_ci //ID, input string, transliterated string 2752e5b6d6dSopenharmony_ci "Any-Hex", "hello", UnicodeString("\\u0068\\u0065\\u006C\\u006C\\u006F", "") , 2762e5b6d6dSopenharmony_ci "Hex-Any", UnicodeString("\\u0068\\u0065\\u006C\\u006C\\u006F", ""), "hello" , 2772e5b6d6dSopenharmony_ci "Latin-Devanagari",CharsToUnicodeString("bha\\u0304rata"), CharsToUnicodeString("\\u092D\\u093E\\u0930\\u0924") , 2782e5b6d6dSopenharmony_ci "Latin-Devanagari",UnicodeString("kra ksha khra gra cra dya dhya",""), CharsToUnicodeString("\\u0915\\u094D\\u0930 \\u0915\\u094D\\u0936 \\u0916\\u094D\\u0930 \\u0917\\u094D\\u0930 \\u091a\\u094D\\u0930 \\u0926\\u094D\\u092F \\u0927\\u094D\\u092F") , 2792e5b6d6dSopenharmony_ci 2802e5b6d6dSopenharmony_ci "Devanagari-Latin", CharsToUnicodeString("\\u092D\\u093E\\u0930\\u0924"), CharsToUnicodeString("bh\\u0101rata"), 2812e5b6d6dSopenharmony_ci // "Contracted-Expanded", CharsToUnicodeString("\\u00C0\\u00C1\\u0042"), CharsToUnicodeString("\\u0041\\u0300\\u0041\\u0301\\u0042") , 2822e5b6d6dSopenharmony_ci // "Expanded-Contracted", CharsToUnicodeString("\\u0041\\u0300\\u0041\\u0301\\u0042"), CharsToUnicodeString("\\u00C0\\u00C1\\u0042") , 2832e5b6d6dSopenharmony_ci //"Latin-Arabic", "aap", CharsToUnicodeString("\\u0627\\u06A4") , 2842e5b6d6dSopenharmony_ci //"Arabic-Latin", CharsToUnicodeString("\\u0627\\u06A4"), "aap" 2852e5b6d6dSopenharmony_ci }; 2862e5b6d6dSopenharmony_ci 2872e5b6d6dSopenharmony_ci UnicodeString gotResult; 2882e5b6d6dSopenharmony_ci UnicodeString temp; 2892e5b6d6dSopenharmony_ci UnicodeString message; 2902e5b6d6dSopenharmony_ci Transliterator* t; 2912e5b6d6dSopenharmony_ci logln("Testing transliterate"); 2922e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 2932e5b6d6dSopenharmony_ci UParseError parseError; 2942e5b6d6dSopenharmony_ci 2952e5b6d6dSopenharmony_ci for(uint32_t i=0;i<UPRV_LENGTHOF(Data); i=i+3){ 2962e5b6d6dSopenharmony_ci t=Transliterator::createInstance(Data[i+0], UTRANS_FORWARD, parseError, status); 2972e5b6d6dSopenharmony_ci if(t==0){ 2982e5b6d6dSopenharmony_ci dataerrln("FAIL: construction: " + Data[i+0] + " Error: " + u_errorName(status)); 2992e5b6d6dSopenharmony_ci dataerrln("PreContext: " + prettify(parseError.preContext) + " PostContext: " + prettify( parseError.postContext) ); 3002e5b6d6dSopenharmony_ci status = U_ZERO_ERROR; 3012e5b6d6dSopenharmony_ci continue; 3022e5b6d6dSopenharmony_ci } 3032e5b6d6dSopenharmony_ci gotResult = Data[i+1]; 3042e5b6d6dSopenharmony_ci t->transliterate(gotResult); 3052e5b6d6dSopenharmony_ci message=t->getID() + "->transliterate(UnicodeString, UnicodeString) for\n\t Source:" + prettify(Data[i+1]); 3062e5b6d6dSopenharmony_ci doTest(message, gotResult, Data[i+2]); 3072e5b6d6dSopenharmony_ci 3082e5b6d6dSopenharmony_ci //doubt here 3092e5b6d6dSopenharmony_ci temp=Data[i+1]; 3102e5b6d6dSopenharmony_ci t->transliterate(temp); 3112e5b6d6dSopenharmony_ci message.remove(); 3122e5b6d6dSopenharmony_ci message.append(t->getID()); 3132e5b6d6dSopenharmony_ci message.append("->transliterate(Replaceable) for \n\tSource:"); 3142e5b6d6dSopenharmony_ci message.append(Data[i][1]); 3152e5b6d6dSopenharmony_ci doTest(message, temp, Data[i+2]); 3162e5b6d6dSopenharmony_ci 3172e5b6d6dSopenharmony_ci callEverything(t, __LINE__); 3182e5b6d6dSopenharmony_ci delete t; 3192e5b6d6dSopenharmony_ci } 3202e5b6d6dSopenharmony_ci} 3212e5b6d6dSopenharmony_ci 3222e5b6d6dSopenharmony_civoid TransliteratorAPITest::TestTransliterate2(){ 3232e5b6d6dSopenharmony_ci //testing tranliterate(String text, int start, int limit, StringBuffer result) 3242e5b6d6dSopenharmony_ci UnicodeString Data2[]={ 3252e5b6d6dSopenharmony_ci //ID, input string, start, limit, transliterated string 3262e5b6d6dSopenharmony_ci "Any-Hex", "hello! How are you?", "0", "5", UnicodeString("\\u0068\\u0065\\u006C\\u006C\\u006F", ""), UnicodeString("\\u0068\\u0065\\u006C\\u006C\\u006F! How are you?", "") , 3272e5b6d6dSopenharmony_ci "Any-Hex", "hello! How are you?", "7", "12", UnicodeString("\\u0048\\u006F\\u0077\\u0020\\u0061", ""), UnicodeString("hello! \\u0048\\u006F\\u0077\\u0020\\u0061re you?", ""), 3282e5b6d6dSopenharmony_ci "Hex-Any", CharsToUnicodeString("\\u0068\\u0065\\u006C\\u006C\\u006F\\u0021\\u0020"), "0", "5", "hello", "hello! " , 3292e5b6d6dSopenharmony_ci // "Contracted-Expanded", CharsToUnicodeString("\\u00C0\\u00C1\\u0042"), "1", "2", CharsToUnicodeString("\\u0041\\u0301"), CharsToUnicodeString("\\u00C0\\u0041\\u0301\\u0042") , 3302e5b6d6dSopenharmony_ci "Devanagari-Latin", CharsToUnicodeString("\\u092D\\u093E\\u0930\\u0924"), "0", "1", "bha", CharsToUnicodeString("bha\\u093E\\u0930\\u0924") , 3312e5b6d6dSopenharmony_ci "Devanagari-Latin", CharsToUnicodeString("\\u092D\\u093E\\u0930\\u0924"), "1", "2", CharsToUnicodeString("\\u0314\\u0101"), CharsToUnicodeString("\\u092D\\u0314\\u0101\\u0930\\u0924") 3322e5b6d6dSopenharmony_ci 3332e5b6d6dSopenharmony_ci }; 3342e5b6d6dSopenharmony_ci logln("\n Testing transliterate(String, int, int, StringBuffer)"); 3352e5b6d6dSopenharmony_ci Transliterator* t; 3362e5b6d6dSopenharmony_ci UnicodeString gotResBuf; 3372e5b6d6dSopenharmony_ci UnicodeString temp; 3382e5b6d6dSopenharmony_ci int32_t start, limit; 3392e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 3402e5b6d6dSopenharmony_ci UParseError parseError; 3412e5b6d6dSopenharmony_ci 3422e5b6d6dSopenharmony_ci for(uint32_t i=0; i<UPRV_LENGTHOF(Data2); i=i+6){ 3432e5b6d6dSopenharmony_ci t=Transliterator::createInstance(Data2[i+0], UTRANS_FORWARD, parseError, status); 3442e5b6d6dSopenharmony_ci if(t==0){ 3452e5b6d6dSopenharmony_ci dataerrln("FAIL: construction: " + prettify(Data2[i+0]) + " - " + u_errorName(status)); 3462e5b6d6dSopenharmony_ci continue; 3472e5b6d6dSopenharmony_ci } 3482e5b6d6dSopenharmony_ci start=getInt(Data2[i+2]); 3492e5b6d6dSopenharmony_ci limit=getInt(Data2[i+3]); 3502e5b6d6dSopenharmony_ci Data2[i+1].extractBetween(start, limit, gotResBuf); 3512e5b6d6dSopenharmony_ci t->transliterate(gotResBuf); 3522e5b6d6dSopenharmony_ci // errln("FAIL: calling transliterate on " + t->getID()); 3532e5b6d6dSopenharmony_ci doTest(t->getID() + ".transliterate(UnicodeString, int32_t, int32_t, UnicodeString):(" + start + "," + limit + ") for \n\t source: " + prettify(Data2[i+1]), gotResBuf, Data2[i+4]); 3542e5b6d6dSopenharmony_ci 3552e5b6d6dSopenharmony_ci temp=Data2[i+1]; 3562e5b6d6dSopenharmony_ci t->transliterate(temp, start, limit); 3572e5b6d6dSopenharmony_ci doTest(t->getID() + ".transliterate(Replaceable, int32_t, int32_t, ):(" + start + "," + limit + ") for \n\t source: " + prettify(Data2[i+1]), temp, Data2[i+5]); 3582e5b6d6dSopenharmony_ci status = U_ZERO_ERROR; 3592e5b6d6dSopenharmony_ci callEverything(t, __LINE__); 3602e5b6d6dSopenharmony_ci delete t; 3612e5b6d6dSopenharmony_ci t = NULL; 3622e5b6d6dSopenharmony_ci } 3632e5b6d6dSopenharmony_ci 3642e5b6d6dSopenharmony_ci status = U_ZERO_ERROR; 3652e5b6d6dSopenharmony_ci logln("\n Try calling transliterate with illegal start and limit values"); 3662e5b6d6dSopenharmony_ci t=Transliterator::createInstance("Any-Hex", UTRANS_FORWARD, parseError, status); 3672e5b6d6dSopenharmony_ci if(U_FAILURE(status)) { 3682e5b6d6dSopenharmony_ci errln("Error creating transliterator %s", u_errorName(status)); 3692e5b6d6dSopenharmony_ci delete t; 3702e5b6d6dSopenharmony_ci return; 3712e5b6d6dSopenharmony_ci } 3722e5b6d6dSopenharmony_ci gotResBuf = temp = "try start greater than limit"; 3732e5b6d6dSopenharmony_ci t->transliterate(gotResBuf, 10, 5); 3742e5b6d6dSopenharmony_ci if(gotResBuf == temp) { 3752e5b6d6dSopenharmony_ci logln("OK: start greater than limit value handled correctly"); 3762e5b6d6dSopenharmony_ci } else { 3772e5b6d6dSopenharmony_ci errln("FAIL: start greater than limit value returned" + gotResBuf); 3782e5b6d6dSopenharmony_ci } 3792e5b6d6dSopenharmony_ci 3802e5b6d6dSopenharmony_ci callEverything(t, __LINE__); 3812e5b6d6dSopenharmony_ci delete t; 3822e5b6d6dSopenharmony_ci 3832e5b6d6dSopenharmony_ci} 3842e5b6d6dSopenharmony_civoid TransliteratorAPITest::TestTransliterate3(){ 3852e5b6d6dSopenharmony_ci UnicodeString rs="This is the replaceable String"; 3862e5b6d6dSopenharmony_ci UnicodeString Data[] = { 3872e5b6d6dSopenharmony_ci "0", "0", "This is the replaceable String", 3882e5b6d6dSopenharmony_ci "2", "3", UnicodeString("Th\\u0069s is the replaceable String", ""), 3892e5b6d6dSopenharmony_ci "21", "23", UnicodeString("Th\\u0069s is the repl\\u0061\\u0063eable String", ""), 3902e5b6d6dSopenharmony_ci "14", "17", UnicodeString("Th\\u0069s is t\\u0068\\u0065\\u0020repl\\u0061\\u0063eable String", ""), 3912e5b6d6dSopenharmony_ci }; 3922e5b6d6dSopenharmony_ci int start, limit; 3932e5b6d6dSopenharmony_ci UnicodeString message; 3942e5b6d6dSopenharmony_ci UParseError parseError; 3952e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 3962e5b6d6dSopenharmony_ci Transliterator *t=Transliterator::createInstance("Any-Hex", UTRANS_FORWARD, parseError, status); 3972e5b6d6dSopenharmony_ci if(U_FAILURE(status)) { 3982e5b6d6dSopenharmony_ci errln("Error creating transliterator %s", u_errorName(status)); 3992e5b6d6dSopenharmony_ci delete t; 4002e5b6d6dSopenharmony_ci return; 4012e5b6d6dSopenharmony_ci } 4022e5b6d6dSopenharmony_ci 4032e5b6d6dSopenharmony_ci if(t == 0) 4042e5b6d6dSopenharmony_ci errln("FAIL : construction"); 4052e5b6d6dSopenharmony_ci for(uint32_t i=0; i<UPRV_LENGTHOF(Data); i=i+3){ 4062e5b6d6dSopenharmony_ci start=getInt(Data[i+0]); 4072e5b6d6dSopenharmony_ci limit=getInt(Data[i+1]); 4082e5b6d6dSopenharmony_ci t->transliterate(rs, start, limit); 4092e5b6d6dSopenharmony_ci message=t->getID() + ".transliterate(ReplaceableString, start, limit):("+start+","+limit+"):"; 4102e5b6d6dSopenharmony_ci doTest(message, rs, Data[i+2]); 4112e5b6d6dSopenharmony_ci } 4122e5b6d6dSopenharmony_ci delete t; 4132e5b6d6dSopenharmony_ci} 4142e5b6d6dSopenharmony_ci 4152e5b6d6dSopenharmony_civoid TransliteratorAPITest::TestSimpleKeyboardTransliterator(){ 4162e5b6d6dSopenharmony_ci logln("simple call to transliterate"); 4172e5b6d6dSopenharmony_ci UErrorCode status=U_ZERO_ERROR; 4182e5b6d6dSopenharmony_ci UParseError parseError; 4192e5b6d6dSopenharmony_ci Transliterator* t=Transliterator::createInstance("Any-Hex", UTRANS_FORWARD, parseError, status); 4202e5b6d6dSopenharmony_ci if(t == 0) { 4212e5b6d6dSopenharmony_ci UnicodeString context; 4222e5b6d6dSopenharmony_ci 4232e5b6d6dSopenharmony_ci if (parseError.preContext[0]) { 4242e5b6d6dSopenharmony_ci context += (UnicodeString)" at " + parseError.preContext; 4252e5b6d6dSopenharmony_ci } 4262e5b6d6dSopenharmony_ci if (parseError.postContext[0]) { 4272e5b6d6dSopenharmony_ci context += (UnicodeString)" | " + parseError.postContext; 4282e5b6d6dSopenharmony_ci } 4292e5b6d6dSopenharmony_ci errln((UnicodeString)"FAIL: can't create Any-Hex, " + 4302e5b6d6dSopenharmony_ci (UnicodeString)u_errorName(status) + context); 4312e5b6d6dSopenharmony_ci return; 4322e5b6d6dSopenharmony_ci } 4332e5b6d6dSopenharmony_ci UTransPosition index={19,20,20,20}; 4342e5b6d6dSopenharmony_ci UnicodeString rs= "Transliterate this-''"; 4352e5b6d6dSopenharmony_ci UnicodeString insertion="abc"; 4362e5b6d6dSopenharmony_ci UnicodeString expected=UnicodeString("Transliterate this-'\\u0061\\u0062\\u0063'", ""); 4372e5b6d6dSopenharmony_ci t->transliterate(rs, index, insertion, status); 4382e5b6d6dSopenharmony_ci if(U_FAILURE(status)) 4392e5b6d6dSopenharmony_ci errln("FAIL: " + t->getID()+ ".translitere(Replaceable, int[], UnicodeString, UErrorCode)-->" + (UnicodeString)u_errorName(status)); 4402e5b6d6dSopenharmony_ci t->finishTransliteration(rs, index); 4412e5b6d6dSopenharmony_ci UnicodeString message="transliterate"; 4422e5b6d6dSopenharmony_ci doTest(message, rs, expected); 4432e5b6d6dSopenharmony_ci 4442e5b6d6dSopenharmony_ci logln("try calling transliterate with invalid index values"); 4452e5b6d6dSopenharmony_ci UTransPosition index1[]={ 4462e5b6d6dSopenharmony_ci //START, LIMIT, CURSOR 4472e5b6d6dSopenharmony_ci {10, 10, 12, 10}, //invalid since CURSOR>LIMIT valid:-START <= CURSOR <= LIMIT 4482e5b6d6dSopenharmony_ci {17, 16, 17, 17}, //invalid since START>LIMIT valid:-0<=START<=LIMIT 4492e5b6d6dSopenharmony_ci {-1, 16, 14, 16}, //invalid since START<0 4502e5b6d6dSopenharmony_ci {3, 50, 2, 50} //invalid since LIMIT>text.length() 4512e5b6d6dSopenharmony_ci }; 4522e5b6d6dSopenharmony_ci for(uint32_t i=0; i<UPRV_LENGTHOF(index1); i++){ 4532e5b6d6dSopenharmony_ci status=U_ZERO_ERROR; 4542e5b6d6dSopenharmony_ci t->transliterate(rs, index1[i], insertion, status); 4552e5b6d6dSopenharmony_ci if(status == U_ILLEGAL_ARGUMENT_ERROR) 4562e5b6d6dSopenharmony_ci logln("OK: invalid index values handled correctly"); 4572e5b6d6dSopenharmony_ci else 4582e5b6d6dSopenharmony_ci errln("FAIL: invalid index values didn't throw U_ILLEGAL_ARGUMENT_ERROR throw" + (UnicodeString)u_errorName(status)); 4592e5b6d6dSopenharmony_ci } 4602e5b6d6dSopenharmony_ci 4612e5b6d6dSopenharmony_ci delete t; 4622e5b6d6dSopenharmony_ci} 4632e5b6d6dSopenharmony_civoid TransliteratorAPITest::TestKeyboardTransliterator1(){ 4642e5b6d6dSopenharmony_ci UnicodeString Data[]={ 4652e5b6d6dSopenharmony_ci //insertion, buffer 4662e5b6d6dSopenharmony_ci "a", UnicodeString("\\u0061", "") , 4672e5b6d6dSopenharmony_ci "bbb", UnicodeString("\\u0061\\u0062\\u0062\\u0062", "") , 4682e5b6d6dSopenharmony_ci "ca", UnicodeString("\\u0061\\u0062\\u0062\\u0062\\u0063\\u0061", "") , 4692e5b6d6dSopenharmony_ci " ", UnicodeString("\\u0061\\u0062\\u0062\\u0062\\u0063\\u0061\\u0020", "") , 4702e5b6d6dSopenharmony_ci "", UnicodeString("\\u0061\\u0062\\u0062\\u0062\\u0063\\u0061\\u0020", "") , 4712e5b6d6dSopenharmony_ci 4722e5b6d6dSopenharmony_ci "a", UnicodeString("\\u0061", "") , 4732e5b6d6dSopenharmony_ci "b", UnicodeString("\\u0061\\u0062", "") , 4742e5b6d6dSopenharmony_ci "z", UnicodeString("\\u0061\\u0062\\u007A", "") , 4752e5b6d6dSopenharmony_ci "", UnicodeString("\\u0061\\u0062\\u007A", "") 4762e5b6d6dSopenharmony_ci 4772e5b6d6dSopenharmony_ci }; 4782e5b6d6dSopenharmony_ci UParseError parseError; 4792e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 4802e5b6d6dSopenharmony_ci Transliterator* t=Transliterator::createInstance("Any-Hex", UTRANS_FORWARD, parseError, status); 4812e5b6d6dSopenharmony_ci if(U_FAILURE(status)) { 4822e5b6d6dSopenharmony_ci errln("Error creating transliterator %s", u_errorName(status)); 4832e5b6d6dSopenharmony_ci delete t; 4842e5b6d6dSopenharmony_ci return; 4852e5b6d6dSopenharmony_ci } 4862e5b6d6dSopenharmony_ci //keyboardAux(t, Data); 4872e5b6d6dSopenharmony_ci UTransPosition index={0, 0, 0, 0}; 4882e5b6d6dSopenharmony_ci UnicodeString s; 4892e5b6d6dSopenharmony_ci uint32_t i; 4902e5b6d6dSopenharmony_ci logln("Testing transliterate(Replaceable, int32_t, UnicodeString, UErrorCode)"); 4912e5b6d6dSopenharmony_ci for (i=0; i<10; i=i+2) { 4922e5b6d6dSopenharmony_ci UnicodeString log; 4932e5b6d6dSopenharmony_ci if (Data[i+0] != "") { 4942e5b6d6dSopenharmony_ci log = s + " + " + Data[i+0] + " -> "; 4952e5b6d6dSopenharmony_ci t->transliterate(s, index, Data[i+0], status); 4962e5b6d6dSopenharmony_ci if(U_FAILURE(status)){ 4972e5b6d6dSopenharmony_ci errln("FAIL: " + t->getID()+ ".transliterate(Replaceable, int32_t[], UnicodeString, UErrorCode)-->" + (UnicodeString)u_errorName(status)); 4982e5b6d6dSopenharmony_ci continue; 4992e5b6d6dSopenharmony_ci } 5002e5b6d6dSopenharmony_ci }else { 5012e5b6d6dSopenharmony_ci log = s + " => "; 5022e5b6d6dSopenharmony_ci t->finishTransliteration(s, index); 5032e5b6d6dSopenharmony_ci } 5042e5b6d6dSopenharmony_ci // Show the start index '{' and the cursor '|' 5052e5b6d6dSopenharmony_ci displayOutput(s, Data[i+1], log, index); 5062e5b6d6dSopenharmony_ci 5072e5b6d6dSopenharmony_ci } 5082e5b6d6dSopenharmony_ci 5092e5b6d6dSopenharmony_ci s=""; 5102e5b6d6dSopenharmony_ci status=U_ZERO_ERROR; 5112e5b6d6dSopenharmony_ci index.contextStart = index.contextLimit = index.start = index.limit = 0; 5122e5b6d6dSopenharmony_ci logln("Testing transliterate(Replaceable, int32_t, UChar, UErrorCode)"); 5132e5b6d6dSopenharmony_ci for(i=10; i<UPRV_LENGTHOF(Data); i=i+2){ 5142e5b6d6dSopenharmony_ci UnicodeString log; 5152e5b6d6dSopenharmony_ci if (Data[i+0] != "") { 5162e5b6d6dSopenharmony_ci log = s + " + " + Data[i+0] + " -> "; 5172e5b6d6dSopenharmony_ci UChar c=Data[i+0].charAt(0); 5182e5b6d6dSopenharmony_ci t->transliterate(s, index, c, status); 5192e5b6d6dSopenharmony_ci if(U_FAILURE(status)) { 5202e5b6d6dSopenharmony_ci errln("FAIL: " + t->getID()+ ".transliterate(Replaceable, int32_t[], UChar, UErrorCode)-->" + (UnicodeString)u_errorName(status)); 5212e5b6d6dSopenharmony_ci continue; 5222e5b6d6dSopenharmony_ci } 5232e5b6d6dSopenharmony_ci } else { 5242e5b6d6dSopenharmony_ci log = s + " => "; 5252e5b6d6dSopenharmony_ci t->finishTransliteration(s, index); 5262e5b6d6dSopenharmony_ci } 5272e5b6d6dSopenharmony_ci // Show the start index '{' and the cursor '|' 5282e5b6d6dSopenharmony_ci displayOutput(s, Data[i+1], log, index); 5292e5b6d6dSopenharmony_ci } 5302e5b6d6dSopenharmony_ci 5312e5b6d6dSopenharmony_ci delete t; 5322e5b6d6dSopenharmony_ci} 5332e5b6d6dSopenharmony_ci 5342e5b6d6dSopenharmony_civoid TransliteratorAPITest::TestKeyboardTransliterator2(){ 5352e5b6d6dSopenharmony_ci UnicodeString Data[]={ 5362e5b6d6dSopenharmony_ci //insertion, buffer, index[START], index[LIMIT], index[CURSOR] 5372e5b6d6dSopenharmony_ci //data for Any-Hex 5382e5b6d6dSopenharmony_ci "abc", UnicodeString("Initial String: add-\\u0061\\u0062\\u0063-", ""), "19", "20", "20", 5392e5b6d6dSopenharmony_ci "a", UnicodeString("In\\u0069\\u0061tial String: add-\\u0061\\u0062\\u0063-", ""), "2", "3", "2" , 5402e5b6d6dSopenharmony_ci "b", UnicodeString("\\u0062In\\u0069\\u0061tial String: add-\\u0061\\u0062\\u0063-", ""), "0", "0", "0" , 5412e5b6d6dSopenharmony_ci "", UnicodeString("\\u0062In\\u0069\\u0061tial String: add-\\u0061\\u0062\\u0063-", ""), "0", "0", "0" , 5422e5b6d6dSopenharmony_ci //data for Latin-Devanagiri 5432e5b6d6dSopenharmony_ci CharsToUnicodeString("a\\u0304"), CharsToUnicodeString("Hindi -\\u0906-"), "6", "7", "6", 5442e5b6d6dSopenharmony_ci CharsToUnicodeString("ma\\u0304"), CharsToUnicodeString("Hindi -\\u0906\\u092E\\u093E-"), "7", "8", "7", 5452e5b6d6dSopenharmony_ci CharsToUnicodeString("ra\\u0304"), CharsToUnicodeString("Hi\\u0930\\u093Endi -\\u0906\\u092E\\u093E-"),"1", "2", "2", 5462e5b6d6dSopenharmony_ci CharsToUnicodeString(""), CharsToUnicodeString("Hi\\u0930\\u093Endi -\\u0906\\u092E\\u093E-"),"1", "2", "2" 5472e5b6d6dSopenharmony_ci //data for contracted-Expanded 5482e5b6d6dSopenharmony_ci // CharsToUnicodeString("\\u00C1"), CharsToUnicodeString("Ad\\u0041\\u0301d here:"), "1", "2", "1" , 5492e5b6d6dSopenharmony_ci // CharsToUnicodeString("\\u00C0"), CharsToUnicodeString("Ad\\u0041\\u0301d here:\\u0041\\u0300"), "11", "11", "11", 5502e5b6d6dSopenharmony_ci // "", CharsToUnicodeString("Ad\\u0041\\u0301d here:\\u0041\\u0300"), "11", "11", "11", 5512e5b6d6dSopenharmony_ci }; 5522e5b6d6dSopenharmony_ci Transliterator *t; 5532e5b6d6dSopenharmony_ci UnicodeString rs; 5542e5b6d6dSopenharmony_ci UnicodeString dataStr; 5552e5b6d6dSopenharmony_ci logln("Testing transliterate(Replaceable, int32_t, UnicodeString, UErrorCode)"); 5562e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 5572e5b6d6dSopenharmony_ci UParseError parseError; 5582e5b6d6dSopenharmony_ci rs="Initial String: add--"; 5592e5b6d6dSopenharmony_ci t=Transliterator::createInstance("Any-Hex", UTRANS_FORWARD, parseError, status); 5602e5b6d6dSopenharmony_ci if(t == 0) 5612e5b6d6dSopenharmony_ci dataerrln("FAIL : construction - %s", u_errorName(status)); 5622e5b6d6dSopenharmony_ci else { 5632e5b6d6dSopenharmony_ci keyboardAux(t, Data, rs, 0, 20); 5642e5b6d6dSopenharmony_ci delete t; 5652e5b6d6dSopenharmony_ci } 5662e5b6d6dSopenharmony_ci 5672e5b6d6dSopenharmony_ci rs="Hindi --"; 5682e5b6d6dSopenharmony_ci t=Transliterator::createInstance("Latin-Devanagari", UTRANS_FORWARD, parseError, status); 5692e5b6d6dSopenharmony_ci if(t == 0) 5702e5b6d6dSopenharmony_ci dataerrln("FAIL : construction - %s", u_errorName(status)); 5712e5b6d6dSopenharmony_ci else 5722e5b6d6dSopenharmony_ci keyboardAux(t, Data, rs, 20, 40); 5732e5b6d6dSopenharmony_ci 5742e5b6d6dSopenharmony_ci 5752e5b6d6dSopenharmony_ci // rs="Add here:"; 5762e5b6d6dSopenharmony_ci // t=Transliterator::createInstance("Contracted-Expanded"); 5772e5b6d6dSopenharmony_ci // keyboardAux(t, Data, rs, 35, 55); 5782e5b6d6dSopenharmony_ci 5792e5b6d6dSopenharmony_ci 5802e5b6d6dSopenharmony_ci delete t; 5812e5b6d6dSopenharmony_ci} 5822e5b6d6dSopenharmony_ci 5832e5b6d6dSopenharmony_civoid TransliteratorAPITest::TestKeyboardTransliterator3(){ 5842e5b6d6dSopenharmony_ci UnicodeString s="This is the main string"; 5852e5b6d6dSopenharmony_ci UnicodeString Data[] = { 5862e5b6d6dSopenharmony_ci "0", "0", "0", "This is the main string", 5872e5b6d6dSopenharmony_ci "1", "3", "2", UnicodeString("Th\\u0069s is the main string", ""), 5882e5b6d6dSopenharmony_ci "20", "21", "20", UnicodeString("Th\\u0069s is the mai\\u006E string", "") 5892e5b6d6dSopenharmony_ci }; 5902e5b6d6dSopenharmony_ci 5912e5b6d6dSopenharmony_ci UErrorCode status=U_ZERO_ERROR; 5922e5b6d6dSopenharmony_ci UParseError parseError; 5932e5b6d6dSopenharmony_ci UTransPosition index={0, 0, 0, 0}; 5942e5b6d6dSopenharmony_ci logln("Testing transliterate(Replaceable, int32_t, UErrorCode)"); 5952e5b6d6dSopenharmony_ci Transliterator *t=Transliterator::createInstance("Any-Hex", UTRANS_FORWARD, parseError, status); 5962e5b6d6dSopenharmony_ci if(t == 0 || U_FAILURE(status)) { 5972e5b6d6dSopenharmony_ci errln("Error creating transliterator %s", u_errorName(status)); 5982e5b6d6dSopenharmony_ci delete t; 5992e5b6d6dSopenharmony_ci return; 6002e5b6d6dSopenharmony_ci } 6012e5b6d6dSopenharmony_ci for(uint32_t i=0; i<UPRV_LENGTHOF(Data); i=i+4){ 6022e5b6d6dSopenharmony_ci UnicodeString log; 6032e5b6d6dSopenharmony_ci index.contextStart=getInt(Data[i+0]); 6042e5b6d6dSopenharmony_ci index.contextLimit=index.limit=getInt(Data[i+1]); 6052e5b6d6dSopenharmony_ci index.start=getInt(Data[i+2]); 6062e5b6d6dSopenharmony_ci t->transliterate(s, index, status); 6072e5b6d6dSopenharmony_ci if(U_FAILURE(status)){ 6082e5b6d6dSopenharmony_ci errln("FAIL: " + t->getID()+ ".transliterate(Replaceable, int32_t[], UErrorCode)-->" + (UnicodeString)u_errorName(status)); 6092e5b6d6dSopenharmony_ci continue; 6102e5b6d6dSopenharmony_ci } 6112e5b6d6dSopenharmony_ci t->finishTransliteration(s, index); 6122e5b6d6dSopenharmony_ci log = s + " => "; 6132e5b6d6dSopenharmony_ci // Show the start index '{' and the cursor '|' 6142e5b6d6dSopenharmony_ci displayOutput(s, Data[i+3], log, index); 6152e5b6d6dSopenharmony_ci } 6162e5b6d6dSopenharmony_ci 6172e5b6d6dSopenharmony_ci delete t; 6182e5b6d6dSopenharmony_ci} 6192e5b6d6dSopenharmony_civoid TransliteratorAPITest::TestNullTransliterator(){ 6202e5b6d6dSopenharmony_ci UErrorCode status=U_ZERO_ERROR; 6212e5b6d6dSopenharmony_ci UnicodeString s("Transliterate using null transliterator"); 6222e5b6d6dSopenharmony_ci Transliterator *nullTrans=Transliterator::createInstance("Any-Null", UTRANS_FORWARD, status); 6232e5b6d6dSopenharmony_ci if (!assertSuccess(WHERE, status)) { 6242e5b6d6dSopenharmony_ci return; 6252e5b6d6dSopenharmony_ci } 6262e5b6d6dSopenharmony_ci int32_t transLimit; 6272e5b6d6dSopenharmony_ci int32_t start=0; 6282e5b6d6dSopenharmony_ci int32_t limit=s.length(); 6292e5b6d6dSopenharmony_ci UnicodeString replaceable=s; 6302e5b6d6dSopenharmony_ci transLimit=nullTrans->transliterate(replaceable, start, limit); 6312e5b6d6dSopenharmony_ci if(transLimit != limit){ 6322e5b6d6dSopenharmony_ci errln("ERROR: NullTransliterator->transliterate() failed"); 6332e5b6d6dSopenharmony_ci } 6342e5b6d6dSopenharmony_ci doTest((UnicodeString)"nulTrans->transliterate", replaceable, s); 6352e5b6d6dSopenharmony_ci replaceable.remove(); 6362e5b6d6dSopenharmony_ci replaceable.append(s); 6372e5b6d6dSopenharmony_ci UTransPosition index; 6382e5b6d6dSopenharmony_ci index.contextStart =start; 6392e5b6d6dSopenharmony_ci index.contextLimit = limit; 6402e5b6d6dSopenharmony_ci index.start = 0; 6412e5b6d6dSopenharmony_ci index.limit = limit; 6422e5b6d6dSopenharmony_ci nullTrans->finishTransliteration(replaceable, index); 6432e5b6d6dSopenharmony_ci if(index.start != limit){ 6442e5b6d6dSopenharmony_ci errln("ERROR: NullTransliterator->handleTransliterate() failed"); 6452e5b6d6dSopenharmony_ci } 6462e5b6d6dSopenharmony_ci doTest((UnicodeString)"NullTransliterator->handleTransliterate", replaceable, s); 6472e5b6d6dSopenharmony_ci callEverything(nullTrans, __LINE__); 6482e5b6d6dSopenharmony_ci delete nullTrans; 6492e5b6d6dSopenharmony_ci 6502e5b6d6dSopenharmony_ci 6512e5b6d6dSopenharmony_ci} 6522e5b6d6dSopenharmony_civoid TransliteratorAPITest::TestRegisterUnregister(){ 6532e5b6d6dSopenharmony_ci 6542e5b6d6dSopenharmony_ci UErrorCode status=U_ZERO_ERROR; 6552e5b6d6dSopenharmony_ci /* Make sure it doesn't exist */ 6562e5b6d6dSopenharmony_ci if (Transliterator::createInstance("TestA-TestB", UTRANS_FORWARD, status) != NULL) { 6572e5b6d6dSopenharmony_ci errln("FAIL: TestA-TestB already registered\n"); 6582e5b6d6dSopenharmony_ci return; 6592e5b6d6dSopenharmony_ci } 6602e5b6d6dSopenharmony_ci /* Check inverse too 6612e5b6d6dSopenharmony_ci if (Transliterator::createInstance("TestA-TestB", 6622e5b6d6dSopenharmony_ci (UTransDirection)UTRANS_REVERSE) != NULL) { 6632e5b6d6dSopenharmony_ci errln("FAIL: TestA-TestB inverse already registered\n"); 6642e5b6d6dSopenharmony_ci return; 6652e5b6d6dSopenharmony_ci } 6662e5b6d6dSopenharmony_ci */ 6672e5b6d6dSopenharmony_ci status =U_ZERO_ERROR; 6682e5b6d6dSopenharmony_ci 6692e5b6d6dSopenharmony_ci /* Create it */ 6702e5b6d6dSopenharmony_ci UParseError parseError; 6712e5b6d6dSopenharmony_ci Transliterator *t = Transliterator::createFromRules("TestA-TestB", 6722e5b6d6dSopenharmony_ci "a<>b", 6732e5b6d6dSopenharmony_ci UTRANS_FORWARD, parseError, 6742e5b6d6dSopenharmony_ci status); 6752e5b6d6dSopenharmony_ci /* Register it */ 6762e5b6d6dSopenharmony_ci Transliterator::registerInstance(t); 6772e5b6d6dSopenharmony_ci 6782e5b6d6dSopenharmony_ci /* Now check again -- should exist now*/ 6792e5b6d6dSopenharmony_ci Transliterator *s = Transliterator::createInstance("TestA-TestB", UTRANS_FORWARD, status); 6802e5b6d6dSopenharmony_ci if (s == NULL) { 6812e5b6d6dSopenharmony_ci errln("FAIL: TestA-TestB not registered\n"); 6822e5b6d6dSopenharmony_ci return; 6832e5b6d6dSopenharmony_ci } 6842e5b6d6dSopenharmony_ci callEverything(s, __LINE__); 6852e5b6d6dSopenharmony_ci callEverything(t, __LINE__); 6862e5b6d6dSopenharmony_ci delete s; 6872e5b6d6dSopenharmony_ci 6882e5b6d6dSopenharmony_ci /* Check inverse too 6892e5b6d6dSopenharmony_ci s = Transliterator::createInstance("TestA-TestB", 6902e5b6d6dSopenharmony_ci (UTransDirection)UTRANS_REVERSE); 6912e5b6d6dSopenharmony_ci if (s == NULL) { 6922e5b6d6dSopenharmony_ci errln("FAIL: TestA-TestB inverse not registered\n"); 6932e5b6d6dSopenharmony_ci return; 6942e5b6d6dSopenharmony_ci } 6952e5b6d6dSopenharmony_ci delete s; 6962e5b6d6dSopenharmony_ci */ 6972e5b6d6dSopenharmony_ci 6982e5b6d6dSopenharmony_ci /*unregister the instance*/ 6992e5b6d6dSopenharmony_ci Transliterator::unregister("TestA-TestB"); 7002e5b6d6dSopenharmony_ci /* now Make sure it doesn't exist */ 7012e5b6d6dSopenharmony_ci if (Transliterator::createInstance("TestA-TestB", UTRANS_FORWARD, status) != NULL) { 7022e5b6d6dSopenharmony_ci errln("FAIL: TestA-TestB isn't unregistered\n"); 7032e5b6d6dSopenharmony_ci return; 7042e5b6d6dSopenharmony_ci } 7052e5b6d6dSopenharmony_ci 7062e5b6d6dSopenharmony_ci} 7072e5b6d6dSopenharmony_ci 7082e5b6d6dSopenharmony_ci 7092e5b6d6dSopenharmony_ciint gTestFilter1ClassID = 0; 7102e5b6d6dSopenharmony_ciint gTestFilter2ClassID = 0; 7112e5b6d6dSopenharmony_ciint gTestFilter3ClassID = 0; 7122e5b6d6dSopenharmony_ci 7132e5b6d6dSopenharmony_ci/** 7142e5b6d6dSopenharmony_ci * Used by TestFiltering(). 7152e5b6d6dSopenharmony_ci */ 7162e5b6d6dSopenharmony_ciclass TestFilter1 : public UnicodeFilter { 7172e5b6d6dSopenharmony_ci UClassID getDynamicClassID()const override { return &gTestFilter1ClassID; } 7182e5b6d6dSopenharmony_ci virtual TestFilter1* clone() const override { 7192e5b6d6dSopenharmony_ci return new TestFilter1(*this); 7202e5b6d6dSopenharmony_ci } 7212e5b6d6dSopenharmony_ci virtual UBool contains(UChar32 c) const override { 7222e5b6d6dSopenharmony_ci if(c==0x63 || c==0x61 || c==0x43 || c==0x41) 7232e5b6d6dSopenharmony_ci return false; 7242e5b6d6dSopenharmony_ci else 7252e5b6d6dSopenharmony_ci return true; 7262e5b6d6dSopenharmony_ci } 7272e5b6d6dSopenharmony_ci // Stubs 7282e5b6d6dSopenharmony_ci virtual UnicodeString& toPattern(UnicodeString& result, 7292e5b6d6dSopenharmony_ci UBool /*escapeUnprintable*/) const override { 7302e5b6d6dSopenharmony_ci return result; 7312e5b6d6dSopenharmony_ci } 7322e5b6d6dSopenharmony_ci virtual UBool matchesIndexValue(uint8_t /*v*/) const override { 7332e5b6d6dSopenharmony_ci return false; 7342e5b6d6dSopenharmony_ci } 7352e5b6d6dSopenharmony_ci virtual void addMatchSetTo(UnicodeSet& /*toUnionTo*/) const override {} 7362e5b6d6dSopenharmony_ci}; 7372e5b6d6dSopenharmony_ciclass TestFilter2 : public UnicodeFilter { 7382e5b6d6dSopenharmony_ci UClassID getDynamicClassID() const override { return &gTestFilter2ClassID; } 7392e5b6d6dSopenharmony_ci virtual TestFilter2* clone() const override { 7402e5b6d6dSopenharmony_ci return new TestFilter2(*this); 7412e5b6d6dSopenharmony_ci } 7422e5b6d6dSopenharmony_ci virtual UBool contains(UChar32 c) const override { 7432e5b6d6dSopenharmony_ci if(c==0x65 || c==0x6c) 7442e5b6d6dSopenharmony_ci return false; 7452e5b6d6dSopenharmony_ci else 7462e5b6d6dSopenharmony_ci return true; 7472e5b6d6dSopenharmony_ci } 7482e5b6d6dSopenharmony_ci // Stubs 7492e5b6d6dSopenharmony_ci virtual UnicodeString& toPattern(UnicodeString& result, 7502e5b6d6dSopenharmony_ci UBool /*escapeUnprintable*/) const override { 7512e5b6d6dSopenharmony_ci return result; 7522e5b6d6dSopenharmony_ci } 7532e5b6d6dSopenharmony_ci virtual UBool matchesIndexValue(uint8_t /*v*/) const override { 7542e5b6d6dSopenharmony_ci return false; 7552e5b6d6dSopenharmony_ci } 7562e5b6d6dSopenharmony_ci virtual void addMatchSetTo(UnicodeSet& /*toUnionTo*/) const override {} 7572e5b6d6dSopenharmony_ci}; 7582e5b6d6dSopenharmony_ciclass TestFilter3 : public UnicodeFilter { 7592e5b6d6dSopenharmony_ci UClassID getDynamicClassID() const override { return &gTestFilter3ClassID; } 7602e5b6d6dSopenharmony_ci virtual TestFilter3* clone() const override { 7612e5b6d6dSopenharmony_ci return new TestFilter3(*this); 7622e5b6d6dSopenharmony_ci } 7632e5b6d6dSopenharmony_ci virtual UBool contains(UChar32 c) const override { 7642e5b6d6dSopenharmony_ci if(c==0x6f || c==0x77) 7652e5b6d6dSopenharmony_ci return false; 7662e5b6d6dSopenharmony_ci else 7672e5b6d6dSopenharmony_ci return true; 7682e5b6d6dSopenharmony_ci } 7692e5b6d6dSopenharmony_ci // Stubs 7702e5b6d6dSopenharmony_ci virtual UnicodeString& toPattern(UnicodeString& result, 7712e5b6d6dSopenharmony_ci UBool /*escapeUnprintable*/) const override { 7722e5b6d6dSopenharmony_ci return result; 7732e5b6d6dSopenharmony_ci } 7742e5b6d6dSopenharmony_ci virtual UBool matchesIndexValue(uint8_t /*v*/) const override { 7752e5b6d6dSopenharmony_ci return false; 7762e5b6d6dSopenharmony_ci } 7772e5b6d6dSopenharmony_ci virtual void addMatchSetTo(UnicodeSet& /*toUnionTo*/) const override {} 7782e5b6d6dSopenharmony_ci}; 7792e5b6d6dSopenharmony_ci 7802e5b6d6dSopenharmony_ci 7812e5b6d6dSopenharmony_civoid TransliteratorAPITest::TestGetAdoptFilter(){ 7822e5b6d6dSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 7832e5b6d6dSopenharmony_ci UParseError parseError; 7842e5b6d6dSopenharmony_ci Transliterator *t=Transliterator::createInstance("Any-Hex", UTRANS_FORWARD, parseError, status); 7852e5b6d6dSopenharmony_ci if(t == 0 || U_FAILURE(status)) { 7862e5b6d6dSopenharmony_ci errln("Error creating transliterator %s", u_errorName(status)); 7872e5b6d6dSopenharmony_ci delete t; 7882e5b6d6dSopenharmony_ci return; 7892e5b6d6dSopenharmony_ci } 7902e5b6d6dSopenharmony_ci const UnicodeFilter *u=t->getFilter(); 7912e5b6d6dSopenharmony_ci if(u != NULL){ 7922e5b6d6dSopenharmony_ci errln("FAIL: getFilter failed. Didn't return null when the transliterator used no filtering"); 7932e5b6d6dSopenharmony_ci delete t; 7942e5b6d6dSopenharmony_ci return; 7952e5b6d6dSopenharmony_ci } 7962e5b6d6dSopenharmony_ci 7972e5b6d6dSopenharmony_ci UnicodeString got, temp, message; 7982e5b6d6dSopenharmony_ci UnicodeString data="ABCabcbbCBa"; 7992e5b6d6dSopenharmony_ci temp = data; 8002e5b6d6dSopenharmony_ci t->transliterate(temp); 8012e5b6d6dSopenharmony_ci t->adoptFilter(new TestFilter1); 8022e5b6d6dSopenharmony_ci 8032e5b6d6dSopenharmony_ci got = data; 8042e5b6d6dSopenharmony_ci t->transliterate(got); 8052e5b6d6dSopenharmony_ci UnicodeString exp=UnicodeString("A\\u0042Ca\\u0062c\\u0062\\u0062C\\u0042a", ""); 8062e5b6d6dSopenharmony_ci message="transliteration after adoptFilter(a,A,c,C) "; 8072e5b6d6dSopenharmony_ci doTest(message, got, exp); 8082e5b6d6dSopenharmony_ci 8092e5b6d6dSopenharmony_ci logln("Testing round trip"); 8102e5b6d6dSopenharmony_ci t->adoptFilter((UnicodeFilter*)u); 8112e5b6d6dSopenharmony_ci if(t->getFilter() == NULL) 8122e5b6d6dSopenharmony_ci logln("OK: adoptFilter and getFilter round trip worked"); 8132e5b6d6dSopenharmony_ci else 8142e5b6d6dSopenharmony_ci errln("FAIL: adoptFilter or getFilter round trip failed"); 8152e5b6d6dSopenharmony_ci 8162e5b6d6dSopenharmony_ci got = data; 8172e5b6d6dSopenharmony_ci t->transliterate(got); 8182e5b6d6dSopenharmony_ci exp=UnicodeString("\\u0041\\u0042\\u0043\\u0061\\u0062\\u0063\\u0062\\u0062\\u0043\\u0042\\u0061", ""); 8192e5b6d6dSopenharmony_ci message="transliteration after adopting null filter"; 8202e5b6d6dSopenharmony_ci doTest(message, got, exp); 8212e5b6d6dSopenharmony_ci message="adoptFilter round trip"; 8222e5b6d6dSopenharmony_ci doTest("adoptFilter round trip", got, temp); 8232e5b6d6dSopenharmony_ci 8242e5b6d6dSopenharmony_ci t->adoptFilter(new TestFilter2); 8252e5b6d6dSopenharmony_ci callEverything(t, __LINE__); 8262e5b6d6dSopenharmony_ci data="heelloe"; 8272e5b6d6dSopenharmony_ci exp=UnicodeString("\\u0068eell\\u006Fe", ""); 8282e5b6d6dSopenharmony_ci got = data; 8292e5b6d6dSopenharmony_ci t->transliterate(got); 8302e5b6d6dSopenharmony_ci message="transliteration using (e,l) filter"; 8312e5b6d6dSopenharmony_ci doTest("transliteration using (e,l) filter", got, exp); 8322e5b6d6dSopenharmony_ci 8332e5b6d6dSopenharmony_ci data="are well"; 8342e5b6d6dSopenharmony_ci exp=UnicodeString("\\u0061\\u0072e\\u0020\\u0077ell", ""); 8352e5b6d6dSopenharmony_ci got = data; 8362e5b6d6dSopenharmony_ci t->transliterate(got); 8372e5b6d6dSopenharmony_ci doTest(message, got, exp); 8382e5b6d6dSopenharmony_ci 8392e5b6d6dSopenharmony_ci t->adoptFilter(new TestFilter3); 8402e5b6d6dSopenharmony_ci data="ho, wow!"; 8412e5b6d6dSopenharmony_ci exp=UnicodeString("\\u0068o\\u002C\\u0020wow\\u0021", ""); 8422e5b6d6dSopenharmony_ci got = data; 8432e5b6d6dSopenharmony_ci t->transliterate(got); 8442e5b6d6dSopenharmony_ci message="transliteration using (o,w) filter"; 8452e5b6d6dSopenharmony_ci doTest("transliteration using (o,w) filter", got, exp); 8462e5b6d6dSopenharmony_ci 8472e5b6d6dSopenharmony_ci data="owl"; 8482e5b6d6dSopenharmony_ci exp=UnicodeString("ow\\u006C", ""); 8492e5b6d6dSopenharmony_ci got = data; 8502e5b6d6dSopenharmony_ci t->transliterate(got); 8512e5b6d6dSopenharmony_ci doTest("transliteration using (o,w) filter", got, exp); 8522e5b6d6dSopenharmony_ci 8532e5b6d6dSopenharmony_ci delete t; 8542e5b6d6dSopenharmony_ci 8552e5b6d6dSopenharmony_ci} 8562e5b6d6dSopenharmony_ci 8572e5b6d6dSopenharmony_ci 8582e5b6d6dSopenharmony_ci 8592e5b6d6dSopenharmony_civoid TransliteratorAPITest::keyboardAux(Transliterator *t, UnicodeString DATA[], UnicodeString& s, int32_t begin, int32_t end) { 8602e5b6d6dSopenharmony_ci UTransPosition index={0, 0, 0, 0}; 8612e5b6d6dSopenharmony_ci UErrorCode status=U_ZERO_ERROR; 8622e5b6d6dSopenharmony_ci for (int32_t i=begin; i<end; i=i+5) { 8632e5b6d6dSopenharmony_ci UnicodeString log; 8642e5b6d6dSopenharmony_ci if (DATA[i+0] != "") { 8652e5b6d6dSopenharmony_ci log = s + " + " + DATA[i] + " -> "; 8662e5b6d6dSopenharmony_ci index.contextStart=getInt(DATA[i+2]); 8672e5b6d6dSopenharmony_ci index.contextLimit=index.limit=getInt(DATA[i+3]); 8682e5b6d6dSopenharmony_ci index.start=getInt(DATA[i+4]); 8692e5b6d6dSopenharmony_ci t->transliterate(s, index, DATA[i+0], status); 8702e5b6d6dSopenharmony_ci if(U_FAILURE(status)){ 8712e5b6d6dSopenharmony_ci errln("FAIL: " + t->getID()+ ".transliterate(Replaceable, int32_t[], UnicodeString, UErrorCode)-->" + (UnicodeString)u_errorName(status)); 8722e5b6d6dSopenharmony_ci continue; 8732e5b6d6dSopenharmony_ci } 8742e5b6d6dSopenharmony_ci log = s + " => "; 8752e5b6d6dSopenharmony_ci t->finishTransliteration(s, index); 8762e5b6d6dSopenharmony_ci } 8772e5b6d6dSopenharmony_ci // Show the start index '{' and the cursor '|' 8782e5b6d6dSopenharmony_ci displayOutput(s, DATA[i+1], log, index); 8792e5b6d6dSopenharmony_ci 8802e5b6d6dSopenharmony_ci } 8812e5b6d6dSopenharmony_ci} 8822e5b6d6dSopenharmony_ci 8832e5b6d6dSopenharmony_civoid TransliteratorAPITest::displayOutput(const UnicodeString& got, const UnicodeString& expected, UnicodeString& log, UTransPosition& index){ 8842e5b6d6dSopenharmony_ci // Show the start index '{' and the cursor '|' 8852e5b6d6dSopenharmony_ci UnicodeString a, b, c, d, e; 8862e5b6d6dSopenharmony_ci got.extractBetween(0, index.contextStart, a); 8872e5b6d6dSopenharmony_ci got.extractBetween(index.contextStart, index.start, b); 8882e5b6d6dSopenharmony_ci got.extractBetween(index.start, index.limit, c); 8892e5b6d6dSopenharmony_ci got.extractBetween(index.limit, index.contextLimit, d); 8902e5b6d6dSopenharmony_ci got.extractBetween(index.contextLimit, got.length(), e); 8912e5b6d6dSopenharmony_ci log.append(a). 8922e5b6d6dSopenharmony_ci append((UChar)0x7b/*{*/). 8932e5b6d6dSopenharmony_ci append(b). 8942e5b6d6dSopenharmony_ci append((UChar)0x7c/*|*/). 8952e5b6d6dSopenharmony_ci append(c). 8962e5b6d6dSopenharmony_ci append((UChar)0x7c). 8972e5b6d6dSopenharmony_ci append(d). 8982e5b6d6dSopenharmony_ci append((UChar)0x7d/*}*/). 8992e5b6d6dSopenharmony_ci append(e); 9002e5b6d6dSopenharmony_ci if (got == expected) 9012e5b6d6dSopenharmony_ci logln("OK:" + prettify(log)); 9022e5b6d6dSopenharmony_ci else 9032e5b6d6dSopenharmony_ci errln("FAIL: " + prettify(log) + ", expected " + prettify(expected)); 9042e5b6d6dSopenharmony_ci} 9052e5b6d6dSopenharmony_ci 9062e5b6d6dSopenharmony_ci 9072e5b6d6dSopenharmony_ci/*Internal Functions used*/ 9082e5b6d6dSopenharmony_civoid TransliteratorAPITest::doTest(const UnicodeString& message, const UnicodeString& result, const UnicodeString& expected){ 9092e5b6d6dSopenharmony_ci if (prettify(result) == prettify(expected)) 9102e5b6d6dSopenharmony_ci logln((UnicodeString)"Ok: " + prettify(message) + " passed \"" + prettify(expected) + "\""); 9112e5b6d6dSopenharmony_ci else 9122e5b6d6dSopenharmony_ci dataerrln((UnicodeString)"FAIL:" + message + " failed Got-->" + prettify(result)+ ", Expected--> " + prettify(expected) ); 9132e5b6d6dSopenharmony_ci} 9142e5b6d6dSopenharmony_ci 9152e5b6d6dSopenharmony_ci 9162e5b6d6dSopenharmony_ci// 9172e5b6d6dSopenharmony_ci// callEverything call all of the const (non-destructive) methods on a 9182e5b6d6dSopenharmony_ci// transliterator, just to verify that they don't fail in some 9192e5b6d6dSopenharmony_ci// destructive way. 9202e5b6d6dSopenharmony_ci// 9212e5b6d6dSopenharmony_ci#define CEASSERT(a) UPRV_BLOCK_MACRO_BEGIN { \ 9222e5b6d6dSopenharmony_ci if (!(a)) { \ 9232e5b6d6dSopenharmony_ci errln("FAIL at line %d from line %d: %s", __LINE__, line, #a); \ 9242e5b6d6dSopenharmony_ci return; \ 9252e5b6d6dSopenharmony_ci } \ 9262e5b6d6dSopenharmony_ci} UPRV_BLOCK_MACRO_END 9272e5b6d6dSopenharmony_ci 9282e5b6d6dSopenharmony_civoid TransliteratorAPITest::callEverything(const Transliterator *tr, int line) { 9292e5b6d6dSopenharmony_ci Transliterator *clonedTR = tr->clone(); 9302e5b6d6dSopenharmony_ci CEASSERT(clonedTR != NULL); 9312e5b6d6dSopenharmony_ci 9322e5b6d6dSopenharmony_ci int32_t maxcl = tr->getMaximumContextLength(); 9332e5b6d6dSopenharmony_ci CEASSERT(clonedTR->getMaximumContextLength() == maxcl); 9342e5b6d6dSopenharmony_ci 9352e5b6d6dSopenharmony_ci UnicodeString id; 9362e5b6d6dSopenharmony_ci UnicodeString clonedId; 9372e5b6d6dSopenharmony_ci id = tr->getID(); 9382e5b6d6dSopenharmony_ci clonedId = clonedTR->getID(); 9392e5b6d6dSopenharmony_ci CEASSERT(id == clonedId); 9402e5b6d6dSopenharmony_ci 9412e5b6d6dSopenharmony_ci const UnicodeFilter *filter = tr->getFilter(); 9422e5b6d6dSopenharmony_ci const UnicodeFilter *clonedFilter = clonedTR->getFilter(); 9432e5b6d6dSopenharmony_ci if (filter == NULL || clonedFilter == NULL) { 9442e5b6d6dSopenharmony_ci // If one filter is NULL they better both be NULL. 9452e5b6d6dSopenharmony_ci CEASSERT(filter == clonedFilter); 9462e5b6d6dSopenharmony_ci } else { 9472e5b6d6dSopenharmony_ci CEASSERT(filter != clonedFilter); 9482e5b6d6dSopenharmony_ci } 9492e5b6d6dSopenharmony_ci 9502e5b6d6dSopenharmony_ci UnicodeString rules; 9512e5b6d6dSopenharmony_ci UnicodeString clonedRules; 9522e5b6d6dSopenharmony_ci rules = tr->toRules(rules, false); 9532e5b6d6dSopenharmony_ci clonedRules = clonedTR->toRules(clonedRules, false); 9542e5b6d6dSopenharmony_ci CEASSERT(rules == clonedRules); 9552e5b6d6dSopenharmony_ci 9562e5b6d6dSopenharmony_ci UnicodeSet sourceSet; 9572e5b6d6dSopenharmony_ci UnicodeSet clonedSourceSet; 9582e5b6d6dSopenharmony_ci tr->getSourceSet(sourceSet); 9592e5b6d6dSopenharmony_ci clonedTR->getSourceSet(clonedSourceSet); 9602e5b6d6dSopenharmony_ci CEASSERT(clonedSourceSet == sourceSet); 9612e5b6d6dSopenharmony_ci 9622e5b6d6dSopenharmony_ci UnicodeSet targetSet; 9632e5b6d6dSopenharmony_ci UnicodeSet clonedTargetSet; 9642e5b6d6dSopenharmony_ci tr->getTargetSet(targetSet); 9652e5b6d6dSopenharmony_ci clonedTR->getTargetSet(clonedTargetSet); 9662e5b6d6dSopenharmony_ci CEASSERT(targetSet == clonedTargetSet); 9672e5b6d6dSopenharmony_ci 9682e5b6d6dSopenharmony_ci UClassID classID = tr->getDynamicClassID(); 9692e5b6d6dSopenharmony_ci CEASSERT(classID == clonedTR->getDynamicClassID()); 9702e5b6d6dSopenharmony_ci CEASSERT(classID != 0); 9712e5b6d6dSopenharmony_ci 9722e5b6d6dSopenharmony_ci delete clonedTR; 9732e5b6d6dSopenharmony_ci} 9742e5b6d6dSopenharmony_ci 9752e5b6d6dSopenharmony_cistatic const int MyUnicodeFunctorTestClassID = 0; 9762e5b6d6dSopenharmony_ciclass MyUnicodeFunctorTestClass : public UnicodeFunctor { 9772e5b6d6dSopenharmony_cipublic: 9782e5b6d6dSopenharmony_ci virtual UnicodeFunctor* clone() const override {return NULL;} 9792e5b6d6dSopenharmony_ci static UClassID getStaticClassID(void) {return (UClassID)&MyUnicodeFunctorTestClassID;} 9802e5b6d6dSopenharmony_ci virtual UClassID getDynamicClassID(void) const override {return getStaticClassID();} 9812e5b6d6dSopenharmony_ci virtual void setData(const TransliterationRuleData*) override {} 9822e5b6d6dSopenharmony_ci}; 9832e5b6d6dSopenharmony_ci 9842e5b6d6dSopenharmony_civoid TransliteratorAPITest::TestUnicodeFunctor() { 9852e5b6d6dSopenharmony_ci MyUnicodeFunctorTestClass myClass; 9862e5b6d6dSopenharmony_ci if (myClass.toMatcher() != NULL) { 9872e5b6d6dSopenharmony_ci errln("FAIL: UnicodeFunctor::toMatcher did not return NULL"); 9882e5b6d6dSopenharmony_ci } 9892e5b6d6dSopenharmony_ci if (myClass.toReplacer() != NULL) { 9902e5b6d6dSopenharmony_ci errln("FAIL: UnicodeFunctor::toReplacer did not return NULL"); 9912e5b6d6dSopenharmony_ci } 9922e5b6d6dSopenharmony_ci} 9932e5b6d6dSopenharmony_ci 9942e5b6d6dSopenharmony_ci 9952e5b6d6dSopenharmony_ci#endif /* #if !UCONFIG_NO_TRANSLITERATION */ 996