]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test/test-locale-util.c
Merge pull request #8417 from brauner/2018-03-09/add_bind_mount_fallback_to_private_d...
[thirdparty/systemd.git] / src / test / test-locale-util.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
2b89a960
RC
2/***
3 This file is part of systemd
4
5 Copyright 2014 Ronny Chevalier
2b89a960
RC
6***/
7
2b89a960
RC
8
9#include "locale-util.h"
2b89a960 10#include "macro.h"
cf0fbc49 11#include "strv.h"
2b89a960
RC
12
13static 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
28static 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
ed457f13
TB
41static 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
2b89a960
RC
68int main(int argc, char *argv[]) {
69 test_get_locales();
70 test_locale_is_valid();
71
ed457f13
TB
72 test_keymaps();
73
2b89a960
RC
74 return 0;
75}