summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorFrantisek Sumsal <frantisek@sumsal.cz>2023-04-15 13:58:20 +0200
committerFrantisek Sumsal <frantisek@sumsal.cz>2023-04-15 23:36:40 +0200
commitcb68860ece01406b51257ce65c065f44c4ab9aaf (patch)
treee3aeaca5ad60324d28fe77f71a7eb6265f6e0a8b /src/test
parent1a127aa02bf9fb0c02e268744d6348c1992207b1 (diff)
downloadsystemd-cb68860ece01406b51257ce65c065f44c4ab9aaf.tar.gz
test: add a test case for table_dup_cell()
Also, sneak in coverage for "less popular" cell types.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test-format-table.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/test/test-format-table.c b/src/test/test-format-table.c
index a1bc8b99ac..7d544b18fd 100644
--- a/src/test/test-format-table.c
+++ b/src/test/test-format-table.c
@@ -583,6 +583,49 @@ TEST(path_basename) {
assert_se(streq(formatted, "bar\nbar\nbaz\n"));
}
+TEST(dup_cell) {
+ _cleanup_(table_unrefp) Table *t = NULL;
+ _cleanup_free_ char *formatted = NULL;
+
+ assert_se(t = table_new("foo", "bar", "x", "baz", ".", "%", "!", "~", "+"));
+ table_set_width(t, 75);
+
+ assert_se(table_add_many(t,
+ TABLE_STRING, "hello",
+ TABLE_UINT8, UINT8_C(42),
+ TABLE_UINT16, UINT16_C(666),
+ TABLE_UINT32, UINT32_C(253),
+ TABLE_PERCENT, 0,
+ TABLE_PATH_BASENAME, "/foo/bar",
+ TABLE_STRING, "aaa",
+ TABLE_STRING, "bbb",
+ TABLE_STRING, "ccc") >= 0);
+
+ /* Add the second row by duping cells */
+ for (size_t i = 0; i < table_get_columns(t); i++)
+ assert_se(table_dup_cell(t, table_get_cell(t, 1, i)) >= 0);
+
+ /* Another row, but dupe the last three strings from the same cell */
+ assert_se(table_add_many(t,
+ TABLE_STRING, "aaa",
+ TABLE_UINT8, UINT8_C(0),
+ TABLE_UINT16, UINT16_C(65535),
+ TABLE_UINT32, UINT32_C(4294967295),
+ TABLE_PERCENT, 100,
+ TABLE_PATH_BASENAME, "../") >= 0);
+
+ for (size_t i = 6; i < table_get_columns(t); i++)
+ assert_se(table_dup_cell(t, table_get_cell(t, 2, 0)) >= 0);
+
+ assert_se(table_format(t, &formatted) >= 0);
+ printf("%s\n", formatted);
+ assert_se(streq(formatted,
+ "FOO BAR X BAZ . % ! ~ +\n"
+ "hello 42 666 253 0% bar aaa bbb ccc\n"
+ "hello 42 666 253 0% bar aaa bbb ccc\n"
+ "aaa 0 65535 4294967295 100% ../ hello hello hello\n"));
+}
+
static int intro(void) {
assert_se(setenv("SYSTEMD_COLORS", "0", 1) >= 0);
assert_se(setenv("COLUMNS", "40", 1) >= 0);