Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: source/test/cintltst/cloctst.c

Issue 845603002: Update ICU to 54.1 step 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@master
Patch Set: remove unusued directories Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « source/test/cintltst/cloctst.h ('k') | source/test/cintltst/cmsccoll.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /******************************************************************** 1 /********************************************************************
2 * COPYRIGHT: 2 * COPYRIGHT:
3 * Copyright (c) 1997-2013, International Business Machines Corporation and 3 * Copyright (c) 1997-2014, International Business Machines Corporation and
4 * others. All Rights Reserved. 4 * others. All Rights Reserved.
5 ********************************************************************/ 5 ********************************************************************/
6 /***************************************************************************** 6 /*****************************************************************************
7 * 7 *
8 * File CLOCTST.C 8 * File CLOCTST.C
9 * 9 *
10 * Modification History: 10 * Modification History:
11 * Name Description 11 * Name Description
12 * Madhu Katragadda Ported for C API 12 * Madhu Katragadda Ported for C API
13 ****************************************************************************** 13 ******************************************************************************
(...skipping 15 matching lines...) Expand all
29 #include "unicode/uloc.h" 29 #include "unicode/uloc.h"
30 #include "unicode/umsg.h" 30 #include "unicode/umsg.h"
31 #include "unicode/ures.h" 31 #include "unicode/ures.h"
32 #include "unicode/uset.h" 32 #include "unicode/uset.h"
33 #include "unicode/ustring.h" 33 #include "unicode/ustring.h"
34 #include "unicode/utypes.h" 34 #include "unicode/utypes.h"
35 #include "unicode/ulocdata.h" 35 #include "unicode/ulocdata.h"
36 #include "unicode/uldnames.h" 36 #include "unicode/uldnames.h"
37 #include "unicode/parseerr.h" /* may not be included with some uconfig switches */ 37 #include "unicode/parseerr.h" /* may not be included with some uconfig switches */
38 #include "udbgutil.h" 38 #include "udbgutil.h"
39 #define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
40 39
41 static void TestNullDefault(void); 40 static void TestNullDefault(void);
42 static void TestNonexistentLanguageExemplars(void); 41 static void TestNonexistentLanguageExemplars(void);
43 static void TestLocDataErrorCodeChaining(void); 42 static void TestLocDataErrorCodeChaining(void);
44 static void TestLanguageExemplarsFallbacks(void); 43 static void TestLanguageExemplarsFallbacks(void);
45 static void TestDisplayNameBrackets(void); 44 static void TestDisplayNameBrackets(void);
46 45
47 static void TestUnicodeDefines(void); 46 static void TestUnicodeDefines(void);
48 47
48 static void TestIsRightToLeft(void);
49
49 void PrintDataTable(); 50 void PrintDataTable();
50 51
51 /*--------------------------------------------------- 52 /*---------------------------------------------------
52 table of valid data 53 table of valid data
53 --------------------------------------------------- */ 54 --------------------------------------------------- */
54 #define LOCALE_SIZE 9 55 #define LOCALE_SIZE 9
55 #define LOCALE_INFO_SIZE 28 56 #define LOCALE_INFO_SIZE 28
56 57
57 static const char* const rawData2[LOCALE_INFO_SIZE][LOCALE_SIZE] = { 58 static const char* const rawData2[LOCALE_INFO_SIZE][LOCALE_SIZE] = {
58 /* language code */ 59 /* language code */
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 { "anglais", "fran\\u00E7ais", "catalan", "grec", "norv\\u00E9gien", "chinois", "allemand", "espagnol", "japonais" }, 92 { "anglais", "fran\\u00E7ais", "catalan", "grec", "norv\\u00E9gien", "chinois", "allemand", "espagnol", "japonais" },
92 /* display script code (French) */ 93 /* display script code (French) */
93 { "", "", "", "", "", "sinogrammes simplifi\\u00e9s", "", "", "" }, 94 { "", "", "", "", "", "sinogrammes simplifi\\u00e9s", "", "", "" },
94 /* display country (French) */ 95 /* display country (French) */
95 { "\\u00C9tats-Unis", "France", "Espagne", "Gr\\u00E8ce", "Norv\\u 00E8ge", "Chine", "Allemagne", "", "Japon" }, 96 { "\\u00C9tats-Unis", "France", "Espagne", "Gr\\u00E8ce", "Norv\\u 00E8ge", "Chine", "Allemagne", "", "Japon" },
96 /* display variant (French) */ 97 /* display variant (French) */
97 { "", "", "", "", "NY", "", "", "", "" }, 98 { "", "", "", "", "NY", "", "", "", "" },
98 /* display name (French) */ 99 /* display name (French) */
99 { "anglais (\\u00C9tats-Unis)", "fran\\u00E7ais (France)", "catalan (Espag ne)", 100 { "anglais (\\u00C9tats-Unis)", "fran\\u00E7ais (France)", "catalan (Espag ne)",
100 "grec (Gr\\u00E8ce)", "norv\\u00E9gien (Norv\\u00E8ge, NY)", "chinois ( simplifi\\u00e9, Chine)", 101 "grec (Gr\\u00E8ce)", "norv\\u00E9gien (Norv\\u00E8ge, NY)", "chinois ( simplifi\\u00e9, Chine)",
101 "allemand (Allemagne, ordre de tri=Ordre de l\\u2019annuaire)", "espagno l (ordre de tri=Ordre traditionnel)", "japonais (Japon, calendrier=Calendrier ja ponais)" }, 102 "allemand (Allemagne, ordre de tri=Ordre de l\\u2019annuaire)", "espagno l (ordre de tri=Ordre traditionnel)", "japonais (Japon, calendrier=calendrier ja ponais)" },
102 103
103 /* display language (Catalan) */ 104 /* display language (Catalan) */
104 { "angl\\u00E8s", "franc\\u00E8s", "catal\\u00E0", "grec", "noruec", "xin \\u00E8s", "alemany", "espanyol", "japon\\u00E8s" }, 105 { "angl\\u00E8s", "franc\\u00E8s", "catal\\u00E0", "grec", "noruec", "xin \\u00E8s", "alemany", "espanyol", "japon\\u00E8s" },
105 /* display script code (Catalan) */ 106 /* display script code (Catalan) */
106 { "", "", "", "", "", "han simplificat", "", "", "" }, 107 { "", "", "", "", "", "han simplificat", "", "", "" },
107 /* display country (Catalan) */ 108 /* display country (Catalan) */
108 { "Estats Units", "Fran\\u00E7a", "Espanya", "Gr\\u00E8cia", "Noruega", "Xina", "Alemanya", "", "Jap\\u00F3" }, 109 { "Estats Units", "Fran\\u00E7a", "Espanya", "Gr\\u00E8cia", "Noruega", "Xina", "Alemanya", "", "Jap\\u00F3" },
109 /* display variant (Catalan) */ 110 /* display variant (Catalan) */
110 { "", "", "", "", "NY", "", "", "", "" }, 111 { "", "", "", "", "NY", "", "", "", "" },
111 /* display name (Catalan) */ 112 /* display name (Catalan) */
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 TESTCASE(TestAcceptLanguage); 242 TESTCASE(TestAcceptLanguage);
242 TESTCASE(TestGetLocaleForLCID); 243 TESTCASE(TestGetLocaleForLCID);
243 TESTCASE(TestOrientation); 244 TESTCASE(TestOrientation);
244 TESTCASE(TestLikelySubtags); 245 TESTCASE(TestLikelySubtags);
245 TESTCASE(TestToLanguageTag); 246 TESTCASE(TestToLanguageTag);
246 TESTCASE(TestForLanguageTag); 247 TESTCASE(TestForLanguageTag);
247 TESTCASE(TestTrailingNull); 248 TESTCASE(TestTrailingNull);
248 TESTCASE(TestUnicodeDefines); 249 TESTCASE(TestUnicodeDefines);
249 TESTCASE(TestEnglishExemplarCharacters); 250 TESTCASE(TestEnglishExemplarCharacters);
250 TESTCASE(TestDisplayNameBrackets); 251 TESTCASE(TestDisplayNameBrackets);
252 TESTCASE(TestIsRightToLeft);
253 TESTCASE(TestToUnicodeLocaleKey);
254 TESTCASE(TestToLegacyKey);
255 TESTCASE(TestToUnicodeLocaleType);
256 TESTCASE(TestToLegacyType);
251 } 257 }
252 258
253 259
254 /* testing uloc(), uloc_getName(), uloc_getLanguage(), uloc_getVariant(), uloc_g etCountry() */ 260 /* testing uloc(), uloc_getName(), uloc_getLanguage(), uloc_getVariant(), uloc_g etCountry() */
255 static void TestBasicGetters() { 261 static void TestBasicGetters() {
256 int32_t i; 262 int32_t i;
257 int32_t cap; 263 int32_t cap;
258 UErrorCode status = U_ZERO_ERROR; 264 UErrorCode status = U_ZERO_ERROR;
259 char *testLocale = 0; 265 char *testLocale = 0;
260 char *temp = 0, *name = 0; 266 char *temp = 0, *name = 0;
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 doTestDisplayNames("en_US", DLANG_EN); 664 doTestDisplayNames("en_US", DLANG_EN);
659 log_verbose(" In locale = fr_FR....\n"); 665 log_verbose(" In locale = fr_FR....\n");
660 doTestDisplayNames("fr_FR", DLANG_FR); 666 doTestDisplayNames("fr_FR", DLANG_FR);
661 log_verbose(" In locale = ca_ES...\n"); 667 log_verbose(" In locale = ca_ES...\n");
662 doTestDisplayNames("ca_ES", DLANG_CA); 668 doTestDisplayNames("ca_ES", DLANG_CA);
663 log_verbose(" In locale = gr_EL..\n"); 669 log_verbose(" In locale = gr_EL..\n");
664 doTestDisplayNames("el_GR", DLANG_EL); 670 doTestDisplayNames("el_GR", DLANG_EL);
665 671
666 /* test that the default locale has a display name for its own language */ 672 /* test that the default locale has a display name for its own language */
667 errorCode=U_ZERO_ERROR; 673 errorCode=U_ZERO_ERROR;
668 length=uloc_getDisplayLanguage(NULL, NULL, buffer, LENGTHOF(buffer), &errorC ode); 674 length=uloc_getDisplayLanguage(NULL, NULL, buffer, UPRV_LENGTHOF(buffer), &e rrorCode);
669 if(U_FAILURE(errorCode) || (length<=3 && buffer[0]<=0x7f)) { 675 if(U_FAILURE(errorCode) || (length<=3 && buffer[0]<=0x7f)) {
670 /* check <=3 to reject getting the language code as a display name */ 676 /* check <=3 to reject getting the language code as a display name */
671 log_data_err("unable to get a display string for the language of the def ault locale - %s (Are you missing data?)\n", u_errorName(errorCode)); 677 log_data_err("unable to get a display string for the language of the def ault locale - %s (Are you missing data?)\n", u_errorName(errorCode));
672 } 678 }
673 679
674 /* test that we get the language code itself for an unknown language, and a default warning */ 680 /* test that we get the language code itself for an unknown language, and a default warning */
675 errorCode=U_ZERO_ERROR; 681 errorCode=U_ZERO_ERROR;
676 length=uloc_getDisplayLanguage("qq", "rr", buffer, LENGTHOF(buffer), &errorC ode); 682 length=uloc_getDisplayLanguage("qq", "rr", buffer, UPRV_LENGTHOF(buffer), &e rrorCode);
677 if(errorCode!=U_USING_DEFAULT_WARNING || length!=2 || buffer[0]!=0x71 || buf fer[1]!=0x71) { 683 if(errorCode!=U_USING_DEFAULT_WARNING || length!=2 || buffer[0]!=0x71 || buf fer[1]!=0x71) {
678 log_err("error getting the display string for an unknown language - %s\n ", u_errorName(errorCode)); 684 log_err("error getting the display string for an unknown language - %s\n ", u_errorName(errorCode));
679 } 685 }
680 686
681 /* test that we get a default warning for a display name where one component is unknown (4255) */ 687 /* test that we get a default warning for a display name where one component is unknown (4255) */
682 errorCode=U_ZERO_ERROR; 688 errorCode=U_ZERO_ERROR;
683 length=uloc_getDisplayName("qq_US_POSIX", "en_US", buffer, LENGTHOF(buffer), &errorCode); 689 length=uloc_getDisplayName("qq_US_POSIX", "en_US", buffer, UPRV_LENGTHOF(buf fer), &errorCode);
684 if(errorCode!=U_USING_DEFAULT_WARNING) { 690 if(errorCode!=U_USING_DEFAULT_WARNING) {
685 log_err("error getting the display name for a locale with an unknown lan guage - %s\n", u_errorName(errorCode)); 691 log_err("error getting the display name for a locale with an unknown lan guage - %s\n", u_errorName(errorCode));
686 } 692 }
687 693
688 { 694 {
689 int32_t i; 695 int32_t i;
690 static const char *aLocale = "es@collation=traditional;calendar=japanese "; 696 static const char *aLocale = "es@collation=traditional;calendar=japanese ";
691 static const char *testL[] = { "en_US", 697 static const char *testL[] = { "en_US",
692 "fr_FR", 698 "fr_FR",
693 "ca_ES", 699 "ca_ES",
694 "el_GR" }; 700 "el_GR" };
695 static const char *expect[] = { "Spanish (Calendar=Japanese Calendar, So rt Order=Traditional Sort Order)", /* note sorted order of keywords */ 701 static const char *expect[] = { "Spanish (Calendar=Japanese Calendar, So rt Order=Traditional Sort Order)", /* note sorted order of keywords */
696 "espagnol (calendrier=Calendrier japonais, ordre de tri=Ordre tradit ionnel)", 702 "espagnol (calendrier=calendrier japonais, ordre de tri=Ordre tradit ionnel)",
697 "espanyol (calendari=calendari japon\\u00e8s, ordenaci\\u00f3=ordre tradicional)", 703 "espanyol (calendari=calendari japon\\u00e8s, ordenaci\\u00f3=ordre tradicional)",
698 "\\u0399\\u03c3\\u03c0\\u03b1\\u03bd\\u03b9\\u03ba\\u03ac (\\u0397\\ u03bc\\u03b5\\u03c1\\u03bf\\u03bb\\u03cc\\u03b3\\u03b9\\u03bf=\\u0399\\u03b1\\u0 3c0\\u03c9\\u03bd\\u03b9\\u03ba\\u03cc \\u03b7\\u03bc\\u03b5\\u03c1\\u03bf\\u03b b\\u03cc\\u03b3\\u03b9\\u03bf, \\u03a3\\u03b5\\u03b9\\u03c1\\u03ac \\u03c4\\u03b 1\\u03be\\u03b9\\u03bd\\u03cc\\u03bc\\u03b7\\u03c3\\u03b7\\u03c2=\\u03a0\\u03b1\ \u03c1\\u03b1\\u03b4\\u03bf\\u03c3\\u03b9\\u03b1\\u03ba\\u03ae \\u03c3\\u03b5\\u 03b9\\u03c1\\u03ac \\u03c4\\u03b1\\u03be\\u03b9\\u03bd\\u03cc\\u03bc\\u03b7\\u03 c3\\u03b7\\u03c2)" }; 704 "\\u0399\\u03c3\\u03c0\\u03b1\\u03bd\\u03b9\\u03ba\\u03ac (\\u0397\\ u03bc\\u03b5\\u03c1\\u03bf\\u03bb\\u03cc\\u03b3\\u03b9\\u03bf=\\u0399\\u03b1\\u0 3c0\\u03c9\\u03bd\\u03b9\\u03ba\\u03cc \\u03b7\\u03bc\\u03b5\\u03c1\\u03bf\\u03b b\\u03cc\\u03b3\\u03b9\\u03bf, \\u03a3\\u03b5\\u03b9\\u03c1\\u03ac \\u03c4\\u03b 1\\u03be\\u03b9\\u03bd\\u03cc\\u03bc\\u03b7\\u03c3\\u03b7\\u03c2=\\u03a0\\u03b1\ \u03c1\\u03b1\\u03b4\\u03bf\\u03c3\\u03b9\\u03b1\\u03ba\\u03ae \\u03c3\\u03b5\\u 03b9\\u03c1\\u03ac \\u03c4\\u03b1\\u03be\\u03b9\\u03bd\\u03cc\\u03bc\\u03b7\\u03 c3\\u03b7\\u03c2)" };
699 UChar *expectBuffer; 705 UChar *expectBuffer;
700 706
701 for(i=0;i<LENGTHOF(testL);i++) { 707 for(i=0;i<UPRV_LENGTHOF(testL);i++) {
702 errorCode = U_ZERO_ERROR; 708 errorCode = U_ZERO_ERROR;
703 uloc_getDisplayName(aLocale, testL[i], buffer, LENGTHOF(buffer), &er rorCode); 709 uloc_getDisplayName(aLocale, testL[i], buffer, UPRV_LENGTHOF(buffer) , &errorCode);
704 if(U_FAILURE(errorCode)) { 710 if(U_FAILURE(errorCode)) {
705 log_err("FAIL in uloc_getDisplayName(%s,%s,..) -> %s\n", aLocale , testL[i], u_errorName(errorCode)); 711 log_err("FAIL in uloc_getDisplayName(%s,%s,..) -> %s\n", aLocale , testL[i], u_errorName(errorCode));
706 } else { 712 } else {
707 expectBuffer = CharsToUChars(expect[i]); 713 expectBuffer = CharsToUChars(expect[i]);
708 if(u_strcmp(buffer,expectBuffer)) { 714 if(u_strcmp(buffer,expectBuffer)) {
709 log_data_err("FAIL in uloc_getDisplayName(%s,%s,..) expected '%s' got '%s' (Are you missing data?)\n", aLocale, testL[i], expect[i], austrdu p(buffer)); 715 log_data_err("FAIL in uloc_getDisplayName(%s,%s,..) expected '%s' got '%s' (Are you missing data?)\n", aLocale, testL[i], expect[i], austrdu p(buffer));
710 } else { 716 } else {
711 log_verbose("pass in uloc_getDisplayName(%s,%s,..) got '%s'\ n", aLocale, testL[i], expect[i]); 717 log_verbose("pass in uloc_getDisplayName(%s,%s,..) got '%s'\ n", aLocale, testL[i], expect[i]);
712 } 718 }
713 free(expectBuffer); 719 free(expectBuffer);
(...skipping 11 matching lines...) Expand all
725 "\\u30a2\\u30bc\\u30eb\\u30d0\\u30a4\\u30b8\\u30e3\\u30f3\\u8a9e " 731 "\\u30a2\\u30bc\\u30eb\\u30d0\\u30a4\\u30b8\\u30e3\\u30f3\\u8a9e "
726 "(\\u30ad\\u30ea\\u30eb\\u6587\\u5b57)"; 732 "(\\u30ad\\u30ea\\u30eb\\u6587\\u5b57)";
727 UErrorCode ec=U_ZERO_ERROR; 733 UErrorCode ec=U_ZERO_ERROR;
728 UChar result[256]; 734 UChar result[256];
729 int32_t len; 735 int32_t len;
730 int32_t preflightLen=uloc_getDisplayName(locale, displayLocale, NULL, 0, &ec); 736 int32_t preflightLen=uloc_getDisplayName(locale, displayLocale, NULL, 0, &ec);
731 /* inconvenient semantics when preflighting, this condition is expected. .. */ 737 /* inconvenient semantics when preflighting, this condition is expected. .. */
732 if(ec==U_BUFFER_OVERFLOW_ERROR) { 738 if(ec==U_BUFFER_OVERFLOW_ERROR) {
733 ec=U_ZERO_ERROR; 739 ec=U_ZERO_ERROR;
734 } 740 }
735 len=uloc_getDisplayName(locale, displayLocale, result, LENGTHOF(result), &ec); 741 len=uloc_getDisplayName(locale, displayLocale, result, UPRV_LENGTHOF(res ult), &ec);
736 if(U_FAILURE(ec)) { 742 if(U_FAILURE(ec)) {
737 log_err("uloc_getDisplayName(%s, %s...) returned error: %s", 743 log_err("uloc_getDisplayName(%s, %s...) returned error: %s",
738 locale, displayLocale, u_errorName(ec)); 744 locale, displayLocale, u_errorName(ec));
739 } else { 745 } else {
740 UChar *expected=CharsToUChars(expectedChars); 746 UChar *expected=CharsToUChars(expectedChars);
741 int32_t expectedLen=u_strlen(expected); 747 int32_t expectedLen=u_strlen(expected);
742 748
743 if(len!=expectedLen) { 749 if(len!=expectedLen) {
744 log_data_err("uloc_getDisplayName(%s, %s...) returned string of length %d, expected length %d", 750 log_data_err("uloc_getDisplayName(%s, %s...) returned string of length %d, expected length %d",
745 locale, displayLocale, len, expectedLen); 751 locale, displayLocale, len, expectedLen);
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 ulen = uldn_localeDisplayName(uldn, itemPtr->namedLocale, getName, k DisplayNameBracketsMax, &status); 1093 ulen = uldn_localeDisplayName(uldn, itemPtr->namedLocale, getName, k DisplayNameBracketsMax, &status);
1088 if ( U_FAILURE(status) || u_strcmp(getName, expectLocaleName) != 0 ) { 1094 if ( U_FAILURE(status) || u_strcmp(getName, expectLocaleName) != 0 ) {
1089 log_data_err("uldn_localeDisplayName for displayLocale %s and na medLocale %s returns unexpected name or status %s\n", itemPtr->displayLocale, it emPtr->namedLocale, myErrorName(status)); 1095 log_data_err("uldn_localeDisplayName for displayLocale %s and na medLocale %s returns unexpected name or status %s\n", itemPtr->displayLocale, it emPtr->namedLocale, myErrorName(status));
1090 } 1096 }
1091 1097
1092 uldn_close(uldn); 1098 uldn_close(uldn);
1093 } else { 1099 } else {
1094 log_data_err("uldn_open fails for displayLocale %s, status=%s\n", it emPtr->displayLocale, u_errorName(status)); 1100 log_data_err("uldn_open fails for displayLocale %s, status=%s\n", it emPtr->displayLocale, u_errorName(status));
1095 } 1101 }
1096 #endif 1102 #endif
1103 (void)ulen; /* Suppress variable not used warning */
1097 } 1104 }
1098 } 1105 }
1099 1106
1100 /*------------------------------ 1107 /*------------------------------
1101 * TestISOFunctions 1108 * TestISOFunctions
1102 */ 1109 */
1103 1110
1104 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION 1111 #if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
1105 /* test for uloc_getISOLanguages, uloc_getISOCountries */ 1112 /* test for uloc_getISOLanguages, uloc_getISOCountries */
1106 static void TestISOFunctions() 1113 static void TestISOFunctions()
(...skipping 1664 matching lines...) Expand 10 before | Expand all | Expand 10 after
2771 2778
2772 static void TestCalendar() { 2779 static void TestCalendar() {
2773 #if !UCONFIG_NO_FORMATTING 2780 #if !UCONFIG_NO_FORMATTING
2774 int i; 2781 int i;
2775 UErrorCode status = U_ZERO_ERROR; 2782 UErrorCode status = U_ZERO_ERROR;
2776 UResourceBundle *resIndex = ures_open(NULL,"res_index", &status); 2783 UResourceBundle *resIndex = ures_open(NULL,"res_index", &status);
2777 if(U_FAILURE(status)){ 2784 if(U_FAILURE(status)){
2778 log_err_status(status, "Could not open res_index.res. Exiting. Error: %s \n", u_errorName(status)); 2785 log_err_status(status, "Could not open res_index.res. Exiting. Error: %s \n", u_errorName(status));
2779 return; 2786 return;
2780 } 2787 }
2781 for (i=0; i<LENGTHOF(LOCALE_ALIAS); i++) { 2788 for (i=0; i<UPRV_LENGTHOF(LOCALE_ALIAS); i++) {
2782 const char* oldLoc = LOCALE_ALIAS[i][0]; 2789 const char* oldLoc = LOCALE_ALIAS[i][0];
2783 const char* newLoc = LOCALE_ALIAS[i][1]; 2790 const char* newLoc = LOCALE_ALIAS[i][1];
2784 UCalendar* c1 = NULL; 2791 UCalendar* c1 = NULL;
2785 UCalendar* c2 = NULL; 2792 UCalendar* c2 = NULL;
2786 2793
2787 /*Test function "getLocale(ULocale.VALID_LOCALE)"*/ 2794 /*Test function "getLocale(ULocale.VALID_LOCALE)"*/
2788 const char* l1 = ucal_getLocaleByType(c1, ULOC_VALID_LOCALE, &status); 2795 const char* l1 = ucal_getLocaleByType(c1, ULOC_VALID_LOCALE, &status);
2789 const char* l2 = ucal_getLocaleByType(c2, ULOC_VALID_LOCALE, &status); 2796 const char* l2 = ucal_getLocaleByType(c2, ULOC_VALID_LOCALE, &status);
2790 2797
2791 if(!isLocaleAvailable(resIndex, newLoc)){ 2798 if(!isLocaleAvailable(resIndex, newLoc)){
(...skipping 15 matching lines...) Expand all
2807 2814
2808 static void TestDateFormat() { 2815 static void TestDateFormat() {
2809 #if !UCONFIG_NO_FORMATTING 2816 #if !UCONFIG_NO_FORMATTING
2810 int i; 2817 int i;
2811 UErrorCode status = U_ZERO_ERROR; 2818 UErrorCode status = U_ZERO_ERROR;
2812 UResourceBundle *resIndex = ures_open(NULL,"res_index", &status); 2819 UResourceBundle *resIndex = ures_open(NULL,"res_index", &status);
2813 if(U_FAILURE(status)){ 2820 if(U_FAILURE(status)){
2814 log_err_status(status, "Could not open res_index.res. Exiting. Error: %s \n", u_errorName(status)); 2821 log_err_status(status, "Could not open res_index.res. Exiting. Error: %s \n", u_errorName(status));
2815 return; 2822 return;
2816 } 2823 }
2817 for (i=0; i<LENGTHOF(LOCALE_ALIAS); i++) { 2824 for (i=0; i<UPRV_LENGTHOF(LOCALE_ALIAS); i++) {
2818 const char* oldLoc = LOCALE_ALIAS[i][0]; 2825 const char* oldLoc = LOCALE_ALIAS[i][0];
2819 const char* newLoc = LOCALE_ALIAS[i][1]; 2826 const char* newLoc = LOCALE_ALIAS[i][1];
2820 UDateFormat* df1 = NULL; 2827 UDateFormat* df1 = NULL;
2821 UDateFormat* df2 = NULL; 2828 UDateFormat* df2 = NULL;
2822 const char* l1 = NULL; 2829 const char* l1 = NULL;
2823 const char* l2 = NULL; 2830 const char* l2 = NULL;
2824 2831
2825 if(!isLocaleAvailable(resIndex, newLoc)){ 2832 if(!isLocaleAvailable(resIndex, newLoc)){
2826 continue; 2833 continue;
2827 } 2834 }
(...skipping 22 matching lines...) Expand all
2850 2857
2851 static void TestCollation() { 2858 static void TestCollation() {
2852 #if !UCONFIG_NO_COLLATION 2859 #if !UCONFIG_NO_COLLATION
2853 int i; 2860 int i;
2854 UErrorCode status = U_ZERO_ERROR; 2861 UErrorCode status = U_ZERO_ERROR;
2855 UResourceBundle *resIndex = ures_open(NULL,"res_index", &status); 2862 UResourceBundle *resIndex = ures_open(NULL,"res_index", &status);
2856 if(U_FAILURE(status)){ 2863 if(U_FAILURE(status)){
2857 log_err_status(status, "Could not open res_index.res. Exiting. Error: %s \n", u_errorName(status)); 2864 log_err_status(status, "Could not open res_index.res. Exiting. Error: %s \n", u_errorName(status));
2858 return; 2865 return;
2859 } 2866 }
2860 for (i=0; i<LENGTHOF(LOCALE_ALIAS); i++) { 2867 for (i=0; i<UPRV_LENGTHOF(LOCALE_ALIAS); i++) {
2861 const char* oldLoc = LOCALE_ALIAS[i][0]; 2868 const char* oldLoc = LOCALE_ALIAS[i][0];
2862 const char* newLoc = LOCALE_ALIAS[i][1]; 2869 const char* newLoc = LOCALE_ALIAS[i][1];
2863 UCollator* c1 = NULL; 2870 UCollator* c1 = NULL;
2864 UCollator* c2 = NULL; 2871 UCollator* c2 = NULL;
2865 const char* l1 = NULL; 2872 const char* l1 = NULL;
2866 const char* l2 = NULL; 2873 const char* l2 = NULL;
2867 2874
2868 status = U_ZERO_ERROR; 2875 status = U_ZERO_ERROR;
2869 if(!isLocaleAvailable(resIndex, newLoc)){ 2876 if(!isLocaleAvailable(resIndex, newLoc)){
2870 continue; 2877 continue;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
2974 } 2981 }
2975 2982
2976 static void TestULocale() { 2983 static void TestULocale() {
2977 int i; 2984 int i;
2978 UErrorCode status = U_ZERO_ERROR; 2985 UErrorCode status = U_ZERO_ERROR;
2979 UResourceBundle *resIndex = ures_open(NULL,"res_index", &status); 2986 UResourceBundle *resIndex = ures_open(NULL,"res_index", &status);
2980 if(U_FAILURE(status)){ 2987 if(U_FAILURE(status)){
2981 log_err_status(status, "Could not open res_index.res. Exiting. Error: %s \n", u_errorName(status)); 2988 log_err_status(status, "Could not open res_index.res. Exiting. Error: %s \n", u_errorName(status));
2982 return; 2989 return;
2983 } 2990 }
2984 for (i=0; i<LENGTHOF(LOCALE_ALIAS); i++) { 2991 for (i=0; i<UPRV_LENGTHOF(LOCALE_ALIAS); i++) {
2985 const char* oldLoc = LOCALE_ALIAS[i][0]; 2992 const char* oldLoc = LOCALE_ALIAS[i][0];
2986 const char* newLoc = LOCALE_ALIAS[i][1]; 2993 const char* newLoc = LOCALE_ALIAS[i][1];
2987 UChar name1[256], name2[256]; 2994 UChar name1[256], name2[256];
2988 char names1[256], names2[256]; 2995 char names1[256], names2[256];
2989 int32_t capacity = 256; 2996 int32_t capacity = 256;
2990 2997
2991 status = U_ZERO_ERROR; 2998 status = U_ZERO_ERROR;
2992 if(!isLocaleAvailable(resIndex, newLoc)){ 2999 if(!isLocaleAvailable(resIndex, newLoc)){
2993 continue; 3000 continue;
2994 } 3001 }
(...skipping 25 matching lines...) Expand all
3020 UResourceBundle* rb1 = NULL; 3027 UResourceBundle* rb1 = NULL;
3021 UResourceBundle* rb2 = NULL; 3028 UResourceBundle* rb2 = NULL;
3022 UErrorCode status = U_ZERO_ERROR; 3029 UErrorCode status = U_ZERO_ERROR;
3023 int i; 3030 int i;
3024 UResourceBundle *resIndex = NULL; 3031 UResourceBundle *resIndex = NULL;
3025 if(U_FAILURE(status)){ 3032 if(U_FAILURE(status)){
3026 log_err("Could not open res_index.res. Exiting. Error: %s\n", u_errorNam e(status)); 3033 log_err("Could not open res_index.res. Exiting. Error: %s\n", u_errorNam e(status));
3027 return; 3034 return;
3028 } 3035 }
3029 resIndex = ures_open(NULL,"res_index", &status); 3036 resIndex = ures_open(NULL,"res_index", &status);
3030 for (i=0; i<LENGTHOF(LOCALE_ALIAS); i++) { 3037 for (i=0; i<UPRV_LENGTHOF(LOCALE_ALIAS); i++) {
3031 3038
3032 const char* oldLoc = LOCALE_ALIAS[i][0]; 3039 const char* oldLoc = LOCALE_ALIAS[i][0];
3033 const char* newLoc = LOCALE_ALIAS[i][1]; 3040 const char* newLoc = LOCALE_ALIAS[i][1];
3034 if(!isLocaleAvailable(resIndex, newLoc)){ 3041 if(!isLocaleAvailable(resIndex, newLoc)){
3035 continue; 3042 continue;
3036 } 3043 }
3037 rb1 = ures_open(NULL, oldLoc, &status); 3044 rb1 = ures_open(NULL, oldLoc, &status);
3038 if (U_FAILURE(status)) { 3045 if (U_FAILURE(status)) {
3039 log_err("ures_open(%s) failed %s\n", oldLoc, u_errorName(status)); 3046 log_err("ures_open(%s) failed %s\n", oldLoc, u_errorName(status));
3040 } 3047 }
(...skipping 24 matching lines...) Expand all
3065 3072
3066 UChar oldCountry[256] = {'\0'}; 3073 UChar oldCountry[256] = {'\0'};
3067 UChar newCountry[256] = {'\0'}; 3074 UChar newCountry[256] = {'\0'};
3068 UChar oldLang[256] = {'\0'}; 3075 UChar oldLang[256] = {'\0'};
3069 UChar newLang[256] = {'\0'}; 3076 UChar newLang[256] = {'\0'};
3070 char country[256] ={'\0'}; 3077 char country[256] ={'\0'};
3071 char language[256] ={'\0'}; 3078 char language[256] ={'\0'};
3072 int32_t capacity = 256; 3079 int32_t capacity = 256;
3073 int i =0; 3080 int i =0;
3074 int j=0; 3081 int j=0;
3075 for (i=0; i<LENGTHOF(LOCALE_ALIAS); i++) { 3082 for (i=0; i<UPRV_LENGTHOF(LOCALE_ALIAS); i++) {
3076 const char* oldLoc = LOCALE_ALIAS[i][0]; 3083 const char* oldLoc = LOCALE_ALIAS[i][0];
3077 const char* newLoc = LOCALE_ALIAS[i][1]; 3084 const char* newLoc = LOCALE_ALIAS[i][1];
3078 UErrorCode status = U_ZERO_ERROR; 3085 UErrorCode status = U_ZERO_ERROR;
3079 int32_t available = uloc_countAvailable(); 3086 int32_t available = uloc_countAvailable();
3080 3087
3081 for(j=0; j<available; j++){ 3088 for(j=0; j<available; j++){
3082 3089
3083 const char* dispLoc = uloc_getAvailable(j); 3090 const char* dispLoc = uloc_getAvailable(j);
3084 int32_t oldCountryLen = uloc_getDisplayCountry(oldLoc,dispLoc, oldCo untry, capacity, &status); 3091 int32_t oldCountryLen = uloc_getDisplayCountry(oldLoc,dispLoc, oldCo untry, capacity, &status);
3085 int32_t newCountryLen = uloc_getDisplayCountry(newLoc, dispLoc, newC ountry, capacity, &status); 3092 int32_t newCountryLen = uloc_getDisplayCountry(newLoc, dispLoc, newC ountry, capacity, &status);
(...skipping 1624 matching lines...) Expand 10 before | Expand all | Expand 10 after
4710 }, { 4717 }, {
4711 "und_UY", 4718 "und_UY",
4712 "es_Latn_UY", 4719 "es_Latn_UY",
4713 "es_UY" 4720 "es_UY"
4714 }, { 4721 }, {
4715 "und_UZ", 4722 "und_UZ",
4716 "uz_Latn_UZ", 4723 "uz_Latn_UZ",
4717 "uz" 4724 "uz"
4718 }, { 4725 }, {
4719 "und_VA", 4726 "und_VA",
4720 "la_Latn_VA", 4727 "it_Latn_VA",
4721 "la" 4728 "it_VA"
4722 }, { 4729 }, {
4723 "und_VE", 4730 "und_VE",
4724 "es_Latn_VE", 4731 "es_Latn_VE",
4725 "es_VE" 4732 "es_VE"
4726 }, { 4733 }, {
4727 "und_VN", 4734 "und_VN",
4728 "vi_Latn_VN", 4735 "vi_Latn_VN",
4729 "vi" 4736 "vi"
4730 }, { 4737 }, {
4731 "und_VU", 4738 "und_VU",
(...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after
5663 else if (status == U_BUFFER_OVERFLOW_ERROR || status == U_STRING_NOT_TER MINATED_WARNING) { 5670 else if (status == U_BUFFER_OVERFLOW_ERROR || status == U_STRING_NOT_TER MINATED_WARNING) {
5664 if (uprv_strnicmp(minimal, buffer, bufferSize) != 0) { 5671 if (uprv_strnicmp(minimal, buffer, bufferSize) != 0) {
5665 log_err(" minimal doesn't match expected \"%s\" in uloc_minimiz eSubtags(), minimal \"%s\" = \"%*s\"\n", 5672 log_err(" minimal doesn't match expected \"%s\" in uloc_minimiz eSubtags(), minimal \"%s\" = \"%*s\"\n",
5666 minimal, maximal, (int)sizeof(buffer), buffer); 5673 minimal, maximal, (int)sizeof(buffer), buffer);
5667 } 5674 }
5668 } 5675 }
5669 } 5676 }
5670 } 5677 }
5671 5678
5672 const char* const locale_to_langtag[][3] = { 5679 const char* const locale_to_langtag[][3] = {
5673 {"@x=elmer", "x-elmer", "x-elmer"},
5674 {"", "und", "und"}, 5680 {"", "und", "und"},
5675 {"en", "en", "en"}, 5681 {"en", "en", "en"},
5676 {"en_US", "en-US", "en-US"}, 5682 {"en_US", "en-US", "en-US"},
5677 {"iw_IL", "he-IL", "he-IL"}, 5683 {"iw_IL", "he-IL", "he-IL"},
5678 {"sr_Latn_SR", "sr-Latn-SR", "sr-Latn-SR"}, 5684 {"sr_Latn_SR", "sr-Latn-SR", "sr-Latn-SR"},
5679 {"en__POSIX", "en-u-va-posix", "en-u-va-posix"}, 5685 {"en__POSIX", "en-u-va-posix", "en-u-va-posix"},
5680 {"en_POSIX", "en-u-va-posix", "en-u-va-posix"}, 5686 {"en_POSIX", "en-u-va-posix", "en-u-va-posix"},
5681 {"en_US_POSIX_VAR", "en-US-posix-x-lvariant-var", NULL}, /* variant POSIX_V AR is processed as regular variant */ 5687 {"en_US_POSIX_VAR", "en-US-posix-x-lvariant-var", NULL}, /* variant POSIX_V AR is processed as regular variant */
5682 {"en_US_VAR_POSIX", "en-US-x-lvariant-var-posix", NULL}, /* variant VAR_POS IX is processed as regular variant */ 5688 {"en_US_VAR_POSIX", "en-US-x-lvariant-var-posix", NULL}, /* variant VAR_POS IX is processed as regular variant */
5683 {"en_US_POSIX@va=posix2", "en-US-u-va-posix2", "en-US-u-va-posix2"}, /* if keyword va=xxx already exists, variant POSIX is simply dropped */ 5689 {"en_US_POSIX@va=posix2", "en-US-u-va-posix2", "en-US-u-va-posix2"}, /* if keyword va=xxx already exists, variant POSIX is simply dropped */
(...skipping 13 matching lines...) Expand all
5697 {"en_US_VARIANTA_VARIANTB", "en-US-varianta-variantb", "en-US-varianta-vari antb"}, 5703 {"en_US_VARIANTA_VARIANTB", "en-US-varianta-variantb", "en-US-varianta-vari antb"},
5698 {"ja__9876_5432", "ja-9876-5432", "ja-9876-5432"}, 5704 {"ja__9876_5432", "ja-9876-5432", "ja-9876-5432"},
5699 {"zh_Hant__VAR", "zh-Hant-x-lvariant-var", NULL}, 5705 {"zh_Hant__VAR", "zh-Hant-x-lvariant-var", NULL},
5700 {"es__BADVARIANT_GOODVAR", "es-goodvar", NULL}, 5706 {"es__BADVARIANT_GOODVAR", "es-goodvar", NULL},
5701 {"en@calendar=gregorian", "en-u-ca-gregory", "en-u-ca-gregory"}, 5707 {"en@calendar=gregorian", "en-u-ca-gregory", "en-u-ca-gregory"},
5702 {"de@collation=phonebook;calendar=gregorian", "de-u-ca-gregory-co-phonebk" , "de-u-ca-gregory-co-phonebk"}, 5708 {"de@collation=phonebook;calendar=gregorian", "de-u-ca-gregory-co-phonebk" , "de-u-ca-gregory-co-phonebk"},
5703 {"th@numbers=thai;z=extz;x=priv-use;a=exta", "th-a-exta-u-nu-thai-z-extz-x -priv-use", "th-a-exta-u-nu-thai-z-extz-x-priv-use"}, 5709 {"th@numbers=thai;z=extz;x=priv-use;a=exta", "th-a-exta-u-nu-thai-z-extz-x -priv-use", "th-a-exta-u-nu-thai-z-extz-x-priv-use"},
5704 {"en@timezone=America/New_York;calendar=japanese", "en-u-ca-japanese-tz-u snyc", "en-u-ca-japanese-tz-usnyc"}, 5710 {"en@timezone=America/New_York;calendar=japanese", "en-u-ca-japanese-tz-u snyc", "en-u-ca-japanese-tz-usnyc"},
5705 {"en@timezone=US/Eastern", "en-u-tz-usnyc", "en-u-tz-usnyc"}, 5711 {"en@timezone=US/Eastern", "en-u-tz-usnyc", "en-u-tz-usnyc"},
5706 {"en@x=x-y-z;a=a-b-c", "en-x-x-y-z", NULL}, 5712 {"en@x=x-y-z;a=a-b-c", "en-x-x-y-z", NULL},
5707 {"it@collation=badcollationtype;colStrength=identical;cu=usd-eur", "it-u-ks- identic", NULL}, 5713 {"it@collation=badcollationtype;colStrength=identical;cu=usd-eur", "it-u-cu- usd-eur-ks-identic", NULL},
5708 {"en_US_POSIX", "en-US-u-va-posix", "en-US-u-va-posix"}, 5714 {"en_US_POSIX", "en-US-u-va-posix", "en-US-u-va-posix"},
5709 {"en_US_POSIX@calendar=japanese;currency=EUR","en-US-u-ca-japanese-cu-EUR-va -posix", "en-US-u-ca-japanese-cu-EUR-va-posix"}, 5715 {"en_US_POSIX@calendar=japanese;currency=EUR","en-US-u-ca-japanese-cu-eur-va -posix", "en-US-u-ca-japanese-cu-eur-va-posix"},
5710 {"@x=elmer", "x-elmer", "x-elmer"}, 5716 {"@x=elmer", "x-elmer", "x-elmer"},
5711 {"en@x=elmer", "en-x-elmer", "en-x-elmer"}, 5717 {"en@x=elmer", "en-x-elmer", "en-x-elmer"},
5712 {"@x=elmer;a=exta", "und-a-exta-x-elmer", "und-a-exta-x-elmer"}, 5718 {"@x=elmer;a=exta", "und-a-exta-x-elmer", "und-a-exta-x-elmer"},
5713 {"en_US@attribute=attr1-attr2;calendar=gregorian", "en-US-u-attr1-attr2-ca-g regory", "en-US-u-attr1-attr2-ca-gregory"}, 5719 {"en_US@attribute=attr1-attr2;calendar=gregorian", "en-US-u-attr1-attr2-ca-g regory", "en-US-u-attr1-attr2-ca-gregory"},
5714 {NULL, NULL, NULL} 5720 {NULL, NULL, NULL}
5715 }; 5721 };
5716 5722
5717 static void TestToLanguageTag(void) { 5723 static void TestToLanguageTag(void) {
5718 char langtag[256]; 5724 char langtag[256];
5719 int32_t i; 5725 int32_t i;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
5769 } 5775 }
5770 } 5776 }
5771 } 5777 }
5772 5778
5773 #define FULL_LENGTH -1 5779 #define FULL_LENGTH -1
5774 static const struct { 5780 static const struct {
5775 const char *bcpID; 5781 const char *bcpID;
5776 const char *locID; 5782 const char *locID;
5777 int32_t len; 5783 int32_t len;
5778 } langtag_to_locale[] = { 5784 } langtag_to_locale[] = {
5785 {"ja-u-ijkl-efgh-abcd-ca-japanese-xx-yyy-zzz-kn", "ja@attribute=abcd-efgh- ijkl;calendar=japanese;colnumeric=yes;xx=yyy-zzz", FULL_LENGTH},
5779 {"en", "en", FULL_LENGTH}, 5786 {"en", "en", FULL_LENGTH},
5780 {"en-us", "en_US", FULL_LENGTH}, 5787 {"en-us", "en_US", FULL_LENGTH},
5781 {"und-US", "_US", FULL_LENGTH}, 5788 {"und-US", "_US", FULL_LENGTH},
5782 {"und-latn", "_Latn", FULL_LENGTH}, 5789 {"und-latn", "_Latn", FULL_LENGTH},
5783 {"en-US-posix", "en_US_POSIX", FULL_LENGTH}, 5790 {"en-US-posix", "en_US_POSIX", FULL_LENGTH},
5784 {"de-de_euro", "de", 2}, 5791 {"de-de_euro", "de", 2},
5785 {"kok-IN", "kok_IN", FULL_LENGTH}, 5792 {"kok-IN", "kok_IN", FULL_LENGTH},
5786 {"123", "", 0}, 5793 {"123", "", 0},
5787 {"en_us", "", 0}, 5794 {"en_us", "", 0},
5788 {"en-latn-x", "en_Latn", 7}, 5795 {"en-latn-x", "en_Latn", 7},
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
5838 expParsedLen = langtag_to_locale[i].len; 5845 expParsedLen = langtag_to_locale[i].len;
5839 if (expParsedLen == FULL_LENGTH) { 5846 if (expParsedLen == FULL_LENGTH) {
5840 expParsedLen = uprv_strlen(langtag_to_locale[i].bcpID); 5847 expParsedLen = uprv_strlen(langtag_to_locale[i].bcpID);
5841 } 5848 }
5842 uloc_forLanguageTag(langtag_to_locale[i].bcpID, locale, sizeof(locale), &parsedLen, &status); 5849 uloc_forLanguageTag(langtag_to_locale[i].bcpID, locale, sizeof(locale), &parsedLen, &status);
5843 if (U_FAILURE(status)) { 5850 if (U_FAILURE(status)) {
5844 log_err_status(status, "Error returned by uloc_forLanguageTag for la nguage tag [%s] - error: %s\n", 5851 log_err_status(status, "Error returned by uloc_forLanguageTag for la nguage tag [%s] - error: %s\n",
5845 langtag_to_locale[i].bcpID, u_errorName(status)); 5852 langtag_to_locale[i].bcpID, u_errorName(status));
5846 } else { 5853 } else {
5847 if (uprv_strcmp(langtag_to_locale[i].locID, locale) != 0) { 5854 if (uprv_strcmp(langtag_to_locale[i].locID, locale) != 0) {
5848 log_err("uloc_forLanguageTag returned locale [%s] for input lang uage tag [%s] - expected: [%s]\n", 5855 log_data_err("uloc_forLanguageTag returned locale [%s] for input language tag [%s] - expected: [%s]\n",
5849 locale, langtag_to_locale[i].bcpID, langtag_to_locale[i].loc ID); 5856 locale, langtag_to_locale[i].bcpID, langtag_to_locale[i].loc ID);
5850 } 5857 }
5851 if (parsedLen != expParsedLen) { 5858 if (parsedLen != expParsedLen) {
5852 log_err("uloc_forLanguageTag parsed length of %d for input langu age tag [%s] - expected parsed length: %d\n", 5859 log_err("uloc_forLanguageTag parsed length of %d for input langu age tag [%s] - expected parsed length: %d\n",
5853 parsedLen, langtag_to_locale[i].bcpID, expParsedLen); 5860 parsedLen, langtag_to_locale[i].bcpID, expParsedLen);
5854 } 5861 }
5855 } 5862 }
5856 } 5863 }
5857 } 5864 }
5858 5865
5866 static void TestToUnicodeLocaleKey(void)
5867 {
5868 /* $IN specifies the result should be the input pointer itself */
5869 static const char* DATA[][2] = {
5870 {"calendar", "ca"},
5871 {"CALEndar", "ca"}, /* difference casing */
5872 {"ca", "ca"}, /* bcp key itself */
5873 {"kv", "kv"}, /* no difference between legacy and bcp */
5874 {"foo", NULL}, /* unknown, bcp ill-formed */
5875 {"ZZ", "$IN"}, /* unknown, bcp well-formed - */
5876 {NULL, NULL}
5877 };
5878
5879 int32_t i;
5880 for (i = 0; DATA[i][0] != NULL; i++) {
5881 const char* keyword = DATA[i][0];
5882 const char* expected = DATA[i][1];
5883 const char* bcpKey = NULL;
5884
5885 bcpKey = uloc_toUnicodeLocaleKey(keyword);
5886 if (expected == NULL) {
5887 if (bcpKey != NULL) {
5888 log_err("toUnicodeLocaleKey: keyword=%s => %s, expected=NULL\n", keyword, bcpKey);
5889 }
5890 } else if (bcpKey == NULL) {
5891 log_data_err("toUnicodeLocaleKey: keyword=%s => NULL, expected=%s\n" , keyword, expected);
5892 } else if (uprv_strcmp(expected, "$IN") == 0) {
5893 if (bcpKey != keyword) {
5894 log_err("toUnicodeLocaleKey: keyword=%s => %s, expected=%s(input pointer)\n", keyword, bcpKey, keyword);
5895 }
5896 } else if (uprv_strcmp(bcpKey, expected) != 0) {
5897 log_err("toUnicodeLocaleKey: keyword=%s => %s, expected=%s\n", keywo rd, bcpKey, expected);
5898 }
5899 }
5900 }
5901
5902 static void TestToLegacyKey(void)
5903 {
5904 /* $IN specifies the result should be the input pointer itself */
5905 static const char* DATA[][2] = {
5906 {"kb", "colbackwards"},
5907 {"kB", "colbackwards"}, /* different casing */
5908 {"Collation", "collation"}, /* keyword itself with different casing */
5909 {"kv", "kv"}, /* no difference between legacy and bcp */
5910 {"foo", "$IN"}, /* unknown, bcp ill-formed */
5911 {"ZZ", "$IN"}, /* unknown, bcp well-formed */
5912 {"e=mc2", NULL}, /* unknown, bcp/legacy ill-formed */
5913 {NULL, NULL}
5914 };
5915
5916 int32_t i;
5917 for (i = 0; DATA[i][0] != NULL; i++) {
5918 const char* keyword = DATA[i][0];
5919 const char* expected = DATA[i][1];
5920 const char* legacyKey = NULL;
5921
5922 legacyKey = uloc_toLegacyKey(keyword);
5923 if (expected == NULL) {
5924 if (legacyKey != NULL) {
5925 log_err("toLegacyKey: keyword=%s => %s, expected=NULL\n", keywor d, legacyKey);
5926 }
5927 } else if (legacyKey == NULL) {
5928 log_err("toLegacyKey: keyword=%s => NULL, expected=%s\n", keyword, e xpected);
5929 } else if (uprv_strcmp(expected, "$IN") == 0) {
5930 if (legacyKey != keyword) {
5931 log_err("toLegacyKey: keyword=%s => %s, expected=%s(input pointe r)\n", keyword, legacyKey, keyword);
5932 }
5933 } else if (uprv_strcmp(legacyKey, expected) != 0) {
5934 log_data_err("toUnicodeLocaleKey: keyword=%s, %s, expected=%s\n", ke yword, legacyKey, expected);
5935 }
5936 }
5937 }
5938
5939 static void TestToUnicodeLocaleType(void)
5940 {
5941 /* $IN specifies the result should be the input pointer itself */
5942 static const char* DATA[][3] = {
5943 {"tz", "Asia/Kolkata", "inccu"},
5944 {"calendar", "gregorian", "gregory"},
5945 {"ca", "gregorian", "gregory"},
5946 {"ca", "Gregorian", "gregory"},
5947 {"ca", "buddhist", "buddhist"},
5948 {"Calendar", "Japanese", "japanese"},
5949 {"calendar", "Islamic-Civil", "islamic-civil"},
5950 {"calendar", "islamicc", "islamic-civil"}, /* bcp type alias */
5951 {"colalternate", "NON-IGNORABLE", "noignore"},
5952 {"colcaselevel", "yes", "true"},
5953 {"tz", "america/new_york", "usnyc"},
5954 {"tz", "Asia/Kolkata", "inccu"},
5955 {"timezone", "navajo", "usden"},
5956 {"ca", "aaaa", "$IN"}, /* unknown type, wel l-formed type */
5957 {"ca", "gregory-japanese-islamic", "$IN"}, /* unknown type, well-formed type */
5958 {"zz", "gregorian", NULL}, /* unknown key, ill- formed type */
5959 {"co", "foo-", NULL}, /* unknown type, ill -formed type */
5960 {"variableTop", "00A0", "$IN"}, /* valid codepoints type */
5961 {"variableTop", "wxyz", "$IN"}, /* invalid codepoint s type - return as is for now */
5962 {"kr", "space-punct", "space-punct"}, /* valid reorder code type */
5963 {"kr", "digit-spacepunct", NULL}, /* invalid (bcp ill- formed) reordercode type */
5964 {NULL, NULL, NULL}
5965 };
5966
5967 int32_t i;
5968 for (i = 0; DATA[i][0] != NULL; i++) {
5969 const char* keyword = DATA[i][0];
5970 const char* value = DATA[i][1];
5971 const char* expected = DATA[i][2];
5972 const char* bcpType = NULL;
5973
5974 bcpType = uloc_toUnicodeLocaleType(keyword, value);
5975 if (expected == NULL) {
5976 if (bcpType != NULL) {
5977 log_err("toUnicodeLocaleType: keyword=%s, value=%s => %s, expect ed=NULL\n", keyword, value, bcpType);
5978 }
5979 } else if (bcpType == NULL) {
5980 log_data_err("toUnicodeLocaleType: keyword=%s, value=%s => NULL, exp ected=%s\n", keyword, value, expected);
5981 } else if (uprv_strcmp(expected, "$IN") == 0) {
5982 if (bcpType != value) {
5983 log_err("toUnicodeLocaleType: keyword=%s, value=%s => %s, expect ed=%s(input pointer)\n", keyword, value, bcpType, value);
5984 }
5985 } else if (uprv_strcmp(bcpType, expected) != 0) {
5986 log_data_err("toUnicodeLocaleType: keyword=%s, value=%s => %s, expec ted=%s\n", keyword, value, bcpType, expected);
5987 }
5988 }
5989 }
5990
5991 static void TestToLegacyType(void)
5992 {
5993 /* $IN specifies the result should be the input pointer itself */
5994 static const char* DATA[][3] = {
5995 {"calendar", "gregory", "gregorian"},
5996 {"ca", "gregory", "gregorian"},
5997 {"ca", "Gregory", "gregorian"},
5998 {"ca", "buddhist", "buddhist"},
5999 {"Calendar", "Japanese", "japanese"},
6000 {"calendar", "Islamic-Civil", "islamic-civil"},
6001 {"calendar", "islamicc", "islamic-civil"}, /* bcp type alias */
6002 {"colalternate", "noignore", "non-ignorable"},
6003 {"colcaselevel", "true", "yes"},
6004 {"tz", "usnyc", "America/New_York"},
6005 {"tz", "inccu", "Asia/Calcutta"},
6006 {"timezone", "usden", "America/Denver"},
6007 {"timezone", "usnavajo", "America/Denver"}, /* bcp type alias */
6008 {"colstrength", "quarternary", "quaternary"}, /* type alias */
6009 {"ca", "aaaa", "$IN"}, /* unknown type */
6010 {"calendar", "gregory-japanese-islamic", "$IN"}, /* unknown type, well-formed type */
6011 {"zz", "gregorian", "$IN"}, /* unknown key, bcp ill- formed type */
6012 {"ca", "gregorian-calendar", "$IN"}, /* known key, bcp il l-formed type */
6013 {"co", "e=mc2", NULL}, /* known key, ill-formed bcp/legacy type */
6014 {"variableTop", "00A0", "$IN"}, /* valid codepoints type */
6015 {"variableTop", "wxyz", "$IN"}, /* invalid codepoints type - return as is for now */
6016 {"kr", "space-punct", "space-punct"}, /* valid reorder code type */
6017 {"kr", "digit-spacepunct", "digit-spacepunct"}, /* inval id reordercode type, but ok for legacy syntax */
6018 {NULL, NULL, NULL}
6019 };
6020
6021 int32_t i;
6022 for (i = 0; DATA[i][0] != NULL; i++) {
6023 const char* keyword = DATA[i][0];
6024 const char* value = DATA[i][1];
6025 const char* expected = DATA[i][2];
6026 const char* legacyType = NULL;
6027
6028 legacyType = uloc_toLegacyType(keyword, value);
6029 if (expected == NULL) {
6030 if (legacyType != NULL) {
6031 log_err("toLegacyType: keyword=%s, value=%s => %s, expected=NULL \n", keyword, value, legacyType);
6032 }
6033 } else if (legacyType == NULL) {
6034 log_err("toLegacyType: keyword=%s, value=%s => NULL, expected=%s\n", keyword, value, expected);
6035 } else if (uprv_strcmp(expected, "$IN") == 0) {
6036 if (legacyType != value) {
6037 log_err("toLegacyType: keyword=%s, value=%s => %s, expected=%s(i nput pointer)\n", keyword, value, legacyType, value);
6038 }
6039 } else if (uprv_strcmp(legacyType, expected) != 0) {
6040 log_data_err("toLegacyType: keyword=%s, value=%s => %s, expected=%s\ n", keyword, value, legacyType, expected);
6041 }
6042 }
6043 }
6044
6045
6046
5859 static void test_unicode_define(const char *namech, char ch, const char *nameu, UChar uch) 6047 static void test_unicode_define(const char *namech, char ch, const char *nameu, UChar uch)
5860 { 6048 {
5861 UChar asUch[1]; 6049 UChar asUch[1];
5862 asUch[0]=0; 6050 asUch[0]=0;
5863 log_verbose("Testing whether %s[\\x%02x,'%c'] == %s[U+%04X]\n", namech, ch,(in t)ch, nameu, (int) uch); 6051 log_verbose("Testing whether %s[\\x%02x,'%c'] == %s[U+%04X]\n", namech, ch,(in t)ch, nameu, (int) uch);
5864 u_charsToUChars(&ch, asUch, 1); 6052 u_charsToUChars(&ch, asUch, 1);
5865 if(asUch[0] != uch) { 6053 if(asUch[0] != uch) {
5866 log_err("FAIL: %s[\\x%02x,'%c'] maps to U+%04X, but %s = U+%04X\n", namech, ch, (int)ch, (int)asUch[0], nameu, (int)uch); 6054 log_err("FAIL: %s[\\x%02x,'%c'] maps to U+%04X, but %s = U+%04X\n", namech, ch, (int)ch, (int)asUch[0], nameu, (int)uch);
5867 } else { 6055 } else {
5868 log_verbose(" .. OK, == U+%04X\n", (int)asUch[0]); 6056 log_verbose(" .. OK, == U+%04X\n", (int)asUch[0]);
5869 } 6057 }
5870 } 6058 }
5871 6059
5872 #define TEST_UNICODE_DEFINE(x,y) test_unicode_define(#x, (char)(x), #y, (UChar)( y)) 6060 #define TEST_UNICODE_DEFINE(x,y) test_unicode_define(#x, (char)(x), #y, (UChar)( y))
5873 6061
5874 static void TestUnicodeDefines(void) { 6062 static void TestUnicodeDefines(void) {
5875 TEST_UNICODE_DEFINE(ULOC_KEYWORD_SEPARATOR, ULOC_KEYWORD_SEPARATOR_UNICODE); 6063 TEST_UNICODE_DEFINE(ULOC_KEYWORD_SEPARATOR, ULOC_KEYWORD_SEPARATOR_UNICODE);
5876 TEST_UNICODE_DEFINE(ULOC_KEYWORD_ASSIGN, ULOC_KEYWORD_ASSIGN_UNICODE); 6064 TEST_UNICODE_DEFINE(ULOC_KEYWORD_ASSIGN, ULOC_KEYWORD_ASSIGN_UNICODE);
5877 TEST_UNICODE_DEFINE(ULOC_KEYWORD_ITEM_SEPARATOR, ULOC_KEYWORD_ITEM_SEPARATOR_U NICODE); 6065 TEST_UNICODE_DEFINE(ULOC_KEYWORD_ITEM_SEPARATOR, ULOC_KEYWORD_ITEM_SEPARATOR_U NICODE);
5878 } 6066 }
6067
6068 static void TestIsRightToLeft() {
6069 // API test only. More test cases in intltest/LocaleTest.
6070 if(uloc_isRightToLeft("root") || !uloc_isRightToLeft("EN-HEBR")) {
6071 log_err("uloc_isRightToLeft() failed");
6072 }
6073 }
OLDNEW
« no previous file with comments | « source/test/cintltst/cloctst.h ('k') | source/test/cintltst/cmsccoll.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698