[C] Reorganised tests

This commit is contained in:
seleznevae 2018-11-24 23:14:26 +03:00
parent e4cba07b55
commit 64abbfd41b
15 changed files with 130 additions and 51 deletions

View File

@ -79,7 +79,7 @@ endif("${FORT_COMPILER}" STREQUAL "MSVC")
# Sources and executables # Sources and executables
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
FILE(GLOB_RECURSE FortHeaders "lib/*.h" "lib/*.hpp" "tests/*.h" "src/*.h") FILE(GLOB_RECURSE FortHeaders "lib/*.h" "lib/*.hpp" "tests/*.h" "tests/*.hpp" "src/*.h")
add_custom_target(headers SOURCES ${FortHeaders}) add_custom_target(headers SOURCES ${FortHeaders})
@ -118,6 +118,7 @@ set(TEST_SOURCES_DEV
tests/bb_tests/test_table_border_style.c tests/bb_tests/test_table_border_style.c
tests/bb_tests/test_table_properties.c tests/bb_tests/test_table_properties.c
tests/bb_tests/test_memory_errors.c tests/bb_tests/test_memory_errors.c
tests/tests.c
tests/test_utils.c) tests/test_utils.c)
add_executable(${PROJECT_NAME}_test_dev add_executable(${PROJECT_NAME}_test_dev
${FORT_DEV_SOURCES} ${FORT_DEV_SOURCES}
@ -132,6 +133,7 @@ set(TEST_SOURCES
tests/bb_tests/test_table_border_style.c tests/bb_tests/test_table_border_style.c
tests/bb_tests/test_table_properties.c tests/bb_tests/test_table_properties.c
tests/bb_tests/test_memory_errors.c tests/bb_tests/test_memory_errors.c
tests/tests.c
tests/test_utils.c) tests/test_utils.c)
add_executable(${PROJECT_NAME}_test add_executable(${PROJECT_NAME}_test
lib/fort.c lib/fort.c
@ -142,7 +144,7 @@ set(TEST_SOURCES_CPP
tests/main_test_cpp.cpp tests/main_test_cpp.cpp
tests/bb_tests_cpp/test_table_basic.cpp tests/bb_tests_cpp/test_table_basic.cpp
tests/bb_tests_cpp/test_table_properties.cpp tests/bb_tests_cpp/test_table_properties.cpp
tests/test_utils.c tests/tests.c
tests/test_utils.cpp) tests/test_utils.cpp)
add_executable(${PROJECT_NAME}_test_cpp add_executable(${PROJECT_NAME}_test_cpp
lib/fort.c lib/fort.c
@ -188,7 +190,7 @@ if("${FORT_COMPILER}" STREQUAL "GNU" OR "${FORT_COMPILER}" STREQUAL "Clang")
target_link_libraries(${PROJECT_NAME}_example_cpp ubsan) target_link_libraries(${PROJECT_NAME}_example_cpp ubsan)
target_link_libraries(${PROJECT_NAME}_test ubsan) target_link_libraries(${PROJECT_NAME}_test ubsan)
endif("${FORT_COMPILER}" STREQUAL "GNU") endif("${FORT_COMPILER}" STREQUAL "GNU")
endif("${FORT_COMPILER}" STREQUAL "ubsan") endif(FORT_BUILD_TYPE STREQUAL "ubsan")
#coveralls case #coveralls case
if(FORT_BUILD_TYPE STREQUAL "coveralls") if(FORT_BUILD_TYPE STREQUAL "coveralls")
@ -252,6 +254,7 @@ if(FORT_ENABLE_ASTYLE)
${CMAKE_SOURCE_DIR}/src/*.c ${CMAKE_SOURCE_DIR}/src/*.c
${CMAKE_SOURCE_DIR}/tests/*.c ${CMAKE_SOURCE_DIR}/tests/*.c
${CMAKE_SOURCE_DIR}/tests/*.h ${CMAKE_SOURCE_DIR}/tests/*.h
${CMAKE_SOURCE_DIR}/tests/*.hpp
${CMAKE_SOURCE_DIR}/tests/bb_tests/*.c ${CMAKE_SOURCE_DIR}/tests/bb_tests/*.c
${CMAKE_SOURCE_DIR}/tests/wb_tests/*.c ${CMAKE_SOURCE_DIR}/tests/wb_tests/*.c
${CMAKE_SOURCE_DIR}/tests/bb_tests_cpp/*.cpp ${CMAKE_SOURCE_DIR}/tests/bb_tests_cpp/*.cpp

View File

@ -1,4 +1,5 @@
#include "tests.h" #include "tests.h"
#include "test_utils.h"
#include <wchar.h> #include <wchar.h>
#include "fort.h" #include "fort.h"

View File

@ -1,5 +1,6 @@
#include "tests.h" #include "tests.h"
#include "fort.h" #include "fort.h"
#include "test_utils.h"

View File

@ -5,6 +5,7 @@
#include <stdio.h> #include <stdio.h>
#include "properties.h" #include "properties.h"
#include "vector.h" #include "vector.h"
#include "test_utils.h"

View File

@ -1,6 +1,6 @@
#include "tests.h" #include "tests.h"
#include "fort.hpp" #include "fort.hpp"
#include "test_utils.hpp"
void test_cpp_table_basic(void) void test_cpp_table_basic(void)
{ {

View File

@ -1,5 +1,6 @@
#include "tests.h" #include "tests.h"
#include "fort.hpp" #include "fort.hpp"
#include "test_utils.hpp"
void test_cpp_table_tbl_properties(void) void test_cpp_table_tbl_properties(void)

View File

@ -2,6 +2,26 @@
#include <stdio.h> #include <stdio.h>
#include "fort.h" #include "fort.h"
/* Test cases */
void test_vector_basic(void);
void test_vector_stress(void);
void test_string_buffer(void);
void test_table_sizes(void);
void test_table_geometry(void);
void test_table_basic(void);
void test_table_copy(void);
#ifdef FT_HAVE_WCHAR
void test_wcs_table_boundaries(void);
#endif
void test_table_write(void);
void test_table_border_style(void);
void test_table_builtin_border_styles(void);
void test_table_cell_properties(void);
void test_table_text_styles(void);
void test_table_tbl_properties(void);
void test_memory_errors(void);
#ifdef FORT_WB_TESTING_ENABLED #ifdef FORT_WB_TESTING_ENABLED
struct test_case wb_test_suit [] = { struct test_case wb_test_suit [] = {
{"test_vector_basic", test_vector_basic}, {"test_vector_basic", test_vector_basic},

View File

@ -2,6 +2,7 @@
#include <stdio.h> #include <stdio.h>
#include "fort.h" #include "fort.h"
/* Test cases */
void test_cpp_table_basic(void); void test_cpp_table_basic(void);
void test_cpp_table_write(void); void test_cpp_table_write(void);
void test_cpp_table_tbl_properties(void); void test_cpp_table_tbl_properties(void);

View File

@ -1,4 +1,5 @@
#include "tests.h" #include "tests.h"
#include "test_utils.h"
#include "fort.h" #include "fort.h"
int set_test_props_for_table(struct ft_table *table) int set_test_props_for_table(struct ft_table *table)
@ -132,19 +133,19 @@ struct ft_table *create_test_int_wtable(int set_test_opts)
#endif #endif
void run_test_suit(const char *test_suit_name, int n_tests, struct test_case test_suit[]) //void run_test_suit(const char *test_suit_name, int n_tests, struct test_case test_suit[])
{ //{
fprintf(stderr, " == RUNNING %s ==\n", test_suit_name); // fprintf(stderr, " == RUNNING %s ==\n", test_suit_name);
fprintf(stderr, "[==========] Running %d test(s).\n", n_tests); // fprintf(stderr, "[==========] Running %d test(s).\n", n_tests);
int i; // int i;
for (i = 0; i < n_tests; ++i) { // for (i = 0; i < n_tests; ++i) {
fprintf(stderr, "[ RUN ] %s\n", test_suit[i].name); // fprintf(stderr, "[ RUN ] %s\n", test_suit[i].name);
test_suit[i].test(); // test_suit[i].test();
fprintf(stderr, "[ OK ] %s\n", test_suit[i].name); // fprintf(stderr, "[ OK ] %s\n", test_suit[i].name);
} // }
fprintf(stderr, "[==========] %d test(s) run.\n", n_tests); // fprintf(stderr, "[==========] %d test(s) run.\n", n_tests);
fprintf(stderr, "[ PASSED ] %d test(s).\n", n_tests); // fprintf(stderr, "[ PASSED ] %d test(s).\n", n_tests);
} //}

View File

@ -48,3 +48,39 @@ fort::table create_cpp_test_int_table(int set_test_opts)
return table; return table;
} }
int set_test_properties_as_default(void)
{
bool status = true;
status = status && fort::table::default_props().set_cell_min_width(0);
status = status && fort::table::default_props().set_cell_text_align(fort::text_align::right);
status = status && fort::table::default_props().set_cell_bottom_padding(1);
status = status && fort::table::default_props().set_cell_top_padding(1);
status = status && fort::table::default_props().set_cell_left_padding(1);
status = status && fort::table::default_props().set_cell_right_padding(1);
status = status && fort::table::default_props().set_cell_empty_str_height(1);
assert_true(status == true);
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 fort::set_default_border_style(&brdr_style);
}

11
tests/test_utils.h Normal file
View File

@ -0,0 +1,11 @@
#ifndef TEST_UTILS_H
#define TEST_UTILS_H
struct ft_table;
int set_test_props_for_table(struct ft_table *table);
int set_test_properties_as_default(void);
struct ft_table *create_test_int_table(int set_test_opts);
struct ft_table *create_test_int_wtable(int set_test_opts);
#endif // TEST_UTILS_H

16
tests/test_utils.hpp Normal file
View File

@ -0,0 +1,16 @@
#ifndef TEST_UTILS_HPP
#define TEST_UTILS_HPP
namespace fort
{
class table;
}
int set_test_properties_as_default(void);
bool set_cpp_test_props_for_table(fort::table *table);
fort::table create_cpp_test_int_table(int set_test_opts);
#endif // TEST_UTILS_HPP

16
tests/tests.c Normal file
View File

@ -0,0 +1,16 @@
#include "tests.h"
void run_test_suit(const char *test_suit_name, int n_tests, struct test_case test_suit[])
{
fprintf(stderr, " == RUNNING %s ==\n", test_suit_name);
fprintf(stderr, "[==========] Running %d test(s).\n", n_tests);
int i;
for (i = 0; i < n_tests; ++i) {
fprintf(stderr, "[ RUN ] %s\n", test_suit[i].name);
test_suit[i].test();
fprintf(stderr, "[ OK ] %s\n", test_suit[i].name);
}
fprintf(stderr, "[==========] %d test(s) run.\n", n_tests);
fprintf(stderr, "[ PASSED ] %d test(s).\n", n_tests);
}

View File

@ -18,25 +18,6 @@
#define FT_HAVE_WCHAR #define FT_HAVE_WCHAR
#endif #endif
/* Test cases */
void test_vector_basic(void);
void test_vector_stress(void);
void test_string_buffer(void);
void test_table_sizes(void);
void test_table_geometry(void);
void test_table_basic(void);
void test_table_copy(void);
#ifdef FT_HAVE_WCHAR
void test_wcs_table_boundaries(void);
#endif
void test_table_write(void);
void test_table_border_style(void);
void test_table_builtin_border_styles(void);
void test_table_cell_properties(void);
void test_table_text_styles(void);
void test_table_tbl_properties(void);
void test_memory_errors(void);
struct test_case { struct test_case {
char name [128]; char name [128];
void (*test)(void); void (*test)(void);
@ -68,28 +49,17 @@ struct test_case {
exit(EXIT_FAILURE); \ exit(EXIT_FAILURE); \
} }
struct ft_table; #define assert_string_equal(str1, str2) assert_str_equal(str1.c_str(), str2.c_str())
#ifdef __cplusplus #ifdef __cplusplus
#define assert_string_equal(str1, str2) assert_str_equal(str1.c_str(), str2.c_str())
namespace fort
{
class table;
}
bool set_cpp_test_props_for_table(fort::table *table);
fort::table create_cpp_test_int_table(int set_test_opts);
extern "C" { extern "C" {
#endif #endif
int set_test_props_for_table(struct ft_table *table);
int set_test_properties_as_default(void);
struct ft_table *create_test_int_table(int set_test_opts);
struct ft_table *create_test_int_wtable(int set_test_opts);
void run_test_suit(const char *test_suit_name, int n_tests, struct test_case test_suit[]); void run_test_suit(const char *test_suit_name, int n_tests, struct test_case test_suit[]);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif // TESTS_H #endif // TESTS_H

View File

@ -1,5 +1,6 @@
#include "tests.h" #include "tests.h"
#include "table.h" #include "table.h"
#include "test_utils.h"
void test_table_sizes(void) void test_table_sizes(void)
{ {