]> mj.ucw.cz Git - libucw.git/blob - ucw/table-test-2.c
tableprinter: update of some FIXME
[libucw.git] / ucw / table-test-2.c
1 /*
2  *      Unit tests of table printer
3  *
4  *      (c) 2014 Robert Kessl <robert.kessl@economia.cz>
5  */
6
7 #include <ucw/lib.h>
8 #include <ucw/table.h>
9 #include <ucw/table-types.h>
10 #include <ucw/opt.h>
11 #include <stdio.h>
12
13 enum test_table_cols {
14   TEST_COL0_SIZE, TEST_COL1_TS
15 };
16
17 static struct table test_tbl = {
18   TBL_COLUMNS {
19     [TEST_COL0_SIZE] = TBL_COL_SIZE_FMT("size", 10, UNIT_BYTE),
20     [TEST_COL1_TS] = TBL_COL_TIMESTAMP("ts", 20),
21     TBL_COL_END
22   },
23   TBL_OUTPUT_HUMAN_READABLE,
24 };
25
26 static void do_test(void)
27 {
28   struct fastbuf *out;
29   out = bfdopen_shared(1, 4096);
30   table_init(&test_tbl);
31   table_start(&test_tbl, out);
32
33   u64 test_time = 1403685533;
34   s64 test_size = 4LU*(1024LU * 1024LU * 1024LU);
35
36   table_col_size(&test_tbl, TEST_COL0_SIZE, test_size);
37   table_col_timestamp(&test_tbl, TEST_COL1_TS, test_time);
38   table_end_row(&test_tbl);
39
40   test_tbl.column_order[TEST_COL0_SIZE].output_type = UNIT_KILOBYTE;
41   table_col_size(&test_tbl, TEST_COL0_SIZE, test_size);
42   table_col_timestamp(&test_tbl, TEST_COL1_TS, test_time);
43   table_end_row(&test_tbl);
44
45   test_tbl.column_order[TEST_COL0_SIZE].output_type = UNIT_MEGABYTE;
46   table_col_size(&test_tbl, TEST_COL0_SIZE, test_size);
47   table_col_timestamp(&test_tbl, TEST_COL1_TS, test_time);
48   table_end_row(&test_tbl);
49
50   test_tbl.column_order[TEST_COL0_SIZE].output_type = UNIT_GIGABYTE;
51   test_tbl.column_order[TEST_COL1_TS].output_type = TIMESTAMP_DATETIME;
52   table_col_size(&test_tbl, TEST_COL0_SIZE, test_size);
53   table_col_timestamp(&test_tbl, TEST_COL1_TS, test_time);
54   table_end_row(&test_tbl);
55
56   test_size = test_size * 1024LU;
57   test_tbl.column_order[TEST_COL0_SIZE].output_type = UNIT_TERABYTE;
58   test_tbl.column_order[TEST_COL1_TS].output_type = TIMESTAMP_DATETIME;
59   table_col_size(&test_tbl, TEST_COL0_SIZE, test_size);
60   table_col_timestamp(&test_tbl, TEST_COL1_TS, test_time);
61   table_end_row(&test_tbl);
62
63   table_end(&test_tbl);
64   table_cleanup(&test_tbl);
65
66   bclose(out);
67 }
68
69 int main(int argc UNUSED, char **argv UNUSED)
70 {
71   do_test();
72   return 0;
73 }
74