Changeset 13814


Ignore:
Timestamp:
Jan 21, 2013, 12:00:00 AM (8 years ago)
Author:
jordan
Message:

(libT) #5234 'typo causing RPC session-get error in nightlies': add unit test (currently failing) to test for this issue.

Location:
trunk/libtransmission
Files:
4 edited

Legend:

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

    r13812 r13814  
    1 
     1#include <assert.h>
    22#include <stdio.h>
    33
     
    166166}
    167167
     168#define MEM_K 1024
     169#define MEM_B_STR   "B"
     170#define MEM_K_STR "KiB"
     171#define MEM_M_STR "MiB"
     172#define MEM_G_STR "GiB"
     173#define MEM_T_STR "TiB"
     174
     175#define DISK_K 1000
     176#define DISK_B_STR  "B"
     177#define DISK_K_STR "kB"
     178#define DISK_M_STR "MB"
     179#define DISK_G_STR "GB"
     180#define DISK_T_STR "TB"
     181
     182#define SPEED_K 1000
     183#define SPEED_B_STR  "B/s"
     184#define SPEED_K_STR "kB/s"
     185#define SPEED_M_STR "MB/s"
     186#define SPEED_G_STR "GB/s"
     187#define SPEED_T_STR "TB/s"
     188
    168189void
    169190libtransmission_test_session_init (void)
     
    172193  char * downloadDir;
    173194  tr_variant dict;
     195
     196  tr_formatter_mem_init (MEM_K, MEM_K_STR, MEM_M_STR, MEM_G_STR, MEM_T_STR);
     197  tr_formatter_size_init (DISK_K,DISK_K_STR, DISK_M_STR, DISK_G_STR, DISK_T_STR);
     198  tr_formatter_speed_init (SPEED_K, SPEED_K_STR, SPEED_M_STR, SPEED_G_STR, SPEED_T_STR);
    174199
    175200  /* create a sandbox for the test session */
     
    201226  tr_free (sandbox);
    202227}
     228
     229/***
     230****
     231***/
     232
     233tr_torrent *
     234libtransmission_test_zero_torrent_init (void)
     235{
     236  int err;
     237  int metainfo_len;
     238  char * metainfo;
     239  const char * metainfo_base64;
     240  tr_torrent * tor;
     241  tr_ctor * ctor;
     242
     243  /*
     244     1048576 files-filled-with-zeroes/1048576
     245        4096 files-filled-with-zeroes/4096
     246         512 files-filled-with-zeroes/512
     247   */
     248  metainfo_base64 =
     249    "ZDg6YW5ub3VuY2UzMTpodHRwOi8vd3d3LmV4YW1wbGUuY29tL2Fubm91bmNlMTA6Y3JlYXRlZCBi"
     250    "eTI1OlRyYW5zbWlzc2lvbi8yLjYxICgxMzQwNykxMzpjcmVhdGlvbiBkYXRlaTEzNTg3MDQwNzVl"
     251    "ODplbmNvZGluZzU6VVRGLTg0OmluZm9kNTpmaWxlc2xkNjpsZW5ndGhpMTA0ODU3NmU0OnBhdGhs"
     252    "NzoxMDQ4NTc2ZWVkNjpsZW5ndGhpNDA5NmU0OnBhdGhsNDo0MDk2ZWVkNjpsZW5ndGhpNTEyZTQ6"
     253    "cGF0aGwzOjUxMmVlZTQ6bmFtZTI0OmZpbGVzLWZpbGxlZC13aXRoLXplcm9lczEyOnBpZWNlIGxl"
     254    "bmd0aGkzMjc2OGU2OnBpZWNlczY2MDpRiEMYSbRhMVL9e9umo/8KT9ZCS1GIQxhJtGExUv1726aj"
     255    "/wpP1kJLUYhDGEm0YTFS/XvbpqP/Ck/WQktRiEMYSbRhMVL9e9umo/8KT9ZCS1GIQxhJtGExUv17"
     256    "26aj/wpP1kJLUYhDGEm0YTFS/XvbpqP/Ck/WQktRiEMYSbRhMVL9e9umo/8KT9ZCS1GIQxhJtGEx"
     257    "Uv1726aj/wpP1kJLUYhDGEm0YTFS/XvbpqP/Ck/WQktRiEMYSbRhMVL9e9umo/8KT9ZCS1GIQxhJ"
     258    "tGExUv1726aj/wpP1kJLUYhDGEm0YTFS/XvbpqP/Ck/WQktRiEMYSbRhMVL9e9umo/8KT9ZCS1GI"
     259    "QxhJtGExUv1726aj/wpP1kJLUYhDGEm0YTFS/XvbpqP/Ck/WQktRiEMYSbRhMVL9e9umo/8KT9ZC"
     260    "S1GIQxhJtGExUv1726aj/wpP1kJLUYhDGEm0YTFS/XvbpqP/Ck/WQktRiEMYSbRhMVL9e9umo/8K"
     261    "T9ZCS1GIQxhJtGExUv1726aj/wpP1kJLUYhDGEm0YTFS/XvbpqP/Ck/WQktRiEMYSbRhMVL9e9um"
     262    "o/8KT9ZCS1GIQxhJtGExUv1726aj/wpP1kJLUYhDGEm0YTFS/XvbpqP/Ck/WQktRiEMYSbRhMVL9"
     263    "e9umo/8KT9ZCS1GIQxhJtGExUv1726aj/wpP1kJLUYhDGEm0YTFS/XvbpqP/Ck/WQktRiEMYSbRh"
     264    "MVL9e9umo/8KT9ZCS1GIQxhJtGExUv1726aj/wpP1kJLUYhDGEm0YTFS/XvbpqP/Ck/WQktRiEMY"
     265    "SbRhMVL9e9umo/8KT9ZCS1GIQxhJtGExUv1726aj/wpP1kJLOlf5A+Tz30nMBVuNM2hpV3wg/103"
     266    "OnByaXZhdGVpMGVlZQ==";
     267
     268  /* create the torrent ctor */
     269  metainfo = tr_base64_decode (metainfo_base64, -1, &metainfo_len);
     270  assert (metainfo != NULL);
     271  assert (metainfo_len > 0);
     272  assert (session != NULL);
     273  ctor = tr_ctorNew (session);
     274  tr_ctorSetMetainfo (ctor, (uint8_t*)metainfo, metainfo_len);
     275  tr_ctorSetPaused (ctor, TR_FORCE, true);
     276
     277  /* create the torrent */
     278  err = 0;
     279  tor = tr_torrentNew (ctor, &err);
     280  assert (!err);
     281
     282  /* cleanup */
     283  tr_free (metainfo);
     284  tr_ctorFree (ctor);
     285  return tor;
     286}
  • trunk/libtransmission/libtransmission-test.h

    r13812 r13814  
    66#include <stdio.h>
    77
     8#include "transmission.h"
    89#include "utils.h" /* tr_strcmp0 () */
    910
     
    6970void libtransmission_test_session_init (void);
    7071void libtransmission_test_session_close (void);
     72tr_torrent * libtransmission_test_zero_torrent_init (void);
     73
    7174
    7275
  • trunk/libtransmission/rpc-test.c

    r13667 r13814  
     1#include <string.h>
     2
     3#include <event2/buffer.h>
     4
    15#include "transmission.h"
    26#include "rpcimpl.h"
     
    913test_list (void)
    1014{
    11     size_t len;
    12     int64_t i;
    13     const char * str;
    14     tr_variant top;
     15  size_t len;
     16  int64_t i;
     17  const char * str;
     18  tr_variant top;
    1519
    16     tr_rpc_parse_list_str (&top, "12", -1);
    17     check (tr_variantIsInt (&top));
    18     check (tr_variantGetInt (&top, &i));
    19     check_int_eq (12, i);
    20     tr_variantFree (&top);
     20  tr_rpc_parse_list_str (&top, "12", -1);
     21  check (tr_variantIsInt (&top));
     22  check (tr_variantGetInt (&top, &i));
     23  check_int_eq (12, i);
     24  tr_variantFree (&top);
    2125
    22     tr_rpc_parse_list_str (&top, "12", 1);
    23     check (tr_variantIsInt (&top));
    24     check (tr_variantGetInt (&top, &i));
    25     check_int_eq (1, i);
    26     tr_variantFree (&top);
     26  tr_rpc_parse_list_str (&top, "12", 1);
     27  check (tr_variantIsInt (&top));
     28  check (tr_variantGetInt (&top, &i));
     29  check_int_eq (1, i);
     30  tr_variantFree (&top);
    2731
    28     tr_rpc_parse_list_str (&top, "6,7", -1);
    29     check (tr_variantIsList (&top));
    30     check (tr_variantListSize (&top) == 2);
    31     check (tr_variantGetInt (tr_variantListChild (&top, 0), &i));
    32     check_int_eq (6, i);
    33     check (tr_variantGetInt (tr_variantListChild (&top, 1), &i));
    34     check_int_eq (7, i);
    35     tr_variantFree (&top);
     32  tr_rpc_parse_list_str (&top, "6,7", -1);
     33  check (tr_variantIsList (&top));
     34  check (tr_variantListSize (&top) == 2);
     35  check (tr_variantGetInt (tr_variantListChild (&top, 0), &i));
     36  check_int_eq (6, i);
     37  check (tr_variantGetInt (tr_variantListChild (&top, 1), &i));
     38  check_int_eq (7, i);
     39  tr_variantFree (&top);
    3640
    37     tr_rpc_parse_list_str (&top, "asdf", -1);
    38     check (tr_variantIsString (&top));
    39     check (tr_variantGetStr (&top, &str, &len));
    40     check_int_eq (4, len);
    41     check_streq ("asdf", str);
    42     tr_variantFree (&top);
     41  tr_rpc_parse_list_str (&top, "asdf", -1);
     42  check (tr_variantIsString (&top));
     43  check (tr_variantGetStr (&top, &str, &len));
     44  check_int_eq (4, len);
     45  check_streq ("asdf", str);
     46  tr_variantFree (&top);
    4347
    44     tr_rpc_parse_list_str (&top, "1,3-5", -1);
    45     check (tr_variantIsList (&top));
    46     check (tr_variantListSize (&top) == 4);
    47     check (tr_variantGetInt (tr_variantListChild (&top, 0), &i));
    48     check_int_eq (1, i);
    49     check (tr_variantGetInt (tr_variantListChild (&top, 1), &i));
    50     check_int_eq (3, i);
    51     check (tr_variantGetInt (tr_variantListChild (&top, 2), &i));
    52     check_int_eq (4, i);
    53     check (tr_variantGetInt (tr_variantListChild (&top, 3), &i));
    54     check_int_eq (5, i);
    55     tr_variantFree (&top);
     48  tr_rpc_parse_list_str (&top, "1,3-5", -1);
     49  check (tr_variantIsList (&top));
     50  check (tr_variantListSize (&top) == 4);
     51  check (tr_variantGetInt (tr_variantListChild (&top, 0), &i));
     52  check_int_eq (1, i);
     53  check (tr_variantGetInt (tr_variantListChild (&top, 1), &i));
     54  check_int_eq (3, i);
     55  check (tr_variantGetInt (tr_variantListChild (&top, 2), &i));
     56  check_int_eq (4, i);
     57  check (tr_variantGetInt (tr_variantListChild (&top, 3), &i));
     58  check_int_eq (5, i);
     59  tr_variantFree (&top);
    5660
    57     return 0;
     61  return 0;
    5862}
    5963
    60 MAIN_SINGLE_TEST (test_list)
     64/***
     65****
     66***/
     67
     68static void
     69rpc_response_func (tr_session      * session    UNUSED,
     70                   struct evbuffer * response,
     71                   void            * setme)
     72{
     73  tr_variantFromBuf (setme, TR_VARIANT_FMT_JSON, evbuffer_pullup(response,-1), evbuffer_get_length(response), NULL, NULL);
     74}
     75
     76static int
     77test_session_get_and_set (void)
     78{
     79  const char * json;
     80  tr_variant response;
     81  tr_variant * args;
     82  tr_torrent * tor = libtransmission_test_zero_torrent_init ();
     83  check (tor != NULL);
     84
     85  json = "{\"method\":\"session-get\"}";
     86  tr_rpc_request_exec_json (session, json, strlen(json), rpc_response_func, &response);
     87
     88  check (tr_variantIsDict(&response));
     89  check (tr_variantIsDict(&response));
     90  check (tr_variantDictFindDict (&response, TR_KEY_arguments, &args));
     91  check (tr_variantDictFind (args, TR_KEY_alt_speed_down) != NULL);
     92  check (tr_variantDictFind (args, TR_KEY_alt_speed_enabled) != NULL);
     93  check (tr_variantDictFind (args, TR_KEY_alt_speed_time_begin) != NULL);
     94  check (tr_variantDictFind (args, TR_KEY_alt_speed_time_day) != NULL);
     95  check (tr_variantDictFind (args, TR_KEY_alt_speed_time_enabled) != NULL);
     96  check (tr_variantDictFind (args, TR_KEY_alt_speed_time_end) != NULL);
     97  check (tr_variantDictFind (args, TR_KEY_alt_speed_up) != NULL);
     98  check (tr_variantDictFind (args, TR_KEY_blocklist_enabled) != NULL);
     99  check (tr_variantDictFind (args, TR_KEY_blocklist_size) != NULL);
     100  check (tr_variantDictFind (args, TR_KEY_blocklist_url) != NULL);
     101  check (tr_variantDictFind (args, TR_KEY_cache_size_mb) != NULL);
     102  check (tr_variantDictFind (args, TR_KEY_config_dir) != NULL);
     103  check (tr_variantDictFind (args, TR_KEY_dht_enabled) != NULL);
     104  check (tr_variantDictFind (args, TR_KEY_download_dir) != NULL);
     105  check (tr_variantDictFind (args, TR_KEY_download_dir_free_space) != NULL);
     106  check (tr_variantDictFind (args, TR_KEY_download_queue_enabled) != NULL);
     107  check (tr_variantDictFind (args, TR_KEY_download_queue_size) != NULL);
     108  check (tr_variantDictFind (args, TR_KEY_encryption) != NULL);
     109  check (tr_variantDictFind (args, TR_KEY_idle_seeding_limit) != NULL);
     110  check (tr_variantDictFind (args, TR_KEY_idle_seeding_limit_enabled) != NULL);
     111  check (tr_variantDictFind (args, TR_KEY_incomplete_dir) != NULL);
     112  check (tr_variantDictFind (args, TR_KEY_incomplete_dir_enabled) != NULL);
     113  check (tr_variantDictFind (args, TR_KEY_lpd_enabled) != NULL);
     114  check (tr_variantDictFind (args, TR_KEY_peer_limit_global) != NULL);
     115  check (tr_variantDictFind (args, TR_KEY_peer_limit_per_torrent) != NULL);
     116  check (tr_variantDictFind (args, TR_KEY_peer_port) != NULL);
     117  check (tr_variantDictFind (args, TR_KEY_peer_port_random_on_start) != NULL);
     118  check (tr_variantDictFind (args, TR_KEY_pex_enabled) != NULL);
     119  check (tr_variantDictFind (args, TR_KEY_port_forwarding_enabled) != NULL);
     120  check (tr_variantDictFind (args, TR_KEY_queue_stalled_enabled) != NULL);
     121  check (tr_variantDictFind (args, TR_KEY_queue_stalled_minutes) != NULL);
     122  check (tr_variantDictFind (args, TR_KEY_rename_partial_files) != NULL);
     123  check (tr_variantDictFind (args, TR_KEY_rpc_version) != NULL);
     124  check (tr_variantDictFind (args, TR_KEY_rpc_version_minimum) != NULL);
     125  check (tr_variantDictFind (args, TR_KEY_script_torrent_done_enabled) != NULL);
     126  check (tr_variantDictFind (args, TR_KEY_script_torrent_done_filename) != NULL);
     127  check (tr_variantDictFind (args, TR_KEY_seed_queue_enabled) != NULL);
     128  check (tr_variantDictFind (args, TR_KEY_seed_queue_size) != NULL);
     129  check (tr_variantDictFind (args, TR_KEY_seedRatioLimit) != NULL);
     130  check (tr_variantDictFind (args, TR_KEY_seedRatioLimited) != NULL);
     131  check (tr_variantDictFind (args, TR_KEY_speed_limit_down) != NULL);
     132  check (tr_variantDictFind (args, TR_KEY_speed_limit_down_enabled) != NULL);
     133  check (tr_variantDictFind (args, TR_KEY_speed_limit_up) != NULL);
     134  check (tr_variantDictFind (args, TR_KEY_speed_limit_up_enabled) != NULL);
     135  check (tr_variantDictFind (args, TR_KEY_start_added_torrents) != NULL);
     136  check (tr_variantDictFind (args, TR_KEY_trash_original_torrent_files) != NULL);
     137  check (tr_variantDictFind (args, TR_KEY_units) != NULL);
     138  check (tr_variantDictFind (args, TR_KEY_utp_enabled) != NULL);
     139  check (tr_variantDictFind (args, TR_KEY_version) != NULL);
     140  tr_variantFree (&response);
     141
     142  /* cleanup */
     143  tr_torrentRemove (tor, false, NULL);
     144  return 0;
     145}
     146
     147/***
     148****
     149***/
     150
     151int
     152main (void)
     153{
     154  int ret;
     155  const testFunc tests[] = { test_list,
     156                             test_session_get_and_set };
     157
     158  libtransmission_test_session_init ();
     159  ret = runTests (tests, NUM_TESTS (tests));
     160  libtransmission_test_session_close ();
     161
     162  return ret;
     163}
  • trunk/libtransmission/rpcimpl.h

    r13667 r13814  
    2727struct evbuffer;
    2828
    29 /* FIXME (libevent2): make "response" an evbuffer and remove response_len */
    30 typedef void (*tr_rpc_response_func)(tr_session        * session,
    31                                        struct evbuffer * response,
    32                                        void            * user_data);
     29typedef void (*tr_rpc_response_func)(tr_session      * session,
     30                                     struct evbuffer * response,
     31                                     void            * user_data);
    3332/* http://www.json.org/ */
    3433void tr_rpc_request_exec_json (tr_session            * session,
Note: See TracChangeset for help on using the changeset viewer.