Skip to content

Commit

Permalink
Use new test interface definitions
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Perron <jacob@openrobotics.org>
  • Loading branch information
jacobperron committed May 1, 2019
1 parent 4f07417 commit fcb55a9
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 108 deletions.
22 changes: 11 additions & 11 deletions rcl/test/rcl/client_fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "rcl/client.h"
#include "rcl/rcl.h"

#include "test_msgs/srv/primitives.h"
#include "test_msgs/srv/basic_types.h"

#include "osrf_testing_tools_cpp/scope_exit.hpp"
#include "rcl/error_handling.h"
Expand Down Expand Up @@ -153,8 +153,8 @@ int main(int argc, char ** argv)
});

const rosidl_service_type_support_t * ts = ROSIDL_GET_SRV_TYPE_SUPPORT(
test_msgs, srv, Primitives);
const char * service_name = "primitives";
test_msgs, srv, BasicTypes);
const char * service_name = "basic_types";

rcl_client_t client = rcl_get_zero_initialized_client();
rcl_client_options_t client_options = rcl_client_get_default_options();
Expand All @@ -180,11 +180,11 @@ int main(int argc, char ** argv)
}

// Initialize a request.
test_msgs__srv__Primitives_Request client_request;
test_msgs__srv__BasicTypes_Request client_request;
// TODO(dirk-thomas) zero initialization necessary until
// https://github.com/ros2/ros2/issues/397 is implemented
memset(&client_request, 0, sizeof(test_msgs__srv__Primitives_Request));
test_msgs__srv__Primitives_Request__init(&client_request);
memset(&client_request, 0, sizeof(test_msgs__srv__BasicTypes_Request));
test_msgs__srv__BasicTypes_Request__init(&client_request);
client_request.uint8_value = 1;
client_request.uint32_value = 2;
int64_t sequence_number;
Expand All @@ -200,14 +200,14 @@ int main(int argc, char ** argv)
return -1;
}

test_msgs__srv__Primitives_Request__fini(&client_request);
test_msgs__srv__BasicTypes_Request__fini(&client_request);

// Initialize the response owned by the client and take the response.
test_msgs__srv__Primitives_Response client_response;
test_msgs__srv__BasicTypes_Response client_response;
// TODO(dirk-thomas) zero initialization necessary until
// https://github.com/ros2/ros2/issues/397 is implemented
memset(&client_response, 0, sizeof(test_msgs__srv__Primitives_Response));
test_msgs__srv__Primitives_Response__init(&client_response);
memset(&client_response, 0, sizeof(test_msgs__srv__BasicTypes_Response));
test_msgs__srv__BasicTypes_Response__init(&client_response);

if (!wait_for_client_to_be_ready(&client, &context, 1000, 100)) {
RCUTILS_LOG_ERROR_NAMED(ROS_PACKAGE_NAME, "Client never became ready");
Expand All @@ -220,7 +220,7 @@ int main(int argc, char ** argv)
return -1;
}

test_msgs__srv__Primitives_Response__fini(&client_response);
test_msgs__srv__BasicTypes_Response__fini(&client_response);
}

return main_ret;
Expand Down
22 changes: 11 additions & 11 deletions rcl/test/rcl/service_fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#include "rcl/rcl.h"

#include "test_msgs/srv/primitives.h"
#include "test_msgs/srv/basic_types.h"

#include "osrf_testing_tools_cpp/scope_exit.hpp"
#include "rcl/error_handling.h"
Expand Down Expand Up @@ -126,8 +126,8 @@ int main(int argc, char ** argv)
});

const rosidl_service_type_support_t * ts = ROSIDL_GET_SRV_TYPE_SUPPORT(
test_msgs, srv, Primitives);
const char * service_name = "primitives";
test_msgs, srv, BasicTypes);
const char * service_name = "basic_types";

rcl_service_t service = rcl_get_zero_initialized_service();
rcl_service_options_t service_options = rcl_service_get_default_options();
Expand All @@ -147,13 +147,13 @@ int main(int argc, char ** argv)
});

