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.
| 15 | // key in std::unordered_map — undefined behavior (null pointer dereference). |
| 16 | // After the fix, this should throw a descriptive RuntimeError. |
| 17 | TEST(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 | } |
nothing calls this directly
no test coverage detected