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*
86f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org* File CLOCTST.C
96f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org*
106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org* Modification History:
116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org*        Name                     Description
126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org*     Madhu Katragadda            Ported for C API
136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org******************************************************************************
146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org*/
156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "cloctst.h"
166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include <stdlib.h>
176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include <stdio.h>
186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include <string.h>
196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "cintltst.h"
206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "cstring.h"
216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "uparse.h"
226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "uresimp.h"
236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/putil.h"
256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/ubrk.h"
266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/uchar.h"
276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/ucol.h"
286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/udat.h"
296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/uloc.h"
306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/umsg.h"
316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/ures.h"
326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/uset.h"
336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/ustring.h"
346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/utypes.h"
356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/ulocdata.h"
366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/uldnames.h"
376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/parseerr.h" /* may not be included with some uconfig switches */
386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "udbgutil.h"
396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestNullDefault(void);
426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestNonexistentLanguageExemplars(void);
436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestLocDataErrorCodeChaining(void);
446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestLanguageExemplarsFallbacks(void);
456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestDisplayNameBrackets(void);
466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestUnicodeDefines(void);
486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid PrintDataTable();
506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/*---------------------------------------------------
526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  table of valid data
536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org --------------------------------------------------- */
546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define LOCALE_SIZE 9
556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define LOCALE_INFO_SIZE 28
566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic const char* const rawData2[LOCALE_INFO_SIZE][LOCALE_SIZE] = {
586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* language code */
596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {   "en",   "fr",   "ca",   "el",   "no",   "zh",   "de",   "es",  "ja"    },
606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* script code */
616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {   "",     "",     "",     "",     "",     "", "", "", ""  },
626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* country code */
636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {   "US",   "FR",   "ES",   "GR",   "NO",   "CN", "DE", "", "JP"    },
646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* variant code */
656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {   "",     "",     "",     "",     "NY",   "", "", "", ""      },
666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* full name */
676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {   "en_US",    "fr_FR",    "ca_ES",
686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "el_GR",    "no_NO_NY", "zh_Hans_CN",
696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "de_DE@collation=phonebook", "es@collation=traditional",  "ja_JP@calendar=japanese" },
706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* ISO-3 language */
716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {   "eng",  "fra",  "cat",  "ell",  "nor",  "zho", "deu", "spa", "jpn"   },
726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* ISO-3 country */
736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {   "USA",  "FRA",  "ESP",  "GRC",  "NOR",  "CHN", "DEU", "", "JPN"   },
746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* LCID */
756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {   "409", "40c", "403", "408", "814",  "804", "10407", "40a", "411"     },
766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* display language (English) */
786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {   "English",  "French",   "Catalan", "Greek",    "Norwegian", "Chinese", "German", "Spanish", "Japanese"    },
796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* display script code (English) */
806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {   "",     "",     "",     "",     "",     "Simplified Han", "", "", ""       },
816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* display country (English) */
826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {   "United States",    "France",   "Spain",  "Greece",   "Norway", "China", "Germany", "", "Japan"       },
836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* display variant (English) */
846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {   "",     "",     "",     "",     "NY",  "", "", "", ""       },
856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* display name (English) */
866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {   "English (United States)", "French (France)", "Catalan (Spain)",
876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "Greek (Greece)", "Norwegian (Norway, NY)", "Chinese (Simplified, China)",
886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "German (Germany, Sort Order=Phonebook Sort Order)", "Spanish (Sort Order=Traditional Sort Order)", "Japanese (Japan, Calendar=Japanese Calendar)" },
896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* display language (French) */
916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {   "anglais",  "fran\\u00E7ais",   "catalan", "grec",    "norv\\u00E9gien",    "chinois", "allemand", "espagnol", "japonais"     },
926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* display script code (French) */
936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {   "",     "",     "",     "",     "",     "sinogrammes simplifi\\u00e9s", "", "", ""         },
946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* display country (French) */
956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {   "\\u00C9tats-Unis",    "France",   "Espagne",  "Gr\\u00E8ce",   "Norv\\u00E8ge",    "Chine", "Allemagne", "", "Japon"       },
966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* display variant (French) */
976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {   "",     "",     "",     "",     "NY",   "", "", "", ""       },
986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* display name (French) */
996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {   "anglais (\\u00C9tats-Unis)", "fran\\u00E7ais (France)", "catalan (Espagne)",
1006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "grec (Gr\\u00E8ce)", "norv\\u00E9gien (Norv\\u00E8ge, NY)",  "chinois (simplifi\\u00e9, Chine)",
1016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "allemand (Allemagne, ordre de tri=Ordre de l\\u2019annuaire)", "espagnol (ordre de tri=Ordre traditionnel)", "japonais (Japon, calendrier=Calendrier japonais)" },
1026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* display language (Catalan) */
1046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {   "angl\\u00E8s", "franc\\u00E8s", "catal\\u00E0", "grec",  "noruec", "xin\\u00E8s", "alemany", "espanyol", "japon\\u00E8s"    },
1056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* display script code (Catalan) */
1066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {   "",     "",     "",     "",     "",     "han simplificat", "", "", ""         },
1076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* display country (Catalan) */
1086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {   "Estats Units", "Fran\\u00E7a", "Espanya",  "Gr\\u00E8cia", "Noruega",  "Xina", "Alemanya", "", "Jap\\u00F3"    },
1096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* display variant (Catalan) */
1106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {   "", "", "",                    "", "NY",    "", "", "", ""    },
1116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* display name (Catalan) */
1126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {   "angl\\u00E8s (Estats Units)", "franc\\u00E8s (Fran\\u00E7a)", "catal\\u00E0 (Espanya)",
1136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    "grec (Gr\\u00E8cia)", "noruec (Noruega, NY)", "xin\\u00E8s (simplificat, Xina)",
1146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    "alemany (Alemanya, ordenaci\\u00F3=ordre de la guia telef\\u00F2nica)", "espanyol (ordenaci\\u00F3=ordre tradicional)", "japon\\u00E8s (Jap\\u00F3, calendari=calendari japon\\u00e8s)" },
1156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* display language (Greek) */
1176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
1186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u0391\\u03b3\\u03b3\\u03bb\\u03b9\\u03ba\\u03ac",
1196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u0393\\u03b1\\u03bb\\u03bb\\u03b9\\u03ba\\u03ac",
1206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u039a\\u03b1\\u03c4\\u03b1\\u03bb\\u03b1\\u03bd\\u03b9\\u03ba\\u03ac",
1216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u0395\\u03bb\\u03bb\\u03b7\\u03bd\\u03b9\\u03ba\\u03ac",
1226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u039d\\u03bf\\u03c1\\u03b2\\u03b7\\u03b3\\u03b9\\u03ba\\u03ac",
1236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u039A\\u03B9\\u03BD\\u03B5\\u03B6\\u03B9\\u03BA\\u03AC",
1246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u0393\\u03B5\\u03C1\\u03BC\\u03B1\\u03BD\\u03B9\\u03BA\\u03AC",
1256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u0399\\u03C3\\u03C0\\u03B1\\u03BD\\u03B9\\u03BA\\u03AC",
1266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u0399\\u03B1\\u03C0\\u03C9\\u03BD\\u03B9\\u03BA\\u03AC"
1276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    },
1286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* display script code (Greek) */
1296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {   "",     "",     "",     "",     "", "\\u0391\\u03c0\\u03bb\\u03bf\\u03c0\\u03bf\\u03b9\\u03b7\\u03bc\\u03ad\\u03bd\\u03bf \\u03a7\\u03b1\\u03bd", "", "", "" },
1316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* display country (Greek) */
1326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
1336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u0397\\u03BD\\u03C9\\u03BC\\u03AD\\u03BD\\u03B5\\u03C2 \\u03A0\\u03BF\\u03BB\\u03B9\\u03C4\\u03B5\\u03AF\\u03B5\\u03C2",
1346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u0393\\u03b1\\u03bb\\u03bb\\u03af\\u03b1",
1356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u0399\\u03c3\\u03c0\\u03b1\\u03bd\\u03af\\u03b1",
1366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u0395\\u03bb\\u03bb\\u03ac\\u03b4\\u03b1",
1376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u039d\\u03bf\\u03c1\\u03b2\\u03b7\\u03b3\\u03af\\u03b1",
1386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u039A\\u03AF\\u03BD\\u03B1",
1396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u0393\\u03B5\\u03C1\\u03BC\\u03B1\\u03BD\\u03AF\\u03B1",
1406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "",
1416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u0399\\u03B1\\u03C0\\u03C9\\u03BD\\u03AF\\u03B1"
1426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    },
1436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* display variant (Greek) */
1446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {   "", "", "", "", "NY", "", "", "", ""    }, /* TODO: currently there is no translation for NY in Greek fix this test when we have it */
1456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* display name (Greek) */
1466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
1476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@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)",
1486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u0393\\u03b1\\u03bb\\u03bb\\u03b9\\u03ba\\u03ac (\\u0393\\u03b1\\u03bb\\u03bb\\u03af\\u03b1)",
1496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u039a\\u03b1\\u03c4\\u03b1\\u03bb\\u03b1\\u03bd\\u03b9\\u03ba\\u03ac (\\u0399\\u03c3\\u03c0\\u03b1\\u03bd\\u03af\\u03b1)",
1506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u0395\\u03bb\\u03bb\\u03b7\\u03bd\\u03b9\\u03ba\\u03ac (\\u0395\\u03bb\\u03bb\\u03ac\\u03b4\\u03b1)",
1516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u039d\\u03bf\\u03c1\\u03b2\\u03b7\\u03b3\\u03b9\\u03ba\\u03ac (\\u039d\\u03bf\\u03c1\\u03b2\\u03b7\\u03b3\\u03af\\u03b1, NY)",
1526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@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)",
1536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u0393\\u03b5\\u03c1\\u03bc\\u03b1\\u03bd\\u03b9\\u03ba\\u03ac (\\u0393\\u03b5\\u03c1\\u03bc\\u03b1\\u03bd\\u03af\\u03b1, \\u03a3\\u03b5\\u03b9\\u03c1\\u03ac \\u03c4\\u03b1\\u03be\\u03b9\\u03bd\\u03cc\\u03bc\\u03b7\\u03c3\\u03b7\\u03c2=\\u03a3\\u03b5\\u03b9\\u03c1\\u03ac \\u03c4\\u03b1\\u03be\\u03b9\\u03bd\\u03cc\\u03bc\\u03b7\\u03c3\\u03b7\\u03c2 \\u03c4\\u03b7\\u03bb\\u03b5\\u03c6\\u03c9\\u03bd\\u03b9\\u03ba\\u03bf\\u03cd \\u03ba\\u03b1\\u03c4\\u03b1\\u03bb\\u03cc\\u03b3\\u03bf\\u03c5)",
1546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u0399\\u03c3\\u03c0\\u03b1\\u03bd\\u03b9\\u03ba\\u03ac (\\u03a3\\u03b5\\u03b9\\u03c1\\u03ac \\u03c4\\u03b1\\u03be\\u03b9\\u03bd\\u03cc\\u03bc\\u03b7\\u03c3\\u03b7\\u03c2=\\u03a0\\u03b1\\u03c1\\u03b1\\u03b4\\u03bf\\u03c3\\u03b9\\u03b1\\u03ba\\u03ae \\u03c3\\u03b5\\u03b9\\u03c1\\u03ac \\u03c4\\u03b1\\u03be\\u03b9\\u03bd\\u03cc\\u03bc\\u03b7\\u03c3\\u03b7\\u03c2)",
1556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u0399\\u03b1\\u03c0\\u03c9\\u03bd\\u03b9\\u03ba\\u03ac (\\u0399\\u03b1\\u03c0\\u03c9\\u03bd\\u03af\\u03b1, \\u0397\\u03bc\\u03b5\\u03c1\\u03bf\\u03bb\\u03cc\\u03b3\\u03b9\\u03bf=\\u0399\\u03b1\\u03c0\\u03c9\\u03bd\\u03b9\\u03ba\\u03cc \\u03b7\\u03bc\\u03b5\\u03c1\\u03bf\\u03bb\\u03cc\\u03b3\\u03b9\\u03bf)"
1566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
1576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org};
1586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic UChar*** dataTable=0;
1606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgenum {
1616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ENGLISH = 0,
1626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    FRENCH = 1,
1636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    CATALAN = 2,
1646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    GREEK = 3,
1656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    NORWEGIAN = 4
1666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org};
1676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgenum {
1696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    LANG = 0,
1706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    SCRIPT = 1,
1716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    CTRY = 2,
1726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    VAR = 3,
1736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    NAME = 4,
1746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    LANG3 = 5,
1756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    CTRY3 = 6,
1766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    LCID = 7,
1776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DLANG_EN = 8,
1786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DSCRIPT_EN = 9,
1796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DCTRY_EN = 10,
1806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DVAR_EN = 11,
1816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DNAME_EN = 12,
1826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DLANG_FR = 13,
1836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DSCRIPT_FR = 14,
1846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DCTRY_FR = 15,
1856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DVAR_FR = 16,
1866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DNAME_FR = 17,
1876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DLANG_CA = 18,
1886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DSCRIPT_CA = 19,
1896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DCTRY_CA = 20,
1906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DVAR_CA = 21,
1916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DNAME_CA = 22,
1926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DLANG_EL = 23,
1936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DSCRIPT_EL = 24,
1946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DCTRY_EL = 25,
1956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DVAR_EL = 26,
1966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    DNAME_EL = 27
1976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org};
1986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define TESTCASE(name) addTest(root, &name, "tsutil/cloctst/" #name)
2006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid addLocaleTest(TestNode** root);
2026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid addLocaleTest(TestNode** root)
2046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
2056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestObsoleteNames); /* srl- move */
2066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestBasicGetters);
2076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestNullDefault);
2086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestPrefixes);
2096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestSimpleResourceInfo);
2106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestDisplayNames);
2116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestGetAvailableLocales);
2126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestDataDirectory);
2136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
2146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestISOFunctions);
2156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
2166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestISO3Fallback);
2176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestUninstalledISO3Names);
2186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestSimpleDisplayNames);
2196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestVariantParsing);
2206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestKeywordVariants);
2216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestKeywordVariantParsing);
2226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestCanonicalization);
2236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestKeywordSet);
2246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestKeywordSetError);
2256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestDisplayKeywords);
2266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestDisplayKeywordValues);
2276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestGetBaseName);
2286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_FILE_IO
2296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestGetLocale);
2306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
2316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestDisplayNameWarning);
2326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestNonexistentLanguageExemplars);
2336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestLocDataErrorCodeChaining);
2346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestLanguageExemplarsFallbacks);
2356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestCalendar);
2366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestDateFormat);
2376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestCollation);
2386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestULocale);
2396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestUResourceBundle);
2406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestDisplayName);
2416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestAcceptLanguage);
2426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestGetLocaleForLCID);
2436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestOrientation);
2446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestLikelySubtags);
2456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestToLanguageTag);
2466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestForLanguageTag);
2476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestTrailingNull);
2486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestUnicodeDefines);
2496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestEnglishExemplarCharacters);
2506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TESTCASE(TestDisplayNameBrackets);
2516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
2526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/* testing uloc(), uloc_getName(), uloc_getLanguage(), uloc_getVariant(), uloc_getCountry() */
2556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestBasicGetters() {
2566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t i;
2576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t cap;
2586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
2596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    char *testLocale = 0;
2606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    char *temp = 0, *name = 0;
2616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    log_verbose("Testing Basic Getters\n");
2626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (i = 0; i < LOCALE_SIZE; i++) {
2636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        testLocale=(char*)malloc(sizeof(char) * (strlen(rawData2[NAME][i])+1));
2646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        strcpy(testLocale,rawData2[NAME][i]);
2656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_verbose("Testing   %s  .....\n", testLocale);
2676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        cap=uloc_getLanguage(testLocale, NULL, 0, &status);
2686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(status==U_BUFFER_OVERFLOW_ERROR){
2696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            status=U_ZERO_ERROR;
2706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            temp=(char*)malloc(sizeof(char) * (cap+1));
2716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            uloc_getLanguage(testLocale, temp, cap+1, &status);
2726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
2736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(U_FAILURE(status)){
2746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("ERROR: in uloc_getLanguage  %s\n", myErrorName(status));
2756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
2766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (0 !=strcmp(temp,rawData2[LANG][i]))    {
2776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("  Language code mismatch: %s versus  %s\n", temp, rawData2[LANG][i]);
2786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
2796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        cap=uloc_getCountry(testLocale, temp, cap, &status);
2826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(status==U_BUFFER_OVERFLOW_ERROR){
2836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            status=U_ZERO_ERROR;
2846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            temp=(char*)realloc(temp, sizeof(char) * (cap+1));
2856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            uloc_getCountry(testLocale, temp, cap+1, &status);
2866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
2876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(U_FAILURE(status)){
2886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("ERROR: in uloc_getCountry  %s\n", myErrorName(status));
2896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
2906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (0 != strcmp(temp, rawData2[CTRY][i])) {
2916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err(" Country code mismatch:  %s  versus   %s\n", temp, rawData2[CTRY][i]);
2926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org          }
2946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        cap=uloc_getVariant(testLocale, temp, cap, &status);
2966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(status==U_BUFFER_OVERFLOW_ERROR){
2976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            status=U_ZERO_ERROR;
2986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            temp=(char*)realloc(temp, sizeof(char) * (cap+1));
2996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            uloc_getVariant(testLocale, temp, cap+1, &status);
3006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
3016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(U_FAILURE(status)){
3026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("ERROR: in uloc_getVariant  %s\n", myErrorName(status));
3036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
3046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (0 != strcmp(temp, rawData2[VAR][i])) {
3056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("Variant code mismatch:  %s  versus   %s\n", temp, rawData2[VAR][i]);
3066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
3076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        cap=uloc_getName(testLocale, NULL, 0, &status);
3096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(status==U_BUFFER_OVERFLOW_ERROR){
3106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            status=U_ZERO_ERROR;
3116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            name=(char*)malloc(sizeof(char) * (cap+1));
3126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            uloc_getName(testLocale, name, cap+1, &status);
3136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        } else if(status==U_ZERO_ERROR) {
3146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org          log_err("ERROR: in uloc_getName(%s,NULL,0,..), expected U_BUFFER_OVERFLOW_ERROR!\n", testLocale);
3156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
3166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(U_FAILURE(status)){
3176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("ERROR: in uloc_getName   %s\n", myErrorName(status));
3186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
3196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (0 != strcmp(name, rawData2[NAME][i])){
3206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err(" Mismatch in getName:  %s  versus   %s\n", name, rawData2[NAME][i]);
3216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
3226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        free(temp);
3246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        free(name);
3256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        free(testLocale);
3276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
3286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
3296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestNullDefault() {
3316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
3326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    char original[ULOC_FULLNAME_CAPACITY];
3336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    uprv_strcpy(original, uloc_getDefault());
3356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    uloc_setDefault("qq_BLA", &status);
3366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (uprv_strcmp(uloc_getDefault(), "qq_BLA") != 0) {
3376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err(" Mismatch in uloc_setDefault:  qq_BLA  versus   %s\n", uloc_getDefault());
3386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
3396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    uloc_setDefault(NULL, &status);
3406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (uprv_strcmp(uloc_getDefault(), original) != 0) {
3416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err(" uloc_setDefault(NULL, &status) didn't get the default locale back!\n");
3426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
3436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
3456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* Test that set & get of default locale work, and that
3466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     * default locales are cached and reused, and not overwritten.
3476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     */
3486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char *n_en_US;
3496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char *n_fr_FR;
3506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char *n2_en_US;
3516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        status = U_ZERO_ERROR;
3536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        uloc_setDefault("en_US", &status);
3546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        n_en_US = uloc_getDefault();
3556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (strcmp(n_en_US, "en_US") != 0) {
3566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("Wrong result from uloc_getDefault().  Expected \"en_US\", got \"%s\"\n", n_en_US);
3576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
3586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        uloc_setDefault("fr_FR", &status);
3606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        n_fr_FR = uloc_getDefault();
3616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (strcmp(n_en_US, "en_US") != 0) {
3626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("uloc_setDefault altered previously default string."
3636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "Expected \"en_US\", got \"%s\"\n",  n_en_US);
3646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
3656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (strcmp(n_fr_FR, "fr_FR") != 0) {
3666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("Wrong result from uloc_getDefault().  Expected \"fr_FR\", got %s\n",  n_fr_FR);
3676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
3686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        uloc_setDefault("en_US", &status);
3706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        n2_en_US = uloc_getDefault();
3716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (strcmp(n2_en_US, "en_US") != 0) {
3726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("Wrong result from uloc_getDefault().  Expected \"en_US\", got \"%s\"\n", n_en_US);
3736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
3746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (n2_en_US != n_en_US) {
3756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("Default locale cache failed to reuse en_US locale.\n");
3766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
3776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (U_FAILURE(status)) {
3796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("Failure returned from uloc_setDefault - \"%s\"\n", u_errorName(status));
3806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
3816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
3836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
3856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/* Test the i- and x- and @ and . functionality
3866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org*/
3876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define PREFIXBUFSIZ 128
3896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestPrefixes() {
3916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int row = 0;
3926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int n;
3936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char *loc, *expected;
3946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const char * const testData[][7] =
3966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
3976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* NULL canonicalize() column means "expect same as getName()" */
3986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {"sv", "", "FI", "AL", "sv-fi-al", "sv_FI_AL", NULL},
3996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {"en", "", "GB", "", "en-gb", "en_GB", NULL},
4006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {"i-hakka", "", "MT", "XEMXIJA", "i-hakka_MT_XEMXIJA", "i-hakka_MT_XEMXIJA", NULL},
4016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {"i-hakka", "", "CN", "", "i-hakka_CN", "i-hakka_CN", NULL},
4026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {"i-hakka", "", "MX", "", "I-hakka_MX", "i-hakka_MX", NULL},
4036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {"x-klingon", "", "US", "SANJOSE", "X-KLINGON_us_SANJOSE", "x-klingon_US_SANJOSE", NULL},
4046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {"zh", "Hans", "", "PINYIN", "zh-Hans-pinyin", "zh_Hans__PINYIN", "zh_Hans@collation=pinyin"},
4066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {"hy", "", "", "AREVMDA", "hy_AREVMDA", "hy__AREVMDA", NULL},
4076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {"de", "", "", "1901", "de-1901", "de__1901", NULL},
4096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {"mr", "", "", "", "mr.utf8", "mr.utf8", "mr"},
4106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {"de", "", "TV", "", "de-tv.koi8r", "de_TV.koi8r", "de_TV"},
4116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {"x-piglatin", "", "ML", "", "x-piglatin_ML.MBE", "x-piglatin_ML.MBE", "x-piglatin_ML"},  /* Multibyte English */
4126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {"i-cherokee", "","US", "", "i-Cherokee_US.utf7", "i-cherokee_US.utf7", "i-cherokee_US"},
4136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {"x-filfli", "", "MT", "FILFLA", "x-filfli_MT_FILFLA.gb-18030", "x-filfli_MT_FILFLA.gb-18030", "x-filfli_MT_FILFLA"},
4146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {"no", "", "NO", "NY", "no-no-ny.utf32@B", "no_NO_NY.utf32@B", "no_NO_NY_B"},
4156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {"no", "", "NO", "",  "no-no.utf32@B", "no_NO.utf32@B", "no_NO_B"},
4166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {"no", "", "",   "NY", "no__ny", "no__NY", NULL},
4176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {"no", "", "",   "", "no@ny", "no@ny", "no__NY"},
4186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {"el", "Latn", "", "", "el-latn", "el_Latn", NULL},
4196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {"en", "Cyrl", "RU", "", "en-cyrl-ru", "en_Cyrl_RU", NULL},
4206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {"zh", "Hant", "TW", "STROKE", "zh-hant_TW_STROKE", "zh_Hant_TW_STROKE", "zh_Hant_TW@collation=stroke"},
4216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {"qq", "Qqqq", "QQ", "QQ", "qq_Qqqq_QQ_QQ", "qq_Qqqq_QQ_QQ", NULL},
4226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {"qq", "Qqqq", "", "QQ", "qq_Qqqq__QQ", "qq_Qqqq__QQ", NULL},
4236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {"ab", "Cdef", "GH", "IJ", "ab_cdef_gh_ij", "ab_Cdef_GH_IJ", NULL}, /* total garbage */
4246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {NULL,NULL,NULL,NULL,NULL,NULL,NULL}
4266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
4276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const char * const testTitles[] = {
4296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "uloc_getLanguage()",
4306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "uloc_getScript()",
4316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "uloc_getCountry()",
4326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "uloc_getVariant()",
4336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "name",
4346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "uloc_getName()",
4356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "uloc_canonicalize()"
4366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
4376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    char buf[PREFIXBUFSIZ];
4396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t len;
4406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode err;
4416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for(row=0;testData[row][0] != NULL;row++) {
4446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        loc = testData[row][NAME];
4456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_verbose("Test #%d: %s\n", row, loc);
4466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        err = U_ZERO_ERROR;
4486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        len=0;
4496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        buf[0]=0;
4506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for(n=0;n<=(NAME+2);n++) {
4516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if(n==NAME) continue;
4526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            for(len=0;len<PREFIXBUFSIZ;len++) {
4546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                buf[len] = '%'; /* Set a tripwire.. */
4556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
4566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            len = 0;
4576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            switch(n) {
4596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            case LANG:
4606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                len = uloc_getLanguage(loc, buf, PREFIXBUFSIZ, &err);
4616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                break;
4626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            case SCRIPT:
4646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                len = uloc_getScript(loc, buf, PREFIXBUFSIZ, &err);
4656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                break;
4666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            case CTRY:
4686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                len = uloc_getCountry(loc, buf, PREFIXBUFSIZ, &err);
4696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                break;
4706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            case VAR:
4726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                len = uloc_getVariant(loc, buf, PREFIXBUFSIZ, &err);
4736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                break;
4746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            case NAME+1:
4766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                len = uloc_getName(loc, buf, PREFIXBUFSIZ, &err);
4776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                break;
4786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            case NAME+2:
4806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                len = uloc_canonicalize(loc, buf, PREFIXBUFSIZ, &err);
4816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                break;
4826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            default:
4846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                strcpy(buf, "**??");
4856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                len=4;
4866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
4876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if(U_FAILURE(err)) {
4896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                log_err("#%d: %s on %s: err %s\n",
4906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    row, testTitles[n], loc, u_errorName(err));
4916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            } else {
4926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                log_verbose("#%d: %s on %s: -> [%s] (length %d)\n",
4936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    row, testTitles[n], loc, buf, len);
4946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                if(len != (int32_t)strlen(buf)) {
4966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    log_err("#%d: %s on %s: -> [%s] (length returned %d, actual %d!)\n",
4976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        row, testTitles[n], loc, buf, len, strlen(buf)+1);
4986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                }
5006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                /* see if they smashed something */
5026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                if(buf[len+1] != '%') {
5036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    log_err("#%d: %s on %s: -> [%s] - wrote [%X] out ofbounds!\n",
5046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        row, testTitles[n], loc, buf, buf[len+1]);
5056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                }
5066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                expected = testData[row][n];
5086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                if (expected == NULL && n == (NAME+2)) {
5096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    /* NULL expected canonicalize() means "expect same as getName()" */
5106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    expected = testData[row][NAME+1];
5116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                }
5126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                if(strcmp(buf, expected)) {
5136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    log_err("#%d: %s on %s: -> [%s] (expected '%s'!)\n",
5146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        row, testTitles[n], loc, buf, expected);
5156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                }
5176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
5186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
5196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
5206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
5216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/* testing uloc_getISO3Language(), uloc_getISO3Country(),  */
5246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestSimpleResourceInfo() {
5256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t i;
5266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    char* testLocale = 0;
5276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar* expected = 0;
5286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char* temp;
5306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    char            temp2[20];
5316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    testLocale=(char*)malloc(sizeof(char) * 1);
5326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expected=(UChar*)malloc(sizeof(UChar) * 1);
5336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    setUpDataTable();
5356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    log_verbose("Testing getISO3Language and getISO3Country\n");
5366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (i = 0; i < LOCALE_SIZE; i++) {
5376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        testLocale=(char*)realloc(testLocale, sizeof(char) * (u_strlen(dataTable[NAME][i])+1));
5396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        u_austrcpy(testLocale, dataTable[NAME][i]);
5406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_verbose("Testing   %s ......\n", testLocale);
5426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        temp=uloc_getISO3Language(testLocale);
5446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expected=(UChar*)realloc(expected, sizeof(UChar) * (strlen(temp) + 1));
5456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        u_uastrcpy(expected,temp);
5466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (0 != u_strcmp(expected, dataTable[LANG3][i])) {
5476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("  ISO-3 language code mismatch:  %s versus  %s\n",  austrdup(expected),
5486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                austrdup(dataTable[LANG3][i]));
5496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
5506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        temp=uloc_getISO3Country(testLocale);
5526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expected=(UChar*)realloc(expected, sizeof(UChar) * (strlen(temp) + 1));
5536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        u_uastrcpy(expected,temp);
5546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (0 != u_strcmp(expected, dataTable[CTRY3][i])) {
5556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("  ISO-3 Country code mismatch:  %s versus  %s\n",  austrdup(expected),
5566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                austrdup(dataTable[CTRY3][i]));
5576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
5586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        sprintf(temp2, "%x", (int)uloc_getLCID(testLocale));
5596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (strcmp(temp2, rawData2[LCID][i]) != 0) {
5606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("LCID mismatch: %s versus %s\n", temp2 , rawData2[LCID][i]);
5616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
5626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
5636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    free(expected);
5656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    free(testLocale);
5666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    cleanUpDataTable();
5676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
5686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/* if len < 0, we convert until we hit UChar 0x0000, which is not output. will add trailing null
5706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * if there's room but won't be included in result.  result < 0 indicates an error.
5716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Returns the number of chars written (not those that would be written if there's enough room.*/
5726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic int32_t UCharsToEscapedAscii(const UChar* utext, int32_t len, char* resultChars, int32_t buflen) {
5736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const struct {
5746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        char escapedChar;
5756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UChar sourceVal;
5766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } ESCAPE_MAP[] = {
5776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /*a*/ {'a', 0x07},
5786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /*b*/ {'b', 0x08},
5796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /*e*/ {'e', 0x1b},
5806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /*f*/ {'f', 0x0c},
5816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /*n*/ {'n', 0x0a},
5826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /*r*/ {'r', 0x0d},
5836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /*t*/ {'t', 0x09},
5846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /*v*/ {'v', 0x0b}
5856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
5866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t ESCAPE_MAP_LENGTH = sizeof(ESCAPE_MAP)/sizeof(ESCAPE_MAP[0]);
5876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const char HEX_DIGITS[] = {
5886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        '0', '1', '2', '3', '4', '5', '6', '7',
5896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
5906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
5916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t i, j;
5926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t resultLen = 0;
5936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const int32_t limit = len<0 ? buflen : len; /* buflen is long enough to hit the buffer limit */
5946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const int32_t escapeLimit1 = buflen-2;
5956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const int32_t escapeLimit2 = buflen-6;
5966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar uc;
5976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(utext==NULL || resultChars==NULL || buflen<0) {
5996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return -1;
6006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
6016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for(i=0;i<limit && resultLen<buflen;++i) {
6036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        uc=utext[i];
6046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(len<0 && uc==0) {
6056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            break;
6066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
6076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(uc<0x20) {
6086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            for(j=0;j<ESCAPE_MAP_LENGTH && uc!=ESCAPE_MAP[j].sourceVal;j++) {
6096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
6106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if(j<ESCAPE_MAP_LENGTH) {
6116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                if(resultLen>escapeLimit1) {
6126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    break;
6136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                }
6146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                resultChars[resultLen++]='\\';
6156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                resultChars[resultLen++]=ESCAPE_MAP[j].escapedChar;
6166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                continue;
6176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
6186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        } else if(uc<0x7f) {
6196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            u_austrncpy(resultChars + resultLen, &uc, 1);
6206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            resultLen++;
6216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            continue;
6226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
6236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(resultLen>escapeLimit2) {
6256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            break;
6266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
6276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* have to escape the uchar */
6296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        resultChars[resultLen++]='\\';
6306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        resultChars[resultLen++]='u';
6316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        resultChars[resultLen++]=HEX_DIGITS[(uc>>12)&0xff];
6326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        resultChars[resultLen++]=HEX_DIGITS[(uc>>8)&0xff];
6336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        resultChars[resultLen++]=HEX_DIGITS[(uc>>4)&0xff];
6346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        resultChars[resultLen++]=HEX_DIGITS[uc&0xff];
6356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
6366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(resultLen<buflen) {
6386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        resultChars[resultLen] = 0;
6396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
6406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    return resultLen;
6426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
6436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/*
6456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Jitterbug 2439 -- markus 20030425
6466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org *
6476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * The lookup of display names must not fall back through the default
6486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * locale because that yields useless results.
6496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
6506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestDisplayNames()
6516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
6526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar buffer[100];
6536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode errorCode=U_ZERO_ERROR;
6546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t length;
6556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    log_verbose("Testing getDisplayName for different locales\n");
6566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    log_verbose("  In locale = en_US...\n");
6586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    doTestDisplayNames("en_US", DLANG_EN);
6596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    log_verbose("  In locale = fr_FR....\n");
6606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    doTestDisplayNames("fr_FR", DLANG_FR);
6616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    log_verbose("  In locale = ca_ES...\n");
6626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    doTestDisplayNames("ca_ES", DLANG_CA);
6636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    log_verbose("  In locale = gr_EL..\n");
6646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    doTestDisplayNames("el_GR", DLANG_EL);
6656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* test that the default locale has a display name for its own language */
6676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    errorCode=U_ZERO_ERROR;
6686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    length=uloc_getDisplayLanguage(NULL, NULL, buffer, LENGTHOF(buffer), &errorCode);
6696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(U_FAILURE(errorCode) || (length<=3 && buffer[0]<=0x7f)) {
6706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* check <=3 to reject getting the language code as a display name */
6716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_data_err("unable to get a display string for the language of the default locale - %s (Are you missing data?)\n", u_errorName(errorCode));
6726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
6736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* test that we get the language code itself for an unknown language, and a default warning */
6756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    errorCode=U_ZERO_ERROR;
6766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    length=uloc_getDisplayLanguage("qq", "rr", buffer, LENGTHOF(buffer), &errorCode);
6776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(errorCode!=U_USING_DEFAULT_WARNING || length!=2 || buffer[0]!=0x71 || buffer[1]!=0x71) {
6786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("error getting the display string for an unknown language - %s\n", u_errorName(errorCode));
6796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
6806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* test that we get a default warning for a display name where one component is unknown (4255) */
6826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    errorCode=U_ZERO_ERROR;
6836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    length=uloc_getDisplayName("qq_US_POSIX", "en_US", buffer, LENGTHOF(buffer), &errorCode);
6846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(errorCode!=U_USING_DEFAULT_WARNING) {
6856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("error getting the display name for a locale with an unknown language - %s\n", u_errorName(errorCode));
6866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
6876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
6896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int32_t i;
6906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const char *aLocale = "es@collation=traditional;calendar=japanese";
6916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const char *testL[] = { "en_US",
6926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "fr_FR",
6936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "ca_ES",
6946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "el_GR" };
6956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const char *expect[] = { "Spanish (Calendar=Japanese Calendar, Sort Order=Traditional Sort Order)", /* note sorted order of keywords */
6966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "espagnol (calendrier=Calendrier japonais, ordre de tri=Ordre traditionnel)",
6976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "espanyol (calendari=calendari japon\\u00e8s, ordenaci\\u00f3=ordre tradicional)",
6986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "\\u0399\\u03c3\\u03c0\\u03b1\\u03bd\\u03b9\\u03ba\\u03ac (\\u0397\\u03bc\\u03b5\\u03c1\\u03bf\\u03bb\\u03cc\\u03b3\\u03b9\\u03bf=\\u0399\\u03b1\\u03c0\\u03c9\\u03bd\\u03b9\\u03ba\\u03cc \\u03b7\\u03bc\\u03b5\\u03c1\\u03bf\\u03bb\\u03cc\\u03b3\\u03b9\\u03bf, \\u03a3\\u03b5\\u03b9\\u03c1\\u03ac \\u03c4\\u03b1\\u03be\\u03b9\\u03bd\\u03cc\\u03bc\\u03b7\\u03c3\\u03b7\\u03c2=\\u03a0\\u03b1\\u03c1\\u03b1\\u03b4\\u03bf\\u03c3\\u03b9\\u03b1\\u03ba\\u03ae \\u03c3\\u03b5\\u03b9\\u03c1\\u03ac \\u03c4\\u03b1\\u03be\\u03b9\\u03bd\\u03cc\\u03bc\\u03b7\\u03c3\\u03b7\\u03c2)" };
6996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UChar *expectBuffer;
7006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for(i=0;i<LENGTHOF(testL);i++) {
7026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errorCode = U_ZERO_ERROR;
7036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            uloc_getDisplayName(aLocale, testL[i], buffer, LENGTHOF(buffer), &errorCode);
7046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if(U_FAILURE(errorCode)) {
7056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                log_err("FAIL in uloc_getDisplayName(%s,%s,..) -> %s\n", aLocale, testL[i], u_errorName(errorCode));
7066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            } else {
7076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                expectBuffer = CharsToUChars(expect[i]);
7086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                if(u_strcmp(buffer,expectBuffer)) {
7096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    log_data_err("FAIL in uloc_getDisplayName(%s,%s,..) expected '%s' got '%s' (Are you missing data?)\n", aLocale, testL[i], expect[i], austrdup(buffer));
7106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                } else {
7116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    log_verbose("pass in uloc_getDisplayName(%s,%s,..) got '%s'\n", aLocale, testL[i], expect[i]);
7126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                }
7136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                free(expectBuffer);
7146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
7156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
7166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
7176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* test that we properly preflight and return data when there's a non-default pattern,
7196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       see ticket #8262. */
7206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
7216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int32_t i;
7226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const char *locale="az_Cyrl";
7236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const char *displayLocale="ja";
7246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const char *expectedChars =
7256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "\\u30a2\\u30bc\\u30eb\\u30d0\\u30a4\\u30b8\\u30e3\\u30f3\\u8a9e "
7266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                "(\\u30ad\\u30ea\\u30eb\\u6587\\u5b57)";
7276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UErrorCode ec=U_ZERO_ERROR;
7286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UChar result[256];
7296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int32_t len;
7306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int32_t preflightLen=uloc_getDisplayName(locale, displayLocale, NULL, 0, &ec);
7316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* inconvenient semantics when preflighting, this condition is expected... */
7326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(ec==U_BUFFER_OVERFLOW_ERROR) {
7336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            ec=U_ZERO_ERROR;
7346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
7356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        len=uloc_getDisplayName(locale, displayLocale, result, LENGTHOF(result), &ec);
7366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(U_FAILURE(ec)) {
7376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("uloc_getDisplayName(%s, %s...) returned error: %s",
7386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    locale, displayLocale, u_errorName(ec));
7396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        } else {
7406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            UChar *expected=CharsToUChars(expectedChars);
7416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            int32_t expectedLen=u_strlen(expected);
7426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if(len!=expectedLen) {
7446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                log_data_err("uloc_getDisplayName(%s, %s...) returned string of length %d, expected length %d",
7456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        locale, displayLocale, len, expectedLen);
7466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            } else if(preflightLen!=expectedLen) {
7476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                log_err("uloc_getDisplayName(%s, %s...) returned preflight length %d, expected length %d",
7486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        locale, displayLocale, preflightLen, expectedLen);
7496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            } else if(u_strncmp(result, expected, len)) {
7506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                int32_t cap=len*6+1;  /* worst case + space for trailing null */
7516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                char* resultChars=(char*)malloc(cap);
7526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                int32_t resultCharsLen=UCharsToEscapedAscii(result, len, resultChars, cap);
7536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                if(resultCharsLen<0 || resultCharsLen<cap-1) {
7546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    log_err("uloc_getDisplayName(%s, %s...) mismatch", locale, displayLocale);
7556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                } else {
7566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    log_err("uloc_getDisplayName(%s, %s...) returned '%s' but expected '%s'",
7576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            locale, displayLocale, resultChars, expectedChars);
7586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                }
7596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                free(resultChars);
7606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                resultChars=NULL;
7616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            } else {
7626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                /* test all buffer sizes */
7636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                for(i=len+1;i>=0;--i) {
7646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    len=uloc_getDisplayName(locale, displayLocale, result, i, &ec);
7656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    if(ec==U_BUFFER_OVERFLOW_ERROR) {
7666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        ec=U_ZERO_ERROR;
7676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    }
7686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    if(U_FAILURE(ec)) {
7696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        log_err("using buffer of length %d returned error %s", i, u_errorName(ec));
7706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        break;
7716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    }
7726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    if(len!=expectedLen) {
7736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        log_err("with buffer of length %d, expected length %d but got %d", i, expectedLen, len);
7746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        break;
7756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    }
7766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    /* There's no guarantee about what's in the buffer if we've overflowed, in particular,
7776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                     * we don't know that it's been filled, so no point in checking. */
7786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                }
7796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
7806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            free(expected);
7826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
7836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
7846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
7856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/* test for uloc_getAvialable()  and uloc_countAvilable()*/
7886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestGetAvailableLocales()
7896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
7906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char *locList;
7926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t locCount,i;
7936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    log_verbose("Testing the no of avialable locales\n");
7956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    locCount=uloc_countAvailable();
7966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (locCount == 0)
7976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_data_err("countAvailable() returned an empty list!\n");
7986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* use something sensible w/o hardcoding the count */
8006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    else if(locCount < 0){
8016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_data_err("countAvailable() returned a wrong value!= %d\n", locCount);
8026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
8036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    else{
8046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_info("Number of locales returned = %d\n", locCount);
8056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
8066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for(i=0;i<locCount;i++){
8076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        locList=uloc_getAvailable(i);
8086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_verbose(" %s\n", locList);
8106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
8116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
8126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/* test for u_getDataDirectory, u_setDataDirectory, uloc_getISO3Language */
8146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestDataDirectory()
8156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
8166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    char            oldDirectory[512];
8186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char     *temp,*testValue1,*testValue2,*testValue3;
8196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char path[40] ="d:\\icu\\source\\test\\intltest" U_FILE_SEP_STRING; /*give the required path */
8206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    log_verbose("Testing getDataDirectory()\n");
8226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    temp = u_getDataDirectory();
8236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    strcpy(oldDirectory, temp);
8246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    testValue1=uloc_getISO3Language("en_US");
8266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    log_verbose("first fetch of language retrieved  %s\n", testValue1);
8276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (0 != strcmp(testValue1,"eng")){
8296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("Initial check of ISO3 language failed: expected \"eng\", got  %s \n", testValue1);
8306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
8316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*defining the path for DataDirectory */
8336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    log_verbose("Testing setDataDirectory\n");
8346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    u_setDataDirectory( path );
8356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(strcmp(path, u_getDataDirectory())==0)
8366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_verbose("setDataDirectory working fine\n");
8376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    else
8386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("Error in setDataDirectory. Directory not set correctly - came back as [%s], expected [%s]\n", u_getDataDirectory(), path);
8396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    testValue2=uloc_getISO3Language("en_US");
8416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    log_verbose("second fetch of language retrieved  %s \n", testValue2);
8426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    u_setDataDirectory(oldDirectory);
8446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    testValue3=uloc_getISO3Language("en_US");
8456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    log_verbose("third fetch of language retrieved  %s \n", testValue3);
8466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (0 != strcmp(testValue3,"eng")) {
8486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       log_err("get/setDataDirectory() failed: expected \"eng\", got \" %s  \" \n", testValue3);
8496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
8506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
8516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/*=========================================================== */
8556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic UChar _NUL=0;
8576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void doTestDisplayNames(const char* displayLocale, int32_t compareIndex)
8596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
8606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
8616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t i;
8626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t maxresultsize;
8636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char *testLocale;
8656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar  *testLang  = 0;
8686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar  *testScript  = 0;
8696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar  *testCtry = 0;
8706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar  *testVar = 0;
8716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar  *testName = 0;
8726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar*  expectedLang = 0;
8756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar*  expectedScript = 0;
8766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar*  expectedCtry = 0;
8776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar*  expectedVar = 0;
8786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar*  expectedName = 0;
8796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgsetUpDataTable();
8816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for(i=0;i<LOCALE_SIZE; ++i)
8836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
8846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        testLocale=rawData2[NAME][i];
8856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_verbose("Testing.....  %s\n", testLocale);
8876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        maxresultsize=0;
8896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        maxresultsize=uloc_getDisplayLanguage(testLocale, displayLocale, NULL, maxresultsize, &status);
8906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(status==U_BUFFER_OVERFLOW_ERROR)
8916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {
8926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            status=U_ZERO_ERROR;
8936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            testLang=(UChar*)malloc(sizeof(UChar) * (maxresultsize+1));
8946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            uloc_getDisplayLanguage(testLocale, displayLocale, testLang, maxresultsize + 1, &status);
8956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
8966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        else
8976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {
8986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            testLang=&_NUL;
8996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
9006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(U_FAILURE(status)){
9016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("Error in getDisplayLanguage()  %s\n", myErrorName(status));
9026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
9036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        maxresultsize=0;
9056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        maxresultsize=uloc_getDisplayScript(testLocale, displayLocale, NULL, maxresultsize, &status);
9066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(status==U_BUFFER_OVERFLOW_ERROR)
9076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {
9086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            status=U_ZERO_ERROR;
9096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            testScript=(UChar*)malloc(sizeof(UChar) * (maxresultsize+1));
9106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            uloc_getDisplayScript(testLocale, displayLocale, testScript, maxresultsize + 1, &status);
9116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
9126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        else
9136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {
9146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            testScript=&_NUL;
9156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
9166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(U_FAILURE(status)){
9176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("Error in getDisplayScript()  %s\n", myErrorName(status));
9186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
9196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        maxresultsize=0;
9216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        maxresultsize=uloc_getDisplayCountry(testLocale, displayLocale, NULL, maxresultsize, &status);
9226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(status==U_BUFFER_OVERFLOW_ERROR)
9236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {
9246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            status=U_ZERO_ERROR;
9256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            testCtry=(UChar*)malloc(sizeof(UChar) * (maxresultsize+1));
9266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            uloc_getDisplayCountry(testLocale, displayLocale, testCtry, maxresultsize + 1, &status);
9276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
9286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        else
9296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {
9306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            testCtry=&_NUL;
9316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
9326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(U_FAILURE(status)){
9336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("Error in getDisplayCountry()  %s\n", myErrorName(status));
9346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
9356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        maxresultsize=0;
9376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        maxresultsize=uloc_getDisplayVariant(testLocale, displayLocale, NULL, maxresultsize, &status);
9386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(status==U_BUFFER_OVERFLOW_ERROR)
9396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {
9406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            status=U_ZERO_ERROR;
9416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            testVar=(UChar*)malloc(sizeof(UChar) * (maxresultsize+1));
9426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            uloc_getDisplayVariant(testLocale, displayLocale, testVar, maxresultsize + 1, &status);
9436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
9446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        else
9456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {
9466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            testVar=&_NUL;
9476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
9486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(U_FAILURE(status)){
9496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                log_err("Error in getDisplayVariant()  %s\n", myErrorName(status));
9506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
9516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        maxresultsize=0;
9536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        maxresultsize=uloc_getDisplayName(testLocale, displayLocale, NULL, maxresultsize, &status);
9546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(status==U_BUFFER_OVERFLOW_ERROR)
9556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {
9566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            status=U_ZERO_ERROR;
9576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            testName=(UChar*)malloc(sizeof(UChar) * (maxresultsize+1));
9586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            uloc_getDisplayName(testLocale, displayLocale, testName, maxresultsize + 1, &status);
9596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
9606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        else
9616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {
9626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            testName=&_NUL;
9636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
9646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(U_FAILURE(status)){
9656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("Error in getDisplayName()  %s\n", myErrorName(status));
9666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
9676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectedLang=dataTable[compareIndex][i];
9696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(u_strlen(expectedLang)== 0)
9706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            expectedLang=dataTable[DLANG_EN][i];
9716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectedScript=dataTable[compareIndex + 1][i];
9736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(u_strlen(expectedScript)== 0)
9746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            expectedScript=dataTable[DSCRIPT_EN][i];
9756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectedCtry=dataTable[compareIndex + 2][i];
9776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(u_strlen(expectedCtry)== 0)
9786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            expectedCtry=dataTable[DCTRY_EN][i];
9796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectedVar=dataTable[compareIndex + 3][i];
9816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(u_strlen(expectedVar)== 0)
9826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            expectedVar=dataTable[DVAR_EN][i];
9836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectedName=dataTable[compareIndex + 4][i];
9856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(u_strlen(expectedName) == 0)
9866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            expectedName=dataTable[DNAME_EN][i];
9876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (0 !=u_strcmp(testLang,expectedLang))  {
9896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_data_err(" Display Language mismatch: got %s expected %s displayLocale=%s (Are you missing data?)\n", austrdup(testLang), austrdup(expectedLang), displayLocale);
9906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
9916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (0 != u_strcmp(testScript,expectedScript))   {
9936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_data_err(" Display Script mismatch: got %s expected %s displayLocale=%s (Are you missing data?)\n", austrdup(testScript), austrdup(expectedScript), displayLocale);
9946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
9956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (0 != u_strcmp(testCtry,expectedCtry))   {
9976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_data_err(" Display Country mismatch: got %s expected %s displayLocale=%s (Are you missing data?)\n", austrdup(testCtry), austrdup(expectedCtry), displayLocale);
9986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
9996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (0 != u_strcmp(testVar,expectedVar))    {
10016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_data_err(" Display Variant mismatch: got %s expected %s displayLocale=%s (Are you missing data?)\n", austrdup(testVar), austrdup(expectedVar), displayLocale);
10026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
10036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(0 != u_strcmp(testName, expectedName))    {
10056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_data_err(" Display Name mismatch: got %s expected %s displayLocale=%s (Are you missing data?)\n", austrdup(testName), austrdup(expectedName), displayLocale);
10066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
10076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(testName!=&_NUL) {
10096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            free(testName);
10106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
10116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(testLang!=&_NUL) {
10126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            free(testLang);
10136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
10146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(testScript!=&_NUL) {
10156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            free(testScript);
10166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
10176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(testCtry!=&_NUL) {
10186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            free(testCtry);
10196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
10206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(testVar!=&_NUL) {
10216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            free(testVar);
10226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
10236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
10246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgcleanUpDataTable();
10256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
10266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/*------------------------------
10286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * TestDisplayNameBrackets
10296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
10306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgtypedef struct {
10326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char * displayLocale;
10336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char * namedRegion;
10346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char * namedLocale;
10356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char * regionName;
10366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char * localeName;
10376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org} DisplayNameBracketsItem;
10386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic const DisplayNameBracketsItem displayNameBracketsItems[] = {
10406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    { "en", "CC", "en_CC",      "Cocos (Keeling) Islands",  "English (Cocos [Keeling] Islands)"  },
10416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    { "en", "MM", "my_MM",      "Myanmar (Burma)",          "Burmese (Myanmar [Burma])"          },
10426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    { "en", "MM", "my_Mymr_MM", "Myanmar (Burma)",          "Burmese (Myanmar, Myanmar [Burma])" },
10436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    { "zh", "CC", "en_CC",      "\\u79D1\\u79D1\\u65AF\\uFF08\\u57FA\\u6797\\uFF09\\u7FA4\\u5C9B", "\\u82F1\\u6587\\uFF08\\u79D1\\u79D1\\u65AF\\uFF3B\\u57FA\\u6797\\uFF3D\\u7FA4\\u5C9B\\uFF09" },
10446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    { "zh", "CG", "fr_CG",      "\\u521A\\u679C\\uFF08\\u5E03\\uFF09",                             "\\u6CD5\\u6587\\uFF08\\u521A\\u679C\\uFF3B\\u5E03\\uFF3D\\uFF09" },
10456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    { NULL, NULL, NULL,         NULL,                       NULL                                 }
10466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org};
10476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgenum { kDisplayNameBracketsMax = 128 };
10496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestDisplayNameBrackets()
10516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
10526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const DisplayNameBracketsItem * itemPtr = displayNameBracketsItems;
10536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (; itemPtr->displayLocale != NULL; itemPtr++) {
10546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ULocaleDisplayNames * uldn;
10556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UErrorCode status;
10566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UChar expectRegionName[kDisplayNameBracketsMax];
10576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UChar expectLocaleName[kDisplayNameBracketsMax];
10586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UChar getName[kDisplayNameBracketsMax];
10596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int32_t ulen;
10606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        (void) u_unescape(itemPtr->regionName, expectRegionName, kDisplayNameBracketsMax);
10626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        (void) u_unescape(itemPtr->localeName, expectLocaleName, kDisplayNameBracketsMax);
10636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        status = U_ZERO_ERROR;
10656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ulen = uloc_getDisplayCountry(itemPtr->namedLocale, itemPtr->displayLocale, getName, kDisplayNameBracketsMax, &status);
10666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if ( U_FAILURE(status) || u_strcmp(getName, expectRegionName) != 0 ) {
10676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_data_err("uloc_getDisplayCountry for displayLocale %s and namedLocale %s returns unexpected name or status %s\n", itemPtr->displayLocale, itemPtr->namedLocale, myErrorName(status));
10686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
10696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        status = U_ZERO_ERROR;
10716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ulen = uloc_getDisplayName(itemPtr->namedLocale, itemPtr->displayLocale, getName, kDisplayNameBracketsMax, &status);
10726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if ( U_FAILURE(status) || u_strcmp(getName, expectLocaleName) != 0 ) {
10736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_data_err("uloc_getDisplayName for displayLocale %s and namedLocale %s returns unexpected name or status %s\n", itemPtr->displayLocale, itemPtr->namedLocale, myErrorName(status));
10746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
10756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_FORMATTING
10776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        status = U_ZERO_ERROR;
10786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        uldn = uldn_open(itemPtr->displayLocale, ULDN_STANDARD_NAMES, &status);
10796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (U_SUCCESS(status)) {
10806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            status = U_ZERO_ERROR;
10816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            ulen = uldn_regionDisplayName(uldn, itemPtr->namedRegion, getName, kDisplayNameBracketsMax, &status);
10826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if ( U_FAILURE(status) || u_strcmp(getName, expectRegionName) != 0 ) {
10836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                log_data_err("uldn_regionDisplayName for displayLocale %s and namedRegion %s returns unexpected name or status %s\n", itemPtr->displayLocale, itemPtr->namedRegion, myErrorName(status));
10846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
10856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            status = U_ZERO_ERROR;
10876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            ulen = uldn_localeDisplayName(uldn, itemPtr->namedLocale, getName, kDisplayNameBracketsMax, &status);
10886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if ( U_FAILURE(status) || u_strcmp(getName, expectLocaleName) != 0 ) {
10896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                log_data_err("uldn_localeDisplayName for displayLocale %s and namedLocale %s returns unexpected name or status %s\n", itemPtr->displayLocale, itemPtr->namedLocale, myErrorName(status));
10906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
10916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            uldn_close(uldn);
10936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        } else {
10946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_data_err("uldn_open fails for displayLocale %s, status=%s\n", itemPtr->displayLocale, u_errorName(status));
10956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
10966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
10976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
10986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
10996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/*------------------------------
11016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * TestISOFunctions
11026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
11036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
11056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/* test for uloc_getISOLanguages, uloc_getISOCountries */
11066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestISOFunctions()
11076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
11086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char* const* str=uloc_getISOLanguages();
11096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char* const* str1=uloc_getISOCountries();
11106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char* test;
11116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char *key = NULL;
11126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t count = 0, skipped = 0;
11136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t expect;
11146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UResourceBundle *res;
11156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UResourceBundle *subRes;
11166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
11176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*  test getISOLanguages*/
11196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*str=uloc_getISOLanguages(); */
11206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    log_verbose("Testing ISO Languages: \n");
11216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* use structLocale - this data is no longer in root */
11236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    res = ures_openDirect(loadTestData(&status), "structLocale", &status);
11246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    subRes = ures_getByKey(res, "Languages", NULL, &status);
11256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status)) {
11266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_data_err("There is an error in structLocale's ures_getByKey(\"Languages\"), status=%s\n", u_errorName(status));
11276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
11286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
11296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect = ures_getSize(subRes);
11316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for(count = 0; *(str+count) != 0; count++)
11326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
11336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        key = NULL;
11346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        test = *(str+count);
11356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        status = U_ZERO_ERROR;
11366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        do {
11386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            /* Skip over language tags. This API only returns language codes. */
11396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            skipped += (key != NULL);
11406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            ures_getNextString(subRes, NULL, &key, &status);
11416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
11426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        while (key != NULL && strchr(key, '_'));
11436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(key == NULL)
11456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            break;
11466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* TODO: Consider removing sh, which is deprecated */
11476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(strcmp(key,"root") == 0 || strcmp(key,"Fallback") == 0 || strcmp(key,"sh") == 0) {
11486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            ures_getNextString(subRes, NULL, &key, &status);
11496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            skipped++;
11506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
11516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if U_CHARSET_FAMILY==U_ASCII_FAMILY
11526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* This code only works on ASCII machines where the keys are stored in ASCII order */
11536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(strcmp(test,key)) {
11546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            /* The first difference usually implies the place where things get out of sync */
11556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("FAIL Language diff at offset %d, \"%s\" != \"%s\"\n", count, test, key);
11566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
11576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
11586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(!strcmp(test,"in"))
11606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("FAIL getISOLanguages() has obsolete language code %s\n", test);
11616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(!strcmp(test,"iw"))
11626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("FAIL getISOLanguages() has obsolete language code %s\n", test);
11636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(!strcmp(test,"ji"))
11646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("FAIL getISOLanguages() has obsolete language code %s\n", test);
11656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(!strcmp(test,"jw"))
11666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("FAIL getISOLanguages() has obsolete language code %s\n", test);
11676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(!strcmp(test,"sh"))
11686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("FAIL getISOLanguages() has obsolete language code %s\n", test);
11696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
11706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect -= skipped; /* Ignore the skipped resources from structLocale */
11726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(count!=expect) {
11746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("There is an error in getISOLanguages, got %d, expected %d (as per structLocale)\n", count, expect);
11756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
11766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    subRes = ures_getByKey(res, "Countries", subRes, &status);
11786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    log_verbose("Testing ISO Countries");
11796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    skipped = 0;
11806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect = ures_getSize(subRes) - 1; /* Skip ZZ */
11816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for(count = 0; *(str1+count) != 0; count++)
11826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
11836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        key = NULL;
11846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        test = *(str1+count);
11856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        do {
11866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            /* Skip over numeric UN tags. This API only returns ISO-3166 codes. */
11876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            skipped += (key != NULL);
11886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            ures_getNextString(subRes, NULL, &key, &status);
11896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
11906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        while (key != NULL && strlen(key) != 2);
11916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(key == NULL)
11936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            break;
11946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* TODO: Consider removing CS, which is deprecated */
11956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        while(strcmp(key,"QO") == 0 || strcmp(key,"QU") == 0 || strcmp(key,"CS") == 0) {
11966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            ures_getNextString(subRes, NULL, &key, &status);
11976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            skipped++;
11986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
11996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if U_CHARSET_FAMILY==U_ASCII_FAMILY
12006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* This code only works on ASCII machines where the keys are stored in ASCII order */
12016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(strcmp(test,key)) {
12026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            /* The first difference usually implies the place where things get out of sync */
12036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("FAIL Country diff at offset %d, \"%s\" != \"%s\"\n", count, test, key);
12046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
12056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
12066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(!strcmp(test,"FX"))
12076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("FAIL getISOCountries() has obsolete country code %s\n", test);
12086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(!strcmp(test,"YU"))
12096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("FAIL getISOCountries() has obsolete country code %s\n", test);
12106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(!strcmp(test,"ZR"))
12116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("FAIL getISOCountries() has obsolete country code %s\n", test);
12126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
12136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ures_getNextString(subRes, NULL, &key, &status);
12156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (strcmp(key, "ZZ") != 0) {
12166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("ZZ was expected to be the last entry in structLocale, but got %s\n", key);
12176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
12186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if U_CHARSET_FAMILY==U_EBCDIC_FAMILY
12196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* On EBCDIC machines, the numbers are sorted last. Account for those in the skipped value too. */
12206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    key = NULL;
12216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    do {
12226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* Skip over numeric UN tags. uloc_getISOCountries only returns ISO-3166 codes. */
12236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        skipped += (key != NULL);
12246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ures_getNextString(subRes, NULL, &key, &status);
12256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
12266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    while (U_SUCCESS(status) && key != NULL && strlen(key) != 2);
12276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
12286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expect -= skipped; /* Ignore the skipped resources from structLocale */
12296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(count!=expect)
12306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
12316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("There is an error in getISOCountries, got %d, expected %d \n", count, expect);
12326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
12336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ures_close(subRes);
12346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ures_close(res);
12356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
12366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
12376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void setUpDataTable()
12396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
12406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t i,j;
12416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    dataTable = (UChar***)(calloc(sizeof(UChar**),LOCALE_INFO_SIZE));
12426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (i = 0; i < LOCALE_INFO_SIZE; i++) {
12446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        dataTable[i] = (UChar**)(calloc(sizeof(UChar*),LOCALE_SIZE));
12456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for (j = 0; j < LOCALE_SIZE; j++){
12466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            dataTable[i][j] = CharsToUChars(rawData2[i][j]);
12476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
12486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
12496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
12506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void cleanUpDataTable()
12526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
12536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t i,j;
12546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(dataTable != NULL) {
12556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for (i=0; i<LOCALE_INFO_SIZE; i++) {
12566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            for(j = 0; j < LOCALE_SIZE; j++) {
12576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                free(dataTable[i][j]);
12586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
12596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            free(dataTable[i]);
12606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
12616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        free(dataTable);
12626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
12636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    dataTable = NULL;
12646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
12656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
12676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * @bug 4011756 4011380
12686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
12696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestISO3Fallback()
12706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
12716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char* test="xx_YY";
12726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char * result;
12746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    result = uloc_getISO3Language(test);
12766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* Conform to C API usage  */
12786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (!result || (result[0] != 0))
12806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org       log_err("getISO3Language() on xx_YY returned %s instead of \"\"");
12816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    result = uloc_getISO3Country(test);
12836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (!result || (result[0] != 0))
12856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("getISO3Country() on xx_YY returned %s instead of \"\"");
12866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
12876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
12896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * @bug 4118587
12906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
12916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestSimpleDisplayNames()
12926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
12936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  /*
12946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     This test is different from TestDisplayNames because TestDisplayNames checks
12956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     fallback behavior, combination of language and country names to form locale
12966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     names, and other stuff like that.  This test just checks specific language
12976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     and country codes to make sure we have the correct names for them.
12986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  */
12996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    char languageCodes[] [4] = { "he", "id", "iu", "ug", "yi", "za", "419" };
13006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char* languageNames [] = { "Hebrew", "Indonesian", "Inuktitut", "Uyghur", "Yiddish",
13016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                               "Zhuang", "419" };
13026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char* inLocale [] = { "en_US", "zh_Hant"};
13036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status=U_ZERO_ERROR;
13046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t i;
13066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t localeIndex = 0;
13076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (i = 0; i < 7; i++) {
13086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UChar *testLang=0;
13096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UChar *expectedLang=0;
13106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int size=0;
13116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (i == 6) {
13136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            localeIndex = 1; /* Use the second locale for the rest of the test. */
13146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
13156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        size=uloc_getDisplayLanguage(languageCodes[i], inLocale[localeIndex], NULL, size, &status);
13176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(status==U_BUFFER_OVERFLOW_ERROR) {
13186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            status=U_ZERO_ERROR;
13196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            testLang=(UChar*)malloc(sizeof(UChar) * (size + 1));
13206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            uloc_getDisplayLanguage(languageCodes[i], inLocale[localeIndex], testLang, size + 1, &status);
13216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
13226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectedLang=(UChar*)malloc(sizeof(UChar) * (strlen(languageNames[i])+1));
13236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        u_uastrcpy(expectedLang, languageNames[i]);
13246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (u_strcmp(testLang, expectedLang) != 0)
13256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_data_err("Got wrong display name for %s : Expected \"%s\", got \"%s\".\n",
13266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    languageCodes[i], languageNames[i], austrdup(testLang));
13276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        free(testLang);
13286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        free(expectedLang);
13296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
13306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
13326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
13346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * @bug 4118595
13356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
13366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestUninstalledISO3Names()
13376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
13386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  /* This test checks to make sure getISO3Language and getISO3Country work right
13396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     even for locales that are not installed. */
13406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const char iso2Languages [][4] = {     "am", "ba", "fy", "mr", "rn",
13416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                        "ss", "tw", "zu" };
13426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const char iso3Languages [][5] = {     "amh", "bak", "fry", "mar", "run",
13436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                        "ssw", "twi", "zul" };
13446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const char iso2Countries [][6] = {     "am_AF", "ba_BW", "fy_KZ", "mr_MO", "rn_MN",
13456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                        "ss_SB", "tw_TC", "zu_ZW" };
13466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const char iso3Countries [][4] = {     "AFG", "BWA", "KAZ", "MAC", "MNG",
13476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                        "SLB", "TCA", "ZWE" };
13486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t i;
13496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (i = 0; i < 8; i++) {
13516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      UErrorCode err = U_ZERO_ERROR;
13526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      const char *test;
13536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      test = uloc_getISO3Language(iso2Languages[i]);
13546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      if(strcmp(test, iso3Languages[i]) !=0 || U_FAILURE(err))
13556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org         log_err("Got wrong ISO3 code for %s : Expected \"%s\", got \"%s\". %s\n",
13566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                     iso2Languages[i], iso3Languages[i], test, myErrorName(err));
13576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
13586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (i = 0; i < 8; i++) {
13596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      UErrorCode err = U_ZERO_ERROR;
13606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      const char *test;
13616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      test = uloc_getISO3Country(iso2Countries[i]);
13626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org      if(strcmp(test, iso3Countries[i]) !=0 || U_FAILURE(err))
13636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org         log_err("Got wrong ISO3 code for %s : Expected \"%s\", got \"%s\". %s\n",
13646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                     iso2Countries[i], iso3Countries[i], test, myErrorName(err));
13656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
13666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
13676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestVariantParsing()
13706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
13716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const char* en_US_custom="en_US_De Anza_Cupertino_California_United States_Earth";
13726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const char* dispName="English (United States, DE ANZA_CUPERTINO_CALIFORNIA_UNITED STATES_EARTH)";
13736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const char* dispVar="DE ANZA_CUPERTINO_CALIFORNIA_UNITED STATES_EARTH";
13746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const char* shortVariant="fr_FR_foo";
13756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const char* bogusVariant="fr_FR__foo";
13766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const char* bogusVariant2="fr_FR_foo_";
13776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const char* bogusVariant3="fr_FR__foo_";
13786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar displayVar[100];
13816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar displayName[100];
13826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status=U_ZERO_ERROR;
13836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar* got=0;
13846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t size=0;
13856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    size=uloc_getDisplayVariant(en_US_custom, "en_US", NULL, size, &status);
13866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(status==U_BUFFER_OVERFLOW_ERROR) {
13876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        status=U_ZERO_ERROR;
13886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        got=(UChar*)realloc(got, sizeof(UChar) * (size+1));
13896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        uloc_getDisplayVariant(en_US_custom, "en_US", got, size + 1, &status);
13906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
13916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    else {
13926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("FAIL: Didn't get U_BUFFER_OVERFLOW_ERROR\n");
13936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
13946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    u_uastrcpy(displayVar, dispVar);
13956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(u_strcmp(got,displayVar)!=0) {
13966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("FAIL: getDisplayVariant() Wanted %s, got %s\n", dispVar, austrdup(got));
13976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
13986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    size=0;
13996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    size=uloc_getDisplayName(en_US_custom, "en_US", NULL, size, &status);
14006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(status==U_BUFFER_OVERFLOW_ERROR) {
14016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        status=U_ZERO_ERROR;
14026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        got=(UChar*)realloc(got, sizeof(UChar) * (size+1));
14036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        uloc_getDisplayName(en_US_custom, "en_US", got, size + 1, &status);
14046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
14056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    else {
14066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("FAIL: Didn't get U_BUFFER_OVERFLOW_ERROR\n");
14076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
14086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    u_uastrcpy(displayName, dispName);
14096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(u_strcmp(got,displayName)!=0) {
14106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (status == U_USING_DEFAULT_WARNING) {
14116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_data_err("FAIL: getDisplayName() got %s. Perhaps you are missing data?\n", u_errorName(status));
14126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        } else {
14136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("FAIL: getDisplayName() Wanted %s, got %s\n", dispName, austrdup(got));
14146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
14156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
14166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    size=0;
14186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    status=U_ZERO_ERROR;
14196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    size=uloc_getDisplayVariant(shortVariant, NULL, NULL, size, &status);
14206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(status==U_BUFFER_OVERFLOW_ERROR) {
14216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        status=U_ZERO_ERROR;
14226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        got=(UChar*)realloc(got, sizeof(UChar) * (size+1));
14236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        uloc_getDisplayVariant(shortVariant, NULL, got, size + 1, &status);
14246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
14256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    else {
14266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("FAIL: Didn't get U_BUFFER_OVERFLOW_ERROR\n");
14276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
14286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(strcmp(austrdup(got),"FOO")!=0) {
14296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("FAIL: getDisplayVariant()  Wanted: foo  Got: %s\n", austrdup(got));
14306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
14316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    size=0;
14326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    status=U_ZERO_ERROR;
14336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    size=uloc_getDisplayVariant(bogusVariant, NULL, NULL, size, &status);
14346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(status==U_BUFFER_OVERFLOW_ERROR) {
14356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        status=U_ZERO_ERROR;
14366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        got=(UChar*)realloc(got, sizeof(UChar) * (size+1));
14376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        uloc_getDisplayVariant(bogusVariant, NULL, got, size + 1, &status);
14386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
14396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    else {
14406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("FAIL: Didn't get U_BUFFER_OVERFLOW_ERROR\n");
14416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
14426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(strcmp(austrdup(got),"_FOO")!=0) {
14436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("FAIL: getDisplayVariant()  Wanted: _FOO  Got: %s\n", austrdup(got));
14446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
14456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    size=0;
14466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    status=U_ZERO_ERROR;
14476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    size=uloc_getDisplayVariant(bogusVariant2, NULL, NULL, size, &status);
14486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(status==U_BUFFER_OVERFLOW_ERROR) {
14496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        status=U_ZERO_ERROR;
14506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        got=(UChar*)realloc(got, sizeof(UChar) * (size+1));
14516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        uloc_getDisplayVariant(bogusVariant2, NULL, got, size + 1, &status);
14526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
14536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    else {
14546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("FAIL: Didn't get U_BUFFER_OVERFLOW_ERROR\n");
14556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
14566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(strcmp(austrdup(got),"FOO_")!=0) {
14576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("FAIL: getDisplayVariant()  Wanted: FOO_  Got: %s\n", austrdup(got));
14586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
14596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    size=0;
14606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    status=U_ZERO_ERROR;
14616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    size=uloc_getDisplayVariant(bogusVariant3, NULL, NULL, size, &status);
14626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(status==U_BUFFER_OVERFLOW_ERROR) {
14636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        status=U_ZERO_ERROR;
14646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        got=(UChar*)realloc(got, sizeof(UChar) * (size+1));
14656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        uloc_getDisplayVariant(bogusVariant3, NULL, got, size + 1, &status);
14666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
14676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    else {
14686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("FAIL: Didn't get U_BUFFER_OVERFLOW_ERROR\n");
14696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
14706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(strcmp(austrdup(got),"_FOO_")!=0) {
14716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("FAIL: getDisplayVariant()  Wanted: _FOO_  Got: %s\n", austrdup(got));
14726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
14736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    free(got);
14746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
14756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestObsoleteNames(void)
14786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
14796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t i;
14806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
14816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    char buff[256];
14826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const struct
14846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
14856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        char locale[9];
14866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        char lang3[4];
14876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        char lang[4];
14886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        char ctry3[4];
14896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        char ctry[4];
14906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } tests[] =
14916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
14926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "eng_USA", "eng", "en", "USA", "US" },
14936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "kok",  "kok", "kok", "", "" },
14946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "in",  "ind", "in", "", "" },
14956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "id",  "ind", "id", "", "" }, /* NO aliasing */
14966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "sh",  "srp", "sh", "", "" },
14976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "zz_CS",  "", "zz", "SCG", "CS" },
14986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "zz_FX",  "", "zz", "FXX", "FX" },
14996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "zz_RO",  "", "zz", "ROU", "RO" },
15006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "zz_TP",  "", "zz", "TMP", "TP" },
15016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "zz_TL",  "", "zz", "TLS", "TL" },
15026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "zz_ZR",  "", "zz", "ZAR", "ZR" },
15036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "zz_FXX",  "", "zz", "FXX", "FX" }, /* no aliasing. Doesn't go to PS(PSE). */
15046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "zz_ROM",  "", "zz", "ROU", "RO" },
15056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "zz_ROU",  "", "zz", "ROU", "RO" },
15066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "zz_ZAR",  "", "zz", "ZAR", "ZR" },
15076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "zz_TMP",  "", "zz", "TMP", "TP" },
15086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "zz_TLS",  "", "zz", "TLS", "TL" },
15096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "zz_YUG",  "", "zz", "YUG", "YU" },
15106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "mlt_PSE", "mlt", "mt", "PSE", "PS" },
15116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "iw", "heb", "iw", "", "" },
15126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "ji", "yid", "ji", "", "" },
15136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "jw", "jaw", "jw", "", "" },
15146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "sh", "srp", "sh", "", "" },
15156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "", "", "", "", "" }
15166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
15176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for(i=0;tests[i].locale[0];i++)
15196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
15206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char *locale;
15216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        locale = tests[i].locale;
15236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_verbose("** %s:\n", locale);
15246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        status = U_ZERO_ERROR;
15266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(strcmp(tests[i].lang3,uloc_getISO3Language(locale)))
15276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {
15286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("FAIL: uloc_getISO3Language(%s)==\t\"%s\",\t expected \"%s\"\n",
15296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                locale,  uloc_getISO3Language(locale), tests[i].lang3);
15306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
15316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        else
15326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {
15336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_verbose("   uloc_getISO3Language()==\t\"%s\"\n",
15346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                uloc_getISO3Language(locale) );
15356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
15366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        status = U_ZERO_ERROR;
15386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        uloc_getLanguage(locale, buff, 256, &status);
15396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(U_FAILURE(status))
15406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {
15416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("FAIL: error getting language from %s\n", locale);
15426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
15436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        else
15446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {
15456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if(strcmp(buff,tests[i].lang))
15466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            {
15476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                log_err("FAIL: uloc_getLanguage(%s)==\t\"%s\"\t expected \"%s\"\n",
15486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    locale, buff, tests[i].lang);
15496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
15506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            else
15516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            {
15526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                log_verbose("  uloc_getLanguage(%s)==\t%s\n", locale, buff);
15536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
15546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
15556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(strcmp(tests[i].lang3,uloc_getISO3Language(locale)))
15566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {
15576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("FAIL: uloc_getISO3Language(%s)==\t\"%s\",\t expected \"%s\"\n",
15586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                locale,  uloc_getISO3Language(locale), tests[i].lang3);
15596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
15606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        else
15616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {
15626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_verbose("   uloc_getISO3Language()==\t\"%s\"\n",
15636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                uloc_getISO3Language(locale) );
15646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
15656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(strcmp(tests[i].ctry3,uloc_getISO3Country(locale)))
15676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {
15686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("FAIL: uloc_getISO3Country(%s)==\t\"%s\",\t expected \"%s\"\n",
15696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                locale,  uloc_getISO3Country(locale), tests[i].ctry3);
15706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
15716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        else
15726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {
15736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_verbose("   uloc_getISO3Country()==\t\"%s\"\n",
15746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                uloc_getISO3Country(locale) );
15756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
15766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        status = U_ZERO_ERROR;
15786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        uloc_getCountry(locale, buff, 256, &status);
15796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(U_FAILURE(status))
15806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {
15816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("FAIL: error getting country from %s\n", locale);
15826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
15836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        else
15846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {
15856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if(strcmp(buff,tests[i].ctry))
15866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            {
15876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                log_err("FAIL: uloc_getCountry(%s)==\t\"%s\"\t expected \"%s\"\n",
15886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    locale, buff, tests[i].ctry);
15896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
15906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            else
15916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            {
15926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                log_verbose("  uloc_getCountry(%s)==\t%s\n", locale, buff);
15936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
15946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
15956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
15966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (uloc_getLCID("iw_IL") != uloc_getLCID("he_IL")) {
15986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("he,iw LCID mismatch: %X versus %X\n", uloc_getLCID("iw_IL"), uloc_getLCID("he_IL"));
15996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
16006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (uloc_getLCID("iw") != uloc_getLCID("he")) {
16026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("he,iw LCID mismatch: %X versus %X\n", uloc_getLCID("iw"), uloc_getLCID("he"));
16036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
16046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if 0
16066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    i = uloc_getLanguage("kok",NULL,0,&icu_err);
16086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(U_FAILURE(icu_err))
16096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
16106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("FAIL: Got %s trying to do uloc_getLanguage(kok)\n", u_errorName(icu_err));
16116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
16126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    icu_err = U_ZERO_ERROR;
16146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    uloc_getLanguage("kok",r1_buff,12,&icu_err);
16156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(U_FAILURE(icu_err))
16166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
16176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("FAIL: Got %s trying to do uloc_getLanguage(kok, buff)\n", u_errorName(icu_err));
16186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
16196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    r1_addr = (char *)uloc_getISO3Language("kok");
16216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    icu_err = U_ZERO_ERROR;
16236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (strcmp(r1_buff,"kok") != 0)
16246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
16256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("FAIL: uloc_getLanguage(kok)==%s not kok\n",r1_buff);
16266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        line--;
16276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
16286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    r1_addr = (char *)uloc_getISO3Language("in");
16296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    i = uloc_getLanguage(r1_addr,r1_buff,12,&icu_err);
16306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (strcmp(r1_buff,"id") != 0)
16316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
16326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        printf("uloc_getLanguage error (%s)\n",r1_buff);
16336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        line--;
16346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
16356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    r1_addr = (char *)uloc_getISO3Language("sh");
16366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    i = uloc_getLanguage(r1_addr,r1_buff,12,&icu_err);
16376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (strcmp(r1_buff,"sr") != 0)
16386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
16396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        printf("uloc_getLanguage error (%s)\n",r1_buff);
16406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        line--;
16416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
16426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    r1_addr = (char *)uloc_getISO3Country("zz_ZR");
16446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    strcpy(p1_buff,"zz_");
16456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    strcat(p1_buff,r1_addr);
16466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    i = uloc_getCountry(p1_buff,r1_buff,12,&icu_err);
16476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (strcmp(r1_buff,"ZR") != 0)
16486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
16496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        printf("uloc_getCountry error (%s)\n",r1_buff);
16506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        line--;
16516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
16526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    r1_addr = (char *)uloc_getISO3Country("zz_FX");
16536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    strcpy(p1_buff,"zz_");
16546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    strcat(p1_buff,r1_addr);
16556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    i = uloc_getCountry(p1_buff,r1_buff,12,&icu_err);
16566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (strcmp(r1_buff,"FX") != 0)
16576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
16586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        printf("uloc_getCountry error (%s)\n",r1_buff);
16596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        line--;
16606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
16616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
16636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
16656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestKeywordVariants(void)
16676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
16686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const struct {
16696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char *localeID;
16706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char *expectedLocaleID;
16716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char *expectedLocaleIDNoKeywords;
16726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char *expectedCanonicalID;
16736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char *expectedKeywords[10];
16746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int32_t numKeywords;
16756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UErrorCode expectedStatus; /* from uloc_openKeywords */
16766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } testCases[] = {
16776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {
16786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "de_DE@  currency = euro; C o ll A t i o n   = Phonebook   ; C alen dar = buddhist   ",
16796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "de_DE@calendar=buddhist;collation=Phonebook;currency=euro",
16806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "de_DE",
16816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "de_DE@calendar=buddhist;collation=Phonebook;currency=euro",
16826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            {"calendar", "collation", "currency"},
16836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            3,
16846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            U_ZERO_ERROR
16856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        },
16866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {
16876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "de_DE@euro",
16886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "de_DE@euro",
16896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "de_DE",
16906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "de_DE@currency=EUR",
16916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            {"","","","","","",""},
16926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0,
16936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            U_INVALID_FORMAT_ERROR /* must have '=' after '@' */
16946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        },
16956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {
16966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "de_DE@euro;collation=phonebook",
16976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "de_DE", /* error result; bad format */
16986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "de_DE", /* error result; bad format */
16996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "de_DE", /* error result; bad format */
17006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            {"","","","","","",""},
17016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            0,
17026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            U_INVALID_FORMAT_ERROR
17036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
17046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
17056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
17066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t i = 0, j = 0;
17086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t resultLen = 0;
17096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    char buffer[256];
17106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UEnumeration *keywords;
17116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t keyCount = 0;
17126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char *keyword = NULL;
17136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t keywordLen = 0;
17146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for(i = 0; i < sizeof(testCases)/sizeof(testCases[0]); i++) {
17166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        status = U_ZERO_ERROR;
17176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        *buffer = 0;
17186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        keywords = uloc_openKeywords(testCases[i].localeID, &status);
17196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(status != testCases[i].expectedStatus) {
17216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("Expected to uloc_openKeywords(\"%s\") => status %s. Got %s instead\n",
17226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    testCases[i].localeID,
17236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    u_errorName(testCases[i].expectedStatus), u_errorName(status));
17246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
17256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        status = U_ZERO_ERROR;
17266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(keywords) {
17276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if((keyCount = uenum_count(keywords, &status)) != testCases[i].numKeywords) {
17286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                log_err("Expected to get %i keywords, got %i\n", testCases[i].numKeywords, keyCount);
17296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
17306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if(keyCount) {
17316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                j = 0;
17326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                while((keyword = uenum_next(keywords, &keywordLen, &status))) {
17336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    if(strcmp(keyword, testCases[i].expectedKeywords[j]) != 0) {
17346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        log_err("Expected to get keyword value %s, got %s\n", testCases[i].expectedKeywords[j], keyword);
17356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    }
17366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    j++;
17376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                }
17386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                j = 0;
17396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                uenum_reset(keywords, &status);
17406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                while((keyword = uenum_next(keywords, &keywordLen, &status))) {
17416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    if(strcmp(keyword, testCases[i].expectedKeywords[j]) != 0) {
17426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        log_err("Expected to get keyword value %s, got %s\n", testCases[i].expectedKeywords[j], keyword);
17436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    }
17446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    j++;
17456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                }
17466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
17476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            uenum_close(keywords);
17486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
17496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        resultLen = uloc_getName(testCases[i].localeID, buffer, 256, &status);
17506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        (void)resultLen;    /* Suppress set but not used warning. */
17516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (uprv_strcmp(testCases[i].expectedLocaleID, buffer) != 0) {
17526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("Expected uloc_getName(\"%s\") => \"%s\"; got \"%s\"\n",
17536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    testCases[i].localeID, testCases[i].expectedLocaleID, buffer);
17546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
17556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        resultLen = uloc_canonicalize(testCases[i].localeID, buffer, 256, &status);
17566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (uprv_strcmp(testCases[i].expectedCanonicalID, buffer) != 0) {
17576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("Expected uloc_canonicalize(\"%s\") => \"%s\"; got \"%s\"\n",
17586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    testCases[i].localeID, testCases[i].expectedCanonicalID, buffer);
17596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
17606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
17616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
17636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestKeywordVariantParsing(void)
17656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
17666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const struct {
17676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char *localeID;
17686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char *keyword;
17696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char *expectedValue;
17706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } testCases[] = {
17716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "de_DE@  C o ll A t i o n   = Phonebook   ", "c o ll a t i o n", "Phonebook" },
17726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "de_DE", "collation", ""},
17736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "de_DE@collation=PHONEBOOK", "collation", "PHONEBOOK" },
17746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "de_DE@currency = euro; CoLLaTion   = PHONEBOOk", "collatiON", "PHONEBOOk" },
17756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
17766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
17786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t i = 0;
17806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t resultLen = 0;
17816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    char buffer[256];
17826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for(i = 0; i < sizeof(testCases)/sizeof(testCases[0]); i++) {
17846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        *buffer = 0;
17856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        resultLen = uloc_getKeywordValue(testCases[i].localeID, testCases[i].keyword, buffer, 256, &status);
17866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        (void)resultLen;    /* Suppress set but not used warning. */
17876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(uprv_strcmp(testCases[i].expectedValue, buffer) != 0) {
17886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("Expected to extract \"%s\" from \"%s\" for keyword \"%s\". Got \"%s\" instead\n",
17896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                testCases[i].expectedValue, testCases[i].localeID, testCases[i].keyword, buffer);
17906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
17916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
17926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
17936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic const struct {
17956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  const char *l; /* locale */
17966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  const char *k; /* kw */
17976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  const char *v; /* value */
17986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  const char *x; /* expected */
17996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org} kwSetTestCases[] = {
18006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if 1
18016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  { "en_US", "calendar", "japanese", "en_US@calendar=japanese" },
18026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  { "en_US@", "calendar", "japanese", "en_US@calendar=japanese" },
18036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  { "en_US@calendar=islamic", "calendar", "japanese", "en_US@calendar=japanese" },
18046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  { "en_US@calendar=slovakian", "calendar", "gregorian", "en_US@calendar=gregorian" }, /* don't know what this means, but it has the same # of chars as gregorian */
18056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  { "en_US@calendar=gregorian", "calendar", "japanese", "en_US@calendar=japanese" },
18066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  { "de", "Currency", "CHF", "de@currency=CHF" },
18076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  { "de", "Currency", "CHF", "de@currency=CHF" },
18086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
18096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  { "en_US@collation=phonebook", "calendar", "japanese", "en_US@calendar=japanese;collation=phonebook" },
18106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  { "en_US@calendar=japanese", "collation", "phonebook", "en_US@calendar=japanese;collation=phonebook" },
18116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  { "de@collation=phonebook", "Currency", "CHF", "de@collation=phonebook;currency=CHF" },
18126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  { "en_US@calendar=gregorian;collation=phonebook", "calendar", "japanese", "en_US@calendar=japanese;collation=phonebook" },
18136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  { "en_US@calendar=slovakian;collation=phonebook", "calendar", "gregorian", "en_US@calendar=gregorian;collation=phonebook" }, /* don't know what this means, but it has the same # of chars as gregorian */
18146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  { "en_US@calendar=slovakian;collation=videobook", "collation", "phonebook", "en_US@calendar=slovakian;collation=phonebook" }, /* don't know what this means, but it has the same # of chars as gregorian */
18156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  { "en_US@calendar=islamic;collation=phonebook", "calendar", "japanese", "en_US@calendar=japanese;collation=phonebook" },
18166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  { "de@collation=phonebook", "Currency", "CHF", "de@collation=phonebook;currency=CHF" },
18176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
18186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if 1
18196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  { "mt@a=0;b=1;c=2;d=3", "c","j", "mt@a=0;b=1;c=j;d=3" },
18206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  { "mt@a=0;b=1;c=2;d=3", "x","j", "mt@a=0;b=1;c=2;d=3;x=j" },
18216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  { "mt@a=0;b=1;c=2;d=3", "a","f", "mt@a=f;b=1;c=2;d=3" },
18226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  { "mt@a=0;aa=1;aaa=3", "a","x", "mt@a=x;aa=1;aaa=3" },
18236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  { "mt@a=0;aa=1;aaa=3", "aa","x", "mt@a=0;aa=x;aaa=3" },
18246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  { "mt@a=0;aa=1;aaa=3", "aaa","x", "mt@a=0;aa=1;aaa=x" },
18256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  { "mt@a=0;aa=1;aaa=3", "a","yy", "mt@a=yy;aa=1;aaa=3" },
18266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  { "mt@a=0;aa=1;aaa=3", "aa","yy", "mt@a=0;aa=yy;aaa=3" },
18276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  { "mt@a=0;aa=1;aaa=3", "aaa","yy", "mt@a=0;aa=1;aaa=yy" },
18286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
18296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if 1
18306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  /* removal tests */
18316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  /* 1. removal of item at end */
18326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  { "de@collation=phonebook;currency=CHF", "currency",   "", "de@collation=phonebook" },
18336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  { "de@collation=phonebook;currency=CHF", "currency", NULL, "de@collation=phonebook" },
18346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  /* 2. removal of item at beginning */
18356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  { "de@collation=phonebook;currency=CHF", "collation", "", "de@currency=CHF" },
18366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  { "de@collation=phonebook;currency=CHF", "collation", NULL, "de@currency=CHF" },
18376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  /* 3. removal of an item not there */
18386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  { "de@collation=phonebook;currency=CHF", "calendar", NULL, "de@collation=phonebook;currency=CHF" },
18396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  /* 4. removal of only item */
18406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  { "de@collation=phonebook", "collation", NULL, "de" },
18416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
18426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  { "de@collation=phonebook", "Currency", "CHF", "de@collation=phonebook;currency=CHF" }
18436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org};
18446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
18456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
18466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestKeywordSet(void)
18476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
18486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t i = 0;
18496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t resultLen = 0;
18506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    char buffer[1024];
18516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
18526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    char cbuffer[1024];
18536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
18546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for(i = 0; i < sizeof(kwSetTestCases)/sizeof(kwSetTestCases[0]); i++) {
18556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UErrorCode status = U_ZERO_ERROR;
18566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        memset(buffer,'%',1023);
18576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        strcpy(buffer, kwSetTestCases[i].l);
18586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
18596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        uloc_canonicalize(kwSetTestCases[i].l, cbuffer, 1023, &status);
18606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(strcmp(buffer,cbuffer)) {
18616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org          log_verbose("note: [%d] wasn't canonical, should be: '%s' not '%s'. Won't check for canonicity in output.\n", i, cbuffer, buffer);
18626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
18636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org          /* sanity check test case results for canonicity */
18646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        uloc_canonicalize(kwSetTestCases[i].x, cbuffer, 1023, &status);
18656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(strcmp(kwSetTestCases[i].x,cbuffer)) {
18666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org          log_err("%s:%d: ERROR: kwSetTestCases[%d].x = '%s', should be %s (must be canonical)\n", __FILE__, __LINE__, i, kwSetTestCases[i].x, cbuffer);
18676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
18686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
18696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        resultLen = uloc_setKeywordValue(kwSetTestCases[i].k, kwSetTestCases[i].v, buffer, 1023, &status);
18706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(U_FAILURE(status)) {
18716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org          log_err("Err on test case %d: got error %s\n", i, u_errorName(status));
18726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org          continue;
18736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
18746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(strcmp(buffer,kwSetTestCases[i].x) || ((int32_t)strlen(buffer)!=resultLen)) {
18756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org          log_err("FAIL: #%d: %s + [%s=%s] -> %s (%d) expected %s (%d)\n", i, kwSetTestCases[i].l, kwSetTestCases[i].k,
18766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  kwSetTestCases[i].v, buffer, resultLen, kwSetTestCases[i].x, strlen(buffer));
18776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        } else {
18786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org          log_verbose("pass: #%d: %s + [%s=%s] -> %s\n", i, kwSetTestCases[i].l, kwSetTestCases[i].k, kwSetTestCases[i].v,buffer);
18796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
18806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
18816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
18826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
18836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestKeywordSetError(void)
18846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
18856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    char buffer[1024];
18866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status;
18876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t res;
18886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t i;
18896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t blen;
18906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
18916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* 0-test whether an error condition modifies the buffer at all */
18926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    blen=0;
18936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    i=0;
18946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    memset(buffer,'%',1023);
18956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    status = U_ZERO_ERROR;
18966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    res = uloc_setKeywordValue(kwSetTestCases[i].k, kwSetTestCases[i].v, buffer, blen, &status);
18976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(status != U_ILLEGAL_ARGUMENT_ERROR) {
18986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("expected illegal err got %s\n", u_errorName(status));
18996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
19006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
19016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*  if(res!=strlen(kwSetTestCases[i].x)) {
19026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    log_err("expected result %d got %d\n", strlen(kwSetTestCases[i].x), res);
19036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    return;
19046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } */
19056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(buffer[blen]!='%') {
19066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_err("Buffer byte %d was modified: now %c\n", blen, buffer[blen]);
19076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
19086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
19096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    log_verbose("0-buffer modify OK\n");
19106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for(i=0;i<=2;i++) {
19126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* 1- test a short buffer with growing text */
19136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        blen=(int32_t)strlen(kwSetTestCases[i].l)+1;
19146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        memset(buffer,'%',1023);
19156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        strcpy(buffer,kwSetTestCases[i].l);
19166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        status = U_ZERO_ERROR;
19176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        res = uloc_setKeywordValue(kwSetTestCases[i].k, kwSetTestCases[i].v, buffer, blen, &status);
19186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(status != U_BUFFER_OVERFLOW_ERROR) {
19196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("expected buffer overflow on buffer %d got %s, len %d (%s + [%s=%s])\n", blen, u_errorName(status), res, kwSetTestCases[i].l, kwSetTestCases[i].k, kwSetTestCases[i].v);
19206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            return;
19216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
19226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(res!=(int32_t)strlen(kwSetTestCases[i].x)) {
19236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("expected result %d got %d\n", strlen(kwSetTestCases[i].x), res);
19246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            return;
19256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
19266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(buffer[blen]!='%') {
19276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("Buffer byte %d was modified: now %c\n", blen, buffer[blen]);
19286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            return;
19296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
19306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_verbose("1/%d-buffer modify OK\n",i);
19316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
19326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for(i=3;i<=4;i++) {
19346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* 2- test a short buffer - text the same size or shrinking   */
19356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        blen=(int32_t)strlen(kwSetTestCases[i].l)+1;
19366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        memset(buffer,'%',1023);
19376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        strcpy(buffer,kwSetTestCases[i].l);
19386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        status = U_ZERO_ERROR;
19396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        res = uloc_setKeywordValue(kwSetTestCases[i].k, kwSetTestCases[i].v, buffer, blen, &status);
19406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(status != U_ZERO_ERROR) {
19416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("expected zero error got %s\n", u_errorName(status));
19426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            return;
19436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
19446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(buffer[blen+1]!='%') {
19456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("Buffer byte %d was modified: now %c\n", blen+1, buffer[blen+1]);
19466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            return;
19476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
19486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(res!=(int32_t)strlen(kwSetTestCases[i].x)) {
19496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("expected result %d got %d\n", strlen(kwSetTestCases[i].x), res);
19506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            return;
19516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
19526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(strcmp(buffer,kwSetTestCases[i].x) || ((int32_t)strlen(buffer)!=res)) {
19536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_err("FAIL: #%d: %s + [%s=%s] -> %s (%d) expected %s (%d)\n", i, kwSetTestCases[i].l, kwSetTestCases[i].k,
19546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                kwSetTestCases[i].v, buffer, res, kwSetTestCases[i].x, strlen(buffer));
19556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        } else {
19566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            log_verbose("pass: #%d: %s + [%s=%s] -> %s\n", i, kwSetTestCases[i].l, kwSetTestCases[i].k, kwSetTestCases[i].v,
19576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                buffer);
19586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
19596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        log_verbose("2/%d-buffer modify OK\n",i);
19606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
19616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
19626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic int32_t _canonicalize(int32_t selector, /* 0==getName, 1==canonicalize */
19646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                             const char* localeID,
19656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                             char* result,
19666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                             int32_t resultCapacity,
19676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                             UErrorCode* ec) {
19686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* YOU can change this to use function pointers if you like */
19696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    switch (selector) {
19706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    case 0:
19716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return uloc_getName(localeID, result, resultCapacity, ec);
19726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    case 1:
19736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return uloc_canonicalize(localeID, result, resultCapacity, ec);
19746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    default:
19756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return -1;
19766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
19776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
19786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestCanonicalization(void)
19806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
19816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const struct {
19826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char *localeID;    /* input */
19836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char *getNameID;   /* expected getName() result */
19846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char *canonicalID; /* expected canonicalize() result */
19856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } testCases[] = {
19866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "ca_ES_PREEURO-with-extra-stuff-that really doesn't make any sense-unless-you're trying to increase code coverage",
19876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org          "ca_ES_PREEURO_WITH_EXTRA_STUFF_THAT REALLY DOESN'T MAKE ANY SENSE_UNLESS_YOU'RE TRYING TO INCREASE CODE COVERAGE",
19886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org          "ca_ES_PREEURO_WITH_EXTRA_STUFF_THAT REALLY DOESN'T MAKE ANY SENSE_UNLESS_YOU'RE TRYING TO INCREASE CODE COVERAGE"},
19896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "ca_ES_PREEURO", "ca_ES_PREEURO", "ca_ES@currency=ESP" },
19906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "de_AT_PREEURO", "de_AT_PREEURO", "de_AT@currency=ATS" },
19916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "de_DE_PREEURO", "de_DE_PREEURO", "de_DE@currency=DEM" },
19926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "de_LU_PREEURO", "de_LU_PREEURO", "de_LU@currency=LUF" },
19936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "el_GR_PREEURO", "el_GR_PREEURO", "el_GR@currency=GRD" },
19946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "en_BE_PREEURO", "en_BE_PREEURO", "en_BE@currency=BEF" },
19956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "en_IE_PREEURO", "en_IE_PREEURO", "en_IE@currency=IEP" },
19966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "es_ES_PREEURO", "es_ES_PREEURO", "es_ES@currency=ESP" },
19976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "eu_ES_PREEURO", "eu_ES_PREEURO", "eu_ES@currency=ESP" },
19986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "fi_FI_PREEURO", "fi_FI_PREEURO", "fi_FI@currency=FIM" },
19996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "fr_BE_PREEURO", "fr_BE_PREEURO", "fr_BE@currency=BEF" },
20006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "fr_FR_PREEURO", "fr_FR_PREEURO", "fr_FR@currency=FRF" },
20016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "fr_LU_PREEURO", "fr_LU_PREEURO", "fr_LU@currency=LUF" },
20026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "ga_IE_PREEURO", "ga_IE_PREEURO", "ga_IE@currency=IEP" },
20036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "gl_ES_PREEURO", "gl_ES_PREEURO", "gl_ES@currency=ESP" },
20046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "it_IT_PREEURO", "it_IT_PREEURO", "it_IT@currency=ITL" },
20056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "nl_BE_PREEURO", "nl_BE_PREEURO", "nl_BE@currency=BEF" },
20066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "nl_NL_PREEURO", "nl_NL_PREEURO", "nl_NL@currency=NLG" },
20076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "pt_PT_PREEURO", "pt_PT_PREEURO", "pt_PT@currency=PTE" },
20086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "de__PHONEBOOK", "de__PHONEBOOK", "de@collation=phonebook" },
20096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "en_GB_EURO", "en_GB_EURO", "en_GB@currency=EUR" },
20106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "en_GB@EURO", "en_GB@EURO", "en_GB@currency=EUR" }, /* POSIX ID */
20116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "es__TRADITIONAL", "es__TRADITIONAL", "es@collation=traditional" },
20126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "hi__DIRECT", "hi__DIRECT", "hi@collation=direct" },
20136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "ja_JP_TRADITIONAL", "ja_JP_TRADITIONAL", "ja_JP@calendar=japanese" },
20146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "th_TH_TRADITIONAL", "th_TH_TRADITIONAL", "th_TH@calendar=buddhist" },
20156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "zh_TW_STROKE", "zh_TW_STROKE", "zh_TW@collation=stroke" },
20166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "zh__PINYIN", "zh__PINYIN", "zh@collation=pinyin" },
20176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "zh@collation=pinyin", "zh@collation=pinyin", "zh@collation=pinyin" },
20186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "zh_CN@collation=pinyin", "zh_CN@collation=pinyin", "zh_CN@collation=pinyin" },
20196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "zh_CN_STROKE", "zh_CN_STROKE", "zh_CN@collation=stroke" },
20206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "zh_CN_CA@collation=pinyin", "zh_CN_CA@collation=pinyin", "zh_CN_CA@collation=pinyin" },
20216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "en_US_POSIX", "en_US_POSIX", "en_US_POSIX" },
20226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "hy_AM_REVISED", "hy_AM_REVISED", "hy_AM_REVISED" },
20236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "no_NO_NY", "no_NO_NY", "no_NO_NY" /* not: "nn_NO" [alan ICU3.0] */ },
20246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "no@ny", "no@ny", "no__NY" /* not: "nn" [alan ICU3.0] */ }, /* POSIX ID */
20256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "no-no.utf32@B", "no_NO.utf32@B", "no_NO_B" /* not: "nb_NO_B" [alan ICU3.0] */ }, /* POSIX ID */
20266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "qz-qz@Euro", "qz_QZ@Euro", "qz_QZ@currency=EUR" }, /* qz-qz uses private use iso codes */
20276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "en-BOONT", "en__BOONT", "en__BOONT" }, /* registered name */
20286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "de-1901", "de__1901", "de__1901" }, /* registered name */
20296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "de-1906", "de__1906", "de__1906" }, /* registered name */
20306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "sr-SP-Cyrl", "sr_SP_CYRL", "sr_Cyrl_RS" }, /* .NET name */
20316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "sr-SP-Latn", "sr_SP_LATN", "sr_Latn_RS" }, /* .NET name */
20326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "sr_YU_CYRILLIC", "sr_YU_CYRILLIC", "sr_Cyrl_RS" }, /* Linux name */
20336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "uz-UZ-Cyrl", "uz_UZ_CYRL", "uz_Cyrl_UZ" }, /* .NET name */
20346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "uz-UZ-Latn", "uz_UZ_LATN", "uz_Latn_UZ" }, /* .NET name */
20356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "zh-CHS", "zh_CHS", "zh_Hans" }, /* .NET name */
20366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "zh-CHT", "zh_CHT", "zh_Hant" }, /* .NET name This may change back to zh_Hant */
20376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* posix behavior that used to be performed by getName */
20396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "mr.utf8", "mr.utf8", "mr" },
20406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "de-tv.koi8r", "de_TV.koi8r", "de_TV" },
20416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "x-piglatin_ML.MBE", "x-piglatin_ML.MBE", "x-piglatin_ML" },
20426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "i-cherokee_US.utf7", "i-cherokee_US.utf7", "i-cherokee_US" },
20436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "x-filfli_MT_FILFLA.gb-18030", "x-filfli_MT_FILFLA.gb-18030", "x-filfli_MT_FILFLA" },
20446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@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 */
20456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* fleshing out canonicalization */
20476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* trim space and sort keywords, ';' is separator so not present at end in canonical form */
20486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@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" },
20496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* already-canonical ids are not changed */
20506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@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" },
20516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* PRE_EURO and EURO conversions don't affect other keywords */
20526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "es_ES_PREEURO@CALendar=Japanese", "es_ES_PREEURO@calendar=Japanese", "es_ES@calendar=Japanese;currency=ESP" },
20536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "es_ES_EURO@SHOUT=zipeedeedoodah", "es_ES_EURO@shout=zipeedeedoodah", "es_ES@currency=EUR;shout=zipeedeedoodah" },
20546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* currency keyword overrides PRE_EURO and EURO currency */
20556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "es_ES_PREEURO@currency=EUR", "es_ES_PREEURO@currency=EUR", "es_ES@currency=EUR" },
20566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "es_ES_EURO@currency=ESP", "es_ES_EURO@currency=ESP", "es_ES@currency=ESP" },
20576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* norwegian is just too weird, if we handle things in their full generality */
20586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@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] */ },
20596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* test cases reflecting internal resource bundle usage */
20616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "root@kw=foo", "root@kw=foo", "root@kw=foo" },
20626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "@calendar=gregorian", "@calendar=gregorian", "@calendar=gregorian" },
20636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "ja_JP@calendar=Japanese", "ja_JP@calendar=Japanese", "ja_JP@calendar=Japanese" },
20646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "ja_JP", "ja_JP", "ja_JP" },
20656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* test case for "i-default" */
20676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "i-default", "en@x=i-default", "en@x=i-default" }
20686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
20696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const char* label[] = { "getName", "canonicalize" };
20716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
20736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t i, j, resultLen = 0, origResultLen;
20746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    char buffer[256];
20756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (i=0; i < sizeof(testCases)/sizeof(testCases[0]); i++) {
20776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for (j=0; j<2; ++j) {
20786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            const char* expected = (j==0) ? testCases[i].getNameID : testCases[i].canonicalID;
20796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            *buffer = 0;
20806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            status = U_ZERO_ERROR;
20816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (expected == NULL) {
20836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                expected = uloc_getDefault();
20846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
20856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            /* log_verbose("testing %s -> %s\n", testCases[i], testCases[i].canonicalID); */
20876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            origResultLen = _canonicalize(j, testCases[i].localeID, NULL, 0, &status);
20886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (status != U_BUFFER_OVERFLOW_ERROR) {
20896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                log_err("FAIL: uloc_%s(%s) => %s, expected U_BUFFER_OVERFLOW_ERROR\n",
20906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        label[j], testCases[i].localeID, u_errorName(status));
20916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                continue;
20926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
20936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            status = U_ZERO_ERROR;
20946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            resultLen = _canonicalize(j, testCases[i].localeID, buffer, sizeof(buffer), &status);
20956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (U_FAILURE(status)) {
20966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                log_err("FAIL: uloc_%s(%s) => %s, expected U_ZERO_ERROR\n",
20976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        label[j], testCases[i].localeID, u_errorName(status));
20986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                continue;
20996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
21006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if(uprv_strcmp(expected, buffer) != 0) {
21016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                log_err("FAIL: uloc_%s(%s) => \"%s\", expected \"%s\"\n",
21026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        label[j], testCases[i].localeID, buffer, expected);
21036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            } else {
21046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                log_verbose("Ok: uloc_%s(%s) => \"%s\"\n",
21056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                            label[j], testCases[i].localeID, buffer);
21066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
21076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (resultLen != (int32_t)strlen(buffer)) {
21086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                log_err("FAIL: uloc_%s(%s) => len %d, expected len %d\n",
21096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        label[j], testCases[i].localeID, resultLen, strlen(buffer));
21106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
21116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (origResultLen != resultLen) {
21126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                log_err("FAIL: uloc_%s(%s) => preflight len %d != actual len %d\n",
21136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                        label[j], testCases[i].localeID, origResultLen, resultLen);
21146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
21156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
21166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
21176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
21186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
21196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestDisplayKeywords(void)
21206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
21216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t i;
21226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
21236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const struct {
21246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char *localeID;
21256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char *displayLocale;
21266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UChar displayKeyword[200];
21276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } testCases[] = {
21286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "ca_ES@currency=ESP",         "de_AT",
21296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            {0x0057, 0x00e4, 0x0068, 0x0072, 0x0075, 0x006e, 0x0067, 0x0000},
21306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        },
21316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "ja_JP@calendar=japanese",         "de",
21326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            { 0x004b, 0x0061, 0x006c, 0x0065, 0x006e, 0x0064, 0x0065, 0x0072, 0x0000}
21336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        },
21346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "de_DE@collation=traditional",       "de_DE",
21356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            {0x0053, 0x006f, 0x0072, 0x0074, 0x0069, 0x0065, 0x0072, 0x0075, 0x006e, 0x0067, 0x0000}
21366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        },
21376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
21386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for(i = 0; i < sizeof(testCases)/sizeof(testCases[0]); i++) {
21396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UErrorCode status = U_ZERO_ERROR;
21406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char* keyword =NULL;
21416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int32_t keywordLen = 0;
21426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int32_t keywordCount = 0;
21436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UChar *displayKeyword=NULL;
21446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int32_t displayKeywordLen = 0;
21456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UEnumeration* keywordEnum = uloc_openKeywords(testCases[i].localeID, &status);
21466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for(keywordCount = uenum_count(keywordEnum, &status); keywordCount > 0 ; keywordCount--){
21476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              if(U_FAILURE(status)){
21486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  log_err("uloc_getKeywords failed for locale id: %s with error : %s \n", testCases[i].localeID, u_errorName(status));
21496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  break;
21506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              }
21516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              /* the uenum_next returns NUL terminated string */
21526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              keyword = uenum_next(keywordEnum, &keywordLen, &status);
21536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              /* fetch the displayKeyword */
21546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              displayKeywordLen = uloc_getDisplayKeyword(keyword, testCases[i].displayLocale, displayKeyword, displayKeywordLen, &status);
21556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              if(status==U_BUFFER_OVERFLOW_ERROR){
21566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  status = U_ZERO_ERROR;
21576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  displayKeywordLen++; /* for null termination */
21586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  displayKeyword = (UChar*) malloc(displayKeywordLen * U_SIZEOF_UCHAR);
21596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  displayKeywordLen = uloc_getDisplayKeyword(keyword, testCases[i].displayLocale, displayKeyword, displayKeywordLen, &status);
21606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  if(U_FAILURE(status)){
21616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                      log_err("uloc_getDisplayKeyword filed for keyword : %s in locale id: %s for display locale: %s \n", testCases[i].localeID, keyword, testCases[i].displayLocale, u_errorName(status));
21626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                      break;
21636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  }
21646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  if(u_strncmp(displayKeyword, testCases[i].displayKeyword, displayKeywordLen)!=0){
21656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                      if (status == U_USING_DEFAULT_WARNING) {
21666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                          log_data_err("uloc_getDisplayKeyword did not get the expected value for keyword : %s in locale id: %s for display locale: %s . Got error: %s. Perhaps you are missing data?\n", testCases[i].localeID, keyword, testCases[i].displayLocale, u_errorName(status));
21676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                      } else {
21686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                          log_err("uloc_getDisplayKeyword did not get the expected value for keyword : %s in locale id: %s for display locale: %s \n", testCases[i].localeID, keyword, testCases[i].displayLocale);
21696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                      }
21706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                      break;
21716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  }
21726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              }else{
21736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  log_err("uloc_getDisplayKeyword did not return the expected error. Error: %s\n", u_errorName(status));
21746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              }
21756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
21766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              free(displayKeyword);
21776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
21786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
21796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        uenum_close(keywordEnum);
21806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
21816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
21826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
21836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic void TestDisplayKeywordValues(void){
21846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t i;
21856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
21866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const struct {
21876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char *localeID;
21886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char *displayLocale;
21896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UChar displayKeywordValue[500];
21906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } testCases[] = {
21916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "ca_ES@currency=ESP",         "de_AT",
21926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            {0x0053, 0x0070, 0x0061, 0x006e, 0x0069, 0x0073, 0x0063, 0x0068, 0x0065, 0x0020, 0x0050, 0x0065, 0x0073, 0x0065, 0x0074, 0x0061, 0x0000}
21936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        },
21946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "de_AT@currency=ATS",         "fr_FR",
21956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            {0x0073, 0x0063, 0x0068, 0x0069, 0x006c, 0x006c, 0x0069, 0x006e, 0x0067, 0x0020, 0x0061, 0x0075, 0x0074, 0x0072, 0x0069, 0x0063, 0x0068, 0x0069, 0x0065, 0x006e, 0x0000}
21966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        },
21976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "de_DE@currency=DEM",         "it",
21986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            {0x004d, 0x0061, 0x0072, 0x0063, 0x006f, 0x0020, 0x0054, 0x0065, 0x0064, 0x0065, 0x0073, 0x0063, 0x006f, 0x0000}
21996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        },
22006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "el_GR@currency=GRD",         "en",
22016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            {0x0047, 0x0072, 0x0065, 0x0065, 0x006b, 0x0020, 0x0044, 0x0072, 0x0061, 0x0063, 0x0068, 0x006d, 0x0061, 0x0000}
22026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        },
22036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "eu_ES@currency=ESP",         "it_IT",
22046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            {0x0050, 0x0065, 0x0073, 0x0065, 0x0074, 0x0061, 0x0020, 0x0053, 0x0070, 0x0061, 0x0067, 0x006e, 0x006f, 0x006c, 0x0061, 0x0000}
22056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        },
22066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        {   "de@collation=phonebook",     "es",
22076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            {0x006F, 0x0072, 0x0064, 0x0065, 0x006E, 0x0020, 0x0064, 0x0065, 0x0020, 0x006C, 0x0069, 0x0073, 0x0074, 0x00ED, 0x006E, 0x0020, 0x0074, 0x0065, 0x006C, 0x0065, 0x0066, 0x00F3, 0x006E, 0x0069, 0x0063, 0x006F, 0x0000}
22086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        },
22096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "de_DE@collation=phonebook",  "es",
22116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org          {0x006F, 0x0072, 0x0064, 0x0065, 0x006E, 0x0020, 0x0064, 0x0065, 0x0020, 0x006C, 0x0069, 0x0073, 0x0074, 0x00ED, 0x006E, 0x0020, 0x0074, 0x0065, 0x006C, 0x0065, 0x0066, 0x00F3, 0x006E, 0x0069, 0x0063, 0x006F, 0x0000}
22126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        },
22136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "es_ES@collation=traditional","de",
22146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org          {0x0054, 0x0072, 0x0061, 0x0064, 0x0069, 0x0074, 0x0069, 0x006f, 0x006e, 0x0065, 0x006c, 0x006c, 0x0065, 0x0020, 0x0053, 0x006f, 0x0072, 0x0074, 0x0069, 0x0065, 0x0072, 0x0072, 0x0065, 0x0067, 0x0065, 0x006c, 0x006e, 0x0000}
22156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        },
22166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        { "ja_JP@calendar=japanese",    "de",
22176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org           {0x004a, 0x0061, 0x0070, 0x0061, 0x006e, 0x0069, 0x0073, 0x0063, 0x0068, 0x0065, 0x0072, 0x0020, 0x004b, 0x0061, 0x006c, 0x0065, 0x006e, 0x0064, 0x0065, 0x0072, 0x0000}
22186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        },
22196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
22206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for(i = 0; i < sizeof(testCases)/sizeof(testCases[0]); i++) {
22216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UErrorCode status = U_ZERO_ERROR;
22226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char* keyword =NULL;
22236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int32_t keywordLen = 0;
22246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int32_t keywordCount = 0;
22256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UChar *displayKeywordValue = NULL;
22266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int32_t displayKeywordValueLen = 0;
22276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UEnumeration* keywordEnum = uloc_openKeywords(testCases[i].localeID, &status);
22286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for(keywordCount = uenum_count(keywordEnum, &status); keywordCount > 0 ; keywordCount--){
22296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              if(U_FAILURE(status)){
22306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  log_err("uloc_getKeywords failed for locale id: %s in display locale: % with error : %s \n", testCases[i].localeID, testCases[i].displayLocale, u_errorName(status));
22316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  break;
22326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              }
22336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              /* the uenum_next returns NUL terminated string */
22346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              keyword = uenum_next(keywordEnum, &keywordLen, &status);
22356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              /* fetch the displayKeywordValue */
22376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              displayKeywordValueLen = uloc_getDisplayKeywordValue(testCases[i].localeID, keyword, testCases[i].displayLocale, displayKeywordValue, displayKeywordValueLen, &status);
22386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              if(status==U_BUFFER_OVERFLOW_ERROR){
22396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  status = U_ZERO_ERROR;
22406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  displayKeywordValueLen++; /* for null termination */
22416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  displayKeywordValue = (UChar*)malloc(displayKeywordValueLen * U_SIZEOF_UCHAR);
22426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  displayKeywordValueLen = uloc_getDisplayKeywordValue(testCases[i].localeID, keyword, testCases[i].displayLocale, displayKeywordValue, displayKeywordValueLen, &status);
22436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  if(U_FAILURE(status)){
22446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                      log_err("uloc_getDisplayKeywordValue failed for keyword : %s in locale id: %s for display locale: %s with error : %s \n", testCases[i].localeID, keyword, testCases[i].displayLocale, u_errorName(status));
22456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                      break;
22466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  }
22476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  if(u_strncmp(displayKeywordValue, testCases[i].displayKeywordValue, displayKeywordValueLen)!=0){
22486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                      if (status == U_USING_DEFAULT_WARNING) {
22496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                          log_data_err("uloc_getDisplayKeywordValue did not return the expected value keyword : %s in locale id: %s for display locale: %s with error : %s Perhaps you are missing data\n", testCases[i].localeID, keyword, testCases[i].displayLocale, u_errorName(status));
22506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                      } else {
22516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                          log_err("uloc_getDisplayKeywordValue did not return the expected value keyword : %s in locale id: %s for display locale: %s with error : %s \n", testCases[i].localeID, keyword, testCases[i].displayLocale, u_errorName(status));
22526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                      }
22536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                      break;
22546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  }
22556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              }else{
22566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  log_err("uloc_getDisplayKeywordValue did not return the expected error. Error: %s\n", u_errorName(status));
22576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              }
22586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              free(displayKeywordValue);
22596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
22606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        uenum_close(keywordEnum);
22616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
22626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
22636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /* test a multiple keywords */
22646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UErrorCode status = U_ZERO_ERROR;
22656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char* keyword =NULL;
22666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int32_t keywordLen = 0;
22676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int32_t keywordCount = 0;
22686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char* localeID = "es@collation=phonebook;calendar=buddhist;currency=DEM";
22696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        const char* displayLocale = "de";
22706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const UChar expected[][50] = {
22716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            {0x0042, 0x0075, 0x0064, 0x0064, 0x0068, 0x0069, 0x0073, 0x0074, 0x0069, 0x0073, 0x0063, 0x0068, 0x0065, 0x0072, 0x0020, 0x004b, 0x0061, 0x006c, 0x0065, 0x006e, 0x0064, 0x0065, 0x0072, 0x0000},
22726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            {0x0054, 0x0065, 0x006c, 0x0065, 0x0066, 0x006f, 0x006e, 0x0062, 0x0075, 0x0063, 0x0068, 0x002d, 0x0053, 0x006f, 0x0072, 0x0074, 0x0069, 0x0065, 0x0072, 0x0075, 0x006e, 0x0067, 0x0000},
22746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            {0x0044, 0x0065, 0x0075, 0x0074, 0x0073, 0x0063, 0x0068, 0x0065, 0x0020, 0x004d, 0x0061, 0x0072, 0x006b, 0x0000},
22756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        };
22766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UEnumeration* keywordEnum = uloc_openKeywords(localeID, &status);
22786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for(keywordCount = 0; keywordCount < uenum_count(keywordEnum, &status) ; keywordCount++){
22806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              UChar *displayKeywordValue = NULL;
22816f31ac30b9092fd02a8c97e5216cf53f3e4fae4