1
0
Fork 0

[A] Added new functions to the library API

This commit is contained in:
seleznevae 2018-01-20 21:27:24 +03:00
parent 3ae884ac52
commit ac6533cd63
5 changed files with 359 additions and 42 deletions

View File

@ -2,17 +2,42 @@
#include "fort.h"
int main()
{
FTABLE *table = ft_create_table();
int n = ft_hdr_printf(table, "%d , %c|| %s|%f", 3, 'c', "234", 3.14);
ft_hdr_printf_ln(table, "%d , %c|| %s|%f", 3, 'c', "234", 3.14);
fprintf(stderr, "n = %d\n", n);
const char *row[] = {"AAA", " ADf qwer", "qwerwqer", "11111 23333", "qwe"};
fprintf(stderr, "result: %s\n", ft_to_string(table));
ft_row_write_ln(table, 5, row);
ft_row_write(table, 5, row);
ft_row_write(table, 5, row);
ft_ln(table);
const char *ctab[2][2] = {
{"AAA", " ADf qwer"},
{"AAA", " ADf 2222"}
};
ft_s_table_write_ln(table, 2, 2, ctab);
const char **tab[2] = {
row,
row
};
ft_table_write(table, 2, 5, tab);
ft_ln(table);
ft_nwrite(table, 3, "123", "2345", "4567");
ft_ln(table);
FT_NWRITE(table, "123", "345", "Anton", "Petr", "Pavel");
fprintf(stderr, "Table:\n");
fprintf(stderr, "%s\n", ft_to_string(table));
// printf("Hello, world!\n");
// char buffer[3] = {'a', 'b', 'c'};

View File

@ -76,6 +76,13 @@ SOFTWARE.
#define FORT_EXTERN extern
#endif
#define STR_2_CAT_(arg1, arg2) \
arg1##arg2
#define STR_2_CAT(arg1, arg2) \
STR_2_CAT_(arg1, arg2)
/*
* libfort structures and functions declarations
*/
@ -89,18 +96,120 @@ FORT_EXTERN FTABLE * ft_create_table(void);
FORT_EXTERN void ft_destroy_table(FTABLE *FORT_RESTRICT table);
//FORT_EXTERN int ft_printf(FTABLE *FORT_RESTRICT table, const char* FORT_RESTRICT fmt, ...);
FORT_EXTERN void ft_ln(FTABLE *FORT_RESTRICT table);
FORT_EXTERN int ft_printf(FTABLE *FORT_RESTRICT table, size_t row, const char* FORT_RESTRICT fmt, ...);
FORT_EXTERN int ft_printf_ln(FTABLE *FORT_RESTRICT table, size_t row, const char* FORT_RESTRICT fmt, ...);
#define FT_PRINTF(table, row, ...) \
(( 0 ? fprintf(stderr, __VA_ARGS__) : 1), ft_printf(table, row, __VA_ARGS__))
#define FT_PRINTF_LN(table, row, ...) \
(( 0 ? fprintf(stderr, __VA_ARGS__) : 1), ft_printf_ln(table, row, __VA_ARGS__))
FORT_EXTERN int ft_hdr_printf(FTABLE *FORT_RESTRICT table, const char* FORT_RESTRICT fmt, ...);
FORT_EXTERN int ft_row_printf(FTABLE *FORT_RESTRICT table, size_t row, const char* FORT_RESTRICT fmt, ...);
//FORT_EXTERN int ft_cell_printf(FTABLE *FORT_RESTRICT table, size_t row, size_t col, const char* FORT_RESTRICT fmt, ...);
FORT_EXTERN int ft_hdr_printf_ln(FTABLE *FORT_RESTRICT table, const char* FORT_RESTRICT fmt, ...);
#define FT_HDR_PRINTF(table, ...) \
(( 0 ? fprintf(stderr, __VA_ARGS__) : 1), ft_hdr_printf(table, __VA_ARGS__))
#define FT_HDR_PRINTF_LN(table, ...) \
(( 0 ? fprintf(stderr, __VA_ARGS__) : 1), ft_hdr_printf_ln(table, __VA_ARGS__))
FORT_EXTERN int ft_write(FTABLE *FORT_RESTRICT table, const char* FORT_RESTRICT cell_content);
FORT_EXTERN int ft_write_ln(FTABLE *FORT_RESTRICT table, const char* FORT_RESTRICT cell_content);
#define FT_HDR_PRINTF(table, ...) \
(( 0 ? fprintf(stderr, __VA_ARGS__) : 1), ft_hdr_printf(table, __VA_ARGS__))
#define FT_ROW_PRINTF(table, row, ...) \
(( 0 ? fprintf(stderr, __VA_ARGS__) : 1), ft_row_printf(table, row, __VA_ARGS__))
static inline void fort_check_if_string_helper(const char*str)
{
(void)str;
}
#define PP_ARG_N( \
_1, _2, _3, _4, _5, _6, _7, _8, _9,_10, \
_11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \
_21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \
_31, N, ...) N
#define PP_RSEQ_N() \
31,30, \
29,28,27,26,25,24,23,22,21,20, \
19,18,17,16,15,14,13,12,11,10, \
9, 8, 7, 6, 5, 4, 3, 2, 1, 0
#define PP_NARG_(...) \
PP_ARG_N(__VA_ARGS__)
#define PP_NARG(...) \
PP_NARG_(__VA_ARGS__,PP_RSEQ_N())
#define CHECK_IF_ARG_IS_STRING_32(arg,...) (fort_check_if_string_helper(arg),CHECK_IF_ARG_IS_STRING_31(__VA_ARGS__))
#define CHECK_IF_ARG_IS_STRING_31(arg,...) (fort_check_if_string_helper(arg),CHECK_IF_ARG_IS_STRING_30(__VA_ARGS__))
#define CHECK_IF_ARG_IS_STRING_30(arg,...) (fort_check_if_string_helper(arg),CHECK_IF_ARG_IS_STRING_29(__VA_ARGS__))
#define CHECK_IF_ARG_IS_STRING_29(arg,...) (fort_check_if_string_helper(arg),CHECK_IF_ARG_IS_STRING_28(__VA_ARGS__))
#define CHECK_IF_ARG_IS_STRING_28(arg,...) (fort_check_if_string_helper(arg),CHECK_IF_ARG_IS_STRING_27(__VA_ARGS__))
#define CHECK_IF_ARG_IS_STRING_27(arg,...) (fort_check_if_string_helper(arg),CHECK_IF_ARG_IS_STRING_26(__VA_ARGS__))
#define CHECK_IF_ARG_IS_STRING_26(arg,...) (fort_check_if_string_helper(arg),CHECK_IF_ARG_IS_STRING_25(__VA_ARGS__))
#define CHECK_IF_ARG_IS_STRING_25(arg,...) (fort_check_if_string_helper(arg),CHECK_IF_ARG_IS_STRING_24(__VA_ARGS__))
#define CHECK_IF_ARG_IS_STRING_24(arg,...) (fort_check_if_string_helper(arg),CHECK_IF_ARG_IS_STRING_23(__VA_ARGS__))
#define CHECK_IF_ARG_IS_STRING_23(arg,...) (fort_check_if_string_helper(arg),CHECK_IF_ARG_IS_STRING_22(__VA_ARGS__))
#define CHECK_IF_ARG_IS_STRING_22(arg,...) (fort_check_if_string_helper(arg),CHECK_IF_ARG_IS_STRING_21(__VA_ARGS__))
#define CHECK_IF_ARG_IS_STRING_21(arg,...) (fort_check_if_string_helper(arg),CHECK_IF_ARG_IS_STRING_20(__VA_ARGS__))
#define CHECK_IF_ARG_IS_STRING_20(arg,...) (fort_check_if_string_helper(arg),CHECK_IF_ARG_IS_STRING_19(__VA_ARGS__))
#define CHECK_IF_ARG_IS_STRING_19(arg,...) (fort_check_if_string_helper(arg),CHECK_IF_ARG_IS_STRING_18(__VA_ARGS__))
#define CHECK_IF_ARG_IS_STRING_18(arg,...) (fort_check_if_string_helper(arg),CHECK_IF_ARG_IS_STRING_17(__VA_ARGS__))
#define CHECK_IF_ARG_IS_STRING_17(arg,...) (fort_check_if_string_helper(arg),CHECK_IF_ARG_IS_STRING_16(__VA_ARGS__))
#define CHECK_IF_ARG_IS_STRING_16(arg,...) (fort_check_if_string_helper(arg),CHECK_IF_ARG_IS_STRING_15(__VA_ARGS__))
#define CHECK_IF_ARG_IS_STRING_15(arg,...) (fort_check_if_string_helper(arg),CHECK_IF_ARG_IS_STRING_14(__VA_ARGS__))
#define CHECK_IF_ARG_IS_STRING_14(arg,...) (fort_check_if_string_helper(arg),CHECK_IF_ARG_IS_STRING_13(__VA_ARGS__))
#define CHECK_IF_ARG_IS_STRING_13(arg,...) (fort_check_if_string_helper(arg),CHECK_IF_ARG_IS_STRING_12(__VA_ARGS__))
#define CHECK_IF_ARG_IS_STRING_12(arg,...) (fort_check_if_string_helper(arg),CHECK_IF_ARG_IS_STRING_11(__VA_ARGS__))
#define CHECK_IF_ARG_IS_STRING_11(arg,...) (fort_check_if_string_helper(arg),CHECK_IF_ARG_IS_STRING_10(__VA_ARGS__))
#define CHECK_IF_ARG_IS_STRING_10(arg,...) (fort_check_if_string_helper(arg),CHECK_IF_ARG_IS_STRING_9(__VA_ARGS__))
#define CHECK_IF_ARG_IS_STRING_9(arg,...) (fort_check_if_string_helper(arg),CHECK_IF_ARG_IS_STRING_8(__VA_ARGS__))
#define CHECK_IF_ARG_IS_STRING_8(arg,...) (fort_check_if_string_helper(arg),CHECK_IF_ARG_IS_STRING_7(__VA_ARGS__))
#define CHECK_IF_ARG_IS_STRING_7(arg,...) (fort_check_if_string_helper(arg),CHECK_IF_ARG_IS_STRING_6(__VA_ARGS__))
#define CHECK_IF_ARG_IS_STRING_6(arg,...) (fort_check_if_string_helper(arg),CHECK_IF_ARG_IS_STRING_5(__VA_ARGS__))
#define CHECK_IF_ARG_IS_STRING_5(arg,...) (fort_check_if_string_helper(arg),CHECK_IF_ARG_IS_STRING_4(__VA_ARGS__))
#define CHECK_IF_ARG_IS_STRING_4(arg,...) (fort_check_if_string_helper(arg),CHECK_IF_ARG_IS_STRING_3(__VA_ARGS__))
#define CHECK_IF_ARG_IS_STRING_3(arg,...) (fort_check_if_string_helper(arg),CHECK_IF_ARG_IS_STRING_2(__VA_ARGS__))
#define CHECK_IF_ARG_IS_STRING_2(arg,...) (fort_check_if_string_helper(arg),CHECK_IF_ARG_IS_STRING_1(__VA_ARGS__))
#define CHECK_IF_ARG_IS_STRING_1(arg) (fort_check_if_string_helper(arg))
#define CHECK_IF_ARGS_ARE_STRINGS__(func, ...) func(__VA_ARGS__)
#define CHECK_IF_ARGS_ARE_STRINGS_(basis, n, ...) CHECK_IF_ARGS_ARE_STRINGS__(STR_2_CAT_(basis, n), __VA_ARGS__)
#define CHECK_IF_ARGS_ARE_STRINGS(...) CHECK_IF_ARGS_ARE_STRINGS_(CHECK_IF_ARG_IS_STRING_,PP_NARG(__VA_ARGS__), __VA_ARGS__)
#define FT_NWRITE(table, ...)\
(CHECK_IF_ARGS_ARE_STRINGS(__VA_ARGS__),ft_nwrite(table, PP_NARG(__VA_ARGS__), __VA_ARGS__))
FORT_EXTERN int ft_nwrite(FTABLE *FORT_RESTRICT table, size_t n, const char* FORT_RESTRICT cell_content, ...);
FORT_EXTERN int ft_nwrite_ln(FTABLE *FORT_RESTRICT table, size_t n, const char* FORT_RESTRICT cell_content, ...);
FORT_EXTERN int ft_write_status(FTABLE *FORT_RESTRICT table, int status, const char* FORT_RESTRICT cell_content);
FORT_EXTERN int ft_row_write(FTABLE *FORT_RESTRICT table, size_t cols, const char* FORT_RESTRICT row_cells[]);
FORT_EXTERN int ft_row_write_ln(FTABLE *FORT_RESTRICT table, size_t cols, const char* FORT_RESTRICT row_cells[]);
FORT_EXTERN int ft_s_table_write(FTABLE *FORT_RESTRICT table, size_t rows, size_t cols, const char* FORT_RESTRICT table_cells[rows][cols]);
FORT_EXTERN int ft_s_table_write_ln(FTABLE *FORT_RESTRICT table, size_t rows, size_t cols, const char* FORT_RESTRICT table_cells[rows][cols]);
FORT_EXTERN int ft_table_write(FTABLE *FORT_RESTRICT table, size_t rows, size_t cols, const char* * FORT_RESTRICT table_cells[rows]);
FORT_EXTERN int ft_table_write_ln(FTABLE *FORT_RESTRICT table, size_t rows, size_t cols, const char* * FORT_RESTRICT table_cells[rows]);
FORT_EXTERN const char* ft_to_string(const FTABLE *FORT_RESTRICT table);

