Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 92a6155

Browse files
committed
Fix bug in default port values
1 parent ba66795 commit 92a6155

File tree

4 files changed

+55
-9
lines changed

4 files changed

+55
-9
lines changed

include/behaviortree_cpp_v3/basic_types.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,6 @@ template <typename T = void> inline
296296
return out;
297297
}
298298

299-
template <typename T = void> inline
300-
std::pair<std::string,PortInfo> OutputPort(StringView name, const T& default_value, StringView description)
301-
{
302-
auto out = CreatePort<T>(PortDirection::OUTPUT, name, description );
303-
out.second.setDefaultValue( BT::toStr(default_value) );
304-
return out;
305-
}
306-
307299
template <typename T = void> inline
308300
std::pair<std::string,PortInfo> BidirectionalPort(StringView name, const T& default_value, StringView description)
309301
{

src/xml_parsing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ TreeNode::Ptr XMLParser::Pimpl::createNodeFromXML(const XMLElement *element,
569569
const PortInfo& port_info = port_it.second;
570570

571571
auto direction = port_info.direction();
572-
if( direction != PortDirection::INPUT &&
572+
if( direction != PortDirection::OUTPUT &&
573573
config.input_ports.count(port_name) == 0 &&
574574
port_info.defaultValue().empty() == false)
575575
{

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ set(BT_TESTS
1313
gtest_factory.cpp
1414
gtest_decorator.cpp
1515
gtest_blackboard.cpp
16+
gtest_ports.cpp
1617
navigation_test.cpp
1718
gtest_subtree.cpp
1819
gtest_switch.cpp

tests/gtest_ports.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include <gtest/gtest.h>
2+
#include "behaviortree_cpp_v3/bt_factory.h"
3+
4+
using namespace BT;
5+
6+
class NodeWithPorts: public SyncActionNode
7+
{
8+
public:
9+
NodeWithPorts(const std::string & name, const NodeConfiguration & config)
10+
: SyncActionNode(name, config)
11+
{
12+
std::cout << "ctor" << std::endl;
13+
}
14+
15+
NodeStatus tick()
16+
{
17+
int val_A = 0;
18+
int val_B = 0;
19+
if( getInput("in_port_A", val_A) &&
20+
getInput("in_port_B", val_B) &&
21+
val_A == 42 && val_B == 66)
22+
{
23+
return NodeStatus::SUCCESS;
24+
}
25+
return NodeStatus::FAILURE;
26+
}
27+
28+
static PortsList providedPorts()
29+
{
30+
return { BT::InputPort<int>("in_port_A", 42, "magic_number"),
31+
BT::InputPort<int>("in_port_B") };
32+
}
33+
};
34+
35+
TEST(PortTest, DefaultPorts)
36+
{
37+
std::string xml_txt = R"(
38+
<root main_tree_to_execute = "MainTree" >
39+
<BehaviorTree ID="MainTree">
40+
<NodeWithPorts name = "first" in_port_B="66" />
41+
</BehaviorTree>
42+
</root>)";
43+
44+
BehaviorTreeFactory factory;
45+
factory.registerNodeType<NodeWithPorts>("NodeWithPorts");
46+
47+
auto tree = factory.createTreeFromText(xml_txt);
48+
49+
NodeStatus status = tree.root_node->executeTick();
50+
ASSERT_EQ( status, NodeStatus::SUCCESS );
51+
52+
}
53+

0 commit comments

Comments
 (0)