1 /********************************************************************
2 * Copyright (c) 2014-2016, International Business Machines Corporation
3 * and others. All Rights Reserved.
4 ********************************************************************/
5 /* C API TEST FOR UREGION */
6 /***********************************************************************
7 * Test cases ported from ICU4J ( RegionTest.java )
8 * to C++ (regiontst.cpp) to here.
9 * Try to keep them in sync if at all possible...!
10 ***********************************************************************/
12 #include "unicode/utypes.h"
14 #if !UCONFIG_NO_FORMATTING
16 #include "unicode/ustring.h"
17 #include "unicode/uregion.h"
18 #include "unicode/uenum.h"
23 static void TestKnownRegions(void);
24 static void TestGetContainedRegions(void);
25 static void TestGetContainedRegionsWithType(void);
26 static void TestGetContainingRegion(void);
27 static void TestGetContainingRegionWithType(void);
28 static void TestGetPreferredValues(void);
29 static void TestContains(void);
31 void addURegionTest(TestNode
** root
);
33 #define TESTCASE(x) addTest(root, &x, "tsformat/uregiontest/" #x)
35 void addURegionTest(TestNode
** root
)
37 TESTCASE(TestKnownRegions
);
38 TESTCASE(TestGetContainedRegions
);
39 TESTCASE(TestGetContainedRegionsWithType
);
40 TESTCASE(TestGetContainingRegion
);
41 TESTCASE(TestGetContainingRegionWithType
);
42 TESTCASE(TestGetPreferredValues
);
43 TESTCASE(TestContains
);
46 typedef struct KnownRegion
{
51 const char *containingContinent
;
54 static KnownRegion knownRegions
[] = {
55 // Code, Num, Parent, Type, Containing Continent
56 { "TP" , 626, "035", URGN_TERRITORY
, "142" },
57 { "001", 1, NULL
, URGN_WORLD
, NULL
},
58 { "002", 2, "001", URGN_CONTINENT
, NULL
},
59 { "003", 3, NULL
, URGN_GROUPING
, NULL
},
60 { "005", 5, "019", URGN_SUBCONTINENT
, "019" },
61 { "009", 9, "001", URGN_CONTINENT
, NULL
},
62 { "011", 11, "002", URGN_SUBCONTINENT
, "002" },
63 { "013", 13, "019", URGN_SUBCONTINENT
, "019" },
64 { "014", 14, "002", URGN_SUBCONTINENT
, "002" },
65 { "015", 15, "002", URGN_SUBCONTINENT
, "002" },
66 { "017", 17, "002", URGN_SUBCONTINENT
, "002" },
67 { "018", 18, "002", URGN_SUBCONTINENT
, "002" },
68 { "019", 19, "001", URGN_CONTINENT
, NULL
},
69 { "021", 21, "019", URGN_SUBCONTINENT
, "019" },
70 { "029", 29, "019", URGN_SUBCONTINENT
, "019" },
71 { "030", 30, "142", URGN_SUBCONTINENT
, "142" },
72 { "034", 34, "142", URGN_SUBCONTINENT
, "142" },
73 { "035", 35, "142", URGN_SUBCONTINENT
, "142" },
74 { "039", 39, "150", URGN_SUBCONTINENT
, "150"},
75 { "053", 53, "009", URGN_SUBCONTINENT
, "009" },
76 { "054", 54, "009", URGN_SUBCONTINENT
, "009" },
77 { "057", 57, "009", URGN_SUBCONTINENT
, "009" },
78 { "061", 61, "009", URGN_SUBCONTINENT
, "009" },
79 { "142", 142, "001", URGN_CONTINENT
, NULL
},
80 { "143", 143, "142", URGN_SUBCONTINENT
, "142" },
81 { "145", 145, "142", URGN_SUBCONTINENT
, "142" },
82 { "150", 150, "001", URGN_CONTINENT
, NULL
},
83 { "151", 151, "150", URGN_SUBCONTINENT
, "150" },
84 { "154", 154, "150", URGN_SUBCONTINENT
, "150" },
85 { "155", 155, "150", URGN_SUBCONTINENT
, "150" },
86 { "419", 419, NULL
, URGN_GROUPING
, NULL
},
87 { "AC" , -1, "QO" , URGN_TERRITORY
, "009" },
88 { "AD" , 20, "039", URGN_TERRITORY
, "150" },
89 { "AE" , 784, "145", URGN_TERRITORY
, "142" },
90 { "AF" , 4, "034", URGN_TERRITORY
, "142" },
91 { "AG" , 28, "029", URGN_TERRITORY
, "019" },
92 { "AI" , 660, "029", URGN_TERRITORY
, "019" },
93 { "AL" , 8, "039", URGN_TERRITORY
, "150" },
94 { "AM" , 51, "145", URGN_TERRITORY
, "142" },
95 { "AN" , 530, NULL
, URGN_DEPRECATED
, NULL
},
96 { "AO" , 24, "017", URGN_TERRITORY
, "002" },
97 { "AQ" , 10, "QO" , URGN_TERRITORY
, "009" },
98 { "AR" , 32, "005", URGN_TERRITORY
, "019" },
99 { "AS" , 16, "061", URGN_TERRITORY
, "009" },
100 { "AT" , 40, "155", URGN_TERRITORY
, "150" },
101 { "AU" , 36, "053", URGN_TERRITORY
, "009" },
102 { "AW" , 533, "029", URGN_TERRITORY
, "019" },
103 { "AX" , 248, "154", URGN_TERRITORY
, "150" },
104 { "AZ" , 31, "145", URGN_TERRITORY
, "142" },
105 { "BA" , 70, "039", URGN_TERRITORY
, "150" },
106 { "BB" , 52, "029", URGN_TERRITORY
, "019" },
107 { "BD" , 50, "034", URGN_TERRITORY
, "142" },
108 { "BE" , 56, "155", URGN_TERRITORY
, "150" },
109 { "BF" , 854, "011", URGN_TERRITORY
, "002" },
110 { "BG" , 100, "151", URGN_TERRITORY
, "150" },
111 { "BH" , 48, "145", URGN_TERRITORY
, "142" },
112 { "BI" , 108, "014", URGN_TERRITORY
, "002" },
113 { "BJ" , 204, "011", URGN_TERRITORY
, "002" },
114 { "BL" , 652, "029", URGN_TERRITORY
, "019" },
115 { "BM" , 60, "021", URGN_TERRITORY
, "019" },
116 { "BN" , 96, "035", URGN_TERRITORY
, "142" },
117 { "BO" , 68, "005", URGN_TERRITORY
, "019" },
118 { "BQ" , 535, "029", URGN_TERRITORY
, "019" },
119 { "BR" , 76, "005", URGN_TERRITORY
, "019" },
120 { "BS" , 44, "029", URGN_TERRITORY
, "019" },
121 { "BT" , 64, "034", URGN_TERRITORY
, "142" },
122 { "BU" , 104, "035", URGN_TERRITORY
, "142" },
123 { "BV" , 74, "QO" , URGN_TERRITORY
, "009" },
124 { "BW" , 72, "018", URGN_TERRITORY
, "002" },
125 { "BY" , 112, "151", URGN_TERRITORY
, "150" },
126 { "BZ" , 84, "013", URGN_TERRITORY
, "019" },
127 { "CA" , 124, "021", URGN_TERRITORY
, "019" },
128 { "CC" , 166, "QO" , URGN_TERRITORY
, "009" },
129 { "CD" , 180, "017", URGN_TERRITORY
, "002" },
130 { "CF" , 140, "017", URGN_TERRITORY
, "002" },
131 { "CG" , 178, "017", URGN_TERRITORY
, "002" },
132 { "CH" , 756, "155", URGN_TERRITORY
, "150" },
133 { "CI" , 384, "011", URGN_TERRITORY
, "002" },
134 { "CK" , 184, "061", URGN_TERRITORY
, "009" },
135 { "CL" , 152, "005", URGN_TERRITORY
, "019" },
136 { "CM" , 120, "017", URGN_TERRITORY
, "002" },
137 { "CN" , 156, "030", URGN_TERRITORY
, "142" },
138 { "CO" , 170, "005", URGN_TERRITORY
, "019" },
139 { "CP" , -1 , "QO" , URGN_TERRITORY
, "009" },
140 { "CR" , 188, "013", URGN_TERRITORY
, "019" },
141 { "CU" , 192, "029", URGN_TERRITORY
, "019" },
142 { "CV" , 132, "011", URGN_TERRITORY
, "002" },
143 { "CW" , 531, "029", URGN_TERRITORY
, "019" },
144 { "CX" , 162, "QO" , URGN_TERRITORY
, "009" },
145 { "CY" , 196, "145", URGN_TERRITORY
, "142" },
146 { "CZ" , 203, "151", URGN_TERRITORY
, "150" },
147 { "DD" , 276, "155", URGN_TERRITORY
, "150" },
148 { "DE" , 276, "155", URGN_TERRITORY
, "150" },
149 { "DG" , -1 , "QO" , URGN_TERRITORY
, "009" },
150 { "DJ" , 262, "014", URGN_TERRITORY
, "002" },
151 { "DK" , 208, "154", URGN_TERRITORY
, "150" },
152 { "DM" , 212, "029", URGN_TERRITORY
, "019" },
153 { "DO" , 214, "029", URGN_TERRITORY
, "019" },
154 { "DZ" , 12, "015", URGN_TERRITORY
, "002" },
155 { "EA" , -1, "015", URGN_TERRITORY
, "002" },
156 { "EC" , 218, "005", URGN_TERRITORY
, "019" },
157 { "EE" , 233, "154", URGN_TERRITORY
, "150" },
158 { "EG" , 818, "015", URGN_TERRITORY
, "002" },
159 { "EH" , 732, "015", URGN_TERRITORY
, "002" },
160 { "ER" , 232, "014", URGN_TERRITORY
, "002" },
161 { "ES" , 724, "039", URGN_TERRITORY
, "150" },
162 { "ET" , 231, "014", URGN_TERRITORY
, "002" },
163 { "EU" , 967, NULL
, URGN_GROUPING
, NULL
},
164 { "FI" , 246, "154", URGN_TERRITORY
, "150" },
165 { "FJ" , 242, "054", URGN_TERRITORY
, "009" },
166 { "FK" , 238, "005", URGN_TERRITORY
, "019" },
167 { "FM" , 583, "057", URGN_TERRITORY
, "009" },
168 { "FO" , 234, "154", URGN_TERRITORY
, "150" },
169 { "FR" , 250, "155", URGN_TERRITORY
, "150" },
170 { "FX" , 250, "155", URGN_TERRITORY
, "150" },
171 { "GA" , 266, "017", URGN_TERRITORY
, "002" },
172 { "GB" , 826, "154", URGN_TERRITORY
, "150" },
173 { "GD" , 308, "029", URGN_TERRITORY
, "019" },
174 { "GE" , 268, "145", URGN_TERRITORY
, "142" },
175 { "GF" , 254, "005", URGN_TERRITORY
, "019" },
176 { "GG" , 831, "154", URGN_TERRITORY
, "150" },
177 { "GH" , 288, "011", URGN_TERRITORY
, "002" },
178 { "GI" , 292, "039", URGN_TERRITORY
, "150" },
179 { "GL" , 304, "021", URGN_TERRITORY
, "019" },
180 { "GM" , 270, "011", URGN_TERRITORY
, "002" },
181 { "GN" , 324, "011", URGN_TERRITORY
, "002" },
182 { "GP" , 312, "029", URGN_TERRITORY
, "019" },
183 { "GQ" , 226, "017", URGN_TERRITORY
, "002" },
184 { "GR" , 300, "039", URGN_TERRITORY
, "150" },
185 { "GS" , 239, "QO" , URGN_TERRITORY
, "009" },
186 { "GT" , 320, "013", URGN_TERRITORY
, "019" },
187 { "GU" , 316, "057", URGN_TERRITORY
, "009" },
188 { "GW" , 624, "011", URGN_TERRITORY
, "002" },
189 { "GY" , 328, "005", URGN_TERRITORY
, "019" },
190 { "HK" , 344, "030", URGN_TERRITORY
, "142" },
191 { "HM" , 334, "QO" , URGN_TERRITORY
, "009" },
192 { "HN" , 340, "013", URGN_TERRITORY
, "019" },
193 { "HR" , 191, "039", URGN_TERRITORY
, "150" },
194 { "HT" , 332, "029", URGN_TERRITORY
, "019" },
195 { "HU" , 348, "151", URGN_TERRITORY
, "150" },
196 { "IC" , -1, "015", URGN_TERRITORY
, "002" },
197 { "ID" , 360, "035", URGN_TERRITORY
, "142" },
198 { "IE" , 372, "154", URGN_TERRITORY
, "150" },
199 { "IL" , 376, "145", URGN_TERRITORY
, "142" },
200 { "IM" , 833, "154", URGN_TERRITORY
, "150" },
201 { "IN" , 356, "034", URGN_TERRITORY
, "142" },
202 { "IO" , 86, "QO" , URGN_TERRITORY
, "009" },
203 { "IQ" , 368, "145", URGN_TERRITORY
, "142" },
204 { "IR" , 364, "034", URGN_TERRITORY
, "142" },
205 { "IS" , 352, "154", URGN_TERRITORY
, "150" },
206 { "IT" , 380, "039", URGN_TERRITORY
, "150" },
207 { "JE" , 832, "154", URGN_TERRITORY
, "150" },
208 { "JM" , 388, "029", URGN_TERRITORY
, "019" },
209 { "JO" , 400, "145", URGN_TERRITORY
, "142" },
210 { "JP" , 392, "030", URGN_TERRITORY
, "142" },
211 { "KE" , 404, "014", URGN_TERRITORY
, "002" },
212 { "KG" , 417, "143", URGN_TERRITORY
, "142" },
213 { "KH" , 116, "035", URGN_TERRITORY
, "142" },
214 { "KI" , 296, "057", URGN_TERRITORY
, "009" },
215 { "KM" , 174, "014", URGN_TERRITORY
, "002" },
216 { "KN" , 659, "029", URGN_TERRITORY
, "019" },
217 { "KP" , 408, "030", URGN_TERRITORY
, "142" },
218 { "KR" , 410, "030", URGN_TERRITORY
, "142" },
219 { "KW" , 414, "145", URGN_TERRITORY
, "142" },
220 { "KY" , 136, "029", URGN_TERRITORY
, "019" },
221 { "KZ" , 398, "143", URGN_TERRITORY
, "142" },
222 { "LA" , 418, "035", URGN_TERRITORY
, "142" },
223 { "LB" , 422, "145", URGN_TERRITORY
, "142" },
224 { "LC" , 662, "029", URGN_TERRITORY
, "019" },
225 { "LI" , 438, "155", URGN_TERRITORY
, "150" },
226 { "LK" , 144, "034", URGN_TERRITORY
, "142" },
227 { "LR" , 430, "011", URGN_TERRITORY
, "002" },
228 { "LS" , 426, "018", URGN_TERRITORY
, "002" },
229 { "LT" , 440, "154", URGN_TERRITORY
, "150" },
230 { "LU" , 442, "155", URGN_TERRITORY
, "150" },
231 { "LV" , 428, "154", URGN_TERRITORY
, "150" },
232 { "LY" , 434, "015", URGN_TERRITORY
, "002" },
233 { "MA" , 504, "015", URGN_TERRITORY
, "002" },
234 { "MC" , 492, "155", URGN_TERRITORY
, "150" },
235 { "MD" , 498, "151", URGN_TERRITORY
, "150" },
236 { "ME" , 499, "039", URGN_TERRITORY
, "150" },
237 { "MF" , 663, "029", URGN_TERRITORY
, "019" },
238 { "MG" , 450, "014", URGN_TERRITORY
, "002" },
239 { "MH" , 584, "057", URGN_TERRITORY
, "009" },
240 { "MK" , 807, "039", URGN_TERRITORY
, "150" },
241 { "ML" , 466, "011", URGN_TERRITORY
, "002" },
242 { "MM" , 104, "035", URGN_TERRITORY
, "142" },
243 { "MN" , 496, "030", URGN_TERRITORY
, "142" },
244 { "MO" , 446, "030", URGN_TERRITORY
, "142" },
245 { "MP" , 580, "057", URGN_TERRITORY
, "009" },
246 { "MQ" , 474, "029", URGN_TERRITORY
, "019" },
247 { "MR" , 478, "011", URGN_TERRITORY
, "002" },
248 { "MS" , 500, "029", URGN_TERRITORY
, "019" },
249 { "MT" , 470, "039", URGN_TERRITORY
, "150" },
250 { "MU" , 480, "014", URGN_TERRITORY
, "002" },
251 { "MV" , 462, "034", URGN_TERRITORY
, "142" },
252 { "MW" , 454, "014", URGN_TERRITORY
, "002" },
253 { "MX" , 484, "013", URGN_TERRITORY
, "019"},
254 { "MY" , 458, "035", URGN_TERRITORY
, "142" },
255 { "MZ" , 508, "014", URGN_TERRITORY
, "002" },
256 { "NA" , 516, "018", URGN_TERRITORY
, "002" },
257 { "NC" , 540, "054", URGN_TERRITORY
, "009" },
258 { "NE" , 562, "011", URGN_TERRITORY
, "002" },
259 { "NF" , 574, "053", URGN_TERRITORY
, "009" },
260 { "NG" , 566, "011", URGN_TERRITORY
, "002" },
261 { "NI" , 558, "013", URGN_TERRITORY
, "019" },
262 { "NL" , 528, "155", URGN_TERRITORY
, "150" },
263 { "NO" , 578, "154", URGN_TERRITORY
, "150" },
264 { "NP" , 524, "034", URGN_TERRITORY
, "142" },
265 { "NR" , 520, "057", URGN_TERRITORY
, "009" },
266 { "NT" , 536, NULL
, URGN_DEPRECATED
, NULL
},
267 { "NU" , 570, "061", URGN_TERRITORY
, "009" },
268 { "NZ" , 554, "053", URGN_TERRITORY
, "009" },
269 { "OM" , 512, "145", URGN_TERRITORY
, "142" },
270 { "PA" , 591, "013", URGN_TERRITORY
, "019" },
271 { "PE" , 604, "005", URGN_TERRITORY
, "019" },
272 { "PF" , 258, "061", URGN_TERRITORY
, "009" },
273 { "PG" , 598, "054", URGN_TERRITORY
, "009" },
274 { "PH" , 608, "035", URGN_TERRITORY
, "142" },
275 { "PK" , 586, "034", URGN_TERRITORY
, "142" },
276 { "PL" , 616, "151", URGN_TERRITORY
, "150" },
277 { "PM" , 666, "021", URGN_TERRITORY
, "019" },
278 { "PN" , 612, "061", URGN_TERRITORY
, "009" },
279 { "PR" , 630, "029", URGN_TERRITORY
, "019" },
280 { "PS" , 275, "145", URGN_TERRITORY
, "142" },
281 { "PT" , 620, "039", URGN_TERRITORY
, "150" },
282 { "PW" , 585, "057", URGN_TERRITORY
, "009" },
283 { "PY" , 600, "005", URGN_TERRITORY
, "019" },
284 { "QA" , 634, "145", URGN_TERRITORY
, "142" },
285 { "QO" , 961, "009", URGN_SUBCONTINENT
, "009" },
286 { "QU" , 967, NULL
, URGN_GROUPING
, NULL
},
287 { "RE" , 638, "014", URGN_TERRITORY
, "002" },
288 { "RO" , 642, "151", URGN_TERRITORY
, "150" },
289 { "RS" , 688, "039", URGN_TERRITORY
, "150" },
290 { "RU" , 643, "151", URGN_TERRITORY
, "150" },
291 { "RW" , 646, "014", URGN_TERRITORY
, "002" },
292 { "SA" , 682, "145", URGN_TERRITORY
, "142" },
293 { "SB" , 90, "054", URGN_TERRITORY
, "009" },
294 { "SC" , 690, "014", URGN_TERRITORY
, "002" },
295 { "SD" , 729, "015", URGN_TERRITORY
, "002" },
296 { "SE" , 752, "154", URGN_TERRITORY
, "150" },
297 { "SG" , 702, "035", URGN_TERRITORY
, "142" },
298 { "SH" , 654, "011", URGN_TERRITORY
, "002" },
299 { "SI" , 705, "039", URGN_TERRITORY
, "150" },
300 { "SJ" , 744, "154", URGN_TERRITORY
, "150" },
301 { "SK" , 703, "151", URGN_TERRITORY
, "150" },
302 { "SL" , 694, "011", URGN_TERRITORY
, "002" },
303 { "SM" , 674, "039", URGN_TERRITORY
, "150" },
304 { "SN" , 686, "011", URGN_TERRITORY
, "002" },
305 { "SO" , 706, "014", URGN_TERRITORY
, "002" },
306 { "SR" , 740, "005", URGN_TERRITORY
, "019" },
307 { "SS" , 728, "014", URGN_TERRITORY
, "002" },
308 { "ST" , 678, "017", URGN_TERRITORY
, "002" },
309 { "SU" , 810, NULL
, URGN_DEPRECATED
, NULL
},
310 { "SV" , 222, "013", URGN_TERRITORY
, "019" },
311 { "SX" , 534, "029", URGN_TERRITORY
, "019" },
312 { "SY" , 760, "145", URGN_TERRITORY
, "142" },
313 { "SZ" , 748, "018", URGN_TERRITORY
, "002" },
314 { "TA" , -1, "QO", URGN_TERRITORY
, "009" },
315 { "TC" , 796, "029", URGN_TERRITORY
, "019" },
316 { "TD" , 148, "017", URGN_TERRITORY
, "002" },
317 { "TF" , 260, "QO" , URGN_TERRITORY
, "009" },
318 { "TG" , 768, "011", URGN_TERRITORY
, "002" },
319 { "TH" , 764, "035", URGN_TERRITORY
, "142" },
320 { "TJ" , 762, "143", URGN_TERRITORY
, "142" },
321 { "TK" , 772, "061", URGN_TERRITORY
, "009" },
322 { "TL" , 626, "035", URGN_TERRITORY
, "142" },
323 { "TM" , 795, "143", URGN_TERRITORY
, "142" },
324 { "TN" , 788, "015", URGN_TERRITORY
, "002" },
325 { "TO" , 776, "061", URGN_TERRITORY
, "009" },
326 { "TP" , 626, "035", URGN_TERRITORY
, "142" },
327 { "TR" , 792, "145", URGN_TERRITORY
, "142" },
328 { "TT" , 780, "029", URGN_TERRITORY
, "019" },
329 { "TV" , 798, "061", URGN_TERRITORY
, "009" },
330 { "TW" , 158, "030", URGN_TERRITORY
, "142" },
331 { "TZ" , 834, "014", URGN_TERRITORY
, "002" },
332 { "UA" , 804, "151", URGN_TERRITORY
, "150" },
333 { "UG" , 800, "014", URGN_TERRITORY
, "002" },
334 { "UM" , 581, "QO" , URGN_TERRITORY
, "009" },
335 { "US" , 840, "021", URGN_TERRITORY
, "019" },
336 { "UY" , 858, "005", URGN_TERRITORY
, "019" },
337 { "UZ" , 860, "143", URGN_TERRITORY
, "142" },
338 { "VA" , 336, "039", URGN_TERRITORY
, "150" },
339 { "VC" , 670, "029", URGN_TERRITORY
, "019" },
340 { "VE" , 862, "005", URGN_TERRITORY
, "019" },
341 { "VG" , 92, "029", URGN_TERRITORY
, "019" },
342 { "VI" , 850, "029", URGN_TERRITORY
, "019" },
343 { "VN" , 704, "035", URGN_TERRITORY
, "142" },
344 { "VU" , 548, "054", URGN_TERRITORY
, "009" },
345 { "WF" , 876, "061", URGN_TERRITORY
, "009" },
346 { "WS" , 882, "061", URGN_TERRITORY
, "009" },
347 { "YD" , 887, "145", URGN_TERRITORY
, "142" },
348 { "YE" , 887, "145", URGN_TERRITORY
, "142" },
349 { "YT" , 175, "014", URGN_TERRITORY
, "002" },
350 { "ZA" , 710, "018", URGN_TERRITORY
, "002" },
351 { "ZM" , 894, "014", URGN_TERRITORY
, "002" },
352 { "ZR" , 180, "017", URGN_TERRITORY
, "002" },
353 { "ZW" , 716, "014", URGN_TERRITORY
, "002" },
354 { "ZZ" , 999, NULL
, URGN_UNKNOWN
, NULL
},
355 { NULL
, 0, NULL
, URGN_UNKNOWN
, NULL
} /* terminator */
359 static void TestKnownRegions() {
360 const KnownRegion
* rd
;
361 for (rd
= knownRegions
; rd
->code
!= NULL
; rd
++ ) {
362 UErrorCode status
= U_ZERO_ERROR
;
363 const URegion
*r
= uregion_getRegionFromCode(rd
->code
, &status
);
364 if ( U_SUCCESS(status
) ) {
365 int32_t n
= uregion_getNumericCode(r
);
366 int32_t e
= rd
->numeric
;
368 log_err("ERROR: Numeric code mismatch for region %s. Expected:%d Got:%d\n", uregion_getRegionCode(r
), e
, n
);
370 if (uregion_getType(r
) != rd
->type
) {
371 log_err("ERROR: Expected region %s to be of type %d. Got: %d\n", uregion_getRegionCode(r
), rd
->type
, uregion_getType(r
) );
374 const URegion
*ncRegion
= uregion_getRegionFromNumericCode(e
, &status
);
375 if ( !uregion_areEqual(ncRegion
, r
) && e
!= 891 ) { // 891 is special case - CS and YU both deprecated codes for region 891
376 log_err("ERROR: Creating region %s by its numeric code returned a different region. Got: %s instead.\n",
377 uregion_getRegionCode(r
), uregion_getRegionCode(ncRegion
) );
381 log_data_err("ERROR: Known region %s was not recognized.\n", rd
->code
);
386 static void TestGetContainedRegions() {
387 const KnownRegion
* rd
;
388 for (rd
= knownRegions
; rd
->code
!= NULL
; rd
++ ) {
389 UErrorCode status
= U_ZERO_ERROR
;
390 const URegion
*r
= uregion_getRegionFromCode(rd
->code
, &status
);
391 if ( U_SUCCESS(status
) ) {
392 UEnumeration
*containedRegions
;
394 if (uregion_getType(r
) == URGN_GROUPING
) {
397 containedRegions
= uregion_getContainedRegions(r
, &status
);
398 if (containedRegions
!= NULL
) {
399 while ((crID
= uenum_next(containedRegions
, NULL
, &status
)) != NULL
&& U_SUCCESS(status
) ) {
400 const URegion
*cr
= uregion_getRegionFromCode(crID
, &status
);
401 const URegion
*containingRegion
= (cr
)? uregion_getContainingRegion(cr
) : NULL
;
402 if ( !containingRegion
|| !uregion_areEqual(containingRegion
, r
) ) {
403 log_err("ERROR: Region: %s contains region %s. Expected containing region of this region to be the original region, but got %s\n",
404 uregion_getRegionCode(r
), uregion_getRegionCode(cr
), (containingRegion
)?uregion_getRegionCode(containingRegion
):"NULL" );
407 uenum_close(containedRegions
);
410 log_data_err("ERROR: Known region %s was not recognized.\n", rd
->code
);
415 static void TestGetContainedRegionsWithType() {
416 const KnownRegion
* rd
;
417 for (rd
= knownRegions
; rd
->code
!= NULL
; rd
++ ) {
418 UErrorCode status
= U_ZERO_ERROR
;
419 const URegion
*r
= uregion_getRegionFromCode(rd
->code
, &status
);
420 if ( U_SUCCESS(status
) ) {
421 UEnumeration
*containedRegions
;
423 if (uregion_getType(r
) != URGN_CONTINENT
) {
426 containedRegions
= uregion_getContainedRegionsOfType(r
, URGN_TERRITORY
, &status
);
427 if (containedRegions
!= NULL
) {
428 while ((crID
= uenum_next(containedRegions
, NULL
, &status
)) != NULL
&& U_SUCCESS(status
) ) {
429 const URegion
*cr
= uregion_getRegionFromCode(crID
, &status
);
430 const URegion
*containingRegion
= (cr
)? uregion_getContainingRegionOfType(cr
, URGN_CONTINENT
) : NULL
;
431 if ( !containingRegion
|| !uregion_areEqual(containingRegion
, r
) ) {
432 log_err("ERROR: Continent: %s contains territory %s. Expected containing continent of this region to be the original region, but got %s\n",
433 uregion_getRegionCode(r
), uregion_getRegionCode(cr
), (containingRegion
)?uregion_getRegionCode(containingRegion
):"NULL" );
436 uenum_close(containedRegions
);
439 log_data_err("ERROR: Known region %s was not recognized.\n", rd
->code
);
444 static void TestGetContainingRegion() {
445 const KnownRegion
* rd
;
446 for (rd
= knownRegions
; rd
->code
!= NULL
; rd
++ ) {
447 UErrorCode status
= U_ZERO_ERROR
;
448 const URegion
*r
= uregion_getRegionFromCode(rd
->code
, &status
);
449 if ( U_SUCCESS(status
) ) {
450 const URegion
*c
= uregion_getContainingRegion(r
);
451 if (rd
->parent
== NULL
) {
453 log_err("ERROR: Containing region for %s should have been NULL. Got: %s\n", uregion_getRegionCode(r
), uregion_getRegionCode(c
) );
456 const URegion
*p
= uregion_getRegionFromCode(rd
->parent
, &status
);
457 if ( c
== NULL
|| !uregion_areEqual(p
, c
) ) {
458 log_err("ERROR: Expected containing continent of region %s to be %s. Got: %s\n",
459 uregion_getRegionCode(r
), (p
)?uregion_getRegionCode(p
):"NULL", (c
)?uregion_getRegionCode(c
):"NULL" );
463 log_data_err("ERROR: Known region %s was not recognized.\n", rd
->code
);
468 static void TestGetContainingRegionWithType() {
469 const KnownRegion
* rd
;
470 for (rd
= knownRegions
; rd
->code
!= NULL
; rd
++ ) {
471 UErrorCode status
= U_ZERO_ERROR
;
472 const URegion
*r
= uregion_getRegionFromCode(rd
->code
, &status
);
473 if ( U_SUCCESS(status
) ) {
474 const URegion
*c
= uregion_getContainingRegionOfType(r
, URGN_CONTINENT
);
475 if (rd
->containingContinent
== NULL
) {
477 log_err("ERROR: Containing continent for %s should have been NULL. Got: %s\n", uregion_getRegionCode(r
), uregion_getRegionCode(c
) );
480 const URegion
*p
= uregion_getRegionFromCode(rd
->containingContinent
, &status
);
481 if ( !uregion_areEqual(p
, c
) ) {
482 log_err("ERROR: Expected containing continent of region %s to be %s. Got: %s\n",
483 uregion_getRegionCode(r
), (p
)?uregion_getRegionCode(p
):"NULL", (c
)?uregion_getRegionCode(c
):"NULL" );
487 log_data_err("ERROR: Known region %s was not recognized.\n", rd
->code
);
492 static const char * expectPrefRegions0
[] = { "AN","CW","SX","BQ",NULL
}; /* Netherlands Antilles */
493 static const char * expectPrefRegions1
[] = { "CS","RS","ME",NULL
}; /* Serbia & Montenegro */
494 static const char * expectPrefRegions2
[] = { "FQ","AQ","TF",NULL
}; /* French Southern and Antarctic Territories */
495 static const char * expectPrefRegions3
[] = { "NT","IQ","SA",NULL
}; /* Neutral Zone */
496 static const char * expectPrefRegions4
[] = { "PC","FM","MH","MP","PW",NULL
}; /* Pacific Islands Trust Territory */
497 static const char * expectPrefRegions5
[] = { "SU","RU","AM","AZ","BY","EE","GE","KZ","KG","LV","LT","MD","TJ","TM","UA","UZ",NULL
}; /* Soviet Union */
498 static const char ** expectPrefRegionsTestData
[] = {
508 static void TestGetPreferredValues() {
509 const char *** testDataPtr
= expectPrefRegionsTestData
;
510 const char ** regionListPtr
;
511 while ( (regionListPtr
= *testDataPtr
++) != NULL
) {
512 UErrorCode status
= U_ZERO_ERROR
;
513 const char * deprecatedCode
= *regionListPtr
++;
514 const URegion
*r
= uregion_getRegionFromCode(deprecatedCode
, &status
);
515 if ( U_SUCCESS(status
) ) {
516 UEnumeration
*preferredRegions
= uregion_getPreferredValues(r
, &status
);
517 if ( U_SUCCESS(status
) ) {
518 if (preferredRegions
!= NULL
) {
519 const char * preferredCode
;
520 while ( (preferredCode
= *regionListPtr
++) != NULL
) {
523 uenum_reset(preferredRegions
, &status
);
524 while ((check
= uenum_next(preferredRegions
, NULL
, &status
)) != NULL
&& U_SUCCESS(status
) ) {
525 if ( !uprv_strcmp(check
,preferredCode
) ) {
531 log_err("ERROR: uregion_getPreferredValues for region \"%s\" should have contained \"%s\" but it didn't.\n", uregion_getRegionCode(r
), preferredCode
);
534 uenum_close(preferredRegions
);
537 log_err("ERROR: uregion_getPreferredValues failed for region %s.\n", uregion_getRegionCode(r
));
540 log_data_err("ERROR: Known region %s was not recognized.\n", deprecatedCode
);
545 static void TestContains() {
546 const KnownRegion
* rd
;
547 for (rd
= knownRegions
; rd
->code
!= NULL
; rd
++ ) {
548 UErrorCode status
= U_ZERO_ERROR
;
549 const URegion
*r
= uregion_getRegionFromCode(rd
->code
, &status
);
550 if ( U_SUCCESS(status
) ) {
551 const URegion
*c
= uregion_getContainingRegion(r
);
553 if ( !uregion_contains(c
, r
) ) {
554 log_err("ERROR: Region \"%s\" should have contained \"%s\" but it didn't.\n", uregion_getRegionCode(c
), uregion_getRegionCode(r
) );
556 c
= uregion_getContainingRegion(c
);
559 log_data_err("ERROR: Known region %s was not recognized.\n", rd
->code
);
564 #endif /* #if !UCONFIG_NO_FORMATTING */