MCPcopy Create free account
hub / github.com/BehaviorTree/BehaviorTree.CPP / TEST

Function TEST

tests/gtest_xml_null_subtree_id.cpp:17–37  ·  view source on GitHub ↗

BUG-7: If a element inside is missing the "ID" attribute, Attribute("ID") returns nullptr, which is used as a key in std::unordered_map — undefined behavior (null pointer dereference). After the fix, this should throw a descriptive RuntimeError.

Source from the content-addressed store, hash-verified

15// key in std::unordered_map — undefined behavior (null pointer dereference).
16// After the fix, this should throw a descriptive RuntimeError.
17TEST(XMLParserTest, SubTreeModelMissingID_Bug7)
18{
19 const std::string xml_text = R"(
20 <root BTCPP_format="4">
21 <BehaviorTree ID="MainTree">
22 <AlwaysSuccess />
23 </BehaviorTree>
24 <TreeNodesModel>
25 <SubTree>
26 <input_port name="some_port"/>
27 </SubTree>
28 </TreeNodesModel>
29 </root>
30 )";
31
32 BehaviorTreeFactory factory;
33
34 // Before fix: crash (null pointer as map key)
35 // After fix: should throw RuntimeError about missing ID
36 EXPECT_THROW(factory.registerBehaviorTreeFromText(xml_text), RuntimeError);
37}

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected