mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-09 15:49:20 +00:00
* Added a new Command type based on std::tr1::function aimed at replacing the current ones.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1149 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "command_helpers.h"
|
||||
#include "rpc/command_map.h"
|
||||
|
||||
#import "command_map_test.h"
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(CommandMapTest);
|
||||
|
||||
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_any_string(__UNUSED rpc::target_type target, const std::string& rawArgs) { return (int64_t)3; }
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
CPPUNIT_ASSERT(m_map.call_command("any_string", "").as_value() == 3);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
#include "rpc/command_map.h"
|
||||
#include "rpc/command_new_slot.h"
|
||||
|
||||
class CommandMapTest : public CppUnit::TestFixture {
|
||||
CPPUNIT_TEST_SUITE(CommandMapTest);
|
||||
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();
|
||||
|
||||
private:
|
||||
rpc::CommandMap m_map;
|
||||
|
||||
rpc::command_base m_commands[cmd_size];
|
||||
rpc::command_base* m_commandItr;
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <torrent/object.h>
|
||||
#include "rpc/command_map.h"
|
||||
|
||||
#import "command_slot_test.h"
|
||||
|
||||
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); }
|
||||
|
||||
void
|
||||
CommandSlotTest::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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void
|
||||
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));
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
#include "rpc/command_new_slot.h"
|
||||
|
||||
class CommandSlotTest : public CppUnit::TestFixture {
|
||||
CPPUNIT_TEST_SUITE(CommandSlotTest);
|
||||
CPPUNIT_TEST(test_basics);
|
||||
CPPUNIT_TEST(test_type_validity);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
void setUp() {}
|
||||
void tearDown() {}
|
||||
|
||||
void test_basics();
|
||||
void test_type_validity();
|
||||
};
|
||||
Reference in New Issue
Block a user