From 758116535629a69964c91abc020328bf63b644b3 Mon Sep 17 00:00:00 2001 From: seleznevae Date: Fri, 25 Oct 2019 22:20:59 +0300 Subject: [PATCH] [F] Fix incorrect behaviour when using `FT_CUR_...` macroses When macroses FT_CUR_ROW, FT_CUR_CELL were used behaviour was unexpected - properties were not applied. Cause of bug - simple typo. Also we didn't have tests for usage of these macroses. So I added them also. --- CMakeLists.txt | 2 +- ChangeLog.md | 6 +++++ lib/fort.c | 2 +- src/fort.h | 4 +-- src/fort_impl.c | 2 +- tests/bb_tests/test_table_properties.c | 34 ++++++++++++++++++++++++++ 6 files changed, 45 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 30d7fd3..3c6d58e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.0) -project(libfort VERSION 0.3.0) +project(libfort VERSION 0.3.1) string(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\1.\\2" libfort_SOVERSION diff --git a/ChangeLog.md b/ChangeLog.md index 49dc437..8ecaa1b 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,3 +1,9 @@ +## v0.3.1 + +### Bug fixes + +- Fix incorrect behaviour when setting properties with `FT_CUR_...` macroses. + ## v0.3.0 ### API diff --git a/lib/fort.c b/lib/fort.c index 0553666..9888e9e 100644 --- a/lib/fort.c +++ b/lib/fort.c @@ -3394,7 +3394,7 @@ int ft_set_cell_prop(ft_table_t *table, size_t row, size_t col, uint32_t propert if (row == FT_CUR_ROW) row = table->cur_row; - if (row == FT_CUR_COLUMN) + if (col == FT_CUR_COLUMN) col = table->cur_col; return set_cell_property(table->properties->cell_properties, row, col, property, value); diff --git a/src/fort.h b/src/fort.h index a45a0e4..a47ae64 100644 --- a/src/fort.h +++ b/src/fort.h @@ -46,8 +46,8 @@ SOFTWARE. #define LIBFORT_MAJOR_VERSION 0 #define LIBFORT_MINOR_VERSION 3 -#define LIBFORT_REVISION 0 -#define LIBFORT_VERSION_STR "0.3.0" +#define LIBFORT_REVISION 1 +#define LIBFORT_VERSION_STR "0.3.1" /***************************************************************************** diff --git a/src/fort_impl.c b/src/fort_impl.c index a3eca58..446478e 100644 --- a/src/fort_impl.c +++ b/src/fort_impl.c @@ -843,7 +843,7 @@ int ft_set_cell_prop(ft_table_t *table, size_t row, size_t col, uint32_t propert if (row == FT_CUR_ROW) row = table->cur_row; - if (row == FT_CUR_COLUMN) + if (col == FT_CUR_COLUMN) col = table->cur_col; return set_cell_property(table->properties->cell_properties, row, col, property, value); diff --git a/tests/bb_tests/test_table_properties.c b/tests/bb_tests/test_table_properties.c index 0910e4a..b3defae 100644 --- a/tests/bb_tests/test_table_properties.c +++ b/tests/bb_tests/test_table_properties.c @@ -220,6 +220,40 @@ void test_table_cell_properties(void) ft_destroy_table(table); } + WHEN("Setting property for the current cell") { + set_test_properties_as_default(); + + table = create_test_int_table(0); + ft_set_cell_prop(table, FT_CUR_ROW, FT_CUR_COLUMN, FT_CPROP_TOP_PADDING, 2); + ft_write(table, "3", "4"); + ft_set_cell_prop(table, FT_CUR_ROW, FT_CUR_COLUMN, FT_CPROP_TOP_PADDING, 0); + ft_write_ln(table, "55", "67"); + + 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" + "| | | 55 | |\n" + "| | 4 | | 67 |\n" + "| 3 | | | |\n" + "| | | | |\n" + "+---+---+----+----+\n"; + assert_str_equal(table_str, table_str_etalon); + ft_destroy_table(table); + } + WHEN("Setting property for all cells in the table") { set_test_properties_as_default();