CHG: changed the return val from the tcp classes to string

This commit is contained in:
Henry Winkel
2023-07-05 18:02:23 +02:00
parent 1d154f71d4
commit 8bc80f9885
5 changed files with 10 additions and 10 deletions

View File

@@ -25,7 +25,7 @@ namespace DirectCommunication
~DirectCommunicationClient();
void sendMessage(std::string msg);
std::unique_ptr<std::string> getLatestMessage();
std::string getLatestMessage();
private:
ushort port_;

View File

@@ -25,7 +25,7 @@ namespace DirectCommunication
~DirectCommunicationServer();
void sendMessage(std::string msg);
std::unique_ptr<std::string> getLatestMessage();
std::string getLatestMessage();
int countClients();

View File

@@ -46,13 +46,13 @@ namespace DirectCommunication
}
std::unique_ptr<std::string> DirectCommunicationClient::getLatestMessage()
std::string DirectCommunicationClient::getLatestMessage()
{
if (receivedMessages_.size() > 0)
{
std::string msg;
receivedMessages_.get(msg);
return std::make_unique<std::string>(std::move(msg));
return msg;
}
return nullptr;
}

View File

@@ -47,13 +47,13 @@ namespace DirectCommunication
}
}
std::unique_ptr<std::string> DirectCommunicationServer::getLatestMessage()
std::string DirectCommunicationServer::getLatestMessage()
{
if (receivedMessages_.size() > 0)
{
std::string msg;
receivedMessages_.get(msg);
return std::make_unique<std::string>(std::move(msg));
return msg;
}
return nullptr;
}

View File

@@ -49,23 +49,23 @@ SCENARIO("A test scenario","[keywords]")
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
auto msg1FromClient = server.getLatestMessage();
LOG_S(INFO)<< *msg1FromClient.get();
LOG_S(INFO)<< msg1FromClient;
LOG_S(INFO)<< server.countClients();
THEN("expecting something to happen")
{
REQUIRE(server.countClients() == 1 );
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
REQUIRE(*msg1FromClient.get() == "hello server");
REQUIRE(msg1FromClient == "hello server");
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
server.sendMessage(msg1);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
REQUIRE(*client.getLatestMessage().get() == msg1);
REQUIRE(client.getLatestMessage() == msg1);
server.sendMessage(msg2);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
REQUIRE(*client.getLatestMessage().get() == msg2);
REQUIRE(client.getLatestMessage() == msg2);
} // THEN