From beee17f9b23cb780db092a787765faeb4d8ceff1 Mon Sep 17 00:00:00 2001 From: Jordan Lee Date: Wed, 23 Jan 2013 22:10:40 +0000 Subject: [PATCH] (libT) more hacking on the rename + .part unit test --- libtransmission/rename-test.c | 114 +++++++++++++++++----------------- 1 file changed, 58 insertions(+), 56 deletions(-) diff --git a/libtransmission/rename-test.c b/libtransmission/rename-test.c index c0758dde0..21a164814 100644 --- a/libtransmission/rename-test.c +++ b/libtransmission/rename-test.c @@ -460,62 +460,54 @@ test_multifile_torrent (void) ***/ static void -create_zero_torrent_partial_contents (const char * top) +create_zero_torrent_partial_contents (tr_torrent * tor, bool incomplete) { - int i; - int n; - int rv; - FILE * fp; - char * path; - char buf[32]; + tr_file_index_t i; -fprintf (stderr, "top %s exists %d\n", top, (int)tr_fileExists(top,NULL)); + for (i=0; iinfo.fileCount; ++i) + { + uint64_t j; + FILE * fp; + char * path; + char * dirname; + const tr_file * file = &tor->info.files[i]; - errno = 0; - path = tr_buildPath (top, "files-filled-with-zeroes", NULL); - rv = tr_mkdirp (path, 0700); - assert (rv == 0); - assert (errno == 0); -fprintf (stderr, "%s:%d %s\n", __FILE__, __LINE__, path); -fprintf (stderr, "errno is %d (%s)\n", errno, tr_strerror (errno)); - tr_free (path); + path = tr_buildPath (tor->downloadDir, file->name, NULL); + dirname = tr_dirname (path); + tr_mkdirp (dirname, 0700); + fp = fopen (path, "wb+"); + for (j=0; jlength; ++j) + fputc ('\0', fp); + fclose (fp); + sync (); - n = 512; - tr_snprintf (buf, sizeof(buf), "%d", n); - path = tr_buildPath (top, "files-filled-with-zeroes", buf, NULL); -fprintf (stderr, "%s:%d %s\n", __FILE__, __LINE__, path); -fprintf (stderr, "errno is %d (%s)\n", errno, tr_strerror (errno)); - fp = fopen (path, "wb+"); - for (i=0; iinfo.fileCount); check_int_eq (totalSize, tor->info.totalSize); check_int_eq (pieceSize, tor->info.pieceSize); + check_int_eq (pieceCount, tor->info.pieceCount); check_streq ("files-filled-with-zeroes/1048576", tor->info.files[0].name); check_streq ("files-filled-with-zeroes/4096", tor->info.files[1].name); check_streq ("files-filled-with-zeroes/512", tor->info.files[2].name); - create_zero_torrent_partial_contents (tor->downloadDir); - verify_and_block_until_done (tor); - check (!tr_torrentIsSeed (tor)); + create_zero_torrent_partial_contents (tor, true); + fst = tr_torrentFiles (tor, NULL); + check_int_eq (length[0] - pieceSize, fst[0].bytesCompleted); + check_int_eq (length[1], fst[1].bytesCompleted); + check_int_eq (length[2], fst[2].bytesCompleted); + tr_torrentFilesFree (fst, tor->info.fileCount); st = tr_torrentStat (tor); check_int_eq (totalSize, st->sizeWhenDone); check_int_eq (pieceSize, st->leftUntilDone); + /*** + **** + ***/ + check_int_eq (0, torrentRenameAndWait (tor, "files-filled-with-zeroes", "foo")); check_int_eq (0, torrentRenameAndWait (tor, "foo/1048576", "bar")); strings[0] = "foo/bar"; @@ -579,8 +581,8 @@ int main (void) { int ret; - const testFunc tests[] = { test_single_filename_torrent, - test_multifile_torrent, + const testFunc tests[] = { //test_single_filename_torrent, + //test_multifile_torrent, test_partial_file }; verbose = 1;