2023-07-26 11:46:18 +02:00
|
|
|
/*
|
|
|
|
* 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 2023 MPLv2
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \defgroup xy test
|
|
|
|
*
|
|
|
|
* These scenarios test xy
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define CATCH_CONFIG_MAIN
|
|
|
|
|
|
|
|
#include <catch2/catch_all.hpp>
|
|
|
|
|
|
|
|
#include <WhisperCom/Service.hpp>
|
|
|
|
#include <TestMessage.pb.h>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Verify functional correctness of the class WhisperCom::Service.
|
|
|
|
* \ingroup class_test
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
SCENARIO("Constructing two services that send and receive messages.","[Service]")
|
|
|
|
{
|
|
|
|
using namespace std::chrono_literals;
|
|
|
|
GIVEN("Two services, one for sending and one for receiving messages.")
|
|
|
|
{
|
|
|
|
std::string testTopic = "testTopic";
|
|
|
|
|
|
|
|
std::shared_ptr<WhisperCom::Service> serviceSource = nullptr;
|
2023-07-31 14:54:28 +02:00
|
|
|
REQUIRE_NOTHROW( serviceSource = std::make_shared<WhisperCom::Service>() );
|
2023-07-26 11:46:18 +02:00
|
|
|
REQUIRE( serviceSource != nullptr );
|
|
|
|
serviceSource->subscribe( testTopic );
|
|
|
|
|
|
|
|
std::shared_ptr<WhisperCom::Service> serviceSink = nullptr;
|
2023-07-31 14:54:28 +02:00
|
|
|
REQUIRE_NOTHROW( serviceSink = std::make_shared<WhisperCom::Service>() );
|
2023-07-26 11:46:18 +02:00
|
|
|
REQUIRE( serviceSink != nullptr );
|
|
|
|
serviceSink->subscribe( testTopic );
|
|
|
|
|
|
|
|
WHEN("Sending a message")
|
|
|
|
{
|
|
|
|
WhisperCom::Protobuf::TestMessage msg;
|
|
|
|
msg.set_str( "Hello World" );
|
|
|
|
WhisperCom::Protobuf::Message wmsg{};
|
|
|
|
wmsg.mutable_payload()->PackFrom( msg );
|
|
|
|
serviceSource->sendMessage( "test", wmsg );
|
2023-07-31 14:54:28 +02:00
|
|
|
std::this_thread::sleep_for( 400ms );
|
2023-07-26 11:46:18 +02:00
|
|
|
|
|
|
|
THEN("The sink service should receive the message")
|
|
|
|
{
|
|
|
|
CHECK( serviceSink->hasMessages() );
|
|
|
|
} //THEN
|
|
|
|
} // WHEN
|
|
|
|
|
|
|
|
serviceSource->stop();
|
|
|
|
serviceSink->stop();
|
|
|
|
} // GIVEN
|
|
|
|
} //SCENARIO
|