#include "usc_impl.h"
#include "udatamem.h" /* for testing ucase_openBinary() */
#include "cucdapi.h"
-
-#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
+#include "cmemory.h"
/* prototypes --------------------------------------------------------------- */
static void TestCodePoint(void);
static void TestCharLength(void);
static void TestCharNames(void);
+static void TestUCharFromNameUnderflow(void);
static void TestMirroring(void);
static void TestUScriptRunAPI(void);
static void TestAdditionalProperties(void);
addTest(root, &TestControlPrint, "tsutil/cucdtst/TestControlPrint");
addTest(root, &TestIdentifier, "tsutil/cucdtst/TestIdentifier");
addTest(root, &TestCharNames, "tsutil/cucdtst/TestCharNames");
+ addTest(root, &TestUCharFromNameUnderflow, "tsutil/cucdtst/TestUCharFromNameUnderflow");
addTest(root, &TestMirroring, "tsutil/cucdtst/TestMirroring");
addTest(root, &TestUScriptCodeAPI, "tsutil/cucdtst/TestUScriptCodeAPI");
addTest(root, &TestHasScript, "tsutil/cucdtst/TestHasScript");
memset(icuVersion, 0, U_MAX_VERSION_STRING_LENGTH);
- testSampleCharProps(u_isspace, "u_isspace", sampleSpaces, LENGTHOF(sampleSpaces), TRUE);
- testSampleCharProps(u_isspace, "u_isspace", sampleNonSpaces, LENGTHOF(sampleNonSpaces), FALSE);
+ testSampleCharProps(u_isspace, "u_isspace", sampleSpaces, UPRV_LENGTHOF(sampleSpaces), TRUE);
+ testSampleCharProps(u_isspace, "u_isspace", sampleNonSpaces, UPRV_LENGTHOF(sampleNonSpaces), FALSE);
testSampleCharProps(u_isJavaSpaceChar, "u_isJavaSpaceChar",
- sampleSpaces, LENGTHOF(sampleSpaces), TRUE);
+ sampleSpaces, UPRV_LENGTHOF(sampleSpaces), TRUE);
testSampleCharProps(u_isJavaSpaceChar, "u_isJavaSpaceChar",
- sampleNonSpaces, LENGTHOF(sampleNonSpaces), FALSE);
+ sampleNonSpaces, UPRV_LENGTHOF(sampleNonSpaces), FALSE);
testSampleCharProps(u_isWhitespace, "u_isWhitespace",
- sampleWhiteSpaces, LENGTHOF(sampleWhiteSpaces), TRUE);
+ sampleWhiteSpaces, UPRV_LENGTHOF(sampleWhiteSpaces), TRUE);
testSampleCharProps(u_isWhitespace, "u_isWhitespace",
- sampleNonWhiteSpaces, LENGTHOF(sampleNonWhiteSpaces), FALSE);
+ sampleNonWhiteSpaces, UPRV_LENGTHOF(sampleNonWhiteSpaces), FALSE);
testSampleCharProps(u_isdefined, "u_isdefined",
- sampleDefined, LENGTHOF(sampleDefined), TRUE);
+ sampleDefined, UPRV_LENGTHOF(sampleDefined), TRUE);
testSampleCharProps(u_isdefined, "u_isdefined",
- sampleUndefined, LENGTHOF(sampleUndefined), FALSE);
+ sampleUndefined, UPRV_LENGTHOF(sampleUndefined), FALSE);
- testSampleCharProps(u_isbase, "u_isbase", sampleBase, LENGTHOF(sampleBase), TRUE);
- testSampleCharProps(u_isbase, "u_isbase", sampleNonBase, LENGTHOF(sampleNonBase), FALSE);
+ testSampleCharProps(u_isbase, "u_isbase", sampleBase, UPRV_LENGTHOF(sampleBase), TRUE);
+ testSampleCharProps(u_isbase, "u_isbase", sampleNonBase, UPRV_LENGTHOF(sampleNonBase), FALSE);
- testSampleCharProps(u_isdigit, "u_isdigit", sampleDigits, LENGTHOF(sampleDigits), TRUE);
- testSampleCharProps(u_isdigit, "u_isdigit", sampleNonDigits, LENGTHOF(sampleNonDigits), FALSE);
+ testSampleCharProps(u_isdigit, "u_isdigit", sampleDigits, UPRV_LENGTHOF(sampleDigits), TRUE);
+ testSampleCharProps(u_isdigit, "u_isdigit", sampleNonDigits, UPRV_LENGTHOF(sampleNonDigits), FALSE);
- for (i = 0; i < LENGTHOF(sampleDigits); i++) {
+ for (i = 0; i < UPRV_LENGTHOF(sampleDigits); i++) {
if (u_charDigitValue(sampleDigits[i]) != sampleDigitValues[i]) {
log_err("error: u_charDigitValue(U+04x)=%d != %d\n",
sampleDigits[i], u_charDigitValue(sampleDigits[i]), sampleDigitValues[i]);
{ 0xff3a, 37, -1 }
};
- for(i=0; i<LENGTHOF(data); ++i) {
+ for(i=0; i<UPRV_LENGTHOF(data); ++i) {
if(u_digit(data[i].c, data[i].radix)!=data[i].value) {
log_err("u_digit(U+%04x, %d)=%d expected %d\n",
data[i].c,
mask=1;
for(cl=0; cl<12; ++cl) {
- for(i=0; i<LENGTHOF(posixData); ++i) {
+ for(i=0; i<UPRV_LENGTHOF(posixData); ++i) {
expect=(UBool)((posixData[i].posixResults&mask)!=0);
if(posixClasses[cl].fn(posixData[i].c)!=expect) {
log_err("u_%s(U+%04x)=%s is wrong\n",
const UChar32 sampleNonPrintable[] = {0x200c, 0x009f, 0x001b};
UChar32 c;
- testSampleCharProps(u_iscntrl, "u_iscntrl", sampleControl, LENGTHOF(sampleControl), TRUE);
- testSampleCharProps(u_iscntrl, "u_iscntrl", sampleNonControl, LENGTHOF(sampleNonControl), FALSE);
+ testSampleCharProps(u_iscntrl, "u_iscntrl", sampleControl, UPRV_LENGTHOF(sampleControl), TRUE);
+ testSampleCharProps(u_iscntrl, "u_iscntrl", sampleNonControl, UPRV_LENGTHOF(sampleNonControl), FALSE);
testSampleCharProps(u_isprint, "u_isprint",
- samplePrintable, LENGTHOF(samplePrintable), TRUE);
+ samplePrintable, UPRV_LENGTHOF(samplePrintable), TRUE);
testSampleCharProps(u_isprint, "u_isprint",
- sampleNonPrintable, LENGTHOF(sampleNonPrintable), FALSE);
+ sampleNonPrintable, UPRV_LENGTHOF(sampleNonPrintable), FALSE);
/* test all ISO 8 controls */
for(c=0; c<=0x9f; ++c) {
const UChar32 sampleNonIDIgnore[] = {0x0075, 0x00a3, 0x0061};
testSampleCharProps(u_isJavaIDStart, "u_isJavaIDStart",
- sampleJavaIDStart, LENGTHOF(sampleJavaIDStart), TRUE);
+ sampleJavaIDStart, UPRV_LENGTHOF(sampleJavaIDStart), TRUE);
testSampleCharProps(u_isJavaIDStart, "u_isJavaIDStart",
- sampleNonJavaIDStart, LENGTHOF(sampleNonJavaIDStart), FALSE);
+ sampleNonJavaIDStart, UPRV_LENGTHOF(sampleNonJavaIDStart), FALSE);
testSampleCharProps(u_isJavaIDPart, "u_isJavaIDPart",
- sampleJavaIDPart, LENGTHOF(sampleJavaIDPart), TRUE);
+ sampleJavaIDPart, UPRV_LENGTHOF(sampleJavaIDPart), TRUE);
testSampleCharProps(u_isJavaIDPart, "u_isJavaIDPart",
- sampleNonJavaIDPart, LENGTHOF(sampleNonJavaIDPart), FALSE);
+ sampleNonJavaIDPart, UPRV_LENGTHOF(sampleNonJavaIDPart), FALSE);
/* IDPart should imply IDStart */
testSampleCharProps(u_isJavaIDPart, "u_isJavaIDPart",
- sampleJavaIDStart, LENGTHOF(sampleJavaIDStart), TRUE);
+ sampleJavaIDStart, UPRV_LENGTHOF(sampleJavaIDStart), TRUE);
testSampleCharProps(u_isIDStart, "u_isIDStart",
- sampleUnicodeIDStart, LENGTHOF(sampleUnicodeIDStart), TRUE);
+ sampleUnicodeIDStart, UPRV_LENGTHOF(sampleUnicodeIDStart), TRUE);
testSampleCharProps(u_isIDStart, "u_isIDStart",
- sampleNonUnicodeIDStart, LENGTHOF(sampleNonUnicodeIDStart), FALSE);
+ sampleNonUnicodeIDStart, UPRV_LENGTHOF(sampleNonUnicodeIDStart), FALSE);
testSampleCharProps(u_isIDPart, "u_isIDPart",
- sampleUnicodeIDPart, LENGTHOF(sampleUnicodeIDPart), TRUE);
+ sampleUnicodeIDPart, UPRV_LENGTHOF(sampleUnicodeIDPart), TRUE);
testSampleCharProps(u_isIDPart, "u_isIDPart",
- sampleNonUnicodeIDPart, LENGTHOF(sampleNonUnicodeIDPart), FALSE);
+ sampleNonUnicodeIDPart, UPRV_LENGTHOF(sampleNonUnicodeIDPart), FALSE);
/* IDPart should imply IDStart */
testSampleCharProps(u_isIDPart, "u_isIDPart",
- sampleUnicodeIDStart, LENGTHOF(sampleUnicodeIDStart), TRUE);
+ sampleUnicodeIDStart, UPRV_LENGTHOF(sampleUnicodeIDStart), TRUE);
testSampleCharProps(u_isIDIgnorable, "u_isIDIgnorable",
- sampleIDIgnore, LENGTHOF(sampleIDIgnore), TRUE);
+ sampleIDIgnore, UPRV_LENGTHOF(sampleIDIgnore), TRUE);
testSampleCharProps(u_isIDIgnorable, "u_isIDIgnorable",
- sampleNonIDIgnore, LENGTHOF(sampleNonIDIgnore), FALSE);
+ sampleNonIDIgnore, UPRV_LENGTHOF(sampleNonIDIgnore), FALSE);
}
/* for each line of UnicodeData.txt, check some of the properties */
return FALSE;
}
- count=LENGTHOF(test);
+ count=UPRV_LENGTHOF(test);
for(i=0; i<count; ++i) {
if(start<=test[i][0] && test[i][0]<limit) {
if(type!=(UCharCategory)test[i][1]) {
if(type==U_UNASSIGNED || type==U_PRIVATE_USE_CHAR) {
/* enumerate the intersections of defaultBidi ranges with [start..limit[ */
c=start;
- for(i=0; i<LENGTHOF(defaultBidi) && c<limit; ++i) {
+ for(i=0; i<UPRV_LENGTHOF(defaultBidi) && c<limit; ++i) {
if((int32_t)c<defaultBidi[i][0]) {
while(c<limit && (int32_t)c<defaultBidi[i][0]) {
if(U_IS_UNICODE_NONCHAR(c) || u_hasBinaryProperty(c, UCHAR_DEFAULT_IGNORABLE_CODE_POINT)) {
/* ### TODO: test error cases and other interesting things */
}
+static void
+TestUCharFromNameUnderflow() {
+ // Ticket #10889: Underflow crash when there is no dash.
+ UErrorCode errorCode=U_ZERO_ERROR;
+ UChar32 c=u_charFromName(U_EXTENDED_CHAR_NAME, "<NO BREAK SPACE>", &errorCode);
+ if(U_SUCCESS(errorCode)) {
+ log_err("u_charFromName(<NO BREAK SPACE>) = U+%04x but should fail - %s\n", c, u_errorName(errorCode));
+ }
+
+ // Test related edge cases.
+ errorCode=U_ZERO_ERROR;
+ c=u_charFromName(U_EXTENDED_CHAR_NAME, "<-00a0>", &errorCode);
+ if(U_SUCCESS(errorCode)) {
+ log_err("u_charFromName(<-00a0>) = U+%04x but should fail - %s\n", c, u_errorName(errorCode));
+ }
+
+ errorCode=U_ZERO_ERROR;
+ c=u_charFromName(U_EXTENDED_CHAR_NAME, "<control->", &errorCode);
+ if(U_SUCCESS(errorCode)) {
+ log_err("u_charFromName(<control->) = U+%04x but should fail - %s\n", c, u_errorName(errorCode));
+ }
+
+ errorCode=U_ZERO_ERROR;
+ c=u_charFromName(U_EXTENDED_CHAR_NAME, "<control-111111>", &errorCode);
+ if(U_SUCCESS(errorCode)) {
+ log_err("u_charFromName(<control-111111>) = U+%04x but should fail - %s\n", c, u_errorName(errorCode));
+ }
+}
+
/* test u_isMirrored() and u_charMirror() ----------------------------------- */
static void
const RunTestData *testData;
int32_t nRuns;
} testDataEntries[] = {
- {testData1, LENGTHOF(testData1)},
- {testData2, LENGTHOF(testData2)}
+ {testData1, UPRV_LENGTHOF(testData1)},
+ {testData2, UPRV_LENGTHOF(testData2)}
};
- static const int32_t nTestEntries = LENGTHOF(testDataEntries);
+ static const int32_t nTestEntries = UPRV_LENGTHOF(testDataEntries);
int32_t testEntry;
for (testEntry = 0; testEntry < nTestEntries; testEntry += 1) {
{ 0x10909, UCHAR_BIDI_CLASS, U_RIGHT_TO_LEFT },
{ 0x10fe4, UCHAR_BIDI_CLASS, U_RIGHT_TO_LEFT },
- { 0x0605, UCHAR_BIDI_CLASS, U_RIGHT_TO_LEFT_ARABIC },
- { 0x061c, UCHAR_BIDI_CLASS, U_RIGHT_TO_LEFT_ARABIC },
+ { 0x061d, UCHAR_BIDI_CLASS, U_RIGHT_TO_LEFT_ARABIC },
{ 0x063f, UCHAR_BIDI_CLASS, U_RIGHT_TO_LEFT_ARABIC },
{ 0x070e, UCHAR_BIDI_CLASS, U_RIGHT_TO_LEFT_ARABIC },
{ 0x0775, UCHAR_BIDI_CLASS, U_RIGHT_TO_LEFT_ARABIC },
{ 0x155A, UCHAR_BLOCK, UBLOCK_UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS },
{ 0x1717, UCHAR_BLOCK, UBLOCK_TAGALOG },
{ 0x1900, UCHAR_BLOCK, UBLOCK_LIMBU },
- { 0x1AFF, UCHAR_BLOCK, UBLOCK_NO_BLOCK },
+ { 0x1CBF, UCHAR_BLOCK, UBLOCK_NO_BLOCK },
{ 0x3040, UCHAR_BLOCK, UBLOCK_HIRAGANA },
{ 0x1D0FF, UCHAR_BLOCK, UBLOCK_BYZANTINE_MUSICAL_SYMBOLS },
{ 0x50000, UCHAR_BLOCK, UBLOCK_NO_BLOCK },
{ 0xFF5B, UCHAR_BIDI_PAIRED_BRACKET_TYPE, U_BPT_OPEN },
{ 0xFF5D, UCHAR_BIDI_PAIRED_BRACKET_TYPE, U_BPT_CLOSE },
+ { -1, 0x700, 0 }, /* version break for Unicode 7.0 */
+
+ /* new character range with Joining_Group values */
+ { 0x10ABF, UCHAR_JOINING_GROUP, U_JG_NO_JOINING_GROUP },
+ { 0x10AC0, UCHAR_JOINING_GROUP, U_JG_MANICHAEAN_ALEPH },
+ { 0x10AC1, UCHAR_JOINING_GROUP, U_JG_MANICHAEAN_BETH },
+ { 0x10AEF, UCHAR_JOINING_GROUP, U_JG_MANICHAEAN_HUNDRED },
+ { 0x10AF0, UCHAR_JOINING_GROUP, U_JG_NO_JOINING_GROUP },
+
/* undefined UProperty values */
{ 0x61, 0x4a7, 0 },
{ 0x234bc, 0x15ed, 0 }
UChar32 c;
int32_t i, type;
- for(i=0; i<LENGTHOF(values); ++i) {
+ for(i=0; i<UPRV_LENGTHOF(values); ++i) {
c=values[i].c;
type=u_getIntPropertyValue(c, UCHAR_NUMERIC_TYPE);
nv=u_getNumericValue(c);
log_err("u_foldCase(U+%04lx, default)=U+%04lx != U+%04lx\n", (long)c, (long)c2, (long)simple);
}
if((which&CF_FULL)!=0) {
- length2=u_strFoldCase(t, LENGTHOF(t), s, length, 0, &errorCode);
+ length2=u_strFoldCase(t, UPRV_LENGTHOF(t), s, length, 0, &errorCode);
if(length2!=fullLength || 0!=u_memcmp(t, full, fullLength)) {
log_err("u_strFoldCase(U+%04lx, default) does not fold properly\n", (long)c);
}
log_err("u_foldCase(U+%04lx, turkic)=U+%04lx != U+%04lx\n", (long)c, (long)c2, (long)simple);
}
- length2=u_strFoldCase(t, LENGTHOF(t), s, length, U_FOLD_CASE_EXCLUDE_SPECIAL_I, &errorCode);
+ length2=u_strFoldCase(t, UPRV_LENGTHOF(t), s, length, U_FOLD_CASE_EXCLUDE_SPECIAL_I, &errorCode);
if(length2!=turkicFullLength || 0!=u_memcmp(t, turkicFull, length2)) {
log_err("u_strFoldCase(U+%04lx, turkic) does not fold properly\n", (long)c);
}