source: trunk/libtransmission/rename-test.c @ 14382

Last change on this file since 14382 was 14382, checked in by mikedld, 8 years ago

Fix compilation on Windows

This should not affect non-Win32 platforms in any way.
As for Win32 (both MinGW and MSVC), this should hopefully allow for
unpatched compilation. Correct functioning is not yet guaranteed though.

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