1 #include <gtest/gtest.h> 2 #include <gmock/gmock.h> 7 #include <mbf_msgs/GetPathAction.h> 12 #include <boost/chrono.hpp> 13 #include <boost/thread/thread.hpp> 14 #include <boost/thread/condition.hpp> 23 using geometry_msgs::PoseStamped;
29 MOCK_METHOD6(makePlan, uint32_t(
const PoseStamped&,
const PoseStamped&,
double, std::vector<PoseStamped>&,
double&,
40 using mbf_msgs::GetPathAction;
46 using testing::Return;
47 using testing::SetArgReferee;
57 MockedActionServer(boost::function<
void(GoalHandle)> goal_cb, boost::function<
void(GoalHandle)> cancel_cb)
58 : ActionServerBase(goal_cb, cancel_cb, true)
63 MOCK_METHOD2(publishResult,
void(
const actionlib_msgs::GoalStatus&,
const Result&));
107 mbf_msgs::GetPathActionGoalPtr
goal;
111 , action_name(
"action_name")
113 , global_frame(
"global_frame")
114 , local_frame(
"local_frame")
116 , goal(new mbf_msgs::GetPathActionGoal())
117 , robot_info(*tf, global_frame, local_frame, dur)
118 , planner_action(action_name, robot_info)
122 tf->setUsingDedicatedThread(
true);
123 config.planner_patience = 0;
133 boost::unique_lock<boost::mutex> lock(m);
134 done_condition_.wait_for(lock, boost::chrono::seconds(1));
139 planner_action.start(goal_handle, boost::make_shared<AbstractPlannerExecution>(
"plugin", planner, tf, config));
144 planner_action.cancel(goal_handle);
151 goal->goal.use_start_pose =
true;
152 goal->goal.start_pose.header.frame_id = goal->goal.target_pose.header.frame_id = global_frame;
158 publishResult(_, Field(&mbf_msgs::GetPathResult::outcome, Eq(mbf_msgs::GetPathResult::EMPTY_PATH))))
160 .WillOnce(Notify(&done_condition_));
163 #if !ROS_VERSION_MINIMUM(1, 14, 0) 172 std::vector<geometry_msgs::PoseStamped> path(10);
174 for (
size_t ii = 0; ii != path.size(); ++ii)
176 path[ii].header.frame_id = global_frame;
177 path[ii].pose.orientation.w = 1;
181 goal->goal.use_start_pose =
true;
182 goal->goal.start_pose.header.frame_id = goal->goal.target_pose.header.frame_id = global_frame;
185 EXPECT_CALL(*
planner, makePlan(_, _, _, _, _, _)).WillOnce(DoAll(SetArgReferee<3>(path), Return(0)));
187 publishResult(_, Field(&mbf_msgs::GetPathResult::outcome, Eq(mbf_msgs::GetPathResult::SUCCESS))))
189 .WillOnce(Notify(&done_condition_));
195 std::vector<geometry_msgs::PoseStamped> path(10);
197 for (
size_t ii = 0; ii != path.size(); ++ii)
198 path[ii].
header.frame_id =
"unknown";
201 EXPECT_CALL(*
planner, makePlan(_, _, _, _, _, _)).WillOnce(DoAll(SetArgReferee<3>(path), Return(0)));
203 publishResult(_, Field(&mbf_msgs::GetPathResult::outcome, Eq(mbf_msgs::GetPathResult::TF_ERROR))))
205 .WillOnce(Notify(&done_condition_));
208 goal->goal.use_start_pose =
true;
209 goal->goal.start_pose.header.frame_id = goal->goal.target_pose.header.frame_id = global_frame;
218 goal->goal.use_start_pose =
false;
219 goal->goal.start_pose.header.frame_id = goal->goal.target_pose.header.frame_id = global_frame;
223 publishResult(_, Field(&mbf_msgs::GetPathResult::outcome, Eq(mbf_msgs::GetPathResult::TF_ERROR))))
225 .WillOnce(Notify(&done_condition_));
232 config.planner_max_retries = 0;
235 goal->goal.use_start_pose =
true;
236 goal->goal.start_pose.header.frame_id = goal->goal.target_pose.header.frame_id = global_frame;
239 EXPECT_CALL(*
planner, makePlan(_, _, _, _, _, _)).WillOnce(Return(mbf_msgs::GetPathResult::NO_PATH_FOUND));
241 publishResult(_, Field(&mbf_msgs::GetPathResult::outcome, Eq(mbf_msgs::GetPathResult::NO_PATH_FOUND))))
243 .WillOnce(Notify(&done_condition_));
248 boost::this_thread::sleep_for(boost::chrono::milliseconds(10));
257 config.planner_max_retries = 5;
258 config.planner_patience = 0.001;
261 goal->goal.use_start_pose =
true;
262 goal->goal.start_pose.header.frame_id = goal->goal.target_pose.header.frame_id = global_frame;
267 publishResult(_, Field(&mbf_msgs::GetPathResult::outcome, Eq(mbf_msgs::GetPathResult::PAT_EXCEEDED))))
269 .WillOnce(Notify(&done_condition_));
272 int main(
int argc,
char** argv)
276 testing::InitGoogleTest(&argc, argv);
277 return RUN_ALL_TESTS();
void goalCallback(const boost::shared_ptr< const ActionGoal > &goal)
boost::shared_ptr< MockPlanner > planner
the mocked planner
actionlib::ActionServerBase< GetPathAction > ActionServerBase
MoveBaseFlexConfig config
config for the mbf
int main(int argc, char **argv)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void cancelAction(MockedActionServer::GoalHandle goal_handle)
TEST_F(PlannerActionFixture, emptyPath)
boost::condition_variable done_condition_
cv triggered on makePlan
EXPECT_CALL(action_server, publishResult(_, Field(&mbf_msgs::GetPathResult::outcome, Eq(mbf_msgs::GetPathResult::SUCCESS)))) .Times(1) .WillOnce(Notify(&done_condition_))
MockedActionServer(boost::function< void(GoalHandle)> goal_cb, boost::function< void(GoalHandle)> cancel_cb)
PlannerAction planner_action
EXPECT_CALL * planner(_, _, _, _, _, _)).WillOnce(DoAll(SetArgReferee< 3 >(path), Return(0))
virtual void initialize()
void publishFeedback(const actionlib_msgs::GoalStatus &, const Feedback &)
mbf_utility::RobotInformation robot_info
MockedActionServer action_server
mbf_msgs::GetPathActionGoalPtr goal
The AbstractPlannerExecution class loads and binds the global planner plugin. It contains a thread ru...
mbf_msgs::GetPathResult expected_result
actionlib::ServerGoalHandle< GetPathAction > GoalHandle
void callAction(MockedActionServer::GoalHandle goal_handle)