From 2725d452d4c6f5f0ddd5f983bfe54987e7557c72 Mon Sep 17 00:00:00 2001 From: seleznevae Date: Sun, 6 May 2018 14:11:03 +0300 Subject: [PATCH] [C] Split tests to 2 categories --- tests/test.c | 41 ++++++++++++++++++++++++--------- tests/test_memory_errors.c | 1 + tests/test_string_buffer.c | 4 +--- tests/test_table_basic.c | 1 + tests/test_table_border_style.c | 2 +- tests/test_table_geometry.c | 1 - tests/test_utility.c | 6 ++--- tests/test_vector.c | 2 -- tests/tests.h | 21 ++++++++++------- 9 files changed, 50 insertions(+), 29 deletions(-) diff --git a/tests/test.c b/tests/test.c index 10684e3..abebe02 100644 --- a/tests/test.c +++ b/tests/test.c @@ -1,12 +1,33 @@ #include "tests.h" #include +#include "fort.h" -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 %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); +} + + + + +struct test_case wb_test_suit [] = { {"test_vector_basic", test_vector_basic}, {"test_vector_stress", test_vector_stress}, {"test_string_buffer", test_string_buffer}, {"test_table_sizes", test_table_sizes}, {"test_table_geometry", test_table_geometry}, +}; + +struct test_case bb_test_suit [] = { {"test_table_basic", test_table_basic}, #ifdef FT_HAVE_WCHAR {"test_wcs_table_boundaries", test_wcs_table_boundaries}, @@ -18,17 +39,15 @@ struct test_case test_suit [] = { {"test_memory_errors", test_memory_errors}, }; + int main(void) { - int n_tests = sizeof(test_suit) / sizeof(test_suit[0]); - 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); + int wb_n_tests = sizeof(wb_test_suit) / sizeof(wb_test_suit[0]); + run_test_suit("WHITE BOX TEST SUITE", wb_n_tests, wb_test_suit); + + fprintf(stderr, "\n"); + int bb_n_tests = sizeof(bb_test_suit) / sizeof(bb_test_suit[0]); + run_test_suit("BLACK BOX TEST SUITE", bb_n_tests, bb_test_suit); + return 0; } diff --git a/tests/test_memory_errors.c b/tests/test_memory_errors.c index 7916268..2bb9613 100644 --- a/tests/test_memory_errors.c +++ b/tests/test_memory_errors.c @@ -1,4 +1,5 @@ #include "tests.h" +#include "fort.h" static int aloc_num = 0; static int aloc_lim = 9999; diff --git a/tests/test_string_buffer.c b/tests/test_string_buffer.c index 5c9447e..9f79dee 100644 --- a/tests/test_string_buffer.c +++ b/tests/test_string_buffer.c @@ -1,8 +1,6 @@ #include "tests.h" - #include "string_buffer.h" -//#include "../src/fort.c" -#include "wchar.h" +#include size_t strchr_count(const char *str, char ch); diff --git a/tests/test_table_basic.c b/tests/test_table_basic.c index befc069..e9fdc4a 100644 --- a/tests/test_table_basic.c +++ b/tests/test_table_basic.c @@ -1,5 +1,6 @@ #include "tests.h" #include +#include "fort.h" void test_table_basic(void) { diff --git a/tests/test_table_border_style.c b/tests/test_table_border_style.c index 96bcd9c..5fcd9d9 100644 --- a/tests/test_table_border_style.c +++ b/tests/test_table_border_style.c @@ -1,5 +1,5 @@ #include "tests.h" - +#include "fort.h" diff --git a/tests/test_table_geometry.c b/tests/test_table_geometry.c index 83a0419..ad43d5a 100644 --- a/tests/test_table_geometry.c +++ b/tests/test_table_geometry.c @@ -1,7 +1,6 @@ #include "tests.h" #include "table.h" - void test_table_sizes(void) { ft_table_t *table = ft_create_table(); diff --git a/tests/test_utility.c b/tests/test_utility.c index 04705c0..1780c59 100644 --- a/tests/test_utility.c +++ b/tests/test_utility.c @@ -1,7 +1,7 @@ #include "tests.h" #include "fort.h" -int set_test_options_for_table(ft_table_t *table) +int set_test_options_for_table(struct ft_table *table) { assert(table); int status = FT_SUCCESS; @@ -71,7 +71,7 @@ int set_test_options_as_default(void) -ft_table_t *create_test_int_table(int set_test_opts) +struct ft_table *create_test_int_table(int set_test_opts) { ft_table_t *table = NULL; @@ -102,7 +102,7 @@ ft_table_t *create_test_int_table(int set_test_opts) } #ifdef FT_HAVE_WCHAR -ft_table_t *create_test_int_wtable(int set_test_opts) +struct ft_table *create_test_int_wtable(int set_test_opts) { ft_table_t *table = NULL; diff --git a/tests/test_vector.c b/tests/test_vector.c index 748a2bf..36f1aba 100644 --- a/tests/test_vector.c +++ b/tests/test_vector.c @@ -1,7 +1,5 @@ #include "tests.h" - #include "vector.h" -//#include "../src/fort.c" void test_vector_basic(void) diff --git a/tests/tests.h b/tests/tests.h index 8410d61..88b19e8 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -4,15 +4,20 @@ #include #include #include -#include "fort_impl.h" #include -#include "wchar.h" -#include "locale.h" +#include +#include +#include +#include #define WHEN(...) #define THEN(...) #define SCENARIO(...) +#if defined(FT_CONGIG_HAVE_WCHAR) +#define FT_HAVE_WCHAR +#endif + /* Test cases */ void test_vector_basic(void); void test_vector_stress(void); @@ -35,7 +40,6 @@ struct test_case void (*test)(void); }; - /* * Test utility funcitons */ @@ -62,13 +66,14 @@ struct test_case exit(EXIT_FAILURE); \ } -int set_test_options_for_table(ft_table_t *table); +struct ft_table; +int set_test_options_for_table(struct ft_table *table); int set_test_options_as_default(void); -ft_table_t *create_test_int_table(int set_test_opts); -ft_table_t *create_test_int_wtable(int set_test_opts); - +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 []);