X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/b75a7d8f3b4adbae880cab104ce2c6a50eee4db2..374ca955a76ecab1204ca8bfa63ff9238d998416:/icuSources/test/intltest/loctest.cpp diff --git a/icuSources/test/intltest/loctest.cpp b/icuSources/test/intltest/loctest.cpp index 9735f786..3f9e1f16 100644 --- a/icuSources/test/intltest/loctest.cpp +++ b/icuSources/test/intltest/loctest.cpp @@ -1,85 +1,122 @@ /******************************************************************** - * COPYRIGHT: - * Copyright (c) 1997-2003, International Business Machines Corporation and + * COPYRIGHT: + * Copyright (c) 1997-2004, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ #include "loctest.h" #include -#include -#include - #include "unicode/decimfmt.h" -//#include "unicode/datefmt.h" +#include "unicode/ucurr.h" #include "unicode/smpdtfmt.h" +#include "unicode/dtfmtsym.h" +#include "unicode/brkiter.h" +#include "unicode/coll.h" +#include "cstring.h" +#include "uassert.h" -const char* rawData[27][7] = { +const char* rawData[33][8] = { // language code - { "en", "fr", "hr", "el", "no", "it", "xx" }, + { "en", "fr", "ca", "el", "no", "it", "xx", "zh" }, + // script code + { "", "", "", "", "", "", "", "Hans" }, // country code - { "US", "FR", "HR", "GR", "NO", "", "YY" }, + { "US", "FR", "ES", "GR", "NO", "", "YY", "CN" }, // variant code - { "", "", "", "", "NY", "", "" }, + { "", "", "", "", "NY", "", "", "" }, // full name - { "en_US", "fr_FR", "hr_HR", "el_GR", "no_NO_NY", "it", "xx_YY" }, + { "en_US", "fr_FR", "ca_ES", "el_GR", "no_NO_NY", "it", "xx_YY", "zh_Hans_CN" }, // ISO-3 language - { "eng", "fra", "hrv", "ell", "nor", "ita", "" }, + { "eng", "fra", "cat", "ell", "nor", "ita", "", "zho" }, // ISO-3 country - { "USA", "FRA", "HRV", "GRC", "NOR", "", "" }, - // LCID (not currently public) - { "409", "40c", "41a", "408", "814", "", "" }, + { "USA", "FRA", "ESP", "GRC", "NOR", "", "", "CHN" }, + // LCID + { "409", "40c", "403", "408", "814", "10", "0", "804" }, // display langage (English) - { "English", "French", "Croatian", "Greek", "Norwegian", "Italian", "xx" }, + { "English", "French", "Catalan", "Greek", "Norwegian", "Italian", "xx", "Chinese" }, + // display script (English) + { "", "", "", "", "", "", "", "Simplified Han" }, // display country (English) - { "United States", "France", "Croatia", "Greece", "Norway", "", "YY" }, + { "United States", "France", "Spain", "Greece", "Norway", "", "YY", "China" }, // display variant (English) - { "", "", "", "", "Nynorsk", "", ""}, - //{ "", "", "", "", "NY", "", ""}, + { "", "", "", "", "NY", "", "", ""}, // display name (English) // Updated no_NO_NY English display name for new pattern-based algorithm // (part of Euro support). - { "English (United States)", "French (France)", "Croatian (Croatia)", "Greek (Greece)", "Norwegian (Norway, Nynorsk)", "Italian", "xx (YY)" }, - //{ "English (United States)", "French (France)", "Croatian (Croatia)", "Greek (Greece)", "Norwegian (Norway,NY)", "Italian", "xx (YY)" }, + { "English (United States)", "French (France)", "Catalan (Spain)", "Greek (Greece)", "Norwegian (Norway, NY)", "Italian", "xx (YY)", "Chinese (Simplified Han, China)" }, // display langage (French) - { "anglais", "fran\\u00E7ais", "croate", "grec", "norv\\u00E9gien", "italien", "xx" }, + { "anglais", "fran\\u00E7ais", "catalan", "grec", "norv\\u00E9gien", "italien", "xx", "chinois" }, + // display script (French) + { "", "", "", "", "", "", "", "han simplifi\\u00E9" }, // display country (French) - { "\\u00C9tats-Unis", "France", "Croatie", "Gr\\u00E8ce", "Norv\\u00E8ge", "", "YY" }, + { "\\u00C9tats-Unis", "France", "Espagne", "Gr\\u00E8ce", "Norv\\u00E8ge", "", "YY", "Chine" }, // display variant (French) - { "", "", "", "", "Nynorsk", "", "" }, + { "", "", "", "", "NY", "", "", "" }, // display name (French) - //{ "anglais (États-Unis)", "français (France)", "croate (Croatie)", "grec (Grèce)", "norvégien (Norvège,Nynorsk)", "italien", "xx (YY)" }, - { "anglais (\\u00C9tats-Unis)", "fran\\u00E7ais (France)", "croate (Croatie)", "grec (Gr\\u00E8ce)", "norv\\u00E9gien (Norv\\u00E8ge, Nynorsk)", "italien", "xx (YY)" }, // STILL not right - - // display langage (Croatian) - { "", "", "hrvatski", "", "", "", "xx" }, - // display country (Croatian) - { "", "", "Hrvatska", "", "", "", "YY" }, - // display variant (Croatian) - { "", "", "", "", "", "", ""}, - // display name (Croatian) - { "", "", "hrvatski (Hrvatska)", "", "", "", "xx (YY)" }, + //{ "anglais (Etats-Unis)", "francais (France)", "catalan (Espagne)", "grec (Grece)", "norvegien (Norvege,Nynorsk)", "italien", "xx (YY)" }, + { "anglais (\\u00C9tats-Unis)", "fran\\u00E7ais (France)", "catalan (Espagne)", "grec (Gr\\u00E8ce)", "norv\\u00E9gien (Norv\\u00E8ge, NY)", "italien", "xx (YY)", "chinois (han simplifi\\u00E9, Chine)" }, // STILL not right + + + /* display language (Catalan) */ + { "angl\\u00E8s", "franc\\u00E8s", "catal\\u00E0", "grec", "noruec", "itali\\u00E0", "", "xin\\u00E9s" }, + /* display script (Catalan) */ + { "", "", "", "", "", "", "", "Hans" }, + /* display country (Catalan) */ + { "Estats Units", "Fran\\u00E7a", "Espanya", "Gr\\u00E8cia", "Noruega", "", "", "Xina" }, + /* display variant (Catalan) */ + { "", "", "", "", "NY", "", "" }, + /* display name (Catalan) */ + { "angl\\u00E8s (Estats Units)", "franc\\u00E8s (Fran\\u00E7a)", "catal\\u00E0 (Espanya)", "grec (Gr\\u00E8cia)", "noruec (Noruega, NY)", "itali\\u00E0", "", "xin\\u00E9s (Hans, Xina)" }, // display langage (Greek)[actual values listed below] - { "\\u0391\\u03b3\\u03b3\\u03bb\\u03b9\\u03ba\\u03ac", "\\u0393\\u03b1\\u03bb\\u03bb\\u03b9\\u03ba\\u03ac", "\\u039a\\u03c1\\u03bf\\u03b1\\u03c4\\u03b9\\u03ba\\u03ac", "", "\\u039d\\u03bf\\u03c1\\u03b2\\u03b7\\u03b3\\u03b9\\u03ba\\u03ac", "", "" }, + { "\\u0391\\u03b3\\u03b3\\u03bb\\u03b9\\u03ba\\u03ac", + "\\u0393\\u03b1\\u03bb\\u03bb\\u03b9\\u03ba\\u03ac", + "\\u039a\\u03b1\\u03c4\\u03b1\\u03bb\\u03b1\\u03bd\\u03b9\\u03ba\\u03ac", + "\\u0395\\u03bb\\u03bb\\u03b7\\u03bd\\u03b9\\u03ba\\u03ac", + "\\u039d\\u03bf\\u03c1\\u03b2\\u03b7\\u03b3\\u03b9\\u03ba\\u03ac", + "\\u0399\\u03c4\\u03b1\\u03bb\\u03b9\\u03ba\\u03ac", + "", + "\\u039A\\u03B9\\u03BD\\u03B5\\u03B6\\u03B9\\u03BA\\u03AC" + }, + // display script (Greek) + { "", "", "", "", "", "", "", "Hans" }, // display country (Greek)[actual values listed below] - { "\\u0397\\u03bd\\u03c9\\u03bc\\u03ad\\u03bd\\u03b5\\u03c2 \\u03a0\\u03bf\\u03bb\\u03b9\\u03c4\\u03b5\\u03af\\u03b5\\u03c2 \\u0391\\u03bc\\u03b5\\u03c1\\u03b9\\u03ba\\u03ae\\u03c2", "\\u0393\\u03b1\\u03bb\\u03bb\\u03af\\u03b1", "\\u039a\\u03c1\\u03bf\\u03b1\\u03c4\\u03af\\u03b1", "", "\\u039d\\u03bf\\u03c1\\u03b2\\u03b7\\u03b3\\u03af\\u03b1", "", "" }, + { "\\u0397\\u03BD\\u03C9\\u03BC\\u03AD\\u03BD\\u03B5\\u03C2 \\u03A0\\u03BF\\u03BB\\u03B9\\u03C4\\u03B5\\u03AF\\u03B5\\u03C2", + "\\u0393\\u03b1\\u03bb\\u03bb\\u03af\\u03b1", + "\\u0399\\u03c3\\u03c0\\u03b1\\u03bd\\u03af\\u03b1", + "\\u0395\\u03bb\\u03bb\\u03ac\\u03b4\\u03b1", + "\\u039d\\u03bf\\u03c1\\u03b2\\u03b7\\u03b3\\u03af\\u03b1", + "", + "", + "\\u039A\\u03AF\\u03BD\\u03B1" + }, // display variant (Greek) - { "", "", "", "", "", "", "" }, + { "", "", "", "", "NY", "", "" }, // display name (Greek)[actual values listed below] - { "\\u0391\\u03b3\\u03b3\\u03bb\\u03b9\\u03ba\\u03ac (\\u0397\\u03bd\\u03c9\\u03bc\\u03ad\\u03bd\\u03b5\\u03c2 \\u03a0\\u03bf\\u03bb\\u03b9\\u03c4\\u03b5\\u03af\\u03b5\\u03c2 \\u0391\\u03bc\\u03b5\\u03c1\\u03b9\\u03ba\\u03ae\\u03c2)", "\\u0393\\u03b1\\u03bb\\u03bb\\u03b9\\u03ba\\u03ac (\\u0393\\u03b1\\u03bb\\u03bb\\u03af\\u03b1)", "\\u039a\\u03c1\\u03bf\\u03b1\\u03c4\\u03b9\\u03ba\\u03ac (\\u039a\\u03c1\\u03bf\\u03b1\\u03c4\\u03af\\u03b1)", "", "\\u039d\\u03bf\\u03c1\\u03b2\\u03b7\\u03b3\\u03b9\\u03ba\\u03ac (\\u039d\\u03bf\\u03c1\\u03b2\\u03b7\\u03b3\\u03af\\u03b1, Nynorsk)", "", "" }, + { "\\u0391\\u03b3\\u03b3\\u03bb\\u03b9\\u03ba\\u03ac (\\u0397\\u03BD\\u03C9\\u03BC\\u03AD\\u03BD\\u03B5\\u03C2 \\u03A0\\u03BF\\u03BB\\u03B9\\u03C4\\u03B5\\u03AF\\u03B5\\u03C2)", + "\\u0393\\u03b1\\u03bb\\u03bb\\u03b9\\u03ba\\u03ac (\\u0393\\u03b1\\u03bb\\u03bb\\u03af\\u03b1)", + "\\u039a\\u03b1\\u03c4\\u03b1\\u03bb\\u03b1\\u03bd\\u03b9\\u03ba\\u03ac (\\u0399\\u03c3\\u03c0\\u03b1\\u03bd\\u03af\\u03b1)", + "\\u0395\\u03bb\\u03bb\\u03b7\\u03bd\\u03b9\\u03ba\\u03ac (\\u0395\\u03bb\\u03bb\\u03ac\\u03b4\\u03b1)", + "\\u039d\\u03bf\\u03c1\\u03b2\\u03b7\\u03b3\\u03b9\\u03ba\\u03ac (\\u039d\\u03bf\\u03c1\\u03b2\\u03b7\\u03b3\\u03af\\u03b1, NY)", + "\\u0399\\u03c4\\u03b1\\u03bb\\u03b9\\u03ba\\u03ac", + "", + "\\u039A\\u03B9\\u03BD\\u03B5\\u03B6\\u03B9\\u03BA\\u03AC (Hans, \\u039A\\u03AF\\u03BD\\u03B1)" + }, // display langage () - { "English", "French", "Croatian", "Greek", "Norwegian", "Italian", "xx" }, + { "English", "French", "Catalan", "Greek", "Norwegian", "Italian", "xx", "" }, + // display script () + { "", "", "", "", "", "", "", ""}, // display country () - { "United States", "France", "Croatia", "Greece", "Norway", "", "YY" }, + { "United States", "France", "Spain", "Greece", "Norway", "", "YY", "" }, // display variant () - { "", "", "", "", "Nynorsk", "", ""}, + { "", "", "", "", "Nynorsk", "", "", ""}, // display name () - //{ "English (United States)", "French (France)", "Croatian (Croatia)", "Greek (Greece)", "Norwegian (Norway,Nynorsk)", "Italian", "xx (YY)" }, - { "English (United States)", "French (France)", "Croatian (Croatia)", "Greek (Greece)", "Norwegian (Norway,NY)", "Italian", "xx (YY)" } + //{ "English (United States)", "French (France)", "Catalan (Spain)", "Greek (Greece)", "Norwegian (Norway,Nynorsk)", "Italian", "xx (YY)" }, + { "English (United States)", "French (France)", "Catalan (Spain)", "Greek (Greece)", "Norwegian (Norway,NY)", "Italian", "xx (YY)", "" } }; // * test macros @@ -93,7 +130,7 @@ const char* rawData[27][7] = { Example: test_compare(i=3,i,3, someNumberFormatter(i)); - test_compare(0,1+1,2,someNumberFormatter(1+1)); + test_compare(0,1+1,2,someNumberFormatter(1+1)); Note that in the second example the expression is 0, because the fcn produces it's own result. @@ -144,7 +181,7 @@ LocaleTest::LocaleTest() LocaleTest::~LocaleTest() { if (dataTable != 0) { - for (int32_t i = 0; i < 27; i++) { + for (int32_t i = 0; i < 33; i++) { delete []dataTable[i]; } delete []dataTable; @@ -152,48 +189,51 @@ LocaleTest::~LocaleTest() } } -#define CASE(id,test) case id: name = #test; if (exec) { logln(#test "---"); logln((UnicodeString)""); test(); } break; - void LocaleTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ ) { - if (exec) logln("TestSuite LocaleTest: "); switch (index) { - case 0: name = "TestBasicGetters"; if (exec) TestBasicGetters(); break; - case 1: name = "TestSimpleResourceInfo"; if (exec) TestSimpleResourceInfo(); break; - case 2: name = "TestDisplayNames"; if (exec) TestDisplayNames(); break; - case 3: name = "TestSimpleObjectStuff"; if (exec) TestSimpleObjectStuff(); break; - case 4: name = "TestPOSIXParsing"; if (exec) TestPOSIXParsing(); break; - case 5: name = "TestGetAvailableLocales"; if (exec) TestGetAvailableLocales(); break; - case 6: name = "TestDataDirectory"; if (exec) TestDataDirectory(); break; - - CASE(7, TestISO3Fallback) - CASE(8, TestGetLangsAndCountries) - CASE(9, TestSimpleDisplayNames) - CASE(10, TestUninstalledISO3Names) - CASE(11, TestAtypicalLocales) + TESTCASE(0, TestBasicGetters); + TESTCASE(1, TestSimpleResourceInfo); + TESTCASE(2, TestDisplayNames); + TESTCASE(3, TestSimpleObjectStuff); + TESTCASE(4, TestPOSIXParsing); + TESTCASE(5, TestGetAvailableLocales); + TESTCASE(6, TestDataDirectory); + TESTCASE(7, TestISO3Fallback); + TESTCASE(8, TestGetLangsAndCountries); + TESTCASE(9, TestSimpleDisplayNames); + TESTCASE(10, TestUninstalledISO3Names); + TESTCASE(11, TestAtypicalLocales); #if !UCONFIG_NO_FORMATTING - CASE(12, TestThaiCurrencyFormat) - CASE(13, TestEuroSupport) + TESTCASE(12, TestThaiCurrencyFormat); + TESTCASE(13, TestEuroSupport); #endif - CASE(14, TestToString) + TESTCASE(14, TestToString); #if !UCONFIG_NO_FORMATTING - CASE(15, Test4139940) - CASE(16, Test4143951) + TESTCASE(15, Test4139940); + TESTCASE(16, Test4143951); #endif - CASE(17, Test4147315) - CASE(18, Test4147317) - CASE(19, Test4147552) - CASE(20, TestVariantParsing) + TESTCASE(17, Test4147315); + TESTCASE(18, Test4147317); + TESTCASE(19, Test4147552); + TESTCASE(20, TestVariantParsing); #if !UCONFIG_NO_FORMATTING - CASE(21, Test4105828) + TESTCASE(21, Test4105828); #endif - CASE(22, TestSetIsBogus) - CASE(23, TestParallelAPIValues) + TESTCASE(22, TestSetIsBogus); + TESTCASE(23, TestParallelAPIValues); + TESTCASE(24, TestKeywordVariants); + TESTCASE(25, TestKeywordVariantParsing); + TESTCASE(26, TestGetBaseName); + TESTCASE(27, TestGetLocale); + TESTCASE(28, TestVariantWithOutCountry); + TESTCASE(29, TestCanonicalization); + // keep the last index in sync with the condition in default: default: - if(index <= 23) { // keep this in sync with the last index! - name = "switched off"; // UCONFIG_NO_FORMATTING + if (index <= 28) { // keep this in sync with the last index! + name = "(test omitted by !UCONFIG_NO_FORMATTING)"; } else { name = ""; } @@ -206,12 +246,21 @@ void LocaleTest::TestBasicGetters() { int32_t i; for (i = 0; i <= MAX_LOCALES; i++) { - Locale testLocale(rawData[LANG][i], rawData[CTRY][i], rawData[VAR][i]); + Locale testLocale(""); + if (rawData[SCRIPT][i] && rawData[SCRIPT][i][0] != 0) { + testLocale = Locale(rawData[LANG][i], rawData[SCRIPT][i], rawData[CTRY][i], rawData[VAR][i]); + } + else { + testLocale = Locale(rawData[LANG][i], rawData[CTRY][i], rawData[VAR][i]); + } logln("Testing " + (UnicodeString)testLocale.getName() + "..."); if ( (temp=testLocale.getLanguage()) != (dataTable[LANG][i])) errln(" Language code mismatch: " + temp + " versus " + dataTable[LANG][i]); + if ( (temp=testLocale.getScript()) != (dataTable[SCRIPT][i])) + errln(" Script code mismatch: " + temp + " versus " + + dataTable[SCRIPT][i]); if ( (temp=testLocale.getCountry()) != (dataTable[CTRY][i])) errln(" Country code mismatch: " + temp + " versus " + dataTable[CTRY][i]); @@ -225,36 +274,52 @@ void LocaleTest::TestBasicGetters() { logln("Same thing without variant codes..."); for (i = 0; i <= MAX_LOCALES; i++) { - Locale testLocale(rawData[LANG][i], rawData[CTRY][i]); + Locale testLocale(""); + if (rawData[SCRIPT][i] && rawData[SCRIPT][i][0] != 0) { + testLocale = Locale(rawData[LANG][i], rawData[SCRIPT][i], rawData[CTRY][i]); + } + else { + testLocale = Locale(rawData[LANG][i], rawData[CTRY][i]); + } logln("Testing " + (temp=testLocale.getName()) + "..."); if ( (temp=testLocale.getLanguage()) != (dataTable[LANG][i])) - errln(" Language code mismatch: " + temp + " versus " + errln("Language code mismatch: " + temp + " versus " + dataTable[LANG][i]); + if ( (temp=testLocale.getScript()) != (dataTable[SCRIPT][i])) + errln("Script code mismatch: " + temp + " versus " + + dataTable[SCRIPT][i]); if ( (temp=testLocale.getCountry()) != (dataTable[CTRY][i])) - errln(" Country code mismatch: " + temp + " versus " + errln("Country code mismatch: " + temp + " versus " + dataTable[CTRY][i]); if (testLocale.getVariant()[0] != 0) - errln(" Variant code mismatch: something versus \"\""); + errln("Variant code mismatch: something versus \"\""); } logln("Testing long language names and getters"); - Locale test8 = Locale::createFromName("x-klingon-zx.utf32be@special"); + Locale test8 = Locale::createFromName("x-klingon-latn-zx.utf32be@special"); temp = test8.getLanguage(); if (temp != UnicodeString("x-klingon") ) - errln(" Language code mismatch: " + temp + " versus \"x-klingon\""); + errln("Language code mismatch: " + temp + " versus \"x-klingon\""); + + temp = test8.getScript(); + if (temp != UnicodeString("Latn") ) + errln("Script code mismatch: " + temp + " versus \"Latn\""); temp = test8.getCountry(); if (temp != UnicodeString("ZX") ) - errln(" Country code mismatch: " + temp + " versus \"ZX\""); + errln("Country code mismatch: " + temp + " versus \"ZX\""); temp = test8.getVariant(); - if (temp != UnicodeString("SPECIAL") ) - errln(" Variant code mismatch: " + temp + " versus \"SPECIAL\""); + //if (temp != UnicodeString("SPECIAL") ) + // errln("Variant code mismatch: " + temp + " versus \"SPECIAL\""); + // As of 3.0, the "@special" will *not* be parsed by uloc_getName() + if (temp != UnicodeString("") ) + errln("Variant code mismatch: " + temp + " versus \"\""); if (Locale::getDefault() != Locale::createFromName(NULL)) - errln("Locale::getDefault() == Locale::createFromName(NULL)"); + errln("Locale::getDefault() == Locale::createFromName(NULL)"); /*----------*/ // NOTE: There used to be a special test for locale names that had language or @@ -276,6 +341,13 @@ void LocaleTest::TestBasicGetters() { ) { errln("assignment to bogus Locale does not unbogus it or sets bad data"); } + + Locale a("eo_DE@currency=DEM"); + Locale *pb=a.clone(); + if(pb==&a || *pb!=a) { + errln("Locale.clone() failed"); + } + delete pb; } void LocaleTest::TestParallelAPIValues() { @@ -349,40 +421,40 @@ void LocaleTest::TestParallelAPIValues() { void LocaleTest::TestSimpleResourceInfo() { - UnicodeString temp; - char temp2[20]; - UErrorCode err = U_ZERO_ERROR; - int32_t i = 0; - - for (i = 0; i <= MAX_LOCALES; i++) { - Locale testLocale(rawData[LANG][i], rawData[CTRY][i], rawData[VAR][i]); - logln("Testing " + (temp=testLocale.getName()) + "..."); - - if ( (temp=testLocale.getISO3Language()) != (dataTable[LANG3][i])) - errln(" ISO-3 language code mismatch: " + temp - + " versus " + dataTable[LANG3][i]); - if ( (temp=testLocale.getISO3Country()) != (dataTable[CTRY3][i])) - errln(" ISO-3 country code mismatch: " + temp - + " versus " + dataTable[CTRY3][i]); - - sprintf(temp2, "%x", testLocale.getLCID()); - if (UnicodeString(temp2) != dataTable[LCID][i]) - errln((UnicodeString)" LCID mismatch: " + temp2 + " versus " - + dataTable[LCID][i]); - - if(U_FAILURE(err)) - { - errln((UnicodeString)"Some error on number " + i + u_errorName(err)); - } - err = U_ZERO_ERROR; - } + UnicodeString temp; + char temp2[20]; + UErrorCode err = U_ZERO_ERROR; + int32_t i = 0; + + for (i = 0; i <= MAX_LOCALES; i++) { + Locale testLocale(rawData[LANG][i], rawData[CTRY][i], rawData[VAR][i]); + logln("Testing " + (temp=testLocale.getName()) + "..."); + + if ( (temp=testLocale.getISO3Language()) != (dataTable[LANG3][i])) + errln(" ISO-3 language code mismatch: " + temp + + " versus " + dataTable[LANG3][i]); + if ( (temp=testLocale.getISO3Country()) != (dataTable[CTRY3][i])) + errln(" ISO-3 country code mismatch: " + temp + + " versus " + dataTable[CTRY3][i]); + + sprintf(temp2, "%x", (int)testLocale.getLCID()); + if (UnicodeString(temp2) != dataTable[LCID][i]) + errln((UnicodeString)" LCID mismatch: " + temp2 + " versus " + + dataTable[LCID][i]); - Locale locale("en"); - if(strcmp(locale.getName(), "en") != 0|| - strcmp(locale.getLanguage(), "en") != 0) { - errln("construction of Locale(en) failed\n"); - } - /*-----*/ + if(U_FAILURE(err)) + { + errln((UnicodeString)"Some error on number " + i + u_errorName(err)); + } + err = U_ZERO_ERROR; + } + + Locale locale("en"); + if(strcmp(locale.getName(), "en") != 0|| + strcmp(locale.getLanguage(), "en") != 0) { + errln("construction of Locale(en) failed\n"); + } + /*-----*/ } @@ -392,20 +464,20 @@ void LocaleTest::TestSimpleResourceInfo() { * The lookup of display names must not fall back through the default * locale because that yields useless results. */ -void -LocaleTest::TestDisplayNames() +void +LocaleTest::TestDisplayNames() { Locale english("en", "US"); Locale french("fr", "FR"); - Locale croatian("hr", "HR"); + Locale croatian("ca", "ES"); Locale greek("el", "GR"); logln(" In locale = en_US..."); doTestDisplayNames(english, DLANG_EN); logln(" In locale = fr_FR..."); doTestDisplayNames(french, DLANG_FR); - logln(" In locale = hr_HR..."); - doTestDisplayNames(croatian, DLANG_HR); + logln(" In locale = ca_ES..."); + doTestDisplayNames(croatian, DLANG_CA); logln(" In locale = el_GR..."); doTestDisplayNames(greek, DLANG_EL); @@ -457,10 +529,10 @@ void LocaleTest::TestSimpleObjectStuff() { Locale test2("aa", "AA"); Locale test3(test1); Locale test4("zz", "ZZ"); - Locale test5("aa", "AA", ""); - Locale test6("aa", "AA", "ANTARES"); + Locale test5("aa", "AA", ""); + Locale test6("aa", "AA", "ANTARES"); Locale test7("aa", "AA", "JUPITER"); - Locale test8 = Locale::createFromName("aa-aa.utf8@jupiter"); + Locale test8 = Locale::createFromName("aa-aa-jupiTER"); // was "aa-aa.utf8@jupiter" but in 3.0 getName won't normalize that // now list them all for debugging usage. test_dumpLocale(test1); @@ -530,7 +602,7 @@ void LocaleTest::TestSimpleObjectStuff() { test_assert(!(test3 != test4)); test_assert(test1 == test4); test_assert(test4 == test1); - + // test assignments with a variant logln("test7 = test6"); test7 = test6; @@ -575,7 +647,7 @@ void LocaleTest::TestPOSIXParsing() POSIXLocale test4("ab_AB_Antares"); POSIXLocale test5(UnicodeString("ab_AB_Antares")); - Locale test6("ab", "AB", "Antares"); + Locale test6("ab", "AB", "Antares"); test_dumpLocale(test1); test_dumpLocale(test2); @@ -653,7 +725,7 @@ void LocaleTest::TestDataDirectory() logln("second fetch of language retrieved " + testValue); if (testValue != "xxx") errln("setDataDirectory() failed: expected \"xxx\", got \"" + testValue + "\""); - + Locale::setDataDirectory(oldDirectory); test.getISO3Language(testValue); logln("third fetch of language retrieved " + testValue); @@ -666,22 +738,31 @@ void LocaleTest::TestDataDirectory() void LocaleTest::doTestDisplayNames(Locale& displayLocale, int32_t compareIndex) { UnicodeString temp; - + for (int32_t i = 0; i <= MAX_LOCALES; i++) { - Locale testLocale(rawData[LANG][i], rawData[CTRY][i], rawData[VAR][i]); + Locale testLocale(""); + if (rawData[SCRIPT][i] && rawData[SCRIPT][i][0] != 0) { + testLocale = Locale(rawData[LANG][i], rawData[SCRIPT][i], rawData[CTRY][i], rawData[VAR][i]); + } + else { + testLocale = Locale(rawData[LANG][i], rawData[CTRY][i], rawData[VAR][i]); + } logln(" Testing " + (temp=testLocale.getName()) + "..."); UnicodeString testLang; + UnicodeString testScript; UnicodeString testCtry; UnicodeString testVar; UnicodeString testName; testLocale.getDisplayLanguage(displayLocale, testLang); + testLocale.getDisplayScript(displayLocale, testScript); testLocale.getDisplayCountry(displayLocale, testCtry); testLocale.getDisplayVariant(displayLocale, testVar); testLocale.getDisplayName(displayLocale, testName); UnicodeString expectedLang; + UnicodeString expectedScript; UnicodeString expectedCtry; UnicodeString expectedVar; UnicodeString expectedName; @@ -690,26 +771,32 @@ void LocaleTest::doTestDisplayNames(Locale& displayLocale, int32_t compareIndex) if (expectedLang.length() == 0) expectedLang = dataTable[DLANG_EN][i]; - expectedCtry = dataTable[compareIndex + 1][i]; + expectedScript = dataTable[compareIndex + 1][i]; + if (expectedScript.length() == 0) + expectedScript = dataTable[DSCRIPT_EN][i]; + + expectedCtry = dataTable[compareIndex + 2][i]; if (expectedCtry.length() == 0) expectedCtry = dataTable[DCTRY_EN][i]; - expectedVar = dataTable[compareIndex + 2][i]; + expectedVar = dataTable[compareIndex + 3][i]; if (expectedVar.length() == 0) expectedVar = dataTable[DVAR_EN][i]; - expectedName = dataTable[compareIndex + 3][i]; + expectedName = dataTable[compareIndex + 4][i]; if (expectedName.length() == 0) expectedName = dataTable[DNAME_EN][i]; if (testLang != expectedLang) - errln("Display language (" + UnicodeString(displayLocale.getName()) + ") got " + testLang + " expected " + expectedLang); + errln("Display language (" + UnicodeString(displayLocale.getName()) + ") of (" + UnicodeString(testLocale.getName()) + ") got " + testLang + " expected " + expectedLang); + if (testScript != expectedScript) + errln("Display script (" + UnicodeString(displayLocale.getName()) + ") of (" + UnicodeString(testLocale.getName()) + ") got " + testScript + " expected " + expectedScript); if (testCtry != expectedCtry) - errln("Display country (" + UnicodeString(displayLocale.getName()) + ") got " + testCtry + " expected " + expectedCtry); + errln("Display country (" + UnicodeString(displayLocale.getName()) + ") of (" + UnicodeString(testLocale.getName()) + ") got " + testCtry + " expected " + expectedCtry); if (testVar != expectedVar) - errln("Display variant (" + UnicodeString(displayLocale.getName()) + ") got " + testVar + " expected " + expectedVar); + errln("Display variant (" + UnicodeString(displayLocale.getName()) + ") of (" + UnicodeString(testLocale.getName()) + ") got " + testVar + " expected " + expectedVar); if (testName != expectedName) - errln("Display name (" + UnicodeString(displayLocale.getName()) + ") got " + testName + " expected " + expectedName); + errln("Display name (" + UnicodeString(displayLocale.getName()) + ") of (" + UnicodeString(testLocale.getName()) + ") got " + testName + " expected " + expectedName); } } @@ -718,25 +805,18 @@ void LocaleTest::doTestDisplayNames(Locale& displayLocale, int32_t compareIndex) //--------------------------------------------------- -UChar greekDisplayLanguage[] = { 0x03b5, 0x03bb, 0x03bb, 0x03b7, 0x03bd, 0x03b9, 0x03ba, 0x03ac, 0 }; -UChar greekDisplayCountry[] = { 0x0395, 0x03bb, 0x03bb, 0x03ac, 0x03b4, 0x03b1, 0 }; -UChar greekDisplayName[] = { 0x03b5, 0x03bb, 0x03bb, 0x03b7, 0x03bd, 0x03b9, 0x03ba, - 0x03ac, 0x20, 0x28, 0x0395, 0x03bb, 0x03bb, 0x03ac, 0x03b4, 0x03b1, 0x29, 0 }; - + void LocaleTest::setUpDataTable() { if (dataTable == 0) { - dataTable = new UnicodeString*[27]; + dataTable = new UnicodeString*[33]; - for (int32_t i = 0; i < 27; i++) { - dataTable[i] = new UnicodeString[7]; - for (int32_t j = 0; j < 7; j++) { + for (int32_t i = 0; i < 33; i++) { + dataTable[i] = new UnicodeString[8]; + for (int32_t j = 0; j < 8; j++) { dataTable[i][j] = CharsToUnicodeString(rawData[i][j]); } } - dataTable[DLANG_EL][GREEK] = greekDisplayLanguage; - dataTable[DCTRY_EL][GREEK] = greekDisplayCountry; - dataTable[DNAME_EL][GREEK] = greekDisplayName; } } @@ -746,8 +826,8 @@ void LocaleTest::setUpDataTable() /** * @bug 4011756 4011380 */ -void -LocaleTest::TestISO3Fallback() +void +LocaleTest::TestISO3Fallback() { Locale test("xx", "YY"); @@ -755,7 +835,7 @@ LocaleTest::TestISO3Fallback() result = test.getISO3Language(); - // Conform to C API usage + // Conform to C API usage if (!result || (result[0] != 0)) errln("getISO3Language() on xx_YY returned " + UnicodeString(result) + " instead of \"\""); @@ -769,8 +849,8 @@ LocaleTest::TestISO3Fallback() /** * @bug 4106155 4118587 */ -void -LocaleTest::TestGetLangsAndCountries() +void +LocaleTest::TestGetLangsAndCountries() { // It didn't seem right to just do an exhaustive test of everything here, so I check // for the following things: @@ -782,17 +862,18 @@ LocaleTest::TestGetLangsAndCountries() // 4) Is each list in sorted order? int32_t testCount = 0; const char * const * test = Locale::getISOLanguages(); - const char spotCheck1[ ][4] = { "en", "es", "fr", "de", "it", - "ja", "ko", "zh", "th", "he", + const char spotCheck1[ ][4] = { "en", "es", "fr", "de", "it", + "ja", "ko", "zh", "th", "he", "id", "iu", "ug", "yi", "za" }; int32_t i; - + for(testCount = 0;test[testCount];testCount++) ; - if (testCount != 450) - errln("Expected getISOLanguages() to return 450 languages; it returned %d", testCount); + /* TODO: Change this test to be more like the cloctst version? */ + if (testCount != 468) + errln("Expected getISOLanguages() to return 468 languages; it returned %d", testCount); else { for (i = 0; i < 15; i++) { int32_t j; @@ -815,8 +896,8 @@ LocaleTest::TestGetLangsAndCountries() } test = Locale::getISOCountries(); - UnicodeString spotCheck2 [] = { "US", "CA", "GB", "FR", "DE", - "IT", "JP", "KR", "CN", "TW", + UnicodeString spotCheck2 [] = { "US", "CA", "GB", "FR", "DE", + "IT", "JP", "KR", "CN", "TW", "TH" }; int32_t spot2Len = 11; for(testCount=0;test[testCount];testCount++) @@ -854,15 +935,15 @@ LocaleTest::TestGetLangsAndCountries() /** * @bug 4118587 */ -void -LocaleTest::TestSimpleDisplayNames() +void +LocaleTest::TestSimpleDisplayNames() { // This test is different from TestDisplayNames because TestDisplayNames checks // fallback behavior, combination of language and country names to form locale // names, and other stuff like that. This test just checks specific language // and country codes to make sure we have the correct names for them. char languageCodes[] [4] = { "he", "id", "iu", "ug", "yi", "za" }; - UnicodeString languageNames [] = { "Hebrew", "Indonesian", "Inukitut", "Uighur", "Yiddish", + UnicodeString languageNames [] = { "Hebrew", "Indonesian", "Inuktitut", "Uighur", "Yiddish", "Zhuang" }; for (int32_t i = 0; i < 6; i++) { @@ -878,14 +959,14 @@ LocaleTest::TestSimpleDisplayNames() /** * @bug 4118595 */ -void -LocaleTest::TestUninstalledISO3Names() +void +LocaleTest::TestUninstalledISO3Names() { // This test checks to make sure getISO3Language and getISO3Country work right // even for locales that are not installed. - const char iso2Languages [][4] = { "am", "ba", "fy", "mr", "rn", + const char iso2Languages [][4] = { "am", "ba", "fy", "mr", "rn", "ss", "tw", "zu" }; - const char iso3Languages [][5] = { "amh", "bak", "fry", "mar", "run", + const char iso3Languages [][5] = { "amh", "bak", "fry", "mar", "run", "ssw", "twi", "zul" }; int32_t i; @@ -901,9 +982,9 @@ LocaleTest::TestUninstalledISO3Names() iso3Languages[i] + "\", got \"" + test + "\"." + UnicodeString(u_errorName(err))); } - char iso2Countries [][4] = { "AF", "BW", "KZ", "MO", "MN", + char iso2Countries [][4] = { "AF", "BW", "KZ", "MO", "MN", "SB", "TC", "ZW" }; - char iso3Countries [][4] = { "AFG", "BWA", "KAZ", "MAC", "MNG", + char iso3Countries [][4] = { "AFG", "BWA", "KAZ", "MAC", "MNG", "SLB", "TCA", "ZWE" }; for (i = 0; i < 8; i++) { @@ -922,8 +1003,8 @@ LocaleTest::TestUninstalledISO3Names() * big locale-data reorg of 10/28/97. The lookup logic for language and country * display names was also changed at that time in that check-in. --rtg 3/20/98 */ -void -LocaleTest::TestAtypicalLocales() +void +LocaleTest::TestAtypicalLocales() { Locale localesToTest [] = { Locale("de", "CA"), Locale("ja", "ZA"), @@ -951,7 +1032,7 @@ LocaleTest::TestAtypicalLocales() "espagnol (Allemagne)", "Croatie", CharsToUnicodeString("Su\\u00E8de"), - CharsToUnicodeString("R\\u00E9publique Dominicaine"), + CharsToUnicodeString("R\\u00E9publique dominicaine"), "Belgique" }; UnicodeString spanishDisplayNames [] = { CharsToUnicodeString("alem\\u00E1n (Canad\\u00E1)"), @@ -963,16 +1044,17 @@ LocaleTest::TestAtypicalLocales() "Suecia", CharsToUnicodeString("Rep\\u00FAblica Dominicana"), CharsToUnicodeString("B\\u00E9lgica") }; - UnicodeString arabicDisplayNames [] = { "German (Canada)", - "Japanese (South Africa)", - "Russian (Mexico)", - "English (France)", - "Spanish (Germany)", - "Croatia", - "Sweden", - "Dominican Republic", - "Belgium" }; - + // De-Anglicizing root required the change from + // English display names to ISO Codes - ram 2003/09/26 + UnicodeString bengaliDisplayNames [] = { "de (CA)", + "ja (ZA)", + "ru (MX)", + "en (FR)", + "es (DE)", + "HR", + "SE", + "DO", + "BE" }; int32_t i; UErrorCode status = U_ZERO_ERROR; @@ -1009,15 +1091,15 @@ LocaleTest::TestAtypicalLocales() for (i = 0; i < 9; i++) { UnicodeString name; - localesToTest[i].getDisplayName(Locale("ar", "ES"), name); - logln(name + " Locale fallback to ar, and data fallback to root"); - if (name != arabicDisplayNames[i]) - errln("Lookup in Arabic failed: expected \"" + arabicDisplayNames[i] + localesToTest[i].getDisplayName(Locale("be", "ES"), name); + logln(name + " Locale fallback to be, and data fallback to root"); + if (name != bengaliDisplayNames[i]) + errln("Lookup in Bengali failed: expected \"" + bengaliDisplayNames[i] + "\", got \"" + name + "\""); - localesToTest[i].getDisplayName(Locale("ar", "EG"), name); + localesToTest[i].getDisplayName(Locale("be", "EG"), name); logln(name + " Data fallback to root"); - if (name != arabicDisplayNames[i]) - errln("Lookup in Arabic failed: expected \"" + arabicDisplayNames[i] + if (name != bengaliDisplayNames[i]) + errln("Lookup in Bengali failed: expected \"" + bengaliDisplayNames[i] + "\", got \"" + name + "\""); } } @@ -1029,8 +1111,8 @@ LocaleTest::TestAtypicalLocales() * This would be better tested by the LocaleDataTest. Will move it when I * get the LocaleDataTest working again. */ -void -LocaleTest::TestThaiCurrencyFormat() +void +LocaleTest::TestThaiCurrencyFormat() { UErrorCode status = U_ZERO_ERROR; DecimalFormat *thaiCurrency = (DecimalFormat*)NumberFormat::createCurrencyInstance( @@ -1064,8 +1146,8 @@ LocaleTest::TestThaiCurrencyFormat() * test must be updated. * */ -void -LocaleTest::TestEuroSupport() +void +LocaleTest::TestEuroSupport() { UChar euro = 0x20ac; const UnicodeString EURO_CURRENCY(&euro, 1, 1); // Look for this UnicodeString in formatted Euro currency @@ -1077,6 +1159,8 @@ LocaleTest::TestEuroSupport() "el_GR", "en_BE", "en_IE", + "en_GB_EURO", + "en_US_EURO", "es_ES", "eu_ES", "fi_FI", @@ -1100,24 +1184,58 @@ LocaleTest::TestEuroSupport() for (;*locales!=NULL;locales++) { Locale loc (*locales); UnicodeString temp; - NumberFormat *nf = NumberFormat::createCurrencyInstance(loc, status); - UnicodeString pos; - nf->format(271828.182845, pos); - UnicodeString neg; - nf->format(-271828.182845, neg); - if (pos.indexOf(EURO_CURRENCY) >= 0 && - neg.indexOf(EURO_CURRENCY) >= 0) { - logln("Ok: " + (temp=loc.getName()) + - ": " + pos + " / " + neg); - } - else { - errln("Fail: " + (temp=loc.getName()) + - " formats without " + EURO_CURRENCY + - ": " + pos + " / " + neg + - "\n*** THIS FAILURE MAY ONLY MEAN THAT LOCALE DATA HAS CHANGED ***"); - } - - delete nf; + NumberFormat *nf = NumberFormat::createCurrencyInstance(loc, status); + UnicodeString pos; + nf->format(271828.182845, pos); + UnicodeString neg; + nf->format(-271828.182845, neg); + if (pos.indexOf(EURO_CURRENCY) >= 0 && + neg.indexOf(EURO_CURRENCY) >= 0) { + logln("Ok: " + (temp=loc.getName()) + + ": " + pos + " / " + neg); + } + else { + errln("Fail: " + (temp=loc.getName()) + + " formats without " + EURO_CURRENCY + + ": " + pos + " / " + neg + + "\n*** THIS FAILURE MAY ONLY MEAN THAT LOCALE DATA HAS CHANGED ***"); + } + + delete nf; + } + + UnicodeString dollarStr("USD", ""), euroStr("EUR", ""), genericStr((UChar)0x00a4), resultStr; + UChar tmp[4]; + status = U_ZERO_ERROR; + + ucurr_forLocale("en_US", tmp, 4, &status); + resultStr.setTo(tmp); + if (dollarStr != resultStr) { + errln("Fail: en_US didn't return USD"); + } + ucurr_forLocale("en_US_EURO", tmp, 4, &status); + resultStr.setTo(tmp); + if (euroStr != resultStr) { + errln("Fail: en_US_EURO didn't return EUR"); + } + ucurr_forLocale("en_GB_EURO", tmp, 4, &status); + resultStr.setTo(tmp); + if (euroStr != resultStr) { + errln("Fail: en_GB_EURO didn't return EUR"); + } + ucurr_forLocale("en_US_PREEURO", tmp, 4, &status); + resultStr.setTo(tmp); + if (dollarStr != resultStr) { + errln("Fail: en_US_PREEURO didn't fallback to en_US"); + } + ucurr_forLocale("en_US_Q", tmp, 4, &status); + resultStr.setTo(tmp); + if (dollarStr != resultStr) { + errln("Fail: en_US_Q didn't fallback to en_US"); + } + int32_t invalidLen = ucurr_forLocale("en_QQ", tmp, 4, &status); + if (invalidLen || U_SUCCESS(status)) { + errln("Fail: en_QQ didn't return NULL"); } } @@ -1127,7 +1245,7 @@ LocaleTest::TestEuroSupport() * @bug 4139504 * toString() doesn't work with language_VARIANT. */ -void +void LocaleTest::TestToString() { Locale DATA [] = { Locale("xx", "", ""), @@ -1148,7 +1266,7 @@ LocaleTest::TestToString() { "_YY_ZZ", "xx_YY_ZZ", }; - + for (int32_t i=0; i < 7; ++i) { const char *name; name = DATA[i].getName(); @@ -1169,8 +1287,8 @@ LocaleTest::TestToString() { * Couldn't reproduce this bug -- probably was fixed earlier. * * ORIGINAL BUG REPORT: - * -- basically, hungarian for monday shouldn't have an \u00f4 - * (o circumflex)in it instead it should be an o with 2 inclined + * -- basically, hungarian for monday shouldn't have an \u00f4 + * (o circumflex)in it instead it should be an o with 2 inclined * (right) lines over it.. * * You may wonder -- why do all this -- why not just add a line to @@ -1180,10 +1298,10 @@ LocaleTest::TestToString() { * is that something is wrong with the font mapping subsystem, but we can't * test that here. */ -void -LocaleTest::Test4139940() +void +LocaleTest::Test4139940() { - Locale mylocale("hu", "", ""); + Locale mylocale("hu", "", ""); UDate mydate = date(98,3,13); // A Monday UErrorCode status = U_ZERO_ERROR; SimpleDateFormat df_full("EEEE", mylocale, status); @@ -1194,8 +1312,11 @@ LocaleTest::Test4139940() // o double acute (\u0151) IS. UChar ocf = 0x00f4; UChar oda = 0x0151; - if (str.indexOf(oda) < 0 || str.indexOf(ocf) >= 0) - errln("Fail: Monday in Hungarian is wrong"); + if (str.indexOf(oda) < 0 || str.indexOf(ocf) >= 0) { + errln("Fail: Monday in Hungarian is wrong - oda's index is %d and ocf's is %d", + str.indexOf(oda), str.indexOf(ocf)); + logln(UnicodeString("String is: ") + str ); + } } UDate @@ -1203,14 +1324,14 @@ LocaleTest::date(int32_t y, int32_t m, int32_t d, int32_t hr, int32_t min, int32 { UErrorCode status = U_ZERO_ERROR; Calendar *cal = Calendar::createInstance(status); - if (cal == 0) + if (cal == 0) return 0.0; cal->clear(); cal->set(1900 + y, m, d, hr, min, sec); // Add 1900 to follow java.util.Date protocol UDate dt = cal->getTime(status); if (U_FAILURE(status)) return 0.0; - + delete cal; return dt; } @@ -1219,8 +1340,8 @@ LocaleTest::date(int32_t y, int32_t m, int32_t d, int32_t hr, int32_t min, int32 * @bug 4143951 * Russian first day of week should be Monday. Confirmed. */ -void -LocaleTest::Test4143951() +void +LocaleTest::Test4143951() { UErrorCode status = U_ZERO_ERROR; Calendar *cal = Calendar::createInstance(Locale("ru", "", ""), status); @@ -1239,19 +1360,19 @@ LocaleTest::Test4143951() * java.util.Locale.getISO3Country() works wrong for non ISO-3166 codes. * Should throw an exception for unknown locales */ -void -LocaleTest::Test4147315() +void +LocaleTest::Test4147315() { UnicodeString temp; // Try with codes that are the wrong length but happen to match text // at a valid offset in the mapping table Locale locale("aaa", "CCC"); - + const char *result = locale.getISO3Country(); // Change to conform to C api usage if((result==NULL)||(result[0] != 0)) - errln("ERROR: getISO3Country() returns: " + UnicodeString(result,"") + + errln("ERROR: getISO3Country() returns: " + UnicodeString(result,"") + " for locale '" + (temp=locale.getName()) + "' rather than exception" ); } @@ -1260,52 +1381,48 @@ LocaleTest::Test4147315() * java.util.Locale.getISO3Language() works wrong for non ISO-3166 codes. * Should throw an exception for unknown locales */ -void -LocaleTest::Test4147317() +void +LocaleTest::Test4147317() { UnicodeString temp; // Try with codes that are the wrong length but happen to match text // at a valid offset in the mapping table Locale locale("aaa", "CCC"); - + const char *result = locale.getISO3Language(); // Change to conform to C api usage if((result==NULL)||(result[0] != 0)) - errln("ERROR: getISO3Language() returns: " + UnicodeString(result,"") + + errln("ERROR: getISO3Language() returns: " + UnicodeString(result,"") + " for locale '" + (temp=locale.getName()) + "' rather than exception" ); } /* * @bug 4147552 */ -void -LocaleTest::Test4147552() +void +LocaleTest::Test4147552() { - Locale locales [] = { Locale("no", "NO"), + Locale locales [] = { Locale("no", "NO"), Locale("no", "NO", "B"), - Locale("no", "NO", "NY") + Locale("no", "NO", "NY") }; - - UnicodeString edn("Norwegian (Norway, Bokm"); - edn += (UChar32)0x00e5; - edn += "l)"; - UnicodeString englishDisplayNames [] = { + + UnicodeString edn("Norwegian (Norway, B)"); + UnicodeString englishDisplayNames [] = { "Norwegian (Norway)", edn, // "Norwegian (Norway,B)", - //"Norwegian (Norway,NY)" - "Norwegian (Norway, Nynorsk)" + //"Norwegian (Norway,NY)" + "Norwegian (Norway, NY)" }; - UnicodeString ndn("norsk (Norge, Bokm"); - ndn += (UChar32)0x00e5; - ndn += "l)"; - UnicodeString norwegianDisplayNames [] = { + UnicodeString ndn("norsk (Norge, B"); + UnicodeString norwegianDisplayNames [] = { "norsk (Norge)", - //"norsk (Norge,B)", - ndn, - //"norsk (Norge,NY)" - "norsk (Noreg, Nynorsk)" + "norsk (Norge, B)", + //ndn, + "norsk (Noreg, NY)" + //"Norsk (Noreg, Nynorsk)" }; for (int32_t i = 0; i < 3; ++i) { @@ -1328,9 +1445,9 @@ LocaleTest::TestVariantParsing() UnicodeString dispName("English (United States, DE ANZA_CUPERTINO_CALIFORNIA_UNITED STATES_EARTH)"); UnicodeString dispVar("DE ANZA_CUPERTINO_CALIFORNIA_UNITED STATES_EARTH"); - + UnicodeString got; - + en_US_custom.getDisplayVariant(Locale::getUS(), got); if(got != dispVar) { errln("FAIL: getDisplayVariant()"); @@ -1347,7 +1464,7 @@ LocaleTest::TestVariantParsing() Locale shortVariant("fr", "FR", "foo"); shortVariant.getDisplayVariant(got); - + if(got != "FOO") { errln("FAIL: getDisplayVariant()"); errln("Wanted: foo"); @@ -1356,7 +1473,7 @@ LocaleTest::TestVariantParsing() Locale bogusVariant("fr", "FR", "_foo"); bogusVariant.getDisplayVariant(got); - + if(got != "FOO") { errln("FAIL: getDisplayVariant()"); errln("Wanted: foo"); @@ -1365,7 +1482,7 @@ LocaleTest::TestVariantParsing() Locale bogusVariant2("fr", "FR", "foo_"); bogusVariant2.getDisplayVariant(got); - + if(got != "FOO") { errln("FAIL: getDisplayVariant()"); errln("Wanted: foo"); @@ -1374,7 +1491,7 @@ LocaleTest::TestVariantParsing() Locale bogusVariant3("fr", "FR", "_foo_"); bogusVariant3.getDisplayVariant(got); - + if(got != "FOO") { errln("FAIL: getDisplayVariant()"); errln("Wanted: foo"); @@ -1389,8 +1506,8 @@ LocaleTest::TestVariantParsing() * Currency symbol in zh is wrong. We will test this at the NumberFormat * end to test the whole pipe. */ -void -LocaleTest::Test4105828() +void +LocaleTest::Test4105828() { Locale LOC [] = { Locale::getChinese(), Locale("zh", "CN", ""), Locale("zh", "TW", ""), Locale("zh", "HK", "") }; @@ -1418,14 +1535,569 @@ LocaleTest::Test4105828() // Jitterbug 1735 void LocaleTest::TestSetIsBogus() { - Locale l("en_US"); - l.setToBogus(); - if(l.isBogus() != TRUE) { - errln("After setting bogus, didn't return TRUE"); - } - l = "en_US"; // This should reset bogus - if(l.isBogus() != FALSE) { - errln("After resetting bogus, didn't return FALSE"); - } + Locale l("en_US"); + l.setToBogus(); + if(l.isBogus() != TRUE) { + errln("After setting bogus, didn't return TRUE"); + } + l = "en_US"; // This should reset bogus + if(l.isBogus() != FALSE) { + errln("After resetting bogus, didn't return FALSE"); + } } + +void +LocaleTest::TestKeywordVariants(void) { + struct { + const char *localeID; + const char *expectedLocaleID; + //const char *expectedLocaleIDNoKeywords; + //const char *expectedCanonicalID; + const char *expectedKeywords[10]; + int32_t numKeywords; + UErrorCode expectedStatus; + } testCases[] = { + { + "de_DE@ currency = euro; C o ll A t i o n = Phonebook ; C alen dar = buddhist ", + "de_DE@calendar=buddhist;collation=Phonebook;currency=euro", + //"de_DE", + //"de_DE@calendar=buddhist;collation=Phonebook;currency=euro", + {"calendar", "collation", "currency"}, + 3, + U_ZERO_ERROR + }, + { + "de_DE@euro", + "de_DE@euro", + //"de_DE", + //"de_DE@currency=EUR", + {"","","","","","",""}, + 0, + U_INVALID_FORMAT_ERROR /* must have '=' after '@' */ + } + }; + UErrorCode status = U_ZERO_ERROR; + + int32_t i = 0, j = 0; + const char *result = NULL; + StringEnumeration *keywords; + int32_t keyCount = 0; + const char *keyword = NULL; + const UnicodeString *keywordString; + int32_t keywordLen = 0; + + for(i = 0; i < (int32_t)(sizeof(testCases)/sizeof(testCases[0])); i++) { + status = U_ZERO_ERROR; + Locale l(testCases[i].localeID); + keywords = l.createKeywords(status); + + if(status != testCases[i].expectedStatus) { + err("Expected to get status %s. Got %s instead\n", + u_errorName(testCases[i].expectedStatus), u_errorName(status)); + } + status = U_ZERO_ERROR; + if(keywords) { + if((keyCount = keywords->count(status)) != testCases[i].numKeywords) { + err("Expected to get %i keywords, got %i\n", testCases[i].numKeywords, keyCount); + } + if(keyCount) { + for(j = 0;;) { + if((j&1)==0) { + if((keyword = keywords->next(&keywordLen, status)) == NULL) { + break; + } + if(strcmp(keyword, testCases[i].expectedKeywords[j]) != 0) { + err("Expected to get keyword value %s, got %s\n", testCases[i].expectedKeywords[j], keyword); + } + } else { + if((keywordString = keywords->snext(status)) == NULL) { + break; + } + if(*keywordString != UnicodeString(testCases[i].expectedKeywords[j], "")) { + err("Expected to get keyword UnicodeString %s, got %s\n", testCases[i].expectedKeywords[j], keyword); + } + } + j++; + + if(j == keyCount / 2) { + // replace keywords with a clone of itself + StringEnumeration *k2 = keywords->clone(); + if(k2 == NULL || keyCount != k2->count(status)) { + errln("KeywordEnumeration.clone() failed"); + } else { + delete keywords; + keywords = k2; + } + } + } + } + delete keywords; + } + result = l.getName(); + if(uprv_strcmp(testCases[i].expectedLocaleID, result) != 0) { + err("Expected to get \"%s\" from \"%s\". Got \"%s\" instead\n", + testCases[i].expectedLocaleID, testCases[i].localeID, result); + } + + } + +} + +void +LocaleTest::TestKeywordVariantParsing(void) { + struct { + const char *localeID; + const char *keyword; + const char *expectedValue; + } testCases[] = { + { "de_DE@ C o ll A t i o n = Phonebook ", "collation", "Phonebook" }, + { "de_DE", "collation", ""}, + { "de_DE@collation= PHONEBOOK", "collation", "PHONEBOOK" }, + { "de_DE@ currency = euro ; CoLLaTion = PHONEBOOk ", "collation", "PHONEBOOk" }, + }; + + UErrorCode status = U_ZERO_ERROR; + + int32_t i = 0; + int32_t resultLen = 0; + char buffer[256]; + + for(i = 0; i < (int32_t)(sizeof(testCases)/sizeof(testCases[0])); i++) { + *buffer = 0; + Locale l(testCases[i].localeID); + resultLen = l.getKeywordValue(testCases[i].keyword, buffer, 256, status); + if(uprv_strcmp(testCases[i].expectedValue, buffer) != 0) { + err("Expected to extract \"%s\" from \"%s\" for keyword \"%s\". Got \"%s\" instead\n", + testCases[i].expectedValue, testCases[i].localeID, testCases[i].keyword, buffer); + } + } +} + +void +LocaleTest::TestGetBaseName(void) { + struct { + const char *localeID; + const char *baseName; + } testCases[] = { + { "de_DE@ C o ll A t i o n = Phonebook ", "de_DE" }, + { "de@currency = euro; CoLLaTion = PHONEBOOk", "de" }, + { "ja@calendar = buddhist", "ja" } + }; + + int32_t i = 0; + + for(i = 0; i < (int32_t)(sizeof(testCases)/sizeof(testCases[0])); i++) { + Locale loc(testCases[i].localeID); + if(strcmp(testCases[i].baseName, loc.getBaseName())) { + errln("For locale \"%s\" expected baseName \"%s\", but got \"%s\"", + testCases[i].localeID, testCases[i].baseName, loc.getBaseName()); + return; + } + } +} + +/** + * Compare two locale IDs. If they are equal, return 0. If `string' + * starts with `prefix' plus an additional element, that is, string == + * prefix + '_' + x, then return 1. Otherwise return a value < 0. + */ +static UBool _loccmp(const char* string, const char* prefix) { + int32_t slen = (int32_t)strlen(string), + plen = (int32_t)strlen(prefix); + int32_t c = uprv_strncmp(string, prefix, plen); + /* 'root' is "less than" everything */ + if (uprv_strcmp(prefix, "root") == 0) { + return (uprv_strcmp(string, "root") == 0) ? 0 : 1; + } + if (c) return -1; /* mismatch */ + if (slen == plen) return 0; + if (string[plen] == '_') return 1; + return -2; /* false match, e.g. "en_USX" cmp "en_US" */ +} + +/** + * Check the relationship between requested locales, and report problems. + * The caller specifies the expected relationships between requested + * and valid (expReqValid) and between valid and actual (expValidActual). + * Possible values are: + * "gt" strictly greater than, e.g., en_US > en + * "ge" greater or equal, e.g., en >= en + * "eq" equal, e.g., en == en + */ +void LocaleTest::_checklocs(const char* label, + const char* req, + const Locale& validLoc, + const Locale& actualLoc, + const char* expReqValid, + const char* expValidActual) { + const char* valid = validLoc.getName(); + const char* actual = actualLoc.getName(); + int32_t reqValid = _loccmp(req, valid); + int32_t validActual = _loccmp(valid, actual); + if (((0 == uprv_strcmp(expReqValid, "gt") && reqValid > 0) || + (0 == uprv_strcmp(expReqValid, "ge") && reqValid >= 0) || + (0 == uprv_strcmp(expReqValid, "eq") && reqValid == 0)) && + ((0 == uprv_strcmp(expValidActual, "gt") && validActual > 0) || + (0 == uprv_strcmp(expValidActual, "ge") && validActual >= 0) || + (0 == uprv_strcmp(expValidActual, "eq") && validActual == 0))) { + logln("%s; req=%s, valid=%s, actual=%s", + label, req, valid, actual); + } else { + errln("FAIL: %s; req=%s, valid=%s, actual=%s. Require (R %s V) and (V %s A)", + label, req, valid, actual, + expReqValid, expValidActual); + } +} + +void LocaleTest::TestGetLocale(void) { +#if !UCONFIG_NO_SERVICE + UErrorCode ec = U_ZERO_ERROR; + const char *req; + Locale valid, actual, reqLoc; + + // Calendar +#if !UCONFIG_NO_FORMATTING + req = "en_US_BROOKLYN"; + Calendar* cal = Calendar::createInstance(Locale::createFromName(req), ec); + if (U_FAILURE(ec)) { + errln("FAIL: Calendar::createInstance failed"); + } else { + valid = cal->getLocale(ULOC_VALID_LOCALE, ec); + actual = cal->getLocale(ULOC_ACTUAL_LOCALE, ec); + if (U_FAILURE(ec)) { + errln("FAIL: Calendar::getLocale() failed"); + } else { + _checklocs("Calendar", req, valid, actual); + } + } + delete cal; +#endif + + // DecimalFormat, DecimalFormatSymbols +#if !UCONFIG_NO_FORMATTING + req = "fr_FR_NICE"; + DecimalFormat* dec = (DecimalFormat*) + NumberFormat::createInstance(Locale::createFromName(req), ec); + U_ASSERT(dec->getDynamicClassID() == DecimalFormat::getStaticClassID()); + if (U_FAILURE(ec)) { + errln("FAIL: NumberFormat::createInstance failed"); + } else { + valid = dec->getLocale(ULOC_VALID_LOCALE, ec); + actual = dec->getLocale(ULOC_ACTUAL_LOCALE, ec); + if (U_FAILURE(ec)) { + errln("FAIL: DecimalFormat::getLocale() failed"); + } else { + _checklocs("DecimalFormat", req, valid, actual); + } + + const DecimalFormatSymbols* sym = dec->getDecimalFormatSymbols(); + U_ASSERT(sym != 0); + valid = sym->getLocale(ULOC_VALID_LOCALE, ec); + actual = sym->getLocale(ULOC_ACTUAL_LOCALE, ec); + if (U_FAILURE(ec)) { + errln("FAIL: DecimalFormatSymbols::getLocale() failed"); + } else { + _checklocs("DecimalFormatSymbols", req, valid, actual); + } + } + delete dec; +#endif + + // DateFormat, DateFormatSymbols +#if !UCONFIG_NO_FORMATTING + req = "de_CH_LUCERNE"; + SimpleDateFormat* dat = (SimpleDateFormat*) + DateFormat::createDateInstance(DateFormat::kDefault, + Locale::createFromName(req)); + U_ASSERT(dat != 0); + U_ASSERT(dat->getDynamicClassID() == SimpleDateFormat::getStaticClassID()); + valid = dat->getLocale(ULOC_VALID_LOCALE, ec); + actual = dat->getLocale(ULOC_ACTUAL_LOCALE, ec); + if (U_FAILURE(ec)) { + errln("FAIL: SimpleDateFormat::getLocale() failed"); + } else { + _checklocs("SimpleDateFormat", req, valid, actual); + } + + const DateFormatSymbols* sym = dat->getDateFormatSymbols(); + U_ASSERT(sym != 0); + valid = sym->getLocale(ULOC_VALID_LOCALE, ec); + actual = sym->getLocale(ULOC_ACTUAL_LOCALE, ec); + if (U_FAILURE(ec)) { + errln("FAIL: DateFormatSymbols::getLocale() failed"); + } else { + _checklocs("DateFormatSymbols", req, valid, actual); + } + delete dat; +#endif + + // BreakIterator +#if !UCONFIG_NO_BREAK_ITERATION + req = "es_ES_BARCELONA"; + reqLoc = Locale::createFromName(req); + BreakIterator* brk = BreakIterator::createWordInstance(reqLoc, ec); + if (U_FAILURE(ec)) { + errln("FAIL: BreakIterator::createWordInstance failed"); + } else { + valid = brk->getLocale(ULOC_VALID_LOCALE, ec); + actual = brk->getLocale(ULOC_ACTUAL_LOCALE, ec); + if (U_FAILURE(ec)) { + errln("FAIL: BreakIterator::getLocale() failed"); + } else { + _checklocs("BreakIterator", req, valid, actual); + } + + // After registering something, the behavior should be different + URegistryKey key = BreakIterator::registerInstance(brk, reqLoc, UBRK_WORD, ec); + brk = 0; // registerInstance adopts + if (U_FAILURE(ec)) { + errln("FAIL: BreakIterator::registerInstance() failed"); + } else { + brk = BreakIterator::createWordInstance(reqLoc, ec); + if (U_FAILURE(ec)) { + errln("FAIL: BreakIterator::createWordInstance failed"); + } else { + valid = brk->getLocale(ULOC_VALID_LOCALE, ec); + actual = brk->getLocale(ULOC_ACTUAL_LOCALE, ec); + if (U_FAILURE(ec)) { + errln("FAIL: BreakIterator::getLocale() failed"); + } else { + // N.B.: now expect valid==actual==req + _checklocs("BreakIterator(registered)", + req, valid, actual, "eq", "eq"); + } + } + // No matter what, unregister + BreakIterator::unregister(key, ec); + if (U_FAILURE(ec)) { + errln("FAIL: BreakIterator::unregister() failed"); + } + delete brk; + brk = 0; + } + + // After unregistering, should behave normally again + brk = BreakIterator::createWordInstance(reqLoc, ec); + if (U_FAILURE(ec)) { + errln("FAIL: BreakIterator::createWordInstance failed"); + } else { + valid = brk->getLocale(ULOC_VALID_LOCALE, ec); + actual = brk->getLocale(ULOC_ACTUAL_LOCALE, ec); + if (U_FAILURE(ec)) { + errln("FAIL: BreakIterator::getLocale() failed"); + } else { + _checklocs("BreakIterator(unregistered)", req, valid, actual); + } + } + } + delete brk; +#endif + + // Collator +#if !UCONFIG_NO_COLLATION + req = "hi_IN_BHOPAL"; + reqLoc = Locale::createFromName(req); + Collator* coll = Collator::createInstance(reqLoc, ec); + if (U_FAILURE(ec)) { + errln("FAIL: Collator::createInstance failed"); + } else { + valid = coll->getLocale(ULOC_VALID_LOCALE, ec); + actual = coll->getLocale(ULOC_ACTUAL_LOCALE, ec); + if (U_FAILURE(ec)) { + errln("FAIL: Collator::getLocale() failed"); + } else { + _checklocs("Collator", req, valid, actual); + } + + // After registering something, the behavior should be different + URegistryKey key = Collator::registerInstance(coll, reqLoc, ec); + coll = 0; // registerInstance adopts + if (U_FAILURE(ec)) { + errln("FAIL: Collator::registerInstance() failed"); + } else { + coll = Collator::createInstance(reqLoc, ec); + if (U_FAILURE(ec)) { + errln("FAIL: Collator::createWordInstance failed"); + } else { + valid = coll->getLocale(ULOC_VALID_LOCALE, ec); + actual = coll->getLocale(ULOC_ACTUAL_LOCALE, ec); + if (U_FAILURE(ec)) { + errln("FAIL: Collator::getLocale() failed"); + } else { + // N.B.: now expect valid==actual==req + _checklocs("Collator(registered)", + req, valid, actual, "eq", "eq"); + } + } + // No matter what, unregister + Collator::unregister(key, ec); + if (U_FAILURE(ec)) { + errln("FAIL: Collator::unregister() failed"); + } + delete coll; + coll = 0; + } + + // After unregistering, should behave normally again + coll = Collator::createInstance(reqLoc, ec); + if (U_FAILURE(ec)) { + errln("FAIL: Collator::createInstance failed"); + } else { + valid = coll->getLocale(ULOC_VALID_LOCALE, ec); + actual = coll->getLocale(ULOC_ACTUAL_LOCALE, ec); + if (U_FAILURE(ec)) { + errln("FAIL: Collator::getLocale() failed"); + } else { + _checklocs("Collator(unregistered)", req, valid, actual); + } + } + } + delete coll; +#endif +#endif +} + +void LocaleTest::TestVariantWithOutCountry(void) { + Locale loc("en","","POSIX"); + if (0 != strcmp(loc.getVariant(), "POSIX")) { + errln("FAIL: en__POSIX didn't get parsed correctly"); + } + Locale loc2("en","","FOUR"); + if (0 != strcmp(loc2.getVariant(), "FOUR")) { + errln("FAIL: en__FOUR didn't get parsed correctly"); + } + Locale loc3("en","Latn","","FOUR"); + if (0 != strcmp(loc3.getVariant(), "FOUR")) { + errln("FAIL: en_Latn__FOUR didn't get parsed correctly"); + } + Locale loc4("","Latn","","FOUR"); + if (0 != strcmp(loc4.getVariant(), "FOUR")) { + errln("FAIL: _Latn__FOUR didn't get parsed correctly"); + } + Locale loc5("","Latn","US","FOUR"); + if (0 != strcmp(loc5.getVariant(), "FOUR")) { + errln("FAIL: _Latn_US_FOUR didn't get parsed correctly"); + } +} + +static Locale _canonicalize(int32_t selector, /* 0==createFromName, 1==createCanonical, 2==Locale ct */ + const char* localeID) { + switch (selector) { + case 0: + return Locale::createFromName(localeID); + case 1: + return Locale::createCanonical(localeID); + case 2: + return Locale(localeID); + default: + return Locale(""); + } +} + +void LocaleTest::TestCanonicalization(void) +{ + static struct { + const char *localeID; /* input */ + const char *getNameID; /* expected getName() result */ + const char *canonicalID; /* expected canonicalize() result */ + } testCases[] = { + { "ca_ES_PREEURO-with-extra-stuff-that really doesn't make any sense-unless-you're trying to increase code coverage", + "ca_ES_PREEURO_WITH_EXTRA_STUFF_THAT REALLY DOESN'T MAKE ANY SENSE_UNLESS_YOU'RE TRYING TO INCREASE CODE COVERAGE", + "ca_ES_PREEURO_WITH_EXTRA_STUFF_THAT REALLY DOESN'T MAKE ANY SENSE_UNLESS_YOU'RE TRYING TO INCREASE CODE COVERAGE"}, + { "ca_ES_PREEURO", "ca_ES_PREEURO", "ca_ES@currency=ESP" }, + { "de_AT_PREEURO", "de_AT_PREEURO", "de_AT@currency=ATS" }, + { "de_DE_PREEURO", "de_DE_PREEURO", "de_DE@currency=DEM" }, + { "de_LU_PREEURO", "de_LU_PREEURO", "de_LU@currency=LUF" }, + { "el_GR_PREEURO", "el_GR_PREEURO", "el_GR@currency=GRD" }, + { "en_BE_PREEURO", "en_BE_PREEURO", "en_BE@currency=BEF" }, + { "en_IE_PREEURO", "en_IE_PREEURO", "en_IE@currency=IEP" }, + { "es_ES_PREEURO", "es_ES_PREEURO", "es_ES@currency=ESP" }, + { "eu_ES_PREEURO", "eu_ES_PREEURO", "eu_ES@currency=ESP" }, + { "fi_FI_PREEURO", "fi_FI_PREEURO", "fi_FI@currency=FIM" }, + { "fr_BE_PREEURO", "fr_BE_PREEURO", "fr_BE@currency=BEF" }, + { "fr_FR_PREEURO", "fr_FR_PREEURO", "fr_FR@currency=FRF" }, + { "fr_LU_PREEURO", "fr_LU_PREEURO", "fr_LU@currency=LUF" }, + { "ga_IE_PREEURO", "ga_IE_PREEURO", "ga_IE@currency=IEP" }, + { "gl_ES_PREEURO", "gl_ES_PREEURO", "gl_ES@currency=ESP" }, + { "it_IT_PREEURO", "it_IT_PREEURO", "it_IT@currency=ITL" }, + { "nl_BE_PREEURO", "nl_BE_PREEURO", "nl_BE@currency=BEF" }, + { "nl_NL_PREEURO", "nl_NL_PREEURO", "nl_NL@currency=NLG" }, + { "pt_PT_PREEURO", "pt_PT_PREEURO", "pt_PT@currency=PTE" }, + { "de__PHONEBOOK", "de__PHONEBOOK", "de@collation=phonebook" }, + { "en_GB_EURO", "en_GB_EURO", "en_GB@currency=EUR" }, + { "en_GB@EURO", "en_GB@EURO", "en_GB@currency=EUR" }, /* POSIX ID */ + { "es__TRADITIONAL", "es__TRADITIONAL", "es@collation=traditional" }, + { "hi__DIRECT", "hi__DIRECT", "hi@collation=direct" }, + { "ja_JP_TRADITIONAL", "ja_JP_TRADITIONAL", "ja_JP@calendar=japanese" }, + { "th_TH_TRADITIONAL", "th_TH_TRADITIONAL", "th_TH@calendar=buddhist" }, + { "zh_TW_STROKE", "zh_TW_STROKE", "zh_TW@collation=stroke" }, + { "zh__PINYIN", "zh__PINYIN", "zh@collation=pinyin" }, + { "zh@collation=pinyin", "zh@collation=pinyin", "zh@collation=pinyin" }, + { "zh_CN@collation=pinyin", "zh_CN@collation=pinyin", "zh_CN@collation=pinyin" }, + { "zh_CN_CA@collation=pinyin", "zh_CN_CA@collation=pinyin", "zh_CN_CA@collation=pinyin" }, + { "en_US_POSIX", "en_US_POSIX", "en_US_POSIX" }, + { "hy_AM_REVISED", "hy_AM_REVISED", "hy_AM_REVISED" }, + { "no_NO_NY", "no_NO_NY", "no_NO_NY" /* not: "nn_NO" [alan ICU3.0] */ }, + { "no@ny", "no@ny", "no__NY" /* not: "nn" [alan ICU3.0] */ }, /* POSIX ID */ + { "no-no.utf32@B", "no_NO.utf32@B", "no_NO_B" /* not: "nb_NO_B" [alan ICU3.0] */ }, /* POSIX ID */ + { "qz-qz@Euro", "qz_QZ@Euro", "qz_QZ@currency=EUR" }, /* qz-qz uses private use iso codes */ + // NOTE: uloc_getName() works on en-BOONT, but Locale() parser considers it BOGUS + // TODO: unify this behavior + { "en-BOONT", "BOGUS", "en__BOONT" }, /* registered name */ + { "de-1901", "de_1901", "de__1901" }, /* registered name */ + { "de-1906", "de_1906", "de__1906" }, /* registered name */ + { "sr-SP-Cyrl", "sr_SP_CYRL", "sr_Cyrl_SP" }, /* .NET name */ + { "sr-SP-Latn", "sr_SP_LATN", "sr_Latn_SP" }, /* .NET name */ + { "uz-UZ-Cyrl", "uz_UZ_CYRL", "uz_Cyrl_UZ" }, /* .NET name */ + { "uz-UZ-Latn", "uz_UZ_LATN", "uz_Latn_UZ" }, /* .NET name */ + { "zh-CHS", "zh_CHS", "zh_Hans" }, /* .NET name */ + { "zh-CHT", "zh_CHT", "zh_TW" }, /* .NET name This may change back to zh_Hant */ + + /* posix behavior that used to be performed by getName */ + { "mr.utf8", "mr.utf8", "mr" }, + { "de-tv.koi8r", "de_TV.koi8r", "de_TV" }, + { "x-piglatin_ML.MBE", "x-piglatin_ML.MBE", "x-piglatin_ML" }, + { "i-cherokee_US.utf7", "i-cherokee_US.utf7", "i-cherokee_US" }, + { "x-filfli_MT_FILFLA.gb-18030", "x-filfli_MT_FILFLA.gb-18030", "x-filfli_MT_FILFLA" }, + { "no-no-ny.utf8@B", "no_NO_NY.utf8@B", "no_NO_NY_B" /* not: "nn_NO" [alan ICU3.0] */ }, /* @ ignored unless variant is empty */ + + /* fleshing out canonicalization */ + /* trim space and sort keywords, ';' is separator so not present at end in canonical form */ + { "en_Hant_IL_VALLEY_GIRL@ currency = EUR; calendar = Japanese ;", "en_Hant_IL_VALLEY_GIRL@calendar=Japanese;currency=EUR", "en_Hant_IL_VALLEY_GIRL@calendar=Japanese;currency=EUR" }, + /* already-canonical ids are not changed */ + { "en_Hant_IL_VALLEY_GIRL@calendar=Japanese;currency=EUR", "en_Hant_IL_VALLEY_GIRL@calendar=Japanese;currency=EUR", "en_Hant_IL_VALLEY_GIRL@calendar=Japanese;currency=EUR" }, + /* PRE_EURO and EURO conversions don't affect other keywords */ + { "es_ES_PREEURO@CALendar=Japanese", "es_ES_PREEURO@calendar=Japanese", "es_ES@calendar=Japanese;currency=ESP" }, + { "es_ES_EURO@SHOUT=zipeedeedoodah", "es_ES_EURO@shout=zipeedeedoodah", "es_ES@currency=EUR;shout=zipeedeedoodah" }, + /* currency keyword overrides PRE_EURO and EURO currency */ + { "es_ES_PREEURO@currency=EUR", "es_ES_PREEURO@currency=EUR", "es_ES@currency=EUR" }, + { "es_ES_EURO@currency=ESP", "es_ES_EURO@currency=ESP", "es_ES@currency=ESP" }, + /* norwegian is just too weird, if we handle things in their full generality */ + { "no-Hant-GB_NY@currency=$$$", "no_Hant_GB_NY@currency=$$$", "no_Hant_GB_NY@currency=$$$" /* not: "nn_Hant_GB@currency=$$$" [alan ICU3.0] */ }, + + /* test cases reflecting internal resource bundle usage */ + { "root@kw=foo", "root@kw=foo", "root@kw=foo" }, + { "@calendar=gregorian", "@calendar=gregorian", "@calendar=gregorian" }, + { "ja_JP@calendar=Japanese", "ja_JP@calendar=Japanese", "ja_JP@calendar=Japanese" } + }; + + static const char* label[] = { "createFromName", "createCanonical", "Locale" }; + + int32_t i, j; + + for (i=0; i < (int)(sizeof(testCases)/sizeof(testCases[0])); i++) { + for (j=0; j<3; ++j) { + const char* expected = (j==1) ? testCases[i].canonicalID : testCases[i].getNameID; + Locale loc = _canonicalize(j, testCases[i].localeID); + const char* getName = loc.isBogus() ? "BOGUS" : loc.getName(); + if(uprv_strcmp(expected, getName) != 0) { + errln("FAIL: %s(%s).getName() => \"%s\", expected \"%s\"", + label[j], testCases[i].localeID, getName, expected); + } else { + logln("Ok: %s(%s) => \"%s\"", + label[j], testCases[i].localeID, getName); + } + } + } +}