Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new interface definitions #350

Merged
merged 14 commits into from
May 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions test_communication/msg/FieldsWithSameType.msg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test_msgs/Primitives primitive_values1
test_msgs/Primitives primitive_values2
test_msgs/BasicTypes basic_types_values1
test_msgs/BasicTypes basic_types_values2
200 changes: 101 additions & 99 deletions test_communication/test/test_message_serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@
#include "rmw/serialized_message.h"
#include "rmw/rmw.h"

#include "test_msgs/msg/bounded_array_nested.h"
#include "test_msgs/msg/bounded_array_nested.hpp"
#include "test_msgs/msg/primitives.h"
#include "test_msgs/msg/primitives.hpp"
#include "test_msgs/msg/basic_types.h"
#include "test_msgs/msg/basic_types.hpp"
#include "test_msgs/msg/bounded_sequences.h"
#include "test_msgs/msg/bounded_sequences.hpp"

#include "rcutils/allocator.h"

#include "rosidl_generator_c/string_functions.h"

#include "rosidl_typesupport_cpp/message_type_support.hpp"

#ifdef RMW_IMPLEMENTATION
Expand Down Expand Up @@ -54,45 +52,53 @@ void print_serialized_buffer(
printf("\n");
}

void fill_c_message(test_msgs__msg__BoundedArrayNested * bounded_array_nested_msg_c)
void fill_c_message(test_msgs__msg__BasicTypes * basic_types_msg_c)
{
test_msgs__msg__BasicTypes__init(basic_types_msg_c);
basic_types_msg_c->bool_value = true;
basic_types_msg_c->byte_value = 255;
basic_types_msg_c->char_value = 'k';
basic_types_msg_c->float32_value = 1;
basic_types_msg_c->float64_value = 2;
basic_types_msg_c->int8_value = 3;
basic_types_msg_c->uint8_value = 4;
basic_types_msg_c->int16_value = 5;
basic_types_msg_c->uint16_value = 6;
basic_types_msg_c->int32_value = 7;
basic_types_msg_c->uint32_value = 8;
basic_types_msg_c->int64_value = 9;
basic_types_msg_c->uint64_value = 10;
}

void fill_c_message(test_msgs__msg__BoundedSequences * bounded_sequences_msg_c)
{
test_msgs__msg__BoundedSequences__init(bounded_sequences_msg_c);
test_msgs__msg__BasicTypes__Sequence__init(&bounded_sequences_msg_c->basic_types_values, 1);
fill_c_message(&bounded_sequences_msg_c->basic_types_values.data[0]);
}

void fill_cpp_message(test_msgs::msg::BasicTypes * basic_types_msg_cpp)
{
test_msgs__msg__BoundedArrayNested__init(bounded_array_nested_msg_c);
test_msgs__msg__Primitives__Sequence__init(&bounded_array_nested_msg_c->primitive_values, 1);
bounded_array_nested_msg_c->primitive_values.data[0].bool_value = true;
bounded_array_nested_msg_c->primitive_values.data[0].byte_value = 255;
bounded_array_nested_msg_c->primitive_values.data[0].char_value = 'k';
bounded_array_nested_msg_c->primitive_values.data[0].float32_value = 1;
bounded_array_nested_msg_c->primitive_values.data[0].float64_value = 2;
bounded_array_nested_msg_c->primitive_values.data[0].int8_value = 3;
bounded_array_nested_msg_c->primitive_values.data[0].uint8_value = 4;
bounded_array_nested_msg_c->primitive_values.data[0].int16_value = 5;
bounded_array_nested_msg_c->primitive_values.data[0].uint16_value = 6;
bounded_array_nested_msg_c->primitive_values.data[0].int32_value = 7;
bounded_array_nested_msg_c->primitive_values.data[0].uint32_value = 8;
bounded_array_nested_msg_c->primitive_values.data[0].int64_value = 9;
bounded_array_nested_msg_c->primitive_values.data[0].uint64_value = 10;
rosidl_generator_c__String__assign(
&bounded_array_nested_msg_c->primitive_values.data[0].string_value, "hello world");
basic_types_msg_cpp->bool_value = true;
basic_types_msg_cpp->byte_value = 255;
basic_types_msg_cpp->char_value = 'k';
basic_types_msg_cpp->float32_value = 1;
basic_types_msg_cpp->float64_value = 2;
basic_types_msg_cpp->int8_value = 3;
basic_types_msg_cpp->uint8_value = 4;
basic_types_msg_cpp->int16_value = 5;
basic_types_msg_cpp->uint16_value = 6;
basic_types_msg_cpp->int32_value = 7;
basic_types_msg_cpp->uint32_value = 8;
basic_types_msg_cpp->int64_value = 9;
basic_types_msg_cpp->uint64_value = 10;
}

