Skip to content

Commit

Permalink
Refs #21082. Fix negative tests.
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Company <miguelcompany@eprosima.com>
  • Loading branch information
MiguelCompany committed Jun 19, 2024
1 parent 33e456b commit b4e4ef8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
10 changes: 1 addition & 9 deletions src/cpp/rtps/history/WriterHistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CacheChangePool>(cfg, change_init);
change_pool_ = std::make_shared<CacheChangePool>(cfg);
}

WriterHistory::WriterHistory(
Expand Down
18 changes: 18 additions & 0 deletions src/cpp/rtps/participant/RTPSParticipantImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down
20 changes: 13 additions & 7 deletions test/unittest/rtps/writer/RTPSWriterTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,6 @@ void pool_initialization_test (
ASSERT_NE(participant, nullptr);

std::shared_ptr<TestPayloadPool> pool;
pool = std::make_shared<TestPayloadPool>();

// 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;
Expand All @@ -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<TestPayloadPool>();
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());

Expand Down

0 comments on commit b4e4ef8

Please sign in to comment.