diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/CMakeLists.txt | 34 | ||||
| -rw-r--r-- | test/test_data.bin | bin | 0 -> 580 bytes | |||
| -rw-r--r-- | test/test_reloc_match.c | 6 | ||||
| -rw-r--r-- | test/test_reloc_read.c | 4 | ||||
| -rw-r--r-- | test/test_reloc_write.c | 28 | 
5 files changed, 61 insertions, 11 deletions
| diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6b79d98..9dab686 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,12 +1,34 @@  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_reloc_test(test_reloc_write test_reloc_write.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_data.bin b/test/test_data.binBinary files differ new file mode 100644 index 0000000..a670304 --- /dev/null +++ b/test/test_data.bin 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); 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;  } 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 <unistd.h>  // 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(); +} | 
