Add tests for md5 and sha1
This commit is contained in:
parent
5e3ff56921
commit
28bb93b999
8 changed files with 95 additions and 1 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,5 +1,7 @@
|
||||||
haggis
|
haggis
|
||||||
config.mk
|
config.mk
|
||||||
|
test/output/
|
||||||
*.o
|
*.o
|
||||||
*.a
|
*.a
|
||||||
*.so
|
*.so
|
||||||
|
*.core
|
||||||
|
|
|
@ -36,7 +36,11 @@ LIBS += -lmd
|
||||||
|
|
||||||
tests += store_device
|
tests += store_device
|
||||||
tests += load_device
|
tests += load_device
|
||||||
total = 2
|
tests += store_md5
|
||||||
|
tests += load_md5
|
||||||
|
tests += store_sha1
|
||||||
|
tests += load_sha1
|
||||||
|
total = 6
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test: $(tests)
|
test: $(tests)
|
||||||
|
@ -62,6 +66,18 @@ store_device: store_device.c haggis_private.h output
|
||||||
load_device: load_device.c haggis_private.h output
|
load_device: load_device.c haggis_private.h output
|
||||||
$(CC) $(CFLAGS) -o $@ $< $(LIBS)
|
$(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
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(tests) output/*
|
rm -rf $(tests) output/*
|
||||||
|
|
18
test/load_md5.c
Normal file
18
test/load_md5.c
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#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/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);
|
||||||
|
}
|
||||||
|
}
|
19
test/load_sha1.c
Normal file
19
test/load_sha1.c
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
#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/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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Binary file not shown.
19
test/store_md5.c
Normal file
19
test/store_md5.c
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
#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 = 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;
|
||||||
|
}
|
20
test/store_sha1.c
Normal file
20
test/store_sha1.c
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#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 = 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;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue