From 100a32545ec23369bea9cd672028a161e0596da0 Mon Sep 17 00:00:00 2001 From: Marcus Tomlinson Date: Mon, 8 Jan 2024 16:23:59 +0000 Subject: [PATCH] Add "SeparateProcess" test --- tests/main.cpp | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/tests/main.cpp b/tests/main.cpp index 85b445c..52217be 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -48,7 +48,7 @@ Ipc::Message RecvCallback( const Ipc::Message& recvHeader, const Ipc::Message& r return std::string( "Unix Domain Sockets!" ); } -TEST( Client, Simple ) +TEST( Client, SameProcess ) { Ipc::Server server( c_serverSocket ); auto listenThread = std::thread( @@ -72,6 +72,42 @@ TEST( Client, Simple ) listenThread.join(); } +TEST( Simple, SeparateProcess ) +{ + std::thread( + [] + { + Ipc::Server server( c_serverSocket ); + ASSERT_TRUE( server.Listen( RecvCallback ) ); + ASSERT_TRUE( server.Listen( RecvCallback ) ); + } ) + .detach(); + + EXPECT_EXIT( + { + Ipc::Client client( c_serverSocket ); + + auto response = client.Send( std::string( "bin" ), std::vector{ 0 } ); + ASSERT_FALSE( response.IsError() ); + ASSERT_EQ( response.AsByteVect(), std::vector{ 1 } ); + + exit( 0 ); + }, + testing::ExitedWithCode( 0 ), "" ); + + EXPECT_EXIT( + { + Ipc::Client client( c_serverSocket ); + + auto response = client.Send( std::vector{ 0 }, std::string( "Hello?" ) ); + ASSERT_FALSE( response.IsError() ); + ASSERT_EQ( response.AsString(), "Unix Domain Sockets!" ); + + exit( 0 ); + }, + testing::ExitedWithCode( 0 ), "" ); +} + TEST( Server, StopListening ) { Ipc::Server server( c_serverSocket );