/******************************************************************** * COPYRIGHT: * Copyright (c) 1997-2003, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ /******************************************************************************** * * File CUCDTST.C * * Modification History: * Name Description * Madhu Katragadda Ported for C API, added tests for string functions ********************************************************************************* */ #include #include #include #include "unicode/utypes.h" #include "unicode/uchar.h" #include "unicode/putil.h" #include "unicode/ustring.h" #include "unicode/uloc.h" #include "cintltst.h" #include "uparse.h" #include "uprops.h" #include "usc_impl.h" #include "unormimp.h" #include "cucdapi.h" #define LENGTHOF(array) (sizeof(array)/sizeof((array)[0])) /* prototypes --------------------------------------------------------------- */ static void TestUpperLower(void); static void TestLetterNumber(void); static void TestMisc(void); static void TestPOSIX(void); static void TestControlPrint(void); static void TestIdentifier(void); static void TestUnicodeData(void); static void TestCodeUnit(void); static void TestCodePoint(void); static void TestCharLength(void); static void TestCharNames(void); static void TestMirroring(void); /* void TestUScriptCodeAPI(void);*/ /* defined in cucdapi.h */ static void TestUScriptRunAPI(void); static void TestAdditionalProperties(void); static void TestNumericProperties(void); static void TestPropertyNames(void); static void TestPropertyValues(void); static void TestConsistency(void); /* internal methods used */ static int32_t MakeProp(char* str); static int32_t MakeDir(char* str); #define LENGTHOF(array) (sizeof(array)/sizeof((array)[0])) /* test data ---------------------------------------------------------------- */ static const UChar LAST_CHAR_CODE_IN_FILE = 0xFFFD; static const char tagStrings[] = "MnMcMeNdNlNoZsZlZpCcCfCsCoCnLuLlLtLmLoPcPdPsPePoSmScSkSoPiPf"; static const int32_t tagValues[] = { /* Mn */ U_NON_SPACING_MARK, /* Mc */ U_COMBINING_SPACING_MARK, /* Me */ U_ENCLOSING_MARK, /* Nd */ U_DECIMAL_DIGIT_NUMBER, /* Nl */ U_LETTER_NUMBER, /* No */ U_OTHER_NUMBER, /* Zs */ U_SPACE_SEPARATOR, /* Zl */ U_LINE_SEPARATOR, /* Zp */ U_PARAGRAPH_SEPARATOR, /* Cc */ U_CONTROL_CHAR, /* Cf */ U_FORMAT_CHAR, /* Cs */ U_SURROGATE, /* Co */ U_PRIVATE_USE_CHAR, /* Cn */ U_UNASSIGNED, /* Lu */ U_UPPERCASE_LETTER, /* Ll */ U_LOWERCASE_LETTER, /* Lt */ U_TITLECASE_LETTER, /* Lm */ U_MODIFIER_LETTER, /* Lo */ U_OTHER_LETTER, /* Pc */ U_CONNECTOR_PUNCTUATION, /* Pd */ U_DASH_PUNCTUATION, /* Ps */ U_START_PUNCTUATION, /* Pe */ U_END_PUNCTUATION, /* Po */ U_OTHER_PUNCTUATION, /* Sm */ U_MATH_SYMBOL, /* Sc */ U_CURRENCY_SYMBOL, /* Sk */ U_MODIFIER_SYMBOL, /* So */ U_OTHER_SYMBOL, /* Pi */ U_INITIAL_PUNCTUATION, /* Pf */ U_FINAL_PUNCTUATION }; static const char dirStrings[][5] = { "L", "R", "EN", "ES", "ET", "AN", "CS", "B", "S", "WS", "ON", "LRE", "LRO", "AL", "RLE", "RLO", "PDF", "NSM", "BN" }; void addUnicodeTest(TestNode** root); void addUnicodeTest(TestNode** root) { addTest(root, &TestUnicodeData, "tsutil/cucdtst/TestUnicodeData"); addTest(root, &TestCodeUnit, "tsutil/cucdtst/TestCodeUnit"); addTest(root, &TestCodePoint, "tsutil/cucdtst/TestCodePoint"); addTest(root, &TestCharLength, "tsutil/cucdtst/TestCharLength"); addTest(root, &TestAdditionalProperties, "tsutil/cucdtst/TestAdditionalProperties"); addTest(root, &TestNumericProperties, "tsutil/cucdtst/TestNumericProperties"); addTest(root, &TestUpperLower, "tsutil/cucdtst/TestUpperLower"); addTest(root, &TestLetterNumber, "tsutil/cucdtst/TestLetterNumber"); addTest(root, &TestMisc, "tsutil/cucdtst/TestMisc"); addTest(root, &TestPOSIX, "tsutil/cucdtst/TestPOSIX"); addTest(root, &TestControlPrint, "tsutil/cucdtst/TestControlPrint"); addTest(root, &TestIdentifier, "tsutil/cucdtst/TestIdentifier"); addTest(root, &TestCharNames, "tsutil/cucdtst/TestCharNames"); addTest(root, &TestMirroring, "tsutil/cucdtst/TestMirroring"); addTest(root, &TestUScriptCodeAPI, "tsutil/cucdtst/TestUScriptCodeAPI"); addTest(root, &TestUScriptRunAPI, "tsutil/cucdtst/TestUScriptRunAPI"); addTest(root, &TestPropertyNames, "tsutil/cucdtst/TestPropertyNames"); addTest(root, &TestPropertyValues, "tsutil/cucdtst/TestPropertyValues"); addTest(root, &TestConsistency, "tsutil/cucdtst/TestConsistency"); } /*==================================================== */ /* test u_toupper() and u_tolower() */ /*==================================================== */ static void TestUpperLower() { const UChar upper[] = {0x41, 0x42, 0x00b2, 0x01c4, 0x01c6, 0x01c9, 0x01c8, 0x01c9, 0x000c, 0x0000}; const UChar lower[] = {0x61, 0x62, 0x00b2, 0x01c6, 0x01c6, 0x01c9, 0x01c9, 0x01c9, 0x000c, 0x0000}; U_STRING_DECL(upperTest, "abcdefg123hij.?:klmno", 21); U_STRING_DECL(lowerTest, "ABCDEFG123HIJ.?:KLMNO", 21); int32_t i; U_STRING_INIT(upperTest, "abcdefg123hij.?:klmno", 21); U_STRING_INIT(lowerTest, "ABCDEFG123HIJ.?:KLMNO", 21); /* Checks LetterLike Symbols which were previously a source of confusion [Bertrand A. D. 02/04/98] */ for (i=0x2100;i<0x2138;i++) { if(i!=0x2126 && i!=0x212a && i!=0x212b) { if (i != (int)u_tolower(i)) /* itself */ log_err("Failed case conversion with itself: U+%04x\n", i); if (i != (int)u_toupper(i)) log_err("Failed case conversion with itself: U+%04x\n", i); } } for(i=0; i < u_strlen(upper); i++){ if(u_tolower(upper[i]) != lower[i]){ log_err("FAILED u_tolower() for %lx Expected %lx Got %lx\n", upper[i], lower[i], u_tolower(upper[i])); } } log_verbose("testing upper lower\n"); for (i = 0; i < 21; i++) { if (u_isalpha(upperTest[i]) && !u_islower(upperTest[i])) { log_err("Failed isLowerCase test at %c\n", upperTest[i]); } else if (u_isalpha(lowerTest[i]) && !u_isupper(lowerTest[i])) { log_err("Failed isUpperCase test at %c\n", lowerTest[i]); } else if (upperTest[i] != u_tolower(lowerTest[i])) { log_err("Failed case conversion from %c To %c :\n", lowerTest[i], upperTest[i]); } else if (lowerTest[i] != u_toupper(upperTest[i])) { log_err("Failed case conversion : %c To %c \n", upperTest[i], lowerTest[i]); } else if (upperTest[i] != u_tolower(upperTest[i])) { log_err("Failed case conversion with itself: %c\n", upperTest[i]); } else if (lowerTest[i] != u_toupper(lowerTest[i])) { log_err("Failed case conversion with itself: %c\n", lowerTest[i]); } } log_verbose("done testing upper lower\n"); log_verbose("testing u_istitle\n"); { static const UChar expected[] = { 0x1F88, 0x1F89, 0x1F8A, 0x1F8B, 0x1F8C, 0x1F8D, 0x1F8E, 0x1F8F, 0x1F88, 0x1F89, 0x1F8A, 0x1F8B, 0x1F8C, 0x1F8D, 0x1F8E, 0x1F8F, 0x1F98, 0x1F99, 0x1F9A, 0x1F9B, 0x1F9C, 0x1F9D, 0x1F9E, 0x1F9F, 0x1F98, 0x1F99, 0x1F9A, 0x1F9B, 0x1F9C, 0x1F9D, 0x1F9E, 0x1F9F, 0x1FA8, 0x1FA9, 0x1FAA, 0x1FAB, 0x1FAC, 0x1FAD, 0x1FAE, 0x1FAF, 0x1FA8, 0x1FA9, 0x1FAA, 0x1FAB, 0x1FAC, 0x1FAD, 0x1FAE, 0x1FAF, 0x1FBC, 0x1FBC, 0x1FCC, 0x1FCC, 0x1FFC, 0x1FFC, }; int32_t num = sizeof(expected)/sizeof(expected[0]); for(i=0; i=UCHAR_MAX_VALUE + 1) { log_err("error in UnicodeData.txt: code point %lu out of range\n", c); return; } /* get general category, field 2 */ *fields[2][1]=0; type = (int8_t)tagValues[MakeProp(fields[2][0])]; if(u_charType(c)!=type) { log_err("error: u_charType(U+%04lx)==%u instead of %u\n", c, u_charType(c), type); } if((uint32_t)u_getIntPropertyValue(c, UCHAR_GENERAL_CATEGORY_MASK)!=U_MASK(type)) { log_err("error: (uint32_t)u_getIntPropertyValue(U+%04lx, UCHAR_GENERAL_CATEGORY_MASK)!=U_MASK(u_charType())\n", c); } /* get canonical combining class, field 3 */ value=strtoul(fields[3][0], &end, 10); if(end<=fields[3][0] || end!=fields[3][1]) { log_err("error: syntax error in field 3 at code 0x%lx\n", c); return; } if(value>255) { log_err("error in UnicodeData.txt: combining class %lu out of range\n", value); return; } #if !UCONFIG_NO_NORMALIZATION if(value!=u_getCombiningClass(c) || value!=(uint32_t)u_getIntPropertyValue(c, UCHAR_CANONICAL_COMBINING_CLASS)) { log_err("error: u_getCombiningClass(U+%04lx)==%hu instead of %lu\n", c, u_getCombiningClass(c), value); } #endif /* get BiDi category, field 4 */ *fields[4][1]=0; i=MakeDir(fields[4][0]); if(i!=u_charDirection(c) || i!=u_getIntPropertyValue(c, UCHAR_BIDI_CLASS)) { log_err("error: u_charDirection(U+%04lx)==%u instead of %u (%s)\n", c, u_charDirection(c), MakeDir(fields[4][0]), fields[4][0]); } /* get ISO Comment, field 11 */ *fields[11][1]=0; i=u_getISOComment(c, buffer, sizeof(buffer), pErrorCode); if(U_FAILURE(*pErrorCode) || 0!=strcmp(fields[11][0], buffer)) { log_err("error: u_getISOComment(U+%04lx) wrong (%s): \"%s\" should be \"%s\"\n", c, u_errorName(*pErrorCode), U_FAILURE(*pErrorCode) ? buffer : "[error]", fields[11][0]); } /* get uppercase mapping, field 12 */ if(fields[12][0]!=fields[12][1]) { value=strtoul(fields[12][0], &end, 16); if(end!=fields[12][1]) { log_err("error: syntax error in field 12 at code 0x%lx\n", c); return; } if((UChar32)value!=u_toupper(c)) { log_err("error: u_toupper(U+%04lx)==U+%04lx instead of U+%04lx\n", c, u_toupper(c), value); } } else { /* no case mapping: the API must map the code point to itself */ if(c!=u_toupper(c)) { log_err("error: U+%04lx does not have an uppercase mapping but u_toupper()==U+%04lx\n", c, u_toupper(c)); } } /* get lowercase mapping, field 13 */ if(fields[13][0]!=fields[13][1]) { value=strtoul(fields[13][0], &end, 16); if(end!=fields[13][1]) { log_err("error: syntax error in field 13 at code 0x%lx\n", c); return; } if((UChar32)value!=u_tolower(c)) { log_err("error: u_tolower(U+%04lx)==U+%04lx instead of U+%04lx\n", c, u_tolower(c), value); } } else { /* no case mapping: the API must map the code point to itself */ if(c!=u_tolower(c)) { log_err("error: U+%04lx does not have a lowercase mapping but u_tolower()==U+%04lx\n", c, u_tolower(c)); } } /* get titlecase mapping, field 14 */ if(fields[14][0]!=fields[14][1]) { value=strtoul(fields[14][0], &end, 16); if(end!=fields[14][1]) { log_err("error: syntax error in field 14 at code 0x%lx\n", c); return; } if((UChar32)value!=u_totitle(c)) { log_err("error: u_totitle(U+%04lx)==U+%04lx instead of U+%04lx\n", c, u_totitle(c), value); } } else { /* no case mapping: the API must map the code point to itself */ if(c!=u_totitle(c)) { log_err("error: U+%04lx does not have a titlecase mapping but u_totitle()==U+%04lx\n", c, u_totitle(c)); } } } static UBool U_CALLCONV enumTypeRange(const void *context, UChar32 start, UChar32 limit, UCharCategory type) { static const UChar32 test[][2]={ {0x41, U_UPPERCASE_LETTER}, {0x308, U_NON_SPACING_MARK}, {0xfffe, U_GENERAL_OTHER_TYPES}, {0xe0041, U_FORMAT_CHAR}, {0xeffff, U_UNASSIGNED} }; /* default Bidi classes for unassigned code points */ static const int32_t defaultBidi[][2]={ /* { limit, class } */ { 0x0590, U_LEFT_TO_RIGHT }, { 0x0600, U_RIGHT_TO_LEFT }, { 0x07C0, U_RIGHT_TO_LEFT_ARABIC }, { 0x0900, U_RIGHT_TO_LEFT }, { 0xFB1D, U_LEFT_TO_RIGHT }, { 0xFB50, U_RIGHT_TO_LEFT }, { 0xFE00, U_RIGHT_TO_LEFT_ARABIC }, { 0xFE70, U_LEFT_TO_RIGHT }, { 0xFF00, U_RIGHT_TO_LEFT_ARABIC }, { 0x10800, U_LEFT_TO_RIGHT }, { 0x11000, U_RIGHT_TO_LEFT }, { 0x110000, U_LEFT_TO_RIGHT } }; UChar32 c; int i, count; if(0!=strcmp((const char *)context, "a1")) { log_err("error: u_enumCharTypes() passes on an incorrect context pointer\n"); return FALSE; } count=sizeof(test)/sizeof(test[0]); for(i=0; itest[count-1][0]) { log_err("error: u_enumCharTypes() has range [U+%04lx, U+%04lx[ with %ld after it should have stopped\n", start, limit, (long)type); return FALSE; } /* * LineBreak.txt specifies: * # - Assigned characters that are not listed explicitly are given the value * # "AL". * # - Unassigned characters are given the value "XX". * * PUA characters are listed explicitly with "XX". * Verify that no assigned character has "XX". */ if(type!=U_UNASSIGNED && type!=U_PRIVATE_USE_CHAR) { c=start; while(c= 4 && i< 8){ if(!(UTF_IS_LEAD(c)) || UTF_IS_SINGLE(c) || UTF_IS_TRAIL(c) || !(UTF_IS_SURROGATE(c))){ log_err("ERROR: U+%04x is a first surrogate", c); } } if(i >= 8 && i< 12){ if(!(UTF_IS_TRAIL(c)) || UTF_IS_SINGLE(c) || UTF_IS_LEAD(c) || !(UTF_IS_SURROGATE(c))){ log_err("ERROR: U+%04x is a second surrogate", c); } } } } static void TestCodePoint(){ const UChar32 codePoint[]={ /*surrogate, notvalid(codepoint), not a UnicodeChar, not Error */ 0xd800, 0xdbff, 0xdc00, 0xdfff, 0xdc04, 0xd821, /*not a surrogate, valid, isUnicodeChar , not Error*/ 0x20ac, 0xd7ff, 0xe000, 0xe123, 0x0061, 0xe065, 0x20402, 0x24506, 0x23456, 0x20402, 0x10402, 0x23456, /*not a surrogate, not valid, isUnicodeChar, isError */ 0x0015, 0x009f, /*not a surrogate, not valid, not isUnicodeChar, isError */ 0xffff, 0xfffe, }; int32_t i; for(i=0; i<(int32_t)(sizeof(codePoint)/sizeof(codePoint[0])); i++){ UChar32 c=codePoint[i]; if(i<6){ if(!UTF_IS_SURROGATE(c) || !U_IS_SURROGATE(c) || !U16_IS_SURROGATE(c)){ log_err("ERROR: isSurrogate() failed for U+%04x\n", c); } if(UTF_IS_VALID(c)){ log_err("ERROR: isValid() failed for U+%04x\n", c); } if(UTF_IS_UNICODE_CHAR(c) || U_IS_UNICODE_CHAR(c)){ log_err("ERROR: isUnicodeChar() failed for U+%04x\n", c); } if(UTF_IS_ERROR(c)){ log_err("ERROR: isError() failed for U+%04x\n", c); } }else if(i >=6 && i<18){ if(UTF_IS_SURROGATE(c) || U_IS_SURROGATE(c) || U16_IS_SURROGATE(c)){ log_err("ERROR: isSurrogate() failed for U+%04x\n", c); } if(!UTF_IS_VALID(c)){ log_err("ERROR: isValid() failed for U+%04x\n", c); } if(!UTF_IS_UNICODE_CHAR(c) || !U_IS_UNICODE_CHAR(c)){ log_err("ERROR: isUnicodeChar() failed for U+%04x\n", c); } if(UTF_IS_ERROR(c)){ log_err("ERROR: isError() failed for U+%04x\n", c); } }else if(i >=18 && i<20){ if(UTF_IS_SURROGATE(c) || U_IS_SURROGATE(c) || U16_IS_SURROGATE(c)){ log_err("ERROR: isSurrogate() failed for U+%04x\n", c); } if(UTF_IS_VALID(c)){ log_err("ERROR: isValid() failed for U+%04x\n", c); } if(!UTF_IS_UNICODE_CHAR(c) || !U_IS_UNICODE_CHAR(c)){ log_err("ERROR: isUnicodeChar() failed for U+%04x\n", c); } if(!UTF_IS_ERROR(c)){ log_err("ERROR: isError() failed for U+%04x\n", c); } } else if(i >=18 && i<(int32_t)(sizeof(codePoint)/sizeof(codePoint[0]))){ if(UTF_IS_SURROGATE(c) || U_IS_SURROGATE(c) || U16_IS_SURROGATE(c)){ log_err("ERROR: isSurrogate() failed for U+%04x\n", c); } if(UTF_IS_VALID(c)){ log_err("ERROR: isValid() failed for U+%04x\n", c); } if(UTF_IS_UNICODE_CHAR(c) || U_IS_UNICODE_CHAR(c)){ log_err("ERROR: isUnicodeChar() failed for U+%04x\n", c); } if(!UTF_IS_ERROR(c)){ log_err("ERROR: isError() failed for U+%04x\n", c); } } } if( !U_IS_BMP(0) || !U_IS_BMP(0x61) || !U_IS_BMP(0x20ac) || !U_IS_BMP(0xd9da) || !U_IS_BMP(0xdfed) || !U_IS_BMP(0xffff) || U_IS_BMP(U_SENTINEL) || U_IS_BMP(0x10000) || U_IS_BMP(0x50005) || U_IS_BMP(0x10ffff) || U_IS_BMP(0x110000) || U_IS_BMP(0x7fffffff) ) { log_err("error with U_IS_BMP()\n"); } if( U_IS_SUPPLEMENTARY(0) || U_IS_SUPPLEMENTARY(0x61) || U_IS_SUPPLEMENTARY(0x20ac) || U_IS_SUPPLEMENTARY(0xd9da) || U_IS_SUPPLEMENTARY(0xdfed) || U_IS_SUPPLEMENTARY(0xffff) || U_IS_SUPPLEMENTARY(U_SENTINEL) || !U_IS_SUPPLEMENTARY(0x10000) || !U_IS_SUPPLEMENTARY(0x50005) || !U_IS_SUPPLEMENTARY(0x10ffff) || U_IS_SUPPLEMENTARY(0x110000) || U_IS_SUPPLEMENTARY(0x7fffffff) ) { log_err("error with U_IS_SUPPLEMENTARY()\n"); } } static void TestCharLength() { const int32_t codepoint[]={ 1, 0x0061, 1, 0xe065, 1, 0x20ac, 2, 0x20402, 2, 0x23456, 2, 0x24506, 2, 0x20402, 2, 0x10402, 1, 0xd7ff, 1, 0xe000 }; int32_t i; UBool multiple; for(i=0; i<(int32_t)(sizeof(codepoint)/sizeof(codepoint[0])); i=(int16_t)(i+2)){ UChar32 c=codepoint[i+1]; if(UTF_CHAR_LENGTH(c) != codepoint[i] || U16_LENGTH(c) != codepoint[i]){ log_err("The no: of code units for U+%04x:- Expected: %d Got: %d\n", c, codepoint[i], UTF_CHAR_LENGTH(c)); } multiple=(UBool)(codepoint[i] == 1 ? FALSE : TRUE); if(UTF_NEED_MULTIPLE_UCHAR(c) != multiple){ log_err("ERROR: Unicode::needMultipleUChar() failed for U+%04x\n", c); } } } /*internal functions ----*/ static int32_t MakeProp(char* str) { int32_t result = 0; char* matchPosition =0; matchPosition = strstr(tagStrings, str); if (matchPosition == 0) { log_err("unrecognized type letter "); log_err(str); } else result = ((matchPosition - tagStrings) / 2); return result; } static int32_t MakeDir(char* str) { int32_t pos = 0; for (pos = 0; pos < 19; pos++) { if (strcmp(str, dirStrings[pos]) == 0) { return pos; } } return -1; } /* test u_charName() -------------------------------------------------------- */ static const struct { uint32_t code; const char *name, *oldName, *extName; } names[]={ {0x0061, "LATIN SMALL LETTER A", "", "LATIN SMALL LETTER A"}, {0x0284, "LATIN SMALL LETTER DOTLESS J WITH STROKE AND HOOK", "LATIN SMALL LETTER DOTLESS J BAR HOOK", "LATIN SMALL LETTER DOTLESS J WITH STROKE AND HOOK" }, {0x3401, "CJK UNIFIED IDEOGRAPH-3401", "", "CJK UNIFIED IDEOGRAPH-3401" }, {0x7fed, "CJK UNIFIED IDEOGRAPH-7FED", "", "CJK UNIFIED IDEOGRAPH-7FED" }, {0xac00, "HANGUL SYLLABLE GA", "", "HANGUL SYLLABLE GA" }, {0xd7a3, "HANGUL SYLLABLE HIH", "", "HANGUL SYLLABLE HIH" }, {0xd800, "", "", "" }, {0xdc00, "", "", "" }, {0xff08, "FULLWIDTH LEFT PARENTHESIS", "FULLWIDTH OPENING PARENTHESIS", "FULLWIDTH LEFT PARENTHESIS" }, {0xffe5, "FULLWIDTH YEN SIGN", "", "FULLWIDTH YEN SIGN" }, {0xffff, "", "", "" }, {0x23456, "CJK UNIFIED IDEOGRAPH-23456", "", "CJK UNIFIED IDEOGRAPH-23456" } }; static UBool enumCharNamesFn(void *context, UChar32 code, UCharNameChoice nameChoice, const char *name, int32_t length) { int32_t *pCount=(int32_t *)context; int i; if(length<=0 || length!=(int32_t)strlen(name)) { /* should not be called with an empty string or invalid length */ log_err("u_enumCharName(0x%lx)=%s but length=%ld\n", name, length); return TRUE; } ++*pCount; for(i=0; ilast != (int32_t) code - 1) { if (ecncp->last < 0) { log_err("u_enumCharName(0x%lx - Ext) after u_enumCharName(0x%lx - Ext) instead of u_enumCharName(0x%lx - Ext)\n", code, ecncp->last, ecncp->last + 1); } else { log_err("u_enumCharName(0x%lx - Ext) instead of u_enumCharName(0x0 - Ext)\n", code); } } ecncp->last = (int32_t) code; if (!*name) { log_err("u_enumCharName(0x%lx - Ext) should not be an empty string\n", code); } return enumCharNamesFn(&ecncp->length, code, nameChoice, name, length); } /** * This can be made more efficient by moving it into putil.c and having * it directly access the ebcdic translation tables. * TODO: If we get this method in putil.c, then delete it from here. */ static UChar u_charToUChar(char c) { UChar uc; u_charsToUChars(&c, &uc, 1); return uc; } static void TestCharNames() { static char name[80]; UErrorCode errorCode=U_ZERO_ERROR; struct enumExtCharNamesContext extContext; int32_t length; UChar32 c; int32_t i; log_verbose("Testing uprv_getMaxCharNameLength()\n"); length=uprv_getMaxCharNameLength(); if(length==0) { /* no names data available */ return; } if(length<83) { /* Unicode 3.2 max char name length */ log_err("uprv_getMaxCharNameLength()=%d is too short"); } /* ### TODO same tests for max ISO comment length as for max name length */ log_verbose("Testing u_charName()\n"); for(i=0; i<(int32_t)(sizeof(names)/sizeof(names[0])); ++i) { /* modern Unicode character name */ length=u_charName(names[i].code, U_UNICODE_CHAR_NAME, name, sizeof(name), &errorCode); if(U_FAILURE(errorCode)) { log_err("u_charName(0x%lx) error %s\n", names[i].code, u_errorName(errorCode)); return; } if(length<0 || 0!=strcmp(name, names[i].name) || length!=(uint16_t)strlen(name)) { log_err("u_charName(0x%lx) gets: %s (length %ld) instead of: %s\n", names[i].code, name, length, names[i].name); } /* find the modern name */ if (*names[i].name) { c=u_charFromName(U_UNICODE_CHAR_NAME, names[i].name, &errorCode); if(U_FAILURE(errorCode)) { log_err("u_charFromName(%s) error %s\n", names[i].name, u_errorName(errorCode)); return; } if(c!=(UChar32)names[i].code) { log_err("u_charFromName(%s) gets 0x%lx instead of 0x%lx\n", names[i].name, c, names[i].code); } } /* Unicode 1.0 character name */ length=u_charName(names[i].code, U_UNICODE_10_CHAR_NAME, name, sizeof(name), &errorCode); if(U_FAILURE(errorCode)) { log_err("u_charName(0x%lx - 1.0) error %s\n", names[i].code, u_errorName(errorCode)); return; } if(length<0 || (length>0 && 0!=strcmp(name, names[i].oldName)) || length!=(uint16_t)strlen(name)) { log_err("u_charName(0x%lx - 1.0) gets %s length %ld instead of nothing or %s\n", names[i].code, name, length, names[i].oldName); } /* find the Unicode 1.0 name if it is stored (length>0 means that we could read it) */ if(names[i].oldName[0]!=0 /* && length>0 */) { c=u_charFromName(U_UNICODE_10_CHAR_NAME, names[i].oldName, &errorCode); if(U_FAILURE(errorCode)) { log_err("u_charFromName(%s - 1.0) error %s\n", names[i].oldName, u_errorName(errorCode)); return; } if(c!=(UChar32)names[i].code) { log_err("u_charFromName(%s - 1.0) gets 0x%lx instead of 0x%lx\n", names[i].oldName, c, names[i].code); } } } /* test u_enumCharNames() */ length=0; errorCode=U_ZERO_ERROR; u_enumCharNames(UCHAR_MIN_VALUE, UCHAR_MAX_VALUE + 1, enumCharNamesFn, &length, U_UNICODE_CHAR_NAME, &errorCode); if(U_FAILURE(errorCode) || length<94140) { log_err("u_enumCharNames(%ld..%lx) error %s names count=%ld\n", UCHAR_MIN_VALUE, UCHAR_MAX_VALUE, u_errorName(errorCode), length); } extContext.length = 0; extContext.last = -1; errorCode=U_ZERO_ERROR; u_enumCharNames(UCHAR_MIN_VALUE, UCHAR_MAX_VALUE + 1, enumExtCharNamesFn, &extContext, U_EXTENDED_CHAR_NAME, &errorCode); if(U_FAILURE(errorCode) || extContext.lengthmaxLength) { maxLength=len; } for (i=0; i= BUFSIZE) { l1 = BUFSIZE-1; pat[l1] = 0; } if (l2 >= BUFSIZE) { l2 = BUFSIZE-1; dumbPat[l2] = 0; } if (!ok) { log_err("FAIL: uprv_getCharNameCharacters() returned %s, expected %s (too many lowercase a-z are ok)\n", aescstrdup(pat, l1), aescstrdup(dumbPat, l2)); } else if(VERBOSITY) { log_verbose("Ok: uprv_getCharNameCharacters() returned %s\n", aescstrdup(pat, l1)); } uset_close(set); uset_close(dumb); } /* ### TODO: test error cases and other interesting things */ } /* test u_isMirrored() and u_charMirror() ----------------------------------- */ static void TestMirroring() { log_verbose("Testing u_isMirrored()\n"); if(!(u_isMirrored(0x28) && u_isMirrored(0xbb) && u_isMirrored(0x2045) && u_isMirrored(0x232a) && !u_isMirrored(0x27) && !u_isMirrored(0x61) && !u_isMirrored(0x284) && !u_isMirrored(0x3400) ) ) { log_err("u_isMirrored() does not work correctly\n"); } log_verbose("Testing u_charMirror()\n"); if(!(u_charMirror(0x3c)==0x3e && u_charMirror(0x5d)==0x5b && u_charMirror(0x208d)==0x208e && u_charMirror(0x3017)==0x3016 && u_charMirror(0x2e)==0x2e && u_charMirror(0x6f3)==0x6f3 && u_charMirror(0x301c)==0x301c && u_charMirror(0xa4ab)==0xa4ab ) ) { log_err("u_charMirror() does not work correctly\n"); } } struct RunTestData { const char *runText; UScriptCode runCode; }; typedef struct RunTestData RunTestData; static void CheckScriptRuns(UScriptRun *scriptRun, int32_t *runStarts, const RunTestData *testData, int32_t nRuns, const char *prefix) { int32_t run, runStart, runLimit; UScriptCode runCode; /* iterate over all the runs */ run = 0; while (uscript_nextRun(scriptRun, &runStart, &runLimit, &runCode)) { if (runStart != runStarts[run]) { log_err("%s: incorrect start offset for run %d: expected %d, got %d\n", prefix, run, runStarts[run], runStart); } if (runLimit != runStarts[run + 1]) { log_err("%s: incorrect limit offset for run %d: expected %d, got %d\n", prefix, run, runStarts[run + 1], runLimit); } if (runCode != testData[run].runCode) { log_err("%s: incorrect script for run %d: expected \"%s\", got \"%s\"\n", prefix, run, uscript_getName(testData[run].runCode), uscript_getName(runCode)); } run += 1; /* stop when we've seen all the runs we expect to see */ if (run >= nRuns) { break; } } /* Complain if we didn't see then number of runs we expected */ if (run != nRuns) { log_err("%s: incorrect number of runs: expected %d, got %d\n", prefix, run, nRuns); } } static void TestUScriptRunAPI() { static const RunTestData testData[] = { {"\\u0020\\u0946\\u0939\\u093F\\u0928\\u094D\\u0926\\u0940\\u0020", USCRIPT_DEVANAGARI}, {"\\u0627\\u0644\\u0639\\u0631\\u0628\\u064A\\u0629\\u0020", USCRIPT_ARABIC}, {"\\u0420\\u0443\\u0441\\u0441\\u043A\\u0438\\u0439\\u0020", USCRIPT_CYRILLIC}, {"English (", USCRIPT_LATIN}, {"\\u0E44\\u0E17\\u0E22", USCRIPT_THAI}, {") ", USCRIPT_LATIN}, {"\\u6F22\\u5B75", USCRIPT_HAN}, {"\\u3068\\u3072\\u3089\\u304C\\u306A\\u3068", USCRIPT_HIRAGANA}, {"\\u30AB\\u30BF\\u30AB\\u30CA", USCRIPT_KATAKANA}, {"\\U00010400\\U00010401\\U00010402\\U00010403", USCRIPT_DESERET} }; int32_t nTestRuns = sizeof testData / sizeof testData[0]; UChar testString[1024]; int32_t runStarts[256]; int32_t run, stringLimit; UScriptRun *scriptRun = NULL; UErrorCode err; /* * Fill in the test string and the runStarts array. */ stringLimit = 0; for (run = 0; run < nTestRuns; run += 1) { runStarts[run] = stringLimit; stringLimit += u_unescape(testData[run].runText, &testString[stringLimit], 1024 - stringLimit); /*stringLimit -= 1;*/ } /* The limit of the last run */ runStarts[nTestRuns] = stringLimit; /* * Make sure that calling uscript_OpenRun with a NULL text pointer * and a non-zero text length returns the correct error. */ err = U_ZERO_ERROR; scriptRun = uscript_openRun(NULL, stringLimit, &err); if (err != U_ILLEGAL_ARGUMENT_ERROR) { log_err("uscript_openRun(NULL, stringLimit, &err) returned %s instead of U_ILLEGAL_ARGUMENT_ERROR.\n", u_errorName(err)); } if (scriptRun != NULL) { log_err("uscript_openRun(NULL, stringLimit, &err) returned a non-NULL result.\n"); uscript_closeRun(scriptRun); } /* * Make sure that calling uscript_OpenRun with a non-NULL text pointer * and a zero text length returns the correct error. */ err = U_ZERO_ERROR; scriptRun = uscript_openRun(testString, 0, &err); if (err != U_ILLEGAL_ARGUMENT_ERROR) { log_err("uscript_openRun(testString, 0, &err) returned %s instead of U_ILLEGAL_ARGUMENT_ERROR.\n", u_errorName(err)); } if (scriptRun != NULL) { log_err("uscript_openRun(testString, 0, &err) returned a non-NULL result.\n"); uscript_closeRun(scriptRun); } /* * Make sure that calling uscript_openRun with a NULL text pointer * and a zero text length doesn't return an error. */ err = U_ZERO_ERROR; scriptRun = uscript_openRun(NULL, 0, &err); if (U_FAILURE(err)) { log_err("Got error %s from uscript_openRun(NULL, 0, &err)\n", u_errorName(err)); } /* Make sure that the empty iterator doesn't find any runs */ if (uscript_nextRun(scriptRun, NULL, NULL, NULL)) { log_err("uscript_nextRun(...) returned TRUE for an empty iterator.\n"); } /* * Make sure that calling uscript_setRunText with a NULL text pointer * and a non-zero text length returns the correct error. */ err = U_ZERO_ERROR; uscript_setRunText(scriptRun, NULL, stringLimit, &err); if (err != U_ILLEGAL_ARGUMENT_ERROR) { log_err("uscript_setRunText(scriptRun, NULL, stringLimit, &err) returned %s instead of U_ILLEGAL_ARGUMENT_ERROR.\n", u_errorName(err)); } /* * Make sure that calling uscript_OpenRun with a non-NULL text pointer * and a zero text length returns the correct error. */ err = U_ZERO_ERROR; uscript_setRunText(scriptRun, testString, 0, &err); if (err != U_ILLEGAL_ARGUMENT_ERROR) { log_err("uscript_setRunText(scriptRun, testString, 0, &err) returned %s instead of U_ILLEGAL_ARGUMENT_ERROR.\n", u_errorName(err)); } /* * Now call uscript_setRunText on the empty iterator * and make sure that it works. */ err = U_ZERO_ERROR; uscript_setRunText(scriptRun, testString, stringLimit, &err); if (U_FAILURE(err)) { log_err("Got error %s from uscript_setRunText(...)\n", u_errorName(err)); } else { CheckScriptRuns(scriptRun, runStarts, testData, nTestRuns, "uscript_setRunText"); } uscript_closeRun(scriptRun); /* * Now open an interator over the testString * using uscript_openRun and make sure that it works */ scriptRun = uscript_openRun(testString, stringLimit, &err); if (U_FAILURE(err)) { log_err("Got error %s from uscript_openRun(...)\n", u_errorName(err)); } else { CheckScriptRuns(scriptRun, runStarts, testData, nTestRuns, "uscript_openRun"); } /* Now reset the iterator, and make sure * that it still works. */ uscript_resetRun(scriptRun); CheckScriptRuns(scriptRun, runStarts, testData, nTestRuns, "uscript_resetRun"); /* Close the iterator */ uscript_closeRun(scriptRun); } /* test additional, non-core properties */ static void TestAdditionalProperties() { /* test data for u_charAge() */ static const struct { UChar32 c; UVersionInfo version; } charAges[]={ {0x41, { 1, 1, 0, 0 }}, {0xffff, { 1, 1, 0, 0 }}, {0x20ab, { 2, 0, 0, 0 }}, {0x2fffe, { 2, 0, 0, 0 }}, {0x20ac, { 2, 1, 0, 0 }}, {0xfb1d, { 3, 0, 0, 0 }}, {0x3f4, { 3, 1, 0, 0 }}, {0x10300, { 3, 1, 0, 0 }}, {0x220, { 3, 2, 0, 0 }}, {0xff60, { 3, 2, 0, 0 }} }; /* test data for u_hasBinaryProperty() */ static int32_t props[][3]={ /* code point, property, value */ { 0x0627, UCHAR_ALPHABETIC, TRUE }, { 0x1034a, UCHAR_ALPHABETIC, TRUE }, { 0x2028, UCHAR_ALPHABETIC, FALSE }, { 0x0066, UCHAR_ASCII_HEX_DIGIT, TRUE }, { 0x0067, UCHAR_ASCII_HEX_DIGIT, FALSE }, { 0x202c, UCHAR_BIDI_CONTROL, TRUE }, { 0x202f, UCHAR_BIDI_CONTROL, FALSE }, { 0x003c, UCHAR_BIDI_MIRRORED, TRUE }, { 0x003d, UCHAR_BIDI_MIRRORED, FALSE }, { 0x058a, UCHAR_DASH, TRUE }, { 0x007e, UCHAR_DASH, FALSE }, { 0x0c4d, UCHAR_DIACRITIC, TRUE }, { 0x3000, UCHAR_DIACRITIC, FALSE }, { 0x0e46, UCHAR_EXTENDER, TRUE }, { 0x0020, UCHAR_EXTENDER, FALSE }, #if !UCONFIG_NO_NORMALIZATION { 0xfb1d, UCHAR_FULL_COMPOSITION_EXCLUSION, TRUE }, { 0x1d15f, UCHAR_FULL_COMPOSITION_EXCLUSION, TRUE }, { 0xfb1e, UCHAR_FULL_COMPOSITION_EXCLUSION, FALSE }, #endif { 0x0044, UCHAR_HEX_DIGIT, TRUE }, { 0xff46, UCHAR_HEX_DIGIT, TRUE }, { 0x0047, UCHAR_HEX_DIGIT, FALSE }, { 0x30fb, UCHAR_HYPHEN, TRUE }, { 0xfe58, UCHAR_HYPHEN, FALSE }, { 0x2172, UCHAR_ID_CONTINUE, TRUE }, { 0x0307, UCHAR_ID_CONTINUE, TRUE }, { 0x005c, UCHAR_ID_CONTINUE, FALSE }, { 0x2172, UCHAR_ID_START, TRUE }, { 0x007a, UCHAR_ID_START, TRUE }, { 0x0039, UCHAR_ID_START, FALSE }, { 0x4db5, UCHAR_IDEOGRAPHIC, TRUE }, { 0x2f999, UCHAR_IDEOGRAPHIC, TRUE }, { 0x2f99, UCHAR_IDEOGRAPHIC, FALSE }, { 0x200c, UCHAR_JOIN_CONTROL, TRUE }, { 0x2029, UCHAR_JOIN_CONTROL, FALSE }, { 0x1d7bc, UCHAR_LOWERCASE, TRUE }, { 0x0345, UCHAR_LOWERCASE, TRUE }, { 0x0030, UCHAR_LOWERCASE, FALSE }, { 0x1d7a9, UCHAR_MATH, TRUE }, { 0x2135, UCHAR_MATH, TRUE }, { 0x0062, UCHAR_MATH, FALSE }, { 0xfde1, UCHAR_NONCHARACTER_CODE_POINT, TRUE }, { 0x10ffff, UCHAR_NONCHARACTER_CODE_POINT, TRUE }, { 0x10fffd, UCHAR_NONCHARACTER_CODE_POINT, FALSE }, { 0x0022, UCHAR_QUOTATION_MARK, TRUE }, { 0xff62, UCHAR_QUOTATION_MARK, TRUE }, { 0xd840, UCHAR_QUOTATION_MARK, FALSE }, { 0x061f, UCHAR_TERMINAL_PUNCTUATION, TRUE }, { 0xe003f, UCHAR_TERMINAL_PUNCTUATION, FALSE }, { 0x1d44a, UCHAR_UPPERCASE, TRUE }, { 0x2162, UCHAR_UPPERCASE, TRUE }, { 0x0345, UCHAR_UPPERCASE, FALSE }, { 0x0020, UCHAR_WHITE_SPACE, TRUE }, { 0x202f, UCHAR_WHITE_SPACE, TRUE }, { 0x3001, UCHAR_WHITE_SPACE, FALSE }, { 0x0711, UCHAR_XID_CONTINUE, TRUE }, { 0x1d1aa, UCHAR_XID_CONTINUE, TRUE }, { 0x007c, UCHAR_XID_CONTINUE, FALSE }, { 0x16ee, UCHAR_XID_START, TRUE }, { 0x23456, UCHAR_XID_START, TRUE }, { 0x1d1aa, UCHAR_XID_START, FALSE }, /* * Version break: * The following properties are only supported starting with the * Unicode version indicated in the second field. */ { -1, 0x32, 0 }, { 0x180c, UCHAR_DEFAULT_IGNORABLE_CODE_POINT, TRUE }, { 0xfe02, UCHAR_DEFAULT_IGNORABLE_CODE_POINT, TRUE }, { 0x1801, UCHAR_DEFAULT_IGNORABLE_CODE_POINT, FALSE }, { 0x0341, UCHAR_DEPRECATED, TRUE }, { 0xe0041, UCHAR_DEPRECATED, FALSE }, { 0x00a0, UCHAR_GRAPHEME_BASE, TRUE }, { 0x0a4d, UCHAR_GRAPHEME_BASE, FALSE }, { 0xff9f, UCHAR_GRAPHEME_BASE, TRUE }, /* changed from Unicode 3.2 to 4 */ { 0x0300, UCHAR_GRAPHEME_EXTEND, TRUE }, { 0xff9f, UCHAR_GRAPHEME_EXTEND, FALSE }, /* changed from Unicode 3.2 to 4 */ { 0x0603, UCHAR_GRAPHEME_EXTEND, FALSE }, { 0x0a4d, UCHAR_GRAPHEME_LINK, TRUE }, { 0xff9f, UCHAR_GRAPHEME_LINK, FALSE }, { 0x2ff7, UCHAR_IDS_BINARY_OPERATOR, TRUE }, { 0x2ff3, UCHAR_IDS_BINARY_OPERATOR, FALSE }, { 0x2ff3, UCHAR_IDS_TRINARY_OPERATOR, TRUE }, { 0x2f03, UCHAR_IDS_TRINARY_OPERATOR, FALSE }, { 0x0ec1, UCHAR_LOGICAL_ORDER_EXCEPTION, TRUE }, { 0xdcba, UCHAR_LOGICAL_ORDER_EXCEPTION, FALSE }, { 0x2e9b, UCHAR_RADICAL, TRUE }, { 0x4e00, UCHAR_RADICAL, FALSE }, { 0x012f, UCHAR_SOFT_DOTTED, TRUE }, { 0x0049, UCHAR_SOFT_DOTTED, FALSE }, { 0xfa11, UCHAR_UNIFIED_IDEOGRAPH, TRUE }, { 0xfa12, UCHAR_UNIFIED_IDEOGRAPH, FALSE }, /* enum/integer type properties */ /* UCHAR_BIDI_CLASS tested for assigned characters in TestUnicodeData() */ /* test default Bidi classes for unassigned code points */ { 0x0590, UCHAR_BIDI_CLASS, U_RIGHT_TO_LEFT }, { 0x05a2, UCHAR_BIDI_CLASS, U_RIGHT_TO_LEFT }, { 0x05ed, UCHAR_BIDI_CLASS, U_RIGHT_TO_LEFT }, { 0x07f2, UCHAR_BIDI_CLASS, U_RIGHT_TO_LEFT }, { 0x08ba, UCHAR_BIDI_CLASS, U_RIGHT_TO_LEFT }, { 0xfb37, UCHAR_BIDI_CLASS, U_RIGHT_TO_LEFT }, { 0xfb42, UCHAR_BIDI_CLASS, U_RIGHT_TO_LEFT }, { 0x10806, UCHAR_BIDI_CLASS, U_RIGHT_TO_LEFT }, { 0x10909, UCHAR_BIDI_CLASS, U_RIGHT_TO_LEFT }, { 0x10fe4, UCHAR_BIDI_CLASS, U_RIGHT_TO_LEFT }, { 0x0606, UCHAR_BIDI_CLASS, U_RIGHT_TO_LEFT_ARABIC }, { 0x061c, 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 }, { 0xfbc2, UCHAR_BIDI_CLASS, U_RIGHT_TO_LEFT_ARABIC }, { 0xfd90, UCHAR_BIDI_CLASS, U_RIGHT_TO_LEFT_ARABIC }, { 0xfefe, UCHAR_BIDI_CLASS, U_RIGHT_TO_LEFT_ARABIC }, { 0x02AF, UCHAR_BLOCK, UBLOCK_IPA_EXTENSIONS }, { 0x0C4E, UCHAR_BLOCK, UBLOCK_TELUGU }, { 0x155A, UCHAR_BLOCK, UBLOCK_UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS }, { 0x1717, UCHAR_BLOCK, UBLOCK_TAGALOG }, { 0x1AFF, UCHAR_BLOCK, UBLOCK_NO_BLOCK }, { 0x3040, UCHAR_BLOCK, UBLOCK_HIRAGANA }, { 0x1D0FF, UCHAR_BLOCK, UBLOCK_BYZANTINE_MUSICAL_SYMBOLS }, { 0x10D0FF, UCHAR_BLOCK, UBLOCK_SUPPLEMENTARY_PRIVATE_USE_AREA_B }, { 0xEFFFF, UCHAR_BLOCK, UBLOCK_NO_BLOCK }, /* UCHAR_CANONICAL_COMBINING_CLASS tested for assigned characters in TestUnicodeData() */ { 0xd7d7, UCHAR_CANONICAL_COMBINING_CLASS, 0 }, { 0x00A0, UCHAR_DECOMPOSITION_TYPE, U_DT_NOBREAK }, { 0x00A8, UCHAR_DECOMPOSITION_TYPE, U_DT_COMPAT }, { 0x00bf, UCHAR_DECOMPOSITION_TYPE, U_DT_NONE }, { 0x00c0, UCHAR_DECOMPOSITION_TYPE, U_DT_CANONICAL }, { 0x1E9B, UCHAR_DECOMPOSITION_TYPE, U_DT_CANONICAL }, { 0xBCDE, UCHAR_DECOMPOSITION_TYPE, U_DT_CANONICAL }, { 0xFB5D, UCHAR_DECOMPOSITION_TYPE, U_DT_MEDIAL }, { 0x1D736, UCHAR_DECOMPOSITION_TYPE, U_DT_FONT }, { 0xe0033, UCHAR_DECOMPOSITION_TYPE, U_DT_NONE }, { 0x0009, UCHAR_EAST_ASIAN_WIDTH, U_EA_NEUTRAL }, { 0x0020, UCHAR_EAST_ASIAN_WIDTH, U_EA_NARROW }, { 0x00B1, UCHAR_EAST_ASIAN_WIDTH, U_EA_AMBIGUOUS }, { 0x20A9, UCHAR_EAST_ASIAN_WIDTH, U_EA_HALFWIDTH }, { 0x2FFB, UCHAR_EAST_ASIAN_WIDTH, U_EA_WIDE }, { 0x3000, UCHAR_EAST_ASIAN_WIDTH, U_EA_FULLWIDTH }, { 0x35bb, UCHAR_EAST_ASIAN_WIDTH, U_EA_WIDE }, { 0x58bd, UCHAR_EAST_ASIAN_WIDTH, U_EA_WIDE }, { 0xD7A3, UCHAR_EAST_ASIAN_WIDTH, U_EA_WIDE }, { 0xEEEE, UCHAR_EAST_ASIAN_WIDTH, U_EA_AMBIGUOUS }, { 0x1D198, UCHAR_EAST_ASIAN_WIDTH, U_EA_NEUTRAL }, { 0x20000, UCHAR_EAST_ASIAN_WIDTH, U_EA_WIDE }, { 0x2F8C7, UCHAR_EAST_ASIAN_WIDTH, U_EA_WIDE }, { 0x3a5bd, UCHAR_EAST_ASIAN_WIDTH, U_EA_WIDE }, /* plane 3 got default W values in Unicode 4 */ { 0x5a5bd, UCHAR_EAST_ASIAN_WIDTH, U_EA_NEUTRAL }, { 0xFEEEE, UCHAR_EAST_ASIAN_WIDTH, U_EA_AMBIGUOUS }, { 0x10EEEE, UCHAR_EAST_ASIAN_WIDTH, U_EA_AMBIGUOUS }, /* UCHAR_GENERAL_CATEGORY tested for assigned characters in TestUnicodeData() */ { 0xd7d7, UCHAR_GENERAL_CATEGORY, 0 }, { 0x0444, UCHAR_JOINING_GROUP, U_JG_NO_JOINING_GROUP }, { 0x0639, UCHAR_JOINING_GROUP, U_JG_AIN }, { 0x072A, UCHAR_JOINING_GROUP, U_JG_DALATH_RISH }, { 0x0647, UCHAR_JOINING_GROUP, U_JG_HEH }, { 0x06C1, UCHAR_JOINING_GROUP, U_JG_HEH_GOAL }, { 0x06C3, UCHAR_JOINING_GROUP, U_JG_HAMZA_ON_HEH_GOAL }, { 0x200C, UCHAR_JOINING_TYPE, U_JT_NON_JOINING }, { 0x200D, UCHAR_JOINING_TYPE, U_JT_JOIN_CAUSING }, { 0x0639, UCHAR_JOINING_TYPE, U_JT_DUAL_JOINING }, { 0x0640, UCHAR_JOINING_TYPE, U_JT_JOIN_CAUSING }, { 0x06C3, UCHAR_JOINING_TYPE, U_JT_RIGHT_JOINING }, { 0x0300, UCHAR_JOINING_TYPE, U_JT_TRANSPARENT }, { 0x070F, UCHAR_JOINING_TYPE, U_JT_TRANSPARENT }, { 0xe0033, UCHAR_JOINING_TYPE, U_JT_TRANSPARENT }, /* TestUnicodeData() verifies that no assigned character has "XX" (unknown) */ { 0xe7e7, UCHAR_LINE_BREAK, U_LB_UNKNOWN }, { 0x10fffd, UCHAR_LINE_BREAK, U_LB_UNKNOWN }, { 0x0028, UCHAR_LINE_BREAK, U_LB_OPEN_PUNCTUATION }, { 0x232A, UCHAR_LINE_BREAK, U_LB_CLOSE_PUNCTUATION }, { 0x3401, UCHAR_LINE_BREAK, U_LB_IDEOGRAPHIC }, { 0x4e02, UCHAR_LINE_BREAK, U_LB_IDEOGRAPHIC }, { 0xac03, UCHAR_LINE_BREAK, U_LB_IDEOGRAPHIC }, { 0x20004, UCHAR_LINE_BREAK, U_LB_IDEOGRAPHIC }, { 0xf905, UCHAR_LINE_BREAK, U_LB_IDEOGRAPHIC }, { 0xdb7e, UCHAR_LINE_BREAK, U_LB_SURROGATE }, { 0xdbfd, UCHAR_LINE_BREAK, U_LB_SURROGATE }, { 0xdffc, UCHAR_LINE_BREAK, U_LB_SURROGATE }, { 0x2762, UCHAR_LINE_BREAK, U_LB_EXCLAMATION }, { 0x002F, UCHAR_LINE_BREAK, U_LB_BREAK_SYMBOLS }, { 0x1D49C, UCHAR_LINE_BREAK, U_LB_ALPHABETIC }, { 0x1731, UCHAR_LINE_BREAK, U_LB_ALPHABETIC }, /* UCHAR_NUMERIC_TYPE tested in TestNumericProperties() */ /* UCHAR_SCRIPT tested in TestUScriptCodeAPI() */ { 0x1100, UCHAR_HANGUL_SYLLABLE_TYPE, U_HST_LEADING_JAMO }, { 0x1111, UCHAR_HANGUL_SYLLABLE_TYPE, U_HST_LEADING_JAMO }, { 0x1159, UCHAR_HANGUL_SYLLABLE_TYPE, U_HST_LEADING_JAMO }, { 0x115f, UCHAR_HANGUL_SYLLABLE_TYPE, U_HST_LEADING_JAMO }, { 0x1160, UCHAR_HANGUL_SYLLABLE_TYPE, U_HST_VOWEL_JAMO }, { 0x1161, UCHAR_HANGUL_SYLLABLE_TYPE, U_HST_VOWEL_JAMO }, { 0x1172, UCHAR_HANGUL_SYLLABLE_TYPE, U_HST_VOWEL_JAMO }, { 0x11a2, UCHAR_HANGUL_SYLLABLE_TYPE, U_HST_VOWEL_JAMO }, { 0x11a8, UCHAR_HANGUL_SYLLABLE_TYPE, U_HST_TRAILING_JAMO }, { 0x11b8, UCHAR_HANGUL_SYLLABLE_TYPE, U_HST_TRAILING_JAMO }, { 0x11c8, UCHAR_HANGUL_SYLLABLE_TYPE, U_HST_TRAILING_JAMO }, { 0x11f9, UCHAR_HANGUL_SYLLABLE_TYPE, U_HST_TRAILING_JAMO }, { 0x115a, UCHAR_HANGUL_SYLLABLE_TYPE, 0 }, { 0x115e, UCHAR_HANGUL_SYLLABLE_TYPE, 0 }, { 0x11a3, UCHAR_HANGUL_SYLLABLE_TYPE, 0 }, { 0x11a7, UCHAR_HANGUL_SYLLABLE_TYPE, 0 }, { 0x11fa, UCHAR_HANGUL_SYLLABLE_TYPE, 0 }, { 0x11ff, UCHAR_HANGUL_SYLLABLE_TYPE, 0 }, { 0xac00, UCHAR_HANGUL_SYLLABLE_TYPE, U_HST_LV_SYLLABLE }, { 0xac1c, UCHAR_HANGUL_SYLLABLE_TYPE, U_HST_LV_SYLLABLE }, { 0xc5ec, UCHAR_HANGUL_SYLLABLE_TYPE, U_HST_LV_SYLLABLE }, { 0xd788, UCHAR_HANGUL_SYLLABLE_TYPE, U_HST_LV_SYLLABLE }, { 0xac01, UCHAR_HANGUL_SYLLABLE_TYPE, U_HST_LVT_SYLLABLE }, { 0xac1b, UCHAR_HANGUL_SYLLABLE_TYPE, U_HST_LVT_SYLLABLE }, { 0xac1d, UCHAR_HANGUL_SYLLABLE_TYPE, U_HST_LVT_SYLLABLE }, { 0xc5ee, UCHAR_HANGUL_SYLLABLE_TYPE, U_HST_LVT_SYLLABLE }, { 0xd7a3, UCHAR_HANGUL_SYLLABLE_TYPE, U_HST_LVT_SYLLABLE }, { 0xd7a4, UCHAR_HANGUL_SYLLABLE_TYPE, 0 }, /* undefined UProperty values */ { 0x61, 0x4a7, 0 }, { 0x234bc, 0x15ed, 0 } }; UVersionInfo version; UChar32 c; int32_t i, result, uVersion; UProperty which; /* what is our Unicode version? */ u_getUnicodeVersion(version); uVersion=(version[0]<<4)|version[1]; /* major/minor version numbers */ u_charAge(0x20, version); if(version[0]==0) { /* no additional properties available */ log_err("TestAdditionalProperties: no additional properties available, not tested\n"); return; } /* test u_charAge() */ for(i=0; i 10 && !atLeastSomething) { log_data_err("Never got anything after 10 tries.\nYour data is probably fried. Quitting this test\n", p, choice); return; } for (choice=0; ; ++choice) { const char* name = u_getPropertyName(p, choice); if (name) { if (!sawProp) log_verbose("prop 0x%04x+%2d:", p&~0xfff, p&0xfff); log_verbose("%d=\"%s\"", choice, name); sawProp = TRUE; atLeastSomething = TRUE; /* test reverse mapping */ rev = u_getPropertyEnum(name); if (rev != p) { log_err("Property round-trip failure: %d -> %s -> %d\n", p, name, rev); } } if (!name && choice>0) break; } if (sawProp) { /* looks like a valid property; check the values */ const char* pname = u_getPropertyName(p, U_LONG_PROPERTY_NAME); int32_t max = 0; if (p == UCHAR_CANONICAL_COMBINING_CLASS) { max = 255; } else if (p == UCHAR_GENERAL_CATEGORY_MASK) { /* it's far too slow to iterate all the way up to the real max, U_GC_P_MASK */ max = U_GC_NL_MASK; } else if (p == UCHAR_BLOCK) { /* UBlockCodes, unlike other values, start at 1 */ max = 1; } log_verbose("\n"); for (v=-1; ; ++v) { UBool sawValue = FALSE; for (choice=0; ; ++choice) { const char* vname = u_getPropertyValueName(p, v, choice); if (vname) { if (!sawValue) log_verbose(" %s, value %d:", pname, v); log_verbose("%d=\"%s\"", choice, vname); sawValue = TRUE; /* test reverse mapping */ rev = u_getPropertyValueEnum(p, vname); if (rev != v) { log_err("Value round-trip failure (%s): %d -> %s -> %d\n", pname, v, vname, rev); } } if (!vname && choice>0) break; } if (sawValue) { log_verbose("\n"); } if (!sawValue && v>=max) break; } } if (!sawProp) { if (p>=UCHAR_STRING_LIMIT) { break; } else if (p>=UCHAR_DOUBLE_LIMIT) { p = UCHAR_STRING_START - 1; } else if (p>=UCHAR_MASK_LIMIT) { p = UCHAR_DOUBLE_START - 1; } else if (p>=UCHAR_INT_LIMIT) { p = UCHAR_MASK_START - 1; } else if (p>=UCHAR_BINARY_LIMIT) { p = UCHAR_INT_START - 1; } } } } /** * Test the property values API. See JB#2410. */ static void TestPropertyValues(void) { int32_t i, p, min, max; UErrorCode ec; /* Min should be 0 for everything. */ /* Until JB#2478 is fixed, the one exception is UCHAR_BLOCK. */ for (p=UCHAR_INT_START; p1 && buffer16[0]==0x49) { uset_add(set2, start); } } compareUSets(set1, set2, "[canon start set of 0049]", "[all c with canon decomp with 0049]", TRUE); uset_close(set1); uset_close(set2); #endif }