From: Peter Krempa <[email protected]>

The new test case iterates over all combinations and tries the
formatting of the table with strings of 3 distinct lengths (1 char, 8
chars and maximum widht that fits in the column (8+3 characters)).

Signed-off-by: Peter Krempa <[email protected]>
---
 tests/vshtabletest.c                         | 68 ++++++++++++++++++++
 tests/vshtabletestdata/testRowsWithFlags.out | 24 +++++++
 2 files changed, 92 insertions(+)
 create mode 100644 tests/vshtabletestdata/testRowsWithFlags.out

diff --git a/tests/vshtabletest.c b/tests/vshtabletest.c
index bb75a41418..e4c670d27f 100644
--- a/tests/vshtabletest.c
+++ b/tests/vshtabletest.c
@@ -316,6 +316,71 @@ testNTables(const void *opaque G_GNUC_UNUSED)
     return 0;
 }

+
+static int
+testRowsWithFlags(const void *opaque G_GNUC_UNUSED)
+{
+    g_autoptr(vshTable) t = vshTableNew("comment", "|", "content", "|", NULL);
+    g_autofree char *act  = NULL;
+    unsigned int fl;
+    unsigned int maxfl = VSH_TABLE_CELL_SKIP_LEADING | 
VSH_TABLE_CELL_SKIP_TRAILING | VSH_TABLE_CELL_ALIGN_RIGHT;
+
+    for (fl = 0; fl <= maxfl; fl++) {
+        size_t maxlen = 8;
+        g_auto(virBuffer) b = VIR_BUFFER_INITIALIZER;
+        g_auto(virBuffer) n = VIR_BUFFER_INITIALIZER;
+        size_t i;
+
+        virBufferAddLit(&n, "base");
+
+        if (fl & VSH_TABLE_CELL_SKIP_LEADING) {
+            maxlen += 1;
+            virBufferAddLit(&n, "+skip_leading");
+        }
+
+        if (fl & VSH_TABLE_CELL_SKIP_TRAILING) {
+            maxlen += 2;
+            virBufferAddLit(&n, "+skip_trailing");
+        }
+
+        if (fl & VSH_TABLE_CELL_ALIGN_RIGHT) {
+            virBufferAddLit(&n, "+align_right");
+        }
+
+        for (i = 0; i < maxlen; i++)
+            virBufferAddChar(&b, 'b');
+
+        vshTableRowAppendFlags(t,
+                               VSH_TABLE_CELL_DEFAULT, 
virBufferCurrentContent(&n),
+                               VSH_TABLE_CELL_SKIP_LEADING | 
VSH_TABLE_CELL_SKIP_TRAILING, "|",
+                               fl, "short",
+                               VSH_TABLE_CELL_SKIP_LEADING | 
VSH_TABLE_CELL_SKIP_TRAILING, "|",
+                               0, NULL);
+
+        vshTableRowAppendFlags(t,
+                               VSH_TABLE_CELL_DEFAULT, 
virBufferCurrentContent(&n),
+                               VSH_TABLE_CELL_SKIP_LEADING | 
VSH_TABLE_CELL_SKIP_TRAILING, "|",
+                               fl, "8__chars",
+                               VSH_TABLE_CELL_SKIP_LEADING | 
VSH_TABLE_CELL_SKIP_TRAILING, "|",
+                               0, NULL);
+
+        vshTableRowAppendFlags(t,
+                               VSH_TABLE_CELL_DEFAULT, 
virBufferCurrentContent(&n),
+                               VSH_TABLE_CELL_SKIP_LEADING | 
VSH_TABLE_CELL_SKIP_TRAILING, "|",
+                               fl, virBufferCurrentContent(&b),
+                               VSH_TABLE_CELL_SKIP_LEADING | 
VSH_TABLE_CELL_SKIP_TRAILING, "|",
+                               0, NULL);
+    }
+
+    act = vshTablePrintToString(t, false);
+
+    if (virTestCompareToFile(act, abs_srcdir 
"/vshtabletestdata/testRowsWithFlags.out") < 0)
+        return -1;
+
+    return 0;
+}
+
+
 static int
 mymain(void)
 {
@@ -357,6 +422,9 @@ mymain(void)
     if (virTestRun("testNTables", testNTables, NULL) < 0)
         ret = -1;

+    if (virTestRun("testRowsWithFlags", testRowsWithFlags, NULL) < 0)
+        ret = -1;
+
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }

diff --git a/tests/vshtabletestdata/testRowsWithFlags.out 
b/tests/vshtabletestdata/testRowsWithFlags.out
new file mode 100644
index 0000000000..5de74586eb
--- /dev/null
+++ b/tests/vshtabletestdata/testRowsWithFlags.out
@@ -0,0 +1,24 @@
+ base                                         | short     |
+ base                                         | 8__chars  |
+ base                                         | bbbbbbbb  |
+ base+skip_leading                            |short      |
+ base+skip_leading                            |8__chars   |
+ base+skip_leading                            |bbbbbbbbb  |
+ base+skip_trailing                           | short     |
+ base+skip_trailing                           | 8__chars  |
+ base+skip_trailing                           | bbbbbbbbbb|
+ base+skip_leading+skip_trailing              |short      |
+ base+skip_leading+skip_trailing              |8__chars   |
+ base+skip_leading+skip_trailing              |bbbbbbbbbbb|
+ base+align_right                             |    short  |
+ base+align_right                             | 8__chars  |
+ base+align_right                             | bbbbbbbb  |
+ base+skip_leading+align_right                |    short  |
+ base+skip_leading+align_right                | 8__chars  |
+ base+skip_leading+align_right                |bbbbbbbbb  |
+ base+skip_trailing+align_right               |      short|
+ base+skip_trailing+align_right               |   8__chars|
+ base+skip_trailing+align_right               | bbbbbbbbbb|
+ base+skip_leading+skip_trailing+align_right  |      short|
+ base+skip_leading+skip_trailing+align_right  |   8__chars|
+ base+skip_leading+skip_trailing+align_right  |bbbbbbbbbbb|
-- 
2.53.0

Reply via email to