From cb28447b459fff3a9a154ad4f3c5b51287919658 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Fri, 22 Nov 2019 00:31:01 -0500 Subject: Add test_data.bin --- test/test_data.bin | Bin 0 -> 580 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/test_data.bin (limited to 'test') diff --git a/test/test_data.bin b/test/test_data.bin new file mode 100644 index 0000000..a670304 Binary files /dev/null and b/test/test_data.bin differ -- cgit From 6e877cf4f49f4b396e3a2e8898eef69188df8fdb Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Fri, 22 Nov 2019 00:34:32 -0500 Subject: Improve testing --- test/CMakeLists.txt | 33 +++++++++++++++++++++++++++------ test/test_reloc_read.c | 4 ++-- 2 files changed, 29 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6b79d98..56cdae2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,12 +1,33 @@ project(tests) +set(INPUT_SEARCH + /_0123456789_0123456789_0123456789_0123456789_0123456789_0123456789_0123456789_) +set(INPUT_REPLACE + _ctest_replaced_this) +set(INPUT_FN + test_data.bin) +set(OUTPUT_FN + test_data.out) + +configure_file(${INPUT_FN} ${INPUT_FN} COPYONLY) +file(REMOVE ${OUTPUT_FN}) + include_directories("${CMAKE_SOURCE_DIR}") include_directories("${CMAKE_BINARY_DIR}") -add_executable(test_reloc_match test_reloc_match.c) -add_executable(test_reloc_read test_reloc_read.c) -target_link_libraries(test_reloc_match relocate) -target_link_libraries(test_reloc_read relocate) +function(add_reloc_test target) + add_executable(${target} ${ARGN}) + target_link_libraries(${target} relocate) + add_test(${target} ${target}) +endfunction() + +function(add_exec_test target) + add_test(NAME ${target} COMMAND ${ARGN}) +endfunction() + +add_reloc_test(test_reloc_match test_reloc_match.c) +add_reloc_test(test_reloc_read test_reloc_read.c) +add_exec_test(test_exec_success reloc "${INPUT_SEARCH}" "${INPUT_REPLACE}" "${INPUT_FN}" "${OUTPUT_FN}") -add_test(test_reloc_match test_reloc_match) -add_test(test_reloc_read test_reloc_read) +# Windows users need grep too. "findstr" and "find" were not reliable here +add_exec_test(test_exec_result grep "${INPUT_REPLACE}" "${OUTPUT_FN}") diff --git a/test/test_reloc_read.c b/test/test_reloc_read.c index 39d5eb8..934bb9f 100644 --- a/test/test_reloc_read.c +++ b/test/test_reloc_read.c @@ -19,7 +19,7 @@ int test_reloc_read() { myassert("info->size is incorrect", info->size == sizeof(test_case)); myassert("info->path is incorrect", !strcmp(info->path, input_file)); myassert("info->data is uninitialized", info->data); - free(info); + reloc_deinit_data(info); return 0; } @@ -27,7 +27,7 @@ int test_reloc_read_verify() { RelocData *info = reloc_read(input_file); myassert("failed to populate RelocData struct", info); myassert("info->data != input_data contents", !memcmp(test_case, info->data, info->size)); - free(info); + reloc_deinit_data(info); return 0; } -- cgit From 8ff58f7703bb2854a05acfbbda317b0abad2c0e7 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Fri, 22 Nov 2019 16:01:37 -0500 Subject: Add test_reloc_write test --- test/CMakeLists.txt | 1 + test/test_reloc_write.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 test/test_reloc_write.c (limited to 'test') diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 56cdae2..9dab686 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -27,6 +27,7 @@ endfunction() add_reloc_test(test_reloc_match test_reloc_match.c) add_reloc_test(test_reloc_read test_reloc_read.c) +add_reloc_test(test_reloc_write test_reloc_write.c) add_exec_test(test_exec_success reloc "${INPUT_SEARCH}" "${INPUT_REPLACE}" "${INPUT_FN}" "${OUTPUT_FN}") # Windows users need grep too. "findstr" and "find" were not reliable here diff --git a/test/test_reloc_write.c b/test/test_reloc_write.c new file mode 100644 index 0000000..b2044c7 --- /dev/null +++ b/test/test_reloc_write.c @@ -0,0 +1,28 @@ +#include "reloc.h" +#include "myassert.h" +#if !defined(_MSC_VER) +#include // unlink() +#endif + +const char *input_file = "test_data.bin"; +const char *output_file = "test_reloc_write.out"; + + +int test_reloc_write() { + RelocData *info = reloc_read(input_file); + myassert("failed to populate RelocData struct", info); + size_t size = reloc_write(info, output_file); + myassert("incorrect number of bytes written", size == info->size); + reloc_deinit_data(info); + if (unlink(output_file) != 0) { + perror("Could not delete output file"); + return errno; + } + + return 0; +} + + +int main() { + return test_reloc_write(); +} -- cgit From 2ae80482cd88fb9786d3ff54777b8a462641f29f Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Fri, 22 Nov 2019 22:12:03 -0500 Subject: Decrease MSVC chatter --- test/test_reloc_match.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/test_reloc_match.c b/test/test_reloc_match.c index bb9d6b0..ed725cd 100644 --- a/test/test_reloc_match.c +++ b/test/test_reloc_match.c @@ -72,11 +72,11 @@ int test_reloc_match() { myassert("Invalid match->end", match->end != NULL); printf("\tpost=\"%s\", data=\"%s\"\n", match->post, match->begin); myassert("Invalid match->post", !strcmp(match->post, test_solution_post[i])); - printf("\tlength=%lu\n", match->length); + printf("\tlength=" SIZE_T_FMT "\n", match->length); myassert("Invalid match->length", match->length == test_solution_length[i]); - printf("\tpost_length=%lu\n", match->post_length); + printf("\tpost_length=" SIZE_T_FMT "\n", match->post_length); myassert("Invalid match->post_length", match->post_length == test_solution_post_length[i]); - printf("\ttotal_length=%lu\n", match->total_length); + printf("\ttotal_length=" SIZE_T_FMT "\n", match->total_length); myassert("Invalid match->total_length", match->total_length == test_solution_total_length[i]); if (match) { free(match); -- cgit