test: Add tests for isd_get_commercial_credit()
[libisds.git] / test / offline / utf82locale.c
blob3616d15d654090874e537e0cdf86da21585ecfc2
1 #include "../test.h"
2 #include "utils.h"
3 #include <locale.h>
5 static int prepare_locale(_Bool utf8) {
6 char *old_locale;
8 if (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;
14 } else {
15 old_locale = setlocale(LC_ALL, "C");
16 if (old_locale != NULL) return 0;
19 return -1;
22 static int test_utf82locale(const void *input, const void *correct) {
23 void *output = NULL;
25 output = _isds_utf82locale(input);
27 TEST_STRING_DUPLICITY(correct, output);
29 free(output);
30 PASS_TEST;
34 int main(int argc, char **argv) {
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ý",
44 "Ší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);
53 SUM_TEST();