9 /* return whether byte strings are equal or not.
10 * NULL strings are never equal
12 static int my_streq(const char *va
, const char *vb
) {
16 if ((NULL
== a
) || (NULL
== b
)) {
19 for (i
=0; a
[i
] != '\0' && b
[i
] != '\0'; i
++) {
27 #if defined(CODESET_UTF_8)
28 #define MY_CODESET "UTF-8"
29 #elif defined(CODESET_LATIN1)
30 #define MY_CODESET "iso-8859-1"
31 #elif defined(CODESET_DEFAULT)
32 #define MY_CODESET "default"
33 #define bind_textdomain_codeset(domain,codeset) \
36 #error Define one of the CODESET_* macros!
46 const TestCase testcases
[] = {
48 N_("High saturation"),
49 /* ä latin1 oct 333 hex e4 dec 228 */
51 /* ä utf-8 oct 303 244 hex c3 a4 dec 195 164 */
52 "Hohe S\303\244ttigung" },
55 /* é latin1 oct 351 hex e9 dec 233 */
57 /* é utf-8 oct 303 251 hex c3 dec 195 */
61 N_("High saturation"),
62 /* ó latin1 oct hex dec 243 */
64 /* ó utf-8 oct hex c3 b3 dec */
65 "Alta saturaci\303\263n"
67 { NULL
, NULL
, NULL
, NULL
}
71 static int check(const int i
)
73 const char *oldtextdomain
= textdomain(NULL
);
74 const char *newtextdomain
= textdomain(GETTEXT_PACKAGE
);
76 const char *newcodeset
= MY_CODESET
;
77 const char *oldcodeset
= bind_textdomain_codeset(GETTEXT_PACKAGE
, NULL
);
78 const char *realcodeset
= bind_textdomain_codeset(GETTEXT_PACKAGE
, MY_CODESET
);
80 const char *orig
= testcases
[i
].orig
;
81 const char *transl
= gettext(testcases
[i
].orig
);
82 const char *latin1
= testcases
[i
].latin1
;
83 const char *utf8
= testcases
[i
].utf8
;
86 "Old textdomain: %s\n"
87 "New textdomain: %s\n",
92 if (NULL
!= oldcodeset
) {
94 "Old codeset: \"%s\" (locale default)\n",
99 "Old codeset: \"%s\"\n",
105 "Wanted codeset: %s\n"
106 "Real codeset: %s\n",
122 #if defined(CODESET_UTF_8)
123 return (my_streq(transl
, utf8
));
124 #elif defined(CODESET_LATIN_1)
125 return (my_streq(transl
, latin1
));
127 /* make sure my_streq is used once */
128 return (my_streq(orig
, orig
));
137 const char *localeenv
= getenv("LOCALEDIR");
138 const char *localedir
= (localeenv
!=NULL
)?localeenv
:LOCALEDIR
;
139 const char *msgcatdir
= bindtextdomain(GETTEXT_PACKAGE
, localedir
);
141 /* set locale to env settings */
142 const char *oldlocale
= setlocale(LC_ALL
, NULL
);
143 const char *newlocale
= setlocale(LC_ALL
, "");
145 if (localeenv
!= NULL
) {
146 printf("Msg catalog dir: %s (from environment variable LOCALEDIR\n",
149 printf("Msg catalog dir: %s\n", msgcatdir
);
152 if (newlocale
== NULL
) {
153 printf("Locale not available: \"%s\"\n", newlocale
);
154 printf("Aborting without error.\n");
166 for (i
=0; testcases
[i
].locale
!= NULL
; i
++) {
167 const int localelen
= strlen(testcases
[i
].locale
);
168 if (strncmp(newlocale
, testcases
[i
].locale
, localelen
) == 0) {
173 printf("No test case found for locale: %s\n", newlocale
);
178 int main(int argc
, char *argv
[])
181 if ((argc
== 2) && (strcmp("--list", argv
[1]) == 0)) {
183 for (i
=0; testcases
[i
].locale
!= NULL
; i
++) {
184 printf("%s\n", testcases
[i
].locale
);
189 fprintf(stderr
, "Illegal command line. Aborting.\n");
190 fprintf(stderr
, "argc: %03d\n", argc
);
191 for (i
=0; i
<argc
; i
++) {
192 fprintf(stderr
, "%03d \"%s\"\n", i
, argv
[i
]);
198 printf("Test result: %s\n", (ret
)?"success":"failure");