Changeset 13848


Ignore:
Timestamp:
Jan 23, 2013, 8:23:37 PM (8 years ago)
Author:
jordan
Message:

(libT) #1220 'change file and folder names': add a unit test for the r13837 bugfix of .part files + tr_torrentRenamePath()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/rename-test.c

    r13836 r13848  
    169169    "f6LvqLXBVvSHqCk6Nzpwcml2YXRlaTBlZWU=");
    170170  check (tr_isTorrent (tor));
    171   tr_ctorFree (ctor);
    172171
    173172  /* sanity check the info */
     
    241240
    242241  /* cleanup */
     242  tr_ctorFree (ctor);
    243243  tr_torrentRemove (tor, false, NULL);
    244244  return 0;
     
    453453***/
    454454
     455static void
     456create_zero_torrent_partial_contents (const char * top)
     457{
     458  int i;
     459  int n;
     460  FILE * fp;
     461  char * path;
     462  char buf[32];
     463
     464  path = tr_buildPath (top, "files-filled-with-zeroes", NULL);
     465  tr_mkdirp (path, 0700);
     466  tr_free (path);
     467
     468  n = 512;
     469  tr_snprintf (buf, sizeof(buf), "%d", n);
     470  path = tr_buildPath (top, "files-filled-with-zeroes", buf, NULL);
     471  fp = fopen (path, "wb+");
     472  for (i=0; i<n; ++i)
     473    fputc ('\0', fp);
     474  fclose (fp);
     475  tr_free (path);
     476
     477  n = 4096;
     478  tr_snprintf (buf, sizeof(buf), "%d", n);
     479  path = tr_buildPath (top, "files-filled-with-zeroes", buf, NULL);
     480  fp = fopen (path, "wb+");
     481  for (i=0; i<n; ++i)
     482    fputc ('\0', fp);
     483  fclose (fp);
     484  tr_free (path);
     485
     486  n = 1048576;
     487  tr_snprintf (buf, sizeof(buf), "%d.part", n);
     488  path = tr_buildPath (top, "files-filled-with-zeroes", buf, NULL);
     489  fp = fopen (path, "wb+");
     490  n -= 100;
     491  for (i=0; i<n; ++i)
     492    fputc ('\0', fp);
     493  fclose (fp);
     494  tr_free (path);
     495
     496  sync ();
     497}
     498
     499static int
     500test_partial_file (void)
     501{
     502  tr_file_index_t i;
     503  tr_torrent * tor;
     504  const tr_stat * st;
     505  const uint32_t pieceSize = 32768;
     506  const uint64_t totalSize = 1048576 + 4096 + 512;
     507  const char * strings[3];
     508
     509  /***
     510  ****  create our test torrent with an incomplete .part file
     511  ***/
     512
     513  tor = libtransmission_test_zero_torrent_init ();
     514  check_int_eq (3, tor->info.fileCount);
     515  check_int_eq (totalSize, tor->info.totalSize);
     516  check_int_eq (pieceSize, tor->info.pieceSize);
     517  check_streq ("files-filled-with-zeroes/1048576", tor->info.files[0].name);
     518  check_streq ("files-filled-with-zeroes/4096",    tor->info.files[1].name);
     519  check_streq ("files-filled-with-zeroes/512",     tor->info.files[2].name);
     520
     521  create_zero_torrent_partial_contents (tor->downloadDir);
     522  verify_and_block_until_done (tor);
     523  check (!tr_torrentIsSeed (tor));
     524  st = tr_torrentStat (tor);
     525  check_int_eq (totalSize, st->sizeWhenDone);
     526  check_int_eq (pieceSize, st->leftUntilDone);
     527
     528  check_int_eq (0, torrentRenameAndWait (tor, "files-filled-with-zeroes", "foo"));
     529  check_int_eq (0, torrentRenameAndWait (tor, "foo/1048576", "bar"));
     530  strings[0] = "foo/bar";
     531  strings[1] = "foo/4096";
     532  strings[2] = "foo/512";
     533  for (i=0; i<3; ++i)
     534    {
     535      check_streq (strings[i], tor->info.files[i].name);
     536    }
     537
     538  strings[0] = "foo/bar.part";
     539  for (i=0; i<3; ++i)
     540    {
     541      char * expected = tr_buildPath (tor->downloadDir, strings[i], NULL);
     542      char * path = tr_torrentFindFile (tor, i);
     543      check_streq (expected, path);
     544      tr_free (path);
     545      tr_free (expected);
     546    }
     547
     548  tr_torrentRemove (tor, false, NULL);
     549  return 0;
     550}
     551
     552/***
     553****
     554***/
     555
    455556int
    456557main (void)
     
    458559  int ret;
    459560  const testFunc tests[] = { test_single_filename_torrent,
    460                              test_multifile_torrent };
     561                             test_multifile_torrent,
     562                             test_partial_file };
    461563
    462564  libtransmission_test_session_init ();
Note: See TracChangeset for help on using the changeset viewer.