1 #include <gtest/gtest.h>
7 using std::chrono::milliseconds;
9 TEST(Reactive, RunningChildren)
11 static const char* reactive_xml_text = R
"(
12 <root BTCPP_format="4" >
13 <BehaviorTree ID="MainTree">
15 <Sequence name="first">
20 <AsyncSequence name="second">
31 std::array<int, 6> counters;
42 status = tree.tickExactlyOnce();
45 ASSERT_NE(100,
count);
47 ASSERT_EQ(status, NodeStatus::SUCCESS);
49 ASSERT_EQ(counters[0], 3);
50 ASSERT_EQ(counters[1], 3);
51 ASSERT_EQ(counters[2], 3);
53 ASSERT_EQ(counters[3], 1);
54 ASSERT_EQ(counters[4], 1);
55 ASSERT_EQ(counters[5], 1);
62 static const char* reactive_xml_text = R
"(
63 <root BTCPP_format="4" >
64 <BehaviorTree ID="Example A">
66 <Script code="test := false"/>
68 <RetryUntilSuccessful name="Retry 1" num_attempts="-1" _skipIf="test ">
69 <TestA name="Success 1" _onSuccess="test = true"/>
70 </RetryUntilSuccessful>
71 <RetryUntilSuccessful name="Retry 2" num_attempts="5">
72 <AlwaysFailure name="Failure 2"/>
73 </RetryUntilSuccessful>
81 std::array<int, 2> counters;
87 ASSERT_EQ(counters[0], 1);
90 TEST(Reactive, PreTickHooks)
94 static const char* reactive_xml_text = R
"(
95 <root BTCPP_format="4" >
96 <BehaviorTree ID="Main">
98 <AlwaysFailure name="failureA"/>
99 <AlwaysFailure name="failureB"/>
111 std::cout << node.name() <<
" callback" << std::endl;
115 tree.applyVisitor([&](
TreeNode* node) ->
void {
122 auto ret = tree.tickWhileRunning();
130 static const char* reactive_xml_text = R
"(
131 <root BTCPP_format="4" >
132 <BehaviorTree ID="Main">
134 <TestA name="testA"/>
135 <AlwaysSuccess name="success"/>
144 std::array<int, 1> counters;
150 auto ret = tree.tickWhileRunning();
153 int num_ticks = counters[0];
154 ASSERT_GE(num_ticks, 5);
160 TEST(Reactive, TwoAsyncNodesInReactiveSequence)
162 static const char* reactive_xml_text = R
"(
163 <root BTCPP_format="4" >
164 <BehaviorTree ID="MainTree">
166 <AsyncSequence name="first">
171 <AsyncSequence name="second">
182 std::array<int, 6> counters;