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;
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();