home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / test / intltest / loctest.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-19  |  47.8 KB  |  1,423 lines

  1. /*
  2. *****************************************************************************************
  3. *                                                                                       *
  4. * COPYRIGHT:                                                                            *
  5. *   (C) Copyright Taligent, Inc.,  1997                                                 *
  6. *   (C) Copyright International Business Machines Corporation,  1997-1998               *
  7. *   Licensed Material - Program-Property of IBM - All Rights Reserved.                  *
  8. *   US Government Users Restricted Rights - Use, duplication, or disclosure             *
  9. *   restricted by GSA ADP Schedule Contract with IBM Corp.                              *
  10. *                                                                                       *
  11. *****************************************************************************************
  12. */
  13.  
  14. #include "loctest.h"
  15. #include <stdio.h>
  16. #include <string.h>
  17.  
  18. #include "decimfmt.h"
  19. //#include "datefmt.h"
  20. #include "smpdtfmt.h"
  21.  
  22. // * test macros
  23. /*
  24.  Usage:
  25.     test_compare(    Function to be performed,
  26.                        Test of the function,
  27.                        expected result of the test,
  28.                        printable result
  29.                   )
  30.  
  31.    Example:
  32.        test_compare(i=3,i,3, someNumberFormatter(i));
  33.        test_compare(0,1+1,2,someNumberFormatter(1+1)); 
  34.  
  35.    Note that in the second example the expression is 0, because the fcn produces it's own result.
  36.  
  37.    Macro is ugly but makes the tests pretty.
  38. */
  39.  
  40. #define test_compare(expression,test,expected,printableResult) \
  41.     { \
  42.         expression; \
  43.         \
  44.         if((test) != (expected)) \
  45.             errln("FAIL: " + UnicodeString(#expression) + "; -> " + printableResult + "\n" + \
  46.                     "   (" + UnicodeString(#test) + " != " + UnicodeString(#expected) + ")" ); \
  47.         else \
  48.             logln(UnicodeString(#expression) + " -> " + printableResult + " (" + UnicodeString(#test) + ")"); \
  49.     }
  50.  
  51.  
  52.  
  53.  
  54. /*
  55.  Usage:
  56.     test_assert_print(    Test (should be TRUE),  printable  )
  57.  
  58.    Example:
  59.        test_assert(i==3, toString(i));
  60.  
  61.    the macro is ugly but makes the tests pretty.
  62. */
  63.  
  64. #define test_assert_print(test,print) \
  65.     { \
  66.         if(!(test)) \
  67.             errln("FAIL: " + UnicodeString(#test) + " was not true." + "-> " + UnicodeString(print) ); \
  68.         else \
  69.             logln("PASS: asserted " + UnicodeString(#test) + "-> " + UnicodeString(print)); \
  70.     }
  71.  
  72.  
  73. #define test_dumpLocale(l) { UnicodeString s; l.getName(s); logln(#l + UnicodeString(" = ") + s); }
  74.  
  75. LocaleTest::LocaleTest()
  76. {
  77.     setUpDataTable();
  78. }
  79.  
  80. LocaleTest::~LocaleTest()
  81. {
  82. }
  83.  
  84. #define CASE(id,test) case id: name = #test; if (exec) { logln(#test "---"); logln((UnicodeString)""); test(); } break;
  85.  
  86. void LocaleTest::runIndexedTest( int32_t index, bool_t exec, char* &name, char* par )
  87. {
  88.     if (exec) logln("TestSuite LocaleTest: ");
  89.     switch (index) {
  90.         case 0: name = "TestBasicGetters"; if (exec) TestBasicGetters(); break;
  91.         case 1: name = "TestSimpleResourceInfo"; if (exec) TestSimpleResourceInfo(); break;
  92.         case 2: name = "TestDisplayNames"; if (exec) TestDisplayNames(); break;
  93.         case 3: name = "TestSimpleObjectStuff"; if (exec) TestSimpleObjectStuff(); break;
  94.         case 4: name = "TestPOSIXParsing"; if (exec) TestPOSIXParsing(); break;
  95.         case 5: name = "TestGetAvailableLocales"; if (exec) TestGetAvailableLocales(); break;
  96.         case 6: name = "TestDataDirectory"; if (exec) TestDataDirectory(); break;
  97.  
  98.         CASE(7, TestISO3Fallback)
  99.         CASE(8, TestGetLangsAndCountries)
  100.         CASE(9, Test4126880)
  101.         CASE(10, TestBug4135316)
  102.         CASE(11, TestSimpleDisplayNames)
  103.         CASE(12, TestUninstalledISO3Names)
  104.         CASE(13, TestChangedISO639Codes)
  105.         CASE(14, TestAtypicalLocales)
  106.         CASE(15, TestThaiCurrencyFormat)
  107.         CASE(16, TestEuroSupport)
  108.         CASE(17, TestToString)
  109.         CASE(18, Test4139940)
  110.         CASE(19, Test4143951)
  111.         CASE(20, Test4147315)
  112.         CASE(21, Test4147317)
  113.         CASE(22, Test4147552)
  114.         CASE(23, TestVariantParsing)
  115.         CASE(24, Test4105828)
  116.  
  117.         default: name = ""; break; //needed to end loop
  118.     }
  119. }
  120.  
  121. void LocaleTest::TestBasicGetters() {
  122.     UnicodeString   temp;
  123.  
  124.     int32_t i;
  125.     for (i = 0; i <= MAX_LOCALES; i++) {
  126.         Locale testLocale(dataTable[LANG][i], dataTable[CTRY][i], dataTable[VAR][i]);
  127.         logln("Testing " + testLocale.getName(temp) + "...");
  128.  
  129.         if (testLocale.getLanguage(temp) != (dataTable[LANG][i]))
  130.             errln("  Language code mismatch: " + temp + " versus "
  131.                         + dataTable[LANG][i]);
  132.         if (testLocale.getCountry(temp) != (dataTable[CTRY][i]))
  133.             errln("  Country code mismatch: " + temp + " versus "
  134.                         + dataTable[CTRY][i]);
  135.         if (testLocale.getVariant(temp) != (dataTable[VAR][i]))
  136.             errln("  Variant code mismatch: " + temp + " versus "
  137.                         + dataTable[VAR][i]);
  138.         if (testLocale.getName(temp) != (dataTable[NAME][i]))
  139.             errln("  Locale name mismatch: " + temp + " versus "
  140.                         + dataTable[NAME][i]);
  141.     }
  142.  
  143.     logln("Same thing without variant codes...");
  144.     for (i = 0; i <= MAX_LOCALES; i++) {
  145.         Locale testLocale(dataTable[LANG][i], dataTable[CTRY][i]);
  146.         logln("Testing " + testLocale.getName(temp) + "...");
  147.  
  148.         if (testLocale.getLanguage(temp) != (dataTable[LANG][i]))
  149.             errln("  Language code mismatch: " + temp + " versus "
  150.                         + dataTable[LANG][i]);
  151.         if (testLocale.getCountry(temp) != (dataTable[CTRY][i]))
  152.             errln("  Country code mismatch: " + temp + " versus "
  153.                         + dataTable[CTRY][i]);
  154.         if (testLocale.getVariant(temp).size() != 0)
  155.             errln("  Variant code mismatch: " + temp + " versus \"\"");
  156.     }
  157.  
  158.  
  159.     // NOTE: There used to be a special test for locale names that had language or
  160.     // country codes that were longer than two letters.  The new version of Locale
  161.     // doesn't support anything that isn't an officially recognized language or
  162.     // country code, so we no longer support this feature.
  163. }
  164.  
  165. void LocaleTest::TestSimpleResourceInfo() {
  166.   UnicodeString   temp;
  167.   char            temp2[20];
  168.   
  169.   for (int32_t i = 0; i <= MAX_LOCALES; i++) {
  170.     Locale testLocale(dataTable[LANG][i], dataTable[CTRY][i], dataTable[VAR][i]);
  171.     logln("Testing " + testLocale.getName(temp) + "...");
  172.     
  173.     if (testLocale.getISO3Language(temp) != (dataTable[LANG3][i]))
  174.       errln("  ISO-3 language code mismatch: " + temp
  175.         + " versus " + dataTable[LANG3][i]);
  176.     if (testLocale.getISO3Country(temp) != (dataTable[CTRY3][i]))
  177.       errln("  ISO-3 country code mismatch: " + temp
  178.         + " versus " + dataTable[CTRY3][i]);
  179.     
  180.     sprintf(temp2, "%x", testLocale.getLCID());
  181.     if (UnicodeString(temp2) != dataTable[LCID][i])
  182.       errln((UnicodeString)"  LCID mismatch: " + (int32_t)testLocale.getLCID() + " versus "
  183.         + dataTable[LCID][i]);
  184.   }
  185. }
  186.  
  187. void 
  188. LocaleTest::TestDisplayNames() 
  189. {
  190.     Locale  saveDefault = Locale::getDefault();
  191.     Locale  empty("", "");
  192.     Locale  english("en", "US");
  193.     Locale  french("fr", "FR");
  194.     Locale  croatian("hr", "HR");
  195.     Locale  greek("el", "GR");
  196.     UErrorCode err = U_ZERO_ERROR;
  197.  
  198.     Locale::setDefault(english, err);
  199.     if (U_FAILURE(err)) {
  200.         errln("Locale::setDefault returned error code " + (int)err);
  201.         return;
  202.     }
  203.  
  204.     logln("With default = en_US...");
  205.     logln("  In default locale...");
  206.     doTestDisplayNames(empty, DLANG_EN, FALSE);
  207.     logln("  In locale = en_US...");
  208.     doTestDisplayNames(english, DLANG_EN, FALSE);
  209.     logln("  In locale = fr_FR...");
  210.     doTestDisplayNames(french, DLANG_FR, FALSE);
  211.     logln("  In locale = hr_HR...");
  212.     doTestDisplayNames(croatian, DLANG_HR, FALSE);
  213.     logln("  In locale = el_GR...");
  214.     doTestDisplayNames(greek, DLANG_EL, FALSE);
  215.  
  216.     Locale::setDefault(french, err);
  217.     if (U_FAILURE(err)) {
  218.         errln("Locale::setDefault returned error code " + (int)err);
  219.         return;
  220.     }
  221.  
  222.     logln("With default = fr_FR...");
  223.     logln("  In default locale...");
  224.     doTestDisplayNames(empty, DLANG_FR, TRUE);
  225.     logln("  In locale = en_US...");
  226.     doTestDisplayNames(english, DLANG_EN, TRUE);
  227.     logln("  In locale = fr_FR...");
  228.     doTestDisplayNames(french, DLANG_FR, TRUE);
  229.     logln("  In locale = hr_HR...");
  230.     doTestDisplayNames(croatian, DLANG_HR, TRUE);
  231.     logln("  In locale = el_GR...");
  232.     doTestDisplayNames(greek, DLANG_EL, TRUE);
  233.  
  234.     Locale::setDefault(saveDefault, err);
  235.     if (U_FAILURE(err)) {
  236.         errln("Locale::setDefault returned error code " + (int)err);
  237.         return;
  238.     }
  239. }
  240.  
  241. /*
  242.  Usage:
  243.     test_assert(    Test (should be TRUE)  )
  244.  
  245.    Example:
  246.        test_assert(i==3);
  247.  
  248.    the macro is ugly but makes the tests pretty.
  249. */
  250.  
  251. #define test_assert(test) \
  252.     { \
  253.         if(!(test)) \
  254.             errln("FAIL: " + UnicodeString(#test) + " was not true." ); \
  255.         else \
  256.             logln("PASS: asserted " + UnicodeString(#test) ); \
  257.     }
  258.  
  259. void LocaleTest::TestSimpleObjectStuff() {
  260.     Locale  test1("aa", "AA");
  261.     Locale  test2("aa", "AA");
  262.     Locale  test3(test1);
  263.     Locale  test4("zz", "ZZ");
  264.     Locale  test5("aa", "AA", ""); 
  265.     Locale  test6("aa", "AA", "Antares"); 
  266.     Locale  test7("aa", "AA", "Jupiter");
  267.  
  268.     // now list them all for debugging usage.
  269.     test_dumpLocale(test1);
  270.     test_dumpLocale(test2);
  271.     test_dumpLocale(test3);
  272.     test_dumpLocale(test4);
  273.     test_dumpLocale(test5);
  274.     test_dumpLocale(test6);
  275.     test_dumpLocale(test7)
  276.  
  277.     // Make sure things compare to themselves!
  278.     test_assert(test1 == test1);
  279.     test_assert(test2 == test2);
  280.     test_assert(test3 == test3);
  281.     test_assert(test4 == test4);
  282.     test_assert(test5 == test5);
  283.     test_assert(test6 == test6);
  284.     test_assert(test7 == test7);
  285.  
  286.     // make sure things are not equal to themselves.
  287.     test_assert(!(test1 != test1));
  288.     test_assert(!(test2 != test2));
  289.     test_assert(!(test3 != test3));
  290.     test_assert(!(test4 != test4));
  291.     test_assert(!(test5 != test5));
  292.     test_assert(!(test6 != test6));
  293.     test_assert(!(test7 != test7));
  294.  
  295.     // make sure things that are equal to each other don't show up as unequal.
  296.     test_assert(!(test1 != test2));
  297.     test_assert(!(test2 != test1));
  298.     test_assert(!(test1 != test3));
  299.     test_assert(!(test2 != test3));
  300.     test_assert(test5 == test1);
  301.     test_assert(test6 != test2);
  302.     test_assert(test6 != test5);
  303.  
  304.     test_assert(test6 != test7);
  305.  
  306.     // test for things that shouldn't compare equal.
  307.     test_assert(!(test1 == test4));
  308.     test_assert(!(test2 == test4));
  309.     test_assert(!(test3 == test4));
  310.  
  311.     // test for hash codes to be the same.
  312.     int32_t hash1 = test1.hashCode();
  313.     int32_t hash2 = test2.hashCode();
  314.     int32_t hash3 = test3.hashCode();
  315.  
  316.     test_assert(hash1 == hash2);
  317.     test_assert(hash1 == hash3);
  318.     test_assert(hash2 == hash3);
  319.  
  320.     // test that the assignment operator works.
  321.     test4 = test1;
  322.     logln("test4=test1;");
  323.     test_dumpLocale(test4);
  324.     test_assert(test4 == test4);
  325.  
  326.     test_assert(!(test1 != test4));
  327.     test_assert(!(test2 != test4));
  328.     test_assert(!(test3 != test4));
  329.     test_assert(test1 == test4);
  330.     test_assert(test4 == test1);
  331.     
  332.     // test assignments with a variant
  333.     logln("test7 = test6");
  334.     test7 = test6;
  335.     test_dumpLocale(test7);
  336.     test_assert(test7 == test7);
  337.     test_assert(test7 == test6);
  338.     test_assert(test7 != test5);
  339.  
  340.     logln("test6 = test1");
  341.     test6=test1;
  342.     test_dumpLocale(test6);
  343.     test_assert(test6 != test7);
  344.     test_assert(test6 == test1);
  345.     test_assert(test6 == test6);
  346. }
  347.  
  348. // A class which exposes constructors that are implemented in terms of the POSIX parsing code.
  349. class POSIXLocale : public Locale
  350. {
  351. public:
  352.     POSIXLocale(const UnicodeString& l)
  353.         :Locale()
  354.     {
  355.         setFromPOSIXID(l);
  356.     }
  357.     POSIXLocale(const char *l)
  358.         :Locale()
  359.     {
  360.         setFromPOSIXID(l);
  361.     }
  362. };
  363.  
  364. void LocaleTest::TestPOSIXParsing()
  365. {
  366.     POSIXLocale  test1("ab_AB");
  367.     POSIXLocale  test2(UnicodeString("ab_AB"));
  368.     Locale  test3("ab","AB");
  369.  
  370.     POSIXLocale test4("ab_AB_Antares");
  371.     POSIXLocale test5(UnicodeString("ab_AB_Antares"));
  372.     Locale  test6("ab", "AB", "Antares"); 
  373.  
  374.     test_dumpLocale(test1);
  375.     test_dumpLocale(test2);
  376.     test_dumpLocale(test3);
  377.     test_dumpLocale(test4);
  378.     test_dumpLocale(test5);
  379.     test_dumpLocale(test6);
  380.  
  381.     test_assert(test1 == test1);
  382.  
  383.     test_assert(test1 == test2);
  384.     test_assert(test2 == test3);
  385.     test_assert(test3 == test1);
  386.  
  387.     test_assert(test4 == test5);
  388.     test_assert(test5 == test6);
  389.     test_assert(test6 == test4);
  390.  
  391.     test_assert(test1 != test4);
  392.     test_assert(test5 != test3);
  393.     test_assert(test5 != test2);
  394.  
  395.     int32_t hash1 = test1.hashCode();
  396.     int32_t hash2 = test2.hashCode();
  397.     int32_t hash3 = test3.hashCode();
  398.  
  399.     test_assert(hash1 == hash2);
  400.     test_assert(hash2 == hash3);
  401.     test_assert(hash3 == hash1);
  402. }
  403.  
  404. void LocaleTest::TestGetAvailableLocales()
  405. {
  406.     int32_t locCount = 0;
  407.     const Locale* locList = Locale::getAvailableLocales(locCount);
  408.  
  409.     if (locCount == 0)
  410.         errln("getAvailableLocales() returned an empty list!");
  411.     else {
  412.         logln(UnicodeString("Number of locales returned = ") + locCount);
  413.         UnicodeString temp;
  414.         for(int32_t i = 0; i < locCount; ++i)
  415.             logln(locList[i].getName(temp));
  416.     }
  417.     // I have no idea how to test this function...
  418. }
  419.  
  420. // This test isn't applicable anymore - getISO3Language is
  421. // independent of the data directory
  422. void LocaleTest::TestDataDirectory()
  423. {
  424. /*
  425.     char            oldDirectory[80];
  426.     const char*     temp;
  427.     UErrorCode       err = U_ZERO_ERROR;
  428.     UnicodeString   testValue;
  429.  
  430.     temp = Locale::getDataDirectory();
  431.     strcpy(oldDirectory, temp);
  432.     logln(UnicodeString("oldDirectory = ") + oldDirectory);
  433.  
  434.     Locale  test(Locale::US);
  435.     test.getISO3Language(testValue);
  436.     logln("first fetch of language retrieved " + testValue);
  437.     if (testValue != "eng")
  438.         errln("Initial check of ISO3 language failed: expected \"eng\", got \"" + testValue + "\"");
  439.  
  440.     {
  441.         char *path;
  442.         path=IntlTest::getTestDirectory();
  443.         Locale::setDataDirectory( path );
  444.     }
  445.  
  446.     test.getISO3Language(testValue);
  447.     logln("second fetch of language retrieved " + testValue);
  448.     if (testValue != "xxx")
  449.         errln("setDataDirectory() failed: expected \"xxx\", got \"" + testValue + "\"");
  450.     
  451.     Locale::setDataDirectory(oldDirectory);
  452.     test.getISO3Language(testValue);
  453.     logln("third fetch of language retrieved " + testValue);
  454.     if (testValue != "eng")
  455.         errln("get/setDataDirectory() failed: expected \"eng\", got \"" + testValue + "\"");
  456. */
  457. }
  458.  
  459. //===========================================================
  460.  
  461. void LocaleTest::doTestDisplayNames(Locale& inLocale,
  462.                                     int32_t compareIndex,
  463.                                     bool_t defaultIsFrench) {
  464.     UnicodeString   temp;
  465.     
  466.     if (defaultIsFrench && Locale::getDefault().getLanguage(temp) != "fr")
  467.         errln("Default locale should be French, but it's really " + temp);
  468.     else if (!defaultIsFrench && Locale::getDefault().getLanguage(temp) != "en")
  469.         errln("Default locale should be English, but it's really " + temp);
  470.  
  471.     for (int32_t i = 0; i <= MAX_LOCALES; i++) {
  472.         Locale testLocale(dataTable[LANG][i], dataTable[CTRY][i], dataTable[VAR][i]);
  473.         logln("  Testing " + testLocale.getName(temp) + "...");
  474.  
  475.         UnicodeString  testLang;
  476.         UnicodeString  testCtry;
  477.         UnicodeString  testVar;
  478.         UnicodeString  testName;
  479.  
  480.         if (inLocale == Locale("", "", "")) {
  481.             testLocale.getDisplayLanguage(testLang);
  482.             testLocale.getDisplayCountry(testCtry);
  483.             testLocale.getDisplayVariant(testVar);
  484.             testLocale.getDisplayName(testName);
  485.         }
  486.         else {
  487.             testLocale.getDisplayLanguage(inLocale, testLang);
  488.             testLocale.getDisplayCountry(inLocale, testCtry);
  489.             testLocale.getDisplayVariant(inLocale, testVar);
  490.             testLocale.getDisplayName(inLocale, testName);
  491.         }
  492.  
  493.         UnicodeString  expectedLang;
  494.         UnicodeString  expectedCtry;
  495.         UnicodeString  expectedVar;
  496.         UnicodeString  expectedName;
  497.  
  498.         expectedLang = dataTable[compareIndex][i];
  499.         if (expectedLang.size() == 0 && defaultIsFrench)
  500.             expectedLang = dataTable[DLANG_FR][i];
  501.         if (expectedLang.size() == 0)
  502.             expectedLang = dataTable[DLANG_EN][i];
  503.  
  504.         expectedCtry = dataTable[compareIndex + 1][i];
  505.         if (expectedCtry.size() == 0 && defaultIsFrench)
  506.             expectedCtry = dataTable[DCTRY_FR][i];
  507.         if (expectedCtry.size() == 0)
  508.             expectedCtry = dataTable[DCTRY_EN][i];
  509.  
  510.         expectedVar = dataTable[compareIndex + 2][i];
  511.         if (expectedVar.size() == 0 && defaultIsFrench)
  512.             expectedVar = dataTable[DVAR_FR][i];
  513.         if (expectedVar.size() == 0)
  514.             expectedVar = dataTable[DVAR_EN][i];
  515.  
  516.         expectedName = dataTable[compareIndex + 3][i];
  517.         if (expectedName.size() == 0 && defaultIsFrench)
  518.             expectedName = dataTable[DNAME_FR][i];
  519.         if (expectedName.size() == 0)
  520.             expectedName = dataTable[DNAME_EN][i];
  521.  
  522.         if (testLang != expectedLang)
  523.             errln("Display language mismatch: " + testLang + " versus " + expectedLang);
  524.         if (testCtry != expectedCtry)
  525.             errln("Display country mismatch: " + testCtry + " versus " + expectedCtry);
  526.         if (testVar != expectedVar)
  527.             errln("Display variant mismatch: " + testVar + " versus " + expectedVar);
  528.         if (testName != expectedName)
  529.             errln("Display name mismatch: " + testName + " versus " + expectedName);
  530.     }
  531. }
  532.  
  533. //---------------------------------------------------
  534. // table of valid data
  535. //---------------------------------------------------
  536.  
  537. UnicodeString** LocaleTest::dataTable = 0;
  538.  
  539. char* rawData[27][7] = {
  540.  
  541.         // language code
  542.         {   "en",   "fr",   "hr",   "el",   "no",   "it",   "xx"    },
  543.         // country code
  544.         {   "US",   "FR",   "HR",   "GR",   "NO",   "",     "YY"    },
  545.         // variant code
  546.         {   "",     "",     "",     "",     "NY",   "",     ""    },
  547.         // full name
  548.         {   "en_US",    "fr_FR",    "hr_HR",    "el_GR",    "no_NO_NY", "it",   "xx_YY"  },
  549.         // ISO-3 language
  550.         {   "eng",  "fra",  "hrv",  "ell",  "nor",  "ita",  ""   },
  551.         // ISO-3 country
  552.         {   "USA",  "FRA",  "HRV",  "GRC",  "NOR",  "",     ""   },
  553.         // LCID (not currently public)
  554.         {   "409", "40c", "41a", "408", "814", "",     ""  },
  555.  
  556.         // display langage (English)
  557.         {   "English",  "French",   "Croatian", "Greek",    "Norwegian",    "Italian",  "xx" },
  558.         // display country (English)
  559.         {   "United States",    "France",   "Croatia",  "Greece",   "Norway",   "",     "YY" },
  560.         // display variant (English)
  561.         {   "",     "",     "",     "",     "Nynorsk",   "",     ""},
  562.         //{   "",     "",     "",     "",     "NY",   "",     ""},
  563.         // display name (English)
  564.         // Updated no_NO_NY English display name for new pattern-based algorithm
  565.         // (part of Euro support).
  566.         {   "English (United States)", "French (France)", "Croatian (Croatia)", "Greek (Greece)", "Norwegian (Norway, Nynorsk)", "Italian", "xx (YY)" },
  567.         //{   "English (United States)", "French (France)", "Croatian (Croatia)", "Greek (Greece)", "Norwegian (Norway,NY)", "Italian", "xx (YY)" },
  568.  
  569.         // display langage (French)
  570.         {   "anglais",  "français",   "", "grec",    "norvégien",    "italien", "xx" },
  571.         // display country (French)
  572.         {   "États-Unis",    "France",   "",  "Grèce",   "Norvège", "",     "YY" },
  573.         // display variant (French)
  574.         {   "",     "",     "",     "",     "Nynorsk",     "",     "" },
  575.         // display name (French)
  576.         //{   "anglais (États-Unis)", "français (France)", "", "grec (Grèce)", "norvégien (Norvège,Nynorsk)", "italien", "xx (YY)" },
  577.         {   "anglais (États-Unis)", "français (France)", "", "grec (Grèce)", "norvégien (Norvège, Nynorsk)", "italien", "xx (YY)" },
  578.  
  579.         // display langage (Croatian)
  580.         {   "",  "", "hrvatski", "",    "", "", "xx" },
  581.         // display country (Croatian)
  582.         {   "",    "",   "Hrvatska",  "",   "", "", "YY" },
  583.         // display variant (Croatian)
  584.         {   "",     "",     "",     "",     "", "", ""},
  585.         // display name (Croatian)
  586.         {   "", "", "hrvatski (Hrvatska)", "", "",  "", "xx (YY)" },
  587.  
  588.         // display langage (Greek)[actual values listed below]
  589.     {   "",  "", "", "",    "", "", "" },
  590.         // display country (Greek)[actual values listed below]
  591.     {   "",  "", "", "",    "", "", "" },
  592.         // display variant (Greek)
  593.         {   "",     "",     "",     "",     "", "", "" },
  594.         // display name (Greek)[actual values listed below]
  595.     {   "",  "", "", "",    "", "", "" },
  596.  
  597.         // display langage (<root>)
  598.         {   "English",  "French",   "Croatian", "Greek",    "Norwegian",    "Italian",  "xx" },
  599.         // display country (<root>)
  600.         {   "United States",    "France",   "Croatia",  "Greece",   "Norway",   "",     "YY" },
  601.         // display variant (<root>)
  602.         {   "",     "",     "",     "",     "Nynorsk",   "",     ""},
  603.         // display name (<root>)
  604.         //{   "English (United States)", "French (France)", "Croatian (Croatia)", "Greek (Greece)", "Norwegian (Norway,Nynorsk)", "Italian", "xx (YY)" },
  605.         {   "English (United States)", "French (France)", "Croatian (Croatia)", "Greek (Greece)", "Norwegian (Norway,NY)", "Italian", "xx (YY)" }
  606. };
  607.  
  608. UChar greekDisplayLanguage[] = { 0x03b5, 0x03bb, 0x03bb, 0x03b7, 0x03bd, 0x03b9, 0x03ba, 0x03ac, 0 };
  609. UChar greekDisplayCountry[] = { 0x0395, 0x03bb, 0x03bb, 0x03ac, 0x03b4, 0x03b1, 0 };
  610. UChar greekDisplayName[] = { 0x03b5, 0x03bb, 0x03bb, 0x03b7, 0x03bd, 0x03b9, 0x03ba,
  611.     0x03ac, ' ', '(', 0x0395, 0x03bb, 0x03bb, 0x03ac, 0x03b4, 0x03b1, ')', 0 };
  612.     
  613. void LocaleTest::setUpDataTable()
  614. {
  615.     if (dataTable == 0) {
  616.         dataTable = new UnicodeString*[27];
  617.  
  618.         for (int32_t i = 0; i < 27; i++) {
  619.             dataTable[i] = new UnicodeString[7];
  620.             for (int32_t j = 0; j < 7; j++)
  621.                 dataTable[i][j] = rawData[i][j];
  622.         }
  623.         dataTable[DLANG_EL][GREEK] = greekDisplayLanguage;
  624.         dataTable[DCTRY_EL][GREEK] = greekDisplayCountry;
  625.         dataTable[DNAME_EL][GREEK] = greekDisplayName;
  626.     }
  627. }
  628.  
  629.  
  630. // ====================
  631.  
  632.  
  633. /**
  634.  * @bug 4011756 4011380
  635.  */
  636. void 
  637. LocaleTest::TestISO3Fallback() 
  638. {
  639.     Locale test("xx", "YY");
  640.     bool_t gotException = FALSE;
  641.     UnicodeString result;
  642.     UErrorCode err = U_ZERO_ERROR;
  643.  
  644.     //try {
  645.         result = test.getISO3Language(result, err);
  646.     //}
  647.     //catch (MissingResourceException e) {
  648.         if(U_FAILURE(err))
  649.             gotException = TRUE;
  650.     //}
  651.     if (!gotException)
  652.         errln("getISO3Language() on xx_YY returned " + result + " instead of throwing an exception");
  653.  
  654.     gotException = FALSE;
  655.     err = U_ZERO_ERROR;
  656.     //try {
  657.         result = test.getISO3Country(result, err);
  658.     //}
  659.     //catch (MissingResourceException e) {
  660.         if(U_FAILURE(err))
  661.             gotException = TRUE;
  662.     //}
  663.     if (!gotException)
  664.         errln("getISO3Country() on xx_YY returned " + result + " instead of throwing an exception");
  665. }
  666.  
  667. /**
  668.  * @bug 4106155 4118587
  669.  */
  670. void 
  671. LocaleTest::TestGetLangsAndCountries() 
  672. {
  673.     // It didn't seem right to just do an exhaustive test of everything here, so I check
  674.     // for the following things:
  675.     // 1) Does each list have the right total number of entries?
  676.     // 2) Does each list contain certain language and country codes we think are important
  677.     //     (the G7 countries, plus a couple others)?
  678.     // 3) Does each list have every entry formatted correctly? (i.e., two characters,
  679.     //     all lower case for the language codes, all upper case for the country codes)
  680.     // 4) Is each list in sorted order?
  681.     int32_t testCount = 0;
  682.     const UnicodeString *test = Locale::getISOLanguages(testCount);
  683.     UnicodeString spotCheck1 [] = { "en", "es", "fr", "de", "it", 
  684.                                     "ja", "ko", "zh", "th", "he", 
  685.                                     "id", "iu", "ug", "yi", "za" };
  686.     int32_t spotLen = 15;
  687.  
  688.     int32_t i;
  689.  
  690.     if (testCount != 142)
  691.         errln("Expected getISOLanguages() to return 142 languages; it returned" + testCount);
  692.     else {
  693.         for (i = 0; i < 15; i++) {
  694.             int32_t j;
  695.             for (j = 0; j < testCount; j++)
  696.                 if (test[j] == spotCheck1[i])
  697.                     break;
  698.             if (j == testCount || test[j] != spotCheck1[i])
  699.                 errln("Couldn't find " + spotCheck1[i] + " in language list.");
  700.         }
  701.     }
  702.     for (i = 0; i < testCount; i++) {
  703.         UnicodeString lc(test[i]);
  704.         if (test[i] != lc.toLower())
  705.             errln(test[i] + " is not all lower case.");
  706.         if (test[i].size() != 2)
  707.             errln(test[i] + " is not two characters long.");
  708.         if (i > 0 && test[i].compare(test[i - 1]) <= 0)
  709.             errln(test[i] + " appears in an out-of-order position in the list.");
  710.     }
  711.  
  712.     test = Locale::getISOCountries(testCount);
  713.     UnicodeString spotCheck2 [] = { "US", "CA", "GB", "FR", "DE", 
  714.                                     "IT", "JP", "KR", "CN", "TW", 
  715.                                     "TH" };
  716.     int32_t spot2Len = 11;
  717.  
  718.  
  719.     if (testCount != 239)
  720.         errln("Expected getISOLanguages to return 238 languages; it returned" + testCount);
  721.     else {
  722.         for (i = 0; i < spot2Len; i++) {
  723.             int32_t j;
  724.             for (j = 0; j < testCount; j++)
  725.                 if (test[j] == spotCheck2[i])
  726.                     break;
  727.             if (j == testCount || test[j] != spotCheck2[i])
  728.                 errln("Couldn't find " + spotCheck2[i] + " in country list.");
  729.         }
  730.     }
  731.     for (i = 0; i < testCount; i++) {
  732.         UnicodeString uc(test[i]);
  733.         if (test[i] != uc.toUpper())
  734.             errln(test[i] + " is not all upper case.");
  735.         if (test[i].size() != 2)
  736.             errln(test[i] + " is not two characters long.");
  737.         if (i > 0 && test[i].compare(test[i - 1]) <= 0)
  738.             errln(test[i] + " appears in an out-of-order position in the list.");
  739.     }
  740. }
  741.  
  742. /**
  743.  * @bug 4126880
  744.  */
  745. // since this returns const UnicodeString* in C++, is this test applicable?
  746. void 
  747. LocaleTest::Test4126880() 
  748. {
  749.     /*
  750.     const UnicodeString *test;
  751.     int32_t testCount;
  752.  
  753.     test = Locale::getISOCountries(testCount);
  754.     test[0] = "SUCKER!!!";
  755.     test = Locale::getISOCountries(testCount);
  756.     if (test[0] == "SUCKER!!!")
  757.         errln("Changed internal country code list!");
  758.  
  759.     test = Locale::getISOLanguages(testCount);
  760.     test[0] = "HAHAHAHA!!!";
  761.     test = Locale::getISOLanguages(testCount);
  762.     if (test[0] == "HAHAHAHA!!!") // Fixed typo
  763.         errln("Changes internal language code list!");
  764. */
  765. }
  766.  
  767. /**
  768.  * @bug 4135316
  769.  */
  770. // not applicable in C++ - const Locale*
  771. void 
  772. LocaleTest::TestBug4135316() 
  773. {
  774. /*
  775.     Locale[] locales1 = Locale.getAvailableLocales();
  776.     Locale[] locales2 = Locale.getAvailableLocales();
  777.     if (locales1 == locales2)
  778.         errln("Locale.getAvailableLocales() doesn't clone its internal storage!");
  779. */
  780. }
  781.  
  782. /**
  783.  * @bug 4107953
  784.  */
  785. /*
  786. test commented out pending API-change approval
  787. public void TestGetLanguagesForCountry() {
  788.     UnicodeString[] languages = Locale.getLanguagesForCountry("US");
  789.  
  790.     if (!searchStringArrayFor("en", languages))
  791.         errln("Didn't get en as a language for US");
  792.  
  793.     languages = Locale.getLanguagesForCountry("FR");
  794.     if (!searchStringArrayFor("fr", languages))
  795.         errln("Didn't get fr as a language for FR");
  796.  
  797.     languages = Locale.getLanguagesForCountry("CH");
  798.     if (!searchStringArrayFor("fr", languages))
  799.         errln("Didn't get fr as a language for CH");
  800.     if (!searchStringArrayFor("it", languages))
  801.         errln("Didn't get it as a language for CH");
  802.     if (!searchStringArrayFor("de", languages))
  803.         errln("Didn't get de as a language for CH");
  804.  
  805.     languages = Locale.getLanguagesForCountry("JP");
  806.     if (!searchStringArrayFor("ja", languages))
  807.         errln("Didn't get ja as a language for JP");
  808. }
  809. */
  810.  
  811. /*
  812. private bool_t searchStringArrayFor(UnicodeString s, UnicodeString[] array) {
  813.     for (int32_t i = 0; i < array.length; i++)
  814.         if (s.equals(array[i]))
  815.             return TRUE;
  816.     return FALSE;
  817. }
  818. */
  819.  
  820. /**
  821.  * @bug 4110613
  822.  */
  823. // not applicable in C++
  824.  /*
  825. void 
  826. LocaleTest::TestSerialization() throws ClassNotFoundException, OptionalDataException,
  827.                 IOException, StreamCorruptedException
  828. {
  829.     ObjectOutputStream ostream;
  830.     ByteArrayOutputStream obstream;
  831.     byte[] bytes = null;
  832.  
  833.     obstream = new ByteArrayOutputStream();
  834.     ostream = new ObjectOutputStream(obstream);
  835.  
  836.     Locale test1 = new Locale("zh", "TW", "");
  837.     int32_t dummy = test1.hashCode();   // fill in the cached hash-code value
  838.     ostream.writeObject(test1);
  839.  
  840.     bytes = obstream.toByteArray();
  841.  
  842.     ObjectInputStream istream = new ObjectInputStream(new ByteArrayInputStream(bytes));
  843.  
  844.     Locale test2 = (Locale)(istream.readObject());
  845.  
  846.     if (!test1.equals(test2) || test1.hashCode() != test2.hashCode())
  847.         errln("Locale failed to deserialize correctly.");
  848. }
  849. */
  850.  
  851. /**
  852.  * @bug 4118587
  853.  */
  854. void 
  855. LocaleTest::TestSimpleDisplayNames() 
  856. {
  857.     // This test is different from TestDisplayNames because TestDisplayNames checks
  858.     // fallback behavior, combination of language and country names to form locale
  859.     // names, and other stuff like that.  This test just checks specific language
  860.     // and country codes to make sure we have the correct names for them.
  861.     UnicodeString languageCodes [] = { "he", "id", "iu", "ug", "yi", "za" };
  862.     UnicodeString languageNames [] = { "Hebrew", "Indonesian", "Inukitut", "Uighur", "Yiddish",
  863.                                "Zhuang" };
  864.  
  865.     for (int32_t i = 0; i < 6; i++) {
  866.         UnicodeString test;
  867.         Locale l(languageCodes[i], "", "");
  868.         l.getDisplayLanguage(Locale::US, test);
  869.         if (test != languageNames[i])
  870.             errln("Got wrong display name for " + languageCodes[i] + ": Expected \"" +
  871.                   languageNames[i] + "\", got \"" + test + "\".");
  872.     }
  873. }
  874.  
  875. /**
  876.  * @bug 4118595
  877.  */
  878. void 
  879. LocaleTest::TestUninstalledISO3Names() 
  880. {
  881.     // This test checks to make sure getISO3Language and getISO3Country work right
  882.     // even for locales that are not installed.
  883.     UnicodeString iso2Languages [] = {     "am", "ba", "fy", "mr", "rn", 
  884.                                         "ss", "tw", "zu" };
  885.     UnicodeString iso3Languages [] = {     "amh", "bak", "fry", "mar", "run", 
  886.                                         "ssw", "twi", "zul" };
  887.  
  888.     int32_t i;
  889.  
  890.     for (i = 0; i < 8; i++) {
  891.         UnicodeString test;
  892.         Locale l(iso2Languages[i], "", "");
  893.         l.getISO3Language(test);
  894.         if(test != iso3Languages[i])
  895.             errln("Got wrong ISO3 code for " + iso2Languages[i] + ": Expected \"" +
  896.                     iso3Languages[i] + "\", got \"" + test + "\".");
  897.     }
  898.  
  899.     UnicodeString iso2Countries [] = {     "AF", "BW", "KZ", "MO", "MN", 
  900.                                         "SB", "TC", "ZW" };
  901.     UnicodeString iso3Countries [] = {     "AFG", "BWA", "KAZ", "MAC", "MNG", 
  902.                                         "SLB", "TCA", "ZWE" };
  903.  
  904.     for (i = 0; i < 8; i++) {
  905.         UnicodeString test;
  906.         Locale l("", iso2Countries[i], "");
  907.         l.getISO3Country(test);
  908.         if (test != iso3Countries[i])
  909.             errln("Got wrong ISO3 code for " + iso2Countries[i] + ": Expected \"" +
  910.                     iso3Countries[i] + "\", got \"" + test + "\".");
  911.     }
  912. }
  913.  
  914. /**
  915.  * @bug 4052404
  916.  */
  917. void 
  918. LocaleTest::TestChangedISO639Codes() 
  919. {
  920.     Locale hebrewOld("iw", "IL", "");
  921.     Locale hebrewNew("he", "IL", "");
  922.     Locale yiddishOld("ji", "IL", "");
  923.     Locale yiddishNew("yi", "IL", "");
  924.     Locale indonesianOld("in", "", "");
  925.     Locale indonesianNew("id", "", "");
  926.  
  927.     UnicodeString temp;
  928.  
  929.     if (hebrewNew.getLanguage(temp) != "iw")
  930.         errln("Got back wrong language code for Hebrew: expected \"iw\", got \"" +
  931.                         hebrewNew.getLanguage(temp) + "\"");
  932.     if (yiddishNew.getLanguage(temp) != "ji")
  933.         errln("Got back wrong language code for Yiddish: expected \"ji\", got \"" +
  934.                         yiddishNew.getLanguage(temp) + "\"");
  935.     if (indonesianNew.getLanguage(temp) != "in")
  936.         errln("Got back wrong language code for Indonesian: expected \"in\", got \"" +
  937.                         indonesianNew.getLanguage(temp) + "\"");
  938.  
  939.     if (hebrewOld != hebrewNew)
  940.         errln("Old and new Hebrew locales don't compare equal.");
  941.     if (yiddishOld != yiddishNew)
  942.         errln("Old and new Yiddish locales don't compare equal.");
  943.     if (indonesianOld != indonesianNew)
  944.         errln("Old and new Indonesian locales don't compare equal.");
  945. }
  946.  
  947. /**
  948.  * @bug 4092475
  949.  * I could not reproduce this bug.  I'm pretty convinced it was fixed with the
  950.  * big locale-data reorg of 10/28/97.  The lookup logic for language and country
  951.  * display names was also changed at that time in that check-in.    --rtg 3/20/98
  952.  */
  953. void 
  954. LocaleTest::TestAtypicalLocales() 
  955. {
  956.     Locale localesToTest [] = { Locale("de", "CA"),
  957.                                   Locale("ja", "ZA"),
  958.                                    Locale("ru", "MX"),
  959.                                    Locale("en", "FR"),
  960.                                    Locale("es", "DE"),
  961.                                    Locale("", "HR"),
  962.                                    Locale("", "SE"),
  963.                                    Locale("", "DO"),
  964.                                    Locale("", "BE") };
  965.  
  966.     UnicodeString englishDisplayNames [] = { "German (Canada)",
  967.                                      "Japanese (South Africa)",
  968.                                      "Russian (Mexico)",
  969.                                      "English (France)",
  970.                                      "Spanish (Germany)",
  971.                                      "Croatia",
  972.                                      "Sweden",
  973.                                      "Dominican Republic",
  974.                                      "Belgium" };
  975.     UnicodeString frenchDisplayNames []= { "allemand (Canada)",
  976.                                     "japonais (South Africa)",
  977.                                     "Russian (Mexico)",
  978.                                      "anglais (France)",
  979.                                      "espagnol (Allemagne)",
  980.                                     "Croatia",
  981.                                     "Suède",
  982.                                     "Dominican Republic",
  983.                                     "Belgique" };
  984.     UnicodeString rus("Russian (M");
  985.     rus += 0x00e9;
  986.     rus += "xico)";
  987.  
  988.     UnicodeString esp("espa");
  989.     esp += 0x00f1;
  990.     esp += "ol (Germany)";
  991.  
  992.     UnicodeString dr("Rep");
  993.     dr += 0x00fa;
  994.     dr += "blica Dominicana";
  995.  
  996.     UnicodeString spanishDisplayNames [] = { "German (Canada)",
  997.                                      "Japanese (South Africa)",
  998.                                      rus,
  999.                                      "English (France)",
  1000.                                      esp,
  1001.                                      "Croatia",
  1002.                                      "Sweden",
  1003.                                      dr,
  1004.                                      "Belgium" };
  1005.  
  1006.     int32_t i;
  1007.     UErrorCode status = U_ZERO_ERROR;
  1008.     Locale::setDefault(Locale::US, status);
  1009.     for (i = 0; i < 9; ++i) {
  1010.         UnicodeString name;
  1011.         localesToTest[i].getDisplayName(Locale::US, name);
  1012.         logln(name);
  1013.         if (name != englishDisplayNames[i])
  1014.         {
  1015.             errln("Lookup in English failed: expected \"" + englishDisplayNames[i]
  1016.                         + "\", got \"" + name + "\"");
  1017.             logln("Locale name was-> " + localesToTest[i].getName(name));
  1018.         }
  1019.     }
  1020.  
  1021.     for (i = 0; i < 9; i++) {
  1022.         UnicodeString name;
  1023.         localesToTest[i].getDisplayName(Locale("es", "ES"), name);
  1024.         logln(name);
  1025.         if (name != spanishDisplayNames[i])
  1026.             errln("Lookup in Spanish failed: expected \"" + spanishDisplayNames[i]
  1027.                         + "\", got \"" + name + "\"");
  1028.     }
  1029.  
  1030.     for (i = 0; i < 9; i++) {
  1031.         UnicodeString name;
  1032.         localesToTest[i].getDisplayName(Locale::FRANCE, name);
  1033.         logln(name);
  1034.         if (name != frenchDisplayNames[i])
  1035.             errln("Lookup in French failed: expected \"" + frenchDisplayNames[i]
  1036.                         + "\", got \"" + name + "\"");
  1037.     }
  1038. }
  1039.  
  1040. /**
  1041.  * @bug 4126371
  1042.  */
  1043. // not applicable in C++, setDefault() takes a reference
  1044. void 
  1045. LocaleTest::TestNullDefault() 
  1046. {
  1047. /*
  1048.     // why on earth anyone would ever try to do this is beyond me, but we should
  1049.     // definitely make sure we don't let them
  1050.     bool_t gotException = FALSE;
  1051.     try {
  1052.         Locale.setDefault(null);
  1053.     }
  1054.     catch (NullPointerException e) {
  1055.         // all other exception types propagate through here back to the test harness
  1056.         gotException = TRUE;
  1057.     }
  1058.     if (Locale.getDefault() == null)
  1059.         errln("Locale.getDefault() allowed us to set default to NULL!");
  1060.     if (!gotException)
  1061.         errln("Trying to set default locale to NULL didn't throw exception!");
  1062. */
  1063. }
  1064.  
  1065. /**
  1066.  * @bug 4135752
  1067.  * This would be better tested by the LocaleDataTest.  Will move it when I
  1068.  * get the LocaleDataTest working again.
  1069.  */
  1070. void 
  1071. LocaleTest::TestThaiCurrencyFormat() 
  1072. {
  1073.     UErrorCode status = U_ZERO_ERROR;
  1074.     DecimalFormat *thaiCurrency = (DecimalFormat*)NumberFormat::createCurrencyInstance(
  1075.                     Locale("th", "TH"), status);
  1076.     UChar posPrefix = 0x0e3f;
  1077.     UnicodeString temp;
  1078.     if (thaiCurrency->getPositivePrefix(temp) != UnicodeString(&posPrefix, 1, 1))
  1079.         errln("Thai currency prefix wrong: expected 0x0e3f, got \"" +
  1080.                         thaiCurrency->getPositivePrefix(temp) + "\"");
  1081.     if (thaiCurrency->getPositiveSuffix(temp) != "")
  1082.         errln("Thai currency suffix wrong: expected \"\", got \"" +
  1083.                         thaiCurrency->getPositiveSuffix(temp) + "\"");
  1084.  
  1085.     delete thaiCurrency;
  1086. }
  1087.  
  1088. /**
  1089.  * @bug 4122371
  1090.  * Confirm that Euro support works.  This test is pretty rudimentary; all it does
  1091.  * is check that any locales with the EURO variant format a number using the
  1092.  * Euro currency symbol.
  1093.  *
  1094.  * ASSUME: All locales encode the Euro character "\u20AC".
  1095.  * If this is changed to use the single-character Euro symbol, this
  1096.  * test must be updated.
  1097.  *
  1098.  * DON'T ASSUME: Any specific countries support the Euro.  Instead,
  1099.  * iterate through all locales.
  1100.  */
  1101. void 
  1102. LocaleTest::TestEuroSupport() 
  1103. {
  1104.     const UnicodeString EURO_VARIANT("EURO");
  1105.     UChar euro = 0x20ac;
  1106.     const UnicodeString EURO_CURRENCY(&euro, 1, 1); // Look for this UnicodeString in formatted Euro currency
  1107.  
  1108.     UErrorCode status = U_ZERO_ERROR;
  1109.  
  1110.     UnicodeString temp;
  1111.  
  1112.     int32_t locCount = 0;
  1113.     const Locale *locales = NumberFormat::getAvailableLocales(locCount);      
  1114.     for (int32_t i=0; i < locCount; ++i) {
  1115.         Locale loc = locales[i];
  1116.         UnicodeString temp;
  1117.         if (loc.getVariant(temp).indexOf(EURO_VARIANT) >= 0) {
  1118.             NumberFormat *nf = NumberFormat::createCurrencyInstance(loc, status);
  1119.             UnicodeString pos;
  1120.             nf->format(271828.182845, pos);
  1121.             UnicodeString neg;
  1122.             nf->format(-271828.182845, neg);
  1123.             if (pos.indexOf(EURO_CURRENCY) >= 0 &&
  1124.                 neg.indexOf(EURO_CURRENCY) >= 0) {
  1125.                 logln("Ok: " + loc.getName(temp) +
  1126.                       ": " + pos + " / " + neg);
  1127.             }
  1128.             else {
  1129.                 errln("Fail: " + loc.getName(temp) +
  1130.                       " formats without " + EURO_CURRENCY +
  1131.                       ": " + pos + " / " + neg +
  1132.                       "\n*** THIS FAILURE MAY ONLY MEAN THAT LOCALE DATA HAS CHANGED ***");
  1133.             }
  1134.         
  1135.             delete nf;
  1136.         }
  1137.     }
  1138. }
  1139.  
  1140. /**
  1141.  * @bug 4139504
  1142.  * toString() doesn't work with language_VARIANT.
  1143.  */
  1144. void 
  1145. LocaleTest::TestToString() {
  1146.     Locale DATA [] = {
  1147.         Locale("xx", "", ""),
  1148.         Locale("", "YY", ""),
  1149.         Locale("", "", "ZZ"),
  1150.         Locale("xx", "YY", ""),
  1151.         Locale("xx", "", "ZZ"),
  1152.         Locale("", "YY", "ZZ"),
  1153.         Locale("xx", "YY", "ZZ"),
  1154.     };
  1155.  
  1156.     UnicodeString DATA_S [] = {
  1157.         "xx",
  1158.         "_YY",
  1159.         "__ZZ",
  1160.         "xx_YY",
  1161.         "xx__ZZ",
  1162.         "_YY_ZZ",
  1163.         "xx_YY_ZZ",
  1164.     };
  1165.     
  1166.     for (int32_t i=0; i < 7; ++i) {
  1167.         UnicodeString name;
  1168.         if (DATA[i].getName(name) != DATA_S[i]) {
  1169.             errln("Fail: Locale.getName(), got:" + name + ", expected: " + DATA_S[i]);
  1170.         }
  1171.         else
  1172.             logln("Pass: Locale.getName(), got:" + name );
  1173.     }
  1174. }
  1175.  
  1176. /**
  1177.  * @bug 4139940
  1178.  * Couldn't reproduce this bug -- probably was fixed earlier.
  1179.  *
  1180.  * ORIGINAL BUG REPORT:
  1181.  * -- basically, hungarian for monday shouldn't have an \u00f4 
  1182.  * (o circumflex)in it instead it should be an o with 2 inclined 
  1183.  * (right) lines over it..
  1184.  *
  1185.  * You may wonder -- why do all this -- why not just add a line to
  1186.  * LocaleData?  Well, I could see by inspection that the locale file had the
  1187.  * right character in it, so I wanted to check the rest of the pipeline -- a
  1188.  * very remote possibility, but I wanted to be sure.  The other possibility
  1189.  * is that something is wrong with the font mapping subsystem, but we can't
  1190.  * test that here.
  1191.  */
  1192. void 
  1193. LocaleTest::Test4139940() 
  1194. {
  1195.     Locale mylocale("hu", "", "");       
  1196.     UDate mydate = date(98,3,13); // A Monday
  1197.     UErrorCode status = U_ZERO_ERROR;
  1198.     SimpleDateFormat df_full("EEEE", mylocale, status);
  1199.     UnicodeString str;
  1200.     FieldPosition pos(FieldPosition::DONT_CARE);
  1201.     df_full.format(mydate, str, pos);
  1202.     // Make sure that o circumflex (\u00F4) is NOT there, and
  1203.     // o double acute (\u0151) IS.
  1204.     UChar ocf = 0x00f4;
  1205.     UChar oda = 0x0151;
  1206.     if (str.indexOf(oda) < 0 || str.indexOf(ocf) >= 0)
  1207.         errln("Fail: Monday in Hungarian is wrong");
  1208. }
  1209.  
  1210. UDate
  1211. LocaleTest::date(int32_t y, int32_t m, int32_t d, int32_t hr, int32_t min, int32_t sec)
  1212. {
  1213.     UErrorCode status = U_ZERO_ERROR;
  1214.     Calendar *cal = Calendar::createInstance(status);
  1215.     if (cal == 0) 
  1216.         return 0.0;
  1217.     cal->clear();
  1218.     cal->set(1900 + y, m, d, hr, min, sec); // Add 1900 to follow java.util.Date protocol
  1219.     UDate dt = cal->getTime(status);
  1220.     if (U_FAILURE(status))
  1221.         return 0.0;
  1222.     
  1223.     delete cal;
  1224.     return dt;
  1225. }
  1226.  
  1227. /**
  1228.  * @bug 4143951
  1229.  * Russian first day of week should be Monday. Confirmed.
  1230.  */
  1231. void 
  1232. LocaleTest::Test4143951() 
  1233. {
  1234.     UErrorCode status = U_ZERO_ERROR;
  1235.     Calendar *cal = Calendar::createInstance(Locale("ru", "", ""), status);
  1236.     if (cal->getFirstDayOfWeek() != Calendar::MONDAY) {
  1237.         errln("Fail: First day of week in Russia should be Monday");
  1238.     }
  1239.     delete cal;
  1240. }
  1241.  
  1242. /**
  1243.  * @bug 4147315
  1244.  * java.util.Locale.getISO3Country() works wrong for non ISO-3166 codes.
  1245.  * Should throw an exception for unknown locales
  1246.  */
  1247. void 
  1248. LocaleTest::Test4147315() 
  1249. {
  1250.     // Try with codes that are the wrong length but happen to match text
  1251.     // at a valid offset in the mapping table
  1252.     Locale locale("aaa", "CCC");
  1253.     
  1254.     //try {
  1255.         UnicodeString result;
  1256.         UErrorCode err = U_ZERO_ERROR;
  1257.         locale.getISO3Country(result, err);
  1258.  
  1259.         UnicodeString temp;
  1260.         if(U_SUCCESS(err))
  1261.             errln("ERROR: getISO3Country() returns: " + result + 
  1262.                 " for locale '" + locale.getName(temp) + "' rather than exception" );
  1263.     //} catch(MissingResourceException e) { }
  1264. }
  1265.  
  1266. /**
  1267.  * @bug 4147317
  1268.  * java.util.Locale.getISO3Language() works wrong for non ISO-3166 codes.
  1269.  * Should throw an exception for unknown locales
  1270.  */
  1271. void 
  1272. LocaleTest::Test4147317() 
  1273. {
  1274.     // Try with codes that are the wrong length but happen to match text
  1275.     // at a valid offset in the mapping table
  1276.     Locale locale("aaa", "CCC");
  1277.     
  1278.     //try {
  1279.         UnicodeString result;
  1280.         UErrorCode err = U_ZERO_ERROR;
  1281.         locale.getISO3Language(result, err);
  1282.  
  1283.         UnicodeString temp;
  1284.         if(U_SUCCESS(err))
  1285.             errln("ERROR: getISO3Language() returns: " + result + 
  1286.                " for locale '" + locale.getName(temp) + "' rather than exception" );
  1287.     //} catch(MissingResourceException e) { }
  1288. }
  1289.  
  1290. /*
  1291.  * @bug 4147552
  1292.  */
  1293. void 
  1294. LocaleTest::Test4147552() 
  1295. {
  1296.     Locale locales [] = {     Locale("no", "NO"), 
  1297.                             Locale("no", "NO", "B"),
  1298.                              Locale("no", "NO", "NY") 
  1299.     };
  1300.     
  1301.     UnicodeString edn("Norwegian (Norway, Bokm");
  1302.     edn += 0x00e5;
  1303.     edn += "l)";
  1304.     UnicodeString englishDisplayNames [] = { 
  1305.                                                 "Norwegian (Norway)",
  1306.                                                  edn,
  1307.                                                  // "Norwegian (Norway,B)",
  1308.                                                  //"Norwegian (Norway,NY)" 
  1309.                                                  "Norwegian (Norway, Nynorsk)" 
  1310.     };
  1311.     UnicodeString ndn("norsk (Norge, Bokm");
  1312.     ndn += 0x00e5;
  1313.     ndn += "l)";
  1314.     UnicodeString norwegianDisplayNames [] = { 
  1315.                                                 "norsk (Norge)",
  1316.                                                 //"norsk (Norge,B)", 
  1317.                                                 ndn, 
  1318.                                                  //"norsk (Norge,NY)" 
  1319.                                                  "norsk (Norge, Nynorsk)" 
  1320.     };
  1321.  
  1322.     for (int32_t i = 0; i < 3; ++i) {
  1323.         Locale loc = locales[i];
  1324.         UnicodeString temp;
  1325.         if (loc.getDisplayName(temp) != englishDisplayNames[i])
  1326.            errln("English display-name mismatch: expected " +
  1327.                    englishDisplayNames[i] + ", got " + loc.getDisplayName(temp));
  1328.         if (loc.getDisplayName(loc, temp) != norwegianDisplayNames[i])
  1329.             errln("Norwegian display-name mismatch: expected " +
  1330.                    norwegianDisplayNames[i] + ", got " +
  1331.                    loc.getDisplayName(loc, temp));
  1332.     }
  1333. }
  1334.  
  1335. void
  1336. LocaleTest::TestVariantParsing()
  1337. {
  1338.     Locale en_US_custom("en", "US", "De Anza_Cupertino_California_United States_Earth");
  1339.  
  1340.     UnicodeString dispName("English (United States, DE ANZA_CUPERTINO_CALIFORNIA_UNITED STATES_EARTH)");
  1341.     UnicodeString dispVar("DE ANZA_CUPERTINO_CALIFORNIA_UNITED STATES_EARTH");
  1342.     
  1343.     UnicodeString got;
  1344.     
  1345.     en_US_custom.getDisplayVariant(Locale::US, got);
  1346.     if(got != dispVar) {
  1347.         errln("FAIL: getDisplayVariant()");
  1348.         errln("Wanted: " + dispVar);
  1349.         errln("Got   : " + got);
  1350.     }
  1351.  
  1352.     en_US_custom.getDisplayName(Locale::US, got);
  1353.     if(got != dispName) {
  1354.         errln("FAIL: getDisplayName()");
  1355.         errln("Wanted: " + dispName);
  1356.         errln("Got   : " + got);
  1357.     }
  1358.  
  1359.     Locale shortVariant("fr", "FR", "foo");
  1360.     shortVariant.getDisplayVariant(got);
  1361.     
  1362.     if(got != "FOO") {
  1363.         errln("FAIL: getDisplayVariant()");
  1364.         errln("Wanted: foo");
  1365.         errln("Got   : " + got);
  1366.     }
  1367.  
  1368.     Locale bogusVariant("fr", "FR", "_foo");
  1369.     bogusVariant.getDisplayVariant(got);
  1370.     
  1371.     if(got != "FOO") {
  1372.         errln("FAIL: getDisplayVariant()");
  1373.         errln("Wanted: foo");
  1374.         errln("Got   : " + got);
  1375.     }
  1376.  
  1377.     Locale bogusVariant2("fr", "FR", "foo_");
  1378.     bogusVariant2.getDisplayVariant(got);
  1379.     
  1380.     if(got != "FOO") {
  1381.         errln("FAIL: getDisplayVariant()");
  1382.         errln("Wanted: foo");
  1383.         errln("Got   : " + got);
  1384.     }
  1385.  
  1386.     Locale bogusVariant3("fr", "FR", "_foo_");
  1387.     bogusVariant3.getDisplayVariant(got);
  1388.     
  1389.     if(got != "FOO") {
  1390.         errln("FAIL: getDisplayVariant()");
  1391.         errln("Wanted: foo");
  1392.         errln("Got   : " + got);
  1393.     }
  1394. }
  1395.  
  1396. /**
  1397.  * @bug 4105828
  1398.  * Currency symbol in zh is wrong.  We will test this at the NumberFormat
  1399.  * end to test the whole pipe.
  1400.  */
  1401. void 
  1402. LocaleTest::Test4105828() 
  1403. {
  1404.     Locale LOC [] = { Locale::CHINESE,  Locale("zh", "CN", ""),
  1405.                      Locale("zh", "TW", ""), Locale("zh", "HK", "") };
  1406.     UErrorCode status = U_ZERO_ERROR;
  1407.     for (int32_t i = 0; i < 4; ++i) {
  1408.         NumberFormat *fmt = NumberFormat::createPercentInstance(LOC[i], status);
  1409.         if(U_FAILURE(status)) {
  1410.             errln("Couldn't create NumberFormat");
  1411.             return;
  1412.         }
  1413.         UnicodeString result;
  1414.         FieldPosition pos(0);
  1415.         fmt->format((int32_t)1, result, pos);
  1416.         UnicodeString temp;
  1417.         if(result != "100%") {
  1418.             errln(UnicodeString("Percent for ") + LOC[i].getDisplayName(temp) + " should be 100%, got " + result);
  1419.         }
  1420.         delete fmt;
  1421.     }
  1422. }
  1423.