From e3b7da9b85e2fd388ed9d0e5ee1aa7883a392b01 Mon Sep 17 00:00:00 2001 From: Sven Eden Date: Tue, 23 Oct 2018 20:06:23 +0200 Subject: Prep v240: Fix tests running on systems with non-UTF-8 locales. Bug: #85 Closes: #85 Signed-off-by: Sven Eden --- src/test/test-format-table.c | 16 ++++++++++++++++ src/test/test-process-util.c | 9 +++++++++ src/test/test-string-util.c | 24 ++++++++++++++++++++++++ 3 files changed, 49 insertions(+) (limited to 'src/test') diff --git a/src/test/test-format-table.c b/src/test/test-format-table.c index 2527cacbb..f94cdf624 100644 --- a/src/test/test-format-table.c +++ b/src/test/test-format-table.c @@ -5,6 +5,9 @@ #include "string-util.h" #include "time-util.h" +/// Additional includes needed by elogind +#include "locale-util.h" + static void test_issue_9549(void) { _cleanup_(table_unrefp) Table *table = NULL; _cleanup_free_ char *formatted = NULL; @@ -74,6 +77,10 @@ int main(int argc, char *argv[]) { table_set_width(t, 12); assert_se(table_format(t, &formatted) >= 0); + +#if 1 /// elogind supports systems with non-UTF-8 locales, the next would fail there + if (is_locale_utf8()) { +#endif // 1 printf("%s\n", formatted); assert_se(streq(formatted, @@ -104,6 +111,9 @@ int main(int argc, char *argv[]) { "… … …\n")); formatted = mfree(formatted); +#if 1 /// elogind supports systems with non-UTF-8 locales, the previous would fail there + } +#endif // 1 table_set_width(t, (size_t) -1); assert_se(table_set_sort(t, (size_t) 0, (size_t) 2, (size_t) -1) >= 0); @@ -120,6 +130,9 @@ int main(int argc, char *argv[]) { table_set_header(t, false); +#if 1 /// elogind supports systems with non-UTF-8 locales, the next would fail there + if (is_locale_utf8()) { +#endif // 1 assert_se(table_add_many(t, TABLE_STRING, "fäää", TABLE_STRING, "uuu", @@ -158,6 +171,9 @@ int main(int argc, char *argv[]) { " yes fäää yes fäää fäää \n" " yes xxx yes xxx xxx \n" "5min 5min \n")); +#if 1 /// elogind supports systems with non-UTF-8 locales, the previous would fail there + } +#endif // 1 test_issue_9549(); diff --git a/src/test/test-process-util.c b/src/test/test-process-util.c index f19875dae..6f0472dc0 100644 --- a/src/test/test-process-util.c +++ b/src/test/test-process-util.c @@ -27,6 +27,9 @@ #include "util.h" #include "virt.h" +/// Additional includes needed by elogind +#include "locale-util.h" + static void test_get_process_comm(pid_t pid) { struct stat st; _cleanup_free_ char *a = NULL, *c = NULL, *d = NULL, *f = NULL, *i = NULL; @@ -113,12 +116,18 @@ static void test_get_process_comm_escape(void) { test_get_process_comm_escape_one("foo", "foo"); test_get_process_comm_escape_one("012345678901234", "012345678901234"); test_get_process_comm_escape_one("0123456789012345", "012345678901234"); +#if 1 /// elogind supports systems with non-UTF-8 locales, the next would fail there + if (is_locale_utf8()) { +#endif // 1 test_get_process_comm_escape_one("äöüß", "\\303\\244\\303…"); test_get_process_comm_escape_one("xäöüß", "x\\303\\244…"); test_get_process_comm_escape_one("xxäöüß", "xx\\303\\244…"); test_get_process_comm_escape_one("xxxäöüß", "xxx\\303\\244…"); test_get_process_comm_escape_one("xxxxäöüß", "xxxx\\303\\244…"); test_get_process_comm_escape_one("xxxxxäöüß", "xxxxx\\303…"); +#if 1 /// elogind supports systems with non-UTF-8 locales, the previous would fail there + } +#endif // 1 assert_se(prctl(PR_SET_NAME, saved) >= 0); } diff --git a/src/test/test-string-util.c b/src/test/test-string-util.c index 2d10041b2..54f9b29ef 100644 --- a/src/test/test-string-util.c +++ b/src/test/test-string-util.c @@ -171,6 +171,9 @@ static void test_cellescape(void) { assert_se(streq(cellescape(buf, 1, "\020"), "")); assert_se(streq(cellescape(buf, 2, "\020"), ".")); assert_se(streq(cellescape(buf, 3, "\020"), "..")); +#if 1 /// elogind supports systems with non-UTF-8 locales, the next would fail there + if (is_locale_utf8()) { +#endif // 1 assert_se(streq(cellescape(buf, 4, "\020"), "…")); assert_se(streq(cellescape(buf, 5, "\020"), "\\020")); @@ -178,26 +181,47 @@ static void test_cellescape(void) { assert_se(streq(cellescape(buf, 6, "1234\020"), "12…")); assert_se(streq(cellescape(buf, 7, "1234\020"), "123…")); assert_se(streq(cellescape(buf, 8, "1234\020"), "1234…")); +#if 1 /// elogind supports systems with non-UTF-8 locales, the previous would fail there + } +#endif // 1 assert_se(streq(cellescape(buf, 9, "1234\020"), "1234\\020")); assert_se(streq(cellescape(buf, 1, "\t\n"), "")); assert_se(streq(cellescape(buf, 2, "\t\n"), ".")); assert_se(streq(cellescape(buf, 3, "\t\n"), "..")); +#if 1 /// elogind supports systems with non-UTF-8 locales, the next would fail there + if (is_locale_utf8()) { +#endif // 1 assert_se(streq(cellescape(buf, 4, "\t\n"), "…")); +#if 1 /// elogind supports systems with non-UTF-8 locales, the previous would fail there + } +#endif // 1 assert_se(streq(cellescape(buf, 5, "\t\n"), "\\t\\n")); +#if 1 /// elogind supports systems with non-UTF-8 locales, the next would fail there + if (is_locale_utf8()) { +#endif // 1 assert_se(streq(cellescape(buf, 5, "1234\t\n"), "1…")); assert_se(streq(cellescape(buf, 6, "1234\t\n"), "12…")); assert_se(streq(cellescape(buf, 7, "1234\t\n"), "123…")); assert_se(streq(cellescape(buf, 8, "1234\t\n"), "1234…")); +#if 1 /// elogind supports systems with non-UTF-8 locales, the previous would fail there + } +#endif // 1 assert_se(streq(cellescape(buf, 9, "1234\t\n"), "1234\\t\\n")); +#if 1 /// elogind supports systems with non-UTF-8 locales, the next would fail there + if (is_locale_utf8()) { +#endif // 1 assert_se(streq(cellescape(buf, 4, "x\t\020\n"), "…")); assert_se(streq(cellescape(buf, 5, "x\t\020\n"), "x…")); assert_se(streq(cellescape(buf, 6, "x\t\020\n"), "x…")); assert_se(streq(cellescape(buf, 7, "x\t\020\n"), "x\\t…")); assert_se(streq(cellescape(buf, 8, "x\t\020\n"), "x\\t…")); assert_se(streq(cellescape(buf, 9, "x\t\020\n"), "x\\t…")); +#if 1 /// elogind supports systems with non-UTF-8 locales, the previous would fail there + } +#endif // 1 assert_se(streq(cellescape(buf, 10, "x\t\020\n"), "x\\t\\020\\n")); assert_se(streq(cellescape(buf, 6, "1\011"), "1\\t")); -- cgit v1.2.3