2018-04-04 21:13:37 +02:00
|
|
|
#include "tests.h"
|
2018-05-06 13:11:03 +02:00
|
|
|
#include "fort.h"
|
2018-04-04 21:13:37 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-01 09:43:29 +01:00
|
|
|
static int create_table_and_show(void)
|
2018-04-04 21:13:37 +02:00
|
|
|
{
|
2018-05-05 21:34:45 +02:00
|
|
|
ft_table_t *table = NULL;
|
2019-01-02 07:52:31 +01:00
|
|
|
ft_table_t *table_copy = NULL;
|
2018-04-04 21:13:37 +02:00
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
table = ft_create_table();
|
|
|
|
if (table == NULL) {
|
|
|
|
result = 1;
|
|
|
|
goto exit;
|
|
|
|
}
|
2018-05-08 20:46:24 +02:00
|
|
|
/*
|
2018-11-03 21:50:30 +01:00
|
|
|
if (set_test_props_for_table(table) != FT_SUCCESS)
|
2018-05-08 20:46:24 +02:00
|
|
|
return 2;
|
|
|
|
*/
|
2018-04-04 21:13:37 +02:00
|
|
|
|
2018-11-03 21:50:30 +01:00
|
|
|
if (ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER) != FT_SUCCESS) {
|
2018-04-04 21:13:37 +02:00
|
|
|
result = 3;
|
|
|
|
goto exit;
|
|
|
|
}
|
2019-01-02 08:08:36 +01:00
|
|
|
if (ft_set_cell_prop(table, FT_ANY_ROW, 0, FT_CPROP_LEFT_PADDING, 2) != FT_SUCCESS) {
|
2018-04-04 21:13:37 +02:00
|
|
|
result = 4;
|
|
|
|
goto exit;
|
|
|
|
}
|
2019-01-02 08:08:36 +01:00
|
|
|
if (ft_set_cell_prop(table, 2, 1, FT_CPROP_TOP_PADDING, 2) != FT_SUCCESS) {
|
2018-04-04 21:13:37 +02:00
|
|
|
result = 5;
|
|
|
|
goto exit;
|
|
|
|
}
|
2019-01-02 08:08:36 +01:00
|
|
|
if (ft_set_cell_prop(table, 2, 1, FT_CPROP_BOTTOM_PADDING, 0) != FT_SUCCESS) {
|
|
|
|
result = 6;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (ft_write_ln(table, "3", "c", "234", "3.140000") != FT_SUCCESS) {
|
|
|
|
result = 7;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (ft_write_ln(table, "3", "c", "234", "3.140000") != FT_SUCCESS) {
|
|
|
|
result = 8;
|
|
|
|
goto exit;
|
|
|
|
}
|
2018-12-01 09:43:29 +01:00
|
|
|
ft_add_separator(table);
|
2018-04-24 19:41:14 +02:00
|
|
|
if (ft_write_ln(table, "3", "c", "234", "3.140000") != FT_SUCCESS) {
|
2019-01-02 08:08:36 +01:00
|
|
|
result = 9;
|
2018-04-04 21:13:37 +02:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2018-12-22 10:30:26 +01:00
|
|
|
if (ft_printf_ln(table, "%d|%c|%d|%f", 3, 'c', 234, 3.140000) != 4) {
|
2019-01-02 08:08:36 +01:00
|
|
|
result = 10;
|
2018-12-22 10:30:26 +01:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2019-01-02 07:52:31 +01:00
|
|
|
table_copy = ft_copy_table(table);
|
|
|
|
if (table_copy == NULL) {
|
2019-01-02 08:08:36 +01:00
|
|
|
result = 11;
|
2018-04-04 21:13:37 +02:00
|
|
|
goto exit;
|
|
|
|
}
|
2019-01-02 07:52:31 +01:00
|
|
|
|
|
|
|
const char *table_str = ft_to_string(table_copy);
|
|
|
|
if (table_str == NULL) {
|
2019-01-02 08:08:36 +01:00
|
|
|
result = 12;
|
2019-01-02 07:52:31 +01:00
|
|
|
goto exit;
|
|
|
|
}
|
2018-04-04 21:13:37 +02:00
|
|
|
const char *table_str_etalon =
|
2019-01-02 08:08:36 +01:00
|
|
|
"+----+---+-----+----------+\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| 3 | c | 234 | 3.140000 |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"+----+---+-----+----------+\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| 3 | c | 234 | 3.140000 |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"+====+===+=====+==========+\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| 3 | | 234 | 3.140000 |\n"
|
|
|
|
"| | c | | |\n"
|
|
|
|
"+----+---+-----+----------+\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"| 3 | c | 234 | 3.140000 |\n"
|
|
|
|
"| | | | |\n"
|
|
|
|
"+----+---+-----+----------+\n";
|
2018-05-08 20:46:24 +02:00
|
|
|
/*assert_str_equal(table_str, table_str_etalon);*/
|
2018-04-04 21:13:37 +02:00
|
|
|
if (strcmp(table_str, table_str_etalon) != 0) {
|
2019-01-02 08:08:36 +01:00
|
|
|
result = 13;
|
2018-04-04 21:13:37 +02:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
exit:
|
|
|
|
ft_destroy_table(table);
|
2019-01-02 07:52:31 +01:00
|
|
|
ft_destroy_table(table_copy);
|
2018-04-04 21:13:37 +02:00
|
|
|
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;
|
2018-12-01 09:43:29 +01:00
|
|
|
int result = create_table_and_show();
|
2018-04-04 21:13:37 +02:00
|
|
|
if (result == 0)
|
|
|
|
break;
|
|
|
|
if (aloc_num != 0) {
|
|
|
|
assert_true(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_true(i != ITER_MAX);
|
|
|
|
ft_set_memory_funcs(NULL, NULL);
|
|
|
|
}
|