* Added missing command_new_slot.{cc,h} files.

* Converted more commands.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1150 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2010-03-21 09:45:45 +00:00
parent 8622100e09
commit 83e993a1eb
10 changed files with 380 additions and 142 deletions
+10 -3
View File
@@ -7,6 +7,13 @@
CPPUNIT_TEST_SUITE_REGISTRATION(CommandMapTest);
#undef CMD2_A_FUNCTION
#define CMD2_A_FUNCTION(key, function, func_type, slot, parm, doc) \
commandNewSlotItr->set_function<rpc::func_type>(slot); \
m_map.insert_type(key, commandNewSlotItr++, &rpc::function, \
rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, 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); }
@@ -14,9 +21,9 @@ torrent::Object cmd_test_any_string(__UNUSED rpc::target_type target, const std:
void
CommandMapTest::test_basics() {
CMD2_A("test_a", &cmd_test_map_a);
CMD2_A("test_b", std::tr1::bind(&cmd_test_map_b, std::tr1::placeholders::_1, std::tr1::placeholders::_2, (uint64_t)2));
CMD2_A_STRING("any_string", &cmd_test_any_string);
CMD2_ANY("test_a", &cmd_test_map_a);
CMD2_ANY("test_b", std::tr1::bind(&cmd_test_map_b, std::tr1::placeholders::_1, std::tr1::placeholders::_2, (uint64_t)2));
CMD2_ANY_STRING("any_string", &cmd_test_any_string);
CPPUNIT_ASSERT(m_map.call_command("test_a", (int64_t)1).as_value() == 1);
CPPUNIT_ASSERT(m_map.call_command("test_b", (int64_t)1).as_value() == 2);
+25
View File
@@ -11,6 +11,14 @@ CPPUNIT_TEST_SUITE_REGISTRATION(CommandSlotTest);
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(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
CommandSlotTest::test_basics() {
rpc::command_base test_any;
@@ -19,6 +27,9 @@ CommandSlotTest::test_basics() {
test_any.set_function<rpc::any_function>(std::tr1::bind(&cmd_test_b, std::tr1::placeholders::_1, std::tr1::placeholders::_2, (uint64_t)2));
CPPUNIT_ASSERT(rpc::command_base_call_any(&test_any, rpc::make_target(), (int64_t)1).as_value() == 2);
test_any.set_function<rpc::any_list_function>(&cmd_test_list);
CPPUNIT_ASSERT(rpc::command_base_call_any_list(&test_any, rpc::make_target(), (int64_t)3).as_value() == 3);
}
void
@@ -26,3 +37,17 @@ CommandSlotTest::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() {
rpc::command_base test_any;
test_any.set_function<rpc::any_function>(&cmd_test_convert_string);
CPPUNIT_ASSERT(rpc::command_base_call_any(&test_any, rpc::make_target(), (int64_t)1).as_string() == "test_1");
test_any.set_function<rpc::any_function>(&cmd_test_convert_const_string);
CPPUNIT_ASSERT(rpc::command_base_call_any(&test_any, rpc::make_target(), (int64_t)1).as_string() == "test_2");
// test_any.set_function<rpc::any_function>(object_convert_void(&cmd_test_convert_void));
// CPPUNIT_ASSERT(rpc::command_base_call_any(&test_any, rpc::make_target(), (int64_t)1).is_empty());
}
+2
View File
@@ -6,6 +6,7 @@ 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:
@@ -14,4 +15,5 @@ public:
void test_basics();
void test_type_validity();
void test_convert_return();
};