void fill_cpp_message(test_msgs::msg::BoundedArrayNested * bounded_array_nested_msg_cpp)
void fill_cpp_message(test_msgs::msg::BoundedSequences * bounded_sequences_msg_cpp)
{
test_msgs::msg::Primitives primitive_msg_cpp;
primitive_msg_cpp.bool_value = true;
primitive_msg_cpp.byte_value = 255;
primitive_msg_cpp.char_value = 'k';
primitive_msg_cpp.float32_value = 1;
primitive_msg_cpp.float64_value = 2;
primitive_msg_cpp.int8_value = 3;
primitive_msg_cpp.uint8_value = 4;
primitive_msg_cpp.int16_value = 5;
primitive_msg_cpp.uint16_value = 6;
primitive_msg_cpp.int32_value = 7;
primitive_msg_cpp.uint32_value = 8;
primitive_msg_cpp.int64_value = 9;
primitive_msg_cpp.uint64_value = 10;
primitive_msg_cpp.string_value = "hello world";
bounded_array_nested_msg_cpp->primitive_values.push_back(primitive_msg_cpp);
test_msgs::msg::BasicTypes basic_types;
fill_cpp_message(&basic_types);
bounded_sequences_msg_cpp->basic_types_values.push_back(basic_types);
}

TEST_F(CLASSNAME(TestMessageSerialization, RMW_IMPLEMENTATION), de_serialize_c) {
Expand All @@ -102,40 +108,38 @@ TEST_F(CLASSNAME(TestMessageSerialization, RMW_IMPLEMENTATION), de_serialize_c)
auto ret = rmw_serialized_message_init(&serialized_message_c, 0, &allocator);
ASSERT_EQ(RMW_RET_OK, ret);

auto message_c_typesupport = ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, BoundedArrayNested);
test_msgs__msg__BoundedArrayNested bounded_array_nested_msg_c;
fill_c_message(&bounded_array_nested_msg_c);
auto message_c_typesupport = ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, BasicTypes);
test_msgs__msg__BasicTypes basic_types_msg_c;
fill_c_message(&basic_types_msg_c);

ret = rmw_serialize(&bounded_array_nested_msg_c, message_c_typesupport, &serialized_message_c);
ret = rmw_serialize(&basic_types_msg_c, message_c_typesupport, &serialized_message_c);
EXPECT_EQ(RMW_RET_OK, ret);
EXPECT_EQ(76u, serialized_message_c.buffer_length); // measured from wireshark
EXPECT_EQ(52u, serialized_message_c.buffer_length); // measured from wireshark

printf("serialized data length: %zu\n", serialized_message_c.buffer_length);
print_serialized_buffer(serialized_message_c, "serialized message c");

test_msgs__msg__BoundedArrayNested bounded_array_nested_c_reverse;
test_msgs__msg__BoundedArrayNested__init(&bounded_array_nested_c_reverse);
test_msgs__msg__BasicTypes basic_types_c_reverse;
test_msgs__msg__BasicTypes__init(&basic_types_c_reverse);
ret =
rmw_deserialize(&serialized_message_c, message_c_typesupport, &bounded_array_nested_c_reverse);
rmw_deserialize(&serialized_message_c, message_c_typesupport, &basic_types_c_reverse);
EXPECT_EQ(RMW_RET_OK, ret);
EXPECT_EQ(true, bounded_array_nested_c_reverse.primitive_values.data[0].bool_value);
EXPECT_EQ(255, bounded_array_nested_c_reverse.primitive_values.data[0].byte_value);
EXPECT_EQ('k', bounded_array_nested_c_reverse.primitive_values.data[0].char_value);
EXPECT_EQ(1, bounded_array_nested_c_reverse.primitive_values.data[0].float32_value);
EXPECT_EQ(2, bounded_array_nested_c_reverse.primitive_values.data[0].float64_value);
EXPECT_EQ(3, bounded_array_nested_c_reverse.primitive_values.data[0].int8_value);
EXPECT_EQ(4u, bounded_array_nested_c_reverse.primitive_values.data[0].uint8_value);
EXPECT_EQ(5, bounded_array_nested_c_reverse.primitive_values.data[0].int16_value);
EXPECT_EQ(6u, bounded_array_nested_c_reverse.primitive_values.data[0].uint16_value);
EXPECT_EQ(7, bounded_array_nested_c_reverse.primitive_values.data[0].int32_value);
EXPECT_EQ(8u, bounded_array_nested_c_reverse.primitive_values.data[0].uint32_value);
EXPECT_EQ(9, bounded_array_nested_c_reverse.primitive_values.data[0].int64_value);
EXPECT_EQ(10u, bounded_array_nested_c_reverse.primitive_values.data[0].uint64_value);
EXPECT_STREQ(
"hello world", bounded_array_nested_c_reverse.primitive_values.data[0].string_value.data);

