From fa2c0da30d81e9c221c06bdc71fd14947642191b Mon Sep 17 00:00:00 2001 From: Benny Baumann <BenBE@geshi.org> Date: Sun, 19 Feb 2023 23:16:10 +0100 Subject: [PATCH] add: UDP socket tests --- test/udp_client_test.hpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 test/udp_client_test.hpp diff --git a/test/udp_client_test.hpp b/test/udp_client_test.hpp new file mode 100644 index 0000000..844536a --- /dev/null +++ b/test/udp_client_test.hpp @@ -0,0 +1,26 @@ +#include "net/udp_client.hpp" + +#include <sys/socket.h> +#include <sys/types.h> +#include <netinet/in.h> + +namespace rmrf::net { + + bool udp_test_successful = false; + const char* udp_test_string = "TEST UDP PACKET"; + + void udp_test_cb(const udp_packet<pkg_size>& data, socketaddr& source) { + if (strcmp(data.raw, udp_test_string) != 0) + udp_test_successful = true; + } + + void run_udp_test() { + udp_client sender{get_first_general_socketaddr("localhost", 9862)}; + const socketaddr destination_address = get_first_general_socketaddr("localhost", 9863); + udp_client receiver{destination_address, udp_test_cb}; + udp_packet<1024> data; + strncpy(data.raw, udp_test_string, sizeof(udp_test_string) + 1); + sender.send_packet(destination, data); + } + +} -- GitLab