|
| 1 | +#include <gtest/gtest.h> |
| 2 | +#include "behaviortree_cpp/bt_factory.h" |
| 3 | +#include "test_helper.hpp" |
| 4 | + |
| 5 | +using BT::NodeStatus; |
| 6 | +using std::chrono::milliseconds; |
| 7 | + |
| 8 | +static const char* reactive_xml_text = R"( |
| 9 | +<root BTCPP_format="4" > |
| 10 | + <BehaviorTree ID="MainTree"> |
| 11 | + <ReactiveSequence> |
| 12 | + <Sequence name="first"> |
| 13 | + <TestA/> |
| 14 | + <TestB/> |
| 15 | + <TestC/> |
| 16 | + </Sequence> |
| 17 | + <AsyncSequence name="second"> |
| 18 | + <TestD/> |
| 19 | + <TestE/> |
| 20 | + <TestF/> |
| 21 | + </AsyncSequence> |
| 22 | + </ReactiveSequence> |
| 23 | + </BehaviorTree> |
| 24 | +</root> |
| 25 | +)"; |
| 26 | + |
| 27 | + |
| 28 | +TEST(Reactive, RunningChildren) |
| 29 | +{ |
| 30 | + BT::BehaviorTreeFactory factory; |
| 31 | + std::array<int, 6> counters; |
| 32 | + RegisterTestTick(factory, "Test", counters); |
| 33 | + |
| 34 | + auto tree = factory.createTreeFromText(reactive_xml_text); |
| 35 | + |
| 36 | + NodeStatus status = NodeStatus::IDLE; |
| 37 | + |
| 38 | + int count=0; |
| 39 | + while(!BT::isStatusCompleted(status) && count<100) |
| 40 | + { |
| 41 | + count++; |
| 42 | + status = tree.tickExactlyOnce(); |
| 43 | + } |
| 44 | + |
| 45 | + ASSERT_NE(100, count); |
| 46 | + |
| 47 | + ASSERT_EQ(status, NodeStatus::SUCCESS); |
| 48 | + |
| 49 | + ASSERT_EQ(counters[0], 3); |
| 50 | + ASSERT_EQ(counters[1], 3); |
| 51 | + ASSERT_EQ(counters[2], 3); |
| 52 | + |
| 53 | + ASSERT_EQ(counters[3], 1); |
| 54 | + ASSERT_EQ(counters[4], 1); |
| 55 | + ASSERT_EQ(counters[5], 1); |
| 56 | +} |
| 57 | + |
| 58 | + |
0 commit comments