aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2019-11-14 09:28:30 -0500
committerJoseph Hunkeler <jhunkeler@gmail.com>2019-11-14 09:28:30 -0500
commit0256732772c3fdf8a8adc77e54b848e1a2f92c75 (patch)
tree9582f76c9a5d97772a6e48a8b007f2a6ac4e8cf3
parent4d497fcf5f021117d644e955bac6e6427ce3d9b4 (diff)
downloadreloc-0256732772c3fdf8a8adc77e54b848e1a2f92c75.tar.gz
Finish read test
-rw-r--r--test/test_reloc_read.c32
1 files changed, 19 insertions, 13 deletions
diff --git a/test/test_reloc_read.c b/test/test_reloc_read.c
index 310370d..39d5eb8 100644
--- a/test/test_reloc_read.c
+++ b/test/test_reloc_read.c
@@ -1,38 +1,44 @@
#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"
+ "jumps over\n\x00 \xEE\x09"
"\xAB\xCD\xEF the quick brown fox\n\x00"
"\xBBthe lazy\n\x00 dog\n";
+const char *input_file = "input.bin";
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;
- }
+ RelocData *info = reloc_read(input_file);
+ myassert("failed to populate RelocData struct", info);
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);
+ return 0;
+}
+
+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);
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;
- }
+ int result = 0;
+ FILE *fp = fopen(input_file, "w+b");
+ myassert("failed to write input file with test_case data", fp);
fwrite(test_case, sizeof(char), sizeof(test_case), fp);
fclose(fp);
- return test_reloc_read();
+ result += test_reloc_read();
+ result += test_reloc_read_verify();
+ return result;
}