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

@ -54,7 +54,7 @@ SCENARIO("IpAddress", "[NETWORK][IPADDRESS]")
CHECK(Nz::IpAddress("1:2:3:4:5::7:8") == Nz::IpAddress(1, 2, 3, 4, 5, 0, 7, 8));
CHECK(Nz::IpAddress("1:2:3:4::7:8") == Nz::IpAddress(1, 2, 3, 4, 0, 0, 7, 8));
CHECK(Nz::IpAddress("1:2:3::7:8") == Nz::IpAddress(1, 2, 3, 0, 0, 0, 7, 8));
CHECK(Nz::IpAddress("1:2::5:6:7:8") == Nz::IpAddress(1, 2, 0, 0, 0, 6, 7, 8));
CHECK(Nz::IpAddress("1:2::5:6:7:8") == Nz::IpAddress(1, 2, 0, 0, 5, 6, 7, 8));
CHECK(Nz::IpAddress("1::7:8") == Nz::IpAddress(1, 0, 0, 0, 0, 0, 7, 8));
CHECK(Nz::IpAddress("1::8") == Nz::IpAddress(1, 0, 0, 0, 0, 0, 0, 8));
CHECK(Nz::IpAddress("::8") == Nz::IpAddress(0, 0, 0, 0, 0, 0, 0, 8));

View File

@ -25,18 +25,27 @@ SCENARIO("TCP", "[NETWORK][TCP]")
REQUIRE(serverIP.IsValid());
Nz::TcpClient client;
CHECK(client.WaitForConnected(100) == Nz::SocketState::NotConnected);
REQUIRE(client.Connect(serverIP) == Nz::SocketState::Connecting);
Nz::IpAddress clientIP = client.GetRemoteAddress();
CHECK(clientIP.IsValid());
std::this_thread::sleep_for(std::chrono::milliseconds(100));
REQUIRE(client.WaitForConnected(100) == Nz::SocketState::Connected);
CHECK(client.IsBlockingEnabled());
CHECK_FALSE(client.IsKeepAliveEnabled());
CHECK_FALSE(client.IsLowDelayEnabled());
CHECK(client.QueryReceiveBufferSize() > 0);
CHECK(client.QuerySendBufferSize() > 0);
Nz::TcpClient serverToClient;
REQUIRE(server.AcceptClient(&serverToClient));
WHEN("We send data from client")
{
CHECK(serverToClient.EndOfStream());
Nz::NetPacket packet(1);
Nz::Vector3f vector123(1.f, 2.f, 3.f);
packet << vector123;
@ -44,6 +53,8 @@ SCENARIO("TCP", "[NETWORK][TCP]")
THEN("We should get it on the server")
{
CHECK(!serverToClient.EndOfStream());
Nz::NetPacket resultPacket;
REQUIRE(serverToClient.ReceivePacket(&resultPacket));

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")
{