summaryrefslogtreecommitdiffstats
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.c39
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);