// Initialize a response.
test_msgs__srv__Primitives_Response service_response;
test_msgs__srv__BasicTypes_Response service_response;
// TODO(dirk-thomas) zero initialization necessary until
// https://github.com/ros2/ros2/issues/397 is implemented
memset(&service_response, 0, sizeof(test_msgs__srv__Primitives_Response));
test_msgs__srv__Primitives_Response__init(&service_response);
memset(&service_response, 0, sizeof(test_msgs__srv__BasicTypes_Response));
test_msgs__srv__BasicTypes_Response__init(&service_response);
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({
test_msgs__srv__Primitives_Response__fini(&service_response);
test_msgs__srv__BasicTypes_Response__fini(&service_response);
});

// Block until a client request comes in.
Expand All @@ -164,13 +164,13 @@ int main(int argc, char ** argv)
}

// Take the pending request.
test_msgs__srv__Primitives_Request service_request;
test_msgs__srv__BasicTypes_Request service_request;
// TODO(dirk-thomas) zero initialization necessary until
// https://github.com/ros2/ros2/issues/397 is implemented
memset(&service_request, 0, sizeof(test_msgs__srv__Primitives_Request));
test_msgs__srv__Primitives_Request__init(&service_request);
memset(&service_request, 0, sizeof(test_msgs__srv__BasicTypes_Request));
test_msgs__srv__BasicTypes_Request__init(&service_request);
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({
test_msgs__srv__Primitives_Request__fini(&service_request);
test_msgs__srv__BasicTypes_Request__fini(&service_request);
});
rmw_request_id_t header;
// TODO(jacquelinekay) May have to check for timeout error codes
Expand Down
11 changes: 5 additions & 6 deletions rcl/test/rcl/test_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

#include "rcl/rcl.h"

#include "rosidl_generator_c/string_functions.h"
#include "test_msgs/srv/primitives.h"
#include "test_msgs/srv/basic_types.h"

#include "./failing_allocator_functions.hpp"
#include "osrf_testing_tools_cpp/scope_exit.hpp"
Expand Down Expand Up @@ -76,7 +75,7 @@ TEST_F(TestClientFixture, test_client_nominal) {
rcl_client_options_t client_options = rcl_client_get_default_options();

const rosidl_service_type_support_t * ts = ROSIDL_GET_SRV_TYPE_SUPPORT(
test_msgs, srv, Primitives);
test_msgs, srv, BasicTypes);
ret = rcl_client_init(&client, this->node_ptr, ts, topic_name, &client_options);

// Check the return code of initialization and that the service name matches what's expected
Expand All @@ -89,8 +88,8 @@ TEST_F(TestClientFixture, test_client_nominal) {
});

// Initialize the client request.
test_msgs__srv__Primitives_Request req;
test_msgs__srv__Primitives_Request__init(&req);
test_msgs__srv__BasicTypes_Request req;
test_msgs__srv__BasicTypes_Request__init(&req);
req.uint8_value = 1;
req.uint32_value = 2;

Expand All @@ -110,7 +109,7 @@ TEST_F(TestClientFixture, test_client_init_fini) {
rcl_client_t client;

const rosidl_service_type_support_t * ts = ROSIDL_GET_SRV_TYPE_SUPPORT(
test_msgs, srv, Primitives);
test_msgs, srv, BasicTypes);
const char * topic_name = "chatter";
rcl_client_options_t default_client_options = rcl_client_get_default_options();

Expand Down
8 changes: 4 additions & 4 deletions rcl/test/rcl/test_count_matched.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

#include "rcutils/logging_macros.h"

#include "test_msgs/msg/primitives.h"
#include "test_msgs/srv/primitives.h"
#include "test_msgs/msg/basic_types.h"
#include "test_msgs/srv/basic_types.h"

#include "rcl/error_handling.h"

