Skip to content

Commit 0fcb2e4

Browse files
dirk-thomasKarsten1987
authored andcommitted
fix compilation against master (ros2#111)
* use refactored test messages Signed-off-by: Dirk Thomas <[email protected]> * partial update Signed-off-by: Dirk Thomas <[email protected]> * fix rsbag2_converter_default_plugins Signed-off-by: Karsten Knese <[email protected]> * fix rosbag2_transport Signed-off-by: Karsten Knese <[email protected]> * fix rosbag2_tests Signed-off-by: Karsten Knese <[email protected]> * add wstring to introspection message Signed-off-by: Karsten Knese <[email protected]> * default initialize qos profile Signed-off-by: Karsten Knese <[email protected]> * avoid deprecated publish signature Signed-off-by: Karsten Knese <[email protected]>
1 parent 8b746c7 commit 0fcb2e4

22 files changed

Lines changed: 319 additions & 257 deletions

File tree

‎rosbag2/src/rosbag2/types/introspection_message.cpp‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ void cleanup_element(
8989
if (member.type_id_ == rosidl_typesupport_introspection_cpp::ROS_TYPE_STRING) {
9090
std::string empty;
9191
static_cast<std::string *>(data)->swap(empty);
92+
} else if (member.type_id_ == rosidl_typesupport_introspection_cpp::ROS_TYPE_WSTRING) {
93+
std::wstring empty;
94+
static_cast<std::wstring *>(data)->swap(empty);
9295
} else if (member.type_id_ == rosidl_typesupport_introspection_cpp::ROS_TYPE_MESSAGE) {
9396
deallocate_internal_types(
9497
data,
@@ -106,6 +109,12 @@ void cleanup_array(
106109
auto * element = static_cast<std::string *>(member.get_function(data, i));
107110
element->swap(empty);
108111
}
112+
} else if (member.type_id_ == rosidl_typesupport_introspection_cpp::ROS_TYPE_STRING) {
113+
for (size_t i = 0; i < member.array_size_; ++i) {
114+
std::wstring empty;
115+
auto * element = static_cast<std::wstring *>(member.get_function(data, i));
116+
element->swap(empty);
117+
}
109118
} else if (member.type_id_ == rosidl_typesupport_introspection_cpp::ROS_TYPE_MESSAGE) {
110119
auto nested_ts =
111120
static_cast<const rosidl_typesupport_introspection_cpp::MessageMembers *>(
@@ -205,6 +214,12 @@ void cleanup_vector(
205214
data_vector->swap(empty);
206215
break;
207216
}
217+
case rosidl_typesupport_introspection_cpp::ROS_TYPE_WSTRING: {
218+
auto data_vector = static_cast<std::vector<std::wstring> *>(data);
219+
std::vector<std::wstring> empty;
220+
data_vector->swap(empty);
221+
break;
222+
}
208223
case rosidl_typesupport_introspection_cpp::ROS_TYPE_MESSAGE: {
209224
auto data_vector = static_cast<std::vector<uint8_t> *>(data);
210225

@@ -264,6 +279,12 @@ void allocate_array(
264279
// This is necessary because initialization of empty strings fails for g++ compiled builds
265280
new (element) std::string("");
266281
}
282+
} else if (member.type_id_ == rosidl_typesupport_introspection_cpp::ROS_TYPE_WSTRING) {
283+
for (size_t i = 0; i < member.array_size_; ++i) {
284+
auto * element = static_cast<std::string *>(member.get_function(data, i));
285+
// This is necessary because initialization of empty strings fails for g++ compiled builds
286+
new (element) std::wstring();
287+
}
267288
} else if (member.type_id_ == rosidl_typesupport_introspection_cpp::ROS_TYPE_MESSAGE) {
268289
auto nested_ts = static_cast<const rosidl_typesupport_introspection_cpp::MessageMembers *>(
269290
member.members_->data);
@@ -280,6 +301,8 @@ void allocate_element(
280301
if (member.type_id_ == rosidl_typesupport_introspection_cpp::ROS_TYPE_STRING) {
281302
// This is necessary because initialization of empty strings fails for g++ compiled builds
282303
new (data) std::string("");
304+
} else if (member.type_id_ == rosidl_typesupport_introspection_cpp::ROS_TYPE_WSTRING) {
305+
new (data) std::wstring();
283306
} else if (member.type_id_ == rosidl_typesupport_introspection_cpp::ROS_TYPE_MESSAGE) {
284307
allocate_internal_types(
285308
data,

‎rosbag2/test/rosbag2/test_sequential_reader.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class SequentialReaderTest : public Test
4141

4242
rosbag2_storage::TopicMetadata topic_with_type;
4343
topic_with_type.name = "topic";
44-
topic_with_type.type = "test_msgs/Primitives";
44+
topic_with_type.type = "test_msgs/BasicTypes";
4545
auto topics_and_types = std::vector<rosbag2_storage::TopicMetadata>{topic_with_type};
4646
EXPECT_CALL(*storage_, get_all_topics_and_types())
4747
.Times(AtMost(1)).WillRepeatedly(Return(topics_and_types));

‎rosbag2/test/rosbag2/test_typesupport_helpers.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ TEST(TypesupportHelpersTest, throws_exception_if_library_cannot_be_found) {
5555

5656
TEST(TypesupportHelpersTest, returns_c_type_info_for_valid_library) {
5757
auto string_typesupport =
58-
rosbag2::get_typesupport("test_msgs/Primitives", "rosidl_typesupport_cpp");
58+
rosbag2::get_typesupport("test_msgs/BasicTypes", "rosidl_typesupport_cpp");
5959

6060
EXPECT_THAT(std::string(string_typesupport->typesupport_identifier),
6161
ContainsRegex("rosidl_typesupport"));

‎rosbag2/test/rosbag2/test_writer.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ TEST_F(WriterTest,
7575
auto message = std::make_shared<rosbag2::SerializedBagMessage>();
7676
message->topic_name = "test_topic";
7777
writer_->open(storage_options_, {input_format, storage_serialization_format});
78-
writer_->create_topic({"test_topic", "test_msgs/Primitives", ""});
78+
writer_->create_topic({"test_topic", "test_msgs/BasicTypes", ""});
7979
writer_->write(message);
8080
}
8181

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

‎rosbag2/test/rosbag2/types/test_ros2_message.cpp‎

Lines changed: 54 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,14 @@
2121

2222
#include "rosbag2/typesupport_helpers.hpp"
2323
#include "rosbag2/types/introspection_message.hpp"
24-
#include "test_msgs/msg/bounded_array_nested.hpp"
25-
#include "test_msgs/msg/bounded_array_primitives_nested.hpp"
26-
#include "test_msgs/msg/bounded_array_primitives.hpp"
27-
#include "test_msgs/msg/dynamic_array_primitives_nested.hpp"
28-
#include "test_msgs/msg/dynamic_array_nested.hpp"
29-
#include "test_msgs/msg/dynamic_array_primitives.hpp"
30-
#include "test_msgs/msg/dynamic_array_static_array_primitives_nested.hpp"
31-
#include "test_msgs/msg/nested.hpp"
32-
#include "test_msgs/msg/primitives.hpp"
33-
#include "test_msgs/msg/static_array_nested.hpp"
34-
#include "test_msgs/msg/static_array_primitives.hpp"
3524
#include "test_msgs/message_fixtures.hpp"
25+
#include "test_msgs/msg/arrays.hpp"
26+
#include "test_msgs/msg/basic_types.hpp"
27+
#include "test_msgs/msg/bounded_sequences.hpp"
28+
#include "test_msgs/msg/multi_nested.hpp"
29+
#include "test_msgs/msg/nested.hpp"
30+
#include "test_msgs/msg/strings.hpp"
31+
#include "test_msgs/msg/unbounded_sequences.hpp"
3632

3733
using namespace testing; // NOLINT
3834

@@ -58,163 +54,119 @@ class Ros2MessageTest : public Test
5854
rcutils_allocator_t allocator_;
5955
};
6056

61-
TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_primitive_message) {
62-
auto message = get_allocated_message("test_msgs/Primitives");
57+
TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_basic_types_message) {
58+
auto message = get_allocated_message("test_msgs/BasicTypes");
6359

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

6662
data->bool_value = true;
67-
data->string_value = "content";
6863
data->int16_value = 144;
6964
}
7065

71-
TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_primitive_message_with_empty_string) {
72-
auto message = get_allocated_message("test_msgs/Primitives");
66+
TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_strings_message_with_empty_string) {
67+
auto message = get_allocated_message("test_msgs/Strings");
7368

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

76-
data->bool_value = true;
7771
data->string_value = "";
78-
data->int16_value = 144;
7972
}
8073

81-
TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_primitive_message_with_big_string_no_SSO) {
82-
auto message = get_allocated_message("test_msgs/Primitives");
74+
TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_strings_message_with_big_string_no_SSO) {
75+
auto message = get_allocated_message("test_msgs/Strings");
8376

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

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

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

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

96-
data->primitive_values.bool_value = true;
97-
data->primitive_values.string_value = "content";
98-
data->primitive_values.int16_value = 143;
87+
data->basic_types_value.bool_value = true;
88+
data->basic_types_value.int16_value = 143;
9989
}
10090

101-
TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_static_array_message) {
102-
auto message = get_allocated_message("test_msgs/StaticArrayPrimitives");
91+
TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_arrays_message) {
92+
auto message = get_allocated_message("test_msgs/Arrays");
10393

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

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

111-
TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_static_array_message_with_empty_string) {
112-
auto message = get_allocated_message("test_msgs/StaticArrayPrimitives");
101+
TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_arrays_message_with_empty_string) {
102+
auto message = get_allocated_message("test_msgs/Arrays");
113103

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

116106
data->bool_values = {{true, false, true}};
117107
data->string_values = {{"", "zwei", std::string(1000, 'a')}};
118108
data->int32_values = {{11, 22, 33}};
109+
110+
data->basic_types_values[0].bool_value = true;
111+
data->basic_types_values[0].int64_value = 123;
112+
data->basic_types_values[1].bool_value = false;
113+
data->basic_types_values[1].int64_value = 123;
119114
}
120115

121-
TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_dynamic_array_message) {
122-
auto message = get_allocated_message("test_msgs/DynamicArrayPrimitives");
116+
TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_unbounded_sequences_message) {
117+
auto message = get_allocated_message("test_msgs/UnboundedSequences");
123118

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

126121
data->bool_values = {{true, false, true, false}};
127122
data->string_values = {{"eins", std::string(1000, 'b'), ""}};
128123
data->int32_values = {{11, 22, 33, 44, 55}};
124+
125+
data->basic_types_values.push_back(*get_messages_basic_types()[1]);
126+
data->basic_types_values.push_back(*get_messages_basic_types()[2]);
129127
}
130128

131-
TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_bounded_array_message) {
132-
auto message = get_allocated_message("test_msgs/BoundedArrayPrimitives");
129+
TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_bounded_sequences_message) {
130+
auto message = get_allocated_message("test_msgs/BoundedSequences");
133131

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

136134
data->bool_values = {{true, false, true}};
137135
data->string_values = {{"eins", std::string(1000, 'z'), ""}};
138136
data->int32_values = {11};
139-
}
140-
141-
TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_static_array_nested_message) {
142-
auto message = get_allocated_message("test_msgs/StaticArrayNested");
143137

144-
auto data = static_cast<test_msgs::msg::StaticArrayNested *>(message->message);
145-
146-
data->primitive_values[0].bool_value = true;
147-
data->primitive_values[0].string_value = "eins";
148-
data->primitive_values[0].int64_value = 123;
149-
data->primitive_values[1].bool_value = false;
150-
data->primitive_values[1].string_value = std::string(1000, '2');
151-
data->primitive_values[1].int64_value = 123;
138+
data->basic_types_values.push_back(*get_messages_basic_types()[1]);
139+
data->basic_types_values.push_back(*get_messages_basic_types()[2]);
152140
}
153141

154-
TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_dynamic_array_nested_message) {
155-
auto message = get_allocated_message("test_msgs/DynamicArrayNested");
156-
157-
auto data = static_cast<test_msgs::msg::DynamicArrayNested *>(message->message);
142+
TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_multi_nested_message) {
143+
auto message = get_allocated_message("test_msgs/MultiNested");
158144

159-
data->primitive_values.push_back(*get_messages_primitives()[1]);
160-
data->primitive_values.push_back(*get_messages_primitives()[2]);
161-
}
162-
163-
TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_bounded_array_nested_message) {
164-
auto message = get_allocated_message("test_msgs/BoundedArrayNested");
165-
166-
auto data = static_cast<test_msgs::msg::BoundedArrayNested *>(message->message);
167-
168-
data->primitive_values.push_back(*get_messages_primitives()[1]);
169-
data->primitive_values.push_back(*get_messages_primitives()[2]);
170-
}
171-
172-
TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_nested_static_array_nested_message) {
173-
auto message = get_allocated_message("test_msgs/DynamicArrayStaticArrayPrimitivesNested");
174-
175-
auto data =
176-
static_cast<test_msgs::msg::DynamicArrayStaticArrayPrimitivesNested *>(message->message);
177-
178-
data->dynamic_array_static_array_primitive_values.push_back(
179-
*get_messages_static_array_primitives()[0]);
180-
data->dynamic_array_static_array_primitive_values.push_back(
181-
*get_messages_static_array_primitives()[0]);
182-
}
183-
184-
TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_nested_dynamic_array_nested_message) {
185-
auto message = get_allocated_message("test_msgs/DynamicArrayPrimitivesNested");
186-
187-
auto data =
188-
static_cast<test_msgs::msg::DynamicArrayPrimitivesNested *>(message->message);
189-
190-
data->dynamic_array_primitive_values.push_back(
191-
*get_messages_dynamic_array_primitives()[1]);
192-
data->dynamic_array_primitive_values.push_back(
193-
*get_messages_dynamic_array_primitives()[2]);
194-
}
145+
auto data = static_cast<test_msgs::msg::MultiNested *>(message->message);
195146

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

