Related refactoring to updated of ThrottleList to use new Scheduler.

This commit is contained in:
Jari Sundell
2025-05-12 10:38:07 +02:00
committed by GitHub
parent 6d888c008d
commit 9ff373fe58
33 changed files with 1005 additions and 230 deletions
-19
View File
@@ -1,19 +0,0 @@
#include <cppunit/extensions/HelperMacros.h>
#include "rpc/command.h"
class CommandTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(CommandTest);
CPPUNIT_TEST(test_stack);
CPPUNIT_TEST(test_stack_double);
CPPUNIT_TEST_SUITE_END();
public:
void setUp() { }
void tearDown() {}
void test_stack();
void test_stack_double();
private:
};
-19
View File
@@ -1,19 +0,0 @@
#include <cppunit/extensions/HelperMacros.h>
#include "rpc/command_map.h"
#include "rpc/jsonrpc.h"
class JsonrpcTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(JsonrpcTest);
CPPUNIT_TEST(test_basics);
CPPUNIT_TEST_SUITE_END();
public:
void setUp();
void tearDown() {}
void test_basics();
private:
rpc::JsonRpc m_jsonrpc;
};
@@ -1,8 +1,10 @@
#include "config.h"
#include "command_test.h"
#include "test/rpc/test_command.h"
CPPUNIT_TEST_SUITE_REGISTRATION(CommandTest);
#include "rpc/command.h"
CPPUNIT_TEST_SUITE_REGISTRATION(TestCommand);
bool
command_stack_all_empty() {
@@ -11,7 +13,7 @@ command_stack_all_empty() {
}
void
CommandTest::test_stack() {
TestCommand::test_stack() {
torrent::Object::list_type args;
rpc::command_base::stack_type stack;
torrent::Object* last_stack;
@@ -50,7 +52,7 @@ CommandTest::test_stack() {
}
void
CommandTest::test_stack_double() {
TestCommand::test_stack_double() {
torrent::Object::list_type args;
rpc::command_base::stack_type stack_first;
rpc::command_base::stack_type stack_second;
+14
View File
@@ -0,0 +1,14 @@
#include "test/helpers/test_fixture.h"
class TestCommand : public test_fixture {
CPPUNIT_TEST_SUITE(TestCommand);
CPPUNIT_TEST(test_stack);
CPPUNIT_TEST(test_stack_double);
CPPUNIT_TEST_SUITE_END();
public:
void test_stack();
void test_stack_double();
};
@@ -1,11 +1,11 @@
#include "config.h"
#include "test/rpc/test_command_map.h"
#include "command_helpers.h"
#include "rpc/command_map.h"
#include "command_map_test.h"
CPPUNIT_TEST_SUITE_REGISTRATION(CommandMapTest);
CPPUNIT_TEST_SUITE_REGISTRATION(TestCommandMap);
#undef CMD2_A_FUNCTION
@@ -13,13 +13,13 @@ CPPUNIT_TEST_SUITE_REGISTRATION(CommandMapTest);
m_map.insert_slot<rpc::command_base_is_type<rpc::function>::type>(key, slot, &rpc::function, \
rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_rpc, NULL, NULL);
torrent::Object cmd_test_map_a(rpc::target_type t, const torrent::Object& obj) { return obj; }
torrent::Object cmd_test_map_b(rpc::target_type t, const torrent::Object& obj, uint64_t c) { return torrent::Object(c); }
torrent::Object cmd_test_map_a([[maybe_unused]] rpc::target_type t, const torrent::Object& obj) { return obj; }
torrent::Object cmd_test_map_b([[maybe_unused]] rpc::target_type t, [[maybe_unused]] const torrent::Object& obj, uint64_t c) { return torrent::Object(c); }
torrent::Object cmd_test_any_string(__UNUSED rpc::target_type target, const std::string& rawArgs) { return (int64_t)3; }
torrent::Object cmd_test_any_string([[maybe_unused]] rpc::target_type target, [[maybe_unused]] const std::string& rawArgs) { return (int64_t)3; }
void
CommandMapTest::test_basics() {
TestCommandMap::test_basics() {
CMD2_ANY("test_a", &cmd_test_map_a);
CMD2_ANY("test_b", std::bind(&cmd_test_map_b, std::placeholders::_1, std::placeholders::_2, (uint64_t)2));
CMD2_ANY_STRING("any_string", &cmd_test_any_string);
@@ -1,17 +1,18 @@
#include <cppunit/extensions/HelperMacros.h>
#include "test/helpers/test_fixture.h"
#include "rpc/command_map.h"
class CommandMapTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(CommandMapTest);
class TestCommandMap : public test_fixture {
CPPUNIT_TEST_SUITE(TestCommandMap);
CPPUNIT_TEST(test_basics);
CPPUNIT_TEST_SUITE_END();
public:
static const int cmd_size = 256;
void setUp() { m_commandItr = m_commands; }
void tearDown() {}
void test_basics();
@@ -1,26 +1,27 @@
#include "config.h"
#include "test/rpc/test_command_slot.h"
#include <sstream>
#include <torrent/object.h>
#include "rpc/command_map.h"
#include "command_slot_test.h"
CPPUNIT_TEST_SUITE_REGISTRATION(TestCommandSlot);
CPPUNIT_TEST_SUITE_REGISTRATION(CommandSlotTest);
torrent::Object cmd_test_a([[maybe_unused]] rpc::target_type t, const torrent::Object& obj) { return obj; }
torrent::Object cmd_test_b([[maybe_unused]] rpc::target_type t, [[maybe_unused]] const torrent::Object& obj, uint64_t c) { return torrent::Object(c); }
torrent::Object cmd_test_a(rpc::target_type t, const torrent::Object& obj) { return obj; }
torrent::Object cmd_test_b(rpc::target_type t, const torrent::Object& obj, uint64_t c) { return torrent::Object(c); }
torrent::Object cmd_test_list([[maybe_unused]] rpc::target_type t, const torrent::Object::list_type& obj) { return torrent::Object(obj.front()); }
torrent::Object cmd_test_list(rpc::target_type t, const torrent::Object::list_type& obj) { return torrent::Object(obj.front()); }
void cmd_test_convert_void(rpc::target_type t, const torrent::Object& obj) {}
int32_t cmd_test_convert_int32_t(rpc::target_type t, const torrent::Object& obj) { return 9; }
int64_t cmd_test_convert_int64_t(rpc::target_type t, const torrent::Object& obj) { return 10; }
std::string cmd_test_convert_string(rpc::target_type t, const torrent::Object& obj) { return "test_1"; }
const std::string& cmd_test_convert_const_string(rpc::target_type t, const torrent::Object& obj) { static const std::string ret = "test_2"; return ret; }
void cmd_test_convert_void([[maybe_unused]] rpc::target_type t, [[maybe_unused]] const torrent::Object& obj) {}
int32_t cmd_test_convert_int32_t([[maybe_unused]] rpc::target_type t, [[maybe_unused]] const torrent::Object& obj) { return 9; }
int64_t cmd_test_convert_int64_t([[maybe_unused]] rpc::target_type t, [[maybe_unused]] const torrent::Object& obj) { return 10; }
std::string cmd_test_convert_string([[maybe_unused]] rpc::target_type t, [[maybe_unused]] const torrent::Object& obj) { return "test_1"; }
const std::string& cmd_test_convert_const_string([[maybe_unused]] rpc::target_type t, [[maybe_unused]] const torrent::Object& obj) { static const std::string ret = "test_2"; return ret; }
void
CommandSlotTest::test_basics() {
TestCommandSlot::test_basics() {
// rpc::command_base test_any;
// test_any.set_function<rpc::any_function>(&cmd_test_a);
// CPPUNIT_ASSERT(rpc::command_base_call_any(&test_any, rpc::make_target(), (int64_t)1).as_value() == 1);
@@ -33,13 +34,13 @@ CommandSlotTest::test_basics() {
}
void
CommandSlotTest::test_type_validity() {
TestCommandSlot::test_type_validity() {
// CPPUNIT_ASSERT((rpc::command_base_is_type<rpc::any_function, &rpc::command_base_call_any>::value));
// CPPUNIT_ASSERT((rpc::command_base_is_type<rpc::any_string_function, &rpc::command_base_call_any_string>::value));
}
void
CommandSlotTest::test_convert_return() {
TestCommandSlot::test_convert_return() {
// rpc::command_base test_any;
// test_any.set_function<rpc::any_function>(&cmd_test_convert_string);
@@ -1,18 +1,15 @@
#include <cppunit/extensions/HelperMacros.h>
#include "test/helpers/test_fixture.h"
#include "rpc/command.h"
class TestCommandSlot : public test_fixture {
CPPUNIT_TEST_SUITE(TestCommandSlot);
class CommandSlotTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(CommandSlotTest);
CPPUNIT_TEST(test_basics);
CPPUNIT_TEST(test_type_validity);
CPPUNIT_TEST(test_convert_return);
CPPUNIT_TEST_SUITE_END();
public:
void setUp() {}
void tearDown() {}
void test_basics();
void test_type_validity();
void test_convert_return();
@@ -1,14 +1,15 @@
#include "config.h"
#include <string>
#include "command_helpers.h"
#include "rpc/command_map.h"
#include "test/rpc/test_jsonrpc.h"
#include <string>
#include "control.h"
#include "globals.h"
#include "jsonrpc_test.h"
#include "command_helpers.h"
#include "rpc/command_map.h"
CPPUNIT_TEST_SUITE_REGISTRATION(JsonrpcTest);
CPPUNIT_TEST_SUITE_REGISTRATION(TestJsonrpc);
torrent::Object
jsonrpc_cmd_test_reflect([[maybe_unused]] rpc::target_type t, const torrent::Object& obj) { return obj; }
@@ -117,19 +118,27 @@ std::vector<std::tuple<std::string, std::string, std::string>> basic_jsonrpc_req
};
void
JsonrpcTest::setUp() {
TestJsonrpc::setUp() {
m_test_main_thread = TestMainThread::create();
m_test_main_thread->init_thread();
m_jsonrpc = rpc::JsonRpc();
m_jsonrpc.initialize();
setlocale(LC_ALL, "");
// cachedTime = rak::timer::current();
control = new Control;
control = new Control;
if (rpc::commands.find("jsonrpc_reflect") == rpc::commands.end()) {
CMD2_ANY("jsonrpc_reflect", &jsonrpc_cmd_test_reflect);
}
}
void
JsonrpcTest::test_basics() {
TestJsonrpc::tearDown() {
m_test_main_thread.reset();
}
void
TestJsonrpc::test_basics() {
for (auto& test : basic_jsonrpc_requests) {
std::string output;
m_jsonrpc.process(std::get<1>(test).c_str(), std::get<1>(test).size(), [&output](const char* c, uint32_t l) { output.append(c, l); return true; });
+24
View File
@@ -0,0 +1,24 @@
#include "test/helpers/test_fixture.h"
#include "test/helpers/test_main_thread.h"
#include "rpc/command_map.h"
#include "rpc/jsonrpc.h"
class TestJsonrpc : public test_fixture {
CPPUNIT_TEST_SUITE(TestJsonrpc);
CPPUNIT_TEST(test_basics);
CPPUNIT_TEST_SUITE_END();
public:
void setUp();
void tearDown();
void test_basics();
private:
std::unique_ptr<TestMainThread> m_test_main_thread;
rpc::JsonRpc m_jsonrpc;
};
@@ -1,16 +1,17 @@
#include "config.h"
#include "object_storage_test.h"
#include "test/rpc/test_object_storage.h"
#include "helpers/assert.h"
CPPUNIT_TEST_SUITE_REGISTRATION(ObjectStorageTest);
CPPUNIT_TEST_SUITE_REGISTRATION(TestObjectStorage);
void
ObjectStorageTest::test_basics() {
TestObjectStorage::test_basics() {
rpc::object_storage::iterator itr;
CPPUNIT_ASSERT(m_storage.empty());
itr = m_storage.insert("test_1", torrent::Object("a"), rpc::object_storage::flag_string_type);
CPPUNIT_ASSERT(itr != m_storage.end());
@@ -32,7 +33,7 @@ ObjectStorageTest::test_basics() {
}
void
ObjectStorageTest::test_conversions() {
TestObjectStorage::test_conversions() {
CPPUNIT_ASSERT(m_storage.insert("test_1", torrent::Object("a"), rpc::object_storage::flag_string_type) != m_storage.end());
CPPUNIT_ASSERT(m_storage.insert_str(std::string("test_2"), torrent::Object("a"), rpc::object_storage::flag_string_type) != m_storage.end());
@@ -44,7 +45,7 @@ ObjectStorageTest::test_conversions() {
}
void
ObjectStorageTest::test_validate_keys() {
TestObjectStorage::test_validate_keys() {
torrent::raw_string raw_string_4("test_4\0foo", 10);
ASSERT_CATCH_INPUT_ERROR( { m_storage.insert(raw_string_4, torrent::Object("a"), rpc::object_storage::flag_string_type); } );
@@ -55,7 +56,7 @@ ObjectStorageTest::test_validate_keys() {
// Test for various conversions of fixed_key_type.
void
ObjectStorageTest::test_access() {
TestObjectStorage::test_access() {
m_storage.insert("string_1", torrent::Object("gen_a"), rpc::object_storage::flag_string_type);
m_storage.insert("value_1", int64_t(1), rpc::object_storage::flag_value_type);
@@ -68,7 +69,7 @@ ObjectStorageTest::test_access() {
// CPPUNIT_ASSERT(m_storage.set_c_str_value("value_1", "123").as_value() == 123);
// CPPUNIT_ASSERT(m_storage.set_c_str_value("value_1", torrent::raw_string::from_c_str("321")).as_value() == 321);
// CPPUNIT_ASSERT(m_storage.set_c_str_value("value_1", torrent::raw_bencode::from_c_str("i567e")).as_value() == 567);
// ASSERT_CATCH_INPUT_ERROR( { m_storage.set_c_str_value("value_1", "e123"); } );
// Test string from raw and normal, list, etc.
@@ -1,19 +1,18 @@
#include <cppunit/extensions/HelperMacros.h>
#include "test/helpers/test_fixture.h"
#include "rpc/object_storage.h"
class ObjectStorageTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(ObjectStorageTest);
class TestObjectStorage : public test_fixture {
CPPUNIT_TEST_SUITE(TestObjectStorage);
CPPUNIT_TEST(test_basics);
CPPUNIT_TEST(test_conversions);
CPPUNIT_TEST(test_validate_keys);
CPPUNIT_TEST(test_access);
CPPUNIT_TEST_SUITE_END();
public:
void setUp() { }
void tearDown() {}
void test_basics();
void test_conversions();
+4 -5
View File
@@ -1,8 +1,6 @@
#include "config.h"
#include "test_parse_options.h"
#include "helpers/assert.h"
#include "test/rpc/test_parse_options.h"
#include <array>
#include <torrent/connection_manager.h>
@@ -10,6 +8,7 @@
#include <torrent/utils/log.h>
#include <torrent/utils/option_strings.h>
#include "test/helpers/assert.h"
#include "rpc/parse_options.h"
CPPUNIT_TEST_SUITE_REGISTRATION(TestParseOptions);
@@ -37,7 +36,7 @@ flag_to_int(const std::string& flag) {
for (auto f : flag_list)
if (f.first == flag)
return f.second;
throw torrent::input_error("unknown flag");
}
@@ -86,7 +85,7 @@ TestParseOptions::test_flag_error() {
FLAG_ASSERT_ERROR("");
FLAG_ASSERT_ERROR("foo|bar");
FLAG_ASSERT_ERROR("foo|bar|baz");
FLAG_ASSERT_ERROR("foo |bar");
FLAG_ASSERT_ERROR("foo | bar| baz");
}
+4 -5
View File
@@ -1,7 +1,8 @@
#include <cppunit/extensions/HelperMacros.h>
#include "test/helpers/test_fixture.h"
class TestParseOptions : public CppUnit::TestFixture {
class TestParseOptions : public test_fixture {
CPPUNIT_TEST_SUITE(TestParseOptions);
CPPUNIT_TEST(test_flag_basic);
CPPUNIT_TEST(test_flag_error);
@@ -14,12 +15,10 @@ class TestParseOptions : public CppUnit::TestFixture {
CPPUNIT_TEST(test_flag_libtorrent);
CPPUNIT_TEST(test_flags_libtorrent);
CPPUNIT_TEST_SUITE_END();
public:
void setUp() { }
void tearDown() {}
void test_flag_basic();
void test_flag_error();
@@ -1,14 +1,15 @@
#include "config.h"
#include "test/rpc/test_xmlrpc.h"
#include <string>
#include "control.h"
#include "globals.h"
#include "command_helpers.h"
#include "rpc/command_map.h"
#include "xmlrpc_test.h"
#include "control.h"
#include "globals.h"
CPPUNIT_TEST_SUITE_REGISTRATION(XmlrpcTest);
CPPUNIT_TEST_SUITE_REGISTRATION(TestXmlrpc);
torrent::Object xmlrpc_cmd_test_reflect([[maybe_unused]] rpc::target_type t, const torrent::Object& obj) { return obj; }
@@ -99,19 +100,27 @@ std::vector<std::tuple<std::string, std::string, std::string>> basic_requests =
};
void
XmlrpcTest::setUp() {
TestXmlrpc::setUp() {
m_test_main_thread = TestMainThread::create();
m_test_main_thread->init_thread();
m_xmlrpc = rpc::XmlRpc();
m_xmlrpc.initialize();
setlocale(LC_ALL, "");
// cachedTime = rak::timer::current();
control = new Control;
if (rpc::commands.find("xmlrpc_reflect") == rpc::commands.end()) {
CMD2_ANY("xmlrpc_reflect", &xmlrpc_cmd_test_reflect);
}
}
void
XmlrpcTest::test_basics() {
TestXmlrpc::tearDown() {
m_test_main_thread.reset();
}
void
TestXmlrpc::test_basics() {
for (auto& test : basic_requests) {
std::string output;
m_xmlrpc.process(std::get<1>(test).c_str(), std::get<1>(test).size(), [&output](const char* c, uint32_t l){ output.append(c, l); return true;});
@@ -120,7 +129,7 @@ XmlrpcTest::test_basics() {
}
void
XmlrpcTest::test_invalid_utf8() {
TestXmlrpc::test_invalid_utf8() {
// Surprisingly, this call doesn't fail. TinyXML-2 technically expects
// valid UTF-8, but doesn't check strings, and Object strings are
// just a series of bytes so it reflects just fine.
@@ -132,7 +141,7 @@ XmlrpcTest::test_invalid_utf8() {
}
void
XmlrpcTest::test_size_limit() {
TestXmlrpc::test_size_limit() {
std::string input = "<?xml version=\"1.0\"?><methodCall><methodName>xmlrpc_reflect</methodName><params><param><value><string></string></value></param><param><value><string>\xc3\x28</string></value></param></params></methodCall>";
std::string expected = "<?xml version=\"1.0\"?><methodResponse><fault><value><struct><member><name>faultCode</name><value><i8>-509</i8></value></member><member><name>faultString</name><value><string>Content size exceeds maximum XML-RPC limit</string></value></member></struct></value></fault></methodResponse>";
std::string output;
@@ -140,9 +149,13 @@ XmlrpcTest::test_size_limit() {
m_xmlrpc.process(input.c_str(), input.size(), [&output](const char* c, uint32_t l){ output.append(c, l); return true;});
CPPUNIT_ASSERT_EQUAL(expected, output);
}
#else
void XmlrpcTest::test_invalid_utf8() {}
void XmlrpcTest::test_basics() {}
void XmlrpcTest::test_size_limit() {}
void XmlrpcTest::setUp() {}
void TestXmlrpc::test_invalid_utf8() {}
void TestXmlrpc::test_basics() {}
void TestXmlrpc::test_size_limit() {}
void TestXmlrpc::setUp() {}
void TestXmlrpc::tearDown() {}
#endif
@@ -1,29 +1,32 @@
#include <cppunit/extensions/HelperMacros.h>
#include "test/helpers/test_fixture.h"
#include "test/helpers/test_main_thread.h"
#include "rpc/command_map.h"
#include "rpc/xmlrpc.h"
class XmlrpcTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(XmlrpcTest);
class TestXmlrpc : public test_fixture {
CPPUNIT_TEST_SUITE(TestXmlrpc);
CPPUNIT_TEST(test_basics);
CPPUNIT_TEST(test_invalid_utf8);
CPPUNIT_TEST(test_size_limit);
CPPUNIT_TEST_SUITE_END();
public:
static const int cmd_size = 256;
void setUp();
void tearDown() {}
void tearDown();
void test_basics();
void test_invalid_utf8();
void test_size_limit();
private:
rpc::XmlRpc m_xmlrpc;
rpc::CommandMap m_map;
std::unique_ptr<TestMainThread> m_test_main_thread;
rpc::XmlRpc m_xmlrpc;
rpc::CommandMap m_map;
rpc::command_base m_commands[cmd_size];
};