diff --git a/test/Makefile b/test/Makefile index 2822a33..3ea394d 100644 --- a/test/Makefile +++ b/test/Makefile @@ -40,13 +40,15 @@ tests += store_md5 tests += load_md5 tests += store_sha1 tests += load_sha1 -total = 6 +tests += store_sha256 +tests += load_sha256 +total != echo $(tests) | wc -w | awk '{ print $$1 }' .PHONY: test test: $(tests) @printf "\n\tRunning %i tests\n\n" $(total) @idx=1 ; success=0 ; fail=0; for t in $(tests) ; \ - do printf "[%i/$(total)] \"$${t}\"\t" $${idx} ; \ + do printf "[%i/$(total)] \%-25s" $${idx} $${t} ; \ idx=$$(expr $${idx} + 1) ; \ ./$${t} ; \ if [ $$? -eq 0 ] ; \ @@ -60,22 +62,7 @@ test: $(tests) output: @ [-d $@ ] 2>/dev/null || install -d $@ -store_device: store_device.c haggis_private.h output - $(CC) $(CFLAGS) -o $@ $< $(LIBS) - -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 +$(tests): $@.c haggis_private.h output $(CC) $(CFLAGS) -o $@ $< $(LIBS) .PHONY: clean diff --git a/test/load_sha256.c b/test/load_sha256.c new file mode 100644 index 0000000..b2c2c17 --- /dev/null +++ b/test/load_sha256.c @@ -0,0 +1,20 @@ +#include "haggis.h" +#include "haggis_private.h" +#include +#include +#include + +int main() { + haggis_checksum cksum; + FILE *f; + int i, ret; + + f = fopen("output/sha256", "r"); + if (haggis_load_cksum(f, &cksum)) return 1; + assert(cksum.tag == sha256); + for (i = 0; i < 32; i++) { + assert(cksum.sum.sha1[i] == (uint8_t)i); + } +} + + diff --git a/test/store_sha256.c b/test/store_sha256.c new file mode 100644 index 0000000..b2fb729 --- /dev/null +++ b/test/store_sha256.c @@ -0,0 +1,21 @@ +#include "haggis.h" +#include "haggis_private.h" +#include +#include + +int main() { + haggis_checksum cksum; + FILE *f; + int i, ret; + + cksum.tag = sha256; + for (i = 0; i < 32; i++) { + cksum.sum.sha256[i] = (uint8_t)i; + } + f = fopen("output/sha256", "w"); + ret = haggis_store_cksum(f, &cksum); + fclose(f); + return ret; +} + +