From: alex Date: Tue, 21 Dec 2021 07:01:07 +0000 (-0800) Subject: ... X-Git-Url: http://git.infiniteadaptability.org/?a=commitdiff_plain;h=615ba350ea4ac7b1c148bd5afc7894e2e8da9bc6;p=seeder ... --- diff --git a/src/tree.c b/src/tree.c index b660585..0da7b55 100644 --- a/src/tree.c +++ b/src/tree.c @@ -179,7 +179,6 @@ size_t tree_bencode_length(struct tree *tree) { i++; // : i += len; - i++; // { if(p->children!=NULL) { i += tree_bencode_length(p->children); } else { @@ -187,7 +186,7 @@ size_t tree_bencode_length(struct tree *tree) { i += bencode_size_int(p->file->size); } - i++; // } + p = p->next; } i++; // } diff --git a/test/unit/tree.tests.c b/test/unit/tree.tests.c index 30a4786..4e503ee 100644 --- a/test/unit/tree.tests.c +++ b/test/unit/tree.tests.c @@ -7,6 +7,7 @@ static char *create_random_path(); static void tree_add_basic_test(); static void tree_add_extended_test(); static void tree_bencode_basic_test(); +static void tree_bencode_length_basic_test(); static void tree_init_basic_test(); int main() { @@ -16,6 +17,7 @@ int main() { tree_add_basic_test(); tree_bencode_basic_test(); tree_add_extended_test(); + tree_bencode_length_basic_test(); clean_env(); @@ -186,6 +188,33 @@ static void tree_bencode_basic_test() { tree_free(root); } +static void tree_bencode_length_basic_test() { + struct tree *root; + struct file *file; + char fileA_path[] = "dir1/dir2/fileA.txt"; + char fileB_path[] = "test/hello/notadirectory.nope"; + + assert(1==tree_init(&root)); + + assert(1==file_init(&file,fileA_path)); + memset(file->root,48,crypto_hash_sha256_BYTES); + file->size = 1024; + + assert(1==tree_add(root,file->path,file)); + + assert(98==tree_bencode_length(root)); + + assert(1==file_init(&file,fileB_path)); + memset(file->root,48,crypto_hash_sha256_BYTES); + file->size = 512; + + assert(1==tree_add(root,file->path,file)); + + assert(204==tree_bencode_length(root)); + + tree_free(root); +} + static void tree_init_basic_test() { struct tree *p;