[R] Refactoring of tests
This commit is contained in:
		@@ -5,9 +5,7 @@ cmake_minimum_required(VERSION 2.8)
 | 
			
		||||
 | 
			
		||||
# Built options
 | 
			
		||||
option(FORT_CXX_BUILD "Compile with c++ compiler instead of c" OFF)
 | 
			
		||||
#option(FORT_COVERALLS_BUILD "Build for coveralls" OFF)
 | 
			
		||||
set(FORT_BUILD_TYPE "common" CACHE STRING "Built types (possible values: common, asan, ubsan, coveralls)")
 | 
			
		||||
#set(FORT_COMPILER "gcc" CACHE STRING "Compiler (possible values: gcc, clang, msvc)")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# Determine compiler (pos. values Clang, GNU, Intel, MSVC, AppleClang... (https://cmake.org/cmake/help/v3.0/variable/CMAKE_LANG_COMPILER_ID.html)
 | 
			
		||||
@@ -63,8 +61,12 @@ add_executable(${PROJECT_NAME}_example
 | 
			
		||||
set(TEST_SOURCES
 | 
			
		||||
    tests/test.c
 | 
			
		||||
    tests/test_vector.c
 | 
			
		||||
    tests/test_table.c
 | 
			
		||||
    tests/test_string_buffer.c)
 | 
			
		||||
    tests/test_string_buffer.c
 | 
			
		||||
    tests/test_table_geometry.c
 | 
			
		||||
    tests/test_table_basic.c
 | 
			
		||||
    tests/test_table_border_style.c
 | 
			
		||||
    tests/test_table_options.c
 | 
			
		||||
    tests/test_utility.c)
 | 
			
		||||
add_executable(${PROJECT_NAME}_test
 | 
			
		||||
    ${FORT_SOURCES}
 | 
			
		||||
    ${TEST_SOURCES})
 | 
			
		||||
@@ -113,7 +115,4 @@ if(FORT_COMPILER STREQUAL "GNU")
 | 
			
		||||
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fuse-ld=gold")
 | 
			
		||||
endif(FORT_COMPILER STREQUAL "GNU")
 | 
			
		||||
 | 
			
		||||
# Coveralls support
 | 
			
		||||
#if(FORT_COVERALLS_BUILD)
 | 
			
		||||
#    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -fprofile-arcs -ftest-coverage")
 | 
			
		||||
