Simplify test/Makefile; Add sha256 tests
This commit is contained in:
parent
28bb93b999
commit
f0ee28d495
3 changed files with 46 additions and 18 deletions
|
@ -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
|
||||
|
|
20
test/load_sha256.c
Normal file
20
test/load_sha256.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
#include "haggis.h"
|
||||
#include "haggis_private.h"
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
21
test/store_sha256.c
Normal file
21
test/store_sha256.c
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include "haggis.h"
|
||||
#include "haggis_private.h"
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
Add table
Reference in a new issue