/*
**********************************************************************
-* Copyright (c) 2002-2004, International Business Machines
+* Copyright (c) 2002-2009, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
*/
static void Testj2269(void);
static void TestSerialized(void);
static void TestNonInvariantPattern(void);
+static void TestBadPattern(void);
+static void TestFreezable(void);
+static void TestSpan(void);
void addUSetTest(TestNode** root);
TEST(Testj2269);
TEST(TestSerialized);
TEST(TestNonInvariantPattern);
+ TEST(TestBadPattern);
+ TEST(TestFreezable);
+ TEST(TestSpan);
}
/*------------------------------------------------------------------
UErrorCode ec;
/* [] */
+ set = uset_openEmpty();
+ expect(set, "", "abc{ab}", NULL);
+ uset_close(set);
+
+ set = uset_open(1, 0);
+ expect(set, "", "abc{ab}", NULL);
+ uset_close(set);
+
set = uset_open(1, 1);
uset_clear(set);
expect(set, "", "abc{ab}", NULL);
ec = U_ZERO_ERROR;
set = uset_openPattern(PAT, PAT_LEN, &ec);
if(U_FAILURE(ec)) {
- log_data_err("uset_openPattern([a-c{ab}]) failed - %s\n", u_errorName(ec));
+ log_err("uset_openPattern([a-c{ab}]) failed - %s\n", u_errorName(ec));
return;
}
if(!uset_resemblesPattern(PAT, PAT_LEN, 0)) {
- log_data_err("uset_resemblesPattern of PAT failed\n");
+ log_err("uset_resemblesPattern of PAT failed\n");
}
expect(set, "abc{ab}", "def{bc}", &ec);
expect(set, "ghijkl", "de{bc}", NULL);
if (uset_indexOf(set, 0x0067) != 0) {
- log_data_err("uset_indexOf failed finding correct index of 'g'\n");
+ log_err("uset_indexOf failed finding correct index of 'g'\n");
}
if (uset_charAt(set, 0) != 0x0067) {
- log_data_err("uset_charAt failed finding correct char 'g' at index 0\n");
+ log_err("uset_charAt failed finding correct char 'g' at index 0\n");
}
/* How to test this one...? */
/* UCHAR_ASCII_HEX_DIGIT */
uset_applyIntPropertyValue(set, UCHAR_ASCII_HEX_DIGIT, 1, &ec);
if(U_FAILURE(ec)) {
- log_data_err("uset_applyIntPropertyValue([UCHAR_ASCII_HEX_DIGIT]) failed - %s\n", u_errorName(ec));
+ log_err("uset_applyIntPropertyValue([UCHAR_ASCII_HEX_DIGIT]) failed - %s\n", u_errorName(ec));
return;
}
expect(set, "0123456789ABCDEFabcdef", "GHIjkl{bc}", NULL);
+ /* [ab] */
+ uset_clear(set);
+ uset_addAllCodePoints(set, STR_ab, STR_ab_LEN);
+ expect(set, "ab", "def{ab}", NULL);
+ if (uset_containsAllCodePoints(set, STR_bc, STR_bc_LEN)){
+ log_err("set should not conatin all characters of \"bc\" \n");
+ }
+
/* [] */
set2 = uset_open(1, 1);
uset_clear(set2);
uset_set(set, 0x0067, 0x0069);
/* [a-c g-i] */
+ if (uset_containsSome(set, set2)) {
+ log_err("set should not contain some of set2 yet\n");
+ }
uset_complementAll(set, set2);
+ if (!uset_containsSome(set, set2)) {
+ log_err("set should contain some of set2\n");
+ }
expect(set, "abcghi", "def{bc}", NULL);
/* [g-i] */
(isIn ? "contains" : "does not contain"),
strCopy);
} else {
- log_err("FAIL: %s %s \"%s\"\n", pat,
+ log_data_err("FAIL: %s %s \"%s\" (Are you missing data?)\n", pat,
(isIn ? "does not contain" : "contains"),
strCopy);
}
(isIn ? "contains" : "does not contain"),
*p);
} else {
- log_err("FAIL: %s %s '%c'\n", pat,
+ log_data_err("FAIL: %s %s '%c' (Are you missing data?)\n", pat,
(isIn ? "does not contain" : "contains"),
*p);
}
(isIn ? "contains" : "does not contain"),
rangeStart, rangeEnd);
} else {
- log_err("FAIL: %s %s U+%04X-U+%04X\n", pat,
+ log_data_err("FAIL: %s %s U+%04X-U+%04X (Are you missing data?)\n", pat,
(isIn ? "does not contain" : "contains"),
rangeStart, rangeEnd);
}
(isIn ? "contains" : "does not contain"),
rangeStart, rangeEnd);
} else {
- log_err("FAIL: %s %s U+%04X-U+%04X\n", pat,
+ log_data_err("FAIL: %s %s U+%04X-U+%04X (Are you missing data?)\n", pat,
(isIn ? "does not contain" : "contains"),
rangeStart, rangeEnd);
}
pat=aescstrdup(ustr, length);
if (uset_isEmpty(set) != (strlen(items)==0)) {
- log_err("FAIL: %s should return %s from isEmpty\n",
+ log_data_err("FAIL: %s should return %s from isEmpty (Are you missing data?)\n",
pat,
strlen(items)==0 ? "TRUE" : "FALSE");
}
if (start > end || start == -1) {
/* Fetch our next item */
if (itemIndex >= itemCount) {
- log_err("FAIL: ran out of items iterating %s\n", pat);
+ log_data_err("FAIL: ran out of items iterating %s (Are you missing data?)\n", pat);
return;
}
errorCode=U_ZERO_ERROR;
set=uset_openPattern(pattern, -1, &errorCode);
if(U_FAILURE(errorCode)) {
- log_data_err("uset_openPattern([:Cf:]) failed - %s\n", u_errorName(errorCode));
+ log_data_err("uset_openPattern([:Cf:]) failed - %s (Are you missing data?)\n", u_errorName(errorCode));
return;
}
uset_close(set);
}
+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));
+ }
+}
+
+static USet *openIDSet() {
+ UErrorCode errorCode = U_ZERO_ERROR;
+ U_STRING_DECL(pattern, "[:ID_Continue:]", 15);
+ U_STRING_INIT(pattern, "[:ID_Continue:]", 15);
+ return uset_openPattern(pattern, 15, &errorCode);
+}
+
+static void TestFreezable() {
+ USet *idSet;
+ USet *frozen;
+ USet *thawed;
+
+ idSet=openIDSet();
+
+ if (idSet == NULL) {
+ log_data_err("openIDSet() returned NULL. (Are you missing data?)\n");
+ uset_close(idSet);
+ return;
+ }
+
+ frozen=uset_clone(idSet);
+
+ if (frozen == NULL) {
+ log_err("uset_Clone() returned NULL\n");
+ return;
+ }
+
+ if(!uset_equals(frozen, idSet)) {
+ log_err("uset_clone() did not make an equal copy\n");
+ }
+
+ uset_freeze(frozen);
+ uset_addRange(frozen, 0xd802, 0xd805);
+
+ if(uset_isFrozen(idSet) || !uset_isFrozen(frozen) || !uset_equals(frozen, idSet)) {
+ log_err("uset_freeze() or uset_isFrozen() does not work\n");
+ }
+
+ thawed=uset_cloneAsThawed(frozen);
+
+ if (thawed == NULL) {
+ log_err("uset_cloneAsThawed(frozen) returned NULL");
+ uset_close(frozen);
+ uset_close(idSet);
+ return;
+ }
+
+ uset_addRange(thawed, 0xd802, 0xd805);
+
+ if(uset_isFrozen(thawed) || uset_equals(thawed, idSet) || !uset_containsRange(thawed, 0xd802, 0xd805)) {
+ log_err("uset_cloneAsThawed() does not work\n");
+ }
+
+ uset_close(idSet);
+ uset_close(frozen);
+ uset_close(thawed);
+}
+
+static void TestSpan() {
+ static const UChar s16[2]={ 0xe01, 0x3000 };
+ static const char* s8="\xE0\xB8\x81\xE3\x80\x80";
+
+ USet *idSet=openIDSet();
+
+ if (idSet == NULL) {
+ log_data_err("openIDSet() returned NULL (Are you missing data?)\n");
+ return;
+ }
+
+ if(
+ 1!=uset_span(idSet, s16, 2, USET_SPAN_CONTAINED) ||
+ 0!=uset_span(idSet, s16, 2, USET_SPAN_NOT_CONTAINED) ||
+ 2!=uset_spanBack(idSet, s16, 2, USET_SPAN_CONTAINED) ||
+ 1!=uset_spanBack(idSet, s16, 2, USET_SPAN_NOT_CONTAINED)
+ ) {
+ log_err("uset_span() or uset_spanBack() does not work\n");
+ }
+
+ if(
+ 3!=uset_spanUTF8(idSet, s8, 6, USET_SPAN_CONTAINED) ||
+ 0!=uset_spanUTF8(idSet, s8, 6, USET_SPAN_NOT_CONTAINED) ||
+ 6!=uset_spanBackUTF8(idSet, s8, 6, USET_SPAN_CONTAINED) ||
+ 3!=uset_spanBackUTF8(idSet, s8, 6, USET_SPAN_NOT_CONTAINED)
+ ) {
+ log_err("uset_spanUTF8() or uset_spanBackUTF8() does not work\n");
+ }
+
+ uset_freeze(idSet);
+
+ if(
+ 1!=uset_span(idSet, s16, 2, USET_SPAN_CONTAINED) ||
+ 0!=uset_span(idSet, s16, 2, USET_SPAN_NOT_CONTAINED) ||
+ 2!=uset_spanBack(idSet, s16, 2, USET_SPAN_CONTAINED) ||
+ 1!=uset_spanBack(idSet, s16, 2, USET_SPAN_NOT_CONTAINED)
+ ) {
+ log_err("uset_span(frozen) or uset_spanBack(frozen) does not work\n");
+ }
+
+ if(
+ 3!=uset_spanUTF8(idSet, s8, 6, USET_SPAN_CONTAINED) ||
+ 0!=uset_spanUTF8(idSet, s8, 6, USET_SPAN_NOT_CONTAINED) ||
+ 6!=uset_spanBackUTF8(idSet, s8, 6, USET_SPAN_CONTAINED) ||
+ 3!=uset_spanBackUTF8(idSet, s8, 6, USET_SPAN_NOT_CONTAINED)
+ ) {
+ log_err("uset_spanUTF8(frozen) or uset_spanBackUTF8(frozen) does not work\n");
+ }
+
+ uset_close(idSet);
+}
+
/*eof*/