30 #include <gmock/gmock.h> 33 #include <actionlib/TwoIntsAction.h> 45 const std::chrono::milliseconds
DELAY(250);
56 std::unique_lock<std::mutex> lock(mtx_);
68 for (
size_t i = 0; i <
ATTEMPTS; ++i)
71 std::this_thread::sleep_for(
DELAY);
72 std::unique_lock<std::mutex> lock(mtx_);
78 std::unique_lock<std::mutex> lock(mtx_);
85 bool have_feedback_ =
false;
91 std::unique_lock<std::mutex> lock(mtx_);
92 have_feedback_ =
true;
97 for (
size_t i = 0; i <
ATTEMPTS; ++i)
100 std::this_thread::sleep_for(
DELAY);
101 std::unique_lock<std::mutex> lock(mtx_);
107 std::unique_lock<std::mutex> lock(mtx_);
108 return have_feedback_;
112 std::shared_ptr<TwoIntsActionClient>
114 const std::string & server_name,
117 auto ac = std::make_shared<TwoIntsActionClient>(server_name,
true);
119 for (
size_t i = 0; i <
ATTEMPTS && !ac->isServerConnected(); ++i)
122 std::this_thread::sleep_for(
DELAY);
124 if (!ac->isServerConnected())
128 actionlib::TwoIntsGoal goal;
145 if (ac->getState().isDone())
149 std::this_thread::sleep_for(
DELAY);
154 std::shared_ptr<TwoIntsActionServer>
158 auto as = std::make_shared<TwoIntsActionServer>(
169 const std::string server_name(
"set_aborted");
173 ASSERT_NE(
nullptr, client.get());
177 ASSERT_TRUE(rt_handle.valid());
180 actionlib::TwoIntsResult::Ptr result(
new actionlib::TwoIntsResult);
182 rt_handle.setAborted(result);
187 auto state = client->getState();
189 auto result = client->getResult();
190 ASSERT_NE(
nullptr, result.get());
191 EXPECT_EQ(42, result->sum);
197 const std::string server_name(
"set_canceled");
201 ASSERT_NE(
nullptr, client.get());
205 ASSERT_TRUE(rt_handle.valid());
208 client->cancelGoal();
209 for (
size_t i = 0; i <
ATTEMPTS; ++i)
212 if (gs.status == actionlib_msgs::GoalStatus::PREEMPTING) {
216 std::this_thread::sleep_for(
DELAY);
221 actionlib::TwoIntsResult::Ptr result(
new actionlib::TwoIntsResult);
223 rt_handle.setCanceled(result);
228 auto state = client->getState();
230 auto result = client->getResult();
231 ASSERT_NE(
nullptr, result.get());
232 EXPECT_EQ(1234, result->sum);
238 const std::string server_name(
"set_succeeded");
242 ASSERT_NE(
nullptr, client.get());
246 ASSERT_TRUE(rt_handle.valid());
249 actionlib::TwoIntsResult::Ptr result(
new actionlib::TwoIntsResult);
251 rt_handle.setSucceeded(result);
256 auto state = client->getState();
258 auto result = client->getResult();
259 ASSERT_NE(
nullptr, result.get());
260 EXPECT_EQ(321, result->sum);
267 const std::string server_name(
"send_feedback");
270 auto client =
send_goal(server_name, &client_callbacks);
271 ASSERT_NE(
nullptr, client.get());
275 ASSERT_TRUE(rt_handle.valid());
278 actionlib::TwoIntsFeedback::Ptr fb(
new actionlib::TwoIntsFeedback());
279 rt_handle.setFeedback(fb);
286 int main(
int argc,
char ** argv) {
287 ::testing::InitGoogleTest(&argc, argv);
288 ros::init(argc, argv,
"realtime_server_goal_handle_tests");
289 return RUN_ALL_TESTS();
std::shared_ptr< TwoIntsActionClient > send_goal(const std::string &server_name, FeedbackCallback *cb=nullptr)
ServerGoalHandle< ActionSpec > GoalHandle
bool wait_for_result(std::shared_ptr< TwoIntsActionClient > ac)
void feedback_callback(const FeedbackConstPtr &)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
const std::chrono::milliseconds DELAY(250)
actionlib_msgs::GoalStatus getGoalStatus() const
void cancel_callback(GoalHandle handle)
void setAccepted(const std::string &text=std::string(""))
boost::function< void()> SimpleActiveCallback
std::shared_ptr< TwoIntsActionServer > make_server(const std::string &server_name, ActionCallback &callbacks)
void goal_callback(GoalHandle handle)
TwoIntsActionServer::FeedbackConstPtr FeedbackConstPtr
boost::function< void(const SimpleClientGoalState &state, const ResultConstPtr &result)> SimpleDoneCallback
TEST(RealtimeServerGoalHandle, set_aborted)
int main(int argc, char **argv)
ROSCPP_DECL void spinOnce()