Expand Down Expand Up @@ -152,7 +152,7 @@ TEST_F(CLASSNAME(TestCountFixture, RMW_IMPLEMENTATION), test_count_matched_funct

rcl_publisher_t pub = rcl_get_zero_initialized_publisher();
rcl_publisher_options_t pub_ops = rcl_publisher_get_default_options();
auto ts = ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, Primitives);
auto ts = ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, BasicTypes);
ret = rcl_publisher_init(&pub, this->node_ptr, ts, topic_name.c_str(), &pub_ops);
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
rcl_reset_error();
Expand Down Expand Up @@ -202,7 +202,7 @@ TEST_F(CLASSNAME(TestCountFixture, RMW_IMPLEMENTATION),
pub_ops.qos.avoid_ros_namespace_conventions = false;
pub_ops.allocator = rcl_get_default_allocator();

auto ts = ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, Primitives);
auto ts = ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, BasicTypes);
ret = rcl_publisher_init(&pub, this->node_ptr, ts, topic_name.c_str(), &pub_ops);
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
rcl_reset_error();
Expand Down
6 changes: 3 additions & 3 deletions rcl/test/rcl/test_get_actual_qos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#include "rcutils/logging_macros.h"
#include "rcutils/macros.h"

#include "test_msgs/msg/primitives.h"
#include "test_msgs/srv/primitives.h"
#include "test_msgs/msg/basic_types.h"
#include "test_msgs/srv/basic_types.h"

#ifdef RMW_IMPLEMENTATION
# define CLASSNAME_(NAME, SUFFIX) NAME ## __ ## SUFFIX
Expand Down Expand Up @@ -116,7 +116,7 @@ TEST_P_RMW(TestGetActualQoS, test_publisher_get_qos_settings) {
rcl_publisher_t pub = rcl_get_zero_initialized_publisher();
rcl_publisher_options_t pub_ops = rcl_publisher_get_default_options();
pub_ops.qos = parameters.qos_to_set;
auto ts = ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, Primitives);
auto ts = ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, BasicTypes);
ret = rcl_publisher_init(&pub, this->node_ptr, ts, topic_name.c_str(), &pub_ops);
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
rcl_reset_error();
Expand Down
18 changes: 9 additions & 9 deletions rcl/test/rcl/test_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
#include "rcutils/logging_macros.h"
#include "rcutils/logging.h"

#include "test_msgs/msg/primitives.h"
#include "test_msgs/srv/primitives.h"
#include "test_msgs/msg/basic_types.h"
#include "test_msgs/srv/basic_types.h"

#include "osrf_testing_tools_cpp/scope_exit.hpp"

