13 #include <gtest/gtest.h> 19 using std::chrono::milliseconds;
29 , action(
"action", milliseconds(100))
30 , condition(
"condition")
52 , action_1(
"action_1", milliseconds(100))
53 , condition_1(
"condition_1")
54 , condition_2(
"condition_2")
55 , seq_conditions(
"sequence_conditions")
59 seq_conditions.
addChild(&condition_1);
60 seq_conditions.
addChild(&condition_2);
79 : root(
"root_sequence")
80 , condition(
"condition")
81 , action_1(
"action_1", milliseconds(100))
82 , action_2(
"action_2")
83 , action_3(
"action_3", milliseconds(100))
108 : root(
"root_sequence")
109 , action_1(
"action_1", milliseconds(100))
110 , action_2(
"action_2", milliseconds(100))
111 , seq_1(
"sequence_1")
112 , seq_2(
"sequence_2")
113 , condition_1(
"condition_1")
114 , condition_2(
"condition_2")
140 root(
"root_sequence")
141 , action(
"action", milliseconds(100))
142 , condition(
"condition")
167 : root(
"root_sequence")
168 , action_1(
"action_1", milliseconds(100))
169 , action_2(
"action_2", milliseconds(100))
170 , condition_1(
"condition_1")
171 , condition_2(
"condition_2")
172 , seq_conditions(
"sequence_conditions")
173 , seq_actions(
"sequence_actions")
177 seq_conditions.
addChild(&condition_1);
178 seq_conditions.
addChild(&condition_2);
202 : root(
"root_parallel", 4)
203 , action_1(
"action_1", milliseconds(100))
204 , condition_1(
"condition_1")
205 , action_2(
"action_2", milliseconds(100))
206 , condition_2(
"condition_2")
223 std::cout <<
"Ticking the root node !" << std::endl << std::endl;
228 ASSERT_EQ(NodeStatus::RUNNING, state);
237 ASSERT_EQ(NodeStatus::FAILURE, state);
246 ASSERT_EQ(NodeStatus::RUNNING, state);
247 ASSERT_EQ(NodeStatus::SUCCESS, seq_conditions.status());
248 ASSERT_EQ(NodeStatus::IDLE, condition_1.status());
249 ASSERT_EQ(NodeStatus::IDLE, condition_1.status());
250 ASSERT_EQ(NodeStatus::RUNNING, action_1.status());
257 const auto timeout = system_clock::now() + milliseconds(650);
259 action_1.setTime( milliseconds(300) );
260 action_3.setTime( milliseconds(300) );
266 ASSERT_EQ(NodeStatus::RUNNING, state);
267 ASSERT_EQ(NodeStatus::RUNNING, action_1.status());
268 ASSERT_EQ(NodeStatus::IDLE, action_2.status());
269 ASSERT_EQ(NodeStatus::IDLE, action_3.status());
272 while (state != NodeStatus::SUCCESS && system_clock::now() < timeout)
274 std::this_thread::sleep_for(milliseconds(10));
278 ASSERT_EQ(NodeStatus::SUCCESS, state);
283 ASSERT_EQ(action_1.tickCount(), 1);
284 ASSERT_EQ(action_2.tickCount(), 1);
285 ASSERT_EQ(action_3.tickCount(), 1);
287 ASSERT_EQ(NodeStatus::IDLE, action_1.status());
288 ASSERT_EQ(NodeStatus::IDLE, action_2.status());
289 ASSERT_EQ(NodeStatus::IDLE, action_3.status());
290 ASSERT_TRUE(system_clock::now() < timeout);
299 ASSERT_EQ(NodeStatus::RUNNING, state);
300 ASSERT_EQ(NodeStatus::RUNNING, seq_1.status());
301 ASSERT_EQ(NodeStatus::SUCCESS, condition_1.status());
302 ASSERT_EQ(NodeStatus::RUNNING, action_1.status());
303 ASSERT_EQ(NodeStatus::IDLE, seq_2.status());
304 ASSERT_EQ(NodeStatus::IDLE, condition_2.status());
305 ASSERT_EQ(NodeStatus::IDLE, action_2.status());
307 std::this_thread::sleep_for(milliseconds(300));
310 ASSERT_EQ(NodeStatus::RUNNING, state);
311 ASSERT_EQ(NodeStatus::SUCCESS, seq_1.status());
312 ASSERT_EQ(NodeStatus::IDLE, condition_1.status());
313 ASSERT_EQ(NodeStatus::IDLE, action_1.status());
314 ASSERT_EQ(NodeStatus::RUNNING, seq_2.status());
315 ASSERT_EQ(NodeStatus::SUCCESS, condition_2.status());
316 ASSERT_EQ(NodeStatus::RUNNING, action_2.status());
325 condition_1.setExpectedResult(NodeStatus::FAILURE);
329 ASSERT_EQ(NodeStatus::FAILURE, state);
330 ASSERT_EQ(NodeStatus::IDLE, seq_conditions.status());
331 ASSERT_EQ(NodeStatus::IDLE, condition_1.status());
332 ASSERT_EQ(NodeStatus::IDLE, condition_2.status());
333 ASSERT_EQ(NodeStatus::IDLE, action_1.status());
340 condition_2.setExpectedResult(NodeStatus::FAILURE);
344 ASSERT_EQ(NodeStatus::FAILURE, state);
345 ASSERT_EQ(NodeStatus::IDLE, seq_conditions.status());
346 ASSERT_EQ(NodeStatus::IDLE, condition_1.status());
347 ASSERT_EQ(NodeStatus::IDLE, condition_2.status());
348 ASSERT_EQ(NodeStatus::IDLE, action_1.status());
354 std::this_thread::sleep_for( milliseconds(50) );
356 ASSERT_EQ(NodeStatus::RUNNING, state);
365 ASSERT_EQ(NodeStatus::RUNNING, state);
372 ASSERT_EQ(NodeStatus::RUNNING, state);
381 ASSERT_EQ(NodeStatus::RUNNING, state);
382 ASSERT_EQ(NodeStatus::SUCCESS, seq_conditions.status());
383 ASSERT_EQ(NodeStatus::IDLE, condition_1.status());
384 ASSERT_EQ(NodeStatus::IDLE, condition_2.status());
385 ASSERT_EQ(NodeStatus::RUNNING, seq_actions.status());
386 ASSERT_EQ(NodeStatus::RUNNING, action_1.status());
387 ASSERT_EQ(NodeStatus::IDLE, action_2.status());
394 condition_1.setExpectedResult(NodeStatus::FAILURE);
398 ASSERT_EQ(NodeStatus::RUNNING, state);
399 ASSERT_EQ(NodeStatus::SUCCESS, seq_conditions.status());
400 ASSERT_EQ(NodeStatus::IDLE, condition_1.status());
401 ASSERT_EQ(NodeStatus::IDLE, condition_2.status());
402 ASSERT_EQ(NodeStatus::RUNNING, seq_actions.status());
403 ASSERT_EQ(NodeStatus::RUNNING, action_1.status());
404 ASSERT_EQ(NodeStatus::IDLE, action_2.status());
411 condition_2.setExpectedResult(NodeStatus::FAILURE);
415 ASSERT_EQ(NodeStatus::RUNNING, state);
416 ASSERT_EQ(NodeStatus::SUCCESS, seq_conditions.status());
417 ASSERT_EQ(NodeStatus::IDLE, condition_1.status());
418 ASSERT_EQ(NodeStatus::IDLE, condition_2.status());
419 ASSERT_EQ(NodeStatus::RUNNING, seq_actions.status());
420 ASSERT_EQ(NodeStatus::RUNNING, action_1.status());
421 ASSERT_EQ(NodeStatus::IDLE, action_2.status());
428 condition_2.setExpectedResult(NodeStatus::FAILURE);
433 ASSERT_EQ(NodeStatus::SUCCESS, seq_conditions.status());
434 ASSERT_EQ(NodeStatus::IDLE, condition_1.status());
435 ASSERT_EQ(NodeStatus::IDLE, condition_2.status());
436 ASSERT_EQ(NodeStatus::RUNNING, seq_actions.status());
437 ASSERT_EQ(NodeStatus::RUNNING, action_1.status());
438 ASSERT_EQ(NodeStatus::IDLE, action_2.status());
440 std::this_thread::sleep_for(milliseconds(150));
443 ASSERT_EQ(NodeStatus::SUCCESS, seq_conditions.status());
444 ASSERT_EQ(NodeStatus::IDLE, condition_1.status());
445 ASSERT_EQ(NodeStatus::IDLE, condition_2.status());
446 ASSERT_EQ(NodeStatus::RUNNING, seq_actions.status());
447 ASSERT_EQ(NodeStatus::SUCCESS, action_1.status());
448 ASSERT_EQ(NodeStatus::RUNNING, action_2.status());
450 std::this_thread::sleep_for(milliseconds(150));
453 ASSERT_EQ(NodeStatus::SUCCESS,
root.
status());
454 ASSERT_EQ(NodeStatus::IDLE, seq_conditions.status());
455 ASSERT_EQ(NodeStatus::IDLE, condition_1.status());
456 ASSERT_EQ(NodeStatus::IDLE, condition_2.status());
457 ASSERT_EQ(NodeStatus::IDLE, seq_actions.status());
458 ASSERT_EQ(NodeStatus::IDLE, action_1.status());
459 ASSERT_EQ(NodeStatus::IDLE, action_2.status());
~SequenceTripleActionTest()
BT::ConditionTestNode condition_1
BT::AsyncActionTest action_2
The SequenceStarNode is used to tick children in an ordered sequence. If any child returns RUNNING...
BT::ConditionTestNode condition_1
SequenceTripleActionTest()
BT::ConditionTestNode condition_2
BT::SequenceStarNode seq_conditions
BT::ConditionTestNode condition_1
TEST_F(SimpleSequenceTest, ConditionTrue)
BT::SequenceStarNode root
BT::AsyncActionTest action_1
~ComplexSequenceWithMemoryTest()
SimpleSequenceWithMemoryTest()
BT::ConditionTestNode condition_2
BT::AsyncActionTest action
BT::AsyncActionTest action
void setExpectedResult(NodeStatus res)
ComplexSequence2ActionsTest()
BT::AsyncActionTest action_1
BT::ReactiveSequence root
BT::ConditionTestNode condition
BT::SequenceStarNode seq_actions
BT::SyncActionTest action_2
BT::ConditionTestNode condition_2
BT::AsyncActionTest action_3
void addChild(TreeNode *child)
The method used to add nodes to the children vector.
BT::SequenceNode seq_conditions
BT::ConditionTestNode condition
BT::ConditionTestNode condition
NodeStatus status() const
BT::AsyncActionTest action_1
BT::AsyncActionTest action_2
~ComplexSequence2ActionsTest()
ComplexSequenceWithMemoryTest()
The ReactiveSequence is similar to a ParallelNode. All the children are ticked from first to last: ...
BT::SequenceStarNode root
virtual BT::NodeStatus executeTick()
The method that should be used to invoke tick() and setStatus();.
~SimpleSequenceWithMemoryTest()
The SequenceNode is used to tick children in an ordered sequence. If any child returns RUNNING...
BT::AsyncActionTest action_1