ADD: added test for direct zmq tcp and a first version of the server and client class
This commit is contained in:
74
tests/test_DirectComms.cpp
Normal file
74
tests/test_DirectComms.cpp
Normal 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
|
||||
Reference in New Issue
Block a user