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