mirror of
https://github.com/momo5502/emulator.git
synced 2026-01-28 07:21:02 +00:00
Add UDP socket test
This commit is contained in:
@@ -9,3 +9,7 @@ list(SORT SRC_FILES)
|
|||||||
add_executable(test-sample ${SRC_FILES})
|
add_executable(test-sample ${SRC_FILES})
|
||||||
|
|
||||||
momo_assign_source_group(${SRC_FILES})
|
momo_assign_source_group(${SRC_FILES})
|
||||||
|
|
||||||
|
target_link_libraries(test-sample PRIVATE
|
||||||
|
emulator-common
|
||||||
|
)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
#include <Windows.h>
|
#include <network/udp_socket.hpp>
|
||||||
|
|
||||||
using namespace std::literals;
|
using namespace std::literals;
|
||||||
|
|
||||||
@@ -195,7 +195,7 @@ std::optional<std::string> read_registry_string(const HKEY root, const char* pat
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
return {std::string(data, min(length - 1, sizeof(data)))};
|
return {std::string(data, std::min(static_cast<size_t>(length - 1), sizeof(data)))};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool test_registry()
|
bool test_registry()
|
||||||
@@ -231,6 +231,36 @@ bool test_exceptions()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool test_socket()
|
||||||
|
{
|
||||||
|
network::udp_socket receiver{AF_INET};
|
||||||
|
const network::udp_socket sender{AF_INET};
|
||||||
|
const network::address destination{"127.0.0.1:28970", AF_INET};
|
||||||
|
constexpr std::string_view send_data = "Hello World";
|
||||||
|
|
||||||
|
if (!receiver.bind(destination))
|
||||||
|
{
|
||||||
|
puts("Failed to bind socket!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!sender.send(destination, send_data))
|
||||||
|
{
|
||||||
|
puts("Failed to send data!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto response = receiver.receive();
|
||||||
|
|
||||||
|
if (!response)
|
||||||
|
{
|
||||||
|
puts("Failed to recieve data!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return send_data == response->second;
|
||||||
|
}
|
||||||
|
|
||||||
void throw_access_violation()
|
void throw_access_violation()
|
||||||
{
|
{
|
||||||
if (do_the_task)
|
if (do_the_task)
|
||||||
@@ -256,7 +286,7 @@ bool test_ud2_exception(void* address)
|
|||||||
{
|
{
|
||||||
__try
|
__try
|
||||||
{
|
{
|
||||||
static_cast<void (*)()>(address)();
|
reinterpret_cast<void (*)()>(address)();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
__except (EXCEPTION_EXECUTE_HANDLER)
|
__except (EXCEPTION_EXECUTE_HANDLER)
|
||||||
@@ -301,7 +331,7 @@ void print_time()
|
|||||||
puts(res ? "Success" : "Fail"); \
|
puts(res ? "Success" : "Fail"); \
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, const char* argv[])
|
int main(const int argc, const char* argv[])
|
||||||
{
|
{
|
||||||
if (argc == 2 && argv[1] == "-time"sv)
|
if (argc == 2 && argv[1] == "-time"sv)
|
||||||
{
|
{
|
||||||
@@ -319,6 +349,7 @@ int main(int argc, const char* argv[])
|
|||||||
RUN_TEST(test_exceptions, "Exceptions")
|
RUN_TEST(test_exceptions, "Exceptions")
|
||||||
RUN_TEST(test_native_exceptions, "Native Exceptions")
|
RUN_TEST(test_native_exceptions, "Native Exceptions")
|
||||||
RUN_TEST(test_tls, "TLS")
|
RUN_TEST(test_tls, "TLS")
|
||||||
|
RUN_TEST(test_socket, "Socket")
|
||||||
|
|
||||||
return valid ? 0 : 1;
|
return valid ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user