1 #include <gtest/gtest.h>
10 TEST(SkippingLogic, Sequence)
13 std::array<int, 2> counters;
18 <root BTCPP_format="4" >
19 <BehaviorTree ID="MainTree">
21 <Script code = "A:=1"/>
22 <TestA _successIf="A==2" _failureIf="A!=1" _skipIf="A==1"/>
31 ASSERT_EQ(counters[0], 0);
32 ASSERT_EQ(counters[1], 1);
35 TEST(SkippingLogic, SkipAll)
38 std::array<int, 3> counters;
43 <root BTCPP_format="4" >
44 <BehaviorTree ID="MainTree">
46 <TestA _skipIf="A==1"/>
47 <TestB _skipIf="A<2"/>
48 <TestC _skipIf="A>0"/>
56 const auto status = tree.tickWhileRunning();
57 ASSERT_EQ(counters[0], 0);
58 ASSERT_EQ(counters[1], 0);
59 ASSERT_EQ(counters[2], 0);
63 TEST(SkippingLogic, SkipSubtree)
66 std::array<int, 3> counters;
71 <root BTCPP_format="4" >
72 <BehaviorTree ID="main">
75 <Script code=" data:=true "/>
76 <SubTree ID="sub" _skipIf="data"/>
80 <BehaviorTree ID="sub">
90 const auto status = tree.tickWhileRunning();
91 ASSERT_EQ(counters[0], 1);
92 ASSERT_EQ(counters[1], 0);
96 TEST(SkippingLogic, ReactiveSingleChild)
99 <root BTCPP_format="4">
100 <BehaviorTree ID="Untitled">
102 <AlwaysSuccess _skipIf="flag"/>
110 root_blackboard->set<
bool>(
"flag",
true);
117 TEST(SkippingLogic, SkippingReactiveSequence)
120 std::array<int, 2> counters;
123 const std::string xml_text_noskip = R
"(
124 <root BTCPP_format="4" >
127 <Script code=" value:=50 "/>
128 <TestA _skipIf="value < 25"/>
134 const std::string xml_text_skip = R
"(
135 <root BTCPP_format="4" >
138 <Script code=" value:=10 "/>
139 <TestB _skipIf="value < 25"/>
147 int expected_test_A_ticks = 0;
149 for(
auto const*
xml_text : { &xml_text_noskip, &xml_text_skip })
158 status = tree.tickOnce();
162 expected_test_A_ticks++;
165 tree.sleep(std::chrono::milliseconds{ 15 });
171 ASSERT_EQ(counters[0], expected_test_A_ticks);
174 ASSERT_EQ(counters[1], 0);
180 std::array<int, 2> counters;
183 const std::string xml_text_noskip = R
"(
184 <root BTCPP_format="4" >
187 <Script code=" doit:=true "/>
189 <TestA _while="doit"/>
195 const std::string xml_text_skip = R
"(
196 <root BTCPP_format="4" >
199 <Script code=" doit:=false "/>
201 <TestB _while="doit"/>
207 for(
auto const*
xml_text : { &xml_text_noskip, &xml_text_skip })
214 ASSERT_EQ(counters[0], 1);
217 ASSERT_EQ(counters[1], 0);