Skip to content

Commit

Permalink
Refs #20742: Apply rev suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: JesusPoderoso <[email protected]>
  • Loading branch information
JesusPoderoso committed May 7, 2024
1 parent e9e08fd commit 6a0a230
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 25 deletions.
3 changes: 1 addition & 2 deletions src/cpp/fastdds/subscriber/DataReaderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1814,8 +1814,7 @@ std::shared_ptr<IPayloadPool> DataReaderImpl::get_payload_pool()

if (!sample_pool_)
{
sample_pool_ =
std::make_shared<detail::SampleLoanManager>(config, type_, is_plain);
sample_pool_ = std::make_shared<detail::SampleLoanManager>(config, type_, is_plain);
}
if (!is_custom_payload_pool_)
{
Expand Down
19 changes: 11 additions & 8 deletions test/unittest/dds/publisher/DataWriterTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2178,19 +2178,20 @@ class DataRepresentationTestsTypeSupport : public LoanableTypeSupport
return true;
}

MOCK_CONST_METHOD1(custom_is_plain, bool(DataRepresentationId_t data_representation_id));
MOCK_CONST_METHOD1(custom_is_plain_with_rep, bool(DataRepresentationId_t data_representation_id));

bool is_plain(
DataRepresentationId_t data_representation_id) const override
{
return custom_is_plain(data_representation_id);
return custom_is_plain_with_rep(data_representation_id);
}

MOCK_CONST_METHOD0(custom_is_plain, bool());

bool is_plain() const override
{
return is_plain(DataRepresentationId_t::XCDR_DATA_REPRESENTATION); // default XCDR1
return custom_is_plain();
}

};

TEST(DataWriterTests, data_type_is_plain_data_representation)
Expand All @@ -2215,9 +2216,10 @@ TEST(DataWriterTests, data_type_is_plain_data_representation)
qos_xcdr.endpoint().history_memory_policy = PREALLOCATED_WITH_REALLOC_MEMORY_MODE;

/* Expect the "is_plain" method called with default data representation (XCDR1) */
EXPECT_CALL(*type, custom_is_plain(DataRepresentationId_t::XCDR_DATA_REPRESENTATION)).Times(
EXPECT_CALL(*type, custom_is_plain()).Times(0);
EXPECT_CALL(*type, custom_is_plain_with_rep(DataRepresentationId_t::XCDR_DATA_REPRESENTATION)).Times(
testing::AtLeast(1)).WillRepeatedly(testing::Return(true));
EXPECT_CALL(*type, custom_is_plain(DataRepresentationId_t::XCDR2_DATA_REPRESENTATION)).Times(0);
EXPECT_CALL(*type, custom_is_plain_with_rep(DataRepresentationId_t::XCDR2_DATA_REPRESENTATION)).Times(0);

/* Create a datawriter will trigger the "is_plain" call */
DataWriter* datawriter_xcdr = publisher->create_datawriter(topic, qos_xcdr);
Expand All @@ -2232,8 +2234,9 @@ TEST(DataWriterTests, data_type_is_plain_data_representation)
qos_xcdr2.representation().m_value.push_back(DataRepresentationId_t::XCDR2_DATA_REPRESENTATION);

/* Expect the "is_plain" method called with XCDR2 data representation */
EXPECT_CALL(*type, custom_is_plain(DataRepresentationId_t::XCDR_DATA_REPRESENTATION)).Times(0);
EXPECT_CALL(*type, custom_is_plain(DataRepresentationId_t::XCDR2_DATA_REPRESENTATION)).Times(
EXPECT_CALL(*type, custom_is_plain()).Times(0);
EXPECT_CALL(*type, custom_is_plain_with_rep(DataRepresentationId_t::XCDR_DATA_REPRESENTATION)).Times(0);
EXPECT_CALL(*type, custom_is_plain_with_rep(DataRepresentationId_t::XCDR2_DATA_REPRESENTATION)).Times(
testing::AtLeast(1)).WillRepeatedly(testing::Return(true));

/* Create a datawriter will trigger the "is_plain" call */
Expand Down
42 changes: 27 additions & 15 deletions test/unittest/dds/subscriber/DataReaderTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3818,26 +3818,20 @@ class DataRepresentationTestsTypeSupport : public TopicDataType
return true;
}

MOCK_CONST_METHOD1(custom_is_plain, bool(DataRepresentationId_t data_representation_id));
MOCK_CONST_METHOD1(custom_is_plain_with_rep, bool(DataRepresentationId_t data_representation_id));

bool is_plain(
DataRepresentationId_t data_representation_id) const override
{
return custom_is_plain(data_representation_id);
return custom_is_plain_with_rep(data_representation_id);
}

bool is_plain() const override
{
return is_plain(DataRepresentationId_t::XCDR_DATA_REPRESENTATION); // default XCDR1
}
MOCK_CONST_METHOD0(custom_is_plain, bool());

bool construct_sample(
void* sample) const override
bool is_plain() const override
{
new (sample) LoanableType();
return true;
return custom_is_plain();
}

};

TEST_F(DataReaderTests, data_type_is_plain_data_representation)
Expand All @@ -3864,9 +3858,10 @@ TEST_F(DataReaderTests, data_type_is_plain_data_representation)
qos_xcdr.type_consistency().representation.m_value.push_back(DataRepresentationId_t::XCDR_DATA_REPRESENTATION);

/* Expect the "is_plain" method called with default data representation (XCDR1) */
EXPECT_CALL(*type, custom_is_plain(DataRepresentationId_t::XCDR_DATA_REPRESENTATION)).Times(
EXPECT_CALL(*type, custom_is_plain()).Times(0);
EXPECT_CALL(*type, custom_is_plain_with_rep(DataRepresentationId_t::XCDR_DATA_REPRESENTATION)).Times(
testing::AtLeast(1)).WillRepeatedly(testing::Return(true));
EXPECT_CALL(*type, custom_is_plain(DataRepresentationId_t::XCDR2_DATA_REPRESENTATION)).Times(0);
EXPECT_CALL(*type, custom_is_plain_with_rep(DataRepresentationId_t::XCDR2_DATA_REPRESENTATION)).Times(0);

/* Create a datareader will trigger the "is_plain" call */
DataReader* datareader_xcdr = subscriber->create_datareader(topic, qos_xcdr);
Expand All @@ -3881,14 +3876,31 @@ TEST_F(DataReaderTests, data_type_is_plain_data_representation)
qos_xcdr2.type_consistency().representation.m_value.push_back(DataRepresentationId_t::XCDR2_DATA_REPRESENTATION);

/* Expect the "is_plain" method called with XCDR2 data representation */
EXPECT_CALL(*type, custom_is_plain(DataRepresentationId_t::XCDR_DATA_REPRESENTATION)).Times(0);
EXPECT_CALL(*type, custom_is_plain(DataRepresentationId_t::XCDR2_DATA_REPRESENTATION)).Times(
EXPECT_CALL(*type, custom_is_plain()).Times(0);
EXPECT_CALL(*type, custom_is_plain_with_rep(DataRepresentationId_t::XCDR_DATA_REPRESENTATION)).Times(0);
EXPECT_CALL(*type, custom_is_plain_with_rep(DataRepresentationId_t::XCDR2_DATA_REPRESENTATION)).Times(
testing::AtLeast(1)).WillRepeatedly(testing::Return(true));

/* Create a datareader will trigger the "is_plain" call */
DataReader* datareader_xcdr2 = subscriber->create_datareader(topic, qos_xcdr2);
ASSERT_NE(datareader_xcdr2, nullptr);

/* NOT Define data representation QoS to force "is_plain" call */
DataReaderQos qos_no_xcdr = DATAREADER_QOS_DEFAULT;
qos_no_xcdr.endpoint().history_memory_policy = PREALLOCATED_WITH_REALLOC_MEMORY_MODE;
qos_no_xcdr.type_consistency().representation.m_value.clear();

/* Expect the "is_plain" method called with both data representation */
EXPECT_CALL(*type, custom_is_plain()).Times(0);
EXPECT_CALL(*type, custom_is_plain_with_rep(DataRepresentationId_t::XCDR_DATA_REPRESENTATION)).Times(
testing::AtLeast(1)).WillRepeatedly(testing::Return(true));
EXPECT_CALL(*type, custom_is_plain_with_rep(DataRepresentationId_t::XCDR2_DATA_REPRESENTATION)).Times(
testing::AtLeast(1)).WillRepeatedly(testing::Return(true));

/* Create a datareader will trigger the "is_plain" call */
DataReader* datareader_no_xcdr = subscriber->create_datareader(topic, qos_no_xcdr);
ASSERT_NE(datareader_no_xcdr, nullptr);

/* Tear down */
participant->delete_contained_entities();
DomainParticipantFactory::get_instance()->delete_participant(participant);
Expand Down

0 comments on commit 6a0a230

Please sign in to comment.