Skip to content

Commit 342c9b6

Browse files
committed
[Tests/Script/LuaNetwork] Added TCP client & server unit tests
1 parent f69f39d commit 342c9b6

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ endif ()
105105
if (RAZ_USE_NETWORKING AND NOT RAZ_USE_EMSCRIPTEN)
106106
file(GLOB RAZ_NETWORK_TEST_FILES "${PROJECT_SOURCE_DIR}/src/RaZ/Network/*.cpp")
107107
list(APPEND RAZ_TEST_FILES ${RAZ_NETWORK_TEST_FILES})
108+
else ()
109+
list(REMOVE_ITEM RAZ_TEST_FILES "${PROJECT_SOURCE_DIR}/src/RaZ/Script/LuaNetwork.cpp")
108110
endif ()
109111

110112
#####################
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include "TestUtils.hpp"
2+
3+
#include <catch2/catch_test_macros.hpp>
4+
5+
TEST_CASE("LuaNetwork TcpClient", "[script][lua][network]") {
6+
CHECK(TestUtils::executeLuaScript(R"(
7+
local tcpClient = TcpClient.new()
8+
--tcpClient = TcpClient.new("localhost", 1234) -- Throws as there's no available server
9+
10+
--tcpClient:connect("localhost", 1234) -- Throws as there's no available server
11+
assert(not tcpClient:isConnected())
12+
-- Data transfer functions throw when not connected
13+
--tcpClient:send("data")
14+
--tcpClient:recoverAvailableByteCount()
15+
--tcpClient:receive()
16+
--tcpClient:receiveAtLeast(1)
17+
--tcpClient:receiveExactly(1)
18+
--tcpClient:receiveUntil("\0")
19+
tcpClient:disconnect()
20+
)"));
21+
}
22+
23+
TEST_CASE("LuaNetwork TcpServer", "[script][lua][network]") {
24+
CHECK(TestUtils::executeLuaScript(R"(
25+
local tcpServer = TcpServer.new()
26+
27+
tcpServer:start(1234)
28+
tcpServer:stop()
29+
)"));
30+
}

0 commit comments

Comments
 (0)