Skip to content

Commit aa18ef5

Browse files
authored
Cleanup the TypeAdapt tests (#1858)
* Cleanup test_publisher_with_type_adapter. It had a lot of infrastructure that it didn't need, so remove most of that. Also move the creation of the node to open-coded, since we weren't really saving anything. Finally make sure to reset the node pointers as appropriate, which cleans up errant error messages. * Cleanup test_subscription_with_type_adapter. It had a lot of infrastructure that it didn't need, so remove most of that. Also move the creation of the node to open-coded, since we weren't really saving anything. Finally make sure to reset the node pointers as appropriate, which cleans up errant error messages. Signed-off-by: Chris Lalancette <[email protected]>
1 parent 1688f05 commit aa18ef5

File tree

3 files changed

+8
-102
lines changed

3 files changed

+8
-102
lines changed

rclcpp/test/rclcpp/CMakeLists.txt

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -368,35 +368,17 @@ ament_add_gtest(test_publisher_with_type_adapter test_publisher_with_type_adapte
368368
APPEND_LIBRARY_DIRS "${append_library_dirs}"
369369
)
370370
if(TARGET test_publisher_with_type_adapter)
371-
ament_target_dependencies(test_publisher_with_type_adapter
372-
"rcutils"
373-
"rcl_interfaces"
374-
"rmw"
375-
"rosidl_runtime_cpp"
376-
"rosidl_typesupport_cpp"
377-
"test_msgs"
378-
)
379371
target_link_libraries(test_publisher_with_type_adapter
380372
${PROJECT_NAME}
381-
mimick
382373
${cpp_typesupport_target})
383374
endif()
384375

385376
ament_add_gtest(test_subscription_with_type_adapter test_subscription_with_type_adapter.cpp
386377
APPEND_LIBRARY_DIRS "${append_library_dirs}"
387378
)
388379
if(TARGET test_subscription_with_type_adapter)
389-
ament_target_dependencies(test_subscription_with_type_adapter
390-
"rcutils"
391-
"rcl_interfaces"
392-
"rmw"
393-
"rosidl_runtime_cpp"
394-
"rosidl_typesupport_cpp"
395-
"test_msgs"
396-
)
397380
target_link_libraries(test_subscription_with_type_adapter
398381
${PROJECT_NAME}
399-
mimick
400382
${cpp_typesupport_target})
401383
endif()
402384

rclcpp/test/rclcpp/test_publisher_with_type_adapter.cpp

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,18 @@
1616
#include <gtest/gtest.h>
1717

1818
#include <chrono>
19-
#include <functional>
2019
#include <memory>
2120
#include <string>
2221
#include <thread>
2322
#include <utility>
24-
#include <vector>
2523

2624
#include "rclcpp/exceptions.hpp"
2725
#include "rclcpp/loaned_message.hpp"
2826
#include "rclcpp/rclcpp.hpp"
2927

30-
#include "../mocking_utils/patch.hpp"
31-
#include "../utils/rclcpp_gtest_macros.hpp"
32-
33-
#include "test_msgs/msg/empty.hpp"
3428
#include "rclcpp/msg/string.hpp"
3529

3630

37-
#ifdef RMW_IMPLEMENTATION
38-
# define CLASSNAME_(NAME, SUFFIX) NAME ## __ ## SUFFIX
39-
# define CLASSNAME(NAME, SUFFIX) CLASSNAME_(NAME, SUFFIX)
40-
#else
41-
# define CLASSNAME(NAME, SUFFIX) NAME
42-
#endif
43-
44-
4531
using namespace std::chrono_literals;
4632

4733
static const int g_max_loops = 200;
@@ -58,28 +44,6 @@ class TestPublisher : public ::testing::Test
5844
}
5945
}
6046

