]> infiniteadaptability.org Git - seeder/commitdiff
...
authoralex <[email protected]>
Tue, 21 Dec 2021 07:01:07 +0000 (23:01 -0800)
committeralex <[email protected]>
Tue, 21 Dec 2021 07:01:07 +0000 (23:01 -0800)
src/tree.c
test/unit/tree.tests.c

index b66058573b59420a060ed6e104e23dac2775e2f5..0da7b550abb0c95262546916f5446a6978bb1562 100644 (file)
@@ -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++; // }
index 30a4786f937b0885cabed22d323a1be182861d16..4e503eeeb97cb6cc487f4c04c112457c7455a05e 100644 (file)
@@ -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;