Skip to content

Commit

Permalink
fix compilation against master (#111)
Browse files Browse the repository at this point in the history
* use refactored test messages

Signed-off-by: Dirk Thomas <dirk-thomas@users.noreply.github.com>

* partial update

Signed-off-by: Dirk Thomas <dirk-thomas@users.noreply.github.com>

* fix rsbag2_converter_default_plugins

Signed-off-by: Karsten Knese <karsten@openrobotics.org>

* fix rosbag2_transport

Signed-off-by: Karsten Knese <karsten@openrobotics.org>

* fix rosbag2_tests

Signed-off-by: Karsten Knese <karsten@openrobotics.org>

* add wstring to introspection message

Signed-off-by: Karsten Knese <karsten@openrobotics.org>

* default initialize qos profile

Signed-off-by: Karsten Knese <karsten@openrobotics.org>

* avoid deprecated publish signature

Signed-off-by: Karsten Knese <karsten@openrobotics.org>
  • Loading branch information
dirk-thomas authored and Karsten1987 committed May 7, 2019
1 parent 8b746c7 commit 0fcb2e4
Show file tree
Hide file tree
Showing 22 changed files with 319 additions and 257 deletions.
23 changes: 23 additions & 0 deletions rosbag2/src/rosbag2/types/introspection_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ void cleanup_element(
if (member.type_id_ == rosidl_typesupport_introspection_cpp::ROS_TYPE_STRING) {
std::string empty;
static_cast<std::string *>(data)->swap(empty);
} else if (member.type_id_ == rosidl_typesupport_introspection_cpp::ROS_TYPE_WSTRING) {
std::wstring empty;
static_cast<std::wstring *>(data)->swap(empty);
} else if (member.type_id_ == rosidl_typesupport_introspection_cpp::ROS_TYPE_MESSAGE) {
deallocate_internal_types(
data,
Expand All @@ -106,6 +109,12 @@ void cleanup_array(
auto * element = static_cast<std::string *>(member.get_function(data, i));
element->swap(empty);
}
} else if (member.type_id_ == rosidl_typesupport_introspection_cpp::ROS_TYPE_STRING) {
for (size_t i = 0; i < member.array_size_; ++i) {
std::wstring empty;
auto * element = static_cast<std::wstring *>(member.get_function(data, i));
element->swap(empty);
}
} else if (member.type_id_ == rosidl_typesupport_introspection_cpp::ROS_TYPE_MESSAGE) {
auto nested_ts =
static_cast<const rosidl_typesupport_introspection_cpp::MessageMembers *>(
Expand Down Expand Up @@ -205,6 +214,12 @@ void cleanup_vector(
data_vector->swap(empty);
break;
}
case rosidl_typesupport_introspection_cpp::ROS_TYPE_WSTRING: {
auto data_vector = static_cast<std::vector<std::wstring> *>(data);
std::vector<std::wstring> empty;
data_vector->swap(empty);
break;
}
case rosidl_typesupport_introspection_cpp::ROS_TYPE_MESSAGE: {
auto data_vector = static_cast<std::vector<uint8_t> *>(data);

Expand Down Expand Up @@ -264,6 +279,12 @@ void allocate_array(
// This is necessary because initialization of empty strings fails for g++ compiled builds
new (element) std::string("");
}
} else if (member.type_id_ == rosidl_typesupport_introspection_cpp::ROS_TYPE_WSTRING) {
for (size_t i = 0; i < member.array_size_; ++i) {
auto * element = static_cast<std::string *>(member.get_function(data, i));
// This is necessary because initialization of empty strings fails for g++ compiled builds
new (element) std::wstring();
}
} else if (member.type_id_ == rosidl_typesupport_introspection_cpp::ROS_TYPE_MESSAGE) {
auto nested_ts = static_cast<const rosidl_typesupport_introspection_cpp::MessageMembers *>(
member.members_->data);
Expand All @@ -280,6 +301,8 @@ void allocate_element(
if (member.type_id_ == rosidl_typesupport_introspection_cpp::ROS_TYPE_STRING) {
// This is necessary because initialization of empty strings fails for g++ compiled builds
new (data) std::string("");
} else if (member.type_id_ == rosidl_typesupport_introspection_cpp::ROS_TYPE_WSTRING) {
new (data) std::wstring();
} else if (member.type_id_ == rosidl_typesupport_introspection_cpp::ROS_TYPE_MESSAGE) {
allocate_internal_types(
data,
Expand Down
2 changes: 1 addition & 1 deletion rosbag2/test/rosbag2/test_sequential_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class SequentialReaderTest : public Test

rosbag2_storage::TopicMetadata topic_with_type;
topic_with_type.name = "topic";
topic_with_type.type = "test_msgs/Primitives";
topic_with_type.type = "test_msgs/BasicTypes";
auto topics_and_types = std::vector<rosbag2_storage::TopicMetadata>{topic_with_type};
EXPECT_CALL(*storage_, get_all_topics_and_types())
.Times(AtMost(1)).WillRepeatedly(Return(topics_and_types));
Expand Down
2 changes: 1 addition & 1 deletion rosbag2/test/rosbag2/test_typesupport_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ TEST(TypesupportHelpersTest, throws_exception_if_library_cannot_be_found) {

TEST(TypesupportHelpersTest, returns_c_type_info_for_valid_library) {
auto string_typesupport =
rosbag2::get_typesupport("test_msgs/Primitives", "rosidl_typesupport_cpp");
rosbag2::get_typesupport("test_msgs/BasicTypes", "rosidl_typesupport_cpp");

EXPECT_THAT(std::string(string_typesupport->typesupport_identifier),
ContainsRegex("rosidl_typesupport"));
Expand Down
4 changes: 2 additions & 2 deletions rosbag2/test/rosbag2/test_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ TEST_F(WriterTest,
auto message = std::make_shared<rosbag2::SerializedBagMessage>();
message->topic_name = "test_topic";
writer_->open(storage_options_, {input_format, storage_serialization_format});
writer_->create_topic({"test_topic", "test_msgs/Primitives", ""});
writer_->create_topic({"test_topic", "test_msgs/BasicTypes", ""});
writer_->write(message);
}

Expand All @@ -91,7 +91,7 @@ TEST_F(WriterTest, write_does_not_use_converters_if_input_and_output_format_are_
auto message = std::make_shared<rosbag2::SerializedBagMessage>();
message->topic_name = "test_topic";
writer_->open(storage_options_, {storage_serialization_format, storage_serialization_format});
writer_->create_topic({"test_topic", "test_msgs/Primitives", ""});
writer_->create_topic({"test_topic", "test_msgs/BasicTypes", ""});
writer_->write(message);
}

Expand Down
156 changes: 54 additions & 102 deletions rosbag2/test/rosbag2/types/test_ros2_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,14 @@

#include "rosbag2/typesupport_helpers.hpp"
#include "rosbag2/types/introspection_message.hpp"
#include "test_msgs/msg/bounded_array_nested.hpp"
#include "test_msgs/msg/bounded_array_primitives_nested.hpp"
#include "test_msgs/msg/bounded_array_primitives.hpp"
#include "test_msgs/msg/dynamic_array_primitives_nested.hpp"
#include "test_msgs/msg/dynamic_array_nested.hpp"
#include "test_msgs/msg/dynamic_array_primitives.hpp"
#include "test_msgs/msg/dynamic_array_static_array_primitives_nested.hpp"
#include "test_msgs/msg/nested.hpp"
#include "test_msgs/msg/primitives.hpp"
#include "test_msgs/msg/static_array_nested.hpp"
#include "test_msgs/msg/static_array_primitives.hpp"
#include "test_msgs/message_fixtures.hpp"
#include "test_msgs/msg/arrays.hpp"
#include "test_msgs/msg/basic_types.hpp"
#include "test_msgs/msg/bounded_sequences.hpp"
#include "test_msgs/msg/multi_nested.hpp"
#include "test_msgs/msg/nested.hpp"
#include "test_msgs/msg/strings.hpp"
#include "test_msgs/msg/unbounded_sequences.hpp"

using namespace testing; // NOLINT

Expand All @@ -58,163 +54,119 @@ class Ros2MessageTest : public Test
rcutils_allocator_t allocator_;
};

TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_primitive_message) {
auto message = get_allocated_message("test_msgs/Primitives");
TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_basic_types_message) {
auto message = get_allocated_message("test_msgs/BasicTypes");

auto data = static_cast<test_msgs::msg::Primitives *>(message->message);
auto data = static_cast<test_msgs::msg::BasicTypes *>(message->message);

data->bool_value = true;
data->string_value = "content";
data->int16_value = 144;
}

TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_primitive_message_with_empty_string) {
auto message = get_allocated_message("test_msgs/Primitives");
TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_strings_message_with_empty_string) {
auto message = get_allocated_message("test_msgs/Strings");

auto data = static_cast<test_msgs::msg::Primitives *>(message->message);
auto data = static_cast<test_msgs::msg::Strings *>(message->message);

data->bool_value = true;
data->string_value = "";
data->int16_value = 144;
}

TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_primitive_message_with_big_string_no_SSO) {
auto message = get_allocated_message("test_msgs/Primitives");
TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_strings_message_with_big_string_no_SSO) {
auto message = get_allocated_message("test_msgs/Strings");

auto data = static_cast<test_msgs::msg::Primitives *>(message->message);
auto data = static_cast<test_msgs::msg::Strings *>(message->message);

data->bool_value = true;
data->string_value = std::string(1000, 's');
data->int16_value = 144;
}

TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_nested_message) {
auto message = get_allocated_message("test_msgs/Nested");

auto data = static_cast<test_msgs::msg::Nested *>(message->message);

data->primitive_values.bool_value = true;
data->primitive_values.string_value = "content";
data->primitive_values.int16_value = 143;
data->basic_types_value.bool_value = true;
data->basic_types_value.int16_value = 143;
}

TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_static_array_message) {
auto message = get_allocated_message("test_msgs/StaticArrayPrimitives");
TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_arrays_message) {
auto message = get_allocated_message("test_msgs/Arrays");

auto data = static_cast<test_msgs::msg::StaticArrayPrimitives *>(message->message);
auto data = static_cast<test_msgs::msg::Arrays *>(message->message);

data->bool_values = {{true, false, true}};
data->string_values = {{"eins", "zwei", std::string(1000, 'd')}};
data->int32_values = {{11, 22, 33}};
}

TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_static_array_message_with_empty_string) {
auto message = get_allocated_message("test_msgs/StaticArrayPrimitives");
TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_arrays_message_with_empty_string) {
auto message = get_allocated_message("test_msgs/Arrays");

auto data = static_cast<test_msgs::msg::StaticArrayPrimitives *>(message->message);
auto data = static_cast<test_msgs::msg::Arrays *>(message->message);

data->bool_values = {{true, false, true}};
data->string_values = {{"", "zwei", std::string(1000, 'a')}};
data->int32_values = {{11, 22, 33}};

data->basic_types_values[0].bool_value = true;
data->basic_types_values[0].int64_value = 123;
data->basic_types_values[1].bool_value = false;
data->basic_types_values[1].int64_value = 123;
}

TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_dynamic_array_message) {
auto message = get_allocated_message("test_msgs/DynamicArrayPrimitives");
TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_unbounded_sequences_message) {
auto message = get_allocated_message("test_msgs/UnboundedSequences");

auto data = static_cast<test_msgs::msg::DynamicArrayPrimitives *>(message->message);
auto data = static_cast<test_msgs::msg::UnboundedSequences *>(message->message);

data->bool_values = {{true, false, true, false}};
data->string_values = {{"eins", std::string(1000, 'b'), ""}};
data->int32_values = {{11, 22, 33, 44, 55}};

data->basic_types_values.push_back(*get_messages_basic_types()[1]);
data->basic_types_values.push_back(*get_messages_basic_types()[2]);
}

TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_bounded_array_message) {
auto message = get_allocated_message("test_msgs/BoundedArrayPrimitives");
TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_bounded_sequences_message) {
auto message = get_allocated_message("test_msgs/BoundedSequences");

auto data = static_cast<test_msgs::msg::BoundedArrayPrimitives *>(message->message);
auto data = static_cast<test_msgs::msg::BoundedSequences *>(message->message);

data->bool_values = {{true, false, true}};
data->string_values = {{"eins", std::string(1000, 'z'), ""}};
data->int32_values = {11};
}

TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_static_array_nested_message) {
auto message = get_allocated_message("test_msgs/StaticArrayNested");

auto data = static_cast<test_msgs::msg::StaticArrayNested *>(message->message);

data->primitive_values[0].bool_value = true;
data->primitive_values[0].string_value = "eins";
data->primitive_values[0].int64_value = 123;
data->primitive_values[1].bool_value = false;
data->primitive_values[1].string_value = std::string(1000, '2');
data->primitive_values[1].int64_value = 123;
data->basic_types_values.push_back(*get_messages_basic_types()[1]);
data->basic_types_values.push_back(*get_messages_basic_types()[2]);
}

TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_dynamic_array_nested_message) {
auto message = get_allocated_message("test_msgs/DynamicArrayNested");

auto data = static_cast<test_msgs::msg::DynamicArrayNested *>(message->message);
TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_multi_nested_message) {
auto message = get_allocated_message("test_msgs/MultiNested");

data->primitive_values.push_back(*get_messages_primitives()[1]);
data->primitive_values.push_back(*get_messages_primitives()[2]);
}

TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_bounded_array_nested_message) {
auto message = get_allocated_message("test_msgs/BoundedArrayNested");

auto data = static_cast<test_msgs::msg::BoundedArrayNested *>(message->message);

data->primitive_values.push_back(*get_messages_primitives()[1]);
data->primitive_values.push_back(*get_messages_primitives()[2]);
}

TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_nested_static_array_nested_message) {
auto message = get_allocated_message("test_msgs/DynamicArrayStaticArrayPrimitivesNested");

auto data =
static_cast<test_msgs::msg::DynamicArrayStaticArrayPrimitivesNested *>(message->message);

data->dynamic_array_static_array_primitive_values.push_back(
*get_messages_static_array_primitives()[0]);
data->dynamic_array_static_array_primitive_values.push_back(
*get_messages_static_array_primitives()[0]);
}

TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_nested_dynamic_array_nested_message) {
auto message = get_allocated_message("test_msgs/DynamicArrayPrimitivesNested");

auto data =
static_cast<test_msgs::msg::DynamicArrayPrimitivesNested *>(message->message);

data->dynamic_array_primitive_values.push_back(
*get_messages_dynamic_array_primitives()[1]);
data->dynamic_array_primitive_values.push_back(
*get_messages_dynamic_array_primitives()[2]);
}
auto data = static_cast<test_msgs::msg::MultiNested *>(message->message);

TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_nested_bounded_array_nested_message) {
auto message = get_allocated_message("test_msgs/BoundedArrayPrimitivesNested");
data->array_of_arrays[0] = *get_messages_arrays()[0];

auto data =
static_cast<test_msgs::msg::BoundedArrayPrimitivesNested *>(message->message);
data->bounded_sequence_of_bounded_sequences.push_back(
*get_messages_bounded_sequences()[0]);
data->bounded_sequence_of_bounded_sequences.push_back(
*get_messages_bounded_sequences()[1]);

data->bounded_array_primitive_values.push_back(
*get_messages_bounded_array_primitives()[0]);
data->bounded_array_primitive_values.push_back(
*get_messages_bounded_array_primitives()[1]);
data->unbounded_sequence_of_unbounded_sequences.push_back(
*get_messages_unbounded_sequences()[0]);
data->unbounded_sequence_of_unbounded_sequences.push_back(
*get_messages_unbounded_sequences()[0]);
}

TEST_F(Ros2MessageTest, allocate_ros2_message_cleans_up_topic_name_on_shutdown) {
auto message = get_allocated_message("test_msgs/BoundedArrayNested");
auto message = get_allocated_message("test_msgs/BoundedSequences");

rosbag2::introspection_message_set_topic_name(message.get(), "Topic name");

EXPECT_THAT(message->topic_name, StrEq("Topic name"));
}

TEST_F(Ros2MessageTest, duplicate_set_topic_does_not_leak) {
auto message = get_allocated_message("test_msgs/BoundedArrayNested");
auto message = get_allocated_message("test_msgs/BoundedSequences");

rosbag2::introspection_message_set_topic_name(message.get(), "Topic name");
rosbag2::introspection_message_set_topic_name(message.get(), "Topic name");
Expand Down
Loading

0 comments on commit 0fcb2e4

Please sign in to comment.