libswarm-ng

C implementation of BMT hasher, Swarmhash and Single Owner Chunk for swarm
git clone git://git.defalsify.org/libswarm-ng.git
Log | Files | Refs | Submodules | README

commit d1926b628743376ea13ae8fac5102df53e1298ab
parent 6da10c71dd4ae8e4a884c76ac844d5b4318d2cf0
Author: nolash <dev@holbrook.no>
Date:   Tue, 14 Sep 2021 12:17:14 +0200

Add filehasher source files and test

Diffstat:
Msrc/file.c | 2++
Msrc/file.h | 2++
Mtest/check_file.c | 16++++++++++++++++
3 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/src/file.c b/src/file.c @@ -8,6 +8,8 @@ int filehash_init(filehash_t *filehash_context) { for (i = 0; i < SWARM_LEVELS; i++) { filehash_context->ptr[i] = filehash_context->buf; } + filehash_context->length = 0; + filehash_context->writes = 0; return 0; } diff --git a/src/file.h b/src/file.h @@ -9,6 +9,8 @@ typedef struct filehash { char buf[SWARM_LEVELS][BLOCK_SIZE]; char *ptr[SWARM_LEVELS]; + long long byte_length; + long long writes; } filehash_t; int filehash_init(filehash_t *filehash_context); diff --git a/test/check_file.c b/test/check_file.c @@ -1,5 +1,6 @@ #include <check.h> #include <stdlib.h> +#include <string.h> #include "file.h" @@ -17,6 +18,20 @@ START_TEST(check_file_init) { } END_TEST +START_TEST(check_file_single_write) { + filehash_t fh; + int r; + + char *data = "foo"; + + + filehash_init(&fh); + + r = filehash_write(&fh, data, strlen(data)); +} +END_TEST + + Suite * common_suite(void) { Suite *s; TCase *tc; @@ -24,6 +39,7 @@ Suite * common_suite(void) { s = suite_create("file"); tc = tcase_create("core"); tcase_add_test(tc, check_file_init); + tcase_add_test(tc, check_file_single_write); suite_add_tcase(s, tc); return s;