1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*
2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *******************************************************************************
385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho *   Copyright (C) 1997-2009, International Business Machines
4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *   Corporation and others.  All Rights Reserved.
5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *******************************************************************************
6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *   Date        Name        Description
7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *   06/23/00    aliu        Creation.
8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *******************************************************************************
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 <stdlib.h>
16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <string.h>
17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utrans.h"
18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/ustring.h"
19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cintltst.h"
20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define TEST(x) addTest(root, &x, "utrans/" # x)
22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestAPI(void);
24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestSimpleRules(void);
25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestFilter(void);
26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestOpenInverse(void);
27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestClone(void);
28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestRegisterUnregister(void);
29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestExtractBetween(void);
30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestUnicodeIDs(void);
31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void _expectRules(const char*, const char*, const char*);
33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void _expect(const UTransliterator* trans, const char* cfrom, const char* cto);
34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid addUTransTest(TestNode** root);
36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid
39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruaddUTransTest(TestNode** root) {
40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TEST(TestAPI);
41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TEST(TestSimpleRules);
42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TEST(TestFilter);
43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TEST(TestOpenInverse);
44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TEST(TestClone);
45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TEST(TestRegisterUnregister);
46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TEST(TestExtractBetween);
47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TEST(TestUnicodeIDs);
48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*------------------------------------------------------------------
51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Replaceable glue
52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *
53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * To test the Replaceable glue we have to dummy up a C-based
54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Replaceable callback.  This code is for testing purposes only.
55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *------------------------------------------------------------------*/
56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querutypedef struct XReplaceable {
58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar* text;    /* MUST BE null-terminated */
59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} XReplaceable;
60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void InitXReplaceable(XReplaceable* rep, const char* cstring) {
62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    rep->text = malloc(sizeof(UChar) * (strlen(cstring)+1));
63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(rep->text, cstring);
64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void FreeXReplaceable(XReplaceable* rep) {
67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (rep->text != NULL) {
68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        free(rep->text);
69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        rep->text = NULL;
70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* UReplaceableCallbacks callback */
74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic int32_t Xlength(const UReplaceable* rep) {
75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const XReplaceable* x = (const XReplaceable*)rep;
76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return u_strlen(x->text);
77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* UReplaceableCallbacks callback */
80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic UChar XcharAt(const UReplaceable* rep, int32_t offset) {
81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const XReplaceable* x = (const XReplaceable*)rep;
82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return x->text[offset];
83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* UReplaceableCallbacks callback */
86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic UChar32 Xchar32At(const UReplaceable* rep, int32_t offset) {
87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const XReplaceable* x = (const XReplaceable*)rep;
88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return x->text[offset];
89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* UReplaceableCallbacks callback */
92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void Xreplace(UReplaceable* rep, int32_t start, int32_t limit,
93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru              const UChar* text, int32_t textLength) {
94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    XReplaceable* x = (XReplaceable*)rep;
95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t newLen = Xlength(rep) + limit - start + textLength;
96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar* newText = (UChar*) malloc(sizeof(UChar) * (newLen+1));
97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_strncpy(newText, x->text, start);
98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_strncpy(newText + start, text, textLength);
99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_strcpy(newText + start + textLength, x->text + limit);
100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(x->text);
101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    x->text = newText;
102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* UReplaceableCallbacks callback */
105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void Xcopy(UReplaceable* rep, int32_t start, int32_t limit, int32_t dest) {
106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    XReplaceable* x = (XReplaceable*)rep;
107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t newLen = Xlength(rep) + limit - start;
108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar* newText = (UChar*) malloc(sizeof(UChar) * (newLen+1));
109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_strncpy(newText, x->text, dest);
110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_strncpy(newText + dest, x->text + start, limit - start);
111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_strcpy(newText + dest + limit - start, x->text + dest);
112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    free(x->text);
113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    x->text = newText;
114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* UReplaceableCallbacks callback */
117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void Xextract(UReplaceable* rep, int32_t start, int32_t limit, UChar* dst) {
118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    XReplaceable* x = (XReplaceable*)rep;
119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t len = limit - start;
120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_strncpy(dst, x->text, len);
121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void InitXReplaceableCallbacks(UReplaceableCallbacks* callbacks) {
124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    callbacks->length = Xlength;
125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    callbacks->charAt = XcharAt;
126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    callbacks->char32At = Xchar32At;
127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    callbacks->replace = Xreplace;
128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    callbacks->extract = Xextract;
129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    callbacks->copy = Xcopy;
130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*------------------------------------------------------------------
133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Tests
134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *------------------------------------------------------------------*/
135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestAPI() {
137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    enum { BUF_CAP = 128 };
138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char buf[BUF_CAP], buf2[BUF_CAP];
139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UTransliterator* trans = NULL;
141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t i, n;
142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Test getAvailableIDs */
144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    n = utrans_countAvailableIDs();
145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (n < 1) {
146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: utrans_countAvailableIDs() returned %d\n", n);
147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("System ID count: %d\n", n);
149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for (i=0; i<n; ++i) {
151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        utrans_getAvailableID(i, buf, BUF_CAP);
152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (*buf == 0) {
153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("FAIL: System transliterator %d: \"\"\n", i);
154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        } else {
155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_verbose("System transliterator %d: \"%s\"\n", i, buf);
156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Test open */
160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    utrans_getAvailableID(0, buf, BUF_CAP);
161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    trans = utrans_open(buf, UTRANS_FORWARD,NULL,0,NULL, &status);
162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: utrans_open(%s) failed, error=%s\n",
164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                buf, u_errorName(status));
165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    else {
168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* Test getID */
169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        utrans_getID(trans, buf2, BUF_CAP);
170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (0 != strcmp(buf, buf2)) {
171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("FAIL: utrans_getID(%s) returned %s\n",
172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    buf, buf2);
173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        utrans_close(trans);
175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestUnicodeIDs() {
179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UEnumeration *uenum;
180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UTransliterator *utrans;
181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const UChar *id, *id2;
182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t idLength, id2Length, count, count2;
183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode errorCode;
185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    errorCode=U_ZERO_ERROR;
187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uenum=utrans_openIDs(&errorCode);
188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(errorCode)) {
189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("utrans_openIDs() failed - %s\n", u_errorName(errorCode));
190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    count=uenum_count(uenum, &errorCode);
194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(errorCode) || count<1) {
195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("uenum_count(transliterator IDs)=%d - %s\n", count, u_errorName(errorCode));
196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
197ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    count=0;
199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for(;;) {
200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        id=uenum_unext(uenum, &idLength, &errorCode);
201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(U_FAILURE(errorCode)) {
202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("uenum_unext(transliterator ID %d) failed - %s\n", count, u_errorName(errorCode));
203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            break;
204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(id==NULL) {
206ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            break;
207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(++count>10) {
210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            /* try to actually open only a few transliterators */
211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            continue;
212ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
214ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        utrans=utrans_openU(id, idLength, UTRANS_FORWARD, NULL, 0, NULL, &errorCode);
215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(U_FAILURE(errorCode)) {
216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("utrans_openU(%s) failed - %s\n", aescstrdup(id, idLength), u_errorName(errorCode));
217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            continue;
218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        id2=utrans_getUnicodeID(utrans, &id2Length);
221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(idLength!=id2Length || 0!=u_memcmp(id, id2, idLength)) {
222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("utrans_getUnicodeID(%s) does not match the original ID\n", aescstrdup(id, idLength));
223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        utrans_close(utrans);
226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uenum_reset(uenum, &errorCode);
229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(errorCode) || count<1) {
230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("uenum_reset(transliterator IDs) failed - %s\n", u_errorName(errorCode));
231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        count2=uenum_count(uenum, &errorCode);
233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(U_FAILURE(errorCode) || count<1) {
234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("2nd uenum_count(transliterator IDs)=%d - %s\n", count2, u_errorName(errorCode));
235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        } else if(count!=count2) {
236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("uenum_unext(transliterator IDs) returned %d IDs but uenum_count() after uenum_reset() claims there are %d\n", count, count2);
237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    uenum_close(uenum);
241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestOpenInverse(){
244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status=U_ZERO_ERROR;
245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UTransliterator* t1=NULL;
246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UTransliterator* inverse1=NULL;
247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    enum { BUF_CAP = 128 };
248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char buf1[BUF_CAP];
249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t i=0;
250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char TransID[][25]={
252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           "Halfwidth-Fullwidth",
253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           "Fullwidth-Halfwidth",
254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           "Greek-Latin" ,
255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           "Latin-Greek",
256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           /*"Arabic-Latin", // Removed in 2.0*/
257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           /*"Latin-Arabic", // Removed in 2.0*/
258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           "Katakana-Latin",
259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           "Latin-Katakana",
260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           /*"Hebrew-Latin", // Removed in 2.0*/
261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           /*"Latin-Hebrew", // Removed in 2.0*/
262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           "Cyrillic-Latin",
263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           "Latin-Cyrillic",
264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           "Devanagari-Latin",
265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           "Latin-Devanagari",
266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           "Any-Hex",
267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru           "Hex-Any"
268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         };
269ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
270ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for(i=0; i<sizeof(TransID)/sizeof(TransID[0]); i=i+2){
271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        status = U_ZERO_ERROR;
272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        t1=utrans_open(TransID[i], UTRANS_FORWARD,NULL,0,NULL, &status);
273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(t1 == NULL || U_FAILURE(status)){
27485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            log_data_err("FAIL: in instantiation for id=%s -> %s (Are you missing data?)\n", TransID[i], u_errorName(status));
275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            continue;
276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
277ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        inverse1=utrans_openInverse(t1, &status);
278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(U_FAILURE(status)){
279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("FAIL: utrans_openInverse() failed for id=%s. Error=%s\n", TransID[i], myErrorName(status));
280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            continue;
281ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
282ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        utrans_getID(inverse1, buf1, BUF_CAP);
283ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if(strcmp(buf1, TransID[i+1]) != 0){
284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("FAIL :openInverse() for %s returned %s instead of %s\n", TransID[i], buf1, TransID[i+1]);
285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
286ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        utrans_close(t1);
287ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        utrans_close(inverse1);
288ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru   }
289ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
290ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
291ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestClone(){
292ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status=U_ZERO_ERROR;
293ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UTransliterator* t1=NULL;
294ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UTransliterator* t2=NULL;
295ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UTransliterator* t3=NULL;
296ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UTransliterator* t4=NULL;
297ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    enum { BUF_CAP = 128 };
298ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char buf1[BUF_CAP], buf2[BUF_CAP], buf3[BUF_CAP];
299ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
300ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    t1=utrans_open("Latin-Devanagari", UTRANS_FORWARD, NULL,0,NULL,&status);
301ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)){
30285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_data_err("FAIL: construction -> %s (Are you missing data?)\n", u_errorName(status));
303ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
304ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
305ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    t2=utrans_open("Latin-Greek", UTRANS_FORWARD, NULL,0,NULL,&status);
306ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)){
307ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: construction\n");
308ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        utrans_close(t1);
309ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
310ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
311ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
312ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    t3=utrans_clone(t1, &status);
313ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    t4=utrans_clone(t2, &status);
314ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
315ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    utrans_getID(t1, buf1, BUF_CAP);
316ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    utrans_getID(t2, buf2, BUF_CAP);
317ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    utrans_getID(t3, buf3, BUF_CAP);
318ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
319ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(strcmp(buf1, buf3) != 0 ||
320ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        strcmp(buf1, buf2) == 0) {
321ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: utrans_clone() failed\n");
322ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
323ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
324ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    utrans_getID(t4, buf3, BUF_CAP);
325ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
326ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(strcmp(buf2, buf3) != 0 ||
327ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        strcmp(buf1, buf3) == 0) {
328ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: utrans_clone() failed\n");
329ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
330ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
331ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    utrans_close(t1);
332ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    utrans_close(t2);
333ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    utrans_close(t3);
334ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    utrans_close(t4);
335ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
336ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
337ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
338ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestRegisterUnregister(){
339ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status=U_ZERO_ERROR;
340ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UTransliterator* t1=NULL;
341ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UTransliterator* rules=NULL, *rules2;
342ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UTransliterator* inverse1=NULL;
343ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar rule[]={ 0x0061, 0x003c, 0x003e, 0x0063}; /*a<>b*/
344ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
345ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    U_STRING_DECL(ID, "TestA-TestB", 11);
346ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    U_STRING_INIT(ID, "TestA-TestB", 11);
347ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
348ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Make sure it doesn't exist */
349ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    t1=utrans_open("TestA-TestB", UTRANS_FORWARD,NULL,0,NULL, &status);
350ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(t1 != NULL || U_SUCCESS(status)) {
351ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: TestA-TestB already registered\n");
352ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
353ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
354ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    status=U_ZERO_ERROR;
355ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Check inverse too */
356ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    inverse1=utrans_open("TestA-TestB", UTRANS_REVERSE, NULL,0,NULL,&status);
357ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(inverse1 != NULL || U_SUCCESS(status)) {
358ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: TestA-TestB already registered\n");
359ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
360ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
361ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    status=U_ZERO_ERROR;
362ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Create it */
363ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    rules=utrans_open("TestA-TestB",UTRANS_FORWARD, rule, 4, NULL, &status);
364ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)){
365ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: utrans_openRules(a<>B) failed with error=%s\n", myErrorName(status));
366ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
367ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
368ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
369ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* clone it so we can register it a second time */
370ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    rules2=utrans_clone(rules, &status);
371ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)) {
372ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: utrans_clone(a<>B) failed with error=%s\n", myErrorName(status));
373ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
374ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
375ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
376ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    status=U_ZERO_ERROR;
377ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Register it */
378ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    utrans_register(rules, &status);
379ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)){
380ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: utrans_register failed with error=%s\n", myErrorName(status));
381ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
382ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
383ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    status=U_ZERO_ERROR;
384ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Now check again -- should exist now*/
385ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    t1= utrans_open("TestA-TestB", UTRANS_FORWARD, NULL,0,NULL,&status);
386ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status) || t1 == NULL){
387ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: TestA-TestB not registered\n");
388ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
389ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
390ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    utrans_close(t1);
391ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
392ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*unregister the instance*/
393ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    status=U_ZERO_ERROR;
394ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    utrans_unregister("TestA-TestB");
395ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* now Make sure it doesn't exist */
396ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    t1=utrans_open("TestA-TestB", UTRANS_FORWARD,NULL,0,NULL, &status);
397ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_SUCCESS(status) || t1 != NULL) {
398ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: TestA-TestB isn't unregistered\n");
399ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
400ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
401ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    utrans_close(t1);
402ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
403ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* now with utrans_unregisterID(const UChar *) */
404ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    status=U_ZERO_ERROR;
405ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    utrans_register(rules2, &status);
406ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status)){
407ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: 2nd utrans_register failed with error=%s\n", myErrorName(status));
408ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
409ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
410ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    status=U_ZERO_ERROR;
411ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Now check again -- should exist now*/
412ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    t1= utrans_open("TestA-TestB", UTRANS_FORWARD, NULL,0,NULL,&status);
413ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_FAILURE(status) || t1 == NULL){
414ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: 2nd TestA-TestB not registered\n");
415ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
416ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
417ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    utrans_close(t1);
418ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
419ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /*unregister the instance*/
420ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    status=U_ZERO_ERROR;
421ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    utrans_unregisterID(ID, -1);
422ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* now Make sure it doesn't exist */
423ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    t1=utrans_openU(ID, -1, UTRANS_FORWARD,NULL,0,NULL, &status);
424ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if(U_SUCCESS(status) || t1 != NULL) {
425ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: 2nd TestA-TestB isn't unregistered\n");
426ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
427ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
428ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
429ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    utrans_close(t1);
430ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    utrans_close(inverse1);
431ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
432ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
433ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestSimpleRules() {
434ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Test rules */
435ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Example: rules 1. ab>x|y
436ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *                2. yc>z
437ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *
438ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * []|eabcd  start - no match, copy e to tranlated buffer
439ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * [e]|abcd  match rule 1 - copy output & adjust cursor
440ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * [ex|y]cd  match rule 2 - copy output & adjust cursor
441ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * [exz]|d   no match, copy d to transliterated buffer
442ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * [exzd]|   done
443ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
444ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    _expectRules("ab>x|y;"
445ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                 "yc>z",
446ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                 "eabcd", "exzd");
447ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
448ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Another set of rules:
449ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *    1. ab>x|yzacw
450ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *    2. za>q
451ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *    3. qc>r
452ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *    4. cw>n
453ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *
454ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * []|ab       Rule 1
455ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * [x|yzacw]   No match
456ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * [xy|zacw]   Rule 2
457ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * [xyq|cw]    Rule 4
458ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * [xyqn]|     Done
459ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
460ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    _expectRules("ab>x|yzacw;"
461ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                 "za>q;"
462ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                 "qc>r;"
463ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                 "cw>n",
464ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                 "ab", "xyqn");
465ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
466ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Test categories
467ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
468ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    _expectRules("$dummy=" "\\uE100" ";" /* careful here with E100 */
469ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                 "$vowel=[aeiouAEIOU];"
470ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                 "$lu=[:Lu:];"
471ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                 "$vowel } $lu > '!';"
472ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                 "$vowel > '&';"
473ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                 "'!' { $lu > '^';"
474ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                 "$lu > '*';"
475ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                 "a > ERROR",
476ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                 "abcdefgABCDEFGU", "&bcd&fg!^**!^*&");
47785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
47885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    /* Test multiple passes
47985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    */
48085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    _expectRules("abc > xy;"
48185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                 "::Null;"
48285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                 "aba > z;",
48385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                 "abc ababc aba", "xy abxy z");
484ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
485ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
486ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestFilter() {
487ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
488ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar filt[128];
489ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar buf[128];
490ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar exp[128];
491ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    char *cbuf;
492ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t limit;
493ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char* DATA[] = {
494ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "[^c]", /* Filter out 'c' */
495ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "abcde",
496ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "\\u0061\\u0062c\\u0064\\u0065",
497ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
498ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "", /* No filter */
499ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "abcde",
500ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        "\\u0061\\u0062\\u0063\\u0064\\u0065"
501ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    };
502ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t DATA_length = sizeof(DATA) / sizeof(DATA[0]);
503ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t i;
504ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
505ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UTransliterator* hex = utrans_open("Any-Hex", UTRANS_FORWARD, NULL,0,NULL,&status);
506ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
507ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (hex == 0 || U_FAILURE(status)) {
508ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: utrans_open(Unicode-Hex) failed, error=%s\n",
509ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                u_errorName(status));
510ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        goto exit;
511ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
512ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
513ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for (i=0; i<DATA_length; i+=3) {
514ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /*u_uastrcpy(filt, DATA[i]);*/
515ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        u_charsToUChars(DATA[i], filt, (int32_t)strlen(DATA[i])+1);
516ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        utrans_setFilter(hex, filt, -1, &status);
517ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
518ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (U_FAILURE(status)) {
519ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("FAIL: utrans_setFilter() failed, error=%s\n",
520ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    u_errorName(status));
521ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            goto exit;
522ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
523ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
524ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /*u_uastrcpy(buf, DATA[i+1]);*/
525ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        u_charsToUChars(DATA[i+1], buf, (int32_t)strlen(DATA[i+1])+1);
526ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        limit = 5;
527ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        utrans_transUChars(hex, buf, NULL, 128, 0, &limit, &status);
528ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
529ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (U_FAILURE(status)) {
530ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("FAIL: utrans_transUChars() failed, error=%s\n",
531ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    u_errorName(status));
532ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            goto exit;
533ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
534ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
535ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        cbuf=aescstrdup(buf, -1);
536ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        u_charsToUChars(DATA[i+2], exp, (int32_t)strlen(DATA[i+2])+1);
537ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (0 == u_strcmp(buf, exp)) {
538ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_verbose("Ok: %s | %s -> %s\n", DATA[i+1], DATA[i], cbuf);
539ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        } else {
540ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            log_err("FAIL: %s | %s -> %s, expected %s\n", DATA[i+1], DATA[i], cbuf, DATA[i+2]);
541ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
542ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
543ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
544ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru exit:
545ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    utrans_close(hex);
546ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
547ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
548ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
549ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Test the UReplaceableCallback extractBetween support.  We use a
550ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * transliterator known to rely on this call.
551ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
552ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void TestExtractBetween() {
553ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
554ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UTransliterator *trans;
555ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
556ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UParseError parseErr;
557ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
558ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    trans = utrans_open("Lower", UTRANS_FORWARD, NULL, -1,
559ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                        &parseErr, &status);
560ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
561ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
562ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: utrans_open(Lower) failed, error=%s\n",
563ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                u_errorName(status));
564ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
565ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        _expect(trans, "ABC", "abc");
566ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
567ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        utrans_close(trans);
568ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
569ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
570ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
571ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void _expectRules(const char* crules,
572ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                  const char* cfrom,
573ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                  const char* cto) {
574ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* u_uastrcpy has no capacity param for the buffer -- so just
575ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * make all buffers way too big */
576ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    enum { CAP = 256 };
577ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar rules[CAP];
578ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UTransliterator *trans;
579ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
580ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UParseError parseErr;
581ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
582ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(rules, crules);
583ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
584ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    trans = utrans_open(crules /*use rules as ID*/, UTRANS_FORWARD, rules, -1,
585ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                             &parseErr, &status);
586ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
587ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        utrans_close(trans);
58885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        log_data_err("FAIL: utrans_openRules(%s) failed, error=%s (Are you missing data?)\n",
589ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                crules, u_errorName(status));
590ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
591ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
592ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
593ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    _expect(trans, cfrom, cto);
594ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
595ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    utrans_close(trans);
596ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
597ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
598ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void _expect(const UTransliterator* trans,
599ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru             const char* cfrom,
600ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru             const char* cto) {
601ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* u_uastrcpy has no capacity param for the buffer -- so just
602ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * make all buffers way too big */
603ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    enum { CAP = 256 };
604ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar from[CAP];
605ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar to[CAP];
606ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar buf[CAP];
607ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const UChar *ID;
608ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t IDLength;
609ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const char *id;
610ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
611ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
612ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t limit;
613ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UTransPosition pos;
614ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    XReplaceable xrep;
615ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    XReplaceable *xrepPtr = &xrep;
616ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UReplaceableCallbacks xrepVtable;
617ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
618ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(from, cfrom);
619ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_uastrcpy(to, cto);
620ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
621ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ID = utrans_getUnicodeID(trans, &IDLength);
622ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    id = aescstrdup(ID, IDLength);
623ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
624ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* utrans_transUChars() */
625ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_strcpy(buf, from);
626ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    limit = u_strlen(buf);
627ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    utrans_transUChars(trans, buf, NULL, CAP, 0, &limit, &status);
628ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
629ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: utrans_transUChars() failed, error=%s\n",
630ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                u_errorName(status));
631ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
632ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
633ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
634ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (0 == u_strcmp(buf, to)) {
635ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("Ok: utrans_transUChars(%s) x %s -> %s\n",
636ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    id, cfrom, cto);
637ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
638ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        char actual[CAP];
639ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        u_austrcpy(actual, buf);
640ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: utrans_transUChars(%s) x %s -> %s, expected %s\n",
641ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                id, cfrom, actual, cto);
642ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
643ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
644ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* utrans_transIncrementalUChars() */
645ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_strcpy(buf, from);
646ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    pos.start = pos.contextStart = 0;
647ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    pos.limit = pos.contextLimit = u_strlen(buf);
648ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    utrans_transIncrementalUChars(trans, buf, NULL, CAP, &pos, &status);
649ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    utrans_transUChars(trans, buf, NULL, CAP, pos.start, &pos.limit, &status);
650ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
651ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: utrans_transIncrementalUChars() failed, error=%s\n",
652ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                u_errorName(status));
653ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
654ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
655ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
656ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (0 == u_strcmp(buf, to)) {
657ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("Ok: utrans_transIncrementalUChars(%s) x %s -> %s\n",
658ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    id, cfrom, cto);
659ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
660ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        char actual[CAP];
661ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        u_austrcpy(actual, buf);
662ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: utrans_transIncrementalUChars(%s) x %s -> %s, expected %s\n",
663ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                id, cfrom, actual, cto);
664ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
665ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
666ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* utrans_trans() */
667ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    InitXReplaceableCallbacks(&xrepVtable);
668ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    InitXReplaceable(&xrep, cfrom);
669ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    limit = u_strlen(from);
670ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    utrans_trans(trans, (UReplaceable*)xrepPtr, &xrepVtable, 0, &limit, &status);
671ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
672ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: utrans_trans() failed, error=%s\n",
673ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                u_errorName(status));
674ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        FreeXReplaceable(&xrep);
675ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
676ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
677ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
678ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (0 == u_strcmp(xrep.text, to)) {
679ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("Ok: utrans_trans(%s) x %s -> %s\n",
680ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    id, cfrom, cto);
681ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
682ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        char actual[CAP];
683ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        u_austrcpy(actual, xrep.text);
684ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: utrans_trans(%s) x %s -> %s, expected %s\n",
685ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                id, cfrom, actual, cto);
686ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
687ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    FreeXReplaceable(&xrep);
688ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
689ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* utrans_transIncremental() */
690ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    InitXReplaceable(&xrep, cfrom);
691ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    pos.start = pos.contextStart = 0;
692ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    pos.limit = pos.contextLimit = u_strlen(from);
693ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    utrans_transIncremental(trans, (UReplaceable*)xrepPtr, &xrepVtable, &pos, &status);
694ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    utrans_trans(trans, (UReplaceable*)xrepPtr, &xrepVtable, pos.start, &pos.limit, &status);
695ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
696ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: utrans_transIncremental() failed, error=%s\n",
697ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                u_errorName(status));
698ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        FreeXReplaceable(&xrep);
699ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
700ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
701ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
702ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (0 == u_strcmp(xrep.text, to)) {
703ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_verbose("Ok: utrans_transIncremental(%s) x %s -> %s\n",
704ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                    id, cfrom, cto);
705ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
706ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        char actual[CAP];
707ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        u_austrcpy(actual, xrep.text);
708ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        log_err("FAIL: utrans_transIncremental(%s) x %s -> %s, expected %s\n",
709ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                id, cfrom, actual, cto);
710ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
711ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    FreeXReplaceable(&xrep);
712ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
713ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
714ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif /* #if !UCONFIG_NO_TRANSLITERATION */
715