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