Skip to content

Commit d4d8ae1

Browse files
AndyZeAndyZe
and
AndyZe
authored
Additional XML verification for ReactiveSequence nodes (#885)
* Additional XML verification for Control nodes * Parse for async nodes based on node name * Add a unit test * Improve the check by counting num async children * Minor update (const) --------- Co-authored-by: AndyZe <[email protected]>
1 parent 40d535d commit d4d8ae1

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/xml_parsing.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,29 @@ void VerifyXML(const std::string& xml_text,
541541
ThrowError(line_number,
542542
std::string("The node <") + name + "> must have 1 or more children");
543543
}
544+
if(name == "ReactiveSequence")
545+
{
546+
size_t async_count = 0;
547+
for(auto child = node->FirstChildElement(); child != nullptr;
548+
child = child->NextSiblingElement())
549+
{
550+
const std::string child_name = node->FirstChildElement()->Name();
551+
const auto child_search = registered_nodes.find(child_name);
552+
const auto child_type = child_search->second;
553+
if(child_type == NodeType::CONTROL &&
554+
((child_name == "ThreadedAction") ||
555+
(child_name == "StatefulActionNode") ||
556+
(child_name == "CoroActionNode") || (child_name == "AsyncSequence")))
557+
{
558+
++async_count;
559+
if(async_count > 1)
560+
{
561+
ThrowError(line_number, std::string("A ReactiveSequence cannot have more "
562+
"than one async child."));
563+
}
564+
}
565+
}
566+
}
544567
}
545568
}
546569
//recursion

tests/gtest_reactive.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,31 @@ TEST(Reactive, TestLogging)
156156
ASSERT_EQ(observer.getStatistics("testA").success_count, num_ticks);
157157
ASSERT_EQ(observer.getStatistics("success").success_count, num_ticks);
158158
}
159+
160+
TEST(Reactive, TwoAsyncNodesInReactiveSequence)
161+
{
162+
static const char* reactive_xml_text = R"(
163+
<root BTCPP_format="4" >
164+
<BehaviorTree ID="MainTree">
165+
<ReactiveSequence>
166+
<AsyncSequence name="first">
167+
<TestA/>
168+
<TestB/>
169+
<TestC/>
170+
</AsyncSequence>
171+
<AsyncSequence name="second">
172+
<TestD/>
173+
<TestE/>
174+
<TestF/>
175+
</AsyncSequence>
176+
</ReactiveSequence>
177+
</BehaviorTree>
178+
</root>
179+
)";
180+
181+
BT::BehaviorTreeFactory factory;
182+
std::array<int, 6> counters;
183+
RegisterTestTick(factory, "Test", counters);
184+
185+
EXPECT_ANY_THROW(auto tree = factory.createTreeFromText(reactive_xml_text));
186+
}

0 commit comments

Comments
 (0)