diff --git a/src/input/input_event.h b/src/input/input_event.h index b98a1d29..a3dbc5ad 100644 --- a/src/input/input_event.h +++ b/src/input/input_event.h @@ -2,12 +2,11 @@ #define RTORRENT_INPUT_INPUT_EVENT_H #include - -#include +#include namespace input { -class InputEvent : public torrent::Event { +class InputEvent : public torrent::system::Event { public: typedef std::function slot_int; diff --git a/src/rpc/scgi.h b/src/rpc/scgi.h index b475cf20..e0a50d7b 100644 --- a/src/rpc/scgi.h +++ b/src/rpc/scgi.h @@ -3,13 +3,13 @@ #include #include -#include +#include #include "rpc/scgi_task.h" namespace rpc { -class SCgi : public torrent::Event { +class SCgi : public torrent::system::Event { public: static const int max_tasks = 100; diff --git a/src/rpc/scgi_task.h b/src/rpc/scgi_task.h index 8cb30184..bffe8101 100644 --- a/src/rpc/scgi_task.h +++ b/src/rpc/scgi_task.h @@ -4,13 +4,13 @@ #include #include #include -#include +#include namespace rpc { class SCgi; -class SCgiTask : public torrent::Event { +class SCgiTask : public torrent::system::Event { public: static constexpr int default_buffer_size = 8191; static constexpr int max_header_size = 2000; diff --git a/test/helpers/mock_compare.h b/test/helpers/mock_compare.h index e84a6be8..e47104d0 100644 --- a/test/helpers/mock_compare.h +++ b/test/helpers/mock_compare.h @@ -2,9 +2,10 @@ #define LIBTORRENT_HELPERS_MOCK_COMPARE_H #include +#include #include -#include #include +#include // Compare arguments to mock functions with what is expected. The lhs // are the expected arguments, rhs are the ones called with. @@ -13,13 +14,13 @@ template inline bool mock_compare_arg(Arg lhs, Arg rhs) { return lhs == rhs; } template -typename std::enable_if::type +std::enable_if_t mock_compare_tuple(const std::tuple& lhs, const std::tuple& rhs) { return mock_compare_arg(std::get(lhs), std::get(rhs)) ? 0 : 1; } template -typename std::enable_if<1 < I, int>::type +std::enable_if_t<1 < I, int> mock_compare_tuple(const std::tuple& lhs, const std::tuple& rhs) { auto res = mock_compare_tuple(lhs, rhs); @@ -70,24 +71,37 @@ void mock_compare_add(T* v) { // Specialize: // +constexpr int mock_compare_gt_two_int = -0xFD30; + +template <> +inline bool mock_compare_arg(int lhs, int rhs) { + if (lhs == mock_compare_gt_two_int) + return rhs > 2; + if (rhs == mock_compare_gt_two_int) + return lhs > 2; + + return lhs == rhs; +} + template <> inline bool mock_compare_arg(sockaddr* lhs, sockaddr* rhs) { return lhs != nullptr && rhs != nullptr && torrent::sa_equal(lhs, rhs); } + template <> inline bool mock_compare_arg(const sockaddr* lhs, const sockaddr* rhs) { return lhs != nullptr && rhs != nullptr && torrent::sa_equal(lhs, rhs); } template <> -inline bool mock_compare_arg(torrent::Event* lhs, torrent::Event* rhs) { - if (mock_compare_map::is_key(lhs)) { - if (!mock_compare_map::has_value(rhs)) { - mock_compare_map::values[lhs] = rhs; +inline bool mock_compare_arg(torrent::system::Event* lhs, torrent::system::Event* rhs) { + if (mock_compare_map::is_key(lhs)) { + if (!mock_compare_map::has_value(rhs)) { + mock_compare_map::values[lhs] = rhs; return true; } - return mock_compare_map::has_key(lhs) && mock_compare_map::get(lhs) == rhs; + return mock_compare_map::has_key(lhs) && mock_compare_map::get(lhs) == rhs; } return lhs == rhs; diff --git a/test/helpers/mock_function.cc b/test/helpers/mock_function.cc index 9c384246..3c716e37 100644 --- a/test/helpers/mock_function.cc +++ b/test/helpers/mock_function.cc @@ -6,9 +6,9 @@ #include #include -#include "torrent/event.h" #include "torrent/net/socket_address.h" #include "torrent/net/fd.h" +#include "torrent/system/event.h" #include "torrent/utils/log.h" #include "torrent/utils/random.h" @@ -32,7 +32,7 @@ mock_clear(bool ignore_assert) { MOCK_CLEANUP_MAP(torrent::random_uniform_uint16); MOCK_CLEANUP_MAP(torrent::random_uniform_uint32); - mock_compare_map::values.clear(); + mock_compare_map::values.clear(); } } // namespace @@ -55,7 +55,9 @@ mock_redirect_defaults([[maybe_unused]] mock_redirect_flags flags) { mock_redirect(torrent::fd__close, std::function([](int fildes) { return ::close(fildes); })); mock_redirect(torrent::fd__fcntl_int, std::function([](int fildes, int cmd, int arg) { return ::fcntl(fildes, cmd, arg); })); - mock_redirect(torrent::fd__setsockopt_int, std::function([](int socket, int level, int option_name, int option_value) { return ::setsockopt(socket, level, option_name, &option_value, sizeof(int)); })); + mock_redirect(torrent::fd__setsockopt_int, std::function([](int socket, int level, int option_name, int option_value) { + return ::setsockopt(socket, level, option_name, &option_value, sizeof(int)); + })); mock_redirect(torrent::fd__socket, std::function([](int domain, int type, int protocol) { return ::socket(domain, type, protocol); })); } @@ -112,69 +114,6 @@ int fd__socket(int domain, int type, int protocol) { return mock_call(__func__, &torrent::fd__socket, domain, type, protocol); } -// -// Mock functions for 'torrent/common.h': -// - -namespace this_thread { - -void event_open(Event* event) { - MOCK_LOG("fd:%i type_name:%s", event->file_descriptor(), event->type_name()); - return mock_call(__func__, &torrent::this_thread::event_open, event); -} - -void event_open_and_count(Event* event) { - MOCK_LOG("fd:%i type_name:%s", event->file_descriptor(), event->type_name()); - return mock_call(__func__, &torrent::this_thread::event_open_and_count, event); -} - -void event_close_and_count(Event* event) { - MOCK_LOG("fd:%i type_name:%s", event->file_descriptor(), event->type_name()); - return mock_call(__func__, &torrent::this_thread::event_close_and_count, event); -} - -void event_closed_and_count(Event* event) { - MOCK_LOG("fd:%i type_name:%s", event->file_descriptor(), event->type_name()); - return mock_call(__func__, &torrent::this_thread::event_closed_and_count, event); -} - -void event_insert_read(Event* event) { - MOCK_LOG("fd:%i type_name:%s", event->file_descriptor(), event->type_name()); - return mock_call(__func__, &torrent::this_thread::event_insert_read, event); -} - -void event_insert_write(Event* event) { - MOCK_LOG("fd:%i type_name:%s", event->file_descriptor(), event->type_name()); - return mock_call(__func__, &torrent::this_thread::event_insert_write, event); -} - -void event_insert_error(Event* event) { - MOCK_LOG("fd:%i type_name:%s", event->file_descriptor(), event->type_name()); - return mock_call(__func__, &torrent::this_thread::event_insert_error, event); -} - -void event_remove_read(Event* event) { - MOCK_LOG("fd:%i type_name:%s", event->file_descriptor(), event->type_name()); - return mock_call(__func__, &torrent::this_thread::event_remove_read, event); -} - -void event_remove_write(Event* event) { - MOCK_LOG("fd:%i type_name:%s", event->file_descriptor(), event->type_name()); - return mock_call(__func__, &torrent::this_thread::event_remove_write, event); -} - -void event_remove_error(Event* event) { - MOCK_LOG("fd:%i type_name:%s", event->file_descriptor(), event->type_name()); - return mock_call(__func__, &torrent::this_thread::event_remove_error, event); -} - -void event_remove_and_close(Event* event) { - MOCK_LOG("fd:%i type_name:%s", event->file_descriptor(), event->type_name()); - return mock_call(__func__, &torrent::this_thread::event_remove_and_close, event); -} - -} - // // Mock functions for 'torrent/utils/random.h': //