View File

@ -83,7 +83,12 @@ void ft_destroy_table(FTABLE *FORT_RESTRICT table)
F_FREE(table);
}
void ft_ln(FTABLE *FORT_RESTRICT table)
{
assert(table);
table->cur_col = 0;
table->cur_row++;
}
static int ft_row_printf_impl(FTABLE *FORT_RESTRICT table, size_t row, const char* FORT_RESTRICT fmt, va_list *va)
@ -118,9 +123,9 @@ static int ft_row_printf_impl(FTABLE *FORT_RESTRICT table, size_t row, const cha
destroy_row(*cur_row_p);
*cur_row_p = new_row;
table->cur_col = 0;
table->cur_row++;
return columns_in_row(new_row);
size_t new_cols = columns_in_row(new_row);
table->cur_col += new_cols;
return new_cols;
clear:
destroy_row(new_row);
@ -129,6 +134,9 @@ clear:
int ft_hdr_printf(FTABLE *FORT_RESTRICT table, const char* FORT_RESTRICT fmt, ...)
{
assert(table);
assert(fmt);
va_list va;
va_start(va, fmt);
int result = ft_row_printf_impl(table, 0, fmt, &va);
@ -142,7 +150,28 @@ int ft_hdr_printf(FTABLE *FORT_RESTRICT table, const char* FORT_RESTRICT fmt, ..
return result;
}
int ft_row_printf(FTABLE *FORT_RESTRICT table, size_t row, const char* FORT_RESTRICT fmt, ...)
int ft_hdr_printf_ln(FTABLE *FORT_RESTRICT table, const char* FORT_RESTRICT fmt, ...)
{
assert(table);
assert(fmt);
va_list va;
va_start(va, fmt);
int result = ft_row_printf_impl(table, 0, fmt, &va);
va_end(va);
if (result >= 0 && table->rows) {
int sz = vector_size(table->rows);
if (sz != 0) {
set_row_type(*(fort_row_t**)vector_at(table->rows, sz - 1), Header);
}
}
if (result >= 0) {
ft_ln(table);
}
return result;
}
int ft_printf(FTABLE *FORT_RESTRICT table, size_t row, const char* FORT_RESTRICT fmt, ...)
{
va_list va;
va_start(va, fmt);
@ -151,6 +180,19 @@ int ft_row_printf(FTABLE *FORT_RESTRICT table, size_t row, const char* FORT_REST
return result;
}
int ft_printf_ln(FTABLE *FORT_RESTRICT table, size_t row, const char* FORT_RESTRICT fmt, ...)
{
va_list va;
va_start(va, fmt);
int result = ft_row_printf_impl(table, row, fmt, &va);
if (result >= 0) {
ft_ln(table);
}
va_end(va);
return result;
}
int ft_write(FTABLE *FORT_RESTRICT table, const char* FORT_RESTRICT cell_content)
{
string_buffer_t *str_buffer = get_cur_str_buffer_and_create_if_not_exists(table);
@ -168,12 +210,153 @@ int ft_write_ln(FTABLE *FORT_RESTRICT table, const char* FORT_RESTRICT cell_cont
{
int status = ft_write(table, cell_content);
if (IS_SUCCESS(status)) {
table->cur_col = 0;
table->cur_row++;
ft_ln(table);
}
return status;
}
FORT_EXTERN int ft_nwrite(FTABLE *FORT_RESTRICT table, size_t n, const char* FORT_RESTRICT cell_content, ...)
{
assert(table);
int status = ft_write(table, cell_content);
if (IS_ERROR(status))
return status;
va_list va;
va_start(va, cell_content);
--n;
for (size_t i = 0; i < n; ++i) {
const char *cell = va_arg(va, const char*);
status = ft_write(table, cell);
if (IS_ERROR(status))
return status;
}
va_end(va);
return status;
}
FORT_EXTERN int ft_nwrite_ln(FTABLE *FORT_RESTRICT table, size_t n, const char* FORT_RESTRICT cell_content, ...)
{
assert(table);
int status = ft_write(table, cell_content);
if (IS_ERROR(status))
return status;
va_list va;
va_start(va, cell_content);
--n;
for (size_t i = 0; i < n; ++i) {
const char *cell = va_arg(va, const char*);
status = ft_write(table, cell);
if (IS_ERROR(status))
return status;
}
va_end(va);
return status;
ft_ln(table);
return status;
}
FORT_EXTERN int ft_write_status(FTABLE *FORT_RESTRICT table, int status, const char* FORT_RESTRICT cell_content)
{
assert(table);
if (IS_ERROR(status))
return status;
return ft_write(table, cell_content);
}
FORT_EXTERN int ft_row_write(FTABLE *FORT_RESTRICT table, size_t cols, const char* FORT_RESTRICT cells[])
{
assert(table);
for (size_t i = 0; i < cols; ++i) {
int status = ft_write(table, cells[i]);
if (IS_ERROR(status)) {
//todo: maybe current pos in case of error should be equal to the one before function call?
return status;
}
}
return F_SUCCESS;
}
FORT_EXTERN int ft_row_write_ln(FTABLE *FORT_RESTRICT table, size_t cols, const char* FORT_RESTRICT cells[])
{
assert(table);
int status = ft_row_write(table, cols, cells);
if (IS_SUCCESS(status)) {
ft_ln(table);
}
return status;
}
//FORT_EXTERN int ft_table_write(FTABLE *FORT_RESTRICT table, size_t rows, size_t cols, const char** FORT_RESTRICT table_cells[]);
//FORT_EXTERN int ft_table_write_ln(FTABLE *FORT_RESTRICT table, size_t rows, size_t cols, const char** FORT_RESTRICT table_cells[]);
//int ft_table_write(FTABLE *FORT_RESTRICT table, size_t rows, size_t cols, const char* FORT_RESTRICT table_cells[rows][cols]);
//int ft_table_write_ln(FTABLE *FORT_RESTRICT table, size_t rows, size_t cols, const char** FORT_RESTRICT table_cells[rows][cols]);
int ft_s_table_write(FTABLE *FORT_RESTRICT table, size_t rows, size_t cols, const char* FORT_RESTRICT table_cells[rows][cols])
{
assert(table);
for (size_t i = 0; i < rows; ++i) {
int status = ft_row_write(table, cols, table_cells[i]);
if (IS_ERROR(status)) {
//todo: maybe current pos in case of error should be equal to the one before function call?
return status;
}
if (i != rows - 1)
ft_ln(table);
}
return F_SUCCESS;
}
int ft_s_table_write_ln(FTABLE *FORT_RESTRICT table, size_t rows, size_t cols, const char* FORT_RESTRICT table_cells[rows][cols])
{
assert(table);
int status = ft_s_table_write(table, rows, cols, table_cells);
if (IS_SUCCESS(status)) {
ft_ln(table);
}
return status;
}
int ft_table_write(FTABLE *FORT_RESTRICT table, size_t rows, size_t cols, const char* * FORT_RESTRICT table_cells[rows])
{
assert(table);
for (size_t i = 0; i < rows; ++i) {
int status = ft_row_write(table, cols, table_cells[i]);
if (IS_ERROR(status)) {
//todo: maybe current pos in case of error should be equal to the one before function call?
return status;
}
if (i != rows - 1)
ft_ln(table);
}
return F_SUCCESS;
}
int ft_table_write_ln(FTABLE *FORT_RESTRICT table, size_t rows, size_t cols, const char* * FORT_RESTRICT table_cells[rows])
{
assert(table);
int status = ft_table_write(table, rows, cols, table_cells);
if (IS_SUCCESS(status)) {
ft_ln(table);
}
return status;
}
int ft_set_default_options(const fort_table_options_t *options)
{
memcpy(&g_table_options, options, sizeof(fort_table_options_t));

View File

@ -60,10 +60,10 @@ enum F_BOOL
* ***************************************************************************/
typedef int fort_status_t;
#define F_SUCCESS 0
#define F_MEMORY_ERROR 1
#define F_ERROR 2
#define IS_SUCCESS(arg) ((arg) == F_SUCCESS)
#define IS_ERROR(arg) (!IS_SUCCESS(arg))
#define F_MEMORY_ERROR -1
#define F_ERROR -2
#define IS_SUCCESS(arg) ((arg) >= 0)
#define IS_ERROR(arg) ((arg) < 0)
/*****************************************************************************
* DEFAULT_SIZES

View File

@ -24,7 +24,7 @@ void test_table_sizes(void **state)
}
WHEN("Insert one cell") {
int n = FT_HDR_PRINTF(table, "%c", 'c');
int n = FT_HDR_PRINTF_LN(table, "%c", 'c');
assert_true( n == 1 );
status = get_table_sizes(table, &rows, &cols);
assert_true( IS_SUCCESS(status) );
@ -33,7 +33,7 @@ void test_table_sizes(void **state)
}
WHEN("Insert two cells in the next row") {
int n = FT_ROW_PRINTF(table, 1, "%c|%c", 'c', 'd');
int n = FT_PRINTF_LN(table, 1, "%c|%c", 'c', 'd');
assert_true( n == 2 );
status = get_table_sizes(table, &rows, &cols);
assert_true( IS_SUCCESS(status) );
@ -42,7 +42,7 @@ void test_table_sizes(void **state)
}
WHEN("Insert five cells in the next row") {
int n = FT_ROW_PRINTF(table, 2, "%d|%d|%d|%d|%d", 1, 2, 3, 4, 5);
int n = FT_PRINTF_LN(table, 2, "%d|%d|%d|%d|%d", 1, 2, 3, 4, 5);
assert_true( n == 5 );
status = get_table_sizes(table, &rows, &cols);
assert_true( IS_SUCCESS(status) );
@ -71,7 +71,7 @@ void test_table_geometry(void **state)
}
WHEN("Table has one cell") {
int n = FT_HDR_PRINTF(table, "%c", 'c');
int n = FT_HDR_PRINTF_LN(table, "%c", 'c');
assert_true( n == 1 );
status = table_geometry(table, &height, &width);
assert_true( IS_SUCCESS(status) );
@ -80,7 +80,7 @@ void test_table_geometry(void **state)
}
WHEN("Inserting 3 cells in the next row") {
int n = FT_ROW_PRINTF(table, 1, "%c|%s|%c", 'c', "as", 'e');
int n = FT_PRINTF_LN(table, 1, "%c|%s|%c", 'c', "as", 'e');
assert_true( n == 3 );
status = table_geometry(table, &height, &width);
assert_true( IS_SUCCESS(status) );
@ -97,11 +97,11 @@ void test_table_basic(void **state)
FTABLE *table = ft_create_table();
WHEN("All columns are equal and not empty") {
int n = FT_HDR_PRINTF(table, "%d|%c|%s|%f", 3, 'c', "234", 3.14);
int n = FT_HDR_PRINTF_LN(table, "%d|%c|%s|%f", 3, 'c', "234", 3.14);
assert_true( n == 4 );
n = FT_ROW_PRINTF(table, 1, "%d|%c|%s|%f", 3, 'c', "234", 3.14);
n = FT_PRINTF_LN(table, 1, "%d|%c|%s|%f", 3, 'c', "234", 3.14);
assert_true( n == 4 );
n = FT_ROW_PRINTF(table, 2, "%d|%c|%s|%f", 3, 'c', "234", 3.14);
n = FT_PRINTF_LN(table, 2, "%d|%c|%s|%f", 3, 'c', "234", 3.14);
assert_true( n == 4 );
const char *table_str = ft_to_string(table);
@ -132,11 +132,11 @@ void test_table_basic(void **state)
WHEN("All columns are not equal and not empty") {
table = ft_create_table();
int n = FT_HDR_PRINTF(table, "%d|%c|%s|%f", 3, 'c', "234", 3.14);
int n = FT_HDR_PRINTF_LN(table, "%d|%c|%s|%f", 3, 'c', "234", 3.14);
assert_true( n == 4 );
n = FT_ROW_PRINTF(table, 1, "%c|%s|%f|%d", 'c', "234", 3.14, 3);
n = FT_PRINTF_LN(table, 1, "%c|%s|%f|%d", 'c', "234", 3.14, 3);
assert_true( n == 4 );
n = FT_ROW_PRINTF(table, 2, "%s|%f|%d|%c", "234", 3.14, 3, 'c');
n = FT_PRINTF_LN(table, 2, "%s|%f|%d|%c", "234", 3.14, 3, 'c');
assert_true( n == 4 );
const char *table_str = ft_to_string(table);
@ -165,11 +165,11 @@ void test_table_basic(void **state)
WHEN("All columns are not equal and some cells are empty") {
table = ft_create_table();
int n = FT_HDR_PRINTF(table, "||%s|%f", "234", 3.14);
int n = FT_HDR_PRINTF_LN(table, "||%s|%f", "234", 3.14);
assert_true( n == 4 );
n = FT_ROW_PRINTF(table, 1, "%c|%s|%f", 'c', "234", 3.14);
n = FT_PRINTF_LN(table, 1, "%c|%s|%f", 'c', "234", 3.14);
assert_true( n == 3 );
n = FT_ROW_PRINTF(table, 2, "%s|%f||", "234", 3.14);
n = FT_PRINTF_LN(table, 2, "%s|%f||", "234", 3.14);
assert_true( n == 4 );
const char *table_str = ft_to_string(table);
@ -198,11 +198,11 @@ void test_table_basic(void **state)
WHEN("All cells are empty") {
table = ft_create_table();
int n = FT_HDR_PRINTF(table, "|||");
int n = FT_HDR_PRINTF_LN(table, "|||");
assert_true( n == 4 );
n = FT_ROW_PRINTF(table, 1, "|||");
n = FT_PRINTF_LN(table, 1, "|||");
assert_true( n == 4 );
n = FT_ROW_PRINTF(table, 2, "|||");
n = FT_PRINTF_LN(table, 2, "|||");
assert_true( n == 4 );
const char *table_str = ft_to_string(table);
@ -240,7 +240,7 @@ FTABLE *create_test_int_table()
assert_true (table != NULL);
int n = FT_HDR_PRINTF(table, "%d|%d|%d|%d", 3, 4, 55, 67);
int n = FT_HDR_PRINTF_LN(table, "%d|%d|%d|%d", 3, 4, 55, 67);
assert_true( n == 4 );
assert(ft_write(table, "3") == F_SUCCESS);
@ -400,7 +400,7 @@ void test_table_options(void **state)
ft_set_default_options(&table_options);
table = create_test_int_table();
int n = ft_row_printf(table, 3, "|||");
int n = ft_printf_ln(table, 3, "|||");
assert_true( n == 4 );
const char *table_str = ft_to_string(table);