2014-01-19 01:09:44 +00:00
|
|
|
/*
|
|
|
|
* This file Copyright (C) 2013-2014 Mnemosyne LLC
|
|
|
|
*
|
2014-01-21 03:10:30 +00:00
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
2014-01-19 01:09:44 +00:00
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-06-04 17:14:58 +00:00
|
|
|
#include "transmission.h"
|
2008-09-05 14:31:58 +00:00
|
|
|
#include "rpcimpl.h"
|
2008-06-04 17:14:58 +00:00
|
|
|
#include "utils.h"
|
2012-12-14 04:34:42 +00:00
|
|
|
#include "variant.h"
|
2008-06-04 17:14:58 +00:00
|
|
|
|
2012-08-18 16:07:05 +00:00
|
|
|
#include "libtransmission-test.h"
|
2008-06-04 17:14:58 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static int test_list(void)
|
2008-07-21 16:11:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
size_t len;
|
|
|
|
int64_t i;
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* str;
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variant top;
|
|
|
|
|
|
|
|
tr_rpc_parse_list_str(&top, "12", TR_BAD_SIZE);
|
|
|
|
check(tr_variantIsInt(&top));
|
|
|
|
check(tr_variantGetInt(&top, &i));
|
2017-05-29 20:22:36 +00:00
|
|
|
check_int(i, ==, 12);
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variantFree(&top);
|
|
|
|
|
|
|
|
tr_rpc_parse_list_str(&top, "12", 1);
|
|
|
|
check(tr_variantIsInt(&top));
|
|
|
|
check(tr_variantGetInt(&top, &i));
|
2017-05-29 20:22:36 +00:00
|
|
|
check_int(i, ==, 1);
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variantFree(&top);
|
|
|
|
|
|
|
|
tr_rpc_parse_list_str(&top, "6,7", TR_BAD_SIZE);
|
|
|
|
check(tr_variantIsList(&top));
|
2017-05-30 17:56:12 +00:00
|
|
|
check_uint(tr_variantListSize(&top), ==, 2);
|
2017-04-19 12:04:45 +00:00
|
|
|
check(tr_variantGetInt(tr_variantListChild(&top, 0), &i));
|
2017-05-29 20:22:36 +00:00
|
|
|
check_int(i, ==, 6);
|
2017-04-19 12:04:45 +00:00
|
|
|
check(tr_variantGetInt(tr_variantListChild(&top, 1), &i));
|
2017-05-29 20:22:36 +00:00
|
|
|
check_int(i, ==, 7);
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variantFree(&top);
|
|
|
|
|
|
|
|
tr_rpc_parse_list_str(&top, "asdf", TR_BAD_SIZE);
|
|
|
|
check(tr_variantIsString(&top));
|
|
|
|
check(tr_variantGetStr(&top, &str, &len));
|
2017-05-29 20:39:51 +00:00
|
|
|
check_uint(len, ==, 4);
|
2017-05-29 19:48:02 +00:00
|
|
|
check_str(str, ==, "asdf");
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variantFree(&top);
|
|
|
|
|
|
|
|
tr_rpc_parse_list_str(&top, "1,3-5", TR_BAD_SIZE);
|
|
|
|
check(tr_variantIsList(&top));
|
2017-05-30 17:56:12 +00:00
|
|
|
check_uint(tr_variantListSize(&top), ==, 4);
|
2017-04-19 12:04:45 +00:00
|
|
|
check(tr_variantGetInt(tr_variantListChild(&top, 0), &i));
|
2017-05-29 20:22:36 +00:00
|
|
|
check_int(i, ==, 1);
|
2017-04-19 12:04:45 +00:00
|
|
|
check(tr_variantGetInt(tr_variantListChild(&top, 1), &i));
|
2017-05-29 20:22:36 +00:00
|
|
|
check_int(i, ==, 3);
|
2017-04-19 12:04:45 +00:00
|
|
|
check(tr_variantGetInt(tr_variantListChild(&top, 2), &i));
|
2017-05-29 20:22:36 +00:00
|
|
|
check_int(i, ==, 4);
|
2017-04-19 12:04:45 +00:00
|
|
|
check(tr_variantGetInt(tr_variantListChild(&top, 3), &i));
|
2017-05-29 20:22:36 +00:00
|
|
|
check_int(i, ==, 5);
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variantFree(&top);
|
|
|
|
|
|
|
|
return 0;
|
2013-01-21 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void rpc_response_func(tr_session* session UNUSED, tr_variant* response, void* setme)
|
2013-01-21 00:00:00 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
*(tr_variant*)setme = *response;
|
|
|
|
tr_variantInitBool(response, false);
|
2008-07-21 16:11:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static int test_session_get_and_set(void)
|
2013-01-21 00:00:00 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_session* session;
|
|
|
|
tr_variant request;
|
|
|
|
tr_variant response;
|
|
|
|
tr_variant* args;
|
|
|
|
tr_torrent* tor;
|
|
|
|
|
|
|
|
session = libttest_session_init(NULL);
|
|
|
|
tor = libttest_zero_torrent_init(session);
|
2017-05-30 17:56:12 +00:00
|
|
|
check_ptr(tor, !=, NULL);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
tr_variantInitDict(&request, 1);
|
|
|
|
tr_variantDictAddStr(&request, TR_KEY_method, "session-get");
|
|
|
|
tr_rpc_request_exec_json(session, &request, rpc_response_func, &response);
|
|
|
|
tr_variantFree(&request);
|
|
|
|
|
|
|
|
check(tr_variantIsDict(&response));
|
|
|
|
check(tr_variantDictFindDict(&response, TR_KEY_arguments, &args));
|
2017-05-30 17:56:12 +00:00
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_alt_speed_down), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_alt_speed_enabled), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_alt_speed_time_begin), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_alt_speed_time_day), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_alt_speed_time_enabled), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_alt_speed_time_end), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_alt_speed_up), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_blocklist_enabled), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_blocklist_size), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_blocklist_url), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_cache_size_mb), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_config_dir), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_dht_enabled), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_download_dir), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_download_dir_free_space), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_download_queue_enabled), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_download_queue_size), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_encryption), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_idle_seeding_limit), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_idle_seeding_limit_enabled), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_incomplete_dir), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_incomplete_dir_enabled), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_lpd_enabled), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_peer_limit_global), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_peer_limit_per_torrent), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_peer_port), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_peer_port_random_on_start), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_pex_enabled), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_port_forwarding_enabled), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_queue_stalled_enabled), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_queue_stalled_minutes), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_rename_partial_files), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_rpc_version), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_rpc_version_minimum), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_script_torrent_done_enabled), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_script_torrent_done_filename), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_seed_queue_enabled), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_seed_queue_size), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_seedRatioLimit), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_seedRatioLimited), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_speed_limit_down), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_speed_limit_down_enabled), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_speed_limit_up), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_speed_limit_up_enabled), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_start_added_torrents), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_trash_original_torrent_files), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_units), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_utp_enabled), !=, NULL);
|
|
|
|
check_ptr(tr_variantDictFind(args, TR_KEY_version), !=, NULL);
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variantFree(&response);
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
tr_torrentRemove(tor, false, NULL);
|
|
|
|
libttest_session_close(session);
|
|
|
|
return 0;
|
2013-01-21 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
int main(void)
|
2013-01-21 00:00:00 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
testFunc const tests[] =
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
test_list,
|
|
|
|
test_session_get_and_set
|
|
|
|
};
|
2013-01-21 00:00:00 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return runTests(tests, NUM_TESTS(tests));
|
2013-01-21 00:00:00 +00:00
|
|
|
}
|