libfort/tests/test_utils.c

152 lines
5.0 KiB
C
Raw Permalink Normal View History

2018-03-19 21:07:18 +01:00
#include "tests.h"
2018-11-24 21:14:26 +01:00
#include "test_utils.h"
2018-03-19 21:07:18 +01:00
#include "fort.h"
2018-11-03 21:50:30 +01:00
int set_test_props_for_table(struct ft_table *table)
2018-03-19 21:07:18 +01:00
{
assert(table);
int status = FT_SUCCESS;
2018-11-03 21:50:30 +01:00
status |= ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_BOTTOM_PADDING, 1);
status |= ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_TOP_PADDING, 1);
status |= ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_LEFT_PADDING, 1);
status |= ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_RIGHT_PADDING, 1);
status |= ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_EMPTY_STR_HEIGHT, 1);
2018-03-19 21:07:18 +01:00
2018-03-31 12:33:37 +02:00
assert_true(status == FT_SUCCESS);
2018-03-19 21:07:18 +01:00
struct ft_border_style brdr_style;
2018-05-02 20:16:41 +02:00
brdr_style.border_chs.top_border_ch = "-";
brdr_style.border_chs.separator_ch = "-";
brdr_style.border_chs.bottom_border_ch = "-";
brdr_style.border_chs.side_border_ch = "|";
brdr_style.border_chs.out_intersect_ch = "+";
brdr_style.border_chs.in_intersect_ch = "+";
brdr_style.header_border_chs.top_border_ch = "-";
brdr_style.header_border_chs.separator_ch = "-";
brdr_style.header_border_chs.bottom_border_ch = "-";
brdr_style.header_border_chs.side_border_ch = "|";
brdr_style.header_border_chs.out_intersect_ch = "+";
brdr_style.header_border_chs.in_intersect_ch = "+";
brdr_style.hor_separator_char = "=";
2018-03-19 21:07:18 +01:00
return ft_set_border_style(table, &brdr_style);
}
2018-11-03 21:50:30 +01:00
int set_test_properties_as_default(void)
2018-03-19 21:07:18 +01:00
{
int status = FT_SUCCESS;
2018-11-03 21:50:30 +01:00
status |= ft_set_default_cell_prop(FT_CPROP_MIN_WIDTH, 0);
status |= ft_set_default_cell_prop(FT_CPROP_TEXT_ALIGN, FT_ALIGNED_RIGHT);
2018-03-19 21:07:18 +01:00
2018-11-03 21:50:30 +01:00
status |= ft_set_default_cell_prop(FT_CPROP_BOTTOM_PADDING, 1);
status |= ft_set_default_cell_prop(FT_CPROP_TOP_PADDING, 1);
status |= ft_set_default_cell_prop(FT_CPROP_LEFT_PADDING, 1);
status |= ft_set_default_cell_prop(FT_CPROP_RIGHT_PADDING, 1);
status |= ft_set_default_cell_prop(FT_CPROP_EMPTY_STR_HEIGHT, 1);
2018-03-19 21:07:18 +01:00
2018-03-31 12:33:37 +02:00
assert_true(status == FT_SUCCESS);
2018-03-19 21:07:18 +01:00
struct ft_border_style brdr_style;
2018-05-02 20:16:41 +02:00
brdr_style.border_chs.top_border_ch = "-";
brdr_style.border_chs.separator_ch = "-";
brdr_style.border_chs.bottom_border_ch = "-";
brdr_style.border_chs.side_border_ch = "|";
brdr_style.border_chs.out_intersect_ch = "+";
brdr_style.border_chs.in_intersect_ch = "+";
brdr_style.header_border_chs.top_border_ch = "-";
brdr_style.header_border_chs.separator_ch = "-";
brdr_style.header_border_chs.bottom_border_ch = "-";
brdr_style.header_border_chs.side_border_ch = "|";
brdr_style.header_border_chs.out_intersect_ch = "+";
brdr_style.header_border_chs.in_intersect_ch = "+";
brdr_style.hor_separator_char = "=";
2018-03-19 21:07:18 +01:00
return ft_set_default_border_style(&brdr_style);
}
2018-05-06 13:11:03 +02:00
struct ft_table *create_test_int_table(int set_test_opts)
2018-03-19 21:07:18 +01:00
{
2018-05-05 21:34:45 +02:00
ft_table_t *table = NULL;
2018-03-19 21:07:18 +01:00
table = ft_create_table();
2018-03-31 12:33:37 +02:00
assert_true(table != NULL);
2018-03-19 21:07:18 +01:00
if (set_test_opts) {
2018-11-03 21:50:30 +01:00
assert_true(set_test_props_for_table(table) == FT_SUCCESS);
2018-03-19 21:07:18 +01:00
}
2018-03-31 12:33:37 +02:00
assert_true(table != NULL);
2018-03-19 21:07:18 +01:00
2018-11-03 21:50:30 +01:00
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
2018-04-24 19:41:14 +02:00
int n = ft_write_ln(table, "3", "4", "55", "67");
2018-03-25 10:32:10 +02:00
assert(n == FT_SUCCESS);
2018-03-19 21:07:18 +01:00
assert(ft_write(table, "3") == FT_SUCCESS);
assert(ft_write(table, "4") == FT_SUCCESS);
assert(ft_write(table, "55") == FT_SUCCESS);
assert(ft_write_ln(table, "67") == FT_SUCCESS);
assert(ft_write(table, "3") == FT_SUCCESS);
assert(ft_write(table, "4") == FT_SUCCESS);
assert(ft_write(table, "55") == FT_SUCCESS);
assert(ft_write_ln(table, "67") == FT_SUCCESS);
return table;
}
2018-03-25 10:32:10 +02:00
2018-04-16 20:01:45 +02:00
#ifdef FT_HAVE_WCHAR
2018-05-06 13:11:03 +02:00
struct ft_table *create_test_int_wtable(int set_test_opts)
2018-03-25 10:32:10 +02:00
{
2018-05-05 21:34:45 +02:00
ft_table_t *table = NULL;
2018-03-25 10:32:10 +02:00
table = ft_create_table();
2018-03-31 12:33:37 +02:00
assert_true(table != NULL);
2018-03-25 10:32:10 +02:00
if (set_test_opts) {
2018-11-03 21:50:30 +01:00
assert_true(set_test_props_for_table(table) == FT_SUCCESS);
2018-03-25 10:32:10 +02:00
}
2018-03-31 12:33:37 +02:00
assert_true(table != NULL);
2018-03-25 10:32:10 +02:00
2018-11-03 21:50:30 +01:00
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
2018-04-24 19:41:14 +02:00
int n = ft_wwrite_ln(table, L"3", L"4", L"55", L"67");
2018-03-25 10:32:10 +02:00
assert(n == FT_SUCCESS);
assert(ft_wwrite(table, L"3") == FT_SUCCESS);
assert(ft_wwrite(table, L"4") == FT_SUCCESS);
assert(ft_wwrite(table, L"55") == FT_SUCCESS);
assert(ft_wwrite_ln(table, L"67") == FT_SUCCESS);
assert(ft_wwrite(table, L"3") == FT_SUCCESS);
assert(ft_wwrite(table, L"4") == FT_SUCCESS);
assert(ft_wwrite(table, L"55") == FT_SUCCESS);
assert(ft_wwrite_ln(table, L"67") == FT_SUCCESS);
return table;
}
2018-04-16 20:01:45 +02:00
#endif
2018-05-06 15:21:45 +02:00
2018-11-24 21:14:26 +01:00
//void run_test_suit(const char *test_suit_name, int n_tests, struct test_case test_suit[])
//{
// fprintf(stderr, " == RUNNING %s ==\n", test_suit_name);
// fprintf(stderr, "[==========] Running %d test(s).\n", n_tests);
// int i;
// for (i = 0; i < n_tests; ++i) {
// fprintf(stderr, "[ RUN ] %s\n", test_suit[i].name);
// test_suit[i].test();
// fprintf(stderr, "[ OK ] %s\n", test_suit[i].name);
// }
// fprintf(stderr, "[==========] %d test(s) run.\n", n_tests);
// fprintf(stderr, "[ PASSED ] %d test(s).\n", n_tests);
//}
2018-05-06 15:21:45 +02:00