1b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/********************************************************************
2b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * COPYRIGHT:
3fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius * Copyright (c) 1997-2014, International Business Machines Corporation and
4b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * others. All Rights Reserved.
5b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru ********************************************************************/
6b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*****************************************************************************
7b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*
8b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru* File CLOCTST.C
9b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*
10b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru* Modification History:
11b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*        Name                     Description
12b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*     Madhu Katragadda            Ported for C API
13b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru******************************************************************************
14b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*/
15b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "cloctst.h"
16b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include <stdlib.h>
17b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include <stdio.h>
18b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include <string.h>
19b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "cintltst.h"
20b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "cstring.h"
21b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "uparse.h"
22b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "uresimp.h"
23b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
24b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/putil.h"
25b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/ubrk.h"
26b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/uchar.h"
27b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/ucol.h"
28b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/udat.h"
29b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/uloc.h"
30b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/umsg.h"
31b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/ures.h"
32b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/uset.h"
33b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/ustring.h"
34b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/utypes.h"
35b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/ulocdata.h"
3659d709d503bab6e2b61931737e662dd293b40578ccornelius#include "unicode/uldnames.h"
37b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/parseerr.h" /* may not be included with some uconfig switches */
3827f654740f2a26ad62a5c155af9199af9e69b889claireho#include "udbgutil.h"
39b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
40b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
41b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void TestNullDefault(void);
42b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void TestNonexistentLanguageExemplars(void);
43b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void TestLocDataErrorCodeChaining(void);
44b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void TestLanguageExemplarsFallbacks(void);
4559d709d503bab6e2b61931737e662dd293b40578ccorneliusstatic void TestDisplayNameBrackets(void);
46b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
4727f654740f2a26ad62a5c155af9199af9e69b889clairehostatic void TestUnicodeDefines(void);
4827f654740f2a26ad62a5c155af9199af9e69b889claireho
49b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid PrintDataTable();
50b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
51b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*---------------------------------------------------
52b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  table of valid data
53b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru --------------------------------------------------- */
54b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#define LOCALE_SIZE 9
55b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#define LOCALE_INFO_SIZE 28
56b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
57b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic const char* const rawData2[LOCALE_INFO_SIZE][LOCALE_SIZE] = {
58b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* language code */
59b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {   "en",   "fr",   "ca",   "el",   "no",   "zh",   "de",   "es",  "ja"    },
60b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* script code */
6150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    {   "",     "",     "",     "",     "",     "", "", "", ""  },
62b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* country code */
63b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {   "US",   "FR",   "ES",   "GR",   "NO",   "CN", "DE", "", "JP"    },
64b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* variant code */
65b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {   "",     "",     "",     "",     "NY",   "", "", "", ""      },
66b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* full name */
67b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {   "en_US",    "fr_FR",    "ca_ES",
68b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "el_GR",    "no_NO_NY", "zh_Hans_CN",
69b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "de_DE@collation=phonebook", "es@collation=traditional",  "ja_JP@calendar=japanese" },
70b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* ISO-3 language */
71b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {   "eng",  "fra",  "cat",  "ell",  "nor",  "zho", "deu", "spa", "jpn"   },
72b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* ISO-3 country */
73b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {   "USA",  "FRA",  "ESP",  "GRC",  "NOR",  "CHN", "DEU", "", "JPN"   },
74b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* LCID */
75b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {   "409", "40c", "403", "408", "814",  "804", "10407", "40a", "411"     },
76b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
77b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* display language (English) */
78b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {   "English",  "French",   "Catalan", "Greek",    "Norwegian", "Chinese", "German", "Spanish", "Japanese"    },
79b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* display script code (English) */
80103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius    {   "",     "",     "",     "",     "",     "Simplified Han", "", "", ""       },
81b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* display country (English) */
82b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {   "United States",    "France",   "Spain",  "Greece",   "Norway", "China", "Germany", "", "Japan"       },
83b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* display variant (English) */
84b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {   "",     "",     "",     "",     "NY",  "", "", "", ""       },
85b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* display name (English) */
86b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {   "English (United States)", "French (France)", "Catalan (Spain)",
87b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        "Greek (Greece)", "Norwegian (Norway, NY)", "Chinese (Simplified, China)",
88b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        "German (Germany, Sort Order=Phonebook Sort Order)", "Spanish (Sort Order=Traditional Sort Order)", "Japanese (Japan, Calendar=Japanese Calendar)" },
89b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
90b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* display language (French) */
91b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {   "anglais",  "fran\\u00E7ais",   "catalan", "grec",    "norv\\u00E9gien",    "chinois", "allemand", "espagnol", "japonais"     },
92b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* display script code (French) */
9359d709d503bab6e2b61931737e662dd293b40578ccornelius    {   "",     "",     "",     "",     "",     "sinogrammes simplifi\\u00e9s", "", "", ""         },
94b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* display country (French) */
95b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {   "\\u00C9tats-Unis",    "France",   "Espagne",  "Gr\\u00E8ce",   "Norv\\u00E8ge",    "Chine", "Allemagne", "", "Japon"       },
96b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* display variant (French) */
97b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {   "",     "",     "",     "",     "NY",   "", "", "", ""       },
98b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* display name (French) */
99b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {   "anglais (\\u00C9tats-Unis)", "fran\\u00E7ais (France)", "catalan (Espagne)",
10054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius        "grec (Gr\\u00E8ce)", "norv\\u00E9gien (Norv\\u00E8ge, NY)",  "chinois (simplifi\\u00e9, Chine)",
10159d709d503bab6e2b61931737e662dd293b40578ccornelius        "allemand (Allemagne, ordre de tri=Ordre de l\\u2019annuaire)", "espagnol (ordre de tri=Ordre traditionnel)", "japonais (Japon, calendrier=Calendrier japonais)" },
102b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
103b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* display language (Catalan) */
104c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru    {   "angl\\u00E8s", "franc\\u00E8s", "catal\\u00E0", "grec",  "noruec", "xin\\u00E8s", "alemany", "espanyol", "japon\\u00E8s"    },
105b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* display script code (Catalan) */
10659d709d503bab6e2b61931737e662dd293b40578ccornelius    {   "",     "",     "",     "",     "",     "han simplificat", "", "", ""         },
107b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* display country (Catalan) */
108b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {   "Estats Units", "Fran\\u00E7a", "Espanya",  "Gr\\u00E8cia", "Noruega",  "Xina", "Alemanya", "", "Jap\\u00F3"    },
109b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* display variant (Catalan) */
110b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {   "", "", "",                    "", "NY",    "", "", "", ""    },
111b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* display name (Catalan) */
112b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {   "angl\\u00E8s (Estats Units)", "franc\\u00E8s (Fran\\u00E7a)", "catal\\u00E0 (Espanya)",
113b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    "grec (Gr\\u00E8cia)", "noruec (Noruega, NY)", "xin\\u00E8s (simplificat, Xina)",
11459d709d503bab6e2b61931737e662dd293b40578ccornelius    "alemany (Alemanya, ordenaci\\u00F3=ordre de la guia telef\\u00F2nica)", "espanyol (ordenaci\\u00F3=ordre tradicional)", "japon\\u00E8s (Jap\\u00F3, calendari=calendari japon\\u00e8s)" },
115b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
116b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* display language (Greek) */
117b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {
118b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "\\u0391\\u03b3\\u03b3\\u03bb\\u03b9\\u03ba\\u03ac",
119b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "\\u0393\\u03b1\\u03bb\\u03bb\\u03b9\\u03ba\\u03ac",
120b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "\\u039a\\u03b1\\u03c4\\u03b1\\u03bb\\u03b1\\u03bd\\u03b9\\u03ba\\u03ac",
121b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "\\u0395\\u03bb\\u03bb\\u03b7\\u03bd\\u03b9\\u03ba\\u03ac",
122b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "\\u039d\\u03bf\\u03c1\\u03b2\\u03b7\\u03b3\\u03b9\\u03ba\\u03ac",
123b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "\\u039A\\u03B9\\u03BD\\u03B5\\u03B6\\u03B9\\u03BA\\u03AC",
124b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "\\u0393\\u03B5\\u03C1\\u03BC\\u03B1\\u03BD\\u03B9\\u03BA\\u03AC",
125b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "\\u0399\\u03C3\\u03C0\\u03B1\\u03BD\\u03B9\\u03BA\\u03AC",
126b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "\\u0399\\u03B1\\u03C0\\u03C9\\u03BD\\u03B9\\u03BA\\u03AC"
127b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    },
128b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* display script code (Greek) */
129b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
13059d709d503bab6e2b61931737e662dd293b40578ccornelius    {   "",     "",     "",     "",     "", "\\u0391\\u03c0\\u03bb\\u03bf\\u03c0\\u03bf\\u03b9\\u03b7\\u03bc\\u03ad\\u03bd\\u03bf \\u03a7\\u03b1\\u03bd", "", "", "" },
131b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* display country (Greek) */
132b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {
13359d709d503bab6e2b61931737e662dd293b40578ccornelius        "\\u0397\\u03BD\\u03C9\\u03BC\\u03AD\\u03BD\\u03B5\\u03C2 \\u03A0\\u03BF\\u03BB\\u03B9\\u03C4\\u03B5\\u03AF\\u03B5\\u03C2",
134b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "\\u0393\\u03b1\\u03bb\\u03bb\\u03af\\u03b1",
135b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "\\u0399\\u03c3\\u03c0\\u03b1\\u03bd\\u03af\\u03b1",
136b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "\\u0395\\u03bb\\u03bb\\u03ac\\u03b4\\u03b1",
137b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "\\u039d\\u03bf\\u03c1\\u03b2\\u03b7\\u03b3\\u03af\\u03b1",
138b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "\\u039A\\u03AF\\u03BD\\u03B1",
139b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "\\u0393\\u03B5\\u03C1\\u03BC\\u03B1\\u03BD\\u03AF\\u03B1",
140b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "",
141b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "\\u0399\\u03B1\\u03C0\\u03C9\\u03BD\\u03AF\\u03B1"
142b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    },
143b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* display variant (Greek) */
144b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {   "", "", "", "", "NY", "", "", "", ""    }, /* TODO: currently there is no translation for NY in Greek fix this test when we have it */
145b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* display name (Greek) */
146b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {
14759d709d503bab6e2b61931737e662dd293b40578ccornelius        "\\u0391\\u03b3\\u03b3\\u03bb\\u03b9\\u03ba\\u03ac (\\u0397\\u03BD\\u03C9\\u03BC\\u03AD\\u03BD\\u03B5\\u03C2 \\u03A0\\u03BF\\u03BB\\u03B9\\u03C4\\u03B5\\u03AF\\u03B5\\u03C2)",
148b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "\\u0393\\u03b1\\u03bb\\u03bb\\u03b9\\u03ba\\u03ac (\\u0393\\u03b1\\u03bb\\u03bb\\u03af\\u03b1)",
149b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "\\u039a\\u03b1\\u03c4\\u03b1\\u03bb\\u03b1\\u03bd\\u03b9\\u03ba\\u03ac (\\u0399\\u03c3\\u03c0\\u03b1\\u03bd\\u03af\\u03b1)",
150b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "\\u0395\\u03bb\\u03bb\\u03b7\\u03bd\\u03b9\\u03ba\\u03ac (\\u0395\\u03bb\\u03bb\\u03ac\\u03b4\\u03b1)",
15159d709d503bab6e2b61931737e662dd293b40578ccornelius        "\\u039d\\u03bf\\u03c1\\u03b2\\u03b7\\u03b3\\u03b9\\u03ba\\u03ac (\\u039d\\u03bf\\u03c1\\u03b2\\u03b7\\u03b3\\u03af\\u03b1, NY)",
15259d709d503bab6e2b61931737e662dd293b40578ccornelius        "\\u039A\\u03B9\\u03BD\\u03B5\\u03B6\\u03B9\\u03BA\\u03AC (\\u0391\\u03c0\\u03bb\\u03bf\\u03c0\\u03bf\\u03b9\\u03b7\\u03bc\\u03ad\\u03bd\\u03bf, \\u039A\\u03AF\\u03BD\\u03B1)",
15359d709d503bab6e2b61931737e662dd293b40578ccornelius        "\\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)",
15454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius        "\\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)",
15559d709d503bab6e2b61931737e662dd293b40578ccornelius        "\\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)"
156b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
157b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru};
158b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
159b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic UChar*** dataTable=0;
160b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruenum {
161b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    ENGLISH = 0,
162b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    FRENCH = 1,
163b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    CATALAN = 2,
164b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    GREEK = 3,
165b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    NORWEGIAN = 4
166b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru};
167b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
168b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruenum {
169b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    LANG = 0,
170b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    SCRIPT = 1,
171b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    CTRY = 2,
172b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    VAR = 3,
173b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    NAME = 4,
174b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    LANG3 = 5,
175b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    CTRY3 = 6,
176b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    LCID = 7,
177b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DLANG_EN = 8,
178b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DSCRIPT_EN = 9,
179b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DCTRY_EN = 10,
180b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DVAR_EN = 11,
181b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DNAME_EN = 12,
182b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DLANG_FR = 13,
183b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DSCRIPT_FR = 14,
184b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DCTRY_FR = 15,
185b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DVAR_FR = 16,
186b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DNAME_FR = 17,
187b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DLANG_CA = 18,
188b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DSCRIPT_CA = 19,
189b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DCTRY_CA = 20,
190b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DVAR_CA = 21,
191b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DNAME_CA = 22,
192b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DLANG_EL = 23,
193b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DSCRIPT_EL = 24,
194b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DCTRY_EL = 25,
195b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DVAR_EL = 26,
196b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    DNAME_EL = 27
197b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru};
198b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
199b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#define TESTCASE(name) addTest(root, &name, "tsutil/cloctst/" #name)
200b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
201b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid addLocaleTest(TestNode** root);
202b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
203b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid addLocaleTest(TestNode** root)
204b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{
205b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    TESTCASE(TestObsoleteNames); /* srl- move */
206b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    TESTCASE(TestBasicGetters);
207b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    TESTCASE(TestNullDefault);
208b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    TESTCASE(TestPrefixes);
209b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    TESTCASE(TestSimpleResourceInfo);
210b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    TESTCASE(TestDisplayNames);
211b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    TESTCASE(TestGetAvailableLocales);
212b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    TESTCASE(TestDataDirectory);
21350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
214b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    TESTCASE(TestISOFunctions);
21550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#endif
216b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    TESTCASE(TestISO3Fallback);
217b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    TESTCASE(TestUninstalledISO3Names);
218b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    TESTCASE(TestSimpleDisplayNames);
219b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    TESTCASE(TestVariantParsing);
220b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    TESTCASE(TestKeywordVariants);
221b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    TESTCASE(TestKeywordVariantParsing);
222b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    TESTCASE(TestCanonicalization);
223b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    TESTCASE(TestKeywordSet);
224b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    TESTCASE(TestKeywordSetError);
225b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    TESTCASE(TestDisplayKeywords);
226b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    TESTCASE(TestDisplayKeywordValues);
227b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    TESTCASE(TestGetBaseName);
22850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#if !UCONFIG_NO_FILE_IO
229b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    TESTCASE(TestGetLocale);
23050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#endif
231b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    TESTCASE(TestDisplayNameWarning);
232b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    TESTCASE(TestNonexistentLanguageExemplars);
233b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    TESTCASE(TestLocDataErrorCodeChaining);
234b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    TESTCASE(TestLanguageExemplarsFallbacks);
235b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    TESTCASE(TestCalendar);
236b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    TESTCASE(TestDateFormat);
237b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    TESTCASE(TestCollation);
238b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    TESTCASE(TestULocale);
239b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    TESTCASE(TestUResourceBundle);
240b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    TESTCASE(TestDisplayName);
241b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    TESTCASE(TestAcceptLanguage);
242b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    TESTCASE(TestGetLocaleForLCID);
243c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru    TESTCASE(TestOrientation);
244c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru    TESTCASE(TestLikelySubtags);
245b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru    TESTCASE(TestToLanguageTag);
246b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru    TESTCASE(TestForLanguageTag);
24750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    TESTCASE(TestTrailingNull);
24827f654740f2a26ad62a5c155af9199af9e69b889claireho    TESTCASE(TestUnicodeDefines);
2498393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius    TESTCASE(TestEnglishExemplarCharacters);
25059d709d503bab6e2b61931737e662dd293b40578ccornelius    TESTCASE(TestDisplayNameBrackets);
251b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
252b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
253b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
254b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/* testing uloc(), uloc_getName(), uloc_getLanguage(), uloc_getVariant(), uloc_getCountry() */
255b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void TestBasicGetters() {
256b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t i;
257b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t cap;
258b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
259b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    char *testLocale = 0;
260b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    char *temp = 0, *name = 0;
261b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    log_verbose("Testing Basic Getters\n");
262b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    for (i = 0; i < LOCALE_SIZE; i++) {
263b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        testLocale=(char*)malloc(sizeof(char) * (strlen(rawData2[NAME][i])+1));
264b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        strcpy(testLocale,rawData2[NAME][i]);
265b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
266b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_verbose("Testing   %s  .....\n", testLocale);
267b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        cap=uloc_getLanguage(testLocale, NULL, 0, &status);
268b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(status==U_BUFFER_OVERFLOW_ERROR){
269b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            status=U_ZERO_ERROR;
270b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            temp=(char*)malloc(sizeof(char) * (cap+1));
271b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            uloc_getLanguage(testLocale, temp, cap+1, &status);
272b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
273b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(U_FAILURE(status)){
274b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("ERROR: in uloc_getLanguage  %s\n", myErrorName(status));
275b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
276b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (0 !=strcmp(temp,rawData2[LANG][i]))    {
277b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("  Language code mismatch: %s versus  %s\n", temp, rawData2[LANG][i]);
278b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
279b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
280b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
281b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        cap=uloc_getCountry(testLocale, temp, cap, &status);
282b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(status==U_BUFFER_OVERFLOW_ERROR){
283b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            status=U_ZERO_ERROR;
284b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            temp=(char*)realloc(temp, sizeof(char) * (cap+1));
285b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            uloc_getCountry(testLocale, temp, cap+1, &status);
286b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
287b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(U_FAILURE(status)){
288b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("ERROR: in uloc_getCountry  %s\n", myErrorName(status));
289b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
290b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (0 != strcmp(temp, rawData2[CTRY][i])) {
291b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err(" Country code mismatch:  %s  versus   %s\n", temp, rawData2[CTRY][i]);
292b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
293b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru          }
294b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
295b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        cap=uloc_getVariant(testLocale, temp, cap, &status);
296b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(status==U_BUFFER_OVERFLOW_ERROR){
297b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            status=U_ZERO_ERROR;
298b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            temp=(char*)realloc(temp, sizeof(char) * (cap+1));
299b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            uloc_getVariant(testLocale, temp, cap+1, &status);
300b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
301b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(U_FAILURE(status)){
302b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("ERROR: in uloc_getVariant  %s\n", myErrorName(status));
303b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
304b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (0 != strcmp(temp, rawData2[VAR][i])) {
305b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("Variant code mismatch:  %s  versus   %s\n", temp, rawData2[VAR][i]);
306b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
307b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
308b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        cap=uloc_getName(testLocale, NULL, 0, &status);
309b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(status==U_BUFFER_OVERFLOW_ERROR){
310b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            status=U_ZERO_ERROR;
311b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            name=(char*)malloc(sizeof(char) * (cap+1));
312b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            uloc_getName(testLocale, name, cap+1, &status);
313b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        } else if(status==U_ZERO_ERROR) {
314b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru          log_err("ERROR: in uloc_getName(%s,NULL,0,..), expected U_BUFFER_OVERFLOW_ERROR!\n", testLocale);
315b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
316b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(U_FAILURE(status)){
317b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("ERROR: in uloc_getName   %s\n", myErrorName(status));
318b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
319b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (0 != strcmp(name, rawData2[NAME][i])){
320b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err(" Mismatch in getName:  %s  versus   %s\n", name, rawData2[NAME][i]);
321b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
322b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
323b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        free(temp);
324b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        free(name);
325b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
326b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        free(testLocale);
327b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
328b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
329b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
330b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void TestNullDefault() {
331b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
332b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    char original[ULOC_FULLNAME_CAPACITY];
333b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
334b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    uprv_strcpy(original, uloc_getDefault());
335b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    uloc_setDefault("qq_BLA", &status);
336b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (uprv_strcmp(uloc_getDefault(), "qq_BLA") != 0) {
337b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_err(" Mismatch in uloc_setDefault:  qq_BLA  versus   %s\n", uloc_getDefault());
338b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
339b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    uloc_setDefault(NULL, &status);
340b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (uprv_strcmp(uloc_getDefault(), original) != 0) {
341b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_err(" uloc_setDefault(NULL, &status) didn't get the default locale back!\n");
342b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
343b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
344b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {
345b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* Test that set & get of default locale work, and that
346b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru     * default locales are cached and reused, and not overwritten.
347b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru     */
348b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        const char *n_en_US;
349b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        const char *n_fr_FR;
350b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        const char *n2_en_US;
351b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
352b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        status = U_ZERO_ERROR;
353b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        uloc_setDefault("en_US", &status);
354b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        n_en_US = uloc_getDefault();
355b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (strcmp(n_en_US, "en_US") != 0) {
356b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("Wrong result from uloc_getDefault().  Expected \"en_US\", got \"%s\"\n", n_en_US);
357b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
358b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
359b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        uloc_setDefault("fr_FR", &status);
360b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        n_fr_FR = uloc_getDefault();
361b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (strcmp(n_en_US, "en_US") != 0) {
362b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("uloc_setDefault altered previously default string."
363b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                "Expected \"en_US\", got \"%s\"\n",  n_en_US);
364b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
365b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (strcmp(n_fr_FR, "fr_FR") != 0) {
366b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("Wrong result from uloc_getDefault().  Expected \"fr_FR\", got %s\n",  n_fr_FR);
367b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
368b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
369b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        uloc_setDefault("en_US", &status);
370b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        n2_en_US = uloc_getDefault();
371b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (strcmp(n2_en_US, "en_US") != 0) {
372b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("Wrong result from uloc_getDefault().  Expected \"en_US\", got \"%s\"\n", n_en_US);
373b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
374b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (n2_en_US != n_en_US) {
375b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("Default locale cache failed to reuse en_US locale.\n");
376b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
377b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
378b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (U_FAILURE(status)) {
379b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("Failure returned from uloc_setDefault - \"%s\"\n", u_errorName(status));
380b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
381b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
382b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
383b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
384b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
385b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/* Test the i- and x- and @ and . functionality
386b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*/
387b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
388b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#define PREFIXBUFSIZ 128
389b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
390b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void TestPrefixes() {
391b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int row = 0;
392b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int n;
393b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    const char *loc, *expected;
394b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
395b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    static const char * const testData[][7] =
396b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {
397b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        /* NULL canonicalize() column means "expect same as getName()" */
398b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {"sv", "", "FI", "AL", "sv-fi-al", "sv_FI_AL", NULL},
399b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {"en", "", "GB", "", "en-gb", "en_GB", NULL},
400b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {"i-hakka", "", "MT", "XEMXIJA", "i-hakka_MT_XEMXIJA", "i-hakka_MT_XEMXIJA", NULL},
401b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {"i-hakka", "", "CN", "", "i-hakka_CN", "i-hakka_CN", NULL},
402b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {"i-hakka", "", "MX", "", "I-hakka_MX", "i-hakka_MX", NULL},
403b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {"x-klingon", "", "US", "SANJOSE", "X-KLINGON_us_SANJOSE", "x-klingon_US_SANJOSE", NULL},
404b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
40554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius        {"zh", "Hans", "", "PINYIN", "zh-Hans-pinyin", "zh_Hans__PINYIN", "zh_Hans@collation=pinyin"},
40654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius        {"hy", "", "", "AREVMDA", "hy_AREVMDA", "hy__AREVMDA", NULL},
40727f654740f2a26ad62a5c155af9199af9e69b889claireho
40854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius        {"de", "", "", "1901", "de-1901", "de__1901", NULL},
409b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {"mr", "", "", "", "mr.utf8", "mr.utf8", "mr"},
410b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {"de", "", "TV", "", "de-tv.koi8r", "de_TV.koi8r", "de_TV"},
411b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {"x-piglatin", "", "ML", "", "x-piglatin_ML.MBE", "x-piglatin_ML.MBE", "x-piglatin_ML"},  /* Multibyte English */
412b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {"i-cherokee", "","US", "", "i-Cherokee_US.utf7", "i-cherokee_US.utf7", "i-cherokee_US"},
413b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {"x-filfli", "", "MT", "FILFLA", "x-filfli_MT_FILFLA.gb-18030", "x-filfli_MT_FILFLA.gb-18030", "x-filfli_MT_FILFLA"},
414b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {"no", "", "NO", "NY", "no-no-ny.utf32@B", "no_NO_NY.utf32@B", "no_NO_NY_B"},
415b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {"no", "", "NO", "",  "no-no.utf32@B", "no_NO.utf32@B", "no_NO_B"},
416b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {"no", "", "",   "NY", "no__ny", "no__NY", NULL},
417b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {"no", "", "",   "", "no@ny", "no@ny", "no__NY"},
418b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {"el", "Latn", "", "", "el-latn", "el_Latn", NULL},
419b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {"en", "Cyrl", "RU", "", "en-cyrl-ru", "en_Cyrl_RU", NULL},
420c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru        {"zh", "Hant", "TW", "STROKE", "zh-hant_TW_STROKE", "zh_Hant_TW_STROKE", "zh_Hant_TW@collation=stroke"},
421b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {"qq", "Qqqq", "QQ", "QQ", "qq_Qqqq_QQ_QQ", "qq_Qqqq_QQ_QQ", NULL},
422b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {"qq", "Qqqq", "", "QQ", "qq_Qqqq__QQ", "qq_Qqqq__QQ", NULL},
423103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius        {"ab", "Cdef", "GH", "IJ", "ab_cdef_gh_ij", "ab_Cdef_GH_IJ", NULL}, /* total garbage */
424b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
425b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {NULL,NULL,NULL,NULL,NULL,NULL,NULL}
426b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    };
427b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
428b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    static const char * const testTitles[] = {
429b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "uloc_getLanguage()",
430b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "uloc_getScript()",
431b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "uloc_getCountry()",
432b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "uloc_getVariant()",
433b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "name",
434b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "uloc_getName()",
435b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        "uloc_canonicalize()"
436b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    };
437b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
438b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    char buf[PREFIXBUFSIZ];
439b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t len;
440b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode err;
441b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
442b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
443b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    for(row=0;testData[row][0] != NULL;row++) {
444b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        loc = testData[row][NAME];
445b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_verbose("Test #%d: %s\n", row, loc);
446b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
447b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        err = U_ZERO_ERROR;
448b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        len=0;
449b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        buf[0]=0;
450b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        for(n=0;n<=(NAME+2);n++) {
451b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            if(n==NAME) continue;
452b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
453b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            for(len=0;len<PREFIXBUFSIZ;len++) {
454b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                buf[len] = '%'; /* Set a tripwire.. */
455b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            }
456b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            len = 0;
457b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
458b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            switch(n) {
459b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            case LANG:
460b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                len = uloc_getLanguage(loc, buf, PREFIXBUFSIZ, &err);
461b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                break;
462b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
463b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            case SCRIPT:
464b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                len = uloc_getScript(loc, buf, PREFIXBUFSIZ, &err);
465b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                break;
466b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
467b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            case CTRY:
468b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                len = uloc_getCountry(loc, buf, PREFIXBUFSIZ, &err);
469b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                break;
470b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
471b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            case VAR:
472b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                len = uloc_getVariant(loc, buf, PREFIXBUFSIZ, &err);
473b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                break;
474b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
475b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            case NAME+1:
476b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                len = uloc_getName(loc, buf, PREFIXBUFSIZ, &err);
477b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                break;
478b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
479b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            case NAME+2:
480b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                len = uloc_canonicalize(loc, buf, PREFIXBUFSIZ, &err);
481b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                break;
482b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
483b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            default:
484b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                strcpy(buf, "**??");
485b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                len=4;
486b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            }
487b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
488b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            if(U_FAILURE(err)) {
489b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                log_err("#%d: %s on %s: err %s\n",
490b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    row, testTitles[n], loc, u_errorName(err));
491b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            } else {
492b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                log_verbose("#%d: %s on %s: -> [%s] (length %d)\n",
493b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    row, testTitles[n], loc, buf, len);
494b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
495b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                if(len != (int32_t)strlen(buf)) {
496b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    log_err("#%d: %s on %s: -> [%s] (length returned %d, actual %d!)\n",
497b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                        row, testTitles[n], loc, buf, len, strlen(buf)+1);
498b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
499b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                }
500b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
501b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                /* see if they smashed something */
502b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                if(buf[len+1] != '%') {
503b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    log_err("#%d: %s on %s: -> [%s] - wrote [%X] out ofbounds!\n",
504b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                        row, testTitles[n], loc, buf, buf[len+1]);
505b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                }
506b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
507b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                expected = testData[row][n];
508b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                if (expected == NULL && n == (NAME+2)) {
509b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    /* NULL expected canonicalize() means "expect same as getName()" */
510b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    expected = testData[row][NAME+1];
511b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                }
512b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                if(strcmp(buf, expected)) {
513b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    log_err("#%d: %s on %s: -> [%s] (expected '%s'!)\n",
514b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                        row, testTitles[n], loc, buf, expected);
515b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
516b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                }
517b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            }
518b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
519b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
520b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
521b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
522b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
523b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/* testing uloc_getISO3Language(), uloc_getISO3Country(),  */
524b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void TestSimpleResourceInfo() {
525b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t i;
526b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    char* testLocale = 0;
527b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UChar* expected = 0;
528b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
529b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    const char* temp;
530b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    char            temp2[20];
531b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    testLocale=(char*)malloc(sizeof(char) * 1);
532b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expected=(UChar*)malloc(sizeof(UChar) * 1);
533b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
534b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    setUpDataTable();
535b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    log_verbose("Testing getISO3Language and getISO3Country\n");
536b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    for (i = 0; i < LOCALE_SIZE; i++) {
537b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
538b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        testLocale=(char*)realloc(testLocale, sizeof(char) * (u_strlen(dataTable[NAME][i])+1));
539b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        u_austrcpy(testLocale, dataTable[NAME][i]);
540b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
541b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_verbose("Testing   %s ......\n", testLocale);
542b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
543b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        temp=uloc_getISO3Language(testLocale);
544b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        expected=(UChar*)realloc(expected, sizeof(UChar) * (strlen(temp) + 1));
545b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        u_uastrcpy(expected,temp);
546b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (0 != u_strcmp(expected, dataTable[LANG3][i])) {
547b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("  ISO-3 language code mismatch:  %s versus  %s\n",  austrdup(expected),
548b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                austrdup(dataTable[LANG3][i]));
549b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
550b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
551b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        temp=uloc_getISO3Country(testLocale);
552b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        expected=(UChar*)realloc(expected, sizeof(UChar) * (strlen(temp) + 1));
553b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        u_uastrcpy(expected,temp);
554b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (0 != u_strcmp(expected, dataTable[CTRY3][i])) {
555b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("  ISO-3 Country code mismatch:  %s versus  %s\n",  austrdup(expected),
556b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                austrdup(dataTable[CTRY3][i]));
557b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
558b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        sprintf(temp2, "%x", (int)uloc_getLCID(testLocale));
559b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (strcmp(temp2, rawData2[LCID][i]) != 0) {
560b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("LCID mismatch: %s versus %s\n", temp2 , rawData2[LCID][i]);
561b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
562b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
563b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
564b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    free(expected);
565b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    free(testLocale);
566b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    cleanUpDataTable();
567b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
568b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
569b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho/* if len < 0, we convert until we hit UChar 0x0000, which is not output. will add trailing null
570b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho * if there's room but won't be included in result.  result < 0 indicates an error.
571b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho * Returns the number of chars written (not those that would be written if there's enough room.*/
572b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2clairehostatic int32_t UCharsToEscapedAscii(const UChar* utext, int32_t len, char* resultChars, int32_t buflen) {
573b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    static const struct {
574b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        char escapedChar;
575b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        UChar sourceVal;
576b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    } ESCAPE_MAP[] = {
577b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        /*a*/ {'a', 0x07},
578b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        /*b*/ {'b', 0x08},
579b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        /*e*/ {'e', 0x1b},
580b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        /*f*/ {'f', 0x0c},
581b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        /*n*/ {'n', 0x0a},
582b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        /*r*/ {'r', 0x0d},
583b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        /*t*/ {'t', 0x09},
584b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        /*v*/ {'v', 0x0b}
585b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    };
586b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    static const int32_t ESCAPE_MAP_LENGTH = sizeof(ESCAPE_MAP)/sizeof(ESCAPE_MAP[0]);
587b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    static const char HEX_DIGITS[] = {
588b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        '0', '1', '2', '3', '4', '5', '6', '7',
589b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
590b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    };
591b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    int32_t i, j;
592b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    int32_t resultLen = 0;
593b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    const int32_t limit = len<0 ? buflen : len; /* buflen is long enough to hit the buffer limit */
594b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    const int32_t escapeLimit1 = buflen-2;
595b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    const int32_t escapeLimit2 = buflen-6;
596b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    UChar uc;
597b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
598b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    if(utext==NULL || resultChars==NULL || buflen<0) {
599b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        return -1;
600b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    }
601b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
602b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    for(i=0;i<limit && resultLen<buflen;++i) {
603b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        uc=utext[i];
604b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        if(len<0 && uc==0) {
605b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            break;
606b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        }
607b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        if(uc<0x20) {
608b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            for(j=0;j<ESCAPE_MAP_LENGTH && uc!=ESCAPE_MAP[j].sourceVal;j++) {
609b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            }
610b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            if(j<ESCAPE_MAP_LENGTH) {
611b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                if(resultLen>escapeLimit1) {
612b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                    break;
613b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                }
614b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                resultChars[resultLen++]='\\';
615b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                resultChars[resultLen++]=ESCAPE_MAP[j].escapedChar;
616b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                continue;
617b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            }
618b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        } else if(uc<0x7f) {
619b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            u_austrncpy(resultChars + resultLen, &uc, 1);
620b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            resultLen++;
621b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            continue;
622b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        }
623b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
624b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        if(resultLen>escapeLimit2) {
625b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            break;
626b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        }
627b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
628b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        /* have to escape the uchar */
629b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        resultChars[resultLen++]='\\';
630b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        resultChars[resultLen++]='u';
631b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        resultChars[resultLen++]=HEX_DIGITS[(uc>>12)&0xff];
632b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        resultChars[resultLen++]=HEX_DIGITS[(uc>>8)&0xff];
633b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        resultChars[resultLen++]=HEX_DIGITS[(uc>>4)&0xff];
634b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        resultChars[resultLen++]=HEX_DIGITS[uc&0xff];
635b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    }
636b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
637b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    if(resultLen<buflen) {
638b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        resultChars[resultLen] = 0;
639b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    }
640b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
641b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    return resultLen;
642b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho}
643b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
644b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*
645b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Jitterbug 2439 -- markus 20030425
646b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *
647b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * The lookup of display names must not fall back through the default
648b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * locale because that yields useless results.
649b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */
650b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void TestDisplayNames()
651b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{
652b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UChar buffer[100];
653b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode errorCode=U_ZERO_ERROR;
654b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t length;
655b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    log_verbose("Testing getDisplayName for different locales\n");
656b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
657b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    log_verbose("  In locale = en_US...\n");
658b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    doTestDisplayNames("en_US", DLANG_EN);
659b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    log_verbose("  In locale = fr_FR....\n");
660b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    doTestDisplayNames("fr_FR", DLANG_FR);
661b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    log_verbose("  In locale = ca_ES...\n");
662b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    doTestDisplayNames("ca_ES", DLANG_CA);
663b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    log_verbose("  In locale = gr_EL..\n");
664b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    doTestDisplayNames("el_GR", DLANG_EL);
665b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
666b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* test that the default locale has a display name for its own language */
667b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    errorCode=U_ZERO_ERROR;
668b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    length=uloc_getDisplayLanguage(NULL, NULL, buffer, LENGTHOF(buffer), &errorCode);
669b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(U_FAILURE(errorCode) || (length<=3 && buffer[0]<=0x7f)) {
670b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        /* check <=3 to reject getting the language code as a display name */
6716d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru        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));
672b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
673b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
674b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* test that we get the language code itself for an unknown language, and a default warning */
675b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    errorCode=U_ZERO_ERROR;
676b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    length=uloc_getDisplayLanguage("qq", "rr", buffer, LENGTHOF(buffer), &errorCode);
677b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(errorCode!=U_USING_DEFAULT_WARNING || length!=2 || buffer[0]!=0x71 || buffer[1]!=0x71) {
678b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_err("error getting the display string for an unknown language - %s\n", u_errorName(errorCode));
679b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
680b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
681b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* test that we get a default warning for a display name where one component is unknown (4255) */
682b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    errorCode=U_ZERO_ERROR;
683b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    length=uloc_getDisplayName("qq_US_POSIX", "en_US", buffer, LENGTHOF(buffer), &errorCode);
684b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(errorCode!=U_USING_DEFAULT_WARNING) {
685b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_err("error getting the display name for a locale with an unknown language - %s\n", u_errorName(errorCode));
686b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
687b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
688b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {
689b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        int32_t i;
690b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        static const char *aLocale = "es@collation=traditional;calendar=japanese";
691b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        static const char *testL[] = { "en_US",
692b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            "fr_FR",
693b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            "ca_ES",
694b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            "el_GR" };
695b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        static const char *expect[] = { "Spanish (Calendar=Japanese Calendar, Sort Order=Traditional Sort Order)", /* note sorted order of keywords */
69659d709d503bab6e2b61931737e662dd293b40578ccornelius            "espagnol (calendrier=Calendrier japonais, ordre de tri=Ordre traditionnel)",
69759d709d503bab6e2b61931737e662dd293b40578ccornelius            "espanyol (calendari=calendari japon\\u00e8s, ordenaci\\u00f3=ordre tradicional)",
69859d709d503bab6e2b61931737e662dd293b40578ccornelius            "\\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)" };
699b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        UChar *expectBuffer;
700b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
701b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        for(i=0;i<LENGTHOF(testL);i++) {
702b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            errorCode = U_ZERO_ERROR;
703b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            uloc_getDisplayName(aLocale, testL[i], buffer, LENGTHOF(buffer), &errorCode);
704b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            if(U_FAILURE(errorCode)) {
705b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                log_err("FAIL in uloc_getDisplayName(%s,%s,..) -> %s\n", aLocale, testL[i], u_errorName(errorCode));
706b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            } else {
707b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                expectBuffer = CharsToUChars(expect[i]);
708b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                if(u_strcmp(buffer,expectBuffer)) {
7096d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru                    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));
710b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                } else {
711b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    log_verbose("pass in uloc_getDisplayName(%s,%s,..) got '%s'\n", aLocale, testL[i], expect[i]);
712b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                }
713b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                free(expectBuffer);
714b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            }
715b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
716b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
717b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
718b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    /* test that we properly preflight and return data when there's a non-default pattern,
719b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho       see ticket #8262. */
720b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    {
721b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        int32_t i;
722b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        static const char *locale="az_Cyrl";
723b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        static const char *displayLocale="ja";
724b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        static const char *expectedChars =
72559d709d503bab6e2b61931737e662dd293b40578ccornelius                "\\u30a2\\u30bc\\u30eb\\u30d0\\u30a4\\u30b8\\u30e3\\u30f3\\u8a9e "
726b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                "(\\u30ad\\u30ea\\u30eb\\u6587\\u5b57)";
727b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        UErrorCode ec=U_ZERO_ERROR;
728b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        UChar result[256];
729b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        int32_t len;
730b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        int32_t preflightLen=uloc_getDisplayName(locale, displayLocale, NULL, 0, &ec);
731b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        /* inconvenient semantics when preflighting, this condition is expected... */
732b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        if(ec==U_BUFFER_OVERFLOW_ERROR) {
733b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            ec=U_ZERO_ERROR;
734b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        }
735b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        len=uloc_getDisplayName(locale, displayLocale, result, LENGTHOF(result), &ec);
736b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        if(U_FAILURE(ec)) {
737b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            log_err("uloc_getDisplayName(%s, %s...) returned error: %s",
738b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                    locale, displayLocale, u_errorName(ec));
739b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        } else {
740b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            UChar *expected=CharsToUChars(expectedChars);
741b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            int32_t expectedLen=u_strlen(expected);
742b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
743b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            if(len!=expectedLen) {
744b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                log_data_err("uloc_getDisplayName(%s, %s...) returned string of length %d, expected length %d",
745b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                        locale, displayLocale, len, expectedLen);
746b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            } else if(preflightLen!=expectedLen) {
747b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                log_err("uloc_getDisplayName(%s, %s...) returned preflight length %d, expected length %d",
748b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                        locale, displayLocale, preflightLen, expectedLen);
749b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            } else if(u_strncmp(result, expected, len)) {
750b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                int32_t cap=len*6+1;  /* worst case + space for trailing null */
751b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                char* resultChars=(char*)malloc(cap);
752b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                int32_t resultCharsLen=UCharsToEscapedAscii(result, len, resultChars, cap);
753b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                if(resultCharsLen<0 || resultCharsLen<cap-1) {
754b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                    log_err("uloc_getDisplayName(%s, %s...) mismatch", locale, displayLocale);
755b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                } else {
756b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                    log_err("uloc_getDisplayName(%s, %s...) returned '%s' but expected '%s'",
757b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                            locale, displayLocale, resultChars, expectedChars);
758b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                }
759b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                free(resultChars);
760b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                resultChars=NULL;
761b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            } else {
762b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                /* test all buffer sizes */
763b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                for(i=len+1;i>=0;--i) {
764b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                    len=uloc_getDisplayName(locale, displayLocale, result, i, &ec);
765b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                    if(ec==U_BUFFER_OVERFLOW_ERROR) {
766b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                        ec=U_ZERO_ERROR;
767b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                    }
768b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                    if(U_FAILURE(ec)) {
769b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                        log_err("using buffer of length %d returned error %s", i, u_errorName(ec));
770b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                        break;
771b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                    }
772b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                    if(len!=expectedLen) {
773b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                        log_err("with buffer of length %d, expected length %d but got %d", i, expectedLen, len);
774b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                        break;
775b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                    }
776b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                    /* There's no guarantee about what's in the buffer if we've overflowed, in particular,
777b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                     * we don't know that it's been filled, so no point in checking. */
778b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho                }
779b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            }
780b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
781b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho            free(expected);
782b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        }
783b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    }
784b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
785b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
786b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
787b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/* test for uloc_getAvialable()  and uloc_countAvilable()*/
788b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void TestGetAvailableLocales()
789b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{
790b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
791b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    const char *locList;
792b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t locCount,i;
793b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
794b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    log_verbose("Testing the no of avialable locales\n");
795b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    locCount=uloc_countAvailable();
796b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (locCount == 0)
797b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_data_err("countAvailable() returned an empty list!\n");
798b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
799b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* use something sensible w/o hardcoding the count */
800b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    else if(locCount < 0){
801b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_data_err("countAvailable() returned a wrong value!= %d\n", locCount);
802b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
803b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    else{
804b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_info("Number of locales returned = %d\n", locCount);
805b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
806b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    for(i=0;i<locCount;i++){
807b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        locList=uloc_getAvailable(i);
808b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
809b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_verbose(" %s\n", locList);
810b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
811b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
812b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
813b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/* test for u_getDataDirectory, u_setDataDirectory, uloc_getISO3Language */
814b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void TestDataDirectory()
815b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{
816b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
817b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    char            oldDirectory[512];
818b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    const char     *temp,*testValue1,*testValue2,*testValue3;
819b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    const char path[40] ="d:\\icu\\source\\test\\intltest" U_FILE_SEP_STRING; /*give the required path */
820b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
821b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    log_verbose("Testing getDataDirectory()\n");
822b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    temp = u_getDataDirectory();
823b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    strcpy(oldDirectory, temp);
824b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
825b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    testValue1=uloc_getISO3Language("en_US");
826b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    log_verbose("first fetch of language retrieved  %s\n", testValue1);
827b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
828b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (0 != strcmp(testValue1,"eng")){
829b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_err("Initial check of ISO3 language failed: expected \"eng\", got  %s \n", testValue1);
830b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
831b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
832b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /*defining the path for DataDirectory */
833b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    log_verbose("Testing setDataDirectory\n");
834b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    u_setDataDirectory( path );
835b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(strcmp(path, u_getDataDirectory())==0)
836b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_verbose("setDataDirectory working fine\n");
837b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    else
838b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_err("Error in setDataDirectory. Directory not set correctly - came back as [%s], expected [%s]\n", u_getDataDirectory(), path);
839b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
840b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    testValue2=uloc_getISO3Language("en_US");
841b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    log_verbose("second fetch of language retrieved  %s \n", testValue2);
842b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
843b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    u_setDataDirectory(oldDirectory);
844b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    testValue3=uloc_getISO3Language("en_US");
845b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    log_verbose("third fetch of language retrieved  %s \n", testValue3);
846b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
847b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (0 != strcmp(testValue3,"eng")) {
848b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru       log_err("get/setDataDirectory() failed: expected \"eng\", got \" %s  \" \n", testValue3);
849b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
850b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
851b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
852b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
853b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
854b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*=========================================================== */
855b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
856b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic UChar _NUL=0;
857b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
858b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void doTestDisplayNames(const char* displayLocale, int32_t compareIndex)
859b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{
860b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
861b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t i;
862b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t maxresultsize;
863b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
864b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    const char *testLocale;
865b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
866b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
867b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UChar  *testLang  = 0;
868b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UChar  *testScript  = 0;
869b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UChar  *testCtry = 0;
870b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UChar  *testVar = 0;
871b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UChar  *testName = 0;
872b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
873b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
874b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UChar*  expectedLang = 0;
875b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UChar*  expectedScript = 0;
876b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UChar*  expectedCtry = 0;
877b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UChar*  expectedVar = 0;
878b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UChar*  expectedName = 0;
879b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
880b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QuerusetUpDataTable();
881b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
882b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    for(i=0;i<LOCALE_SIZE; ++i)
883b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {
884b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        testLocale=rawData2[NAME][i];
885b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
886b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_verbose("Testing.....  %s\n", testLocale);
887b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
888b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        maxresultsize=0;
889b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        maxresultsize=uloc_getDisplayLanguage(testLocale, displayLocale, NULL, maxresultsize, &status);
890b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(status==U_BUFFER_OVERFLOW_ERROR)
891b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {
892b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            status=U_ZERO_ERROR;
893b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            testLang=(UChar*)malloc(sizeof(UChar) * (maxresultsize+1));
894b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            uloc_getDisplayLanguage(testLocale, displayLocale, testLang, maxresultsize + 1, &status);
895b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
896b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        else
897b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {
898b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            testLang=&_NUL;
899b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
900b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(U_FAILURE(status)){
901b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("Error in getDisplayLanguage()  %s\n", myErrorName(status));
902b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
903b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
904b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        maxresultsize=0;
905b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        maxresultsize=uloc_getDisplayScript(testLocale, displayLocale, NULL, maxresultsize, &status);
906b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(status==U_BUFFER_OVERFLOW_ERROR)
907b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {
908b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            status=U_ZERO_ERROR;
909b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            testScript=(UChar*)malloc(sizeof(UChar) * (maxresultsize+1));
910b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            uloc_getDisplayScript(testLocale, displayLocale, testScript, maxresultsize + 1, &status);
911b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
912b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        else
913b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {
914b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            testScript=&_NUL;
915b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
916b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(U_FAILURE(status)){
917b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("Error in getDisplayScript()  %s\n", myErrorName(status));
918b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
919b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
920b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        maxresultsize=0;
921b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        maxresultsize=uloc_getDisplayCountry(testLocale, displayLocale, NULL, maxresultsize, &status);
922b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(status==U_BUFFER_OVERFLOW_ERROR)
923b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {
924b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            status=U_ZERO_ERROR;
925b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            testCtry=(UChar*)malloc(sizeof(UChar) * (maxresultsize+1));
926b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            uloc_getDisplayCountry(testLocale, displayLocale, testCtry, maxresultsize + 1, &status);
927b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
928b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        else
929b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {
930b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            testCtry=&_NUL;
931b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
932b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(U_FAILURE(status)){
933b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("Error in getDisplayCountry()  %s\n", myErrorName(status));
934b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
935b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
936b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        maxresultsize=0;
937b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        maxresultsize=uloc_getDisplayVariant(testLocale, displayLocale, NULL, maxresultsize, &status);
938b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(status==U_BUFFER_OVERFLOW_ERROR)
939b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {
940b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            status=U_ZERO_ERROR;
941b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            testVar=(UChar*)malloc(sizeof(UChar) * (maxresultsize+1));
942b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            uloc_getDisplayVariant(testLocale, displayLocale, testVar, maxresultsize + 1, &status);
943b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
944b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        else
945b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {
946b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            testVar=&_NUL;
947b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
948b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(U_FAILURE(status)){
949b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                log_err("Error in getDisplayVariant()  %s\n", myErrorName(status));
950b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
951b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
952b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        maxresultsize=0;
953b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        maxresultsize=uloc_getDisplayName(testLocale, displayLocale, NULL, maxresultsize, &status);
954b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(status==U_BUFFER_OVERFLOW_ERROR)
955b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {
956b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            status=U_ZERO_ERROR;
957b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            testName=(UChar*)malloc(sizeof(UChar) * (maxresultsize+1));
958b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            uloc_getDisplayName(testLocale, displayLocale, testName, maxresultsize + 1, &status);
959b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
960b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        else
961b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {
962b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            testName=&_NUL;
963b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
964b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(U_FAILURE(status)){
965b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("Error in getDisplayName()  %s\n", myErrorName(status));
966b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
967b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
968b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        expectedLang=dataTable[compareIndex][i];
969b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(u_strlen(expectedLang)== 0)
970b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            expectedLang=dataTable[DLANG_EN][i];
971b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
972b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        expectedScript=dataTable[compareIndex + 1][i];
973b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(u_strlen(expectedScript)== 0)
974b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            expectedScript=dataTable[DSCRIPT_EN][i];
975b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
976b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        expectedCtry=dataTable[compareIndex + 2][i];
977b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(u_strlen(expectedCtry)== 0)
978b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            expectedCtry=dataTable[DCTRY_EN][i];
979b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
980b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        expectedVar=dataTable[compareIndex + 3][i];
981b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(u_strlen(expectedVar)== 0)
982b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            expectedVar=dataTable[DVAR_EN][i];
983b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
984b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        expectedName=dataTable[compareIndex + 4][i];
985b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(u_strlen(expectedName) == 0)
986b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            expectedName=dataTable[DNAME_EN][i];
987b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
988b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (0 !=u_strcmp(testLang,expectedLang))  {
9896d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru            log_data_err(" Display Language mismatch: got %s expected %s displayLocale=%s (Are you missing data?)\n", austrdup(testLang), austrdup(expectedLang), displayLocale);
990b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
991b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
992b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (0 != u_strcmp(testScript,expectedScript))   {
9936d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru            log_data_err(" Display Script mismatch: got %s expected %s displayLocale=%s (Are you missing data?)\n", austrdup(testScript), austrdup(expectedScript), displayLocale);
994b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
995b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
996b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (0 != u_strcmp(testCtry,expectedCtry))   {
9976d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru            log_data_err(" Display Country mismatch: got %s expected %s displayLocale=%s (Are you missing data?)\n", austrdup(testCtry), austrdup(expectedCtry), displayLocale);
998b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
999b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1000b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (0 != u_strcmp(testVar,expectedVar))    {
10016d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru            log_data_err(" Display Variant mismatch: got %s expected %s displayLocale=%s (Are you missing data?)\n", austrdup(testVar), austrdup(expectedVar), displayLocale);
1002b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1003b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1004b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(0 != u_strcmp(testName, expectedName))    {
10056d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru            log_data_err(" Display Name mismatch: got %s expected %s displayLocale=%s (Are you missing data?)\n", austrdup(testName), austrdup(expectedName), displayLocale);
1006b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1007b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1008b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(testName!=&_NUL) {
1009b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            free(testName);
1010b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1011b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(testLang!=&_NUL) {
1012b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            free(testLang);
1013b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1014b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(testScript!=&_NUL) {
1015b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            free(testScript);
1016b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1017b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(testCtry!=&_NUL) {
1018b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            free(testCtry);
1019b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1020b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(testVar!=&_NUL) {
1021b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            free(testVar);
1022b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1023b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1024b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QuerucleanUpDataTable();
1025b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
1026b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
102759d709d503bab6e2b61931737e662dd293b40578ccornelius/*------------------------------
102859d709d503bab6e2b61931737e662dd293b40578ccornelius * TestDisplayNameBrackets
102959d709d503bab6e2b61931737e662dd293b40578ccornelius */
103059d709d503bab6e2b61931737e662dd293b40578ccornelius
103159d709d503bab6e2b61931737e662dd293b40578ccorneliustypedef struct {
103259d709d503bab6e2b61931737e662dd293b40578ccornelius    const char * displayLocale;
103359d709d503bab6e2b61931737e662dd293b40578ccornelius    const char * namedRegion;
103459d709d503bab6e2b61931737e662dd293b40578ccornelius    const char * namedLocale;
103559d709d503bab6e2b61931737e662dd293b40578ccornelius    const char * regionName;
103659d709d503bab6e2b61931737e662dd293b40578ccornelius    const char * localeName;
103759d709d503bab6e2b61931737e662dd293b40578ccornelius} DisplayNameBracketsItem;
103859d709d503bab6e2b61931737e662dd293b40578ccornelius
103959d709d503bab6e2b61931737e662dd293b40578ccorneliusstatic const DisplayNameBracketsItem displayNameBracketsItems[] = {
104059d709d503bab6e2b61931737e662dd293b40578ccornelius    { "en", "CC", "en_CC",      "Cocos (Keeling) Islands",  "English (Cocos [Keeling] Islands)"  },
104159d709d503bab6e2b61931737e662dd293b40578ccornelius    { "en", "MM", "my_MM",      "Myanmar (Burma)",          "Burmese (Myanmar [Burma])"          },
104259d709d503bab6e2b61931737e662dd293b40578ccornelius    { "en", "MM", "my_Mymr_MM", "Myanmar (Burma)",          "Burmese (Myanmar, Myanmar [Burma])" },
104359d709d503bab6e2b61931737e662dd293b40578ccornelius    { "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" },
104459d709d503bab6e2b61931737e662dd293b40578ccornelius    { "zh", "CG", "fr_CG",      "\\u521A\\u679C\\uFF08\\u5E03\\uFF09",                             "\\u6CD5\\u6587\\uFF08\\u521A\\u679C\\uFF3B\\u5E03\\uFF3D\\uFF09" },
104559d709d503bab6e2b61931737e662dd293b40578ccornelius    { NULL, NULL, NULL,         NULL,                       NULL                                 }
104659d709d503bab6e2b61931737e662dd293b40578ccornelius};
104759d709d503bab6e2b61931737e662dd293b40578ccornelius
104859d709d503bab6e2b61931737e662dd293b40578ccorneliusenum { kDisplayNameBracketsMax = 128 };
104959d709d503bab6e2b61931737e662dd293b40578ccornelius
105059d709d503bab6e2b61931737e662dd293b40578ccorneliusstatic void TestDisplayNameBrackets()
105159d709d503bab6e2b61931737e662dd293b40578ccornelius{
105259d709d503bab6e2b61931737e662dd293b40578ccornelius    const DisplayNameBracketsItem * itemPtr = displayNameBracketsItems;
105359d709d503bab6e2b61931737e662dd293b40578ccornelius    for (; itemPtr->displayLocale != NULL; itemPtr++) {
105459d709d503bab6e2b61931737e662dd293b40578ccornelius        ULocaleDisplayNames * uldn;
105559d709d503bab6e2b61931737e662dd293b40578ccornelius        UErrorCode status;
105659d709d503bab6e2b61931737e662dd293b40578ccornelius        UChar expectRegionName[kDisplayNameBracketsMax];
105759d709d503bab6e2b61931737e662dd293b40578ccornelius        UChar expectLocaleName[kDisplayNameBracketsMax];
105859d709d503bab6e2b61931737e662dd293b40578ccornelius        UChar getName[kDisplayNameBracketsMax];
105959d709d503bab6e2b61931737e662dd293b40578ccornelius        int32_t ulen;
106059d709d503bab6e2b61931737e662dd293b40578ccornelius
106159d709d503bab6e2b61931737e662dd293b40578ccornelius        (void) u_unescape(itemPtr->regionName, expectRegionName, kDisplayNameBracketsMax);
106259d709d503bab6e2b61931737e662dd293b40578ccornelius        (void) u_unescape(itemPtr->localeName, expectLocaleName, kDisplayNameBracketsMax);
106359d709d503bab6e2b61931737e662dd293b40578ccornelius
106459d709d503bab6e2b61931737e662dd293b40578ccornelius        status = U_ZERO_ERROR;
106559d709d503bab6e2b61931737e662dd293b40578ccornelius        ulen = uloc_getDisplayCountry(itemPtr->namedLocale, itemPtr->displayLocale, getName, kDisplayNameBracketsMax, &status);
106659d709d503bab6e2b61931737e662dd293b40578ccornelius        if ( U_FAILURE(status) || u_strcmp(getName, expectRegionName) != 0 ) {
106759d709d503bab6e2b61931737e662dd293b40578ccornelius            log_data_err("uloc_getDisplayCountry for displayLocale %s and namedLocale %s returns unexpected name or status %s\n", itemPtr->displayLocale, itemPtr->namedLocale, myErrorName(status));
106859d709d503bab6e2b61931737e662dd293b40578ccornelius        }
106959d709d503bab6e2b61931737e662dd293b40578ccornelius
107059d709d503bab6e2b61931737e662dd293b40578ccornelius        status = U_ZERO_ERROR;
107159d709d503bab6e2b61931737e662dd293b40578ccornelius        ulen = uloc_getDisplayName(itemPtr->namedLocale, itemPtr->displayLocale, getName, kDisplayNameBracketsMax, &status);
107259d709d503bab6e2b61931737e662dd293b40578ccornelius        if ( U_FAILURE(status) || u_strcmp(getName, expectLocaleName) != 0 ) {
107359d709d503bab6e2b61931737e662dd293b40578ccornelius            log_data_err("uloc_getDisplayName for displayLocale %s and namedLocale %s returns unexpected name or status %s\n", itemPtr->displayLocale, itemPtr->namedLocale, myErrorName(status));
107459d709d503bab6e2b61931737e662dd293b40578ccornelius        }
107559d709d503bab6e2b61931737e662dd293b40578ccornelius
107659d709d503bab6e2b61931737e662dd293b40578ccornelius#if !UCONFIG_NO_FORMATTING
107759d709d503bab6e2b61931737e662dd293b40578ccornelius        status = U_ZERO_ERROR;
107859d709d503bab6e2b61931737e662dd293b40578ccornelius        uldn = uldn_open(itemPtr->displayLocale, ULDN_STANDARD_NAMES, &status);
107959d709d503bab6e2b61931737e662dd293b40578ccornelius        if (U_SUCCESS(status)) {
108059d709d503bab6e2b61931737e662dd293b40578ccornelius            status = U_ZERO_ERROR;
108159d709d503bab6e2b61931737e662dd293b40578ccornelius            ulen = uldn_regionDisplayName(uldn, itemPtr->namedRegion, getName, kDisplayNameBracketsMax, &status);
108259d709d503bab6e2b61931737e662dd293b40578ccornelius            if ( U_FAILURE(status) || u_strcmp(getName, expectRegionName) != 0 ) {
108359d709d503bab6e2b61931737e662dd293b40578ccornelius                log_data_err("uldn_regionDisplayName for displayLocale %s and namedRegion %s returns unexpected name or status %s\n", itemPtr->displayLocale, itemPtr->namedRegion, myErrorName(status));
108459d709d503bab6e2b61931737e662dd293b40578ccornelius            }
108559d709d503bab6e2b61931737e662dd293b40578ccornelius
108659d709d503bab6e2b61931737e662dd293b40578ccornelius            status = U_ZERO_ERROR;
108759d709d503bab6e2b61931737e662dd293b40578ccornelius            ulen = uldn_localeDisplayName(uldn, itemPtr->namedLocale, getName, kDisplayNameBracketsMax, &status);
108859d709d503bab6e2b61931737e662dd293b40578ccornelius            if ( U_FAILURE(status) || u_strcmp(getName, expectLocaleName) != 0 ) {
108959d709d503bab6e2b61931737e662dd293b40578ccornelius                log_data_err("uldn_localeDisplayName for displayLocale %s and namedLocale %s returns unexpected name or status %s\n", itemPtr->displayLocale, itemPtr->namedLocale, myErrorName(status));
109059d709d503bab6e2b61931737e662dd293b40578ccornelius            }
109159d709d503bab6e2b61931737e662dd293b40578ccornelius
109259d709d503bab6e2b61931737e662dd293b40578ccornelius            uldn_close(uldn);
109359d709d503bab6e2b61931737e662dd293b40578ccornelius        } else {
109459d709d503bab6e2b61931737e662dd293b40578ccornelius            log_data_err("uldn_open fails for displayLocale %s, status=%s\n", itemPtr->displayLocale, u_errorName(status));
109559d709d503bab6e2b61931737e662dd293b40578ccornelius        }
109659d709d503bab6e2b61931737e662dd293b40578ccornelius#endif
1097fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius    (void)ulen;   /* Suppress variable not used warning */
109859d709d503bab6e2b61931737e662dd293b40578ccornelius    }
109959d709d503bab6e2b61931737e662dd293b40578ccornelius}
110059d709d503bab6e2b61931737e662dd293b40578ccornelius
110159d709d503bab6e2b61931737e662dd293b40578ccornelius/*------------------------------
110259d709d503bab6e2b61931737e662dd293b40578ccornelius * TestISOFunctions
110359d709d503bab6e2b61931737e662dd293b40578ccornelius */
110459d709d503bab6e2b61931737e662dd293b40578ccornelius
110554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius#if !UCONFIG_NO_FILE_IO && !UCONFIG_NO_LEGACY_CONVERSION
1106b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/* test for uloc_getISOLanguages, uloc_getISOCountries */
1107b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void TestISOFunctions()
1108b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{
1109b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    const char* const* str=uloc_getISOLanguages();
1110b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    const char* const* str1=uloc_getISOCountries();
1111b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    const char* test;
1112b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    const char *key = NULL;
1113b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t count = 0, skipped = 0;
1114b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t expect;
1115b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UResourceBundle *res;
1116b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UResourceBundle *subRes;
1117b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
1118b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1119b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /*  test getISOLanguages*/
1120b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /*str=uloc_getISOLanguages(); */
1121b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    log_verbose("Testing ISO Languages: \n");
1122b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1123b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* use structLocale - this data is no longer in root */
1124b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    res = ures_openDirect(loadTestData(&status), "structLocale", &status);
1125b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    subRes = ures_getByKey(res, "Languages", NULL, &status);
1126b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (U_FAILURE(status)) {
1127c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru        log_data_err("There is an error in structLocale's ures_getByKey(\"Languages\"), status=%s\n", u_errorName(status));
1128b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        return;
1129b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1130b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1131b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect = ures_getSize(subRes);
1132b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    for(count = 0; *(str+count) != 0; count++)
1133b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {
1134b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        key = NULL;
1135b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        test = *(str+count);
1136b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        status = U_ZERO_ERROR;
1137b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1138b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        do {
1139b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            /* Skip over language tags. This API only returns language codes. */
1140b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            skipped += (key != NULL);
1141b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            ures_getNextString(subRes, NULL, &key, &status);
1142b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1143b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        while (key != NULL && strchr(key, '_'));
1144b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1145b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(key == NULL)
1146b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            break;
1147b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        /* TODO: Consider removing sh, which is deprecated */
1148b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(strcmp(key,"root") == 0 || strcmp(key,"Fallback") == 0 || strcmp(key,"sh") == 0) {
1149b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            ures_getNextString(subRes, NULL, &key, &status);
1150b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            skipped++;
1151b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1152b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#if U_CHARSET_FAMILY==U_ASCII_FAMILY
1153b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        /* This code only works on ASCII machines where the keys are stored in ASCII order */
1154b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(strcmp(test,key)) {
1155b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            /* The first difference usually implies the place where things get out of sync */
1156b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("FAIL Language diff at offset %d, \"%s\" != \"%s\"\n", count, test, key);
1157b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1158b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#endif
1159b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1160b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(!strcmp(test,"in"))
1161b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("FAIL getISOLanguages() has obsolete language code %s\n", test);
1162b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(!strcmp(test,"iw"))
1163b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("FAIL getISOLanguages() has obsolete language code %s\n", test);
1164b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(!strcmp(test,"ji"))
1165b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("FAIL getISOLanguages() has obsolete language code %s\n", test);
1166b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(!strcmp(test,"jw"))
1167b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("FAIL getISOLanguages() has obsolete language code %s\n", test);
1168b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(!strcmp(test,"sh"))
1169b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("FAIL getISOLanguages() has obsolete language code %s\n", test);
1170b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1171b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1172b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect -= skipped; /* Ignore the skipped resources from structLocale */
1173b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1174b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(count!=expect) {
1175b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_err("There is an error in getISOLanguages, got %d, expected %d (as per structLocale)\n", count, expect);
1176b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1177b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1178b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    subRes = ures_getByKey(res, "Countries", subRes, &status);
1179b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    log_verbose("Testing ISO Countries");
1180b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    skipped = 0;
1181b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect = ures_getSize(subRes) - 1; /* Skip ZZ */
1182b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    for(count = 0; *(str1+count) != 0; count++)
1183b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {
1184b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        key = NULL;
1185b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        test = *(str1+count);
1186b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        do {
1187b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            /* Skip over numeric UN tags. This API only returns ISO-3166 codes. */
1188b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            skipped += (key != NULL);
1189b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            ures_getNextString(subRes, NULL, &key, &status);
1190b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1191b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        while (key != NULL && strlen(key) != 2);
1192b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1193b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(key == NULL)
1194b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            break;
1195b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        /* TODO: Consider removing CS, which is deprecated */
1196b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        while(strcmp(key,"QO") == 0 || strcmp(key,"QU") == 0 || strcmp(key,"CS") == 0) {
1197b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            ures_getNextString(subRes, NULL, &key, &status);
1198b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            skipped++;
1199b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1200b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#if U_CHARSET_FAMILY==U_ASCII_FAMILY
1201b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        /* This code only works on ASCII machines where the keys are stored in ASCII order */
1202b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(strcmp(test,key)) {
1203b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            /* The first difference usually implies the place where things get out of sync */
1204b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("FAIL Country diff at offset %d, \"%s\" != \"%s\"\n", count, test, key);
1205b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1206b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#endif
1207b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(!strcmp(test,"FX"))
1208b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("FAIL getISOCountries() has obsolete country code %s\n", test);
1209b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(!strcmp(test,"YU"))
1210b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("FAIL getISOCountries() has obsolete country code %s\n", test);
1211b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(!strcmp(test,"ZR"))
1212b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("FAIL getISOCountries() has obsolete country code %s\n", test);
1213b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1214b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1215b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    ures_getNextString(subRes, NULL, &key, &status);
1216b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (strcmp(key, "ZZ") != 0) {
1217b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_err("ZZ was expected to be the last entry in structLocale, but got %s\n", key);
1218b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1219b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#if U_CHARSET_FAMILY==U_EBCDIC_FAMILY
1220b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* On EBCDIC machines, the numbers are sorted last. Account for those in the skipped value too. */
1221b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    key = NULL;
1222b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    do {
1223b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        /* Skip over numeric UN tags. uloc_getISOCountries only returns ISO-3166 codes. */
1224b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        skipped += (key != NULL);
1225b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        ures_getNextString(subRes, NULL, &key, &status);
1226b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1227b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    while (U_SUCCESS(status) && key != NULL && strlen(key) != 2);
1228b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#endif
1229b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    expect -= skipped; /* Ignore the skipped resources from structLocale */
1230b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(count!=expect)
1231b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {
1232b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_err("There is an error in getISOCountries, got %d, expected %d \n", count, expect);
1233b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1234b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    ures_close(subRes);
1235b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    ures_close(res);
1236b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
123754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius#endif
1238b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1239b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void setUpDataTable()
1240b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{
1241b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t i,j;
1242b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    dataTable = (UChar***)(calloc(sizeof(UChar**),LOCALE_INFO_SIZE));
1243b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1244b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    for (i = 0; i < LOCALE_INFO_SIZE; i++) {
1245b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        dataTable[i] = (UChar**)(calloc(sizeof(UChar*),LOCALE_SIZE));
1246b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        for (j = 0; j < LOCALE_SIZE; j++){
1247b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            dataTable[i][j] = CharsToUChars(rawData2[i][j]);
1248b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1249b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1250b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
1251b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1252b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void cleanUpDataTable()
1253b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{
1254b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t i,j;
1255b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(dataTable != NULL) {
1256b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        for (i=0; i<LOCALE_INFO_SIZE; i++) {
1257b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            for(j = 0; j < LOCALE_SIZE; j++) {
1258b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                free(dataTable[i][j]);
1259b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            }
1260b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            free(dataTable[i]);
1261b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1262b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        free(dataTable);
1263b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1264b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    dataTable = NULL;
1265b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
1266b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1267b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/**
1268b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * @bug 4011756 4011380
1269b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */
1270b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void TestISO3Fallback()
1271b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{
1272b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    const char* test="xx_YY";
1273b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1274b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    const char * result;
1275b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1276b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    result = uloc_getISO3Language(test);
1277b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1278b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* Conform to C API usage  */
1279b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1280b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (!result || (result[0] != 0))
1281b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru       log_err("getISO3Language() on xx_YY returned %s instead of \"\"");
1282b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1283b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    result = uloc_getISO3Country(test);
1284b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1285b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (!result || (result[0] != 0))
1286b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_err("getISO3Country() on xx_YY returned %s instead of \"\"");
1287b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
1288b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1289b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/**
1290b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * @bug 4118587
1291b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */
1292b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void TestSimpleDisplayNames()
1293b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{
1294b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  /*
1295b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru     This test is different from TestDisplayNames because TestDisplayNames checks
1296b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru     fallback behavior, combination of language and country names to form locale
1297b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru     names, and other stuff like that.  This test just checks specific language
1298b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru     and country codes to make sure we have the correct names for them.
1299b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  */
1300b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru    char languageCodes[] [4] = { "he", "id", "iu", "ug", "yi", "za", "419" };
13018393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius    const char* languageNames [] = { "Hebrew", "Indonesian", "Inuktitut", "Uyghur", "Yiddish",
1302b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru                               "Zhuang", "419" };
1303b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru    const char* inLocale [] = { "en_US", "zh_Hant"};
1304b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode status=U_ZERO_ERROR;
1305b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1306b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t i;
1307b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru    int32_t localeIndex = 0;
1308b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru    for (i = 0; i < 7; i++) {
1309b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        UChar *testLang=0;
1310b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        UChar *expectedLang=0;
1311b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        int size=0;
1312b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru
1313b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru        if (i == 6) {
1314b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru            localeIndex = 1; /* Use the second locale for the rest of the test. */
1315b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru        }
1316b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru
1317b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru        size=uloc_getDisplayLanguage(languageCodes[i], inLocale[localeIndex], NULL, size, &status);
1318b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(status==U_BUFFER_OVERFLOW_ERROR) {
1319b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            status=U_ZERO_ERROR;
1320b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            testLang=(UChar*)malloc(sizeof(UChar) * (size + 1));
1321b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru            uloc_getDisplayLanguage(languageCodes[i], inLocale[localeIndex], testLang, size + 1, &status);
1322b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1323b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        expectedLang=(UChar*)malloc(sizeof(UChar) * (strlen(languageNames[i])+1));
1324b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        u_uastrcpy(expectedLang, languageNames[i]);
1325b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (u_strcmp(testLang, expectedLang) != 0)
1326b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_data_err("Got wrong display name for %s : Expected \"%s\", got \"%s\".\n",
1327b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    languageCodes[i], languageNames[i], austrdup(testLang));
1328b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        free(testLang);
1329b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        free(expectedLang);
1330b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1331b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1332b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
1333b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1334b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/**
1335b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * @bug 4118595
1336b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */
1337b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void TestUninstalledISO3Names()
1338b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{
1339b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  /* This test checks to make sure getISO3Language and getISO3Country work right
1340b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru     even for locales that are not installed. */
1341b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    static const char iso2Languages [][4] = {     "am", "ba", "fy", "mr", "rn",
1342b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                                        "ss", "tw", "zu" };
1343b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    static const char iso3Languages [][5] = {     "amh", "bak", "fry", "mar", "run",
1344b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                                        "ssw", "twi", "zul" };
1345b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    static const char iso2Countries [][6] = {     "am_AF", "ba_BW", "fy_KZ", "mr_MO", "rn_MN",
1346b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                                        "ss_SB", "tw_TC", "zu_ZW" };
1347b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    static const char iso3Countries [][4] = {     "AFG", "BWA", "KAZ", "MAC", "MNG",
1348b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                                        "SLB", "TCA", "ZWE" };
1349b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t i;
1350b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1351b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    for (i = 0; i < 8; i++) {
1352b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru      UErrorCode err = U_ZERO_ERROR;
1353b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru      const char *test;
1354b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru      test = uloc_getISO3Language(iso2Languages[i]);
1355b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru      if(strcmp(test, iso3Languages[i]) !=0 || U_FAILURE(err))
1356b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru         log_err("Got wrong ISO3 code for %s : Expected \"%s\", got \"%s\". %s\n",
1357b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                     iso2Languages[i], iso3Languages[i], test, myErrorName(err));
1358b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1359b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    for (i = 0; i < 8; i++) {
1360b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru      UErrorCode err = U_ZERO_ERROR;
1361b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru      const char *test;
1362b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru      test = uloc_getISO3Country(iso2Countries[i]);
1363b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru      if(strcmp(test, iso3Countries[i]) !=0 || U_FAILURE(err))
1364b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru         log_err("Got wrong ISO3 code for %s : Expected \"%s\", got \"%s\". %s\n",
1365b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                     iso2Countries[i], iso3Countries[i], test, myErrorName(err));
1366b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1367b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
1368b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1369b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1370b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void TestVariantParsing()
1371b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{
1372b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    static const char* en_US_custom="en_US_De Anza_Cupertino_California_United States_Earth";
1373b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    static const char* dispName="English (United States, DE ANZA_CUPERTINO_CALIFORNIA_UNITED STATES_EARTH)";
1374b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    static const char* dispVar="DE ANZA_CUPERTINO_CALIFORNIA_UNITED STATES_EARTH";
1375b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    static const char* shortVariant="fr_FR_foo";
1376b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    static const char* bogusVariant="fr_FR__foo";
1377b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    static const char* bogusVariant2="fr_FR_foo_";
1378b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    static const char* bogusVariant3="fr_FR__foo_";
1379b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1380b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1381b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UChar displayVar[100];
1382b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UChar displayName[100];
1383b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode status=U_ZERO_ERROR;
1384b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UChar* got=0;
1385b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t size=0;
1386b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    size=uloc_getDisplayVariant(en_US_custom, "en_US", NULL, size, &status);
1387b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(status==U_BUFFER_OVERFLOW_ERROR) {
1388b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        status=U_ZERO_ERROR;
1389b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        got=(UChar*)realloc(got, sizeof(UChar) * (size+1));
1390b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        uloc_getDisplayVariant(en_US_custom, "en_US", got, size + 1, &status);
1391b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1392b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    else {
1393b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_err("FAIL: Didn't get U_BUFFER_OVERFLOW_ERROR\n");
1394b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1395b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    u_uastrcpy(displayVar, dispVar);
1396b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(u_strcmp(got,displayVar)!=0) {
1397b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_err("FAIL: getDisplayVariant() Wanted %s, got %s\n", dispVar, austrdup(got));
1398b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1399b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    size=0;
1400b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    size=uloc_getDisplayName(en_US_custom, "en_US", NULL, size, &status);
1401b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(status==U_BUFFER_OVERFLOW_ERROR) {
1402b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        status=U_ZERO_ERROR;
1403b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        got=(UChar*)realloc(got, sizeof(UChar) * (size+1));
1404b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        uloc_getDisplayName(en_US_custom, "en_US", got, size + 1, &status);
1405b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1406b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    else {
1407b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_err("FAIL: Didn't get U_BUFFER_OVERFLOW_ERROR\n");
1408b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1409b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    u_uastrcpy(displayName, dispName);
1410b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(u_strcmp(got,displayName)!=0) {
14116d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru        if (status == U_USING_DEFAULT_WARNING) {
14126d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru            log_data_err("FAIL: getDisplayName() got %s. Perhaps you are missing data?\n", u_errorName(status));
14136d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru        } else {
14146d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru            log_err("FAIL: getDisplayName() Wanted %s, got %s\n", dispName, austrdup(got));
14156d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru        }
1416b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1417b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1418b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    size=0;
1419b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    status=U_ZERO_ERROR;
1420b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    size=uloc_getDisplayVariant(shortVariant, NULL, NULL, size, &status);
1421b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(status==U_BUFFER_OVERFLOW_ERROR) {
1422b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        status=U_ZERO_ERROR;
1423b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        got=(UChar*)realloc(got, sizeof(UChar) * (size+1));
1424b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        uloc_getDisplayVariant(shortVariant, NULL, got, size + 1, &status);
1425b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1426b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    else {
1427b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_err("FAIL: Didn't get U_BUFFER_OVERFLOW_ERROR\n");
1428b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1429b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(strcmp(austrdup(got),"FOO")!=0) {
1430b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_err("FAIL: getDisplayVariant()  Wanted: foo  Got: %s\n", austrdup(got));
1431b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1432b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    size=0;
1433b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    status=U_ZERO_ERROR;
1434b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    size=uloc_getDisplayVariant(bogusVariant, NULL, NULL, size, &status);
1435b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(status==U_BUFFER_OVERFLOW_ERROR) {
1436b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        status=U_ZERO_ERROR;
1437b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        got=(UChar*)realloc(got, sizeof(UChar) * (size+1));
1438b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        uloc_getDisplayVariant(bogusVariant, NULL, got, size + 1, &status);
1439b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1440b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    else {
1441b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_err("FAIL: Didn't get U_BUFFER_OVERFLOW_ERROR\n");
1442b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1443b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(strcmp(austrdup(got),"_FOO")!=0) {
1444b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_err("FAIL: getDisplayVariant()  Wanted: _FOO  Got: %s\n", austrdup(got));
1445b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1446b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    size=0;
1447b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    status=U_ZERO_ERROR;
1448b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    size=uloc_getDisplayVariant(bogusVariant2, NULL, NULL, size, &status);
1449b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(status==U_BUFFER_OVERFLOW_ERROR) {
1450b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        status=U_ZERO_ERROR;
1451b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        got=(UChar*)realloc(got, sizeof(UChar) * (size+1));
1452b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        uloc_getDisplayVariant(bogusVariant2, NULL, got, size + 1, &status);
1453b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1454b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    else {
1455b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_err("FAIL: Didn't get U_BUFFER_OVERFLOW_ERROR\n");
1456b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1457b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(strcmp(austrdup(got),"FOO_")!=0) {
1458b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_err("FAIL: getDisplayVariant()  Wanted: FOO_  Got: %s\n", austrdup(got));
1459b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1460b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    size=0;
1461b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    status=U_ZERO_ERROR;
1462b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    size=uloc_getDisplayVariant(bogusVariant3, NULL, NULL, size, &status);
1463b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(status==U_BUFFER_OVERFLOW_ERROR) {
1464b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        status=U_ZERO_ERROR;
1465b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        got=(UChar*)realloc(got, sizeof(UChar) * (size+1));
1466b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        uloc_getDisplayVariant(bogusVariant3, NULL, got, size + 1, &status);
1467b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1468b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    else {
1469b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_err("FAIL: Didn't get U_BUFFER_OVERFLOW_ERROR\n");
1470b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1471b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(strcmp(austrdup(got),"_FOO_")!=0) {
1472b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_err("FAIL: getDisplayVariant()  Wanted: _FOO_  Got: %s\n", austrdup(got));
1473b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1474b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    free(got);
1475b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
1476b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1477b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1478b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void TestObsoleteNames(void)
1479b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{
1480b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t i;
1481b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
1482b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    char buff[256];
1483b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1484b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    static const struct
1485b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {
1486b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        char locale[9];
1487b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        char lang3[4];
1488b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        char lang[4];
1489b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        char ctry3[4];
1490b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        char ctry[4];
1491b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    } tests[] =
1492b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {
1493b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "eng_USA", "eng", "en", "USA", "US" },
1494b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "kok",  "kok", "kok", "", "" },
1495b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "in",  "ind", "in", "", "" },
1496b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "id",  "ind", "id", "", "" }, /* NO aliasing */
1497b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "sh",  "srp", "sh", "", "" },
1498b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "zz_CS",  "", "zz", "SCG", "CS" },
1499b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "zz_FX",  "", "zz", "FXX", "FX" },
1500b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "zz_RO",  "", "zz", "ROU", "RO" },
1501b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "zz_TP",  "", "zz", "TMP", "TP" },
1502b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "zz_TL",  "", "zz", "TLS", "TL" },
1503b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "zz_ZR",  "", "zz", "ZAR", "ZR" },
1504b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "zz_FXX",  "", "zz", "FXX", "FX" }, /* no aliasing. Doesn't go to PS(PSE). */
1505b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "zz_ROM",  "", "zz", "ROU", "RO" },
1506b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "zz_ROU",  "", "zz", "ROU", "RO" },
1507b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "zz_ZAR",  "", "zz", "ZAR", "ZR" },
1508b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "zz_TMP",  "", "zz", "TMP", "TP" },
1509b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "zz_TLS",  "", "zz", "TLS", "TL" },
1510b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "zz_YUG",  "", "zz", "YUG", "YU" },
1511b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "mlt_PSE", "mlt", "mt", "PSE", "PS" },
1512b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "iw", "heb", "iw", "", "" },
1513b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "ji", "yid", "ji", "", "" },
1514b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "jw", "jaw", "jw", "", "" },
1515b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "sh", "srp", "sh", "", "" },
1516b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "", "", "", "", "" }
1517b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    };
1518b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1519b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    for(i=0;tests[i].locale[0];i++)
1520b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {
1521b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        const char *locale;
1522b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1523b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        locale = tests[i].locale;
1524b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_verbose("** %s:\n", locale);
1525b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1526b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        status = U_ZERO_ERROR;
1527b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(strcmp(tests[i].lang3,uloc_getISO3Language(locale)))
1528b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {
1529b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("FAIL: uloc_getISO3Language(%s)==\t\"%s\",\t expected \"%s\"\n",
1530b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                locale,  uloc_getISO3Language(locale), tests[i].lang3);
1531b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1532b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        else
1533b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {
1534b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_verbose("   uloc_getISO3Language()==\t\"%s\"\n",
1535b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                uloc_getISO3Language(locale) );
1536b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1537b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1538b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        status = U_ZERO_ERROR;
1539b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        uloc_getLanguage(locale, buff, 256, &status);
1540b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(U_FAILURE(status))
1541b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {
1542b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("FAIL: error getting language from %s\n", locale);
1543b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1544b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        else
1545b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {
1546b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            if(strcmp(buff,tests[i].lang))
1547b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            {
1548b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                log_err("FAIL: uloc_getLanguage(%s)==\t\"%s\"\t expected \"%s\"\n",
1549b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    locale, buff, tests[i].lang);
1550b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            }
1551b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            else
1552b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            {
1553b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                log_verbose("  uloc_getLanguage(%s)==\t%s\n", locale, buff);
1554b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            }
1555b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1556b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(strcmp(tests[i].lang3,uloc_getISO3Language(locale)))
1557b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {
1558b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("FAIL: uloc_getISO3Language(%s)==\t\"%s\",\t expected \"%s\"\n",
1559b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                locale,  uloc_getISO3Language(locale), tests[i].lang3);
1560b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1561b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        else
1562b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {
1563b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_verbose("   uloc_getISO3Language()==\t\"%s\"\n",
1564b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                uloc_getISO3Language(locale) );
1565b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1566b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1567b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(strcmp(tests[i].ctry3,uloc_getISO3Country(locale)))
1568b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {
1569b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("FAIL: uloc_getISO3Country(%s)==\t\"%s\",\t expected \"%s\"\n",
1570b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                locale,  uloc_getISO3Country(locale), tests[i].ctry3);
1571b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1572b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        else
1573b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {
1574b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_verbose("   uloc_getISO3Country()==\t\"%s\"\n",
1575b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                uloc_getISO3Country(locale) );
1576b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1577b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1578b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        status = U_ZERO_ERROR;
1579b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        uloc_getCountry(locale, buff, 256, &status);
1580b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(U_FAILURE(status))
1581b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {
1582b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("FAIL: error getting country from %s\n", locale);
1583b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1584b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        else
1585b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {
1586b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            if(strcmp(buff,tests[i].ctry))
1587b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            {
1588b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                log_err("FAIL: uloc_getCountry(%s)==\t\"%s\"\t expected \"%s\"\n",
1589b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    locale, buff, tests[i].ctry);
1590b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            }
1591b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            else
1592b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            {
1593b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                log_verbose("  uloc_getCountry(%s)==\t%s\n", locale, buff);
1594b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            }
1595b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1596b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1597b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1598b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (uloc_getLCID("iw_IL") != uloc_getLCID("he_IL")) {
1599b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_err("he,iw LCID mismatch: %X versus %X\n", uloc_getLCID("iw_IL"), uloc_getLCID("he_IL"));
1600b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1601b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1602b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (uloc_getLCID("iw") != uloc_getLCID("he")) {
1603b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_err("he,iw LCID mismatch: %X versus %X\n", uloc_getLCID("iw"), uloc_getLCID("he"));
1604b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1605b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1606b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#if 0
1607b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1608b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    i = uloc_getLanguage("kok",NULL,0,&icu_err);
1609b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(U_FAILURE(icu_err))
1610b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {
1611b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_err("FAIL: Got %s trying to do uloc_getLanguage(kok)\n", u_errorName(icu_err));
1612b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1613b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1614b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    icu_err = U_ZERO_ERROR;
1615b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    uloc_getLanguage("kok",r1_buff,12,&icu_err);
1616b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(U_FAILURE(icu_err))
1617b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {
1618b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_err("FAIL: Got %s trying to do uloc_getLanguage(kok, buff)\n", u_errorName(icu_err));
1619b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1620b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1621b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    r1_addr = (char *)uloc_getISO3Language("kok");
1622b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1623b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    icu_err = U_ZERO_ERROR;
1624b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (strcmp(r1_buff,"kok") != 0)
1625b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {
1626b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_err("FAIL: uloc_getLanguage(kok)==%s not kok\n",r1_buff);
1627b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        line--;
1628b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1629b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    r1_addr = (char *)uloc_getISO3Language("in");
1630b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    i = uloc_getLanguage(r1_addr,r1_buff,12,&icu_err);
1631b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (strcmp(r1_buff,"id") != 0)
1632b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {
1633b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        printf("uloc_getLanguage error (%s)\n",r1_buff);
1634b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        line--;
1635b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1636b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    r1_addr = (char *)uloc_getISO3Language("sh");
1637b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    i = uloc_getLanguage(r1_addr,r1_buff,12,&icu_err);
1638b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (strcmp(r1_buff,"sr") != 0)
1639b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {
1640b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        printf("uloc_getLanguage error (%s)\n",r1_buff);
1641b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        line--;
1642b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1643b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1644b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    r1_addr = (char *)uloc_getISO3Country("zz_ZR");
1645b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    strcpy(p1_buff,"zz_");
1646b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    strcat(p1_buff,r1_addr);
1647b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    i = uloc_getCountry(p1_buff,r1_buff,12,&icu_err);
1648b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (strcmp(r1_buff,"ZR") != 0)
1649b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {
1650b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        printf("uloc_getCountry error (%s)\n",r1_buff);
1651b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        line--;
1652b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1653b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    r1_addr = (char *)uloc_getISO3Country("zz_FX");
1654b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    strcpy(p1_buff,"zz_");
1655b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    strcat(p1_buff,r1_addr);
1656b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    i = uloc_getCountry(p1_buff,r1_buff,12,&icu_err);
1657b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if (strcmp(r1_buff,"FX") != 0)
1658b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {
1659b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        printf("uloc_getCountry error (%s)\n",r1_buff);
1660b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        line--;
1661b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1662b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1663b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#endif
1664b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1665b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
1666b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1667b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void TestKeywordVariants(void)
1668b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{
1669b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    static const struct {
1670b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        const char *localeID;
1671b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        const char *expectedLocaleID;
1672b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        const char *expectedLocaleIDNoKeywords;
1673b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        const char *expectedCanonicalID;
1674b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        const char *expectedKeywords[10];
1675b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        int32_t numKeywords;
1676b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        UErrorCode expectedStatus; /* from uloc_openKeywords */
1677b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    } testCases[] = {
1678b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {
1679b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            "de_DE@  currency = euro; C o ll A t i o n   = Phonebook   ; C alen dar = buddhist   ",
1680b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            "de_DE@calendar=buddhist;collation=Phonebook;currency=euro",
1681b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            "de_DE",
1682b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            "de_DE@calendar=buddhist;collation=Phonebook;currency=euro",
1683b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            {"calendar", "collation", "currency"},
1684b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            3,
1685b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            U_ZERO_ERROR
1686b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        },
1687b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {
1688b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            "de_DE@euro",
1689b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            "de_DE@euro",
1690b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            "de_DE",
1691b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            "de_DE@currency=EUR",
1692b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            {"","","","","","",""},
1693b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            0,
1694b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            U_INVALID_FORMAT_ERROR /* must have '=' after '@' */
1695b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        },
1696b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {
1697b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            "de_DE@euro;collation=phonebook",
1698b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            "de_DE", /* error result; bad format */
1699b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            "de_DE", /* error result; bad format */
1700b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            "de_DE", /* error result; bad format */
1701b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            {"","","","","","",""},
1702b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            0,
1703b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            U_INVALID_FORMAT_ERROR
1704b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1705b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    };
1706b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
1707b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1708b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t i = 0, j = 0;
1709b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t resultLen = 0;
1710b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    char buffer[256];
1711b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UEnumeration *keywords;
1712b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t keyCount = 0;
1713b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    const char *keyword = NULL;
1714b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t keywordLen = 0;
1715b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1716b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    for(i = 0; i < sizeof(testCases)/sizeof(testCases[0]); i++) {
1717b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        status = U_ZERO_ERROR;
1718b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        *buffer = 0;
1719b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        keywords = uloc_openKeywords(testCases[i].localeID, &status);
1720b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1721b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(status != testCases[i].expectedStatus) {
1722b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("Expected to uloc_openKeywords(\"%s\") => status %s. Got %s instead\n",
1723b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    testCases[i].localeID,
1724b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    u_errorName(testCases[i].expectedStatus), u_errorName(status));
1725b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1726b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        status = U_ZERO_ERROR;
1727b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(keywords) {
1728b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            if((keyCount = uenum_count(keywords, &status)) != testCases[i].numKeywords) {
1729b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                log_err("Expected to get %i keywords, got %i\n", testCases[i].numKeywords, keyCount);
1730b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            }
1731b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            if(keyCount) {
1732b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                j = 0;
1733b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                while((keyword = uenum_next(keywords, &keywordLen, &status))) {
1734b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    if(strcmp(keyword, testCases[i].expectedKeywords[j]) != 0) {
1735b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                        log_err("Expected to get keyword value %s, got %s\n", testCases[i].expectedKeywords[j], keyword);
1736b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    }
1737b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    j++;
1738b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                }
1739b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                j = 0;
1740b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                uenum_reset(keywords, &status);
1741b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                while((keyword = uenum_next(keywords, &keywordLen, &status))) {
1742b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    if(strcmp(keyword, testCases[i].expectedKeywords[j]) != 0) {
1743b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                        log_err("Expected to get keyword value %s, got %s\n", testCases[i].expectedKeywords[j], keyword);
1744b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    }
1745b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    j++;
1746b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                }
1747b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            }
1748b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            uenum_close(keywords);
1749b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1750b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        resultLen = uloc_getName(testCases[i].localeID, buffer, 256, &status);
175159d709d503bab6e2b61931737e662dd293b40578ccornelius        (void)resultLen;    /* Suppress set but not used warning. */
1752b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (uprv_strcmp(testCases[i].expectedLocaleID, buffer) != 0) {
1753b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("Expected uloc_getName(\"%s\") => \"%s\"; got \"%s\"\n",
1754b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    testCases[i].localeID, testCases[i].expectedLocaleID, buffer);
1755b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1756b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        resultLen = uloc_canonicalize(testCases[i].localeID, buffer, 256, &status);
1757b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (uprv_strcmp(testCases[i].expectedCanonicalID, buffer) != 0) {
1758b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("Expected uloc_canonicalize(\"%s\") => \"%s\"; got \"%s\"\n",
1759b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                    testCases[i].localeID, testCases[i].expectedCanonicalID, buffer);
1760b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1761b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1762b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1763b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
1764b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1765b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void TestKeywordVariantParsing(void)
1766b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{
1767b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    static const struct {
1768b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        const char *localeID;
1769b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        const char *keyword;
1770b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        const char *expectedValue;
1771b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    } testCases[] = {
1772b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "de_DE@  C o ll A t i o n   = Phonebook   ", "c o ll a t i o n", "Phonebook" },
1773b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "de_DE", "collation", ""},
1774b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "de_DE@collation=PHONEBOOK", "collation", "PHONEBOOK" },
1775b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "de_DE@currency = euro; CoLLaTion   = PHONEBOOk", "collatiON", "PHONEBOOk" },
1776b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    };
1777b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1778b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
1779b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1780b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t i = 0;
1781b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t resultLen = 0;
1782b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    char buffer[256];
1783b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1784b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    for(i = 0; i < sizeof(testCases)/sizeof(testCases[0]); i++) {
1785b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        *buffer = 0;
1786b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        resultLen = uloc_getKeywordValue(testCases[i].localeID, testCases[i].keyword, buffer, 256, &status);
178759d709d503bab6e2b61931737e662dd293b40578ccornelius        (void)resultLen;    /* Suppress set but not used warning. */
1788b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(uprv_strcmp(testCases[i].expectedValue, buffer) != 0) {
1789b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("Expected to extract \"%s\" from \"%s\" for keyword \"%s\". Got \"%s\" instead\n",
1790b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                testCases[i].expectedValue, testCases[i].localeID, testCases[i].keyword, buffer);
1791b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1792b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1793b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
1794b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1795b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic const struct {
1796b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  const char *l; /* locale */
1797b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  const char *k; /* kw */
1798b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  const char *v; /* value */
1799b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  const char *x; /* expected */
1800b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} kwSetTestCases[] = {
1801b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#if 1
1802b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  { "en_US", "calendar", "japanese", "en_US@calendar=japanese" },
1803b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  { "en_US@", "calendar", "japanese", "en_US@calendar=japanese" },
1804b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  { "en_US@calendar=islamic", "calendar", "japanese", "en_US@calendar=japanese" },
1805b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  { "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 */
1806b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  { "en_US@calendar=gregorian", "calendar", "japanese", "en_US@calendar=japanese" },
1807b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  { "de", "Currency", "CHF", "de@currency=CHF" },
1808b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  { "de", "Currency", "CHF", "de@currency=CHF" },
1809b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1810b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  { "en_US@collation=phonebook", "calendar", "japanese", "en_US@calendar=japanese;collation=phonebook" },
1811b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  { "en_US@calendar=japanese", "collation", "phonebook", "en_US@calendar=japanese;collation=phonebook" },
1812b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  { "de@collation=phonebook", "Currency", "CHF", "de@collation=phonebook;currency=CHF" },
1813b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  { "en_US@calendar=gregorian;collation=phonebook", "calendar", "japanese", "en_US@calendar=japanese;collation=phonebook" },
1814b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  { "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 */
1815b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  { "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 */
1816b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  { "en_US@calendar=islamic;collation=phonebook", "calendar", "japanese", "en_US@calendar=japanese;collation=phonebook" },
1817b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  { "de@collation=phonebook", "Currency", "CHF", "de@collation=phonebook;currency=CHF" },
1818b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#endif
1819b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#if 1
1820b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  { "mt@a=0;b=1;c=2;d=3", "c","j", "mt@a=0;b=1;c=j;d=3" },
1821b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  { "mt@a=0;b=1;c=2;d=3", "x","j", "mt@a=0;b=1;c=2;d=3;x=j" },
1822b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  { "mt@a=0;b=1;c=2;d=3", "a","f", "mt@a=f;b=1;c=2;d=3" },
1823b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  { "mt@a=0;aa=1;aaa=3", "a","x", "mt@a=x;aa=1;aaa=3" },
1824b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  { "mt@a=0;aa=1;aaa=3", "aa","x", "mt@a=0;aa=x;aaa=3" },
1825b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  { "mt@a=0;aa=1;aaa=3", "aaa","x", "mt@a=0;aa=1;aaa=x" },
1826b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  { "mt@a=0;aa=1;aaa=3", "a","yy", "mt@a=yy;aa=1;aaa=3" },
1827b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  { "mt@a=0;aa=1;aaa=3", "aa","yy", "mt@a=0;aa=yy;aaa=3" },
1828b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  { "mt@a=0;aa=1;aaa=3", "aaa","yy", "mt@a=0;aa=1;aaa=yy" },
1829b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#endif
1830b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#if 1
1831b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  /* removal tests */
1832b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  /* 1. removal of item at end */
1833b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  { "de@collation=phonebook;currency=CHF", "currency",   "", "de@collation=phonebook" },
1834b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  { "de@collation=phonebook;currency=CHF", "currency", NULL, "de@collation=phonebook" },
1835b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  /* 2. removal of item at beginning */
1836b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  { "de@collation=phonebook;currency=CHF", "collation", "", "de@currency=CHF" },
1837b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  { "de@collation=phonebook;currency=CHF", "collation", NULL, "de@currency=CHF" },
1838b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  /* 3. removal of an item not there */
1839b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  { "de@collation=phonebook;currency=CHF", "calendar", NULL, "de@collation=phonebook;currency=CHF" },
1840b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  /* 4. removal of only item */
1841b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  { "de@collation=phonebook", "collation", NULL, "de" },
1842b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#endif
1843b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru  { "de@collation=phonebook", "Currency", "CHF", "de@collation=phonebook;currency=CHF" }
1844b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru};
1845b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1846b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1847b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void TestKeywordSet(void)
1848b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{
1849b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t i = 0;
1850b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t resultLen = 0;
1851b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    char buffer[1024];
1852b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1853b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    char cbuffer[1024];
1854b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1855b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    for(i = 0; i < sizeof(kwSetTestCases)/sizeof(kwSetTestCases[0]); i++) {
1856b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        UErrorCode status = U_ZERO_ERROR;
1857b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        memset(buffer,'%',1023);
1858b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        strcpy(buffer, kwSetTestCases[i].l);
1859b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1860b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        uloc_canonicalize(kwSetTestCases[i].l, cbuffer, 1023, &status);
1861b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(strcmp(buffer,cbuffer)) {
1862b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru          log_verbose("note: [%d] wasn't canonical, should be: '%s' not '%s'. Won't check for canonicity in output.\n", i, cbuffer, buffer);
1863b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1864b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru          /* sanity check test case results for canonicity */
1865b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        uloc_canonicalize(kwSetTestCases[i].x, cbuffer, 1023, &status);
1866b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(strcmp(kwSetTestCases[i].x,cbuffer)) {
1867b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru          log_err("%s:%d: ERROR: kwSetTestCases[%d].x = '%s', should be %s (must be canonical)\n", __FILE__, __LINE__, i, kwSetTestCases[i].x, cbuffer);
1868b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1869b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1870b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        resultLen = uloc_setKeywordValue(kwSetTestCases[i].k, kwSetTestCases[i].v, buffer, 1023, &status);
1871b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(U_FAILURE(status)) {
1872b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru          log_err("Err on test case %d: got error %s\n", i, u_errorName(status));
1873b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru          continue;
1874b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1875b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(strcmp(buffer,kwSetTestCases[i].x) || ((int32_t)strlen(buffer)!=resultLen)) {
1876b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru          log_err("FAIL: #%d: %s + [%s=%s] -> %s (%d) expected %s (%d)\n", i, kwSetTestCases[i].l, kwSetTestCases[i].k,
1877b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  kwSetTestCases[i].v, buffer, resultLen, kwSetTestCases[i].x, strlen(buffer));
1878b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        } else {
1879b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru          log_verbose("pass: #%d: %s + [%s=%s] -> %s\n", i, kwSetTestCases[i].l, kwSetTestCases[i].k, kwSetTestCases[i].v,buffer);
1880b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1881b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1882b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
1883b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1884b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void TestKeywordSetError(void)
1885b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{
1886b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    char buffer[1024];
1887b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode status;
1888b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t res;
1889b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t i;
1890b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t blen;
1891b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1892b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* 0-test whether an error condition modifies the buffer at all */
1893b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    blen=0;
1894b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    i=0;
1895b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    memset(buffer,'%',1023);
1896b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    status = U_ZERO_ERROR;
1897b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    res = uloc_setKeywordValue(kwSetTestCases[i].k, kwSetTestCases[i].v, buffer, blen, &status);
1898b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(status != U_ILLEGAL_ARGUMENT_ERROR) {
1899b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_err("expected illegal err got %s\n", u_errorName(status));
1900b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        return;
1901b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1902b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /*  if(res!=strlen(kwSetTestCases[i].x)) {
1903b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    log_err("expected result %d got %d\n", strlen(kwSetTestCases[i].x), res);
1904b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    return;
1905b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    } */
1906b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(buffer[blen]!='%') {
1907b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_err("Buffer byte %d was modified: now %c\n", blen, buffer[blen]);
1908b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        return;
1909b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1910b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    log_verbose("0-buffer modify OK\n");
1911b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1912b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    for(i=0;i<=2;i++) {
1913b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        /* 1- test a short buffer with growing text */
1914b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        blen=(int32_t)strlen(kwSetTestCases[i].l)+1;
1915b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        memset(buffer,'%',1023);
1916b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        strcpy(buffer,kwSetTestCases[i].l);
1917b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        status = U_ZERO_ERROR;
1918b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        res = uloc_setKeywordValue(kwSetTestCases[i].k, kwSetTestCases[i].v, buffer, blen, &status);
1919b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(status != U_BUFFER_OVERFLOW_ERROR) {
1920b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            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);
1921b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            return;
1922b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1923b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(res!=(int32_t)strlen(kwSetTestCases[i].x)) {
1924b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("expected result %d got %d\n", strlen(kwSetTestCases[i].x), res);
1925b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            return;
1926b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1927b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(buffer[blen]!='%') {
1928b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("Buffer byte %d was modified: now %c\n", blen, buffer[blen]);
1929b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            return;
1930b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1931b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_verbose("1/%d-buffer modify OK\n",i);
1932b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1933b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1934b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    for(i=3;i<=4;i++) {
1935b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        /* 2- test a short buffer - text the same size or shrinking   */
1936b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        blen=(int32_t)strlen(kwSetTestCases[i].l)+1;
1937b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        memset(buffer,'%',1023);
1938b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        strcpy(buffer,kwSetTestCases[i].l);
1939b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        status = U_ZERO_ERROR;
1940b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        res = uloc_setKeywordValue(kwSetTestCases[i].k, kwSetTestCases[i].v, buffer, blen, &status);
1941b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(status != U_ZERO_ERROR) {
1942b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("expected zero error got %s\n", u_errorName(status));
1943b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            return;
1944b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1945b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(buffer[blen+1]!='%') {
1946b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("Buffer byte %d was modified: now %c\n", blen+1, buffer[blen+1]);
1947b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            return;
1948b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1949b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(res!=(int32_t)strlen(kwSetTestCases[i].x)) {
1950b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("expected result %d got %d\n", strlen(kwSetTestCases[i].x), res);
1951b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            return;
1952b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1953b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(strcmp(buffer,kwSetTestCases[i].x) || ((int32_t)strlen(buffer)!=res)) {
1954b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_err("FAIL: #%d: %s + [%s=%s] -> %s (%d) expected %s (%d)\n", i, kwSetTestCases[i].l, kwSetTestCases[i].k,
1955b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                kwSetTestCases[i].v, buffer, res, kwSetTestCases[i].x, strlen(buffer));
1956b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        } else {
1957b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            log_verbose("pass: #%d: %s + [%s=%s] -> %s\n", i, kwSetTestCases[i].l, kwSetTestCases[i].k, kwSetTestCases[i].v,
1958b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                buffer);
1959b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
1960b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        log_verbose("2/%d-buffer modify OK\n",i);
1961b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1962b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
1963b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1964b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic int32_t _canonicalize(int32_t selector, /* 0==getName, 1==canonicalize */
1965b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                             const char* localeID,
1966b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                             char* result,
1967b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                             int32_t resultCapacity,
1968b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                             UErrorCode* ec) {
1969b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* YOU can change this to use function pointers if you like */
1970b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    switch (selector) {
1971b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    case 0:
1972b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        return uloc_getName(localeID, result, resultCapacity, ec);
1973b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    case 1:
1974b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        return uloc_canonicalize(localeID, result, resultCapacity, ec);
1975b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    default:
1976b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        return -1;
1977b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
1978b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
1979b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1980b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void TestCanonicalization(void)
1981b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{
1982b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    static const struct {
1983b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        const char *localeID;    /* input */
1984b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        const char *getNameID;   /* expected getName() result */
1985b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        const char *canonicalID; /* expected canonicalize() result */
1986b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    } testCases[] = {
1987b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "ca_ES_PREEURO-with-extra-stuff-that really doesn't make any sense-unless-you're trying to increase code coverage",
1988b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru          "ca_ES_PREEURO_WITH_EXTRA_STUFF_THAT REALLY DOESN'T MAKE ANY SENSE_UNLESS_YOU'RE TRYING TO INCREASE CODE COVERAGE",
1989b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru          "ca_ES_PREEURO_WITH_EXTRA_STUFF_THAT REALLY DOESN'T MAKE ANY SENSE_UNLESS_YOU'RE TRYING TO INCREASE CODE COVERAGE"},
1990b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "ca_ES_PREEURO", "ca_ES_PREEURO", "ca_ES@currency=ESP" },
1991b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "de_AT_PREEURO", "de_AT_PREEURO", "de_AT@currency=ATS" },
1992b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "de_DE_PREEURO", "de_DE_PREEURO", "de_DE@currency=DEM" },
1993b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "de_LU_PREEURO", "de_LU_PREEURO", "de_LU@currency=LUF" },
1994b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "el_GR_PREEURO", "el_GR_PREEURO", "el_GR@currency=GRD" },
1995b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "en_BE_PREEURO", "en_BE_PREEURO", "en_BE@currency=BEF" },
1996b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "en_IE_PREEURO", "en_IE_PREEURO", "en_IE@currency=IEP" },
1997b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "es_ES_PREEURO", "es_ES_PREEURO", "es_ES@currency=ESP" },
1998b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "eu_ES_PREEURO", "eu_ES_PREEURO", "eu_ES@currency=ESP" },
1999b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "fi_FI_PREEURO", "fi_FI_PREEURO", "fi_FI@currency=FIM" },
2000b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "fr_BE_PREEURO", "fr_BE_PREEURO", "fr_BE@currency=BEF" },
2001b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "fr_FR_PREEURO", "fr_FR_PREEURO", "fr_FR@currency=FRF" },
2002b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "fr_LU_PREEURO", "fr_LU_PREEURO", "fr_LU@currency=LUF" },
2003b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "ga_IE_PREEURO", "ga_IE_PREEURO", "ga_IE@currency=IEP" },
2004b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "gl_ES_PREEURO", "gl_ES_PREEURO", "gl_ES@currency=ESP" },
2005b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "it_IT_PREEURO", "it_IT_PREEURO", "it_IT@currency=ITL" },
2006b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "nl_BE_PREEURO", "nl_BE_PREEURO", "nl_BE@currency=BEF" },
2007b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "nl_NL_PREEURO", "nl_NL_PREEURO", "nl_NL@currency=NLG" },
2008b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "pt_PT_PREEURO", "pt_PT_PREEURO", "pt_PT@currency=PTE" },
2009b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "de__PHONEBOOK", "de__PHONEBOOK", "de@collation=phonebook" },
2010b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "en_GB_EURO", "en_GB_EURO", "en_GB@currency=EUR" },
2011b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "en_GB@EURO", "en_GB@EURO", "en_GB@currency=EUR" }, /* POSIX ID */
2012b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "es__TRADITIONAL", "es__TRADITIONAL", "es@collation=traditional" },
2013b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "hi__DIRECT", "hi__DIRECT", "hi@collation=direct" },
2014b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "ja_JP_TRADITIONAL", "ja_JP_TRADITIONAL", "ja_JP@calendar=japanese" },
2015b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "th_TH_TRADITIONAL", "th_TH_TRADITIONAL", "th_TH@calendar=buddhist" },
2016c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru        { "zh_TW_STROKE", "zh_TW_STROKE", "zh_TW@collation=stroke" },
2017b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "zh__PINYIN", "zh__PINYIN", "zh@collation=pinyin" },
2018b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "zh@collation=pinyin", "zh@collation=pinyin", "zh@collation=pinyin" },
2019b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "zh_CN@collation=pinyin", "zh_CN@collation=pinyin", "zh_CN@collation=pinyin" },
2020c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru        { "zh_CN_STROKE", "zh_CN_STROKE", "zh_CN@collation=stroke" },
2021b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "zh_CN_CA@collation=pinyin", "zh_CN_CA@collation=pinyin", "zh_CN_CA@collation=pinyin" },
2022b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "en_US_POSIX", "en_US_POSIX", "en_US_POSIX" },
2023b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "hy_AM_REVISED", "hy_AM_REVISED", "hy_AM_REVISED" },
2024b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "no_NO_NY", "no_NO_NY", "no_NO_NY" /* not: "nn_NO" [alan ICU3.0] */ },
2025b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "no@ny", "no@ny", "no__NY" /* not: "nn" [alan ICU3.0] */ }, /* POSIX ID */
2026b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "no-no.utf32@B", "no_NO.utf32@B", "no_NO_B" /* not: "nb_NO_B" [alan ICU3.0] */ }, /* POSIX ID */
2027b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "qz-qz@Euro", "qz_QZ@Euro", "qz_QZ@currency=EUR" }, /* qz-qz uses private use iso codes */
202854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius        { "en-BOONT", "en__BOONT", "en__BOONT" }, /* registered name */
202954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius        { "de-1901", "de__1901", "de__1901" }, /* registered name */
203054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius        { "de-1906", "de__1906", "de__1906" }, /* registered name */
2031c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru        { "sr-SP-Cyrl", "sr_SP_CYRL", "sr_Cyrl_RS" }, /* .NET name */
2032c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru        { "sr-SP-Latn", "sr_SP_LATN", "sr_Latn_RS" }, /* .NET name */
2033c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru        { "sr_YU_CYRILLIC", "sr_YU_CYRILLIC", "sr_Cyrl_RS" }, /* Linux name */
2034b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "uz-UZ-Cyrl", "uz_UZ_CYRL", "uz_Cyrl_UZ" }, /* .NET name */
2035b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "uz-UZ-Latn", "uz_UZ_LATN", "uz_Latn_UZ" }, /* .NET name */
2036b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "zh-CHS", "zh_CHS", "zh_Hans" }, /* .NET name */
2037b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "zh-CHT", "zh_CHT", "zh_Hant" }, /* .NET name This may change back to zh_Hant */
2038b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
2039b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        /* posix behavior that used to be performed by getName */
2040b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "mr.utf8", "mr.utf8", "mr" },
2041b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "de-tv.koi8r", "de_TV.koi8r", "de_TV" },
2042b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "x-piglatin_ML.MBE", "x-piglatin_ML.MBE", "x-piglatin_ML" },
2043b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "i-cherokee_US.utf7", "i-cherokee_US.utf7", "i-cherokee_US" },
2044b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "x-filfli_MT_FILFLA.gb-18030", "x-filfli_MT_FILFLA.gb-18030", "x-filfli_MT_FILFLA" },
2045b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "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 */
2046b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
2047b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        /* fleshing out canonicalization */
2048b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        /* trim space and sort keywords, ';' is separator so not present at end in canonical form */
2049b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "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" },
2050b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        /* already-canonical ids are not changed */
2051b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "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" },
2052b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        /* PRE_EURO and EURO conversions don't affect other keywords */
2053b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "es_ES_PREEURO@CALendar=Japanese", "es_ES_PREEURO@calendar=Japanese", "es_ES@calendar=Japanese;currency=ESP" },
2054b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "es_ES_EURO@SHOUT=zipeedeedoodah", "es_ES_EURO@shout=zipeedeedoodah", "es_ES@currency=EUR;shout=zipeedeedoodah" },
2055b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        /* currency keyword overrides PRE_EURO and EURO currency */
2056b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "es_ES_PREEURO@currency=EUR", "es_ES_PREEURO@currency=EUR", "es_ES@currency=EUR" },
2057b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "es_ES_EURO@currency=ESP", "es_ES_EURO@currency=ESP", "es_ES@currency=ESP" },
2058b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        /* norwegian is just too weird, if we handle things in their full generality */
2059b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "no-Hant-GB_NY@currency=$$$", "no_Hant_GB_NY@currency=$$$", "no_Hant_GB_NY@currency=$$$" /* not: "nn_Hant_GB@currency=$$$" [alan ICU3.0] */ },
2060b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
2061b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        /* test cases reflecting internal resource bundle usage */
2062b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "root@kw=foo", "root@kw=foo", "root@kw=foo" },
2063b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "@calendar=gregorian", "@calendar=gregorian", "@calendar=gregorian" },
2064b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "ja_JP@calendar=Japanese", "ja_JP@calendar=Japanese", "ja_JP@calendar=Japanese" },
2065b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "ja_JP", "ja_JP", "ja_JP" },
2066b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
2067b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        /* test case for "i-default" */
2068b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho        { "i-default", "en@x=i-default", "en@x=i-default" }
2069b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    };
2070b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
2071b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    static const char* label[] = { "getName", "canonicalize" };
2072b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
2073b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UErrorCode status = U_ZERO_ERROR;
2074b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t i, j, resultLen = 0, origResultLen;
2075b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    char buffer[256];
2076b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
2077b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    for (i=0; i < sizeof(testCases)/sizeof(testCases[0]); i++) {
2078b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        for (j=0; j<2; ++j) {
2079b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            const char* expected = (j==0) ? testCases[i].getNameID : testCases[i].canonicalID;
2080b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            *buffer = 0;
2081b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            status = U_ZERO_ERROR;
2082b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
2083b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            if (expected == NULL) {
2084b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                expected = uloc_getDefault();
2085b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            }
2086b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
2087b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            /* log_verbose("testing %s -> %s\n", testCases[i], testCases[i].canonicalID); */
2088b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            origResultLen = _canonicalize(j, testCases[i].localeID, NULL, 0, &status);
2089b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            if (status != U_BUFFER_OVERFLOW_ERROR) {
2090b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                log_err("FAIL: uloc_%s(%s) => %s, expected U_BUFFER_OVERFLOW_ERROR\n",
2091b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                        label[j], testCases[i].localeID, u_errorName(status));
2092b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                continue;
2093b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            }
2094b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            status = U_ZERO_ERROR;
2095b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            resultLen = _canonicalize(j, testCases[i].localeID, buffer, sizeof(buffer), &status);
2096b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            if (U_FAILURE(status)) {
2097b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                log_err("FAIL: uloc_%s(%s) => %s, expected U_ZERO_ERROR\n",
2098b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                        label[j], testCases[i].localeID, u_errorName(status));
2099b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                continue;
2100b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            }
2101b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            if(uprv_strcmp(expected, buffer) != 0) {
2102b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                log_err("FAIL: uloc_%s(%s) => \"%s\", expected \"%s\"\n",
2103b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                        label[j], testCases[i].localeID, buffer, expected);
2104b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            } else {
2105b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                log_verbose("Ok: uloc_%s(%s) => \"%s\"\n",
2106b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                            label[j], testCases[i].localeID, buffer);
2107b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            }
2108b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            if (resultLen != (int32_t)strlen(buffer)) {
2109b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                log_err("FAIL: uloc_%s(%s) => len %d, expected len %d\n",
2110b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                        label[j], testCases[i].localeID, resultLen, strlen(buffer));
2111b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            }
2112b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            if (origResultLen != resultLen) {
2113b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                log_err("FAIL: uloc_%s(%s) => preflight len %d != actual len %d\n",
2114b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                        label[j], testCases[i].localeID, origResultLen, resultLen);
2115b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            }
2116b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
2117b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
2118b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
2119b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
2120b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void TestDisplayKeywords(void)
2121b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{
2122b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t i;
2123b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
2124b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    static const struct {
2125b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        const char *localeID;
2126b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        const char *displayLocale;
2127b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        UChar displayKeyword[200];
2128b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    } testCases[] = {
2129b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {   "ca_ES@currency=ESP",         "de_AT",
2130b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            {0x0057, 0x00e4, 0x0068, 0x0072, 0x0075, 0x006e, 0x0067, 0x0000},
2131b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        },
2132b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {   "ja_JP@calendar=japanese",         "de",
2133b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            { 0x004b, 0x0061, 0x006c, 0x0065, 0x006e, 0x0064, 0x0065, 0x0072, 0x0000}
2134b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        },
2135b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {   "de_DE@collation=traditional",       "de_DE",
2136b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            {0x0053, 0x006f, 0x0072, 0x0074, 0x0069, 0x0065, 0x0072, 0x0075, 0x006e, 0x0067, 0x0000}
2137b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        },
2138b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    };
2139b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    for(i = 0; i < sizeof(testCases)/sizeof(testCases[0]); i++) {
2140b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        UErrorCode status = U_ZERO_ERROR;
2141b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        const char* keyword =NULL;
2142b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        int32_t keywordLen = 0;
2143b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        int32_t keywordCount = 0;
2144b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        UChar *displayKeyword=NULL;
2145b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        int32_t displayKeywordLen = 0;
2146b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        UEnumeration* keywordEnum = uloc_openKeywords(testCases[i].localeID, &status);
2147b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        for(keywordCount = uenum_count(keywordEnum, &status); keywordCount > 0 ; keywordCount--){
2148b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru              if(U_FAILURE(status)){
2149b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  log_err("uloc_getKeywords failed for locale id: %s with error : %s \n", testCases[i].localeID, u_errorName(status));
2150b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  break;
2151b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru              }
2152b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru              /* the uenum_next returns NUL terminated string */
2153b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru              keyword = uenum_next(keywordEnum, &keywordLen, &status);
2154b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru              /* fetch the displayKeyword */
2155b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru              displayKeywordLen = uloc_getDisplayKeyword(keyword, testCases[i].displayLocale, displayKeyword, displayKeywordLen, &status);
2156b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru              if(status==U_BUFFER_OVERFLOW_ERROR){
2157b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  status = U_ZERO_ERROR;
2158b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  displayKeywordLen++; /* for null termination */
2159b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  displayKeyword = (UChar*) malloc(displayKeywordLen * U_SIZEOF_UCHAR);
2160b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  displayKeywordLen = uloc_getDisplayKeyword(keyword, testCases[i].displayLocale, displayKeyword, displayKeywordLen, &status);
2161b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  if(U_FAILURE(status)){
2162b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                      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));
2163b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                      break;
2164b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  }
2165b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  if(u_strncmp(displayKeyword, testCases[i].displayKeyword, displayKeywordLen)!=0){
21666d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru                      if (status == U_USING_DEFAULT_WARNING) {
21676d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru                          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));
21686d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru                      } else {
21696d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru                          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);
21706d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru                      }
2171b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                      break;
2172b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  }
2173b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru              }else{
2174b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  log_err("uloc_getDisplayKeyword did not return the expected error. Error: %s\n", u_errorName(status));
2175b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru              }
2176b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
2177b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru              free(displayKeyword);
2178b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
2179b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
2180b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        uenum_close(keywordEnum);
2181b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
2182b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
2183b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
2184b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustatic void TestDisplayKeywordValues(void){
2185b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    int32_t i;
2186b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
2187b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    static const struct {
2188b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        const char *localeID;
2189b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        const char *displayLocale;
2190b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        UChar displayKeywordValue[500];
2191b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    } testCases[] = {
2192b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {   "ca_ES@currency=ESP",         "de_AT",
2193b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru            {0x0053, 0x0070, 0x0061, 0x006e, 0x0069, 0x0073, 0x0063, 0x0068, 0x0065, 0x0020, 0x0050, 0x0065, 0x0073, 0x0065, 0x0074, 0x0061, 0x0000}
2194b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        },
2195b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {   "de_AT@currency=ATS",         "fr_FR",
2196b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            {0x0073, 0x0063, 0x0068, 0x0069, 0x006c, 0x006c, 0x0069, 0x006e, 0x0067, 0x0020, 0x0061, 0x0075, 0x0074, 0x0072, 0x0069, 0x0063, 0x0068, 0x0069, 0x0065, 0x006e, 0x0000}
2197b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        },
2198b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "de_DE@currency=DEM",         "it",
2199b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            {0x004d, 0x0061, 0x0072, 0x0063, 0x006f, 0x0020, 0x0054, 0x0065, 0x0064, 0x0065, 0x0073, 0x0063, 0x006f, 0x0000}
2200b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        },
2201b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {   "el_GR@currency=GRD",         "en",
2202b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            {0x0047, 0x0072, 0x0065, 0x0065, 0x006b, 0x0020, 0x0044, 0x0072, 0x0061, 0x0063, 0x0068, 0x006d, 0x0061, 0x0000}
2203b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        },
2204b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {   "eu_ES@currency=ESP",         "it_IT",
2205b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            {0x0050, 0x0065, 0x0073, 0x0065, 0x0074, 0x0061, 0x0020, 0x0053, 0x0070, 0x0061, 0x0067, 0x006e, 0x006f, 0x006c, 0x0061, 0x0000}
2206b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        },
2207b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        {   "de@collation=phonebook",     "es",
2208b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            {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}
2209b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        },
2210b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
2211b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "de_DE@collation=phonebook",  "es",
2212b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru          {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}
2213b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        },
2214b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "es_ES@collation=traditional","de",
2215b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru          {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}
2216b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        },
2217b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        { "ja_JP@calendar=japanese",    "de",
2218b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru           {0x004a, 0x0061, 0x0070, 0x0061, 0x006e, 0x0069, 0x0073, 0x0063, 0x0068, 0x0065, 0x0072, 0x0020, 0x004b, 0x0061, 0x006c, 0x0065, 0x006e, 0x0064, 0x0065, 0x0072, 0x0000}
2219b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        },
2220b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    };
2221b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    for(i = 0; i < sizeof(testCases)/sizeof(testCases[0]); i++) {
2222b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        UErrorCode status = U_ZERO_ERROR;
2223b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        const char* keyword =NULL;
2224b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        int32_t keywordLen = 0;
2225b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        int32_t keywordCount = 0;
2226b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        UChar *displayKeywordValue = NULL;
2227b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        int32_t displayKeywordValueLen = 0;
2228b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        UEnumeration* keywordEnum = uloc_openKeywords(testCases[i].localeID, &status);
2229b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        for(keywordCount = uenum_count(keywordEnum, &status); keywordCount > 0 ; keywordCount--){
2230b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru              if(U_FAILURE(status)){
2231b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  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));
2232b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  break;
2233b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru              }
2234b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru              /* the uenum_next returns NUL terminated string */
2235b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru              keyword = uenum_next(keywordEnum, &keywordLen, &status);
2236b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
2237b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru              /* fetch the displayKeywordValue */
2238b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru              displayKeywordValueLen = uloc_getDisplayKeywordValue(testCases[i].localeID, keyword, testCases[i].displayLocale, displayKeywordValue, displayKeywordValueLen, &status);
2239b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru              if(status==U_BUFFER_OVERFLOW_ERROR){
2240b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  status = U_ZERO_ERROR;
2241b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  displayKeywordValueLen++; /* for null termination */
2242b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  displayKeywordValue = (UChar*)malloc(displayKeywordValueLen * U_SIZEOF_UCHAR);
2243b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  displayKeywordValueLen = uloc_getDisplayKeywordValue(testCases[i].localeID, keyword, testCases[i].displayLocale, displayKeywordValue, displayKeywordValueLen, &status);
2244b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  if(U_FAILURE(status)){
2245b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                      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));
2246b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                      break;
2247b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  }
2248b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  if(u_strncmp(displayKeywordValue, testCases[i].displayKeywordValue, displayKeywordValueLen)!=0){
22496d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru                      if (status == U_USING_DEFAULT_WARNING) {
22506d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru                          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));
22516d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru                      } else {
22526d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru                          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));
22536d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru                      }
2254b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                      break;
2255b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  }
2256b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru              }else{
2257b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                  log_err("uloc_getDisplayKeywordValue did not return the expected error. Error: %s\n", u_errorName(status));
2258b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru              }
2259b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru              free(displayKeywordValue);
2260b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
2261b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        uenum_close(keywordEnum);
2262b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
2263b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    {
2264b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        /* test a multiple keywords */
2265b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        UErrorCode status = U_ZERO_ERROR;
2266b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        const char* keyword =NULL;
2267b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        int32_t keywordLen = 0;
2268b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        int32_t keywordCount = 0;
2269b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        const char* localeID = "es@collation=phonebook;calendar=buddhist;currency=DEM";
2270b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        const char* displayLocale = "de";
2271b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        static const UChar expected[][50] = {
2272b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            {0x0042, 0x0075, 0x0064, 0x0064, 0x0068, 0x0069, 0x0073, 0x0074, 0x0069, 0x0073, 0x0063, 0x0068, 0x0065, 0x0072, 0x0020, 0x004b, 0x0061, 0x006c, 0x0065, 0x006e, 0x0064, 0x0065, 0x0072, 0x0000},
2273b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
227454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius            {0x0054, 0x0065, 0x006c, 0x0065, 0x0066, 0x006f, 0x006e, 0x0062, 0x0075, 0x0063, 0x0068, 0x002d, 0x0053, 0x006f, 0x0072, 0x0074, 0x0069, 0x0065, 0x0072, 0x0075, 0x006e, 0x0067, 0x0000},
2275b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            {0x0044, 0x0065, 0x0075, 0x0074, 0x0073, 0x0063, 0x0068, 0x0065, 0x0020, 0x004d, 0x0061, 0x0072, 0x006b, 0x0000},
2276b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        };
2277b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
2278b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        UEnumeration* keywordEnum = uloc_openKeywords(localeID, &status);
2279b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
2280b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        for(keywordCount = 0; keywordCount < uenum_count(keywordEnum, &status) ; keywordCount++){
2281b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru              UChar *displayKeywordValue = NULL;
2282b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru              int32_t displayKeywordValueLen = 0;
2283b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru              if<