#include<torrent.h>
int main();
-static void torrent_init_basic_test();
static void torrent_add_basic_test();
+static void torrent_init_basic_test();
+static void torrent_magnet_basic_test();
int main() {
setup_env();
torrent_init_basic_test();
torrent_add_basic_test();
+ torrent_magnet_basic_test();
clean_env();
static void torrent_add_basic_test() {
struct torrent *torrent;
- struct file *file1, *file2, *file3, *file4;
+ struct file *file1, *file2, *file3, *file4, *p;
+
+// for(size_t i=0;i<100;i++) {
+ assert(file_init(&file1,TEST_FILE_1)==1);
+ memset(file1->root,1,crypto_hash_sha256_BYTES);
+ assert(file_init(&file2,TEST_FILE_2)==1);
+ memset(file2->root,2,crypto_hash_sha256_BYTES);
+ assert(file_init(&file3,TEST_FILE_3)==1);
+ memset(file3->root,3,crypto_hash_sha256_BYTES);
+ assert(file_init(&file4,TEST_FILE_4)==1);
+ memset(file4->root,4,crypto_hash_sha256_BYTES);
+
+ assert(torrent_init(&torrent,TEST_DIRECTORY,TEST_DIRECTORY,16384)==1);
+
+ assert(torrent_add(torrent,file1)==1);
+ assert(torrent_add(torrent,file2)==1);
+ assert(torrent_add(torrent,file3)==1);
+ assert(torrent_add(torrent,file4)==1);
+
+ assert(torrent->tree->entries->file==file3);
+ assert(torrent->tree->entries->next->file==file4);
+ assert(torrent->tree->entries->next->next->file==file1);
+ assert(torrent->tree->entries->next->next->next->file==file2);
+
+ p = hashmap_find(torrent->files,file1->path,strlen(file1->path));
+ assert(p==file1);
+ p = hashmap_find(torrent->files,file1->root,crypto_hash_sha256_BYTES);
+ assert(p==file1);
+
+ p = hashmap_find(torrent->files,file2->path,strlen(file2->path));
+ assert(p==file2);
+ p = hashmap_find(torrent->files,file2->root,crypto_hash_sha256_BYTES);
+ assert(p==file2);
+
+ p = hashmap_find(torrent->files,file3->path,strlen(file3->path));
+ assert(p==file3);
+ p = hashmap_find(torrent->files,file3->root,crypto_hash_sha256_BYTES);
+ assert(p==file3);
+
+ p = hashmap_find(torrent->files,file4->path,strlen(file4->path));
+ assert(p==file4);
+ p = hashmap_find(torrent->files,file4->root,crypto_hash_sha256_BYTES);
+ assert(p==file4);
+
+ torrent_free(torrent);
+
+ reset_env();
+// }
+}
+
+static void torrent_init_basic_test() {
+ struct torrent *torrent;
+
+ assert(torrent_init(&torrent,NULL,NULL,0)<0);
+ assert(torrent_init(&torrent,"src",NULL,0)<0);
+ assert(torrent_init(&torrent,"src","src",1000)<0);
+
+ assert(torrent_init(&torrent,"src","src",16384)==1);
+ torrent_free(torrent);
+}
+
+static void torrent_magnet_basic_test() {
+ struct torrent *torrent;
+ struct file *file1, *file2;
+ char *p;
assert(file_init(&file1,TEST_FILE_1)==1);
memset(file1->root,1,crypto_hash_sha256_BYTES);
assert(file_init(&file2,TEST_FILE_2)==1);
memset(file2->root,2,crypto_hash_sha256_BYTES);
- assert(file_init(&file3,TEST_FILE_3)==1);
- memset(file3->root,3,crypto_hash_sha256_BYTES);
- assert(file_init(&file4,TEST_FILE_4)==1);
- memset(file4->root,4,crypto_hash_sha256_BYTES);
-
+
assert(torrent_init(&torrent,TEST_DIRECTORY,TEST_DIRECTORY,16384)==1);
-
- memset(torrent->files->key,0,crypto_shorthash_KEYBYTES);
-
+
assert(torrent_add(torrent,file1)==1);
assert(torrent_add(torrent,file2)==1);
- assert(torrent_add(torrent,file3)==1);
- assert(torrent_add(torrent,file4)==1);
-
- assert(torrent->tree->entries->file==file3);
- assert(torrent->tree->entries->next->file==file4);
- assert(torrent->tree->entries->next->next->file==file1);
- assert(torrent->tree->entries->next->next->next->file==file2);
+
+ p = torrent_magnet(torrent);
+ assert(p!=NULL);
- assert(0);
+ assert(strcmp(p,"magnet:?xt=urn:btmh:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&dn=" TEST_DIRECTORY)==0);
+ free(p);
torrent_free(torrent);
reset_env();
}
-
-static void torrent_init_basic_test() {
- struct torrent *torrent;
-
- assert(torrent_init(&torrent,NULL,NULL,0)<0);
- assert(torrent_init(&torrent,"src",NULL,0)<0);
- assert(torrent_init(&torrent,"src","src",1000)<0);
-
- assert(torrent_init(&torrent,"src","src",16384)==1);
- torrent_free(torrent);
-}