diff --git a/rclcpp/include/rclcpp/node_interfaces/node_interfaces.hpp b/rclcpp/include/rclcpp/node_interfaces/node_interfaces.hpp index bc5ddb5c72..2f40380c75 100644 --- a/rclcpp/include/rclcpp/node_interfaces/node_interfaces.hpp +++ b/rclcpp/include/rclcpp/node_interfaces/node_interfaces.hpp @@ -20,11 +20,25 @@ #include "rclcpp/detail/template_unique.hpp" #include "rclcpp/node_interfaces/detail/node_interfaces_helpers.hpp" +#define ALL_RCLCPP_NODE_INTERFACES \ + rclcpp::node_interfaces::NodeBaseInterface, \ + rclcpp::node_interfaces::NodeClockInterface, \ + rclcpp::node_interfaces::NodeGraphInterface, \ + rclcpp::node_interfaces::NodeLoggingInterface, \ + rclcpp::node_interfaces::NodeParametersInterface, \ + rclcpp::node_interfaces::NodeServicesInterface, \ + rclcpp::node_interfaces::NodeTimeSourceInterface, \ + rclcpp::node_interfaces::NodeTimersInterface, \ + rclcpp::node_interfaces::NodeTopicsInterface, \ + rclcpp::node_interfaces::NodeWaitablesInterface + + namespace rclcpp { namespace node_interfaces { + /// A helper class for aggregating node interfaces. template class NodeInterfaces @@ -144,6 +158,7 @@ class NodeInterfaces {} }; + } // namespace node_interfaces } // namespace rclcpp diff --git a/rclcpp/test/rclcpp/CMakeLists.txt b/rclcpp/test/rclcpp/CMakeLists.txt index 55c308b876..6dffb543e9 100644 --- a/rclcpp/test/rclcpp/CMakeLists.txt +++ b/rclcpp/test/rclcpp/CMakeLists.txt @@ -267,7 +267,7 @@ ament_add_gtest(test_node_interfaces__node_waitables if(TARGET test_node_interfaces__node_waitables) target_link_libraries(test_node_interfaces__node_waitables ${PROJECT_NAME} mimick) endif() -add_library(test_node_interfaces__test_template_utils # Compile time test +ament_add_gtest(test_node_interfaces__test_template_utils # Compile time test node_interfaces/detail/test_template_utils.cpp) if(TARGET test_node_interfaces__test_template_utils) target_link_libraries(test_node_interfaces__test_template_utils ${PROJECT_NAME}) diff --git a/rclcpp/test/rclcpp/node_interfaces/detail/test_template_utils.cpp b/rclcpp/test/rclcpp/node_interfaces/detail/test_template_utils.cpp index 1a218589fd..9ae715ebce 100644 --- a/rclcpp/test/rclcpp/node_interfaces/detail/test_template_utils.cpp +++ b/rclcpp/test/rclcpp/node_interfaces/detail/test_template_utils.cpp @@ -12,9 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include + #include "rclcpp/detail/template_contains.hpp" #include "rclcpp/detail/template_unique.hpp" + +TEST(NoOpTests, test_node_interfaces_template_utils) { +} // This is just to let gtest work + namespace rclcpp { namespace detail diff --git a/rclcpp/test/rclcpp/node_interfaces/test_node_interfaces.cpp b/rclcpp/test/rclcpp/node_interfaces/test_node_interfaces.cpp index 377d8ddd1e..96596dea37 100644 --- a/rclcpp/test/rclcpp/node_interfaces/test_node_interfaces.cpp +++ b/rclcpp/test/rclcpp/node_interfaces/test_node_interfaces.cpp @@ -179,3 +179,67 @@ TEST_F(TestNodeInterfaces, ni_init) { time_source = ni.get_node_time_source_interface(); } } + +/* + Testing macro'ed getters. + */ +TEST_F(TestNodeInterfaces, ni_all_init) { + auto node = std::make_shared("my_node", "/ns"); + + using rclcpp::node_interfaces::NodeInterfaces; + using rclcpp::node_interfaces::NodeBaseInterface; + using rclcpp::node_interfaces::NodeClockInterface; + using rclcpp::node_interfaces::NodeGraphInterface; + using rclcpp::node_interfaces::NodeLoggingInterface; + using rclcpp::node_interfaces::NodeTimersInterface; + using rclcpp::node_interfaces::NodeTopicsInterface; + using rclcpp::node_interfaces::NodeServicesInterface; + using rclcpp::node_interfaces::NodeWaitablesInterface; + using rclcpp::node_interfaces::NodeParametersInterface; + using rclcpp::node_interfaces::NodeTimeSourceInterface; + + auto ni = rclcpp::node_interfaces::NodeInterfaces(node); + + { + auto base = ni.get(); + base = ni.get_node_base_interface(); + EXPECT_STREQ(base->get_name(), "my_node"); // Test for functionality + } + { + auto clock = ni.get(); + clock = ni.get_node_clock_interface(); + clock->get_clock(); + } + { + auto graph = ni.get(); + graph = ni.get_node_graph_interface(); + } + { + auto logging = ni.get(); + logging = ni.get_node_logging_interface(); + } + { + auto timers = ni.get(); + timers = ni.get_node_timers_interface(); + } + { + auto topics = ni.get(); + topics = ni.get_node_topics_interface(); + } + { + auto services = ni.get(); + services = ni.get_node_services_interface(); + } + { + auto waitables = ni.get(); + waitables = ni.get_node_waitables_interface(); + } + { + auto parameters = ni.get(); + parameters = ni.get_node_parameters_interface(); + } + { + auto time_source = ni.get(); + time_source = ni.get_node_time_source_interface(); + } +}