tests: make tests pass with non-utf8 locale
authorAdrian Szyndela <adrian.s@samsung.com>
Fri, 27 Mar 2020 15:29:24 +0000 (16:29 +0100)
committerAdrian Szyndela <adrian.s@samsung.com>
Thu, 2 Apr 2020 09:49:00 +0000 (11:49 +0200)
src/test/test-format-table.c
src/test/test-string-util.c

index 96b1d77..0f7fc4a 100644 (file)
@@ -4,6 +4,7 @@
 
 #include "alloc-util.h"
 #include "format-table.h"
+#include "locale-util.h"
 #include "string-util.h"
 #include "time-util.h"
 
@@ -25,10 +26,16 @@ static void test_issue_9549(void) {
         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"
-                        ));
+        if (is_locale_utf8())
+                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"
+                                ));
+        else
+                assert_se(streq(formatted,
+                                "NAME  TYPE RO  USAGE CREATED                    MODIFIED                   \n"
+                                "foooo raw  no 673.6M Wed 2018-07-11 00:10:33... Wed 2018-07-11 00:16:00 JST\n"
+                                ));
 }
 
 int main(int argc, char *argv[]) {
@@ -80,10 +87,16 @@ int main(int argc, char *argv[]) {
         assert_se(table_format(t, &formatted) >= 0);
         printf("%s\n", formatted);
 
-        assert_se(streq(formatted,
-                        "ONE TWO THR…\n"
-                        "xxx yyy  yes\n"
-                        "a … YYY   no\n"));
+        if (is_locale_utf8())
+                assert_se(streq(formatted,
+                                "ONE TWO THR…\n"
+                                "xxx yyy  yes\n"
+                                "a … YYY   no\n"));
+        else
+                assert_se(streq(formatted,
+                                "ONE TWO T...\n"
+                                "xxx yyy  yes\n"
+                                "... YYY   no\n"));
 
         formatted = mfree(formatted);
 
@@ -91,10 +104,16 @@ int main(int argc, char *argv[]) {
         assert_se(table_format(t, &formatted) >= 0);
         printf("%s\n", formatted);
 
-        assert_se(streq(formatted,
-                        "… … …\n"
-                        "… … …\n"
-                        "… … …\n"));
+        if (is_locale_utf8())
+                assert_se(streq(formatted,
+                                "… … …\n"
+                                "… … …\n"
+                                "… … …\n"));
+        else
+                assert_se(streq(formatted,
+                                ". . .\n"
+                                ". . .\n"
+                                ". . .\n"));
 
         formatted = mfree(formatted);
 
@@ -102,10 +121,16 @@ int main(int argc, char *argv[]) {
         assert_se(table_format(t, &formatted) >= 0);
         printf("%s\n", formatted);
 
-        assert_se(streq(formatted,
-                        "… … …\n"
-                        "… … …\n"
-                        "… … …\n"));
+        if (is_locale_utf8())
+                assert_se(streq(formatted,
+                                "… … …\n"
+                                "… … …\n"
+                                "… … …\n"));
+        else
+                assert_se(streq(formatted,
+                                ". . .\n"
+                                ". . .\n"
+                                ". . .\n"));
 
         formatted = mfree(formatted);
 
@@ -156,14 +181,22 @@ int main(int argc, char *argv[]) {
         assert_se(table_format(t, &formatted) >= 0);
         printf("%s\n", formatted);
 
-        if (isatty(STDOUT_FILENO))
-                assert_se(streq(formatted,
-                                "  no a long f…   no a long f… a long fi…\n"
-                                "  no fäää        no fäää      fäää      \n"
-                                " yes fäää       yes fäää      fäää      \n"
-                                " yes xxx        yes xxx       xxx       \n"
-                                "5min           5min                     \n"));
-        else
+        if (isatty(STDOUT_FILENO)) {
+                if (is_locale_utf8())
+                        assert_se(streq(formatted,
+                                        "  no a long f…   no a long f… a long fi…\n"
+                                        "  no fäää        no fäää      fäää      \n"
+                                        " yes fäää       yes fäää      fäää      \n"
+                                        " yes xxx        yes xxx       xxx       \n"
+                                        "5min           5min                     \n"));
+                else
+                        assert_se(streq(formatted,
+                                        "  no a long...   no a long... a long ...\n"
+                                        "  no fäää        no fäää      fäää      \n"
+                                        " yes fäää       yes fäää      fäää      \n"
+                                        " yes xxx        yes xxx       xxx       \n"
+                                        "5min           5min                     \n"));
+        } else
                 assert_se(streq(formatted,
                                 "  no a long field   no a long field a long field\n"
                                 "  no fäää           no fäää         fäää        \n"
index 8ea3994..1bee154 100644 (file)
@@ -147,33 +147,33 @@ 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"), ".."));
-        assert_se(streq(cellescape(buf, 4, "\020"), "…"));
+        assert_se(streq(cellescape(buf, 4, "\020"), is_locale_utf8() ? "…" : "..."));
         assert_se(streq(cellescape(buf, 5, "\020"), "\\020"));
 
-        assert_se(streq(cellescape(buf, 5, "1234\020"), "1…"));
-        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…"));
+        assert_se(streq(cellescape(buf, 5, "1234\020"), is_locale_utf8() ? "1…" : "1..."));
+        assert_se(streq(cellescape(buf, 6, "1234\020"), is_locale_utf8() ? "12…" : "12..."));
+        assert_se(streq(cellescape(buf, 7, "1234\020"), is_locale_utf8() ? "123…" : "123..."));
+        assert_se(streq(cellescape(buf, 8, "1234\020"), is_locale_utf8() ? "1234…" : "1234..."));
         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"), ".."));
-        assert_se(streq(cellescape(buf, 4, "\t\n"), "…"));
+        assert_se(streq(cellescape(buf, 4, "\t\n"), is_locale_utf8() ? "…" : "..."));
         assert_se(streq(cellescape(buf, 5, "\t\n"), "\\t\\n"));
 
-        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…"));
+        assert_se(streq(cellescape(buf, 5, "1234\t\n"), is_locale_utf8() ? "1…" : "1..."));
+        assert_se(streq(cellescape(buf, 6, "1234\t\n"), is_locale_utf8() ? "12…" : "12..."));
+        assert_se(streq(cellescape(buf, 7, "1234\t\n"), is_locale_utf8() ? "123…" : "123..."));
+        assert_se(streq(cellescape(buf, 8, "1234\t\n"), is_locale_utf8() ? "1234…" : "1234..."));
         assert_se(streq(cellescape(buf, 9, "1234\t\n"), "1234\\t\\n"));
 
-        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…"));
+        assert_se(streq(cellescape(buf, 4, "x\t\020\n"), is_locale_utf8() ? "…" : "..."));
+        assert_se(streq(cellescape(buf, 5, "x\t\020\n"), is_locale_utf8() ? "x…" : "x..."));
+        assert_se(streq(cellescape(buf, 6, "x\t\020\n"), is_locale_utf8() ? "x…" : "x..."));
+        assert_se(streq(cellescape(buf, 7, "x\t\020\n"), is_locale_utf8() ? "x\\t…" : "x\\t..."));
+        assert_se(streq(cellescape(buf, 8, "x\t\020\n"), is_locale_utf8() ? "x\\t…" : "x\\t..."));
+        assert_se(streq(cellescape(buf, 9, "x\t\020\n"), is_locale_utf8() ? "x\\t…" : "x\\t..."));
         assert_se(streq(cellescape(buf, 10, "x\t\020\n"), "x\\t\\020\\n"));
 
         assert_se(streq(cellescape(buf, 6, "1\011"), "1\\t"));