test_msgs__msg__BoundedArrayNested__fini(&bounded_array_nested_c_reverse);
test_msgs__msg__BoundedArrayNested__fini(&bounded_array_nested_msg_c);
EXPECT_EQ(true, basic_types_c_reverse.bool_value);
EXPECT_EQ(255, basic_types_c_reverse.byte_value);
EXPECT_EQ('k', basic_types_c_reverse.char_value);
EXPECT_EQ(1, basic_types_c_reverse.float32_value);
EXPECT_EQ(2, basic_types_c_reverse.float64_value);
EXPECT_EQ(3, basic_types_c_reverse.int8_value);
EXPECT_EQ(4u, basic_types_c_reverse.uint8_value);
EXPECT_EQ(5, basic_types_c_reverse.int16_value);
EXPECT_EQ(6u, basic_types_c_reverse.uint16_value);
EXPECT_EQ(7, basic_types_c_reverse.int32_value);
EXPECT_EQ(8u, basic_types_c_reverse.uint32_value);
EXPECT_EQ(9, basic_types_c_reverse.int64_value);
EXPECT_EQ(10u, basic_types_c_reverse.uint64_value);

test_msgs__msg__BasicTypes__fini(&basic_types_c_reverse);
test_msgs__msg__BasicTypes__fini(&basic_types_msg_c);
ret = rmw_serialized_message_fini(&serialized_message_c);
ASSERT_EQ(RMW_RET_OK, ret);
}
Expand All @@ -148,36 +152,34 @@ TEST_F(CLASSNAME(TestMessageSerialization, RMW_IMPLEMENTATION), de_serialize_cpp
ASSERT_EQ(RMW_RET_OK, ret);

auto message_cpp_typesupport =
rosidl_typesupport_cpp::get_message_type_support_handle<test_msgs::msg::BoundedArrayNested>();
rosidl_typesupport_cpp::get_message_type_support_handle<test_msgs::msg::BasicTypes>();

test_msgs::msg::BoundedArrayNested bounded_array_nested_msg_cpp;
fill_cpp_message(&bounded_array_nested_msg_cpp);
test_msgs::msg::BasicTypes basic_types_msg_cpp;
fill_cpp_message(&basic_types_msg_cpp);

ret =
rmw_serialize(&bounded_array_nested_msg_cpp, message_cpp_typesupport, &serialized_message_cpp);
rmw_serialize(&basic_types_msg_cpp, message_cpp_typesupport, &serialized_message_cpp);
EXPECT_EQ(RMW_RET_OK, ret);
EXPECT_EQ(76u, serialized_message_cpp.buffer_length);
EXPECT_EQ(52u, serialized_message_cpp.buffer_length);
print_serialized_buffer(serialized_message_cpp, "serialized message cpp");

test_msgs::msg::BoundedArrayNested bounded_array_nested_cpp_reverse;
test_msgs::msg::BasicTypes basic_types_cpp_reverse;
ret = rmw_deserialize(
&serialized_message_cpp, message_cpp_typesupport, &bounded_array_nested_cpp_reverse);
&serialized_message_cpp, message_cpp_typesupport, &basic_types_cpp_reverse);
EXPECT_EQ(RMW_RET_OK, ret);
EXPECT_EQ(true, bounded_array_nested_cpp_reverse.primitive_values[0].bool_value);
EXPECT_EQ(255, bounded_array_nested_cpp_reverse.primitive_values[0].byte_value);
EXPECT_EQ('k', bounded_array_nested_cpp_reverse.primitive_values[0].char_value);
EXPECT_EQ(1, bounded_array_nested_cpp_reverse.primitive_values[0].float32_value);
EXPECT_EQ(2, bounded_array_nested_cpp_reverse.primitive_values[0].float64_value);
EXPECT_EQ(3, bounded_array_nested_cpp_reverse.primitive_values[0].int8_value);
EXPECT_EQ(4u, bounded_array_nested_cpp_reverse.primitive_values[0].uint8_value);
EXPECT_EQ(5, bounded_array_nested_cpp_reverse.primitive_values[0].int16_value);
EXPECT_EQ(6u, bounded_array_nested_cpp_reverse.primitive_values[0].uint16_value);
EXPECT_EQ(7, bounded_array_nested_cpp_reverse.primitive_values[0].int32_value);
EXPECT_EQ(8u, bounded_array_nested_cpp_reverse.primitive_values[0].uint32_value);
EXPECT_EQ(9, bounded_array_nested_cpp_reverse.primitive_values[0].int64_value);
EXPECT_EQ(10u, bounded_array_nested_cpp_reverse.primitive_values[0].uint64_value);
EXPECT_STREQ(
"hello world", bounded_array_nested_cpp_reverse.primitive_values[0].string_value.c_str());
EXPECT_EQ(true, basic_types_cpp_reverse.bool_value);
EXPECT_EQ(255, basic_types_cpp_reverse.byte_value);
EXPECT_EQ('k', basic_types_cpp_reverse.char_value);
EXPECT_EQ(1, basic_types_cpp_reverse.float32_value);
EXPECT_EQ(2, basic_types_cpp_reverse.float64_value);
EXPECT_EQ(3, basic_types_cpp_reverse.int8_value);
EXPECT_EQ(4u, basic_types_cpp_reverse.uint8_value);
EXPECT_EQ(5, basic_types_cpp_reverse.int16_value);
EXPECT_EQ(6u, basic_types_cpp_reverse.uint16_value);
EXPECT_EQ(7, basic_types_cpp_reverse.int32_value);
EXPECT_EQ(8u, basic_types_cpp_reverse.uint32_value);
EXPECT_EQ(9, basic_types_cpp_reverse.int64_value);
EXPECT_EQ(10u, basic_types_cpp_reverse.uint64_value);

