-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathisocodes_test.c
125 lines (110 loc) · 3.55 KB
/
isocodes_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/**
* @file isocodes_test.c
* @brief Various tests related to iso-codes package
*
* Copyright 2021, 2023 Leon Lynch
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program. If not, see
* <https://www.gnu.org/licenses/>.
*/
#include "isocodes_lookup.h"
#include <stdio.h>
#include <string.h>
#ifdef HAVE_LIBINTL_H
#include <locale.h>
#include <libintl.h>
#endif
int main(void)
{
int r;
const char* country;
const char* currency;
const char* language;
#ifdef HAVE_LIBINTL_H
setlocale(LC_ALL, "nl_NL.UTF-8");
printf("%s\n", dgettext("iso_639-2", "French"));
printf("%s\n", dgettext("iso_3166-1", "France"));
printf("%s\n", dgettext("iso_3166-3", "710")); // Cannot resolve numeric codes via libintl
#endif
r = isocodes_init(NULL);
if (r) {
fprintf(stderr, "isocodes_init() failed; r=%d\n", r);
return 1;
}
country = isocodes_lookup_country_by_alpha2("NL");
if (!country) {
fprintf(stderr, "isocodes_lookup_country_by_alpha2() failed\n");
return 1;
}
if (strcmp(country, "Netherlands") != 0) {
fprintf(stderr, "isocodes_lookup_country_by_alpha2() found unexpected country '%s'\n", country);
return 1;
}
country = isocodes_lookup_country_by_alpha3("NLD");
if (!country) {
fprintf(stderr, "isocodes_lookup_country_by_alpha3() failed\n");
return 1;
}
if (strcmp(country, "Netherlands") != 0) {
fprintf(stderr, "isocodes_lookup_country_by_alpha3() found unexpected country '%s'\n", country);
return 1;
}
country = isocodes_lookup_country_by_numeric(528);
if (!country) {
fprintf(stderr, "isocodes_lookup_country_by_numeric() failed\n");
return 1;
}
if (strcmp(country, "Netherlands") != 0) {
fprintf(stderr, "isocodes_lookup_country_by_numeric() found unexpected country '%s'\n", country);
return 1;
}
currency = isocodes_lookup_currency_by_alpha3("EUR");
if (!currency) {
fprintf(stderr, "isocodes_lookup_currency_by_alpha3() failed\n");
return 1;
}
if (strcmp(currency, "Euro") != 0) {
fprintf(stderr, "isocodes_lookup_currency_by_alpha3() found unexpected currency '%s'\n", currency);
return 1;
}
currency = isocodes_lookup_currency_by_numeric(978);
if (!currency) {
fprintf(stderr, "isocodes_lookup_currency_by_numeric() failed\n");
return 1;
}
if (strcmp(currency, "Euro") != 0) {
fprintf(stderr, "isocodes_lookup_currency_by_numeric() found unexpected currency '%s'\n", currency);
return 1;
}
language = isocodes_lookup_language_by_alpha2("fr");
if (!language) {
fprintf(stderr, "isocodes_lookup_language_by_alpha2() failed\n");
return 1;
}
if (strcmp(language, "French") != 0) {
fprintf(stderr, "isocodes_lookup_language_by_alpha2() found unexpected language '%s'\n", language);
return 1;
}
language = isocodes_lookup_language_by_alpha3("frr");
if (!language) {
fprintf(stderr, "isocodes_lookup_language_by_alpha3() failed\n");
return 1;
}
if (strcmp(language, "Northern Frisian") != 0) {
fprintf(stderr, "isocodes_lookup_language_by_alpha3() found unexpected language '%s'\n", language);
return 1;
}
printf("Success\n");
return 0;
}