diff --git a/.gitignore b/.gitignore index edc1dd3..fde95b3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ haggis config.mk +test/output/ *.o *.a *.so +*.core diff --git a/test/Makefile b/test/Makefile index a0880e5..2822a33 100644 --- a/test/Makefile +++ b/test/Makefile @@ -36,7 +36,11 @@ LIBS += -lmd tests += store_device tests += load_device -total = 2 +tests += store_md5 +tests += load_md5 +tests += store_sha1 +tests += load_sha1 +total = 6 .PHONY: test test: $(tests) @@ -62,6 +66,18 @@ store_device: store_device.c haggis_private.h output load_device: load_device.c haggis_private.h output $(CC) $(CFLAGS) -o $@ $< $(LIBS) +store_md5: store_md5.c haggis_private.h output + $(CC) $(CFLAGS) -o $@ $< $(LIBS) + +load_md5: load_md5.c haggis_private.h output + $(CC) $(CFLAGS) -o $@ $< $(LIBS) + +store_sha1: store_sha1.c haggis_private.h output + $(CC) $(CFLAGS) -o $@ $< $(LIBS) + +load_sha1: load_sha1.c haggis_private.h output + $(CC) $(CFLAGS) -o $@ $< $(LIBS) + .PHONY: clean clean: rm -rf $(tests) output/* diff --git a/test/checksum.c b/test/checksum.c deleted file mode 100644 index e69de29..0000000 diff --git a/test/load_md5.c b/test/load_md5.c new file mode 100644 index 0000000..0892356 --- /dev/null +++ b/test/load_md5.c @@ -0,0 +1,18 @@ +#include "haggis.h" +#include "haggis_private.h" +#include +#include +#include + +int main() { + haggis_checksum cksum; + FILE *f; + int i, ret; + + f = fopen("output/md5", "r"); + if (haggis_load_cksum(f, &cksum)) return 1; + assert(cksum.tag == md5); + for (i = 0; i < 16; i++) { + assert(cksum.sum.md5[i] == (uint8_t)i); + } +} diff --git a/test/load_sha1.c b/test/load_sha1.c new file mode 100644 index 0000000..fcfbe77 --- /dev/null +++ b/test/load_sha1.c @@ -0,0 +1,19 @@ +#include "haggis.h" +#include "haggis_private.h" +#include +#include +#include + +int main() { + haggis_checksum cksum; + FILE *f; + int i, ret; + + f = fopen("output/sha1", "r"); + if (haggis_load_cksum(f, &cksum)) return 1; + assert(cksum.tag == sha1); + for (i = 0; i < 20; i++) { + assert(cksum.sum.sha1[i] == (uint8_t)i); + } +} + diff --git a/test/store_device.core b/test/store_device.core deleted file mode 100644 index d63ec75..0000000 Binary files a/test/store_device.core and /dev/null differ diff --git a/test/store_md5.c b/test/store_md5.c new file mode 100644 index 0000000..aed400a --- /dev/null +++ b/test/store_md5.c @@ -0,0 +1,19 @@ +#include "haggis.h" +#include "haggis_private.h" +#include +#include + +int main() { + haggis_checksum cksum; + FILE *f; + int i, ret; + + cksum.tag = md5; + for (i = 0; i < 16; i++) { + cksum.sum.md5[i] = (uint8_t)i; + } + f = fopen("output/md5", "w"); + ret = haggis_store_cksum(f, &cksum); + fclose(f); + return ret; +} diff --git a/test/store_sha1.c b/test/store_sha1.c new file mode 100644 index 0000000..dedfd63 --- /dev/null +++ b/test/store_sha1.c @@ -0,0 +1,20 @@ +#include "haggis.h" +#include "haggis_private.h" +#include +#include + +int main() { + haggis_checksum cksum; + FILE *f; + int i, ret; + + cksum.tag = sha1; + for (i = 0; i < 20; i++) { + cksum.sum.md5[i] = (uint8_t)i; + } + f = fopen("output/sha1", "w"); + ret = haggis_store_cksum(f, &cksum); + fclose(f); + return ret; +} +