You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
2.6 KiB

  1. #include "config.h"
  2. #include <sstream>
  3. #include <torrent/object.h>
  4. #include "rpc/command_map.h"
  5. #include "command_slot_test.h"
  6. CPPUNIT_TEST_SUITE_REGISTRATION(CommandSlotTest);
  7. torrent::Object cmd_test_a(rpc::target_type t, const torrent::Object& obj) { return obj; }
  8. torrent::Object cmd_test_b(rpc::target_type t, const torrent::Object& obj, uint64_t c) { return torrent::Object(c); }
  9. torrent::Object cmd_test_list(rpc::target_type t, const torrent::Object::list_type& obj) { return torrent::Object(obj.front()); }
  10. void cmd_test_convert_void(rpc::target_type t, const torrent::Object& obj) {}
  11. int32_t cmd_test_convert_int32_t(rpc::target_type t, const torrent::Object& obj) { return 9; }
  12. int64_t cmd_test_convert_int64_t(rpc::target_type t, const torrent::Object& obj) { return 10; }
  13. std::string cmd_test_convert_string(rpc::target_type t, const torrent::Object& obj) { return "test_1"; }
  14. 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; }
  15. void
  16. CommandSlotTest::test_basics() {
  17. // rpc::command_base test_any;
  18. // test_any.set_function<rpc::any_function>(&cmd_test_a);
  19. // CPPUNIT_ASSERT(rpc::command_base_call_any(&test_any, rpc::make_target(), (int64_t)1).as_value() == 1);
  20. // test_any.set_function<rpc::any_function>(tr1::bind(&cmd_test_b, tr1::placeholders::_1, tr1::placeholders::_2, (uint64_t)2));
  21. // CPPUNIT_ASSERT(rpc::command_base_call_any(&test_any, rpc::make_target(), (int64_t)1).as_value() == 2);
  22. // test_any.set_function<rpc::any_list_function>(&cmd_test_list);
  23. // CPPUNIT_ASSERT(rpc::command_base_call_any_list(&test_any, rpc::make_target(), (int64_t)3).as_value() == 3);
  24. }
  25. void
  26. CommandSlotTest::test_type_validity() {
  27. // CPPUNIT_ASSERT((rpc::command_base_is_type<rpc::any_function, &rpc::command_base_call_any>::value));
  28. // CPPUNIT_ASSERT((rpc::command_base_is_type<rpc::any_string_function, &rpc::command_base_call_any_string>::value));
  29. }
  30. void
  31. CommandSlotTest::test_convert_return() {
  32. // rpc::command_base test_any;
  33. // test_any.set_function<rpc::any_function>(&cmd_test_convert_string);
  34. // CPPUNIT_ASSERT(rpc::command_base_call_any(&test_any, rpc::make_target(), (int64_t)1).as_string() == "test_1");
  35. // test_any.set_function<rpc::any_function>(&cmd_test_convert_const_string);
  36. // CPPUNIT_ASSERT(rpc::command_base_call_any(&test_any, rpc::make_target(), (int64_t)1).as_string() == "test_2");
  37. // test_any.set_function<rpc::any_function>(object_convert_void(&cmd_test_convert_void));
  38. // CPPUNIT_ASSERT(rpc::command_base_call_any(&test_any, rpc::make_target(), (int64_t)1).is_empty());
  39. }