Skip to content

Commit e5c9a0d

Browse files
fgallegosalidoMiguelCompanyfujitatomoya
authored
Add tests for Keyed types (#568)
* Added support for KeyedString. Signed-off-by: Miguel Company <[email protected]> * Added support for NonKeyedWithNestedKey. Signed-off-by: Miguel Company <[email protected]> * Added support for ComplexNestedKey. Signed-off-by: Miguel Company <[email protected]> * Make test_communication use idl messages instead of msg ones. Signed-off-by: Miguel Company <[email protected]> * Skip keyed messages for RMWs other than fastrtps ones. Signed-off-by: Miguel Company <[email protected]> * Changed copyright year on new files. Signed-off-by: Miguel Company <[email protected]> * Added tests for KeyedLong type and test interoperability between FastRTPS and Connext RMWs Signed-off-by: Francisco Gallego Salido <[email protected]> * Update test_communication/test/subscribe_key_types.cpp Co-authored-by: Tomoya Fujita <[email protected]> Signed-off-by: Francisco Gallego Salido <[email protected]> * Update test_communication/test/subscribe_key_types.hpp Co-authored-by: Tomoya Fujita <[email protected]> Signed-off-by: Francisco Gallego Salido <[email protected]> --------- Signed-off-by: Miguel Company <[email protected]> Signed-off-by: Francisco Gallego Salido <[email protected]> Co-authored-by: Miguel Company <[email protected]> Co-authored-by: Tomoya Fujita <[email protected]>
1 parent 768e530 commit e5c9a0d

File tree

6 files changed

+180
-4
lines changed

6 files changed

+180
-4
lines changed

test_communication/CMakeLists.txt

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ if(BUILD_TESTING)
4141
foreach(interface_file ${interface_files})
4242
get_filename_component(interface_ns "${interface_file}" DIRECTORY)
4343
get_filename_component(interface_ns "${interface_ns}" NAME)
44-
string_ends_with("${interface_file}" ".msg" is_message)
45-
if(is_message AND interface_ns STREQUAL "msg")
44+
string_ends_with("${interface_file}" ".idl" is_idl)
45+
if(is_idl AND interface_ns STREQUAL "msg")
4646
list(APPEND message_files "${interface_file}")
4747
continue()
4848
endif()
@@ -51,8 +51,7 @@ if(BUILD_TESTING)
5151
list(APPEND service_files "${interface_file}")
5252
continue()
5353
endif()
54-
string_ends_with("${interface_file}" ".idl" is_action)
55-
if(is_action AND interface_ns STREQUAL "action")
54+
if(is_idl AND interface_ns STREQUAL "action")
5655
list(APPEND action_files "${interface_file}")
5756
continue()
5857
endif()
@@ -242,6 +241,26 @@ if(BUILD_TESTING)
242241
set(TEST_MESSAGE_TYPES "")
243242
foreach(message_file ${message_files})
244243
get_filename_component(message_type "${message_file}" NAME_WE)
244+
set(message_has_keys FALSE)
245+
if(
246+
"${message_type}" STREQUAL "KeyedLong" OR
247+
"${message_type}" STREQUAL "KeyedString" OR
248+
"${message_type}" STREQUAL "ComplexNestedKey"
249+
)
250+
set(message_has_keys TRUE)
251+
endif()
252+
253+
# TODO(fgallegosalido): Only fastrtps and connext RMWs interoperate for keyed messages
254+
if(
255+
message_has_keys AND
256+
(
257+
(NOT (rmw_implementation1_is_fastrtps OR rmw_implementation1_is_connext)) OR
258+
(NOT (rmw_implementation2_is_fastrtps OR rmw_implementation2_is_connext))
259+
)
260+
)
261+
continue()
262+
endif()
263+
245264
# TODO(dirk-thomas) WStrings published by FastRTPS can't be received
246265
# correctly by Connext on macOS
247266
if(
@@ -426,6 +445,7 @@ if(BUILD_TESTING)
426445
add_library(subscribe_types STATIC
427446
"test/subscribe_array_types.cpp"
428447
"test/subscribe_basic_types.cpp"
448+
"test/subscribe_key_types.cpp"
429449
"test/subscribe_string_types.cpp")
430450
target_link_libraries(subscribe_types
431451
rclcpp::rclcpp
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright 2025 Open Source Robotics Foundation, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include <string>
16+
#include <vector>
17+
18+
#include "rclcpp/rclcpp.hpp"
19+
20+
#include "subscribe_helper.hpp"
21+
#include "subscribe_key_types.hpp"
22+
23+
rclcpp::SubscriptionBase::SharedPtr subscribe_keyed_long(
24+
rclcpp::Node::SharedPtr node,
25+
const std::string & message_type,
26+
const std::vector<test_msgs::msg::KeyedLong::SharedPtr> & expected_messages,
27+
std::vector<bool> & received_messages)
28+
{
29+
return subscribe<test_msgs::msg::KeyedLong>(
30+
node, message_type, expected_messages, received_messages);
31+
}
32+
33+
rclcpp::SubscriptionBase::SharedPtr subscribe_keyed_string(
34+
rclcpp::Node::SharedPtr node,
35+
const std::string & message_type,
36+
const std::vector<test_msgs::msg::KeyedString::SharedPtr> & expected_messages,
37+
std::vector<bool> & received_messages)
38+
{
39+
return subscribe<test_msgs::msg::KeyedString>(
40+
node, message_type, expected_messages, received_messages);
41+
}
42+
43+
rclcpp::SubscriptionBase::SharedPtr subscribe_non_keyed_with_nested_key(
44+
rclcpp::Node::SharedPtr node,
45+
const std::string & message_type,
46+
const std::vector<test_msgs::msg::NonKeyedWithNestedKey::SharedPtr> & expected_messages,
47+
std::vector<bool> & received_messages)
48+
{
49+
return subscribe<test_msgs::msg::NonKeyedWithNestedKey>(
50+
node, message_type, expected_messages, received_messages);
51+
}
52+
53+
rclcpp::SubscriptionBase::SharedPtr subscribe_complex_nested_key(
54+
rclcpp::Node::SharedPtr node,
55+
const std::string & message_type,
56+
const std::vector<test_msgs::msg::ComplexNestedKey::SharedPtr> & expected_messages,
57+
std::vector<bool> & received_messages)
58+
{
59+
return subscribe<test_msgs::msg::ComplexNestedKey>(
60+
node, message_type, expected_messages, received_messages);
61+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2025 Open Source Robotics Foundation, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef SUBSCRIBE_KEY_TYPES_HPP_
16+
#define SUBSCRIBE_KEY_TYPES_HPP_
17+
18+
#include <string>
19+
#include <vector>
20+
21+
#include "rclcpp/rclcpp.hpp"
22+
#include "test_msgs/msg/complex_nested_key.hpp"
23+
#include "test_msgs/msg/keyed_long.hpp"
24+
#include "test_msgs/msg/keyed_string.hpp"
25+
#include "test_msgs/msg/non_keyed_with_nested_key.hpp"
26+
27+
rclcpp::SubscriptionBase::SharedPtr subscribe_keyed_long(
28+
rclcpp::Node::SharedPtr node,
29+
const std::string & message_type,
30+
const std::vector<test_msgs::msg::KeyedLong::SharedPtr> & expected_messages,
31+
std::vector<bool> & received_messages);
32+
33+
rclcpp::SubscriptionBase::SharedPtr subscribe_keyed_string(
34+
rclcpp::Node::SharedPtr node,
35+
const std::string & message_type,
36+
const std::vector<test_msgs::msg::KeyedString::SharedPtr> & expected_messages,
37+
std::vector<bool> & received_messages);
38+
39+
rclcpp::SubscriptionBase::SharedPtr subscribe_non_keyed_with_nested_key(
40+
rclcpp::Node::SharedPtr node,
41+
const std::string & message_type,
42+
const std::vector<test_msgs::msg::NonKeyedWithNestedKey::SharedPtr> & expected_messages,
43+
std::vector<bool> & received_messages);
44+
45+
rclcpp::SubscriptionBase::SharedPtr subscribe_complex_nested_key(
46+
rclcpp::Node::SharedPtr node,
47+
const std::string & message_type,
48+
const std::vector<test_msgs::msg::ComplexNestedKey::SharedPtr> & expected_messages,
49+
std::vector<bool> & received_messages);
50+
51+
#endif // SUBSCRIBE_KEY_TYPES_HPP_

test_communication/test/test_publisher.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,15 @@ int main(int argc, char ** argv)
107107
publish<test_msgs::msg::Strings>(node, message, get_messages_strings());
108108
} else if (message == "WStrings") {
109109
publish<test_msgs::msg::WStrings>(node, message, get_messages_wstrings());
110+
} else if (message == "KeyedLong") {
111+
publish<test_msgs::msg::KeyedLong>(node, message, get_messages_keyed_long());
112+
} else if (message == "KeyedString") {
113+
publish<test_msgs::msg::KeyedString>(node, message, get_messages_keyed_string());
114+
} else if (message == "NonKeyedWithNestedKey") {
115+
publish<test_msgs::msg::NonKeyedWithNestedKey>(
116+
node, message, get_messages_non_keyed_with_nested_key());
117+
} else if (message == "ComplexNestedKey") {
118+
publish<test_msgs::msg::ComplexNestedKey>(node, message, get_messages_complex_nested_key());
110119
} else {
111120
fprintf(stderr, "Unknown message argument '%s'\n", message.c_str());
112121
rclcpp::shutdown();

test_communication/test/test_publisher_subscriber.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "subscribe_array_types.hpp"
2727
#include "subscribe_basic_types.hpp"
28+
#include "subscribe_key_types.hpp"
2829
#include "subscribe_string_types.hpp"
2930

3031
template<typename T>
@@ -98,6 +99,10 @@ int main(int argc, char ** argv)
9899
auto messages_defaults = get_messages_defaults();
99100
auto messages_strings = get_messages_strings();
100101
auto messages_wstrings = get_messages_wstrings();
102+
auto messages_keyed_long = get_messages_keyed_long();
103+
auto messages_keyed_string = get_messages_keyed_string();
104+
auto messages_non_keyed_with_nested_key = get_messages_non_keyed_with_nested_key();
105+
auto messages_complex_nested_key = get_messages_complex_nested_key();
101106

102107
std::thread spin_thread([node]() {
103108
rclcpp::spin(node);
@@ -148,6 +153,21 @@ int main(int argc, char ** argv)
148153
} else if (message == "WStrings") {
149154
subscriber = subscribe_wstrings(node, message, messages_wstrings, received_messages);
150155
publish<test_msgs::msg::WStrings>(node, message, messages_wstrings);
156+
} else if (message == "KeyedLong") {
157+
subscriber = subscribe_keyed_long(node, message, messages_keyed_long, received_messages);
158+
publish<test_msgs::msg::KeyedLong>(node, message, messages_keyed_long);
159+
} else if (message == "KeyedString") {
160+
subscriber = subscribe_keyed_string(node, message, messages_keyed_string, received_messages);
161+
publish<test_msgs::msg::KeyedString>(node, message, messages_keyed_string);
162+
} else if (message == "NonKeyedWithNestedKey") {
163+
subscriber = subscribe_non_keyed_with_nested_key(
164+
node, message, messages_non_keyed_with_nested_key, received_messages);
165+
publish<test_msgs::msg::NonKeyedWithNestedKey>(
166+
node, message, messages_non_keyed_with_nested_key);
167+
} else if (message == "ComplexNestedKey") {
168+
subscriber = subscribe_complex_nested_key(
169+
node, message, messages_complex_nested_key, received_messages);
170+
publish<test_msgs::msg::ComplexNestedKey>(node, message, messages_complex_nested_key);
151171
} else {
152172
fprintf(stderr, "Unknown message argument '%s'\n", message.c_str());
153173
return 1;

test_communication/test/test_subscriber.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include "subscribe_array_types.hpp"
2525
#include "subscribe_basic_types.hpp"
26+
#include "subscribe_key_types.hpp"
2627
#include "subscribe_string_types.hpp"
2728

2829
int main(int argc, char ** argv)
@@ -53,6 +54,10 @@ int main(int argc, char ** argv)
5354
auto messages_defaults = get_messages_defaults();
5455
auto messages_strings = get_messages_strings();
5556
auto messages_wstrings = get_messages_wstrings();
57+
auto messages_keyed_long = get_messages_keyed_long();
58+
auto messages_keyed_string = get_messages_keyed_string();
59+
auto messages_non_keyed_with_nested_key = get_messages_non_keyed_with_nested_key();
60+
auto messages_complex_nested_key = get_messages_complex_nested_key();
5661

5762
rclcpp::SubscriptionBase::SharedPtr subscriber;
5863
std::vector<bool> received_messages; // collect flags about received messages
@@ -85,6 +90,16 @@ int main(int argc, char ** argv)
8590
subscriber = subscribe_strings(node, message, messages_strings, received_messages);
8691
} else if (message == "WStrings") {
8792
subscriber = subscribe_wstrings(node, message, messages_wstrings, received_messages);
93+
} else if (message == "KeyedLong") {
94+
subscriber = subscribe_keyed_long(node, message, messages_keyed_long, received_messages);
95+
} else if (message == "KeyedString") {
96+
subscriber = subscribe_keyed_string(node, message, messages_keyed_string, received_messages);
97+
} else if (message == "NonKeyedWithNestedKey") {
98+
subscriber = subscribe_non_keyed_with_nested_key(
99+
node, message, messages_non_keyed_with_nested_key, received_messages);
100+
} else if (message == "ComplexNestedKey") {
101+
subscriber = subscribe_complex_nested_key(
102+
node, message, messages_complex_nested_key, received_messages);
88103
} else {
89104
fprintf(stderr, "Unknown message argument '%s'\n", message.c_str());
90105
rclcpp::shutdown();

0 commit comments

Comments
 (0)