Improve unit tests

This commit is contained in:
Jérôme Leclercq
2022-02-24 12:56:53 +01:00
parent 7dbaed9aa5
commit 05e56d627d
3 changed files with 18 additions and 12 deletions

View File

@@ -2,27 +2,22 @@
#include <Nazara/Network/UdpSocket.hpp>
#include <Nazara/Network/NetPacket.hpp>
#include <catch2/catch.hpp>
#include <random>
SCENARIO("UdpSocket", "[NETWORK][UDPSOCKET]")
{
GIVEN("Two UdpSocket, one client, one server")
{
std::random_device rd;
std::uniform_int_distribution<Nz::UInt16> dis(1025, 65535);
Nz::UInt16 port = dis(rd);
Nz::UdpSocket server(Nz::NetProtocol::IPv4);
REQUIRE(server.Bind(port) == Nz::SocketState::Bound);
REQUIRE(server.Bind(0) == Nz::SocketState::Bound);
Nz::UInt16 port = server.GetBoundPort();
Nz::IpAddress serverIP(Nz::IpAddress::LoopbackIpV4.ToIPv4(), port);
REQUIRE(serverIP.IsValid());
Nz::UdpSocket client(Nz::NetProtocol::IPv4);
REQUIRE(client.Bind(port + 1) == Nz::SocketState::Bound);
Nz::IpAddress clientIP = client.GetBoundAddress();
REQUIRE(clientIP.IsValid());
CHECK_FALSE(client.IsBroadcastingEnabled());
CHECK(client.QueryMaxDatagramSize() > 1500);
WHEN("We send data from client")
{