2018-03-19 21:07:18 +01:00
|
|
|
#include "tests.h"
|
|
|
|
#include "fort.h"
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2019-04-26 22:11:09 +02:00
|
|
|
|
2018-11-24 21:14:26 +01:00
|
|
|
#include "test_utils.h"
|
2018-03-19 21:07:18 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-03 21:50:30 +01:00
|
|
|
void test_table_tbl_properties(void)
|
2018-03-25 10:11:08 +02:00
|
|
|
{
|
2018-05-05 21:34:45 +02:00
|
|
|
ft_table_t *table = NULL;
|
2018-03-25 10:11:08 +02:00
|
|
|
|
2018-11-03 21:50:30 +01:00
|
|
|
WHEN("Test setting entire table properties") {
|
|
|
|
set_test_properties_as_default();
|
2018-03-25 10:11:08 +02:00
|
|
|
|
|
|
|
table = create_test_int_table(0);
|
|
|
|
|
|
|
|
const char *table_str = ft_to_string(table);
|
2018-03-31 12:33:37 +02:00
|
|
|
assert_true(table_str != NULL);
|
2018-03-25 10:11:08 +02:00
|
|
|
const char *table_str_etalon =
|
2018-03-31 12:33:37 +02:00
|
|
|
"+---+---+----+----+\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";
|
2018-03-25 10:11:08 +02:00
|
|
|
assert_str_equal(table_str, table_str_etalon);
|
|
|
|
|
2018-11-03 21:50:30 +01:00
|
|
|
/* Now set table properties */
|
|
|
|
ft_set_tbl_prop(table, FT_TPROP_TOP_MARGIN, 3);
|
|
|
|
ft_set_tbl_prop(table, FT_TPROP_BOTTOM_MARGIN, 4);
|
|
|
|
ft_set_tbl_prop(table, FT_TPROP_LEFT_MARGIN, 1);
|
|
|
|
ft_set_tbl_prop(table, FT_TPROP_RIGHT_MARGIN, 2);
|
2018-03-25 10:11:08 +02:00
|
|
|
table_str = ft_to_string(table);
|
2018-03-31 12:33:37 +02:00
|
|
|
assert_true(table_str != NULL);
|
2018-03-25 10:11:08 +02:00
|
|
|
table_str_etalon =
|
2018-03-31 12:33:37 +02:00
|
|
|
" \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";
|
2018-03-25 10:11:08 +02:00
|
|
|
assert_str_equal(table_str, table_str_etalon);
|
|
|
|
|
|
|
|
ft_destroy_table(table);
|
|
|
|
}
|
2018-03-25 10:32:10 +02:00
|
|
|
|
|
|
|
|
2018-04-16 20:01:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef FT_HAVE_WCHAR
|
2018-11-03 21:50:30 +01:00
|
|
|
WHEN("Test setting entire table properties(wide strings case)") {
|
|
|
|
set_test_properties_as_default();
|
2018-03-25 10:32:10 +02:00
|
|
|
|
|
|
|
table = create_test_int_wtable(0);
|
|
|
|
|
|
|
|
const wchar_t *table_str = ft_to_wstring(table);
|
2018-03-31 12:33:37 +02:00
|
|
|
assert_true(table_str != NULL);
|
2018-03-25 10:32:10 +02:00
|
|
|
const wchar_t *table_str_etalon =
|
2018-03-31 12:33:37 +02:00
|
|
|
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";
|
2018-03-25 10:32:10 +02:00
|
|
|
assert_wcs_equal(table_str, table_str_etalon);
|
|
|
|
|
2018-11-03 21:50:30 +01:00
|
|
|
/* Now set table properties */
|
|
|
|
ft_set_tbl_prop(table, FT_TPROP_TOP_MARGIN, 3);
|
|
|
|
ft_set_tbl_prop(table, FT_TPROP_BOTTOM_MARGIN, 4);
|
|
|
|
ft_set_tbl_prop(table, FT_TPROP_LEFT_MARGIN, 1);
|
|
|
|
ft_set_tbl_prop(table, FT_TPROP_RIGHT_MARGIN, 2);
|
2018-03-25 10:32:10 +02:00
|
|
|
table_str = ft_to_wstring(table);
|
2018-03-31 12:33:37 +02:00
|
|
|
assert_true(table_str != NULL);
|
2018-03-25 10:32:10 +02:00
|
|
|
table_str_etalon =
|
2018-03-31 12:33:37 +02:00
|
|
|
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";
|
2018-03-25 10:32:10 +02:00
|
|
|
assert_wcs_equal(table_str, table_str_etalon);
|
|
|
|
|
|
|
|
ft_destroy_table(table);
|
|
|
|
}
|
2018-04-16 20:01:45 +02:00
|
|
|
#endif
|
2018-03-25 10:11:08 +02:00
|
|
|
}
|
2018-03-19 21:07:18 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-03 21:50:30 +01:00
|
|
|
void test_table_cell_properties(void)
|
2018-03-19 21:07:18 +01:00
|
|
|
{
|
2018-05-05 21:34:45 +02:00
|
|
|
ft_table_t *table = NULL;
|
2018-03-19 21:07:18 +01:00
|
|
|
|
|
|
|
|
2018-11-10 07:58:21 +01:00
|
|
|
WHEN("Setting property for one cell") {
|
|
|
|
set_test_properties_as_default();
|
|
|
|
|
|
|
|
table = create_test_int_table(0);
|
|
|
|
ft_set_cell_prop(table, 1, 1, FT_CPROP_TOP_PADDING, 2);
|
|
|
|
|
|
|
|
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 | | 55 | 67 |\n"
|
|
|
|
"| | 4 | | |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"+---+---+----+----+\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| 3 | 4 | 55 | 67 |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"+---+---+----+----+\n";
|
|
|
|
assert_str_equal(table_str, table_str_etalon);
|
|
|
|
ft_destroy_table(table);
|
|
|
|
}
|
|
|
|
|
|
|
|
WHEN("Setting property for the row") {
|
|
|
|
set_test_properties_as_default();
|
|
|
|
|
|
|
|
table = create_test_int_table(0);
|
|
|
|
ft_set_cell_prop(table, 1, FT_ANY_COLUMN, FT_CPROP_TOP_PADDING, 2);
|
|
|
|
|
|
|
|
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"
|
|
|
|
"| | | | |\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("Setting property for the column") {
|
|
|
|
set_test_properties_as_default();
|
|
|
|
|
|
|
|
table = create_test_int_table(0);
|
|
|
|
ft_set_cell_prop(table, FT_ANY_ROW, 1, FT_CPROP_TOP_PADDING, 2);
|
|
|
|
|
|
|
|
const char *table_str = ft_to_string(table);
|
|
|
|
assert_true(table_str != NULL);
|
|
|
|
const char *table_str_etalon =
|
|
|
|
"+---+---+----+----+\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| 3 | | 55 | 67 |\n"
|
|
|
|
"| | 4 | | |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"+---+---+----+----+\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| 3 | | 55 | 67 |\n"
|
|
|
|
"| | 4 | | |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"+---+---+----+----+\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| 3 | | 55 | 67 |\n"
|
|
|
|
"| | 4 | | |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"+---+---+----+----+\n";
|
|
|
|
assert_str_equal(table_str, table_str_etalon);
|
|
|
|
ft_destroy_table(table);
|
|
|
|
}
|
|
|
|
|
2019-10-25 21:20:59 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2018-11-10 07:58:21 +01:00
|
|
|
WHEN("Setting property for all cells in the table") {
|
|
|
|
set_test_properties_as_default();
|
|
|
|
|
|
|
|
table = create_test_int_table(0);
|
|
|
|
ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_TOP_PADDING, 2);
|
|
|
|
|
|
|
|
const char *table_str = ft_to_string(table);
|
|
|
|
assert_true(table_str != NULL);
|
|
|
|
const char *table_str_etalon =
|
|
|
|
"+---+---+----+----+\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| 3 | 4 | 55 | 67 |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"+---+---+----+----+\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| 3 | 4 | 55 | 67 |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"+---+---+----+----+\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| 3 | 4 | 55 | 67 |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"+---+---+----+----+\n";
|
|
|
|
assert_str_equal(table_str, table_str_etalon);
|
|
|
|
ft_destroy_table(table);
|
|
|
|
}
|
|
|
|
|
2018-11-23 19:02:08 +01:00
|
|
|
WHEN("Differrent paddings") {
|
2018-11-03 21:50:30 +01:00
|
|
|
set_test_properties_as_default();
|
2018-03-19 21:07:18 +01:00
|
|
|
|
2018-11-23 19:02:08 +01:00
|
|
|
ft_set_default_cell_prop(FT_CPROP_BOTTOM_PADDING, 3);
|
|
|
|
ft_set_default_cell_prop(FT_CPROP_TOP_PADDING, 2);
|
2018-11-03 21:50:30 +01:00
|
|
|
ft_set_default_cell_prop(FT_CPROP_LEFT_PADDING, 1);
|
2018-11-23 19:02:08 +01:00
|
|
|
ft_set_default_cell_prop(FT_CPROP_RIGHT_PADDING, 0);
|
2018-03-19 21:07:18 +01:00
|
|
|
|
|
|
|
table = create_test_int_table(0);
|
|
|
|
|
|
|
|
const char *table_str = ft_to_string(table);
|
2018-03-31 12:33:37 +02:00
|
|
|
assert_true(table_str != NULL);
|
2018-03-19 21:07:18 +01:00
|
|
|
const char *table_str_etalon =
|
2018-11-23 19:02:08 +01:00
|
|
|
"+--+--+---+---+\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| 3| 4| 55| 67|\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"+--+--+---+---+\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| 3| 4| 55| 67|\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"+--+--+---+---+\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| 3| 4| 55| 67|\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"+--+--+---+---+\n";
|
2018-03-24 15:01:29 +01:00
|
|
|
assert_str_equal(table_str, table_str_etalon);
|
2018-03-19 21:07:18 +01:00
|
|
|
ft_destroy_table(table);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
WHEN("Top and bottom padding = 0") {
|
|
|
|
|
2018-11-03 21:50:30 +01:00
|
|
|
ft_set_default_cell_prop(FT_CPROP_BOTTOM_PADDING, 0);
|
|
|
|
ft_set_default_cell_prop(FT_CPROP_TOP_PADDING, 0);
|
|
|
|
ft_set_default_cell_prop(FT_CPROP_LEFT_PADDING, 1);
|
|
|
|
ft_set_default_cell_prop(FT_CPROP_RIGHT_PADDING, 1);
|
2018-03-19 21:07:18 +01:00
|
|
|
|
|
|
|
table = create_test_int_table(0);
|
|
|
|
|
|
|
|
const char *table_str = ft_to_string(table);
|
2018-03-31 12:33:37 +02:00
|
|
|
assert_true(table_str != NULL);
|
2018-03-19 21:07:18 +01:00
|
|
|
const char *table_str_etalon =
|
2018-03-31 12:33:37 +02:00
|
|
|
"+---+---+----+----+\n"
|
|
|
|
"| 3 | 4 | 55 | 67 |\n"
|
|
|
|
"+---+---+----+----+\n"
|
|
|
|
"| 3 | 4 | 55 | 67 |\n"
|
|
|
|
"+---+---+----+----+\n"
|
|
|
|
"| 3 | 4 | 55 | 67 |\n"
|
|
|
|
"+---+---+----+----+\n";
|
2018-03-24 15:01:29 +01:00
|
|
|
assert_str_equal(table_str, table_str_etalon);
|
2018-03-19 21:07:18 +01:00
|
|
|
ft_destroy_table(table);
|
|
|
|
}
|
|
|
|
|
|
|
|
WHEN("Left and right padding = 0") {
|
|
|
|
|
2018-11-03 21:50:30 +01:00
|
|
|
ft_set_default_cell_prop(FT_CPROP_BOTTOM_PADDING, 1);
|
|
|
|
ft_set_default_cell_prop(FT_CPROP_TOP_PADDING, 1);
|
|
|
|
ft_set_default_cell_prop(FT_CPROP_LEFT_PADDING, 0);
|
|
|
|
ft_set_default_cell_prop(FT_CPROP_RIGHT_PADDING, 0);
|
2018-03-19 21:07:18 +01:00
|
|
|
|
|
|
|
table = create_test_int_table(0);
|
|
|
|
|
|
|
|
const char *table_str = ft_to_string(table);
|
2018-03-31 12:33:37 +02:00
|
|
|
assert_true(table_str != NULL);
|
2018-03-19 21:07:18 +01:00
|
|
|
const char *table_str_etalon =
|
2018-03-31 12:33:37 +02:00
|
|
|
"+-+-+--+--+\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";
|
2018-03-24 15:01:29 +01:00
|
|
|
assert_str_equal(table_str, table_str_etalon);
|
2018-03-19 21:07:18 +01:00
|
|
|
ft_destroy_table(table);
|
|
|
|
}
|
|
|
|
|
|
|
|
WHEN("All paddings = 0") {
|
|
|
|
|
2018-11-03 21:50:30 +01:00
|
|
|
ft_set_default_cell_prop(FT_CPROP_BOTTOM_PADDING, 0);
|
|
|
|
ft_set_default_cell_prop(FT_CPROP_TOP_PADDING, 0);
|
|
|
|
ft_set_default_cell_prop(FT_CPROP_LEFT_PADDING, 0);
|
|
|
|
ft_set_default_cell_prop(FT_CPROP_RIGHT_PADDING, 0);
|
2018-03-19 21:07:18 +01:00
|
|
|
|
|
|
|
table = create_test_int_table(0);
|
|
|
|
|
|
|
|
const char *table_str = ft_to_string(table);
|
2018-03-31 12:33:37 +02:00
|
|
|
assert_true(table_str != NULL);
|
2018-03-19 21:07:18 +01:00
|
|
|
const char *table_str_etalon =
|
2018-03-31 12:33:37 +02:00
|
|
|
"+-+-+--+--+\n"
|
|
|
|
"|3|4|55|67|\n"
|
|
|
|
"+-+-+--+--+\n"
|
|
|
|
"|3|4|55|67|\n"
|
|
|
|
"+-+-+--+--+\n"
|
|
|
|
"|3|4|55|67|\n"
|
|
|
|
"+-+-+--+--+\n";
|
2018-03-24 15:01:29 +01:00
|
|
|
assert_str_equal(table_str, table_str_etalon);
|
2018-03-19 21:07:18 +01:00
|
|
|
ft_destroy_table(table);
|
|
|
|
}
|
|
|
|
|
|
|
|
WHEN("Empty string has 0 heigt") {
|
|
|
|
|
2018-11-03 21:50:30 +01:00
|
|
|
ft_set_default_cell_prop(FT_CPROP_BOTTOM_PADDING, 1);
|
|
|
|
ft_set_default_cell_prop(FT_CPROP_TOP_PADDING, 1);
|
|
|
|
ft_set_default_cell_prop(FT_CPROP_LEFT_PADDING, 1);
|
|
|
|
ft_set_default_cell_prop(FT_CPROP_RIGHT_PADDING, 1);
|
|
|
|
ft_set_default_cell_prop(FT_CPROP_EMPTY_STR_HEIGHT, 0);
|
2018-03-19 21:07:18 +01:00
|
|
|
|
|
|
|
table = create_test_int_table(0);
|
|
|
|
int n = ft_printf_ln(table, "|||");
|
2018-03-31 12:33:37 +02:00
|
|
|
assert_true(n == 4);
|
2018-03-19 21:07:18 +01:00
|
|
|
|
|
|
|
const char *table_str = ft_to_string(table);
|
2018-03-31 12:33:37 +02:00
|
|
|
assert_true(table_str != NULL);
|
2018-03-19 21:07:18 +01:00
|
|
|
const char *table_str_etalon =
|
2018-03-31 12:33:37 +02:00
|
|
|
"+---+---+----+----+\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";
|
2018-03-24 15:01:29 +01:00
|
|
|
assert_str_equal(table_str, table_str_etalon);
|
2018-03-19 21:07:18 +01:00
|
|
|
ft_destroy_table(table);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-03 21:50:30 +01:00
|
|
|
WHEN("Setting properties for a particular table") {
|
2018-03-19 21:07:18 +01:00
|
|
|
|
|
|
|
table = create_test_int_table(0);
|
2018-11-03 21:50:30 +01:00
|
|
|
set_test_props_for_table(table);
|
2018-03-19 21:07:18 +01:00
|
|
|
|
2018-11-03 21:50:30 +01:00
|
|
|
ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_BOTTOM_PADDING, 0);
|
|
|
|
ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_TOP_PADDING, 0);
|
|
|
|
ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_LEFT_PADDING, 0);
|
|
|
|
ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_RIGHT_PADDING, 0);
|
2018-03-19 21:07:18 +01:00
|
|
|
|
|
|
|
const char *table_str = ft_to_string(table);
|
2018-03-31 12:33:37 +02:00
|
|
|
assert_true(table_str != NULL);
|
2018-03-19 21:07:18 +01:00
|
|
|
const char *table_str_etalon =
|
2018-03-31 12:33:37 +02:00
|
|
|
"+-+-+--+--+\n"
|
|
|
|
"|3|4|55|67|\n"
|
|
|
|
"+-+-+--+--+\n"
|
|
|
|
"|3|4|55|67|\n"
|
|
|
|
"+-+-+--+--+\n"
|
|
|
|
"|3|4|55|67|\n"
|
|
|
|
"+-+-+--+--+\n";
|
2018-03-24 15:01:29 +01:00
|
|
|
assert_str_equal(table_str, table_str_etalon);
|
2018-03-19 21:07:18 +01:00
|
|
|
|
|
|
|
|
2018-11-03 21:50:30 +01:00
|
|
|
ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_BOTTOM_PADDING, 1);
|
|
|
|
ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_TOP_PADDING, 1);
|
|
|
|
ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_LEFT_PADDING, 0);
|
|
|
|
ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_RIGHT_PADDING, 0);
|
|
|
|
ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_EMPTY_STR_HEIGHT, 0);
|
2018-03-19 21:07:18 +01:00
|
|
|
|
|
|
|
table_str = ft_to_string(table);
|
2018-03-31 12:33:37 +02:00
|
|
|
assert_true(table_str != NULL);
|
2018-03-19 21:07:18 +01:00
|
|
|
table_str_etalon =
|
2018-03-31 12:33:37 +02:00
|
|
|
"+-+-+--+--+\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";
|
2018-03-24 15:01:29 +01:00
|
|
|
assert_str_equal(table_str, table_str_etalon);
|
2018-03-19 21:07:18 +01:00
|
|
|
ft_destroy_table(table);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WHEN("Set table width and column alignment") {
|
|
|
|
|
2018-11-03 21:50:30 +01:00
|
|
|
set_test_properties_as_default();
|
2018-03-19 21:07:18 +01:00
|
|
|
|
|
|
|
table = create_test_int_table(0);
|
|
|
|
int status = FT_SUCCESS;
|
|
|
|
|
2018-11-03 21:50:30 +01:00
|
|
|
status |= ft_set_cell_prop(table, FT_ANY_ROW, 1, FT_CPROP_MIN_WIDTH, 7);
|
|
|
|
status |= ft_set_cell_prop(table, FT_ANY_ROW, 1, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_LEFT);
|
|
|
|
status |= ft_set_cell_prop(table, FT_ANY_ROW, 2, FT_CPROP_MIN_WIDTH, 8);
|
|
|
|
status |= ft_set_cell_prop(table, FT_ANY_ROW, 2, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
2018-03-19 21:07:18 +01:00
|
|
|
|
2018-11-03 21:50:30 +01:00
|
|
|
status |= ft_set_cell_prop(table, 2, 3, FT_CPROP_MIN_WIDTH, 6);
|
|
|
|
status |= ft_set_cell_prop(table, 2, 3, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_LEFT);
|
2018-03-31 12:33:37 +02:00
|
|
|
assert_true(status == FT_SUCCESS);
|
2018-03-19 21:07:18 +01:00
|
|
|
|
|
|
|
|
|
|
|
const char *table_str = ft_to_string(table);
|
2018-03-31 12:33:37 +02:00
|
|
|
assert_true(table_str != NULL);
|
2018-03-19 21:07:18 +01:00
|
|
|
const char *table_str_etalon =
|
2018-03-31 12:33:37 +02:00
|
|
|
"+---+-------+--------+------+\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";
|
2018-03-24 15:01:29 +01:00
|
|
|
assert_str_equal(table_str, table_str_etalon);
|
2018-03-19 21:07:18 +01:00
|
|
|
ft_destroy_table(table);
|
|
|
|
}
|
|
|
|
|
|
|
|
WHEN("Set table width and column alignment as default") {
|
|
|
|
|
2018-11-03 21:50:30 +01:00
|
|
|
set_test_properties_as_default();
|
2018-03-19 21:07:18 +01:00
|
|
|
|
|
|
|
int status = FT_SUCCESS;
|
2018-11-03 21:50:30 +01:00
|
|
|
status |= ft_set_default_cell_prop(FT_CPROP_MIN_WIDTH, 5);
|
|
|
|
status |= ft_set_default_cell_prop(FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
2018-03-31 12:33:37 +02:00
|
|
|
assert_true(status == FT_SUCCESS);
|
2018-03-19 21:07:18 +01:00
|
|
|
|
|
|
|
table = create_test_int_table(0);
|
|
|
|
|
|
|
|
const char *table_str = ft_to_string(table);
|
2018-03-31 12:33:37 +02:00
|
|
|
assert_true(table_str != NULL);
|
2018-03-19 21:07:18 +01:00
|
|
|
const char *table_str_etalon =
|
2018-03-31 12:33:37 +02:00
|
|
|
"+-----+-----+-----+-----+\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";
|
2018-03-24 15:01:29 +01:00
|
|
|
assert_str_equal(table_str, table_str_etalon);
|
2018-03-19 21:07:18 +01:00
|
|
|
ft_destroy_table(table);
|
|
|
|
}
|
|
|
|
|
2018-03-25 10:11:08 +02:00
|
|
|
WHEN("Multiline cell") {
|
2018-11-03 21:50:30 +01:00
|
|
|
set_test_properties_as_default();
|
2018-03-19 21:07:18 +01:00
|
|
|
|
|
|
|
table = ft_create_table();
|
|
|
|
|
2018-11-03 21:50:30 +01:00
|
|
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
2018-03-19 21:07:18 +01:00
|
|
|
int n = ft_printf_ln(table, "%d|%c|%s|%f", 4, 'c', "234", 3.14);
|
|
|
|
|
2018-03-31 12:33:37 +02:00
|
|
|
assert_true(n == 4);
|
2018-04-24 19:41:14 +02:00
|
|
|
n = ft_write_ln(table, "5", "c", "234\n12", "3.140000");
|
2018-03-31 12:33:37 +02:00
|
|
|
assert_true(n == FT_SUCCESS);
|
2018-03-19 21:07:18 +01:00
|
|
|
n = ft_printf_ln(table, "%d|%c|%s|%f", 3, 'c', "234", 3.14);
|
2018-03-31 12:33:37 +02:00
|
|
|
assert_true(n == 4);
|
2018-03-19 21:07:18 +01:00
|
|
|
|
|
|
|
const char *table_str = ft_to_string(table);
|
2018-03-31 12:33:37 +02:00
|
|
|
assert_true(table_str != NULL);
|
2018-03-19 21:07:18 +01:00
|
|
|
const char *table_str_etalon =
|
2018-03-31 12:33:37 +02:00
|
|
|
"+---+---+-----+----------+\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";
|
2018-03-24 15:01:29 +01:00
|
|
|
assert_str_equal(table_str, table_str_etalon);
|
2018-03-19 21:07:18 +01:00
|
|
|
ft_destroy_table(table);
|
|
|
|
}
|
2018-05-04 20:25:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
WHEN("Cells with spans") {
|
2018-11-03 21:50:30 +01:00
|
|
|
set_test_properties_as_default();
|
2018-05-04 20:25:29 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2018-11-03 21:50:30 +01:00
|
|
|
n = ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
2018-05-04 20:25:29 +02:00
|
|
|
assert_true(n == FT_SUCCESS);
|
2018-11-03 21:50:30 +01:00
|
|
|
n = ft_set_cell_prop(table, 1, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
2018-05-04 20:25:29 +02:00
|
|
|
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);
|
|
|
|
}
|
2018-11-02 14:00:58 +01:00
|
|
|
|
2018-12-22 10:30:26 +01:00
|
|
|
WHEN("Cells with spans and with a lot of text in them") {
|
2018-12-22 10:22:20 +01:00
|
|
|
set_test_properties_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_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
|
|
|
assert_true(n == FT_SUCCESS);
|
|
|
|
n = ft_set_cell_prop(table, 1, FT_ANY_COLUMN, FT_CPROP_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", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
|
|
|
|
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 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxx |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"+-------+--------+----------+-------------------------------+\n";
|
|
|
|
assert_str_equal(table_str, table_str_etalon);
|
|
|
|
ft_destroy_table(table);
|
|
|
|
}
|
|
|
|
|
2018-11-02 14:00:58 +01:00
|
|
|
WHEN("Cells with spans in common and header cells") {
|
2018-11-03 21:50:30 +01:00
|
|
|
set_test_properties_as_default();
|
2018-11-02 14:00:58 +01:00
|
|
|
|
|
|
|
table = ft_create_table();
|
|
|
|
ft_set_border_style(table, FT_DOUBLE2_STYLE);
|
|
|
|
|
|
|
|
int n = ft_set_cell_span(table, 0, 0, 2);
|
|
|
|
assert_true(n == FT_SUCCESS);
|
|
|
|
n = ft_set_cell_span(table, 0, 2, 3);
|
|
|
|
assert_true(n == FT_SUCCESS);
|
|
|
|
n = ft_set_cell_span(table, 1, 1, 3);
|
|
|
|
assert_true(n == FT_SUCCESS);
|
|
|
|
|
2018-11-03 21:50:30 +01:00
|
|
|
n = ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
2018-11-02 14:00:58 +01:00
|
|
|
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 │ 33333 ║\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);
|
|
|
|
}
|
2018-03-19 21:07:18 +01:00
|
|
|
}
|
2018-11-10 07:58:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void test_table_text_styles(void)
|
|
|
|
{
|
|
|
|
ft_table_t *table = NULL;
|
|
|
|
set_test_properties_as_default();
|
|
|
|
|
|
|
|
WHEN("Simple table with one cell and foreground content color") {
|
|
|
|
table = ft_create_table();
|
|
|
|
assert(table);
|
|
|
|
assert(ft_set_cell_prop(table, 0, 0, FT_CPROP_CONT_FG_COLOR, FT_COLOR_YELLOW) == FT_SUCCESS);
|
|
|
|
assert(ft_write(table, "42") == FT_SUCCESS);
|
|
|
|
|
|
|
|
const char *table_str = ft_to_string(table);
|
|
|
|
assert_true(table_str != NULL);
|
|
|
|
const char *table_str_etalon =
|
|
|
|
"+----+\n"
|
2019-07-17 21:33:56 +02:00
|
|
|
"|\033[33m\033[0m |\n"
|
|
|
|
"| \033[33m42\033[0m |\n"
|
|
|
|
"|\033[33m\033[0m |\n"
|
2018-11-10 07:58:21 +01:00
|
|
|
"+----+\n";
|
|
|
|
assert_str_equal(table_str, table_str_etalon);
|
|
|
|
ft_destroy_table(table);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef FT_HAVE_WCHAR
|
|
|
|
WHEN("Simple table with one cell and foreground color(wide strings case)") {
|
|
|
|
table = ft_create_table();
|
|
|
|
assert(table);
|
|
|
|
assert(ft_set_cell_prop(table, 0, 0, FT_CPROP_CONT_FG_COLOR, FT_COLOR_YELLOW) == FT_SUCCESS);
|
|
|
|
assert(ft_wwrite(table, L"42") == FT_SUCCESS);
|
|
|
|
|
|
|
|
const wchar_t *table_str = ft_to_wstring(table);
|
|
|
|
assert_true(table_str != NULL);
|
|
|
|
const wchar_t *table_str_etalon =
|
|
|
|
L"+----+\n"
|
2019-07-17 21:33:56 +02:00
|
|
|
L"|\033[33m\033[0m |\n"
|
|
|
|
L"| \033[33m42\033[0m |\n"
|
|
|
|
L"|\033[33m\033[0m |\n"
|
2018-11-10 07:58:21 +01:00
|
|
|
L"+----+\n";
|
|
|
|
assert_wcs_equal(table_str, table_str_etalon);
|
|
|
|
ft_destroy_table(table);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
WHEN("Simple table with one cell and background content color") {
|
|
|
|
table = ft_create_table();
|
|
|
|
assert(table);
|
|
|
|
assert(ft_set_cell_prop(table, 0, 0, FT_CPROP_CONT_BG_COLOR, FT_COLOR_YELLOW) == FT_SUCCESS);
|
|
|
|
assert(ft_write(table, "42") == FT_SUCCESS);
|
|
|
|
|
|
|
|
const char *table_str = ft_to_string(table);
|
|
|
|
assert_true(table_str != NULL);
|
|
|
|
const char *table_str_etalon =
|
|
|
|
"+----+\n"
|
2019-07-17 21:33:56 +02:00
|
|
|
"|\033[43m\033[0m |\n"
|
|
|
|
"| \033[43m42\033[0m |\n"
|
|
|
|
"|\033[43m\033[0m |\n"
|
2018-11-10 07:58:21 +01:00
|
|
|
"+----+\n";
|
|
|
|
assert_str_equal(table_str, table_str_etalon);
|
|
|
|
ft_destroy_table(table);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef FT_HAVE_WCHAR
|
|
|
|
WHEN("Simple table with one cell and background content color(wide strings case)") {
|
|
|
|
table = ft_create_table();
|
|
|
|
assert(table);
|
|
|
|
assert(ft_set_cell_prop(table, 0, 0, FT_CPROP_CONT_BG_COLOR, FT_COLOR_YELLOW) == FT_SUCCESS);
|
|
|
|
assert(ft_wwrite(table, L"42") == FT_SUCCESS);
|
|
|
|
|
|
|
|
const wchar_t *table_str = ft_to_wstring(table);
|
|
|
|
assert_true(table_str != NULL);
|
|
|
|
const wchar_t *table_str_etalon =
|
|
|
|
L"+----+\n"
|
2019-07-17 21:33:56 +02:00
|
|
|
L"|\033[43m\033[0m |\n"
|
|
|
|
L"| \033[43m42\033[0m |\n"
|
|
|
|
L"|\033[43m\033[0m |\n"
|
2018-11-10 07:58:21 +01:00
|
|
|
L"+----+\n";
|
|
|
|
assert_wcs_equal(table_str, table_str_etalon);
|
|
|
|
ft_destroy_table(table);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
WHEN("Simple table with one cell and background cell color") {
|
|
|
|
table = ft_create_table();
|
|
|
|
assert(table);
|
|
|
|
assert(ft_set_cell_prop(table, 0, 0, FT_CPROP_CELL_BG_COLOR, FT_COLOR_YELLOW) == FT_SUCCESS);
|
|
|
|
assert(ft_write(table, "42") == FT_SUCCESS);
|
|
|
|
|
|
|
|
const char *table_str = ft_to_string(table);
|
|
|
|
assert_true(table_str != NULL);
|
|
|
|
const char *table_str_etalon =
|
|
|
|
"+----+\n"
|
2019-07-17 21:33:56 +02:00
|
|
|
"|\033[43m \033[0m|\n"
|
|
|
|
"|\033[43m 42 \033[0m|\n"
|
|
|
|
"|\033[43m \033[0m|\n"
|
2018-11-10 07:58:21 +01:00
|
|
|
"+----+\n";
|
|
|
|
assert_str_equal(table_str, table_str_etalon);
|
|
|
|
ft_destroy_table(table);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef FT_HAVE_WCHAR
|
|
|
|
WHEN("Simple table with one cell and background cell color(wide strings case)") {
|
|
|
|
table = ft_create_table();
|
|
|
|
assert(table);
|
|
|
|
assert(ft_set_cell_prop(table, 0, 0, FT_CPROP_CELL_BG_COLOR, FT_COLOR_YELLOW) == FT_SUCCESS);
|
|
|
|
assert(ft_wwrite(table, L"42") == FT_SUCCESS);
|
|
|
|
|
|
|
|
const wchar_t *table_str = ft_to_wstring(table);
|
|
|
|
assert_true(table_str != NULL);
|
|
|
|
const wchar_t *table_str_etalon =
|
|
|
|
L"+----+\n"
|
2019-07-17 21:33:56 +02:00
|
|
|
L"|\033[43m \033[0m|\n"
|
|
|
|
L"|\033[43m 42 \033[0m|\n"
|
|
|
|
L"|\033[43m \033[0m|\n"
|
2018-11-10 07:58:21 +01:00
|
|
|
L"+----+\n";
|
|
|
|
assert_wcs_equal(table_str, table_str_etalon);
|
|
|
|
ft_destroy_table(table);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
WHEN("Simple table with one cell and content style") {
|
|
|
|
table = ft_create_table();
|
|
|
|
assert(table);
|
|
|
|
assert(ft_set_cell_prop(table, 0, 0, FT_CPROP_CONT_TEXT_STYLE, FT_TSTYLE_UNDERLINED) == FT_SUCCESS);
|
|
|
|
assert(ft_write(table, "42") == FT_SUCCESS);
|
|
|
|
|
|
|
|
const char *table_str = ft_to_string(table);
|
|
|
|
assert_true(table_str != NULL);
|
|
|
|
const char *table_str_etalon =
|
|
|
|
"+----+\n"
|
2019-07-17 21:33:56 +02:00
|
|
|
"|\033[4m\033[0m |\n"
|
|
|
|
"| \033[4m42\033[0m |\n"
|
|
|
|
"|\033[4m\033[0m |\n"
|
2018-11-10 07:58:21 +01:00
|
|
|
"+----+\n";
|
|
|
|
assert_str_equal(table_str, table_str_etalon);
|
|
|
|
ft_destroy_table(table);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef FT_HAVE_WCHAR
|
|
|
|
WHEN("Simple table with one cell and content style(wide strings case)") {
|
|
|
|
table = ft_create_table();
|
|
|
|
assert(table);
|
|
|
|
assert(ft_set_cell_prop(table, 0, 0, FT_CPROP_CONT_TEXT_STYLE, FT_TSTYLE_UNDERLINED) == FT_SUCCESS);
|
|
|
|
assert(ft_wwrite(table, L"42") == FT_SUCCESS);
|
|
|
|
|
|
|
|
const wchar_t *table_str = ft_to_wstring(table);
|
|
|
|
assert_true(table_str != NULL);
|
|
|
|
const wchar_t *table_str_etalon =
|
|
|
|
L"+----+\n"
|
2019-07-17 21:33:56 +02:00
|
|
|
L"|\033[4m\033[0m |\n"
|
|
|
|
L"| \033[4m42\033[0m |\n"
|
|
|
|
L"|\033[4m\033[0m |\n"
|
2018-11-10 07:58:21 +01:00
|
|
|
L"+----+\n";
|
|
|
|
assert_wcs_equal(table_str, table_str_etalon);
|
|
|
|
ft_destroy_table(table);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-11-16 21:20:57 +01:00
|
|
|
WHEN("Simple table with one cell and multiple content style") {
|
|
|
|
table = ft_create_table();
|
|
|
|
assert(table);
|
|
|
|
assert(ft_set_cell_prop(table, 0, 0, FT_CPROP_CONT_TEXT_STYLE, FT_TSTYLE_UNDERLINED) == FT_SUCCESS);
|
|
|
|
assert(ft_set_cell_prop(table, 0, 0, FT_CPROP_CONT_TEXT_STYLE, FT_TSTYLE_BOLD) == FT_SUCCESS);
|
|
|
|
assert(ft_write(table, "42") == FT_SUCCESS);
|
|
|
|
|
|
|
|
const char *table_str = ft_to_string(table);
|
|
|
|
assert_true(table_str != NULL);
|
|
|
|
const char *table_str_etalon =
|
|
|
|
"+----+\n"
|
2019-07-17 21:33:56 +02:00
|
|
|
"|\033[1m\033[4m\033[0m |\n"
|
|
|
|
"| \033[1m\033[4m42\033[0m |\n"
|
|
|
|
"|\033[1m\033[4m\033[0m |\n"
|
2018-11-16 21:20:57 +01:00
|
|
|
"+----+\n";
|
|
|
|
assert_str_equal(table_str, table_str_etalon);
|
|
|
|
ft_destroy_table(table);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef FT_HAVE_WCHAR
|
|
|
|
WHEN("Simple table with one cell and multiple content style(wide strings case)") {
|
|
|
|
table = ft_create_table();
|
|
|
|
assert(table);
|
|
|
|
assert(ft_set_cell_prop(table, 0, 0, FT_CPROP_CONT_TEXT_STYLE, FT_TSTYLE_UNDERLINED) == FT_SUCCESS);
|
|
|
|
assert(ft_set_cell_prop(table, 0, 0, FT_CPROP_CONT_TEXT_STYLE, FT_TSTYLE_BOLD) == FT_SUCCESS);
|
|
|
|
assert(ft_wwrite(table, L"42") == FT_SUCCESS);
|
|
|
|
|
|
|
|
const wchar_t *table_str = ft_to_wstring(table);
|
|
|
|
assert_true(table_str != NULL);
|
|
|
|
const wchar_t *table_str_etalon =
|
|
|
|
L"+----+\n"
|
2019-07-17 21:33:56 +02:00
|
|
|
L"|\033[1m\033[4m\033[0m |\n"
|
|
|
|
L"| \033[1m\033[4m42\033[0m |\n"
|
|
|
|
L"|\033[1m\033[4m\033[0m |\n"
|
2018-11-16 21:20:57 +01:00
|
|
|
L"+----+\n";
|
|
|
|
assert_wcs_equal(table_str, table_str_etalon);
|
|
|
|
ft_destroy_table(table);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-11-10 07:58:21 +01:00
|
|
|
WHEN("Simple table with one cell and cell style") {
|
|
|
|
table = ft_create_table();
|
|
|
|
assert(table);
|
|
|
|
assert(ft_set_cell_prop(table, 0, 0, FT_CPROP_CELL_TEXT_STYLE, FT_TSTYLE_UNDERLINED) == FT_SUCCESS);
|
|
|
|
assert(ft_write(table, "42") == FT_SUCCESS);
|
|
|
|
|
|
|
|
const char *table_str = ft_to_string(table);
|
|
|
|
assert_true(table_str != NULL);
|
|
|
|
const char *table_str_etalon =
|
|
|
|
"+----+\n"
|
2019-07-17 21:33:56 +02:00
|
|
|
"|\033[4m \033[0m|\n"
|
|
|
|
"|\033[4m 42 \033[0m|\n"
|
|
|
|
"|\033[4m \033[0m|\n"
|
2018-11-10 07:58:21 +01:00
|
|
|
"+----+\n";
|
|
|
|
assert_str_equal(table_str, table_str_etalon);
|
|
|
|
ft_destroy_table(table);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef FT_HAVE_WCHAR
|
|
|
|
WHEN("Simple table with one cell and cell style(wide strings case)") {
|
|
|
|
table = ft_create_table();
|
|
|
|
assert(table);
|
|
|
|
assert(ft_set_cell_prop(table, 0, 0, FT_CPROP_CELL_TEXT_STYLE, FT_TSTYLE_UNDERLINED) == FT_SUCCESS);
|
|
|
|
assert(ft_wwrite(table, L"42") == FT_SUCCESS);
|
|
|
|
|
|
|
|
const wchar_t *table_str = ft_to_wstring(table);
|
|
|
|
assert_true(table_str != NULL);
|
|
|
|
const wchar_t *table_str_etalon =
|
|
|
|
L"+----+\n"
|
2019-07-17 21:33:56 +02:00
|
|
|
L"|\033[4m \033[0m|\n"
|
|
|
|
L"|\033[4m 42 \033[0m|\n"
|
|
|
|
L"|\033[4m \033[0m|\n"
|
2018-11-10 07:58:21 +01:00
|
|
|
L"+----+\n";
|
|
|
|
assert_wcs_equal(table_str, table_str_etalon);
|
|
|
|
ft_destroy_table(table);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-11-16 21:20:57 +01:00
|
|
|
WHEN("Simple table with one cell and multiple cell style") {
|
|
|
|
table = ft_create_table();
|
|
|
|
assert(table);
|
|
|
|
assert(ft_set_cell_prop(table, 0, 0, FT_CPROP_CELL_TEXT_STYLE, FT_TSTYLE_UNDERLINED) == FT_SUCCESS);
|
|
|
|
assert(ft_set_cell_prop(table, 0, 0, FT_CPROP_CELL_TEXT_STYLE, FT_TSTYLE_BOLD) == FT_SUCCESS);
|
|
|
|
assert(ft_write(table, "42") == FT_SUCCESS);
|
|
|
|
|
|
|
|
const char *table_str = ft_to_string(table);
|
|
|
|
assert_true(table_str != NULL);
|
|
|
|
const char *table_str_etalon =
|
|
|
|
"+----+\n"
|
2019-07-17 21:33:56 +02:00
|
|
|
"|\033[1m\033[4m \033[0m|\n"
|
|
|
|
"|\033[1m\033[4m 42 \033[0m|\n"
|
|
|
|
"|\033[1m\033[4m \033[0m|\n"
|
2018-11-16 21:20:57 +01:00
|
|
|
"+----+\n";
|
|
|
|
assert_str_equal(table_str, table_str_etalon);
|
|
|
|
ft_destroy_table(table);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef FT_HAVE_WCHAR
|
|
|
|
WHEN("Simple table with one cell and multiple cell style(wide strings case)") {
|
|
|
|
table = ft_create_table();
|
|
|
|
assert(table);
|
|
|
|
assert(ft_set_cell_prop(table, 0, 0, FT_CPROP_CELL_TEXT_STYLE, FT_TSTYLE_UNDERLINED) == FT_SUCCESS);
|
|
|
|
assert(ft_set_cell_prop(table, 0, 0, FT_CPROP_CELL_TEXT_STYLE, FT_TSTYLE_BOLD) == FT_SUCCESS);
|
|
|
|
assert(ft_wwrite(table, L"42") == FT_SUCCESS);
|
|
|
|
|
|
|
|
const wchar_t *table_str = ft_to_wstring(table);
|
|
|
|
assert_true(table_str != NULL);
|
|
|
|
const wchar_t *table_str_etalon =
|
|
|
|
L"+----+\n"
|
2019-07-17 21:33:56 +02:00
|
|
|
L"|\033[1m\033[4m \033[0m|\n"
|
|
|
|
L"|\033[1m\033[4m 42 \033[0m|\n"
|
|
|
|
L"|\033[1m\033[4m \033[0m|\n"
|
2018-11-16 21:20:57 +01:00
|
|
|
L"+----+\n";
|
|
|
|
assert_wcs_equal(table_str, table_str_etalon);
|
|
|
|
ft_destroy_table(table);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2018-11-10 07:58:21 +01:00
|
|
|
WHEN("Simple table with one cell background color, content foreground color and style.") {
|
|
|
|
set_test_properties_as_default();
|
|
|
|
|
|
|
|
table = ft_create_table();
|
|
|
|
assert(table);
|
|
|
|
assert(ft_set_cell_prop(table, 0, 0, FT_CPROP_CONT_FG_COLOR, FT_COLOR_YELLOW) == FT_SUCCESS);
|
|
|
|
assert(ft_set_cell_prop(table, 0, 0, FT_CPROP_CELL_BG_COLOR, FT_COLOR_RED) == FT_SUCCESS);
|
|
|
|
assert(ft_set_cell_prop(table, 0, 0, FT_CPROP_CONT_TEXT_STYLE, FT_TSTYLE_UNDERLINED) == FT_SUCCESS);
|
|
|
|
assert(ft_write(table, "42") == FT_SUCCESS);
|
|
|
|
|
|
|
|
const char *table_str = ft_to_string(table);
|
|
|
|
assert_true(table_str != NULL);
|
|
|
|
const char *table_str_etalon =
|
|
|
|
"+----+\n"
|
2019-07-17 21:33:56 +02:00
|
|
|
"|\033[41m\033[4m\033[33m\033[0m\033[41m \033[0m|\n"
|
|
|
|
"|\033[41m \033[4m\033[33m42\033[0m\033[41m \033[0m|\n"
|
|
|
|
"|\033[41m\033[4m\033[33m\033[0m\033[41m \033[0m|\n"
|
2018-11-10 07:58:21 +01:00
|
|
|
"+----+\n";
|
|
|
|
assert_str_equal(table_str, table_str_etalon);
|
|
|
|
ft_destroy_table(table);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef FT_HAVE_WCHAR
|
|
|
|
WHEN("Simple table with one cell background color, content foreground color and style.") {
|
|
|
|
set_test_properties_as_default();
|
|
|
|
|
|
|
|
table = ft_create_table();
|
|
|
|
assert(table);
|
|
|
|
assert(ft_set_cell_prop(table, 0, 0, FT_CPROP_CONT_FG_COLOR, FT_COLOR_YELLOW) == FT_SUCCESS);
|
|
|
|
assert(ft_set_cell_prop(table, 0, 0, FT_CPROP_CELL_BG_COLOR, FT_COLOR_RED) == FT_SUCCESS);
|
|
|
|
assert(ft_set_cell_prop(table, 0, 0, FT_CPROP_CONT_TEXT_STYLE, FT_TSTYLE_UNDERLINED) == FT_SUCCESS);
|
|
|
|
assert(ft_wwrite(table, L"42") == FT_SUCCESS);
|
|
|
|
|
|
|
|
const wchar_t *table_str = ft_to_wstring(table);
|
|
|
|
assert_true(table_str != NULL);
|
|
|
|
const wchar_t *table_str_etalon =
|
|
|
|
L"+----+\n"
|
2019-07-17 21:33:56 +02:00
|
|
|
L"|\033[41m\033[4m\033[33m\033[0m\033[41m \033[0m|\n"
|
|
|
|
L"|\033[41m \033[4m\033[33m42\033[0m\033[41m \033[0m|\n"
|
|
|
|
L"|\033[41m\033[4m\033[33m\033[0m\033[41m \033[0m|\n"
|
2018-11-10 07:58:21 +01:00
|
|
|
L"+----+\n";
|
|
|
|
assert_wcs_equal(table_str, table_str_etalon);
|
|
|
|
ft_destroy_table(table);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|