From 64abbfd41bebc92a584644247a0857811160c885 Mon Sep 17 00:00:00 2001 From: seleznevae Date: Sat, 24 Nov 2018 23:14:26 +0300 Subject: [PATCH] [C] Reorganised tests --- CMakeLists.txt | 9 +++-- tests/bb_tests/test_table_basic.c | 1 + tests/bb_tests/test_table_border_style.c | 1 + tests/bb_tests/test_table_properties.c | 1 + tests/bb_tests_cpp/test_table_basic.cpp | 2 +- tests/bb_tests_cpp/test_table_properties.cpp | 1 + tests/main_test.c | 20 +++++++++++ tests/main_test_cpp.cpp | 1 + tests/test_utils.c | 27 +++++++------- tests/test_utils.cpp | 36 +++++++++++++++++++ tests/test_utils.h | 11 ++++++ tests/test_utils.hpp | 16 +++++++++ tests/tests.c | 16 +++++++++ tests/tests.h | 38 +++----------------- tests/wb_tests/test_table_geometry.c | 1 + 15 files changed, 130 insertions(+), 51 deletions(-) create mode 100644 tests/test_utils.h create mode 100644 tests/test_utils.hpp create mode 100644 tests/tests.c diff --git a/CMakeLists.txt b/CMakeLists.txt index f8c34e1..de90dc9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,7 +79,7 @@ endif("${FORT_COMPILER}" STREQUAL "MSVC") # 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}) @@ -118,6 +118,7 @@ set(TEST_SOURCES_DEV tests/bb_tests/test_table_border_style.c tests/bb_tests/test_table_properties.c tests/bb_tests/test_memory_errors.c + tests/tests.c tests/test_utils.c) add_executable(${PROJECT_NAME}_test_dev ${FORT_DEV_SOURCES} @@ -132,6 +133,7 @@ set(TEST_SOURCES tests/bb_tests/test_table_border_style.c tests/bb_tests/test_table_properties.c tests/bb_tests/test_memory_errors.c + tests/tests.c tests/test_utils.c) add_executable(${PROJECT_NAME}_test lib/fort.c @@ -142,7 +144,7 @@ set(TEST_SOURCES_CPP tests/main_test_cpp.cpp tests/bb_tests_cpp/test_table_basic.cpp tests/bb_tests_cpp/test_table_properties.cpp - tests/test_utils.c + tests/tests.c tests/test_utils.cpp) add_executable(${PROJECT_NAME}_test_cpp 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}_test ubsan) endif("${FORT_COMPILER}" STREQUAL "GNU") - endif("${FORT_COMPILER}" STREQUAL "ubsan") + endif(FORT_BUILD_TYPE STREQUAL "ubsan") #coveralls case if(FORT_BUILD_TYPE STREQUAL "coveralls") @@ -252,6 +254,7 @@ if(FORT_ENABLE_ASTYLE) ${CMAKE_SOURCE_DIR}/src/*.c ${CMAKE_SOURCE_DIR}/tests/*.c ${CMAKE_SOURCE_DIR}/tests/*.h + ${CMAKE_SOURCE_DIR}/tests/*.hpp ${CMAKE_SOURCE_DIR}/tests/bb_tests/*.c ${CMAKE_SOURCE_DIR}/tests/wb_tests/*.c ${CMAKE_SOURCE_DIR}/tests/bb_tests_cpp/*.cpp diff --git a/tests/bb_tests/test_table_basic.c b/tests/bb_tests/test_table_basic.c index c3d0540..cfc2e01 100644 --- a/tests/bb_tests/test_table_basic.c +++ b/tests/bb_tests/test_table_basic.c @@ -1,4 +1,5 @@ #include "tests.h" +#include "test_utils.h" #include #include "fort.h" diff --git a/tests/bb_tests/test_table_border_style.c b/tests/bb_tests/test_table_border_style.c index ff712e5..8bddc15 100644 --- a/tests/bb_tests/test_table_border_style.c +++ b/tests/bb_tests/test_table_border_style.c @@ -1,5 +1,6 @@ #include "tests.h" #include "fort.h" +#include "test_utils.h" diff --git a/tests/bb_tests/test_table_properties.c b/tests/bb_tests/test_table_properties.c index bc41b51..7142354 100644 --- a/tests/bb_tests/test_table_properties.c +++ b/tests/bb_tests/test_table_properties.c @@ -5,6 +5,7 @@ #include #include "properties.h" #include "vector.h" +#include "test_utils.h" diff --git a/tests/bb_tests_cpp/test_table_basic.cpp b/tests/bb_tests_cpp/test_table_basic.cpp index c5c6de5..81444a5 100644 --- a/tests/bb_tests_cpp/test_table_basic.cpp +++ b/tests/bb_tests_cpp/test_table_basic.cpp @@ -1,6 +1,6 @@ #include "tests.h" #include "fort.hpp" - +#include "test_utils.hpp" void test_cpp_table_basic(void) { diff --git a/tests/bb_tests_cpp/test_table_properties.cpp b/tests/bb_tests_cpp/test_table_properties.cpp index 04e8102..5af752b 100644 --- a/tests/bb_tests_cpp/test_table_properties.cpp +++ b/tests/bb_tests_cpp/test_table_properties.cpp @@ -1,5 +1,6 @@ #include "tests.h" #include "fort.hpp" +#include "test_utils.hpp" void test_cpp_table_tbl_properties(void) diff --git a/tests/main_test.c b/tests/main_test.c index 488a67d..26f22bf 100644 --- a/tests/main_test.c +++ b/tests/main_test.c @@ -2,6 +2,26 @@ #include #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 struct test_case wb_test_suit [] = { {"test_vector_basic", test_vector_basic}, diff --git a/tests/main_test_cpp.cpp b/tests/main_test_cpp.cpp index a72a6cc..ecc7d60 100644 --- a/tests/main_test_cpp.cpp +++ b/tests/main_test_cpp.cpp @@ -2,6 +2,7 @@ #include #include "fort.h" +/* Test cases */ void test_cpp_table_basic(void); void test_cpp_table_write(void); void test_cpp_table_tbl_properties(void); diff --git a/tests/test_utils.c b/tests/test_utils.c index 46ecf3c..08a0ada 100644 --- a/tests/test_utils.c +++ b/tests/test_utils.c @@ -1,4 +1,5 @@ #include "tests.h" +#include "test_utils.h" #include "fort.h" 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 -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); -} +//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); +//} diff --git a/tests/test_utils.cpp b/tests/test_utils.cpp index fad47a0..9b0b38e 100644 --- a/tests/test_utils.cpp +++ b/tests/test_utils.cpp @@ -48,3 +48,39 @@ fort::table create_cpp_test_int_table(int set_test_opts) 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); +} diff --git a/tests/test_utils.h b/tests/test_utils.h new file mode 100644 index 0000000..86315d0 --- /dev/null +++ b/tests/test_utils.h @@ -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 diff --git a/tests/test_utils.hpp b/tests/test_utils.hpp new file mode 100644 index 0000000..5dbed24 --- /dev/null +++ b/tests/test_utils.hpp @@ -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 diff --git a/tests/tests.c b/tests/tests.c new file mode 100644 index 0000000..2582121 --- /dev/null +++ b/tests/tests.c @@ -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); +} diff --git a/tests/tests.h b/tests/tests.h index 044aef3..0ca1f47 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -18,25 +18,6 @@ #define FT_HAVE_WCHAR #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 { char name [128]; void (*test)(void); @@ -68,28 +49,17 @@ struct test_case { exit(EXIT_FAILURE); \ } -struct ft_table; +#define assert_string_equal(str1, str2) assert_str_equal(str1.c_str(), str2.c_str()) + + #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" { #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[]); - #ifdef __cplusplus } #endif + #endif // TESTS_H diff --git a/tests/wb_tests/test_table_geometry.c b/tests/wb_tests/test_table_geometry.c index 3d30046..3a76ccf 100644 --- a/tests/wb_tests/test_table_geometry.c +++ b/tests/wb_tests/test_table_geometry.c @@ -1,5 +1,6 @@ #include "tests.h" #include "table.h" +#include "test_utils.h" void test_table_sizes(void) {