Add load/store file with sha256 hashing tests
This commit is contained in:
parent
2acf8844dd
commit
8837beadaa
5 changed files with 83 additions and 1 deletions
|
@ -55,11 +55,15 @@ tests += init_file_sha1
|
|||
tests += init_file_sha256
|
||||
tests += store_file_md5
|
||||
tests += load_file_md5
|
||||
tests += store_file_sha1
|
||||
tests += load_file_sha1
|
||||
tests += store_file_sha256
|
||||
tests += load_file_sha256
|
||||
total != echo $(tests) | wc -w | awk '{ print $$1 }'
|
||||
|
||||
.PHONY: test
|
||||
test: $(tests)
|
||||
@echo -e "\n\t\e[0;33mRunning $(total) tests\e[0m\n"
|
||||
@echo -e "\n\t=== \e[0;33mRunning $(total) tests\e[0m ===\n"
|
||||
@idx=1 ; success=0 ; fail=0; for t in $(tests) ; \
|
||||
do printf "[%02i/$(total)] \%-25s" $${idx} $${t} ; \
|
||||
idx=$$(expr $${idx} + 1) ; \
|
||||
|
|
16
test/load_file_sha1.c
Normal file
16
test/load_file_sha1.c
Normal file
|
@ -0,0 +1,16 @@
|
|||
#include "haggis_private.h"
|
||||
#include <assert.h>
|
||||
#include <md5.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
haggis_file hf;
|
||||
char *f = "output/store_file_sha1";
|
||||
FILE *fd;
|
||||
int res;
|
||||
|
||||
fd = fopen(f, "r");
|
||||
res = haggis_load_file(fd, &hf);
|
||||
fclose(fd);
|
||||
return res;
|
||||
}
|
16
test/load_file_sha256.c
Normal file
16
test/load_file_sha256.c
Normal file
|
@ -0,0 +1,16 @@
|
|||
#include "haggis_private.h"
|
||||
#include <assert.h>
|
||||
#include <md5.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
haggis_file hf;
|
||||
char *f = "output/store_file_sha256";
|
||||
FILE *fd;
|
||||
int res;
|
||||
|
||||
fd = fopen(f, "r");
|
||||
res = haggis_load_file(fd, &hf);
|
||||
fclose(fd);
|
||||
return res;
|
||||
}
|
23
test/store_file_sha1.c
Normal file
23
test/store_file_sha1.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
#include "haggis_private.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__DragonFly__)
|
||||
#include <sha.h>
|
||||
#elif defined(__NetBSD__) || defined(__OpenBSD__) || defined(__LINUX__)
|
||||
#include <sha1.h>
|
||||
#endif
|
||||
|
||||
int main() {
|
||||
haggis_file hf;
|
||||
char *f = "load_device.c";
|
||||
FILE *fd;
|
||||
|
||||
assert(haggis_file_init(f, &hf, sha1) == 0);
|
||||
fd = fopen("output/store_file_sha1", "w");
|
||||
assert(haggis_store_file(fd, &hf) == 0);
|
||||
fflush(fd);
|
||||
fclose(fd);
|
||||
return 0;
|
||||
}
|
||||
|
23
test/store_file_sha256.c
Normal file
23
test/store_file_sha256.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
#include "haggis_private.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__DragonFly__)
|
||||
#include <sha256.h>
|
||||
#elif defined(__NetBSD__) || defined(__OpenBSD__) || defined(__LINUX__)
|
||||
#include <sha2.h>
|
||||
#endif
|
||||
|
||||
int main() {
|
||||
haggis_file hf;
|
||||
char *f = "load_device.c";
|
||||
FILE *fd;
|
||||
|
||||
assert(haggis_file_init(f, &hf, sha1) == 0);
|
||||
fd = fopen("output/store_file_sha256", "w");
|
||||
assert(haggis_store_file(fd, &hf) == 0);
|
||||
fflush(fd);
|
||||
fclose(fd);
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Add table
Reference in a new issue