From 46758ee0326d471d25da7817d574f5a283df59dc Mon Sep 17 00:00:00 2001 From: seleznevae Date: Tue, 27 Feb 2018 20:59:02 +0300 Subject: [PATCH] [A] Added default cell options --- include/fort.h | 1 + src/fort.c | 5 +++++ tests/test_table.c | 49 +++++++++++++++++++++++++++++++++++----------- 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/include/fort.h b/include/fort.h index 65bac7d..7299416 100644 --- a/include/fort.h +++ b/include/fort.h @@ -271,6 +271,7 @@ FORT_EXTERN int ft_set_default_option(uint32_t option, int value); FORT_EXTERN int ft_set_table_option(FTABLE * FORT_RESTRICT table, uint32_t option, int value); FORT_EXTERN int ft_set_cell_option(FTABLE * FORT_RESTRICT table, unsigned row, unsigned col, uint32_t option, int value); +FORT_EXTERN int ft_set_default_cell_option(uint32_t option, int value); FORT_END_DECLS diff --git a/src/fort.c b/src/fort.c index 1bfb9cd..bbf6b4b 100644 --- a/src/fort.c +++ b/src/fort.c @@ -718,3 +718,8 @@ int ft_set_cell_option(FTABLE *table, unsigned row, unsigned col, uint32_t optio } return set_cell_option(table->options->cell_options, row, col, option, value); } + +int ft_set_default_cell_option(uint32_t option, int value) +{ + return set_default_cell_option(option, value); +} diff --git a/tests/test_table.c b/tests/test_table.c index b957962..d3004ff 100644 --- a/tests/test_table.c +++ b/tests/test_table.c @@ -74,6 +74,10 @@ int set_test_options_for_table(FTABLE *table) int set_test_options_as_default() { int status = F_SUCCESS; + + status |= ft_set_default_cell_option(FT_OPT_MIN_WIDTH, 0); + status |= ft_set_default_cell_option(FT_OPT_TEXT_ALIGN, RightAligned); + status |= ft_set_default_option(FT_OPT_BOTTOM_PADDING, 1); status |= ft_set_default_option(FT_OPT_TOP_PADDING, 1); status |= ft_set_default_option(FT_OPT_LEFT_PADDING, 1); @@ -805,22 +809,11 @@ void test_table_options(void **state) WHEN("Set table width and column alignment") { -// fort_table_options_t table_options; -// memcpy(&table_options, &test_table_opts, sizeof(fort_table_options_t)); -// table_options.cell_padding_bottom = 1; -// table_options.cell_padding_top = 1; -// table_options.cell_padding_left = 1; -// table_options.cell_padding_right = 1; -// ft_set_default_options(&table_options); set_test_options_as_default(); table = create_test_int_table(0); int status = F_SUCCESS; -// status |= ft_set_column_min_width(table, 1, 7); -// status |= ft_set_column_alignment(table, 1, LeftAligned); -// status |= ft_set_column_min_width(table, 2, 8); -// status |= ft_set_column_alignment(table, 2, CenterAligned); status |= ft_set_cell_option(table, FT_ANY_ROW, 1, FT_OPT_MIN_WIDTH, 7); status |= ft_set_cell_option(table, FT_ANY_ROW, 1, FT_OPT_TEXT_ALIGN, LeftAligned); @@ -855,7 +848,41 @@ void test_table_options(void **state) ft_destroy_table(table); } + WHEN("Set table width and column alignment as default") { + + set_test_options_as_default(); + + int status = F_SUCCESS; + status |= ft_set_default_cell_option(FT_OPT_MIN_WIDTH, 5); + status |= ft_set_default_cell_option(FT_OPT_TEXT_ALIGN, CenterAligned); + assert_true( status == F_SUCCESS); + + table = create_test_int_table(0); + + const char *table_str = ft_to_string(table); + assert_true( table_str != NULL ); + const char *table_str_etalon = + "+-----+-----+-----+-----+\n" + "| | | | |\n" + "| 3 | 4 | 55 | 67 |\n" + "| | | | |\n" + "+-----+-----+-----+-----+\n" + "| | | | |\n" + "| 3 | 4 | 55 | 67 |\n" + "| | | | |\n" + "+-----+-----+-----+-----+\n" + "| | | | |\n" + "| 3 | 4 | 55 | 67 |\n" + "| | | | |\n" + "+-----+-----+-----+-----+\n"; + assert_true( strcmp(table_str, table_str_etalon) == 0); + + ft_destroy_table(table); + } + WHEN("All columns are equal and not empty") { + set_test_options_as_default(); + table = ft_create_table(); int n = ft_hdr_printf_ln(table, "%d|%c|%s|%f", 4, 'c', "234", 3.14);