source: trunk/libtransmission/rename-test.c

Last change on this file was 14721, checked in by jordan, 5 years ago

fix a handful of minor compiler warnings, mostly in the unit tests, eg field width shortening or implicit signed/unsigned conversions

  • Property svn:keywords set to Date Rev Author Id
File size: 18.7 KB
Line 
1/*
2 * This file Copyright (C) 2013-2014 Mnemosyne LLC
3 *
4 * It may be used under the GNU GPL versions 2 or 3
5 * or any future license endorsed by Mnemosyne LLC.
6 *
7 * $Id: rename-test.c 14721 2016-03-29 03:04:54Z mikedld $
8 */
9
10#include <assert.h>
11#include <errno.h>
12#include <stdio.h> /* fopen() */
13#include <string.h> /* strcmp() */
14
15#include "transmission.h"
16#include "crypto-utils.h"
17#include "file.h"
18#include "resume.h"
19#include "torrent.h" /* tr_isTorrent() */
20#include "variant.h"
21
22#include "libtransmission-test.h"
23
24/***
25****
26***/
27
28static tr_session * session = NULL;
29
30#define check_have_none(tor, totalSize) \
31  do { \
32    const tr_stat * tst = tr_torrentStat(tor); \
33    check_int_eq (TR_STATUS_STOPPED, tst->activity); \
34    check_int_eq (TR_STAT_OK, tst->error); \
35    check_uint_eq (totalSize, tst->sizeWhenDone); \
36    check_uint_eq (totalSize, tst->leftUntilDone); \
37    check_uint_eq (totalSize, tor->info.totalSize); \
38    check_uint_eq (0, tst->haveValid); \
39  } while (0)
40
41static bool
42testFileExistsAndConsistsOfThisString (const tr_torrent * tor, tr_file_index_t fileIndex, const char * str)
43{
44  char * path;
45  const size_t str_len = strlen (str);
46  bool success = false;
47
48  path = tr_torrentFindFile (tor, fileIndex);
49  if (path != NULL)
50    {
51      uint8_t * contents;
52      size_t contents_len;
53
54      assert (tr_sys_path_exists (path, NULL));
55
56      contents = tr_loadFile (path, &contents_len, NULL);
57
58      success = contents != NULL
59             && str_len == contents_len
60             && memcmp (contents, str, contents_len) == 0;
61
62      tr_free (contents);
63      tr_free (path);
64    }
65
66  return success;
67}
68
69static void
70onRenameDone (tr_torrent * tor UNUSED, const char * oldpath UNUSED, const char * newname UNUSED, int error, void * user_data)
71{
72  *(int*)user_data = error;
73}
74
75static int
76torrentRenameAndWait (tr_torrent * tor,
77                      const char * oldpath,
78                      const char * newname)
79{
80  int error = -1;
81  tr_torrentRenamePath (tor, oldpath, newname, onRenameDone, &error);
82  do {
83    tr_wait_msec (10);
84  } while (error == -1);
85  return error;
86}
87
88/***
89****
90***/
91
92static void
93create_single_file_torrent_contents (const char * top)
94{
95  char * path = tr_buildPath (top, "hello-world.txt", NULL);
96  libtest_create_file_with_string_contents (path, "hello, world!\n");
97  tr_free (path);
98}
99
100static tr_torrent *
101create_torrent_from_base64_metainfo (tr_ctor * ctor, const char * metainfo_base64)
102{
103  int err;
104  size_t metainfo_len;
105  char * metainfo;
106  tr_torrent * tor;
107
108  /* create the torrent ctor */
109  metainfo = tr_base64_decode_str (metainfo_base64, &metainfo_len);
110  assert (metainfo != NULL);
111  assert (metainfo_len > 0);
112  tr_ctorSetMetainfo (ctor, (uint8_t*)metainfo, metainfo_len);
113  tr_ctorSetPaused (ctor, TR_FORCE, true);
114
115  /* create the torrent */
116  err = 0;
117  tor = tr_torrentNew (ctor, &err, NULL);
118  assert (!err);
119
120  /* cleanup */
121  tr_free (metainfo);
122  return tor;
123}
124
125static int
126test_single_filename_torrent (void)
127{
128  uint64_t loaded;
129  tr_torrent * tor;
130  char * tmpstr;
131  const size_t totalSize = 14;
132  tr_ctor * ctor;
133  const tr_stat * st;
134
135  /* this is a single-file torrent whose file is hello-world.txt, holding the string "hello, world!" */
136  ctor = tr_ctorNew (session);
137  tor = create_torrent_from_base64_metainfo (ctor,
138    "ZDEwOmNyZWF0ZWQgYnkyNTpUcmFuc21pc3Npb24vMi42MSAoMTM0MDcpMTM6Y3JlYXRpb24gZGF0"
139    "ZWkxMzU4NTQ5MDk4ZTg6ZW5jb2Rpbmc1OlVURi04NDppbmZvZDY6bGVuZ3RoaTE0ZTQ6bmFtZTE1"
140    "OmhlbGxvLXdvcmxkLnR4dDEyOnBpZWNlIGxlbmd0aGkzMjc2OGU2OnBpZWNlczIwOukboJcrkFUY"
141    "f6LvqLXBVvSHqCk6Nzpwcml2YXRlaTBlZWU=");
142  check (tr_isTorrent (tor));
143
144  /* sanity check the info */
145  check_int_eq (1, tor->info.fileCount);
146  check_streq ("hello-world.txt", tor->info.files[0].name);
147  check (!tor->info.files[0].is_renamed);
148
149  /* sanity check the (empty) stats */
150  libttest_blockingTorrentVerify (tor);
151  check_have_none (tor, totalSize);
152
153  create_single_file_torrent_contents (tor->currentDir);
154
155  /* sanity check the stats again, now that we've added the file */
156  libttest_blockingTorrentVerify (tor);
157  st = tr_torrentStat (tor);
158  check_int_eq (TR_STATUS_STOPPED, st->activity);
159  check_int_eq (TR_STAT_OK, st->error);
160  check_uint_eq (0, st->leftUntilDone);
161  check_uint_eq (0, st->haveUnchecked);
162  check_uint_eq (0, st->desiredAvailable);
163  check_uint_eq (totalSize, st->sizeWhenDone);
164  check_uint_eq (totalSize, st->haveValid);
165
166  /**
167  ***  okay! we've finally put together all the scaffolding to test
168  ***  renaming a single-file torrent
169  **/
170
171  /* confirm that bad inputs get caught */
172
173  check_int_eq (EINVAL, torrentRenameAndWait (tor, "hello-world.txt", NULL));
174  check_int_eq (EINVAL, torrentRenameAndWait (tor, "hello-world.txt", ""));
175  check_int_eq (EINVAL, torrentRenameAndWait (tor, "hello-world.txt", "."));
176  check_int_eq (EINVAL, torrentRenameAndWait (tor, "hello-world.txt", ".."));
177  check_int_eq (0, torrentRenameAndWait (tor, "hello-world.txt", "hello-world.txt"));
178  check_int_eq (EINVAL, torrentRenameAndWait (tor, "hello-world.txt", "hello/world.txt"));
179
180  check (!tor->info.files[0].is_renamed);
181  check_streq ("hello-world.txt", tor->info.files[0].name);
182
183  /***
184  ****  Now try a rename that should succeed
185  ***/
186
187  tmpstr = tr_buildPath (tor->currentDir, "hello-world.txt", NULL);
188  check (tr_sys_path_exists (tmpstr, NULL));
189  check_streq ("hello-world.txt", tr_torrentName(tor));
190  check_int_eq (0, torrentRenameAndWait (tor, tor->info.name, "foobar"));
191  check (!tr_sys_path_exists (tmpstr, NULL)); /* confirm the old filename can't be found */
192  tr_free (tmpstr);
193  check (tor->info.files[0].is_renamed); /* confirm the file's 'renamed' flag is set */
194  check_streq ("foobar", tr_torrentName(tor)); /* confirm the torrent's name is now 'foobar' */
195  check_streq ("foobar", tor->info.files[0].name); /* confirm the file's name is now 'foobar' in our struct */
196  check (strstr (tor->info.torrent, "foobar") == NULL); /* confirm the name in the .torrent file hasn't changed */
197  tmpstr = tr_buildPath (tor->currentDir, "foobar", NULL);
198  check (tr_sys_path_exists (tmpstr, NULL)); /* confirm the file's name is now 'foobar' on the disk */
199  tr_free (tmpstr);
200  check (testFileExistsAndConsistsOfThisString (tor, 0, "hello, world!\n")); /* confirm the contents are right */
201
202  /* (while it's renamed: confirm that the .resume file remembers the changes) */
203  tr_torrentSaveResume (tor);
204  libttest_sync ();
205  loaded = tr_torrentLoadResume (tor, ~0, ctor);
206  check_streq ("foobar", tr_torrentName(tor));
207  check ((loaded & TR_FR_NAME) != 0);
208
209  /***
210  ****  ...and rename it back again
211  ***/
212
213  tmpstr = tr_buildPath (tor->currentDir, "foobar", NULL);
214  check (tr_sys_path_exists (tmpstr, NULL));
215  check_int_eq (0, torrentRenameAndWait (tor, "foobar", "hello-world.txt"));
216  check (!tr_sys_path_exists (tmpstr, NULL));
217  check (tor->info.files[0].is_renamed);
218  check_streq ("hello-world.txt", tor->info.files[0].name);
219  check_streq ("hello-world.txt", tr_torrentName(tor));
220  tr_free (tmpstr);
221  check (testFileExistsAndConsistsOfThisString (tor, 0, "hello, world!\n"));
222
223  /* cleanup */
224  tr_ctorFree (ctor);
225  tr_torrentRemove (tor, false, NULL);
226  return 0;
227}
228
229/***
230****
231****
232****
233***/
234
235static void
236create_multifile_torrent_contents (const char * top)
237{
238  char * path;
239
240  path = tr_buildPath (top, "Felidae", "Felinae", "Acinonyx", "Cheetah", "Chester", NULL);
241  libtest_create_file_with_string_contents (path, "It ain't easy bein' cheesy.\n");
242  tr_free (path);
243
244  path = tr_buildPath (top, "Felidae", "Pantherinae", "Panthera", "Tiger", "Tony", NULL);
245  libtest_create_file_with_string_contents (path, "They’re Grrrrreat!\n");
246  tr_free (path);
247
248  path = tr_buildPath (top, "Felidae", "Felinae", "Felis", "catus", "Kyphi", NULL);
249  libtest_create_file_with_string_contents (path, "Inquisitive\n");
250  tr_free (path);
251
252  path = tr_buildPath (top, "Felidae", "Felinae", "Felis", "catus", "Saffron", NULL);
253  libtest_create_file_with_string_contents (path, "Tough\n");
254  tr_free (path);
255
256  libttest_sync ();
257}
258
259static int
260test_multifile_torrent (void)
261{
262  tr_file_index_t i;
263  uint64_t loaded;
264  tr_torrent * tor;
265  tr_ctor * ctor;
266  char * str;
267  char * tmp;
268  static const size_t totalSize = 67;
269  const tr_stat * st;
270  const tr_file * files;
271  const char * strings[4];
272  const char * expected_files[4] = {
273    "Felidae/Felinae/Acinonyx/Cheetah/Chester",
274    "Felidae/Felinae/Felis/catus/Kyphi",
275    "Felidae/Felinae/Felis/catus/Saffron",
276    "Felidae/Pantherinae/Panthera/Tiger/Tony"
277  };
278  const char * expected_contents[4] = {
279   "It ain't easy bein' cheesy.\n",
280   "Inquisitive\n",
281   "Tough\n",
282   "They’re Grrrrreat!\n"
283  };
284
285  ctor = tr_ctorNew (session);
286  tor = create_torrent_from_base64_metainfo (ctor,
287    "ZDEwOmNyZWF0ZWQgYnkyNTpUcmFuc21pc3Npb24vMi42MSAoMTM0MDcpMTM6Y3JlYXRpb24gZGF0"
288    "ZWkxMzU4NTU1NDIwZTg6ZW5jb2Rpbmc1OlVURi04NDppbmZvZDU6ZmlsZXNsZDY6bGVuZ3RoaTI4"
289    "ZTQ6cGF0aGw3OkZlbGluYWU4OkFjaW5vbnl4NzpDaGVldGFoNzpDaGVzdGVyZWVkNjpsZW5ndGhp"
290    "MTJlNDpwYXRobDc6RmVsaW5hZTU6RmVsaXM1OmNhdHVzNTpLeXBoaWVlZDY6bGVuZ3RoaTZlNDpw"
291    "YXRobDc6RmVsaW5hZTU6RmVsaXM1OmNhdHVzNzpTYWZmcm9uZWVkNjpsZW5ndGhpMjFlNDpwYXRo"
292    "bDExOlBhbnRoZXJpbmFlODpQYW50aGVyYTU6VGlnZXI0OlRvbnllZWU0Om5hbWU3OkZlbGlkYWUx"
293    "MjpwaWVjZSBsZW5ndGhpMzI3NjhlNjpwaWVjZXMyMDp27buFkmy8ICfNX4nsJmt0Ckm2Ljc6cHJp"
294    "dmF0ZWkwZWVl");
295  check (tr_isTorrent (tor));
296  files = tor->info.files;
297
298  /* sanity check the info */
299  check_streq (tor->info.name, "Felidae");
300  check_uint_eq (totalSize, tor->info.totalSize);
301  check_uint_eq (4, tor->info.fileCount);
302  for (i=0; i<4; ++i)
303    check_streq (expected_files[i], files[i].name);
304
305  /* sanity check the (empty) stats */
306  libttest_blockingTorrentVerify (tor);
307  check_have_none (tor, totalSize);
308
309  /* build the local data */
310  create_multifile_torrent_contents (tor->currentDir);
311
312  /* sanity check the (full) stats */
313  libttest_blockingTorrentVerify (tor);
314  st = tr_torrentStat (tor);
315  check_int_eq (TR_STATUS_STOPPED, st->activity);
316  check_int_eq (TR_STAT_OK, st->error);
317  check_uint_eq (0, st->leftUntilDone);
318  check_uint_eq (0, st->haveUnchecked);
319  check_uint_eq (0, st->desiredAvailable);
320  check_uint_eq (totalSize, st->sizeWhenDone);
321  check_uint_eq (totalSize, st->haveValid);
322
323
324  /**
325  ***  okay! let's test renaming.
326  **/
327
328  /* rename a leaf... */
329  check_int_eq (0, torrentRenameAndWait (tor, "Felidae/Felinae/Felis/catus/Kyphi", "placeholder"));
330  check_streq (files[1].name, "Felidae/Felinae/Felis/catus/placeholder");
331  check (testFileExistsAndConsistsOfThisString (tor, 1, "Inquisitive\n"));
332
333  /* ...and back again */
334  check_int_eq (0, torrentRenameAndWait (tor, "Felidae/Felinae/Felis/catus/placeholder", "Kyphi"));
335  check_streq (files[1].name, "Felidae/Felinae/Felis/catus/Kyphi");
336  testFileExistsAndConsistsOfThisString (tor, 1, "Inquisitive\n");
337
338  /* rename a branch... */
339  check_int_eq (0, torrentRenameAndWait (tor, "Felidae/Felinae/Felis/catus", "placeholder"));
340  check_streq (expected_files[0],                           files[0].name);
341  check_streq ("Felidae/Felinae/Felis/placeholder/Kyphi",   files[1].name);
342  check_streq ("Felidae/Felinae/Felis/placeholder/Saffron", files[2].name);
343  check_streq (expected_files[3],                           files[3].name);
344  check (testFileExistsAndConsistsOfThisString (tor, 1, expected_contents[1]));
345  check (testFileExistsAndConsistsOfThisString (tor, 2, expected_contents[2]));
346  check (files[0].is_renamed == false);
347  check (files[1].is_renamed == true);
348  check (files[2].is_renamed == true);
349  check (files[3].is_renamed == false);
350
351  /* (while the branch is renamed: confirm that the .resume file remembers the changes) */
352  tr_torrentSaveResume (tor);
353  /* this is a bit dodgy code-wise, but let's make sure the .resume file got the name */
354  tr_free (files[1].name);
355  tor->info.files[1].name = tr_strdup ("gabba gabba hey");
356  loaded = tr_torrentLoadResume (tor, ~0, ctor);
357  check ((loaded & TR_FR_FILENAMES) != 0);
358  check_streq (expected_files[0],                           files[0].name);
359  check_streq ("Felidae/Felinae/Felis/placeholder/Kyphi",   files[1].name);
360  check_streq ("Felidae/Felinae/Felis/placeholder/Saffron", files[2].name);
361  check_streq (expected_files[3],                           files[3].name);
362
363  /* ...and back again */
364  check_int_eq (0, torrentRenameAndWait (tor, "Felidae/Felinae/Felis/placeholder", "catus"));
365  for (i=0; i<4; ++i)
366    {
367      check_streq (expected_files[i], files[i].name);
368      check (testFileExistsAndConsistsOfThisString (tor, i, expected_contents[i]));
369    }
370  check (files[0].is_renamed == false);
371  check (files[1].is_renamed == true);
372  check (files[2].is_renamed == true);
373  check (files[3].is_renamed == false);
374
375  /***
376  ****  Test it an incomplete torrent...
377  ***/
378
379  /* remove the directory Felidae/Felinae/Felis/catus */
380  str = tr_torrentFindFile (tor, 1);
381  check (str != NULL);
382  tr_sys_path_remove (str, NULL);
383  tr_free (str);
384  str = tr_torrentFindFile (tor, 2);
385  check (str != NULL);
386  tr_sys_path_remove (str, NULL);
387  tmp = tr_sys_path_dirname (str, NULL);
388  tr_sys_path_remove (tmp, NULL);
389  tr_free (tmp);
390  tr_free (str);
391  libttest_sync ();
392  libttest_blockingTorrentVerify (tor);
393  testFileExistsAndConsistsOfThisString (tor, 0, expected_contents[0]);
394  for (i=1; i<=2; ++i)
395    {
396      str = tr_torrentFindFile (tor, i);
397      check_streq (NULL, str);
398      tr_free (str);
399    }
400  testFileExistsAndConsistsOfThisString (tor, 3, expected_contents[3]);
401
402  /* rename a branch... */
403  check_int_eq (0, torrentRenameAndWait (tor, "Felidae/Felinae/Felis/catus", "foo"));
404  check_streq (expected_files[0],                   files[0].name);
405  check_streq ("Felidae/Felinae/Felis/foo/Kyphi",   files[1].name);
406  check_streq ("Felidae/Felinae/Felis/foo/Saffron", files[2].name);
407  check_streq (expected_files[3],                   files[3].name);
408
409  /* ...and back again */
410  check_int_eq (0, torrentRenameAndWait (tor, "Felidae/Felinae/Felis/foo", "catus"));
411  for (i=0; i<4; ++i)
412    check_streq (expected_files[i], files[i].name);
413
414  check_int_eq (0, torrentRenameAndWait (tor, "Felidae", "gabba"));
415  strings[0] = "gabba/Felinae/Acinonyx/Cheetah/Chester";
416  strings[1] = "gabba/Felinae/Felis/catus/Kyphi";
417  strings[2] = "gabba/Felinae/Felis/catus/Saffron";
418  strings[3] = "gabba/Pantherinae/Panthera/Tiger/Tony";
419  for (i=0; i<4; ++i)
420    {
421      check_streq (strings[i], files[i].name);
422      testFileExistsAndConsistsOfThisString (tor, i, expected_contents[i]);
423    }
424
425  /* rename the root, then a branch, and then a leaf... */
426  check_int_eq (0, torrentRenameAndWait (tor, "gabba", "Felidae"));
427  check_int_eq (0, torrentRenameAndWait (tor, "Felidae/Pantherinae/Panthera/Tiger", "Snow Leopard"));
428  check_int_eq (0, torrentRenameAndWait (tor, "Felidae/Pantherinae/Panthera/Snow Leopard/Tony", "10.6"));
429  strings[0] = "Felidae/Felinae/Acinonyx/Cheetah/Chester";
430  strings[1] = "Felidae/Felinae/Felis/catus/Kyphi";
431  strings[2] = "Felidae/Felinae/Felis/catus/Saffron";
432  strings[3] = "Felidae/Pantherinae/Panthera/Snow Leopard/10.6";
433  for (i=0; i<4; ++i)
434    {
435      check_streq (strings[i], files[i].name);
436      testFileExistsAndConsistsOfThisString (tor, i, expected_contents[i]);
437    }
438
439  /**
440  ***  Test renaming prefixes (shouldn't work)
441  **/
442
443  tr_ctorFree (ctor);
444  tr_torrentRemove (tor, false, NULL);
445  do {
446    tr_wait_msec (10);
447  } while (0);
448  ctor = tr_ctorNew (session);
449  tor = create_torrent_from_base64_metainfo (ctor,
450    "ZDEwOmNyZWF0ZWQgYnkyNTpUcmFuc21pc3Npb24vMi42MSAoMTM0MDcpMTM6Y3JlYXRpb24gZGF0"
451    "ZWkxMzU4NTU1NDIwZTg6ZW5jb2Rpbmc1OlVURi04NDppbmZvZDU6ZmlsZXNsZDY6bGVuZ3RoaTI4"
452    "ZTQ6cGF0aGw3OkZlbGluYWU4OkFjaW5vbnl4NzpDaGVldGFoNzpDaGVzdGVyZWVkNjpsZW5ndGhp"
453    "MTJlNDpwYXRobDc6RmVsaW5hZTU6RmVsaXM1OmNhdHVzNTpLeXBoaWVlZDY6bGVuZ3RoaTZlNDpw"
454    "YXRobDc6RmVsaW5hZTU6RmVsaXM1OmNhdHVzNzpTYWZmcm9uZWVkNjpsZW5ndGhpMjFlNDpwYXRo"
455    "bDExOlBhbnRoZXJpbmFlODpQYW50aGVyYTU6VGlnZXI0OlRvbnllZWU0Om5hbWU3OkZlbGlkYWUx"
456    "MjpwaWVjZSBsZW5ndGhpMzI3NjhlNjpwaWVjZXMyMDp27buFkmy8ICfNX4nsJmt0Ckm2Ljc6cHJp"
457    "dmF0ZWkwZWVl");
458  check (tr_isTorrent (tor));
459  files = tor->info.files;
460
461  /* rename prefix of top */
462  check_int_eq (EINVAL, torrentRenameAndWait (tor, "Feli", "FelidaeX"));
463  check_streq (tor->info.name, "Felidae");
464  check (files[0].is_renamed == false);
465  check (files[1].is_renamed == false);
466  check (files[2].is_renamed == false);
467  check (files[3].is_renamed == false);
468
469  /* rename false path */
470  check_int_eq (EINVAL, torrentRenameAndWait (tor, "Felidae/FelinaeX", "Genus Felinae"));
471  check_streq (tor->info.name, "Felidae");
472  check (files[0].is_renamed == false);
473  check (files[1].is_renamed == false);
474  check (files[2].is_renamed == false);
475  check (files[3].is_renamed == false);
476
477  /***
478  ****
479  ***/
480
481  /* cleanup */
482  tr_ctorFree (ctor);
483  tr_torrentRemove (tor, false, NULL);
484  return 0;
485}
486
487/***
488****
489***/
490
491static int
492test_partial_file (void)
493{
494  tr_file_index_t i;
495  tr_torrent * tor;
496  const tr_stat * st;
497  tr_file_stat * fst;
498  const uint32_t pieceCount = 33;
499  const uint32_t pieceSize = 32768;
500  const uint32_t length[] = { 1048576, 4096, 512 };
501  const uint64_t totalSize = length[0] + length[1] + length[2];
502  const char * strings[3];
503
504  /***
505  ****  create our test torrent with an incomplete .part file
506  ***/
507
508  tor = libttest_zero_torrent_init (session);
509  check_uint_eq (totalSize, tor->info.totalSize);
510  check_uint_eq (pieceSize, tor->info.pieceSize);
511  check_uint_eq (pieceCount, tor->info.pieceCount);
512  check_streq ("files-filled-with-zeroes/1048576", tor->info.files[0].name);
513  check_streq ("files-filled-with-zeroes/4096",    tor->info.files[1].name);
514  check_streq ("files-filled-with-zeroes/512",     tor->info.files[2].name);
515
516  libttest_zero_torrent_populate (tor, false);
517  fst = tr_torrentFiles (tor, NULL);
518  check_uint_eq (length[0] - pieceSize, fst[0].bytesCompleted);
519  check_uint_eq (length[1],             fst[1].bytesCompleted);
520  check_uint_eq (length[2],             fst[2].bytesCompleted);
521  tr_torrentFilesFree (fst, tor->info.fileCount);
522  st = tr_torrentStat (tor);
523  check_uint_eq (totalSize, st->sizeWhenDone);
524  check_uint_eq (pieceSize, st->leftUntilDone);
525
526  /***
527  ****
528  ***/
529
530  check_int_eq (0, torrentRenameAndWait (tor, "files-filled-with-zeroes", "foo"));
531  check_int_eq (0, torrentRenameAndWait (tor, "foo/1048576", "bar"));
532  strings[0] = "foo/bar";
533  strings[1] = "foo/4096";
534  strings[2] = "foo/512";
535  for (i=0; i<3; ++i)
536    {
537      check_streq (strings[i], tor->info.files[i].name);
538    }
539
540  strings[0] = "foo/bar.part";
541  for (i=0; i<3; ++i)
542    {
543      char * expected = tr_buildPath (tor->currentDir, strings[i], NULL);
544      char * path = tr_torrentFindFile (tor, i);
545      check_streq (expected, path);
546      tr_free (path);
547      tr_free (expected);
548    }
549
550  tr_torrentRemove (tor, false, NULL);
551  return 0;
552}
553
554/***
555****
556***/
557
558int
559main (void)
560{
561  int ret;
562  const testFunc tests[] = { test_single_filename_torrent,
563                             test_multifile_torrent,
564                             test_partial_file };
565
566  session = libttest_session_init (NULL);
567  ret = runTests (tests, NUM_TESTS (tests));
568  libttest_session_close (session);
569
570  return ret;
571}
Note: See TracBrowser for help on using the repository browser.