61-
protected:
62-
void initialize(const rclcpp::NodeOptions & node_options = rclcpp::NodeOptions())
63-
{
64-
node = std::make_shared<rclcpp::Node>("my_node", "/ns", node_options);
65-
}
66-
67-
void TearDown()
68-
{
69-
node.reset();
70-
}
71-
72-
rclcpp::Node::SharedPtr node;
73-
};
74-
75-
class CLASSNAME (test_intra_process_within_one_node, RMW_IMPLEMENTATION) : public ::testing::Test
76-
{
77-
public:
78-
static void SetUpTestCase()
79-
{
80-
rclcpp::init(0, nullptr);
81-
}
82-
8347
static void TearDownTestCase()
8448
{
8549
rclcpp::shutdown();
@@ -128,7 +92,7 @@ struct TypeAdapter<int, rclcpp::msg::String>
12892
{
12993
(void) source;
13094
(void) destination;
131-
throw std::runtime_error("This should happen");
95+
throw std::runtime_error("This should not happen");
13296
}
13397

13498
static void
@@ -150,7 +114,7 @@ TEST_F(TestPublisher, various_creation_signatures) {
150114
for (auto is_intra_process : {true, false}) {
151115
rclcpp::NodeOptions options;
152116
options.use_intra_process_comms(is_intra_process);
153-
initialize(options);
117+
auto node = std::make_shared<rclcpp::Node>("my_node", "/ns", options);
154118
{
155119
using StringTypeAdapter = rclcpp::TypeAdapter<std::string, rclcpp::msg::String>;
156120
auto publisher = node->create_publisher<StringTypeAdapter>("topic", 42);
@@ -179,7 +143,7 @@ TEST_F(TestPublisher, conversion_exception_is_passed_up) {
179143
(void)msg;
180144
};
181145

182-
initialize(options);
146+
auto node = std::make_shared<rclcpp::Node>("my_node", "/ns", options);
183147
auto pub = node->create_publisher<BadStringTypeAdapter>("topic_name", 1);
184148
// A subscription is created to ensure the existence of a buffer in the intra proccess
185149
// manager which will trigger the faulty conversion.
@@ -192,7 +156,7 @@ TEST_F(TestPublisher, conversion_exception_is_passed_up) {
192156
* Testing that publisher sends type adapted types and ROS message types with intra proccess communications.
193157
*/
194158
TEST_F(
195-
CLASSNAME(test_intra_process_within_one_node, RMW_IMPLEMENTATION),
159+
TestPublisher,
196160
check_type_adapted_message_is_sent_and_received_intra_process) {
197161
using StringTypeAdapter = rclcpp::TypeAdapter<std::string, rclcpp::msg::String>;
198162
const std::string message_data = "Message Data";
@@ -281,7 +245,7 @@ TEST_F(
281245
TEST_F(TestPublisher, check_type_adapted_message_is_sent_and_received) {
282246
using StringTypeAdapter = rclcpp::TypeAdapter<std::string, rclcpp::msg::String>;
283247

284-
initialize();
248+
auto node = std::make_shared<rclcpp::Node>("my_node", "/ns", rclcpp::NodeOptions());
285249

286250
const std::string message_data = "Message Data";
287251
const std::string topic_name = "topic_name";

rclcpp/test/rclcpp/test_subscription_with_type_adapter.cpp

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,16 @@
1616
#include <gtest/gtest.h>
1717

1818
#include <chrono>
19-
#include <functional>
2019
#include <memory>
2120
#include <string>
2221
#include <thread>
23-
#include <utility>
24-
#include <vector>
2522

2623
#include "rclcpp/exceptions.hpp"
27-
#include "rclcpp/loaned_message.hpp"
2824
#include "rclcpp/rclcpp.hpp"
2925

30-
#include "../mocking_utils/patch.hpp"
31-
#include "../utils/rclcpp_gtest_macros.hpp"
32-
33-
#include "test_msgs/msg/empty.hpp"
3426
#include "rclcpp/msg/string.hpp"
3527

3628

37-
#ifdef RMW_IMPLEMENTATION
38-
# define CLASSNAME_(NAME, SUFFIX) NAME ## __ ## SUFFIX
39-
# define CLASSNAME(NAME, SUFFIX) CLASSNAME_(NAME, SUFFIX)
40-
#else
41-
# define CLASSNAME(NAME, SUFFIX) NAME
42-
#endif
43-
44-
4529
using namespace std::chrono_literals;
4630

4731
static const int g_max_loops = 200;
@@ -50,30 +34,6 @@ static const std::chrono::milliseconds g_sleep_per_loop(10);
5034

5135
class TestSubscription : public ::testing::Test
5236
{
53-
public:
54-
static void SetUpTestCase()
55-
{
56-
if (!rclcpp::ok()) {
57-
rclcpp::init(0, nullptr);
58-
}
59-
}
60-
61-
protected:
62-
void initialize(const rclcpp::NodeOptions & node_options = rclcpp::NodeOptions())
63-
{
64-
node = std::make_shared<rclcpp::Node>("my_node", "/ns", node_options);
65-
}
66-
67-
void TearDown()
68-
{
69-
node.reset();
70-
}
71-
72-
rclcpp::Node::SharedPtr node;
73-
};
74-
75-
class CLASSNAME (test_intra_process_within_one_node, RMW_IMPLEMENTATION) : public ::testing::Test
76-
{
7737
public:
7838
static void SetUpTestCase()
7939
{
@@ -148,7 +108,7 @@ bool wait_for_match(
148108
* Testing publisher creation signatures with a type adapter.
149109
*/
150110
TEST_F(TestSubscription, various_creation_signatures) {
151-
initialize();
111+
auto node = std::make_shared<rclcpp::Node>("my_node", "/ns", rclcpp::NodeOptions());
152112
{
153113
using StringTypeAdapter = rclcpp::TypeAdapter<std::string, rclcpp::msg::String>;
154114
auto sub =
@@ -167,7 +127,7 @@ TEST_F(TestSubscription, various_creation_signatures) {
167127
* Testing that subscriber receives type adapted types and ROS message types with intra proccess communications.
168128
*/
169129
TEST_F(
170-
CLASSNAME(test_intra_process_within_one_node, RMW_IMPLEMENTATION),
130+
TestSubscription,
171131
check_type_adapted_messages_are_received_by_intra_process_subscription) {
172132
using StringTypeAdapter = rclcpp::TypeAdapter<std::string, rclcpp::msg::String>;
173133
const std::string message_data = "Message Data";
@@ -386,7 +346,7 @@ TEST_F(
386346
* Testing that subscriber receives type adapted types and ROS message types with inter proccess communications.
387347
*/
388348
TEST_F(
389-
CLASSNAME(test_intra_process_within_one_node, RMW_IMPLEMENTATION),
349+
TestSubscription,
390350
check_type_adapted_messages_are_received_by_inter_process_subscription) {
391351
using StringTypeAdapter = rclcpp::TypeAdapter<std::string, rclcpp::msg::String>;
392352
const std::string message_data = "Message Data";

0 commit comments

Comments
 (0)