aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to '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;
}