xref: /aosp_15_r20/external/icu/icu4c/source/test/cintltst/ulocbuildertst.c (revision 0e209d3975ff4a8c132096b14b0e9364a753506e)
1*0e209d39SAndroid Build Coastguard Worker // © 2023 and later: Unicode, Inc. and others.
2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html
3*0e209d39SAndroid Build Coastguard Worker 
4*0e209d39SAndroid Build Coastguard Worker #include "cintltst.h"
5*0e209d39SAndroid Build Coastguard Worker #include "cstring.h"
6*0e209d39SAndroid Build Coastguard Worker #include "unicode/uloc.h"
7*0e209d39SAndroid Build Coastguard Worker #include "unicode/ulocbuilder.h"
8*0e209d39SAndroid Build Coastguard Worker #include "unicode/ulocale.h"
9*0e209d39SAndroid Build Coastguard Worker 
10*0e209d39SAndroid Build Coastguard Worker #define WHERE __FILE__ ":" XLINE(__LINE__) " "
11*0e209d39SAndroid Build Coastguard Worker #define XLINE(s) LINE(s)
12*0e209d39SAndroid Build Coastguard Worker #define LINE(s) #s
13*0e209d39SAndroid Build Coastguard Worker 
14*0e209d39SAndroid Build Coastguard Worker #ifndef UPRV_LENGTHOF
15*0e209d39SAndroid Build Coastguard Worker #define UPRV_LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
16*0e209d39SAndroid Build Coastguard Worker #endif
17*0e209d39SAndroid Build Coastguard Worker void addLocaleBuilderTest(TestNode** root);
18*0e209d39SAndroid Build Coastguard Worker 
Verify(ULocaleBuilder * bld,const char * expected,const char * msg)19*0e209d39SAndroid Build Coastguard Worker static void Verify(ULocaleBuilder* bld, const char* expected, const char* msg) {
20*0e209d39SAndroid Build Coastguard Worker     UErrorCode status = U_ZERO_ERROR;
21*0e209d39SAndroid Build Coastguard Worker     UErrorCode copyStatus = U_ZERO_ERROR;
22*0e209d39SAndroid Build Coastguard Worker     UErrorCode errorStatus = U_ILLEGAL_ARGUMENT_ERROR;
23*0e209d39SAndroid Build Coastguard Worker     if (ulocbld_copyErrorTo(bld, &copyStatus)) {
24*0e209d39SAndroid Build Coastguard Worker         log_err(msg, u_errorName(copyStatus));
25*0e209d39SAndroid Build Coastguard Worker     }
26*0e209d39SAndroid Build Coastguard Worker     if (!ulocbld_copyErrorTo(bld, &errorStatus)) {
27*0e209d39SAndroid Build Coastguard Worker         log_err("Should always get the previous error and return false");
28*0e209d39SAndroid Build Coastguard Worker     }
29*0e209d39SAndroid Build Coastguard Worker     char tag[ULOC_FULLNAME_CAPACITY];
30*0e209d39SAndroid Build Coastguard Worker     ulocbld_buildLanguageTag(bld, tag, ULOC_FULLNAME_CAPACITY, &status);
31*0e209d39SAndroid Build Coastguard Worker 
32*0e209d39SAndroid Build Coastguard Worker     if (U_FAILURE(status)) {
33*0e209d39SAndroid Build Coastguard Worker         log_err(msg, u_errorName(status));
34*0e209d39SAndroid Build Coastguard Worker     }
35*0e209d39SAndroid Build Coastguard Worker     if (status != copyStatus) {
36*0e209d39SAndroid Build Coastguard Worker         log_err(msg, u_errorName(status));
37*0e209d39SAndroid Build Coastguard Worker     }
38*0e209d39SAndroid Build Coastguard Worker     if (strcmp(tag, expected) != 0) {
39*0e209d39SAndroid Build Coastguard Worker         log_err("should get \"%s\", but got \"%s\"\n", expected, tag);
40*0e209d39SAndroid Build Coastguard Worker     }
41*0e209d39SAndroid Build Coastguard Worker }
42*0e209d39SAndroid Build Coastguard Worker 
TestLocaleBuilder(void)43*0e209d39SAndroid Build Coastguard Worker static void TestLocaleBuilder(void) {
44*0e209d39SAndroid Build Coastguard Worker 
45*0e209d39SAndroid Build Coastguard Worker     // The following test data are copy from
46*0e209d39SAndroid Build Coastguard Worker     // icu4j/main/core/src/test/java/com/ibm/icu/dev/test/util/LocaleBuilderTest.java
47*0e209d39SAndroid Build Coastguard Worker     // "L": +1 = language
48*0e209d39SAndroid Build Coastguard Worker     // "S": +1 = script
49*0e209d39SAndroid Build Coastguard Worker     // "R": +1 = region
50*0e209d39SAndroid Build Coastguard Worker     // "V": +1 = variant
51*0e209d39SAndroid Build Coastguard Worker     // "K": +1 = Unicode locale key / +2 = Unicode locale type
52*0e209d39SAndroid Build Coastguard Worker     // "A": +1 = Unicode locale attribute
53*0e209d39SAndroid Build Coastguard Worker     // "E": +1 = extension letter / +2 = extension value
54*0e209d39SAndroid Build Coastguard Worker     // "P": +1 = private use
55*0e209d39SAndroid Build Coastguard Worker     // "U": +1 = ULocale
56*0e209d39SAndroid Build Coastguard Worker     // "B": +1 = BCP47 language tag
57*0e209d39SAndroid Build Coastguard Worker     // "C": Clear all
58*0e209d39SAndroid Build Coastguard Worker     // "N": Clear extensions
59*0e209d39SAndroid Build Coastguard Worker     // "D": +1 = Unicode locale attribute to be removed
60*0e209d39SAndroid Build Coastguard Worker     // "X": indicates an exception must be thrown
61*0e209d39SAndroid Build Coastguard Worker     // "T": +1 = expected language tag / +2 = expected locale string
62*0e209d39SAndroid Build Coastguard Worker     const char* TESTCASES[][14] = {
63*0e209d39SAndroid Build Coastguard Worker         {"L", "en", "R", "us", "T", "en-US", "en_US"},
64*0e209d39SAndroid Build Coastguard Worker         {"L", "en", "R", "CA", "L", NULL, "T", "und-CA", "_CA"},
65*0e209d39SAndroid Build Coastguard Worker         {"L", "en", "R", "CA", "L", "", "T", "und-CA", "_CA"},
66*0e209d39SAndroid Build Coastguard Worker         {"L", "en", "R", "FR", "L", "fr", "T", "fr-FR", "fr_FR"},
67*0e209d39SAndroid Build Coastguard Worker         {"L", "123", "X"},
68*0e209d39SAndroid Build Coastguard Worker         {"R", "us", "T", "und-US", "_US"},
69*0e209d39SAndroid Build Coastguard Worker         {"R", "usa", "X"},
70*0e209d39SAndroid Build Coastguard Worker         {"R", "123", "L", "it", "R", NULL, "T", "it", "it"},
71*0e209d39SAndroid Build Coastguard Worker         {"R", "123", "L", "it", "R", "", "T", "it", "it"},
72*0e209d39SAndroid Build Coastguard Worker         {"R", "123", "L", "en", "T", "en-123", "en_123"},
73*0e209d39SAndroid Build Coastguard Worker         {"S", "LATN", "L", "DE", "T", "de-Latn", "de_Latn"},
74*0e209d39SAndroid Build Coastguard Worker         {"L", "De", "S", "latn", "R", "de", "S", "", "T", "de-DE", "de_DE"},
75*0e209d39SAndroid Build Coastguard Worker         {"L", "De", "S", "Arab", "R", "de", "S", NULL, "T", "de-DE", "de_DE"},
76*0e209d39SAndroid Build Coastguard Worker         {"S", "latin", "X"},
77*0e209d39SAndroid Build Coastguard Worker         {"V", "1234", "L", "en", "T", "en-1234", "en__1234"},
78*0e209d39SAndroid Build Coastguard Worker         {"V", "1234", "L", "en", "V", "5678", "T", "en-5678", "en__5678"},
79*0e209d39SAndroid Build Coastguard Worker         {"V", "1234", "L", "en", "V", NULL, "T", "en", "en"},
80*0e209d39SAndroid Build Coastguard Worker         {"V", "1234", "L", "en", "V", "", "T", "en", "en"},
81*0e209d39SAndroid Build Coastguard Worker         {"V", "123", "X"},
82*0e209d39SAndroid Build Coastguard Worker         {"U", "en_US", "T", "en-US", "en_US"},
83*0e209d39SAndroid Build Coastguard Worker         {"U", "en_US_WIN", "X"},
84*0e209d39SAndroid Build Coastguard Worker         {"B", "fr-FR-1606nict-u-ca-gregory-x-test", "T",
85*0e209d39SAndroid Build Coastguard Worker           "fr-FR-1606nict-u-ca-gregory-x-test",
86*0e209d39SAndroid Build Coastguard Worker           "fr_FR_1606NICT@calendar=gregorian;x=test"},
87*0e209d39SAndroid Build Coastguard Worker         {"B", "ab-cde-fghij", "T", "cde-fghij", "cde__FGHIJ"},
88*0e209d39SAndroid Build Coastguard Worker         {"B", "und-CA", "T", "und-CA", "_CA"},
89*0e209d39SAndroid Build Coastguard Worker         // Blocked by ICU-20327
90*0e209d39SAndroid Build Coastguard Worker         // {"B", "en-US-x-test-lvariant-var", "T", "en-US-x-test-lvariant-var",
91*0e209d39SAndroid Build Coastguard Worker         // "en_US_VAR@x=test"},
92*0e209d39SAndroid Build Coastguard Worker         {"B", "en-US-VAR", "X"},
93*0e209d39SAndroid Build Coastguard Worker         {"U", "ja_JP@calendar=japanese;currency=JPY", "L", "ko", "T",
94*0e209d39SAndroid Build Coastguard Worker           "ko-JP-u-ca-japanese-cu-jpy", "ko_JP@calendar=japanese;currency=JPY"},
95*0e209d39SAndroid Build Coastguard Worker         {"U", "ja_JP@calendar=japanese;currency=JPY", "K", "ca", NULL, "T",
96*0e209d39SAndroid Build Coastguard Worker           "ja-JP-u-cu-jpy", "ja_JP@currency=JPY"},
97*0e209d39SAndroid Build Coastguard Worker         {"U", "ja_JP@calendar=japanese;currency=JPY", "E", "u",
98*0e209d39SAndroid Build Coastguard Worker           "attr1-ca-gregory", "T", "ja-JP-u-attr1-ca-gregory",
99*0e209d39SAndroid Build Coastguard Worker           "ja_JP@attribute=attr1;calendar=gregorian"},
100*0e209d39SAndroid Build Coastguard Worker         {"U", "en@colnumeric=yes", "K", "kn", "true", "T", "en-u-kn",
101*0e209d39SAndroid Build Coastguard Worker           "en@colnumeric=yes"},
102*0e209d39SAndroid Build Coastguard Worker         {"L", "th", "R", "th", "K", "nu", "thai", "T", "th-TH-u-nu-thai",
103*0e209d39SAndroid Build Coastguard Worker           "th_TH@numbers=thai"},
104*0e209d39SAndroid Build Coastguard Worker         {"U", "zh_Hans", "R", "sg", "K", "ca", "badcalendar", "X"},
105*0e209d39SAndroid Build Coastguard Worker         {"U", "zh_Hans", "R", "sg", "K", "cal", "gregory", "X"},
106*0e209d39SAndroid Build Coastguard Worker         {"E", "z", "ExtZ", "L", "en", "T", "en-z-extz", "en@z=extz"},
107*0e209d39SAndroid Build Coastguard Worker         {"E", "z", "ExtZ", "L", "en", "E", "z", "", "T", "en", "en"},
108*0e209d39SAndroid Build Coastguard Worker         {"E", "z", "ExtZ", "L", "en", "E", "z", NULL, "T", "en", "en"},
109*0e209d39SAndroid Build Coastguard Worker         {"E", "a", "x", "X"},
110*0e209d39SAndroid Build Coastguard Worker         {"E", "a", "abc_def", "T", "und-a-abc-def", "@a=abc-def"},
111*0e209d39SAndroid Build Coastguard Worker         // Design limitation - typeless u extension keyword 0a below is interpreted as a boolean value true/yes.
112*0e209d39SAndroid Build Coastguard Worker         // With the legacy keyword syntax, "yes" is used for such boolean value instead of "true".
113*0e209d39SAndroid Build Coastguard Worker         // However, once the legacy keyword is translated back to BCP 47 u extension, key "0a" is unknown,
114*0e209d39SAndroid Build Coastguard Worker         // so "yes" is preserved - not mapped to "true". We could change the code to automatically transform
115*0e209d39SAndroid Build Coastguard Worker         // key = alphanum alpha
116*0e209d39SAndroid Build Coastguard Worker         {"L", "en", "E", "u", "bbb-aaa-0a", "T", "en-u-aaa-bbb-0a",
117*0e209d39SAndroid Build Coastguard Worker          "en@0a=yes;attribute=aaa-bbb"},
118*0e209d39SAndroid Build Coastguard Worker         {"L", "fr", "R", "FR", "P", "Yoshito-ICU", "T", "fr-FR-x-yoshito-icu",
119*0e209d39SAndroid Build Coastguard Worker           "fr_FR@x=yoshito-icu"},
120*0e209d39SAndroid Build Coastguard Worker         {"L", "ja", "R", "jp", "K", "ca", "japanese", "T", "ja-JP-u-ca-japanese",
121*0e209d39SAndroid Build Coastguard Worker           "ja_JP@calendar=japanese"},
122*0e209d39SAndroid Build Coastguard Worker         {"K", "co", "PHONEBK", "K", "ca", "gregory", "L", "De", "T",
123*0e209d39SAndroid Build Coastguard Worker           "de-u-ca-gregory-co-phonebk", "de@calendar=gregorian;collation=phonebook"},
124*0e209d39SAndroid Build Coastguard Worker         {"E", "o", "OPQR", "E", "a", "aBcD", "T", "und-a-abcd-o-opqr", "@a=abcd;o=opqr"},
125*0e209d39SAndroid Build Coastguard Worker         {"E", "u", "nu-thai-ca-gregory", "L", "TH", "T", "th-u-ca-gregory-nu-thai",
126*0e209d39SAndroid Build Coastguard Worker           "th@calendar=gregorian;numbers=thai"},
127*0e209d39SAndroid Build Coastguard Worker         {"L", "en", "K", "tz", "usnyc", "R", "US", "T", "en-US-u-tz-usnyc",
128*0e209d39SAndroid Build Coastguard Worker           "en_US@timezone=America/New_York"},
129*0e209d39SAndroid Build Coastguard Worker         {"L", "de", "K", "co", "phonebk", "K", "ks", "level1", "K", "kk",
130*0e209d39SAndroid Build Coastguard Worker           "true", "T", "de-u-co-phonebk-kk-ks-level1",
131*0e209d39SAndroid Build Coastguard Worker           "de@collation=phonebook;colnormalization=yes;colstrength=primary"},
132*0e209d39SAndroid Build Coastguard Worker         {"L", "en", "R", "US", "K", "ca", "gregory", "T", "en-US-u-ca-gregory",
133*0e209d39SAndroid Build Coastguard Worker           "en_US@calendar=gregorian"},
134*0e209d39SAndroid Build Coastguard Worker         {"L", "en", "R", "US", "K", "cal", "gregory", "X"},
135*0e209d39SAndroid Build Coastguard Worker         {"L", "en", "R", "US", "K", "ca", "gregorian", "X"},
136*0e209d39SAndroid Build Coastguard Worker         {"L", "en", "R", "US", "K", "kn", "true", "T", "en-US-u-kn",
137*0e209d39SAndroid Build Coastguard Worker           "en_US@colnumeric=yes"},
138*0e209d39SAndroid Build Coastguard Worker         {"B", "de-DE-u-co-phonebk", "C", "L", "pt", "T", "pt", "pt"},
139*0e209d39SAndroid Build Coastguard Worker         {"B", "ja-jp-u-ca-japanese", "N", "T", "ja-JP", "ja_JP"},
140*0e209d39SAndroid Build Coastguard Worker         {"B", "es-u-def-abc-co-trad", "A", "hij", "D", "def", "T",
141*0e209d39SAndroid Build Coastguard Worker           "es-u-abc-hij-co-trad", "es@attribute=abc-hij;collation=traditional"},
142*0e209d39SAndroid Build Coastguard Worker         {"B", "es-u-def-abc-co-trad", "A", "hij", "D", "def", "D", "def", "T",
143*0e209d39SAndroid Build Coastguard Worker           "es-u-abc-hij-co-trad", "es@attribute=abc-hij;collation=traditional"},
144*0e209d39SAndroid Build Coastguard Worker         {"L", "en", "A", "aa", "X"},
145*0e209d39SAndroid Build Coastguard Worker         {"B", "fr-u-attr1-cu-eur", "D", "attribute1", "X"},
146*0e209d39SAndroid Build Coastguard Worker     };
147*0e209d39SAndroid Build Coastguard Worker     UErrorCode status = U_ZERO_ERROR;
148*0e209d39SAndroid Build Coastguard Worker     ULocaleBuilder* bld = ulocbld_open();
149*0e209d39SAndroid Build Coastguard Worker     char tag[ULOC_FULLNAME_CAPACITY];
150*0e209d39SAndroid Build Coastguard Worker     char locale[ULOC_FULLNAME_CAPACITY];
151*0e209d39SAndroid Build Coastguard Worker     for (int tidx = 0; tidx < UPRV_LENGTHOF(TESTCASES); tidx++) {
152*0e209d39SAndroid Build Coastguard Worker         char actions[1000];
153*0e209d39SAndroid Build Coastguard Worker         actions[0] = '\0';
154*0e209d39SAndroid Build Coastguard Worker         for (int p = 0; p < UPRV_LENGTHOF(TESTCASES[tidx]); p++) {
155*0e209d39SAndroid Build Coastguard Worker              if (TESTCASES[tidx][p] == NULL) {
156*0e209d39SAndroid Build Coastguard Worker                  strcpy(actions, " (nullptr)");
157*0e209d39SAndroid Build Coastguard Worker                  break;
158*0e209d39SAndroid Build Coastguard Worker              }
159*0e209d39SAndroid Build Coastguard Worker              if (p > 0) strcpy(actions, " ");
160*0e209d39SAndroid Build Coastguard Worker              strcpy(actions, TESTCASES[tidx][p]);
161*0e209d39SAndroid Build Coastguard Worker         }
162*0e209d39SAndroid Build Coastguard Worker         int i = 0;
163*0e209d39SAndroid Build Coastguard Worker         const char* method;
164*0e209d39SAndroid Build Coastguard Worker         status = U_ZERO_ERROR;
165*0e209d39SAndroid Build Coastguard Worker         ulocbld_clear(bld);
166*0e209d39SAndroid Build Coastguard Worker         while (true) {
167*0e209d39SAndroid Build Coastguard Worker             status = U_ZERO_ERROR;
168*0e209d39SAndroid Build Coastguard Worker             UErrorCode copyStatus = U_ZERO_ERROR;
169*0e209d39SAndroid Build Coastguard Worker             method = TESTCASES[tidx][i++];
170*0e209d39SAndroid Build Coastguard Worker             if (strcmp("L", method) == 0) {
171*0e209d39SAndroid Build Coastguard Worker                 ulocbld_setLanguage(bld, TESTCASES[tidx][i++], -1);
172*0e209d39SAndroid Build Coastguard Worker                 ulocbld_copyErrorTo(bld, &copyStatus);
173*0e209d39SAndroid Build Coastguard Worker                 ulocbld_buildLocaleID(bld, locale, ULOC_FULLNAME_CAPACITY, &status);
174*0e209d39SAndroid Build Coastguard Worker             } else if (strcmp("S", method) == 0) {
175*0e209d39SAndroid Build Coastguard Worker                 ulocbld_setScript(bld, TESTCASES[tidx][i++], -1);
176*0e209d39SAndroid Build Coastguard Worker                 ulocbld_copyErrorTo(bld, &copyStatus);
177*0e209d39SAndroid Build Coastguard Worker                 ulocbld_buildLocaleID(bld, locale, ULOC_FULLNAME_CAPACITY, &status);
178*0e209d39SAndroid Build Coastguard Worker             } else if (strcmp("R", method) == 0) {
179*0e209d39SAndroid Build Coastguard Worker                 ulocbld_setRegion(bld, TESTCASES[tidx][i++], -1);
180*0e209d39SAndroid Build Coastguard Worker                 ulocbld_copyErrorTo(bld, &copyStatus);
181*0e209d39SAndroid Build Coastguard Worker                 ulocbld_buildLocaleID(bld, locale, ULOC_FULLNAME_CAPACITY, &status);
182*0e209d39SAndroid Build Coastguard Worker             } else if (strcmp("V", method) == 0) {
183*0e209d39SAndroid Build Coastguard Worker                 ulocbld_setVariant(bld, TESTCASES[tidx][i++], -1);
184*0e209d39SAndroid Build Coastguard Worker                 ulocbld_copyErrorTo(bld, &copyStatus);
185*0e209d39SAndroid Build Coastguard Worker                 ulocbld_buildLocaleID(bld, locale, ULOC_FULLNAME_CAPACITY, &status);
186*0e209d39SAndroid Build Coastguard Worker             } else if (strcmp("K", method) == 0) {
187*0e209d39SAndroid Build Coastguard Worker                 const char* key = TESTCASES[tidx][i++];
188*0e209d39SAndroid Build Coastguard Worker                 const char* type = TESTCASES[tidx][i++];
189*0e209d39SAndroid Build Coastguard Worker                 ulocbld_setUnicodeLocaleKeyword(bld, key, -1, type, -1);
190*0e209d39SAndroid Build Coastguard Worker                 ulocbld_copyErrorTo(bld, &copyStatus);
191*0e209d39SAndroid Build Coastguard Worker                 ulocbld_buildLocaleID(bld, locale, ULOC_FULLNAME_CAPACITY, &status);
192*0e209d39SAndroid Build Coastguard Worker             } else if (strcmp("A", method) == 0) {
193*0e209d39SAndroid Build Coastguard Worker                 ulocbld_addUnicodeLocaleAttribute(bld, TESTCASES[tidx][i++], -1);
194*0e209d39SAndroid Build Coastguard Worker                 ulocbld_copyErrorTo(bld, &copyStatus);
195*0e209d39SAndroid Build Coastguard Worker                 ulocbld_buildLocaleID(bld, locale, ULOC_FULLNAME_CAPACITY, &status);
196*0e209d39SAndroid Build Coastguard Worker             } else if (strcmp("E", method) == 0) {
197*0e209d39SAndroid Build Coastguard Worker                 const char* key = TESTCASES[tidx][i++];
198*0e209d39SAndroid Build Coastguard Worker                 const char* value = TESTCASES[tidx][i++];
199*0e209d39SAndroid Build Coastguard Worker                 ulocbld_setExtension(bld, key[0], value, -1);
200*0e209d39SAndroid Build Coastguard Worker                 ulocbld_copyErrorTo(bld, &copyStatus);
201*0e209d39SAndroid Build Coastguard Worker                 ulocbld_buildLocaleID(bld, locale, ULOC_FULLNAME_CAPACITY, &status);
202*0e209d39SAndroid Build Coastguard Worker             } else if (strcmp("P", method) == 0) {
203*0e209d39SAndroid Build Coastguard Worker                 ulocbld_setExtension(bld, 'x', TESTCASES[tidx][i++], -1);
204*0e209d39SAndroid Build Coastguard Worker                 ulocbld_copyErrorTo(bld, &copyStatus);
205*0e209d39SAndroid Build Coastguard Worker                 ulocbld_buildLocaleID(bld, locale, ULOC_FULLNAME_CAPACITY, &status);
206*0e209d39SAndroid Build Coastguard Worker             } else if (strcmp("U", method) == 0) {
207*0e209d39SAndroid Build Coastguard Worker                 ulocbld_setLocale(bld, TESTCASES[tidx][i++], -1);
208*0e209d39SAndroid Build Coastguard Worker                 ulocbld_copyErrorTo(bld, &copyStatus);
209*0e209d39SAndroid Build Coastguard Worker                 ulocbld_buildLocaleID(bld, locale, ULOC_FULLNAME_CAPACITY, &status);
210*0e209d39SAndroid Build Coastguard Worker             } else if (strcmp("B", method) == 0) {
211*0e209d39SAndroid Build Coastguard Worker                 ulocbld_setLanguageTag(bld, TESTCASES[tidx][i++], -1);
212*0e209d39SAndroid Build Coastguard Worker                 ulocbld_copyErrorTo(bld, &copyStatus);
213*0e209d39SAndroid Build Coastguard Worker                 ulocbld_buildLocaleID(bld, locale, ULOC_FULLNAME_CAPACITY, &status);
214*0e209d39SAndroid Build Coastguard Worker             }
215*0e209d39SAndroid Build Coastguard Worker             // clear / remove
216*0e209d39SAndroid Build Coastguard Worker             else if (strcmp("C", method) == 0) {
217*0e209d39SAndroid Build Coastguard Worker                 ulocbld_clear(bld);
218*0e209d39SAndroid Build Coastguard Worker                 ulocbld_copyErrorTo(bld, &copyStatus);
219*0e209d39SAndroid Build Coastguard Worker                 ulocbld_buildLocaleID(bld, locale, ULOC_FULLNAME_CAPACITY, &status);
220*0e209d39SAndroid Build Coastguard Worker             } else if (strcmp("N", method) == 0) {
221*0e209d39SAndroid Build Coastguard Worker                 ulocbld_clearExtensions(bld);
222*0e209d39SAndroid Build Coastguard Worker                 ulocbld_copyErrorTo(bld, &copyStatus);
223*0e209d39SAndroid Build Coastguard Worker                 ulocbld_buildLocaleID(bld, locale, ULOC_FULLNAME_CAPACITY, &status);
224*0e209d39SAndroid Build Coastguard Worker             } else if (strcmp("D", method) == 0) {
225*0e209d39SAndroid Build Coastguard Worker                 ulocbld_removeUnicodeLocaleAttribute(bld, TESTCASES[tidx][i++], -1);
226*0e209d39SAndroid Build Coastguard Worker                 ulocbld_copyErrorTo(bld, &copyStatus);
227*0e209d39SAndroid Build Coastguard Worker                 ulocbld_buildLocaleID(bld, locale, ULOC_FULLNAME_CAPACITY, &status);
228*0e209d39SAndroid Build Coastguard Worker             }
229*0e209d39SAndroid Build Coastguard Worker             // result
230*0e209d39SAndroid Build Coastguard Worker             else if (strcmp("X", method) == 0) {
231*0e209d39SAndroid Build Coastguard Worker                 if (U_SUCCESS(status)) {
232*0e209d39SAndroid Build Coastguard Worker                     log_err("FAIL: No error return - test case: %s", actions);
233*0e209d39SAndroid Build Coastguard Worker                 }
234*0e209d39SAndroid Build Coastguard Worker             } else if (strcmp("T", method) == 0) {
235*0e209d39SAndroid Build Coastguard Worker                 status = U_ZERO_ERROR;
236*0e209d39SAndroid Build Coastguard Worker                 ulocbld_buildLocaleID(bld, locale, ULOC_FULLNAME_CAPACITY, &status);
237*0e209d39SAndroid Build Coastguard Worker                 if (status != copyStatus) {
238*0e209d39SAndroid Build Coastguard Worker                     log_err("copyErrorTo not matching");
239*0e209d39SAndroid Build Coastguard Worker                 }
240*0e209d39SAndroid Build Coastguard Worker                 if (U_FAILURE(status) ||
241*0e209d39SAndroid Build Coastguard Worker                     strcmp(locale, TESTCASES[tidx][i + 1]) != 0) {
242*0e209d39SAndroid Build Coastguard Worker                     log_err("FAIL: Wrong locale ID - %s %s %s", locale,
243*0e209d39SAndroid Build Coastguard Worker                             " for test case: ", actions);
244*0e209d39SAndroid Build Coastguard Worker                 }
245*0e209d39SAndroid Build Coastguard Worker                 ulocbld_buildLanguageTag(bld, tag, ULOC_FULLNAME_CAPACITY, &status);
246*0e209d39SAndroid Build Coastguard Worker                 if (U_FAILURE(status) || strcmp(tag, TESTCASES[tidx][i]) != 0) {
247*0e209d39SAndroid Build Coastguard Worker                     log_err("FAIL: Wrong language tag - %s %s %s", tag,
248*0e209d39SAndroid Build Coastguard Worker                             " for test case: ", actions);
249*0e209d39SAndroid Build Coastguard Worker                 }
250*0e209d39SAndroid Build Coastguard Worker                 break;
251*0e209d39SAndroid Build Coastguard Worker             } else {
252*0e209d39SAndroid Build Coastguard Worker                 // Unknown test method
253*0e209d39SAndroid Build Coastguard Worker                 log_err("Unknown test case method: There is an error in the test case data.");
254*0e209d39SAndroid Build Coastguard Worker                 break;
255*0e209d39SAndroid Build Coastguard Worker             }
256*0e209d39SAndroid Build Coastguard Worker             if (status != copyStatus) {
257*0e209d39SAndroid Build Coastguard Worker                 log_err("copyErrorTo not matching");
258*0e209d39SAndroid Build Coastguard Worker             }
259*0e209d39SAndroid Build Coastguard Worker             if (U_FAILURE(status)) {
260*0e209d39SAndroid Build Coastguard Worker                 if (strcmp("X", TESTCASES[tidx][i]) == 0) {
261*0e209d39SAndroid Build Coastguard Worker                     // This failure is expected
262*0e209d39SAndroid Build Coastguard Worker                     break;
263*0e209d39SAndroid Build Coastguard Worker                 } else {
264*0e209d39SAndroid Build Coastguard Worker                     log_err("FAIL: U_ILLEGAL_ARGUMENT_ERROR at offset %d %s %s", i,
265*0e209d39SAndroid Build Coastguard Worker                           " in test case: ", actions);
266*0e209d39SAndroid Build Coastguard Worker                     break;
267*0e209d39SAndroid Build Coastguard Worker                 }
268*0e209d39SAndroid Build Coastguard Worker             }
269*0e209d39SAndroid Build Coastguard Worker             if (strcmp("T", method) == 0) {
270*0e209d39SAndroid Build Coastguard Worker                 break;
271*0e209d39SAndroid Build Coastguard Worker             }
272*0e209d39SAndroid Build Coastguard Worker         }  // while(true)
273*0e209d39SAndroid Build Coastguard Worker     }  // for TESTCASES
274*0e209d39SAndroid Build Coastguard Worker     ulocbld_close(bld);
275*0e209d39SAndroid Build Coastguard Worker }
276*0e209d39SAndroid Build Coastguard Worker 
TestLocaleBuilderBasic(void)277*0e209d39SAndroid Build Coastguard Worker static void TestLocaleBuilderBasic(void) {
278*0e209d39SAndroid Build Coastguard Worker     ULocaleBuilder* bld = ulocbld_open();
279*0e209d39SAndroid Build Coastguard Worker     ulocbld_setLanguage(bld, "zh", -1);
280*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "zh", "ulocbld_setLanguage('zh') got Error: %s\n");
281*0e209d39SAndroid Build Coastguard Worker     ulocbld_setScript(bld, "Hant", -1);
282*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "zh-Hant", "ulocbld_setScript('Hant') got Error: %s\n");
283*0e209d39SAndroid Build Coastguard Worker 
284*0e209d39SAndroid Build Coastguard Worker     ulocbld_setRegion(bld, "SG", -1);
285*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "zh-Hant-SG", "ulocbld_setRegion('SG') got Error: %s\n");
286*0e209d39SAndroid Build Coastguard Worker 
287*0e209d39SAndroid Build Coastguard Worker     ulocbld_setRegion(bld, "HK", -1);
288*0e209d39SAndroid Build Coastguard Worker     ulocbld_setScript(bld, "Hans", -1);
289*0e209d39SAndroid Build Coastguard Worker 
290*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "zh-Hans-HK",
291*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setRegion('HK') and ulocbld_setScript('Hans') got Error: %s\n");
292*0e209d39SAndroid Build Coastguard Worker 
293*0e209d39SAndroid Build Coastguard Worker     ulocbld_setVariant(bld, "revised###", 7);
294*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "zh-Hans-HK-revised",
295*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setVariant('revised') got Error: %s\n");
296*0e209d39SAndroid Build Coastguard Worker 
297*0e209d39SAndroid Build Coastguard Worker     ulocbld_setUnicodeLocaleKeyword(bld, "nu", -1, "thai###", 4);
298*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "zh-Hans-HK-revised-u-nu-thai",
299*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setUnicodeLocaleKeyword('nu', 'thai'') got Error: %s\n");
300*0e209d39SAndroid Build Coastguard Worker 
301*0e209d39SAndroid Build Coastguard Worker     ulocbld_setUnicodeLocaleKeyword(bld, "co###", 2, "pinyin", -1);
302*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "zh-Hans-HK-revised-u-co-pinyin-nu-thai",
303*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setUnicodeLocaleKeyword('co', 'pinyin'') got Error: %s\n");
304*0e209d39SAndroid Build Coastguard Worker 
305*0e209d39SAndroid Build Coastguard Worker     ulocbld_setUnicodeLocaleKeyword(bld, "nu", -1, "latn###", 4);
306*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "zh-Hans-HK-revised-u-co-pinyin-nu-latn",
307*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setUnicodeLocaleKeyword('nu', 'latn'') got Error: %s\n");
308*0e209d39SAndroid Build Coastguard Worker 
309*0e209d39SAndroid Build Coastguard Worker     ulocbld_setUnicodeLocaleKeyword(bld, "nu", -1, "latn", -1);
310*0e209d39SAndroid Build Coastguard Worker     ulocbld_setUnicodeLocaleKeyword(bld, "nu", -1, NULL, 0);
311*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "zh-Hans-HK-revised-u-co-pinyin",
312*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setUnicodeLocaleKeyword('nu', ''') got Error: %s\n");
313*0e209d39SAndroid Build Coastguard Worker 
314*0e209d39SAndroid Build Coastguard Worker 
315*0e209d39SAndroid Build Coastguard Worker     ulocbld_setUnicodeLocaleKeyword(bld, "co", -1, NULL, 0);
316*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "zh-Hans-HK-revised",
317*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setUnicodeLocaleKeyword('nu', NULL) got Error: %s\n");
318*0e209d39SAndroid Build Coastguard Worker 
319*0e209d39SAndroid Build Coastguard Worker     ulocbld_setScript(bld, "", -1);
320*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "zh-HK-revised",
321*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setScript('') got Error: %s\n");
322*0e209d39SAndroid Build Coastguard Worker 
323*0e209d39SAndroid Build Coastguard Worker     ulocbld_setVariant(bld, "", -1);
324*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "zh-HK",
325*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setVariant('') got Error: %s\n");
326*0e209d39SAndroid Build Coastguard Worker 
327*0e209d39SAndroid Build Coastguard Worker     ulocbld_setRegion(bld, "", -1);
328*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "zh",
329*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setRegion('') got Error: %s\n");
330*0e209d39SAndroid Build Coastguard Worker 
331*0e209d39SAndroid Build Coastguard Worker     ulocbld_close(bld);
332*0e209d39SAndroid Build Coastguard Worker }
333*0e209d39SAndroid Build Coastguard Worker 
TestLocaleBuilderBasicWithExtensionsOnDefaultLocale(void)334*0e209d39SAndroid Build Coastguard Worker static void TestLocaleBuilderBasicWithExtensionsOnDefaultLocale(void) {
335*0e209d39SAndroid Build Coastguard Worker     // Change the default locale to one with extension tags.
336*0e209d39SAndroid Build Coastguard Worker     UErrorCode status = U_ZERO_ERROR;
337*0e209d39SAndroid Build Coastguard Worker     char originalDefault[ULOC_FULLNAME_CAPACITY];
338*0e209d39SAndroid Build Coastguard Worker     strcpy(originalDefault, uloc_getDefault());
339*0e209d39SAndroid Build Coastguard Worker     uloc_setDefault("en-US-u-hc-h12", &status);
340*0e209d39SAndroid Build Coastguard Worker     if (U_FAILURE(status)) {
341*0e209d39SAndroid Build Coastguard Worker         log_err("ERROR: Could not change the default locale");
342*0e209d39SAndroid Build Coastguard Worker         return;
343*0e209d39SAndroid Build Coastguard Worker     }
344*0e209d39SAndroid Build Coastguard Worker 
345*0e209d39SAndroid Build Coastguard Worker     // Invoke the basic test now that the default locale has been changed.
346*0e209d39SAndroid Build Coastguard Worker     TestLocaleBuilderBasic();
347*0e209d39SAndroid Build Coastguard Worker 
348*0e209d39SAndroid Build Coastguard Worker     uloc_setDefault(originalDefault, &status);
349*0e209d39SAndroid Build Coastguard Worker     if (U_FAILURE(status)) {
350*0e209d39SAndroid Build Coastguard Worker         log_err("ERROR: Could not restore the default locale");
351*0e209d39SAndroid Build Coastguard Worker     }
352*0e209d39SAndroid Build Coastguard Worker }
353*0e209d39SAndroid Build Coastguard Worker 
TestSetLanguageWellFormed(void)354*0e209d39SAndroid Build Coastguard Worker static void TestSetLanguageWellFormed(void) {
355*0e209d39SAndroid Build Coastguard Worker     // http://www.unicode.org/reports/tr35/tr35.html#unicode_language_subtag
356*0e209d39SAndroid Build Coastguard Worker     // unicode_language_subtag = alpha{2,3} | alpha{5,8};
357*0e209d39SAndroid Build Coastguard Worker     // ICUTC decided also support alpha{4}
358*0e209d39SAndroid Build Coastguard Worker     static const char* wellFormedLanguages[] = {
359*0e209d39SAndroid Build Coastguard Worker         "",
360*0e209d39SAndroid Build Coastguard Worker 
361*0e209d39SAndroid Build Coastguard Worker         // alpha{2}
362*0e209d39SAndroid Build Coastguard Worker         "en",
363*0e209d39SAndroid Build Coastguard Worker         "NE",
364*0e209d39SAndroid Build Coastguard Worker         "eN",
365*0e209d39SAndroid Build Coastguard Worker         "Ne",
366*0e209d39SAndroid Build Coastguard Worker 
367*0e209d39SAndroid Build Coastguard Worker         // alpha{3}
368*0e209d39SAndroid Build Coastguard Worker         "aNe",
369*0e209d39SAndroid Build Coastguard Worker         "zzz",
370*0e209d39SAndroid Build Coastguard Worker         "AAA",
371*0e209d39SAndroid Build Coastguard Worker 
372*0e209d39SAndroid Build Coastguard Worker         // alpha{4}
373*0e209d39SAndroid Build Coastguard Worker         "ABCD",
374*0e209d39SAndroid Build Coastguard Worker         "abcd",
375*0e209d39SAndroid Build Coastguard Worker 
376*0e209d39SAndroid Build Coastguard Worker         // alpha{5}
377*0e209d39SAndroid Build Coastguard Worker         "efgij",
378*0e209d39SAndroid Build Coastguard Worker         "AbCAD",
379*0e209d39SAndroid Build Coastguard Worker         "ZAASD",
380*0e209d39SAndroid Build Coastguard Worker 
381*0e209d39SAndroid Build Coastguard Worker         // alpha{6}
382*0e209d39SAndroid Build Coastguard Worker         "efgijk",
383*0e209d39SAndroid Build Coastguard Worker         "AADGFE",
384*0e209d39SAndroid Build Coastguard Worker         "AkDfFz",
385*0e209d39SAndroid Build Coastguard Worker 
386*0e209d39SAndroid Build Coastguard Worker         // alpha{7}
387*0e209d39SAndroid Build Coastguard Worker         "asdfads",
388*0e209d39SAndroid Build Coastguard Worker         "ADSFADF",
389*0e209d39SAndroid Build Coastguard Worker         "piSFkDk",
390*0e209d39SAndroid Build Coastguard Worker 
391*0e209d39SAndroid Build Coastguard Worker         // alpha{8}
392*0e209d39SAndroid Build Coastguard Worker         "oieradfz",
393*0e209d39SAndroid Build Coastguard Worker         "IADSFJKR",
394*0e209d39SAndroid Build Coastguard Worker         "kkDSFJkR",
395*0e209d39SAndroid Build Coastguard Worker     };
396*0e209d39SAndroid Build Coastguard Worker     for(int32_t i=0;i<UPRV_LENGTHOF(wellFormedLanguages);i++) {
397*0e209d39SAndroid Build Coastguard Worker         const char* lang = wellFormedLanguages[i];
398*0e209d39SAndroid Build Coastguard Worker         UErrorCode status = U_ZERO_ERROR;
399*0e209d39SAndroid Build Coastguard Worker         ULocaleBuilder* bld = ulocbld_open();
400*0e209d39SAndroid Build Coastguard Worker         ulocbld_setLanguage(bld, lang, -1);
401*0e209d39SAndroid Build Coastguard Worker         char buffer[ULOC_FULLNAME_CAPACITY];
402*0e209d39SAndroid Build Coastguard Worker         ulocbld_buildLocaleID(bld, buffer, ULOC_FULLNAME_CAPACITY, &status);
403*0e209d39SAndroid Build Coastguard Worker         if (U_FAILURE(status)) {
404*0e209d39SAndroid Build Coastguard Worker             log_err("setLanguage(\"%s\") got Error: %s\n",
405*0e209d39SAndroid Build Coastguard Worker                   lang, u_errorName(status));
406*0e209d39SAndroid Build Coastguard Worker         }
407*0e209d39SAndroid Build Coastguard Worker         ulocbld_close(bld);
408*0e209d39SAndroid Build Coastguard Worker     }
409*0e209d39SAndroid Build Coastguard Worker }
410*0e209d39SAndroid Build Coastguard Worker 
TestSetLanguageIllFormed(void)411*0e209d39SAndroid Build Coastguard Worker static void TestSetLanguageIllFormed(void) {
412*0e209d39SAndroid Build Coastguard Worker     static const char* illFormed[] = {
413*0e209d39SAndroid Build Coastguard Worker         "a",
414*0e209d39SAndroid Build Coastguard Worker         "z",
415*0e209d39SAndroid Build Coastguard Worker         "A",
416*0e209d39SAndroid Build Coastguard Worker         "F",
417*0e209d39SAndroid Build Coastguard Worker         "2",
418*0e209d39SAndroid Build Coastguard Worker         "0",
419*0e209d39SAndroid Build Coastguard Worker         "9",
420*0e209d39SAndroid Build Coastguard Worker         "{",
421*0e209d39SAndroid Build Coastguard Worker         ".",
422*0e209d39SAndroid Build Coastguard Worker         "[",
423*0e209d39SAndroid Build Coastguard Worker         "]",
424*0e209d39SAndroid Build Coastguard Worker         "\\",
425*0e209d39SAndroid Build Coastguard Worker 
426*0e209d39SAndroid Build Coastguard Worker         "e1",
427*0e209d39SAndroid Build Coastguard Worker         "N2",
428*0e209d39SAndroid Build Coastguard Worker         "3N",
429*0e209d39SAndroid Build Coastguard Worker         "4e",
430*0e209d39SAndroid Build Coastguard Worker         "e:",
431*0e209d39SAndroid Build Coastguard Worker         "43",
432*0e209d39SAndroid Build Coastguard Worker         "a9",
433*0e209d39SAndroid Build Coastguard Worker 
434*0e209d39SAndroid Build Coastguard Worker         "aN0",
435*0e209d39SAndroid Build Coastguard Worker         "z1z",
436*0e209d39SAndroid Build Coastguard Worker         "2zz",
437*0e209d39SAndroid Build Coastguard Worker         "3A3",
438*0e209d39SAndroid Build Coastguard Worker         "456",
439*0e209d39SAndroid Build Coastguard Worker         "af)",
440*0e209d39SAndroid Build Coastguard Worker 
441*0e209d39SAndroid Build Coastguard Worker         // Per 2019-01-23 ICUTC, we still accept 4alpha as tlang. see ICU-20321.
442*0e209d39SAndroid Build Coastguard Worker         // "latn",
443*0e209d39SAndroid Build Coastguard Worker         // "Arab",
444*0e209d39SAndroid Build Coastguard Worker         // "LATN",
445*0e209d39SAndroid Build Coastguard Worker 
446*0e209d39SAndroid Build Coastguard Worker         "e)gij",
447*0e209d39SAndroid Build Coastguard Worker         "Ab3AD",
448*0e209d39SAndroid Build Coastguard Worker         "ZAAS8",
449*0e209d39SAndroid Build Coastguard Worker 
450*0e209d39SAndroid Build Coastguard Worker         "efgi[]",
451*0e209d39SAndroid Build Coastguard Worker         "AA9GFE",
452*0e209d39SAndroid Build Coastguard Worker         "7kD3Fz",
453*0e209d39SAndroid Build Coastguard Worker         "as8fads",
454*0e209d39SAndroid Build Coastguard Worker         "0DSFADF",
455*0e209d39SAndroid Build Coastguard Worker         "'iSFkDk",
456*0e209d39SAndroid Build Coastguard Worker 
457*0e209d39SAndroid Build Coastguard Worker         "oieradf+",
458*0e209d39SAndroid Build Coastguard Worker         "IADSFJK-",
459*0e209d39SAndroid Build Coastguard Worker         "kkDSFJk0",
460*0e209d39SAndroid Build Coastguard Worker 
461*0e209d39SAndroid Build Coastguard Worker         // alpha{9}
462*0e209d39SAndroid Build Coastguard Worker         "oieradfab",
463*0e209d39SAndroid Build Coastguard Worker         "IADSFJKDE",
464*0e209d39SAndroid Build Coastguard Worker         "kkDSFJkzf",
465*0e209d39SAndroid Build Coastguard Worker     };
466*0e209d39SAndroid Build Coastguard Worker     for(int32_t i=0;i<UPRV_LENGTHOF(illFormed);i++) {
467*0e209d39SAndroid Build Coastguard Worker         const char* ill = illFormed[i];
468*0e209d39SAndroid Build Coastguard Worker         UErrorCode status = U_ZERO_ERROR;
469*0e209d39SAndroid Build Coastguard Worker         ULocaleBuilder* bld = ulocbld_open();
470*0e209d39SAndroid Build Coastguard Worker         ulocbld_setLanguage(bld, ill, -1);
471*0e209d39SAndroid Build Coastguard Worker         char buffer[ULOC_FULLNAME_CAPACITY];
472*0e209d39SAndroid Build Coastguard Worker         ulocbld_buildLocaleID(bld, buffer, ULOC_FULLNAME_CAPACITY, &status);
473*0e209d39SAndroid Build Coastguard Worker         if (status != U_ILLEGAL_ARGUMENT_ERROR) {
474*0e209d39SAndroid Build Coastguard Worker             log_err("setLanguage(\"%s\") should fail but has no Error\n", ill);
475*0e209d39SAndroid Build Coastguard Worker         }
476*0e209d39SAndroid Build Coastguard Worker         ulocbld_close(bld);
477*0e209d39SAndroid Build Coastguard Worker     }
478*0e209d39SAndroid Build Coastguard Worker }
479*0e209d39SAndroid Build Coastguard Worker 
TestSetScriptWellFormed(void)480*0e209d39SAndroid Build Coastguard Worker static void TestSetScriptWellFormed(void) {
481*0e209d39SAndroid Build Coastguard Worker     // http://www.unicode.org/reports/tr35/tr35.html#unicode_script_subtag
482*0e209d39SAndroid Build Coastguard Worker     // unicode_script_subtag = alpha{4} ;
483*0e209d39SAndroid Build Coastguard Worker     static const char* wellFormedScripts[] = {
484*0e209d39SAndroid Build Coastguard Worker         "",
485*0e209d39SAndroid Build Coastguard Worker 
486*0e209d39SAndroid Build Coastguard Worker         "Latn",
487*0e209d39SAndroid Build Coastguard Worker         "latn",
488*0e209d39SAndroid Build Coastguard Worker         "lATN",
489*0e209d39SAndroid Build Coastguard Worker         "laTN",
490*0e209d39SAndroid Build Coastguard Worker         "arBN",
491*0e209d39SAndroid Build Coastguard Worker         "ARbn",
492*0e209d39SAndroid Build Coastguard Worker         "adsf",
493*0e209d39SAndroid Build Coastguard Worker         "aADF",
494*0e209d39SAndroid Build Coastguard Worker         "BSVS",
495*0e209d39SAndroid Build Coastguard Worker         "LATn",
496*0e209d39SAndroid Build Coastguard Worker     };
497*0e209d39SAndroid Build Coastguard Worker     for(int32_t i=0;i<UPRV_LENGTHOF(wellFormedScripts);i++) {
498*0e209d39SAndroid Build Coastguard Worker         const char* script = wellFormedScripts[i];
499*0e209d39SAndroid Build Coastguard Worker         UErrorCode status = U_ZERO_ERROR;
500*0e209d39SAndroid Build Coastguard Worker         ULocaleBuilder* bld = ulocbld_open();
501*0e209d39SAndroid Build Coastguard Worker         ulocbld_setScript(bld, script, -1);
502*0e209d39SAndroid Build Coastguard Worker         char buffer[ULOC_FULLNAME_CAPACITY];
503*0e209d39SAndroid Build Coastguard Worker         ulocbld_buildLocaleID(bld, buffer, ULOC_FULLNAME_CAPACITY, &status);
504*0e209d39SAndroid Build Coastguard Worker         if (U_FAILURE(status)) {
505*0e209d39SAndroid Build Coastguard Worker             log_err("setScript(\"%s\") got Error: %s\n",
506*0e209d39SAndroid Build Coastguard Worker                   script, u_errorName(status));
507*0e209d39SAndroid Build Coastguard Worker         }
508*0e209d39SAndroid Build Coastguard Worker         ulocbld_close(bld);
509*0e209d39SAndroid Build Coastguard Worker     }
510*0e209d39SAndroid Build Coastguard Worker }
TestSetScriptIllFormed(void)511*0e209d39SAndroid Build Coastguard Worker static void TestSetScriptIllFormed(void) {
512*0e209d39SAndroid Build Coastguard Worker     static const char* illFormed[] = {
513*0e209d39SAndroid Build Coastguard Worker         "a",
514*0e209d39SAndroid Build Coastguard Worker         "z",
515*0e209d39SAndroid Build Coastguard Worker         "A",
516*0e209d39SAndroid Build Coastguard Worker         "F",
517*0e209d39SAndroid Build Coastguard Worker         "2",
518*0e209d39SAndroid Build Coastguard Worker         "0",
519*0e209d39SAndroid Build Coastguard Worker         "9",
520*0e209d39SAndroid Build Coastguard Worker         "{",
521*0e209d39SAndroid Build Coastguard Worker         ".",
522*0e209d39SAndroid Build Coastguard Worker         "[",
523*0e209d39SAndroid Build Coastguard Worker         "]",
524*0e209d39SAndroid Build Coastguard Worker         "\\",
525*0e209d39SAndroid Build Coastguard Worker 
526*0e209d39SAndroid Build Coastguard Worker         "e1",
527*0e209d39SAndroid Build Coastguard Worker         "N2",
528*0e209d39SAndroid Build Coastguard Worker         "3N",
529*0e209d39SAndroid Build Coastguard Worker         "4e",
530*0e209d39SAndroid Build Coastguard Worker         "e:",
531*0e209d39SAndroid Build Coastguard Worker         "43",
532*0e209d39SAndroid Build Coastguard Worker         "a9",
533*0e209d39SAndroid Build Coastguard Worker 
534*0e209d39SAndroid Build Coastguard Worker         "aN0",
535*0e209d39SAndroid Build Coastguard Worker         "z1z",
536*0e209d39SAndroid Build Coastguard Worker         "2zz",
537*0e209d39SAndroid Build Coastguard Worker         "3A3",
538*0e209d39SAndroid Build Coastguard Worker         "456",
539*0e209d39SAndroid Build Coastguard Worker         "af)",
540*0e209d39SAndroid Build Coastguard Worker 
541*0e209d39SAndroid Build Coastguard Worker         "0atn",
542*0e209d39SAndroid Build Coastguard Worker         "l1tn",
543*0e209d39SAndroid Build Coastguard Worker         "lA2N",
544*0e209d39SAndroid Build Coastguard Worker         "la4N",
545*0e209d39SAndroid Build Coastguard Worker         "arB5",
546*0e209d39SAndroid Build Coastguard Worker         "1234",
547*0e209d39SAndroid Build Coastguard Worker 
548*0e209d39SAndroid Build Coastguard Worker         "e)gij",
549*0e209d39SAndroid Build Coastguard Worker         "Ab3AD",
550*0e209d39SAndroid Build Coastguard Worker         "ZAAS8",
551*0e209d39SAndroid Build Coastguard Worker 
552*0e209d39SAndroid Build Coastguard Worker         "efgi[]",
553*0e209d39SAndroid Build Coastguard Worker         "AA9GFE",
554*0e209d39SAndroid Build Coastguard Worker         "7kD3Fz",
555*0e209d39SAndroid Build Coastguard Worker 
556*0e209d39SAndroid Build Coastguard Worker         "as8fads",
557*0e209d39SAndroid Build Coastguard Worker         "0DSFADF",
558*0e209d39SAndroid Build Coastguard Worker         "'iSFkDk",
559*0e209d39SAndroid Build Coastguard Worker 
560*0e209d39SAndroid Build Coastguard Worker         "oieradf+",
561*0e209d39SAndroid Build Coastguard Worker         "IADSFJK-",
562*0e209d39SAndroid Build Coastguard Worker         "kkDSFJk0",
563*0e209d39SAndroid Build Coastguard Worker 
564*0e209d39SAndroid Build Coastguard Worker         // alpha{9}
565*0e209d39SAndroid Build Coastguard Worker         "oieradfab",
566*0e209d39SAndroid Build Coastguard Worker         "IADSFJKDE",
567*0e209d39SAndroid Build Coastguard Worker         "kkDSFJkzf",
568*0e209d39SAndroid Build Coastguard Worker     };
569*0e209d39SAndroid Build Coastguard Worker     for(int32_t i=0;i<UPRV_LENGTHOF(illFormed);i++) {
570*0e209d39SAndroid Build Coastguard Worker         const char* ill = illFormed[i];
571*0e209d39SAndroid Build Coastguard Worker         UErrorCode status = U_ZERO_ERROR;
572*0e209d39SAndroid Build Coastguard Worker         ULocaleBuilder* bld = ulocbld_open();
573*0e209d39SAndroid Build Coastguard Worker         ulocbld_setScript(bld, ill, -1);
574*0e209d39SAndroid Build Coastguard Worker         char buffer[ULOC_FULLNAME_CAPACITY];
575*0e209d39SAndroid Build Coastguard Worker         ulocbld_buildLocaleID(bld, buffer, ULOC_FULLNAME_CAPACITY, &status);
576*0e209d39SAndroid Build Coastguard Worker         if (status != U_ILLEGAL_ARGUMENT_ERROR) {
577*0e209d39SAndroid Build Coastguard Worker             log_err("setScript(\"%s\") should fail but has no Error\n", ill);
578*0e209d39SAndroid Build Coastguard Worker         }
579*0e209d39SAndroid Build Coastguard Worker         ulocbld_close(bld);
580*0e209d39SAndroid Build Coastguard Worker     }
581*0e209d39SAndroid Build Coastguard Worker }
582*0e209d39SAndroid Build Coastguard Worker 
TestSetRegionWellFormed(void)583*0e209d39SAndroid Build Coastguard Worker static void TestSetRegionWellFormed(void) {
584*0e209d39SAndroid Build Coastguard Worker     // http://www.unicode.org/reports/tr35/tr35.html#unicode_region_subtag
585*0e209d39SAndroid Build Coastguard Worker     // unicode_region_subtag = (alpha{2} | digit{3})
586*0e209d39SAndroid Build Coastguard Worker     static const char* wellFormedRegions[] = {
587*0e209d39SAndroid Build Coastguard Worker         "",
588*0e209d39SAndroid Build Coastguard Worker 
589*0e209d39SAndroid Build Coastguard Worker         // alpha{2}
590*0e209d39SAndroid Build Coastguard Worker         "en",
591*0e209d39SAndroid Build Coastguard Worker         "NE",
592*0e209d39SAndroid Build Coastguard Worker         "eN",
593*0e209d39SAndroid Build Coastguard Worker         "Ne",
594*0e209d39SAndroid Build Coastguard Worker 
595*0e209d39SAndroid Build Coastguard Worker         // digit{3}
596*0e209d39SAndroid Build Coastguard Worker         "000",
597*0e209d39SAndroid Build Coastguard Worker         "999",
598*0e209d39SAndroid Build Coastguard Worker         "123",
599*0e209d39SAndroid Build Coastguard Worker         "987"
600*0e209d39SAndroid Build Coastguard Worker     };
601*0e209d39SAndroid Build Coastguard Worker     for(int32_t i=0;i<UPRV_LENGTHOF(wellFormedRegions);i++) {
602*0e209d39SAndroid Build Coastguard Worker         const char* region = wellFormedRegions[i];
603*0e209d39SAndroid Build Coastguard Worker         UErrorCode status = U_ZERO_ERROR;
604*0e209d39SAndroid Build Coastguard Worker         ULocaleBuilder* bld = ulocbld_open();
605*0e209d39SAndroid Build Coastguard Worker         ulocbld_setRegion(bld, region, -1);
606*0e209d39SAndroid Build Coastguard Worker         char buffer[ULOC_FULLNAME_CAPACITY];
607*0e209d39SAndroid Build Coastguard Worker         ulocbld_buildLocaleID(bld, buffer, ULOC_FULLNAME_CAPACITY, &status);
608*0e209d39SAndroid Build Coastguard Worker         if (U_FAILURE(status)) {
609*0e209d39SAndroid Build Coastguard Worker             log_err("setRegion(\"%s\") got Error: %s\n",
610*0e209d39SAndroid Build Coastguard Worker                   region, u_errorName(status));
611*0e209d39SAndroid Build Coastguard Worker         }
612*0e209d39SAndroid Build Coastguard Worker         ulocbld_close(bld);
613*0e209d39SAndroid Build Coastguard Worker     }
614*0e209d39SAndroid Build Coastguard Worker }
615*0e209d39SAndroid Build Coastguard Worker 
TestSetRegionIllFormed(void)616*0e209d39SAndroid Build Coastguard Worker static void TestSetRegionIllFormed(void) {
617*0e209d39SAndroid Build Coastguard Worker     static const char* illFormed[] = {
618*0e209d39SAndroid Build Coastguard Worker         "a",
619*0e209d39SAndroid Build Coastguard Worker         "z",
620*0e209d39SAndroid Build Coastguard Worker         "A",
621*0e209d39SAndroid Build Coastguard Worker         "F",
622*0e209d39SAndroid Build Coastguard Worker         "2",
623*0e209d39SAndroid Build Coastguard Worker         "0",
624*0e209d39SAndroid Build Coastguard Worker         "9",
625*0e209d39SAndroid Build Coastguard Worker         "{",
626*0e209d39SAndroid Build Coastguard Worker         ".",
627*0e209d39SAndroid Build Coastguard Worker         "[",
628*0e209d39SAndroid Build Coastguard Worker         "]",
629*0e209d39SAndroid Build Coastguard Worker         "\\",
630*0e209d39SAndroid Build Coastguard Worker 
631*0e209d39SAndroid Build Coastguard Worker         "e1",
632*0e209d39SAndroid Build Coastguard Worker         "N2",
633*0e209d39SAndroid Build Coastguard Worker         "3N",
634*0e209d39SAndroid Build Coastguard Worker         "4e",
635*0e209d39SAndroid Build Coastguard Worker         "e:",
636*0e209d39SAndroid Build Coastguard Worker         "43",
637*0e209d39SAndroid Build Coastguard Worker         "a9",
638*0e209d39SAndroid Build Coastguard Worker 
639*0e209d39SAndroid Build Coastguard Worker         "aN0",
640*0e209d39SAndroid Build Coastguard Worker         "z1z",
641*0e209d39SAndroid Build Coastguard Worker         "2zz",
642*0e209d39SAndroid Build Coastguard Worker         "3A3",
643*0e209d39SAndroid Build Coastguard Worker         "4.6",
644*0e209d39SAndroid Build Coastguard Worker         "af)",
645*0e209d39SAndroid Build Coastguard Worker 
646*0e209d39SAndroid Build Coastguard Worker         "0atn",
647*0e209d39SAndroid Build Coastguard Worker         "l1tn",
648*0e209d39SAndroid Build Coastguard Worker         "lA2N",
649*0e209d39SAndroid Build Coastguard Worker         "la4N",
650*0e209d39SAndroid Build Coastguard Worker         "arB5",
651*0e209d39SAndroid Build Coastguard Worker         "1234",
652*0e209d39SAndroid Build Coastguard Worker 
653*0e209d39SAndroid Build Coastguard Worker         "e)gij",
654*0e209d39SAndroid Build Coastguard Worker         "Ab3AD",
655*0e209d39SAndroid Build Coastguard Worker         "ZAAS8",
656*0e209d39SAndroid Build Coastguard Worker 
657*0e209d39SAndroid Build Coastguard Worker         "efgi[]",
658*0e209d39SAndroid Build Coastguard Worker         "AA9GFE",
659*0e209d39SAndroid Build Coastguard Worker         "7kD3Fz",
660*0e209d39SAndroid Build Coastguard Worker 
661*0e209d39SAndroid Build Coastguard Worker         "as8fads",
662*0e209d39SAndroid Build Coastguard Worker         "0DSFADF",
663*0e209d39SAndroid Build Coastguard Worker         "'iSFkDk",
664*0e209d39SAndroid Build Coastguard Worker 
665*0e209d39SAndroid Build Coastguard Worker         "oieradf+",
666*0e209d39SAndroid Build Coastguard Worker         "IADSFJK-",
667*0e209d39SAndroid Build Coastguard Worker         "kkDSFJk0",
668*0e209d39SAndroid Build Coastguard Worker 
669*0e209d39SAndroid Build Coastguard Worker         // alpha{9}
670*0e209d39SAndroid Build Coastguard Worker         "oieradfab",
671*0e209d39SAndroid Build Coastguard Worker         "IADSFJKDE",
672*0e209d39SAndroid Build Coastguard Worker         "kkDSFJkzf",
673*0e209d39SAndroid Build Coastguard Worker     };
674*0e209d39SAndroid Build Coastguard Worker     for(int32_t i=0;i<UPRV_LENGTHOF(illFormed);i++) {
675*0e209d39SAndroid Build Coastguard Worker         const char* ill = illFormed[i];
676*0e209d39SAndroid Build Coastguard Worker         UErrorCode status = U_ZERO_ERROR;
677*0e209d39SAndroid Build Coastguard Worker         ULocaleBuilder* bld = ulocbld_open();
678*0e209d39SAndroid Build Coastguard Worker         ulocbld_setRegion(bld, ill, -1);
679*0e209d39SAndroid Build Coastguard Worker         char buffer[ULOC_FULLNAME_CAPACITY];
680*0e209d39SAndroid Build Coastguard Worker         ulocbld_buildLocaleID(bld, buffer, ULOC_FULLNAME_CAPACITY, &status);
681*0e209d39SAndroid Build Coastguard Worker         if (status != U_ILLEGAL_ARGUMENT_ERROR) {
682*0e209d39SAndroid Build Coastguard Worker             log_err("setRegion(\"%s\") should fail but has no Error\n", ill);
683*0e209d39SAndroid Build Coastguard Worker         }
684*0e209d39SAndroid Build Coastguard Worker         ulocbld_close(bld);
685*0e209d39SAndroid Build Coastguard Worker     }
686*0e209d39SAndroid Build Coastguard Worker }
687*0e209d39SAndroid Build Coastguard Worker 
TestSetVariantWellFormed(void)688*0e209d39SAndroid Build Coastguard Worker static void TestSetVariantWellFormed(void) {
689*0e209d39SAndroid Build Coastguard Worker     // http://www.unicode.org/reports/tr35/tr35.html#unicode_variant_subtag
690*0e209d39SAndroid Build Coastguard Worker     // (sep unicode_variant_subtag)*
691*0e209d39SAndroid Build Coastguard Worker     // unicode_variant_subtag = (alphanum{5,8} | digit alphanum{3}) ;
692*0e209d39SAndroid Build Coastguard Worker     static const char* wellFormedVariants[] = {
693*0e209d39SAndroid Build Coastguard Worker         "",
694*0e209d39SAndroid Build Coastguard Worker 
695*0e209d39SAndroid Build Coastguard Worker         // alphanum{5}
696*0e209d39SAndroid Build Coastguard Worker         "efgij",
697*0e209d39SAndroid Build Coastguard Worker         "AbCAD",
698*0e209d39SAndroid Build Coastguard Worker         "ZAASD",
699*0e209d39SAndroid Build Coastguard Worker         "0AASD",
700*0e209d39SAndroid Build Coastguard Worker         "A1CAD",
701*0e209d39SAndroid Build Coastguard Worker         "ef2ij",
702*0e209d39SAndroid Build Coastguard Worker         "ads3X",
703*0e209d39SAndroid Build Coastguard Worker         "owqF4",
704*0e209d39SAndroid Build Coastguard Worker 
705*0e209d39SAndroid Build Coastguard Worker         // alphanum{6}
706*0e209d39SAndroid Build Coastguard Worker         "efgijk",
707*0e209d39SAndroid Build Coastguard Worker         "AADGFE",
708*0e209d39SAndroid Build Coastguard Worker         "AkDfFz",
709*0e209d39SAndroid Build Coastguard Worker         "0ADGFE",
710*0e209d39SAndroid Build Coastguard Worker         "A9DfFz",
711*0e209d39SAndroid Build Coastguard Worker         "AADG7E",
712*0e209d39SAndroid Build Coastguard Worker 
713*0e209d39SAndroid Build Coastguard Worker         // alphanum{7}
714*0e209d39SAndroid Build Coastguard Worker         "asdfads",
715*0e209d39SAndroid Build Coastguard Worker         "ADSFADF",
716*0e209d39SAndroid Build Coastguard Worker         "piSFkDk",
717*0e209d39SAndroid Build Coastguard Worker         "a0dfads",
718*0e209d39SAndroid Build Coastguard Worker         "ADSF3DF",
719*0e209d39SAndroid Build Coastguard Worker         "piSFkD9",
720*0e209d39SAndroid Build Coastguard Worker 
721*0e209d39SAndroid Build Coastguard Worker         // alphanum{8}
722*0e209d39SAndroid Build Coastguard Worker         "oieradfz",
723*0e209d39SAndroid Build Coastguard Worker         "IADSFJKR",
724*0e209d39SAndroid Build Coastguard Worker         "kkDSFJkR",
725*0e209d39SAndroid Build Coastguard Worker         "0ADSFJKR",
726*0e209d39SAndroid Build Coastguard Worker         "12345679",
727*0e209d39SAndroid Build Coastguard Worker 
728*0e209d39SAndroid Build Coastguard Worker         // digit alphanum{3}
729*0e209d39SAndroid Build Coastguard Worker         "0123",
730*0e209d39SAndroid Build Coastguard Worker         "1abc",
731*0e209d39SAndroid Build Coastguard Worker         "20EF",
732*0e209d39SAndroid Build Coastguard Worker         "30EF",
733*0e209d39SAndroid Build Coastguard Worker         "8A03",
734*0e209d39SAndroid Build Coastguard Worker         "3Ax3",
735*0e209d39SAndroid Build Coastguard Worker         "9Axy",
736*0e209d39SAndroid Build Coastguard Worker 
737*0e209d39SAndroid Build Coastguard Worker         // (sep unicode_variant_subtag)*
738*0e209d39SAndroid Build Coastguard Worker         "0123-4567",
739*0e209d39SAndroid Build Coastguard Worker         "0ab3-ABCDE",
740*0e209d39SAndroid Build Coastguard Worker         "9ax3-xByD9",
741*0e209d39SAndroid Build Coastguard Worker         "9ax3-xByD9-adfk934a",
742*0e209d39SAndroid Build Coastguard Worker 
743*0e209d39SAndroid Build Coastguard Worker         "0123_4567",
744*0e209d39SAndroid Build Coastguard Worker         "0ab3_ABCDE",
745*0e209d39SAndroid Build Coastguard Worker         "9ax3_xByD9",
746*0e209d39SAndroid Build Coastguard Worker         "9ax3_xByD9_adfk934a",
747*0e209d39SAndroid Build Coastguard Worker 
748*0e209d39SAndroid Build Coastguard Worker         "9ax3-xByD9_adfk934a",
749*0e209d39SAndroid Build Coastguard Worker         "9ax3_xByD9-adfk934a",
750*0e209d39SAndroid Build Coastguard Worker     };
751*0e209d39SAndroid Build Coastguard Worker     for(int32_t i=0;i<UPRV_LENGTHOF(wellFormedVariants);i++) {
752*0e209d39SAndroid Build Coastguard Worker         const char* variant = wellFormedVariants[i];
753*0e209d39SAndroid Build Coastguard Worker         UErrorCode status = U_ZERO_ERROR;
754*0e209d39SAndroid Build Coastguard Worker         ULocaleBuilder* bld = ulocbld_open();
755*0e209d39SAndroid Build Coastguard Worker         ulocbld_setVariant(bld, variant, -1);
756*0e209d39SAndroid Build Coastguard Worker         char buffer[ULOC_FULLNAME_CAPACITY];
757*0e209d39SAndroid Build Coastguard Worker         ulocbld_buildLocaleID(bld, buffer, ULOC_FULLNAME_CAPACITY, &status);
758*0e209d39SAndroid Build Coastguard Worker         if (U_FAILURE(status)) {
759*0e209d39SAndroid Build Coastguard Worker             log_err("setVariant(\"%s\") got Error: %s\n",
760*0e209d39SAndroid Build Coastguard Worker                   variant, u_errorName(status));
761*0e209d39SAndroid Build Coastguard Worker         }
762*0e209d39SAndroid Build Coastguard Worker         ulocbld_close(bld);
763*0e209d39SAndroid Build Coastguard Worker     }
764*0e209d39SAndroid Build Coastguard Worker }
765*0e209d39SAndroid Build Coastguard Worker 
TestSetVariantIllFormed(void)766*0e209d39SAndroid Build Coastguard Worker static void TestSetVariantIllFormed(void) {
767*0e209d39SAndroid Build Coastguard Worker     static const char* illFormed[] = {
768*0e209d39SAndroid Build Coastguard Worker         "a",
769*0e209d39SAndroid Build Coastguard Worker         "z",
770*0e209d39SAndroid Build Coastguard Worker         "A",
771*0e209d39SAndroid Build Coastguard Worker         "F",
772*0e209d39SAndroid Build Coastguard Worker         "2",
773*0e209d39SAndroid Build Coastguard Worker         "0",
774*0e209d39SAndroid Build Coastguard Worker         "9",
775*0e209d39SAndroid Build Coastguard Worker         "{",
776*0e209d39SAndroid Build Coastguard Worker         ".",
777*0e209d39SAndroid Build Coastguard Worker         "[",
778*0e209d39SAndroid Build Coastguard Worker         "]",
779*0e209d39SAndroid Build Coastguard Worker         "\\",
780*0e209d39SAndroid Build Coastguard Worker 
781*0e209d39SAndroid Build Coastguard Worker         "e1",
782*0e209d39SAndroid Build Coastguard Worker         "N2",
783*0e209d39SAndroid Build Coastguard Worker         "3N",
784*0e209d39SAndroid Build Coastguard Worker         "4e",
785*0e209d39SAndroid Build Coastguard Worker         "e:",
786*0e209d39SAndroid Build Coastguard Worker         "43",
787*0e209d39SAndroid Build Coastguard Worker         "a9",
788*0e209d39SAndroid Build Coastguard Worker         "en",
789*0e209d39SAndroid Build Coastguard Worker         "NE",
790*0e209d39SAndroid Build Coastguard Worker         "eN",
791*0e209d39SAndroid Build Coastguard Worker         "Ne",
792*0e209d39SAndroid Build Coastguard Worker 
793*0e209d39SAndroid Build Coastguard Worker         "aNe",
794*0e209d39SAndroid Build Coastguard Worker         "zzz",
795*0e209d39SAndroid Build Coastguard Worker         "AAA",
796*0e209d39SAndroid Build Coastguard Worker         "aN0",
797*0e209d39SAndroid Build Coastguard Worker         "z1z",
798*0e209d39SAndroid Build Coastguard Worker         "2zz",
799*0e209d39SAndroid Build Coastguard Worker         "3A3",
800*0e209d39SAndroid Build Coastguard Worker         "4.6",
801*0e209d39SAndroid Build Coastguard Worker         "af)",
802*0e209d39SAndroid Build Coastguard Worker         "345",
803*0e209d39SAndroid Build Coastguard Worker         "923",
804*0e209d39SAndroid Build Coastguard Worker 
805*0e209d39SAndroid Build Coastguard Worker         "Latn",
806*0e209d39SAndroid Build Coastguard Worker         "latn",
807*0e209d39SAndroid Build Coastguard Worker         "lATN",
808*0e209d39SAndroid Build Coastguard Worker         "laTN",
809*0e209d39SAndroid Build Coastguard Worker         "arBN",
810*0e209d39SAndroid Build Coastguard Worker         "ARbn",
811*0e209d39SAndroid Build Coastguard Worker         "adsf",
812*0e209d39SAndroid Build Coastguard Worker         "aADF",
813*0e209d39SAndroid Build Coastguard Worker         "BSVS",
814*0e209d39SAndroid Build Coastguard Worker         "LATn",
815*0e209d39SAndroid Build Coastguard Worker         "l1tn",
816*0e209d39SAndroid Build Coastguard Worker         "lA2N",
817*0e209d39SAndroid Build Coastguard Worker         "la4N",
818*0e209d39SAndroid Build Coastguard Worker         "arB5",
819*0e209d39SAndroid Build Coastguard Worker         "abc3",
820*0e209d39SAndroid Build Coastguard Worker         "A3BC",
821*0e209d39SAndroid Build Coastguard Worker 
822*0e209d39SAndroid Build Coastguard Worker         "e)gij",
823*0e209d39SAndroid Build Coastguard Worker         "A+3AD",
824*0e209d39SAndroid Build Coastguard Worker         "ZAA=8",
825*0e209d39SAndroid Build Coastguard Worker 
826*0e209d39SAndroid Build Coastguard Worker         "efgi[]",
827*0e209d39SAndroid Build Coastguard Worker         "AA9]FE",
828*0e209d39SAndroid Build Coastguard Worker         "7k[3Fz",
829*0e209d39SAndroid Build Coastguard Worker 
830*0e209d39SAndroid Build Coastguard Worker         "as8f/ds",
831*0e209d39SAndroid Build Coastguard Worker         "0DSFAD{",
832*0e209d39SAndroid Build Coastguard Worker         "'iSFkDk",
833*0e209d39SAndroid Build Coastguard Worker 
834*0e209d39SAndroid Build Coastguard Worker         "oieradf+",
835*0e209d39SAndroid Build Coastguard Worker         "IADSFJK-",
836*0e209d39SAndroid Build Coastguard Worker         "k}DSFJk0",
837*0e209d39SAndroid Build Coastguard Worker 
838*0e209d39SAndroid Build Coastguard Worker         // alpha{9}
839*0e209d39SAndroid Build Coastguard Worker         "oieradfab",
840*0e209d39SAndroid Build Coastguard Worker         "IADSFJKDE",
841*0e209d39SAndroid Build Coastguard Worker         "kkDSFJkzf",
842*0e209d39SAndroid Build Coastguard Worker         "123456789",
843*0e209d39SAndroid Build Coastguard Worker 
844*0e209d39SAndroid Build Coastguard Worker         "-0123",
845*0e209d39SAndroid Build Coastguard Worker         "-0123-4567",
846*0e209d39SAndroid Build Coastguard Worker         "0123-4567-",
847*0e209d39SAndroid Build Coastguard Worker         "-123-4567",
848*0e209d39SAndroid Build Coastguard Worker         "_0123",
849*0e209d39SAndroid Build Coastguard Worker         "_0123_4567",
850*0e209d39SAndroid Build Coastguard Worker         "0123_4567_",
851*0e209d39SAndroid Build Coastguard Worker         "_123_4567",
852*0e209d39SAndroid Build Coastguard Worker 
853*0e209d39SAndroid Build Coastguard Worker         "-abcde-figjk",
854*0e209d39SAndroid Build Coastguard Worker         "abcde-figjk-",
855*0e209d39SAndroid Build Coastguard Worker         "-abcde-figjk-",
856*0e209d39SAndroid Build Coastguard Worker         "_abcde_figjk",
857*0e209d39SAndroid Build Coastguard Worker         "abcde_figjk_",
858*0e209d39SAndroid Build Coastguard Worker         "_abcde_figjk_",
859*0e209d39SAndroid Build Coastguard Worker     };
860*0e209d39SAndroid Build Coastguard Worker     for(int32_t i=0;i<UPRV_LENGTHOF(illFormed);i++) {
861*0e209d39SAndroid Build Coastguard Worker         const char* ill = illFormed[i];
862*0e209d39SAndroid Build Coastguard Worker         UErrorCode status = U_ZERO_ERROR;
863*0e209d39SAndroid Build Coastguard Worker         ULocaleBuilder* bld = ulocbld_open();
864*0e209d39SAndroid Build Coastguard Worker         ulocbld_setVariant(bld, ill, -1);
865*0e209d39SAndroid Build Coastguard Worker         char buffer[ULOC_FULLNAME_CAPACITY];
866*0e209d39SAndroid Build Coastguard Worker         ulocbld_buildLocaleID(bld, buffer, ULOC_FULLNAME_CAPACITY, &status);
867*0e209d39SAndroid Build Coastguard Worker         if (status != U_ILLEGAL_ARGUMENT_ERROR) {
868*0e209d39SAndroid Build Coastguard Worker             log_err("setVariant(\"%s\") should fail but has no Error\n", ill);
869*0e209d39SAndroid Build Coastguard Worker         }
870*0e209d39SAndroid Build Coastguard Worker         ulocbld_close(bld);
871*0e209d39SAndroid Build Coastguard Worker     }
872*0e209d39SAndroid Build Coastguard Worker }
873*0e209d39SAndroid Build Coastguard Worker 
TestSetUnicodeLocaleKeywordWellFormed(void)874*0e209d39SAndroid Build Coastguard Worker static void TestSetUnicodeLocaleKeywordWellFormed(void) {
875*0e209d39SAndroid Build Coastguard Worker     // http://www.unicode.org/reports/tr35/tr35.html#unicode_locale_extensions
876*0e209d39SAndroid Build Coastguard Worker     // keyword = key (sep type)? ;
877*0e209d39SAndroid Build Coastguard Worker     // key = alphanum alpha ;
878*0e209d39SAndroid Build Coastguard Worker     // type = alphanum{3,8} (sep alphanum{3,8})* ;
879*0e209d39SAndroid Build Coastguard Worker     static const char* wellFormed_key_value[] = {
880*0e209d39SAndroid Build Coastguard Worker         "aa", "123",
881*0e209d39SAndroid Build Coastguard Worker         "3b", "zyzbcdef",
882*0e209d39SAndroid Build Coastguard Worker         "0Z", "1ZB30zk9-abc",
883*0e209d39SAndroid Build Coastguard Worker         "cZ", "2ck30zfZ-adsf023-234kcZ",
884*0e209d39SAndroid Build Coastguard Worker         "ZZ", "Lant",
885*0e209d39SAndroid Build Coastguard Worker         "ko", "",
886*0e209d39SAndroid Build Coastguard Worker     };
887*0e209d39SAndroid Build Coastguard Worker     for (int i = 0; i < UPRV_LENGTHOF(wellFormed_key_value); i += 2) {
888*0e209d39SAndroid Build Coastguard Worker         UErrorCode status = U_ZERO_ERROR;
889*0e209d39SAndroid Build Coastguard Worker         ULocaleBuilder* bld = ulocbld_open();
890*0e209d39SAndroid Build Coastguard Worker         ulocbld_setUnicodeLocaleKeyword(bld, wellFormed_key_value[i], -1,
891*0e209d39SAndroid Build Coastguard Worker                                         wellFormed_key_value[i + 1], -1);
892*0e209d39SAndroid Build Coastguard Worker         char buffer[ULOC_FULLNAME_CAPACITY];
893*0e209d39SAndroid Build Coastguard Worker         ulocbld_buildLocaleID(bld, buffer, ULOC_FULLNAME_CAPACITY, &status);
894*0e209d39SAndroid Build Coastguard Worker         if (U_FAILURE(status)) {
895*0e209d39SAndroid Build Coastguard Worker             log_err("setUnicodeLocaleKeyword(\"%s\", \"%s\") got Error: %s\n",
896*0e209d39SAndroid Build Coastguard Worker                   wellFormed_key_value[i],
897*0e209d39SAndroid Build Coastguard Worker                   wellFormed_key_value[i + 1],
898*0e209d39SAndroid Build Coastguard Worker                   u_errorName(status));
899*0e209d39SAndroid Build Coastguard Worker         }
900*0e209d39SAndroid Build Coastguard Worker         ulocbld_close(bld);
901*0e209d39SAndroid Build Coastguard Worker     }
902*0e209d39SAndroid Build Coastguard Worker }
903*0e209d39SAndroid Build Coastguard Worker 
TestSetUnicodeLocaleKeywordIllFormedKey(void)904*0e209d39SAndroid Build Coastguard Worker static void TestSetUnicodeLocaleKeywordIllFormedKey(void) {
905*0e209d39SAndroid Build Coastguard Worker     static const char* illFormed[] = {
906*0e209d39SAndroid Build Coastguard Worker         "34",
907*0e209d39SAndroid Build Coastguard Worker         "ab-cde",
908*0e209d39SAndroid Build Coastguard Worker         "123",
909*0e209d39SAndroid Build Coastguard Worker         "b3",
910*0e209d39SAndroid Build Coastguard Worker         "zyzabcdef",
911*0e209d39SAndroid Build Coastguard Worker         "Z0",
912*0e209d39SAndroid Build Coastguard Worker     };
913*0e209d39SAndroid Build Coastguard Worker     for (int i = 0; i < UPRV_LENGTHOF(illFormed); i++) {
914*0e209d39SAndroid Build Coastguard Worker         const char* ill = illFormed[i];
915*0e209d39SAndroid Build Coastguard Worker         UErrorCode status = U_ZERO_ERROR;
916*0e209d39SAndroid Build Coastguard Worker         ULocaleBuilder* bld = ulocbld_open();
917*0e209d39SAndroid Build Coastguard Worker         ulocbld_setUnicodeLocaleKeyword(bld, ill, -1, "abc", 3);
918*0e209d39SAndroid Build Coastguard Worker         char buffer[ULOC_FULLNAME_CAPACITY];
919*0e209d39SAndroid Build Coastguard Worker         ulocbld_buildLocaleID(bld, buffer, ULOC_FULLNAME_CAPACITY, &status);
920*0e209d39SAndroid Build Coastguard Worker         if (status != U_ILLEGAL_ARGUMENT_ERROR) {
921*0e209d39SAndroid Build Coastguard Worker             log_err("setUnicodeLocaleKeyword(\"%s\", \"abc\") should fail but has no Error\n",
922*0e209d39SAndroid Build Coastguard Worker                   ill);
923*0e209d39SAndroid Build Coastguard Worker         }
924*0e209d39SAndroid Build Coastguard Worker         ulocbld_close(bld);
925*0e209d39SAndroid Build Coastguard Worker     }
926*0e209d39SAndroid Build Coastguard Worker }
927*0e209d39SAndroid Build Coastguard Worker 
TestSetUnicodeLocaleKeywordIllFormedValue(void)928*0e209d39SAndroid Build Coastguard Worker static void TestSetUnicodeLocaleKeywordIllFormedValue(void) {
929*0e209d39SAndroid Build Coastguard Worker     static const char* illFormed[] = {
930*0e209d39SAndroid Build Coastguard Worker         "34",
931*0e209d39SAndroid Build Coastguard Worker         "ab-",
932*0e209d39SAndroid Build Coastguard Worker         "-cd",
933*0e209d39SAndroid Build Coastguard Worker         "-ef-",
934*0e209d39SAndroid Build Coastguard Worker         "zyzabcdef",
935*0e209d39SAndroid Build Coastguard Worker         "ab-abc",
936*0e209d39SAndroid Build Coastguard Worker         "1ZB30zfk9-abc",
937*0e209d39SAndroid Build Coastguard Worker         "2ck30zfk9-adsf023-234kcZ",
938*0e209d39SAndroid Build Coastguard Worker     };
939*0e209d39SAndroid Build Coastguard Worker     ULocaleBuilder* bld = ulocbld_open();
940*0e209d39SAndroid Build Coastguard Worker     for (int i = 0; i < UPRV_LENGTHOF(illFormed); i++) {
941*0e209d39SAndroid Build Coastguard Worker         const char* ill = illFormed[i];
942*0e209d39SAndroid Build Coastguard Worker         ulocbld_clear(bld);
943*0e209d39SAndroid Build Coastguard Worker         UErrorCode status = U_ZERO_ERROR;
944*0e209d39SAndroid Build Coastguard Worker         ulocbld_setUnicodeLocaleKeyword(bld, "ab", 2, ill, -1);
945*0e209d39SAndroid Build Coastguard Worker         char buffer[ULOC_FULLNAME_CAPACITY];
946*0e209d39SAndroid Build Coastguard Worker         ulocbld_buildLocaleID(bld, buffer, ULOC_FULLNAME_CAPACITY, &status);
947*0e209d39SAndroid Build Coastguard Worker         if (status != U_ILLEGAL_ARGUMENT_ERROR) {
948*0e209d39SAndroid Build Coastguard Worker             log_err("setUnicodeLocaleKeyword(\"ab\", \"%s\") should fail but has no Error\n",
949*0e209d39SAndroid Build Coastguard Worker                   ill);
950*0e209d39SAndroid Build Coastguard Worker         }
951*0e209d39SAndroid Build Coastguard Worker     }
952*0e209d39SAndroid Build Coastguard Worker     ulocbld_close(bld);
953*0e209d39SAndroid Build Coastguard Worker }
954*0e209d39SAndroid Build Coastguard Worker 
TestAddRemoveUnicodeLocaleAttribute(void)955*0e209d39SAndroid Build Coastguard Worker static void TestAddRemoveUnicodeLocaleAttribute(void) {
956*0e209d39SAndroid Build Coastguard Worker     ULocaleBuilder* bld = ulocbld_open();
957*0e209d39SAndroid Build Coastguard Worker     ulocbld_setLanguage(bld, "fr", -1);
958*0e209d39SAndroid Build Coastguard Worker     ulocbld_addUnicodeLocaleAttribute(bld, "abc", -1);
959*0e209d39SAndroid Build Coastguard Worker     ulocbld_addUnicodeLocaleAttribute(bld, "aBc", -1);
960*0e209d39SAndroid Build Coastguard Worker     ulocbld_addUnicodeLocaleAttribute(bld, "EFG123", 3);
961*0e209d39SAndroid Build Coastguard Worker     ulocbld_addUnicodeLocaleAttribute(bld, "efghi###", 5);
962*0e209d39SAndroid Build Coastguard Worker     ulocbld_addUnicodeLocaleAttribute(bld, "efgh", -1);
963*0e209d39SAndroid Build Coastguard Worker     ulocbld_addUnicodeLocaleAttribute(bld, "efGhi", -1);
964*0e209d39SAndroid Build Coastguard Worker     ulocbld_addUnicodeLocaleAttribute(bld, "EFg", -1);
965*0e209d39SAndroid Build Coastguard Worker     ulocbld_addUnicodeLocaleAttribute(bld, "hijk", -1);
966*0e209d39SAndroid Build Coastguard Worker     ulocbld_addUnicodeLocaleAttribute(bld, "EFG", -1);
967*0e209d39SAndroid Build Coastguard Worker     ulocbld_addUnicodeLocaleAttribute(bld, "HiJK", -1);
968*0e209d39SAndroid Build Coastguard Worker     ulocbld_addUnicodeLocaleAttribute(bld, "aBc", -1);
969*0e209d39SAndroid Build Coastguard Worker     UErrorCode status = U_ZERO_ERROR;
970*0e209d39SAndroid Build Coastguard Worker     char locale[ULOC_FULLNAME_CAPACITY];
971*0e209d39SAndroid Build Coastguard Worker     ulocbld_buildLocaleID(bld, locale, ULOC_FULLNAME_CAPACITY, &status);
972*0e209d39SAndroid Build Coastguard Worker     if (U_FAILURE(status)) {
973*0e209d39SAndroid Build Coastguard Worker         log_err("addUnicodeLocaleAttribute() got Error: %s\n",
974*0e209d39SAndroid Build Coastguard Worker               u_errorName(status));
975*0e209d39SAndroid Build Coastguard Worker     }
976*0e209d39SAndroid Build Coastguard Worker     char languageTag[ULOC_FULLNAME_CAPACITY];
977*0e209d39SAndroid Build Coastguard Worker     ulocbld_buildLanguageTag(bld, languageTag, ULOC_FULLNAME_CAPACITY, &status);
978*0e209d39SAndroid Build Coastguard Worker     const char* expected = "fr-u-abc-efg-efgh-efghi-hijk";
979*0e209d39SAndroid Build Coastguard Worker     if (U_FAILURE(status) || strcmp(languageTag, expected) != 0) {
980*0e209d39SAndroid Build Coastguard Worker         log_err("Should get \"%s\" but get \"%s\"\n", expected, languageTag);
981*0e209d39SAndroid Build Coastguard Worker     }
982*0e209d39SAndroid Build Coastguard Worker 
983*0e209d39SAndroid Build Coastguard Worker     // remove "efgh" in the middle with different casing.
984*0e209d39SAndroid Build Coastguard Worker     ulocbld_removeUnicodeLocaleAttribute(bld, "eFgH", -1);
985*0e209d39SAndroid Build Coastguard Worker     ulocbld_buildLanguageTag(bld, languageTag, ULOC_FULLNAME_CAPACITY, &status);
986*0e209d39SAndroid Build Coastguard Worker     expected = "fr-u-abc-efg-efghi-hijk";
987*0e209d39SAndroid Build Coastguard Worker     if (U_FAILURE(status) || strcmp(languageTag, expected) != 0) {
988*0e209d39SAndroid Build Coastguard Worker         log_err("removeUnicodeLocaleAttribute() got Error: %s\n",
989*0e209d39SAndroid Build Coastguard Worker               u_errorName(status));
990*0e209d39SAndroid Build Coastguard Worker         log_err("Should get \"%s\" but get \"%s\"\n", expected, languageTag);
991*0e209d39SAndroid Build Coastguard Worker     }
992*0e209d39SAndroid Build Coastguard Worker 
993*0e209d39SAndroid Build Coastguard Worker     // remove non-existing attributes.
994*0e209d39SAndroid Build Coastguard Worker     ulocbld_removeUnicodeLocaleAttribute(bld, "efgh", -1);
995*0e209d39SAndroid Build Coastguard Worker     ulocbld_buildLanguageTag(bld, languageTag, ULOC_FULLNAME_CAPACITY, &status);
996*0e209d39SAndroid Build Coastguard Worker     if (U_FAILURE(status) || strcmp(languageTag, expected) != 0) {
997*0e209d39SAndroid Build Coastguard Worker         log_err("removeUnicodeLocaleAttribute() got Error: %s\n",
998*0e209d39SAndroid Build Coastguard Worker               u_errorName(status));
999*0e209d39SAndroid Build Coastguard Worker         log_err("Should get \"%s\" but get \"%s\"\n", expected, languageTag);
1000*0e209d39SAndroid Build Coastguard Worker     }
1001*0e209d39SAndroid Build Coastguard Worker 
1002*0e209d39SAndroid Build Coastguard Worker     // remove "abc" in the beginning with different casing.
1003*0e209d39SAndroid Build Coastguard Worker     ulocbld_removeUnicodeLocaleAttribute(bld, "ABC", -1);
1004*0e209d39SAndroid Build Coastguard Worker     ulocbld_buildLanguageTag(bld, languageTag, ULOC_FULLNAME_CAPACITY, &status);
1005*0e209d39SAndroid Build Coastguard Worker     expected = "fr-u-efg-efghi-hijk";
1006*0e209d39SAndroid Build Coastguard Worker     if (U_FAILURE(status) || strcmp(languageTag, expected) != 0) {
1007*0e209d39SAndroid Build Coastguard Worker         log_err("removeUnicodeLocaleAttribute() got Error: %s\n",
1008*0e209d39SAndroid Build Coastguard Worker               u_errorName(status));
1009*0e209d39SAndroid Build Coastguard Worker         log_err("Should get \"%s\" but get \"%s\"\n", expected, languageTag);
1010*0e209d39SAndroid Build Coastguard Worker     }
1011*0e209d39SAndroid Build Coastguard Worker 
1012*0e209d39SAndroid Build Coastguard Worker     // remove non-existing substring in the end.
1013*0e209d39SAndroid Build Coastguard Worker     ulocbld_removeUnicodeLocaleAttribute(bld, "hij", -1);
1014*0e209d39SAndroid Build Coastguard Worker     ulocbld_buildLanguageTag(bld, languageTag, ULOC_FULLNAME_CAPACITY, &status);
1015*0e209d39SAndroid Build Coastguard Worker     if (U_FAILURE(status) || strcmp(languageTag, expected) != 0) {
1016*0e209d39SAndroid Build Coastguard Worker         log_err("removeUnicodeLocaleAttribute() got Error: %s\n",
1017*0e209d39SAndroid Build Coastguard Worker               u_errorName(status));
1018*0e209d39SAndroid Build Coastguard Worker         log_err("Should get \"%s\" but get \"%s\"\n", expected, languageTag);
1019*0e209d39SAndroid Build Coastguard Worker     }
1020*0e209d39SAndroid Build Coastguard Worker 
1021*0e209d39SAndroid Build Coastguard Worker     // remove "hijk" in the end with different casing.
1022*0e209d39SAndroid Build Coastguard Worker     ulocbld_removeUnicodeLocaleAttribute(bld, "hIJK", -1);
1023*0e209d39SAndroid Build Coastguard Worker     ulocbld_buildLanguageTag(bld, languageTag, ULOC_FULLNAME_CAPACITY, &status);
1024*0e209d39SAndroid Build Coastguard Worker     expected = "fr-u-efg-efghi";
1025*0e209d39SAndroid Build Coastguard Worker     if (U_FAILURE(status) || strcmp(languageTag, expected) != 0) {
1026*0e209d39SAndroid Build Coastguard Worker         log_err("removeUnicodeLocaleAttribute() got Error: %s\n",
1027*0e209d39SAndroid Build Coastguard Worker               u_errorName(status));
1028*0e209d39SAndroid Build Coastguard Worker         log_err("Should get \"%s\" but get \"%s\"\n", expected, languageTag);
1029*0e209d39SAndroid Build Coastguard Worker     }
1030*0e209d39SAndroid Build Coastguard Worker 
1031*0e209d39SAndroid Build Coastguard Worker     // remove "efghi" in the end with different casing.
1032*0e209d39SAndroid Build Coastguard Worker     ulocbld_removeUnicodeLocaleAttribute(bld, "EFGhi", -1);
1033*0e209d39SAndroid Build Coastguard Worker     ulocbld_buildLanguageTag(bld, languageTag, ULOC_FULLNAME_CAPACITY, &status);
1034*0e209d39SAndroid Build Coastguard Worker     expected = "fr-u-efg";
1035*0e209d39SAndroid Build Coastguard Worker     if (U_FAILURE(status) || strcmp(languageTag, expected) != 0) {
1036*0e209d39SAndroid Build Coastguard Worker         log_err("removeUnicodeLocaleAttribute() got Error: %s\n",
1037*0e209d39SAndroid Build Coastguard Worker               u_errorName(status));
1038*0e209d39SAndroid Build Coastguard Worker         log_err("Should get \"%s\" but get \"%s\"\n", expected, languageTag);
1039*0e209d39SAndroid Build Coastguard Worker     }
1040*0e209d39SAndroid Build Coastguard Worker 
1041*0e209d39SAndroid Build Coastguard Worker     // remove "efg" in as the only one, with different casing.
1042*0e209d39SAndroid Build Coastguard Worker     ulocbld_removeUnicodeLocaleAttribute(bld, "EFG", -1);
1043*0e209d39SAndroid Build Coastguard Worker     ulocbld_buildLanguageTag(bld, languageTag, ULOC_FULLNAME_CAPACITY, &status);
1044*0e209d39SAndroid Build Coastguard Worker     expected = "fr";
1045*0e209d39SAndroid Build Coastguard Worker     if (U_FAILURE(status) || strcmp(languageTag, expected) != 0) {
1046*0e209d39SAndroid Build Coastguard Worker         log_err("removeUnicodeLocaleAttribute() got Error: %s\n",
1047*0e209d39SAndroid Build Coastguard Worker               u_errorName(status));
1048*0e209d39SAndroid Build Coastguard Worker         log_err("Should get \"%s\" but get \"%s\"\n", expected, languageTag);
1049*0e209d39SAndroid Build Coastguard Worker     }
1050*0e209d39SAndroid Build Coastguard Worker     ulocbld_close(bld);
1051*0e209d39SAndroid Build Coastguard Worker }
1052*0e209d39SAndroid Build Coastguard Worker 
TestAddRemoveUnicodeLocaleAttributeWellFormed(void)1053*0e209d39SAndroid Build Coastguard Worker static void TestAddRemoveUnicodeLocaleAttributeWellFormed(void) {
1054*0e209d39SAndroid Build Coastguard Worker     // http://www.unicode.org/reports/tr35/tr35.html#unicode_locale_extensions
1055*0e209d39SAndroid Build Coastguard Worker     // attribute = alphanum{3,8} ;
1056*0e209d39SAndroid Build Coastguard Worker     static const char* wellFormedAttributes[] = {
1057*0e209d39SAndroid Build Coastguard Worker         // alphanum{3}
1058*0e209d39SAndroid Build Coastguard Worker         "AbC",
1059*0e209d39SAndroid Build Coastguard Worker         "ZAA",
1060*0e209d39SAndroid Build Coastguard Worker         "0AA",
1061*0e209d39SAndroid Build Coastguard Worker         "x3A",
1062*0e209d39SAndroid Build Coastguard Worker         "xa8",
1063*0e209d39SAndroid Build Coastguard Worker 
1064*0e209d39SAndroid Build Coastguard Worker         // alphanum{4}
1065*0e209d39SAndroid Build Coastguard Worker         "AbCA",
1066*0e209d39SAndroid Build Coastguard Worker         "ZASD",
1067*0e209d39SAndroid Build Coastguard Worker         "0ASD",
1068*0e209d39SAndroid Build Coastguard Worker         "A3a4",
1069*0e209d39SAndroid Build Coastguard Worker         "zK90",
1070*0e209d39SAndroid Build Coastguard Worker 
1071*0e209d39SAndroid Build Coastguard Worker         // alphanum{5}
1072*0e209d39SAndroid Build Coastguard Worker         "efgij",
1073*0e209d39SAndroid Build Coastguard Worker         "AbCAD",
1074*0e209d39SAndroid Build Coastguard Worker         "ZAASD",
1075*0e209d39SAndroid Build Coastguard Worker         "0AASD",
1076*0e209d39SAndroid Build Coastguard Worker         "A1CAD",
1077*0e209d39SAndroid Build Coastguard Worker         "ef2ij",
1078*0e209d39SAndroid Build Coastguard Worker         "ads3X",
1079*0e209d39SAndroid Build Coastguard Worker         "owqF4",
1080*0e209d39SAndroid Build Coastguard Worker 
1081*0e209d39SAndroid Build Coastguard Worker         // alphanum{6}
1082*0e209d39SAndroid Build Coastguard Worker         "efgijk",
1083*0e209d39SAndroid Build Coastguard Worker         "AADGFE",
1084*0e209d39SAndroid Build Coastguard Worker         "AkDfFz",
1085*0e209d39SAndroid Build Coastguard Worker         "0ADGFE",
1086*0e209d39SAndroid Build Coastguard Worker         "A9DfFz",
1087*0e209d39SAndroid Build Coastguard Worker         "AADG7E",
1088*0e209d39SAndroid Build Coastguard Worker 
1089*0e209d39SAndroid Build Coastguard Worker         // alphanum{7}
1090*0e209d39SAndroid Build Coastguard Worker         "asdfads",
1091*0e209d39SAndroid Build Coastguard Worker         "ADSFADF",
1092*0e209d39SAndroid Build Coastguard Worker         "piSFkDk",
1093*0e209d39SAndroid Build Coastguard Worker         "a0dfads",
1094*0e209d39SAndroid Build Coastguard Worker         "ADSF3DF",
1095*0e209d39SAndroid Build Coastguard Worker         "piSFkD9",
1096*0e209d39SAndroid Build Coastguard Worker 
1097*0e209d39SAndroid Build Coastguard Worker         // alphanum{8}
1098*0e209d39SAndroid Build Coastguard Worker         "oieradfz",
1099*0e209d39SAndroid Build Coastguard Worker         "IADSFJKR",
1100*0e209d39SAndroid Build Coastguard Worker         "kkDSFJkR",
1101*0e209d39SAndroid Build Coastguard Worker     };
1102*0e209d39SAndroid Build Coastguard Worker     ULocaleBuilder* bld = ulocbld_open();
1103*0e209d39SAndroid Build Coastguard Worker     for (int i = 0; i < UPRV_LENGTHOF(wellFormedAttributes); i++) {
1104*0e209d39SAndroid Build Coastguard Worker         if (i % 5 == 0) {
1105*0e209d39SAndroid Build Coastguard Worker             ulocbld_clear(bld);
1106*0e209d39SAndroid Build Coastguard Worker         }
1107*0e209d39SAndroid Build Coastguard Worker         ulocbld_addUnicodeLocaleAttribute(bld, wellFormedAttributes[i], -1);
1108*0e209d39SAndroid Build Coastguard Worker         UErrorCode status = U_ZERO_ERROR;
1109*0e209d39SAndroid Build Coastguard Worker         if (ulocbld_copyErrorTo(bld, &status)) {
1110*0e209d39SAndroid Build Coastguard Worker             log_err("addUnicodeLocaleAttribute(\"%s\") got Error: %s\n",
1111*0e209d39SAndroid Build Coastguard Worker                   wellFormedAttributes[i], u_errorName(status));
1112*0e209d39SAndroid Build Coastguard Worker         }
1113*0e209d39SAndroid Build Coastguard Worker         if (i > 2) {
1114*0e209d39SAndroid Build Coastguard Worker             ulocbld_removeUnicodeLocaleAttribute(bld, wellFormedAttributes[i - 1], -1);
1115*0e209d39SAndroid Build Coastguard Worker             if (ulocbld_copyErrorTo(bld, &status)) {
1116*0e209d39SAndroid Build Coastguard Worker                 log_err("removeUnicodeLocaleAttribute(\"%s\") got Error: %s\n",
1117*0e209d39SAndroid Build Coastguard Worker                       wellFormedAttributes[i - 1], u_errorName(status));
1118*0e209d39SAndroid Build Coastguard Worker             }
1119*0e209d39SAndroid Build Coastguard Worker             ulocbld_removeUnicodeLocaleAttribute(bld, wellFormedAttributes[i - 3], -1);
1120*0e209d39SAndroid Build Coastguard Worker             if (ulocbld_copyErrorTo(bld, &status)) {
1121*0e209d39SAndroid Build Coastguard Worker                 log_err("removeUnicodeLocaleAttribute(\"%s\") got Error: %s\n",
1122*0e209d39SAndroid Build Coastguard Worker                       wellFormedAttributes[i - 3], u_errorName(status));
1123*0e209d39SAndroid Build Coastguard Worker             }
1124*0e209d39SAndroid Build Coastguard Worker         }
1125*0e209d39SAndroid Build Coastguard Worker     }
1126*0e209d39SAndroid Build Coastguard Worker     ulocbld_close(bld);
1127*0e209d39SAndroid Build Coastguard Worker }
1128*0e209d39SAndroid Build Coastguard Worker 
TestAddUnicodeLocaleAttributeIllFormed(void)1129*0e209d39SAndroid Build Coastguard Worker static void TestAddUnicodeLocaleAttributeIllFormed(void) {
1130*0e209d39SAndroid Build Coastguard Worker     static const char* illFormed[] = {
1131*0e209d39SAndroid Build Coastguard Worker         "aa",
1132*0e209d39SAndroid Build Coastguard Worker         "34",
1133*0e209d39SAndroid Build Coastguard Worker         "ab-",
1134*0e209d39SAndroid Build Coastguard Worker         "-cd",
1135*0e209d39SAndroid Build Coastguard Worker         "-ef-",
1136*0e209d39SAndroid Build Coastguard Worker         "zyzabcdef",
1137*0e209d39SAndroid Build Coastguard Worker         "123456789",
1138*0e209d39SAndroid Build Coastguard Worker         "ab-abc",
1139*0e209d39SAndroid Build Coastguard Worker         "1ZB30zfk9-abc",
1140*0e209d39SAndroid Build Coastguard Worker         "2ck30zfk9-adsf023-234kcZ",
1141*0e209d39SAndroid Build Coastguard Worker     };
1142*0e209d39SAndroid Build Coastguard Worker     for (int i = 0; i < UPRV_LENGTHOF(illFormed); i++) {
1143*0e209d39SAndroid Build Coastguard Worker         const char* ill = illFormed[i];
1144*0e209d39SAndroid Build Coastguard Worker         UErrorCode status = U_ZERO_ERROR;
1145*0e209d39SAndroid Build Coastguard Worker         ULocaleBuilder* bld = ulocbld_open();
1146*0e209d39SAndroid Build Coastguard Worker         ulocbld_addUnicodeLocaleAttribute(bld, ill, -1);
1147*0e209d39SAndroid Build Coastguard Worker         char buffer[ULOC_FULLNAME_CAPACITY];
1148*0e209d39SAndroid Build Coastguard Worker         ulocbld_buildLocaleID(bld, buffer, ULOC_FULLNAME_CAPACITY, &status);
1149*0e209d39SAndroid Build Coastguard Worker         if (status != U_ILLEGAL_ARGUMENT_ERROR) {
1150*0e209d39SAndroid Build Coastguard Worker             log_err("addUnicodeLocaleAttribute(\"%s\") should fail but has no Error\n",
1151*0e209d39SAndroid Build Coastguard Worker                   ill);
1152*0e209d39SAndroid Build Coastguard Worker         }
1153*0e209d39SAndroid Build Coastguard Worker         ulocbld_close(bld);
1154*0e209d39SAndroid Build Coastguard Worker     }
1155*0e209d39SAndroid Build Coastguard Worker }
1156*0e209d39SAndroid Build Coastguard Worker 
TestSetExtensionU(void)1157*0e209d39SAndroid Build Coastguard Worker static void TestSetExtensionU(void) {
1158*0e209d39SAndroid Build Coastguard Worker     ULocaleBuilder* bld = ulocbld_open();
1159*0e209d39SAndroid Build Coastguard Worker     ulocbld_setLanguage(bld, "zhABC", 2);
1160*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "zh",
1161*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setLanguage(\"zh\") got Error: %s\n");
1162*0e209d39SAndroid Build Coastguard Worker 
1163*0e209d39SAndroid Build Coastguard Worker     ulocbld_setExtension(bld, 'u', "co-stroke", -1);
1164*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "zh-u-co-stroke",
1165*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setExtension('u', \"co-stroke\") got Error: %s\n");
1166*0e209d39SAndroid Build Coastguard Worker 
1167*0e209d39SAndroid Build Coastguard Worker     ulocbld_setExtension(bld, 'U', "ca-islamicABCDE", 10);
1168*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "zh-u-ca-islamic",
1169*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setExtension('U', \"zh-u-ca-islamic\") got Error: %s\n");
1170*0e209d39SAndroid Build Coastguard Worker 
1171*0e209d39SAndroid Build Coastguard Worker     ulocbld_setExtension(bld, 'u', "ca-chinese", 10);
1172*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "zh-u-ca-chinese",
1173*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setExtension('u', \"ca-chinese\") got Error: %s\n");
1174*0e209d39SAndroid Build Coastguard Worker 
1175*0e209d39SAndroid Build Coastguard Worker     ulocbld_setExtension(bld, 'U', "co-pinyin1234", 9);
1176*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "zh-u-co-pinyin",
1177*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setExtension('U', \"co-pinyin\") got Error: %s\n");
1178*0e209d39SAndroid Build Coastguard Worker 
1179*0e209d39SAndroid Build Coastguard Worker     ulocbld_setRegion(bld, "TW123", 2);
1180*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "zh-TW-u-co-pinyin",
1181*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setRegion(\"TW\") got Error: %s\n");
1182*0e209d39SAndroid Build Coastguard Worker 
1183*0e209d39SAndroid Build Coastguard Worker     ulocbld_setExtension(bld, 'U', "", 0);
1184*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "zh-TW",
1185*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setExtension('U', \"\") got Error: %s\n");
1186*0e209d39SAndroid Build Coastguard Worker 
1187*0e209d39SAndroid Build Coastguard Worker     ulocbld_setExtension(bld, 'u', "abc-defg-kr-face", -1);
1188*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "zh-TW-u-abc-defg-kr-face",
1189*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setExtension('u', \"abc-defg-kr-face\") got Error: %s\n");
1190*0e209d39SAndroid Build Coastguard Worker 
1191*0e209d39SAndroid Build Coastguard Worker     ulocbld_setExtension(bld, 'U', "ca-japanese", -1);
1192*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "zh-TW-u-ca-japanese",
1193*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setExtension('U', \"ca-japanese\") got Error: %s\n");
1194*0e209d39SAndroid Build Coastguard Worker 
1195*0e209d39SAndroid Build Coastguard Worker     ulocbld_close(bld);
1196*0e209d39SAndroid Build Coastguard Worker }
1197*0e209d39SAndroid Build Coastguard Worker 
TestSetExtensionValidateUWellFormed(void)1198*0e209d39SAndroid Build Coastguard Worker static void TestSetExtensionValidateUWellFormed(void) {
1199*0e209d39SAndroid Build Coastguard Worker     static const char* wellFormedExtensions[] = {
1200*0e209d39SAndroid Build Coastguard Worker         // keyword
1201*0e209d39SAndroid Build Coastguard Worker         //   keyword = key (sep type)? ;
1202*0e209d39SAndroid Build Coastguard Worker         //   key = alphanum alpha ;
1203*0e209d39SAndroid Build Coastguard Worker         //   type = alphanum{3,8} (sep alphanum{3,8})* ;
1204*0e209d39SAndroid Build Coastguard Worker         "3A",
1205*0e209d39SAndroid Build Coastguard Worker         "ZA",
1206*0e209d39SAndroid Build Coastguard Worker         "az-abc",
1207*0e209d39SAndroid Build Coastguard Worker         "zz-123",
1208*0e209d39SAndroid Build Coastguard Worker         "7z-12345678",
1209*0e209d39SAndroid Build Coastguard Worker         "kb-A234567Z",
1210*0e209d39SAndroid Build Coastguard Worker         // (sep keyword)+
1211*0e209d39SAndroid Build Coastguard Worker         "1z-ZZ",
1212*0e209d39SAndroid Build Coastguard Worker         "2z-ZZ-123",
1213*0e209d39SAndroid Build Coastguard Worker         "3z-ZZ-123-cd",
1214*0e209d39SAndroid Build Coastguard Worker         "0z-ZZ-123-cd-efghijkl",
1215*0e209d39SAndroid Build Coastguard Worker         // attribute
1216*0e209d39SAndroid Build Coastguard Worker         "abc",
1217*0e209d39SAndroid Build Coastguard Worker         "456",
1218*0e209d39SAndroid Build Coastguard Worker         "87654321",
1219*0e209d39SAndroid Build Coastguard Worker         "ZABADFSD",
1220*0e209d39SAndroid Build Coastguard Worker         // (sep attribute)+
1221*0e209d39SAndroid Build Coastguard Worker         "abc-ZABADFSD",
1222*0e209d39SAndroid Build Coastguard Worker         "123-ZABADFSD",
1223*0e209d39SAndroid Build Coastguard Worker         "K2K-12345678",
1224*0e209d39SAndroid Build Coastguard Worker         "K2K-12345678-zzz",
1225*0e209d39SAndroid Build Coastguard Worker         // (sep attribute)+ (sep keyword)*
1226*0e209d39SAndroid Build Coastguard Worker         "K2K-12345678-zz",
1227*0e209d39SAndroid Build Coastguard Worker         "K2K-12345678-zz-0z",
1228*0e209d39SAndroid Build Coastguard Worker         "K2K-12345678-9z-AZ-abc",
1229*0e209d39SAndroid Build Coastguard Worker         "K2K-12345678-zz-9A-234",
1230*0e209d39SAndroid Build Coastguard Worker         "K2K-12345678-zk0-abc-efg-zz-9k-234",
1231*0e209d39SAndroid Build Coastguard Worker     };
1232*0e209d39SAndroid Build Coastguard Worker     for (int i = 0; i < UPRV_LENGTHOF(wellFormedExtensions); i++) {
1233*0e209d39SAndroid Build Coastguard Worker         const char* extension = wellFormedExtensions[i];
1234*0e209d39SAndroid Build Coastguard Worker         UErrorCode status = U_ZERO_ERROR;
1235*0e209d39SAndroid Build Coastguard Worker         ULocaleBuilder* bld = ulocbld_open();
1236*0e209d39SAndroid Build Coastguard Worker         ulocbld_setExtension(bld, 'u', extension, -1);
1237*0e209d39SAndroid Build Coastguard Worker         char buffer[ULOC_FULLNAME_CAPACITY];
1238*0e209d39SAndroid Build Coastguard Worker         ulocbld_buildLocaleID(bld, buffer, ULOC_FULLNAME_CAPACITY, &status);
1239*0e209d39SAndroid Build Coastguard Worker         if (U_FAILURE(status)) {
1240*0e209d39SAndroid Build Coastguard Worker             log_err("setExtension('u', \"%s\") got Error: %s\n",
1241*0e209d39SAndroid Build Coastguard Worker                   extension, u_errorName(status));
1242*0e209d39SAndroid Build Coastguard Worker         }
1243*0e209d39SAndroid Build Coastguard Worker         ulocbld_close(bld);
1244*0e209d39SAndroid Build Coastguard Worker     }
1245*0e209d39SAndroid Build Coastguard Worker }
1246*0e209d39SAndroid Build Coastguard Worker 
TestSetExtensionValidateUIllFormed(void)1247*0e209d39SAndroid Build Coastguard Worker static void TestSetExtensionValidateUIllFormed(void) {
1248*0e209d39SAndroid Build Coastguard Worker     static const char* illFormed[] = {
1249*0e209d39SAndroid Build Coastguard Worker         // bad key
1250*0e209d39SAndroid Build Coastguard Worker         "-",
1251*0e209d39SAndroid Build Coastguard Worker         "-ab",
1252*0e209d39SAndroid Build Coastguard Worker         "ab-",
1253*0e209d39SAndroid Build Coastguard Worker         "abc-",
1254*0e209d39SAndroid Build Coastguard Worker         "-abc",
1255*0e209d39SAndroid Build Coastguard Worker         "0",
1256*0e209d39SAndroid Build Coastguard Worker         "a",
1257*0e209d39SAndroid Build Coastguard Worker         "A0",
1258*0e209d39SAndroid Build Coastguard Worker         "z9",
1259*0e209d39SAndroid Build Coastguard Worker         "09",
1260*0e209d39SAndroid Build Coastguard Worker         "90",
1261*0e209d39SAndroid Build Coastguard Worker         // bad keyword
1262*0e209d39SAndroid Build Coastguard Worker         "AB-A0",
1263*0e209d39SAndroid Build Coastguard Worker         "AB-efg-A0",
1264*0e209d39SAndroid Build Coastguard Worker         "xy-123456789",
1265*0e209d39SAndroid Build Coastguard Worker         "AB-Aa-",
1266*0e209d39SAndroid Build Coastguard Worker         "AB-Aac-",
1267*0e209d39SAndroid Build Coastguard Worker         // bad attribute
1268*0e209d39SAndroid Build Coastguard Worker         "abcdefghi",
1269*0e209d39SAndroid Build Coastguard Worker         "abcdefgh-",
1270*0e209d39SAndroid Build Coastguard Worker         "abcdefgh-abcdefghi",
1271*0e209d39SAndroid Build Coastguard Worker         "abcdefgh-1",
1272*0e209d39SAndroid Build Coastguard Worker         "abcdefgh-a",
1273*0e209d39SAndroid Build Coastguard Worker         "abcdefgh-a2345678z",
1274*0e209d39SAndroid Build Coastguard Worker     };
1275*0e209d39SAndroid Build Coastguard Worker     for (int i = 0; i < UPRV_LENGTHOF(illFormed); i++) {
1276*0e209d39SAndroid Build Coastguard Worker         const char* ill = illFormed[i];
1277*0e209d39SAndroid Build Coastguard Worker         UErrorCode status = U_ZERO_ERROR;
1278*0e209d39SAndroid Build Coastguard Worker         ULocaleBuilder* bld = ulocbld_open();
1279*0e209d39SAndroid Build Coastguard Worker         ulocbld_setExtension(bld, 'u', ill, -1);
1280*0e209d39SAndroid Build Coastguard Worker         char buffer[ULOC_FULLNAME_CAPACITY];
1281*0e209d39SAndroid Build Coastguard Worker         ulocbld_buildLocaleID(bld, buffer, ULOC_FULLNAME_CAPACITY, &status);
1282*0e209d39SAndroid Build Coastguard Worker         if (status != U_ILLEGAL_ARGUMENT_ERROR) {
1283*0e209d39SAndroid Build Coastguard Worker             log_err("setExtension('u', \"%s\") should fail but has no Error\n",
1284*0e209d39SAndroid Build Coastguard Worker                   ill);
1285*0e209d39SAndroid Build Coastguard Worker         }
1286*0e209d39SAndroid Build Coastguard Worker         ulocbld_close(bld);
1287*0e209d39SAndroid Build Coastguard Worker     }
1288*0e209d39SAndroid Build Coastguard Worker }
1289*0e209d39SAndroid Build Coastguard Worker 
TestSetExtensionT(void)1290*0e209d39SAndroid Build Coastguard Worker static void TestSetExtensionT(void) {
1291*0e209d39SAndroid Build Coastguard Worker     ULocaleBuilder* bld = ulocbld_open();
1292*0e209d39SAndroid Build Coastguard Worker     ulocbld_setLanguage(bld, "fr", 2);
1293*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "fr",
1294*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setLanguage(\"fr\") got Error: %s\n");
1295*0e209d39SAndroid Build Coastguard Worker 
1296*0e209d39SAndroid Build Coastguard Worker     ulocbld_setExtension(bld, 'T', "zh", -1);
1297*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "fr-t-zh",
1298*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setExtension('T', \"zh\") got Error: %s\n");
1299*0e209d39SAndroid Build Coastguard Worker 
1300*0e209d39SAndroid Build Coastguard Worker     ulocbld_setExtension(bld, 't', "zh-Hant-TW-1234-A9-123-456ABCDE", -1);
1301*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "fr-t-zh-hant-tw-1234-a9-123-456abcde",
1302*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setExtension('t', \"zh-Hant-TW-1234-A9-123-456ABCDE\") got Error: %s\n");
1303*0e209d39SAndroid Build Coastguard Worker 
1304*0e209d39SAndroid Build Coastguard Worker     ulocbld_setExtension(bld, 'T', "a9-123", -1);
1305*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "fr-t-a9-123",
1306*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setExtension('T', \"a9-123\") got Error: %s\n");
1307*0e209d39SAndroid Build Coastguard Worker 
1308*0e209d39SAndroid Build Coastguard Worker     ulocbld_setRegion(bld, "MX###", 2);
1309*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "fr-MX-t-a9-123",
1310*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setRegion(\"MX\") got Error: %s\n");
1311*0e209d39SAndroid Build Coastguard Worker 
1312*0e209d39SAndroid Build Coastguard Worker     ulocbld_setScript(bld, "Hans##", 4);
1313*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "fr-Hans-MX-t-a9-123",
1314*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setScript(\"Hans\") got Error: %s\n");
1315*0e209d39SAndroid Build Coastguard Worker 
1316*0e209d39SAndroid Build Coastguard Worker     ulocbld_setVariant(bld, "9abc-abcde1234", 10 );
1317*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "fr-Hans-MX-9abc-abcde-t-a9-123",
1318*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setVariant(\"9abc-abcde\") got Error: %s\n");
1319*0e209d39SAndroid Build Coastguard Worker 
1320*0e209d39SAndroid Build Coastguard Worker     ulocbld_setExtension(bld, 'T', "", 0);
1321*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "fr-Hans-MX-9abc-abcde",
1322*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setExtension('T', \"\") got Error: %s\n");
1323*0e209d39SAndroid Build Coastguard Worker 
1324*0e209d39SAndroid Build Coastguard Worker     ulocbld_close(bld);
1325*0e209d39SAndroid Build Coastguard Worker }
1326*0e209d39SAndroid Build Coastguard Worker 
TestSetExtensionValidateTWellFormed(void)1327*0e209d39SAndroid Build Coastguard Worker static void TestSetExtensionValidateTWellFormed(void) {
1328*0e209d39SAndroid Build Coastguard Worker     // ((sep tlang (sep tfield)*) | (sep tfield)+)
1329*0e209d39SAndroid Build Coastguard Worker     static const char* wellFormedExtensions[] = {
1330*0e209d39SAndroid Build Coastguard Worker         // tlang
1331*0e209d39SAndroid Build Coastguard Worker         //  tlang = unicode_language_subtag (sep unicode_script_subtag)?
1332*0e209d39SAndroid Build Coastguard Worker         //          (sep unicode_region_subtag)?  (sep unicode_variant_subtag)* ;
1333*0e209d39SAndroid Build Coastguard Worker         // unicode_language_subtag
1334*0e209d39SAndroid Build Coastguard Worker         "en",
1335*0e209d39SAndroid Build Coastguard Worker         "abc",
1336*0e209d39SAndroid Build Coastguard Worker         "abcde",
1337*0e209d39SAndroid Build Coastguard Worker         "ABCDEFGH",
1338*0e209d39SAndroid Build Coastguard Worker         // unicode_language_subtag sep unicode_script_subtag
1339*0e209d39SAndroid Build Coastguard Worker         "en-latn",
1340*0e209d39SAndroid Build Coastguard Worker         "abc-arab",
1341*0e209d39SAndroid Build Coastguard Worker         "ABCDEFGH-Thai",
1342*0e209d39SAndroid Build Coastguard Worker         // unicode_language_subtag sep unicode_script_subtag sep unicode_region_subtag
1343*0e209d39SAndroid Build Coastguard Worker         "en-latn-ME",
1344*0e209d39SAndroid Build Coastguard Worker         "abc-arab-RU",
1345*0e209d39SAndroid Build Coastguard Worker         "ABCDEFGH-Thai-TH",
1346*0e209d39SAndroid Build Coastguard Worker         "en-latn-409",
1347*0e209d39SAndroid Build Coastguard Worker         "abc-arab-123",
1348*0e209d39SAndroid Build Coastguard Worker         "ABCDEFGH-Thai-456",
1349*0e209d39SAndroid Build Coastguard Worker         // unicode_language_subtag sep unicode_region_subtag
1350*0e209d39SAndroid Build Coastguard Worker         "en-ME",
1351*0e209d39SAndroid Build Coastguard Worker         "abc-RU",
1352*0e209d39SAndroid Build Coastguard Worker         "ABCDEFGH-TH",
1353*0e209d39SAndroid Build Coastguard Worker         "en-409",
1354*0e209d39SAndroid Build Coastguard Worker         "abc-123",
1355*0e209d39SAndroid Build Coastguard Worker         "ABCDEFGH-456",
1356*0e209d39SAndroid Build Coastguard Worker         // unicode_language_subtag sep unicode_script_subtag sep unicode_region_subtag
1357*0e209d39SAndroid Build Coastguard Worker         // sep (sep unicode_variant_subtag)*
1358*0e209d39SAndroid Build Coastguard Worker         "en-latn-ME-abcde",
1359*0e209d39SAndroid Build Coastguard Worker         "abc-arab-RU-3abc-abcdef",
1360*0e209d39SAndroid Build Coastguard Worker         "ABCDEFGH-Thai-TH-ADSFS-9xyz-abcdef",
1361*0e209d39SAndroid Build Coastguard Worker         "en-latn-409-xafsa",
1362*0e209d39SAndroid Build Coastguard Worker         "abc-arab-123-ADASDF",
1363*0e209d39SAndroid Build Coastguard Worker         "ABCDEFGH-Thai-456-9sdf-ADASFAS",
1364*0e209d39SAndroid Build Coastguard Worker         // (sep tfield)+
1365*0e209d39SAndroid Build Coastguard Worker         "A0-abcde",
1366*0e209d39SAndroid Build Coastguard Worker         "z9-abcde123",
1367*0e209d39SAndroid Build Coastguard Worker         "z9-abcde123-a1-abcde",
1368*0e209d39SAndroid Build Coastguard Worker         // tlang (sep tfield)*
1369*0e209d39SAndroid Build Coastguard Worker         "fr-A0-abcde",
1370*0e209d39SAndroid Build Coastguard Worker         "fr-FR-A0-abcde",
1371*0e209d39SAndroid Build Coastguard Worker         "fr-123-z9-abcde123-a1-abcde",
1372*0e209d39SAndroid Build Coastguard Worker         "fr-Latn-FR-z9-abcde123-a1-abcde",
1373*0e209d39SAndroid Build Coastguard Worker         "gab-Thai-TH-abcde-z9-abcde123-a1-abcde",
1374*0e209d39SAndroid Build Coastguard Worker         "gab-Thai-TH-0bde-z9-abcde123-a1-abcde",
1375*0e209d39SAndroid Build Coastguard Worker     };
1376*0e209d39SAndroid Build Coastguard Worker     ULocaleBuilder* bld = ulocbld_open();
1377*0e209d39SAndroid Build Coastguard Worker     for (int i = 0; i < UPRV_LENGTHOF(wellFormedExtensions); i++) {
1378*0e209d39SAndroid Build Coastguard Worker         ulocbld_clear(bld);
1379*0e209d39SAndroid Build Coastguard Worker         const char* extension = wellFormedExtensions[i];
1380*0e209d39SAndroid Build Coastguard Worker         ulocbld_setExtension(bld, 't', extension, -1);
1381*0e209d39SAndroid Build Coastguard Worker         UErrorCode status = U_ZERO_ERROR;
1382*0e209d39SAndroid Build Coastguard Worker         if (ulocbld_copyErrorTo(bld, &status)) {
1383*0e209d39SAndroid Build Coastguard Worker             log_err("ulocbld_setExtension('t', \"%s\") got Error: %s\n",
1384*0e209d39SAndroid Build Coastguard Worker                   extension, u_errorName(status));
1385*0e209d39SAndroid Build Coastguard Worker         }
1386*0e209d39SAndroid Build Coastguard Worker     }
1387*0e209d39SAndroid Build Coastguard Worker     ulocbld_close(bld);
1388*0e209d39SAndroid Build Coastguard Worker }
1389*0e209d39SAndroid Build Coastguard Worker 
TestSetExtensionValidateTIllFormed(void)1390*0e209d39SAndroid Build Coastguard Worker static void TestSetExtensionValidateTIllFormed(void) {
1391*0e209d39SAndroid Build Coastguard Worker     static const char* illFormed[] = {
1392*0e209d39SAndroid Build Coastguard Worker         "a",
1393*0e209d39SAndroid Build Coastguard Worker         "a-",
1394*0e209d39SAndroid Build Coastguard Worker         "0",
1395*0e209d39SAndroid Build Coastguard Worker         "9-",
1396*0e209d39SAndroid Build Coastguard Worker         "-9",
1397*0e209d39SAndroid Build Coastguard Worker         "-z",
1398*0e209d39SAndroid Build Coastguard Worker         "Latn",
1399*0e209d39SAndroid Build Coastguard Worker         "Latn-",
1400*0e209d39SAndroid Build Coastguard Worker         "en-",
1401*0e209d39SAndroid Build Coastguard Worker         "nob-",
1402*0e209d39SAndroid Build Coastguard Worker         "-z9",
1403*0e209d39SAndroid Build Coastguard Worker         "a3",
1404*0e209d39SAndroid Build Coastguard Worker         "a3-",
1405*0e209d39SAndroid Build Coastguard Worker         "3a",
1406*0e209d39SAndroid Build Coastguard Worker         "0z-",
1407*0e209d39SAndroid Build Coastguard Worker         "en-123-a1",
1408*0e209d39SAndroid Build Coastguard Worker         "en-TH-a1",
1409*0e209d39SAndroid Build Coastguard Worker         "gab-TH-a1",
1410*0e209d39SAndroid Build Coastguard Worker         "gab-Thai-a1",
1411*0e209d39SAndroid Build Coastguard Worker         "gab-Thai-TH-a1",
1412*0e209d39SAndroid Build Coastguard Worker         "gab-Thai-TH-0bde-a1",
1413*0e209d39SAndroid Build Coastguard Worker         "gab-Thai-TH-0bde-3b",
1414*0e209d39SAndroid Build Coastguard Worker         "gab-Thai-TH-0bde-z9-a1",
1415*0e209d39SAndroid Build Coastguard Worker         "gab-Thai-TH-0bde-z9-3b",
1416*0e209d39SAndroid Build Coastguard Worker         "gab-Thai-TH-0bde-z9-abcde123-3b",
1417*0e209d39SAndroid Build Coastguard Worker         "gab-Thai-TH-0bde-z9-abcde123-ab",
1418*0e209d39SAndroid Build Coastguard Worker         "gab-Thai-TH-0bde-z9-abcde123-ab",
1419*0e209d39SAndroid Build Coastguard Worker         "gab-Thai-TH-0bde-z9-abcde123-a1",
1420*0e209d39SAndroid Build Coastguard Worker         "gab-Thai-TH-0bde-z9-abcde123-a1-",
1421*0e209d39SAndroid Build Coastguard Worker         "gab-Thai-TH-0bde-z9-abcde123-a1-a",
1422*0e209d39SAndroid Build Coastguard Worker         "gab-Thai-TH-0bde-z9-abcde123-a1-ab",
1423*0e209d39SAndroid Build Coastguard Worker         // ICU-21408
1424*0e209d39SAndroid Build Coastguard Worker         "root",
1425*0e209d39SAndroid Build Coastguard Worker     };
1426*0e209d39SAndroid Build Coastguard Worker     ULocaleBuilder* bld = ulocbld_open();
1427*0e209d39SAndroid Build Coastguard Worker     for (int i = 0; i < UPRV_LENGTHOF(illFormed); i++) {
1428*0e209d39SAndroid Build Coastguard Worker         ulocbld_clear(bld);
1429*0e209d39SAndroid Build Coastguard Worker         const char* ill = illFormed[i];
1430*0e209d39SAndroid Build Coastguard Worker         UErrorCode status = U_ZERO_ERROR;
1431*0e209d39SAndroid Build Coastguard Worker         ulocbld_setExtension(bld, 't', ill, -1);
1432*0e209d39SAndroid Build Coastguard Worker         if (!ulocbld_copyErrorTo(bld, &status) || status != U_ILLEGAL_ARGUMENT_ERROR) {
1433*0e209d39SAndroid Build Coastguard Worker             log_err("setExtension('t', \"%s\") should fail but has no Error\n",
1434*0e209d39SAndroid Build Coastguard Worker                   ill);
1435*0e209d39SAndroid Build Coastguard Worker         }
1436*0e209d39SAndroid Build Coastguard Worker     }
1437*0e209d39SAndroid Build Coastguard Worker     ulocbld_close(bld);
1438*0e209d39SAndroid Build Coastguard Worker }
1439*0e209d39SAndroid Build Coastguard Worker 
TestSetExtensionPU(void)1440*0e209d39SAndroid Build Coastguard Worker static void TestSetExtensionPU(void) {
1441*0e209d39SAndroid Build Coastguard Worker     ULocaleBuilder* bld = ulocbld_open();
1442*0e209d39SAndroid Build Coastguard Worker     ulocbld_setLanguage(bld, "ar123", 2);
1443*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "ar",
1444*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setLanguage(\"ar\") got Error: %s\n");
1445*0e209d39SAndroid Build Coastguard Worker 
1446*0e209d39SAndroid Build Coastguard Worker     ulocbld_setExtension(bld, 'X', "a-b-c-d-e12345", 9);
1447*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "ar-x-a-b-c-d-e",
1448*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setExtension('X', \"a-b-c-d-e\") got Error: %s\n");
1449*0e209d39SAndroid Build Coastguard Worker 
1450*0e209d39SAndroid Build Coastguard Worker     ulocbld_setExtension(bld, 'x', "0-1-2-3", -1);
1451*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "ar-x-0-1-2-3",
1452*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setExtension('x', \"0-1-2-3\") got Error: %s\n");
1453*0e209d39SAndroid Build Coastguard Worker 
1454*0e209d39SAndroid Build Coastguard Worker     ulocbld_setExtension(bld, 'X', "0-12345678-x-x", -1);
1455*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "ar-x-0-12345678-x-x",
1456*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setExtension('x', \"ar-x-0-12345678-x-x\") got Error: %s\n");
1457*0e209d39SAndroid Build Coastguard Worker 
1458*0e209d39SAndroid Build Coastguard Worker     ulocbld_setRegion(bld, "TH123", 2);
1459*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "ar-TH-x-0-12345678-x-x",
1460*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setRegion(\"TH\") got Error: %s\n");
1461*0e209d39SAndroid Build Coastguard Worker 
1462*0e209d39SAndroid Build Coastguard Worker     ulocbld_setExtension(bld, 'X', "", -1);
1463*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "ar-TH",
1464*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setExtension(\"X\") got Error: %s\n");
1465*0e209d39SAndroid Build Coastguard Worker     ulocbld_close(bld);
1466*0e209d39SAndroid Build Coastguard Worker }
1467*0e209d39SAndroid Build Coastguard Worker 
TestSetExtensionValidatePUWellFormed(void)1468*0e209d39SAndroid Build Coastguard Worker static void TestSetExtensionValidatePUWellFormed(void) {
1469*0e209d39SAndroid Build Coastguard Worker     // ((sep tlang (sep tfield)*) | (sep tfield)+)
1470*0e209d39SAndroid Build Coastguard Worker     static const char* wellFormedExtensions[] = {
1471*0e209d39SAndroid Build Coastguard Worker         "a",  // Short subtag
1472*0e209d39SAndroid Build Coastguard Worker         "z",  // Short subtag
1473*0e209d39SAndroid Build Coastguard Worker         "0",  // Short subtag, digit
1474*0e209d39SAndroid Build Coastguard Worker         "9",  // Short subtag, digit
1475*0e209d39SAndroid Build Coastguard Worker         "a-0",  // Two short subtag, alpha and digit
1476*0e209d39SAndroid Build Coastguard Worker         "9-z",  // Two short subtag, digit and alpha
1477*0e209d39SAndroid Build Coastguard Worker         "ab",
1478*0e209d39SAndroid Build Coastguard Worker         "abc",
1479*0e209d39SAndroid Build Coastguard Worker         "abcefghi",  // Long subtag
1480*0e209d39SAndroid Build Coastguard Worker         "87654321",
1481*0e209d39SAndroid Build Coastguard Worker         "01",
1482*0e209d39SAndroid Build Coastguard Worker         "234",
1483*0e209d39SAndroid Build Coastguard Worker         "0a-ab-87654321",  // Three subtags
1484*0e209d39SAndroid Build Coastguard Worker         "87654321-ab-00-3A",  // Four subtabs
1485*0e209d39SAndroid Build Coastguard Worker         "a-9-87654321",  // Three subtags with short and long subtags
1486*0e209d39SAndroid Build Coastguard Worker         "87654321-ab-0-3A",
1487*0e209d39SAndroid Build Coastguard Worker     };
1488*0e209d39SAndroid Build Coastguard Worker     ULocaleBuilder* bld = ulocbld_open();
1489*0e209d39SAndroid Build Coastguard Worker     for (int i = 0; i < UPRV_LENGTHOF(wellFormedExtensions); i++) {
1490*0e209d39SAndroid Build Coastguard Worker         ulocbld_clear(bld);
1491*0e209d39SAndroid Build Coastguard Worker         const char* extension = wellFormedExtensions[i];
1492*0e209d39SAndroid Build Coastguard Worker         UErrorCode status = U_ZERO_ERROR;
1493*0e209d39SAndroid Build Coastguard Worker         ulocbld_setExtension(bld, 'x', extension, -1);
1494*0e209d39SAndroid Build Coastguard Worker         if (ulocbld_copyErrorTo(bld, &status) || U_FAILURE(status)) {
1495*0e209d39SAndroid Build Coastguard Worker             log_err("setExtension('x', \"%s\") got Error: %s\n",
1496*0e209d39SAndroid Build Coastguard Worker                   extension, u_errorName(status));
1497*0e209d39SAndroid Build Coastguard Worker         }
1498*0e209d39SAndroid Build Coastguard Worker     }
1499*0e209d39SAndroid Build Coastguard Worker     ulocbld_close(bld);
1500*0e209d39SAndroid Build Coastguard Worker }
1501*0e209d39SAndroid Build Coastguard Worker 
TestSetExtensionValidatePUIllFormed(void)1502*0e209d39SAndroid Build Coastguard Worker static void TestSetExtensionValidatePUIllFormed(void) {
1503*0e209d39SAndroid Build Coastguard Worker     static const char* illFormed[] = {
1504*0e209d39SAndroid Build Coastguard Worker         "123456789",  // Too long
1505*0e209d39SAndroid Build Coastguard Worker         "abcdefghi",  // Too long
1506*0e209d39SAndroid Build Coastguard Worker         "ab-123456789",  // Second subtag too long
1507*0e209d39SAndroid Build Coastguard Worker         "abcdefghi-12",  // First subtag too long
1508*0e209d39SAndroid Build Coastguard Worker         "a-ab-987654321",  // Third subtag too long
1509*0e209d39SAndroid Build Coastguard Worker         "987654321-a-0-3",  // First subtag too long
1510*0e209d39SAndroid Build Coastguard Worker     };
1511*0e209d39SAndroid Build Coastguard Worker     ULocaleBuilder* bld = ulocbld_open();
1512*0e209d39SAndroid Build Coastguard Worker     for (int i = 0; i < UPRV_LENGTHOF(illFormed); i++) {
1513*0e209d39SAndroid Build Coastguard Worker         const char* ill = illFormed[i];
1514*0e209d39SAndroid Build Coastguard Worker         ulocbld_clear(bld);
1515*0e209d39SAndroid Build Coastguard Worker         ulocbld_setExtension(bld, 'x', ill, -1);
1516*0e209d39SAndroid Build Coastguard Worker         UErrorCode status = U_ZERO_ERROR;
1517*0e209d39SAndroid Build Coastguard Worker         if (!ulocbld_copyErrorTo(bld, &status) ||status != U_ILLEGAL_ARGUMENT_ERROR) {
1518*0e209d39SAndroid Build Coastguard Worker             log_err("ulocbld_setExtension('x', \"%s\") should fail but has no Error\n",
1519*0e209d39SAndroid Build Coastguard Worker                   ill);
1520*0e209d39SAndroid Build Coastguard Worker         }
1521*0e209d39SAndroid Build Coastguard Worker     }
1522*0e209d39SAndroid Build Coastguard Worker     ulocbld_close(bld);
1523*0e209d39SAndroid Build Coastguard Worker }
1524*0e209d39SAndroid Build Coastguard Worker 
TestSetExtensionOthers(void)1525*0e209d39SAndroid Build Coastguard Worker static void TestSetExtensionOthers(void) {
1526*0e209d39SAndroid Build Coastguard Worker     ULocaleBuilder* bld = ulocbld_open();
1527*0e209d39SAndroid Build Coastguard Worker     ulocbld_setLanguage(bld, "fr", -1);
1528*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "fr",
1529*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setLanguage(\"fr\") got Error: %s\n");
1530*0e209d39SAndroid Build Coastguard Worker 
1531*0e209d39SAndroid Build Coastguard Worker     ulocbld_setExtension(bld, 'Z', "ab1234", 2);
1532*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "fr-z-ab",
1533*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setExtension('Z', \"ab\") got Error: %s\n");
1534*0e209d39SAndroid Build Coastguard Worker 
1535*0e209d39SAndroid Build Coastguard Worker     ulocbld_setExtension(bld, '0', "xyz12345-abcdefg", -1);
1536*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "fr-0-xyz12345-abcdefg-z-ab",
1537*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setExtension('0', \"xyz12345-abcdefg\") got Error: %s\n");
1538*0e209d39SAndroid Build Coastguard Worker 
1539*0e209d39SAndroid Build Coastguard Worker     ulocbld_setExtension(bld, 'a', "01-12345678-ABcdef", -1);
1540*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "fr-0-xyz12345-abcdefg-a-01-12345678-abcdef-z-ab",
1541*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setExtension('a', \"01-12345678-ABcdef\") got Error: %s\n");
1542*0e209d39SAndroid Build Coastguard Worker 
1543*0e209d39SAndroid Build Coastguard Worker     ulocbld_setRegion(bld, "TH1234", 2);
1544*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "fr-TH-0-xyz12345-abcdefg-a-01-12345678-abcdef-z-ab",
1545*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setRegion(\"TH\") got Error: %s\n");
1546*0e209d39SAndroid Build Coastguard Worker 
1547*0e209d39SAndroid Build Coastguard Worker     ulocbld_setScript(bld, "Arab", -1);
1548*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "fr-Arab-TH-0-xyz12345-abcdefg-a-01-12345678-abcdef-z-ab",
1549*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setRegion(\"Arab\") got Error: %s\n");
1550*0e209d39SAndroid Build Coastguard Worker 
1551*0e209d39SAndroid Build Coastguard Worker     ulocbld_setExtension(bld, 'A', "97", 2);
1552*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "fr-Arab-TH-0-xyz12345-abcdefg-a-97-z-ab",
1553*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setExtension('a', \"97\") got Error: %s\n");
1554*0e209d39SAndroid Build Coastguard Worker 
1555*0e209d39SAndroid Build Coastguard Worker     ulocbld_setExtension(bld, 'a', "", 0);
1556*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "fr-Arab-TH-0-xyz12345-abcdefg-z-ab",
1557*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setExtension('a', \"\") got Error: %s\n");
1558*0e209d39SAndroid Build Coastguard Worker 
1559*0e209d39SAndroid Build Coastguard Worker     ulocbld_setExtension(bld, '0', "", -1);
1560*0e209d39SAndroid Build Coastguard Worker     Verify(bld, "fr-Arab-TH-z-ab",
1561*0e209d39SAndroid Build Coastguard Worker            "ulocbld_setExtension('0', \"\") got Error: %s\n");
1562*0e209d39SAndroid Build Coastguard Worker     ulocbld_close(bld);
1563*0e209d39SAndroid Build Coastguard Worker }
1564*0e209d39SAndroid Build Coastguard Worker 
TestSetExtensionValidateOthersWellFormed(void)1565*0e209d39SAndroid Build Coastguard Worker static void TestSetExtensionValidateOthersWellFormed(void) {
1566*0e209d39SAndroid Build Coastguard Worker     static const char* wellFormedExtensions[] = {
1567*0e209d39SAndroid Build Coastguard Worker         "ab",
1568*0e209d39SAndroid Build Coastguard Worker         "abc",
1569*0e209d39SAndroid Build Coastguard Worker         "abcefghi",
1570*0e209d39SAndroid Build Coastguard Worker         "01",
1571*0e209d39SAndroid Build Coastguard Worker         "234",
1572*0e209d39SAndroid Build Coastguard Worker         "87654321",
1573*0e209d39SAndroid Build Coastguard Worker         "0a-ab-87654321",
1574*0e209d39SAndroid Build Coastguard Worker         "87654321-ab-00-3A",
1575*0e209d39SAndroid Build Coastguard Worker     };
1576*0e209d39SAndroid Build Coastguard Worker 
1577*0e209d39SAndroid Build Coastguard Worker     const char * aToZ = "abcdefghijklmnopqrstuvwxyz";
1578*0e209d39SAndroid Build Coastguard Worker     const int32_t aToZLen = strlen(aToZ);
1579*0e209d39SAndroid Build Coastguard Worker     ULocaleBuilder* bld = ulocbld_open();
1580*0e209d39SAndroid Build Coastguard Worker     for (int i = 0; i < UPRV_LENGTHOF(wellFormedExtensions); i++) {
1581*0e209d39SAndroid Build Coastguard Worker         const char* extension = wellFormedExtensions[i];
1582*0e209d39SAndroid Build Coastguard Worker         ulocbld_clear(bld);
1583*0e209d39SAndroid Build Coastguard Worker         char ch = aToZ[i];
1584*0e209d39SAndroid Build Coastguard Worker         i = (i + 1) % aToZLen;
1585*0e209d39SAndroid Build Coastguard Worker         UErrorCode status = U_ZERO_ERROR;
1586*0e209d39SAndroid Build Coastguard Worker         ulocbld_setExtension(bld, ch, extension, -1);
1587*0e209d39SAndroid Build Coastguard Worker         if (ulocbld_copyErrorTo(bld, &status) || U_FAILURE(status)) {
1588*0e209d39SAndroid Build Coastguard Worker             log_err("ulocbld_setExtension('%c', \"%s\") got Error: %s\n",
1589*0e209d39SAndroid Build Coastguard Worker                   ch, extension, u_errorName(status));
1590*0e209d39SAndroid Build Coastguard Worker         }
1591*0e209d39SAndroid Build Coastguard Worker     }
1592*0e209d39SAndroid Build Coastguard Worker 
1593*0e209d39SAndroid Build Coastguard Worker     const char* someChars =
1594*0e209d39SAndroid Build Coastguard Worker         "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()-_=+;:,.<>?";
1595*0e209d39SAndroid Build Coastguard Worker     const int32_t someCharsLen = strlen(someChars);
1596*0e209d39SAndroid Build Coastguard Worker     for (int32_t i = 0; i < someCharsLen; i++) {
1597*0e209d39SAndroid Build Coastguard Worker         char ch = someChars[i];
1598*0e209d39SAndroid Build Coastguard Worker         UErrorCode status = U_ZERO_ERROR;
1599*0e209d39SAndroid Build Coastguard Worker         ulocbld_clear(bld);
1600*0e209d39SAndroid Build Coastguard Worker         ulocbld_setExtension(bld, ch, wellFormedExtensions[ch % UPRV_LENGTHOF(wellFormedExtensions)], -1);
1601*0e209d39SAndroid Build Coastguard Worker         if (uprv_isASCIILetter(ch) || ('0' <= ch && ch <= '9')) {
1602*0e209d39SAndroid Build Coastguard Worker             if (ch != 't' && ch != 'T' && ch != 'u' && ch != 'U' && ch != 'x' && ch != 'X') {
1603*0e209d39SAndroid Build Coastguard Worker                 if (ulocbld_copyErrorTo(bld, &status) || U_FAILURE(status)) {
1604*0e209d39SAndroid Build Coastguard Worker                     log_err("setExtension('%c', \"%s\") got Error: %s\n",
1605*0e209d39SAndroid Build Coastguard Worker                           ch, wellFormedExtensions[ch % UPRV_LENGTHOF(wellFormedExtensions)], u_errorName(status));
1606*0e209d39SAndroid Build Coastguard Worker                 }
1607*0e209d39SAndroid Build Coastguard Worker             }
1608*0e209d39SAndroid Build Coastguard Worker         } else {
1609*0e209d39SAndroid Build Coastguard Worker             if (!ulocbld_copyErrorTo(bld, &status) || status != U_ILLEGAL_ARGUMENT_ERROR) {
1610*0e209d39SAndroid Build Coastguard Worker                 log_err("setExtension('%c', \"%s\") should fail but has no Error\n",
1611*0e209d39SAndroid Build Coastguard Worker                       ch, wellFormedExtensions[ch % UPRV_LENGTHOF(wellFormedExtensions)]);
1612*0e209d39SAndroid Build Coastguard Worker             }
1613*0e209d39SAndroid Build Coastguard Worker         }
1614*0e209d39SAndroid Build Coastguard Worker 
1615*0e209d39SAndroid Build Coastguard Worker     }
1616*0e209d39SAndroid Build Coastguard Worker     ulocbld_close(bld);
1617*0e209d39SAndroid Build Coastguard Worker }
1618*0e209d39SAndroid Build Coastguard Worker 
TestSetExtensionValidateOthersIllFormed(void)1619*0e209d39SAndroid Build Coastguard Worker static void TestSetExtensionValidateOthersIllFormed(void) {
1620*0e209d39SAndroid Build Coastguard Worker     static const char* illFormed[] = {
1621*0e209d39SAndroid Build Coastguard Worker         "0",  // Too short
1622*0e209d39SAndroid Build Coastguard Worker         "a",  // Too short
1623*0e209d39SAndroid Build Coastguard Worker         "123456789",  // Too long
1624*0e209d39SAndroid Build Coastguard Worker         "abcdefghi",  // Too long
1625*0e209d39SAndroid Build Coastguard Worker         "ab-123456789",  // Second subtag too long
1626*0e209d39SAndroid Build Coastguard Worker         "abcdefghi-12",  // First subtag too long
1627*0e209d39SAndroid Build Coastguard Worker         "a-ab-87654321",  // Third subtag too long
1628*0e209d39SAndroid Build Coastguard Worker         "87654321-a-0-3",  // First subtag too long
1629*0e209d39SAndroid Build Coastguard Worker     };
1630*0e209d39SAndroid Build Coastguard Worker     const char * aToZ = "abcdefghijklmnopqrstuvwxyz";
1631*0e209d39SAndroid Build Coastguard Worker     const int32_t aToZLen = strlen(aToZ);
1632*0e209d39SAndroid Build Coastguard Worker     ULocaleBuilder* bld = ulocbld_open();
1633*0e209d39SAndroid Build Coastguard Worker     for (int i = 0; i < UPRV_LENGTHOF(illFormed); i++) {
1634*0e209d39SAndroid Build Coastguard Worker         const char* ill = illFormed[i];
1635*0e209d39SAndroid Build Coastguard Worker         char ch = aToZ[i];
1636*0e209d39SAndroid Build Coastguard Worker         ulocbld_clear(bld);
1637*0e209d39SAndroid Build Coastguard Worker         i = (i + 1) % aToZLen;
1638*0e209d39SAndroid Build Coastguard Worker         UErrorCode status = U_ZERO_ERROR;
1639*0e209d39SAndroid Build Coastguard Worker         ulocbld_setExtension(bld, ch, ill, -1);
1640*0e209d39SAndroid Build Coastguard Worker         if (!ulocbld_copyErrorTo(bld, &status) || status != U_ILLEGAL_ARGUMENT_ERROR) {
1641*0e209d39SAndroid Build Coastguard Worker             log_err("setExtension('%c', \"%s\") should fail but has no Error\n",
1642*0e209d39SAndroid Build Coastguard Worker                   ch, ill);
1643*0e209d39SAndroid Build Coastguard Worker         }
1644*0e209d39SAndroid Build Coastguard Worker     }
1645*0e209d39SAndroid Build Coastguard Worker     ulocbld_close(bld);
1646*0e209d39SAndroid Build Coastguard Worker }
1647*0e209d39SAndroid Build Coastguard Worker 
TestSetLocale(void)1648*0e209d39SAndroid Build Coastguard Worker static void TestSetLocale(void) {
1649*0e209d39SAndroid Build Coastguard Worker     ULocaleBuilder* bld1 = ulocbld_open();
1650*0e209d39SAndroid Build Coastguard Worker     ULocaleBuilder* bld2 = ulocbld_open();
1651*0e209d39SAndroid Build Coastguard Worker     UErrorCode status = U_ZERO_ERROR;
1652*0e209d39SAndroid Build Coastguard Worker 
1653*0e209d39SAndroid Build Coastguard Worker     ulocbld_setLanguage(bld1, "en", -1);
1654*0e209d39SAndroid Build Coastguard Worker     ulocbld_setScript(bld1, "Latn", -1);
1655*0e209d39SAndroid Build Coastguard Worker     ulocbld_setRegion(bld1, "MX", -1);
1656*0e209d39SAndroid Build Coastguard Worker     ulocbld_setVariant(bld1, "3456-abcde", -1);
1657*0e209d39SAndroid Build Coastguard Worker     ulocbld_addUnicodeLocaleAttribute(bld1, "456", -1);
1658*0e209d39SAndroid Build Coastguard Worker     ulocbld_addUnicodeLocaleAttribute(bld1, "123", -1);
1659*0e209d39SAndroid Build Coastguard Worker     ulocbld_setUnicodeLocaleKeyword(bld1, "nu", -1, "thai", -1);
1660*0e209d39SAndroid Build Coastguard Worker     ulocbld_setUnicodeLocaleKeyword(bld1, "co", -1, "stroke", -1);
1661*0e209d39SAndroid Build Coastguard Worker     ulocbld_setUnicodeLocaleKeyword(bld1, "ca", -1, "chinese", -1);
1662*0e209d39SAndroid Build Coastguard Worker     char locale1[ULOC_FULLNAME_CAPACITY];
1663*0e209d39SAndroid Build Coastguard Worker     ulocbld_buildLocaleID(bld1, locale1, ULOC_FULLNAME_CAPACITY, &status);
1664*0e209d39SAndroid Build Coastguard Worker 
1665*0e209d39SAndroid Build Coastguard Worker     if (U_FAILURE(status)) {
1666*0e209d39SAndroid Build Coastguard Worker         log_err("build got Error: %s\n", u_errorName(status));
1667*0e209d39SAndroid Build Coastguard Worker     }
1668*0e209d39SAndroid Build Coastguard Worker     ulocbld_setLocale(bld2, locale1, -1);
1669*0e209d39SAndroid Build Coastguard Worker     char locale2[ULOC_FULLNAME_CAPACITY];
1670*0e209d39SAndroid Build Coastguard Worker     ulocbld_buildLocaleID(bld2, locale2, ULOC_FULLNAME_CAPACITY, &status);
1671*0e209d39SAndroid Build Coastguard Worker     if (U_FAILURE(status)) {
1672*0e209d39SAndroid Build Coastguard Worker         log_err("build got Error: %s\n", u_errorName(status));
1673*0e209d39SAndroid Build Coastguard Worker     }
1674*0e209d39SAndroid Build Coastguard Worker     if (strcmp(locale1, locale2) != 0) {
1675*0e209d39SAndroid Build Coastguard Worker         log_err("Two locales should be the same, but one is '%s' and the other is '%s'",
1676*0e209d39SAndroid Build Coastguard Worker               locale1, locale2);
1677*0e209d39SAndroid Build Coastguard Worker     }
1678*0e209d39SAndroid Build Coastguard Worker     ulocbld_close(bld1);
1679*0e209d39SAndroid Build Coastguard Worker     ulocbld_close(bld2);
1680*0e209d39SAndroid Build Coastguard Worker }
1681*0e209d39SAndroid Build Coastguard Worker 
TestBuildULocale(void)1682*0e209d39SAndroid Build Coastguard Worker static void TestBuildULocale(void) {
1683*0e209d39SAndroid Build Coastguard Worker     ULocaleBuilder* bld1 = ulocbld_open();
1684*0e209d39SAndroid Build Coastguard Worker     UErrorCode status = U_ZERO_ERROR;
1685*0e209d39SAndroid Build Coastguard Worker 
1686*0e209d39SAndroid Build Coastguard Worker     ulocbld_setLanguage(bld1, "fr", -1);
1687*0e209d39SAndroid Build Coastguard Worker     ULocale* fr = ulocbld_buildULocale(bld1, &status);
1688*0e209d39SAndroid Build Coastguard Worker     if (assertSuccess(WHERE "ulocbld_buildULocale()", &status)) {
1689*0e209d39SAndroid Build Coastguard Worker         assertEquals(WHERE "ulocale_getLanguage()", "fr", ulocale_getLanguage(fr));
1690*0e209d39SAndroid Build Coastguard Worker     }
1691*0e209d39SAndroid Build Coastguard Worker 
1692*0e209d39SAndroid Build Coastguard Worker     ulocbld_setLanguage(bld1, "ar", -1);
1693*0e209d39SAndroid Build Coastguard Worker     ulocbld_setScript(bld1, "Arab", -1);
1694*0e209d39SAndroid Build Coastguard Worker     ulocbld_setRegion(bld1, "EG", -1);
1695*0e209d39SAndroid Build Coastguard Worker     ulocbld_setVariant(bld1, "3456-abcde", -1);
1696*0e209d39SAndroid Build Coastguard Worker     ulocbld_setUnicodeLocaleKeyword(bld1, "nu", -1, "thai", -1);
1697*0e209d39SAndroid Build Coastguard Worker     ulocbld_setUnicodeLocaleKeyword(bld1, "co", -1, "stroke", -1);
1698*0e209d39SAndroid Build Coastguard Worker     ulocbld_setUnicodeLocaleKeyword(bld1, "ca", -1, "chinese", -1);
1699*0e209d39SAndroid Build Coastguard Worker     ULocale* l = ulocbld_buildULocale(bld1, &status);
1700*0e209d39SAndroid Build Coastguard Worker 
1701*0e209d39SAndroid Build Coastguard Worker     if (assertSuccess(WHERE "ulocbld_buildULocale()", &status)) {
1702*0e209d39SAndroid Build Coastguard Worker         assertEquals(WHERE "ulocale_getLanguage()", "ar", ulocale_getLanguage(l));
1703*0e209d39SAndroid Build Coastguard Worker         assertEquals(WHERE "ulocale_getScript()", "Arab", ulocale_getScript(l));
1704*0e209d39SAndroid Build Coastguard Worker         assertEquals(WHERE "ulocale_getRegion()", "EG", ulocale_getRegion(l));
1705*0e209d39SAndroid Build Coastguard Worker         assertEquals(WHERE "ulocale_getVariant()", "3456_ABCDE", ulocale_getVariant(l));
1706*0e209d39SAndroid Build Coastguard Worker         char buf[ULOC_FULLNAME_CAPACITY];
1707*0e209d39SAndroid Build Coastguard Worker         assertIntEquals(WHERE "ulocale_getUnicodeKeywordValue(\"nu\")", 4,
1708*0e209d39SAndroid Build Coastguard Worker                      ulocale_getUnicodeKeywordValue(l, "nu", -1, buf, ULOC_FULLNAME_CAPACITY, &status));
1709*0e209d39SAndroid Build Coastguard Worker         if (assertSuccess(WHERE "ulocale_getUnicodeKeywordValue(\"nu\")", &status)) {
1710*0e209d39SAndroid Build Coastguard Worker             assertEquals(WHERE "ulocale_getUnicodeKeywordValue(\"nu\")", "thai", buf);
1711*0e209d39SAndroid Build Coastguard Worker         }
1712*0e209d39SAndroid Build Coastguard Worker 
1713*0e209d39SAndroid Build Coastguard Worker         status = U_ZERO_ERROR;
1714*0e209d39SAndroid Build Coastguard Worker         assertIntEquals(WHERE "ulocale_getUnicodeKeywordValue(\"co\")", 6,
1715*0e209d39SAndroid Build Coastguard Worker                      ulocale_getUnicodeKeywordValue(l, "co", -1, buf, ULOC_FULLNAME_CAPACITY, &status));
1716*0e209d39SAndroid Build Coastguard Worker         if (assertSuccess(WHERE "ulocale_getUnicodeKeywordValue(\"co\")", &status)) {
1717*0e209d39SAndroid Build Coastguard Worker             assertEquals(WHERE "ulocale_getUnicodeKeywordValue(\"co\")", "stroke", buf);
1718*0e209d39SAndroid Build Coastguard Worker         }
1719*0e209d39SAndroid Build Coastguard Worker 
1720*0e209d39SAndroid Build Coastguard Worker         status = U_ZERO_ERROR;
1721*0e209d39SAndroid Build Coastguard Worker         assertIntEquals(WHERE "ulocale_getUnicodeKeywordValue(\"ca\")", 7,
1722*0e209d39SAndroid Build Coastguard Worker                      ulocale_getUnicodeKeywordValue(l, "ca", -1, buf, ULOC_FULLNAME_CAPACITY, &status));
1723*0e209d39SAndroid Build Coastguard Worker         if (assertSuccess(WHERE "ulocale_getUnicodeKeywordValue(\"ca\")", &status)) {
1724*0e209d39SAndroid Build Coastguard Worker             assertEquals(WHERE "ulocale_getUnicodeKeywordValue(\"ca\")", "chinese", buf);
1725*0e209d39SAndroid Build Coastguard Worker         }
1726*0e209d39SAndroid Build Coastguard Worker         ulocale_close(l);
1727*0e209d39SAndroid Build Coastguard Worker     }
1728*0e209d39SAndroid Build Coastguard Worker     ulocbld_adoptULocale(bld1, fr);
1729*0e209d39SAndroid Build Coastguard Worker     char buf[ULOC_FULLNAME_CAPACITY];
1730*0e209d39SAndroid Build Coastguard Worker     ulocbld_buildLocaleID(bld1, buf, ULOC_FULLNAME_CAPACITY, &status);
1731*0e209d39SAndroid Build Coastguard Worker     if (assertSuccess(WHERE "ulocbld_buildULocale()", &status)) {
1732*0e209d39SAndroid Build Coastguard Worker         assertEquals(WHERE "ulocbld_buildULocale()", "fr", buf);
1733*0e209d39SAndroid Build Coastguard Worker     }
1734*0e209d39SAndroid Build Coastguard Worker     ulocbld_close(bld1);
1735*0e209d39SAndroid Build Coastguard Worker }
1736*0e209d39SAndroid Build Coastguard Worker 
1737*0e209d39SAndroid Build Coastguard Worker 
TestPosixCases(void)1738*0e209d39SAndroid Build Coastguard Worker static void TestPosixCases(void) {
1739*0e209d39SAndroid Build Coastguard Worker     UErrorCode status = U_ZERO_ERROR;
1740*0e209d39SAndroid Build Coastguard Worker     ULocaleBuilder* bld = ulocbld_open();
1741*0e209d39SAndroid Build Coastguard Worker     ulocbld_setLanguage(bld, "en", -1);
1742*0e209d39SAndroid Build Coastguard Worker     ulocbld_setRegion(bld, "MX", -1);
1743*0e209d39SAndroid Build Coastguard Worker     ulocbld_setScript(bld, "Arab", -1);
1744*0e209d39SAndroid Build Coastguard Worker     ulocbld_setUnicodeLocaleKeyword(bld, "nu", -1, "Thai", -1);
1745*0e209d39SAndroid Build Coastguard Worker     ulocbld_setExtension(bld, 'x', "1", -1);
1746*0e209d39SAndroid Build Coastguard Worker     // All of above should be cleared by the setLocale call.
1747*0e209d39SAndroid Build Coastguard Worker     const char* posix = "en_US_POSIX";
1748*0e209d39SAndroid Build Coastguard Worker     ulocbld_setLocale(bld, posix, -1);
1749*0e209d39SAndroid Build Coastguard Worker     char locale[ULOC_FULLNAME_CAPACITY];
1750*0e209d39SAndroid Build Coastguard Worker     ulocbld_buildLocaleID(bld, locale, ULOC_FULLNAME_CAPACITY, &status);
1751*0e209d39SAndroid Build Coastguard Worker     if (U_FAILURE(status)) {
1752*0e209d39SAndroid Build Coastguard Worker         log_err("build got Error: %s\n", u_errorName(status));
1753*0e209d39SAndroid Build Coastguard Worker     }
1754*0e209d39SAndroid Build Coastguard Worker     if (strcmp(posix, locale) != 0) {
1755*0e209d39SAndroid Build Coastguard Worker         log_err("The result locale should be the set as the setLocale %s but got %s\n",
1756*0e209d39SAndroid Build Coastguard Worker                 posix, locale);
1757*0e209d39SAndroid Build Coastguard Worker     }
1758*0e209d39SAndroid Build Coastguard Worker     ulocbld_close(bld);
1759*0e209d39SAndroid Build Coastguard Worker }
1760*0e209d39SAndroid Build Coastguard Worker 
1761*0e209d39SAndroid Build Coastguard Worker #define TESTCASE(name) addTest(root, &name, "tsutil/ulocbuildertst/" #name)
addLocaleBuilderTest(TestNode ** root)1762*0e209d39SAndroid Build Coastguard Worker void addLocaleBuilderTest(TestNode** root)
1763*0e209d39SAndroid Build Coastguard Worker {
1764*0e209d39SAndroid Build Coastguard Worker     TESTCASE(TestLocaleBuilder);
1765*0e209d39SAndroid Build Coastguard Worker     TESTCASE(TestLocaleBuilderBasic);
1766*0e209d39SAndroid Build Coastguard Worker     TESTCASE(TestLocaleBuilderBasicWithExtensionsOnDefaultLocale);
1767*0e209d39SAndroid Build Coastguard Worker     TESTCASE(TestSetLanguageWellFormed);
1768*0e209d39SAndroid Build Coastguard Worker     TESTCASE(TestSetLanguageIllFormed);
1769*0e209d39SAndroid Build Coastguard Worker     TESTCASE(TestSetScriptWellFormed);
1770*0e209d39SAndroid Build Coastguard Worker     TESTCASE(TestSetScriptIllFormed);
1771*0e209d39SAndroid Build Coastguard Worker     TESTCASE(TestSetRegionWellFormed);
1772*0e209d39SAndroid Build Coastguard Worker     TESTCASE(TestSetRegionIllFormed);
1773*0e209d39SAndroid Build Coastguard Worker     TESTCASE(TestSetVariantWellFormed);
1774*0e209d39SAndroid Build Coastguard Worker     TESTCASE(TestSetVariantIllFormed);
1775*0e209d39SAndroid Build Coastguard Worker     TESTCASE(TestSetUnicodeLocaleKeywordWellFormed);
1776*0e209d39SAndroid Build Coastguard Worker     TESTCASE(TestSetUnicodeLocaleKeywordIllFormedKey);
1777*0e209d39SAndroid Build Coastguard Worker     TESTCASE(TestSetUnicodeLocaleKeywordIllFormedValue);
1778*0e209d39SAndroid Build Coastguard Worker     TESTCASE(TestAddRemoveUnicodeLocaleAttribute);
1779*0e209d39SAndroid Build Coastguard Worker     TESTCASE(TestAddRemoveUnicodeLocaleAttributeWellFormed);
1780*0e209d39SAndroid Build Coastguard Worker     TESTCASE(TestAddUnicodeLocaleAttributeIllFormed);
1781*0e209d39SAndroid Build Coastguard Worker     TESTCASE(TestSetExtensionU);
1782*0e209d39SAndroid Build Coastguard Worker     TESTCASE(TestSetExtensionValidateUWellFormed);
1783*0e209d39SAndroid Build Coastguard Worker     TESTCASE(TestSetExtensionValidateUIllFormed);
1784*0e209d39SAndroid Build Coastguard Worker     TESTCASE(TestSetExtensionT);
1785*0e209d39SAndroid Build Coastguard Worker     TESTCASE(TestSetExtensionValidateTWellFormed);
1786*0e209d39SAndroid Build Coastguard Worker     TESTCASE(TestSetExtensionValidateTIllFormed);
1787*0e209d39SAndroid Build Coastguard Worker     TESTCASE(TestSetExtensionPU);
1788*0e209d39SAndroid Build Coastguard Worker     TESTCASE(TestSetExtensionValidatePUWellFormed);
1789*0e209d39SAndroid Build Coastguard Worker     TESTCASE(TestSetExtensionValidatePUIllFormed);
1790*0e209d39SAndroid Build Coastguard Worker     TESTCASE(TestSetExtensionOthers);
1791*0e209d39SAndroid Build Coastguard Worker     TESTCASE(TestSetExtensionValidateOthersWellFormed);
1792*0e209d39SAndroid Build Coastguard Worker     TESTCASE(TestSetExtensionValidateOthersIllFormed);
1793*0e209d39SAndroid Build Coastguard Worker     TESTCASE(TestSetLocale);
1794*0e209d39SAndroid Build Coastguard Worker     TESTCASE(TestBuildULocale);
1795*0e209d39SAndroid Build Coastguard Worker     TESTCASE(TestPosixCases);
1796*0e209d39SAndroid Build Coastguard Worker }
1797