Merge pull request #3384 from keszybz/localed-keymap

More verbose logging in localed, unit tests, and a few tweaks to keymap conversions
This commit is contained in:
Lennart Poettering
2016-06-13 16:27:52 +02:00
committed by GitHub
6 changed files with 1090 additions and 744 deletions

1
.gitignore vendored
View File

@@ -217,6 +217,7 @@
/test-journal-stream
/test-journal-syslog
/test-journal-verify
/test-keymap-util
/test-libsystemd-sym*
/test-libudev
/test-libudev-sym*

View File

@@ -141,6 +141,10 @@ else
noinst_PROGRAMS =
TESTS =
endif
AM_TESTS_ENVIRONMENT = \
export SYSTEMD_KBD_MODEL_MAP=$(abs_top_srcdir)/src/locale/kbd-model-map; \
export SYSTEMD_LANGUAGE_FALLBACK_MAP=$(abs_top_srcdir)/src/locale/language-fallback-map;
if ENABLE_BASH_COMPLETION
dist_bashcompletion_DATA = $(dist_bashcompletion_data)
nodist_bashcompletion_DATA = $(nodist_bashcompletion_data)
@@ -213,6 +217,7 @@ AM_CPPFLAGS = \
-I $(top_srcdir)/src/shared \
-I $(top_builddir)/src/shared \
-I $(top_srcdir)/src/network \
-I $(top_srcdir)/src/locale \
-I $(top_srcdir)/src/login \
-I $(top_srcdir)/src/journal \
-I $(top_builddir)/src/journal \
@@ -4746,7 +4751,9 @@ BUSNAMES_TARGET_WANTS += \
# ------------------------------------------------------------------------------
if ENABLE_LOCALED
systemd_localed_SOURCES = \
src/locale/localed.c
src/locale/localed.c \
src/locale/keymap-util.c \
src/locale/keymap-util.h
systemd_localed_LDADD = \
libshared.la \
@@ -4784,6 +4791,18 @@ dist_pkgdata_DATA = \
src/locale/kbd-model-map \
src/locale/language-fallback-map
test_keymap_util_SOURCES = \
src/locale/test-keymap-util.c \
src/locale/keymap-util.c \
src/locale/keymap-util.h
test_keymap_util_LDADD = \
libshared.la \
-ldl
tests += \
test-keymap-util
localectl_SOURCES = \
src/locale/localectl.c

724
src/locale/keymap-util.c Normal file

File diff suppressed because it is too large Load Diff

46
src/locale/keymap-util.h Normal file
View File

@@ -0,0 +1,46 @@
/***
This file is part of systemd.
Copyright 2011 Lennart Poettering
Copyright 2013 Kay Sievers
systemd is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "locale-util.h"
typedef struct Context {
char *locale[_VARIABLE_LC_MAX];
char *x11_layout;
char *x11_model;
char *x11_variant;
char *x11_options;
char *vc_keymap;
char *vc_keymap_toggle;
} Context;
int find_converted_keymap(const char *x11_layout, const char *x11_variant, char **new_keymap);
int find_legacy_keymap(Context *c, char **new_keymap);
int find_language_fallback(const char *lang, char **language);
int context_read_data(Context *c);
void context_free(Context *c);
int vconsole_convert_to_x11(Context *c);
int vconsole_write_data(Context *c);
int x11_convert_to_vconsole(Context *c);
int x11_write_data(Context *c);
void locale_simplify(Context *c);
int locale_write_data(Context *c, char ***settings);

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,220 @@
/***
This file is part of systemd.
Copyright 2016 Zbigniew Jędrzejewski-Szmek
systemd is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "alloc-util.h"
#include "keymap-util.h"
#include "log.h"
#include "string-util.h"
static void test_find_language_fallback(void) {
_cleanup_free_ char *ans = NULL, *ans2 = NULL;
log_info("/*** %s ***/", __func__);
assert_se(find_language_fallback("foobar", &ans) == 0);
assert_se(ans == NULL);
assert_se(find_language_fallback("csb", &ans) == 0);
assert_se(ans == NULL);
assert_se(find_language_fallback("csb_PL", &ans) == 1);
assert_se(streq(ans, "csb:pl"));
assert_se(find_language_fallback("szl_PL", &ans2) == 1);
assert_se(streq(ans2, "szl:pl"));
}
static void test_find_converted_keymap(void) {
_cleanup_free_ char *ans = NULL, *ans2 = NULL;
int r;
log_info("/*** %s ***/", __func__);
assert_se(find_converted_keymap("pl", "foobar", &ans) == 0);
assert_se(ans == NULL);
r = find_converted_keymap("pl", NULL, &ans);
if (r == 0) {
log_info("Skipping rest of %s: keymaps are not installed", __func__);
return;
}
assert_se(r == 1);
assert_se(streq(ans, "pl"));
assert_se(find_converted_keymap("pl", "dvorak", &ans) == 1);
assert_se(streq(ans, "pl-dvorak"));
}
static void test_find_legacy_keymap(void) {
Context c = {};
_cleanup_free_ char *ans = NULL, *ans2 = NULL;
log_info("/*** %s ***/", __func__);
c.x11_layout = (char*) "foobar";
assert_se(find_legacy_keymap(&c, &ans) == 0);
assert_se(ans == NULL);
c.x11_layout = (char*) "pl";
assert_se(find_legacy_keymap(&c, &ans) == 1);
assert_se(streq(ans, "pl2"));
c.x11_layout = (char*) "pl,ru";
assert_se(find_legacy_keymap(&c, &ans2) == 1);
assert_se(streq(ans, "pl2"));
}
static void test_vconsole_convert_to_x11(void) {
_cleanup_(context_free) Context c = {};
log_info("/*** %s ***/", __func__);
log_info("/* test emptying first (:) */");
assert_se(free_and_strdup(&c.x11_layout, "foo") >= 0);
assert_se(free_and_strdup(&c.x11_variant, "bar") >= 0);
assert_se(vconsole_convert_to_x11(&c) == 1);
assert_se(c.x11_layout == NULL);
assert_se(c.x11_variant == NULL);
log_info("/* test emptying second (:) */");
assert_se(vconsole_convert_to_x11(&c) == 0);
assert_se(c.x11_layout == NULL);
assert_se(c.x11_variant == NULL);
log_info("/* test without variant, new mapping (es:) */");
assert_se(free_and_strdup(&c.vc_keymap, "es") >= 0);
assert_se(vconsole_convert_to_x11(&c) == 1);
assert_se(streq(c.x11_layout, "es"));
assert_se(c.x11_variant == NULL);
log_info("/* test with known variant, new mapping (es:dvorak) */");
assert_se(free_and_strdup(&c.vc_keymap, "es-dvorak") >= 0);
assert_se(vconsole_convert_to_x11(&c) == 0); // FIXME
assert_se(streq(c.x11_layout, "es"));
assert_se(c.x11_variant == NULL); // FIXME: "dvorak"
log_info("/* test with old mapping (fr:latin9) */");
assert_se(free_and_strdup(&c.vc_keymap, "fr-latin9") >= 0);
assert_se(vconsole_convert_to_x11(&c) == 1);
assert_se(streq(c.x11_layout, "fr"));
assert_se(streq(c.x11_variant, "latin9"));
log_info("/* test with a compound mapping (ru,us) */");
assert_se(free_and_strdup(&c.vc_keymap, "ru") >= 0);
assert_se(vconsole_convert_to_x11(&c) == 1);
assert_se(streq(c.x11_layout, "ru,us"));
assert_se(c.x11_variant == NULL);
log_info("/* test with a simple mapping (us) */");
assert_se(free_and_strdup(&c.vc_keymap, "us") >= 0);
assert_se(vconsole_convert_to_x11(&c) == 1);
assert_se(streq(c.x11_layout, "us"));
assert_se(c.x11_variant == NULL);
}
static void test_x11_convert_to_vconsole(void) {
_cleanup_(context_free) Context c = {};
int r;
log_info("/*** %s ***/", __func__);
log_info("/* test emptying first (:) */");
assert_se(free_and_strdup(&c.vc_keymap, "foobar") >= 0);
assert_se(x11_convert_to_vconsole(&c) == 1);
assert_se(c.vc_keymap == NULL);
log_info("/* test emptying second (:) */");
assert_se(x11_convert_to_vconsole(&c) == 0);
assert_se(c.vc_keymap == NULL);
log_info("/* test without variant, new mapping (es:) */");
assert_se(free_and_strdup(&c.x11_layout, "es") >= 0);
assert_se(x11_convert_to_vconsole(&c) == 1);
assert_se(streq(c.vc_keymap, "es"));
log_info("/* test with unknown variant, new mapping (es:foobar) */");
assert_se(free_and_strdup(&c.x11_variant, "foobar") >= 0);
assert_se(x11_convert_to_vconsole(&c) == 0);
assert_se(streq(c.vc_keymap, "es"));
log_info("/* test with known variant, new mapping (es:dvorak) */");
assert_se(free_and_strdup(&c.x11_variant, "dvorak") >= 0);
r = x11_convert_to_vconsole(&c);
if (r == 0) {
log_info("Skipping rest of %s: keymaps are not installed", __func__);
return;
}
assert_se(r == 1);
assert_se(streq(c.vc_keymap, "es-dvorak"));
log_info("/* test with old mapping (fr:latin9) */");
assert_se(free_and_strdup(&c.x11_layout, "fr") >= 0);
assert_se(free_and_strdup(&c.x11_variant, "latin9") >= 0);
assert_se(x11_convert_to_vconsole(&c) == 1);
assert_se(streq(c.vc_keymap, "fr-latin9"));
log_info("/* test with a compound mapping (us,ru:) */");
assert_se(free_and_strdup(&c.x11_layout, "us,ru") >= 0);
assert_se(free_and_strdup(&c.x11_variant, NULL) >= 0);
assert_se(x11_convert_to_vconsole(&c) == 1);
assert_se(streq(c.vc_keymap, "us"));
log_info("/* test with a compound mapping (ru,us:) */");
assert_se(free_and_strdup(&c.x11_layout, "ru,us") >= 0);
assert_se(free_and_strdup(&c.x11_variant, NULL) >= 0);
assert_se(x11_convert_to_vconsole(&c) == 1);
assert_se(streq(c.vc_keymap, "ru"));
/* https://bugzilla.redhat.com/show_bug.cgi?id=1333998 */
log_info("/* test with a simple new mapping (ru:) */");
assert_se(free_and_strdup(&c.x11_layout, "ru") >= 0);
assert_se(free_and_strdup(&c.x11_variant, NULL) >= 0);
assert_se(x11_convert_to_vconsole(&c) == 0);
assert_se(streq(c.vc_keymap, "ru"));
}
int main(int argc, char **argv) {
log_set_max_level(LOG_DEBUG);
log_parse_environment();
test_find_language_fallback();
test_find_converted_keymap();
test_find_legacy_keymap();
test_vconsole_convert_to_x11();
test_x11_convert_to_vconsole();
return 0;
}