From: alex Date: Thu, 4 Nov 2021 05:35:07 +0000 (-0700) Subject: ... X-Git-Url: http://git.infiniteadaptability.org/?a=commitdiff_plain;h=78ee0c0fdb2d2da034aaa2537af5e2971ae0ff02;p=seeder ... --- diff --git a/test/unit/file.tests.c b/test/unit/file.tests.c index 7be295e..bb8aae4 100644 --- a/test/unit/file.tests.c +++ b/test/unit/file.tests.c @@ -4,6 +4,9 @@ int main(); static void file_hash_basic_test(); +static void file_hash_large_file_test(); +static void file_hash_large_piece_test(); +static void file_hash_random_file_test(); static void file_init_basic_test(); int main() { @@ -11,6 +14,9 @@ int main() { file_init_basic_test(); file_hash_basic_test(); + file_hash_large_file_test(); + file_hash_large_piece_test(); + file_hash_random_file_test(); clean_env(); @@ -61,6 +67,50 @@ static void file_hash_basic_test() { file_free(p); } +static void file_hash_large_file_test() { + struct file *p; + FILE *fp; + unsigned char buf[16384]; + unsigned char expected[crypto_hash_sha256_BYTES] = {0}; + + 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); + + assert(file_init(&p,TEST_FILE_1)==1); + assert(file_hash(p,16384)==1); + assert(memcmp(p->root,expected,crypto_hash_sha256_BYTES)==0); + assert(10000==block_length(p->blocks)); + assert((10000*16384+21)==p->size); + + file_free(p); + + reset_env(); +} + +static void file_hash_large_piece_test() { + +} + +static void file_hash_random_file_test() { + struct file *p; + + system("head -c 256MB " TEST_FILE_5); + + assert(file_init(&p,TEST_FILE_5)==1); + assert(file_hash(p,16384)==1); + assert(1==block_length(p->blocks)); + assert(24==p->size); + + file_free(p); +} + static void file_init_basic_test() { struct file *p; unsigned char expected[crypto_hash_sha256_BYTES]; diff --git a/test/unit/test_utils.h b/test/unit/test_utils.h index e658844..02932cc 100644 --- a/test/unit/test_utils.h +++ b/test/unit/test_utils.h @@ -19,6 +19,7 @@ #define TEST_FILE_3_CONTENTS "sdlifjasdiofjasoidfjaois" #define TEST_FILE_4 PREFIX "/.test.meta" #define TEST_FILE_4_CONTENTS ";alsikdjf;lkasdjflk\n;asjdflk\n;ajsdklfjl;aksdfjla;kj" +#define TEST_FILE_5 PREFIX "/random.test" void clean_env(); void reset_env();