Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow letting value field empty for numeric ports #854

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion src/xml_parsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ TreeNode::Ptr XMLParser::PImpl::createNodeFromXML(const XMLElement* element,
"] is found in the XML, but not in the "
"providedPorts()"));
}
else
else if(!port_value.empty())
{
const auto& port_model = port_model_it->second;
bool is_blacbkboard = port_value.size() >= 3 && port_value.front() == '{' &&
Expand Down
25 changes: 16 additions & 9 deletions tests/gtest_ports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,29 +679,36 @@ TEST(PortTest, Default_Issues_767)
"default nullptr"));
}

TEST(PortTest, DefaultWronglyOverriden)
TEST(PortTest, AllowEmptyValues)
{
BT::BehaviorTreeFactory factory;
factory.registerNodeType<NodeWithPorts>("NodeWithPorts");
factory.registerNodeType<NodeWithDefaultNullptr>("NodeWithDefaultNullptr");

std::string xml_txt_wrong = R"(
std::string xml_txt_empty_number = R"(
<root BTCPP_format="4" >
<BehaviorTree>
<NodeWithPorts in_port_A=""/>
</BehaviorTree>
</root>)";

std::string xml_txt_empty_pointer = R"(
<root BTCPP_format="4" >
<BehaviorTree>
<NodeWithDefaultNullptr input=""/>
</BehaviorTree>
</root>)";

std::string xml_txt_correct = R"(
std::string xml_txt_empty_default = R"(
<root BTCPP_format="4" >
<BehaviorTree>
<NodeWithDefaultNullptr/>
</BehaviorTree>
</root>)";

// this should throw, because we are NOT using the default,
// but overriding it with an empty string instead.
// See issue 768 for reference
ASSERT_ANY_THROW(auto tree = factory.createTreeFromText(xml_txt_wrong));
// This is correct
ASSERT_NO_THROW(auto tree = factory.createTreeFromText(xml_txt_correct));
// All are correct, as we allow empty strings that will get retrieved as std::nullopt
// Note that this is the opposite request on issue 768
ASSERT_NO_THROW(auto tree = factory.createTreeFromText(xml_txt_empty_number));
ASSERT_NO_THROW(auto tree = factory.createTreeFromText(xml_txt_empty_pointer));
ASSERT_NO_THROW(auto tree = factory.createTreeFromText(xml_txt_empty_default));
}
Loading