#endif(FORT_COVERALLS_BUILD)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										26
									
								
								src/fort.c
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								src/fort.c
									
									
									
									
									
								
							@@ -196,7 +196,7 @@ int ft_write(FTABLE *FT_RESTRICT table, const char* FT_RESTRICT cell_content)
 | 
			
		||||
    assert(table);
 | 
			
		||||
    string_buffer_t *str_buffer = get_cur_str_buffer_and_create_if_not_exists(table);
 | 
			
		||||
    if (str_buffer == NULL)
 | 
			
		||||
        return F_ERROR;
 | 
			
		||||
        return FT_ERROR;
 | 
			
		||||
 | 
			
		||||
    int status = fill_buffer_from_string(str_buffer, cell_content);
 | 
			
		||||
    if (IS_SUCCESS(status)) {
 | 
			
		||||
@@ -220,7 +220,7 @@ int ft_wwrite(FTABLE *FT_RESTRICT table, const wchar_t* FT_RESTRICT cell_content
 | 
			
		||||
    assert(table);
 | 
			
		||||
    string_buffer_t *str_buffer = get_cur_str_buffer_and_create_if_not_exists(table);
 | 
			
		||||
    if (str_buffer == NULL)
 | 
			
		||||
        return F_ERROR;
 | 
			
		||||
        return FT_ERROR;
 | 
			
		||||
 | 
			
		||||
    int status = fill_buffer_from_wstring(str_buffer, cell_content);
 | 
			
		||||
    if (IS_SUCCESS(status)) {
 | 
			
		||||
@@ -345,7 +345,7 @@ int ft_row_write(FTABLE *FT_RESTRICT table, size_t cols, const char* FT_RESTRICT
 | 
			
		||||
            return status;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return F_SUCCESS;
 | 
			
		||||
    return FT_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int ft_row_write_ln(FTABLE *FT_RESTRICT table, size_t cols, const char* FT_RESTRICT cells[])
 | 
			
		||||
@@ -375,7 +375,7 @@ int ft_s_table_write(FTABLE *FT_RESTRICT table, size_t rows, size_t cols, const
 | 
			
		||||
        if (i != rows - 1)
 | 
			
		||||
            ft_ln(table);
 | 
			
		||||
    }
 | 
			
		||||
    return F_SUCCESS;
 | 
			
		||||
    return FT_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int ft_s_table_write_ln(FTABLE *FT_RESTRICT table, size_t rows, size_t cols, const char* FT_RESTRICT table_cells[rows][cols])
 | 
			
		||||
@@ -402,7 +402,7 @@ int ft_table_write(FTABLE *FT_RESTRICT table, size_t rows, size_t cols, const ch
 | 
			
		||||
        if (i != rows - 1)
 | 
			
		||||
            ft_ln(table);
 | 
			
		||||
    }
 | 
			
		||||
    return F_SUCCESS;
 | 
			
		||||
    return FT_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int ft_table_write_ln(FTABLE *FT_RESTRICT table, size_t rows, size_t cols, const char* * FT_RESTRICT table_cells[rows])
 | 
			
		||||
@@ -649,7 +649,7 @@ int ft_add_separator(FTABLE *table)
 | 
			
		||||
    while(vector_size(table->separators) <= table->cur_row) {
 | 
			
		||||
        separator_t *sep_p = create_separator(F_FALSE);
 | 
			
		||||
        if (sep_p == NULL)
 | 
			
		||||
            return F_MEMORY_ERROR;
 | 
			
		||||
            return FT_MEMORY_ERROR;
 | 
			
		||||
        int status = vector_push(table->separators, &sep_p);
 | 
			
		||||
        if (IS_ERROR(status))
 | 
			
		||||
            return status;
 | 
			
		||||
@@ -662,8 +662,8 @@ int ft_add_separator(FTABLE *table)
 | 
			
		||||
        (*sep_p)->enabled = F_TRUE;
 | 
			
		||||
 | 
			
		||||
    if (*sep_p == NULL)
 | 
			
		||||
        return F_ERROR;
 | 
			
		||||
    return F_SUCCESS;
 | 
			
		||||
        return FT_ERROR;
 | 
			
		||||
    return FT_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -753,7 +753,7 @@ static void set_border_options_for_options(fort_table_options_t *options, struct
 | 
			
		||||
int ft_set_default_border_style(struct ft_border_style *style)
 | 
			
		||||
{
 | 
			
		||||
    set_border_options_for_options(&g_table_options, style);
 | 
			
		||||
    return F_SUCCESS;
 | 
			
		||||
    return FT_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int ft_set_border_style(FTABLE *table, struct ft_border_style *style)
 | 
			
		||||
@@ -762,10 +762,10 @@ int ft_set_border_style(FTABLE *table, struct ft_border_style *style)
 | 
			
		||||
    if (table->options == NULL) {
 | 
			
		||||
        table->options = create_table_options();
 | 
			
		||||
        if (table->options == NULL)
 | 
			
		||||
            return F_MEMORY_ERROR;
 | 
			
		||||
            return FT_MEMORY_ERROR;
 | 
			
		||||
    }
 | 
			
		||||
    set_border_options_for_options(table->options, style);
 | 
			
		||||
    return F_SUCCESS;
 | 
			
		||||
    return FT_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -777,12 +777,12 @@ int ft_set_option(FTABLE *table, unsigned row, unsigned col, uint32_t option, in
 | 
			
		||||
    if (table->options == NULL) {
 | 
			
		||||
        table->options = create_table_options();
 | 
			
		||||
        if (table->options == NULL)
 | 
			
		||||
            return F_MEMORY_ERROR;
 | 
			
		||||
            return FT_MEMORY_ERROR;
 | 
			
		||||
    }
 | 
			
		||||
    if (table->options->cell_options == NULL) {
 | 
			
		||||
        table->options->cell_options = create_cell_opt_container();
 | 
			
		||||
        if (table->options->cell_options == NULL) {
 | 
			
		||||
            return F_ERROR;
 | 
			
		||||
            return FT_ERROR;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return set_cell_option(table->options->cell_options, row, col, option, value);
 | 
			
		||||
 
 | 
			
		||||
@@ -61,9 +61,9 @@ enum F_BOOL
 | 
			
		||||
 *               RETURN CODES
 | 
			
		||||
 * ***************************************************************************/
 | 
			
		||||
typedef int fort_status_t;
 | 
			
		||||
#define F_SUCCESS        0
 | 
			
		||||
#define F_MEMORY_ERROR   -1
 | 
			
		||||
#define F_ERROR          -2
 | 
			
		||||
#define FT_SUCCESS        0
 | 
			
		||||
#define FT_MEMORY_ERROR   -1
 | 
			
		||||
#define FT_ERROR          -2
 | 
			
		||||
#define IS_SUCCESS(arg) ((arg) >= 0)
 | 
			
		||||
#define IS_ERROR(arg) ((arg) < 0)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -175,7 +175,7 @@ static fort_status_t set_cell_option_impl(fort_cell_options_t *opt, uint32_t opt
 | 
			
		||||
        opt->row_type = (enum RowType)value;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return F_SUCCESS;
 | 
			
		||||
    return FT_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -183,7 +183,7 @@ fort_status_t set_cell_option(fort_cell_opt_container_t *cont, unsigned row, uns
 | 
			
		||||
{
 | 
			
		||||
    fort_cell_options_t* opt = get_cell_opt_and_create_if_not_exists(cont, row, col);
 | 
			
		||||
    if (opt == NULL)
 | 
			
		||||
        return F_ERROR;
 | 
			
		||||
        return FT_ERROR;
 | 
			
		||||
 | 
			
		||||
    return set_cell_option_impl(opt, option, value);
 | 
			
		||||
    /*
 | 
			
		||||
@@ -194,7 +194,7 @@ fort_status_t set_cell_option(fort_cell_opt_container_t *cont, unsigned row, uns
 | 
			
		||||
        opt->align = value;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return F_SUCCESS;
 | 
			
		||||
    return FT_SUCCESS;
 | 
			
		||||
    */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -157,12 +157,12 @@ fort_status_t realloc_string_buffer_without_copy(string_buffer_t *buffer)
 | 
			
		||||
    assert(buffer);
 | 
			
		||||
    char *new_str = (char*)F_MALLOC(buffer->data_sz * 2);
 | 
			
		||||
    if (new_str == NULL) {
 | 
			
		||||
        return F_MEMORY_ERROR;
 | 
			
		||||
        return FT_MEMORY_ERROR;
 | 
			
		||||
    }
 | 
			
		||||
    F_FREE(buffer->str.data);
 | 
			
		||||
    buffer->str.data = new_str;
 | 
			
		||||
    buffer->data_sz *= 2;
 | 
			
		||||
    return F_SUCCESS;
 | 
			
		||||
    return FT_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fort_status_t fill_buffer_from_string(string_buffer_t *buffer, const char *str)
 | 
			
		||||
@@ -173,7 +173,7 @@ fort_status_t fill_buffer_from_string(string_buffer_t *buffer, const char *str)
 | 
			
		||||
    size_t sz = strlen(str);
 | 
			
		||||
    char * copy = F_STRDUP(str);
 | 
			
		||||
    if (copy == NULL)
 | 
			
		||||
        return F_MEMORY_ERROR;
 | 
			
		||||
        return FT_MEMORY_ERROR;
 | 
			
		||||
 | 
			
		||||
    while (sz >= string_buffer_capacity(buffer)) {
 | 
			
		||||
        int status = realloc_string_buffer_without_copy(buffer);
 | 
			
		||||
@@ -185,7 +185,7 @@ fort_status_t fill_buffer_from_string(string_buffer_t *buffer, const char *str)
 | 
			
		||||
    buffer->str.cstr = copy;
 | 
			
		||||
    buffer->type = CharBuf;
 | 
			
		||||
 | 
			
		||||
    return F_SUCCESS;
 | 
			
		||||
    return FT_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fort_status_t fill_buffer_from_wstring(string_buffer_t *buffer, const wchar_t *str)
 | 
			
		||||
@@ -196,7 +196,7 @@ fort_status_t fill_buffer_from_wstring(string_buffer_t *buffer, const wchar_t *s
 | 
			
		||||
    size_t sz = wcslen(str);
 | 
			
		||||
    wchar_t * copy = F_WCSDUP(str);
 | 
			
		||||
    if (copy == NULL)
 | 
			
		||||
        return F_MEMORY_ERROR;
 | 
			
		||||
        return FT_MEMORY_ERROR;
 | 
			
		||||
 | 
			
		||||
    while (sz >= string_buffer_capacity(buffer)) {
 | 
			
		||||
        int status = realloc_string_buffer_without_copy(buffer);
 | 
			
		||||
@@ -208,7 +208,7 @@ fort_status_t fill_buffer_from_wstring(string_buffer_t *buffer, const wchar_t *s
 | 
			
		||||
    buffer->str.wstr = copy;
 | 
			
		||||
    buffer->type = WCharBuf;
 | 
			
		||||
 | 
			
		||||
    return F_SUCCESS;
 | 
			
		||||
    return FT_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										12
									
								
								src/table.c
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								src/table.c
									
									
									
									
									
								
							@@ -85,7 +85,7 @@ fort_status_t get_table_sizes(const FTABLE *table, size_t *rows, size_t *cols)
 | 
			
		||||
                *cols = cols_in_row;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return F_SUCCESS;
 | 
			
		||||
    return FT_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fort_status_t table_rows_and_cols_geometry(const FTABLE *table,
 | 
			
		||||
@@ -93,7 +93,7 @@ fort_status_t table_rows_and_cols_geometry(const FTABLE *table,
 | 
			
		||||
                                                  size_t **row_height_arr_p, size_t *row_height_arr_sz)
 | 
			
		||||
{
 | 
			
		||||
    if (table == NULL) {
 | 
			
		||||
        return F_ERROR;
 | 
			
		||||
        return FT_ERROR;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -109,7 +109,7 @@ fort_status_t table_rows_and_cols_geometry(const FTABLE *table,
 | 
			
		||||
    if (col_width_arr == NULL || row_height_arr == NULL) {
 | 
			
		||||
        F_FREE(col_width_arr);
 | 
			
		||||
        F_FREE(row_height_arr);
 | 
			
		||||
        return F_ERROR;
 | 
			
		||||
        return FT_ERROR;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    context_t context;
 | 
			
		||||
@@ -146,7 +146,7 @@ fort_status_t table_rows_and_cols_geometry(const FTABLE *table,
 | 
			
		||||
    *col_width_arr_sz = cols;
 | 
			
		||||
    *row_height_arr_p = row_height_arr;
 | 
			
		||||
    *row_height_arr_sz = rows;
 | 
			
		||||
    return F_SUCCESS;
 | 
			
		||||
    return FT_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
@@ -155,7 +155,7 @@ fort_status_t table_rows_and_cols_geometry(const FTABLE *table,
 | 
			
		||||
fort_status_t table_geometry(const FTABLE *table, size_t *height, size_t *width)
 | 
			
		||||
{
 | 
			
		||||
    if (table == NULL)
 | 
			
		||||
        return F_ERROR;
 | 
			
		||||
        return FT_ERROR;
 | 
			
		||||
 | 
			
		||||
    *height = 0;
 | 
			
		||||
    *width = 0;
 | 
			
		||||
@@ -181,7 +181,7 @@ fort_status_t table_geometry(const FTABLE *table, size_t *height, size_t *width)
 | 
			
		||||
    }
 | 
			
		||||
    F_FREE(col_width_arr);
 | 
			
		||||
    F_FREE(row_height_arr);
 | 
			
		||||
    return F_SUCCESS;
 | 
			
		||||
    return FT_SUCCESS;
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -116,7 +116,7 @@ int vector_push (vector_t* vector, const void* item)
 | 
			
		||||
 | 
			
		||||
    if (vector->m_size == vector->m_capacity) {
 | 
			
		||||
        if (vector_reallocate_(vector, vector->m_capacity * 2) == -1)
 | 
			
		||||
            return F_ERROR;
 | 
			
		||||
            return FT_ERROR;
 | 
			
		||||
        vector->m_capacity = vector->m_capacity * 2;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -125,7 +125,7 @@ int vector_push (vector_t* vector, const void* item)
 | 
			
		||||
 | 
			
		||||
    ++(vector->m_size);
 | 
			
		||||
 | 
			
		||||
    return F_SUCCESS;
 | 
			
		||||
    return FT_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -134,13 +134,13 @@ int vector_erase(vector_t *vector, size_t index)
 | 
			
		||||
    assert(vector);
 | 
			
		||||
 | 
			
		||||
    if (vector->m_size == 0 || index >= vector->m_size)
 | 
			
		||||
        return F_ERROR;
 | 
			
		||||
        return FT_ERROR;
 | 
			
		||||
 | 
			
		||||
    memmove((char*)vector->m_data + vector->m_item_size * index,
 | 
			
		||||
            (char*)vector->m_data + vector->m_item_size * (index + 1),
 | 
			
		||||
            (vector->m_size - 1 - index) * vector->m_item_size);
 | 
			
		||||
    vector->m_size--;
 | 
			
		||||
    return F_SUCCESS;
 | 
			
		||||
    return FT_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -3,11 +3,12 @@
 | 
			
		||||
 | 
			
		||||
struct test_case test_suit [] = {
 | 
			
		||||
    {"test_vector_basic", test_vector_basic},
 | 
			
		||||
    {"test_string_buffer", test_string_buffer},
 | 
			
		||||
    {"test_table_sizes", test_table_sizes},
 | 
			
		||||
    {"test_table_geometry", test_table_geometry},
 | 
			
		||||
    {"test_table_basic", test_table_basic},
 | 
			
		||||
    {"test_table_border_style", test_table_border_style},
 | 
			
		||||
    {"test_table_options", test_table_options},
 | 
			
		||||
    {"test_string_buffer", test_string_buffer},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
int main(void) {
 | 
			
		||||
@@ -16,7 +17,7 @@ int main(void) {
 | 
			
		||||
    int i;
 | 
			
		||||
    for (i = 0; i < n_tests; ++i) {
 | 
			
		||||
        fprintf(stderr, "[ RUN      ] %s\n", test_suit[i].name);
 | 
			
		||||
        test_suit[i].test(NULL);
 | 
			
		||||
        test_suit[i].test();
 | 
			
		||||
        fprintf(stderr, "[       OK ] %s\n", test_suit[i].name);
 | 
			
		||||
    }
 | 
			
		||||
    fprintf(stderr, "[==========] %d test(s) run.\n", n_tests);
 | 
			
		||||
 
 | 
			
		||||
@@ -24,10 +24,8 @@ void test_buffer_text_width(void);
 | 
			
		||||
void test_buffer_text_height(void);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void test_string_buffer(void **state)
 | 
			
		||||
void test_string_buffer(void)
 | 
			
		||||
{
 | 
			
		||||
    (void)state;
 | 
			
		||||
 | 
			
		||||
    test_strchr_count();
 | 
			
		||||
    test_str_n_substring();
 | 
			
		||||
    test_buffer_text_width();
 | 
			
		||||
 
 | 
			
		||||
@@ -1,819 +0,0 @@
 | 
			
		||||
//#define FT_EXTERN static
 | 
			
		||||
#include "tests.h"
 | 
			
		||||
#include "fort.h"
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
//#include "fort.c"
 | 
			
		||||
#include "table.h"
 | 
			
		||||
#include "options.h"
 | 
			
		||||
#include "vector.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
int set_test_options_for_table(FTABLE *table)
 | 
			
		||||
{
 | 
			
		||||
    assert(table);
 | 
			
		||||
    int status = F_SUCCESS;
 | 
			
		||||
    status |= ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_BOTTOM_PADDING, 1);
 | 
			
		||||
    status |= ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_TOP_PADDING, 1);
 | 
			
		||||
    status |= ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_LEFT_PADDING, 1);
 | 
			
		||||
    status |= ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_RIGHT_PADDING, 1);
 | 
			
		||||
    status |= ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_EMPTY_STR_HEIGHT, 1);
 | 
			
		||||
 | 
			
		||||
    assert_true( status == F_SUCCESS );
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    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 = '|';
 | 
			
		||||
    brdr_style.header_border_chs.out_intersect_ch = '+';
 | 
			
		||||
    brdr_style.header_border_chs.in_intersect_ch = '+';
 | 
			
		||||
 | 
			
		||||
    brdr_style.hor_separator_char = '=';
 | 
			
		||||
    return ft_set_border_style(table, &brdr_style);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int set_test_options_as_default()
 | 
			
		||||
{
 | 
			
		||||
    int status = F_SUCCESS;
 | 
			
		||||
 | 
			
		||||
    status |= ft_set_default_option(FT_OPT_MIN_WIDTH, 0);
 | 
			
		||||
    status |= ft_set_default_option(FT_OPT_TEXT_ALIGN, RightAligned);
 | 
			
		||||
 | 
			
		||||
    status |= ft_set_default_option(FT_OPT_BOTTOM_PADDING, 1);
 | 
			
		||||
    status |= ft_set_default_option(FT_OPT_TOP_PADDING, 1);
 | 
			
		||||
    status |= ft_set_default_option(FT_OPT_LEFT_PADDING, 1);
 | 
			
		||||
    status |= ft_set_default_option(FT_OPT_RIGHT_PADDING, 1);
 | 
			
		||||
    status |= ft_set_default_option(FT_OPT_EMPTY_STR_HEIGHT, 1);
 | 
			
		||||
 | 
			
		||||
    assert_true( status == F_SUCCESS );
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    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 = '|';
 | 
			
		||||
    brdr_style.header_border_chs.out_intersect_ch = '+';
 | 
			
		||||
    brdr_style.header_border_chs.in_intersect_ch = '+';
 | 
			
		||||
 | 
			
		||||
    brdr_style.hor_separator_char = '=';
 | 
			
		||||
 | 
			
		||||
    return ft_set_default_border_style(&brdr_style);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void test_table_sizes(void **state)
 | 
			
		||||
{
 | 
			
		||||
    (void)state;
 | 
			
		||||
    FTABLE *table = ft_create_table();
 | 
			
		||||
    assert_true( table != NULL );
 | 
			
		||||
//    ft_set_table_options(table, &test_table_opts);
 | 
			
		||||
 | 
			
		||||
    assert_true( set_test_options_for_table(table) == F_SUCCESS);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    size_t rows = 0;
 | 
			
		||||
    size_t cols = 0;
 | 
			
		||||
    int status = F_SUCCESS;
 | 
			
		||||
 | 
			
		||||
    WHEN("Table is empty") {
 | 
			
		||||
        status = get_table_sizes(table, &rows, &cols);
 | 
			
		||||
        assert_true( IS_SUCCESS(status) );
 | 
			
		||||
        assert_true( rows == 0 );
 | 
			
		||||
        assert_true( cols == 0 );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    WHEN("Insert one cell") {
 | 
			
		||||
        int n = ft_printf_ln(table, "%c", 'c');
 | 
			
		||||
        assert_true( n == 1 );
 | 
			
		||||
        status = get_table_sizes(table, &rows, &cols);
 | 
			
		||||
        assert_true( IS_SUCCESS(status) );
 | 
			
		||||
        assert_true( rows == 1 );
 | 
			
		||||
        assert_true( cols == 1 );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    WHEN("Insert two cells in the next row") {
 | 
			
		||||
        int n = ft_printf_ln(table, "%c|%c", 'c', 'd');
 | 
			
		||||
        assert_true( n == 2 );
 | 
			
		||||
        status = get_table_sizes(table, &rows, &cols);
 | 
			
		||||
        assert_true( IS_SUCCESS(status) );
 | 
			
		||||
        assert_true( rows == 2 );
 | 
			
		||||
        assert_true( cols == 2 );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    WHEN("Insert five cells in the next row") {
 | 
			
		||||
        int n = ft_printf_ln(table, "%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) );
 | 
			
		||||
        assert_true( rows == 3 );
 | 
			
		||||
        assert_true( cols == 5 );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ft_destroy_table(table);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void test_table_geometry(void **state)
 | 
			
		||||
{
 | 
			
		||||
    (void)state;
 | 
			
		||||
    FTABLE *table = ft_create_table();
 | 
			
		||||
    assert_true( table != NULL );
 | 
			
		||||
//    ft_set_table_options(table, &test_table_opts);
 | 
			
		||||
    assert_true( set_test_options_for_table(table) == F_SUCCESS);
 | 
			
		||||
 | 
			
		||||
    size_t height = 0;
 | 
			
		||||
    size_t width = 0;
 | 
			
		||||
    int status = F_SUCCESS;
 | 
			
		||||
 | 
			
		||||
    WHEN("Table is empty") {
 | 
			
		||||
        status = table_geometry(table, &height, &width);
 | 
			
		||||
        assert_true( IS_SUCCESS(status) );
 | 
			
		||||
        assert_true( height == 2 );
 | 
			
		||||
        assert_true( width == 3 );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    WHEN("Table has one cell") {
 | 
			
		||||
        int n = ft_printf_ln(table, "%c", 'c');
 | 
			
		||||
        assert_true( n == 1 );
 | 
			
		||||
        status = table_geometry(table, &height, &width);
 | 
			
		||||
        assert_true( IS_SUCCESS(status) );
 | 
			
		||||
        assert_true( height == 5 );
 | 
			
		||||
        assert_true( width == 6 );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    WHEN("Inserting 3 cells in the next row") {
 | 
			
		||||
        int n = ft_printf_ln(table, "%c|%s|%c", 'c', "as", 'e');
 | 
			
		||||
        assert_true( n == 3 );
 | 
			
		||||
        status = table_geometry(table, &height, &width);
 | 
			
		||||
        assert_true( IS_SUCCESS(status) );
 | 
			
		||||
        assert_true( height == 9 );
 | 
			
		||||
        assert_true( width == 15 );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ft_destroy_table(table);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void test_table_basic(void **state)
 | 
			
		||||
{
 | 
			
		||||
    (void)state;
 | 
			
		||||
 | 
			
		||||
    FTABLE *table = NULL;
 | 
			
		||||
 | 
			
		||||
    WHEN("All columns are equal and not empty") {
 | 
			
		||||
        table = ft_create_table();
 | 
			
		||||
        assert_true( table != NULL );
 | 
			
		||||
//        ft_set_table_options(table, &test_table_opts);
 | 
			
		||||
        assert_true( set_test_options_for_table(table) == F_SUCCESS);
 | 
			
		||||
 | 
			
		||||
        ft_set_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
 | 
			
		||||
        int n = ft_printf_ln(table, "%d|%c|%s|%f", 3, 'c', "234", 3.14);
 | 
			
		||||
 | 
			
		||||
        assert_true( n == 4 );
 | 
			
		||||
        n = ft_printf_ln(table, "%d|%c|%s|%f", 3, 'c', "234", 3.14);
 | 
			
		||||
        assert_true( n == 4 );
 | 
			
		||||
        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"
 | 
			
		||||
                "| 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";
 | 
			
		||||
//        fprintf(stderr, "content:\n%s", table_str);
 | 
			
		||||
 | 
			
		||||
        assert_true( strcmp(table_str, table_str_etalon) == 0);
 | 
			
		||||
 | 
			
		||||
        ft_destroy_table(table);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    WHEN("All columns are not equal and not empty") {
 | 
			
		||||
        table = ft_create_table();
 | 
			
		||||
        assert_true( table != NULL );
 | 
			
		||||
//        ft_set_table_options(table, &test_table_opts);
 | 
			
		||||
        assert_true( set_test_options_for_table(table) == F_SUCCESS);
 | 
			
		||||
 | 
			
		||||
        ft_set_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
 | 
			
		||||
        int n = ft_printf_ln(table, "%d|%c|%s|%f", 3, 'c', "234", 3.14);
 | 
			
		||||
 | 
			
		||||
        assert_true( n == 4 );
 | 
			
		||||
        n = ft_printf_ln(table, "%c|%s|%f|%d", 'c', "234", 3.14, 3);
 | 
			
		||||
        assert_true( n == 4 );
 | 
			
		||||
        n = ft_printf_ln(table, "%s|%f|%d|%c", "234", 3.14,  3, 'c');
 | 
			
		||||
        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 |        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";
 | 
			
		||||
 | 
			
		||||
//        fprintf(stderr, "content:\n%s", table_str);
 | 
			
		||||
        assert_true( strcmp(table_str, table_str_etalon) == 0);
 | 
			
		||||
 | 
			
		||||
        ft_destroy_table(table);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    WHEN("All columns are not equal and some cells are empty") {
 | 
			
		||||
        table = ft_create_table();
 | 
			
		||||
        assert_true( table != NULL );
 | 
			
		||||
//        ft_set_table_options(table, &test_table_opts);
 | 
			
		||||
        assert_true( set_test_options_for_table(table) == F_SUCCESS);
 | 
			
		||||
 | 
			
		||||
        ft_set_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
 | 
			
		||||
        int n = ft_printf_ln(table, "||%s|%f", "234", 3.14);
 | 
			
		||||
 | 
			
		||||
        assert_true( n == 4 );
 | 
			
		||||
        n = ft_printf_ln(table, "%c|%s|%f", 'c', "234", 3.14);
 | 
			
		||||
        assert_true( n == 3 );
 | 
			
		||||
        n = ft_printf_ln(table, "%s|%f||", "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"
 | 
			
		||||
                "|     |          |      234 | 3.140000 |\n"
 | 
			
		||||
                "|     |          |          |          |\n"
 | 
			
		||||
                "+-----+----------+----------+----------+\n"
 | 
			
		||||
                "|     |          |          |          |\n"
 | 
			
		||||
                "|   c |      234 | 3.140000 |          |\n"
 | 
			
		||||
                "|     |          |          |          |\n"
 | 
			
		||||
                "+-----+----------+----------+----------+\n"
 | 
			
		||||
                "|     |          |          |          |\n"
 | 
			
		||||
                "| 234 | 3.140000 |          |          |\n"
 | 
			
		||||
                "|     |          |          |          |\n"
 | 
			
		||||
                "+-----+----------+----------+----------+\n";
 | 
			
		||||
 | 
			
		||||
//        fprintf(stderr, "content:\n%s", table_str);
 | 
			
		||||
        assert_true( strcmp(table_str, table_str_etalon) == 0);
 | 
			
		||||
 | 
			
		||||
        ft_destroy_table(table);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    WHEN("All cells are empty") {
 | 
			
		||||
        table = ft_create_table();
 | 
			
		||||
        assert_true( table != NULL );
 | 
			
		||||
//        ft_set_table_options(table, &test_table_opts);
 | 
			
		||||
        assert_true( set_test_options_for_table(table) == F_SUCCESS);
 | 
			
		||||
 | 
			
		||||
        ft_set_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
 | 
			
		||||
        int n = ft_printf_ln(table, "|||");
 | 
			
		||||
 | 
			
		||||
        assert_true( n == 4 );
 | 
			
		||||
        n = ft_printf_ln(table, "|||");
 | 
			
		||||
        assert_true( n == 4 );
 | 
			
		||||
        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"
 | 
			
		||||
                "|  |  |  |  |\n"
 | 
			
		||||
                "|  |  |  |  |\n"
 | 
			
		||||
                "+--+--+--+--+\n"
 | 
			
		||||
                "|  |  |  |  |\n"
 | 
			
		||||
                "|  |  |  |  |\n"
 | 
			
		||||
                "|  |  |  |  |\n"
 | 
			
		||||
                "+--+--+--+--+\n"
 | 
			
		||||
                "|  |  |  |  |\n"
 | 
			
		||||
                "|  |  |  |  |\n"
 | 
			
		||||
                "|  |  |  |  |\n"
 | 
			
		||||
                "+--+--+--+--+\n";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//        fprintf(stderr, "content:\n%s", table_str);
 | 
			
		||||
        assert_true( strcmp(table_str, table_str_etalon) == 0);
 | 
			
		||||
 | 
			
		||||
        ft_destroy_table(table);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
FTABLE *create_test_int_table(int set_test_opts)
 | 
			
		||||
{
 | 
			
		||||
    FTABLE *table = NULL;
 | 
			
		||||
 | 
			
		||||
    table = ft_create_table();
 | 
			
		||||
    assert_true( table != NULL );
 | 
			
		||||
    if (set_test_opts) {
 | 
			
		||||
        assert_true( set_test_options_for_table(table) == F_SUCCESS);
 | 
			
		||||
    }
 | 
			
		||||
//        ft_set_table_options(table, &test_table_opts);
 | 
			
		||||
 | 
			
		||||
    assert_true (table != NULL);
 | 
			
		||||
 | 
			
		||||
    ft_set_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
 | 
			
		||||
    int n = ft_printf_ln(table, "%d|%d|%d|%d", 3, 4, 55, 67);
 | 
			
		||||
 | 
			
		||||
    assert_true( n == 4 );
 | 
			
		||||
 | 
			
		||||
    assert(ft_write(table, "3") == F_SUCCESS);
 | 
			
		||||
    assert(ft_write(table, "4") == F_SUCCESS);
 | 
			
		||||
    assert(ft_write(table, "55") == F_SUCCESS);
 | 
			
		||||
    assert(ft_write_ln(table, "67") == F_SUCCESS);
 | 
			
		||||
 | 
			
		||||
    assert(ft_write(table, "3") == F_SUCCESS);
 | 
			
		||||
    assert(ft_write(table, "4") == F_SUCCESS);
 | 
			
		||||
    assert(ft_write(table, "55") == F_SUCCESS);
 | 
			
		||||
    assert(ft_write_ln(table, "67") == F_SUCCESS);
 | 
			
		||||
 | 
			
		||||
    return table;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void test_table_options(void **state)
 | 
			
		||||
{
 | 
			
		||||
    (void)state;
 | 
			
		||||
    FTABLE *table = NULL;
 | 
			
		||||
 | 
			
		||||
//    fort_table_options_t def_options =;
 | 
			
		||||
//    ft_get_default_options(&def_options);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    WHEN("All paddings = 1") {
 | 
			
		||||
        set_test_options_as_default();
 | 
			
		||||
 | 
			
		||||
        ft_set_default_option(FT_OPT_BOTTOM_PADDING, 1);
 | 
			
		||||
        ft_set_default_option(FT_OPT_TOP_PADDING, 1);
 | 
			
		||||
        ft_set_default_option(FT_OPT_LEFT_PADDING, 1);
 | 
			
		||||
        ft_set_default_option(FT_OPT_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";
 | 
			
		||||
//        fprintf(stderr, "content:\n%s", table_str);
 | 
			
		||||
 | 
			
		||||
        assert_true( strcmp(table_str, table_str_etalon) == 0);
 | 
			
		||||
 | 
			
		||||
        ft_destroy_table(table);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    WHEN("Separator testing") {
 | 
			
		||||
        table = create_test_int_table(1);
 | 
			
		||||
        ft_add_separator(table);
 | 
			
		||||
 | 
			
		||||
        ft_set_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, 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";
 | 
			
		||||
//        fprintf(stderr, "content:\n%s", table_str);
 | 
			
		||||
 | 
			
		||||
        assert_true( strcmp(table_str, table_str_etalon) == 0);
 | 
			
		||||
 | 
			
		||||
        ft_destroy_table(table);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    WHEN("Top and bottom padding = 0") {
 | 
			
		||||
 | 
			
		||||
        ft_set_default_option(FT_OPT_BOTTOM_PADDING, 0);
 | 
			
		||||
        ft_set_default_option(FT_OPT_TOP_PADDING, 0);
 | 
			
		||||
        ft_set_default_option(FT_OPT_LEFT_PADDING, 1);
 | 
			
		||||
        ft_set_default_option(FT_OPT_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";
 | 
			
		||||
//        fprintf(stderr, "content:\n%s", table_str);
 | 
			
		||||
 | 
			
		||||
        assert_true( strcmp(table_str, table_str_etalon) == 0);
 | 
			
		||||
 | 
			
		||||
        ft_destroy_table(table);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    WHEN("Left and right padding = 0") {
 | 
			
		||||
 | 
			
		||||
        ft_set_default_option(FT_OPT_BOTTOM_PADDING, 1);
 | 
			
		||||
        ft_set_default_option(FT_OPT_TOP_PADDING, 1);
 | 
			
		||||
        ft_set_default_option(FT_OPT_LEFT_PADDING, 0);
 | 
			
		||||
        ft_set_default_option(FT_OPT_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";
 | 
			
		||||
//        fprintf(stderr, "content:\n%s", table_str);
 | 
			
		||||
 | 
			
		||||
        assert_true( strcmp(table_str, table_str_etalon) == 0);
 | 
			
		||||
 | 
			
		||||
        ft_destroy_table(table);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    WHEN("All paddings = 0") {
 | 
			
		||||
 | 
			
		||||
        ft_set_default_option(FT_OPT_BOTTOM_PADDING, 0);
 | 
			
		||||
        ft_set_default_option(FT_OPT_TOP_PADDING, 0);
 | 
			
		||||
        ft_set_default_option(FT_OPT_LEFT_PADDING, 0);
 | 
			
		||||
        ft_set_default_option(FT_OPT_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";
 | 
			
		||||
//        fprintf(stderr, "content:\n%s", table_str);
 | 
			
		||||
 | 
			
		||||
        assert_true( strcmp(table_str, table_str_etalon) == 0);
 | 
			
		||||
 | 
			
		||||
        ft_destroy_table(table);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    WHEN("Empty string has 0 heigt") {
 | 
			
		||||
 | 
			
		||||
        ft_set_default_option(FT_OPT_BOTTOM_PADDING, 1);
 | 
			
		||||
        ft_set_default_option(FT_OPT_TOP_PADDING, 1);
 | 
			
		||||
        ft_set_default_option(FT_OPT_LEFT_PADDING, 1);
 | 
			
		||||
        ft_set_default_option(FT_OPT_RIGHT_PADDING, 1);
 | 
			
		||||
        ft_set_default_option(FT_OPT_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";
 | 
			
		||||
//        fprintf(stderr, "content:\n%s", table_str);
 | 
			
		||||
 | 
			
		||||
        assert_true( strcmp(table_str, table_str_etalon) == 0);
 | 
			
		||||
 | 
			
		||||
        ft_destroy_table(table);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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 = '#';
 | 
			
		||||
        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";
 | 
			
		||||
//        fprintf(stderr, "content:\n%s", table_str);
 | 
			
		||||
 | 
			
		||||
        assert_true( strcmp(table_str, table_str_etalon) == 0);
 | 
			
		||||
 | 
			
		||||
        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 = '#';
 | 
			
		||||
 | 
			
		||||
        ft_set_default_border_style(&brdr_style);
 | 
			
		||||
 | 
			
		||||
        ft_set_default_option(FT_OPT_BOTTOM_PADDING, 0);
 | 
			
		||||
        ft_set_default_option(FT_OPT_TOP_PADDING, 0);
 | 
			
		||||
        ft_set_default_option(FT_OPT_LEFT_PADDING, 1);
 | 
			
		||||
        ft_set_default_option(FT_OPT_RIGHT_PADDING, 1);
 | 
			
		||||
        ft_set_default_option(FT_OPT_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";
 | 
			
		||||
//        fprintf(stderr, "content:\n%s", table_str);
 | 
			
		||||
 | 
			
		||||
        assert_true( strcmp(table_str, table_str_etalon) == 0);
 | 
			
		||||
 | 
			
		||||
        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_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_BOTTOM_PADDING, 0);
 | 
			
		||||
        ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_TOP_PADDING, 0);
 | 
			
		||||
        ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_LEFT_PADDING, 0);
 | 
			
		||||
        ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_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";
 | 
			
		||||
//        fprintf(stderr, "content:\n%s", table_str);
 | 
			
		||||
 | 
			
		||||
        assert_true( strcmp(table_str, table_str_etalon) == 0);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_BOTTOM_PADDING, 1);
 | 
			
		||||
        ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_TOP_PADDING, 1);
 | 
			
		||||
        ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_LEFT_PADDING, 0);
 | 
			
		||||
        ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_RIGHT_PADDING, 0);
 | 
			
		||||
        ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_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";
 | 
			
		||||
//        fprintf(stderr, "content:\n%s", table_str);
 | 
			
		||||
        assert_true( strcmp(table_str, table_str_etalon) == 0);
 | 
			
		||||
 | 
			
		||||
        ft_destroy_table(table);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    WHEN("Set table width and column alignment") {
 | 
			
		||||
 | 
			
		||||
        set_test_options_as_default();
 | 
			
		||||
 | 
			
		||||
        table = create_test_int_table(0);
 | 
			
		||||
        int status = F_SUCCESS;
 | 
			
		||||
 | 
			
		||||
        status |= ft_set_option(table, FT_ANY_ROW, 1, FT_OPT_MIN_WIDTH, 7);
 | 
			
		||||
        status |= ft_set_option(table, FT_ANY_ROW, 1, FT_OPT_TEXT_ALIGN, LeftAligned);
 | 
			
		||||
        status |= ft_set_option(table, FT_ANY_ROW, 2, FT_OPT_MIN_WIDTH, 8);
 | 
			
		||||
        status |= ft_set_option(table, FT_ANY_ROW, 2, FT_OPT_TEXT_ALIGN, CenterAligned);
 | 
			
		||||
 | 
			
		||||
        status |= ft_set_option(table, 2, 3, FT_OPT_MIN_WIDTH, 6);
 | 
			
		||||
        status |= ft_set_option(table, 2, 3, FT_OPT_TEXT_ALIGN, LeftAligned);
 | 
			
		||||
        assert_true( status == F_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";
 | 
			
		||||
//        fprintf(stderr, "content:\n%s", table_str);
 | 
			
		||||
 | 
			
		||||
        assert_true( strcmp(table_str, table_str_etalon) == 0);
 | 
			
		||||
 | 
			
		||||
        ft_destroy_table(table);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    WHEN("Set table width and column alignment as default") {
 | 
			
		||||
 | 
			
		||||
        set_test_options_as_default();
 | 
			
		||||
 | 
			
		||||
        int status = F_SUCCESS;
 | 
			
		||||
        status |= ft_set_default_option(FT_OPT_MIN_WIDTH, 5);
 | 
			
		||||
        status |= ft_set_default_option(FT_OPT_TEXT_ALIGN, CenterAligned);
 | 
			
		||||
        assert_true( status == F_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";
 | 
			
		||||
        //        fprintf(stderr, "content:\n%s", table_str);
 | 
			
		||||
        assert_true( strcmp(table_str, table_str_etalon) == 0);
 | 
			
		||||
 | 
			
		||||
        ft_destroy_table(table);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    WHEN("All columns are equal and not empty") {
 | 
			
		||||
        set_test_options_as_default();
 | 
			
		||||
 | 
			
		||||
        table = ft_create_table();
 | 
			
		||||
 | 
			
		||||
        ft_set_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
 | 
			
		||||
        int n = ft_printf_ln(table, "%d|%c|%s|%f", 4, 'c', "234", 3.14);
 | 
			
		||||
 | 
			
		||||
        assert_true( n == 4 );
 | 
			
		||||
        n = FT_NWRITE_LN(table, "5", "c", "234\n12", "3.140000");
 | 
			
		||||
        assert_true( n == F_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";
 | 
			
		||||
//        fprintf(stderr, "content:\n%s", table_str);
 | 
			
		||||
 | 
			
		||||
        assert_true( strcmp(table_str, table_str_etalon) == 0);
 | 
			
		||||
 | 
			
		||||
        ft_destroy_table(table);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										158
									
								
								tests/test_table_basic.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										158
									
								
								tests/test_table_basic.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,158 @@
 | 
			
		||||
#include "tests.h"
 | 
			
		||||
 | 
			
		||||
void test_table_basic(void)
 | 
			
		||||
{
 | 
			
		||||
    FTABLE *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_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
 | 
			
		||||
        int n = ft_printf_ln(table, "%d|%c|%s|%f", 3, 'c', "234", 3.14);
 | 
			
		||||
 | 
			
		||||
        assert_true( n == 4 );
 | 
			
		||||
        n = ft_printf_ln(table, "%d|%c|%s|%f", 3, 'c', "234", 3.14);
 | 
			
		||||
        assert_true( n == 4 );
 | 
			
		||||
        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"
 | 
			
		||||
                "| 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";
 | 
			
		||||
//        fprintf(stderr, "content:\n%s", table_str);
 | 
			
		||||
 | 
			
		||||
        assert_true( strcmp(table_str, table_str_etalon) == 0);
 | 
			
		||||
 | 
			
		||||
        ft_destroy_table(table);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    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_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
 | 
			
		||||
        int n = ft_printf_ln(table, "%d|%c|%s|%f", 3, 'c', "234", 3.14);
 | 
			
		||||
 | 
			
		||||
        assert_true( n == 4 );
 | 
			
		||||
        n = ft_printf_ln(table, "%c|%s|%f|%d", 'c', "234", 3.14, 3);
 | 
			
		||||
        assert_true( n == 4 );
 | 
			
		||||
        n = ft_printf_ln(table, "%s|%f|%d|%c", "234", 3.14,  3, 'c');
 | 
			
		||||
        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 |        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";
 | 
			
		||||
 | 
			
		||||
//        fprintf(stderr, "content:\n%s", table_str);
 | 
			
		||||
        assert_true( strcmp(table_str, table_str_etalon) == 0);
 | 
			
		||||
 | 
			
		||||
        ft_destroy_table(table);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    WHEN("All columns are not equal and some cells are empty") {
 | 
			
		||||
        table = ft_create_table();
 | 
			
		||||
        assert_true( table != NULL );
 | 
			
		||||
//        ft_set_table_options(table, &test_table_opts);
 | 
			
		||||
        assert_true( set_test_options_for_table(table) == FT_SUCCESS);
 | 
			
		||||
 | 
			
		||||
        ft_set_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
 | 
			
		||||
        int n = ft_printf_ln(table, "||%s|%f", "234", 3.14);
 | 
			
		||||
 | 
			
		||||
        assert_true( n == 4 );
 | 
			
		||||
        n = ft_printf_ln(table, "%c|%s|%f", 'c', "234", 3.14);
 | 
			
		||||
        assert_true( n == 3 );
 | 
			
		||||
        n = ft_printf_ln(table, "%s|%f||", "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"
 | 
			
		||||
                "|     |          |      234 | 3.140000 |\n"
 | 
			
		||||
                "|     |          |          |          |\n"
 | 
			
		||||
                "+-----+----------+----------+----------+\n"
 | 
			
		||||
                "|     |          |          |          |\n"
 | 
			
		||||
                "|   c |      234 | 3.140000 |          |\n"
 | 
			
		||||
                "|     |          |          |          |\n"
 | 
			
		||||
                "+-----+----------+----------+----------+\n"
 | 
			
		||||
                "|     |          |          |          |\n"
 | 
			
		||||
                "| 234 | 3.140000 |          |          |\n"
 | 
			
		||||
                "|     |          |          |          |\n"
 | 
			
		||||
                "+-----+----------+----------+----------+\n";
 | 
			
		||||
 | 
			
		||||
//        fprintf(stderr, "content:\n%s", table_str);
 | 
			
		||||
        assert_true( strcmp(table_str, table_str_etalon) == 0);
 | 
			
		||||
 | 
			
		||||
        ft_destroy_table(table);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
 | 
			
		||||
        int n = ft_printf_ln(table, "|||");
 | 
			
		||||
 | 
			
		||||
        assert_true( n == 4 );
 | 
			
		||||
        n = ft_printf_ln(table, "|||");
 | 
			
		||||
        assert_true( n == 4 );
 | 
			
		||||
        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"
 | 
			
		||||
                "|  |  |  |  |\n"
 | 
			
		||||
                "|  |  |  |  |\n"
 | 
			
		||||
                "+--+--+--+--+\n"
 | 
			
		||||
                "|  |  |  |  |\n"
 | 
			
		||||
                "|  |  |  |  |\n"
 | 
			
		||||
                "|  |  |  |  |\n"
 | 
			
		||||
                "+--+--+--+--+\n"
 | 
			
		||||
                "|  |  |  |  |\n"
 | 
			
		||||
                "|  |  |  |  |\n"
 | 
			
		||||
                "|  |  |  |  |\n"
 | 
			
		||||
                "+--+--+--+--+\n";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//        fprintf(stderr, "content:\n%s", table_str);
 | 
			
		||||
        assert_true( strcmp(table_str, table_str_etalon) == 0);
 | 
			
		||||
 | 
			
		||||
        ft_destroy_table(table);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										144
									
								
								tests/test_table_border_style.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										144
									
								
								tests/test_table_border_style.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,144 @@
 | 
			
		||||
#include "tests.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void test_table_border_style(void)
 | 
			
		||||
{
 | 
			
		||||
    FTABLE *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 = '#';
 | 
			
		||||
        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";
 | 
			
		||||
//        fprintf(stderr, "content:\n%s", table_str);
 | 
			
		||||
 | 
			
		||||
        assert_true( strcmp(table_str, table_str_etalon) == 0);
 | 
			
		||||
 | 
			
		||||
        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 = '#';
 | 
			
		||||
 | 
			
		||||
        ft_set_default_border_style(&brdr_style);
 | 
			
		||||
 | 
			
		||||
        ft_set_default_option(FT_OPT_BOTTOM_PADDING, 0);
 | 
			
		||||
        ft_set_default_option(FT_OPT_TOP_PADDING, 0);
 | 
			
		||||
        ft_set_default_option(FT_OPT_LEFT_PADDING, 1);
 | 
			
		||||
        ft_set_default_option(FT_OPT_RIGHT_PADDING, 1);
 | 
			
		||||
        ft_set_default_option(FT_OPT_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";
 | 
			
		||||
//        fprintf(stderr, "content:\n%s", table_str);
 | 
			
		||||
 | 
			
		||||
        assert_true( strcmp(table_str, table_str_etalon) == 0);
 | 
			
		||||
 | 
			
		||||
        ft_destroy_table(table);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    WHEN("Separator testing") {
 | 
			
		||||
        table = create_test_int_table(1);
 | 
			
		||||
        ft_add_separator(table);
 | 
			
		||||
 | 
			
		||||
        ft_set_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, 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";
 | 
			
		||||
//        fprintf(stderr, "content:\n%s", table_str);
 | 
			
		||||
 | 
			
		||||
        assert_true( strcmp(table_str, table_str_etalon) == 0);
 | 
			
		||||
 | 
			
		||||
        ft_destroy_table(table);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										90
									
								
								tests/test_table_geometry.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										90
									
								
								tests/test_table_geometry.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,90 @@
 | 
			
		||||
#include "tests.h"
 | 
			
		||||
#include "table.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void test_table_sizes(void)
 | 
			
		||||
{
 | 
			
		||||
    FTABLE *table = ft_create_table();
 | 
			
		||||
    assert_true( table != NULL );
 | 
			
		||||
    assert_true( set_test_options_for_table(table) == FT_SUCCESS);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    size_t rows = 0;
 | 
			
		||||
    size_t cols = 0;
 | 
			
		||||
    int status = FT_SUCCESS;
 | 
			
		||||
 | 
			
		||||
    WHEN("Table is empty") {
 | 
			
		||||
        status = get_table_sizes(table, &rows, &cols);
 | 
			
		||||
        assert_true( IS_SUCCESS(status) );
 | 
			
		||||
        assert_true( rows == 0 );
 | 
			
		||||
        assert_true( cols == 0 );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    WHEN("Insert one cell") {
 | 
			
		||||
        int n = ft_printf_ln(table, "%c", 'c');
 | 
			
		||||
        assert_true( n == 1 );
 | 
			
		||||
        status = get_table_sizes(table, &rows, &cols);
 | 
			
		||||
        assert_true( IS_SUCCESS(status) );
 | 
			
		||||
        assert_true( rows == 1 );
 | 
			
		||||
        assert_true( cols == 1 );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    WHEN("Insert two cells in the next row") {
 | 
			
		||||
        int n = ft_printf_ln(table, "%c|%c", 'c', 'd');
 | 
			
		||||
        assert_true( n == 2 );
 | 
			
		||||
        status = get_table_sizes(table, &rows, &cols);
 | 
			
		||||
        assert_true( IS_SUCCESS(status) );
 | 
			
		||||
        assert_true( rows == 2 );
 | 
			
		||||
        assert_true( cols == 2 );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    WHEN("Insert five cells in the next row") {
 | 
			
		||||
        int n = ft_printf_ln(table, "%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) );
 | 
			
		||||
        assert_true( rows == 3 );
 | 
			
		||||
        assert_true( cols == 5 );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ft_destroy_table(table);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void test_table_geometry(void)
 | 
			
		||||
{
 | 
			
		||||
    FTABLE *table = ft_create_table();
 | 
			
		||||
    assert_true( table != NULL );
 | 
			
		||||
    assert_true( set_test_options_for_table(table) == FT_SUCCESS);
 | 
			
		||||
 | 
			
		||||
    size_t height = 0;
 | 
			
		||||
    size_t width = 0;
 | 
			
		||||
    int status = FT_SUCCESS;
 | 
			
		||||
 | 
			
		||||
    WHEN("Table is empty") {
 | 
			
		||||
        status = table_geometry(table, &height, &width);
 | 
			
		||||
        assert_true( IS_SUCCESS(status) );
 | 
			
		||||
        assert_true( height == 2 );
 | 
			
		||||
        assert_true( width == 3 );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    WHEN("Table has one cell") {
 | 
			
		||||
        int n = ft_printf_ln(table, "%c", 'c');
 | 
			
		||||
        assert_true( n == 1 );
 | 
			
		||||
        status = table_geometry(table, &height, &width);
 | 
			
		||||
        assert_true( IS_SUCCESS(status) );
 | 
			
		||||
        assert_true( height == 5 );
 | 
			
		||||
        assert_true( width == 6 );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    WHEN("Inserting 3 cells in the next row") {
 | 
			
		||||
        int n = ft_printf_ln(table, "%c|%s|%c", 'c', "as", 'e');
 | 
			
		||||
        assert_true( n == 3 );
 | 
			
		||||
        status = table_geometry(table, &height, &width);
 | 
			
		||||
        assert_true( IS_SUCCESS(status) );
 | 
			
		||||
        assert_true( height == 9 );
 | 
			
		||||
        assert_true( width == 15 );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ft_destroy_table(table);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										344
									
								
								tests/test_table_options.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										344
									
								
								tests/test_table_options.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,344 @@
 | 
			
		||||
//#define FT_EXTERN static
 | 
			
		||||
#include "tests.h"
 | 
			
		||||
#include "fort.h"
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include "options.h"
 | 
			
		||||
#include "vector.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void test_table_options(void)
 | 
			
		||||
{
 | 
			
		||||
    FTABLE *table = NULL;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    WHEN("All paddings = 1") {
 | 
			
		||||
        set_test_options_as_default();
 | 
			
		||||
 | 
			
		||||
        ft_set_default_option(FT_OPT_BOTTOM_PADDING, 1);
 | 
			
		||||
        ft_set_default_option(FT_OPT_TOP_PADDING, 1);
 | 
			
		||||
        ft_set_default_option(FT_OPT_LEFT_PADDING, 1);
 | 
			
		||||
        ft_set_default_option(FT_OPT_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";
 | 
			
		||||
//        fprintf(stderr, "content:\n%s", table_str);
 | 
			
		||||
 | 
			
		||||
        assert_true( strcmp(table_str, table_str_etalon) == 0);
 | 
			
		||||
 | 
			
		||||
        ft_destroy_table(table);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    WHEN("Top and bottom padding = 0") {
 | 
			
		||||
 | 
			
		||||
        ft_set_default_option(FT_OPT_BOTTOM_PADDING, 0);
 | 
			
		||||
        ft_set_default_option(FT_OPT_TOP_PADDING, 0);
 | 
			
		||||
        ft_set_default_option(FT_OPT_LEFT_PADDING, 1);
 | 
			
		||||
        ft_set_default_option(FT_OPT_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";
 | 
			
		||||
//        fprintf(stderr, "content:\n%s", table_str);
 | 
			
		||||
 | 
			
		||||
        assert_true( strcmp(table_str, table_str_etalon) == 0);
 | 
			
		||||
 | 
			
		||||
        ft_destroy_table(table);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    WHEN("Left and right padding = 0") {
 | 
			
		||||
 | 
			
		||||
        ft_set_default_option(FT_OPT_BOTTOM_PADDING, 1);
 | 
			
		||||
        ft_set_default_option(FT_OPT_TOP_PADDING, 1);
 | 
			
		||||
        ft_set_default_option(FT_OPT_LEFT_PADDING, 0);
 | 
			
		||||
        ft_set_default_option(FT_OPT_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";
 | 
			
		||||
//        fprintf(stderr, "content:\n%s", table_str);
 | 
			
		||||
 | 
			
		||||
        assert_true( strcmp(table_str, table_str_etalon) == 0);
 | 
			
		||||
 | 
			
		||||
        ft_destroy_table(table);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    WHEN("All paddings = 0") {
 | 
			
		||||
 | 
			
		||||
        ft_set_default_option(FT_OPT_BOTTOM_PADDING, 0);
 | 
			
		||||
        ft_set_default_option(FT_OPT_TOP_PADDING, 0);
 | 
			
		||||
        ft_set_default_option(FT_OPT_LEFT_PADDING, 0);
 | 
			
		||||
        ft_set_default_option(FT_OPT_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";
 | 
			
		||||
//        fprintf(stderr, "content:\n%s", table_str);
 | 
			
		||||
 | 
			
		||||
        assert_true( strcmp(table_str, table_str_etalon) == 0);
 | 
			
		||||
 | 
			
		||||
        ft_destroy_table(table);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    WHEN("Empty string has 0 heigt") {
 | 
			
		||||
 | 
			
		||||
        ft_set_default_option(FT_OPT_BOTTOM_PADDING, 1);
 | 
			
		||||
        ft_set_default_option(FT_OPT_TOP_PADDING, 1);
 | 
			
		||||
        ft_set_default_option(FT_OPT_LEFT_PADDING, 1);
 | 
			
		||||
        ft_set_default_option(FT_OPT_RIGHT_PADDING, 1);
 | 
			
		||||
        ft_set_default_option(FT_OPT_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";
 | 
			
		||||
//        fprintf(stderr, "content:\n%s", table_str);
 | 
			
		||||
 | 
			
		||||
        assert_true( strcmp(table_str, table_str_etalon) == 0);
 | 
			
		||||
 | 
			
		||||
        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_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_BOTTOM_PADDING, 0);
 | 
			
		||||
        ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_TOP_PADDING, 0);
 | 
			
		||||
        ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_LEFT_PADDING, 0);
 | 
			
		||||
        ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_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";
 | 
			
		||||
//        fprintf(stderr, "content:\n%s", table_str);
 | 
			
		||||
 | 
			
		||||
        assert_true( strcmp(table_str, table_str_etalon) == 0);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_BOTTOM_PADDING, 1);
 | 
			
		||||
        ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_TOP_PADDING, 1);
 | 
			
		||||
        ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_LEFT_PADDING, 0);
 | 
			
		||||
        ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_RIGHT_PADDING, 0);
 | 
			
		||||
        ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_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";
 | 
			
		||||
//        fprintf(stderr, "content:\n%s", table_str);
 | 
			
		||||
        assert_true( strcmp(table_str, table_str_etalon) == 0);
 | 
			
		||||
 | 
			
		||||
        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_option(table, FT_ANY_ROW, 1, FT_OPT_MIN_WIDTH, 7);
 | 
			
		||||
        status |= ft_set_option(table, FT_ANY_ROW, 1, FT_OPT_TEXT_ALIGN, LeftAligned);
 | 
			
		||||
        status |= ft_set_option(table, FT_ANY_ROW, 2, FT_OPT_MIN_WIDTH, 8);
 | 
			
		||||
        status |= ft_set_option(table, FT_ANY_ROW, 2, FT_OPT_TEXT_ALIGN, CenterAligned);
 | 
			
		||||
 | 
			
		||||
        status |= ft_set_option(table, 2, 3, FT_OPT_MIN_WIDTH, 6);
 | 
			
		||||
        status |= ft_set_option(table, 2, 3, FT_OPT_TEXT_ALIGN, LeftAligned);
 | 
			
		||||
        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";
 | 
			
		||||
//        fprintf(stderr, "content:\n%s", table_str);
 | 
			
		||||
 | 
			
		||||
        assert_true( strcmp(table_str, table_str_etalon) == 0);
 | 
			
		||||
 | 
			
		||||
        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_option(FT_OPT_MIN_WIDTH, 5);
 | 
			
		||||
        status |= ft_set_default_option(FT_OPT_TEXT_ALIGN, CenterAligned);
 | 
			
		||||
        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";
 | 
			
		||||
        //        fprintf(stderr, "content:\n%s", table_str);
 | 
			
		||||
        assert_true( strcmp(table_str, table_str_etalon) == 0);
 | 
			
		||||
 | 
			
		||||
        ft_destroy_table(table);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    WHEN("All columns are equal and not empty") {
 | 
			
		||||
        set_test_options_as_default();
 | 
			
		||||
 | 
			
		||||
        table = ft_create_table();
 | 
			
		||||
 | 
			
		||||
        ft_set_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
 | 
			
		||||
        int n = ft_printf_ln(table, "%d|%c|%s|%f", 4, 'c', "234", 3.14);
 | 
			
		||||
 | 
			
		||||
        assert_true( n == 4 );
 | 
			
		||||
        n = FT_NWRITE_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";
 | 
			
		||||
//        fprintf(stderr, "content:\n%s", table_str);
 | 
			
		||||
 | 
			
		||||
        assert_true( strcmp(table_str, table_str_etalon) == 0);
 | 
			
		||||
 | 
			
		||||
        ft_destroy_table(table);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										103
									
								
								tests/test_utility.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										103
									
								
								tests/test_utility.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,103 @@
 | 
			
		||||
#include "tests.h"
 | 
			
		||||
#include "fort.h"
 | 
			
		||||
 | 
			
		||||
int set_test_options_for_table(FTABLE *table)
 | 
			
		||||
{
 | 
			
		||||
    assert(table);
 | 
			
		||||
    int status = FT_SUCCESS;
 | 
			
		||||
    status |= ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_BOTTOM_PADDING, 1);
 | 
			
		||||
    status |= ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_TOP_PADDING, 1);
 | 
			
		||||
    status |= ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_LEFT_PADDING, 1);
 | 
			
		||||
    status |= ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_RIGHT_PADDING, 1);
 | 
			
		||||
    status |= ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_EMPTY_STR_HEIGHT, 1);
 | 
			
		||||
 | 
			
		||||
    assert_true( status == FT_SUCCESS );
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    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 = '|';
 | 
			
		||||
    brdr_style.header_border_chs.out_intersect_ch = '+';
 | 
			
		||||
    brdr_style.header_border_chs.in_intersect_ch = '+';
 | 
			
		||||
 | 
			
		||||
    brdr_style.hor_separator_char = '=';
 | 
			
		||||
    return ft_set_border_style(table, &brdr_style);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int set_test_options_as_default()
 | 
			
		||||
{
 | 
			
		||||
    int status = FT_SUCCESS;
 | 
			
		||||
 | 
			
		||||
    status |= ft_set_default_option(FT_OPT_MIN_WIDTH, 0);
 | 
			
		||||
    status |= ft_set_default_option(FT_OPT_TEXT_ALIGN, RightAligned);
 | 
			
		||||
 | 
			
		||||
    status |= ft_set_default_option(FT_OPT_BOTTOM_PADDING, 1);
 | 
			
		||||
    status |= ft_set_default_option(FT_OPT_TOP_PADDING, 1);
 | 
			
		||||
    status |= ft_set_default_option(FT_OPT_LEFT_PADDING, 1);
 | 
			
		||||
    status |= ft_set_default_option(FT_OPT_RIGHT_PADDING, 1);
 | 
			
		||||
    status |= ft_set_default_option(FT_OPT_EMPTY_STR_HEIGHT, 1);
 | 
			
		||||
 | 
			
		||||
    assert_true( status == FT_SUCCESS );
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    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 = '|';
 | 
			
		||||
    brdr_style.header_border_chs.out_intersect_ch = '+';
 | 
			
		||||
    brdr_style.header_border_chs.in_intersect_ch = '+';
 | 
			
		||||
 | 
			
		||||
    brdr_style.hor_separator_char = '=';
 | 
			
		||||
 | 
			
		||||
    return ft_set_default_border_style(&brdr_style);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
FTABLE *create_test_int_table(int set_test_opts)
 | 
			
		||||
{
 | 
			
		||||
    FTABLE *table = NULL;
 | 
			
		||||
 | 
			
		||||
    table = ft_create_table();
 | 
			
		||||
    assert_true( table != NULL );
 | 
			
		||||
    if (set_test_opts) {
 | 
			
		||||
        assert_true( set_test_options_for_table(table) == FT_SUCCESS);
 | 
			
		||||
    }
 | 
			
		||||
//        ft_set_table_options(table, &test_table_opts);
 | 
			
		||||
 | 
			
		||||
    assert_true (table != NULL);
 | 
			
		||||
 | 
			
		||||
    ft_set_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
 | 
			
		||||
    int n = ft_printf_ln(table, "%d|%d|%d|%d", 3, 4, 55, 67);
 | 
			
		||||
 | 
			
		||||
    assert_true( n == 4 );
 | 
			
		||||
 | 
			
		||||
    assert(ft_write(table, "3") == FT_SUCCESS);
 | 
			
		||||
    assert(ft_write(table, "4") == FT_SUCCESS);
 | 
			
		||||
    assert(ft_write(table, "55") == FT_SUCCESS);
 | 
			
		||||
    assert(ft_write_ln(table, "67") == FT_SUCCESS);
 | 
			
		||||
 | 
			
		||||
    assert(ft_write(table, "3") == FT_SUCCESS);
 | 
			
		||||
    assert(ft_write(table, "4") == FT_SUCCESS);
 | 
			
		||||
    assert(ft_write(table, "55") == FT_SUCCESS);
 | 
			
		||||
    assert(ft_write_ln(table, "67") == FT_SUCCESS);
 | 
			
		||||
 | 
			
		||||
    return table;
 | 
			
		||||
}
 | 
			
		||||
@@ -4,9 +4,8 @@
 | 
			
		||||
//#include "../src/fort.c"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void test_vector_basic(void **state)
 | 
			
		||||
void test_vector_basic(void)
 | 
			
		||||
{
 | 
			
		||||
    (void)state;
 | 
			
		||||
    size_t i = 0;
 | 
			
		||||
 | 
			
		||||
    typedef short item_t;
 | 
			
		||||
@@ -64,10 +63,10 @@ void test_vector_basic(void **state)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        WHEN("Erasing items") {
 | 
			
		||||
            assert_true( vector_erase(vector, 20) != F_SUCCESS );
 | 
			
		||||
            assert_true( vector_erase(vector, 20) != FT_SUCCESS );
 | 
			
		||||
 | 
			
		||||
            assert_true( vector_erase(vector,  0) == F_SUCCESS );
 | 
			
		||||
            assert_true( vector_erase(vector, 10) == F_SUCCESS );
 | 
			
		||||
            assert_true( vector_erase(vector,  0) == FT_SUCCESS );
 | 
			
		||||
            assert_true( vector_erase(vector, 10) == FT_SUCCESS );
 | 
			
		||||
 | 
			
		||||
            item_t first_item = *(item_t*)vector_at(vector, 0);
 | 
			
		||||
            assert_true( first_item == 2 );
 | 
			
		||||
 
 | 
			
		||||
@@ -4,25 +4,37 @@
 | 
			
		||||
#include <stdarg.h>
 | 
			
		||||
#include <stddef.h>
 | 
			
		||||
#include <setjmp.h>
 | 
			
		||||
#include "fort_impl.h"
 | 
			
		||||
#include <assert.h>
 | 
			
		||||
 | 
			
		||||
#define WHEN(...)
 | 
			
		||||
#define THEN(...)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void test_vector_basic(void **state);
 | 
			
		||||
 | 
			
		||||
void test_table_sizes(void **state);
 | 
			
		||||
void test_table_geometry(void **state);
 | 
			
		||||
void test_table_basic(void **state);
 | 
			
		||||
void test_table_options(void **state);
 | 
			
		||||
void test_string_buffer(void **state);
 | 
			
		||||
/* Test cases */
 | 
			
		||||
void test_vector_basic(void);
 | 
			
		||||
void test_string_buffer(void);
 | 
			
		||||
void test_table_sizes(void);
 | 
			
		||||
void test_table_geometry(void);
 | 
			
		||||
void test_table_basic(void);
 | 
			
		||||
void test_table_border_style(void);
 | 
			
		||||
void test_table_options(void);
 | 
			
		||||
 | 
			
		||||
struct test_case
 | 
			
		||||
{
 | 
			
		||||
    char name [128];
 | 
			
		||||
    void (*test)(void **);
 | 
			
		||||
    void (*test)(void);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 *  Test utility funcitons
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#define assert_true(args) assert(args)
 | 
			
		||||
 | 
			
		||||
int set_test_options_for_table(FTABLE *table);
 | 
			
		||||
int set_test_options_as_default();
 | 
			
		||||
FTABLE *create_test_int_table(int set_test_opts);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif // TESTS_H
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user