Changeset 13853
- Timestamp:
- Jan 23, 2013, 10:10:40 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/rename-test.c
r13852 r13853 461 461 462 462 static void 463 create_zero_torrent_partial_contents (const char * top) 464 { 465 int i; 466 int n; 467 int rv; 468 FILE * fp; 469 char * path; 470 char buf[32]; 471 472 fprintf (stderr, "top %s exists %d\n", top, (int)tr_fileExists(top,NULL)); 473 474 errno = 0; 475 path = tr_buildPath (top, "files-filled-with-zeroes", NULL); 476 rv = tr_mkdirp (path, 0700); 477 assert (rv == 0); 478 assert (errno == 0); 479 fprintf (stderr, "%s:%d %s\n", __FILE__, __LINE__, path); 480 fprintf (stderr, "errno is %d (%s)\n", errno, tr_strerror (errno)); 481 tr_free (path); 482 483 n = 512; 484 tr_snprintf (buf, sizeof(buf), "%d", n); 485 path = tr_buildPath (top, "files-filled-with-zeroes", buf, NULL); 486 fprintf (stderr, "%s:%d %s\n", __FILE__, __LINE__, path); 487 fprintf (stderr, "errno is %d (%s)\n", errno, tr_strerror (errno)); 488 fp = fopen (path, "wb+"); 489 for (i=0; i<n; ++i) 490 fputc ('\0', fp); 491 fclose (fp); 492 tr_free (path); 493 494 n = 4096; 495 tr_snprintf (buf, sizeof(buf), "%d", n); 496 path = tr_buildPath (top, "files-filled-with-zeroes", buf, NULL); 497 fprintf (stderr, "%s\n", path); 498 fprintf (stderr, "errno is %d (%s)\n", errno, tr_strerror (errno)); 499 fp = fopen (path, "wb+"); 500 for (i=0; i<n; ++i) 501 fputc ('\0', fp); 502 fclose (fp); 503 tr_free (path); 504 505 n = 1048576; 506 tr_snprintf (buf, sizeof(buf), "%d.part", n); 507 path = tr_buildPath (top, "files-filled-with-zeroes", buf, NULL); 508 fprintf (stderr, "%s\n", path); 509 fprintf (stderr, "errno is %d (%s)\n", errno, tr_strerror (errno)); 510 fp = fopen (path, "wb+"); 511 n -= 100; 512 for (i=0; i<n; ++i) 513 fputc ('\0', fp); 514 fclose (fp); 515 tr_free (path); 516 fprintf (stderr, "errno is %d (%s)\n", errno, tr_strerror (errno)); 517 518 sync (); 463 create_zero_torrent_partial_contents (tr_torrent * tor, bool incomplete) 464 { 465 tr_file_index_t i; 466 467 for (i=0; i<tor->info.fileCount; ++i) 468 { 469 uint64_t j; 470 FILE * fp; 471 char * path; 472 char * dirname; 473 const tr_file * file = &tor->info.files[i]; 474 475 path = tr_buildPath (tor->downloadDir, file->name, NULL); 476 dirname = tr_dirname (path); 477 tr_mkdirp (dirname, 0700); 478 fp = fopen (path, "wb+"); 479 for (j=0; j<file->length; ++j) 480 fputc ('\0', fp); 481 fclose (fp); 482 sync (); 483 484 tr_free (dirname); 485 tr_free (path); 486 } 487 488 verify_and_block_until_done (tor); 489 assert (tr_torrentIsSeed (tor)); 490 491 if (incomplete) 492 { 493 FILE * fp; 494 char * oldpath = tr_torrentFindFile (tor, 0); 495 char * newpath = tr_strdup_printf ("%s.part", oldpath); 496 497 rename (oldpath, newpath); 498 499 /* invalidate one piece */ 500 fp = fopen (newpath, "rb+"); 501 fputc ('\1', fp); 502 fclose (fp); 503 sync (); 504 505 tr_free (newpath); 506 tr_free (oldpath); 507 508 verify_and_block_until_done (tor); 509 assert (!tr_torrentIsSeed (tor)); 510 } 519 511 } 520 512 … … 525 517 tr_torrent * tor; 526 518 const tr_stat * st; 519 tr_file_stat * fst; 520 const uint32_t pieceCount = 33; 527 521 const uint32_t pieceSize = 32768; 528 const uint64_t totalSize = 1048576 + 4096 + 512; 522 const uint32_t length[] = { 1048576, 4096, 512 }; 523 const uint64_t totalSize = length[0] + length[1] + length[2]; 529 524 const char * strings[3]; 530 525 … … 534 529 535 530 tor = libtransmission_test_zero_torrent_init (); 536 check_int_eq (3, tor->info.fileCount);537 531 check_int_eq (totalSize, tor->info.totalSize); 538 532 check_int_eq (pieceSize, tor->info.pieceSize); 533 check_int_eq (pieceCount, tor->info.pieceCount); 539 534 check_streq ("files-filled-with-zeroes/1048576", tor->info.files[0].name); 540 535 check_streq ("files-filled-with-zeroes/4096", tor->info.files[1].name); 541 536 check_streq ("files-filled-with-zeroes/512", tor->info.files[2].name); 542 537 543 create_zero_torrent_partial_contents (tor->downloadDir); 544 verify_and_block_until_done (tor); 545 check (!tr_torrentIsSeed (tor)); 538 create_zero_torrent_partial_contents (tor, true); 539 fst = tr_torrentFiles (tor, NULL); 540 check_int_eq (length[0] - pieceSize, fst[0].bytesCompleted); 541 check_int_eq (length[1], fst[1].bytesCompleted); 542 check_int_eq (length[2], fst[2].bytesCompleted); 543 tr_torrentFilesFree (fst, tor->info.fileCount); 546 544 st = tr_torrentStat (tor); 547 545 check_int_eq (totalSize, st->sizeWhenDone); 548 546 check_int_eq (pieceSize, st->leftUntilDone); 547 548 /*** 549 **** 550 ***/ 549 551 550 552 check_int_eq (0, torrentRenameAndWait (tor, "files-filled-with-zeroes", "foo")); … … 580 582 { 581 583 int ret; 582 const testFunc tests[] = { test_single_filename_torrent,583 test_multifile_torrent,584 const testFunc tests[] = { //test_single_filename_torrent, 585 //test_multifile_torrent, 584 586 test_partial_file }; 585 587
Note: See TracChangeset
for help on using the changeset viewer.