/*
*******************************************************************************
- * Copyright (C) 1997-2004, International Business Machines
+ * Copyright (C) 1997-2009,2014 International Business Machines
* Corporation and others. All Rights Reserved.
*******************************************************************************
* Date Name Description
#include <string.h>
#include "unicode/utrans.h"
#include "unicode/ustring.h"
+#include "unicode/uset.h"
#include "cintltst.h"
#define TEST(x) addTest(root, &x, "utrans/" # x)
static void TestRegisterUnregister(void);
static void TestExtractBetween(void);
static void TestUnicodeIDs(void);
+static void TestGetRulesAndSourceSet(void);
static void _expectRules(const char*, const char*, const char*);
static void _expect(const UTransliterator* trans, const char* cfrom, const char* cto);
TEST(TestRegisterUnregister);
TEST(TestExtractBetween);
TEST(TestUnicodeIDs);
+ TEST(TestGetRulesAndSourceSet);
}
/*------------------------------------------------------------------
status = U_ZERO_ERROR;
t1=utrans_open(TransID[i], UTRANS_FORWARD,NULL,0,NULL, &status);
if(t1 == NULL || U_FAILURE(status)){
- log_err("FAIL: in instantiation for id=%s\n", TransID[i]);
+ log_data_err("FAIL: in instantiation for id=%s -> %s (Are you missing data?)\n", TransID[i], u_errorName(status));
continue;
}
inverse1=utrans_openInverse(t1, &status);
t1=utrans_open("Latin-Devanagari", UTRANS_FORWARD, NULL,0,NULL,&status);
if(U_FAILURE(status)){
- log_err("FAIL: construction\n");
+ log_data_err("FAIL: construction -> %s (Are you missing data?)\n", u_errorName(status));
return;
}
t2=utrans_open("Latin-Greek", UTRANS_FORWARD, NULL,0,NULL,&status);
"$lu > '*';"
"a > ERROR",
"abcdefgABCDEFGU", "&bcd&fg!^**!^*&");
+
+ /* Test multiple passes
+ */
+ _expectRules("abc > xy;"
+ "::Null;"
+ "aba > z;",
+ "abc ababc aba", "xy abxy z");
}
static void TestFilter() {
}
}
+/**
+ * Test utrans_toRules, utrans_getSourceSet
+ */
+
+/* A simple transform with a small filter & source set: rules 50-100 chars unescaped, 100-200 chars escaped,
+ filter & source set 4-20 chars */
+static const UChar transSimpleID[] = { 0x79,0x6F,0x2D,0x79,0x6F,0x5F,0x42,0x4A,0 }; /* "yo-yo_BJ" */
+static const char* transSimpleCName = "yo-yo_BJ";
+
+enum { kUBufMax = 256 };
+static void TestGetRulesAndSourceSet() {
+ UErrorCode status = U_ZERO_ERROR;
+ UTransliterator *utrans = utrans_openU(transSimpleID, -1, UTRANS_FORWARD, NULL, 0, NULL, &status);
+ if ( U_SUCCESS(status) ) {
+ USet* uset;
+ UChar ubuf[kUBufMax];
+ int32_t ulen;
+
+ status = U_ZERO_ERROR;
+ ulen = utrans_toRules(utrans, FALSE, ubuf, kUBufMax, &status);
+ if ( U_FAILURE(status) || ulen <= 50 || ulen >= 100) {
+ log_err("FAIL: utrans_toRules unescaped, expected noErr and len 50-100, got error=%s and len=%d\n",
+ u_errorName(status), ulen);
+ }
+
+ status = U_ZERO_ERROR;
+ ulen = utrans_toRules(utrans, FALSE, NULL, 0, &status);
+ if ( status != U_BUFFER_OVERFLOW_ERROR || ulen <= 50 || ulen >= 100) {
+ log_err("FAIL: utrans_toRules unescaped, expected U_BUFFER_OVERFLOW_ERROR and len 50-100, got error=%s and len=%d\n",
+ u_errorName(status), ulen);
+ }
+
+ status = U_ZERO_ERROR;
+ ulen = utrans_toRules(utrans, TRUE, ubuf, kUBufMax, &status);
+ if ( U_FAILURE(status) || ulen <= 100 || ulen >= 200) {
+ log_err("FAIL: utrans_toRules escaped, expected noErr and len 100-200, got error=%s and len=%d\n",
+ u_errorName(status), ulen);
+ }
+
+ status = U_ZERO_ERROR;
+ uset = utrans_getSourceSet(utrans, FALSE, NULL, &status);
+ ulen = uset_toPattern(uset, ubuf, kUBufMax, FALSE, &status);
+ uset_close(uset);
+ if ( U_FAILURE(status) || ulen <= 4 || ulen >= 20) {
+ log_err("FAIL: utrans_getSourceSet useFilter, expected noErr and len 4-20, got error=%s and len=%d\n",
+ u_errorName(status), ulen);
+ }
+
+ status = U_ZERO_ERROR;
+ uset = utrans_getSourceSet(utrans, TRUE, NULL, &status);
+ ulen = uset_toPattern(uset, ubuf, kUBufMax, FALSE, &status);
+ uset_close(uset);
+ if ( U_FAILURE(status) || ulen <= 4 || ulen >= 20) {
+ log_err("FAIL: utrans_getSourceSet ignoreFilter, expected noErr and len 4-20, got error=%s and len=%d\n",
+ u_errorName(status), ulen);
+ }
+
+ utrans_close(utrans);
+ } else {
+ log_data_err("FAIL: utrans_openRules(%s) failed, error=%s (Are you missing data?)\n",
+ transSimpleCName, u_errorName(status));
+ }
+}
+
+
static void _expectRules(const char* crules,
const char* cfrom,
const char* cto) {
&parseErr, &status);
if (U_FAILURE(status)) {
utrans_close(trans);
- log_err("FAIL: utrans_openRules(%s) failed, error=%s\n",
+ log_data_err("FAIL: utrans_openRules(%s) failed, error=%s (Are you missing data?)\n",
crules, u_errorName(status));
return;
}
int32_t limit;
UTransPosition pos;
XReplaceable xrep;
+ XReplaceable *xrepPtr = &xrep;
UReplaceableCallbacks xrepVtable;
u_uastrcpy(from, cfrom);
InitXReplaceableCallbacks(&xrepVtable);
InitXReplaceable(&xrep, cfrom);
limit = u_strlen(from);
- utrans_trans(trans, (UReplaceable*)&xrep, &xrepVtable, 0, &limit, &status);
+ utrans_trans(trans, (UReplaceable*)xrepPtr, &xrepVtable, 0, &limit, &status);
if (U_FAILURE(status)) {
log_err("FAIL: utrans_trans() failed, error=%s\n",
u_errorName(status));
InitXReplaceable(&xrep, cfrom);
pos.start = pos.contextStart = 0;
pos.limit = pos.contextLimit = u_strlen(from);
- utrans_transIncremental(trans, (UReplaceable*)&xrep, &xrepVtable, &pos, &status);
- utrans_trans(trans, (UReplaceable*)&xrep, &xrepVtable, pos.start, &pos.limit, &status);
+ utrans_transIncremental(trans, (UReplaceable*)xrepPtr, &xrepVtable, &pos, &status);
+ utrans_trans(trans, (UReplaceable*)xrepPtr, &xrepVtable, pos.start, &pos.limit, &status);
if (U_FAILURE(status)) {
log_err("FAIL: utrans_transIncremental() failed, error=%s\n",
u_errorName(status));