/* * 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 class test * * These scenarios test the class BC::BasicMessageQueue */ #define CATCH_CONFIG_MAIN #include #include #include #include #include #include #include #include /** * \brief Verify functional correctness of class BasicQueueReceiver. * \ingroup class_test * */ SCENARIO("Testing class BasicQueueReceiver ","[BasicQueueReceiver]") { GIVEN("A BasicQueueReceiver object") { std::shared_ptr testReceiver = nullptr; REQUIRE_NOTHROW( testReceiver = std::make_shared() ); REQUIRE( 0 == testReceiver->getQueueSize() ); WHEN("receiving a new message") { testReceiver->receive( new BC::Message{} ); THEN("the message queue should not be empty") { REQUIRE( 1 == testReceiver->getQueueSize() ); } //THEN } // WHEN WHEN("receiving a new message") { testReceiver->receive( new BC::Message{} ); THEN("the message queue should not be empty") { REQUIRE( 1 == testReceiver->getQueueSize() ); } //THEN } // WHEN WHEN("waiting for new message and appending messages") { REQUIRE( 0 == testReceiver->getQueueSize() ); std::thread myTestThread( &BC::BasicQueueReceiver::waitForNewMessage, testReceiver); std::this_thread::sleep_for(std::chrono::milliseconds(100)); THEN("the function should wait for a new message to be received") { CHECK( true == myTestThread.joinable() ); auto msg = std::make_unique(); testReceiver->receive( new BC::Message{} ); std::this_thread::sleep_for(std::chrono::milliseconds(100)); CHECK( 0 == testReceiver->getQueueSize() ); } //THEN myTestThread.join(); } // WHEN } // GIVEN } //SCENARIO