From 03e31af8280bf93908f8b5548172ace0c1e8b1da Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 7 Oct 2016 15:23:08 +0200 Subject: [PATCH] UnitTests: Choose a random port when testing Former-commit-id: ce4e1c4b2b65327917bd0cf14b91102bfdab6327 [formerly e4390f995cb6ccb2c5e3b81a56acf0563d8d2679] [formerly a813d71a45dc17042129a31a8537b35ffaf93120 [formerly 683e75adf03f84ce2dc2454b4c22c2a20ca31668]] Former-commit-id: 65fe6b63137fc3a55439d3ec777147ab51ed259a [formerly 310169d28ca078fdf76307bbf9f0a653c3c85d42] Former-commit-id: fc03da2c66e08f6d349b5eedae057c5ab371ad9e --- tests/Engine/Network/IpAddress.cpp | 2 +- tests/Engine/Network/SocketPoller.cpp | 11 +++++++---- tests/Engine/Network/TCP.cpp | 5 ++++- tests/Engine/Network/UdpSocket.cpp | 12 ++++++++---- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/tests/Engine/Network/IpAddress.cpp b/tests/Engine/Network/IpAddress.cpp index 8bb3e7d16..c87880d7b 100644 --- a/tests/Engine/Network/IpAddress.cpp +++ b/tests/Engine/Network/IpAddress.cpp @@ -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"); } } } diff --git a/tests/Engine/Network/SocketPoller.cpp b/tests/Engine/Network/SocketPoller.cpp index 93012d3de..d44c5f65d 100644 --- a/tests/Engine/Network/SocketPoller.cpp +++ b/tests/Engine/Network/SocketPoller.cpp @@ -1,16 +1,19 @@ +#include +#include #include #include #include #include - -#include -#include +#include SCENARIO("SocketPoller", "[NETWORK][SOCKETPOLLER]") { GIVEN("A TcpServer and a TcpClient in a selector") { - Nz::UInt16 port = 25664; + std::random_device rd; + std::uniform_int_distribution dis(1025, 65535); + + Nz::UInt16 port = dis(rd); Nz::TcpServer server; server.EnableBlocking(false); diff --git a/tests/Engine/Network/TCP.cpp b/tests/Engine/Network/TCP.cpp index 549742fd7..4a61e0197 100644 --- a/tests/Engine/Network/TCP.cpp +++ b/tests/Engine/Network/TCP.cpp @@ -11,7 +11,10 @@ SCENARIO("TCP", "[NETWORK][TCP]") { GIVEN("Two TCP, one client, one server") { - Nz::UInt16 port = 26456; + std::random_device rd; + std::uniform_int_distribution dis(1025, 65535); + + Nz::UInt16 port = dis(rd); Nz::TcpServer server; server.EnableBlocking(false); diff --git a/tests/Engine/Network/UdpSocket.cpp b/tests/Engine/Network/UdpSocket.cpp index 34ce5a19e..00d793e7a 100644 --- a/tests/Engine/Network/UdpSocket.cpp +++ b/tests/Engine/Network/UdpSocket.cpp @@ -1,14 +1,17 @@ -#include -#include - #include +#include #include +#include +#include SCENARIO("UdpSocket", "[NETWORK][UDPSOCKET]") { GIVEN("Two UdpSocket, one client, one server") { - Nz::UInt16 port = 64256; + std::random_device rd; + std::uniform_int_distribution dis(1025, 65535); + + Nz::UInt16 port = dis(rd); Nz::UdpSocket server(Nz::NetProtocol_IPv4); REQUIRE(server.Bind(port) == Nz::SocketState_Bound); @@ -33,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);