From 1af45c5de3b36ca2e1f82f9b6b47a6eca318157a Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Wed, 19 Jun 2024 16:37:12 +0200 Subject: [PATCH] Refs #21082. Fix negative tests. Signed-off-by: Miguel Company --- src/cpp/rtps/history/WriterHistory.cpp | 10 +--------- .../rtps/participant/RTPSParticipantImpl.cpp | 18 +++++++++++++++++ test/unittest/rtps/writer/RTPSWriterTests.cpp | 20 ++++++++++++------- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/cpp/rtps/history/WriterHistory.cpp b/src/cpp/rtps/history/WriterHistory.cpp index f5050939e2e..63fd9dd55de 100644 --- a/src/cpp/rtps/history/WriterHistory.cpp +++ b/src/cpp/rtps/history/WriterHistory.cpp @@ -91,15 +91,7 @@ WriterHistory::WriterHistory( , payload_pool_(payload_pool) { PoolConfig cfg = PoolConfig::from_history_attributes(att); - auto change_init = [&payload_pool, &cfg](CacheChange_t* change) -> void - { - if (payload_pool->get_payload(cfg.payload_initial_size, - change->serializedPayload)) - { - payload_pool->release_payload(change->serializedPayload); - } - }; - change_pool_ = std::make_shared(cfg, change_init); + change_pool_ = std::make_shared(cfg); } WriterHistory::WriterHistory( diff --git a/src/cpp/rtps/participant/RTPSParticipantImpl.cpp b/src/cpp/rtps/participant/RTPSParticipantImpl.cpp index 7c0992f6df8..06683d3cf26 100644 --- a/src/cpp/rtps/participant/RTPSParticipantImpl.cpp +++ b/src/cpp/rtps/participant/RTPSParticipantImpl.cpp @@ -1198,6 +1198,24 @@ bool RTPSParticipantImpl::create_writer( { *WriterOut = nullptr; + if (hist == nullptr) + { + EPROSIMA_LOG_ERROR(RTPS_PARTICIPANT, "Need a WriterHistory to create an RTPSWriter"); + return false; + } + + if (!hist->get_payload_pool()) + { + EPROSIMA_LOG_ERROR(RTPS_PARTICIPANT, "WriterHistory needs a payload pool to create an RTPSWriter"); + return false; + } + + if (!hist->get_change_pool()) + { + EPROSIMA_LOG_ERROR(RTPS_PARTICIPANT, "WriterHistory needs a change pool to create an RTPSWriter"); + return false; + } + auto callback = [hist, listen, this] (const GUID_t& guid, WriterAttributes& watt, fastdds::rtps::FlowController* flow_controller, IPersistenceService* persistence, bool is_reliable) -> RTPSWriter* diff --git a/test/unittest/rtps/writer/RTPSWriterTests.cpp b/test/unittest/rtps/writer/RTPSWriterTests.cpp index 8c4a82cc2fe..215123101f8 100644 --- a/test/unittest/rtps/writer/RTPSWriterTests.cpp +++ b/test/unittest/rtps/writer/RTPSWriterTests.cpp @@ -109,13 +109,6 @@ void pool_initialization_test ( ASSERT_NE(participant, nullptr); std::shared_ptr pool; - pool = std::make_shared(); - - // Creating the Writer initializes the PayloadPool with the initial reserved size - EXPECT_CALL(*pool, get_payload_delegate(TestDataType::data_size, _)) - .Times(0); - EXPECT_CALL(*pool, release_payload_delegate(_)) - .Times(0); HistoryAttributes h_attr; h_attr.memoryPolicy = policy; @@ -125,6 +118,19 @@ void pool_initialization_test ( WriterAttributes w_attr; RTPSWriter* writer = RTPSDomain::createRTPSWriter(participant, w_attr, history); + EXPECT_EQ(nullptr, writer); + + delete history; + pool = std::make_shared(); + history = new WriterHistory(h_attr, pool); + + // Creating the Writer initializes the PayloadPool with the initial reserved size + EXPECT_CALL(*pool, get_payload_delegate(TestDataType::data_size, _)) + .Times(0); + EXPECT_CALL(*pool, release_payload_delegate(_)) + .Times(0); + + writer = RTPSDomain::createRTPSWriter(participant, w_attr, history); Mock::VerifyAndClearExpectations(pool.get());