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_);
91 std::unique_lock<std::mutex> lock(
mtx_);
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_);
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);
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);
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);
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());
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();