]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-locale-util.c
Add SPDX license identifiers to source files under the LGPL
[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 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
11
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
19 ***/
20
21
22 #include "locale-util.h"
23 #include "macro.h"
24 #include "strv.h"
25
26 static void test_get_locales(void) {
27 _cleanup_strv_free_ char **locales = NULL;
28 char **p;
29 int r;
30
31 r = get_locales(&locales);
32 assert_se(r >= 0);
33 assert_se(locales);
34
35 STRV_FOREACH(p, locales) {
36 puts(*p);
37 assert_se(locale_is_valid(*p));
38 }
39 }
40
41 static void test_locale_is_valid(void) {
42 assert_se(locale_is_valid("en_EN.utf8"));
43 assert_se(locale_is_valid("fr_FR.utf8"));
44 assert_se(locale_is_valid("fr_FR@euro"));
45 assert_se(locale_is_valid("fi_FI"));
46 assert_se(locale_is_valid("POSIX"));
47 assert_se(locale_is_valid("C"));
48
49 assert_se(!locale_is_valid(""));
50 assert_se(!locale_is_valid("/usr/bin/foo"));
51 assert_se(!locale_is_valid("\x01gar\x02 bage\x03"));
52 }
53
54 static void test_keymaps(void) {
55 _cleanup_strv_free_ char **kmaps = NULL;
56 char **p;
57 int r;
58
59 assert_se(!keymap_is_valid(""));
60 assert_se(!keymap_is_valid("/usr/bin/foo"));
61 assert_se(!keymap_is_valid("\x01gar\x02 bage\x03"));
62
63 r = get_keymaps(&kmaps);
64 if (r == -ENOENT)
65 return; /* skip test if no keymaps are installed */
66
67 assert_se(r >= 0);
68 assert_se(kmaps);
69
70 STRV_FOREACH(p, kmaps) {
71 puts(*p);
72 assert_se(keymap_is_valid(*p));
73 }
74
75 assert_se(keymap_is_valid("uk"));
76 assert_se(keymap_is_valid("de-nodeadkeys"));
77 assert_se(keymap_is_valid("ANSI-dvorak"));
78 assert_se(keymap_is_valid("unicode"));
79 }
80
81 int main(int argc, char *argv[]) {
82 test_get_locales();
83 test_locale_is_valid();
84
85 test_keymaps();
86
87 return 0;
88 }