1
0
Fork 0

[A] Added write_row functions for wcs tables

This commit is contained in:
seleznevae 2018-03-29 20:09:57 +03:00
parent abcd7aeb99
commit c63c1fcfb2
3 changed files with 104 additions and 4 deletions

View File

@ -366,6 +366,8 @@ FT_EXTERN int ft_wwrite_ln(FTABLE *FT_RESTRICT table, const wchar_t* FT_RESTRICT
FT_EXTERN int ft_nwwrite(FTABLE *FT_RESTRICT table, size_t n, const wchar_t* FT_RESTRICT cell_content, ...);
FT_EXTERN int ft_nwwrite_ln(FTABLE *FT_RESTRICT table, size_t n, const wchar_t* FT_RESTRICT cell_content, ...);
FT_EXTERN int ft_row_wwrite(FTABLE *FT_RESTRICT table, size_t cols, const wchar_t* FT_RESTRICT row_cells[]);
FT_EXTERN int ft_row_wwrite_ln(FTABLE *FT_RESTRICT table, size_t cols, const wchar_t* FT_RESTRICT row_cells[]);
FT_EXTERN const wchar_t* ft_to_wstring(const FTABLE *FT_RESTRICT table);
#endif

View File

@ -215,6 +215,8 @@ int ft_write_ln(FTABLE *FT_RESTRICT table, const char* FT_RESTRICT cell_content)
return status;
}
#ifdef FT_HAVE_WCHAR
int ft_wwrite(FTABLE *FT_RESTRICT table, const wchar_t* FT_RESTRICT cell_content)
{
assert(table);
@ -238,6 +240,7 @@ int ft_wwrite_ln(FTABLE *FT_RESTRICT table, const wchar_t* FT_RESTRICT cell_cont
}
return status;
}
#endif
int ft_nwrite(FTABLE *FT_RESTRICT table, size_t n, const char* FT_RESTRICT cell_content, ...)
@ -286,6 +289,7 @@ int ft_nwrite_ln(FTABLE *FT_RESTRICT table, size_t n, const char* FT_RESTRICT ce
return status;
}
#ifdef FT_HAVE_WCHAR
int ft_nwwrite(FTABLE *FT_RESTRICT table, size_t n, const wchar_t* FT_RESTRICT cell_content, ...)
{
@ -332,6 +336,7 @@ int ft_nwwrite_ln(FTABLE *FT_RESTRICT table, size_t n, const wchar_t* FT_RESTRIC
ft_ln(table);
return status;
}
#endif
int ft_row_write(FTABLE *FT_RESTRICT table, size_t cols, const char* FT_RESTRICT cells[])
@ -358,6 +363,31 @@ int ft_row_write_ln(FTABLE *FT_RESTRICT table, size_t cols, const char* FT_RESTR
return status;
}
#ifdef FT_HAVE_WCHAR
int ft_row_wwrite(FTABLE *FT_RESTRICT table, size_t cols, const wchar_t* FT_RESTRICT cells[])
{
size_t i = 0;
assert(table);
for (i = 0; i < cols; ++i) {
int status = ft_wwrite(table, cells[i]);
if (IS_ERROR(status)) {
/* todo: maybe current pos in case of error should be equal to the one before function call? */
return status;
}
}
return FT_SUCCESS;
}
int ft_row_wwrite_ln(FTABLE *FT_RESTRICT table, size_t cols, const wchar_t* FT_RESTRICT cells[])
{
assert(table);
int status = ft_row_wwrite(table, cols, cells);
if (IS_SUCCESS(status)) {
ft_ln(table);
}
return status;
}
#endif
#if !defined(__cplusplus) && !defined(FT_MICROSOFT_COMPILER)

View File

@ -291,6 +291,72 @@ void test_table_write(void)
{
FTABLE *table = NULL;
SCENARIO("Test row_write functions") {
table = ft_create_table();
assert_true( table != NULL );
assert_true( set_test_options_for_table(table) == FT_SUCCESS);
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header);
const char *row_0[4] = {"3", "c", "234", "3.140000"};
const char *row_1[4] = {"c", "234", "3.140000", "3"};
const char *row_2[4] = {"234", "3.140000", "3", "c"};
assert_true(ft_row_write_ln(table, 4, row_0) == FT_SUCCESS);
assert_true(ft_row_write_ln(table, 4, row_1) == FT_SUCCESS);
assert_true(ft_row_write_ln(table, 4, row_2) == FT_SUCCESS);
const char *table_str = ft_to_string(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);
}
SCENARIO("Test row_write functions(wide strings)") {
table = ft_create_table();
assert_true( table != NULL );
assert_true( set_test_options_for_table(table) == FT_SUCCESS);
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header);
const wchar_t *row_0[4] = {L"3", L"c", L"234", L"3.140000"};
const wchar_t *row_1[4] = {L"c", L"234", L"3.140000", L"3"};
const wchar_t *row_2[4] = {L"234", L"3.140000", L"3", L"c"};
assert_true(ft_row_wwrite_ln(table, 4, row_0) == FT_SUCCESS);
assert_true(ft_row_wwrite_ln(table, 4, row_1) == FT_SUCCESS);
assert_true(ft_row_wwrite_ln(table, 4, row_2) == 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 | c | 234 | 3.140000 |\n"
L"| | | | |\n"
L"+-----+----------+----------+----------+\n"
L"| | | | |\n"
L"| c | 234 | 3.140000 | 3 |\n"
L"| | | | |\n"
L"+-----+----------+----------+----------+\n"
L"| | | | |\n"
L"| 234 | 3.140000 | 3 | c |\n"
L"| | | | |\n"
L"+-----+----------+----------+----------+\n";
assert_wcs_equal( table_str, table_str_etalon );
ft_destroy_table(table);
}
SCENARIO("Test printf functions") {
table = ft_create_table();
@ -321,10 +387,12 @@ void test_table_write(void)
"| 234 | 3.140000 | 3 | c |\n"
"| | | | |\n"
"+-----+----------+----------+----------+\n";
// fprintf(stderr, "content:\n%s", table_str);
assert_true( strcmp(table_str, table_str_etalon) == 0);
assert_str_equal( table_str, table_str_etalon );
ft_destroy_table(table);
}
SCENARIO("Test printf functions(wide strings)") {
/* todo: need to implement */
}
}