chiark / gitweb /
tree-wide: drop license boilerplate
[elogind.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
9 #include "locale-util.h"
10 #include "macro.h"
11 #include "strv.h"
12
13 static void test_get_locales(void) {
14         _cleanup_strv_free_ char **locales = NULL;
15         char **p;
16         int r;
17
18         r = get_locales(&locales);
19         assert_se(r >= 0);
20         assert_se(locales);
21
22         STRV_FOREACH(p, locales) {
23                 puts(*p);
24                 assert_se(locale_is_valid(*p));
25         }
26 }
27
28 static void test_locale_is_valid(void) {
29         assert_se(locale_is_valid("en_EN.utf8"));
30         assert_se(locale_is_valid("fr_FR.utf8"));
31         assert_se(locale_is_valid("fr_FR@euro"));
32         assert_se(locale_is_valid("fi_FI"));
33         assert_se(locale_is_valid("POSIX"));
34         assert_se(locale_is_valid("C"));
35
36         assert_se(!locale_is_valid(""));
37         assert_se(!locale_is_valid("/usr/bin/foo"));
38         assert_se(!locale_is_valid("\x01gar\x02 bage\x03"));
39 }
40
41 static void test_keymaps(void) {
42         _cleanup_strv_free_ char **kmaps = NULL;
43         char **p;
44         int r;
45
46         assert_se(!keymap_is_valid(""));
47         assert_se(!keymap_is_valid("/usr/bin/foo"));
48         assert_se(!keymap_is_valid("\x01gar\x02 bage\x03"));
49
50         r = get_keymaps(&kmaps);
51         if (r == -ENOENT)
52                 return; /* skip test if no keymaps are installed */
53
54         assert_se(r >= 0);
55         assert_se(kmaps);
56
57         STRV_FOREACH(p, kmaps) {
58                 puts(*p);
59                 assert_se(keymap_is_valid(*p));
60         }
61
62         assert_se(keymap_is_valid("uk"));
63         assert_se(keymap_is_valid("de-nodeadkeys"));
64         assert_se(keymap_is_valid("ANSI-dvorak"));
65         assert_se(keymap_is_valid("unicode"));
66 }
67
68 int main(int argc, char *argv[]) {
69         test_get_locales();
70         test_locale_is_valid();
71
72         test_keymaps();
73
74         return 0;
75 }