From 4b0de00c9bc0bb292de59b45368321fee6178789 Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 3 Mar 2022 18:21:44 -0800 Subject: [PATCH] ... --- test/unit/test_macros.h | 10 +++++++--- test/unit/torrent.tests.c | 11 +++++++++++ test/unit/tree.tests.c | 10 ++++++++-- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/test/unit/test_macros.h b/test/unit/test_macros.h index 3b52da6..fdfe3ea 100644 --- a/test/unit/test_macros.h +++ b/test/unit/test_macros.h @@ -40,18 +40,22 @@ struct block *block, *p; \ \ assert(file_init(file_p,filename)==1); \ - memset((*file_p)->root,root_val,crypto_hash_sha256_BYTES); \ + assert(block_init(&((*file_p)->root))==1); \ + memset((*file_p)->root->hash,root_val,crypto_hash_sha256_BYTES); \ for(size_t i=0;i<10;i++) { \ assert(block_init(&block)==1); \ memset(block->hash,i,crypto_hash_sha256_BYTES); \ \ - if((*file_p)->piece_layers==NULL) { \ - (*file_p)->piece_layers = block; \ + if((*file_p)->blocks==NULL) { \ + (*file_p)->blocks = block; \ } else { \ p->next = block; \ } \ p = block; \ } \ +\ + (*file_p)->piece_layers = (*file_p)->blocks; \ + p->next = (*file_p)->root; \ } /* Parameters: diff --git a/test/unit/torrent.tests.c b/test/unit/torrent.tests.c index 9fc62db..211276b 100644 --- a/test/unit/torrent.tests.c +++ b/test/unit/torrent.tests.c @@ -38,12 +38,23 @@ static void torrent_add_basic_test() { for(size_t i=0;i<100;i++) { assert(file_init(&file1,TEST_FILE_1)==1); + assert(1==block_init(&(file1->root))); + file1->blocks = file1->root; memset(file1->root,1,crypto_hash_sha256_BYTES); + assert(file_init(&file2,TEST_FILE_2)==1); + assert(1==block_init(&(file2->root))); + file2->blocks = file2->root; memset(file2->root,2,crypto_hash_sha256_BYTES); + assert(file_init(&file3,TEST_FILE_3)==1); + assert(1==block_init(&(file3->root))); + file3->blocks = file3->root; memset(file3->root,3,crypto_hash_sha256_BYTES); + assert(file_init(&file4,TEST_FILE_4)==1); + assert(1==block_init(&(file4->root))); + file4->blocks = file4->root; memset(file4->root,4,crypto_hash_sha256_BYTES); assert(torrent_init(&torrent,16384)==1); diff --git a/test/unit/tree.tests.c b/test/unit/tree.tests.c index 8a1a89f..61c5b70 100644 --- a/test/unit/tree.tests.c +++ b/test/unit/tree.tests.c @@ -221,7 +221,9 @@ static void tree_bencode_basic_test() { assert(1==tree_init(&root)); assert(1==file_init(&file,fileA_path)); - memset(file->root,48,crypto_hash_sha256_BYTES); + assert(1==block_init(&(file->root))); + file->blocks = file->root; + memset(file->root->hash,48,crypto_hash_sha256_BYTES); file->size = 1024; assert(1==tree_add(root,file->path,file)); @@ -242,7 +244,9 @@ static void tree_bencode_length_basic_test() { assert(1==tree_init(&root)); assert(1==file_init(&file,fileA_path)); - memset(file->root,48,crypto_hash_sha256_BYTES); + assert(1==block_init(&(file->root))); + file->blocks = file->root; + memset(file->root->hash,48,crypto_hash_sha256_BYTES); file->size = 1024; assert(1==tree_add(root,file->path,file)); @@ -250,6 +254,8 @@ static void tree_bencode_length_basic_test() { assert(98==tree_bencode_length(root)); assert(1==file_init(&file,fileB_path)); + assert(1==block_init(&(file->root))); + file->blocks = file->root; memset(file->root,48,crypto_hash_sha256_BYTES); file->size = 512; -- 2.39.5