]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-keymap-util: use kbd-model-map/language-fallback-map from $(srcdir) 3384/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 4 Jun 2016 22:15:42 +0000 (18:15 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 11 Jun 2016 15:24:06 +0000 (11:24 -0400)
This adds (undocumented) environment variables SYSTEMD_KBD_MODEL_MAP
and SYSTEMD_LANGUAGE_FALLBACK_MAP, which, if set, override compiled-in
locations of those two files.

Instead of skipping tests when the maps are not installed, just use
the one from the source dir. We still cannot do the mappings the other
way if /usr/lib/kbd/keymaps is not present, so truncate the tests in
that case.

Also tweak the debug messages a bit to make it easier to see
which function is failing.

Makefile.am
src/locale/keymap-util.c
src/locale/test-keymap-util.c

index fc6f3bf6d5442c35918af9657c4430a8a972e7e5..de3013567eecc40eef77669b2c0344b747bd0500 100644 (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)
index 17bef9e481d856784a360c47fc7f5fcfc97aee75..a6bcd1ad54be14e5860f75ecb126684562431144 100644 (file)
@@ -46,6 +46,26 @@ static const char* strnulldash(const char *s) {
         return isempty(s) || streq(s, "-") ? NULL : s;
 }
 
+static const char* systemd_kbd_model_map(void) {
+        const char* s;
+
+        s = getenv("SYSTEMD_KBD_MODEL_MAP");
+        if (s)
+                return s;
+
+        return SYSTEMD_KBD_MODEL_MAP;
+}
+
+static const char* systemd_language_fallback_map(void) {
+        const char* s;
+
+        s = getenv("SYSTEMD_LANGUAGE_FALLBACK_MAP");
+        if (s)
+                return s;
+
+        return SYSTEMD_LANGUAGE_FALLBACK_MAP;
+}
+
 static void context_free_x11(Context *c) {
         c->x11_layout = mfree(c->x11_layout);
         c->x11_options = mfree(c->x11_options);
@@ -427,8 +447,11 @@ static int read_next_mapping(const char* filename,
 }
 
 int vconsole_convert_to_x11(Context *c) {
+        const char *map;
         int modified = -1;
 
+        map = systemd_kbd_model_map();
+
         if (isempty(c->vc_keymap)) {
                 modified =
                         !isempty(c->x11_layout) ||
@@ -441,7 +464,7 @@ int vconsole_convert_to_x11(Context *c) {
                 _cleanup_fclose_ FILE *f = NULL;
                 unsigned n = 0;
 
-                f = fopen(SYSTEMD_KBD_MODEL_MAP, "re");
+                f = fopen(map, "re");
                 if (!f)
                         return -errno;
 
@@ -449,7 +472,7 @@ int vconsole_convert_to_x11(Context *c) {
                         _cleanup_strv_free_ char **a = NULL;
                         int r;
 
-                        r = read_next_mapping(SYSTEMD_KBD_MODEL_MAP, 5, UINT_MAX, f, &n, &a);
+                        r = read_next_mapping(map, 5, UINT_MAX, f, &n, &a);
                         if (r < 0)
                                 return r;
                         if (r == 0)
@@ -526,14 +549,17 @@ int find_converted_keymap(const char *x11_layout, const char *x11_variant, char
 }
 
 int find_legacy_keymap(Context *c, char **new_keymap) {
-        _cleanup_fclose_ FILE *f;
+        const char *map;
+        _cleanup_fclose_ FILE *f = NULL;
         unsigned n = 0;
         unsigned best_matching = 0;
         int r;
 
         assert(!isempty(c->x11_layout));
 
-        f = fopen(SYSTEMD_KBD_MODEL_MAP, "re");
+        map = systemd_kbd_model_map();
+
+        f = fopen(map, "re");
         if (!f)
                 return -errno;
 
@@ -541,7 +567,7 @@ int find_legacy_keymap(Context *c, char **new_keymap) {
                 _cleanup_strv_free_ char **a = NULL;
                 unsigned matching = 0;
 
-                r = read_next_mapping(SYSTEMD_KBD_MODEL_MAP, 5, UINT_MAX, f, &n, &a);
+                r = read_next_mapping(map, 5, UINT_MAX, f, &n, &a);
                 if (r < 0)
                         return r;
                 if (r == 0)
@@ -619,13 +645,16 @@ int find_legacy_keymap(Context *c, char **new_keymap) {
 }
 
 int find_language_fallback(const char *lang, char **language) {
+        const char *map;
         _cleanup_fclose_ FILE *f = NULL;
         unsigned n = 0;
 
         assert(lang);
         assert(language);
 
-        f = fopen(SYSTEMD_LANGUAGE_FALLBACK_MAP, "re");
+        map = systemd_language_fallback_map();
+
+        f = fopen(map, "re");
         if (!f)
                 return -errno;
 
@@ -633,7 +662,7 @@ int find_language_fallback(const char *lang, char **language) {
                 _cleanup_strv_free_ char **a = NULL;
                 int r;
 
-                r = read_next_mapping(SYSTEMD_LANGUAGE_FALLBACK_MAP, 2, 2, f, &n, &a);
+                r = read_next_mapping(map, 2, 2, f, &n, &a);
                 if (r <= 0)
                         return r;
 
index 1e30fa4cb0566fa75d7924c3191e998a3eb83e69..7e2c9e505a9876ade84c66514158a2cdc77d31e3 100644 (file)
 
 static void test_find_language_fallback(void) {
         _cleanup_free_ char *ans = NULL, *ans2 = NULL;
-        int r;
 
-        log_info("/* %s */", __func__);
+        log_info("/*** %s ***/", __func__);
 
-        r = find_language_fallback("foobar", &ans);
-        if (r == -ENOENT) {
-                log_info_errno(r, "Skipping language fallback tests: %m");
-                return;
-        }
-        assert_se(r == 0);
+        assert_se(find_language_fallback("foobar", &ans) == 0);
         assert_se(ans == NULL);
 
         assert_se(find_language_fallback("csb", &ans) == 0);
@@ -50,16 +44,17 @@ static void test_find_converted_keymap(void) {
         _cleanup_free_ char *ans = NULL, *ans2 = NULL;
         int r;
 
-        log_info("/* %s */", __func__);
+        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_errno(r, "Skipping find_converted_keymap tests: %m");
+                log_info("Skipping rest of %s: keymaps are not installed", __func__);
                 return;
         }
+
         assert_se(r == 1);
         assert_se(streq(ans, "pl"));
 
@@ -70,17 +65,11 @@ static void test_find_converted_keymap(void) {
 static void test_find_legacy_keymap(void) {
         Context c = {};
         _cleanup_free_ char *ans = NULL, *ans2 = NULL;
-        int r;
 
-        log_info("/* %s */", __func__);
+        log_info("/*** %s ***/", __func__);
 
         c.x11_layout = (char*) "foobar";
-        r = find_legacy_keymap(&c, &ans);
-        if (r == -ENOENT) {
-                log_info_errno(r, "Skipping test_legacy_keymap tests: %m");
-                return;
-        }
-        assert_se(r == 0);
+        assert_se(find_legacy_keymap(&c, &ans) == 0);
         assert_se(ans == NULL);
 
         c.x11_layout = (char*) "pl";
@@ -95,7 +84,7 @@ static void test_find_legacy_keymap(void) {
 static void test_vconsole_convert_to_x11(void) {
         _cleanup_(context_free) Context c = {};
 
-        log_info("/* %s */", __func__);
+        log_info("/*** %s ***/", __func__);
 
         log_info("/* test emptying first (:) */");
         assert_se(free_and_strdup(&c.x11_layout, "foo") >= 0);
@@ -148,8 +137,9 @@ static void test_vconsole_convert_to_x11(void) {
 
 static void test_x11_convert_to_vconsole(void) {
         _cleanup_(context_free) Context c = {};
+        int r;
 
-        log_info("/* %s */", __func__);
+        log_info("/*** %s ***/", __func__);
 
         log_info("/* test emptying first (:) */");
         assert_se(free_and_strdup(&c.vc_keymap, "foobar") >= 0);
@@ -176,7 +166,13 @@ static void test_x11_convert_to_vconsole(void) {
         log_info("/* test with known variant, new mapping (es:dvorak) */");
         assert_se(free_and_strdup(&c.x11_variant, "dvorak") >= 0);
 
-        assert_se(x11_convert_to_vconsole(&c) == 1);
+        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) */");