]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/cintltst/cldrtest.c
ICU-64252.0.1.tar.gz
[apple/icu.git] / icuSources / test / cintltst / cldrtest.c
index 338654d611a5efa7a20db514f1a56e67fac165da..bc8d07e8789f0b8b76182dcd3185f94f268fbffc 100644 (file)
@@ -14,6 +14,7 @@
 #include "unicode/udat.h"
 #include "unicode/uscript.h"
 #include "unicode/ulocdata.h"
+#include "unicode/utf16.h"
 #include "cmemory.h"
 #include "cstring.h"
 #include "locmap.h"
@@ -483,7 +484,7 @@ testLCID(UResourceBundle *currentBundle,
             log_verbose("WARNING: %-5s resolves to %s (0x%.4x)\n",
                 localeName, lcidStringC, expectedLCID);
         }
-        else {
+        else if (!(strcmp(localeName, "ku") == 0 && log_knownIssue("20181", "ICU-20181 Fix LCID mapping for ckb vs ku"))) {
             log_err("ERROR:   %-5s has 0x%.4x and the number resolves wrongfully to %s\n",
                 localeName, expectedLCID, lcidStringC);
         }
@@ -563,7 +564,9 @@ TestLocaleStructure(void) {
                 currLoc);
         }
         resolvedLoc = ures_getLocaleByType(currentLocale, ULOC_ACTUAL_LOCALE, &errorCode);
