summaryrefslogtreecommitdiff
path: root/src/test/test-format-table.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/test-format-table.c')
-rw-r--r--src/test/test-format-table.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/test/test-format-table.c b/src/test/test-format-table.c
index adcc41416..f94cdf624 100644
--- a/src/test/test-format-table.c
+++ b/src/test/test-format-table.c
@@ -5,6 +5,33 @@
#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;
+
+ assert_se(table = table_new("NAME", "TYPE", "RO", "USAGE", "CREATED", "MODIFIED"));
+ assert_se(table_set_align_percent(table, TABLE_HEADER_CELL(3), 100) >= 0);
+ assert_se(table_add_many(table,
+ TABLE_STRING, "foooo",
+ TABLE_STRING, "raw",
+ TABLE_BOOLEAN, false,
+ TABLE_SIZE, (uint64_t) (673.7*1024*1024),
+ TABLE_STRING, "Wed 2018-07-11 00:10:33 JST",
+ TABLE_STRING, "Wed 2018-07-11 00:16:00 JST") >= 0);
+
+ table_set_width(table, 75);
+ assert_se(table_format(table, &formatted) >= 0);
+
+ printf("%s\n", formatted);
+ assert_se(streq(formatted,
+ "NAME TYPE RO USAGE CREATED MODIFIED \n"
+ "foooo raw no 673.6M Wed 2018-07-11 00:10:33 J… Wed 2018-07-11 00:16:00 JST\n"
+ ));
+}
+
int main(int argc, char *argv[]) {
_cleanup_(table_unrefp) Table *t = NULL;
@@ -50,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,
@@ -80,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);
@@ -96,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",
@@ -134,6 +171,11 @@ 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();
return 0;
}