chiark / gitweb /
tree-wide: drop copyright headers from frequent contributors
[elogind.git] / src / test / test-locale-util.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include "locale-util.h"
4 #include "macro.h"
5 #include "strv.h"
6
7 static void test_get_locales(void) {
8         _cleanup_strv_free_ char **locales = NULL;
9         char **p;
10         int r;
11
12         r = get_locales(&locales);
13         assert_se(r >= 0);
14         assert_se(locales);
15
16         STRV_FOREACH(p, locales) {
17                 puts(*p);
18                 assert_se(locale_is_valid(*p));
19         }
20 }
21
22 static void test_locale_is_valid(void) {
23         log_info("/* %s */", __func__);
24
25         assert_se(locale_is_valid("en_EN.utf8"));
26         assert_se(locale_is_valid("fr_FR.utf8"));
27         assert_se(locale_is_valid("fr_FR@euro"));
28         assert_se(locale_is_valid("fi_FI"));
29         assert_se(locale_is_valid("POSIX"));
30         assert_se(locale_is_valid("C"));
31
32         assert_se(!locale_is_valid(""));
33         assert_se(!locale_is_valid("/usr/bin/foo"));
34         assert_se(!locale_is_valid("\x01gar\x02 bage\x03"));
35 }
36
37 static void test_keymaps(void) {
38         _cleanup_strv_free_ char **kmaps = NULL;
39         char **p;
40         int r;
41
42         log_info("/* %s */", __func__);
43
44         assert_se(!keymap_is_valid(""));
45         assert_se(!keymap_is_valid("/usr/bin/foo"));
46         assert_se(!keymap_is_valid("\x01gar\x02 bage\x03"));
47
48         r = get_keymaps(&kmaps);
49         if (r == -ENOENT)
50                 return; /* skip test if no keymaps are installed */
51
52         assert_se(r >= 0);
53         assert_se(kmaps);
54
55         STRV_FOREACH(p, kmaps) {
56                 puts(*p);
57                 assert_se(keymap_is_valid(*p));
58         }
59
60         assert_se(keymap_is_valid("uk"));
61         assert_se(keymap_is_valid("de-nodeadkeys"));
62         assert_se(keymap_is_valid("ANSI-dvorak"));
63         assert_se(keymap_is_valid("unicode"));
64 }
65
66 #define dump_glyph(x) log_info(STRINGIFY(x) ": %s", special_glyph(x))
67 static void dump_special_glyphs(void) {
68         assert_cc(ELLIPSIS + 1 == _SPECIAL_GLYPH_MAX);
69
70         log_info("/* %s */", __func__);
71
72         log_info("is_locale_utf8: %s", yes_no(is_locale_utf8()));
73
74         dump_glyph(TREE_VERTICAL);
75         dump_glyph(TREE_BRANCH);
76         dump_glyph(TREE_RIGHT);
77         dump_glyph(TREE_SPACE);
78         dump_glyph(TRIANGULAR_BULLET);
79         dump_glyph(BLACK_CIRCLE);
80         dump_glyph(ARROW);
81         dump_glyph(MDASH);
82         dump_glyph(ELLIPSIS);
83 }
84
85 int main(int argc, char *argv[]) {
86         test_get_locales();
87         test_locale_is_valid();
88         test_keymaps();
89
90         dump_special_glyphs();
91
92         return 0;
93 }