]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/test/cintltst/creststn.c
ICU-64252.0.1.tar.gz
[apple/icu.git] / icuSources / test / cintltst / creststn.c
index 9e772af0272b94bb2403809b223b447b924053fa..4fe69d7a0de8c551b6533cf23968c30f954522ee 100644 (file)
@@ -1,6 +1,8 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
 /********************************************************************
  * COPYRIGHT: 
- * Copyright (c) 1997-2014, International Business Machines Corporation and
+ * Copyright (c) 1997-2016, International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
 /*******************************************************************************
 #include "unicode/putil.h"
 #include "unicode/ustring.h"
 #include "unicode/ucnv.h"
+#include "unicode/utf8.h"
+#include "unicode/utf16.h"
 #include "string.h"
+#include "cmemory.h"
 #include "cstring.h"
 #include "unicode/uchar.h"
 #include "ucol_imp.h"  /* for U_ICUDATA_COLL */
@@ -170,7 +175,7 @@ param[] =
   { "ne",           U_USING_DEFAULT_WARNING,  e_Root,    { TRUE, FALSE, FALSE }, { TRUE, FALSE, FALSE } }
 };
 
-static int32_t bundles_count = sizeof(param) / sizeof(param[0]);
+static int32_t bundles_count = UPRV_LENGTHOF(param);
 
 
 
