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