Skip to content

Commit b4e4ef8

Browse files
committed
Refs #21082. Fix negative tests.
Signed-off-by: Miguel Company <miguelcompany@eprosima.com>
1 parent 33e456b commit b4e4ef8

3 files changed

Lines changed: 32 additions & 16 deletions

File tree

src/cpp/rtps/history/WriterHistory.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,7 @@ WriterHistory::WriterHistory(
9191
, payload_pool_(payload_pool)
9292
{
9393
PoolConfig cfg = PoolConfig::from_history_attributes(att);
94-
auto change_init = [&payload_pool, &cfg](CacheChange_t* change) -> void
95-
{
96-
if (payload_pool->get_payload(cfg.payload_initial_size,
97-
change->serializedPayload))
98-
{
99-
payload_pool->release_payload(change->serializedPayload);
100-
}
101-
};
102-
change_pool_ = std::make_shared<CacheChangePool>(cfg, change_init);
94+
change_pool_ = std::make_shared<CacheChangePool>(cfg);
10395
}
10496

10597
WriterHistory::WriterHistory(

src/cpp/rtps/participant/RTPSParticipantImpl.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,24 @@ bool RTPSParticipantImpl::create_writer(
11981198
{
11991199
*WriterOut = nullptr;
12001200

1201+
if (hist == nullptr)
1202+
{
1203+
EPROSIMA_LOG_ERROR(RTPS_PARTICIPANT, "Need a WriterHistory to create an RTPSWriter");
1204+
return false;
1205+
}
1206+
1207+
if (!hist->get_payload_pool())
1208+
{
1209+
EPROSIMA_LOG_ERROR(RTPS_PARTICIPANT, "WriterHistory needs a payload pool to create an RTPSWriter");
1210+
return false;
1211+
}
1212+
1213+
if (!hist->get_change_pool())
1214+
{
1215+
EPROSIMA_LOG_ERROR(RTPS_PARTICIPANT, "WriterHistory needs a change pool to create an RTPSWriter");
1216+
return false;
1217+
}
1218+
12011219
auto callback = [hist, listen, this]
12021220
(const GUID_t& guid, WriterAttributes& watt, fastdds::rtps::FlowController* flow_controller,
12031221
IPersistenceService* persistence, bool is_reliable) -> RTPSWriter*

test/unittest/rtps/writer/RTPSWriterTests.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,6 @@ void pool_initialization_test (
109109
ASSERT_NE(participant, nullptr);
110110

111111
std::shared_ptr<TestPayloadPool> pool;
112-
pool = std::make_shared<TestPayloadPool>();
113-
114-
// Creating the Writer initializes the PayloadPool with the initial reserved size
115-
EXPECT_CALL(*pool, get_payload_delegate(TestDataType::data_size, _))
116-
.Times(0);
117-
EXPECT_CALL(*pool, release_payload_delegate(_))
118-
.Times(0);
119112

120113
HistoryAttributes h_attr;
121114
h_attr.memoryPolicy = policy;
@@ -125,6 +118,19 @@ void pool_initialization_test (
125118

126119
WriterAttributes w_attr;
127120
RTPSWriter* writer = RTPSDomain::createRTPSWriter(participant, w_attr, history);
121+
EXPECT_EQ(nullptr, writer);
122+
123+
delete history;
124+
pool = std::make_shared<TestPayloadPool>();
125+
history = new WriterHistory(h_attr, pool);
126+
127+
// Creating the Writer initializes the PayloadPool with the initial reserved size
128+
EXPECT_CALL(*pool, get_payload_delegate(TestDataType::data_size, _))
129+
.Times(0);
130+
EXPECT_CALL(*pool, release_payload_delegate(_))
131+
.Times(0);
132+
133+
writer = RTPSDomain::createRTPSWriter(participant, w_attr, history);
128134

129135
Mock::VerifyAndClearExpectations(pool.get());
130136

0 commit comments

Comments
 (0)