13 #include <gtest/gtest.h> 33 auto res = getInput<int>(
"in_port");
36 throw RuntimeError(
"BB_TestNode needs input", res.error());
38 value = res.value() * 2;
39 if (!setOutput(
"out_port", value))
48 return {BT::InputPort<int>(
"in_port"), BT::OutputPort<int>(
"out_port")};
67 BT::InputPort<int>(
"input_int"),
68 BT::InputPort<std::string>(
"input_string"),
71 BT::OutputPort<int>(
"output_int"),
72 BT::OutputPort<std::string>(
"output_string")};
76 TEST(BlackboardTest, GetInputsFromBlackboard)
81 assignDefaultRemapping<BB_TestNode>(config);
84 bb->set(
"in_port", 11);
91 ASSERT_EQ(bb->get<
int>(
"out_port"), 22);
94 TEST(BlackboardTest, BasicRemapping)
103 bb->set(
"my_input_port", 11);
108 ASSERT_EQ(bb->get<
int>(
"my_output_port"), 22);
111 TEST(BlackboardTest, GetInputsFromText)
127 ASSERT_EQ(bb->get<
int>(
"out_port"), 22);
130 TEST(BlackboardTest, SetOutputFromText)
134 <root main_tree_to_execute = "MainTree" > 135 <BehaviorTree ID="MainTree"> 137 <BB_TestNode in_port="11" out_port="{my_port}"/> 138 <SetBlackboard output_key="my_port" value="-43" /> 153 TEST(BlackboardTest, WithFactory)
161 <root main_tree_to_execute = "MainTree" > 162 <BehaviorTree ID="MainTree"> 164 <BB_TestNode name = "first" in_port="11" 165 out_port="{my_input_port}"/> 167 <BB_TestNode name = "second" in_port="{my_input_port}" 168 out_port="{my_input_port}" /> 170 <BB_TestNode name = "third" in_port="{my_input_port}" 171 out_port="{my_output_port}" /> 182 ASSERT_EQ(bb->get<
int>(
"my_input_port"), 44);
183 ASSERT_EQ(bb->get<
int>(
"my_output_port"), 88);
186 TEST(BlackboardTest, TypoInPortName)
193 <root main_tree_to_execute = "MainTree" > 194 <BehaviorTree ID="MainTree"> 195 <BB_TestNode inpuuuut_port="{value}" /> 202 TEST(BlackboardTest, CheckPortType) 208 std::string good_one = R
"( 209 <root main_tree_to_execute = "MainTree" > 210 <BehaviorTree ID="MainTree"> 212 <TypedNode name = "first" output_int="{matching}" output_string="{whatever}" output="{no_problem}" /> 213 <TypedNode name = "second" input_int="{matching}" input="{whatever}" input_string="{no_problem}" /> 219 ASSERT_NE(tree.rootNode(),
nullptr);
221 std::string bad_one = R
"( 222 <root main_tree_to_execute = "MainTree" > 223 <BehaviorTree ID="MainTree"> 225 <TypedNode name = "first" output_int="{value}" /> 226 <TypedNode name = "second" input_string="{value}" /> 239 std::cout <<
"Constructor: ref_count " << sptr_.use_count() << std::endl;
244 std::cout <<
"ctor copy: ref_count " << sptr_.use_count() << std::endl;
249 sptr_ = (from.
sptr_);
250 std::cout <<
"equal copied: ref_count " << sptr_.use_count() << std::endl;
256 std::cout << (
"Destructor") << std::endl;
261 return sptr_.use_count();
268 TEST(BlackboardTest, MoveVsCopy)
276 std::cout << (
"----- before set -----") << std::endl;
277 blackboard->set(
"testmove", test);
278 std::cout << (
" ----- after set -----") << std::endl;
287 TEST(BlackboardTest, CheckTypeSafety)
292 bool is = std::is_constructible<BT::StringView, char*>::value;
295 is = std::is_constructible<BT::StringView, std::string>::value;
NodeStatus tick()
Method to be implemented by the user.
std::pair< std::string, PortInfo > InputPort(StringView name, StringView description={})
static Blackboard::Ptr create(Blackboard::Ptr parent={})
void registerNodeType(const std::string &ID)
TEST(BlackboardTest, GetInputsFromBlackboard)
std::shared_ptr< int > sptr_
virtual NodeStatus executeTick() override
throws if the derived class return RUNNING.
static const char * xml_text
Blackboard::Ptr blackboard
static PortsList providedPorts()
The SyncActionNode is an ActionNode that explicitly prevents the status RUNNING and doesn't require a...
The BehaviorTreeFactory is used to create instances of a TreeNode at run-time.
RefCountClass(const RefCountClass &from)
NodeStatus tickRoot()
tickRoot send the tick signal to the root node. It will propagate through the entire tree...
Tree createTreeFromText(const std::string &text, Blackboard::Ptr blackboard=Blackboard::create())
BB_TypedTestNode(const std::string &name, const NodeConfiguration &config)
NodeStatus tick()
Method to be implemented by the user.
PortsRemapping output_ports
std::unordered_map< std::string, PortInfo > PortsList
std::pair< std::string, PortInfo > OutputPort(StringView name, StringView description={})
static PortsList providedPorts()
RefCountClass(std::shared_ptr< int > value)
PortsRemapping input_ports
RefCountClass & operator=(const RefCountClass &from)
BB_TestNode(const std::string &name, const NodeConfiguration &config)