Skip to content
28 changes: 24 additions & 4 deletions test_communication/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ if(BUILD_TESTING)
foreach(interface_file ${interface_files})
get_filename_component(interface_ns "${interface_file}" DIRECTORY)
get_filename_component(interface_ns "${interface_ns}" NAME)
string_ends_with("${interface_file}" ".msg" is_message)
if(is_message AND interface_ns STREQUAL "msg")
string_ends_with("${interface_file}" ".idl" is_idl)
if(is_idl AND interface_ns STREQUAL "msg")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the same change required for srv to avoid the duplication?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this probably related to #549, although it doesn't seem to be necessary for now and can be backported later

list(APPEND message_files "${interface_file}")
continue()
endif()
Expand All @@ -51,8 +51,7 @@ if(BUILD_TESTING)
list(APPEND service_files "${interface_file}")
continue()
endif()
string_ends_with("${interface_file}" ".idl" is_action)
if(is_action AND interface_ns STREQUAL "action")
if(is_idl AND interface_ns STREQUAL "action")
list(APPEND action_files "${interface_file}")
continue()
endif()
Expand Down Expand Up @@ -242,6 +241,26 @@ if(BUILD_TESTING)
set(TEST_MESSAGE_TYPES "")
foreach(message_file ${message_files})
get_filename_component(message_type "${message_file}" NAME_WE)
set(message_has_keys FALSE)
if(
"${message_type}" STREQUAL "KeyedLong" OR
"${message_type}" STREQUAL "KeyedString" OR
"${message_type}" STREQUAL "ComplexNestedKey"
)
set(message_has_keys TRUE)
endif()

# TODO(fgallegosalido): Only fastrtps and connext RMWs interoperate for keyed messages
if(
message_has_keys AND
(
(NOT (rmw_implementation1_is_fastrtps OR rmw_implementation1_is_connext)) OR
(NOT (rmw_implementation2_is_fastrtps OR rmw_implementation2_is_connext))
)
)
continue()
endif()

