Skip to content

Commit ab6f4a6

Browse files
committed
Propagate skipped conditions in IfThenElse and WhileDoElse
1 parent a9d6e56 commit ab6f4a6

4 files changed

Lines changed: 52 additions & 0 deletions

File tree

‎src/controls/if_then_else_node.cpp‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ NodeStatus IfThenElseNode::tick()
4545
{
4646
return condition_status;
4747
}
48+
if(condition_status == NodeStatus::SKIPPED)
49+
{
50+
resetChildren();
51+
return condition_status;
52+
}
4853
if(condition_status == NodeStatus::SUCCESS)
4954
{
5055
child_idx_ = 1;

‎src/controls/while_do_else_node.cpp‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ NodeStatus WhileDoElseNode::tick()
4242
{
4343
return condition_status;
4444
}
45+
if(condition_status == NodeStatus::SKIPPED)
46+
{
47+
resetChildren();
48+
return condition_status;
49+
}
4550

4651
NodeStatus status = NodeStatus::IDLE;
4752

‎tests/gtest_if_then_else.cpp‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,27 @@ TEST_F(IfThenElseTest, ConditionRunning)
174174
ASSERT_EQ(counters[0], 1); // TestA executed
175175
}
176176

177+
TEST_F(IfThenElseTest, ConditionSkipped)
178+
{
179+
const std::string xml_text = R"(
180+
<root BTCPP_format="4">
181+
<BehaviorTree>
182+
<IfThenElse>
183+
<AlwaysSuccess _skipIf="true"/>
184+
<TestA/>
185+
<TestB/>
186+
</IfThenElse>
187+
</BehaviorTree>
188+
</root>)";
189+
190+
auto tree = factory.createTreeFromText(xml_text);
191+
auto status = tree.tickOnce();
192+
193+
ASSERT_EQ(status, NodeStatus::SKIPPED);
194+
ASSERT_EQ(counters[0], 0);
195+
ASSERT_EQ(counters[1], 0);
196+
}
197+
177198
TEST_F(IfThenElseTest, HaltBehavior)
178199
{
179200
// Test that halt resets the node properly

‎tests/gtest_while_do_else.cpp‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,27 @@ TEST_F(WhileDoElseTest, ConditionFalse_TwoChildren_ReturnsFailure)
9494
ASSERT_EQ(counters[0], 0); // TestA not executed
9595
}
9696

97+
TEST_F(WhileDoElseTest, ConditionSkipped)
98+
{
99+
const std::string xml_text = R"(
100+
<root BTCPP_format="4">
101+
<BehaviorTree>
102+
<WhileDoElse>
103+
<AlwaysSuccess _skipIf="true"/>
104+
<TestA/>
105+
<TestB/>
106+
</WhileDoElse>
107+
</BehaviorTree>
108+
</root>)";
109+
110+
auto tree = factory.createTreeFromText(xml_text);
111+
auto status = tree.tickOnce();
112+
113+
ASSERT_EQ(status, NodeStatus::SKIPPED);
114+
ASSERT_EQ(counters[0], 0);
115+
ASSERT_EQ(counters[1], 0);
116+
}
117+
97118
TEST_F(WhileDoElseTest, DoBranchFails)
98119
{
99120
// When do-branch fails, WhileDoElse returns FAILURE

0 commit comments

Comments
 (0)