Expand Down Expand Up @@ -899,7 +899,7 @@ class NodeGraphMultiNodeFixture : public CLASSNAME(TestGraphFixture, RMW_IMPLEME
TEST_F(NodeGraphMultiNodeFixture, test_node_info_subscriptions)
{
rcl_ret_t ret;
auto ts = ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, Primitives);
auto ts = ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, BasicTypes);
// Create two subscribers.
rcl_subscription_t sub = rcl_get_zero_initialized_subscription();
rcl_subscription_options_t sub_ops = rcl_subscription_get_default_options();
Expand Down Expand Up @@ -935,7 +935,7 @@ TEST_F(NodeGraphMultiNodeFixture, test_node_info_publishers)
// Now create a publisher on "topic_name" and check that it is seen.
rcl_publisher_t pub = rcl_get_zero_initialized_publisher();
rcl_publisher_options_t pub_ops = rcl_publisher_get_default_options();
auto ts = ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, Primitives);
auto ts = ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, BasicTypes);
ret = rcl_publisher_init(&pub, this->node_ptr, ts, this->topic_name.c_str(), &pub_ops);
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
rcl_reset_error();
Expand All @@ -955,7 +955,7 @@ TEST_F(NodeGraphMultiNodeFixture, test_node_info_services)
const char * service_name = "test_service";
rcl_service_t service = rcl_get_zero_initialized_service();
rcl_service_options_t service_options = rcl_service_get_default_options();
auto ts1 = ROSIDL_GET_SRV_TYPE_SUPPORT(test_msgs, srv, Primitives);
auto ts1 = ROSIDL_GET_SRV_TYPE_SUPPORT(test_msgs, srv, BasicTypes);
ret = rcl_service_init(&service, this->node_ptr, ts1, service_name, &service_options);
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
VerifySubsystemCount(expected_node_state{1, 0, 1}, expected_node_state{1, 0, 0});
Expand Down Expand Up @@ -991,7 +991,7 @@ TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), test_graph_query_functio
// Now create a publisher on "topic_name" and check that it is seen.
rcl_publisher_t pub = rcl_get_zero_initialized_publisher();
rcl_publisher_options_t pub_ops = rcl_publisher_get_default_options();
auto ts = ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, Primitives);
auto ts = ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, BasicTypes);
ret = rcl_publisher_init(&pub, this->node_ptr, ts, topic_name.c_str(), &pub_ops);
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
rcl_reset_error();
Expand Down Expand Up @@ -1068,7 +1068,7 @@ TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), test_graph_guard_conditi
rcl_publisher_t pub = rcl_get_zero_initialized_publisher();
rcl_publisher_options_t pub_ops = rcl_publisher_get_default_options();
rcl_ret_t ret = rcl_publisher_init(
&pub, this->node_ptr, ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, Primitives),
&pub, this->node_ptr, ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, BasicTypes),
"/chatter_test_graph_guard_condition_topics", &pub_ops);
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
// sleep
Expand All @@ -1077,7 +1077,7 @@ TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), test_graph_guard_conditi
rcl_subscription_t sub = rcl_get_zero_initialized_subscription();
rcl_subscription_options_t sub_ops = rcl_subscription_get_default_options();
ret = rcl_subscription_init(
&sub, this->node_ptr, ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, Primitives),
&sub, this->node_ptr, ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, BasicTypes),
"/chatter_test_graph_guard_condition_topics", &sub_ops);
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
// sleep
Expand Down Expand Up @@ -1127,7 +1127,7 @@ TEST_F(CLASSNAME(TestGraphFixture, RMW_IMPLEMENTATION), test_rcl_service_server_
rcl_ret_t ret;
// First create a client which will be used to call the function.
rcl_client_t client = rcl_get_zero_initialized_client();
auto ts = ROSIDL_GET_SRV_TYPE_SUPPORT(test_msgs, srv, Primitives);
auto ts = ROSIDL_GET_SRV_TYPE_SUPPORT(test_msgs, srv, BasicTypes);
const char * service_name = "/service_test_rcl_service_server_is_available";
rcl_client_options_t client_options = rcl_client_get_default_options();
ret = rcl_client_init(&client, this->node_ptr, ts, service_name, &client_options);
Expand Down
35 changes: 18 additions & 17 deletions rcl/test/rcl/test_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
#include "rcl/publisher.h"

#include "rcl/rcl.h"
#include "test_msgs/msg/primitives.h"
#include "test_msgs/msg/basic_types.h"
#include "test_msgs/msg/strings.h"
#include "rosidl_generator_c/string_functions.h"

#include "./failing_allocator_functions.hpp"
Expand Down Expand Up @@ -78,7 +79,7 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_nomin
rcl_ret_t ret;
rcl_publisher_t publisher = rcl_get_zero_initialized_publisher();
const rosidl_message_type_support_t * ts =
ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, Primitives);
ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, BasicTypes);
const char * topic_name = "chatter";
const char * expected_topic_name = "/chatter";
rcl_publisher_options_t publisher_options = rcl_publisher_get_default_options();
Expand All @@ -89,11 +90,11 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_nomin
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
});
EXPECT_EQ(strcmp(rcl_publisher_get_topic_name(&publisher), expected_topic_name), 0);
test_msgs__msg__Primitives msg;
test_msgs__msg__Primitives__init(&msg);
test_msgs__msg__BasicTypes msg;
test_msgs__msg__BasicTypes__init(&msg);
msg.int64_value = 42;
ret = rcl_publish(&publisher, &msg);
test_msgs__msg__Primitives__fini(&msg);
test_msgs__msg__BasicTypes__fini(&msg);
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
}

