From 6082281d0e96919e952d881c0e4386f7c932bae7 Mon Sep 17 00:00:00 2001 From: seleznevae Date: Sat, 7 Sep 2019 12:32:57 +0300 Subject: [PATCH] [F] Fix incorrect `ft_u8nwrite` implementation --- CMakeLists.txt | 2 +- ChangeLog.md | 6 + lib/fort.c | 1 - lib/fort.h | 4 +- src/fort.h | 4 +- src/fort_impl.c | 1 - tests/bb_tests/test_table_basic.c | 211 ++++++++++++++++++++++++++++++ 7 files changed, 222 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fce4144..d5e93d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.0) -project(libfort VERSION 0.2.0) +project(libfort VERSION 0.2.1) string(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\1.\\2" libfort_SOVERSION diff --git a/ChangeLog.md b/ChangeLog.md index e5acb1a..3e12343 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,3 +1,9 @@ +## v0.2.1 + +### Bug fixes + +- Fix incorrect `ft_u8nwrite` implementation. + ## v0.2.0 ### API diff --git a/lib/fort.c b/lib/fort.c index 6c2a269..f2b5c5f 100644 --- a/lib/fort.c +++ b/lib/fort.c @@ -3380,7 +3380,6 @@ int ft_u8nwrite(ft_table_t *table, size_t n, const void *cell_content, ...) } va_end(va); - ft_ln(table); return status; } diff --git a/lib/fort.h b/lib/fort.h index 917602c..27a3a5f 100644 --- a/lib/fort.h +++ b/lib/fort.h @@ -46,8 +46,8 @@ SOFTWARE. #define LIBFORT_MAJOR_VERSION 0 #define LIBFORT_MINOR_VERSION 2 -#define LIBFORT_REVISION 0 -#define LIBFORT_VERSION_STR "0.2.0" +#define LIBFORT_REVISION 1 +#define LIBFORT_VERSION_STR "0.2.1" /***************************************************************************** diff --git a/src/fort.h b/src/fort.h index 917602c..27a3a5f 100644 --- a/src/fort.h +++ b/src/fort.h @@ -46,8 +46,8 @@ SOFTWARE. #define LIBFORT_MAJOR_VERSION 0 #define LIBFORT_MINOR_VERSION 2 -#define LIBFORT_REVISION 0 -#define LIBFORT_VERSION_STR "0.2.0" +#define LIBFORT_REVISION 1 +#define LIBFORT_VERSION_STR "0.2.1" /***************************************************************************** diff --git a/src/fort_impl.c b/src/fort_impl.c index ab136b8..f939b76 100644 --- a/src/fort_impl.c +++ b/src/fort_impl.c @@ -918,7 +918,6 @@ int ft_u8nwrite(ft_table_t *table, size_t n, const void *cell_content, ...) } va_end(va); - ft_ln(table); return status; } diff --git a/tests/bb_tests/test_table_basic.c b/tests/bb_tests/test_table_basic.c index 48bd7eb..11de00d 100644 --- a/tests/bb_tests/test_table_basic.c +++ b/tests/bb_tests/test_table_basic.c @@ -826,6 +826,55 @@ void test_table_write(void) } #endif +#ifdef FT_HAVE_UTF8 + SCENARIO("Test wwrite functions(utf8 strings)") { + table = ft_create_table(); + assert_true(table != NULL); + assert_true(set_test_props_for_table(table) == FT_SUCCESS); + + ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER); + assert_true(FT_IS_SUCCESS(ft_u8write(table, "3"))); + assert_true(FT_IS_SUCCESS(ft_u8write(table, "c"))); + assert_true(FT_IS_SUCCESS(ft_u8write(table, "234"))); + assert_true(FT_IS_SUCCESS(ft_u8write(table, "3.140000"))); + ft_ln(table); + assert_true(FT_IS_SUCCESS(ft_u8write(table, "c"))); + assert_true(FT_IS_SUCCESS(ft_u8write(table, "235"))); + assert_true(FT_IS_SUCCESS(ft_u8write(table, "3.150000"))); + assert_true(FT_IS_SUCCESS(ft_u8write_ln(table, "5"))); + + assert_true(FT_IS_SUCCESS(ft_u8write(table, "234"))); + assert_true(FT_IS_SUCCESS(ft_u8write(table, "3.140000"))); + assert_true(FT_IS_SUCCESS(ft_u8write(table, "3"))); + assert_true(FT_IS_SUCCESS(ft_u8write_ln(table, "c"))); + + /* Replace old values */ + ft_set_cur_cell(table, 1, 1); + assert_true(FT_IS_SUCCESS(ft_u8write(table, "234"))); + assert_true(FT_IS_SUCCESS(ft_u8write(table, "3.140000"))); + assert_true(FT_IS_SUCCESS(ft_u8write_ln(table, "3"))); + + const char *table_str = ft_to_u8string(table); + assert_true(table_str != NULL); + const char *table_str_etalon = + "+-----+----------+----------+----------+\n" + "| | | | |\n" + "| 3 | c | 234 | 3.140000 |\n" + "| | | | |\n" + "+-----+----------+----------+----------+\n" + "| | | | |\n" + "| c | 234 | 3.140000 | 3 |\n" + "| | | | |\n" + "+-----+----------+----------+----------+\n" + "| | | | |\n" + "| 234 | 3.140000 | 3 | c |\n" + "| | | | |\n" + "+-----+----------+----------+----------+\n"; + assert_str_equal(table_str, table_str_etalon); + ft_destroy_table(table); + } +#endif + SCENARIO("Test nwrite functions") { table = ft_create_table(); assert_true(table != NULL); @@ -898,6 +947,42 @@ void test_table_write(void) } #endif +#ifdef FT_HAVE_UTF8 + SCENARIO("Test nwwrite functions(utf8 strings)") { + table = ft_create_table(); + assert_true(table != NULL); + assert_true(set_test_props_for_table(table) == FT_SUCCESS); + + ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER); + assert_true(ft_u8nwrite(table, 4, "3", "c", "234", "3.140000") == FT_SUCCESS); + ft_ln(table); + assert_true(ft_u8nwrite_ln(table, 4, "c", "235", "3.150000", "5") == FT_SUCCESS); + assert_true(ft_u8nwrite_ln(table, 4, "234", "3.140000", "3", "c") == FT_SUCCESS); + + /* Replace old values */ + ft_set_cur_cell(table, 1, 1); + assert_true(ft_u8nwrite_ln(table, 3, "234", "3.140000", "3") == FT_SUCCESS); + + const char *table_str = ft_to_u8string(table); + assert_true(table_str != NULL); + const char *table_str_etalon = + "+-----+----------+----------+----------+\n" + "| | | | |\n" + "| 3 | c | 234 | 3.140000 |\n" + "| | | | |\n" + "+-----+----------+----------+----------+\n" + "| | | | |\n" + "| c | 234 | 3.140000 | 3 |\n" + "| | | | |\n" + "+-----+----------+----------+----------+\n" + "| | | | |\n" + "| 234 | 3.140000 | 3 | c |\n" + "| | | | |\n" + "+-----+----------+----------+----------+\n"; + assert_str_equal(table_str, table_str_etalon); + ft_destroy_table(table); + } +#endif /* FT_HAVE_UTF8 */ SCENARIO("Test row_write functions") { table = ft_create_table(); @@ -1129,6 +1214,47 @@ void test_table_write(void) } #endif +#ifdef FT_HAVE_UTF8 + SCENARIO("Test printf functions(utf8 strings)") { + table = ft_create_table(); + assert_true(table != NULL); + assert_true(set_test_props_for_table(table) == FT_SUCCESS); + + ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER); + int n = ft_u8printf_ln(table, "%d|%c|%s|%f", 3, 'c', "234", 3.14); + assert_true(n == 4); + n = ft_u8printf(table, "%c|%s|%f|%d", 'c', "235", 3.15, 5); + assert_true(n == 4); + ft_ln(table); + n = ft_u8printf_ln(table, "%s|%f|%d|%c", "234", 3.14, 3, 'c'); + assert_true(n == 4); + + /* Replace old values */ + ft_set_cur_cell(table, 1, 1); + n = ft_u8printf(table, "%s|%f|%d", "234", 3.14, 3); + assert_true(n == 3); + + const char *table_str = ft_to_u8string(table); + assert_true(table_str != NULL); + const char *table_str_etalon = + "+-----+----------+----------+----------+\n" + "| | | | |\n" + "| 3 | c | 234 | 3.140000 |\n" + "| | | | |\n" + "+-----+----------+----------+----------+\n" + "| | | | |\n" + "| c | 234 | 3.140000 | 3 |\n" + "| | | | |\n" + "+-----+----------+----------+----------+\n" + "| | | | |\n" + "| 234 | 3.140000 | 3 | c |\n" + "| | | | |\n" + "+-----+----------+----------+----------+\n"; + assert_str_equal(table_str, table_str_etalon); + ft_destroy_table(table); + } +#endif + SCENARIO("Test printf functions with strings with separators inside them") { table = ft_create_table(); assert_true(table != NULL); @@ -1211,6 +1337,48 @@ void test_table_write(void) } #endif +#ifdef FT_HAVE_UTF8 + SCENARIO("Test printf functions with strings with separators inside them") { + table = ft_create_table(); + assert_true(table != NULL); + assert_true(set_test_props_for_table(table) == FT_SUCCESS); + + ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER); + int n = ft_u8printf_ln(table, "%d|%c|%s|%f", 3, 'c', "234", 3.14); + assert_true(n == 4); + n = ft_u8printf(table, "%c", 'c'); + assert_true(n == 1); + n = ft_u8printf(table, "%s", "234"); + assert_true(n == 1); + n = ft_u8printf(table, "%s", "string|with separator"); + assert_true(n == 1); + n = ft_u8printf(table, "3"); + assert_true(n == 1); + ft_ln(table); + n = ft_u8printf_ln(table, "%s|%f|%d|%c", "234", 3.14, 3, 'c'); + assert_true(n == 4); + + const char *table_str = ft_to_u8string(table); + assert_true(table_str != NULL); + const char *table_str_etalon = + "+-----+----------+-----------------------+----------+\n" + "| | | | |\n" + "| 3 | c | 234 | 3.140000 |\n" + "| | | | |\n" + "+-----+----------+-----------------------+----------+\n" + "| | | | |\n" + "| c | 234 | string|with separator | 3 |\n" + "| | | | |\n" + "+-----+----------+-----------------------+----------+\n" + "| | | | |\n" + "| 234 | 3.140000 | 3 | c |\n" + "| | | | |\n" + "+-----+----------+-----------------------+----------+\n"; + assert_str_equal(table_str, table_str_etalon); + ft_destroy_table(table); + } +#endif + SCENARIO("Test printf functions with custom separator") { ft_set_default_printf_field_separator('$'); table = ft_create_table(); @@ -1295,6 +1463,49 @@ void test_table_write(void) } #endif +#ifdef FT_HAVE_UTF8 + SCENARIO("Test printf functions(utf8 strings) with custom separator") { + ft_set_default_printf_field_separator('$'); + table = ft_create_table(); + assert_true(table != NULL); + assert_true(set_test_props_for_table(table) == FT_SUCCESS); + + ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER); + int n = ft_u8printf_ln(table, "%d$%c$%s$%f", 3, 'c', "234", 3.14); + assert_true(n == 4); + n = ft_u8printf(table, "%c$%s$%f$%d", 'c', "235", 3.15, 5); + assert_true(n == 4); + ft_ln(table); + n = ft_u8printf_ln(table, "%s$%f$%d$%c", "234", 3.14, 3, 'c'); + assert_true(n == 4); + + /* Replace old values */ + ft_set_cur_cell(table, 1, 1); + n = ft_u8printf(table, "%s$%f$%d", "234", 3.14, 3); + assert_true(n == 3); + + const char *table_str = ft_to_u8string(table); + assert_true(table_str != NULL); + const char *table_str_etalon = + "+-----+----------+----------+----------+\n" + "| | | | |\n" + "| 3 | c | 234 | 3.140000 |\n" + "| | | | |\n" + "+-----+----------+----------+----------+\n" + "| | | | |\n" + "| c | 234 | 3.140000 | 3 |\n" + "| | | | |\n" + "+-----+----------+----------+----------+\n" + "| | | | |\n" + "| 234 | 3.140000 | 3 | c |\n" + "| | | | |\n" + "+-----+----------+----------+----------+\n"; + assert_str_equal(table_str, table_str_etalon); + ft_destroy_table(table); + ft_set_default_printf_field_separator('|'); + } +#endif + }