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