Expand All @@ -103,7 +104,7 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_nomin
rcl_ret_t ret;
rcl_publisher_t publisher = rcl_get_zero_initialized_publisher();
const rosidl_message_type_support_t * ts =
ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, Primitives);
ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, Strings);
const char * topic_name = "chatter";
rcl_publisher_options_t publisher_options = rcl_publisher_get_default_options();
ret = rcl_publisher_init(&publisher, this->node_ptr, ts, topic_name, &publisher_options);
Expand All @@ -112,11 +113,11 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_nomin
rcl_ret_t ret = rcl_publisher_fini(&publisher, this->node_ptr);
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
});
test_msgs__msg__Primitives msg;
test_msgs__msg__Primitives__init(&msg);
test_msgs__msg__Strings msg;
test_msgs__msg__Strings__init(&msg);
ASSERT_TRUE(rosidl_generator_c__String__assign(&msg.string_value, "testing"));
ret = rcl_publish(&publisher, &msg);
test_msgs__msg__Primitives__fini(&msg);
test_msgs__msg__Strings__fini(&msg);
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
}

Expand All @@ -130,7 +131,7 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publishers_diff
rcl_ret_t ret;
rcl_publisher_t publisher = rcl_get_zero_initialized_publisher();
const rosidl_message_type_support_t * ts_int =
ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, Primitives);
ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, BasicTypes);
const char * topic_name = "basename";
const char * expected_topic_name = "/basename";
rcl_publisher_options_t publisher_options = rcl_publisher_get_default_options();
Expand All @@ -144,7 +145,7 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publishers_diff

rcl_publisher_t publisher_in_namespace = rcl_get_zero_initialized_publisher();
const rosidl_message_type_support_t * ts_string = ROSIDL_GET_MSG_TYPE_SUPPORT(
test_msgs, msg, Primitives);
test_msgs, msg, Strings);
topic_name = "namespace/basename";
expected_topic_name = "/namespace/basename";
ret = rcl_publisher_init(
Expand All @@ -156,15 +157,15 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publishers_diff
});
EXPECT_EQ(strcmp(rcl_publisher_get_topic_name(&publisher_in_namespace), expected_topic_name), 0);

test_msgs__msg__Primitives msg_int;
test_msgs__msg__Primitives__init(&msg_int);
test_msgs__msg__BasicTypes msg_int;
test_msgs__msg__BasicTypes__init(&msg_int);
msg_int.int64_value = 42;
ret = rcl_publish(&publisher, &msg_int);
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
test_msgs__msg__Primitives__fini(&msg_int);
test_msgs__msg__BasicTypes__fini(&msg_int);

test_msgs__msg__Primitives msg_string;
test_msgs__msg__Primitives__init(&msg_string);
test_msgs__msg__Strings msg_string;
test_msgs__msg__Strings__init(&msg_string);
ASSERT_TRUE(rosidl_generator_c__String__assign(&msg_string.string_value, "testing"));
ret = rcl_publish(&publisher_in_namespace, &msg_string);
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
Expand All @@ -177,7 +178,7 @@ TEST_F(CLASSNAME(TestPublisherFixture, RMW_IMPLEMENTATION), test_publisher_init_
// Setup valid inputs.
rcl_publisher_t publisher;
const rosidl_message_type_support_t * ts =
ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, Primitives);
ROSIDL_GET_MSG_TYPE_SUPPORT(test_msgs, msg, BasicTypes);
const char * topic_name = "chatter";
rcl_publisher_options_t default_publisher_options = rcl_publisher_get_default_options();

Expand Down
Loading

0 comments on commit fcb55a9

Please sign in to comment.