From: Jordan Lee Date: Sun, 8 Jun 2014 22:21:27 +0000 (+0000) Subject: in makemeta-tests, add tests to generate a .torrent file from a folder of randomly... X-Git-Tag: 2.90~395 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=99eda37b5e95244c245996a351a5f75d9b0bb7f7;p=transmission in makemeta-tests, add tests to generate a .torrent file from a folder of randomly-generated files. --- diff --git a/libtransmission/libtransmission-test.c b/libtransmission/libtransmission-test.c index e6cef2cc3..0fef68482 100644 --- a/libtransmission/libtransmission-test.c +++ b/libtransmission/libtransmission-test.c @@ -489,7 +489,7 @@ libtest_create_tmpfile_with_contents (char* tmpl, const void* payload, size_t n) const ssize_t n = write (fd, payload, n_left); if (n == -1) { - fprintf (stderr, "Error writing '%s': %s", tmpl, tr_strerror(errno)); + fprintf (stderr, "Error writing '%s': %s\n", tmpl, tr_strerror(errno)); break; } n_left -= n; diff --git a/libtransmission/makemeta-test.c b/libtransmission/makemeta-test.c index 501152428..effe7ffca 100644 --- a/libtransmission/makemeta-test.c +++ b/libtransmission/makemeta-test.c @@ -10,8 +10,11 @@ #include "libtransmission-test.h" #include "transmission.h" +#include "crypto.h" #include "makemeta.h" +#include /* sync() */ + #include /* mktemp() */ #include /* strlen() */ @@ -44,7 +47,7 @@ test_single_file_impl (const tr_tracker_info * trackers, check_streq (input_file, builder->files[0].filename); check_int_eq (payloadSize, builder->files[0].size); check_int_eq (payloadSize, builder->totalSize); - check (builder->isSingleFile); + check (!builder->isFolder); check (!builder->abortFlag); /* have tr_makeMetaInfo() build the .torrent file */ @@ -59,6 +62,7 @@ test_single_file_impl (const tr_tracker_info * trackers, /* now let's check our work: parse the .torrent file */ ctor = tr_ctorNew (NULL); + sync (); tr_ctorSetMetainfoFromFile (ctor, torrent_file); parse_result = tr_torrentParse (ctor, &inf); check_int_eq (TR_PARSE_OK, parse_result); @@ -71,7 +75,7 @@ test_single_file_impl (const tr_tracker_info * trackers, check_streq (comment, inf.comment); check_int_eq (1, inf.fileCount); check_int_eq (isPrivate, inf.isPrivate); - check (!inf.isMultifile); + check (!inf.isFolder); check_int_eq (trackerCount, inf.trackerCount); /* cleanup */ @@ -111,11 +115,188 @@ test_single_file (void) return 0; } + +static int +test_single_directory_impl (const tr_tracker_info * trackers, + const size_t trackerCount, + const void ** payloads, + const size_t * payloadSizes, + const size_t payloadCount, + const char * comment, + const bool isPrivate) +{ + char* sandbox; + char* torrent_file; + tr_metainfo_builder* builder; + tr_ctor * ctor; + tr_parse_result parse_result; + tr_info inf; + char * top; + char ** files; + size_t totalSize; + size_t i; + char* tmpstr; + + + /* set up our local test sandbox */ + sandbox = libtest_sandbox_create(); + + /* create the top temp directory */ + top = tr_buildPath (sandbox, "folder.XXXXXX", NULL); + tr_mkdtemp (top); + + /* build the payload files that go into the top temp directory */ + files = tr_new (char*, payloadCount); + totalSize = 0; + for (i=0; iabortFlag); + check_streq (top, builder->top); + check_int_eq (payloadCount, builder->fileCount); + check_int_eq (totalSize, builder->totalSize); + check (builder->isFolder); + for (i=0; ifileCount; i++) + { + check_streq (files[i], builder->files[i].filename); + check_int_eq (payloadSizes[i], builder->files[i].size); + } + + /* call tr_makeMetaInfo() to build the .torrent file */ + torrent_file = tr_strdup_printf ("%s.torrent", top); + tr_makeMetaInfo (builder, torrent_file, trackers, trackerCount, comment, isPrivate); + check (isPrivate == builder->isPrivate); + check_streq (torrent_file, builder->outputFile); + check_streq (comment, builder->comment); + check_int_eq (trackerCount, builder->trackerCount); + while (!builder->isDone) + tr_wait_msec (100); + + /* now let's check our work: parse the .torrent file */ + ctor = tr_ctorNew (NULL); + sync (); + tr_ctorSetMetainfoFromFile (ctor, torrent_file); + parse_result = tr_torrentParse (ctor, &inf); + check_int_eq (TR_PARSE_OK, parse_result); + + /* quick check of some of the parsed metainfo */ + check_int_eq (totalSize, inf.totalSize); + tmpstr = tr_basename(top); + check_streq (tmpstr, inf.name); + tr_free (tmpstr); + check_streq (comment, inf.comment); + check_int_eq (payloadCount, inf.fileCount); + check_int_eq (isPrivate, inf.isPrivate); + check_int_eq (builder->isFolder, inf.isFolder); + check_int_eq (trackerCount, inf.trackerCount); + + /* cleanup */ + tr_free (torrent_file); + tr_ctorFree (ctor); + tr_metainfoFree (&inf); + tr_metaInfoBuilderFree (builder); + for (i=0; iisMultifile = 1; + inf->isFolder = true; inf->fileCount = tr_variantListSize (files); inf->files = tr_new0 (tr_file, inf->fileCount); @@ -193,7 +193,7 @@ parseFiles (tr_info * inf, tr_variant * files, const tr_variant * length) if (path_component_is_suspicious (inf->name)) return "path"; - inf->isMultifile = 0; + inf->isFolder = false; inf->fileCount = 1; inf->files = tr_new0 (tr_file, 1); inf->files[0].name = tr_strdup (inf->name);