[C] Changed test architecture

This commit is contained in:
seleznevae 2018-05-06 16:21:45 +03:00
parent 2725d452d4
commit b7e8d7fbf6
16 changed files with 5250 additions and 66 deletions

View File

@ -85,6 +85,7 @@ script:
- cmake --build . --target all - cmake --build . --target all
- ls - ls
- ./libfort_example - ./libfort_example
- ./libfort_test_dev
- ./libfort_test - ./libfort_test
# Test build without optimizations and with ubsan # Test build without optimizations and with ubsan
@ -97,6 +98,7 @@ script:
cmake --build . --target all ; cmake --build . --target all ;
ls ; ls ;
./libfort_example ; ./libfort_example ;
./libfort_test_dev ;
./libfort_test ; ./libfort_test ;
fi fi
@ -143,7 +145,7 @@ script:
cmake .. -DFORT_BUILD_TYPE=coveralls ; cmake .. -DFORT_BUILD_TYPE=coveralls ;
cmake --build . --target all ; cmake --build . --target all ;
ls ; ls ;
./libfort_test ; ./libfort_test_dev ;
fi fi
- cd .. - cd ..

View File

@ -34,6 +34,7 @@ add_definitions(-DFT_CONGIG_HAVE_WCHAR)
include_directories(include) include_directories(include)
include_directories(src) include_directories(src)
include_directories(tests)
@ -88,18 +89,32 @@ add_executable(${PROJECT_NAME}_example_cpp
${EXAMPLE_CPP_SOURCES} ${EXAMPLE_CPP_SOURCES}
${FORT_SOURCES}) ${FORT_SOURCES})
set(TEST_SOURCES set(TEST_SOURCES_DEV
tests/test.c tests/main_test.c
tests/test_vector.c tests/wb_tests/test_vector.c
tests/test_string_buffer.c tests/wb_tests/test_string_buffer.c
tests/test_table_geometry.c tests/wb_tests/test_table_geometry.c
tests/test_table_basic.c tests/bb_tests/test_table_basic.c
tests/test_table_border_style.c tests/bb_tests/test_table_border_style.c
tests/test_table_options.c tests/bb_tests/test_table_options.c
tests/test_memory_errors.c tests/bb_tests/test_memory_errors.c
tests/test_utility.c) tests/test_common.c)
add_executable(${PROJECT_NAME}_test add_executable(${PROJECT_NAME}_test_dev
${FORT_SOURCES} ${FORT_SOURCES}
${TEST_SOURCES_DEV})
target_compile_definitions(${PROJECT_NAME}_test_dev
PUBLIC FORT_WB_TESTING_ENABLED=1)
set(TEST_SOURCES
tests/main_test.c
tests/bb_tests/test_table_basic.c
tests/bb_tests/test_table_border_style.c
tests/bb_tests/test_table_options.c
tests/bb_tests/test_memory_errors.c
tests/test_common.c)
add_executable(${PROJECT_NAME}_test
include/fort.c
${TEST_SOURCES}) ${TEST_SOURCES})

81
amalgamate.py Normal file
View File