-        if (strcmp(resolvedLoc, currLoc) != 0 && strcmp(currLoc, "ars") != 0) { /* ars IS an aliased locale */
+        if (strcmp(resolvedLoc, currLoc) != 0 && strcmp(currLoc, "ars") != 0 && strcmp(currLoc, "wuu") != 0 // /* ars,wuu are aliased locales */
+                && strcmp(currLoc, "ur_Arab_IN") != 0 && strcmp(currLoc, "ur_Aran_IN") != 0 /* so are ur_Ara?_IN <rdar://problem/47494884> */
+                && strcmp(currLoc, "pa_Aran") != 0) { /* and pa_Aran <rdar://problem/51418203> */
             /* All locales have at least a Version resource.
                If it's absolutely empty, then the previous test will fail too.*/
             log_err("Locale resolves to different locale. Is %s an alias of %s?\n",
@@ -705,7 +708,7 @@ TestConsistentCountryInfo(void) {
         }
         fromVariantLen = uloc_getVariant(fromLocale, fromVariant, ULOC_FULLNAME_CAPACITY, &errorCode);
         if (fromVariantLen > 0) {
-            /* Most variants are ignorable like PREEURO, or collation variants. */
+            /* Most variants are ignorable like collation variants. */
             continue;
         }
         /* Start comparing only after the current index.
@@ -727,7 +730,7 @@ TestConsistentCountryInfo(void) {
             }
             toVariantLen = uloc_getVariant(toLocale, toVariant, ULOC_FULLNAME_CAPACITY, &errorCode);
             if (toVariantLen > 0) {
-                /* Most variants are ignorable like PREEURO, or collation variants. */
+                /* Most variants are ignorable like collation variants. */
                 /* They're a variant for a reason. */
                 continue;
             }
@@ -743,7 +746,7 @@ TestConsistentCountryInfo(void) {
 static int32_t
 findStringSetMismatch(const char *currLoc, const UChar *string, int32_t langSize,
                       USet * mergedExemplarSet,
-                      UBool ignoreNumbers, UChar* badCharPtr) {
+                      UBool ignoreNumbers, UChar32* badCharPtr) {
     UErrorCode errorCode = U_ZERO_ERROR;
     USet *exemplarSet;
     int32_t strIdx;
@@ -756,14 +759,16 @@ findStringSetMismatch(const char *currLoc, const UChar *string, int32_t langSize
         return -1;
     }
 
-    for (strIdx = 0; strIdx < langSize; strIdx++) {
-        if (!uset_contains(exemplarSet, string[strIdx])
-            && string[strIdx] != 0x0020 && string[strIdx] != 0x00A0 && string[strIdx] != 0x002e && string[strIdx] != 0x002c && string[strIdx] != 0x002d && string[strIdx] != 0x0027 && string[strIdx] != 0x005B && string[strIdx] != 0x005D && string[strIdx] != 0x2019 && string[strIdx] != 0x0f0b
-            && string[strIdx] != 0x200C && string[strIdx] != 0x200D) {
-            if (!ignoreNumbers || (ignoreNumbers && (string[strIdx] < 0x30 || string[strIdx] > 0x39))) {
+    for (strIdx = 0; strIdx < langSize;) {
+        UChar32 testChar;
+        U16_NEXT(string, strIdx, langSize, testChar);
+        if (!uset_contains(exemplarSet, testChar)
+            && testChar != 0x0020 && testChar != 0x00A0 && testChar != 0x002e && testChar != 0x002c && testChar != 0x002d && testChar != 0x0027
+            && testChar != 0x005B && testChar != 0x005D && testChar != 0x2019 && testChar != 0x0f0b && testChar != 0x200C && testChar != 0x200D) {
+            if (!ignoreNumbers || (ignoreNumbers && (testChar < 0x30 || testChar > 0x39))) {
                 uset_close(exemplarSet);
                 if (badCharPtr) {
-                    *badCharPtr = string[strIdx];
+                    *badCharPtr = testChar;
                 }
                 return strIdx;
             }
@@ -958,12 +963,13 @@ static void VerifyTranslation(void) {
             UChar langBuffer[128];
             int32_t langSize;
             int32_t strIdx;
-            UChar badChar;
+            UChar32 badChar;
             langSize = uloc_getDisplayLanguage(currLoc, currLoc, langBuffer, UPRV_LENGTHOF(langBuffer), &errorCode);
             if (U_FAILURE(errorCode)) {
                 log_err("error uloc_getDisplayLanguage returned %s\n", u_errorName(errorCode));
-            }
-            else {
+            } else if (uprv_strncmp(currLoc,"gez",3) == 0 || uprv_strcmp(currLoc,"sa") == 0 || uprv_strncmp(currLoc,"sa_",3) == 0) { // Apple xtra locales
+                log_verbose("skipping DisplayLanguage test for %s, name or exemplars may need adjustment\n", currLoc);
+            } else {
                 strIdx = findStringSetMismatch(currLoc, langBuffer, langSize, mergedExemplarSet, FALSE, &badChar);
                 if (strIdx >= 0) {
                     char bbuf[256];
@@ -975,7 +981,17 @@ static void VerifyTranslation(void) {
             if (U_FAILURE(errorCode)) {
                 log_err("error uloc_getDisplayCountry returned %s\n", u_errorName(errorCode));
             }
-            {
+            if (    uprv_strcmp(currLoc,"ba") == 0 || uprv_strncmp(currLoc,"ba_",3) == 0 ||
+                    uprv_strcmp(currLoc,"cv") == 0 || uprv_strncmp(currLoc,"cv_",3) == 0 ||
+                    uprv_strcmp(currLoc,"dv") == 0 || uprv_strncmp(currLoc,"dv_",3) == 0 ||
+                    uprv_strcmp(currLoc,"sa") == 0 || uprv_strncmp(currLoc,"sa_",3) == 0 ||
+                    uprv_strncmp(currLoc,"kaj",3) == 0 || uprv_strncmp(currLoc,"kpe",3) == 0 ||
+                    uprv_strncmp(currLoc,"nqo",3) == 0 || uprv_strncmp(currLoc,"sat",3) == 0 ||
+                    uprv_strncmp(currLoc,"syr",3) == 0 ||
+                    uprv_strcmp(currLoc,"ks_Deva") == 0 || uprv_strncmp(currLoc,"mni_Mtei",8) == 0 ||
+                    uprv_strcmp(currLoc,"sd_Deva") == 0 ) { // Apple xtra locales
+                log_verbose("skipping day/month tests for %s, missing some translated names\n", currLoc);
+            } else {
                 UResourceBundle* cal = ures_getByKey(currentLocale, "calendar", NULL, &errorCode);
                 UResourceBundle* greg = ures_getByKeyWithFallback(cal, "gregorian", NULL, &errorCode);
                 UResourceBundle* names = ures_getByKeyWithFallback(greg,  "dayNames", NULL, &errorCode);
@@ -1430,22 +1446,22 @@ static void TestAvailableIsoCodes(void){
     UChar* isoCode = (UChar*)malloc(sizeof(UChar) * (uprv_strlen(usdCode) + 1));
 
     /* testing available codes with no time ranges */
-    u_charsToUChars(eurCode, isoCode, uprv_strlen(usdCode) + 1);
+    u_charsToUChars(eurCode, isoCode, (int32_t)uprv_strlen(usdCode) + 1);
     if (ucurr_isAvailable(isoCode, U_DATE_MIN, U_DATE_MAX, &errorCode) == FALSE) {
        log_data_err("FAIL: ISO code (%s) is not found.\n", eurCode);
     }
 
-    u_charsToUChars(usdCode, isoCode, uprv_strlen(zzzCode) + 1);
+    u_charsToUChars(usdCode, isoCode, (int32_t)uprv_strlen(zzzCode) + 1);
     if (ucurr_isAvailable(isoCode, U_DATE_MIN, U_DATE_MAX, &errorCode) == FALSE) {
        log_data_err("FAIL: ISO code (%s) is not found.\n", usdCode);
     }
 
-    u_charsToUChars(zzzCode, isoCode, uprv_strlen(zzzCode) + 1);
+    u_charsToUChars(zzzCode, isoCode, (int32_t)uprv_strlen(zzzCode) + 1);
     if (ucurr_isAvailable(isoCode, U_DATE_MIN, U_DATE_MAX, &errorCode) == TRUE) {
        log_err("FAIL: ISO code (%s) is reported as available, but it doesn't exist.\n", zzzCode);
     }
 
-    u_charsToUChars(lastCode, isoCode, uprv_strlen(zzzCode) + 1);
+    u_charsToUChars(lastCode, isoCode, (int32_t)uprv_strlen(zzzCode) + 1);
     if (ucurr_isAvailable(isoCode, U_DATE_MIN, U_DATE_MAX, &errorCode) == FALSE) {
        log_data_err("FAIL: ISO code (%s) is not found.\n", lastCode);
     }
@@ -1514,6 +1530,56 @@ static void TestAvailableIsoCodes(void){
 #endif
 }
 
+// Apple-specific
+typedef struct {
+    const char* locale;
+    const UChar* quoteStart;
+    const UChar* quoteEnd;
+    const UChar* altQuoteStart;
+    const UChar* altQuoteEnd;
+} DelimItem;
+static const DelimItem delimItems[] = {
+    { "en",    u"“", u"”", u"‘", u"’"},
+    { "es",    u"«", u"»", u"“", u"”"},
+    { "es_MX", u"“", u"”", u"‘", u"’"},
+    { "ja",    u"「", u"」", u"『", u"』"},
+    { NULL,NULL,NULL,NULL,NULL }
+};
+enum {kMaxDelimLen = 8};
+
+static void TestDelimiters(void){
+    const DelimItem* itemPtr;
+    for (itemPtr = delimItems; itemPtr->locale != NULL; itemPtr++) {
+        UErrorCode status = U_ZERO_ERROR;
+        ULocaleData* uldat = ulocdata_open(itemPtr->locale, &status);
+        if (U_FAILURE(status)) {
+            log_data_err("FAIL: ulocdata_open fails for locale %s: %s\n", itemPtr->locale, u_errorName(status));
+        } else {
+            UChar quoteStart[kMaxDelimLen+1];
+            UChar quoteEnd[kMaxDelimLen+1];
+            UChar altQuoteStart[kMaxDelimLen+1];
+            UChar altQuoteEnd[kMaxDelimLen+1];
+
+            ulocdata_getDelimiter(uldat, ULOCDATA_QUOTATION_START, quoteStart, kMaxDelimLen, &status);
+            quoteStart[kMaxDelimLen] = 0;
+            ulocdata_getDelimiter(uldat, ULOCDATA_QUOTATION_END, quoteEnd, kMaxDelimLen, &status);
+            quoteEnd[kMaxDelimLen] = 0;
+            ulocdata_getDelimiter(uldat, ULOCDATA_ALT_QUOTATION_START, altQuoteStart, kMaxDelimLen, &status);
+            altQuoteStart[kMaxDelimLen] = 0;
+            ulocdata_getDelimiter(uldat, ULOCDATA_ALT_QUOTATION_END, altQuoteEnd, kMaxDelimLen, &status);
+            altQuoteEnd[kMaxDelimLen] = 0;
+            if (U_FAILURE(status)) {
+                log_err("FAIL: ulocdata_getDelimiter fails for locale %s: %s\n", itemPtr->locale, u_errorName(status));
+            } else if (u_strcmp(quoteStart, itemPtr->quoteStart) != 0 || u_strcmp(quoteEnd, itemPtr->quoteEnd) != 0 ||
+                       u_strcmp(altQuoteStart, itemPtr->altQuoteStart) != 0 || u_strcmp(altQuoteEnd, itemPtr->altQuoteEnd) != 0) {
+                log_err("FAIL: ulocdata_getDelimiter error for locale %s, one or more delimiters not as expected\n", itemPtr->locale);
+            }
+            ulocdata_close(uldat);
+        }
+    }
+}
+
+
 #define TESTCASE(name) addTest(root, &name, "tsutil/cldrtest/" #name)
 
 void addCLDRTest(TestNode** root);
@@ -1531,5 +1597,6 @@ void addCLDRTest(TestNode** root)
     TESTCASE(TestCoverage);
     TESTCASE(TestIndexChars);
     TESTCASE(TestAvailableIsoCodes);
+    TESTCASE(TestDelimiters);
 }