Merge remote-tracking branch 'refs/remotes/origin/master' into culling
This commit is contained in:
@@ -15,12 +15,12 @@ SCENARIO("Model", "[GRAPHICS][MODEL]")
|
||||
Nz::ModelRef model = Nz::Model::New();
|
||||
REQUIRE(model->LoadFromFile("resources/Engine/Graphics/dragon_recon/dragon_vrip_res4.obj", params));
|
||||
|
||||
REQUIRE(model->GetMaterialCount() == 2);
|
||||
REQUIRE(model->GetMaterialCount() == 1);
|
||||
REQUIRE(model->GetSkin() == 0);
|
||||
REQUIRE(model->GetSkinCount() == 1);
|
||||
|
||||
Nz::Material* material = model->GetMaterial(0);
|
||||
REQUIRE(material->GetAmbientColor() == Nz::Color(128));
|
||||
REQUIRE(material->GetAmbientColor() == Nz::Color::Black);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ SCENARIO("IpAddress", "[NETWORK][IPADDRESS]")
|
||||
Nz::IpAddress google(8, 8, 8, 8);
|
||||
THEN("Google (DNS) is 8.8.8.8")
|
||||
{
|
||||
REQUIRE(Nz::IpAddress::ResolveAddress(google) == "google-public-dns-a.google.com");
|
||||
REQUIRE(Nz::IpAddress::ResolveAddress(google) == "google-public-dns-a.google.com");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,13 +7,18 @@ SCENARIO("RUdpConnection", "[NETWORK][RUDPCONNECTION]")
|
||||
{
|
||||
GIVEN("Two RUdpConnection, one client, one server")
|
||||
{
|
||||
Nz::UInt16 port = 64266;
|
||||
// Disabled for now
|
||||
|
||||
/*Nz::UInt16 port = 64266;
|
||||
Nz::RUdpConnection server;
|
||||
REQUIRE(server.Listen(Nz::NetProtocol_IPv4, port));
|
||||
Nz::IpAddress serverIP = server.GetBoundAddress();
|
||||
|
||||
Nz::IpAddress serverIP(Nz::IpAddress::LoopbackIpV4.ToIPv4(), port);
|
||||
REQUIRE(serverIP.IsValid());
|
||||
|
||||
Nz::RUdpConnection client;
|
||||
REQUIRE(client.Listen(Nz::NetProtocol_IPv4, port + 1));
|
||||
|
||||
Nz::IpAddress clientIP = client.GetBoundAddress();
|
||||
REQUIRE(client.Connect(serverIP));
|
||||
REQUIRE(clientIP.IsValid());
|
||||
@@ -30,11 +35,13 @@ SCENARIO("RUdpConnection", "[NETWORK][RUDPCONNECTION]")
|
||||
{
|
||||
Nz::RUdpMessage rudpMessage;
|
||||
server.Update();
|
||||
|
||||
REQUIRE(server.PollMessage(&rudpMessage));
|
||||
|
||||
Nz::Vector3f result;
|
||||
rudpMessage.data >> result;
|
||||
REQUIRE(result == vector123);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
84
tests/Engine/Network/SocketPoller.cpp
Normal file
84
tests/Engine/Network/SocketPoller.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Network/NetPacket.hpp>
|
||||
#include <Nazara/Network/SocketPoller.hpp>
|
||||
#include <Nazara/Network/TcpClient.hpp>
|
||||
#include <Nazara/Network/TcpServer.hpp>
|
||||
#include <Catch/catch.hpp>
|
||||
#include <random>
|
||||
|
||||
SCENARIO("SocketPoller", "[NETWORK][SOCKETPOLLER]")
|
||||
{
|
||||
GIVEN("A TcpServer and a TcpClient in a selector")
|
||||
{
|
||||
std::random_device rd;
|
||||
std::uniform_int_distribution<Nz::UInt16> dis(1025, 65535);
|
||||
|
||||
Nz::UInt16 port = dis(rd);
|
||||
Nz::TcpServer server;
|
||||
server.EnableBlocking(false);
|
||||
|
||||
REQUIRE(server.Listen(Nz::NetProtocol_IPv4, port) == Nz::SocketState_Bound);
|
||||
|
||||
Nz::IpAddress serverIP(Nz::IpAddress::LoopbackIpV4.ToIPv4(), port);
|
||||
REQUIRE(serverIP.IsValid());
|
||||
|
||||
Nz::SocketPoller serverPoller;
|
||||
Nz::TcpClient clientToServer;
|
||||
|
||||
WHEN("We register the server socket to the poller")
|
||||
{
|
||||
REQUIRE(serverPoller.RegisterSocket(server));
|
||||
|
||||
THEN("The poller should have registered our socket")
|
||||
{
|
||||
REQUIRE(serverPoller.IsRegistered(server));
|
||||
}
|
||||
AND_THEN("We connect using a TcpClient")
|
||||
{
|
||||
Nz::SocketState state = clientToServer.Connect(serverIP);
|
||||
|
||||
REQUIRE(state != Nz::SocketState_NotConnected);
|
||||
|
||||
AND_THEN("We wait on our selector, it should return true")
|
||||
{
|
||||
REQUIRE(serverPoller.Wait(1000));
|
||||
|
||||
Nz::TcpClient serverToClient;
|
||||
REQUIRE(server.AcceptClient(&serverToClient));
|
||||
|
||||
WHEN("We register the client socket to the poller")
|
||||
{
|
||||
REQUIRE(serverPoller.RegisterSocket(serverToClient));
|
||||
|
||||
THEN("The poller should have registered our socket")
|
||||
{
|
||||
REQUIRE(serverPoller.IsRegistered(serverToClient));
|
||||
}
|
||||
|
||||
AND_WHEN("We test sending data from the client to the server and checking the poller")
|
||||
{
|
||||
std::array<char, 5> buffer = {"Data"};
|
||||
|
||||
std::size_t sent;
|
||||
REQUIRE(clientToServer.Send(buffer.data(), buffer.size(), &sent));
|
||||
REQUIRE(sent == buffer.size());
|
||||
|
||||
REQUIRE(serverPoller.Wait(1000));
|
||||
|
||||
REQUIRE(serverPoller.IsReady(serverToClient));
|
||||
|
||||
REQUIRE(serverToClient.Read(buffer.data(), buffer.size()) == sent);
|
||||
|
||||
AND_THEN("Our selector should report no socket ready")
|
||||
{
|
||||
REQUIRE(!serverPoller.Wait(100));
|
||||
|
||||
REQUIRE(!serverPoller.IsReady(serverToClient));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,33 +1,36 @@
|
||||
#include <Nazara/Core/Thread.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Network/NetPacket.hpp>
|
||||
#include <Nazara/Network/TcpClient.hpp>
|
||||
#include <Nazara/Network/TcpServer.hpp>
|
||||
#include <Catch/catch.hpp>
|
||||
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Network/NetPacket.hpp>
|
||||
|
||||
#include <random>
|
||||
|
||||
SCENARIO("TCP", "[NETWORK][TCP]")
|
||||
{
|
||||
GIVEN("Two TCP, one client, one server")
|
||||
{
|
||||
// Avoid reusing the same socket
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
std::uniform_int_distribution<> dis(1025, 64245);
|
||||
std::uniform_int_distribution<Nz::UInt16> dis(1025, 65535);
|
||||
|
||||
Nz::UInt16 port = dis(rd);
|
||||
|
||||
Nz::UInt16 port = dis(gen);
|
||||
Nz::TcpServer server;
|
||||
server.EnableBlocking(false);
|
||||
|
||||
REQUIRE(server.Listen(Nz::NetProtocol_IPv4, port) == Nz::SocketState_Bound);
|
||||
Nz::IpAddress serverIP = server.GetBoundAddress();
|
||||
|
||||
Nz::IpAddress serverIP(Nz::IpAddress::LoopbackIpV4.ToIPv4(), port);
|
||||
REQUIRE(serverIP.IsValid());
|
||||
|
||||
Nz::TcpClient client;
|
||||
REQUIRE(client.Connect(serverIP) == Nz::SocketState_Connecting);
|
||||
|
||||
Nz::IpAddress clientIP = client.GetRemoteAddress();
|
||||
REQUIRE(clientIP.IsValid());
|
||||
|
||||
Nz::Thread::Sleep(100);
|
||||
|
||||
Nz::TcpClient serverToClient;
|
||||
REQUIRE(server.AcceptClient(&serverToClient));
|
||||
|
||||
|
||||
@@ -1,20 +1,26 @@
|
||||
#include <Nazara/Network/UdpSocket.hpp>
|
||||
#include <Catch/catch.hpp>
|
||||
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Network/UdpSocket.hpp>
|
||||
#include <Nazara/Network/NetPacket.hpp>
|
||||
#include <Catch/catch.hpp>
|
||||
#include <random>
|
||||
|
||||
SCENARIO("UdpSocket", "[NETWORK][UDPSOCKET]")
|
||||
{
|
||||
GIVEN("Two UdpSocket, one client, one server")
|
||||
{
|
||||
Nz::UInt16 port = 64256;
|
||||
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);
|
||||
Nz::IpAddress serverIP = server.GetBoundAddress();
|
||||
|
||||
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());
|
||||
|
||||
@@ -30,6 +36,7 @@ SCENARIO("UdpSocket", "[NETWORK][UDPSOCKET]")
|
||||
Nz::NetPacket resultPacket;
|
||||
Nz::IpAddress fromIp;
|
||||
REQUIRE(server.ReceivePacket(&resultPacket, &fromIp));
|
||||
|
||||
Nz::Vector3f result;
|
||||
resultPacket >> result;
|
||||
REQUIRE(result == vector123);
|
||||
|
||||
Reference in New Issue
Block a user