MCPcopy Create free account
hub / github.com/MonaSolutions/MonaServer / TCPTest

Function TCPTest

UnitTests/sources/SocketTest.cpp:259–311  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

257};
258
259void TCPTest(SocketManager& sockets) {
260
261 TCPServer server(sockets);
262 list<TCPConnection> connections;
263
264 TCPServer::OnError::Type onError = [](const Exception& ex) {
265 FATAL_ERROR("TCPServer, ",ex.error());
266 };
267 TCPServer::OnConnection::Type onConnection = [&](Exception& ex, const SocketAddress& address, SocketFile& file) {
268 CHECK(address && file);
269 connections.emplace_back(address, file, sockets);
270 };
271 server.OnError::subscribe(onError);
272 server.OnConnection::subscribe(onConnection);
273
274 Exception ex;
275 SocketAddress host(IPAddress::Wildcard(),62435);
276
277 CHECK(server.start(ex, host) && !ex);
278 server.stop();
279 CHECK(server.start(ex, host) && !ex);
280
281 TCPEchoClient client(sockets, &sockets == &ParallelSockets);
282 SocketAddress target(IPAddress::Loopback(),host.port());
283 CHECK(client.connect(ex, target) && !ex && client.connected());
284 CHECK(client.echo(ex,BIN EXPAND("hi mathieu and thomas")) && !ex);
285 CHECK(client.echo(ex,BIN Long0Data.c_str(),Long0Data.size()) && !ex);
286 CHECK(TaskSockets.join(client));
287
288 client.testDisconnection = true;
289
290 client.disconnect();
291
292 CHECK(TaskSockets.join(client));
293
294 // Test an unknown connection
295 SocketAddress unknown(IPAddress::Loopback(),62434);
296 if (client.connect(ex, unknown)) {
297 CHECK(!ex)
298 if (!client.parallel) {
299 CHECK(client.connected());
300 CHECK(client.address());
301 CHECK(client.peerAddress()==unknown);
302 CHECK(client.send(ex, BIN EXPAND("salut")) && !ex)
303 CHECK(client.connected());
304 }
305 CHECK(TaskSockets.join(client));
306 }
307 CHECK(!client.connected());
308
309 server.OnError::unsubscribe(onError);
310 server.OnConnection::unsubscribe(onConnection);
311}
312
313void UDPTest(SocketManager& sockets) {
314 UDPSocket server(sockets);

Callers 1

ADD_TESTFunction · 0.85

Calls 11

errorMethod · 0.80
echoMethod · 0.80
startMethod · 0.45
stopMethod · 0.45
portMethod · 0.45
connectMethod · 0.45
connectedMethod · 0.45
sizeMethod · 0.45
joinMethod · 0.45
disconnectMethod · 0.45
sendMethod · 0.45

Tested by

no test coverage detected