From af8a5c596e619591c1eef9903b4ed4d6b4ab3991 Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 5 Nov 2021 21:10:07 -0700 Subject: [PATCH] ... --- test/unit/file.tests.c | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/test/unit/file.tests.c b/test/unit/file.tests.c index 5888d32..1b36f88 100644 --- a/test/unit/file.tests.c +++ b/test/unit/file.tests.c @@ -3,6 +3,7 @@ #include int main(); +static void extend_file(const char*); static void file_hash_basic_test(); static void file_hash_large_file_test(); static void file_hash_large_piece_test(); @@ -23,6 +24,21 @@ int main() { return EXIT_SUCCESS; } +static void extend_file(const char *file) { + unsigned char buf[16384]; + FILE *fp; + + fp = fopen(file,"a"); + assert(fp!=NULL); + + for(size_t i=0;i<10000;i++) { + memset(buf,i%255,16384); + assert(16384==fwrite(buf,sizeof(char),16384,fp)); + } + + fclose(fp); +} + static void file_hash_basic_test() { struct file *p; unsigned char expected1[crypto_hash_sha256_BYTES] = {174,73,190,37,189,244,236,113,18,122,255,20,5,229,77,151,187,72,27,75,203,32,25,154,81,249,19,29,118,7,228,229}; @@ -69,19 +85,9 @@ static void file_hash_basic_test() { static void file_hash_large_file_test() { struct file *p; - FILE *fp; - unsigned char buf[16384]; unsigned char expected[crypto_hash_sha256_BYTES] = {58,71,55,213,6,94,65,97,113,64,176,175,139,67,229,164,13,18,213,164,166,129,202,162,224,45,9,227,191,155,144,144}; - fp = fopen(TEST_FILE_1,"a"); - assert(fp!=NULL); - - for(size_t i=0;i<10000;i++) { - memset(buf,i%255,16384); - assert(16384==fwrite(buf,sizeof(char),16384,fp)); - } - - fclose(fp); + extend_file(TEST_FILE_1); assert(file_init(&p,TEST_FILE_1)==1); assert(file_hash(p,16384)==1); @@ -95,7 +101,20 @@ static void file_hash_large_file_test() { } static void file_hash_large_piece_test() { + struct file *p; + unsigned char expected[crypto_hash_sha256_BYTES] = {8,234,82,230,152,160,118,109,206,217,92,218,63,67,49,228,4,43,121,68,142,69,129,202,31,34,27,245,63,137,179,83}; + + extend_file(TEST_FILE_2); + + assert(1==file_init(&p,TEST_FILE_2)); + assert(file_hash(p,32768)==1); + assert(memcmp(p->root,expected,crypto_hash_sha256_BYTES)==0); + assert(5000==block_length(p->blocks)); + assert((10000*16384+26)==p->size); + file_free(p); + + reset_env(); } static void file_hash_random_file_test() { -- 2.39.5