]> mj.ucw.cz Git - libucw.git/commitdiff
tableprinter: update of tests
authorRobert Kessl <kesslr@centrum.cz>
Mon, 7 Jul 2014 08:31:37 +0000 (10:31 +0200)
committerRobert Kessl <kesslr@centrum.cz>
Mon, 7 Jul 2014 08:31:37 +0000 (10:31 +0200)
ucw/table-test-2.c
ucw/table-test-2.t

index e4f45bb21bdc24d921ada78d9ba7d4339d901719..f46427c097c445e9bc691a35fee8c6917194301c 100644 (file)
@@ -16,7 +16,7 @@ enum test_table_cols {
 
 static struct table test_tbl = {
   TBL_COLUMNS {
-    [TEST_COL0_SIZE] = TBL_COL_SIZE_FMT("size", 10, UNIT_BYTE),
+    [TEST_COL0_SIZE] = TBL_COL_SIZE_FMT("size", 15, UNIT_BYTE),
     [TEST_COL1_TS] = TBL_COL_TIMESTAMP("ts", 20),
     TBL_COL_END
   },
@@ -66,9 +66,58 @@ static void do_test(void)
   bclose(out);
 }
 
+
+
+static struct table test_tbl2 = {
+  TBL_COLUMNS {
+    [TEST_COL0_SIZE] = TBL_COL_SIZE_FMT("size", 15, UNIT_BYTE),
+    [TEST_COL1_TS] = TBL_COL_TIMESTAMP("ts", 20),
+    TBL_COL_END
+  },
+  TBL_OUTPUT_HUMAN_READABLE,
+};
+
+static void do_test2(void)
+{
+  struct fastbuf *out;
+  out = bfdopen_shared(1, 4096);
+  table_init(&test_tbl2);
+  table_set_col_order_by_name(&test_tbl2, "");
+  const char *err = table_set_option_value(&test_tbl2, "cols", "size[kb],size[mb],size[gb],size[tb],ts[datetime],ts[timestamp]");
+  if(err) {
+    opt_failure("err in table_set_option_value: '%s'.", err);
+    abort();
+  }
+  table_start(&test_tbl2, out);
+
+  u64 test_time = 1403685533;
+  s64 test_size = 4LU*(1024LU * 1024LU * 1024LU);
+
+  table_col_size(&test_tbl2, TEST_COL0_SIZE, test_size);
+  table_col_timestamp(&test_tbl2, TEST_COL1_TS, test_time);
+  table_end_row(&test_tbl2);
+
+  table_col_size(&test_tbl2, TEST_COL0_SIZE, test_size);
+  table_col_timestamp(&test_tbl2, TEST_COL1_TS, test_time);
+  table_end_row(&test_tbl2);
+
+  test_size = test_size * 1024LU;
+
+  table_col_size(&test_tbl2, TEST_COL0_SIZE, test_size);
+  table_col_timestamp(&test_tbl2, TEST_COL1_TS, test_time);
+  table_end_row(&test_tbl2);
+
+  table_end(&test_tbl2);
+  table_cleanup(&test_tbl2);
+
+  bclose(out);
+}
+
 int main(int argc UNUSED, char **argv UNUSED)
 {
   do_test();
+  do_test2();
+
   return 0;
 }
 
index 92874dc91b2f1732a7ddc751b770db58132644e0..649621cb32a98cc24cbdcf8684d36ca591a9cf98 100644 (file)
@@ -1,9 +1,13 @@
 Run: ../obj/ucw/table-test-2
 Out <<EOF
-      size                   ts
-4294967296           1403685533
- 4194304KB           1403685533
-    4096MB           1403685533
-       4GB  2014-06-25 08:38:53
-       4TB  2014-06-25 08:38:53
+           size                   ts
+     4294967296           1403685533
+      4194304KB           1403685533
+         4096MB           1403685533
+            4GB  2014-06-25 08:38:53
+            4TB  2014-06-25 08:38:53
+           size            size            size            size                   ts                   ts
+      4194304KB          4096MB             4GB             0TB  2014-06-25 08:38:53           1403685533
+      4194304KB          4096MB             4GB             0TB  2014-06-25 08:38:53           1403685533
+   4294967296KB       4194304MB          4096GB             4TB  2014-06-25 08:38:53           1403685533
 EOF