ADD: added test for direct zmq tcp and a first version of the server and client class

This commit is contained in:
Henry Winkel
2023-07-05 17:05:03 +02:00
parent f03c00a1a8
commit 828d038d5f
6 changed files with 289 additions and 11 deletions

View File

@@ -0,0 +1,74 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
/**
* @file
* @copyright 2022 MPLv2
*/
/**
* @defgroup tests
*/
#include <string>
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
#include <DirectCommunicationClient.hpp>
#include <DirectCommunicationServer.hpp>
#include <loguru.hpp>
#include <memory>
/**
* @brief brief test description
* @ingroup group
*/
SCENARIO("A test scenario","[keywords]")
{
GIVEN("Preliminaries")
{
DirectCommunication::DirectCommunicationServer server(5555);
// std::this_thread::sleep_for(std::chrono::milliseconds(1000));
DirectCommunication::DirectCommunicationClient client(5555,"127.0.0.1");
std::string msg1 = "hello client";
std::string msg2 = "hello client again";
WHEN("doing something")
{
client.sendMessage("hello server");
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
auto msg1FromClient = server.getLatestMessage();
LOG_S(INFO)<< *msg1FromClient.get();
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");
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);
server.sendMessage(msg2);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
REQUIRE(*client.getLatestMessage().get() == msg2);
} // THEN
} // WHEN
} // GIVEN
} // SCENARIO