Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/controls/if_then_else_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ NodeStatus IfThenElseNode::tick()
{
return condition_status;
}
if(condition_status == NodeStatus::SKIPPED)
{
resetChildren();
return condition_status;
}
if(condition_status == NodeStatus::SUCCESS)
{
child_idx_ = 1;
Expand Down
5 changes: 5 additions & 0 deletions src/controls/while_do_else_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ NodeStatus WhileDoElseNode::tick()
{
return condition_status;
}
if(condition_status == NodeStatus::SKIPPED)
{
resetChildren();
return condition_status;
}

NodeStatus status = NodeStatus::IDLE;

Expand Down
21 changes: 21 additions & 0 deletions tests/gtest_if_then_else.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,27 @@ TEST_F(IfThenElseTest, ConditionRunning)
ASSERT_EQ(counters[0], 1); // TestA executed
}

TEST_F(IfThenElseTest, ConditionSkipped)
{
const std::string xml_text = R"(
<root BTCPP_format="4">
<BehaviorTree>
<IfThenElse>
<AlwaysSuccess _skipIf="true"/>
<TestA/>
<TestB/>
</IfThenElse>
</BehaviorTree>
</root>)";

auto tree = factory.createTreeFromText(xml_text);
auto status = tree.tickOnce();

ASSERT_EQ(status, NodeStatus::SKIPPED);
ASSERT_EQ(counters[0], 0);
ASSERT_EQ(counters[1], 0);
}

TEST_F(IfThenElseTest, HaltBehavior)
{
// Test that halt resets the node properly
Expand Down
21 changes: 21 additions & 0 deletions tests/gtest_while_do_else.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,27 @@ TEST_F(WhileDoElseTest, ConditionFalse_TwoChildren_ReturnsFailure)
ASSERT_EQ(counters[0], 0); // TestA not executed
}

TEST_F(WhileDoElseTest, ConditionSkipped)
{
const std::string xml_text = R"(
<root BTCPP_format="4">
<BehaviorTree>
<WhileDoElse>
<AlwaysSuccess _skipIf="true"/>
<TestA/>
<TestB/>
</WhileDoElse>
</BehaviorTree>
</root>)";

auto tree = factory.createTreeFromText(xml_text);
auto status = tree.tickOnce();

ASSERT_EQ(status, NodeStatus::SKIPPED);
ASSERT_EQ(counters[0], 0);
ASSERT_EQ(counters[1], 0);
}

TEST_F(WhileDoElseTest, DoBranchFails)
{
// When do-branch fails, WhileDoElse returns FAILURE
Expand Down
Loading