aboutsummaryrefslogtreecommitdiff
path: root/test/test_reloc_read.c
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2019-11-13 16:48:03 -0500
committerJoseph Hunkeler <jhunkeler@gmail.com>2019-11-13 16:48:03 -0500
commit244fa85e98fa6f325025f49aca6e1fbb1e440582 (patch)
tree502ab3bbfb49749fad1cfaa5f2e20268d3f5c5e4 /test/test_reloc_read.c
parente801b594a18dbaf9283ad860c86e4a07b2b1e866 (diff)
downloadreloc-244fa85e98fa6f325025f49aca6e1fbb1e440582.tar.gz
Decouple main program and add initial tests
Diffstat (limited to 'test/test_reloc_read.c')
-rw-r--r--test/test_reloc_read.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/test_reloc_read.c b/test/test_reloc_read.c
new file mode 100644
index 0000000..310370d
--- /dev/null
+++ b/test/test_reloc_read.c
@@ -0,0 +1,38 @@
+#include "reloc.h"
+#include "myassert.h"
+
+const char *input_file = "input.bin";
+const char *output_file = "output.bin";
+char test_case[] =
+ "\xAB\xCD\xEF the quick brown fox\n\x00"
+ "jumps over\n\x00 \xEE\x09"
+ "\xAB\xCD\xEF the quick brown fox\n\x00"
+ "jumps over\n\x00 \xEE\x09"
+ "\xBBthe lazy\n\x00 dog\n"
+ "\xAB\xCD\xEF the quick brown fox\n\x00"
+ "\xBBthe lazy\n\x00 dog\n";
+
+
+int test_reloc_read() {
+ RelocData *info = NULL;
+ if (!(info = reloc_read(input_file))) {
+ fprintf(stderr, "Failed to open '%s' for writing\n", input_file);
+ return 1;
+ }
+ 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);
+ return 0;
+}
+
+int main() {
+ FILE *fp;
+ if (!(fp = fopen(input_file, "w+b"))) {
+ fprintf(stderr, "Failed to open '%s' for writing\n", input_file);
+ return 1;
+ }
+ fwrite(test_case, sizeof(char), sizeof(test_case), fp);
+ fclose(fp);
+
+ return test_reloc_read();
+}