naccyde / rpms / systemd

Forked from rpms/systemd a year ago
Clone
87d178
From 3d08c7971a80370f60dd14b068779851e0f82c24 Mon Sep 17 00:00:00 2001
87d178
From: Lennart Poettering <lennart@poettering.net>
87d178
Date: Thu, 30 Apr 2020 18:32:55 +0200
87d178
Subject: [PATCH] test: add test case for locale_is_installed()
87d178
87d178
(cherry picked from commit b45b0a69bb7ef3e6e66d443eae366b6d1c387cab)
87d178
87d178
Related: #1755287
87d178
---
87d178
 src/test/test-locale-util.c | 23 +++++++++++++++++++++++
87d178
 1 file changed, 23 insertions(+)
87d178
87d178
diff --git a/src/test/test-locale-util.c b/src/test/test-locale-util.c
87d178
index 0c3f6a62ed..0d50c33ce5 100644
87d178
--- a/src/test/test-locale-util.c
87d178
+++ b/src/test/test-locale-util.c
87d178
@@ -34,6 +34,28 @@ static void test_locale_is_valid(void) {
87d178
         assert_se(!locale_is_valid("\x01gar\x02 bage\x03"));
87d178
 }
87d178
 
87d178
+static void test_locale_is_installed(void) {
87d178
+        log_info("/* %s */", __func__);
87d178
+
87d178
+        /* Always available */
87d178
+        assert_se(locale_is_installed("POSIX") > 0);
87d178
+        assert_se(locale_is_installed("C") > 0);
87d178
+
87d178
+        /* Might, or might not be installed. */
87d178
+        assert_se(locale_is_installed("en_EN.utf8") >= 0);
87d178
+        assert_se(locale_is_installed("fr_FR.utf8") >= 0);
87d178
+        assert_se(locale_is_installed("fr_FR@euro") >= 0);
87d178
+        assert_se(locale_is_installed("fi_FI") >= 0);
87d178
+
87d178
+        /* Definitely not valid */
87d178
+        assert_se(locale_is_installed("") == 0);
87d178
+        assert_se(locale_is_installed("/usr/bin/foo") == 0);
87d178
+        assert_se(locale_is_installed("\x01gar\x02 bage\x03") == 0);
87d178
+
87d178
+        /* Definitely not installed */
87d178
+        assert_se(locale_is_installed("zz_ZZ") == 0);
87d178
+}
87d178
+
87d178
 static void test_keymaps(void) {
87d178
         _cleanup_strv_free_ char **kmaps = NULL;
87d178
         char **p;
87d178
@@ -95,6 +117,7 @@ static void dump_special_glyphs(void) {
87d178
 int main(int argc, char *argv[]) {
87d178
         test_get_locales();
87d178
         test_locale_is_valid();
87d178
+        test_locale_is_installed();
87d178
         test_keymaps();
87d178
 
87d178
         dump_special_glyphs();