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.
33 #-----------------------------------------------------------------------
34 # Old API - without codeset specified, default to ALPHA_2
35 #-----------------------------------------------------------------------
37 foreach $code (all_country_codes())
39 $country = code2country($code);
40 if (!defined $country)
45 $reverse = country2code($country);
46 if (!defined $reverse)
51 if ($reverse ne $code)
57 print ($ok ? "ok 1\n" : "not ok 1\n");
59 #-----------------------------------------------------------------------
60 # code to country, back to code, for ALPHA2
61 #-----------------------------------------------------------------------
63 foreach $code (all_country_codes(LOCALE_CODE_ALPHA_2))
65 $country = code2country($code, LOCALE_CODE_ALPHA_2);
66 if (!defined $country)
71 $reverse = country2code($country, LOCALE_CODE_ALPHA_2);
72 if (!defined $reverse)
77 if ($reverse ne $code)
83 print ($ok ? "ok 2\n" : "not ok 2\n");
85 #-----------------------------------------------------------------------
86 # code to country, back to code, for ALPHA3
87 #-----------------------------------------------------------------------
89 foreach $code (all_country_codes(LOCALE_CODE_ALPHA_3))
91 $country = code2country($code, LOCALE_CODE_ALPHA_3);
92 if (!defined $country)
97 $reverse = country2code($country, LOCALE_CODE_ALPHA_3);
98 if (!defined $reverse)
103 if ($reverse ne $code)
109 print ($ok ? "ok 3\n" : "not ok 3\n");
111 #-----------------------------------------------------------------------
112 # code to country, back to code, for NUMERIC
113 #-----------------------------------------------------------------------
115 foreach $code (all_country_codes(LOCALE_CODE_NUMERIC))
117 $country = code2country($code, LOCALE_CODE_NUMERIC);
118 if (!defined $country)
123 $reverse = country2code($country, LOCALE_CODE_NUMERIC);
124 if (!defined $reverse)
129 if ($reverse ne $code)
135 print ($ok ? "ok 4\n" : "not ok 4\n");
138 #-----------------------------------------------------------------------
139 # Old API - country to code, back to country, using default of ALPHA_2
140 #-----------------------------------------------------------------------
142 foreach $country (all_country_names())
144 $code = country2code($country);
150 $reverse = code2country($code);
151 if (!defined $reverse)
156 if ($reverse ne $country)
162 print ($ok ? "ok 5\n" : "not ok 5\n");
164 #-----------------------------------------------------------------------
165 # country to code, back to country, using LOCALE_CODE_ALPHA_2
166 #-----------------------------------------------------------------------
168 foreach $country (all_country_names())
170 $code = country2code($country, LOCALE_CODE_ALPHA_2);
176 $reverse = code2country($code, LOCALE_CODE_ALPHA_2);
177 if (!defined $reverse)
182 if ($reverse ne $country)
188 print ($ok ? "ok 6\n" : "not ok 6\n");
190 #-----------------------------------------------------------------------
191 # country to code, back to country, using LOCALE_CODE_ALPHA_3
192 #-----------------------------------------------------------------------
194 foreach $country (all_country_names())
196 $code = country2code($country, LOCALE_CODE_ALPHA_3);
199 next if ($country eq 'Antarctica'
200 || $country eq 'Bouvet Island'
201 || $country eq 'Cocos (Keeling) Islands'
202 || $country eq 'Christmas Island'
203 || $country eq 'France, Metropolitan'
204 || $country eq 'South Georgia and the South Sandwich Islands'
205 || $country eq 'Heard Island and McDonald Islands'
206 || $country eq 'British Indian Ocean Territory'
207 || $country eq 'French Southern Territories'
208 || $country eq 'United States Minor Outlying Islands'
209 || $country eq 'Mayotte'
210 || $country eq 'Zaire');
214 $reverse = code2country($code, LOCALE_CODE_ALPHA_3);
215 if (!defined $reverse)
220 if ($reverse ne $country)
226 print ($ok ? "ok 7\n" : "not ok 7\n");
228 #-----------------------------------------------------------------------
229 # country to code, back to country, using LOCALE_CODE_NUMERIC
230 #-----------------------------------------------------------------------
232 foreach $country (all_country_names())
234 $code = country2code($country, LOCALE_CODE_NUMERIC);
237 next if ($country eq 'Antarctica'
238 || $country eq 'Bouvet Island'
239 || $country eq 'Cocos (Keeling) Islands'
240 || $country eq 'Christmas Island'
241 || $country eq 'France, Metropolitan'
242 || $country eq 'South Georgia and the South Sandwich Islands'
243 || $country eq 'Heard Island and McDonald Islands'
244 || $country eq 'British Indian Ocean Territory'
245 || $country eq 'French Southern Territories'
246 || $country eq 'United States Minor Outlying Islands'
247 || $country eq 'Mayotte'
248 || $country eq 'Zaire');
252 $reverse = code2country($code, LOCALE_CODE_NUMERIC);
253 if (!defined $reverse)
258 if ($reverse ne $country)
264 print ($ok ? "ok 8\n" : "not ok 8\n");
268 foreach $code (all_language_codes())
270 $language = code2language($code);
271 if (!defined $language)
276 $reverse = language2code($language);
277 if (!defined $reverse)
282 if ($reverse ne $code)
288 print ($ok ? "ok 9\n" : "not ok 9\n");
292 foreach $language (all_language_names())
294 $code = language2code($language);
300 $reverse = code2language($code);
301 if (!defined $reverse)
306 if ($reverse ne $language)
312 print ($ok ? "ok 10\n" : "not ok 10\n");
315 foreach $code (all_currency_codes())
317 $currency = code2currency($code);
318 if (!defined $currency)
323 $reverse = currency2code($currency);
324 if (!defined $reverse)
330 # three special cases:
331 # The Kwacha has two codes - used in Zambia and Malawi
332 # The Russian Ruble has two codes - rub and rur
333 # The Belarussian Ruble has two codes - byb and byr
334 if ($reverse ne $code
335 && $code ne 'mwk' && $code ne 'zmk'
336 && $code ne 'byr' && $code ne 'byb'
337 && $code ne 'rub' && $code ne 'rur')
343 print ($ok ? "ok 11\n" : "not ok 11\n");
346 foreach $currency (all_currency_names())
348 $code = currency2code($currency);
354 $reverse = code2currency($code);
355 if (!defined $reverse)
360 if ($reverse ne $currency)
366 print ($ok ? "ok 12\n" : "not ok 12\n");