aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2019-11-22 16:01:37 -0500
committerJoseph Hunkeler <jhunkeler@gmail.com>2019-11-22 16:05:03 -0500
commit8ff58f7703bb2854a05acfbbda317b0abad2c0e7 (patch)
treebea0e4543895fd3c1fdc50640cc02f39277a88ef
parent6e877cf4f49f4b396e3a2e8898eef69188df8fdb (diff)
downloadreloc-8ff58f7703bb2854a05acfbbda317b0abad2c0e7.tar.gz
Add test_reloc_write test
-rw-r--r--test/CMakeLists.txt1
-rw-r--r--test/test_reloc_write.c28
2 files changed, 29 insertions, 0 deletions
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 <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();
+}