ret = rmw_serialized_message_fini(&serialized_message_cpp);
ASSERT_EQ(RMW_RET_OK, ret);
Expand All @@ -194,15 +196,15 @@ TEST_F(CLASSNAME(TestMessageSerialization, RMW_IMPLEMENTATION), cdr_integrity) {
ret = rmw_serialized_message_init(&serialized_message_cpp, 0, &allocator);
ASSERT_EQ(RMW_RET_OK, ret);

auto message_c_typesupport = ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, BoundedArrayNested);
auto message_c_typesupport = ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, BoundedSequences);
auto message_cpp_typesupport =
rosidl_typesupport_cpp::get_message_type_support_handle<test_msgs::msg::BoundedArrayNested>();
rosidl_typesupport_cpp::get_message_type_support_handle<test_msgs::msg::BoundedSequences>();

test_msgs__msg__BoundedArrayNested msg_c;
test_msgs__msg__BoundedArrayNested__init(&msg_c);
test_msgs__msg__BoundedSequences msg_c;
test_msgs__msg__BoundedSequences__init(&msg_c);
fill_c_message(&msg_c);

test_msgs::msg::BoundedArrayNested msg_cpp;
test_msgs::msg::BoundedSequences msg_cpp;
fill_cpp_message(&msg_cpp);

ret = rmw_serialize(&msg_c, message_c_typesupport, &serialized_message_c);
Expand All @@ -213,16 +215,16 @@ TEST_F(CLASSNAME(TestMessageSerialization, RMW_IMPLEMENTATION), cdr_integrity) {
print_serialized_buffer(serialized_message_c, "serialized message c");
print_serialized_buffer(serialized_message_cpp, "serialized message cpp");

test_msgs__msg__BoundedArrayNested msg_c_reverse;
test_msgs__msg__BoundedArrayNested__init(&msg_c_reverse);
test_msgs::msg::BoundedArrayNested msg_cpp_reverse;
test_msgs__msg__BoundedSequences msg_c_reverse;
test_msgs__msg__BoundedSequences__init(&msg_c_reverse);
test_msgs::msg::BoundedSequences msg_cpp_reverse;
ret = rmw_deserialize(&serialized_message_cpp, message_c_typesupport, &msg_c_reverse);
EXPECT_EQ(RMW_RET_OK, ret);
ret = rmw_deserialize(&serialized_message_c, message_cpp_typesupport, &msg_cpp_reverse);
EXPECT_EQ(RMW_RET_OK, ret);

test_msgs__msg__BoundedArrayNested__fini(&msg_c);
test_msgs__msg__BoundedArrayNested__fini(&msg_c_reverse);
test_msgs__msg__BoundedSequences__fini(&msg_c);
test_msgs__msg__BoundedSequences__fini(&msg_c_reverse);
ret = rmw_serialized_message_fini(&serialized_message_c);
ASSERT_EQ(RMW_RET_OK, ret);
ret = rmw_serialized_message_fini(&serialized_message_cpp);
Expand Down
Loading