2 * Unit tests of table printer
4 * (c) 2014 Robert Kessl <robert.kessl@economia.cz>
9 #include <ucw/table-types.h>
13 enum test_table_cols {
14 TEST_COL0_SIZE, TEST_COL1_TS
17 static struct table_template test_tbl = {
19 [TEST_COL0_SIZE] = TBL_COL_SIZE_FMT("size", 15, SIZE_UNITS_FIXED | UNIT_SIZE_BYTE),
20 [TEST_COL1_TS] = TBL_COL_TIMESTAMP("ts", 20),
23 TBL_FMT_HUMAN_READABLE,
26 static void do_test(void)
29 out = bfdopen_shared(1, 4096);
30 struct table *tbl = table_init(&test_tbl);
31 table_start(tbl, out);
33 u64 test_time = 1403685533;
34 s64 test_size = 4LU*(1024LU * 1024LU * 1024LU);
36 table_col_size(tbl, TEST_COL0_SIZE, test_size);
37 table_col_timestamp(tbl, TEST_COL1_TS, test_time);
40 tbl->column_order[TEST_COL0_SIZE].output_type = SIZE_UNITS_FIXED | SIZE_UNIT_KILOBYTE;
41 table_col_size(tbl, TEST_COL0_SIZE, test_size);
42 table_col_timestamp(tbl, TEST_COL1_TS, test_time);
45 tbl->column_order[TEST_COL0_SIZE].output_type = SIZE_UNITS_FIXED | SIZE_UNIT_MEGABYTE;
46 table_col_size(tbl, TEST_COL0_SIZE, test_size);
47 table_col_timestamp(tbl, TEST_COL1_TS, test_time);
50 tbl->column_order[TEST_COL0_SIZE].output_type = SIZE_UNITS_FIXED | SIZE_UNIT_GIGABYTE;
51 tbl->column_order[TEST_COL1_TS].output_type = TIMESTAMP_DATETIME;
52 table_col_size(tbl, TEST_COL0_SIZE, test_size);
53 table_col_timestamp(tbl, TEST_COL1_TS, test_time);
56 test_size = test_size * 1024LU;
57 tbl->column_order[TEST_COL0_SIZE].output_type = SIZE_UNITS_FIXED | SIZE_UNIT_TERABYTE;
58 tbl->column_order[TEST_COL1_TS].output_type = TIMESTAMP_DATETIME;
59 table_col_size(tbl, TEST_COL0_SIZE, test_size);
60 table_col_timestamp(tbl, TEST_COL1_TS, test_time);
69 static struct table_template test_tbl2 = {
71 [TEST_COL0_SIZE] = TBL_COL_SIZE_FMT("size", 15, SIZE_UNITS_FIXED | SIZE_UNIT_BYTE),
72 [TEST_COL1_TS] = TBL_COL_TIMESTAMP("ts", 20),
75 TBL_FMT_HUMAN_READABLE,
78 static void do_test2(void)
81 out = bfdopen_shared(1, 4096);
82 struct table *tbl = table_init(&test_tbl2);
83 table_set_col_order_by_name(tbl, "");
84 const char *err = table_set_option_value(tbl, "cols", "size[kb],size[mb],size[gb],size[tb],ts[datetime],ts[timestamp]");
86 opt_failure("err in table_set_option_value: '%s'.", err);
89 table_start(tbl, out);
91 u64 test_time = 1403685533;
92 s64 test_size = 4LU*(1024LU * 1024LU * 1024LU);
94 table_col_size(tbl, TEST_COL0_SIZE, test_size);
95 table_col_timestamp(tbl, TEST_COL1_TS, test_time);
98 table_col_size(tbl, TEST_COL0_SIZE, test_size);
99 table_col_timestamp(tbl, TEST_COL1_TS, test_time);
102 test_size = test_size * 1024LU;
104 table_col_size(tbl, TEST_COL0_SIZE, test_size);
105 table_col_timestamp(tbl, TEST_COL1_TS, test_time);
114 int main(int argc UNUSED, char **argv UNUSED)