diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 03:50:40 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 03:50:40 +0000 |
commit | fc53809803cd2bc2434e312b19a18fa36776da12 (patch) | |
tree | b4b43bd6538f51965ce32856e9c053d0f90919c8 /src/test/test-format-table.c | |
parent | Adding upstream version 255.5. (diff) | |
download | systemd-fc53809803cd2bc2434e312b19a18fa36776da12.tar.xz systemd-fc53809803cd2bc2434e312b19a18fa36776da12.zip |
Adding upstream version 256.upstream/256
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/test-format-table.c')
-rw-r--r-- | src/test/test-format-table.c | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/src/test/test-format-table.c b/src/test/test-format-table.c index 7d544b1..3dbfda7 100644 --- a/src/test/test-format-table.c +++ b/src/test/test-format-table.c @@ -551,7 +551,7 @@ TEST(vertical) { assert_se(streq(formatted, " pfft aa: foo\n" - " uuu o: 1.0K\n" + " uuu o: 1K\n" "lllllllllllo: jjjjjjjjjjjjjjjjj\n")); _cleanup_(json_variant_unrefp) JsonVariant *a = NULL, *b = NULL; @@ -580,7 +580,7 @@ TEST(path_basename) { assert_se(table_format(t, &formatted) >= 0); - assert_se(streq(formatted, "bar\nbar\nbaz\n")); + ASSERT_STREQ(formatted, "bar\nbar\nbaz\n"); } TEST(dup_cell) { @@ -626,6 +626,41 @@ TEST(dup_cell) { "aaa 0 65535 4294967295 100% ../ hello hello hello\n")); } +TEST(table_bps) { + _cleanup_(table_unrefp) Table *table = NULL; + _cleanup_free_ char *formatted = NULL; + + assert_se(table = table_new("uint64", "size", "bps")); + uint64_t v; + FOREACH_ARGUMENT(v, + 2500, + 10000000, + 20000000, + 25000000, + 1000000000, + 2000000000, + 2500000000) + assert_se(table_add_many(table, + TABLE_UINT64, v, + TABLE_SIZE, v, + TABLE_BPS, v) >= 0); + + table_set_width(table, 50); + assert_se(table_format(table, &formatted) >= 0); + + printf("%s", formatted); + assert_se(streq(formatted, + "UINT64 SIZE BPS\n" + "2500 2.4K 2.5Kbps\n" + "10000000 9.5M 10Mbps\n" + "20000000 19M 20Mbps\n" + "25000000 23.8M 25Mbps\n" + "1000000000 953.6M 1Gbps\n" + "2000000000 1.8G 2Gbps\n" + "2500000000 2.3G 2.5Gbps\n" + )); +} + static int intro(void) { assert_se(setenv("SYSTEMD_COLORS", "0", 1) >= 0); assert_se(setenv("COLUMNS", "40", 1) >= 0); |