+
+ {
+ /* test characters which have Script_Extensions */
+ UErrorCode errorCode=U_ZERO_ERROR;
+ if(!(
+ USCRIPT_COMMON==uscript_getScript(0x0640, &errorCode) &&
+ USCRIPT_INHERITED==uscript_getScript(0x0650, &errorCode) &&
+ USCRIPT_ARABIC==uscript_getScript(0xfdf2, &errorCode)) ||
+ U_FAILURE(errorCode)
+ ) {
+ log_err("uscript_getScript(character with Script_Extensions) failed\n");
+ }
+ }
+}
+
+void TestHasScript() {
+ if(!(
+ !uscript_hasScript(0x063f, USCRIPT_COMMON) &&
+ uscript_hasScript(0x063f, USCRIPT_ARABIC) && /* main Script value */
+ !uscript_hasScript(0x063f, USCRIPT_SYRIAC) &&
+ !uscript_hasScript(0x063f, USCRIPT_THAANA))
+ ) {
+ log_err("uscript_hasScript(U+063F, ...) is wrong\n");
+ }
+ if(!(
+ !uscript_hasScript(0x0640, USCRIPT_COMMON) && /* main Script value */
+ uscript_hasScript(0x0640, USCRIPT_ARABIC) &&
+ uscript_hasScript(0x0640, USCRIPT_SYRIAC) &&
+ !uscript_hasScript(0x0640, USCRIPT_THAANA))
+ ) {
+ log_err("uscript_hasScript(U+0640, ...) is wrong\n");
+ }
+ if(!(
+ !uscript_hasScript(0x0650, USCRIPT_INHERITED) && /* main Script value */
+ uscript_hasScript(0x0650, USCRIPT_ARABIC) &&
+ uscript_hasScript(0x0650, USCRIPT_SYRIAC) &&
+ !uscript_hasScript(0x0650, USCRIPT_THAANA))
+ ) {
+ log_err("uscript_hasScript(U+0650, ...) is wrong\n");
+ }
+ if(!(
+ !uscript_hasScript(0x0660, USCRIPT_COMMON) && /* main Script value */
+ uscript_hasScript(0x0660, USCRIPT_ARABIC) &&
+ !uscript_hasScript(0x0660, USCRIPT_SYRIAC) &&
+ uscript_hasScript(0x0660, USCRIPT_THAANA))
+ ) {
+ log_err("uscript_hasScript(U+0660, ...) is wrong\n");
+ }
+ if(!(
+ !uscript_hasScript(0xfdf2, USCRIPT_COMMON) &&
+ uscript_hasScript(0xfdf2, USCRIPT_ARABIC) && /* main Script value */
+ !uscript_hasScript(0xfdf2, USCRIPT_SYRIAC) &&
+ uscript_hasScript(0xfdf2, USCRIPT_THAANA))
+ ) {
+ log_err("uscript_hasScript(U+FDF2, ...) is wrong\n");
+ }
+ if(uscript_hasScript(0x0640, 0xaffe)) {
+ /* An unguarded implementation might go into an infinite loop. */
+ log_err("uscript_hasScript(U+0640, bogus 0xaffe) is wrong\n");
+ }
+}
+
+static UBool scriptsContain(UScriptCode scripts[], int32_t length, UScriptCode script) {
+ UBool contain=FALSE;
+ int32_t prev=-1, i;
+ for(i=0; i<length; ++i) {
+ int32_t s=scripts[i];
+ if(s<=prev) {
+ log_err("uscript_getScriptExtensions() not in sorted order: %d %d\n", (int)prev, (int)s);
+ }
+ if(s==script) { contain=TRUE; }
+ }
+ return contain;
+}
+
+void TestGetScriptExtensions() {
+ UScriptCode scripts[20];
+ int32_t length;
+ UErrorCode errorCode;
+
+ /* errors and overflows */
+ errorCode=U_PARSE_ERROR;
+ length=uscript_getScriptExtensions(0x0640, scripts, UPRV_LENGTHOF(scripts), &errorCode);
+ if(errorCode!=U_PARSE_ERROR) {
+ log_err("uscript_getScriptExtensions(U+0640, U_PARSE_ERROR) did not preserve the UErrorCode - %s\n",
+ u_errorName(errorCode));
+ }
+ errorCode=U_ZERO_ERROR;
+ length=uscript_getScriptExtensions(0x0640, NULL, UPRV_LENGTHOF(scripts), &errorCode);
+ if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR) {
+ log_err("uscript_getScriptExtensions(U+0640, NULL) did not set U_ILLEGAL_ARGUMENT_ERROR - %s\n",
+ u_errorName(errorCode));
+ }
+ errorCode=U_ZERO_ERROR;
+ length=uscript_getScriptExtensions(0x0640, scripts, -1, &errorCode);
+ if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR) {
+ log_err("uscript_getScriptExtensions(U+0640, capacity<0) did not set U_ILLEGAL_ARGUMENT_ERROR - %s\n",
+ u_errorName(errorCode));
+ }
+ errorCode=U_ZERO_ERROR;
+ length=uscript_getScriptExtensions(0x0640, scripts, 0, &errorCode);
+ if(errorCode!=U_BUFFER_OVERFLOW_ERROR || length<3) {
+ log_err("uscript_getScriptExtensions(U+0640, capacity=0: pure preflighting)=%d < 3 - %s\n",
+ (int)length, u_errorName(errorCode));
+ }
+ errorCode=U_ZERO_ERROR;
+ length=uscript_getScriptExtensions(0x0640, scripts, 1, &errorCode);
+ if(errorCode!=U_BUFFER_OVERFLOW_ERROR || length<3) {
+ log_err("uscript_getScriptExtensions(U+0640, capacity=1: preflighting)=%d < 3 - %s\n",
+ (int)length, u_errorName(errorCode));
+ }
+ /* U+063F has only a Script code, no Script_Extensions. */
+ errorCode=U_ZERO_ERROR;
+ length=uscript_getScriptExtensions(0x063f, scripts, 0, &errorCode);
+ if(errorCode!=U_BUFFER_OVERFLOW_ERROR || length!=1) {
+ log_err("uscript_getScriptExtensions(U+063F, capacity=0)=%d != 1 - %s\n",
+ (int)length, u_errorName(errorCode));
+ }
+
+ /* invalid code points */
+ errorCode=U_ZERO_ERROR;
+ length=uscript_getScriptExtensions(-1, scripts, UPRV_LENGTHOF(scripts), &errorCode);
+ if(U_FAILURE(errorCode) || length!=1 || scripts[0]!=USCRIPT_UNKNOWN) {
+ log_err("uscript_getScriptExtensions(-1)=%d does not return {UNKNOWN} - %s\n",
+ (int)length, u_errorName(errorCode));
+ }
+ errorCode=U_ZERO_ERROR;
+ length=uscript_getScriptExtensions(0x110000, scripts, UPRV_LENGTHOF(scripts), &errorCode);
+ if(U_FAILURE(errorCode) || length!=1 || scripts[0]!=USCRIPT_UNKNOWN) {
+ log_err("uscript_getScriptExtensions(0x110000)=%d does not return {UNKNOWN} - %s\n",
+ (int)length, u_errorName(errorCode));
+ }
+
+ /* normal usage */
+ errorCode=U_ZERO_ERROR;
+ length=uscript_getScriptExtensions(0x063f, scripts, 1, &errorCode);
+ if(U_FAILURE(errorCode) || length!=1 || scripts[0]!=USCRIPT_ARABIC) {
+ log_err("uscript_getScriptExtensions(U+063F, capacity=1)=%d does not return {ARABIC} - %s\n",
+ (int)length, u_errorName(errorCode));
+ }
+ errorCode=U_ZERO_ERROR;
+ length=uscript_getScriptExtensions(0x0640, scripts, UPRV_LENGTHOF(scripts), &errorCode);
+ if(U_FAILURE(errorCode) || length<3 ||
+ !scriptsContain(scripts, length, USCRIPT_ARABIC) ||
+ !scriptsContain(scripts, length, USCRIPT_SYRIAC) ||
+ !scriptsContain(scripts, length, USCRIPT_MANDAIC)) {
+ log_err("uscript_getScriptExtensions(U+0640)=%d failed - %s\n",
+ (int)length, u_errorName(errorCode));
+ }
+ errorCode=U_ZERO_ERROR;
+ length=uscript_getScriptExtensions(0xfdf2, scripts, UPRV_LENGTHOF(scripts), &errorCode);
+ if(U_FAILURE(errorCode) || length!=2 || scripts[0]!=USCRIPT_ARABIC || scripts[1]!=USCRIPT_THAANA) {
+ log_err("uscript_getScriptExtensions(U+FDF2)=%d failed - %s\n",
+ (int)length, u_errorName(errorCode));
+ }
+ errorCode=U_ZERO_ERROR;
+ length=uscript_getScriptExtensions(0xff65, scripts, UPRV_LENGTHOF(scripts), &errorCode);
+ if(U_FAILURE(errorCode) || length!=6 || scripts[0]!=USCRIPT_BOPOMOFO || scripts[5]!=USCRIPT_YI) {
+ log_err("uscript_getScriptExtensions(U+FF65)=%d failed - %s\n",
+ (int)length, u_errorName(errorCode));
+ }
+}
+
+void TestScriptMetadataAPI() {
+ /* API & code coverage. More testing in intltest/ucdtest.cpp. */
+ UErrorCode errorCode=U_ZERO_ERROR;
+ UChar sample[8];
+
+ if(uscript_getSampleString(USCRIPT_LATIN, sample, UPRV_LENGTHOF(sample), &errorCode)!=1 ||
+ U_FAILURE(errorCode) ||
+ uscript_getScript(sample[0], &errorCode)!=USCRIPT_LATIN ||
+ sample[1]!=0) {
+ log_err("uscript_getSampleString(Latn) failed - %s\n", u_errorName(errorCode));
+ }
+ sample[0]=0xfffe;
+ if(uscript_getSampleString(USCRIPT_LATIN, sample, 0, &errorCode)!=1 ||
+ errorCode!=U_BUFFER_OVERFLOW_ERROR ||
+ sample[0]!=0xfffe) {
+ log_err("uscript_getSampleString(Latn, capacity=0) failed - %s\n", u_errorName(errorCode));
+ }
+ errorCode=U_ZERO_ERROR;
+ if(uscript_getSampleString(USCRIPT_INVALID_CODE, sample, UPRV_LENGTHOF(sample), &errorCode)!=0 ||
+ U_FAILURE(errorCode) ||
+ sample[0]!=0) {
+ log_err("uscript_getSampleString(invalid) failed - %s\n", u_errorName(errorCode));
+ }
+ sample[0]=0xfffe;
+ if(uscript_getSampleString(USCRIPT_CODE_LIMIT, sample, 0, &errorCode)!=0 ||
+ errorCode!=U_STRING_NOT_TERMINATED_WARNING ||
+ sample[0]!=0xfffe) {
+ log_err("uscript_getSampleString(limit, capacity=0) failed - %s\n", u_errorName(errorCode));
+ }
+
+ if(uscript_getUsage(USCRIPT_LATIN)!=USCRIPT_USAGE_RECOMMENDED ||
+ // Unicode 10 gives up on "aspirational".
+ uscript_getUsage(USCRIPT_YI)!=USCRIPT_USAGE_LIMITED_USE ||
+ uscript_getUsage(USCRIPT_CHEROKEE)!=USCRIPT_USAGE_LIMITED_USE ||
+ uscript_getUsage(USCRIPT_COPTIC)!=USCRIPT_USAGE_EXCLUDED ||
+ uscript_getUsage(USCRIPT_CIRTH)!=USCRIPT_USAGE_NOT_ENCODED ||
+ uscript_getUsage(USCRIPT_INVALID_CODE)!=USCRIPT_USAGE_NOT_ENCODED ||
+ uscript_getUsage(USCRIPT_CODE_LIMIT)!=USCRIPT_USAGE_NOT_ENCODED) {
+ log_err("uscript_getUsage() failed\n");
+ }
+
+ if(uscript_isRightToLeft(USCRIPT_LATIN) ||
+ uscript_isRightToLeft(USCRIPT_CIRTH) ||
+ !uscript_isRightToLeft(USCRIPT_ARABIC) ||
+ !uscript_isRightToLeft(USCRIPT_HEBREW)) {
+ log_err("uscript_isRightToLeft() failed\n");
+ }
+
+ if(uscript_breaksBetweenLetters(USCRIPT_LATIN) ||
+ uscript_breaksBetweenLetters(USCRIPT_CIRTH) ||
+ !uscript_breaksBetweenLetters(USCRIPT_HAN) ||
+ !uscript_breaksBetweenLetters(USCRIPT_THAI)) {
+ log_err("uscript_breaksBetweenLetters() failed\n");
+ }
+
+ if(uscript_isCased(USCRIPT_CIRTH) ||
+ uscript_isCased(USCRIPT_HAN) ||
+ !uscript_isCased(USCRIPT_LATIN) ||
+ !uscript_isCased(USCRIPT_GREEK)) {
+ log_err("uscript_isCased() failed\n");
+ }