From bf4d589dcb26a9480cb4f03230f312e349a84313 Mon Sep 17 00:00:00 2001 From: Christophe Bedard Date: Wed, 19 Jun 2019 15:46:44 +0200 Subject: [PATCH] Extract test constants --- tracetools_test/src/test_ping.cpp | 10 +++++++--- tracetools_test/src/test_pong.cpp | 10 +++++++--- tracetools_test/src/test_publisher.cpp | 7 +++++-- tracetools_test/src/test_service.cpp | 7 +++++-- tracetools_test/src/test_service_ping.cpp | 10 +++++++--- tracetools_test/src/test_service_pong.cpp | 10 +++++++--- tracetools_test/src/test_subscription.cpp | 7 +++++-- tracetools_test/src/test_timer.cpp | 7 +++++-- 8 files changed, 48 insertions(+), 20 deletions(-) diff --git a/tracetools_test/src/test_ping.cpp b/tracetools_test/src/test_ping.cpp index 90286fb..4f590a9 100644 --- a/tracetools_test/src/test_ping.cpp +++ b/tracetools_test/src/test_ping.cpp @@ -20,18 +20,22 @@ using namespace std::chrono_literals; +#define NODE_NAME "test_ping" +#define SUB_TOPIC_NAME "pong" +#define PUB_TOPIC_NAME "ping" + class PingNode : public rclcpp::Node { public: explicit PingNode(rclcpp::NodeOptions options) - : Node("test_ping", options) + : Node(NODE_NAME, options) { sub_ = this->create_subscription( - "pong", + SUB_TOPIC_NAME, rclcpp::QoS(10), std::bind(&PingNode::callback, this, std::placeholders::_1)); pub_ = this->create_publisher( - "ping", + PUB_TOPIC_NAME, rclcpp::QoS(10)); timer_ = this->create_wall_timer( 500ms, diff --git a/tracetools_test/src/test_pong.cpp b/tracetools_test/src/test_pong.cpp index 9dce655..23e2312 100644 --- a/tracetools_test/src/test_pong.cpp +++ b/tracetools_test/src/test_pong.cpp @@ -17,18 +17,22 @@ #include "rclcpp/rclcpp.hpp" #include "std_msgs/msg/string.hpp" +#define NODE_NAME "test_pong" +#define SUB_TOPIC_NAME "ping" +#define PUB_TOPIC_NAME "pong" + class PongNode : public rclcpp::Node { public: explicit PongNode(rclcpp::NodeOptions options) - : Node("test_pong", options) + : Node(NODE_NAME, options) { sub_ = this->create_subscription( - "ping", + SUB_TOPIC_NAME, rclcpp::QoS(10), std::bind(&PongNode::callback, this, std::placeholders::_1)); pub_ = this->create_publisher( - "pong", + PUB_TOPIC_NAME, rclcpp::QoS(10)); } diff --git a/tracetools_test/src/test_publisher.cpp b/tracetools_test/src/test_publisher.cpp index 6227516..c0d57a7 100644 --- a/tracetools_test/src/test_publisher.cpp +++ b/tracetools_test/src/test_publisher.cpp @@ -17,14 +17,17 @@ #include "rclcpp/rclcpp.hpp" #include "std_msgs/msg/string.hpp" +#define NODE_NAME "test_publisher" +#define TOPIC_NAME "the_topic" + class PubNode : public rclcpp::Node { public: explicit PubNode(rclcpp::NodeOptions options) - : Node("test_publisher", options) + : Node(NODE_NAME, options) { pub_ = this->create_publisher( - "the_topic", + TOPIC_NAME, rclcpp::QoS(10)); } diff --git a/tracetools_test/src/test_service.cpp b/tracetools_test/src/test_service.cpp index aac018e..bd5bc7a 100644 --- a/tracetools_test/src/test_service.cpp +++ b/tracetools_test/src/test_service.cpp @@ -17,14 +17,17 @@ #include "rclcpp/rclcpp.hpp" #include "std_srvs/srv/empty.hpp" +#define NODE_NAME "test_service" +#define SERVICE_NAME "the_service" + class ServiceNode : public rclcpp::Node { public: explicit ServiceNode(rclcpp::NodeOptions options) - : Node("test_service", options) + : Node(NODE_NAME, options) { srv_ = this->create_service( - "the_service", + SERVICE_NAME, std::bind( &ServiceNode::service_callback, this, diff --git a/tracetools_test/src/test_service_ping.cpp b/tracetools_test/src/test_service_ping.cpp index d8b3680..ed06749 100644 --- a/tracetools_test/src/test_service_ping.cpp +++ b/tracetools_test/src/test_service_ping.cpp @@ -20,14 +20,18 @@ using namespace std::chrono_literals; +#define NODE_NAME "test_service_ping" +#define SERVICE_NAME "pong" +#define CLIENT_NAME "ping" + class PingNode : public rclcpp::Node { public: explicit PingNode(rclcpp::NodeOptions options) - : Node("test_service_ping", options) + : Node(NODE_NAME, options) { srv_ = this->create_service( - "pong", + SERVICE_NAME, std::bind( &PingNode::service_callback, this, @@ -35,7 +39,7 @@ public: std::placeholders::_2, std::placeholders::_3)); client_ = this->create_client( - "ping"); + CLIENT_NAME); timer_ = this->create_wall_timer( 500ms, std::bind(&PingNode::timer_callback, this)); diff --git a/tracetools_test/src/test_service_pong.cpp b/tracetools_test/src/test_service_pong.cpp index d1491ea..53ee882 100644 --- a/tracetools_test/src/test_service_pong.cpp +++ b/tracetools_test/src/test_service_pong.cpp @@ -17,21 +17,25 @@ #include "rclcpp/rclcpp.hpp" #include "std_srvs/srv/empty.hpp" +#define NODE_NAME "test_service_pong" +#define SERVICE_NAME "ping" +#define CLIENT_NAME "pong" + class PongNode : public rclcpp::Node { public: explicit PongNode(rclcpp::NodeOptions options) - : Node("test_service_pong", options) + : Node(NODE_NAME, options) { srv_ = this->create_service( - "ping", + SERVICE_NAME, std::bind( &PongNode::service_callback, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); - client_ = this->create_client("pong"); + client_ = this->create_client(CLIENT_NAME); } private: diff --git a/tracetools_test/src/test_subscription.cpp b/tracetools_test/src/test_subscription.cpp index ad3850c..3f3ce82 100644 --- a/tracetools_test/src/test_subscription.cpp +++ b/tracetools_test/src/test_subscription.cpp @@ -17,14 +17,17 @@ #include "rclcpp/rclcpp.hpp" #include "std_msgs/msg/string.hpp" +#define NODE_NAME "test_subscription" +#define TOPIC_NAME "the_topic" + class SubNode : public rclcpp::Node { public: explicit SubNode(rclcpp::NodeOptions options) - : Node("test_subscription", options) + : Node(NODE_NAME, options) { sub_ = this->create_subscription( - "the_topic", + TOPIC_NAME, rclcpp::QoS(10), std::bind(&SubNode::callback, this, std::placeholders::_1)); } diff --git a/tracetools_test/src/test_timer.cpp b/tracetools_test/src/test_timer.cpp index a947d2a..5bfc792 100644 --- a/tracetools_test/src/test_timer.cpp +++ b/tracetools_test/src/test_timer.cpp @@ -19,15 +19,18 @@ using namespace std::chrono_literals; +#define NODE_NAME "test_timer" +#define TIMER_PERIOD 1ms + class TimerNode : public rclcpp::Node { public: explicit TimerNode(rclcpp::NodeOptions options) - : Node("test_timer", options) + : Node(NODE_NAME, options) { is_done_ = false; timer_ = this->create_wall_timer( - 1ms, + TIMER_PERIOD, std::bind(&TimerNode::timer_callback, this)); }