@ -0,0 +1,81 @@
import os
def comment_line(line):
return "/* {} */ /* Commented by amalgamation script */".format(line)
def amalgamate(config):
with open(config["output_file"], "w") as output_f:
output_f.write("/* The file was GENERATED by an amalgamation script.*/\n")
output_f.write("/* DO NOT EDIT BY HAND!!! */\n\n")
for hdr_file in config["header_files"]:
with open(config["src_dir"] + "/" + hdr_file, "r") as input_f:
txt = input_f.read()
output_f.write('\n/********************************************************\n')
output_f.write(' Begin of file "{}"\n'.format(hdr_file))
output_f.write(' ********************************************************/\n\n')
output_f.write(txt)
output_f.write('\n/********************************************************\n')
output_f.write(' End of file "{}"\n'.format(hdr_file))
output_f.write(' ********************************************************/\n\n')
for src_file in config["src_files"]:
with open(config["src_dir"] + "/" + src_file, "r") as input_f:
txt = input_f.read()
output_f.write('\n/********************************************************\n')
output_f.write(' Begin of file "{}"\n'.format(src_file))
output_f.write(' ********************************************************/\n\n')
output_f.write(txt)
output_f.write('\n/********************************************************\n')
output_f.write(' End of file "{}"\n'.format(src_file))
output_f.write(' ********************************************************/\n\n')
with open(config["output_file"]) as f:
lines = f.readlines()
forbidden_strings = map(lambda hdr_name: '#include "{}"'.format(hdr_name), config["header_files"])
lines = map(lambda line: comment_line(line.strip()) + "\n" if line.strip() in forbidden_strings else line, lines)
with open(config["output_file"], "w") as f:
for line in lines:
f.write(line)
def is_c_header_file(file):
return ".h" in file
def is_c_source_file(file):
return ".c" in file
def main():
config = {}
config["output_file"] = "./include/fort.c"
config["src_dir"] = "./src"
all_files = os.listdir(config["src_dir"])
config["src_files"] = filter(is_c_source_file, all_files)
# config["header_files"] = filter(is_c_header_file, all_files)
config["header_files"] = [
"fort_impl.h",
"vector.h",
"wcwidth.h",
"string_buffer.h",
"options.h",
"cell.h",
"row.h",
"table.h"
];
amalgamate(config)
if __name__ == '__main__':
main()

View File

@ -21,5 +21,6 @@ build:
project: $(APPVEYOR_BUILD_FOLDER)\build\$(APPVEYOR_PROJECT_NAME).sln project: $(APPVEYOR_BUILD_FOLDER)\build\$(APPVEYOR_PROJECT_NAME).sln
test_script: test_script:
- '%APPVEYOR_BUILD_FOLDER%\build\Debug\libfort_test_dev.exe'
- '%APPVEYOR_BUILD_FOLDER%\build\Debug\libfort_test.exe' - '%APPVEYOR_BUILD_FOLDER%\build\Debug\libfort_test.exe'
- '%APPVEYOR_BUILD_FOLDER%\build\Debug\libfort_example.exe' - '%APPVEYOR_BUILD_FOLDER%\build\Debug\libfort_example.exe'

5060
include/fort.c Normal file

File diff suppressed because it is too large Load Diff

16
tests/main_test.c Normal file
View File

@ -0,0 +1,16 @@
#include "tests.h"
#include <stdio.h>
#include "fort.h"
int main(void)
{
int status = 0;
#ifdef FORT_WB_TESTING_ENABLED
status |= run_wb_test_suit();
fprintf(stderr, "\n");
#endif
status |= run_bb_test_suit();
return status;
}

View File

@ -1,53 +0,0 @@
#include "tests.h"
#include <stdio.h>
#include "fort.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);
}
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},
#endif
{"test_table_write", test_table_write},
{"test_table_border_style", test_table_border_style},
{"test_table_cell_options", test_table_cell_options},
{"test_table_tbl_options", test_table_tbl_options},
{"test_memory_errors", test_memory_errors},
};
int main(void)
{
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;
}

View File

@ -132,3 +132,62 @@ struct ft_table *create_test_int_wtable(int set_test_opts)
return table; return table;
} }
#endif #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);
}
#ifdef FORT_WB_TESTING_ENABLED
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},
};
#endif
struct test_case bb_test_suit [] = {
{"test_table_basic", test_table_basic},
#ifdef FT_HAVE_WCHAR
{"test_wcs_table_boundaries", test_wcs_table_boundaries},
#endif
{"test_table_write", test_table_write},
{"test_table_border_style", test_table_border_style},
{"test_table_cell_options", test_table_cell_options},
{"test_table_tbl_options", test_table_tbl_options},
{"test_memory_errors", test_memory_errors},
};
#ifdef FORT_WB_TESTING_ENABLED
int run_wb_test_suit(void)
{
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);
return 0;
}
#endif
int run_bb_test_suit(void)
{
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;
}

View File

@ -75,7 +75,10 @@ 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 FORT_WB_TESTING_ENABLED
int run_wb_test_suit(void);
#endif
int run_bb_test_suit(void);
#endif // TESTS_H #endif // TESTS_H