16f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/********************************************************************
26f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * COPYRIGHT:
36f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Copyright (c) 1997-2013, International Business Machines Corporation and
46f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * others. All Rights Reserved.
56f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org ********************************************************************/
66f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
76f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "loctest.h"
86f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/decimfmt.h"
96f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/ucurr.h"
106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/smpdtfmt.h"
116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/dtfmtsym.h"
126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/brkiter.h"
136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/coll.h"
146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "cstring.h"
156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include <stdio.h>
166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include <string.h>
176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "putilimp.h"
186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/ustring.h"
196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic const char* const rawData[33][8] = {
216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // language code
236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "en",   "fr",   "ca",   "el",   "no",   "it",   "xx",   "zh"  },
246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // script code
256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "",     "",     "",     "",     "",     "",     "",     "Hans" },
266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // country code
276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "US",   "FR",   "ES",   "GR",   "NO",   "",     "YY",   "CN"  },
286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // variant code
296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "",     "",     "",     "",     "NY",   "",     "",   ""    },
306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // full name
316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "en_US",    "fr_FR",    "ca_ES",    "el_GR",    "no_NO_NY", "it",   "xx_YY",   "zh_Hans_CN" },
326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // ISO-3 language
336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "eng",  "fra",  "cat",  "ell",  "nor",  "ita",  "",   "zho"   },
346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // ISO-3 country
356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "USA",  "FRA",  "ESP",  "GRC",  "NOR",  "",     "",   "CHN"   },
366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // LCID
376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "409", "40c", "403", "408", "814", "10",     "0",   "804"  },
386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // display langage (English)
406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "English",  "French",   "Catalan", "Greek",    "Norwegian",    "Italian",  "xx",   "Chinese" },
416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // display script (English)
426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "",     "",     "",     "",     "",   "",     "",   "Simplified Han" },
436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // display country (English)
446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "United States",    "France",   "Spain",  "Greece",   "Norway",   "",     "YY",   "China" },
456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // display variant (English)
466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "",     "",     "",     "",     "NY",   "",     "",   ""},
476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // display name (English)
486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // Updated no_NO_NY English display name for new pattern-based algorithm
496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // (part of Euro support).
506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "English (United States)", "French (France)", "Catalan (Spain)", "Greek (Greece)", "Norwegian (Norway, NY)", "Italian", "xx (YY)", "Chinese (Simplified, China)" },
516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // display langage (French)
536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "anglais",  "fran\\u00E7ais",   "catalan", "grec",    "norv\\u00E9gien",    "italien", "xx", "chinois" },
546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // display script (French)
556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "",     "",     "",     "",     "",     "",     "",   "sinogrammes simplifi\\u00E9s" },
566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // display country (French)
576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "\\u00C9tats-Unis",    "France",   "Espagne",  "Gr\\u00E8ce",   "Norv\\u00E8ge", "", "YY", "Chine" },
586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // display variant (French)
596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "",     "",     "",     "",     "NY",     "",     "",   "" },
606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // display name (French)
616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        //{   "anglais (Etats-Unis)", "francais (France)", "catalan (Espagne)", "grec (Grece)", "norvegien (Norvege,Nynorsk)", "italien", "xx (YY)" },
626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "anglais (\\u00C9tats-Unis)", "fran\\u00E7ais (France)", "catalan (Espagne)", "grec (Gr\\u00E8ce)", "norv\\u00E9gien (Norv\\u00E8ge, NY)", "italien", "xx (YY)", "chinois (simplifi\\u00E9, Chine)" },
636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* display language (Catalan) */
666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "angl\\u00E8s", "franc\\u00E8s", "catal\\u00E0", "grec",  "noruec", "itali\\u00E0", "", "xin\\u00E8s" },
676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* display script (Catalan) */
686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "", "", "",                    "", "", "", "", "han simplificat" },
696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* display country (Catalan) */
706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "Estats Units", "Fran\\u00E7a", "Espanya",  "Gr\\u00E8cia", "Noruega", "", "", "Xina" },
716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* display variant (Catalan) */
726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "", "", "",                    "", "NY", "", "" },
736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* display name (Catalan) */
746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "angl\\u00E8s (Estats Units)", "franc\\u00E8s (Fran\\u00E7a)", "catal\\u00E0 (Espanya)", "grec (Gr\\u00E8cia)", "noruec (Noruega, NY)", "itali\\u00E0", "", "xin\\u00E8s (simplificat, Xina)" },
756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // display langage (Greek)[actual values listed below]
776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "\\u0391\\u03b3\\u03b3\\u03bb\\u03b9\\u03ba\\u03ac",
786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "\\u0393\\u03b1\\u03bb\\u03bb\\u03b9\\u03ba\\u03ac",
796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "\\u039a\\u03b1\\u03c4\\u03b1\\u03bb\\u03b1\\u03bd\\u03b9\\u03ba\\u03ac",
806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "\\u0395\\u03bb\\u03bb\\u03b7\\u03bd\\u03b9\\u03ba\\u03ac",
816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "\\u039d\\u03bf\\u03c1\\u03b2\\u03b7\\u03b3\\u03b9\\u03ba\\u03ac",
826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "\\u0399\\u03c4\\u03b1\\u03bb\\u03b9\\u03ba\\u03ac",
836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "",
846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "\\u039A\\u03B9\\u03BD\\u03B5\\u03B6\\u03B9\\u03BA\\u03AC"
856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        },
866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // display script (Greek)
876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "", "", "", "", "", "", "", "\\u0391\\u03c0\\u03bb\\u03bf\\u03c0\\u03bf\\u03b9\\u03b7\\u03bc\\u03ad\\u03bd\\u03bf \\u03a7\\u03b1\\u03bd" },
886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // display country (Greek)[actual values listed below]
896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "\\u0397\\u03BD\\u03C9\\u03BC\\u03AD\\u03BD\\u03B5\\u03C2 \\u03A0\\u03BF\\u03BB\\u03B9\\u03C4\\u03B5\\u03AF\\u03B5\\u03C2",
906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "\\u0393\\u03b1\\u03bb\\u03bb\\u03af\\u03b1",
916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "\\u0399\\u03c3\\u03c0\\u03b1\\u03bd\\u03af\\u03b1",
926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "\\u0395\\u03bb\\u03bb\\u03ac\\u03b4\\u03b1",
936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "\\u039d\\u03bf\\u03c1\\u03b2\\u03b7\\u03b3\\u03af\\u03b1",
946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "",
956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "",
966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "\\u039A\\u03AF\\u03BD\\u03B1"
976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        },
986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // display variant (Greek)
996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "", "", "", "", "NY", "", "" },
1006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // display name (Greek)[actual values listed below]
1016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "\\u0391\\u03b3\\u03b3\\u03bb\\u03b9\\u03ba\\u03ac (\\u0397\\u03BD\\u03C9\\u03BC\\u03AD\\u03BD\\u03B5\\u03C2 \\u03A0\\u03BF\\u03BB\\u03B9\\u03C4\\u03B5\\u03AF\\u03B5\\u03C2)",
1026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "\\u0393\\u03b1\\u03bb\\u03bb\\u03b9\\u03ba\\u03ac (\\u0393\\u03b1\\u03bb\\u03bb\\u03af\\u03b1)",
1036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "\\u039a\\u03b1\\u03c4\\u03b1\\u03bb\\u03b1\\u03bd\\u03b9\\u03ba\\u03ac (\\u0399\\u03c3\\u03c0\\u03b1\\u03bd\\u03af\\u03b1)",
1046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "\\u0395\\u03bb\\u03bb\\u03b7\\u03bd\\u03b9\\u03ba\\u03ac (\\u0395\\u03bb\\u03bb\\u03ac\\u03b4\\u03b1)",
1056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "\\u039d\\u03bf\\u03c1\\u03b2\\u03b7\\u03b3\\u03b9\\u03ba\\u03ac (\\u039d\\u03bf\\u03c1\\u03b2\\u03b7\\u03b3\\u03af\\u03b1, NY)",
1066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "\\u0399\\u03c4\\u03b1\\u03bb\\u03b9\\u03ba\\u03ac",
1076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "",
1086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "\\u039A\\u03B9\\u03BD\\u03B5\\u03B6\\u03B9\\u03BA\\u03AC (\\u0391\\u03c0\\u03bb\\u03bf\\u03c0\\u03bf\\u03b9\\u03b7\\u03bc\\u03ad\\u03bd\\u03bf, \\u039A\\u03AF\\u03BD\\u03B1)"
1096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        },
1106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // display langage (<root>)
1126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "English",  "French",   "Catalan", "Greek",    "Norwegian",    "Italian",  "xx", "" },
1136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // display script (<root>)
1146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "",     "",     "",     "",     "",   "",     "", ""},
1156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // display country (<root>)
1166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "United States",    "France",   "Spain",  "Greece",   "Norway",   "",     "YY", "" },
1176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // display variant (<root>)
1186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "",     "",     "",     "",     "Nynorsk",   "",     "", ""},
1196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // display name (<root>)
1206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        //{   "English (United States)", "French (France)", "Catalan (Spain)", "Greek (Greece)", "Norwegian (Norway,Nynorsk)", "Italian", "xx (YY)" },
1216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "English (United States)", "French (France)", "Catalan (Spain)", "Greek (Greece)", "Norwegian (Norway,NY)", "Italian", "xx (YY)", "" }
1226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org};
1236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/*
1266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org Usage:
1276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(    Test (should be TRUE)  )
1286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   Example:
1306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       test_assert(i==3);
1316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   the macro is ugly but makes the tests pretty.
1336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org*/
1346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define test_assert(test) \
1366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    { \
1376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(!(test)) \
1386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("FAIL: " #test " was not true. In " __FILE__ " on line %d", __LINE__ ); \
1396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        else \
1406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            logln("PASS: asserted " #test); \
1416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
1426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/*
1446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org Usage:
1456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert_print(    Test (should be TRUE),  printable  )
1466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   Example:
1486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       test_assert(i==3, toString(i));
1496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org   the macro is ugly but makes the tests pretty.
1516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org*/
1526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define test_assert_print(test,print) \
1546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    { \
1556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(!(test)) \
1566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("FAIL: " #test " was not true. " + UnicodeString(print) ); \
1576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        else \
1586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            logln("PASS: asserted " #test "-> " + UnicodeString(print)); \
1596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
1606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define test_dumpLocale(l) { logln(#l " = " + UnicodeString(l.getName(), "")); }
1636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgLocaleTest::LocaleTest()
1656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org: dataTable(NULL)
1666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
1676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    setUpDataTable();
1686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
1696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgLocaleTest::~LocaleTest()
1716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
1726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (dataTable != 0) {
1736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for (int32_t i = 0; i < 33; i++) {
1746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            delete []dataTable[i];
1756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
1766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        delete []dataTable;
1776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        dataTable = 0;
1786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
1796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
1806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid LocaleTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ )
1826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
1836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    switch (index) {
1846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TESTCASE(0, TestBasicGetters);
1856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TESTCASE(1, TestSimpleResourceInfo);
1866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TESTCASE(2, TestDisplayNames);
1876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TESTCASE(3, TestSimpleObjectStuff);
1886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TESTCASE(4, TestPOSIXParsing);
1896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TESTCASE(5, TestGetAvailableLocales);
1906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TESTCASE(6, TestDataDirectory);
1916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TESTCASE(7, TestISO3Fallback);
1926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TESTCASE(8, TestGetLangsAndCountries);
1936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TESTCASE(9, TestSimpleDisplayNames);
1946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TESTCASE(10, TestUninstalledISO3Names);
1956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TESTCASE(11, TestAtypicalLocales);
1966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_FORMATTING
1976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TESTCASE(12, TestThaiCurrencyFormat);
1986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TESTCASE(13, TestEuroSupport);
1996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
2006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TESTCASE(14, TestToString);
2016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_FORMATTING
2026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TESTCASE(15, Test4139940);
2036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TESTCASE(16, Test4143951);
2046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
2056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TESTCASE(17, Test4147315);
2066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TESTCASE(18, Test4147317);
2076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TESTCASE(19, Test4147552);
2086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TESTCASE(20, TestVariantParsing);
2096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_FORMATTING
2106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TESTCASE(21, Test4105828);
2116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
2126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TESTCASE(22, TestSetIsBogus);
2136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TESTCASE(23, TestParallelAPIValues);
2146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TESTCASE(24, TestKeywordVariants);
2156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TESTCASE(25, TestKeywordVariantParsing);
2166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TESTCASE(26, TestSetKeywordValue);
2176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TESTCASE(27, TestGetBaseName);
2186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_FILE_IO
2196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TESTCASE(28, TestGetLocale);
2206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
2216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TESTCASE(29, TestVariantWithOutCountry);
2226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TESTCASE(30, TestCanonicalization);
2236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TESTCASE(31, TestCurrencyByDate);
2246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	TESTCASE(32, TestGetVariantWithKeywords);
2256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // keep the last index in sync with the condition in default:
2276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        default:
2296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (index <= 28) { // keep this in sync with the last index!
2306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                name = "(test omitted by !UCONFIG_NO_FORMATTING)";
2316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            } else {
2326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                name = "";
2336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
2346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            break; //needed to end loop
2356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
2366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
2376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid LocaleTest::TestBasicGetters() {
2396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString   temp;
2406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t i;
2426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (i = 0; i <= MAX_LOCALES; i++) {
2436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        Locale testLocale("");
2446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (rawData[SCRIPT][i] && rawData[SCRIPT][i][0] != 0) {
2456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            testLocale = Locale(rawData[LANG][i], rawData[SCRIPT][i], rawData[CTRY][i], rawData[VAR][i]);
2466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
2476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        else {
2486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            testLocale = Locale(rawData[LANG][i], rawData[CTRY][i], rawData[VAR][i]);
2496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
2506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln("Testing " + (UnicodeString)testLocale.getName() + "...");
2516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if ( (temp=testLocale.getLanguage()) != (dataTable[LANG][i]))
2536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("  Language code mismatch: " + temp + " versus "
2546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        + dataTable[LANG][i]);
2556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if ( (temp=testLocale.getScript()) != (dataTable[SCRIPT][i]))
2566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("  Script code mismatch: " + temp + " versus "
2576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        + dataTable[SCRIPT][i]);
2586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if ( (temp=testLocale.getCountry()) != (dataTable[CTRY][i]))
2596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("  Country code mismatch: " + temp + " versus "
2606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        + dataTable[CTRY][i]);
2616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if ( (temp=testLocale.getVariant()) != (dataTable[VAR][i]))
2626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("  Variant code mismatch: " + temp + " versus "
2636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        + dataTable[VAR][i]);
2646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if ( (temp=testLocale.getName()) != (dataTable[NAME][i]))
2656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("  Locale name mismatch: " + temp + " versus "
2666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        + dataTable[NAME][i]);
2676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
2686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    logln("Same thing without variant codes...");
2706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (i = 0; i <= MAX_LOCALES; i++) {
2716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        Locale testLocale("");
2726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (rawData[SCRIPT][i] && rawData[SCRIPT][i][0] != 0) {
2736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            testLocale = Locale(rawData[LANG][i], rawData[SCRIPT][i], rawData[CTRY][i]);
2746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
2756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        else {
2766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            testLocale = Locale(rawData[LANG][i], rawData[CTRY][i]);
2776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
2786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln("Testing " + (temp=testLocale.getName()) + "...");
2796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if ( (temp=testLocale.getLanguage()) != (dataTable[LANG][i]))
2816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("Language code mismatch: " + temp + " versus "
2826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        + dataTable[LANG][i]);
2836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if ( (temp=testLocale.getScript()) != (dataTable[SCRIPT][i]))
2846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("Script code mismatch: " + temp + " versus "
2856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        + dataTable[SCRIPT][i]);
2866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if ( (temp=testLocale.getCountry()) != (dataTable[CTRY][i]))
2876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("Country code mismatch: " + temp + " versus "
2886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        + dataTable[CTRY][i]);
2896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (testLocale.getVariant()[0] != 0)
2906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("Variant code mismatch: something versus \"\"");
2916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
2926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    logln("Testing long language names and getters");
2946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale  test8 = Locale::createFromName("x-klingon-latn-zx.utf32be@special");
2956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    temp = test8.getLanguage();
2976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (temp != UnicodeString("x-klingon") )
2986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Language code mismatch: " + temp + "  versus \"x-klingon\"");
2996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    temp = test8.getScript();
3016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (temp != UnicodeString("Latn") )
3026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Script code mismatch: " + temp + "  versus \"Latn\"");
3036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    temp = test8.getCountry();
3056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (temp != UnicodeString("ZX") )
3066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Country code mismatch: " + temp + "  versus \"ZX\"");
3076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    temp = test8.getVariant();
3096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    //if (temp != UnicodeString("SPECIAL") )
3106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    //    errln("Variant code mismatch: " + temp + "  versus \"SPECIAL\"");
3116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // As of 3.0, the "@special" will *not* be parsed by uloc_getName()
3126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (temp != UnicodeString("") )
3136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Variant code mismatch: " + temp + "  versus \"\"");
3146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (Locale::getDefault() != Locale::createFromName(NULL))
3166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Locale::getDefault() == Locale::createFromName(NULL)");
3176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*----------*/
3196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // NOTE: There used to be a special test for locale names that had language or
3206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // country codes that were longer than two letters.  The new version of Locale
3216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // doesn't support anything that isn't an officially recognized language or
3226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // country code, so we no longer support this feature.
3236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale bogusLang("THISISABOGUSLANGUAGE"); // Jitterbug 2864: language code too long
3256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(!bogusLang.isBogus()) {
3266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Locale(\"THISISABOGUSLANGUAGE\").isBogus()==FALSE");
3276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
3286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    bogusLang=Locale("eo");
3306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if( bogusLang.isBogus() ||
3316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        strcmp(bogusLang.getLanguage(), "eo")!=0 ||
3326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        *bogusLang.getCountry()!=0 ||
3336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        *bogusLang.getVariant()!=0 ||
3346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        strcmp(bogusLang.getName(), "eo")!=0
3356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ) {
3366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("assignment to bogus Locale does not unbogus it or sets bad data");
3376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
3386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale a("eo_DE@currency=DEM");
3406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale *pb=a.clone();
3416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(pb==&a || *pb!=a) {
3426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Locale.clone() failed");
3436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
3446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete pb;
3456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
3466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid LocaleTest::TestParallelAPIValues() {
3486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    logln("Test synchronization between C and C++ API");
3496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (strcmp(Locale::getChinese().getName(), ULOC_CHINESE) != 0) {
3506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Differences for ULOC_CHINESE Locale");
3516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
3526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (strcmp(Locale::getEnglish().getName(), ULOC_ENGLISH) != 0) {
3536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Differences for ULOC_ENGLISH Locale");
3546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
3556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (strcmp(Locale::getFrench().getName(), ULOC_FRENCH) != 0) {
3566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Differences for ULOC_FRENCH Locale");
3576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
3586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (strcmp(Locale::getGerman().getName(), ULOC_GERMAN) != 0) {
3596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Differences for ULOC_GERMAN Locale");
3606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
3616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (strcmp(Locale::getItalian().getName(), ULOC_ITALIAN) != 0) {
3626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Differences for ULOC_ITALIAN Locale");
3636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
3646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (strcmp(Locale::getJapanese().getName(), ULOC_JAPANESE) != 0) {
3656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Differences for ULOC_JAPANESE Locale");
3666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
3676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (strcmp(Locale::getKorean().getName(), ULOC_KOREAN) != 0) {
3686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Differences for ULOC_KOREAN Locale");
3696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
3706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (strcmp(Locale::getSimplifiedChinese().getName(), ULOC_SIMPLIFIED_CHINESE) != 0) {
3716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Differences for ULOC_SIMPLIFIED_CHINESE Locale");
3726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
3736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (strcmp(Locale::getTraditionalChinese().getName(), ULOC_TRADITIONAL_CHINESE) != 0) {
3746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Differences for ULOC_TRADITIONAL_CHINESE Locale");
3756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
3766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (strcmp(Locale::getCanada().getName(), ULOC_CANADA) != 0) {
3796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Differences for ULOC_CANADA Locale");
3806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
3816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (strcmp(Locale::getCanadaFrench().getName(), ULOC_CANADA_FRENCH) != 0) {
3826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Differences for ULOC_CANADA_FRENCH Locale");
3836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
3846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (strcmp(Locale::getChina().getName(), ULOC_CHINA) != 0) {
3856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Differences for ULOC_CHINA Locale");
3866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
3876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (strcmp(Locale::getPRC().getName(), ULOC_PRC) != 0) {
3886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Differences for ULOC_PRC Locale");
3896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
3906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (strcmp(Locale::getFrance().getName(), ULOC_FRANCE) != 0) {
3916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Differences for ULOC_FRANCE Locale");
3926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
3936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (strcmp(Locale::getGermany().getName(), ULOC_GERMANY) != 0) {
3946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Differences for ULOC_GERMANY Locale");
3956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
3966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (strcmp(Locale::getItaly().getName(), ULOC_ITALY) != 0) {
3976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Differences for ULOC_ITALY Locale");
3986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
3996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (strcmp(Locale::getJapan().getName(), ULOC_JAPAN) != 0) {
4006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Differences for ULOC_JAPAN Locale");
4016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
4026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (strcmp(Locale::getKorea().getName(), ULOC_KOREA) != 0) {
4036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Differences for ULOC_KOREA Locale");
4046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
4056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (strcmp(Locale::getTaiwan().getName(), ULOC_TAIWAN) != 0) {
4066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Differences for ULOC_TAIWAN Locale");
4076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
4086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (strcmp(Locale::getUK().getName(), ULOC_UK) != 0) {
4096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Differences for ULOC_UK Locale");
4106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
4116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (strcmp(Locale::getUS().getName(), ULOC_US) != 0) {
4126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Differences for ULOC_US Locale");
4136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
4146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
4156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid LocaleTest::TestSimpleResourceInfo() {
4186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString   temp;
4196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    char            temp2[20];
4206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode err = U_ZERO_ERROR;
4216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t i = 0;
4226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (i = 0; i <= MAX_LOCALES; i++) {
4246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        Locale testLocale(rawData[LANG][i], rawData[CTRY][i], rawData[VAR][i]);
4256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln("Testing " + (temp=testLocale.getName()) + "...");
4266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if ( (temp=testLocale.getISO3Language()) != (dataTable[LANG3][i]))
4286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("  ISO-3 language code mismatch: " + temp
4296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                + " versus " + dataTable[LANG3][i]);
4306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if ( (temp=testLocale.getISO3Country()) != (dataTable[CTRY3][i]))
4316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("  ISO-3 country code mismatch: " + temp
4326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                + " versus " + dataTable[CTRY3][i]);
4336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        sprintf(temp2, "%x", (int)testLocale.getLCID());
4356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (UnicodeString(temp2) != dataTable[LCID][i])
4366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln((UnicodeString)"  LCID mismatch: " + temp2 + " versus "
4376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                + dataTable[LCID][i]);
4386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(U_FAILURE(err))
4406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {
4416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln((UnicodeString)"Some error on number " + i + u_errorName(err));
4426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
4436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        err = U_ZERO_ERROR;
4446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
4456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale locale("en");
4476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(strcmp(locale.getName(), "en") != 0||
4486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        strcmp(locale.getLanguage(), "en") != 0) {
4496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("construction of Locale(en) failed\n");
4506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
4516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*-----*/
4526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
4546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/*
4566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Jitterbug 2439 -- markus 20030425
4576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org *
4586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * The lookup of display names must not fall back through the default
4596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * locale because that yields useless results.
4606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
4616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
4626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgLocaleTest::TestDisplayNames()
4636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
4646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale  english("en", "US");
4656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale  french("fr", "FR");
4666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale  croatian("ca", "ES");
4676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale  greek("el", "GR");
4686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    logln("  In locale = en_US...");
4706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    doTestDisplayNames(english, DLANG_EN);
4716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    logln("  In locale = fr_FR...");
4726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    doTestDisplayNames(french, DLANG_FR);
4736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    logln("  In locale = ca_ES...");
4746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    doTestDisplayNames(croatian, DLANG_CA);
4756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    logln("  In locale = el_GR...");
4766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    doTestDisplayNames(greek, DLANG_EL);
4776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString s;
4796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
4806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_FORMATTING
4826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DecimalFormatSymbols symb(status);
4836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* Check to see if ICU supports this locale */
4846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (symb.getLocale(ULOC_VALID_LOCALE, status) != Locale("root")) {
4856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* test that the default locale has a display name for its own language */
4866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* Currently, there is no language information in the "tl" data file so this test will fail if default locale is "tl" */
4876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (uprv_strcmp(Locale().getLanguage(), "tl") != 0) {
4886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            Locale().getDisplayLanguage(Locale(), s);
4896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if(s.length()<=3 && s.charAt(0)<=0x7f) {
4906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                /* check <=3 to reject getting the language code as a display name */
4916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                dataerrln("unable to get a display string for the language of the default locale: " + s);
4926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
4936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            /*
4956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org             * API coverage improvements: call
4966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org             * Locale::getDisplayLanguage(UnicodeString &) and
4976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org             * Locale::getDisplayCountry(UnicodeString &)
4986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org             */
4996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            s.remove();
5006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            Locale().getDisplayLanguage(s);
5016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if(s.length()<=3 && s.charAt(0)<=0x7f) {
5026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                dataerrln("unable to get a display string for the language of the default locale [2]: " + s);
5036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
5046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
5056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
5066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    else {
5076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln("Default locale %s is unsupported by ICU\n", Locale().getName());
5086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
5096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    s.remove();
5106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
5116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    french.getDisplayCountry(s);
5136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(s.isEmpty()) {
5146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("unable to get any default-locale display string for the country of fr_FR\n");
5156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
5166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    s.remove();
5176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale("zh", "Hant").getDisplayScript(s);
5186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(s.isEmpty()) {
5196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("unable to get any default-locale display string for the country of zh_Hant\n");
5206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
5216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
5226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid LocaleTest::TestSimpleObjectStuff() {
5246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale  test1("aa", "AA");
5256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale  test2("aa", "AA");
5266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale  test3(test1);
5276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale  test4("zz", "ZZ");
5286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale  test5("aa", "AA", "");
5296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale  test6("aa", "AA", "ANTARES");
5306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale  test7("aa", "AA", "JUPITER");
5316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale  test8 = Locale::createFromName("aa-aa-jupiTER"); // was "aa-aa.utf8@jupiter" but in 3.0 getName won't normalize that
5326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // now list them all for debugging usage.
5346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_dumpLocale(test1);
5356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_dumpLocale(test2);
5366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_dumpLocale(test3);
5376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_dumpLocale(test4);
5386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_dumpLocale(test5);
5396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_dumpLocale(test6);
5406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_dumpLocale(test7);
5416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_dumpLocale(test8);
5426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // Make sure things compare to themselves!
5446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(test1 == test1);
5456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(test2 == test2);
5466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(test3 == test3);
5476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(test4 == test4);
5486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(test5 == test5);
5496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(test6 == test6);
5506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(test7 == test7);
5516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(test8 == test8);
5526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // make sure things are not equal to themselves.
5546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(!(test1 != test1));
5556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(!(test2 != test2));
5566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(!(test3 != test3));
5576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(!(test4 != test4));
5586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(!(test5 != test5));
5596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(!(test6 != test6));
5606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(!(test7 != test7));
5616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(!(test8 != test8));
5626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // make sure things that are equal to each other don't show up as unequal.
5646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(!(test1 != test2));
5656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(!(test2 != test1));
5666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(!(test1 != test3));
5676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(!(test2 != test3));
5686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(test5 == test1);
5696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(test6 != test2);
5706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(test6 != test5);
5716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(test6 != test7);
5736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // test for things that shouldn't compare equal.
5756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(!(test1 == test4));
5766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(!(test2 == test4));
5776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(!(test3 == test4));
5786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(test7 == test8);
5806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // test for hash codes to be the same.
5826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t hash1 = test1.hashCode();
5836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t hash2 = test2.hashCode();
5846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t hash3 = test3.hashCode();
5856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(hash1 == hash2);
5876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(hash1 == hash3);
5886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(hash2 == hash3);
5896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // test that the assignment operator works.
5916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test4 = test1;
5926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    logln("test4=test1;");
5936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_dumpLocale(test4);
5946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(test4 == test4);
5956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(!(test1 != test4));
5976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(!(test2 != test4));
5986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(!(test3 != test4));
5996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(test1 == test4);
6006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(test4 == test1);
6016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // test assignments with a variant
6036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    logln("test7 = test6");
6046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test7 = test6;
6056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_dumpLocale(test7);
6066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(test7 == test7);
6076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(test7 == test6);
6086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(test7 != test5);
6096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    logln("test6 = test1");
6116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test6=test1;
6126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_dumpLocale(test6);
6136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(test6 != test7);
6146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(test6 == test1);
6156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(test6 == test6);
6166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
6176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org// A class which exposes constructors that are implemented in terms of the POSIX parsing code.
6196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgclass POSIXLocale : public Locale
6206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
6216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgpublic:
6226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    POSIXLocale(const UnicodeString& l)
6236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        :Locale()
6246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
6256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      char *ch;
6266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      ch = new char[l.length() + 1];
6276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      ch[l.extract(0, 0x7fffffff, ch, "")] = 0;
6286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      setFromPOSIXID(ch);
6296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      delete [] ch;
6306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
6316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    POSIXLocale(const char *l)
6326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        :Locale()
6336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
6346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        setFromPOSIXID(l);
6356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
6366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org};
6376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid LocaleTest::TestPOSIXParsing()
6396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
6406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    POSIXLocale  test1("ab_AB");
6416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    POSIXLocale  test2(UnicodeString("ab_AB"));
6426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale  test3("ab","AB");
6436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    POSIXLocale test4("ab_AB_Antares");
6456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    POSIXLocale test5(UnicodeString("ab_AB_Antares"));
6466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale  test6("ab", "AB", "Antares");
6476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_dumpLocale(test1);
6496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_dumpLocale(test2);
6506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_dumpLocale(test3);
6516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_dumpLocale(test4);
6526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_dumpLocale(test5);
6536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_dumpLocale(test6);
6546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(test1 == test1);
6566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(test1 == test2);
6586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(test2 == test3);
6596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(test3 == test1);
6606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(test4 == test5);
6626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(test5 == test6);
6636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(test6 == test4);
6646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(test1 != test4);
6666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(test5 != test3);
6676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(test5 != test2);
6686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t hash1 = test1.hashCode();
6706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t hash2 = test2.hashCode();
6716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t hash3 = test3.hashCode();
6726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(hash1 == hash2);
6746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(hash2 == hash3);
6756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test_assert(hash3 == hash1);
6766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
6776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid LocaleTest::TestGetAvailableLocales()
6796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
6806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t locCount = 0;
6816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const Locale* locList = Locale::getAvailableLocales(locCount);
6826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (locCount == 0)
6846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        dataerrln("getAvailableLocales() returned an empty list!");
6856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    else {
6866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln(UnicodeString("Number of locales returned = ") + locCount);
6876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString temp;
6886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for(int32_t i = 0; i < locCount; ++i)
6896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            logln(locList[i].getName());
6906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
6916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // I have no idea how to test this function...
6926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
6936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org// This test isn't applicable anymore - getISO3Language is
6956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org// independent of the data directory
6966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid LocaleTest::TestDataDirectory()
6976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
6986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/*
6996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    char            oldDirectory[80];
7006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char*     temp;
7016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode       err = U_ZERO_ERROR;
7026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString   testValue;
7036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    temp = Locale::getDataDirectory();
7056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    strcpy(oldDirectory, temp);
7066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    logln(UnicodeString("oldDirectory = ") + oldDirectory);
7076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale  test(Locale::US);
7096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test.getISO3Language(testValue);
7106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    logln("first fetch of language retrieved " + testValue);
7116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (testValue != "eng")
7126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Initial check of ISO3 language failed: expected \"eng\", got \"" + testValue + "\"");
7136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
7156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        char *path;
7166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        path=IntlTest::getTestDirectory();
7176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        Locale::setDataDirectory( path );
7186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
7196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test.getISO3Language(testValue);
7216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    logln("second fetch of language retrieved " + testValue);
7226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (testValue != "xxx")
7236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("setDataDirectory() failed: expected \"xxx\", got \"" + testValue + "\"");
7246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale::setDataDirectory(oldDirectory);
7266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test.getISO3Language(testValue);
7276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    logln("third fetch of language retrieved " + testValue);
7286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (testValue != "eng")
7296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("get/setDataDirectory() failed: expected \"eng\", got \"" + testValue + "\"");
7306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org*/
7316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
7326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org//===========================================================
7346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid LocaleTest::doTestDisplayNames(Locale& displayLocale, int32_t compareIndex) {
7366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString   temp;
7376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (int32_t i = 0; i <= MAX_LOCALES; i++) {
7396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        Locale testLocale("");
7406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (rawData[SCRIPT][i] && rawData[SCRIPT][i][0] != 0) {
7416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            testLocale = Locale(rawData[LANG][i], rawData[SCRIPT][i], rawData[CTRY][i], rawData[VAR][i]);
7426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
7436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        else {
7446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            testLocale = Locale(rawData[LANG][i], rawData[CTRY][i], rawData[VAR][i]);
7456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
7466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln("  Testing " + (temp=testLocale.getName()) + "...");
7476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString  testLang;
7496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString  testScript;
7506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString  testCtry;
7516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString  testVar;
7526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString  testName;
7536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        testLocale.getDisplayLanguage(displayLocale, testLang);
7556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        testLocale.getDisplayScript(displayLocale, testScript);
7566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        testLocale.getDisplayCountry(displayLocale, testCtry);
7576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        testLocale.getDisplayVariant(displayLocale, testVar);
7586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        testLocale.getDisplayName(displayLocale, testName);
7596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString  expectedLang;
7616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString  expectedScript;
7626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString  expectedCtry;
7636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString  expectedVar;
7646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString  expectedName;
7656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectedLang = dataTable[compareIndex][i];
7676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (expectedLang.length() == 0)
7686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            expectedLang = dataTable[DLANG_EN][i];
7696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectedScript = dataTable[compareIndex + 1][i];
7716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (expectedScript.length() == 0)
7726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            expectedScript = dataTable[DSCRIPT_EN][i];
7736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectedCtry = dataTable[compareIndex + 2][i];
7756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (expectedCtry.length() == 0)
7766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            expectedCtry = dataTable[DCTRY_EN][i];
7776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectedVar = dataTable[compareIndex + 3][i];
7796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (expectedVar.length() == 0)
7806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            expectedVar = dataTable[DVAR_EN][i];
7816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectedName = dataTable[compareIndex + 4][i];
7836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (expectedName.length() == 0)
7846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            expectedName = dataTable[DNAME_EN][i];
7856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (testLang != expectedLang)
7876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            dataerrln("Display language (" + UnicodeString(displayLocale.getName()) + ") of (" + UnicodeString(testLocale.getName()) + ") got " + testLang + " expected " + expectedLang);
7886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (testScript != expectedScript)
7896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            dataerrln("Display script (" + UnicodeString(displayLocale.getName()) + ") of (" + UnicodeString(testLocale.getName()) + ") got " + testScript + " expected " + expectedScript);
7906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (testCtry != expectedCtry)
7916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            dataerrln("Display country (" + UnicodeString(displayLocale.getName()) + ") of (" + UnicodeString(testLocale.getName()) + ") got " + testCtry + " expected " + expectedCtry);
7926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (testVar != expectedVar)
7936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            dataerrln("Display variant (" + UnicodeString(displayLocale.getName()) + ") of (" + UnicodeString(testLocale.getName()) + ") got " + testVar + " expected " + expectedVar);
7946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (testName != expectedName)
7956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            dataerrln("Display name (" + UnicodeString(displayLocale.getName()) + ") of (" + UnicodeString(testLocale.getName()) + ") got " + testName + " expected " + expectedName);
7966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
7976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
7986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org//---------------------------------------------------
8006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org// table of valid data
8016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org//---------------------------------------------------
8026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid LocaleTest::setUpDataTable()
8066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
8076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (dataTable == 0) {
8086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        dataTable = new UnicodeString*[33];
8096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for (int32_t i = 0; i < 33; i++) {
8116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            dataTable[i] = new UnicodeString[8];
8126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            for (int32_t j = 0; j < 8; j++) {
8136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                dataTable[i][j] = CharsToUnicodeString(rawData[i][j]);
8146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
8156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
8166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
8176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
8186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org// ====================
8206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
8236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * @bug 4011756 4011380
8246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
8256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
8266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgLocaleTest::TestISO3Fallback()
8276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
8286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale test("xx", "YY");
8296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char * result;
8316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    result = test.getISO3Language();
8336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // Conform to C API usage
8356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (!result || (result[0] != 0))
8376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("getISO3Language() on xx_YY returned " + UnicodeString(result) + " instead of \"\"");
8386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    result = test.getISO3Country();
8406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (!result || (result[0] != 0))
8426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("getISO3Country() on xx_YY returned " + UnicodeString(result) + " instead of \"\"");
8436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
8446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
8466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * @bug 4106155 4118587
8476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
8486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
8496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgLocaleTest::TestGetLangsAndCountries()
8506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
8516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // It didn't seem right to just do an exhaustive test of everything here, so I check
8526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // for the following things:
8536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // 1) Does each list have the right total number of entries?
8546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // 2) Does each list contain certain language and country codes we think are important
8556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    //     (the G7 countries, plus a couple others)?
8566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // 3) Does each list have every entry formatted correctly? (i.e., two characters,
8576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    //     all lower case for the language codes, all upper case for the country codes)
8586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // 4) Is each list in sorted order?
8596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t testCount = 0;
8606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char * const * test = Locale::getISOLanguages();
8616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char spotCheck1[ ][4] = { "en", "es", "fr", "de", "it",
8626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                    "ja", "ko", "zh", "th", "he",
8636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                    "id", "iu", "ug", "yi", "za" };
8646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t i;
8666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for(testCount = 0;test[testCount];testCount++)
8686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      ;
8696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* TODO: Change this test to be more like the cloctst version? */
8716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (testCount != 560)
8726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Expected getISOLanguages() to return 560 languages; it returned %d", testCount);
8736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    else {
8746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for (i = 0; i < 15; i++) {
8756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            int32_t j;
8766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            for (j = 0; j < testCount; j++)
8776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              if (uprv_strcmp(test[j],spotCheck1[i])== 0)
8786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    break;
8796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (j == testCount || (uprv_strcmp(test[j],spotCheck1[i])!=0))
8806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                errln("Couldn't find " + (UnicodeString)spotCheck1[i] + " in language list.");
8816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
8826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
8836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (i = 0; i < testCount; i++) {
8846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString testee(test[i],"");
8856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString lc(test[i],"");
8866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (testee != lc.toLower())
8876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln(lc + " is not all lower case.");
8886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if ( (testee.length() != 2) && (testee.length() != 3))
8896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln(testee + " is not two or three characters long.");
8906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (i > 0 && testee.compare(test[i - 1]) <= 0)
8916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln(testee + " appears in an out-of-order position in the list.");
8926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
8936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    test = Locale::getISOCountries();
8956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString spotCheck2 [] = { "US", "CA", "GB", "FR", "DE",
8966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                    "IT", "JP", "KR", "CN", "TW",
8976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                    "TH" };
8986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t spot2Len = 11;
8996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for(testCount=0;test[testCount];testCount++)
9006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      ;
9016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (testCount != 249){
9036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Expected getISOCountries to return 249 countries; it returned %d", testCount);
9046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }else {
9056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for (i = 0; i < spot2Len; i++) {
9066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            int32_t j;
9076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            for (j = 0; j < testCount; j++)
9086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              {
9096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                UnicodeString testee(test[j],"");
9106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                if (testee == spotCheck2[i])
9126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    break;
9136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              }
9146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                UnicodeString testee(test[j],"");
9156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (j == testCount || testee != spotCheck2[i])
9166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                errln("Couldn't find " + spotCheck2[i] + " in country list.");
9176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
9186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
9196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (i = 0; i < testCount; i++) {
9206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString testee(test[i],"");
9216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString uc(test[i],"");
9226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (testee != uc.toUpper())
9236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln(testee + " is not all upper case.");
9246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (testee.length() != 2)
9256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln(testee + " is not two characters long.");
9266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (i > 0 && testee.compare(test[i - 1]) <= 0)
9276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln(testee + " appears in an out-of-order position in the list.");
9286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
9296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // This getAvailableLocales and getISO3Language
9316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
9326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int32_t numOfLocales;
9336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        Locale  enLoc ("en");
9346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const Locale *pLocales = Locale::getAvailableLocales(numOfLocales);
9356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for (int i = 0; i < numOfLocales; i++) {
9376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            const Locale    &loc(pLocales[i]);
9386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            UnicodeString   name;
9396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            char        szName[200];
9406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            loc.getDisplayName (enLoc, name);
9426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            name.extract (0, 200, szName, sizeof(szName));
9436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (strlen(loc.getISO3Language()) == 0) {
9456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                errln("getISO3Language() returned an empty string for: " + name);
9466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
9476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
9486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
9496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
9506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
9526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * @bug 4118587
9536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
9546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
9556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgLocaleTest::TestSimpleDisplayNames()
9566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
9576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // This test is different from TestDisplayNames because TestDisplayNames checks
9586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // fallback behavior, combination of language and country names to form locale
9596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // names, and other stuff like that.  This test just checks specific language
9606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // and country codes to make sure we have the correct names for them.
9616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    char languageCodes[] [4] = { "he", "id", "iu", "ug", "yi", "za" };
9626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString languageNames [] = { "Hebrew", "Indonesian", "Inuktitut", "Uyghur", "Yiddish",
9636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                               "Zhuang" };
9646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (int32_t i = 0; i < 6; i++) {
9666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString test;
9676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        Locale l(languageCodes[i], "", "");
9686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        l.getDisplayLanguage(Locale::getUS(), test);
9696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (test != languageNames[i])
9706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            dataerrln("Got wrong display name for " + UnicodeString(languageCodes[i]) + ": Expected \"" +
9716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  languageNames[i] + "\", got \"" + test + "\".");
9726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
9736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
9746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
9766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * @bug 4118595
9776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
9786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
9796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgLocaleTest::TestUninstalledISO3Names()
9806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
9816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // This test checks to make sure getISO3Language and getISO3Country work right
9826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // even for locales that are not installed.
9836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char iso2Languages [][4] = {     "am", "ba", "fy", "mr", "rn",
9846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                        "ss", "tw", "zu" };
9856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char iso3Languages [][5] = {     "amh", "bak", "fry", "mar", "run",
9866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                        "ssw", "twi", "zul" };
9876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t i;
9896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (i = 0; i < 8; i++) {
9916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      UErrorCode err = U_ZERO_ERROR;
9926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      UnicodeString test;
9946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        Locale l(iso2Languages[i], "", "");
9956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        test = l.getISO3Language();
9966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if((test != iso3Languages[i]) || U_FAILURE(err))
9976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("Got wrong ISO3 code for " + UnicodeString(iso2Languages[i]) + ": Expected \"" +
9986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    iso3Languages[i] + "\", got \"" + test + "\"." + UnicodeString(u_errorName(err)));
9996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
10006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    char iso2Countries [][4] = {     "AF", "BW", "KZ", "MO", "MN",
10026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                        "SB", "TC", "ZW" };
10036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    char iso3Countries [][4] = {     "AFG", "BWA", "KAZ", "MAC", "MNG",
10046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                        "SLB", "TCA", "ZWE" };
10056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (i = 0; i < 8; i++) {
10076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      UErrorCode err = U_ZERO_ERROR;
10086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        Locale l("", iso2Countries[i], "");
10096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString test(l.getISO3Country(), "");
10106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (test != iso3Countries[i])
10116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("Got wrong ISO3 code for " + UnicodeString(iso2Countries[i]) + ": Expected \"" +
10126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    UnicodeString(iso3Countries[i]) + "\", got \"" + test + "\"." + u_errorName(err));
10136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
10146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
10156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
10176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * @bug 4092475
10186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * I could not reproduce this bug.  I'm pretty convinced it was fixed with the
10196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * big locale-data reorg of 10/28/97.  The lookup logic for language and country
10206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * display names was also changed at that time in that check-in.    --rtg 3/20/98
10216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
10226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
10236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgLocaleTest::TestAtypicalLocales()
10246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
10256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale localesToTest [] = { Locale("de", "CA"),
10266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                  Locale("ja", "ZA"),
10276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                   Locale("ru", "MX"),
10286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                   Locale("en", "FR"),
10296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                   Locale("es", "DE"),
10306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                   Locale("", "HR"),
10316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                   Locale("", "SE"),
10326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                   Locale("", "DO"),
10336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                   Locale("", "BE") };
10346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString englishDisplayNames [] = { "German (Canada)",
10366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                     "Japanese (South Africa)",
10376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                     "Russian (Mexico)",
10386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                     "English (France)",
10396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                     "Spanish (Germany)",
10406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                     "Croatia",
10416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                     "Sweden",
10426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                     "Dominican Republic",
10436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                     "Belgium" };
10446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString frenchDisplayNames []= { "allemand (Canada)",
10456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                    "japonais (Afrique du Sud)",
10466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                    "russe (Mexique)",
10476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                     "anglais (France)",
10486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                     "espagnol (Allemagne)",
10496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                    "Croatie",
10506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                    CharsToUnicodeString("Su\\u00E8de"),
10516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                    CharsToUnicodeString("R\\u00E9publique dominicaine"),
10526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                    "Belgique" };
10536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString spanishDisplayNames [] = {
10546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                     CharsToUnicodeString("alem\\u00E1n (Canad\\u00E1)"),
10556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                     CharsToUnicodeString("japon\\u00E9s (Sud\\u00E1frica)"),
10566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                     CharsToUnicodeString("ruso (M\\u00E9xico)"),
10576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                     CharsToUnicodeString("ingl\\u00E9s (Francia)"),
10586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                     CharsToUnicodeString("espa\\u00F1ol (Alemania)"),
10596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                     "Croacia",
10606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                     "Suecia",
10616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                     CharsToUnicodeString("Rep\\u00FAblica Dominicana"),
10626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                     CharsToUnicodeString("B\\u00E9lgica") };
10636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // De-Anglicizing root required the change from
10646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // English display names to ISO Codes - ram 2003/09/26
10656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString invDisplayNames [] = { "German (Canada)",
10666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                     "Japanese (South Africa)",
10676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                     "Russian (Mexico)",
10686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                     "English (France)",
10696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                     "Spanish (Germany)",
10706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                     "Croatia",
10716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                     "Sweden",
10726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                     "Dominican Republic",
10736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                     "Belgium" };
10746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t i;
10766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
10776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale saveLocale;
10786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale::setDefault(Locale::getUS(), status);
10796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (i = 0; i < 9; ++i) {
10806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString name;
10816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        localesToTest[i].getDisplayName(Locale::getUS(), name);
10826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln(name);
10836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (name != englishDisplayNames[i])
10846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {
10856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            dataerrln("Lookup in English failed: expected \"" + englishDisplayNames[i]
10866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        + "\", got \"" + name + "\"");
10876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            logln("Locale name was-> " + (name=localesToTest[i].getName()));
10886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
10896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
10906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (i = 0; i < 9; i++) {
10926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString name;
10936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        localesToTest[i].getDisplayName(Locale("es", "ES"), name);
10946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln(name);
10956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (name != spanishDisplayNames[i])
10966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            dataerrln("Lookup in Spanish failed: expected \"" + spanishDisplayNames[i]
10976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        + "\", got \"" + name + "\"");
10986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
10996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (i = 0; i < 9; i++) {
11016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString name;
11026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        localesToTest[i].getDisplayName(Locale::getFrance(), name);
11036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln(name);
11046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (name != frenchDisplayNames[i])
11056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            dataerrln("Lookup in French failed: expected \"" + frenchDisplayNames[i]
11066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        + "\", got \"" + name + "\"");
11076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
11086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (i = 0; i < 9; i++) {
11106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString name;
11116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        localesToTest[i].getDisplayName(Locale("inv", "IN"), name);
11126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln(name + " Locale fallback to be, and data fallback to root");
11136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (name != invDisplayNames[i])
11146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            dataerrln("Lookup in INV failed: expected \"" + prettify(invDisplayNames[i])
11156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        + "\", got \"" + prettify(name) + "\"");
11166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        localesToTest[i].getDisplayName(Locale("inv", "BD"), name);
11176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln(name + " Data fallback to root");
11186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (name != invDisplayNames[i])
11196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            dataerrln("Lookup in INV failed: expected \"" + prettify(invDisplayNames[i])
11206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        + "\", got \"" + prettify(name )+ "\"");
11216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
11226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale::setDefault(saveLocale, status);
11236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
11246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_FORMATTING
11266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
11286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * @bug 4135752
11296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * This would be better tested by the LocaleDataTest.  Will move it when I
11306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * get the LocaleDataTest working again.
11316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
11326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
11336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgLocaleTest::TestThaiCurrencyFormat()
11346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
11356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
11366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DecimalFormat *thaiCurrency = (DecimalFormat*)NumberFormat::createCurrencyInstance(
11376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    Locale("th", "TH"), status);
11386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar posPrefix = 0x0e3f;
11396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString temp;
11406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(U_FAILURE(status) || !thaiCurrency)
11426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
11436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        dataerrln("Couldn't get th_TH currency -> " + UnicodeString(u_errorName(status)));
11446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
11456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
11466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (thaiCurrency->getPositivePrefix(temp) != UnicodeString(&posPrefix, 1, 1))
11476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Thai currency prefix wrong: expected 0x0e3f, got \"" +
11486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        thaiCurrency->getPositivePrefix(temp) + "\"");
11496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (thaiCurrency->getPositiveSuffix(temp) != "")
11506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Thai currency suffix wrong: expected \"\", got \"" +
11516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        thaiCurrency->getPositiveSuffix(temp) + "\"");
11526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete thaiCurrency;
11546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
11556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
11576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * @bug 4122371
11586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Confirm that Euro support works.  This test is pretty rudimentary; all it does
11596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * is check that any locales with the EURO variant format a number using the
11606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Euro currency symbol.
11616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org *
11626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * ASSUME: All locales encode the Euro character "\u20AC".
11636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * If this is changed to use the single-character Euro symbol, this
11646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * test must be updated.
11656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org *
11666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
11676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
11686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgLocaleTest::TestEuroSupport()
11696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
11706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar euro = 0x20ac;
11716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const UnicodeString EURO_CURRENCY(&euro, 1, 1); // Look for this UnicodeString in formatted Euro currency
11726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char* localeArr[] = {
11736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            "ca_ES",
11746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            "de_AT",
11756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            "de_DE",
11766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            "de_LU",
11776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            "el_GR",
11786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            "en_BE",
11796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            "en_IE",
11806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            "en_GB_EURO",
11816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            "en_US_EURO",
11826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            "es_ES",
11836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            "eu_ES",
11846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            "fi_FI",
11856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            "fr_BE",
11866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            "fr_FR",
11876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            "fr_LU",
11886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            "ga_IE",
11896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            "gl_ES",
11906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            "it_IT",
11916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            "nl_BE",
11926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            "nl_NL",
11936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            "pt_PT",
11946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            NULL
11956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        };
11966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char** locales = localeArr;
11976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
11996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString temp;
12016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (;*locales!=NULL;locales++) {
12036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        Locale loc (*locales);
12046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString temp;
12056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        NumberFormat *nf = NumberFormat::createCurrencyInstance(loc, status);
12066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString pos;
12076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (U_FAILURE(status)) {
12096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            dataerrln("Error calling NumberFormat::createCurrencyInstance(%s)", *locales);
12106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            continue;
12116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
12126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        nf->format(271828.182845, pos);
12146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString neg;
12156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        nf->format(-271828.182845, neg);
12166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (pos.indexOf(EURO_CURRENCY) >= 0 &&
12176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            neg.indexOf(EURO_CURRENCY) >= 0) {
12186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            logln("Ok: " + (temp=loc.getName()) +
12196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                ": " + pos + " / " + neg);
12206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
12216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        else {
12226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("Fail: " + (temp=loc.getName()) +
12236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                " formats without " + EURO_CURRENCY +
12246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                ": " + pos + " / " + neg +
12256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\n*** THIS FAILURE MAY ONLY MEAN THAT LOCALE DATA HAS CHANGED ***");
12266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
12276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        delete nf;
12296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
12306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString dollarStr("USD", ""), euroStr("EUR", ""), genericStr((UChar)0x00a4), resultStr;
12326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar tmp[4];
12336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    status = U_ZERO_ERROR;
12346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucurr_forLocale("en_US", tmp, 4, &status);
12366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    resultStr.setTo(tmp);
12376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (dollarStr != resultStr) {
12386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errcheckln(status, "Fail: en_US didn't return USD - %s", u_errorName(status));
12396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
12406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucurr_forLocale("en_US_EURO", tmp, 4, &status);
12416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    resultStr.setTo(tmp);
12426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (euroStr != resultStr) {
12436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errcheckln(status, "Fail: en_US_EURO didn't return EUR - %s", u_errorName(status));
12446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
12456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucurr_forLocale("en_GB_EURO", tmp, 4, &status);
12466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    resultStr.setTo(tmp);
12476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (euroStr != resultStr) {
12486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errcheckln(status, "Fail: en_GB_EURO didn't return EUR - %s", u_errorName(status));
12496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
12506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucurr_forLocale("en_US_PREEURO", tmp, 4, &status);
12516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    resultStr.setTo(tmp);
12526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (dollarStr != resultStr) {
12536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errcheckln(status, "Fail: en_US_PREEURO didn't fallback to en_US - %s", u_errorName(status));
12546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
12556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucurr_forLocale("en_US_Q", tmp, 4, &status);
12566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    resultStr.setTo(tmp);
12576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (dollarStr != resultStr) {
12586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errcheckln(status, "Fail: en_US_Q didn't fallback to en_US - %s", u_errorName(status));
12596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
12606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t invalidLen = ucurr_forLocale("en_QQ", tmp, 4, &status);
12616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (invalidLen || U_SUCCESS(status)) {
12626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Fail: en_QQ didn't return NULL");
12636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
12646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
12656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
12676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
12696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * @bug 4139504
12706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * toString() doesn't work with language_VARIANT.
12716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
12726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
12736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgLocaleTest::TestToString() {
12746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale DATA [] = {
12756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        Locale("xx", "", ""),
12766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        Locale("", "YY", ""),
12776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        Locale("", "", "ZZ"),
12786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        Locale("xx", "YY", ""),
12796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        Locale("xx", "", "ZZ"),
12806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        Locale("", "YY", "ZZ"),
12816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        Locale("xx", "YY", "ZZ"),
12826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
12836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char DATA_S [][20] = {
12856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "xx",
12866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "_YY",
12876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "__ZZ",
12886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "xx_YY",
12896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "xx__ZZ",
12906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "_YY_ZZ",
12916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "xx_YY_ZZ",
12926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
12936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (int32_t i=0; i < 7; ++i) {
12956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      const char *name;
12966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      name = DATA[i].getName();
12976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      if (strcmp(name, DATA_S[i]) != 0)
12996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {
13006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("Fail: Locale.getName(), got:" + UnicodeString(name) + ", expected: " + DATA_S[i]);
13016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
13026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        else
13036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            logln("Pass: Locale.getName(), got:" + UnicodeString(name) );
13046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
13056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
13066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_FORMATTING
13086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
13106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * @bug 4139940
13116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Couldn't reproduce this bug -- probably was fixed earlier.
13126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org *
13136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * ORIGINAL BUG REPORT:
13146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * -- basically, hungarian for monday shouldn't have an \u00f4
13156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * (o circumflex)in it instead it should be an o with 2 inclined
13166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * (right) lines over it..
13176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org *
13186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * You may wonder -- why do all this -- why not just add a line to
13196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * LocaleData?  Well, I could see by inspection that the locale file had the
13206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * right character in it, so I wanted to check the rest of the pipeline -- a
13216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * very remote possibility, but I wanted to be sure.  The other possibility
13226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * is that something is wrong with the font mapping subsystem, but we can't
13236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * test that here.
13246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
13256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
13266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgLocaleTest::Test4139940()
13276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
13286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale mylocale("hu", "", "");
13296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UDate mydate = date(98,3,13); // A Monday
13306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
13316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    SimpleDateFormat df_full("EEEE", mylocale, status);
13326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(U_FAILURE(status)){
13336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        dataerrln(UnicodeString("Could not create SimpleDateFormat object for locale hu. Error: ") + UnicodeString(u_errorName(status)));
13346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
13356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
13366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString str;
13376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    FieldPosition pos(FieldPosition::DONT_CARE);
13386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    df_full.format(mydate, str, pos);
13396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // Make sure that o circumflex (\u00F4) is NOT there, and
13406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // o double acute (\u0151) IS.
13416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar ocf = 0x00f4;
13426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar oda = 0x0151;
13436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (str.indexOf(oda) < 0 || str.indexOf(ocf) >= 0) {
13446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      /* If the default locale is "th" this test will fail because of the buddhist calendar. */
13456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      if (strcmp(Locale::getDefault().getLanguage(), "th") != 0) {
13466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Fail: Monday in Hungarian is wrong - oda's index is %d and ocf's is %d",
13476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              str.indexOf(oda), str.indexOf(ocf));
13486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      } else {
13496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln(UnicodeString("An error is produce in buddhist calendar."));
13506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      }
13516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      logln(UnicodeString("String is: ") + str );
13526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
13536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
13546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgUDate
13566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgLocaleTest::date(int32_t y, int32_t m, int32_t d, int32_t hr, int32_t min, int32_t sec)
13576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
13586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
13596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Calendar *cal = Calendar::createInstance(status);
13606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (cal == 0)
13616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return 0.0;
13626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    cal->clear();
13636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    cal->set(1900 + y, m, d, hr, min, sec); // Add 1900 to follow java.util.Date protocol
13646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UDate dt = cal->getTime(status);
13656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status))
13666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return 0.0;
13676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete cal;
13696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    return dt;
13706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
13716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
13736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * @bug 4143951
13746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Russian first day of week should be Monday. Confirmed.
13756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
13766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
13776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgLocaleTest::Test4143951()
13786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
13796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
13806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Calendar *cal = Calendar::createInstance(Locale("ru", "", ""), status);
13816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(U_SUCCESS(status)) {
13826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      if (cal->getFirstDayOfWeek(status) != UCAL_MONDAY) {
13836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org          dataerrln("Fail: First day of week in Russia should be Monday");
13846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      }
13856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
13866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete cal;
13876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
13886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
13906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
13926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * @bug 4147315
13936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * java.util.Locale.getISO3Country() works wrong for non ISO-3166 codes.
13946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Should throw an exception for unknown locales
13956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
13966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
13976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgLocaleTest::Test4147315()
13986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
13996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  UnicodeString temp;
14006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // Try with codes that are the wrong length but happen to match text
14016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // at a valid offset in the mapping table
14026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale locale("xxx", "CCC");
14036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char *result = locale.getISO3Country();
14056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // Change to conform to C api usage
14076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if((result==NULL)||(result[0] != 0))
14086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      errln("ERROR: getISO3Country() returns: " + UnicodeString(result,"") +
14096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                " for locale '" + (temp=locale.getName()) + "' rather than exception" );
14106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
14116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
14136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * @bug 4147317
14146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * java.util.Locale.getISO3Language() works wrong for non ISO-3166 codes.
14156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Should throw an exception for unknown locales
14166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
14176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
14186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgLocaleTest::Test4147317()
14196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
14206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString temp;
14216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // Try with codes that are the wrong length but happen to match text
14226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // at a valid offset in the mapping table
14236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale locale("xxx", "CCC");
14246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char *result = locale.getISO3Language();
14266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // Change to conform to C api usage
14286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if((result==NULL)||(result[0] != 0))
14296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      errln("ERROR: getISO3Language() returns: " + UnicodeString(result,"") +
14306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                " for locale '" + (temp=locale.getName()) + "' rather than exception" );
14316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
14326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/*
14346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * @bug 4147552
14356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
14366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
14376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgLocaleTest::Test4147552()
14386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
14396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale locales [] = {     Locale("no", "NO"),
14406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            Locale("no", "NO", "B"),
14416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                             Locale("no", "NO", "NY")
14426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
14436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString edn("Norwegian (Norway, B)");
14456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString englishDisplayNames [] = {
14466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                                "Norwegian (Norway)",
14476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                                 edn,
14486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                                 // "Norwegian (Norway,B)",
14496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                                 //"Norwegian (Norway,NY)"
14506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                                 "Norwegian (Norway, NY)"
14516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
14526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString ndn("norsk (Norge, B");
14536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString norwegianDisplayNames [] = {
14546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                                "norsk (Norge)",
14556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                                "norsk (Norge, B)",
14566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                                //ndn,
14576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                                 "norsk (Noreg, NY)"
14586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                                 //"Norsk (Noreg, Nynorsk)"
14596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
14606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
14616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale saveLocale;
14636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale::setDefault(Locale::getEnglish(), status);
14646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (int32_t i = 0; i < 3; ++i) {
14656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        Locale loc = locales[i];
14666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString temp;
14676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (loc.getDisplayName(temp) != englishDisplayNames[i])
14686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           dataerrln("English display-name mismatch: expected " +
14696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                   englishDisplayNames[i] + ", got " + loc.getDisplayName(temp));
14706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (loc.getDisplayName(loc, temp) != norwegianDisplayNames[i])
14716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            dataerrln("Norwegian display-name mismatch: expected " +
14726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                   norwegianDisplayNames[i] + ", got " +
14736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                   loc.getDisplayName(loc, temp));
14746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
14756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale::setDefault(saveLocale, status);
14766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
14776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
14796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgLocaleTest::TestVariantParsing()
14806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
14816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale en_US_custom("en", "US", "De Anza_Cupertino_California_United States_Earth");
14826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString dispName("English (United States, DE ANZA_CUPERTINO_CALIFORNIA_UNITED STATES_EARTH)");
14846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString dispVar("DE ANZA_CUPERTINO_CALIFORNIA_UNITED STATES_EARTH");
14856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString got;
14876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    en_US_custom.getDisplayVariant(Locale::getUS(), got);
14896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(got != dispVar) {
14906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: getDisplayVariant()");
14916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Wanted: " + dispVar);
14926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Got   : " + got);
14936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
14946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    en_US_custom.getDisplayName(Locale::getUS(), got);
14966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(got != dispName) {
14976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        dataerrln("FAIL: getDisplayName()");
14986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        dataerrln("Wanted: " + dispName);
14996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        dataerrln("Got   : " + got);
15006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
15016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale shortVariant("fr", "FR", "foo");
15036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    shortVariant.getDisplayVariant(got);
15046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(got != "FOO") {
15066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: getDisplayVariant()");
15076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Wanted: foo");
15086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Got   : " + got);
15096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
15106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale bogusVariant("fr", "FR", "_foo");
15126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    bogusVariant.getDisplayVariant(got);
15136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(got != "FOO") {
15156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: getDisplayVariant()");
15166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Wanted: foo");
15176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Got   : " + got);
15186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
15196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale bogusVariant2("fr", "FR", "foo_");
15216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    bogusVariant2.getDisplayVariant(got);
15226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(got != "FOO") {
15246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: getDisplayVariant()");
15256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Wanted: foo");
15266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Got   : " + got);
15276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
15286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale bogusVariant3("fr", "FR", "_foo_");
15306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    bogusVariant3.getDisplayVariant(got);
15316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(got != "FOO") {
15336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: getDisplayVariant()");
15346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Wanted: foo");
15356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("Got   : " + got);
15366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
15376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
15386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_FORMATTING
15406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
15426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * @bug 4105828
15436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Currency symbol in zh is wrong.  We will test this at the NumberFormat
15446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * end to test the whole pipe.
15456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
15466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
15476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgLocaleTest::Test4105828()
15486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
15496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale LOC [] = { Locale::getChinese(),  Locale("zh", "CN", ""),
15506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                     Locale("zh", "TW", ""), Locale("zh", "HK", "") };
15516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
15526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (int32_t i = 0; i < 4; ++i) {
15536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        NumberFormat *fmt = NumberFormat::createPercentInstance(LOC[i], status);
15546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(U_FAILURE(status)) {
15556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            dataerrln("Couldn't create NumberFormat - %s", u_errorName(status));
15566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            return;
15576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
15586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString result;
15596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        FieldPosition pos(0);
15606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        fmt->format((int32_t)1, result, pos);
15616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString temp;
15626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(result != "100%") {
15636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln(UnicodeString("Percent for ") + LOC[i].getDisplayName(temp) + " should be 100%, got " + result);
15646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
15656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        delete fmt;
15666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
15676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
15686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
15706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org// Tests setBogus and isBogus APIs for Locale
15726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org// Jitterbug 1735
15736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
15746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgLocaleTest::TestSetIsBogus() {
15756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale l("en_US");
15766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    l.setToBogus();
15776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(l.isBogus() != TRUE) {
15786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("After setting bogus, didn't return TRUE");
15796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
15806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    l = "en_US"; // This should reset bogus
15816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(l.isBogus() != FALSE) {
15826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("After resetting bogus, didn't return FALSE");
15836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
15846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
15856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
15886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgLocaleTest::TestKeywordVariants(void) {
15896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const struct {
15906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char *localeID;
15916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char *expectedLocaleID;
15926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        //const char *expectedLocaleIDNoKeywords;
15936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        //const char *expectedCanonicalID;
15946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char *expectedKeywords[10];
15956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int32_t numKeywords;
15966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UErrorCode expectedStatus;
15976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } testCases[] = {
15986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {
15996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "de_DE@  currency = euro; C o ll A t i o n   = Phonebook   ; C alen dar = buddhist   ",
16006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "de_DE@calendar=buddhist;collation=Phonebook;currency=euro",
16016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            //"de_DE",
16026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            //"de_DE@calendar=buddhist;collation=Phonebook;currency=euro",
16036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            {"calendar", "collation", "currency"},
16046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            3,
16056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            U_ZERO_ERROR
16066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        },
16076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {
16086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "de_DE@euro",
16096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "de_DE@euro",
16106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            //"de_DE",
16116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            //"de_DE@currency=EUR",
16126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            {"","","","","","",""},
16136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0,
16146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            U_INVALID_FORMAT_ERROR /* must have '=' after '@' */
16156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
16166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
16176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
16186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t i = 0, j = 0;
16206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char *result = NULL;
16216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    StringEnumeration *keywords;
16226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t keyCount = 0;
16236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char *keyword = NULL;
16246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const UnicodeString *keywordString;
16256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t keywordLen = 0;
16266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for(i = 0; i < (int32_t)(sizeof(testCases)/sizeof(testCases[0])); i++) {
16286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        status = U_ZERO_ERROR;
16296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        Locale l(testCases[i].localeID);
16306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        keywords = l.createKeywords(status);
16316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(status != testCases[i].expectedStatus) {
16336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            err("Expected to get status %s. Got %s instead\n",
16346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                u_errorName(testCases[i].expectedStatus), u_errorName(status));
16356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
16366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        status = U_ZERO_ERROR;
16376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(keywords) {
16386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if((keyCount = keywords->count(status)) != testCases[i].numKeywords) {
16396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                err("Expected to get %i keywords, got %i\n", testCases[i].numKeywords, keyCount);
16406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
16416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if(keyCount) {
16426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                for(j = 0;;) {
16436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    if((j&1)==0) {
16446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        if((keyword = keywords->next(&keywordLen, status)) == NULL) {
16456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            break;
16466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        }
16476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        if(strcmp(keyword, testCases[i].expectedKeywords[j]) != 0) {
16486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            err("Expected to get keyword value %s, got %s\n", testCases[i].expectedKeywords[j], keyword);
16496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        }
16506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    } else {
16516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        if((keywordString = keywords->snext(status)) == NULL) {
16526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            break;
16536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        }
16546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        if(*keywordString != UnicodeString(testCases[i].expectedKeywords[j], "")) {
16556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            err("Expected to get keyword UnicodeString %s, got %s\n", testCases[i].expectedKeywords[j], keyword);
16566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        }
16576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    }
16586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    j++;
16596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    if(j == keyCount / 2) {
16616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        // replace keywords with a clone of itself
16626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        StringEnumeration *k2 = keywords->clone();
16636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        if(k2 == NULL || keyCount != k2->count(status)) {
16646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            errln("KeywordEnumeration.clone() failed");
16656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        } else {
16666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            delete keywords;
16676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            keywords = k2;
16686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        }
16696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    }
16706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                }
16716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                keywords->reset(status); // Make sure that reset works.
16726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                for(j = 0;;) {
16736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    if((keyword = keywords->next(&keywordLen, status)) == NULL) {
16746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        break;
16756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    }
16766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    if(strcmp(keyword, testCases[i].expectedKeywords[j]) != 0) {
16776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        err("Expected to get keyword value %s, got %s\n", testCases[i].expectedKeywords[j], keyword);
16786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    }
16796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    j++;
16806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                }
16816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
16826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            delete keywords;
16836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
16846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        result = l.getName();
16856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(uprv_strcmp(testCases[i].expectedLocaleID, result) != 0) {
16866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            err("Expected to get \"%s\" from \"%s\". Got \"%s\" instead\n",
16876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                testCases[i].expectedLocaleID, testCases[i].localeID, result);
16886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
16896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
16916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
16936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
16956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgLocaleTest::TestKeywordVariantParsing(void) {
16966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const struct {
16976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char *localeID;
16986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char *keyword;
16996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char *expectedValue;
17006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } testCases[] = {
17016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "de_DE@  C o ll A t i o n   = Phonebook   ", "collation", "Phonebook" },
17026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "de_DE", "collation", ""},
17036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "de_DE@collation= PHONEBOOK", "collation", "PHONEBOOK" },
17046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "de_DE@ currency = euro   ; CoLLaTion   = PHONEBOOk   ", "collation", "PHONEBOOk" },
17056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
17066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
17086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t i = 0;
17106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t resultLen = 0;
17116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    char buffer[256];
17126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for(i = 0; i < (int32_t)(sizeof(testCases)/sizeof(testCases[0])); i++) {
17146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        *buffer = 0;
17156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        Locale l(testCases[i].localeID);
17166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        resultLen = l.getKeywordValue(testCases[i].keyword, buffer, 256, status);
17176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        (void)resultLen;  // Suppress unused variable warning.
17186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(uprv_strcmp(testCases[i].expectedValue, buffer) != 0) {
17196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            err("Expected to extract \"%s\" from \"%s\" for keyword \"%s\". Got \"%s\" instead\n",
17206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                testCases[i].expectedValue, testCases[i].localeID, testCases[i].keyword, buffer);
17216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
17226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
17236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
17246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
17266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgLocaleTest::TestSetKeywordValue(void) {
17276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const struct {
17286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char *keyword;
17296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char *value;
17306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } testCases[] = {
17316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "collation", "phonebook" },
17326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "currency", "euro" },
17336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "calendar", "buddhist" }
17346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
17356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
17376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t i = 0;
17396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t resultLen = 0;
17406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    char buffer[256];
17416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale l(Locale::getGerman());
17436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for(i = 0; i < (int32_t)(sizeof(testCases)/sizeof(testCases[0])); i++) {
17456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        l.setKeywordValue(testCases[i].keyword, testCases[i].value, status);
17466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(U_FAILURE(status)) {
17476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            err("FAIL: Locale::setKeywordValue failed - %s\n", u_errorName(status));
17486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
17496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        *buffer = 0;
17516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        resultLen = l.getKeywordValue(testCases[i].keyword, buffer, 256, status);
17526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        (void)resultLen;  // Suppress unused variable warning.
17536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(uprv_strcmp(testCases[i].value, buffer) != 0) {
17546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            err("Expected to extract \"%s\" for keyword \"%s\". Got \"%s\" instead\n",
17556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                testCases[i].value, testCases[i].keyword, buffer);
17566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
17576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
17586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
17596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
17616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgLocaleTest::TestGetBaseName(void) {
17626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const struct {
17636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char *localeID;
17646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char *baseName;
17656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } testCases[] = {
17666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "de_DE@  C o ll A t i o n   = Phonebook   ", "de_DE" },
17676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "de@currency = euro; CoLLaTion   = PHONEBOOk", "de" },
17686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "ja@calendar = buddhist", "ja" }
17696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
17706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t i = 0;
17726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for(i = 0; i < (int32_t)(sizeof(testCases)/sizeof(testCases[0])); i++) {
17746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        Locale loc(testCases[i].localeID);
17756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(strcmp(testCases[i].baseName, loc.getBaseName())) {
17766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("For locale \"%s\" expected baseName \"%s\", but got \"%s\"",
17776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                testCases[i].localeID, testCases[i].baseName, loc.getBaseName());
17786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            return;
17796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
17806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
17816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
17826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
17846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Compare two locale IDs.  If they are equal, return 0.  If `string'
17856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * starts with `prefix' plus an additional element, that is, string ==
17866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * prefix + '_' + x, then return 1.  Otherwise return a value < 0.
17876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
17886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic UBool _loccmp(const char* string, const char* prefix) {
17896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t slen = (int32_t)strlen(string),
17906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            plen = (int32_t)strlen(prefix);
17916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t c = uprv_strncmp(string, prefix, plen);
17926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* 'root' is "less than" everything */
17936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (uprv_strcmp(prefix, "root") == 0) {
17946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return (uprv_strcmp(string, "root") == 0) ? 0 : 1;
17956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
17966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (c) return -1; /* mismatch */
17976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (slen == plen) return 0;
17986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (string[plen] == '_') return 1;
17996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    return -2; /* false match, e.g. "en_USX" cmp "en_US" */
18006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
18016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
18026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
18036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Check the relationship between requested locales, and report problems.
18046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * The caller specifies the expected relationships between requested
18056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * and valid (expReqValid) and between valid and actual (expValidActual).
18066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Possible values are:
18076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * "gt" strictly greater than, e.g., en_US > en
18086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * "ge" greater or equal,      e.g., en >= en
18096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * "eq" equal,                 e.g., en == en
18106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
18116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid LocaleTest::_checklocs(const char* label,
18126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            const char* req,
18136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            const Locale& validLoc,
18146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            const Locale& actualLoc,
18156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            const char* expReqValid,
18166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            const char* expValidActual) {
18176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char* valid = validLoc.getName();
18186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char* actual = actualLoc.getName();
18196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t reqValid = _loccmp(req, valid);
18206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t validActual = _loccmp(valid, actual);
18216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (((0 == uprv_strcmp(expReqValid, "gt") && reqValid > 0) ||
18226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org         (0 == uprv_strcmp(expReqValid, "ge") && reqValid >= 0) ||
18236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org         (0 == uprv_strcmp(expReqValid, "eq") && reqValid == 0)) &&
18246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ((0 == uprv_strcmp(expValidActual, "gt") && validActual > 0) ||
18256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org         (0 == uprv_strcmp(expValidActual, "ge") && validActual >= 0) ||
18266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org         (0 == uprv_strcmp(expValidActual, "eq") && validActual == 0))) {
18276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln("%s; req=%s, valid=%s, actual=%s",
18286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              label, req, valid, actual);
18296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
18306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        dataerrln("FAIL: %s; req=%s, valid=%s, actual=%s.  Require (R %s V) and (V %s A)",
18316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              label, req, valid, actual,
18326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              expReqValid, expValidActual);
18336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
18346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
18356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
18366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid LocaleTest::TestGetLocale(void) {
18376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_SERVICE
18386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode ec = U_ZERO_ERROR;
18396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char *req;
18406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale valid, actual, reqLoc;
18416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
18426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // Calendar
18436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_FORMATTING
18446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    req = "en_US_BROOKLYN";
18456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Calendar* cal = Calendar::createInstance(Locale::createFromName(req), ec);
18466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(ec)) {
18476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        dataerrln("FAIL: Calendar::createInstance failed - %s", u_errorName(ec));
18486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
18496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        valid = cal->getLocale(ULOC_VALID_LOCALE, ec);
18506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        actual = cal->getLocale(ULOC_ACTUAL_LOCALE, ec);
18516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (U_FAILURE(ec)) {
18526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("FAIL: Calendar::getLocale() failed");
18536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        } else {
18546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            _checklocs("Calendar", req, valid, actual);
18556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
18566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* Make sure that it fails correctly */
18576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ec = U_FILE_ACCESS_ERROR;
18586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (cal->getLocale(ULOC_VALID_LOCALE, ec).getName()[0] != 0) {
18596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("FAIL: Calendar::getLocale() failed to fail correctly. It should have returned \"\"");
18606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
18616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ec = U_ZERO_ERROR;
18626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
18636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete cal;
18646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
18656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
18666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // DecimalFormat, DecimalFormatSymbols
18676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_FORMATTING
18686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    req = "fr_FR_NICE";
18696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    NumberFormat* nf = NumberFormat::createInstance(Locale::createFromName(req), ec);
18706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(ec)) {
18716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        dataerrln("FAIL: NumberFormat::createInstance failed - %s", u_errorName(ec));
18726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
18736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        DecimalFormat* dec = dynamic_cast<DecimalFormat*>(nf);
18746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (dec == NULL) {
18756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("FAIL: NumberFormat::createInstance does not return a DecimalFormat");
18766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            return;
18776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
18786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        valid = dec->getLocale(ULOC_VALID_LOCALE, ec);
18796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        actual = dec->getLocale(ULOC_ACTUAL_LOCALE, ec);
18806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (U_FAILURE(ec)) {
18816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("FAIL: DecimalFormat::getLocale() failed");
18826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        } else {
18836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            _checklocs("DecimalFormat", req, valid, actual);
18846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
18856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
18866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const DecimalFormatSymbols* sym = dec->getDecimalFormatSymbols();
18876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (sym == NULL) {
18886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("FAIL: getDecimalFormatSymbols returned NULL");
18896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            return;
18906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
18916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        valid = sym->getLocale(ULOC_VALID_LOCALE, ec);
18926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        actual = sym->getLocale(ULOC_ACTUAL_LOCALE, ec);
18936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (U_FAILURE(ec)) {
18946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("FAIL: DecimalFormatSymbols::getLocale() failed");
18956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        } else {
18966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            _checklocs("DecimalFormatSymbols", req, valid, actual);
18976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
18986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
18996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete nf;
19006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
19016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // DateFormat, DateFormatSymbols
19036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_FORMATTING
19046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    req = "de_CH_LUCERNE";
19056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DateFormat* df =
19066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        DateFormat::createDateInstance(DateFormat::kDefault,
19076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                       Locale::createFromName(req));
19086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (df == 0){
19096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        dataerrln("Error calling DateFormat::createDateInstance()");
19106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
19116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        SimpleDateFormat* dat = dynamic_cast<SimpleDateFormat*>(df);
19126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (dat == NULL) {
19136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("FAIL: DateFormat::createInstance does not return a SimpleDateFormat");
19146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            return;
19156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
19166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        valid = dat->getLocale(ULOC_VALID_LOCALE, ec);
19176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        actual = dat->getLocale(ULOC_ACTUAL_LOCALE, ec);
19186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (U_FAILURE(ec)) {
19196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("FAIL: SimpleDateFormat::getLocale() failed");
19206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        } else {
19216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            _checklocs("SimpleDateFormat", req, valid, actual);
19226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
19236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const DateFormatSymbols* sym = dat->getDateFormatSymbols();
19256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (sym == NULL) {
19266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("FAIL: getDateFormatSymbols returned NULL");
19276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            return;
19286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
19296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        valid = sym->getLocale(ULOC_VALID_LOCALE, ec);
19306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        actual = sym->getLocale(ULOC_ACTUAL_LOCALE, ec);
19316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (U_FAILURE(ec)) {
19326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("FAIL: DateFormatSymbols::getLocale() failed");
19336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        } else {
19346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            _checklocs("DateFormatSymbols", req, valid, actual);
19356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
19366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
19376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete df;
19386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
19396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // BreakIterator
19416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_BREAK_ITERATION
19426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    req = "es_ES_BARCELONA";
19436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    reqLoc = Locale::createFromName(req);
19446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    BreakIterator* brk = BreakIterator::createWordInstance(reqLoc, ec);
19456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(ec)) {
19466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        dataerrln("FAIL: BreakIterator::createWordInstance failed - %s", u_errorName(ec));
19476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
19486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        valid = brk->getLocale(ULOC_VALID_LOCALE, ec);
19496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        actual = brk->getLocale(ULOC_ACTUAL_LOCALE, ec);
19506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (U_FAILURE(ec)) {
19516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("FAIL: BreakIterator::getLocale() failed");
19526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        } else {
19536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            _checklocs("BreakIterator", req, valid, actual);
19546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
19556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // After registering something, the behavior should be different
19576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        URegistryKey key = BreakIterator::registerInstance(brk, reqLoc, UBRK_WORD, ec);
19586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        brk = 0; // registerInstance adopts
19596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (U_FAILURE(ec)) {
19606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("FAIL: BreakIterator::registerInstance() failed");
19616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        } else {
19626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            brk = BreakIterator::createWordInstance(reqLoc, ec);
19636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (U_FAILURE(ec)) {
19646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                errln("FAIL: BreakIterator::createWordInstance failed");
19656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            } else {
19666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                valid = brk->getLocale(ULOC_VALID_LOCALE, ec);
19676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                actual = brk->getLocale(ULOC_ACTUAL_LOCALE, ec);
19686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                if (U_FAILURE(ec)) {
19696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    errln("FAIL: BreakIterator::getLocale() failed");
19706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                } else {
19716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    // N.B.: now expect valid==actual==req
19726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    _checklocs("BreakIterator(registered)",
19736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                               req, valid, actual, "eq", "eq");
19746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                }
19756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
19766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            // No matter what, unregister
19776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            BreakIterator::unregister(key, ec);
19786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (U_FAILURE(ec)) {
19796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                errln("FAIL: BreakIterator::unregister() failed");
19806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
19816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            delete brk;
19826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            brk = 0;
19836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
19846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // After unregistering, should behave normally again
19866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        brk = BreakIterator::createWordInstance(reqLoc, ec);
19876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (U_FAILURE(ec)) {
19886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("FAIL: BreakIterator::createWordInstance failed");
19896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        } else {
19906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            valid = brk->getLocale(ULOC_VALID_LOCALE, ec);
19916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            actual = brk->getLocale(ULOC_ACTUAL_LOCALE, ec);
19926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (U_FAILURE(ec)) {
19936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                errln("FAIL: BreakIterator::getLocale() failed");
19946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            } else {
19956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                _checklocs("BreakIterator(unregistered)", req, valid, actual);
19966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
19976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
19986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
19996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete brk;
20006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
20016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // Collator
20036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_COLLATION
20046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    req = "hi_IN_BHOPAL";
20056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    reqLoc = Locale::createFromName(req);
20066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Collator* coll = Collator::createInstance(reqLoc, ec);
20076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(ec)) {
20086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        dataerrln("FAIL: Collator::createInstance failed - %s", u_errorName(ec));
20096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
20106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        valid = coll->getLocale(ULOC_VALID_LOCALE, ec);
20116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        actual = coll->getLocale(ULOC_ACTUAL_LOCALE, ec);
20126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (U_FAILURE(ec)) {
20136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("FAIL: Collator::getLocale() failed");
20146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        } else {
20156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            _checklocs("Collator", req, valid, actual);
20166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
20176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // After registering something, the behavior should be different
20196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        URegistryKey key = Collator::registerInstance(coll, reqLoc, ec);
20206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        coll = 0; // registerInstance adopts
20216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (U_FAILURE(ec)) {
20226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("FAIL: Collator::registerInstance() failed");
20236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        } else {
20246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            coll = Collator::createInstance(reqLoc, ec);
20256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (U_FAILURE(ec)) {
20266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                errln("FAIL: Collator::createWordInstance failed");
20276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            } else {
20286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                valid = coll->getLocale(ULOC_VALID_LOCALE, ec);
20296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                actual = coll->getLocale(ULOC_ACTUAL_LOCALE, ec);
20306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                if (U_FAILURE(ec)) {
20316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    errln("FAIL: Collator::getLocale() failed");
20326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                } else {
20336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    // N.B.: now expect valid==actual==req
20346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    _checklocs("Collator(registered)",
20356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                               req, valid, actual, "eq", "eq");
20366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                }
20376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
20386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            // No matter what, unregister
20396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            Collator::unregister(key, ec);
20406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (U_FAILURE(ec)) {
20416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                errln("FAIL: Collator::unregister() failed");
20426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
20436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            delete coll;
20446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            coll = 0;
20456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
20466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // After unregistering, should behave normally again
20486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        coll = Collator::createInstance(reqLoc, ec);
20496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (U_FAILURE(ec)) {
20506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("FAIL: Collator::createInstance failed");
20516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        } else {
20526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            valid = coll->getLocale(ULOC_VALID_LOCALE, ec);
20536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            actual = coll->getLocale(ULOC_ACTUAL_LOCALE, ec);
20546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (U_FAILURE(ec)) {
20556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                errln("FAIL: Collator::getLocale() failed");
20566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            } else {
20576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                _checklocs("Collator(unregistered)", req, valid, actual);
20586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
20596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
20606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
20616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete coll;
20626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
20636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
20646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
20656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid LocaleTest::TestVariantWithOutCountry(void) {
20676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale loc("en","","POSIX");
20686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (0 != strcmp(loc.getVariant(), "POSIX")) {
20696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: en__POSIX didn't get parsed correctly - name is %s - expected %s got %s", loc.getName(), "POSIX", loc.getVariant());
20706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
20716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale loc2("en","","FOUR");
20726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (0 != strcmp(loc2.getVariant(), "FOUR")) {
20736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: en__FOUR didn't get parsed correctly - name is %s - expected %s got %s", loc2.getName(), "FOUR", loc2.getVariant());
20746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
20756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale loc3("en","Latn","","FOUR");
20766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (0 != strcmp(loc3.getVariant(), "FOUR")) {
20776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: en_Latn__FOUR didn't get parsed correctly - name is %s - expected %s got %s", loc3.getName(), "FOUR", loc3.getVariant());
20786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
20796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale loc4("","Latn","","FOUR");
20806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (0 != strcmp(loc4.getVariant(), "FOUR")) {
20816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: _Latn__FOUR didn't get parsed correctly - name is %s - expected %s got %s", loc4.getName(), "FOUR", loc4.getVariant());
20826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
20836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale loc5("","Latn","US","FOUR");
20846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (0 != strcmp(loc5.getVariant(), "FOUR")) {
20856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: _Latn_US_FOUR didn't get parsed correctly - name is %s - expected %s got %s", loc5.getName(), "FOUR", loc5.getVariant());
20866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
20876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Locale loc6("de-1901");
20886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (0 != strcmp(loc6.getVariant(), "1901")) {
20896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: de-1901 didn't get parsed correctly - name is %s - expected %s got %s", loc6.getName(), "1901", loc6.getVariant());
20906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
20916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
20926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic Locale _canonicalize(int32_t selector, /* 0==createFromName, 1==createCanonical, 2==Locale ct */
20946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            const char* localeID) {
20956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    switch (selector) {
20966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    case 0:
20976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return Locale::createFromName(localeID);
20986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    case 1:
20996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return Locale::createCanonical(localeID);
21006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    case 2:
21016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return Locale(localeID);
21026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    default:
21036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return Locale("");
21046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
21056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
21066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
21076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid LocaleTest::TestCanonicalization(void)
21086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
21096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const struct {
21106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char *localeID;    /* input */
21116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char *getNameID;   /* expected getName() result */
21126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char *canonicalID; /* expected canonicalize() result */
21136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } testCases[] = {
21146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "", "", "en_US_POSIX" },
21156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "C", "c", "en_US_POSIX" },
21166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "POSIX", "posix", "en_US_POSIX" },
21176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "ca_ES_PREEURO-with-extra-stuff-that really doesn't make any sense-unless-you're trying to increase code coverage",
21186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org          "ca_ES_PREEURO_WITH_EXTRA_STUFF_THAT REALLY DOESN'T MAKE ANY SENSE_UNLESS_YOU'RE TRYING TO INCREASE CODE COVERAGE",
21196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org          "ca_ES_PREEURO_WITH_EXTRA_STUFF_THAT REALLY DOESN'T MAKE ANY SENSE_UNLESS_YOU'RE TRYING TO INCREASE CODE COVERAGE"},
21206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "ca_ES_PREEURO", "ca_ES_PREEURO", "ca_ES@currency=ESP" },
21216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "de_AT_PREEURO", "de_AT_PREEURO", "de_AT@currency=ATS" },
21226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "de_DE_PREEURO", "de_DE_PREEURO", "de_DE@currency=DEM" },
21236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "de_LU_PREEURO", "de_LU_PREEURO", "de_LU@currency=LUF" },
21246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "el_GR_PREEURO", "el_GR_PREEURO", "el_GR@currency=GRD" },
21256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "en_BE_PREEURO", "en_BE_PREEURO", "en_BE@currency=BEF" },
21266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "en_IE_PREEURO", "en_IE_PREEURO", "en_IE@currency=IEP" },
21276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "es_ES_PREEURO", "es_ES_PREEURO", "es_ES@currency=ESP" },
21286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "eu_ES_PREEURO", "eu_ES_PREEURO", "eu_ES@currency=ESP" },
21296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "fi_FI_PREEURO", "fi_FI_PREEURO", "fi_FI@currency=FIM" },
21306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "fr_BE_PREEURO", "fr_BE_PREEURO", "fr_BE@currency=BEF" },
21316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "fr_FR_PREEURO", "fr_FR_PREEURO", "fr_FR@currency=FRF" },
21326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "fr_LU_PREEURO", "fr_LU_PREEURO", "fr_LU@currency=LUF" },
21336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "ga_IE_PREEURO", "ga_IE_PREEURO", "ga_IE@currency=IEP" },
21346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "gl_ES_PREEURO", "gl_ES_PREEURO", "gl_ES@currency=ESP" },
21356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "it_IT_PREEURO", "it_IT_PREEURO", "it_IT@currency=ITL" },
21366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "nl_BE_PREEURO", "nl_BE_PREEURO", "nl_BE@currency=BEF" },
21376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "nl_NL_PREEURO", "nl_NL_PREEURO", "nl_NL@currency=NLG" },
21386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "pt_PT_PREEURO", "pt_PT_PREEURO", "pt_PT@currency=PTE" },
21396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "de__PHONEBOOK", "de__PHONEBOOK", "de@collation=phonebook" },
21406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "en_GB_EURO", "en_GB_EURO", "en_GB@currency=EUR" },
21416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "en_GB@EURO", "en_GB@EURO", "en_GB@currency=EUR" }, /* POSIX ID */
21426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "es__TRADITIONAL", "es__TRADITIONAL", "es@collation=traditional" },
21436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "hi__DIRECT", "hi__DIRECT", "hi@collation=direct" },
21446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "ja_JP_TRADITIONAL", "ja_JP_TRADITIONAL", "ja_JP@calendar=japanese" },
21456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "th_TH_TRADITIONAL", "th_TH_TRADITIONAL", "th_TH@calendar=buddhist" },
21466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "zh_TW_STROKE", "zh_TW_STROKE", "zh_TW@collation=stroke" },
21476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "zh__PINYIN", "zh__PINYIN", "zh@collation=pinyin" },
21486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "zh@collation=pinyin", "zh@collation=pinyin", "zh@collation=pinyin" },
21496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "zh_CN@collation=pinyin", "zh_CN@collation=pinyin", "zh_CN@collation=pinyin" },
21506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "zh_CN_CA@collation=pinyin", "zh_CN_CA@collation=pinyin", "zh_CN_CA@collation=pinyin" },
21516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "en_US_POSIX", "en_US_POSIX", "en_US_POSIX" },
21526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "hy_AM_REVISED", "hy_AM_REVISED", "hy_AM_REVISED" },
21536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "no_NO_NY", "no_NO_NY", "no_NO_NY" /* not: "nn_NO" [alan ICU3.0] */ },
21546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "no@ny", "no@ny", "no__NY" /* not: "nn" [alan ICU3.0] */ }, /* POSIX ID */
21556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "no-no.utf32@B", "no_NO.utf32@B", "no_NO_B" /* not: "nb_NO_B" [alan ICU3.0] */ }, /* POSIX ID */
21566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "qz-qz@Euro", "qz_QZ@Euro", "qz_QZ@currency=EUR" }, /* qz-qz uses private use iso codes */
21576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // NOTE: uloc_getName() works on en-BOONT, but Locale() parser considers it BOGUS
21586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // TODO: unify this behavior
21596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "en-BOONT", "en__BOONT", "en__BOONT" }, /* registered name */
21606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "de-1901", "de__1901", "de__1901" }, /* registered name */
21616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "de-1906", "de__1906", "de__1906" }, /* registered name */
21626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "sr-SP-Cyrl", "sr_SP_CYRL", "sr_Cyrl_RS" }, /* .NET name */
21636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "sr-SP-Latn", "sr_SP_LATN", "sr_Latn_RS" }, /* .NET name */
21646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "sr_YU_CYRILLIC", "sr_YU_CYRILLIC", "sr_Cyrl_RS" }, /* Linux name */
21656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "uz-UZ-Cyrl", "uz_UZ_CYRL", "uz_Cyrl_UZ" }, /* .NET name */
21666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "uz-UZ-Latn", "uz_UZ_LATN", "uz_Latn_UZ" }, /* .NET name */
21676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "zh-CHS", "zh_CHS", "zh_Hans" }, /* .NET name */
21686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "zh-CHT", "zh_CHT", "zh_Hant" }, /* .NET name This may change back to zh_Hant */
21696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
21706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* posix behavior that used to be performed by getName */
21716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "mr.utf8", "mr.utf8", "mr" },
21726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "de-tv.koi8r", "de_TV.koi8r", "de_TV" },
21736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "x-piglatin_ML.MBE", "x-piglatin_ML.MBE", "x-piglatin_ML" },
21746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "i-cherokee_US.utf7", "i-cherokee_US.utf7", "i-cherokee_US" },
21756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "x-filfli_MT_FILFLA.gb-18030", "x-filfli_MT_FILFLA.gb-18030", "x-filfli_MT_FILFLA" },
21766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "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 */
21776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
21786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* fleshing out canonicalization */
21796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* trim space and sort keywords, ';' is separator so not present at end in canonical form */
21806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "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" },
21816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* already-canonical ids are not changed */
21826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "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" },
21836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* PRE_EURO and EURO conversions don't affect other keywords */
21846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "es_ES_PREEURO@CALendar=Japanese", "es_ES_PREEURO@calendar=Japanese", "es_ES@calendar=Japanese;currency=ESP" },
21856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "es_ES_EURO@SHOUT=zipeedeedoodah", "es_ES_EURO@shout=zipeedeedoodah", "es_ES@currency=EUR;shout=zipeedeedoodah" },
21866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* currency keyword overrides PRE_EURO and EURO currency */
21876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "es_ES_PREEURO@currency=EUR", "es_ES_PREEURO@currency=EUR", "es_ES@currency=EUR" },
21886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "es_ES_EURO@currency=ESP", "es_ES_EURO@currency=ESP", "es_ES@currency=ESP" },
21896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* norwegian is just too weird, if we handle things in their full generality */
21906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "no-Hant-GB_NY@currency=$$$", "no_Hant_GB_NY@currency=$$$", "no_Hant_GB_NY@currency=$$$" /* not: "nn_Hant_GB@currency=$$$" [alan ICU3.0] */ },
21916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
21926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* test cases reflecting internal resource bundle usage */
21936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "root@kw=foo", "root@kw=foo", "root@kw=foo" },
21946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "@calendar=gregorian", "@calendar=gregorian", "@calendar=gregorian" },
21956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "ja_JP@calendar=Japanese", "ja_JP@calendar=Japanese", "ja_JP@calendar=Japanese" }
21966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
21976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
21986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const char* label[] = { "createFromName", "createCanonical", "Locale" };
21996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t i, j;
22016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (i=0; i < (int)(sizeof(testCases)/sizeof(testCases[0])); i++) {
22036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for (j=0; j<3; ++j) {
22046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            const char* expected = (j==1) ? testCases[i].canonicalID : testCases[i].getNameID;
22056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            Locale loc = _canonicalize(j, testCases[i].localeID);
22066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            const char* getName = loc.isBogus() ? "BOGUS" : loc.getName();
22076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if(uprv_strcmp(expected, getName) != 0) {
22086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                errln("FAIL: %s(%s).getName() => \"%s\", expected \"%s\"",
22096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                      label[j], testCases[i].localeID, getName, expected);
22106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            } else {
22116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                logln("Ok: %s(%s) => \"%s\"",
22126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                      label[j], testCases[i].localeID, getName);
22136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
22146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
22156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
22166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
22176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid LocaleTest::TestCurrencyByDate(void)
22196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
22206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_FORMATTING
22216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
22226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UDate date = uprv_getUTCtime();
22236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	UChar TMP[4];
22246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	int32_t index = 0;
22256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	int32_t resLen = 0;
22266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString tempStr, resultStr;
22276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	// Cycle through historical currencies
22296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    date = (UDate)-630720000000.0; // pre 1961 - no currency defined
22306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    index = ucurr_countCurrencies("eo_AM", date, &status);
22316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (index != 0)
22326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	{
22336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		errcheckln(status, "FAIL: didn't return 0 for eo_AM - %s", u_errorName(status));
22346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	}
22356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    resLen = ucurr_forLocaleAndDate("eo_AM", date, index, TMP, 4, &status);
22366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (resLen != 0) {
22376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		errcheckln(status, "FAIL: eo_AM didn't return NULL - %s", u_errorName(status));
22386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
22396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    status = U_ZERO_ERROR;
22406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    date = (UDate)0.0; // 1970 - one currency defined
22426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    index = ucurr_countCurrencies("eo_AM", date, &status);
22436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (index != 1)
22446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	{
22456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		errcheckln(status, "FAIL: didn't return 1 for eo_AM - %s", u_errorName(status));
22466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	}
22476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    resLen = ucurr_forLocaleAndDate("eo_AM", date, index, TMP, 4, &status);
22486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	tempStr.setTo(TMP);
22496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    resultStr.setTo("SUR");
22506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (resultStr != tempStr) {
22516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errcheckln(status, "FAIL: didn't return SUR for eo_AM - %s", u_errorName(status));
22526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
22536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    date = (UDate)693792000000.0; // 1992 - one currency defined
22556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	index = ucurr_countCurrencies("eo_AM", date, &status);
22566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (index != 1)
22576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	{
22586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		errcheckln(status, "FAIL: didn't return 1 for eo_AM - %s", u_errorName(status));
22596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	}
22606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    resLen = ucurr_forLocaleAndDate("eo_AM", date, index, TMP, 4, &status);
22616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	tempStr.setTo(TMP);
22626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    resultStr.setTo("RUR");
22636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (resultStr != tempStr) {
22646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errcheckln(status, "FAIL: didn't return RUR for eo_AM - %s", u_errorName(status));
22656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
22666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	date = (UDate)977616000000.0; // post 1993 - one currency defined
22686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	index = ucurr_countCurrencies("eo_AM", date, &status);
22696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (index != 1)
22706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	{
22716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		errcheckln(status, "FAIL: didn't return 1 for eo_AM - %s", u_errorName(status));
22726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	}
22736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    resLen = ucurr_forLocaleAndDate("eo_AM", date, index, TMP, 4, &status);
22746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	tempStr.setTo(TMP);
22756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    resultStr.setTo("AMD");
22766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (resultStr != tempStr) {
22776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errcheckln(status, "FAIL: didn't return AMD for eo_AM - %s", u_errorName(status));
22786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
22796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // Locale AD has multiple currencies at once
22816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	date = (UDate)977616000000.0; // year 2001
22826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	index = ucurr_countCurrencies("eo_AD", date, &status);
22836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (index != 4)
22846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	{
22856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		errcheckln(status, "FAIL: didn't return 4 for eo_AD - %s", u_errorName(status));
22866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	}
22876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    resLen = ucurr_forLocaleAndDate("eo_AD", date, 1, TMP, 4, &status);
22886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	tempStr.setTo(TMP);
22896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    resultStr.setTo("EUR");
22906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (resultStr != tempStr) {
22916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errcheckln(status, "FAIL: didn't return EUR for eo_AD - %s", u_errorName(status));
22926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
22936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    resLen = ucurr_forLocaleAndDate("eo_AD", date, 2, TMP, 4, &status);
22946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	tempStr.setTo(TMP);
22956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    resultStr.setTo("ESP");
22966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (resultStr != tempStr) {
22976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errcheckln(status, "FAIL: didn't return ESP for eo_AD - %s", u_errorName(status));
22986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
22996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    resLen = ucurr_forLocaleAndDate("eo_AD", date, 3, TMP, 4, &status);
23006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	tempStr.setTo(TMP);
23016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    resultStr.setTo("FRF");
23026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (resultStr != tempStr) {
23036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errcheckln(status, "FAIL: didn't return FRF for eo_AD - %s", u_errorName(status));
23046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
23056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    resLen = ucurr_forLocaleAndDate("eo_AD", date, 4, TMP, 4, &status);
23066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	tempStr.setTo(TMP);
23076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    resultStr.setTo("ADP");
23086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (resultStr != tempStr) {
23096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errcheckln(status, "FAIL: didn't return ADP for eo_AD - %s", u_errorName(status));
23106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
23116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
23126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	date = (UDate)0.0; // year 1970
23136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	index = ucurr_countCurrencies("eo_AD", date, &status);
23146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (index != 3)
23156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	{
23166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org		errcheckln(status, "FAIL: didn't return 3 for eo_AD - %s", u_errorName(status));
23176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	}
23186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    resLen = ucurr_forLocaleAndDate("eo_AD", date, 1, TMP, 4, &status);
23196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	tempStr.setTo(TMP);
23206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    resultStr.setTo("ESP");
23216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (resultStr != tempStr) {
23226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errcheckln(status, "FAIL: didn't return ESP for eo_AD - %s", u_errorName(status));
23236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
23246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    resLen = ucurr_forLocaleAndDate("eo_AD", date, 2, TMP, 4, &status);
23256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org	tempStr.setTo(TMP);
23266f31ac30b9092fd02a8c97e5216cf53f3e4fae4