Merge remote-tracking branch 'refs/remotes/origin/master' into culling

This commit is contained in:
Lynix
2016-10-12 16:51:18 +02:00
95 changed files with 2139 additions and 348 deletions

View File

@@ -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);
}
}
}

View File

@@ -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");
}
}
}

View File

@@ -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);
}
}
}*/
}
}

View 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));
}
}
}
}
}
}
}
}

View File

@@ -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));

View File

@@ -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);

View File

@@ -5,17 +5,20 @@ SCENARIO("Application", "[NDK][APPLICATION]")
{
GIVEN("An application")
{
Ndk::Application application;
application.AddWorld();
Nz::Window& window = application.AddWindow<Nz::Window>();
Nz::Window& window = Ndk::Application::Instance()->AddWindow<Nz::Window>();
WHEN("We close the open window")
WHEN("We open a window")
{
window.Close();
REQUIRE(window.Create(Nz::VideoMode(800, 600, 32), "Nazara Unit Tests"));
THEN("Application should close")
AND_WHEN("We close the open window")
{
REQUIRE(!application.Run());
window.Close();
THEN("Application should close")
{
REQUIRE(!Ndk::Application::Instance()->Run());
}
}
}
}

View File

@@ -6,6 +6,18 @@ namespace
class TestComponent : public Ndk::Component<TestComponent>
{
public:
TestComponent(int value) :
m_value(value)
{
}
int GetValue() const
{
return m_value;
}
int m_value;
static Ndk::ComponentIndex componentIndex;
};
@@ -16,7 +28,7 @@ SCENARIO("Component", "[NDK][COMPONENT]")
{
GIVEN("Our TestComponent")
{
TestComponent testComponent;
TestComponent testComponent(42);
WHEN("We clone it")
{
@@ -24,7 +36,7 @@ SCENARIO("Component", "[NDK][COMPONENT]")
THEN("We should get a copy")
{
REQUIRE(dynamic_cast<TestComponent*>(clone.get()) != nullptr);
REQUIRE(static_cast<TestComponent*>(clone.get())->GetValue() == 42);
}
}
}

View File

@@ -6,15 +6,23 @@ namespace
class TestSystem : public Ndk::System<TestSystem>
{
public:
TestSystem()
TestSystem(int value) :
m_value(value)
{
}
int GetValue() const
{
return m_value;
}
~TestSystem() = default;
static Ndk::SystemIndex systemIndex;
private:
int m_value;
void OnUpdate(float elapsedTime) override
{
}
@@ -27,7 +35,7 @@ SCENARIO("System", "[NDK][SYSTEM]")
{
GIVEN("Our TestSystem")
{
TestSystem testSystem;
TestSystem testSystem(666);
WHEN("We clone it")
{
@@ -35,7 +43,7 @@ SCENARIO("System", "[NDK][SYSTEM]")
THEN("We should get a copy")
{
REQUIRE(dynamic_cast<TestSystem*>(clone.get()) != nullptr);
REQUIRE(static_cast<TestSystem*>(clone.get())->GetValue() == 666);
}
}
}

View File

@@ -1,14 +1,16 @@
#define CATCH_CONFIG_RUNNER
#include <Catch/catch.hpp>
#include <Nazara/Audio/Audio.hpp>
#include <Nazara/Core/Core.hpp>
#include <Nazara/Graphics/Graphics.hpp>
#include <NDK/Application.hpp>
#include <Nazara/Core/Log.hpp>
#include <Nazara/Network/Network.hpp>
int main(int argc, char* const argv[])
int main(int argc, char* argv[])
{
Nz::Initializer<Nz::Audio, Nz::Core, Nz::Graphics, Nz::Network> modules;
Ndk::Application application(argc, argv);
Nz::Initializer<Nz::Network> modules;
Nz::Log::GetLogger()->EnableStdReplication(false);
int result = Catch::Session().run(argc, argv);