source: trunk/libtransmission/rpc-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: 6.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: rpc-test.c 14721 2016-03-29 03:04:54Z mikedld $
8 */
9
10#include "transmission.h"
11#include "rpcimpl.h"
12#include "utils.h"
13#include "variant.h"
14
15#include "libtransmission-test.h"
16
17static int
18test_list (void)
19{
20  size_t len;
21  int64_t i;
22  const char * str;
23  tr_variant top;
24
25  tr_rpc_parse_list_str (&top, "12", TR_BAD_SIZE);
26  check (tr_variantIsInt (&top));
27  check (tr_variantGetInt (&top, &i));
28  check_int_eq (12, i);
29  tr_variantFree (&top);
30
31  tr_rpc_parse_list_str (&top, "12", 1);
32  check (tr_variantIsInt (&top));
33  check (tr_variantGetInt (&top, &i));
34  check_int_eq (1, i);
35  tr_variantFree (&top);
36
37  tr_rpc_parse_list_str (&top, "6,7", TR_BAD_SIZE);
38  check (tr_variantIsList (&top));
39  check (tr_variantListSize (&top) == 2);
40  check (tr_variantGetInt (tr_variantListChild (&top, 0), &i));
41  check_int_eq (6, i);
42  check (tr_variantGetInt (tr_variantListChild (&top, 1), &i));
43  check_int_eq (7, i);
44  tr_variantFree (&top);
45
46  tr_rpc_parse_list_str (&top, "asdf", TR_BAD_SIZE);
47  check (tr_variantIsString (&top));
48  check (tr_variantGetStr (&top, &str, &len));
49  check_uint_eq (4, len);
50  check_streq ("asdf", str);
51  tr_variantFree (&top);
52
53  tr_rpc_parse_list_str (&top, "1,3-5", TR_BAD_SIZE);
54  check (tr_variantIsList (&top));
55  check (tr_variantListSize (&top) == 4);
56  check (tr_variantGetInt (tr_variantListChild (&top, 0), &i));
57  check_int_eq (1, i);
58  check (tr_variantGetInt (tr_variantListChild (&top, 1), &i));
59  check_int_eq (3, i);
60  check (tr_variantGetInt (tr_variantListChild (&top, 2), &i));
61  check_int_eq (4, i);
62  check (tr_variantGetInt (tr_variantListChild (&top, 3), &i));
63  check_int_eq (5, i);
64  tr_variantFree (&top);
65
66  return 0;
67}
68
69/***
70****
71***/
72
73static void
74rpc_response_func (tr_session * session    UNUSED,
75                   tr_variant * response,
76                   void       * setme)
77{
78  *(tr_variant *) setme = *response;
79  tr_variantInitBool (response, false);
80}
81
82static int
83test_session_get_and_set (void)
84{
85  tr_session * session;
86  tr_variant request;
87  tr_variant response;
88  tr_variant * args;
89  tr_torrent * tor;
90
91  session = libttest_session_init (NULL);
92  tor= libttest_zero_torrent_init (session);
93  check (tor != NULL);
94
95  tr_variantInitDict (&request, 1);
96  tr_variantDictAddStr (&request, TR_KEY_method, "session-get");
97  tr_rpc_request_exec_json (session, &request, rpc_response_func, &response);
98  tr_variantFree (&request);
99
100  check (tr_variantIsDict(&response));
101  check (tr_variantDictFindDict (&response, TR_KEY_arguments, &args));
102  check (tr_variantDictFind (args, TR_KEY_alt_speed_down) != NULL);
103  check (tr_variantDictFind (args, TR_KEY_alt_speed_enabled) != NULL);
104  check (tr_variantDictFind (args, TR_KEY_alt_speed_time_begin) != NULL);
105  check (tr_variantDictFind (args, TR_KEY_alt_speed_time_day) != NULL);
106  check (tr_variantDictFind (args, TR_KEY_alt_speed_time_enabled) != NULL);
107  check (tr_variantDictFind (args, TR_KEY_alt_speed_time_end) != NULL);
108  check (tr_variantDictFind (args, TR_KEY_alt_speed_up) != NULL);
109  check (tr_variantDictFind (args, TR_KEY_blocklist_enabled) != NULL);
110  check (tr_variantDictFind (args, TR_KEY_blocklist_size) != NULL);
111  check (tr_variantDictFind (args, TR_KEY_blocklist_url) != NULL);
112  check (tr_variantDictFind (args, TR_KEY_cache_size_mb) != NULL);
113  check (tr_variantDictFind (args, TR_KEY_config_dir) != NULL);
114  check (tr_variantDictFind (args, TR_KEY_dht_enabled) != NULL);
115  check (tr_variantDictFind (args, TR_KEY_download_dir) != NULL);
116  check (tr_variantDictFind (args, TR_KEY_download_dir_free_space) != NULL);
117  check (tr_variantDictFind (args, TR_KEY_download_queue_enabled) != NULL);
118  check (tr_variantDictFind (args, TR_KEY_download_queue_size) != NULL);
119  check (tr_variantDictFind (args, TR_KEY_encryption) != NULL);
120  check (tr_variantDictFind (args, TR_KEY_idle_seeding_limit) != NULL);
121  check (tr_variantDictFind (args, TR_KEY_idle_seeding_limit_enabled) != NULL);
122  check (tr_variantDictFind (args, TR_KEY_incomplete_dir) != NULL);
123  check (tr_variantDictFind (args, TR_KEY_incomplete_dir_enabled) != NULL);
124  check (tr_variantDictFind (args, TR_KEY_lpd_enabled) != NULL);
125  check (tr_variantDictFind (args, TR_KEY_peer_limit_global) != NULL);
126  check (tr_variantDictFind (args, TR_KEY_peer_limit_per_torrent) != NULL);
127  check (tr_variantDictFind (args, TR_KEY_peer_port) != NULL);
128  check (tr_variantDictFind (args, TR_KEY_peer_port_random_on_start) != NULL);
129  check (tr_variantDictFind (args, TR_KEY_pex_enabled) != NULL);
130  check (tr_variantDictFind (args, TR_KEY_port_forwarding_enabled) != NULL);
131  check (tr_variantDictFind (args, TR_KEY_queue_stalled_enabled) != NULL);
132  check (tr_variantDictFind (args, TR_KEY_queue_stalled_minutes) != NULL);
133  check (tr_variantDictFind (args, TR_KEY_rename_partial_files) != NULL);
134  check (tr_variantDictFind (args, TR_KEY_rpc_version) != NULL);
135  check (tr_variantDictFind (args, TR_KEY_rpc_version_minimum) != NULL);
136  check (tr_variantDictFind (args, TR_KEY_script_torrent_done_enabled) != NULL);
137  check (tr_variantDictFind (args, TR_KEY_script_torrent_done_filename) != NULL);
138  check (tr_variantDictFind (args, TR_KEY_seed_queue_enabled) != NULL);
139  check (tr_variantDictFind (args, TR_KEY_seed_queue_size) != NULL);
140  check (tr_variantDictFind (args, TR_KEY_seedRatioLimit) != NULL);
141  check (tr_variantDictFind (args, TR_KEY_seedRatioLimited) != NULL);
142  check (tr_variantDictFind (args, TR_KEY_speed_limit_down) != NULL);
143  check (tr_variantDictFind (args, TR_KEY_speed_limit_down_enabled) != NULL);
144  check (tr_variantDictFind (args, TR_KEY_speed_limit_up) != NULL);
145  check (tr_variantDictFind (args, TR_KEY_speed_limit_up_enabled) != NULL);
146  check (tr_variantDictFind (args, TR_KEY_start_added_torrents) != NULL);
147  check (tr_variantDictFind (args, TR_KEY_trash_original_torrent_files) != NULL);
148  check (tr_variantDictFind (args, TR_KEY_units) != NULL);
149  check (tr_variantDictFind (args, TR_KEY_utp_enabled) != NULL);
150  check (tr_variantDictFind (args, TR_KEY_version) != NULL);
151  tr_variantFree (&response);
152
153  /* cleanup */
154  tr_torrentRemove (tor, false, NULL);
155  libttest_session_close (session);
156  return 0;
157}
158
159/***
160****
161***/
162
163int
164main (void)
165{
166  const testFunc tests[] = { test_list,
167                             test_session_get_and_set };
168
169  return runTests (tests, NUM_TESTS (tests));
170}
Note: See TracBrowser for help on using the repository browser.