diff --git a/tests/test.c b/tests/test.c index 7a3146c..0a7d02c 100644 --- a/tests/test.c +++ b/tests/test.c @@ -7,6 +7,7 @@ struct test_case test_suit [] = { {"test_table_sizes", test_table_sizes}, {"test_table_geometry", test_table_geometry}, {"test_table_basic", test_table_basic}, + {"test_wcs_table_boundaries", test_wcs_table_boundaries}, {"test_table_write", test_table_write}, {"test_table_border_style", test_table_border_style}, {"test_table_options", test_table_options}, diff --git a/tests/test_table_basic.c b/tests/test_table_basic.c index 2971da3..b76fcb0 100644 --- a/tests/test_table_basic.c +++ b/tests/test_table_basic.c @@ -188,7 +188,7 @@ void test_table_basic(void) L"| 234 | 3.140000 | | |\n" L"| | | | |\n" L"+-----+----------+----------+----------+\n"; - fwprintf(stdout, L"content:\n%ls", table_str); +// fwprintf(stdout, L"content:\n%ls", table_str); assert_true( wcscmp(table_str, table_str_etalon) == 0); ft_destroy_table(table); } @@ -257,6 +257,46 @@ void test_table_basic(void) } + + +void test_wcs_table_boundaries(void) +{ + FTABLE *table = NULL; + + WHEN("All columns are not equal and not empty (wide strings)") { + table = ft_create_table(); + assert_true( table != NULL ); + assert_true( set_test_options_for_table(table) == FT_SUCCESS); + + ft_set_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header); + assert_true( FT_NWWRITE_LN(table, L"3", L"12345\x8888\x8888", L"c") == FT_SUCCESS); /* \x8888,\x8888 - occupy 2 columns each */ + assert_true( FT_NWWRITE_LN(table, L"c", L"12345678\x500", L"c") == FT_SUCCESS); /* \x500 - occupies 1 column */ + assert_true( FT_NWWRITE_LN(table, L"234", L"123456789", L"c") == FT_SUCCESS); + + const wchar_t *table_str = ft_to_wstring(table); + assert_true( table_str != NULL ); + const wchar_t *table_str_etalon = + L"+-----+-----------+---+\n" + L"| | | |\n" + L"| 3 | 12345\x8888\x8888 | c |\n" + L"| | | |\n" + L"+-----+-----------+---+\n" + L"| | | |\n" + L"| c | 12345678\x500 | c |\n" + L"| | | |\n" + L"+-----+-----------+---+\n" + L"| | | |\n" + L"| 234 | 123456789 | c |\n" + L"| | | |\n" + L"+-----+-----------+---+\n"; +// setlocale(LC_CTYPE, ""); +// fprintf(stdout, "content:\n%ls", table_str); + assert_wcs_equal( table_str, table_str_etalon ); + ft_destroy_table(table); + } +} + + void test_table_write(void) { FTABLE *table = NULL; diff --git a/tests/tests.h b/tests/tests.h index 097f7ea..bdc0c83 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -6,6 +6,8 @@ #include #include "fort_impl.h" #include +#include "wchar.h" +#include "locale.h" #define WHEN(...) #define THEN(...) @@ -17,6 +19,7 @@ void test_string_buffer(void); void test_table_sizes(void); void test_table_geometry(void); void test_table_basic(void); +void test_wcs_table_boundaries(void); void test_table_write(void); void test_table_border_style(void); void test_table_options(void); @@ -39,4 +42,27 @@ int set_test_options_as_default(); FTABLE *create_test_int_table(int set_test_opts); +#define assert_str_equal(str1, str2) \ + if (strcmp(str1, str2) != 0) \ + { \ + fprintf(stderr, "%s:%d(%s):Abort! Not equals strings:\n",__FILE__,__LINE__, __FUNCTION__); \ + fprintf(stderr, "Left string:\n%s\n", str1); \ + fprintf(stderr, "Right string:\n%s\n", str2); \ + exit(EXIT_FAILURE); \ + } + + + +#define assert_wcs_equal(str1, str2) \ + if (wcscmp(str1, str2) != 0) \ + { \ + setlocale(LC_CTYPE, ""); \ + fwprintf(stdout, L"%s:%d(%s):Abort! Not equals strings:\n",__FILE__,__LINE__, __FUNCTION__); \ + fwprintf(stdout, L"Left string:\n%ls\n", str1); \ + fwprintf(stdout, L"Right string:\n%ls\n", str2); \ + exit(EXIT_FAILURE); \ + } \ + + + #endif // TESTS_H