From: Zbigniew Jędrzejewski-Szmek Date: Wed, 29 May 2024 15:06:55 +0000 (+0200) Subject: test-format-table: add test for TABLE_BPS formatting X-Git-Tag: v256-rc4~78^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=134bdba832c24d8234f935b19edb5676fc81e282;p=thirdparty%2Fsystemd.git test-format-table: add test for TABLE_BPS formatting --- diff --git a/src/test/test-format-table.c b/src/test/test-format-table.c index c16a5b793b8..4425f4097a2 100644 --- a/src/test/test-format-table.c +++ b/src/test/test-format-table.c @@ -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 2Kbps\n" + "10000000 9.5M 10Mbps\n" + "20000000 19.0M 20Mbps\n" + "25000000 23.8M 25Mbps\n" + "1000000000 953.6M 1Gbps\n" + "2000000000 1.8G 2Gbps\n" + "2500000000 2.3G 2Gbps\n" + )); +} + static int intro(void) { assert_se(setenv("SYSTEMD_COLORS", "0", 1) >= 0); assert_se(setenv("COLUMNS", "40", 1) >= 0);