Various pool_event_* and thread API cleanups.

This commit is contained in:
Jari Sundell
2025-05-31 18:22:14 +02:00
committed by GitHub
parent e8c1f3ed2c
commit f0809ec29d
8 changed files with 62 additions and 46 deletions
+49 -33
View File
@@ -6,11 +6,11 @@
#include <iostream>
#include <unistd.h>
#include <torrent/event.h>
#include <torrent/net/socket_address.h>
#include <torrent/net/fd.h>
#include <torrent/utils/log.h>
#include <torrent/utils/random.h>
#include "torrent/event.h"
#include "torrent/net/socket_address.h"
#include "torrent/net/fd.h"
#include "torrent/utils/log.h"
#include "torrent/utils/random.h"
#define MOCK_CLEANUP_MAP(MOCK_FUNC) \
CPPUNIT_ASSERT_MESSAGE("expected mock function calls not completed for '" #MOCK_FUNC "'", mock_cleanup_map(&MOCK_FUNC) || ignore_assert);
@@ -28,15 +28,17 @@ mock_clear(bool ignore_assert) {
MOCK_CLEANUP_MAP(torrent::fd__setsockopt_int);
MOCK_CLEANUP_MAP(torrent::fd__socket);
MOCK_CLEANUP_MAP(torrent::poll_event_open);
MOCK_CLEANUP_MAP(torrent::poll_event_close);
MOCK_CLEANUP_MAP(torrent::poll_event_closed);
MOCK_CLEANUP_MAP(torrent::poll_event_insert_read);
MOCK_CLEANUP_MAP(torrent::poll_event_insert_write);
MOCK_CLEANUP_MAP(torrent::poll_event_insert_error);
MOCK_CLEANUP_MAP(torrent::poll_event_remove_read);
MOCK_CLEANUP_MAP(torrent::poll_event_remove_write);
MOCK_CLEANUP_MAP(torrent::poll_event_remove_error);
MOCK_CLEANUP_MAP(torrent::this_thread::event_open);
MOCK_CLEANUP_MAP(torrent::this_thread::event_open_and_count);
MOCK_CLEANUP_MAP(torrent::this_thread::event_close_and_count);
MOCK_CLEANUP_MAP(torrent::this_thread::event_closed_and_count);
MOCK_CLEANUP_MAP(torrent::this_thread::event_insert_read);
MOCK_CLEANUP_MAP(torrent::this_thread::event_insert_write);
MOCK_CLEANUP_MAP(torrent::this_thread::event_insert_error);
MOCK_CLEANUP_MAP(torrent::this_thread::event_remove_read);
MOCK_CLEANUP_MAP(torrent::this_thread::event_remove_write);
MOCK_CLEANUP_MAP(torrent::this_thread::event_remove_error);
MOCK_CLEANUP_MAP(torrent::this_thread::event_remove_and_close);
MOCK_CLEANUP_MAP(torrent::random_uniform_uint16);
MOCK_CLEANUP_MAP(torrent::random_uniform_uint32);
@@ -117,52 +119,66 @@ int fd__socket(int domain, int type, int protocol) {
}
//
// Mock functions for 'torrent/event.h':
// Mock functions for 'torrent/common.h':
//
void poll_event_open(Event* event) {
namespace this_thread {
void event_open(Event* event) {
MOCK_LOG("fd:%i type_name:%s", event->file_descriptor(), event->type_name());
return mock_call<void>(__func__, &torrent::poll_event_open, event);
return mock_call<void>(__func__, &torrent::this_thread::event_open, event);
}
void poll_event_close(Event* event) {
void event_open_and_count(Event* event) {
MOCK_LOG("fd:%i type_name:%s", event->file_descriptor(), event->type_name());
return mock_call<void>(__func__, &torrent::poll_event_close, event);
return mock_call<void>(__func__, &torrent::this_thread::event_open_and_count, event);
}
void poll_event_closed(Event* event) {
void event_close_and_count(Event* event) {
MOCK_LOG("fd:%i type_name:%s", event->file_descriptor(), event->type_name());
return mock_call<void>(__func__, &torrent::poll_event_closed, event);
return mock_call<void>(__func__, &torrent::this_thread::event_close_and_count, event);
}
void poll_event_insert_read(Event* event) {
void event_closed_and_count(Event* event) {
MOCK_LOG("fd:%i type_name:%s", event->file_descriptor(), event->type_name());
return mock_call<void>(__func__, &torrent::poll_event_insert_read, event);
return mock_call<void>(__func__, &torrent::this_thread::event_closed_and_count, event);
}
void poll_event_insert_write(Event* event) {
void event_insert_read(Event* event) {
MOCK_LOG("fd:%i type_name:%s", event->file_descriptor(), event->type_name());
return mock_call<void>(__func__, &torrent::poll_event_insert_write, event);
return mock_call<void>(__func__, &torrent::this_thread::event_insert_read, event);
}
void poll_event_insert_error(Event* event) {
void event_insert_write(Event* event) {
MOCK_LOG("fd:%i type_name:%s", event->file_descriptor(), event->type_name());
return mock_call<void>(__func__, &torrent::poll_event_insert_error, event);
return mock_call<void>(__func__, &torrent::this_thread::event_insert_write, event);
}
void poll_event_remove_read(Event* event) {
void event_insert_error(Event* event) {
MOCK_LOG("fd:%i type_name:%s", event->file_descriptor(), event->type_name());
return mock_call<void>(__func__, &torrent::poll_event_remove_read, event);
return mock_call<void>(__func__, &torrent::this_thread::event_insert_error, event);
}
void poll_event_remove_write(Event* event) {
void event_remove_read(Event* event) {
MOCK_LOG("fd:%i type_name:%s", event->file_descriptor(), event->type_name());
return mock_call<void>(__func__, &torrent::poll_event_remove_write, event);
return mock_call<void>(__func__, &torrent::this_thread::event_remove_read, event);
}
void poll_event_remove_error(Event* event) {
void event_remove_write(Event* event) {
MOCK_LOG("fd:%i type_name:%s", event->file_descriptor(), event->type_name());
return mock_call<void>(__func__, &torrent::poll_event_remove_error, event);
return mock_call<void>(__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<void>(__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<void>(__func__, &torrent::this_thread::event_remove_and_close, event);
}
}
//