first test for the whisper com service #5
@ -100,3 +100,15 @@ target_link_libraries(wctest whisperCom)
|
||||
|
||||
add_executable(wcListener src/Listener.cpp)
|
||||
target_link_libraries(wcListener whisperCom)
|
||||
|
||||
|
||||
#
|
||||
# Everything TEST related
|
||||
#
|
||||
IF (${TEST_WHISPERCOM})
|
||||
|
||||
add_executable(test_Service tests/test_Service.cpp)
|
||||
target_link_libraries(test_Service Catch2::Catch2WithMain whisperCom loguru)
|
||||
catch_discover_tests(test_Service)
|
||||
|
||||
ENDIF()
|
70
tests/test_Service.cpp
Normal file
70
tests/test_Service.cpp
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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;
|
||||
REQUIRE_NOTHROW( serviceSource == std::make_shared<WhisperCom::Service>() );
|
||||
REQUIRE( serviceSource != nullptr );
|
||||
serviceSource->subscribe( testTopic );
|
||||
std::this_thread::sleep_for( 2000ms );
|
||||
|
||||
std::shared_ptr<WhisperCom::Service> serviceSink = nullptr;
|
||||
REQUIRE_NOTHROW( serviceSink == std::make_shared<WhisperCom::Service>() );
|
||||
REQUIRE( serviceSink != nullptr );
|
||||
serviceSink->subscribe( testTopic );
|
||||
std::this_thread::sleep_for( 2000ms );
|
||||
|
||||
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 );
|
||||
std::this_thread::sleep_for( 200ms );
|
||||
|
||||
THEN("The sink service should receive the message")
|
||||
{
|
||||
CHECK( serviceSink->hasMessages() );
|
||||
std::this_thread::sleep_for( 6000ms );
|
||||
} //THEN
|
||||
} // WHEN
|
||||
|
||||
serviceSource->stop();
|
||||
std::this_thread::sleep_for( 2000ms );
|
||||
serviceSink->stop();
|
||||
} // GIVEN
|
||||
} //SCENARIO
|
Loading…
Reference in New Issue
Block a user