Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/xml_parsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ TreeNode::Ptr XMLParser::PImpl::createNodeFromXML(const XMLElement* element,
if(it == port_remap.end() && !do_autoremap)
{
// remapping is not explicitly defined in the XML: use the model
if(port_info.defaultValueString().empty())
if(port_info.defaultValue().empty())
{
auto msg = StrCat("In the <TreeNodesModel> the <Subtree ID=\"", type_ID,
"\"> is defining a mandatory port called [", port_name,
Expand Down
56 changes: 56 additions & 0 deletions tests/gtest_subtree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,62 @@ TEST(SubTree, WhitespaceInSubtreeModel)
FAIL() << "Exception was not thrown.";
}

TEST(SubTree, EmptyModelDefaultIsNotMandatory)
{
struct TestCase
{
const char* name;
const char* port_model;
const char* invocation_attributes;
const char* expected_value;
bool should_build;
};

const TestCase test_cases[] = {
{ "empty default, not remapped", R"(<inout_port name="note" default=""/>)", "", "",
true },
{ "empty default, explicitly empty", R"(<inout_port name="note" default=""/>)",
R"( note="")", "", true },
{ "non-empty default, not remapped",
R"(<inout_port name="note" default="something"/>)", "", "something", true },
{ "no default, not remapped", R"(<inout_port name="note"/>)", "", "", false },
};

for(const auto& test_case : test_cases)
{
const auto xml_text = StrCat(
R"(<root main_tree_to_execute="MainTree" BTCPP_format="4">
<TreeNodesModel>
<SubTree ID="Child">)",
test_case.port_model,
R"(</SubTree>
</TreeNodesModel>
<BehaviorTree ID="MainTree">
<SubTree ID="Child")",
test_case.invocation_attributes,
R"(/>
</BehaviorTree>
<BehaviorTree ID="Child">
<ScriptCondition code="note==')",
test_case.expected_value,
R"('"/>
</BehaviorTree>
</root>)");

BehaviorTreeFactory factory;
if(test_case.should_build)
{
Tree tree;
ASSERT_NO_THROW(tree = factory.createTreeFromText(xml_text)) << test_case.name;
EXPECT_EQ(tree.tickWhileRunning(), NodeStatus::SUCCESS) << test_case.name;
}
else
{
EXPECT_THROW(factory.createTreeFromText(xml_text), RuntimeError) << test_case.name;
}
}
}

class PrintToConsole : public BT::SyncActionNode
{
public:
Expand Down
Loading