199-
auto data =
200-
static_cast<test_msgs::msg::BoundedArrayPrimitivesNested *>(message->message);
149+
data->bounded_sequence_of_bounded_sequences.push_back(
150+
*get_messages_bounded_sequences()[0]);
151+
data->bounded_sequence_of_bounded_sequences.push_back(
152+
*get_messages_bounded_sequences()[1]);
201153

202-
data->bounded_array_primitive_values.push_back(
203-
*get_messages_bounded_array_primitives()[0]);
204-
data->bounded_array_primitive_values.push_back(
205-
*get_messages_bounded_array_primitives()[1]);
154+
data->unbounded_sequence_of_unbounded_sequences.push_back(
155+
*get_messages_unbounded_sequences()[0]);
156+
data->unbounded_sequence_of_unbounded_sequences.push_back(
157+
*get_messages_unbounded_sequences()[0]);
206158
}
207159

208160
TEST_F(Ros2MessageTest, allocate_ros2_message_cleans_up_topic_name_on_shutdown) {
209-
auto message = get_allocated_message("test_msgs/BoundedArrayNested");
161+
auto message = get_allocated_message("test_msgs/BoundedSequences");
210162

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

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

216168
TEST_F(Ros2MessageTest, duplicate_set_topic_does_not_leak) {
217-
auto message = get_allocated_message("test_msgs/BoundedArrayNested");
169+
auto message = get_allocated_message("test_msgs/BoundedSequences");
218170

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

0 commit comments

Comments
 (0)