
* Implement action server init, fini, and is_valid functions * Add macros for initializing services and publishers * Implement rcl_action_server_get_default_options() * Implement rcl_action_accept_new_goal() * Add function, rcl_action_server_goal_exists(), for checking if goal is already being tracked by an action server * Add unit tests * Implement rcl_action_server_get_goal_handles() * Implement rcl_action_server_get_options() * Implement rcl_action_server_get_action_name() * Implement rcl_action_get_goal_status_array() * Bugfix: reset pointers and size in type finalize functions Also let finalize functions be called on already finalized objects * Implement send/take functions for action server services * Implement action server publishers for feedback and status * Implement rcl_action_process_cancel_request() * Add partial communication tests * Define UUID_SIZE * Use type-erased pointer for rcl_action_publish_status() * Implement rcl_action_clear_expired_goals() Introduce rcl_clock_t to action server implementation. * Change internal goal handle array to be an array of pointers. * Add check for invalid action names * Do heap allocation of temporary array to satisfy MSVC compiler * Bugfix: finalize node in test tear downs and reset expected errors * Update documentation * Update package.xml * Pass in rcl_clock_t to action server Rather than initializing internally. * Do not finalize goal handles in expire function Instead, leave it up to the caller to finalize goal handles. Renamed the function to rcl_action_expire_goals.
139 lines
4.8 KiB
C++
139 lines
4.8 KiB
C++
// Copyright 2018 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 <gtest/gtest.h>
|
|
|
|
#include <iostream>
|
|
|
|
#include "rcl_action/names.h"
|
|
|
|
#include "rcl/allocator.h"
|
|
#include "rcl/error_handling.h"
|
|
#include "rcl/types.h"
|
|
|
|
struct ActionDerivedNameTestSubject
|
|
{
|
|
const char * action_name;
|
|
const char * expected_action_derived_name;
|
|
rcl_ret_t (* get_action_derived_name)(const char *, rcl_allocator_t, char **);
|
|
const char * subject_name;
|
|
};
|
|
|
|
std::ostream & operator<<(std::ostream & os, const ActionDerivedNameTestSubject & test_subject)
|
|
{
|
|
return os << test_subject.subject_name;
|
|
}
|
|
|
|
class TestActionDerivedName
|
|
: public ::testing::TestWithParam<ActionDerivedNameTestSubject>
|
|
{
|
|
protected:
|
|
void SetUp() override
|
|
{
|
|
test_subject = GetParam();
|
|
}
|
|
|
|
ActionDerivedNameTestSubject test_subject;
|
|
};
|
|
|
|
TEST_P(TestActionDerivedName, validate_action_derived_getter)
|
|
{
|
|
rcl_allocator_t default_allocator = rcl_get_default_allocator();
|
|
|
|
char * action_derived_name = NULL;
|
|
const char * const null_action_name = NULL;
|
|
rcl_ret_t ret = test_subject.get_action_derived_name(
|
|
null_action_name, default_allocator,
|
|
&action_derived_name);
|
|
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret);
|
|
|
|
action_derived_name = NULL;
|
|
const char * const invalid_action_name = "";
|
|
ret = test_subject.get_action_derived_name(
|
|
invalid_action_name, default_allocator,
|
|
&action_derived_name);
|
|
EXPECT_EQ(RCL_RET_ACTION_NAME_INVALID, ret) << rcl_get_error_string().str;
|
|
rcl_reset_error();
|
|
|
|
action_derived_name = NULL;
|
|
rcl_allocator_t invalid_allocator =
|
|
(rcl_allocator_t)rcutils_get_zero_initialized_allocator();
|
|
ret = test_subject.get_action_derived_name(
|
|
test_subject.action_name, invalid_allocator,
|
|
&action_derived_name);
|
|
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret) << rcl_get_error_string().str;
|
|
rcl_reset_error();
|
|
|
|
action_derived_name = NULL;
|
|
char ** invalid_ptr_to_action_derived_name = NULL;
|
|
ret = test_subject.get_action_derived_name(
|
|
test_subject.action_name, default_allocator,
|
|
invalid_ptr_to_action_derived_name);
|
|
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret) << rcl_get_error_string().str;
|
|
rcl_reset_error();
|
|
|
|
char dummy_char = '\0';
|
|
action_derived_name = &dummy_char;
|
|
ret = test_subject.get_action_derived_name(
|
|
test_subject.action_name, default_allocator,
|
|
&action_derived_name);
|
|
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret) << rcl_get_error_string().str;
|
|
rcl_reset_error();
|
|
|
|
action_derived_name = NULL;
|
|
ret = test_subject.get_action_derived_name(
|
|
test_subject.action_name, default_allocator,
|
|
&action_derived_name);
|
|
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
|
EXPECT_STREQ(test_subject.expected_action_derived_name, action_derived_name);
|
|
default_allocator.deallocate(action_derived_name, default_allocator.state);
|
|
}
|
|
|
|
const ActionDerivedNameTestSubject action_service_and_topic_subjects[] = {
|
|
{
|
|
"test_it", // action_name
|
|
"test_it/_action/send_goal", // expected_action_derived_name
|
|
rcl_action_get_goal_service_name, // get_action_derived_name
|
|
"goal_service_name_test" // subject_name
|
|
},
|
|
{
|
|
"test_it", // action_name
|
|
"test_it/_action/cancel_goal", // expected_action_derived_name
|
|
rcl_action_get_cancel_service_name, // get_action_derived_name
|
|
"cancel_service_name_test" // subject_name
|
|
},
|
|
{
|
|
"test_it", // action_name
|
|
"test_it/_action/get_result", // expected_action_derived_name
|
|
rcl_action_get_result_service_name, // get_action_derived_name
|
|
"result_service_name_test" // subject_name
|
|
},
|
|
{
|
|
"test_it", // action_name
|
|
"test_it/_action/feedback", // expected_action_derived_name
|
|
rcl_action_get_feedback_topic_name, // get_action_derived_name
|
|
"feedback_topic_name_test" // subject_name
|
|
},
|
|
{
|
|
"test_it", // action_name
|
|
"test_it/_action/status", // expected_action_derived_name
|
|
rcl_action_get_status_topic_name, // get_action_derived_name
|
|
"status_topic_name_test" // subject_name
|
|
}
|
|
};
|
|
|
|
INSTANTIATE_TEST_CASE_P(
|
|
TestActionServiceAndTopicNames, TestActionDerivedName,
|
|
::testing::ValuesIn(action_service_and_topic_subjects),
|
|
::testing::PrintToStringParamName());
|