2002-06-04 23:31:13 +00:00
|
|
|
/*
|
|
|
|
**********************************************************************
|
2004-05-19 21:19:13 +00:00
|
|
|
* Copyright (c) 2002-2004, International Business Machines
|
2002-06-04 23:31:13 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
**********************************************************************
|
|
|
|
*/
|
|
|
|
#include "unicode/uset.h"
|
|
|
|
#include "unicode/ustring.h"
|
2003-04-23 05:49:02 +00:00
|
|
|
#include "cintltst.h"
|
2003-04-24 22:38:45 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2002-06-04 23:31:13 +00:00
|
|
|
|
2003-05-10 23:10:09 +00:00
|
|
|
#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
|
|
|
|
|
2002-06-04 23:31:13 +00:00
|
|
|
#define TEST(x) addTest(root, &x, "uset/" # x)
|
|
|
|
|
|
|
|
static void TestAPI(void);
|
2002-08-29 23:16:45 +00:00
|
|
|
static void Testj2269(void);
|
2003-05-10 23:10:09 +00:00
|
|
|
static void TestSerialized(void);
|
2004-06-01 17:31:17 +00:00
|
|
|
static void TestNonInvariantPattern(void);
|
2004-12-28 21:43:33 +00:00
|
|
|
static void TestBadPattern(void);
|
2002-06-04 23:31:13 +00:00
|
|
|
|
|
|
|
void addUSetTest(TestNode** root);
|
|
|
|
|
|
|
|
static void expect(const USet* set,
|
|
|
|
const char* inList,
|
|
|
|
const char* outList,
|
|
|
|
UErrorCode* ec);
|
|
|
|
static void expectContainment(const USet* set,
|
|
|
|
const char* list,
|
|
|
|
UBool isIn);
|
|
|
|
static char oneUCharToChar(UChar32 c);
|
|
|
|
static void expectItems(const USet* set,
|
|
|
|
const char* items);
|
|
|
|
|
|
|
|
void
|
|
|
|
addUSetTest(TestNode** root) {
|
|
|
|
TEST(TestAPI);
|
2002-08-29 23:16:45 +00:00
|
|
|
TEST(Testj2269);
|
2003-05-10 23:10:09 +00:00
|
|
|
TEST(TestSerialized);
|
2004-06-01 17:31:17 +00:00
|
|
|
TEST(TestNonInvariantPattern);
|
2004-12-28 21:43:33 +00:00
|
|
|
TEST(TestBadPattern);
|
2002-06-04 23:31:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------
|
|
|
|
* Tests
|
|
|
|
*------------------------------------------------------------------*/
|
|
|
|
|
2002-08-29 23:16:45 +00:00
|
|
|
static void Testj2269() {
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
UChar a[4] = { 0x61, 0x62, 0x63, 0 };
|
|
|
|
USet *s = uset_open(1, 0);
|
|
|
|
uset_addString(s, a, 3);
|
|
|
|
a[0] = 0x63; a[1] = 0x63;
|
|
|
|
expect(s, "{abc}", "{ccc}", &status);
|
2002-09-06 23:23:49 +00:00
|
|
|
uset_close(s);
|
2002-08-29 23:16:45 +00:00
|
|
|
}
|
|
|
|
|
2002-06-04 23:31:13 +00:00
|
|
|
static const UChar PAT[] = {91,97,45,99,123,97,98,125,93,0}; /* "[a-c{ab}]" */
|
|
|
|
static const int32_t PAT_LEN = (sizeof(PAT) / sizeof(PAT[0])) - 1;
|
|
|
|
|
2004-08-10 23:22:21 +00:00
|
|
|
static const UChar PAT_lb[] = {0x6C, 0x62, 0}; /* "lb" */
|
|
|
|
static const int32_t PAT_lb_LEN = (sizeof(PAT_lb) / sizeof(PAT_lb[0])) - 1;
|
|
|
|
|
|
|
|
static const UChar VAL_SP[] = {0x53, 0x50, 0}; /* "SP" */
|
|
|
|
static const int32_t VAL_SP_LEN = (sizeof(VAL_SP) / sizeof(VAL_SP[0])) - 1;
|
|
|
|
|
2002-06-04 23:31:13 +00:00
|
|
|
static const UChar STR_bc[] = {98,99,0}; /* "bc" */
|
|
|
|
static const int32_t STR_bc_LEN = (sizeof(STR_bc) / sizeof(STR_bc[0])) - 1;
|
|
|
|
|
|
|
|
static const UChar STR_ab[] = {97,98,0}; /* "ab" */
|
|
|
|
static const int32_t STR_ab_LEN = (sizeof(STR_ab) / sizeof(STR_ab[0])) - 1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Basic API test for uset.x
|
|
|
|
*/
|
|
|
|
static void TestAPI() {
|
|
|
|
USet* set;
|
2004-08-10 23:22:21 +00:00
|
|
|
USet* set2;
|
2002-06-04 23:31:13 +00:00
|
|
|
UErrorCode ec;
|
|
|
|
|
|
|
|
/* [] */
|
|
|
|
set = uset_open(1, 1);
|
2002-06-05 00:01:09 +00:00
|
|
|
uset_clear(set);
|
2002-06-04 23:31:13 +00:00
|
|
|
expect(set, "", "abc{ab}", NULL);
|
|
|
|
uset_close(set);
|
|
|
|
|
|
|
|
/* [ABC] */
|
|
|
|
set = uset_open(0x0041, 0x0043);
|
|
|
|
expect(set, "ABC", "DEF{ab}", NULL);
|
|
|
|
uset_close(set);
|
|
|
|
|
|
|
|
/* [a-c{ab}] */
|
|
|
|
ec = U_ZERO_ERROR;
|
|
|
|
set = uset_openPattern(PAT, PAT_LEN, &ec);
|
2003-06-04 17:35:54 +00:00
|
|
|
if(U_FAILURE(ec)) {
|
2004-12-05 01:49:02 +00:00
|
|
|
log_err("uset_openPattern([a-c{ab}]) failed - %s\n", u_errorName(ec));
|
2003-06-04 17:35:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-08-10 23:22:21 +00:00
|
|
|
if(!uset_resemblesPattern(PAT, PAT_LEN, 0)) {
|
2004-12-05 01:49:02 +00:00
|
|
|
log_err("uset_resemblesPattern of PAT failed\n");
|
2004-08-10 23:22:21 +00:00
|
|
|
}
|
2002-06-04 23:31:13 +00:00
|
|
|
expect(set, "abc{ab}", "def{bc}", &ec);
|
|
|
|
|
2002-06-05 00:01:09 +00:00
|
|
|
/* [a-d{ab}] */
|
|
|
|
uset_add(set, 0x64);
|
|
|
|
expect(set, "abcd{ab}", "ef{bc}", NULL);
|
2002-06-04 23:31:13 +00:00
|
|
|
|
2002-06-05 00:01:09 +00:00
|
|
|
/* [acd{ab}{bc}] */
|
|
|
|
uset_remove(set, 0x62);
|
2002-06-04 23:31:13 +00:00
|
|
|
uset_addString(set, STR_bc, STR_bc_LEN);
|
2002-06-05 00:01:09 +00:00
|
|
|
expect(set, "acd{ab}{bc}", "bef{cd}", NULL);
|
2002-06-04 23:31:13 +00:00
|
|
|
|
2002-06-05 00:01:09 +00:00
|
|
|
/* [acd{bc}] */
|
2002-06-04 23:31:13 +00:00
|
|
|
uset_removeString(set, STR_ab, STR_ab_LEN);
|
2002-06-05 00:01:09 +00:00
|
|
|
expect(set, "acd{bc}", "bfg{ab}", NULL);
|
|
|
|
|
|
|
|
/* [^acd{bc}] */
|
|
|
|
uset_complement(set);
|
|
|
|
expect(set, "bef{bc}", "acd{ac}", NULL);
|
2002-06-04 23:31:13 +00:00
|
|
|
|
2002-11-14 20:34:23 +00:00
|
|
|
/* [a-e{bc}] */
|
|
|
|
uset_complement(set);
|
|
|
|
uset_addRange(set, 0x0062, 0x0065);
|
|
|
|
expect(set, "abcde{bc}", "fg{ab}", NULL);
|
|
|
|
|
|
|
|
/* [de{bc}] */
|
|
|
|
uset_removeRange(set, 0x0050, 0x0063);
|
|
|
|
expect(set, "de{bc}", "bcfg{ab}", NULL);
|
|
|
|
|
2004-08-10 23:22:21 +00:00
|
|
|
/* [g-l] */
|
|
|
|
uset_set(set, 0x0067, 0x006C);
|
|
|
|
expect(set, "ghijkl", "de{bc}", NULL);
|
|
|
|
|
|
|
|
if (uset_indexOf(set, 0x0067) != 0) {
|
2004-12-05 01:49:02 +00:00
|
|
|
log_err("uset_indexOf failed finding correct index of 'g'\n");
|
2004-08-10 23:22:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (uset_charAt(set, 0) != 0x0067) {
|
2004-12-05 01:49:02 +00:00
|
|
|
log_err("uset_charAt failed finding correct char 'g' at index 0\n");
|
2004-08-10 23:22:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* How to test this one...? */
|
|
|
|
uset_compact(set);
|
|
|
|
|
|
|
|
/* [g-i] */
|
|
|
|
uset_retain(set, 0x0067, 0x0069);
|
|
|
|
expect(set, "ghi", "dejkl{bc}", NULL);
|
|
|
|
|
|
|
|
/* UCHAR_ASCII_HEX_DIGIT */
|
|
|
|
uset_applyIntPropertyValue(set, UCHAR_ASCII_HEX_DIGIT, 1, &ec);
|
|
|
|
if(U_FAILURE(ec)) {
|
2004-12-05 01:49:02 +00:00
|
|
|
log_err("uset_applyIntPropertyValue([UCHAR_ASCII_HEX_DIGIT]) failed - %s\n", u_errorName(ec));
|
2004-08-10 23:22:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
expect(set, "0123456789ABCDEFabcdef", "GHIjkl{bc}", NULL);
|
|
|
|
|
|
|
|
/* [] */
|
|
|
|
set2 = uset_open(1, 1);
|
|
|
|
uset_clear(set2);
|
|
|
|
|
|
|
|
/* space */
|
|
|
|
uset_applyPropertyAlias(set2, PAT_lb, PAT_lb_LEN, VAL_SP, VAL_SP_LEN, &ec);
|
|
|
|
expect(set2, " ", "abcdefghi{bc}", NULL);
|
|
|
|
|
|
|
|
/* [a-c] */
|
|
|
|
uset_set(set2, 0x0061, 0x0063);
|
|
|
|
/* [g-i] */
|
|
|
|
uset_set(set, 0x0067, 0x0069);
|
|
|
|
|
|
|
|
/* [a-c g-i] */
|
2004-12-20 23:47:56 +00:00
|
|
|
if (uset_containsSome(set, set2)) {
|
|
|
|
log_err("set should not contain some of set2 yet\n");
|
|
|
|
}
|
2004-08-10 23:22:21 +00:00
|
|
|
uset_complementAll(set, set2);
|
2004-12-20 23:47:56 +00:00
|
|
|
if (!uset_containsSome(set, set2)) {
|
|
|
|
log_err("set should contain some of set2\n");
|
|
|
|
}
|
2004-08-10 23:22:21 +00:00
|
|
|
expect(set, "abcghi", "def{bc}", NULL);
|
|
|
|
|
|
|
|
/* [g-i] */
|
|
|
|
uset_removeAll(set, set2);
|
|
|
|
expect(set, "ghi", "abcdef{bc}", NULL);
|
|
|
|
|
|
|
|
/* [a-c g-i] */
|
|
|
|
uset_addAll(set2, set);
|
|
|
|
expect(set2, "abcghi", "def{bc}", NULL);
|
|
|
|
|
|
|
|
/* [g-i] */
|
|
|
|
uset_retainAll(set2, set);
|
|
|
|
expect(set2, "ghi", "abcdef{bc}", NULL);
|
|
|
|
|
2002-06-04 23:31:13 +00:00
|
|
|
uset_close(set);
|
2004-08-10 23:22:21 +00:00
|
|
|
uset_close(set2);
|
2002-06-04 23:31:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------
|
|
|
|
* Support
|
|
|
|
*------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Verifies that the given set contains the characters and strings in
|
|
|
|
* inList, and does not contain those in outList. Also verifies that
|
|
|
|
* 'set' is not NULL and that 'ec' succeeds.
|
|
|
|
* @param set the set to test, or NULL (on error)
|
|
|
|
* @param inList list of set contents, in iteration order. Format is
|
|
|
|
* list of individual strings, in iteration order, followed by sorted
|
|
|
|
* list of strings, delimited by {}. This means we do not test
|
|
|
|
* characters '{' or '}' and we do not test strings containing those
|
|
|
|
* characters either.
|
|
|
|
* @param outList list of things not in the set. Same format as
|
|
|
|
* inList.
|
|
|
|
* @param ec an error code, checked for success. May be NULL in which
|
|
|
|
* case it is ignored.
|
|
|
|
*/
|
|
|
|
static void expect(const USet* set,
|
|
|
|
const char* inList,
|
|
|
|
const char* outList,
|
|
|
|
UErrorCode* ec) {
|
|
|
|
if (ec!=NULL && U_FAILURE(*ec)) {
|
|
|
|
log_err("FAIL: %s\n", u_errorName(*ec));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (set == NULL) {
|
|
|
|
log_err("FAIL: USet is NULL\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
expectContainment(set, inList, TRUE);
|
|
|
|
expectContainment(set, outList, FALSE);
|
|
|
|
expectItems(set, inList);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void expectContainment(const USet* set,
|
|
|
|
const char* list,
|
|
|
|
UBool isIn) {
|
|
|
|
const char* p = list;
|
2004-08-10 23:22:21 +00:00
|
|
|
UChar ustr[4096];
|
2003-07-02 17:26:20 +00:00
|
|
|
char *pat;
|
2002-06-04 23:31:13 +00:00
|
|
|
UErrorCode ec;
|
2003-07-02 17:26:20 +00:00
|
|
|
int32_t rangeStart = -1, rangeEnd = -1, length;
|
2002-06-04 23:31:13 +00:00
|
|
|
|
|
|
|
ec = U_ZERO_ERROR;
|
2003-07-02 17:26:20 +00:00
|
|
|
length = uset_toPattern(set, ustr, sizeof(ustr), TRUE, &ec);
|
|
|
|
if(U_FAILURE(ec)) {
|
|
|
|
log_err("FAIL: uset_toPattern() fails in expectContainment() - %s\n", u_errorName(ec));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pat=aescstrdup(ustr, length);
|
2002-06-04 23:31:13 +00:00
|
|
|
|
|
|
|
while (*p) {
|
|
|
|
if (*p=='{') {
|
|
|
|
const char* stringStart = ++p;
|
|
|
|
int32_t stringLength = 0;
|
|
|
|
char strCopy[64];
|
|
|
|
|
2004-11-05 18:05:47 +00:00
|
|
|
while (*p++ != '}') {
|
|
|
|
}
|
|
|
|
stringLength = (int32_t)(p - stringStart - 1);
|
2003-04-23 05:49:02 +00:00
|
|
|
strncpy(strCopy, stringStart, stringLength);
|
2002-06-04 23:31:13 +00:00
|
|
|
strCopy[stringLength] = 0;
|
|
|
|
|
|
|
|
u_charsToUChars(stringStart, ustr, stringLength);
|
|
|
|
|
|
|
|
if (uset_containsString(set, ustr, stringLength) == isIn) {
|
|
|
|
log_verbose("Ok: %s %s \"%s\"\n", pat,
|
|
|
|
(isIn ? "contains" : "does not contain"),
|
|
|
|
strCopy);
|
|
|
|
} else {
|
|
|
|
log_err("FAIL: %s %s \"%s\"\n", pat,
|
|
|
|
(isIn ? "does not contain" : "contains"),
|
|
|
|
strCopy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
UChar32 c;
|
|
|
|
|
|
|
|
u_charsToUChars(p, ustr, 1);
|
|
|
|
c = ustr[0];
|
|
|
|
|
|
|
|
if (uset_contains(set, c) == isIn) {
|
|
|
|
log_verbose("Ok: %s %s '%c'\n", pat,
|
|
|
|
(isIn ? "contains" : "does not contain"),
|
|
|
|
*p);
|
|
|
|
} else {
|
|
|
|
log_err("FAIL: %s %s '%c'\n", pat,
|
|
|
|
(isIn ? "does not contain" : "contains"),
|
|
|
|
*p);
|
|
|
|
}
|
|
|
|
|
2002-11-14 20:34:23 +00:00
|
|
|
/* Test the range API too by looking for ranges */
|
|
|
|
if (c == rangeEnd+1) {
|
|
|
|
rangeEnd = c;
|
|
|
|
} else {
|
|
|
|
if (rangeStart >= 0) {
|
|
|
|
if (uset_containsRange(set, rangeStart, rangeEnd) == isIn) {
|
|
|
|
log_verbose("Ok: %s %s U+%04X-U+%04X\n", pat,
|
|
|
|
(isIn ? "contains" : "does not contain"),
|
|
|
|
rangeStart, rangeEnd);
|
|
|
|
} else {
|
|
|
|
log_err("FAIL: %s %s U+%04X-U+%04X\n", pat,
|
|
|
|
(isIn ? "does not contain" : "contains"),
|
|
|
|
rangeStart, rangeEnd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rangeStart = rangeEnd = c;
|
|
|
|
}
|
|
|
|
|
2002-06-04 23:31:13 +00:00
|
|
|
++p;
|
|
|
|
}
|
|
|
|
}
|
2002-11-14 20:34:23 +00:00
|
|
|
|
|
|
|
if (rangeStart >= 0) {
|
|
|
|
if (uset_containsRange(set, rangeStart, rangeEnd) == isIn) {
|
|
|
|
log_verbose("Ok: %s %s U+%04X-U+%04X\n", pat,
|
|
|
|
(isIn ? "contains" : "does not contain"),
|
|
|
|
rangeStart, rangeEnd);
|
|
|
|
} else {
|
|
|
|
log_err("FAIL: %s %s U+%04X-U+%04X\n", pat,
|
|
|
|
(isIn ? "does not contain" : "contains"),
|
|
|
|
rangeStart, rangeEnd);
|
|
|
|
}
|
|
|
|
}
|
2002-06-04 23:31:13 +00:00
|
|
|
}
|
|
|
|
|
2003-07-02 17:26:20 +00:00
|
|
|
/* This only works for invariant BMP chars */
|
2002-06-04 23:31:13 +00:00
|
|
|
static char oneUCharToChar(UChar32 c) {
|
|
|
|
UChar ubuf[1];
|
|
|
|
char buf[1];
|
|
|
|
ubuf[0] = (UChar) c;
|
|
|
|
u_UCharsToChars(ubuf, buf, 1);
|
|
|
|
return buf[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void expectItems(const USet* set,
|
|
|
|
const char* items) {
|
|
|
|
const char* p = items;
|
2004-08-10 23:22:21 +00:00
|
|
|
UChar ustr[4096], itemStr[4096];
|
|
|
|
char buf[4096];
|
2003-07-02 17:26:20 +00:00
|
|
|
char *pat;
|
2002-06-04 23:31:13 +00:00
|
|
|
UErrorCode ec;
|
|
|
|
int32_t expectedSize = 0;
|
|
|
|
int32_t itemCount = uset_getItemCount(set);
|
|
|
|
int32_t itemIndex = 0;
|
|
|
|
UChar32 start = 1, end = 0;
|
2003-07-02 17:26:20 +00:00
|
|
|
int32_t itemLen = 0, length;
|
2002-07-25 18:32:04 +00:00
|
|
|
|
2002-06-04 23:31:13 +00:00
|
|
|
ec = U_ZERO_ERROR;
|
2003-07-02 17:26:20 +00:00
|
|
|
length = uset_toPattern(set, ustr, sizeof(ustr), TRUE, &ec);
|
2002-06-04 23:31:13 +00:00
|
|
|
if (U_FAILURE(ec)) {
|
|
|
|
log_err("FAIL: uset_toPattern => %s\n", u_errorName(ec));
|
|
|
|
return;
|
|
|
|
}
|
2003-07-02 17:26:20 +00:00
|
|
|
pat=aescstrdup(ustr, length);
|
2002-06-04 23:31:13 +00:00
|
|
|
|
2003-04-23 05:49:02 +00:00
|
|
|
if (uset_isEmpty(set) != (strlen(items)==0)) {
|
2002-06-04 23:31:13 +00:00
|
|
|
log_err("FAIL: %s should return %s from isEmpty\n",
|
|
|
|
pat,
|
2003-04-23 05:49:02 +00:00
|
|
|
strlen(items)==0 ? "TRUE" : "FALSE");
|
2002-06-04 23:31:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Don't test patterns starting with "[^" */
|
2003-07-02 17:26:20 +00:00
|
|
|
if (u_strlen(ustr) > 2 && ustr[1] == 0x5e /*'^'*/) {
|
2002-06-04 23:31:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (*p) {
|
|
|
|
|
|
|
|
++expectedSize;
|
|
|
|
|
|
|
|
if (start > end || start == -1) {
|
|
|
|
/* Fetch our next item */
|
|
|
|
if (itemIndex >= itemCount) {
|
|
|
|
log_err("FAIL: ran out of items iterating %s\n", pat);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
itemLen = uset_getItem(set, itemIndex, &start, &end,
|
|
|
|
itemStr, sizeof(itemStr), &ec);
|
|
|
|
if (U_FAILURE(ec) || itemLen < 0) {
|
|
|
|
log_err("FAIL: uset_getItem => %s\n", u_errorName(ec));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemLen == 0) {
|
|
|
|
log_verbose("Ok: %s item %d is %c-%c\n", pat,
|
|
|
|
itemIndex, oneUCharToChar(start),
|
|
|
|
oneUCharToChar(end));
|
|
|
|
} else {
|
|
|
|
itemStr[itemLen] = 0;
|
|
|
|
u_UCharsToChars(itemStr, buf, itemLen+1);
|
|
|
|
log_verbose("Ok: %s item %d is \"%s\"\n", pat, itemIndex, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
++itemIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*p=='{') {
|
|
|
|
const char* stringStart = ++p;
|
|
|
|
int32_t stringLength = 0;
|
|
|
|
char strCopy[64];
|
|
|
|
|
2004-11-05 18:05:47 +00:00
|
|
|
while (*p++ != '}') {
|
|
|
|
}
|
|
|
|
stringLength = (int32_t)(p - stringStart - 1);
|
2003-04-23 05:49:02 +00:00
|
|
|
strncpy(strCopy, stringStart, stringLength);
|
2002-06-04 23:31:13 +00:00
|
|
|
strCopy[stringLength] = 0;
|
|
|
|
|
|
|
|
u_charsToUChars(stringStart, ustr, stringLength);
|
|
|
|
ustr[stringLength] = 0;
|
|
|
|
|
|
|
|
if (itemLen == 0) {
|
|
|
|
log_err("FAIL: for %s expect \"%s\" next, but got a char\n",
|
|
|
|
pat, strCopy);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (u_strcmp(ustr, itemStr) != 0) {
|
|
|
|
log_err("FAIL: for %s expect \"%s\" next\n",
|
|
|
|
pat, strCopy);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
UChar32 c;
|
|
|
|
|
|
|
|
u_charsToUChars(p, ustr, 1);
|
|
|
|
c = ustr[0];
|
|
|
|
|
|
|
|
if (itemLen != 0) {
|
|
|
|
log_err("FAIL: for %s expect '%c' next, but got a string\n",
|
|
|
|
pat, *p);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c != start++) {
|
|
|
|
log_err("FAIL: for %s expect '%c' next\n",
|
|
|
|
pat, *p);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
++p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (uset_size(set) == expectedSize) {
|
|
|
|
log_verbose("Ok: %s size is %d\n", pat, expectedSize);
|
|
|
|
} else {
|
|
|
|
log_err("FAIL: %s size is %d, expected %d\n",
|
|
|
|
pat, uset_size(set), expectedSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-10 23:10:09 +00:00
|
|
|
static void
|
|
|
|
TestSerialized() {
|
|
|
|
uint16_t buffer[1000];
|
|
|
|
USerializedSet sset;
|
|
|
|
USet *set;
|
|
|
|
UErrorCode errorCode;
|
|
|
|
UChar32 c;
|
|
|
|
int32_t length;
|
|
|
|
|
|
|
|
/* use a pattern that generates both BMP and supplementary code points */
|
|
|
|
U_STRING_DECL(pattern, "[:Cf:]", 6);
|
|
|
|
U_STRING_INIT(pattern, "[:Cf:]", 6);
|
|
|
|
|
|
|
|
errorCode=U_ZERO_ERROR;
|
|
|
|
set=uset_openPattern(pattern, -1, &errorCode);
|
|
|
|
if(U_FAILURE(errorCode)) {
|
2004-12-05 01:49:02 +00:00
|
|
|
log_err("uset_openPattern([:Cf:]) failed - %s\n", u_errorName(errorCode));
|
2003-05-10 23:10:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
length=uset_serialize(set, buffer, LENGTHOF(buffer), &errorCode);
|
|
|
|
if(U_FAILURE(errorCode)) {
|
|
|
|
log_err("unable to uset_serialize([:Cf:]) - %s\n", u_errorName(errorCode));
|
|
|
|
uset_close(set);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uset_getSerializedSet(&sset, buffer, length);
|
|
|
|
for(c=0; c<=0x10ffff; ++c) {
|
|
|
|
if(uset_contains(set, c)!=uset_serializedContains(&sset, c)) {
|
|
|
|
log_err("uset_contains(U+%04x)!=uset_serializedContains(U+%04x)\n", c);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uset_close(set);
|
|
|
|
}
|
|
|
|
|
2004-06-01 17:31:17 +00:00
|
|
|
/**
|
|
|
|
* Make sure that when non-invariant chars are passed to uset_openPattern
|
|
|
|
* they do not cause an ugly failure mode (e.g. assertion failure).
|
|
|
|
* JB#3795.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
TestNonInvariantPattern() {
|
|
|
|
UErrorCode ec = U_ZERO_ERROR;
|
|
|
|
/* The critical part of this test is that the following pattern
|
|
|
|
must contain a non-invariant character. */
|
|
|
|
static const char *pattern = "[:ccc!=0:]";
|
|
|
|
UChar buf[256];
|
|
|
|
int32_t len = u_unescape(pattern, buf, 256);
|
|
|
|
/* This test 'fails' by having an assertion failure within the
|
|
|
|
following call. It passes by running to completion with no
|
|
|
|
assertion failure. */
|
|
|
|
USet *set = uset_openPattern(buf, len, &ec);
|
|
|
|
uset_close(set);
|
|
|
|
}
|
|
|
|
|
2004-12-28 21:43:33 +00:00
|
|
|
static void TestBadPattern(void) {
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
USet *pat;
|
|
|
|
U_STRING_DECL(pattern, "[", 1);
|
|
|
|
U_STRING_INIT(pattern, "[", 1);
|
|
|
|
pat = uset_openPatternOptions(pattern, u_strlen(pattern), 0, &status);
|
|
|
|
if (pat != NULL || U_SUCCESS(status)) {
|
|
|
|
log_err("uset_openPatternOptions did not fail as expected %s\n", u_errorName(status));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-04 23:31:13 +00:00
|
|
|
/*eof*/
|