[C] Changed test architecture
This commit is contained in:
107
tests/bb_tests/test_memory_errors.c
Normal file
107
tests/bb_tests/test_memory_errors.c
Normal file
@@ -0,0 +1,107 @@
|
||||
#include "tests.h"
|
||||
#include "fort.h"
|
||||
|
||||
static int aloc_num = 0;
|
||||
static int aloc_lim = 9999;
|
||||
|
||||
void *test_malloc(size_t size)
|
||||
{
|
||||
if (aloc_num < aloc_lim) {
|
||||
void *result = malloc(size);
|
||||
if (result)
|
||||
aloc_num++;
|
||||
return result;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void test_free(void *ptr)
|
||||
{
|
||||
if (ptr != 0) {
|
||||
aloc_num--;
|
||||
free(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
static int create_simple_table_and_show(void)
|
||||
{
|
||||
ft_table_t *table = NULL;
|
||||
int result = 0;
|
||||
|
||||
table = ft_create_table();
|
||||
if (table == NULL) {
|
||||
result = 1;
|
||||
goto exit;
|
||||
}
|
||||
// if (set_test_options_for_table(table) != FT_SUCCESS)
|
||||
// return 2;
|
||||
|
||||
if (ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER) != FT_SUCCESS) {
|
||||
result = 3;
|
||||
goto exit;
|
||||
}
|
||||
if (ft_write_ln(table, "3", "c", "234", "3.140000") != FT_SUCCESS) {
|
||||
result = 4;
|
||||
goto exit;
|
||||
}
|
||||
if (ft_write_ln(table, "3", "c", "234", "3.140000") != FT_SUCCESS) {
|
||||
result = 5;
|
||||
goto exit;
|
||||
}
|
||||
if (ft_write_ln(table, "3", "c", "234", "3.140000") != FT_SUCCESS) {
|
||||
result = 6;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
const char *table_str = ft_to_string(table);
|
||||
if (table_str == NULL) {
|
||||
result = 7;
|
||||
goto exit;
|
||||
}
|
||||
const char *table_str_etalon =
|
||||
"+---+---+-----+----------+\n"
|
||||
"| | | | |\n"
|
||||
"| 3 | c | 234 | 3.140000 |\n"
|
||||
"| | | | |\n"
|
||||
"+---+---+-----+----------+\n"
|
||||
"| | | | |\n"
|
||||
"| 3 | c | 234 | 3.140000 |\n"
|
||||
"| | | | |\n"
|
||||
"+---+---+-----+----------+\n"
|
||||
"| | | | |\n"
|
||||
"| 3 | c | 234 | 3.140000 |\n"
|
||||
"| | | | |\n"
|
||||
"+---+---+-----+----------+\n";
|
||||
// assert_str_equal(table_str, table_str_etalon);
|
||||
if (strcmp(table_str, table_str_etalon) != 0) {
|
||||
result = 8;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
||||
exit:
|
||||
ft_destroy_table(table);
|
||||
return result;
|
||||
}
|
||||
|
||||
void test_memory_errors(void)
|
||||
{
|
||||
ft_set_memory_funcs(&test_malloc, &test_free);
|
||||
|
||||
const int ITER_MAX = 150;
|
||||
int i;
|
||||
for (i = 0; i < ITER_MAX; ++i) {
|
||||
aloc_lim = i;
|
||||
int result = create_simple_table_and_show();
|
||||
if (result == 0)
|
||||
break;
|
||||
if (aloc_num != 0) {
|
||||
assert_true(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert_true(i != ITER_MAX);
|
||||
ft_set_memory_funcs(NULL, NULL);
|
||||
}
|
703
tests/bb_tests/test_table_basic.c
Normal file
703
tests/bb_tests/test_table_basic.c
Normal file
@@ -0,0 +1,703 @@
|
||||
#include "tests.h"
|
||||
#include <wchar.h>
|
||||
#include "fort.h"
|
||||
|
||||
void test_table_basic(void)
|
||||
{
|
||||
ft_table_t *table = NULL;
|
||||
|
||||
WHEN("All columns are equal and not empty") {
|
||||
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, FT_ROW_HEADER);
|
||||
assert_true(ft_write_ln(table, "3", "c", "234", "3.140000") == FT_SUCCESS);
|
||||
assert_true(ft_write_ln(table, "3", "c", "234", "3.140000") == FT_SUCCESS);
|
||||
assert_true(ft_write_ln(table, "3", "c", "234", "3.140000") == 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"
|
||||
"| 3 | c | 234 | 3.140000 |\n"
|
||||
"| | | | |\n"
|
||||
"+---+---+-----+----------+\n"
|
||||
"| | | | |\n"
|
||||
"| 3 | c | 234 | 3.140000 |\n"
|
||||
"| | | | |\n"
|
||||
"+---+---+-----+----------+\n";
|
||||
assert_str_equal(table_str, table_str_etalon);
|
||||
ft_destroy_table(table);
|
||||
}
|
||||
|
||||
#ifdef FT_HAVE_WCHAR
|
||||
WHEN("All columns are 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_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
||||
assert_true(ft_wwrite_ln(table, L"3", L"c", L"234", L"3.140000") == FT_SUCCESS);
|
||||
assert_true(ft_wwrite_ln(table, L"3", L"c", L"234", L"3.140000") == FT_SUCCESS);
|
||||
assert_true(ft_wwrite_ln(table, L"3", L"c", L"234", L"3.140000") == 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"| 3 | c | 234 | 3.140000 |\n"
|
||||
L"| | | | |\n"
|
||||
L"+---+---+-----+----------+\n"
|
||||
L"| | | | |\n"
|
||||
L"| 3 | c | 234 | 3.140000 |\n"
|
||||
L"| | | | |\n"
|
||||
L"+---+---+-----+----------+\n";
|
||||
assert_wcs_equal(table_str, table_str_etalon);
|
||||
ft_destroy_table(table);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
WHEN("All columns are not equal and not empty") {
|
||||
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, FT_ROW_HEADER);
|
||||
assert_true(ft_write_ln(table, "3", "c", "234", "3.140000") == FT_SUCCESS);
|
||||
assert_true(ft_write_ln(table, "c", "234", "3.140000", "3") == FT_SUCCESS);
|
||||
assert_true(ft_write_ln(table, "234", "3.140000", "3", "c") == 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);
|
||||
}
|
||||
|
||||
#ifdef FT_HAVE_WCHAR
|
||||
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_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
||||
assert_true(ft_wwrite_ln(table, L"3", L"c", L"234", L"3.140000") == FT_SUCCESS);
|
||||
assert_true(ft_wwrite_ln(table, L"c", L"234", L"3.140000", L"3") == FT_SUCCESS);
|
||||
assert_true(ft_wwrite_ln(table, L"234", L"3.140000", L"3", 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 | 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);
|
||||
}
|
||||
#endif
|
||||
|
||||
WHEN("All columns are not equal and some cells are empty") {
|
||||
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, FT_ROW_HEADER);
|
||||
assert_true(ft_write_ln(table, "", "", "234", "3.140000") == FT_SUCCESS);
|
||||
assert_true(ft_write_ln(table, "c", "234", "3.140000", "") == FT_SUCCESS);
|
||||
assert_true(ft_write_ln(table, "234", "3.140000", "", "") == FT_SUCCESS);
|
||||
|
||||
const char *table_str = ft_to_string(table);
|
||||
assert_true(table_str != NULL);
|
||||
const char *table_str_etalon =
|
||||
"+-----+----------+----------+----------+\n"
|
||||
"| | | | |\n"
|
||||
"| | | 234 | 3.140000 |\n"
|
||||
"| | | | |\n"
|
||||
"+-----+----------+----------+----------+\n"
|
||||
"| | | | |\n"
|
||||
"| c | 234 | 3.140000 | |\n"
|
||||
"| | | | |\n"
|
||||
"+-----+----------+----------+----------+\n"
|
||||
"| | | | |\n"
|
||||
"| 234 | 3.140000 | | |\n"
|
||||
"| | | | |\n"
|
||||
"+-----+----------+----------+----------+\n";
|
||||
assert_str_equal(table_str, table_str_etalon);
|
||||
ft_destroy_table(table);
|
||||
}
|
||||
|
||||
#ifdef FT_HAVE_WCHAR
|
||||
WHEN("All columns are not equal and some cells are empty (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, FT_ROW_HEADER);
|
||||
assert_true(ft_wwrite_ln(table, L"", L"", L"234", L"3.140000") == FT_SUCCESS);
|
||||
assert_true(ft_wwrite_ln(table, L"c", L"234", L"3.140000", L"") == FT_SUCCESS);
|
||||
assert_true(ft_wwrite_ln(table, L"234", L"3.140000", L"", L"") == 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"| | | 234 | 3.140000 |\n"
|
||||
L"| | | | |\n"
|
||||
L"+-----+----------+----------+----------+\n"
|
||||
L"| | | | |\n"
|
||||
L"| c | 234 | 3.140000 | |\n"
|
||||
L"| | | | |\n"
|
||||
L"+-----+----------+----------+----------+\n"
|
||||
L"| | | | |\n"
|
||||
L"| 234 | 3.140000 | | |\n"
|
||||
L"| | | | |\n"
|
||||
L"+-----+----------+----------+----------+\n";
|
||||
assert_wcs_equal(table_str, table_str_etalon);
|
||||
ft_destroy_table(table);
|
||||
}
|
||||
#endif
|
||||
|
||||
WHEN("All cells are empty") {
|
||||
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, FT_ROW_HEADER);
|
||||
assert_true(ft_write_ln(table, "", "", "", "") == FT_SUCCESS);
|
||||
assert_true(ft_write_ln(table, "", "", "", "") == FT_SUCCESS);
|
||||
assert_true(ft_write_ln(table, "", "", "", "") == FT_SUCCESS);
|
||||
|
||||
const char *table_str = ft_to_string(table);
|
||||
assert_true(table_str != NULL);
|
||||
const char *table_str_etalon =
|
||||
"+--+--+--+--+\n"
|
||||
"| | | | |\n"
|
||||
"| | | | |\n"
|
||||
"| | | | |\n"
|
||||
"+--+--+--+--+\n"
|
||||
"| | | | |\n"
|
||||
"| | | | |\n"
|
||||
"| | | | |\n"
|
||||
"+--+--+--+--+\n"
|
||||
"| | | | |\n"
|
||||
"| | | | |\n"
|
||||
"| | | | |\n"
|
||||
"+--+--+--+--+\n";
|
||||
assert_str_equal(table_str, table_str_etalon);
|
||||
ft_destroy_table(table);
|
||||
}
|
||||
|
||||
#ifdef FT_HAVE_WCHAR
|
||||
WHEN("All cells are empty (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, FT_ROW_HEADER);
|
||||
assert_true(ft_wwrite_ln(table, L"", L"", L"", L"") == FT_SUCCESS);
|
||||
assert_true(ft_wwrite_ln(table, L"", L"", L"", L"") == FT_SUCCESS);
|
||||
assert_true(ft_wwrite_ln(table, L"", L"", L"", L"") == 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"| | | | |\n"
|
||||
L"| | | | |\n"
|
||||
L"+--+--+--+--+\n"
|
||||
L"| | | | |\n"
|
||||
L"| | | | |\n"
|
||||
L"| | | | |\n"
|
||||
L"+--+--+--+--+\n"
|
||||
L"| | | | |\n"
|
||||
L"| | | | |\n"
|
||||
L"| | | | |\n"
|
||||
L"+--+--+--+--+\n";
|
||||
assert_wcs_equal(table_str, table_str_etalon);
|
||||
ft_destroy_table(table);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef FT_HAVE_WCHAR
|
||||
void test_wcs_table_boundaries(void)
|
||||
{
|
||||
ft_table_t *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_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
||||
assert_true(ft_wwrite_ln(table, L"3", L"12345\x8888\x8888", L"c") == FT_SUCCESS); /* \x8888,\x8888 - occupy 2 columns each */
|
||||
assert_true(ft_wwrite_ln(table, L"c", L"12345678\x500", L"c") == FT_SUCCESS); /* \x500 - occupies 1 column */
|
||||
assert_true(ft_wwrite_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";
|
||||
assert_wcs_equal(table_str, table_str_etalon);
|
||||
ft_destroy_table(table);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void test_table_write(void)
|
||||
{
|
||||
ft_table_t *table = NULL;
|
||||
|
||||
SCENARIO("Test 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, FT_ROW_HEADER);
|
||||
assert_true(FT_IS_SUCCESS(ft_write(table, "3")));
|
||||
assert_true(FT_IS_SUCCESS(ft_write(table, "c")));
|
||||
assert_true(FT_IS_SUCCESS(ft_write(table, "234")));
|
||||
assert_true(FT_IS_SUCCESS(ft_write(table, "3.140000")));
|
||||
ft_ln(table);
|
||||
assert_true(FT_IS_SUCCESS(ft_write(table, "c")));
|
||||
assert_true(FT_IS_SUCCESS(ft_write(table, "235")));
|
||||
assert_true(FT_IS_SUCCESS(ft_write(table, "3.150000")));
|
||||
assert_true(FT_IS_SUCCESS(ft_write_ln(table, "5")));
|
||||
|
||||
assert_true(FT_IS_SUCCESS(ft_write(table, "234")));
|
||||
assert_true(FT_IS_SUCCESS(ft_write(table, "3.140000")));
|
||||
assert_true(FT_IS_SUCCESS(ft_write(table, "3")));
|
||||
assert_true(FT_IS_SUCCESS(ft_write_ln(table, "c")));
|
||||
|
||||
/* Replace old values */
|
||||
ft_set_cur_cell(table, 1, 1);
|
||||
assert_true(FT_IS_SUCCESS(ft_write(table, "234")));
|
||||
assert_true(FT_IS_SUCCESS(ft_write(table, "3.140000")));
|
||||
assert_true(FT_IS_SUCCESS(ft_write_ln(table, "3")));
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
#ifdef FT_HAVE_WCHAR
|
||||
SCENARIO("Test wwrite 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, FT_ROW_HEADER);
|
||||
assert_true(FT_IS_SUCCESS(ft_wwrite(table, L"3")));
|
||||
assert_true(FT_IS_SUCCESS(ft_wwrite(table, L"c")));
|
||||
assert_true(FT_IS_SUCCESS(ft_wwrite(table, L"234")));
|
||||
assert_true(FT_IS_SUCCESS(ft_wwrite(table, L"3.140000")));
|
||||
ft_ln(table);
|
||||
assert_true(FT_IS_SUCCESS(ft_wwrite(table, L"c")));
|
||||
assert_true(FT_IS_SUCCESS(ft_wwrite(table, L"235")));
|
||||
assert_true(FT_IS_SUCCESS(ft_wwrite(table, L"3.150000")));
|
||||
assert_true(FT_IS_SUCCESS(ft_wwrite_ln(table, L"5")));
|
||||
|
||||
assert_true(FT_IS_SUCCESS(ft_wwrite(table, L"234")));
|
||||
assert_true(FT_IS_SUCCESS(ft_wwrite(table, L"3.140000")));
|
||||
assert_true(FT_IS_SUCCESS(ft_wwrite(table, L"3")));
|
||||
assert_true(FT_IS_SUCCESS(ft_wwrite_ln(table, L"c")));
|
||||
|
||||
/* Replace old values */
|
||||
ft_set_cur_cell(table, 1, 1);
|
||||
assert_true(FT_IS_SUCCESS(ft_wwrite(table, L"234")));
|
||||
assert_true(FT_IS_SUCCESS(ft_wwrite(table, L"3.140000")));
|
||||
assert_true(FT_IS_SUCCESS(ft_wwrite_ln(table, L"3")));
|
||||
|
||||
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);
|
||||
}
|
||||
#endif
|
||||
|
||||
SCENARIO("Test nwrite 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, FT_ROW_HEADER);
|
||||
assert_true(ft_nwrite(table, 4, "3", "c", "234", "3.140000") == FT_SUCCESS);
|
||||
ft_ln(table);
|
||||
assert_true(ft_nwrite_ln(table, 4, "c", "235", "3.150000", "5") == FT_SUCCESS);
|
||||
assert_true(ft_nwrite_ln(table, 4, "234", "3.140000", "3", "c") == FT_SUCCESS);
|
||||
|
||||
/* Replace old values */
|
||||
ft_set_cur_cell(table, 1, 1);
|
||||
assert_true(ft_nwrite_ln(table, 3, "234", "3.140000", "3") == 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);
|
||||
}
|
||||
|
||||
#ifdef FT_HAVE_WCHAR
|
||||
SCENARIO("Test nwwrite 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, FT_ROW_HEADER);
|
||||
assert_true(ft_nwwrite(table, 4, L"3", L"c", L"234", L"3.140000") == FT_SUCCESS);
|
||||
ft_ln(table);
|
||||
assert_true(ft_nwwrite_ln(table, 4, L"c", L"235", L"3.150000", L"5") == FT_SUCCESS);
|
||||
assert_true(ft_nwwrite_ln(table, 4, L"234", L"3.140000", L"3", L"c") == FT_SUCCESS);
|
||||
|
||||
/* Replace old values */
|
||||
ft_set_cur_cell(table, 1, 1);
|
||||
assert_true(ft_nwwrite_ln(table, 3, L"234", L"3.140000", L"3") == 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);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
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, FT_ROW_HEADER);
|
||||
const char *row_0[4] = {"3", "c", "234", "3.140000"};
|
||||
const char *row_1[4] = {"c", "235", "3.150000", "5"};
|
||||
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(table, 4, row_1) == FT_SUCCESS);
|
||||
ft_ln(table);
|
||||
assert_true(ft_row_write_ln(table, 4, row_2) == FT_SUCCESS);
|
||||
|
||||
/* Replace old values */
|
||||
ft_set_cur_cell(table, 1, 1);
|
||||
const char *row_11[3] = {"234", "3.140000", "3"};
|
||||
assert_true(ft_row_write(table, 3, row_11) == FT_SUCCESS);
|
||||
ft_ln(table);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
#ifdef FT_HAVE_WCHAR
|
||||
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, FT_ROW_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"235", L"3.150000", L"5"};
|
||||
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(table, 4, row_1) == FT_SUCCESS);
|
||||
ft_ln(table);
|
||||
assert_true(ft_row_wwrite_ln(table, 4, row_2) == FT_SUCCESS);
|
||||
|
||||
/* Replace old values */
|
||||
ft_set_cur_cell(table, 1, 1);
|
||||
const wchar_t *row_11[3] = {L"234", L"3.140000", L"3"};
|
||||
assert_true(ft_row_wwrite(table, 3, row_11) == FT_SUCCESS);
|
||||
ft_ln(table);
|
||||
|
||||
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);
|
||||
}
|
||||
#endif
|
||||
|
||||
SCENARIO("Test table_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, FT_ROW_HEADER);
|
||||
const char *table_cont[3][4] = {
|
||||
{"3", "c", "234", "3.140000"},
|
||||
{"c", "234", "3.140000", "3"},
|
||||
{"234", "3.140000", "3", "c"}
|
||||
};
|
||||
assert_true(ft_table_write_ln(table, 3, 4, (const char **)table_cont) == 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);
|
||||
}
|
||||
|
||||
#ifdef FT_HAVE_WCHAR
|
||||
SCENARIO("Test table_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, FT_ROW_HEADER);
|
||||
const wchar_t *table_cont[3][4] = {
|
||||
{L"3", L"c", L"234", L"3.140000"},
|
||||
{L"c", L"234", L"3.140000", L"3"},
|
||||
{L"234", L"3.140000", L"3", L"c"}
|
||||
};
|
||||
assert_true(ft_table_wwrite_ln(table, 3, 4, (const wchar_t **)table_cont) == 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);
|
||||
}
|
||||
#endif
|
||||
|
||||
SCENARIO("Test printf 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, FT_ROW_HEADER);
|
||||
int n = ft_printf_ln(table, "%d|%c|%s|%f", 3, 'c', "234", 3.14);
|
||||
assert_true(n == 4);
|
||||
n = ft_printf(table, "%c|%s|%f|%d", 'c', "235", 3.15, 5);
|
||||
assert_true(n == 4);
|
||||
ft_ln(table);
|
||||
n = ft_printf_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_printf(table, "%s|%f|%d", "234", 3.14, 3);
|
||||
assert_true(n == 3);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
#ifdef FT_HAVE_WCHAR
|
||||
SCENARIO("Test printf 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, FT_ROW_HEADER);
|
||||
int n = ft_wprintf_ln(table, L"%d|%c|%ls|%f", 3, 'c', L"234", 3.14);
|
||||
assert_true(n == 4);
|
||||
n = ft_wprintf(table, L"%c|%ls|%f|%d", 'c', L"235", 3.15, 5);
|
||||
assert_true(n == 4);
|
||||
ft_ln(table);
|
||||
n = ft_wprintf_ln(table, L"%ls|%f|%d|%c", L"234", 3.14, 3, 'c');
|
||||
assert_true(n == 4);
|
||||
|
||||
/* Replace old values */
|
||||
ft_set_cur_cell(table, 1, 1);
|
||||
n = ft_wprintf_ln(table, L"%ls|%f|%d", L"234", 3.14, 3);
|
||||
assert_true(n == 3);
|
||||
|
||||
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);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
131
tests/bb_tests/test_table_border_style.c
Normal file
131
tests/bb_tests/test_table_border_style.c
Normal file
@@ -0,0 +1,131 @@
|
||||
#include "tests.h"
|
||||
#include "fort.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void test_table_border_style(void)
|
||||
{
|
||||
ft_table_t *table = NULL;
|
||||
|
||||
set_test_options_as_default();
|
||||
|
||||
|
||||
WHEN("Changing cell separators") {
|
||||
|
||||
struct ft_border_style brdr_style;
|
||||
brdr_style.border_chs.top_border_ch = "|";
|
||||
brdr_style.border_chs.separator_ch = "|";
|
||||
brdr_style.border_chs.bottom_border_ch = "|";
|
||||
brdr_style.border_chs.side_border_ch = "=";
|
||||
brdr_style.border_chs.out_intersect_ch = "+";
|
||||
brdr_style.border_chs.in_intersect_ch = "#";
|
||||
|
||||
brdr_style.header_border_chs.top_border_ch = "*";
|
||||
brdr_style.header_border_chs.separator_ch = "*";
|
||||
brdr_style.header_border_chs.bottom_border_ch = "*";
|
||||
brdr_style.header_border_chs.side_border_ch = "v";
|
||||
brdr_style.header_border_chs.out_intersect_ch = "+";
|
||||
brdr_style.header_border_chs.in_intersect_ch = "#";
|
||||
|
||||
brdr_style.hor_separator_char = "|";
|
||||
ft_set_default_border_style(&brdr_style);
|
||||
|
||||
|
||||
|
||||
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"
|
||||
"v v v v v\n"
|
||||
"v 3 v 4 v 55 v 67 v\n"
|
||||
"v v v v v\n"
|
||||
"+***#***#****#****+\n"
|
||||
"= = = = =\n"
|
||||
"= 3 = 4 = 55 = 67 =\n"
|
||||
"= = = = =\n"
|
||||
"+|||#|||#||||#||||+\n"
|
||||
"= = = = =\n"
|
||||
"= 3 = 4 = 55 = 67 =\n"
|
||||
"= = = = =\n"
|
||||
"+|||+|||+||||+||||+\n";
|
||||
assert_str_equal(table_str, table_str_etalon);
|
||||
ft_destroy_table(table);
|
||||
|
||||
|
||||
|
||||
brdr_style.border_chs.top_border_ch = "|";
|
||||
brdr_style.border_chs.separator_ch = "\0";
|
||||
brdr_style.border_chs.bottom_border_ch = "|";
|
||||
brdr_style.border_chs.side_border_ch = "=";
|
||||
brdr_style.border_chs.out_intersect_ch = "+";
|
||||
brdr_style.border_chs.in_intersect_ch = "\0";
|
||||
|
||||
brdr_style.header_border_chs.top_border_ch = "*";
|
||||
brdr_style.header_border_chs.separator_ch = "*";
|
||||
brdr_style.header_border_chs.bottom_border_ch = "*";
|
||||
brdr_style.header_border_chs.side_border_ch = "v";
|
||||
brdr_style.header_border_chs.out_intersect_ch = "+";
|
||||
brdr_style.header_border_chs.in_intersect_ch = "#";
|
||||
|
||||
brdr_style.hor_separator_char = "";
|
||||
|
||||
ft_set_default_border_style(&brdr_style);
|
||||
|
||||
ft_set_default_cell_option(FT_COPT_BOTTOM_PADDING, 0);
|
||||
ft_set_default_cell_option(FT_COPT_TOP_PADDING, 0);
|
||||
ft_set_default_cell_option(FT_COPT_LEFT_PADDING, 1);
|
||||
ft_set_default_cell_option(FT_COPT_RIGHT_PADDING, 1);
|
||||
ft_set_default_cell_option(FT_COPT_EMPTY_STR_HEIGHT, 0);
|
||||
|
||||
|
||||
table = create_test_int_table(0);
|
||||
table_str = ft_to_string(table);
|
||||
assert_true(table_str != NULL);
|
||||
table_str_etalon =
|
||||
"+***+***+****+****+\n"
|
||||
"v 3 v 4 v 55 v 67 v\n"
|
||||
"+***#***#****#****+\n"
|
||||
"= 3 = 4 = 55 = 67 =\n"
|
||||
"= 3 = 4 = 55 = 67 =\n"
|
||||
"+|||+|||+||||+||||+\n";
|
||||
assert_str_equal(table_str, table_str_etalon);
|
||||
ft_destroy_table(table);
|
||||
}
|
||||
|
||||
|
||||
WHEN("Separator testing") {
|
||||
table = create_test_int_table(1);
|
||||
ft_add_separator(table);
|
||||
|
||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
||||
int n = ft_printf_ln(table, "%d|%d|%d|%d", 3, 4, 55, 67);
|
||||
|
||||
assert_true(n == 4);
|
||||
|
||||
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"
|
||||
"| | | | |\n"
|
||||
"| 3 | 4 | 55 | 67 |\n"
|
||||
"| | | | |\n"
|
||||
"+---+---+----+----+\n";
|
||||
assert_str_equal(table_str, table_str_etalon);
|
||||
ft_destroy_table(table);
|
||||
}
|
||||
}
|
495
tests/bb_tests/test_table_options.c
Normal file
495
tests/bb_tests/test_table_options.c
Normal file
@@ -0,0 +1,495 @@
|
||||
#include "tests.h"
|
||||
#include "fort.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "options.h"
|
||||
#include "vector.h"
|
||||
|
||||
|
||||
|
||||
void test_table_tbl_options(void)
|
||||
{
|
||||
ft_table_t *table = NULL;
|
||||
|
||||
WHEN("Test setting entire table options") {
|
||||
set_test_options_as_default();
|
||||
|
||||
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_str_equal(table_str, table_str_etalon);
|
||||
|
||||
/* Now set table options */
|
||||
ft_set_tbl_option(table, FT_TOPT_TOP_MARGIN, 3);
|
||||
ft_set_tbl_option(table, FT_TOPT_BOTTOM_MARGIN, 4);
|
||||
ft_set_tbl_option(table, FT_TOPT_LEFT_MARGIN, 1);
|
||||
ft_set_tbl_option(table, FT_TOPT_RIGHT_MARGIN, 2);
|
||||
table_str = ft_to_string(table);
|
||||
assert_true(table_str != NULL);
|
||||
table_str_etalon =
|
||||
" \n"
|
||||
" \n"
|
||||
" \n"
|
||||
" +---+---+----+----+ \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"
|
||||
" \n"
|
||||
" \n"
|
||||
" \n"
|
||||
" \n";
|
||||
assert_str_equal(table_str, table_str_etalon);
|
||||
|
||||
ft_destroy_table(table);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef FT_HAVE_WCHAR
|
||||
WHEN("Test setting entire table options(wide strings case)") {
|
||||
set_test_options_as_default();
|
||||
|
||||
table = create_test_int_wtable(0);
|
||||
|
||||
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 | 4 | 55 | 67 |\n"
|
||||
L"| | | | |\n"
|
||||
L"+---+---+----+----+\n"
|
||||
L"| | | | |\n"
|
||||
L"| 3 | 4 | 55 | 67 |\n"
|
||||
L"| | | | |\n"
|
||||
L"+---+---+----+----+\n"
|
||||
L"| | | | |\n"
|
||||
L"| 3 | 4 | 55 | 67 |\n"
|
||||
L"| | | | |\n"
|
||||
L"+---+---+----+----+\n";
|
||||
assert_wcs_equal(table_str, table_str_etalon);
|
||||
|
||||
/* Now set table options */
|
||||
ft_set_tbl_option(table, FT_TOPT_TOP_MARGIN, 3);
|
||||
ft_set_tbl_option(table, FT_TOPT_BOTTOM_MARGIN, 4);
|
||||
ft_set_tbl_option(table, FT_TOPT_LEFT_MARGIN, 1);
|
||||
ft_set_tbl_option(table, FT_TOPT_RIGHT_MARGIN, 2);
|
||||
table_str = ft_to_wstring(table);
|
||||
assert_true(table_str != NULL);
|
||||
table_str_etalon =
|
||||
L" \n"
|
||||
L" \n"
|
||||
L" \n"
|
||||
L" +---+---+----+----+ \n"
|
||||
L" | | | | | \n"
|
||||
L" | 3 | 4 | 55 | 67 | \n"
|
||||
L" | | | | | \n"
|
||||
L" +---+---+----+----+ \n"
|
||||
L" | | | | | \n"
|
||||
L" | 3 | 4 | 55 | 67 | \n"
|
||||
L" | | | | | \n"
|
||||
L" +---+---+----+----+ \n"
|
||||
L" | | | | | \n"
|
||||
L" | 3 | 4 | 55 | 67 | \n"
|
||||
L" | | | | | \n"
|
||||
L" +---+---+----+----+ \n"
|
||||
L" \n"
|
||||
L" \n"
|
||||
L" \n"
|
||||
L" \n";
|
||||
assert_wcs_equal(table_str, table_str_etalon);
|
||||
|
||||
ft_destroy_table(table);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
void test_table_cell_options(void)
|
||||
{
|
||||
ft_table_t *table = NULL;
|
||||
|
||||
|
||||
WHEN("All paddings = 1") {
|
||||
set_test_options_as_default();
|
||||
|
||||
ft_set_default_cell_option(FT_COPT_BOTTOM_PADDING, 1);
|
||||
ft_set_default_cell_option(FT_COPT_TOP_PADDING, 1);
|
||||
ft_set_default_cell_option(FT_COPT_LEFT_PADDING, 1);
|
||||
ft_set_default_cell_option(FT_COPT_RIGHT_PADDING, 1);
|
||||
|
||||
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_str_equal(table_str, table_str_etalon);
|
||||
ft_destroy_table(table);
|
||||
}
|
||||
|
||||
|
||||
|
||||
WHEN("Top and bottom padding = 0") {
|
||||
|
||||
ft_set_default_cell_option(FT_COPT_BOTTOM_PADDING, 0);
|
||||
ft_set_default_cell_option(FT_COPT_TOP_PADDING, 0);
|
||||
ft_set_default_cell_option(FT_COPT_LEFT_PADDING, 1);
|
||||
ft_set_default_cell_option(FT_COPT_RIGHT_PADDING, 1);
|
||||
|
||||
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"
|
||||
"| 3 | 4 | 55 | 67 |\n"
|
||||
"+---+---+----+----+\n"
|
||||
"| 3 | 4 | 55 | 67 |\n"
|
||||
"+---+---+----+----+\n"
|
||||
"| 3 | 4 | 55 | 67 |\n"
|
||||
"+---+---+----+----+\n";
|
||||
assert_str_equal(table_str, table_str_etalon);
|
||||
ft_destroy_table(table);
|
||||
}
|
||||
|
||||
WHEN("Left and right padding = 0") {
|
||||
|
||||
ft_set_default_cell_option(FT_COPT_BOTTOM_PADDING, 1);
|
||||
ft_set_default_cell_option(FT_COPT_TOP_PADDING, 1);
|
||||
ft_set_default_cell_option(FT_COPT_LEFT_PADDING, 0);
|
||||
ft_set_default_cell_option(FT_COPT_RIGHT_PADDING, 0);
|
||||
|
||||
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_str_equal(table_str, table_str_etalon);
|
||||
ft_destroy_table(table);
|
||||
}
|
||||
|
||||
WHEN("All paddings = 0") {
|
||||
|
||||
ft_set_default_cell_option(FT_COPT_BOTTOM_PADDING, 0);
|
||||
ft_set_default_cell_option(FT_COPT_TOP_PADDING, 0);
|
||||
ft_set_default_cell_option(FT_COPT_LEFT_PADDING, 0);
|
||||
ft_set_default_cell_option(FT_COPT_RIGHT_PADDING, 0);
|
||||
|
||||
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"
|
||||
"|3|4|55|67|\n"
|
||||
"+-+-+--+--+\n"
|
||||
"|3|4|55|67|\n"
|
||||
"+-+-+--+--+\n"
|
||||
"|3|4|55|67|\n"
|
||||
"+-+-+--+--+\n";
|
||||
assert_str_equal(table_str, table_str_etalon);
|
||||
ft_destroy_table(table);
|
||||
}
|
||||
|
||||
WHEN("Empty string has 0 heigt") {
|
||||
|
||||
ft_set_default_cell_option(FT_COPT_BOTTOM_PADDING, 1);
|
||||
ft_set_default_cell_option(FT_COPT_TOP_PADDING, 1);
|
||||
ft_set_default_cell_option(FT_COPT_LEFT_PADDING, 1);
|
||||
ft_set_default_cell_option(FT_COPT_RIGHT_PADDING, 1);
|
||||
ft_set_default_cell_option(FT_COPT_EMPTY_STR_HEIGHT, 0);
|
||||
|
||||
table = create_test_int_table(0);
|
||||
int n = ft_printf_ln(table, "|||");
|
||||
assert_true(n == 4);
|
||||
|
||||
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"
|
||||
"| | | | |\n"
|
||||
"| | | | |\n"
|
||||
"+---+---+----+----+\n";
|
||||
assert_str_equal(table_str, table_str_etalon);
|
||||
ft_destroy_table(table);
|
||||
}
|
||||
|
||||
|
||||
WHEN("Setting options for a particular table") {
|
||||
|
||||
table = create_test_int_table(0);
|
||||
set_test_options_for_table(table);
|
||||
|
||||
ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_BOTTOM_PADDING, 0);
|
||||
ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_TOP_PADDING, 0);
|
||||
ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_LEFT_PADDING, 0);
|
||||
ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_RIGHT_PADDING, 0);
|
||||
|
||||
const char *table_str = ft_to_string(table);
|
||||
assert_true(table_str != NULL);
|
||||
const char *table_str_etalon =
|
||||
"+-+-+--+--+\n"
|
||||
"|3|4|55|67|\n"
|
||||
"+-+-+--+--+\n"
|
||||
"|3|4|55|67|\n"
|
||||
"+-+-+--+--+\n"
|
||||
"|3|4|55|67|\n"
|
||||
"+-+-+--+--+\n";
|
||||
assert_str_equal(table_str, table_str_etalon);
|
||||
|
||||
|
||||
ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_BOTTOM_PADDING, 1);
|
||||
ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_TOP_PADDING, 1);
|
||||
ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_LEFT_PADDING, 0);
|
||||
ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_RIGHT_PADDING, 0);
|
||||
ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_EMPTY_STR_HEIGHT, 0);
|
||||
|
||||
table_str = ft_to_string(table);
|
||||
assert_true(table_str != NULL);
|
||||
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_str_equal(table_str, table_str_etalon);
|
||||
ft_destroy_table(table);
|
||||
}
|
||||
|
||||
|
||||
|
||||
WHEN("Set table width and column alignment") {
|
||||
|
||||
set_test_options_as_default();
|
||||
|
||||
table = create_test_int_table(0);
|
||||
int status = FT_SUCCESS;
|
||||
|
||||
status |= ft_set_cell_option(table, FT_ANY_ROW, 1, FT_COPT_MIN_WIDTH, 7);
|
||||
status |= ft_set_cell_option(table, FT_ANY_ROW, 1, FT_COPT_TEXT_ALIGN, FT_ALIGNED_LEFT);
|
||||
status |= ft_set_cell_option(table, FT_ANY_ROW, 2, FT_COPT_MIN_WIDTH, 8);
|
||||
status |= ft_set_cell_option(table, FT_ANY_ROW, 2, FT_COPT_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
||||
|
||||
status |= ft_set_cell_option(table, 2, 3, FT_COPT_MIN_WIDTH, 6);
|
||||
status |= ft_set_cell_option(table, 2, 3, FT_COPT_TEXT_ALIGN, FT_ALIGNED_LEFT);
|
||||
assert_true(status == FT_SUCCESS);
|
||||
|
||||
|
||||
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_str_equal(table_str, table_str_etalon);
|
||||
ft_destroy_table(table);
|
||||
}
|
||||
|
||||
WHEN("Set table width and column alignment as default") {
|
||||
|
||||
set_test_options_as_default();
|
||||
|
||||
int status = FT_SUCCESS;
|
||||
status |= ft_set_default_cell_option(FT_COPT_MIN_WIDTH, 5);
|
||||
status |= ft_set_default_cell_option(FT_COPT_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
||||
assert_true(status == FT_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_str_equal(table_str, table_str_etalon);
|
||||
ft_destroy_table(table);
|
||||
}
|
||||
|
||||
WHEN("Multiline cell") {
|
||||
set_test_options_as_default();
|
||||
|
||||
table = ft_create_table();
|
||||
|
||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
||||
int n = ft_printf_ln(table, "%d|%c|%s|%f", 4, 'c', "234", 3.14);
|
||||
|
||||
assert_true(n == 4);
|
||||
n = ft_write_ln(table, "5", "c", "234\n12", "3.140000");
|
||||
assert_true(n == FT_SUCCESS);
|
||||
n = ft_printf_ln(table, "%d|%c|%s|%f", 3, 'c', "234", 3.14);
|
||||
assert_true(n == 4);
|
||||
|
||||
const char *table_str = ft_to_string(table);
|
||||
assert_true(table_str != NULL);
|
||||
const char *table_str_etalon =
|
||||
"+---+---+-----+----------+\n"
|
||||
"| | | | |\n"
|
||||
"| 4 | c | 234 | 3.140000 |\n"
|
||||
"| | | | |\n"
|
||||
"+---+---+-----+----------+\n"
|
||||
"| | | | |\n"
|
||||
"| 5 | c | 234 | 3.140000 |\n"
|
||||
"| | | 12 | |\n"
|
||||
"| | | | |\n"
|
||||
"+---+---+-----+----------+\n"
|
||||
"| | | | |\n"
|
||||
"| 3 | c | 234 | 3.140000 |\n"
|
||||
"| | | | |\n"
|
||||
"+---+---+-----+----------+\n";
|
||||
assert_str_equal(table_str, table_str_etalon);
|
||||
ft_destroy_table(table);
|
||||
}
|
||||
|
||||
|
||||
WHEN("Cells with spans") {
|
||||
set_test_options_as_default();
|
||||
|
||||
table = ft_create_table();
|
||||
int n = ft_set_cell_span(table, 0, 0, 5);
|
||||
assert_true(n == FT_SUCCESS);
|
||||
n = ft_set_cell_span(table, 1, 1, 3);
|
||||
assert_true(n == FT_SUCCESS);
|
||||
|
||||
n = ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
||||
assert_true(n == FT_SUCCESS);
|
||||
n = ft_set_cell_option(table, 1, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
||||
assert_true(n == FT_SUCCESS);
|
||||
|
||||
n = ft_write_ln(table, "111", "2222", "33333", "444444", "55555555");
|
||||
assert_true(n == FT_SUCCESS);
|
||||
n = ft_write_ln(table, "2222", "33333", "444444", "55555555", "111");
|
||||
assert_true(n == FT_SUCCESS);
|
||||
|
||||
n = ft_write_ln(table, "33333", "444444", "55555555", "111", "2222");
|
||||
assert_true(n == FT_SUCCESS);
|
||||
n = ft_write_ln(table, "2222", "33333", "444444", "55555555", "111");
|
||||
assert_true(n == FT_SUCCESS);
|
||||
n = ft_write_ln(table, "2222", "33333", "444444", "55555555", "111");
|
||||
assert_true(n == FT_SUCCESS);
|
||||
|
||||
n = ft_set_cell_span(table, 4, 3, 2);
|
||||
assert_true(n == FT_SUCCESS);
|
||||
|
||||
|
||||
const char *table_str = ft_to_string(table);
|
||||
assert_true(table_str != NULL);
|
||||
const char *table_str_etalon =
|
||||
"+---------------------------------------------+\n"
|
||||
"| |\n"
|
||||
"| 111 |\n"
|
||||
"| |\n"
|
||||
"+-------+------------------------------+------+\n"
|
||||
"| | | |\n"
|
||||
"| 2222 | 33333 | 111 |\n"
|
||||
"| | | |\n"
|
||||
"+-------+--------+----------+----------+------+\n"
|
||||
"| | | | | |\n"
|
||||
"| 33333 | 444444 | 55555555 | 111 | 2222 |\n"
|
||||
"| | | | | |\n"
|
||||
"+-------+--------+----------+----------+------+\n"
|
||||
"| | | | | |\n"
|
||||
"| 2222 | 33333 | 444444 | 55555555 | 111 |\n"
|
||||
"| | | | | |\n"
|
||||
"+-------+--------+----------+----------+------+\n"
|
||||
"| | | | |\n"
|
||||
"| 2222 | 33333 | 444444 | 55555555 |\n"
|
||||
"| | | | |\n"
|
||||
"+-------+--------+----------+-----------------+\n";
|
||||
assert_str_equal(table_str, table_str_etalon);
|
||||
ft_destroy_table(table);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user