Changeset 13882
- Timestamp:
- Jan 27, 2013, 6:20:39 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/move-test.c
r13879 r13882 33 33 } 34 34 35 #define check_file_location(tor, i, expected_path) \ 36 do { \ 37 char * path = tr_torrentFindFile (tor, i); \ 38 char * expected = expected_path; \ 39 check_streq (expected, path); \ 40 tr_free (expected); \ 41 tr_free (path); \ 42 } while (0) 35 43 36 44 static int 37 45 test_incomplete_dir_is_subdir_of_download_dir (void) 38 46 { 39 tr_file_index_t i;40 char * path;41 47 char * incomplete_dir; 42 char * expected_path;43 48 tr_torrent * tor; 44 49 tr_completeness completeness; 50 const tr_completeness completeness_unset = -1; 51 const time_t deadline = time(NULL) + 5; 45 52 46 53 /* init the session */ … … 50 57 tr_sessionSetIncompleteDirEnabled (session, true); 51 58 52 /* init an incomplete torrent */ 59 /* init an incomplete torrent. 60 the test zero_torrent will be missing its first piece */ 53 61 tor = libtransmission_test_zero_torrent_init (); 54 62 libtransmission_test_zero_torrent_populate (tor, false); 55 63 check (tr_torrentStat(tor)->leftUntilDone == tor->info.pieceSize); 56 path = tr_torrentFindFile (tor, 0); 57 expected_path = tr_strdup_printf ("%s/%s.part", incomplete_dir, tor->info.files[0].name); 58 check_streq (expected_path, path); 59 tr_free (expected_path); 60 tr_free (path); 61 path = tr_torrentFindFile (tor, 1); 62 expected_path = tr_buildPath (incomplete_dir, tor->info.files[1].name, NULL); 63 check_streq (expected_path, path); 64 tr_free (expected_path); 65 tr_free (path); 64 check_file_location (tor, 0, tr_strdup_printf("%s/%s.part", incomplete_dir, tor->info.files[0].name)); 65 check_file_location (tor, 1, tr_buildPath(incomplete_dir, tor->info.files[1].name, NULL)); 66 66 check_int_eq (tor->info.pieceSize, tr_torrentStat(tor)->leftUntilDone); 67 67 68 68 /* now finish writing it */ 69 69 { 70 //char * block;71 70 uint32_t offset; 72 tr_block_index_t i; 73 tr_block_index_t first; 74 tr_block_index_t last; 75 char * tobuf; 76 struct evbuffer * buf; 71 tr_block_index_t first, last, i; 72 struct evbuffer * buf = evbuffer_new (); 73 char * zero_block = tr_new0 (char, tor->blockSize); 77 74 78 tobuf = tr_new0 (char, tor->blockSize);79 buf = evbuffer_new ();75 completeness = completeness_unset; 76 tr_torrentSetCompletenessCallback (tor, zeroes_completeness_func, &completeness); 80 77 81 78 tr_torGetPieceBlockRange (tor, 0, &first, &last); 82 79 for (offset=0, i=first; i<=last; ++i, offset+=tor->blockSize) 83 80 { 84 evbuffer_add (buf, tobuf, tor->blockSize);81 evbuffer_add (buf, zero_block, tor->blockSize); 85 82 tr_cacheWriteBlock (session->cache, tor, 0, offset, tor->blockSize, buf); 86 83 tr_torrentGotBlock (tor, i); 87 84 } 85 sync (); 86 87 tr_torrentVerify (tor); 88 while ((completeness==completeness_unset) && (time(NULL)<=deadline)) 89 tr_wait_msec (50); 90 check_int_eq (TR_SEED, completeness); 91 for (i=0; i<tor->info.fileCount; ++i) 92 check_file_location (tor, i, tr_buildPath (downloadDir, tor->info.files[i].name, NULL)); 88 93 89 94 evbuffer_free (buf); 90 tr_free ( tobuf);95 tr_free (zero_block); 91 96 } 92 93 completeness = -1;94 tr_torrentSetCompletenessCallback (tor, zeroes_completeness_func, &completeness);95 tr_torrentRecheckCompleteness (tor);96 check_int_eq (TR_SEED, completeness);97 sync ();98 for (i=0; i<tor->info.fileCount; ++i)99 {100 path = tr_torrentFindFile (tor, i);101 expected_path = tr_buildPath (downloadDir, tor->info.files[i].name, NULL);102 check_streq (expected_path, path);103 tr_free (expected_path);104 tr_free (path);105 }106 97 107 98
Note: See TracChangeset
for help on using the changeset viewer.