@@ -271,7 +276,7 @@ static void TestErrorCodes(void) {
 
   if(U_SUCCESS(status) && r != NULL) {
     status = U_USING_DEFAULT_WARNING;
-    r2 = ures_getByKey(r, "LocaleScript", NULL, &status);  /* LocaleScript lives in ti */
+    r2 = ures_getByKey(r, "ExemplarCharacters", NULL, &status);  /* ExemplarCharacters lives in ti */
     checkStatus(__LINE__, U_USING_FALLBACK_WARNING, status);
   }
   ures_close(r);
@@ -353,7 +358,7 @@ static void TestAliasConflict(void) {
     }
     ures_close(he);
 
-    size = sizeof(norwayNames)/sizeof(norwayNames[0]);
+    size = UPRV_LENGTHOF(norwayNames);
     for(i = 0; i < size; i++) {
         status = U_ZERO_ERROR;
         norway = ures_open(NULL, norwayNames[i], &status);
@@ -424,14 +429,10 @@ static void TestDecodedBundle(){
     /* pre-flight */
     int32_t num =0;
     const char *testdatapath = loadTestData(&error);
-    resB = ures_open(testdatapath, "iscii", &error);
+    resB = ures_open(testdatapath, "encoded", &error);
     srcFromRes=tres_getString(resB,-1,"str",&len,&error);
     if(U_FAILURE(error)){
-#if UCONFIG_NO_LEGACY_CONVERSION
-        log_info("Couldn't load iscii.bin from test data bundle, (because UCONFIG_NO_LEGACY_CONVERSION  is turned on)\n");
-#else
-        log_data_err("Could not find iscii.bin from test data bundle. Error: %s\n", u_errorName(error));
-#endif
+        log_data_err("Could not find encoded.res from test data bundle. Error: %s\n", u_errorName(error));
         ures_close(resB);
         return;
     }
@@ -1015,8 +1016,8 @@ static void TestAPI() {
     }
 #endif
 
-    u_memset(largeBuffer, 0x0030, sizeof(largeBuffer)/sizeof(largeBuffer[0]));
-    largeBuffer[sizeof(largeBuffer)/sizeof(largeBuffer[0])-1] = 0;
+    u_memset(largeBuffer, 0x0030, UPRV_LENGTHOF(largeBuffer));
+    largeBuffer[UPRV_LENGTHOF(largeBuffer)-1] = 0;
 
     /*Test ures_openU */
 
@@ -1177,7 +1178,7 @@ static void TestErrorConditions(){
         log_err("ERROR: ures_openU() is supposed to fail path =%s with status != U_ZERO_ERROR\n", austrdup(utestdatapath));
         ures_close(teRes);
     }
-    /*Test ures_openFillIn with UResourceBundle = NULL*/
+    /*Test ures_openFillIn fails when input UResourceBundle parameter is NULL*/
     log_verbose("Testing ures_openFillIn with UResourceBundle = NULL.....\n");
     status=U_ZERO_ERROR;
     ures_openFillIn(NULL, testdatapath, "te", &status);
@@ -1185,6 +1186,14 @@ static void TestErrorConditions(){
         log_err("ERROR: ures_openFillIn with UResourceBundle= NULL should fail.  Expected U_ILLEGAL_ARGUMENT_ERROR, Got: %s\n",
                         myErrorName(status));
     }
+    /*Test ures_openDirectFillIn fails when input UResourceBundle parameter is NULL*/
+    log_verbose("Testing ures_openDirectFillIn with UResourceBundle = NULL.....\n");
+    status=U_ZERO_ERROR;
+    ures_openDirectFillIn(NULL, testdatapath, "te", &status);
+    if(status != U_ILLEGAL_ARGUMENT_ERROR){
+        log_err("ERROR: ures_openDirectFillIn with UResourceBundle= NULL should fail.  Expected U_ILLEGAL_ARGUMENT_ERROR, Got: %s\n",
+                        myErrorName(status));
+    }
     /*Test ures_getLocale() with status != U_ZERO_ERROR*/
     status=U_ZERO_ERROR;
     teRes=ures_openU(utestdatapath, "te", &status);
@@ -1419,7 +1428,18 @@ static void TestGetVersionColl(){
     int32_t locLen;
     const UChar* rules =NULL;
     int32_t len = 0;
-    
+
+    /* test NUL termination of UCARules */
+    resB = ures_open(U_ICUDATA_COLL,locName, &status);
+    rules = tres_getString(resB,-1,"UCARules",&len, &status);
+    if(!rules || U_FAILURE(status)) {
+        log_data_err("Could not load UCARules for locale %s\n", locName);
+        status = U_ZERO_ERROR;
+    } else if(u_strlen(rules) != len){
+        log_err("UCARules string not nul terminated! \n");
+    }
+    ures_close(resB);
+
     log_verbose("The ures_getVersion(%s) tests begin : \n", U_ICUDATA_COLL);
     locs = ures_openAvailableLocales(U_ICUDATA_COLL, &status);
     if (U_FAILURE(status)) {
@@ -1427,22 +1447,13 @@ static void TestGetVersionColl(){
        return;
     }
 
-    do{
+    for (;;) {
         log_verbose("Testing version number for locale %s\n", locName);
         resB = ures_open(U_ICUDATA_COLL,locName, &status);
         if (U_FAILURE(status)) {
             log_err("Resource bundle creation for locale %s:%s failed.: %s\n", U_ICUDATA_COLL, locName, myErrorName(status));
             ures_close(resB);
-            return;
-        }
-        /* test NUL termination of UCARules */
-        rules = tres_getString(resB,-1,"UCARules",&len, &status);
-        if(!rules || U_FAILURE(status)) {
-          log_data_err("Could not load UCARules for locale %s\n", locName);
-          continue;
-        }
-        if(u_strlen(rules) != len){
-            log_err("UCARules string not nul terminated! \n");
+            break;
         }
         ures_getVersion(resB, versionArray);
         for (i=0; i<4; ++i) {
@@ -1455,10 +1466,14 @@ static void TestGetVersionColl(){
             }
         }
         ures_close(resB);
-    } while((locName = uenum_next(locs,&locLen,&status))&&U_SUCCESS(status));
-    
-    if(U_FAILURE(status)) {
-        log_err("Err %s testing Collation locales.\n", u_errorName(status));
+        locName = uenum_next(locs, &locLen, &status);
+        if(U_FAILURE(status)) {
+            log_err("uenum_next(locs) error %s\n", u_errorName(status));
+            break;
+        }
+        if(locName == NULL) {
+            break;
+        }
     }
     uenum_close(locs);
 #endif  /* !UCONFIG_NO_COLLATION */
@@ -2122,7 +2137,7 @@ static void TestFallback()
         UResourceBundle* tResB;
         UResourceBundle* zoneResource;
         const UChar* version = NULL;
-        static const UChar versionStr[] = { 0x0032, 0x002E, 0x0030, 0x002E, 0x0039, 0x0030, 0x002E, 0x0036, 0x0031, 0x0000};
+        static const UChar versionStr[] = { 0x0032, 0x002E, 0x0031, 0x002E, 0x0034, 0x0037, 0x002E, 0x0038, 0x0032, 0x0000}; // 2.1.47.82 in nn_NO
 
         if(err != U_ZERO_ERROR){
             log_data_err("Expected U_ZERO_ERROR when trying to test no_NO_NY aliased to nn_NO for Version err=%s\n",u_errorName(err));
@@ -2207,9 +2222,9 @@ static void TestResourceLevelAliasing(void) {
         status = U_ZERO_ERROR;
       }
       /* testing referencing/composed alias */
-      uk = ures_findResource("ja/LocaleScript/2", uk, &status);
+      uk = ures_findResource("ja/calendar/gregorian/DateTimePatterns/2", uk, &status);
       if((uk == NULL) || U_FAILURE(status)) {
-        log_err_status(status, "Couldn't findResource('ja/LocaleScript/2') err %s\n", u_errorName(status));
+        log_err_status(status, "Couldn't findResource('ja/calendar/gregorian/DateTimePatterns/2') err %s\n", u_errorName(status));
         goto cleanup;
       } 
       
@@ -2228,7 +2243,7 @@ static void TestResourceLevelAliasing(void) {
       }
       
       checkStatus(__LINE__, U_ZERO_ERROR, status);
-      tb = ures_getByKey(aliasB, "LocaleScript", tb, &status);
+      tb = ures_getByKey(aliasB, "DateTimePatterns", tb, &status);
       checkStatus(__LINE__, U_ZERO_ERROR, status);
       tb = ures_getByIndex(tb, 2, tb, &status);
       checkStatus(__LINE__, U_ZERO_ERROR, status);
@@ -2292,7 +2307,7 @@ static void TestResourceLevelAliasing(void) {
         if(U_FAILURE(status)) {
           log_err("FAIL: Couldn't get testGetStringByKeyAliasing resource: %s\n", u_errorName(status));
         } else {
-            for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) {
+            for(i = 0; i < UPRV_LENGTHOF(strings); i++) {
                 result = tres_getString(tb, -1, keys[i], &resultLen, &status);
                 if(U_FAILURE(status)){
                     log_err("(1) Fetching the resource with key %s failed. Error: %s\n", keys[i], u_errorName(status));
@@ -2303,7 +2318,7 @@ static void TestResourceLevelAliasing(void) {
                   log_err("(1) Didn't get correct string while accessing alias table by key (%s)\n", keys[i]);
                 }
             }
-            for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) {
+            for(i = 0; i < UPRV_LENGTHOF(strings); i++) {
                 result = tres_getString(tb, i, NULL, &resultLen, &status); 
                 if(U_FAILURE(status)){
                     log_err("(2) Fetching the resource with key %s failed. Error: %s\n", keys[i], u_errorName(status));
@@ -2314,7 +2329,7 @@ static void TestResourceLevelAliasing(void) {
                   log_err("(2) Didn't get correct string while accesing alias table by index (%s)\n", strings[i]);
                 }
             }
-            for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) {
+            for(i = 0; i < UPRV_LENGTHOF(strings); i++) {
                 result = ures_getNextString(tb, &resultLen, &key, &status);
                 if(U_FAILURE(status)){
                     log_err("(3) Fetching the resource with key %s failed. Error: %s\n", keys[i], u_errorName(status));
@@ -2330,7 +2345,7 @@ static void TestResourceLevelAliasing(void) {
         if(U_FAILURE(status)) {
           log_err("FAIL: Couldn't get testGetStringByIndexAliasing resource: %s\n", u_errorName(status));
         } else {
-            for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) {
+            for(i = 0; i < UPRV_LENGTHOF(strings); i++) {
                 result = tres_getString(tb, i, NULL, &resultLen, &status);
                 if(U_FAILURE(status)){
                     log_err("Fetching the resource with key %s failed. Error: %s\n", keys[i], u_errorName(status));
@@ -2341,7 +2356,7 @@ static void TestResourceLevelAliasing(void) {
                   log_err("Didn't get correct string while accesing alias by index in an array (%s)\n", strings[i]);
                 }
             }
-            for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) {
+            for(i = 0; i < UPRV_LENGTHOF(strings); i++) {
                 result = ures_getNextString(tb, &resultLen, &key, &status);
                 if(U_FAILURE(status)){
                     log_err("Fetching the resource with key %s failed. Error: %s\n", keys[i], u_errorName(status));
@@ -2404,14 +2419,14 @@ static void TestDirectAccess(void) {
         }
     }
     
-    t = ures_findResource("ja/LocaleScript", t, &status);
+    t = ures_findResource("ja/ExemplarCharacters", t, &status);
     if(U_FAILURE(status)) {
         log_data_err("Couldn't access keyed resource, error %s\n", u_errorName(status));
         status = U_ZERO_ERROR;
     } else {
         key = ures_getKey(t);
-        if(strcmp(key, "LocaleScript")!=0) {
-            log_err("Got a strange key, expected 'LocaleScript', got %s\n", key);
+        if(strcmp(key, "ExemplarCharacters")!=0) {
+            log_err("Got a strange key, expected 'ExemplarCharacters', got %s\n", key);
         }
     }
     
@@ -2603,10 +2618,10 @@ static void TestGetFunctionalEquivalentOf(const char *path, const char *resName,
             log_verbose("got:  %c   %s\n", expectAvail?'t':'f',equivLocale);
 
             if((gotAvail != expectAvail) || strcmp(equivLocale, expectLocale)) {
-                log_err("FAIL: got avail=%c, loc=%s but  expected #%d: %c\t%s\t-> loc=%s\n",  
-                    gotAvail?'t':'f', equivLocale,
-                    i/3,
-                    expectAvail?'t':'f', inLocale, expectLocale);
+                log_err("FAIL: #%d: %s -> expect avail=%c, loc=%s but get %c, loc=%s\n",
+                    i/3, inLocale,
+                    expectAvail?'t':'f', expectLocale,
+                    gotAvail?'t':'f',    equivLocale);
 
             }
         }
@@ -2616,36 +2631,32 @@ static void TestGetFunctionalEquivalentOf(const char *path, const char *resName,
 static void TestGetFunctionalEquivalent(void) {
 #if !UCONFIG_NO_COLLATION
     static const char * const collCases[] = {
-        /*   avail   locale          equiv   */
+        /* avail  locale                          equiv */
+        /* note: in ICU 64, empty locales are shown as available for collation */
         "f",    "sv_US_CALIFORNIA",               "sv",
         "f",    "zh_TW@collation=stroke",         "zh@collation=stroke", /* alias of zh_Hant_TW */
-        "f",    "zh_Hant_TW@collation=stroke",    "zh@collation=stroke",
+        "t",    "zh_Hant_TW@collation=stroke",    "zh@collation=stroke",
         "f",    "sv_CN@collation=pinyin",         "sv",
         "t",    "zh@collation=pinyin",            "zh",
         "f",    "zh_CN@collation=pinyin",         "zh", /* alias of zh_Hans_CN */
-        "f",    "zh_Hans_CN@collation=pinyin",    "zh",
+        "t",    "zh_Hans_CN@collation=pinyin",    "zh",
         "f",    "zh_HK@collation=pinyin",         "zh", /* alias of zh_Hant_HK */
-        "f",    "zh_Hant_HK@collation=pinyin",    "zh",
+        "t",    "zh_Hant_HK@collation=pinyin",    "zh",
         "f",    "zh_HK@collation=stroke",         "zh@collation=stroke", /* alias of zh_Hant_HK */
-        "f",    "zh_Hant_HK@collation=stroke",    "zh@collation=stroke",
+        "t",    "zh_Hant_HK@collation=stroke",    "zh@collation=stroke",
         "f",    "zh_HK",                          "zh@collation=stroke", /* alias of zh_Hant_HK */
-        "f",    "zh_Hant_HK",                     "zh@collation=stroke",
+        "t",    "zh_Hant_HK",                     "zh@collation=stroke",
         "f",    "zh_MO",                          "zh@collation=stroke", /* alias of zh_Hant_MO */
-        "f",    "zh_Hant_MO",                     "zh@collation=stroke",
+        "t",    "zh_Hant_MO",                     "zh@collation=stroke",
         "f",    "zh_TW_STROKE",                   "zh@collation=stroke",
-        "f",    "zh_TW_STROKE@collation=big5han", "zh@collation=big5han",
+        "f",    "zh_TW_STROKE@collation=pinyin",  "zh",
         "f",    "sv_CN@calendar=japanese",        "sv",
         "t",    "sv@calendar=japanese",           "sv",
-        "f",    "zh_TW@collation=big5han",        "zh@collation=big5han", /* alias of zh_Hant_TW */
-        "f",    "zh_Hant_TW@collation=big5han",   "zh@collation=big5han",
-        "f",    "zh_TW@collation=gb2312han",      "zh@collation=gb2312han", /* alias of zh_Hant_TW */
-        "f",    "zh_Hant_TW@collation=gb2312han", "zh@collation=gb2312han",
-        "f",    "zh_CN@collation=big5han",        "zh@collation=big5han", /* alias of zh_Hans_CN */
-        "f",    "zh_Hans_CN@collation=big5han",   "zh@collation=big5han",
-        "f",    "zh_CN@collation=gb2312han",      "zh@collation=gb2312han", /* alias of zh_Hans_CN */
-        "f",    "zh_Hans_CN@collation=gb2312han", "zh@collation=gb2312han",
-        "t",    "zh@collation=big5han",           "zh@collation=big5han",
-        "t",    "zh@collation=gb2312han",         "zh@collation=gb2312han",
+        "f",    "zh_TW@collation=pinyin",         "zh", /* alias of zh_Hant_TW */
+        "t",    "zh_Hant_TW@collation=pinyin",    "zh",
+        "f",    "zh_CN@collation=stroke",         "zh@collation=stroke", /* alias of zh_Hans_CN */
+        "t",    "zh_Hans_CN@collation=stroke",    "zh@collation=stroke",
+        "t",    "de@collation=phonebook",         "de@collation=phonebook",
         "t",    "hi@collation=standard",          "hi",
         "f",    "hi_AU@collation=standard;currency=CHF;calendar=buddhist",    "hi",
         "f",    "sv_SE@collation=pinyin",         "sv", /* bug 4582 tests */
@@ -2656,12 +2667,36 @@ static void TestGetFunctionalEquivalent(void) {
         "t",    "nl@collation=stroke",            "root",
         "f",    "nl_NL@collation=stroke",         "root",
         "f",    "nl_NL_EEXT@collation=stroke",    "root",
+        /* Additions to test aliased locales */
+        "f",    "yue_HK",                         "zh@collation=stroke",
+        "f",    "yue_Hant",                       "zh@collation=stroke",
+        "f",    "yue_Hant_HK",                    "zh@collation=stroke",
+        "f",    "yue@collation=stroke",           "zh@collation=stroke",
+        "f",    "yue@collation=pinyin",           "zh",
+        "f",    "yue_CN",                         "zh",
+        "f",    "yue_Hans",                       "zh",
+        "f",    "yue_Hans_CN",                    "zh",
+        "f",    "yue_Hans@collation=pinyin",      "zh",
+        "f",    "yue_Hans@collation=stroke",      "zh@collation=stroke",
+        "f",    "mo",                             "mo", /* ? */
+        "f",    "no",                             "no", /* ? */
+        "f",    "ars",                            "ars", /* ? */
+        "t",    "wuu",                            "wuu", /* ? */
+        /* Additions to test locales without resources */
+        "f",    "en_CN",                          "root",
+        "f",    "zh_Hant_CN",                     "zh@collation=stroke",
+        "f",    "zh_Hant_US",                     "zh@collation=stroke",
+        "f",    "zh_Hans_US",                     "zh",
+        "f",    "yue_TW",                         "zh@collation=stroke",
+        "f",    "yue_US",                         "zh@collation=stroke",
+        "f",    "ja_CN",                          "ja",
+        "f",    "ja_US",                          "ja",
         NULL
     };
 #endif  /* !UCONFIG_NO_COLLATION */
 
     static const char *calCases[] = {
-        /*   avail   locale                       equiv   */
+        /* avail  locale                        equiv */
         "t",    "en_US_POSIX",                   "en@calendar=gregorian",
         "f",    "ja_JP_TOKYO",                   "ja@calendar=gregorian",
         "f",    "ja_JP_TOKYO@calendar=japanese", "ja@calendar=japanese",
@@ -2792,7 +2827,7 @@ static void TestCLDRStyleAliases(void) {
       /* instead of sprintf(resource, "a%i", i); */
       a = ures_getByKeyWithFallback(alias, resource, a, &status);
       result = tres_getString(a, -1, NULL, &len, &status);
-      u_charsToUChars(expects[i], expected, strlen(expects[i])+1);
+      u_charsToUChars(expects[i], expected, (int32_t)strlen(expects[i])+1);
       if(U_FAILURE(status) || !result || u_strcmp(result, expected)) {
         log_err("CLDR style aliases failed resource with name \"%s\" resource, exp %s, got %S (%s)\n", resource, expects[i], result, myErrorName(status)); 
         status = U_ZERO_ERROR;