3 # all.t - tests for all_* routines in
8 # There are four tests. We get a list of all codes, convert to
9 # language/country/currency, # convert back to code,
10 # and check that they're the same. Then we do the same,
11 # starting with list of languages/countries/currencies.
28 #-----------------------------------------------------------------------
29 # Old API - without codeset specified, default to ALPHA_2
30 #-----------------------------------------------------------------------
32 foreach $code (all_country_codes())
34 $country = code2country($code);
35 if (!defined $country)
40 $reverse = country2code($country);
41 if (!defined $reverse)
46 if ($reverse ne $code)
52 print ($ok ? "ok 1\n" : "not ok 1\n");
54 #-----------------------------------------------------------------------
55 # code to country, back to code, for ALPHA2
56 #-----------------------------------------------------------------------
58 foreach $code (all_country_codes(LOCALE_CODE_ALPHA_2))
60 $country = code2country($code, LOCALE_CODE_ALPHA_2);
61 if (!defined $country)
66 $reverse = country2code($country, LOCALE_CODE_ALPHA_2);
67 if (!defined $reverse)
72 if ($reverse ne $code)
78 print ($ok ? "ok 2\n" : "not ok 2\n");
80 #-----------------------------------------------------------------------
81 # code to country, back to code, for ALPHA3
82 #-----------------------------------------------------------------------
84 foreach $code (all_country_codes(LOCALE_CODE_ALPHA_3))
86 $country = code2country($code, LOCALE_CODE_ALPHA_3);
87 if (!defined $country)
92 $reverse = country2code($country, LOCALE_CODE_ALPHA_3);
93 if (!defined $reverse)
98 if ($reverse ne $code)
104 print ($ok ? "ok 3\n" : "not ok 3\n");
106 #-----------------------------------------------------------------------
107 # code to country, back to code, for NUMERIC
108 #-----------------------------------------------------------------------
110 foreach $code (all_country_codes(LOCALE_CODE_NUMERIC))
112 $country = code2country($code, LOCALE_CODE_NUMERIC);
113 if (!defined $country)
118 $reverse = country2code($country, LOCALE_CODE_NUMERIC);
119 if (!defined $reverse)
124 if ($reverse ne $code)
130 print ($ok ? "ok 4\n" : "not ok 4\n");
133 #-----------------------------------------------------------------------
134 # Old API - country to code, back to country, using default of ALPHA_2
135 #-----------------------------------------------------------------------
137 foreach $country (all_country_names())
139 $code = country2code($country);
145 $reverse = code2country($code);
146 if (!defined $reverse)
151 if ($reverse ne $country)
157 print ($ok ? "ok 5\n" : "not ok 5\n");
159 #-----------------------------------------------------------------------
160 # country to code, back to country, using LOCALE_CODE_ALPHA_2
161 #-----------------------------------------------------------------------
163 foreach $country (all_country_names())
165 $code = country2code($country, LOCALE_CODE_ALPHA_2);
171 $reverse = code2country($code, LOCALE_CODE_ALPHA_2);
172 if (!defined $reverse)
177 if ($reverse ne $country)
183 print ($ok ? "ok 6\n" : "not ok 6\n");
185 #-----------------------------------------------------------------------
186 # country to code, back to country, using LOCALE_CODE_ALPHA_3
187 #-----------------------------------------------------------------------
189 foreach $country (all_country_names())
191 $code = country2code($country, LOCALE_CODE_ALPHA_3);
194 next if ($country eq 'Antarctica'
195 || $country eq 'Bouvet Island'
196 || $country eq 'Cocos (Keeling) Islands'
197 || $country eq 'Christmas Island'
198 || $country eq 'France, Metropolitan'
199 || $country eq 'South Georgia and the South Sandwich Islands'
200 || $country eq 'Heard Island and McDonald Islands'
201 || $country eq 'British Indian Ocean Territory'
202 || $country eq 'French Southern Territories'
203 || $country eq 'United States Minor Outlying Islands'
204 || $country eq 'Mayotte'
205 || $country eq 'Zaire');
209 $reverse = code2country($code, LOCALE_CODE_ALPHA_3);
210 if (!defined $reverse)
215 if ($reverse ne $country)
221 print ($ok ? "ok 7\n" : "not ok 7\n");
223 #-----------------------------------------------------------------------
224 # country to code, back to country, using LOCALE_CODE_NUMERIC
225 #-----------------------------------------------------------------------
227 foreach $country (all_country_names())
229 $code = country2code($country, LOCALE_CODE_NUMERIC);
232 next if ($country eq 'Antarctica'
233 || $country eq 'Bouvet Island'
234 || $country eq 'Cocos (Keeling) Islands'
235 || $country eq 'Christmas Island'
236 || $country eq 'France, Metropolitan'
237 || $country eq 'South Georgia and the South Sandwich Islands'
238 || $country eq 'Heard Island and McDonald Islands'
239 || $country eq 'British Indian Ocean Territory'
240 || $country eq 'French Southern Territories'
241 || $country eq 'United States Minor Outlying Islands'
242 || $country eq 'Mayotte'
243 || $country eq 'Zaire');
247 $reverse = code2country($code, LOCALE_CODE_NUMERIC);
248 if (!defined $reverse)
253 if ($reverse ne $country)
259 print ($ok ? "ok 8\n" : "not ok 8\n");
263 foreach $code (all_language_codes())
265 $language = code2language($code);
266 if (!defined $language)
271 $reverse = language2code($language);
272 if (!defined $reverse)
277 if ($reverse ne $code)
283 print ($ok ? "ok 9\n" : "not ok 9\n");
287 foreach $language (all_language_names())
289 $code = language2code($language);
295 $reverse = code2language($code);
296 if (!defined $reverse)
301 if ($reverse ne $language)
307 print ($ok ? "ok 10\n" : "not ok 10\n");
310 foreach $code (all_currency_codes())
312 $currency = code2currency($code);
313 if (!defined $currency)
318 $reverse = currency2code($currency);
319 if (!defined $reverse)
325 # three special cases:
326 # The Kwacha has two codes - used in Zambia and Malawi
327 # The Russian Ruble has two codes - rub and rur
328 # The Belarussian Ruble has two codes - byb and byr
329 if ($reverse ne $code
330 && $code ne 'mwk' && $code ne 'zmk'
331 && $code ne 'byr' && $code ne 'byb'
332 && $code ne 'rub' && $code ne 'rur')
338 print ($ok ? "ok 11\n" : "not ok 11\n");
341 foreach $currency (all_currency_names())
343 $code = currency2code($currency);
349 $reverse = code2currency($code);
350 if (!defined $reverse)
355 if ($reverse ne $currency)
361 print ($ok ? "ok 12\n" : "not ok 12\n");