1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/************************************************************************
2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * COPYRIGHT:
385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * Copyright (c) 2000-2009, International Business Machines Corporation
4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * and others. All Rights Reserved.
5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ************************************************************************/
6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/************************************************************************
7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*   Date        Name        Description
8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*   1/03/2000   Madhu        Creation.
9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru************************************************************************/
10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h"
12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_TRANSLITERATION
14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "ittrans.h"
16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "transapi.h"
17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h"
18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/translit.h"
19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/unifilt.h"
20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cpdtrans.h"
21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <string.h>
22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <stdio.h>
23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <stdlib.h>
24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/rep.h"
25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/locid.h"
26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/uniset.h"
27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruint32_t getInt(UnicodeString str)
29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char buffer[20];
31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int len=str.length();
32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(len>=20) {
33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        len=19;
34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    str.extract(0, len, buffer, "");
36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    buffer[len]=0;
37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return atoi(buffer);
38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru//---------------------------------------------
41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// runIndexedTest
42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru//---------------------------------------------
43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid
45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruTransliteratorAPITest::runIndexedTest(int32_t index, UBool exec,
46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                      const char* &name, char* /*par*/) {
47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    switch (index) {
48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        TESTCASE(0,TestgetInverse);
49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        TESTCASE(1,TestgetID);
50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        TESTCASE(2,TestGetDisplayName);
51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        TESTCASE(3,TestTransliterate1);
52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        TESTCASE(4,TestTransliterate2);
53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        TESTCASE(5,TestTransliterate3);
54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        TESTCASE(6,TestSimpleKeyboardTransliterator);
55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        TESTCASE(7,TestKeyboardTransliterator1);
56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        TESTCASE(8,TestKeyboardTransliterator2);
57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        TESTCASE(9,TestKeyboardTransliterator3);
58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        TESTCASE(10,TestGetAdoptFilter);
59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        TESTCASE(11,TestClone);
60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        TESTCASE(12,TestNullTransliterator);
61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        TESTCASE(13,TestRegisterUnregister);
62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        TESTCASE(14,TestUnicodeFunctor);
63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        default: name = ""; break;
64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TransliteratorAPITest::TestgetID() {
69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString trans="Latin-Greek";
70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString ID;
71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UParseError parseError;
72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    Transliterator* t= Transliterator::createInstance(trans, UTRANS_FORWARD, parseError, status);
74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(t==0 || U_FAILURE(status)){
7585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        dataerrln("FAIL: construction of Latin-Greek -  %s",u_errorName(status));
76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }else{
78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ID= t->getID();
79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(ID != trans)
80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            errln("FAIL: getID returned " + ID + " instead of Latin-Greek");
81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        delete t;
82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int i;
84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for (i=0; i<Transliterator::countAvailableIDs(); i++){
85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        status = U_ZERO_ERROR;
86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        ID = (UnicodeString) Transliterator::getAvailableID(i);
87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(ID.indexOf("Thai")>-1){
88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            continue;
89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        t = Transliterator::createInstance(ID, UTRANS_FORWARD, parseError, status);
91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(t == 0){
92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            errln("FAIL: " + ID);
93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            continue;
94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(ID != t->getID())
96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            errln("FAIL: getID() returned " + t->getID() + " instead of " + ID);
97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        delete t;
98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ID=(UnicodeString)Transliterator::getAvailableID(i);
100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(ID != (UnicodeString)Transliterator::getAvailableID(0)){
101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        errln("FAIL: calling getAvailableID(index > coundAvailableIDs) should make index=0\n");
102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    Transliterator* t1=Transliterator::createInstance("Latin-Devanagari", UTRANS_FORWARD, parseError, status);
105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    Transliterator* t2=Transliterator::createInstance("Latin-Greek", UTRANS_FORWARD, parseError, status);
106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(t1 ==0 || t2 == 0){
107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        errln("FAIL: construction");
108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    Transliterator* t3=t1->clone();
111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    Transliterator* t4=t2->clone();
112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(t1->getID() != t3->getID() || t2->getID() != t4->getID() ||
114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       t1->getID() == t4->getID() || t2->getID() == t3->getID() ||
115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       t1->getID()== t4->getID() )
116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            errln("FAIL: getID or clone failed");
117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    Transliterator* t5=Transliterator::createInstance("Latin-Devanagari", UTRANS_FORWARD, parseError, status);
120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(t5 == 0)
121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        errln("FAIL: construction");
122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    else if(t1->getID() != t5->getID() || t5->getID() != t3->getID() || t1->getID() != t3->getID())
123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        errln("FAIL: getID or clone failed");
124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    delete t1;
127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    delete t2;
128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    delete t3;
129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    delete t4;
130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    delete t5;
131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TransliteratorAPITest::TestgetInverse() {
134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     UErrorCode status = U_ZERO_ERROR;
135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     UParseError parseError;
136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     Transliterator* t1    = Transliterator::createInstance("Katakana-Latin", UTRANS_FORWARD, parseError, status);
137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     Transliterator* invt1 = Transliterator::createInstance("Latin-Katakana", UTRANS_FORWARD, parseError, status);
138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     Transliterator* t2    = Transliterator::createInstance("Latin-Devanagari", UTRANS_FORWARD, parseError, status);
139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     Transliterator* invt2 = Transliterator::createInstance("Devanagari-Latin", UTRANS_FORWARD, parseError, status);
140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     if(t1 == 0 || invt1 == 0 || t2 == 0 || invt2 == 0) {
14185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho         dataerrln("FAIL: in instantiation - %s", u_errorName(status));
142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         return;
143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     }
144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     Transliterator* inverse1=t1->createInverse(status);
146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     Transliterator* inverse2=t2->createInverse(status);
147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     if(inverse1->getID() != invt1->getID() || inverse2->getID() != invt2->getID()
148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        || inverse1->getID() == invt2->getID() || inverse2->getID() == invt1->getID() )
149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        errln("FAIL: getInverse() ");
150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     UnicodeString TransID[]={
152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       "Halfwidth-Fullwidth",
153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       "Fullwidth-Halfwidth",
154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       "Greek-Latin" ,
155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       "Latin-Greek",
156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       //"Arabic-Latin", // removed in 2.0
157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       //"Latin-Arabic",
158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       "Katakana-Latin",
159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       "Latin-Katakana",
160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       //"Hebrew-Latin", // removed in 2.0
161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       //"Latin-Hebrew",
162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       "Cyrillic-Latin",
163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       "Latin-Cyrillic",
164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       "Devanagari-Latin",
165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       "Latin-Devanagari",
166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       "Any-Hex",
167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       "Hex-Any"
168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     };
169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     for(uint32_t i=0; i<sizeof(TransID)/sizeof(TransID[0]); i=i+2){
170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         Transliterator *trans1=Transliterator::createInstance(TransID[i], UTRANS_FORWARD, parseError, status);
171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         if(t1 == 0){
172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           errln("FAIL: in instantiation for" + TransID[i]);
173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           continue;
174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         }
175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         Transliterator *inver1=trans1->createInverse(status);
176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         if(inver1->getID() != TransID[i+1] )
177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru             errln("FAIL :getInverse() for " + TransID[i] + " returned " + inver1->getID() + " instead of " + TransID[i+1]);
178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         delete inver1;
179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         delete trans1;
180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     }
181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     delete t1;
182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     delete t2;
183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     delete invt1;
184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     delete invt2;
185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     delete inverse1;
186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     delete inverse2;
187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TransliteratorAPITest::TestClone(){
191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    Transliterator *t1, *t2, *t3, *t4;
192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UParseError parseError;
194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    t1=Transliterator::createInstance("Latin-Devanagari", UTRANS_FORWARD, parseError, status);
195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    t2=Transliterator::createInstance("Latin-Greek", UTRANS_FORWARD, parseError, status);
196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(t1 == 0 || t2 == 0){
19785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        dataerrln("FAIL: construction - %s", u_errorName(status));
198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    t3=t1->clone();
201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    t4=t2->clone();
202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(t1->getID() != t3->getID() || t2->getID() != t4->getID() )
204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        errln("FAIL: clone or getID failed");
205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(t1->getID()==t4->getID() || t2->getID()==t3->getID() ||  t1->getID()==t4->getID())
206ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        errln("FAIL: clone or getID failed");
207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    delete t1;
209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    delete t2;
210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    delete t3;
211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    delete t4;
212ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
214ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TransliteratorAPITest::TestGetDisplayName() {
216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString dispNames[]= {
217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         //ID, displayName
218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        //"CurlyQuotes-StraightQuotes" ,"CurlyQuotes to StraightQuotes",
219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru          "Any-Hex"                ,"Any to Hex Escape",
220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru          "Halfwidth-Fullwidth"        ,"Halfwidth to Fullwidth" ,
221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru          //"Latin-Arabic"               ,"Latin to Arabic"      ,
222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru          "Latin-Devanagari"           ,"Latin to Devanagari"  ,
223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru          "Greek-Latin"                ,"Greek to Latin"       ,
224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru          //"Arabic-Latin"               ,"Arabic to Latin"      ,
225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru          "Hex-Any"                ,"Hex Escape to Any",
226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru          "Cyrillic-Latin"             ,"Cyrillic to Latin"    ,
227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru          "Latin-Greek"                ,"Latin to Greek"       ,
228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru          "Latin-Katakana"                 ,"Latin to Katakana"        ,
229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru          //"Latin-Hebrew"               ,"Latin to Hebrew"      ,
230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru          "Katakana-Latin"                 ,"Katakana to Latin"
231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      };
232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString name="";
233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    Transliterator* t;
234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString message;
235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UParseError parseError;
237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if UCONFIG_NO_FORMATTING
239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    logln("Skipping, UCONFIG_NO_FORMATTING is set\n");
240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return;
241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#else
242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for (uint32_t i=0; i<sizeof(dispNames)/sizeof(dispNames[0]); i=i+2 ) {
244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        t = Transliterator::createInstance(dispNames[i+0], UTRANS_FORWARD, parseError, status);
245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(t==0){
24685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho             dataerrln("FAIL: construction: " + dispNames[i+0] + " - " + u_errorName(status));
247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru             status = U_ZERO_ERROR;
248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru             continue;
249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        t->getDisplayName(t->getID(), name);
251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        message="Display name for ID:" + t->getID();
252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      //  doTest(message, name, dispNames[i+1]); //!!! This will obviously fail for any locale other than english and its children!!!
253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        name="";
254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        t->getDisplayName(t->getID(), Locale::getUS(), name);
255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        message.remove();
256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        message.append("Display name for on english locale ID:");
257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        message.append(t->getID());
258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // message="Display name for on english locale ID:" + t->getID();
259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        doTest(message, name, dispNames[i+1]);
260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        name="";
261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        delete t;
263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TransliteratorAPITest::TestTransliterate1(){
269ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
270ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString Data[]={
271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         //ID, input string, transliterated string
272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         "Any-Hex",         "hello",    UnicodeString("\\u0068\\u0065\\u006C\\u006C\\u006F", "") ,
273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         "Hex-Any",         UnicodeString("\\u0068\\u0065\\u006C\\u006C\\u006F", ""), "hello"  ,
274ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         "Latin-Devanagari",CharsToUnicodeString("bha\\u0304rata"), CharsToUnicodeString("\\u092D\\u093E\\u0930\\u0924") ,
275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         "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") ,
276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
27785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho         "Devanagari-Latin",    CharsToUnicodeString("\\u092D\\u093E\\u0930\\u0924"),        CharsToUnicodeString("bh\\u0101rata"),
278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     //  "Contracted-Expanded", CharsToUnicodeString("\\u00C0\\u00C1\\u0042"),               CharsToUnicodeString("\\u0041\\u0300\\u0041\\u0301\\u0042") ,
279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     //  "Expanded-Contracted", CharsToUnicodeString("\\u0041\\u0300\\u0041\\u0301\\u0042"), CharsToUnicodeString("\\u00C0\\u00C1\\u0042") ,
280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         //"Latin-Arabic",        "aap",                                 CharsToUnicodeString("\\u0627\\u06A4")     ,
281ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         //"Arabic-Latin",        CharsToUnicodeString("\\u0627\\u06A4"),                      "aap"
282ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
283ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString gotResult;
285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString temp;
286ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString message;
287ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    Transliterator* t;
288ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    logln("Testing transliterate");
289ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
290ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UParseError parseError;
291ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
292ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for(uint32_t i=0;i<sizeof(Data)/sizeof(Data[0]); i=i+3){
293ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        t=Transliterator::createInstance(Data[i+0], UTRANS_FORWARD, parseError, status);
294ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(t==0){
29585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            dataerrln("FAIL: construction: " + Data[i+0] + " Error: "  + u_errorName(status));
29685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            dataerrln("PreContext: " + prettify(parseError.preContext) + " PostContext: " + prettify( parseError.postContext) );
297ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            status = U_ZERO_ERROR;
298ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            continue;
299ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
300ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        gotResult = Data[i+1];
301ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        t->transliterate(gotResult);
302ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        message=t->getID() + "->transliterate(UnicodeString, UnicodeString) for\n\t Source:" + prettify(Data[i+1]);
303ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        doTest(message, gotResult, Data[i+2]);
304ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
305ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        //doubt here
306ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        temp=Data[i+1];
307ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        t->transliterate(temp);
308ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        message.remove();
309ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        message.append(t->getID());
310ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        message.append("->transliterate(Replaceable) for \n\tSource:");
311ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        message.append(Data[i][1]);
312ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        doTest(message, temp, Data[i+2]);
313ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
314ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        callEverything(t, __LINE__);
315ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        delete t;
316ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
317ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
318ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
319ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TransliteratorAPITest::TestTransliterate2(){
320ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     //testing tranliterate(String text, int start, int limit, StringBuffer result)
321ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   UnicodeString Data2[]={
322ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         //ID, input string, start, limit, transliterated string
323ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         "Any-Hex",         "hello! How are you?",  "0", "5", UnicodeString("\\u0068\\u0065\\u006C\\u006C\\u006F", ""), UnicodeString("\\u0068\\u0065\\u006C\\u006C\\u006F! How are you?", "") ,
324ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         "Any-Hex",         "hello! How are you?",  "7", "12", UnicodeString("\\u0048\\u006F\\u0077\\u0020\\u0061", ""), UnicodeString("hello! \\u0048\\u006F\\u0077\\u0020\\u0061re you?", ""),
325ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         "Hex-Any",         CharsToUnicodeString("\\u0068\\u0065\\u006C\\u006C\\u006F\\u0021\\u0020"), "0", "5",  "hello", "hello! "  ,
326ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       //  "Contracted-Expanded", CharsToUnicodeString("\\u00C0\\u00C1\\u0042"),        "1", "2",  CharsToUnicodeString("\\u0041\\u0301"), CharsToUnicodeString("\\u00C0\\u0041\\u0301\\u0042") ,
327ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         "Devanagari-Latin",    CharsToUnicodeString("\\u092D\\u093E\\u0930\\u0924"), "0", "1",  "bha", CharsToUnicodeString("bha\\u093E\\u0930\\u0924") ,
32885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho         "Devanagari-Latin",    CharsToUnicodeString("\\u092D\\u093E\\u0930\\u0924"), "1", "2",  CharsToUnicodeString("\\u0314\\u0101"), CharsToUnicodeString("\\u092D\\u0314\\u0101\\u0930\\u0924")
329ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
330ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
331ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    logln("\n   Testing transliterate(String, int, int, StringBuffer)");
332ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    Transliterator* t;
333ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString gotResBuf;
334ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString temp;
335ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t start, limit;
336ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
337ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UParseError parseError;
338ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
339ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for(uint32_t i=0; i<sizeof(Data2)/sizeof(Data2[0]); i=i+6){
340ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        t=Transliterator::createInstance(Data2[i+0], UTRANS_FORWARD, parseError, status);
341ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(t==0){
34285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            dataerrln("FAIL: construction: " + prettify(Data2[i+0]) + " - " + u_errorName(status));
343ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            continue;
344ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
345ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        start=getInt(Data2[i+2]);
346ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        limit=getInt(Data2[i+3]);
347ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        Data2[i+1].extractBetween(start, limit, gotResBuf);
348ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        t->transliterate(gotResBuf);
349ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        //  errln("FAIL: calling transliterate on " + t->getID());
350ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        doTest(t->getID() + ".transliterate(UnicodeString, int32_t, int32_t, UnicodeString):(" + start + "," + limit + ")  for \n\t source: " + prettify(Data2[i+1]), gotResBuf, Data2[i+4]);
351ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
352ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        temp=Data2[i+1];
353ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        t->transliterate(temp, start, limit);
354ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        doTest(t->getID() + ".transliterate(Replaceable, int32_t, int32_t, ):(" + start + "," + limit + ")  for \n\t source: " + prettify(Data2[i+1]), temp, Data2[i+5]);
355ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        status = U_ZERO_ERROR;
356ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        callEverything(t, __LINE__);
357ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        delete t;
358ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        t = NULL;
359ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
360ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
361ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    status = U_ZERO_ERROR;
362ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    logln("\n   Try calling transliterate with illegal start and limit values");
363ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    t=Transliterator::createInstance("Any-Hex", UTRANS_FORWARD, parseError, status);
364ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)) {
365ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      errln("Error creating transliterator %s", u_errorName(status));
366ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      delete t;
367ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      return;
368ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
369ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    gotResBuf = temp = "try start greater than limit";
370ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    t->transliterate(gotResBuf, 10, 5);
371ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(gotResBuf == temp) {
372ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        logln("OK: start greater than limit value handled correctly");
373ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
374ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        errln("FAIL: start greater than limit value returned" + gotResBuf);
375ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
376ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
377ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    callEverything(t, __LINE__);
378ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    delete t;
379ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
380ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
381ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TransliteratorAPITest::TestTransliterate3(){
382ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString rs="This is the replaceable String";
383ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString Data[] = {
384ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "0",  "0",  "This is the replaceable String",
385ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "2",  "3",  UnicodeString("Th\\u0069s is the replaceable String", ""),
386ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "21", "23", UnicodeString("Th\\u0069s is the repl\\u0061\\u0063eable String", ""),
387ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "14", "17", UnicodeString("Th\\u0069s is t\\u0068\\u0065\\u0020repl\\u0061\\u0063eable String", ""),
388ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
389ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int start, limit;
390ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString message;
391ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UParseError parseError;
392ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
393ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    Transliterator *t=Transliterator::createInstance("Any-Hex", UTRANS_FORWARD, parseError, status);
394ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)) {
395ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      errln("Error creating transliterator %s", u_errorName(status));
396ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      delete t;
397ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      return;
398ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
399ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
400ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(t == 0)
401ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        errln("FAIL : construction");
402ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for(uint32_t i=0; i<sizeof(Data)/sizeof(Data[0]); i=i+3){
403ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        start=getInt(Data[i+0]);
404ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        limit=getInt(Data[i+1]);
405ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        t->transliterate(rs, start, limit);
406ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        message=t->getID() + ".transliterate(ReplaceableString, start, limit):("+start+","+limit+"):";
407ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        doTest(message, rs, Data[i+2]);
408ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
409ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    delete t;
410ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
411ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
412ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TransliteratorAPITest::TestSimpleKeyboardTransliterator(){
413ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    logln("simple call to transliterate");
414ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status=U_ZERO_ERROR;
415ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UParseError parseError;
416ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    Transliterator* t=Transliterator::createInstance("Any-Hex", UTRANS_FORWARD, parseError, status);
417ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(t == 0) {
418ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        UnicodeString context;
419ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
420ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (parseError.preContext[0]) {
421ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            context += (UnicodeString)" at " + parseError.preContext;
422ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
423ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (parseError.postContext[0]) {
424ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            context += (UnicodeString)" | " + parseError.postContext;
425ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
426ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        errln((UnicodeString)"FAIL: can't create Any-Hex, " +
427ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru              (UnicodeString)u_errorName(status) + context);
428ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
429ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
430ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UTransPosition index={19,20,20,20};
431ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString rs= "Transliterate this-''";
432ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString insertion="abc";
433ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString expected=UnicodeString("Transliterate this-'\\u0061\\u0062\\u0063'", "");
434ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    t->transliterate(rs, index, insertion, status);
435ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status))
436ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        errln("FAIL: " + t->getID()+ ".translitere(Replaceable, int[], UnicodeString, UErrorCode)-->" + (UnicodeString)u_errorName(status));
437ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    t->finishTransliteration(rs, index);
438ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString message="transliterate";
439ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doTest(message, rs, expected);
440ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
441ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    logln("try calling transliterate with invalid index values");
442ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UTransPosition index1[]={
443ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        //START, LIMIT, CURSOR
444ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {10, 10, 12, 10},   //invalid since CURSOR>LIMIT valid:-START <= CURSOR <= LIMIT
445ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {17, 16, 17, 17},   //invalid since START>LIMIT valid:-0<=START<=LIMIT
446ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {-1, 16, 14, 16},   //invalid since START<0
447ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        {3,  50, 2,  50}    //invalid since LIMIT>text.length()
448ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
449ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for(uint32_t i=0; i<sizeof(index1)/sizeof(index1[0]); i++){
450ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        status=U_ZERO_ERROR;
451ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        t->transliterate(rs, index1[i], insertion, status);
452ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(status == U_ILLEGAL_ARGUMENT_ERROR)
453ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            logln("OK: invalid index values handled correctly");
454ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        else
455ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            errln("FAIL: invalid index values didn't throw U_ILLEGAL_ARGUMENT_ERROR throw" + (UnicodeString)u_errorName(status));
456ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
457ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
458ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    delete t;
459ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
460ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TransliteratorAPITest::TestKeyboardTransliterator1(){
461ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString Data[]={
462ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        //insertion, buffer
463ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "a",   UnicodeString("\\u0061", "")                                           ,
464ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "bbb", UnicodeString("\\u0061\\u0062\\u0062\\u0062", "")                      ,
465ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "ca",  UnicodeString("\\u0061\\u0062\\u0062\\u0062\\u0063\\u0061", "")        ,
466ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        " ",   UnicodeString("\\u0061\\u0062\\u0062\\u0062\\u0063\\u0061\\u0020", "") ,
467ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "",    UnicodeString("\\u0061\\u0062\\u0062\\u0062\\u0063\\u0061\\u0020", "")   ,
468ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
469ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "a",   UnicodeString("\\u0061", "")                                           ,
470ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "b",   UnicodeString("\\u0061\\u0062", "")                                    ,
471ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "z",   UnicodeString("\\u0061\\u0062\\u007A", "")                             ,
472ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "",    UnicodeString("\\u0061\\u0062\\u007A", "")
473ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
474ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
475ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UParseError parseError;
476ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
477ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    Transliterator* t=Transliterator::createInstance("Any-Hex", UTRANS_FORWARD, parseError, status);
478ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)) {
479ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      errln("Error creating transliterator %s", u_errorName(status));
480ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      delete t;
481ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      return;
482ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
483ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    //keyboardAux(t, Data);
484ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UTransPosition index={0, 0, 0, 0};
485ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString s;
486ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uint32_t i;
487ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    logln("Testing transliterate(Replaceable, int32_t, UnicodeString, UErrorCode)");
488ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for (i=0; i<10; i=i+2) {
489ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       UnicodeString log;
490ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       if (Data[i+0] != "") {
491ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           log = s + " + " + Data[i+0] + " -> ";
492ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           t->transliterate(s, index, Data[i+0], status);
493ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           if(U_FAILURE(status)){
494ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru               errln("FAIL: " + t->getID()+ ".transliterate(Replaceable, int32_t[], UnicodeString, UErrorCode)-->" + (UnicodeString)u_errorName(status));
495ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           continue;
496ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           }
497ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       }else {
498ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           log = s + " => ";
499ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           t->finishTransliteration(s, index);
500ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       }
501ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       // Show the start index '{' and the cursor '|'
502ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       displayOutput(s, Data[i+1], log, index);
503ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
504ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
505ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
506ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    s="";
507ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    status=U_ZERO_ERROR;
508ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    index.contextStart = index.contextLimit = index.start = index.limit = 0;
509ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    logln("Testing transliterate(Replaceable, int32_t, UChar, UErrorCode)");
510ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for(i=10; i<sizeof(Data)/sizeof(Data[0]); i=i+2){
511ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        UnicodeString log;
512ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         if (Data[i+0] != "") {
513ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           log = s + " + " + Data[i+0] + " -> ";
514ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           UChar c=Data[i+0].charAt(0);
515ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           t->transliterate(s, index, c, status);
516ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           if(U_FAILURE(status))
517ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru               errln("FAIL: " + t->getID()+ ".transliterate(Replaceable, int32_t[], UChar, UErrorCode)-->" + (UnicodeString)u_errorName(status));
518ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru               continue;
519ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         }else {
520ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           log = s + " => ";
521ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           t->finishTransliteration(s, index);
522ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         }
523ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        // Show the start index '{' and the cursor '|'
524ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        displayOutput(s, Data[i+1], log, index);
525ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
526ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
527ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    delete t;
528ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
529ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
530ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TransliteratorAPITest::TestKeyboardTransliterator2(){
531ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString Data[]={
532ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        //insertion, buffer, index[START], index[LIMIT], index[CURSOR]
533ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        //data for Any-Hex
534ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "abc",    UnicodeString("Initial String: add-\\u0061\\u0062\\u0063-", ""),                     "19", "20", "20",
535ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "a",      UnicodeString("In\\u0069\\u0061tial String: add-\\u0061\\u0062\\u0063-", ""),        "2",  "3",  "2" ,
536ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "b",      UnicodeString("\\u0062In\\u0069\\u0061tial String: add-\\u0061\\u0062\\u0063-", ""), "0",  "0",  "0" ,
537ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "",       UnicodeString("\\u0062In\\u0069\\u0061tial String: add-\\u0061\\u0062\\u0063-", ""), "0",  "0",  "0" ,
538ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        //data for Latin-Devanagiri
539ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        CharsToUnicodeString("a\\u0304"),     CharsToUnicodeString("Hindi -\\u0906-"),                            "6", "7", "6",
540ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        CharsToUnicodeString("ma\\u0304"),    CharsToUnicodeString("Hindi -\\u0906\\u092E\\u093E-"),              "7", "8", "7",
541ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        CharsToUnicodeString("ra\\u0304"),    CharsToUnicodeString("Hi\\u0930\\u093Endi -\\u0906\\u092E\\u093E-"),"1", "2", "2",
542ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        CharsToUnicodeString(""),       CharsToUnicodeString("Hi\\u0930\\u093Endi -\\u0906\\u092E\\u093E-"),"1", "2", "2"
543ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        //data for contracted-Expanded
544ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     //   CharsToUnicodeString("\\u00C1"), CharsToUnicodeString("Ad\\u0041\\u0301d here:"),             "1",  "2",  "1" ,
545ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     //   CharsToUnicodeString("\\u00C0"), CharsToUnicodeString("Ad\\u0041\\u0301d here:\\u0041\\u0300"), "11", "11", "11",
546ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     //   "",     CharsToUnicodeString("Ad\\u0041\\u0301d here:\\u0041\\u0300"), "11", "11", "11",
547ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
548ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    Transliterator *t;
549ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString rs;
550ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString dataStr;
551ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    logln("Testing transliterate(Replaceable, int32_t, UnicodeString, UErrorCode)");
552ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
553ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UParseError parseError;
554ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    rs="Initial String: add--";
555ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    t=Transliterator::createInstance("Any-Hex", UTRANS_FORWARD, parseError, status);
556ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(t == 0)
55785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        dataerrln("FAIL : construction - %s", u_errorName(status));
558ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    else {
559ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        keyboardAux(t, Data, rs, 0, 20);
560ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        delete t;
561ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
562ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
563ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    rs="Hindi --";
564ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    t=Transliterator::createInstance("Latin-Devanagari", UTRANS_FORWARD, parseError, status);
565ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(t == 0)
56685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        dataerrln("FAIL : construction - %s", u_errorName(status));
567ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    else
568ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        keyboardAux(t, Data, rs, 20, 40);
569ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
570ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
571ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru  //  rs="Add here:";
572ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru //   t=Transliterator::createInstance("Contracted-Expanded");
573ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru //   keyboardAux(t, Data, rs, 35, 55);
574ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
575ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
576ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    delete t;
577ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
578ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
579ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TransliteratorAPITest::TestKeyboardTransliterator3(){
580ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString s="This is the main string";
581ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString Data[] = {
582ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "0", "0", "0",  "This is the main string",
583ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "1", "3", "2",  UnicodeString("Th\\u0069s is the main string", ""),
584ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "20", "21", "20",  UnicodeString("Th\\u0069s is the mai\\u006E string", "")
585ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
586ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
587ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status=U_ZERO_ERROR;
588ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UParseError parseError;
589ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UTransPosition index={0, 0, 0, 0};
590ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    logln("Testing transliterate(Replaceable, int32_t, UErrorCode)");
591ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    Transliterator *t=Transliterator::createInstance("Any-Hex", UTRANS_FORWARD, parseError, status);
592ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(t == 0 || U_FAILURE(status)) {
593ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      errln("Error creating transliterator %s", u_errorName(status));
594ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      delete t;
595ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      return;
596ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
597ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for(uint32_t i=0; i<sizeof(Data)/sizeof(Data[0]); i=i+4){
598ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        UnicodeString log;
599ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        index.contextStart=getInt(Data[i+0]);
600ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        index.contextLimit=index.limit=getInt(Data[i+1]);
601ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        index.start=getInt(Data[i+2]);
602ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        t->transliterate(s, index, status);
603ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(U_FAILURE(status)){
604ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           errln("FAIL: " + t->getID()+ ".transliterate(Replaceable, int32_t[], UErrorCode)-->" + (UnicodeString)u_errorName(status));
605ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           continue;
606ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
607ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        t->finishTransliteration(s, index);
608ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log = s + " => ";
609ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        // Show the start index '{' and the cursor '|'
610ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        displayOutput(s, Data[i+3], log, index);
611ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
612ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
613ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    delete t;
614ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
615ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TransliteratorAPITest::TestNullTransliterator(){
616ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status=U_ZERO_ERROR;
617ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString s("Transliterate using null transliterator");
618ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    Transliterator *nullTrans=Transliterator::createInstance("Any-Null", UTRANS_FORWARD, status);
619ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t transLimit;
620ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t start=0;
621ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t limit=s.length();
622ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString replaceable=s;
623ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    transLimit=nullTrans->transliterate(replaceable, start, limit);
624ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(transLimit != limit){
625ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        errln("ERROR: NullTransliterator->transliterate() failed");
626ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
627ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doTest((UnicodeString)"nulTrans->transliterate", replaceable, s);
628ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    replaceable.remove();
629ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    replaceable.append(s);
630ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UTransPosition index;
631ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    index.contextStart =start;
632ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    index.contextLimit = limit;
633ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    index.start = 0;
634ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    index.limit = limit;
635ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    nullTrans->finishTransliteration(replaceable, index);
636ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(index.start != limit){
637ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        errln("ERROR: NullTransliterator->handleTransliterate() failed");
638ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
639ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doTest((UnicodeString)"NullTransliterator->handleTransliterate", replaceable, s);
640ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    callEverything(nullTrans, __LINE__);
641ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    delete nullTrans;
642ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
643ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
644ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
645ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TransliteratorAPITest::TestRegisterUnregister(){
646ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
647ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   UErrorCode status=U_ZERO_ERROR;
648ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Make sure it doesn't exist */
649ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   if (Transliterator::createInstance("TestA-TestB", UTRANS_FORWARD, status) != NULL) {
650ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      errln("FAIL: TestA-TestB already registered\n");
651ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      return;
652ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   }
653ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   /* Check inverse too
654ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   if (Transliterator::createInstance("TestA-TestB",
655ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                      (UTransDirection)UTRANS_REVERSE) != NULL) {
656ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      errln("FAIL: TestA-TestB inverse already registered\n");
657ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      return;
658ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   }
659ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   */
660ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   status =U_ZERO_ERROR;
661ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
662ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   /* Create it */
663ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   UParseError parseError;
664ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   Transliterator *t = Transliterator::createFromRules("TestA-TestB",
665ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                                   "a<>b",
666ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                                   UTRANS_FORWARD, parseError,
667ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                                   status);
668ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   /* Register it */
669ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   Transliterator::registerInstance(t);
670ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
671ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   /* Now check again -- should exist now*/
672ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   Transliterator *s = Transliterator::createInstance("TestA-TestB", UTRANS_FORWARD, status);
673ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   if (s == NULL) {
674ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      errln("FAIL: TestA-TestB not registered\n");
675ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      return;
676ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   }
677ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   callEverything(s, __LINE__);
678ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   callEverything(t, __LINE__);
679ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   delete s;
680ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
681ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   /* Check inverse too
682ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   s = Transliterator::createInstance("TestA-TestB",
683ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                      (UTransDirection)UTRANS_REVERSE);
684ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   if (s == NULL) {
685ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      errln("FAIL: TestA-TestB inverse not registered\n");
686ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      return;
687ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   }
688ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   delete s;
689ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   */
690ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
691ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   /*unregister the instance*/
692ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   Transliterator::unregister("TestA-TestB");
693ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   /* now Make sure it doesn't exist */
694ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   if (Transliterator::createInstance("TestA-TestB", UTRANS_FORWARD, status) != NULL) {
695ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      errln("FAIL: TestA-TestB isn't unregistered\n");
696ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      return;
697ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   }
698ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
699ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
700ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
701ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
702ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruint gTestFilter1ClassID = 0;
703ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruint gTestFilter2ClassID = 0;
704ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruint gTestFilter3ClassID = 0;
705ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
706ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
707ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Used by TestFiltering().
708ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
709ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruclass TestFilter1 : public UnicodeFilter {
710ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UClassID getDynamicClassID()const { return &gTestFilter1ClassID; }
711ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual UnicodeFunctor* clone() const {
712ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return new TestFilter1(*this);
713ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
714ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual UBool contains(UChar32 c) const {
715ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       if(c==0x63 || c==0x61 || c==0x43 || c==0x41)
716ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru          return FALSE;
717ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       else
718ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru          return TRUE;
719ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
720ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // Stubs
721ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual UnicodeString& toPattern(UnicodeString& result,
722ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                     UBool /*escapeUnprintable*/) const {
723ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return result;
724ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
725ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual UBool matchesIndexValue(uint8_t /*v*/) const {
726ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return FALSE;
727ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
728ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual void addMatchSetTo(UnicodeSet& /*toUnionTo*/) const {}
729ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru};
730ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruclass TestFilter2 : public UnicodeFilter {
731ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UClassID getDynamicClassID()const { return &gTestFilter2ClassID; }
732ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual UnicodeFunctor* clone() const {
733ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return new TestFilter2(*this);
734ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
735ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual UBool contains(UChar32 c) const {
736ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(c==0x65 || c==0x6c)
737ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           return FALSE;
738ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        else
739ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           return TRUE;
740ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
741ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // Stubs
742ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual UnicodeString& toPattern(UnicodeString& result,
743ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                     UBool /*escapeUnprintable*/) const {
744ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return result;
745ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
746ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual UBool matchesIndexValue(uint8_t /*v*/) const {
747ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return FALSE;
748ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
749ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual void addMatchSetTo(UnicodeSet& /*toUnionTo*/) const {}
750ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru};
751ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruclass TestFilter3 : public UnicodeFilter {
752ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UClassID getDynamicClassID()const { return &gTestFilter3ClassID; }
753ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual UnicodeFunctor* clone() const {
754ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return new TestFilter3(*this);
755ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
756ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual UBool contains(UChar32 c) const {
757ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(c==0x6f || c==0x77)
758ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           return FALSE;
759ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        else
760ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           return TRUE;
761ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
762ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // Stubs
763ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual UnicodeString& toPattern(UnicodeString& result,
764ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                     UBool /*escapeUnprintable*/) const {
765ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return result;
766ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
767ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual UBool matchesIndexValue(uint8_t /*v*/) const {
768ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return FALSE;
769ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
770ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual void addMatchSetTo(UnicodeSet& /*toUnionTo*/) const {}
771ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru};
772ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
773ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
774ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TransliteratorAPITest::TestGetAdoptFilter(){
775ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
776ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UParseError parseError;
777ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    Transliterator *t=Transliterator::createInstance("Any-Hex", UTRANS_FORWARD, parseError, status);
778ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(t == 0 || U_FAILURE(status)) {
779ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        errln("Error creating transliterator %s", u_errorName(status));
780ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        delete t;
781ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
782ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
783ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const UnicodeFilter *u=t->getFilter();
784ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(u != NULL){
785ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        errln("FAIL: getFilter failed. Didn't return null when the transliterator used no filtering");
786ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        delete t;
787ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
788ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
789ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
790ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString got, temp, message;
791ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString data="ABCabcbbCBa";
792ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    temp = data;
793ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    t->transliterate(temp);
794ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    t->adoptFilter(new TestFilter1);
795ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
796ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    got = data;
797ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    t->transliterate(got);
798ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString exp=UnicodeString("A\\u0042Ca\\u0062c\\u0062\\u0062C\\u0042a", "");
799ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    message="transliteration after adoptFilter(a,A,c,C) ";
800ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doTest(message, got, exp);
801ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
802ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    logln("Testing round trip");
803ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    t->adoptFilter((UnicodeFilter*)u);
804ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(t->getFilter() == NULL)
805ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       logln("OK: adoptFilter and getFilter round trip worked");
806ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    else
807ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru       errln("FAIL: adoptFilter or getFilter round trip failed");
808ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
809ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    got = data;
810ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    t->transliterate(got);
811ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    exp=UnicodeString("\\u0041\\u0042\\u0043\\u0061\\u0062\\u0063\\u0062\\u0062\\u0043\\u0042\\u0061", "");
812ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    message="transliteration after adopting null filter";
813ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doTest(message, got, exp);
814ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    message="adoptFilter round trip";
815ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doTest("adoptFilter round trip", got, temp);
816ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
817ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    t->adoptFilter(new TestFilter2);
818ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    callEverything(t, __LINE__);
819ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    data="heelloe";
820ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    exp=UnicodeString("\\u0068eell\\u006Fe", "");
821ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    got = data;
822ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    t->transliterate(got);
823ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    message="transliteration using (e,l) filter";
824ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doTest("transliteration using (e,l) filter", got, exp);
825ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
826ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    data="are well";
827ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    exp=UnicodeString("\\u0061\\u0072e\\u0020\\u0077ell", "");
828ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    got = data;
829ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    t->transliterate(got);
830ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doTest(message, got, exp);
831ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
832ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    t->adoptFilter(new TestFilter3);
833ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    data="ho, wow!";
834ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    exp=UnicodeString("\\u0068o\\u002C\\u0020wow\\u0021", "");
835ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    got = data;
836ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    t->transliterate(got);
837ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    message="transliteration using (o,w) filter";
838ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doTest("transliteration using (o,w) filter", got, exp);
839ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
840ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    data="owl";
841ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    exp=UnicodeString("ow\\u006C", "");
842ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    got = data;
843ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    t->transliterate(got);
844ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    doTest("transliteration using (o,w) filter", got, exp);
845ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
846ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    delete t;
847ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
848ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
849ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
850ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
851ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
852ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TransliteratorAPITest::keyboardAux(Transliterator *t, UnicodeString DATA[], UnicodeString& s, int32_t begin, int32_t end) {
853ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UTransPosition index={0, 0, 0, 0};
854ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status=U_ZERO_ERROR;
855ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for (int32_t i=begin; i<end; i=i+5) {
856ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        UnicodeString log;
857ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (DATA[i+0] != "") {
858ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru             log = s + " + " + DATA[i] + " -> ";
859ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru             index.contextStart=getInt(DATA[i+2]);
860ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru             index.contextLimit=index.limit=getInt(DATA[i+3]);
861ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru             index.start=getInt(DATA[i+4]);
862ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru             t->transliterate(s, index, DATA[i+0], status);
863ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru             if(U_FAILURE(status)){
864ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                 errln("FAIL: " + t->getID()+ ".transliterate(Replaceable, int32_t[], UnicodeString, UErrorCode)-->" + (UnicodeString)u_errorName(status));
865ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru             continue;
866ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru             }
867ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           log = s + " => ";
868ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           t->finishTransliteration(s, index);
869ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
870ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         // Show the start index '{' and the cursor '|'
871ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru      displayOutput(s, DATA[i+1], log, index);
872ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
873ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
874ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
875ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
876ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TransliteratorAPITest::displayOutput(const UnicodeString& got, const UnicodeString& expected, UnicodeString& log, UTransPosition& index){
877ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // Show the start index '{' and the cursor '|'
878ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString a, b, c, d, e;
879ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    got.extractBetween(0, index.contextStart, a);
880ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    got.extractBetween(index.contextStart, index.start, b);
881ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    got.extractBetween(index.start, index.limit, c);
882ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    got.extractBetween(index.limit, index.contextLimit, d);
883ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    got.extractBetween(index.contextLimit, got.length(), e);
884ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    log.append(a).
885ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        append((UChar)0x7b/*{*/).
886ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        append(b).
887ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        append((UChar)0x7c/*|*/).
888ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        append(c).
889ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        append((UChar)0x7c).
890ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        append(d).
891ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        append((UChar)0x7d/*}*/).
892ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        append(e);
893ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (got == expected)
894ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        logln("OK:" + prettify(log));
895ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    else
896ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        errln("FAIL: " + prettify(log)  + ", expected " + prettify(expected));
897ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
898ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
899ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
900ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*Internal Functions used*/
901ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TransliteratorAPITest::doTest(const UnicodeString& message, const UnicodeString& result, const UnicodeString& expected){
902ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (prettify(result) == prettify(expected))
903ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        logln((UnicodeString)"Ok: " + prettify(message) + " passed \"" + prettify(expected) + "\"");
904ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    else
90585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        dataerrln((UnicodeString)"FAIL:" + message + " failed  Got-->" + prettify(result)+ ", Expected--> " + prettify(expected) );
906ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
907ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
908ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
909ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru//
910ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru//  callEverything    call all of the const (non-destructive) methods on a
911ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru//                    transliterator, just to verify that they don't fail in some
912ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru//                    destructive way.
913ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru//
914ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define CEASSERT(a) {if (!(a)) { \
915ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruerrln("FAIL at line %d from line %d: %s", __LINE__, line, #a);  return; }}
916ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
917ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TransliteratorAPITest::callEverything(const Transliterator *tr, int line) {
918ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    Transliterator *clonedTR = tr->clone();
919ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    CEASSERT(clonedTR != NULL);
920ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
921ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t  maxcl = tr->getMaximumContextLength();
922ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    CEASSERT(clonedTR->getMaximumContextLength() == maxcl);
923ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
924ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString id;
925ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString clonedId;
926ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    id = tr->getID();
927ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    clonedId = clonedTR->getID();
928ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    CEASSERT(id == clonedId);
929ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
930ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const UnicodeFilter *filter = tr->getFilter();
931ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const UnicodeFilter *clonedFilter = clonedTR->getFilter();
932ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (filter == NULL || clonedFilter == NULL) {
933ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        // If one filter is NULL they better both be NULL.
934ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        CEASSERT(filter == clonedFilter);
935ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
936ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        CEASSERT(filter != clonedFilter);
937ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
938ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
939ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString rules;
940ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString clonedRules;
941ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    rules = tr->toRules(rules, FALSE);
942ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    clonedRules = clonedTR->toRules(clonedRules, FALSE);
943ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    CEASSERT(rules == clonedRules);
944ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
945ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeSet sourceSet;
946ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeSet clonedSourceSet;
947ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    tr->getSourceSet(sourceSet);
948ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    clonedTR->getSourceSet(clonedSourceSet);
949ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    CEASSERT(clonedSourceSet == sourceSet);
950ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
951ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeSet targetSet;
952ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeSet clonedTargetSet;
953ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    tr->getTargetSet(targetSet);
954ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    clonedTR->getTargetSet(clonedTargetSet);
955ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    CEASSERT(targetSet == clonedTargetSet);
956ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
957ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UClassID classID = tr->getDynamicClassID();
958ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    CEASSERT(classID == clonedTR->getDynamicClassID());
959ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    CEASSERT(classID != 0);
960ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
961ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    delete clonedTR;
962ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
963ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
964ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic const int MyUnicodeFunctorTestClassID = 0;
965ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruclass MyUnicodeFunctorTestClass : public UnicodeFunctor {
966ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querupublic:
967ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual UnicodeFunctor* clone() const {return NULL;}
968ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static UClassID getStaticClassID(void) {return (UClassID)&MyUnicodeFunctorTestClassID;}
969ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual UClassID getDynamicClassID(void) const {return getStaticClassID();};
970ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual void setData(const TransliterationRuleData*) {}
971ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru};
972ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
973ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TransliteratorAPITest::TestUnicodeFunctor() {
974ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    MyUnicodeFunctorTestClass myClass;
975ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (myClass.toMatcher() != NULL) {
976ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        errln("FAIL: UnicodeFunctor::toMatcher did not return NULL");
977ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
978ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (myClass.toReplacer() != NULL) {
979ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        errln("FAIL: UnicodeFunctor::toReplacer did not return NULL");
980ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
981ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
982ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
983ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
984ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif /* #if !UCONFIG_NO_TRANSLITERATION */
985