Improve unit tests
This commit is contained in:
parent
7dbaed9aa5
commit
05e56d627d
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue