Skip to content

Commit

Permalink
Add regression test
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Lopez Fernandez <juanlopez@eprosima.com>
  • Loading branch information
juanlofer-eprosima committed Sep 30, 2024
1 parent d3901ec commit d1e90f3
Show file tree
Hide file tree
Showing 8 changed files with 3,314 additions and 2,507 deletions.
5,306 changes: 2,799 additions & 2,507 deletions test/dds-types-test/unions.hpp

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions test/dds-types-test/unionsCdrAux.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ constexpr uint32_t UnionInnerUnionHelper_max_key_cdr_typesize {0UL};



constexpr uint32_t UnionShortExtraMember_max_cdr_typesize {20UL};
constexpr uint32_t UnionShortExtraMember_max_key_cdr_typesize {0UL};



constexpr uint32_t UnionDiscriminatorULongLong_max_cdr_typesize {24UL};
Expand Down Expand Up @@ -378,6 +381,10 @@ eProsima_user_DllExport void serialize_key(



eProsima_user_DllExport void serialize_key(
eprosima::fastcdr::Cdr& scdr,
const UnionShortExtraMember& data);


} // namespace fastcdr
} // namespace eprosima
Expand Down
89 changes: 89 additions & 0 deletions test/dds-types-test/unionsCdrAux.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -8474,6 +8474,95 @@ eProsima_user_DllExport void deserialize(
});
}

template<>
eProsima_user_DllExport size_t calculate_serialized_size(
eprosima::fastcdr::CdrSizeCalculator& calculator,
const UnionShortExtraMember& data,
size_t& current_alignment)
{
static_cast<void>(data);

eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding();
size_t calculated_size {calculator.begin_calculate_type_serialized_size(
eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ?
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 :
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR,
current_alignment)};


calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0),
data.var_union_short(), current_alignment);

calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(1),
data.var_long(), current_alignment);


calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment);

return calculated_size;
}

template<>
eProsima_user_DllExport void serialize(
eprosima::fastcdr::Cdr& scdr,
const UnionShortExtraMember& data)
{
eprosima::fastcdr::Cdr::state current_state(scdr);
scdr.begin_serialize_type(current_state,
eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ?
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 :
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR);

scdr
<< eprosima::fastcdr::MemberId(0) << data.var_union_short()
<< eprosima::fastcdr::MemberId(1) << data.var_long()
;
scdr.end_serialize_type(current_state);
}

template<>
eProsima_user_DllExport void deserialize(
eprosima::fastcdr::Cdr& cdr,
UnionShortExtraMember& data)
{
cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ?
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 :
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR,
[&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool
{
bool ret_value = true;
switch (mid.id)
{
case 0:
dcdr >> data.var_union_short();
break;

case 1:
dcdr >> data.var_long();
break;

default:
ret_value = false;
break;
}
return ret_value;
});
}

void serialize_key(
eprosima::fastcdr::Cdr& scdr,
const UnionShortExtraMember& data)
{

static_cast<void>(scdr);
static_cast<void>(data);
scdr << data.var_union_short();

scdr << data.var_long();

}



} // namespace fastcdr
} // namespace eprosima
Expand Down
181 changes: 181 additions & 0 deletions test/dds-types-test/unionsPubSubTypes.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -7454,6 +7454,187 @@ void UnionSeveralFieldsWithDefaultPubSubType::register_type_object_representatio



UnionShortExtraMemberPubSubType::UnionShortExtraMemberPubSubType()
{
set_name("UnionShortExtraMember");
uint32_t type_size = UnionShortExtraMember_max_cdr_typesize;
type_size += static_cast<uint32_t>(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */
max_serialized_type_size = type_size + 4; /*encapsulation*/
is_compute_key_provided = false;
uint32_t key_length = UnionShortExtraMember_max_key_cdr_typesize > 16 ? UnionShortExtraMember_max_key_cdr_typesize : 16;
key_buffer_ = reinterpret_cast<unsigned char*>(malloc(key_length));
memset(key_buffer_, 0, key_length);
}

UnionShortExtraMemberPubSubType::~UnionShortExtraMemberPubSubType()
{
if (key_buffer_ != nullptr)
{
free(key_buffer_);
}
}

bool UnionShortExtraMemberPubSubType::serialize(
const void* const data,
SerializedPayload_t& payload,
DataRepresentationId_t data_representation)
{
const UnionShortExtraMember* p_type = static_cast<const UnionShortExtraMember*>(data);

// Object that manages the raw buffer.
eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload.data), payload.max_size);
// Object that serializes the data.
eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2);
payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
ser.set_encoding_flag(
data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR :
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2);

try
{
// Serialize encapsulation
ser.serialize_encapsulation();
// Serialize the object.
ser << *p_type;
}
catch (eprosima::fastcdr::exception::Exception& /*exception*/)
{
return false;
}

// Get the serialized length
payload.length = static_cast<uint32_t>(ser.get_serialized_data_length());
return true;
}

bool UnionShortExtraMemberPubSubType::deserialize(
SerializedPayload_t& payload,
void* data)
{
try
{
// Convert DATA to pointer of your type
UnionShortExtraMember* p_type = static_cast<UnionShortExtraMember*>(data);

// Object that manages the raw buffer.
eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload.data), payload.length);

// Object that deserializes the data.
eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN);

// Deserialize encapsulation.
deser.read_encapsulation();
payload.encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;

// Deserialize the object.
deser >> *p_type;
}
catch (eprosima::fastcdr::exception::Exception& /*exception*/)
{
return false;
}

return true;
}

uint32_t UnionShortExtraMemberPubSubType::calculate_serialized_size(
const void* const data,
DataRepresentationId_t data_representation)
{
try
{
eprosima::fastcdr::CdrSizeCalculator calculator(
data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2);
size_t current_alignment {0};
return static_cast<uint32_t>(calculator.calculate_serialized_size(
*static_cast<const UnionShortExtraMember*>(data), current_alignment)) +
4u /*encapsulation*/;
}
catch (eprosima::fastcdr::exception::Exception& /*exception*/)
{
return 0;
}
}

void* UnionShortExtraMemberPubSubType::create_data()
{
return reinterpret_cast<void*>(new UnionShortExtraMember());
}

void UnionShortExtraMemberPubSubType::delete_data(
void* data)
{
delete(reinterpret_cast<UnionShortExtraMember*>(data));
}

bool UnionShortExtraMemberPubSubType::compute_key(
SerializedPayload_t& payload,
InstanceHandle_t& handle,
bool force_md5)
{
if (!is_compute_key_provided)
{
return false;
}

UnionShortExtraMember data;
if (deserialize(payload, static_cast<void*>(&data)))
{
return compute_key(static_cast<void*>(&data), handle, force_md5);
}

return false;
}

bool UnionShortExtraMemberPubSubType::compute_key(
const void* const data,
InstanceHandle_t& handle,
bool force_md5)
{
if (!is_compute_key_provided)
{
return false;
}

const UnionShortExtraMember* p_type = static_cast<const UnionShortExtraMember*>(data);

// Object that manages the raw buffer.
eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(key_buffer_),
UnionShortExtraMember_max_key_cdr_typesize);

// Object that serializes the data.
eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv2);
ser.set_encoding_flag(eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR2);
eprosima::fastcdr::serialize_key(ser, *p_type);
if (force_md5 || UnionShortExtraMember_max_key_cdr_typesize > 16)
{
md5_.init();
md5_.update(key_buffer_, static_cast<unsigned int>(ser.get_serialized_data_length()));
md5_.finalize();
for (uint8_t i = 0; i < 16; ++i)
{
handle.value[i] = md5_.digest[i];
}
}
else
{
for (uint8_t i = 0; i < 16; ++i)
{
handle.value[i] = key_buffer_[i];
}
}
return true;
}

void UnionShortExtraMemberPubSubType::register_type_object_representation()
{
register_UnionShortExtraMember_type_identifier(type_identifiers_);
}


// Include auxiliary functions like for serializing/deserializing.
#include "unionsCdrAux.ipp"
81 changes: 81 additions & 0 deletions test/dds-types-test/unionsPubSubTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3362,5 +3362,86 @@ class UnionSeveralFieldsWithDefaultPubSubType : public eprosima::fastdds::dds::T



/*!
* @brief This class represents the TopicDataType of the type UnionShortExtraMember defined by the user in the IDL file.
* @ingroup unions
*/
class UnionShortExtraMemberPubSubType : public eprosima::fastdds::dds::TopicDataType
{
public:

typedef UnionShortExtraMember type;

eProsima_user_DllExport UnionShortExtraMemberPubSubType();

eProsima_user_DllExport ~UnionShortExtraMemberPubSubType() override;

eProsima_user_DllExport bool serialize(
const void* const data,
eprosima::fastdds::rtps::SerializedPayload_t& payload,
eprosima::fastdds::dds::DataRepresentationId_t data_representation) override;

eProsima_user_DllExport bool deserialize(
eprosima::fastdds::rtps::SerializedPayload_t& payload,
void* data) override;

eProsima_user_DllExport uint32_t calculate_serialized_size(
const void* const data,
eprosima::fastdds::dds::DataRepresentationId_t data_representation) override;

eProsima_user_DllExport bool compute_key(
eprosima::fastdds::rtps::SerializedPayload_t& payload,
eprosima::fastdds::rtps::InstanceHandle_t& ihandle,
bool force_md5 = false) override;

eProsima_user_DllExport bool compute_key(
const void* const data,
eprosima::fastdds::rtps::InstanceHandle_t& ihandle,
bool force_md5 = false) override;

eProsima_user_DllExport void* create_data() override;

eProsima_user_DllExport void delete_data(
void* data) override;

//Register TypeObject representation in Fast DDS TypeObjectRegistry
eProsima_user_DllExport void register_type_object_representation() override;

#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED
eProsima_user_DllExport inline bool is_bounded() const override
{
return true;
}

#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED

#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN

eProsima_user_DllExport inline bool is_plain(
eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override
{
static_cast<void>(data_representation);
return false;
}

#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN

#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE
eProsima_user_DllExport inline bool construct_sample(
void* memory) const override
{
static_cast<void>(memory);
return false;
}

#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE

private:

eprosima::fastdds::MD5 md5_;
unsigned char* key_buffer_;

};

#endif // FAST_DDS_GENERATED__UNIONS_PUBSUBTYPES_HPP

Loading

0 comments on commit d1e90f3

Please sign in to comment.