# TODO(dirk-thomas) WStrings published by FastRTPS can't be received
# correctly by Connext on macOS
if(
Expand Down Expand Up @@ -426,6 +445,7 @@ if(BUILD_TESTING)
add_library(subscribe_types STATIC
"test/subscribe_array_types.cpp"
"test/subscribe_basic_types.cpp"
"test/subscribe_key_types.cpp"
"test/subscribe_string_types.cpp")
target_link_libraries(subscribe_types
rclcpp::rclcpp
Expand Down
61 changes: 61 additions & 0 deletions test_communication/test/subscribe_key_types.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2025 Open Source Robotics Foundation, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <string>
#include <vector>

#include "rclcpp/rclcpp.hpp"

#include "subscribe_helper.hpp"
#include "subscribe_key_types.hpp"

rclcpp::SubscriptionBase::SharedPtr subscribe_keyed_long(
rclcpp::Node::SharedPtr node,
const std::string & message_type,
const std::vector<test_msgs::msg::KeyedLong::SharedPtr> & expected_messages,
std::vector<bool> & received_messages)
{
return subscribe<test_msgs::msg::KeyedLong>(
node, message_type, expected_messages, received_messages);
}

rclcpp::SubscriptionBase::SharedPtr subscribe_keyed_string(
rclcpp::Node::SharedPtr node,
const std::string & message_type,
const std::vector<test_msgs::msg::KeyedString::SharedPtr> & expected_messages,
std::vector<bool> & received_messages)
{
return subscribe<test_msgs::msg::KeyedString>(
node, message_type, expected_messages, received_messages);
}

rclcpp::SubscriptionBase::SharedPtr subscribe_non_keyed_with_nested_key(
rclcpp::Node::SharedPtr node,
const std::string & message_type,
const std::vector<test_msgs::msg::NonKeyedWithNestedKey::SharedPtr> & expected_messages,
std::vector<bool> & received_messages)
{
return subscribe<test_msgs::msg::NonKeyedWithNestedKey>(
node, message_type, expected_messages, received_messages);
}

rclcpp::SubscriptionBase::SharedPtr subscribe_complex_nested_key(
rclcpp::Node::SharedPtr node,
const std::string & message_type,
const std::vector<test_msgs::msg::ComplexNestedKey::SharedPtr> & expected_messages,
std::vector<bool> & received_messages)
{
return subscribe<test_msgs::msg::ComplexNestedKey>(
node, message_type, expected_messages, received_messages);
}
51 changes: 51 additions & 0 deletions test_communication/test/subscribe_key_types.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2025 Open Source Robotics Foundation, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef SUBSCRIBE_KEY_TYPES_HPP_
#define SUBSCRIBE_KEY_TYPES_HPP_

#include <string>
#include <vector>

#include "rclcpp/rclcpp.hpp"
#include "test_msgs/msg/complex_nested_key.hpp"
#include "test_msgs/msg/keyed_long.hpp"
#include "test_msgs/msg/keyed_string.hpp"
#include "test_msgs/msg/non_keyed_with_nested_key.hpp"

rclcpp::SubscriptionBase::SharedPtr subscribe_keyed_long(
rclcpp::Node::SharedPtr node,
const std::string & message_type,
const std::vector<test_msgs::msg::KeyedLong::SharedPtr> & expected_messages,
std::vector<bool> & received_messages);

rclcpp::SubscriptionBase::SharedPtr subscribe_keyed_string(
rclcpp::Node::SharedPtr node,
const std::string & message_type,
const std::vector<test_msgs::msg::KeyedString::SharedPtr> & expected_messages,
std::vector<bool> & received_messages);

rclcpp::SubscriptionBase::SharedPtr subscribe_non_keyed_with_nested_key(
rclcpp::Node::SharedPtr node,
const std::string & message_type,
const std::vector<test_msgs::msg::NonKeyedWithNestedKey::SharedPtr> & expected_messages,
std::vector<bool> & received_messages);

rclcpp::SubscriptionBase::SharedPtr subscribe_complex_nested_key(
rclcpp::Node::SharedPtr node,
const std::string & message_type,
const std::vector<test_msgs::msg::ComplexNestedKey::SharedPtr> & expected_messages,
std::vector<bool> & received_messages);

#endif // SUBSCRIBE_KEY_TYPES_HPP_
9 changes: 9 additions & 0 deletions test_communication/test/test_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ int main(int argc, char ** argv)
publish<test_msgs::msg::Strings>(node, message, get_messages_strings());
} else if (message == "WStrings") {
publish<test_msgs::msg::WStrings>(node, message, get_messages_wstrings());
} else if (message == "KeyedLong") {
publish<test_msgs::msg::KeyedLong>(node, message, get_messages_keyed_long());
} else if (message == "KeyedString") {
publish<test_msgs::msg::KeyedString>(node, message, get_messages_keyed_string());
} else if (message == "NonKeyedWithNestedKey") {
publish<test_msgs::msg::NonKeyedWithNestedKey>(
node, message, get_messages_non_keyed_with_nested_key());
} else if (message == "ComplexNestedKey") {
publish<test_msgs::msg::ComplexNestedKey>(node, message, get_messages_complex_nested_key());
} else {
fprintf(stderr, "Unknown message argument '%s'\n", message.c_str());
rclcpp::shutdown();
Expand Down
20 changes: 20 additions & 0 deletions test_communication/test/test_publisher_subscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include "subscribe_array_types.hpp"
#include "subscribe_basic_types.hpp"
#include "subscribe_key_types.hpp"
#include "subscribe_string_types.hpp"

template<typename T>
Expand Down Expand Up @@ -98,6 +99,10 @@ int main(int argc, char ** argv)
auto messages_defaults = get_messages_defaults();
auto messages_strings = get_messages_strings();
auto messages_wstrings = get_messages_wstrings();
auto messages_keyed_long = get_messages_keyed_long();
auto messages_keyed_string = get_messages_keyed_string();
auto messages_non_keyed_with_nested_key = get_messages_non_keyed_with_nested_key();
auto messages_complex_nested_key = get_messages_complex_nested_key();

std::thread spin_thread([node]() {
rclcpp::spin(node);
Expand Down Expand Up @@ -148,6 +153,21 @@ int main(int argc, char ** argv)
} else if (message == "WStrings") {
subscriber = subscribe_wstrings(node, message, messages_wstrings, received_messages);
publish<test_msgs::msg::WStrings>(node, message, messages_wstrings);
} else if (message == "KeyedLong") {
subscriber = subscribe_keyed_long(node, message, messages_keyed_long, received_messages);
publish<test_msgs::msg::KeyedLong>(node, message, messages_keyed_long);
} else if (message == "KeyedString") {
subscriber = subscribe_keyed_string(node, message, messages_keyed_string, received_messages);
publish<test_msgs::msg::KeyedString>(node, message, messages_keyed_string);
} else if (message == "NonKeyedWithNestedKey") {
subscriber = subscribe_non_keyed_with_nested_key(
node, message, messages_non_keyed_with_nested_key, received_messages);
publish<test_msgs::msg::NonKeyedWithNestedKey>(
node, message, messages_non_keyed_with_nested_key);
} else if (message == "ComplexNestedKey") {
subscriber = subscribe_complex_nested_key(
node, message, messages_complex_nested_key, received_messages);
publish<test_msgs::msg::ComplexNestedKey>(node, message, messages_complex_nested_key);
} else {
fprintf(stderr, "Unknown message argument '%s'\n", message.c_str());
return 1;
Expand Down
15 changes: 15 additions & 0 deletions test_communication/test/test_subscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "subscribe_array_types.hpp"
#include "subscribe_basic_types.hpp"
#include "subscribe_key_types.hpp"
#include "subscribe_string_types.hpp"

int main(int argc, char ** argv)
Expand Down Expand Up @@ -53,6 +54,10 @@ int main(int argc, char ** argv)
auto messages_defaults = get_messages_defaults();
auto messages_strings = get_messages_strings();
auto messages_wstrings = get_messages_wstrings();
auto messages_keyed_long = get_messages_keyed_long();
auto messages_keyed_string = get_messages_keyed_string();
auto messages_non_keyed_with_nested_key = get_messages_non_keyed_with_nested_key();
auto messages_complex_nested_key = get_messages_complex_nested_key();

rclcpp::SubscriptionBase::SharedPtr subscriber;
std::vector<bool> received_messages; // collect flags about received messages
Expand Down Expand Up @@ -85,6 +90,16 @@ int main(int argc, char ** argv)
subscriber = subscribe_strings(node, message, messages_strings, received_messages);
} else if (message == "WStrings") {
subscriber = subscribe_wstrings(node, message, messages_wstrings, received_messages);
} else if (message == "KeyedLong") {
subscriber = subscribe_keyed_long(node, message, messages_keyed_long, received_messages);
} else if (message == "KeyedString") {
subscriber = subscribe_keyed_string(node, message, messages_keyed_string, received_messages);
} else if (message == "NonKeyedWithNestedKey") {
subscriber = subscribe_non_keyed_with_nested_key(
node, message, messages_non_keyed_with_nested_key, received_messages);
} else if (message == "ComplexNestedKey") {
subscriber = subscribe_complex_nested_key(
node, message, messages_complex_nested_key, received_messages);
} else {
fprintf(stderr, "Unknown message argument '%s'\n", message.c_str());
rclcpp::shutdown();
Expand Down