Changeset 13882


Ignore:
Timestamp:
Jan 27, 2013, 6:20:39 AM (8 years ago)
Author:
jordan
Message:

(libT) better implementation of move-test

File:
1 edited

Legend:

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

    r13879 r13882  
    3333}
    3434
     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)
    3543
    3644static int
    3745test_incomplete_dir_is_subdir_of_download_dir (void)
    3846{
    39   tr_file_index_t i;
    40   char * path;
    4147  char * incomplete_dir;
    42   char * expected_path;
    4348  tr_torrent * tor;
    4449  tr_completeness completeness;
     50  const tr_completeness completeness_unset = -1;
     51  const time_t deadline = time(NULL) + 5;
    4552
    4653  /* init the session */
     
    5057  tr_sessionSetIncompleteDirEnabled (session, true);
    5158
    52   /* init an incomplete torrent */
     59  /* init an incomplete torrent.
     60     the test zero_torrent will be missing its first piece */
    5361  tor = libtransmission_test_zero_torrent_init ();
    5462  libtransmission_test_zero_torrent_populate (tor, false);
    5563  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));
    6666  check_int_eq (tor->info.pieceSize, tr_torrentStat(tor)->leftUntilDone);
    6767
    6868  /* now finish writing it */
    6969  {
    70     //char * block;
    7170    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);
    7774
    78     tobuf = tr_new0 (char, tor->blockSize);
    79     buf = evbuffer_new ();
     75    completeness = completeness_unset;
     76    tr_torrentSetCompletenessCallback (tor, zeroes_completeness_func, &completeness);
    8077
    8178    tr_torGetPieceBlockRange (tor, 0, &first, &last);
    8279    for (offset=0, i=first; i<=last; ++i, offset+=tor->blockSize)
    8380      {
    84         evbuffer_add (buf, tobuf, tor->blockSize);
     81        evbuffer_add (buf, zero_block, tor->blockSize);
    8582        tr_cacheWriteBlock (session->cache, tor, 0, offset, tor->blockSize, buf);
    8683        tr_torrentGotBlock (tor, i);
    8784      }
     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));
    8893
    8994    evbuffer_free (buf);
    90     tr_free (tobuf);
     95    tr_free (zero_block);
    9196  }
    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     }
    10697
    10798
Note: See TracChangeset for help on using the changeset viewer.