5 static int prepare_locale(_Bool utf8
) {
9 old_locale
= setlocale(LC_ALL
, "en_US.UTF-8");
10 if (old_locale
!= NULL
) return 0;
12 old_locale
= setlocale(LC_ALL
, "cs_CZ.UTF-8");
13 if (old_locale
!= NULL
) return 0;
15 old_locale
= setlocale(LC_ALL
, "C");
16 if (old_locale
!= NULL
) return 0;
22 static int test_utf82locale(const void *input
, const void *correct
) {
25 output
= _isds_utf82locale(input
);
26 TEST_DESTRUCTOR(free
, output
);
28 TEST_STRING_DUPLICITY(correct
, output
);
35 INIT_TEST("utf8locale");
37 if (prepare_locale(1))
38 ABORT_UNIT("Could not set any UTF-8 locale");
40 TEST("NULL input", test_utf82locale
, NULL
, NULL
);
41 TEST("Empty string", test_utf82locale
, "", "");
42 TEST("ASCII text", test_utf82locale
, "lazy fox", "lazy fox");
43 TEST("non-ASCII text in UTF-8 locale", test_utf82locale
, "Šíleně žluťoučký",
45 TEST("OTP message in UTF-8 locale", test_utf82locale
,
46 "Jednorázový kód odeslán.", "Jednorázový kód odeslán.");
48 if (prepare_locale(0))
49 ABORT_UNIT("Could not set C locale");
51 TEST("non-ASCII text in C locale", test_utf82locale
, "Šíleně žluťoučký", NULL
);