Browse Source
* Added a new Command type based on std::tr1::function aimed at replacing the current ones.
* 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-cc216c733640pull/30/head
13 changed files with 195 additions and 14 deletions
-
3Makefile.am
-
2configure.ac
-
27src/Makefile.am
-
5src/command_download.cc
-
9src/command_helpers.cc
-
22src/command_helpers.h
-
4src/rpc/Makefile.am
-
22test/Makefile.am
-
22test/main.cc
-
24test/rpc/command_map_test.cc
-
24test/rpc/command_map_test.h
-
28test/rpc/command_slot_test.cc
-
17test/rpc/command_slot_test.h
@ -0,0 +1,22 @@ |
|||
TESTS = rtorrentTest |
|||
check_PROGRAMS = $(TESTS) |
|||
rtorrentTest_LDADD = \
|
|||
../src/ui/libsub_ui.a \
|
|||
../src/core/libsub_core.a \
|
|||
../src/display/libsub_display.a \
|
|||
../src/input/libsub_input.a \
|
|||
../src/rpc/libsub_rpc.a \
|
|||
../src/utils/libsub_utils.a \
|
|||
../src/libsub_root.a |
|||
|
|||
rtorrentTest_SOURCES = \
|
|||
rpc/command_map_test.cc \
|
|||
rpc/command_map_test.h \
|
|||
rpc/command_slot_test.cc \
|
|||
rpc/command_slot_test.h \
|
|||
main.cc |
|||
|
|||
rtorrentTest_CXXFLAGS = $(CPPUNIT_CFLAGS) |
|||
rtorrentTest_LDFLAGS = $(CPPUNIT_LIBS) -ldl |
|||
|
|||
INCLUDES = -I$(srcdir) -I$(top_srcdir) -I$(top_srcdir)/src |
|||
@ -0,0 +1,22 @@ |
|||
#include <cppunit/CompilerOutputter.h>
|
|||
#include <cppunit/extensions/TestFactoryRegistry.h>
|
|||
#include <cppunit/ui/text/TestRunner.h>
|
|||
|
|||
int main(int argc, char* argv[]) |
|||
{ |
|||
// Get the top level suite from the registry
|
|||
CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest(); |
|||
|
|||
// Adds the test to the list of test to run
|
|||
CppUnit::TextUi::TestRunner runner; |
|||
runner.addTest( suite ); |
|||
|
|||
// Change the default outputter to a compiler error format outputter
|
|||
runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(), |
|||
std::cerr ) ); |
|||
// Run the tests.
|
|||
bool wasSucessful = runner.run(); |
|||
|
|||
// Return error code 1 if the one of test failed.
|
|||
return wasSucessful ? 0 : 1; |
|||
} |
|||
@ -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(); |
|||
}; |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue