richardphibel / rpms / systemd

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