/*
-*******************************************************************************
-* Copyright (C) 1997-2003, International Business Machines
-* Corporation and others. All Rights Reserved.
-*******************************************************************************
-* Date Name Description
-* 06/23/00 aliu Creation.
-*******************************************************************************
-*/
+ *******************************************************************************
+ * Copyright (C) 1997-2004, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ *******************************************************************************
+ * Date Name Description
+ * 06/23/00 aliu Creation.
+ *******************************************************************************
+ */
#include "unicode/utypes.h"
static void TestClone(void);
static void TestRegisterUnregister(void);
static void TestExtractBetween(void);
+static void TestUnicodeIDs(void);
static void _expectRules(const char*, const char*, const char*);
static void _expect(const UTransliterator* trans, const char* cfrom, const char* cto);
TEST(TestClone);
TEST(TestRegisterUnregister);
TEST(TestExtractBetween);
+ TEST(TestUnicodeIDs);
}
/*------------------------------------------------------------------
}
}
+static void TestUnicodeIDs() {
+ UEnumeration *uenum;
+ UTransliterator *utrans;
+ const UChar *id, *id2;
+ int32_t idLength, id2Length, count, count2;
+
+ UErrorCode errorCode;
+
+ errorCode=U_ZERO_ERROR;
+ uenum=utrans_openIDs(&errorCode);
+ if(U_FAILURE(errorCode)) {
+ log_err("utrans_openIDs() failed - %s\n", u_errorName(errorCode));
+ return;
+ }
+
+ count=uenum_count(uenum, &errorCode);
+ if(U_FAILURE(errorCode) || count<1) {
+ log_err("uenum_count(transliterator IDs)=%d - %s\n", count, u_errorName(errorCode));
+ }
+
+ count=0;
+ for(;;) {
+ id=uenum_unext(uenum, &idLength, &errorCode);
+ if(U_FAILURE(errorCode)) {
+ log_err("uenum_unext(transliterator ID %d) failed - %s\n", count, u_errorName(errorCode));
+ break;
+ }
+ if(id==NULL) {
+ break;
+ }
+
+ if(++count>10) {
+ /* try to actually open only a few transliterators */
+ continue;
+ }
+
+ utrans=utrans_openU(id, idLength, UTRANS_FORWARD, NULL, 0, NULL, &errorCode);
+ if(U_FAILURE(errorCode)) {
+ log_err("utrans_openU(%s) failed - %s\n", aescstrdup(id, idLength), u_errorName(errorCode));
+ continue;
+ }
+
+ id2=utrans_getUnicodeID(utrans, &id2Length);
+ if(idLength!=id2Length || 0!=u_memcmp(id, id2, idLength)) {
+ log_err("utrans_getUnicodeID(%s) does not match the original ID\n", aescstrdup(id, idLength));
+ }
+
+ utrans_close(utrans);
+ }
+
+ uenum_reset(uenum, &errorCode);
+ if(U_FAILURE(errorCode) || count<1) {
+ log_err("uenum_reset(transliterator IDs) failed - %s\n", u_errorName(errorCode));
+ } else {
+ count2=uenum_count(uenum, &errorCode);
+ if(U_FAILURE(errorCode) || count<1) {
+ log_err("2nd uenum_count(transliterator IDs)=%d - %s\n", count2, u_errorName(errorCode));
+ } else if(count!=count2) {
+ log_err("uenum_unext(transliterator IDs) returned %d IDs but uenum_count() after uenum_reset() claims there are %d\n", count, count2);
+ }
+ }
+
+ uenum_close(uenum);
+}
+
static void TestOpenInverse(){
UErrorCode status=U_ZERO_ERROR;
UTransliterator* t1=NULL;
static void TestRegisterUnregister(){
UErrorCode status=U_ZERO_ERROR;
UTransliterator* t1=NULL;
- UTransliterator* rules=NULL;
+ UTransliterator* rules=NULL, *rules2;
UTransliterator* inverse1=NULL;
UChar rule[]={ 0x0061, 0x003c, 0x003e, 0x0063}; /*a<>b*/
+ U_STRING_DECL(ID, "TestA-TestB", 11);
+ U_STRING_INIT(ID, "TestA-TestB", 11);
+
/* Make sure it doesn't exist */
t1=utrans_open("TestA-TestB", UTRANS_FORWARD,NULL,0,NULL, &status);
if(t1 != NULL || U_SUCCESS(status)) {
log_err("FAIL: utrans_openRules(a<>B) failed with error=%s\n", myErrorName(status));
return;
}
+
+ /* clone it so we can register it a second time */
+ rules2=utrans_clone(rules, &status);
+ if(U_FAILURE(status)) {
+ log_err("FAIL: utrans_clone(a<>B) failed with error=%s\n", myErrorName(status));
+ return;
+ }
+
status=U_ZERO_ERROR;
/* Register it */
utrans_register(rules, &status);
log_err("FAIL: TestA-TestB isn't unregistered\n");
return;
}
-
+ utrans_close(t1);
+
+ /* now with utrans_unregisterID(const UChar *) */
+ status=U_ZERO_ERROR;
+ utrans_register(rules2, &status);
+ if(U_FAILURE(status)){
+ log_err("FAIL: 2nd utrans_register failed with error=%s\n", myErrorName(status));
+ return;
+ }
+ status=U_ZERO_ERROR;
+ /* Now check again -- should exist now*/
+ t1= utrans_open("TestA-TestB", UTRANS_FORWARD, NULL,0,NULL,&status);
+ if(U_FAILURE(status) || t1 == NULL){
+ log_err("FAIL: 2nd TestA-TestB not registered\n");
+ return;
+ }
+ utrans_close(t1);
+
+ /*unregister the instance*/
+ status=U_ZERO_ERROR;
+ utrans_unregisterID(ID, -1);
+ /* now Make sure it doesn't exist */
+ t1=utrans_openU(ID, -1, UTRANS_FORWARD,NULL,0,NULL, &status);
+ if(U_SUCCESS(status) || t1 != NULL) {
+ log_err("FAIL: 2nd TestA-TestB isn't unregistered\n");
+ return;
+ }
+
utrans_close(t1);
utrans_close(inverse1);
}
UChar filt[128];
UChar buf[128];
UChar exp[128];
- char cbuf[128];
+ char *cbuf;
int32_t limit;
const char* DATA[] = {
"[^c]", /* Filter out 'c' */
for (i=0; i<DATA_length; i+=3) {
/*u_uastrcpy(filt, DATA[i]);*/
- u_charsToUChars(DATA[i], filt, strlen(DATA[i])+1);
+ u_charsToUChars(DATA[i], filt, (int32_t)strlen(DATA[i])+1);
utrans_setFilter(hex, filt, -1, &status);
if (U_FAILURE(status)) {
}
/*u_uastrcpy(buf, DATA[i+1]);*/
- u_charsToUChars(DATA[i+1], buf, strlen(DATA[i+1])+1);
+ u_charsToUChars(DATA[i+1], buf, (int32_t)strlen(DATA[i+1])+1);
limit = 5;
utrans_transUChars(hex, buf, NULL, 128, 0, &limit, &status);
goto exit;
}
- /*u_austrcpy(cbuf, buf);*/
- u_UCharsToChars(buf, cbuf, u_strlen(buf)+1);
- /*u_uastrcpy(exp, DATA[i+2]);*/
- u_charsToUChars(DATA[i+2], exp, strlen(DATA[i+2])+1);
+ cbuf=aescstrdup(buf, -1);
+ u_charsToUChars(DATA[i+2], exp, (int32_t)strlen(DATA[i+2])+1);
if (0 == u_strcmp(buf, exp)) {
log_verbose("Ok: %s | %s -> %s\n", DATA[i+1], DATA[i], cbuf);
} else {
UChar from[CAP];
UChar to[CAP];
UChar buf[CAP];
- char id[CAP];
+ const UChar *ID;
+ int32_t IDLength;
+ const char *id;
+
UErrorCode status = U_ZERO_ERROR;
int32_t limit;
UTransPosition pos;
u_uastrcpy(from, cfrom);
u_uastrcpy(to, cto);
- utrans_getID(trans, id, CAP);
+ ID = utrans_getUnicodeID(trans, &IDLength);
+ id = aescstrdup(ID, IDLength);
/* utrans_transUChars() */
u_strcpy(buf, from);