]> infiniteadaptability.org Git - seeder/commitdiff
...
authoralex <[email protected]>
Fri, 4 Mar 2022 02:21:44 +0000 (18:21 -0800)
committeralex <[email protected]>
Fri, 4 Mar 2022 02:21:44 +0000 (18:21 -0800)
test/unit/test_macros.h
test/unit/torrent.tests.c
test/unit/tree.tests.c

index 3b52da65f91306e604632e5f453c2b026aa40756..fdfe3ea51238a9d9b17df032712ca085d5112969 100644 (file)
        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:
index 9fc62dbed80e8242b416fc8ff5fa7ad0be347b02..211276b5b635153e0c8f9fbfdee09cd8a53939d3 100644 (file)
@@ -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);
index 8a1a89fd08527395e9691d9be51aedc7eb4f80d4..61c5b705c39d245c71a35250bcf3147595488fd9 100644 (file)
@@ -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;