source: trunk/libtransmission/metainfo-test.c

Last change on this file was 14428, checked in by mikedld, 6 years ago

Replace tabs with spaces; remove trailing spaces

  • Property svn:keywords set to Date Rev Author Id
File size: 3.3 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: metainfo-test.c 14428 2015-01-02 11:15:31Z mikedld $
8 */
9
10#include "libtransmission-test.h"
11
12#include "transmission.h"
13
14#include <errno.h>
15
16static int
17test_magnet_link (void)
18{
19  tr_info inf;
20  tr_ctor * ctor;
21  const char * magnet_link;
22  tr_parse_result parse_result;
23
24  /* background info @ http://wiki.theory.org/BitTorrent_Magnet-URI_Webseeding */
25  magnet_link = "magnet:?"
26                "xt=urn:btih:14FFE5DD23188FD5CB53A1D47F1289DB70ABF31E"
27                "&dn=ubuntu+12+04+1+desktop+32+bit"
28                "&tr=http%3A%2F%2Ftracker.publicbt.com%2Fannounce"
29                "&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80"
30                "&ws=http://transmissionbt.com ";
31  ctor = tr_ctorNew (NULL);
32  tr_ctorSetMetainfoFromMagnetLink (ctor, magnet_link);
33  parse_result = tr_torrentParse (ctor, &inf);
34  check_int_eq (inf.fileCount, 0); /* cos it's a magnet link */
35  check_int_eq (parse_result, TR_PARSE_OK);
36  check_int_eq (inf.trackerCount, 2);
37  check_streq ("http://tracker.publicbt.com/announce", inf.trackers[0].announce);
38  check_streq ("udp://tracker.publicbt.com:80", inf.trackers[1].announce);
39  check_int_eq (inf.webseedCount, 1);
40  check_streq ("http://transmissionbt.com", inf.webseeds[0]);
41
42  /* cleanup */
43  tr_metainfoFree (&inf);
44  tr_ctorFree (ctor);
45  return 0;
46}
47
48#define BEFORE_PATH "d10:created by25:Transmission/2.82 (14160)13:creation datei1402280218e8:encoding5:UTF-84:infod5:filesld6:lengthi2e4:pathl"
49#define AFTER_PATH "eed6:lengthi2e4:pathl5:b.txteee4:name3:foo12:piece lengthi32768e6:pieces20:ÞÉ`âM‘‹Šs¡Å;˺¬.åÂà7:privatei0eee"
50
51static int
52test_metainfo (void)
53{
54  size_t i;
55  const struct {
56    int expected_benc_err;
57    int expected_parse_result;
58    const void * benc;
59  } metainfo[] = {
60    { 0,      TR_PARSE_OK,  BEFORE_PATH "5:a.txt"     AFTER_PATH },
61
62    /* allow empty components, but not =all= empty components, see bug #5517 */
63    { 0,      TR_PARSE_OK,  BEFORE_PATH "0:5:a.txt"   AFTER_PATH },
64    { 0,      TR_PARSE_ERR, BEFORE_PATH "0:0:"        AFTER_PATH },
65
66    /* don't allow path components in a filename */
67    { 0,      TR_PARSE_ERR, BEFORE_PATH "7:a/a.txt"   AFTER_PATH },
68
69    /* fail on "." components */
70    { 0,      TR_PARSE_ERR, BEFORE_PATH "1:.5:a.txt"  AFTER_PATH },
71    { 0,      TR_PARSE_ERR, BEFORE_PATH "5:a.txt1:."  AFTER_PATH },
72
73    /* fail on ".." components */
74    { 0,      TR_PARSE_ERR, BEFORE_PATH "2:..5:a.txt" AFTER_PATH },
75    { 0,      TR_PARSE_ERR, BEFORE_PATH "5:a.txt2:.." AFTER_PATH },
76
77    /* fail on empty string */
78    { EILSEQ, TR_PARSE_ERR, "" }
79  };
80
81  tr_logSetLevel(0); /* yes, we already know these will generate errors, thank you... */
82
83
84  for (i=0; i<(sizeof(metainfo) / sizeof(metainfo[0])); i++)
85    {
86      tr_ctor * ctor = tr_ctorNew (NULL);
87      const int err = tr_ctorSetMetainfo (ctor, metainfo[i].benc, strlen(metainfo[i].benc));
88      check_int_eq (metainfo[i].expected_benc_err, err);
89      if (!err)
90        {
91          const tr_parse_result parse_result = tr_torrentParse (ctor, NULL);
92          check_int_eq (metainfo[i].expected_parse_result, parse_result);
93        }
94      tr_ctorFree (ctor);
95    }
96
97  return 0;
98}
99
100int
101main (void)
102{
103  const testFunc tests[] = { test_magnet_link,
104                             test_metainfo };
105
106  return runTests (tests, NUM_TESTS (tests));
107}
108
Note: See TracBrowser for help on using the repository browser.