Go to the documentation of this file.
13 #include <gtest/gtest.h>
17 #include "../sample_nodes/dummy_nodes.h"
31 auto res = getInput<int>(
"in_port");
34 throw RuntimeError(
"BB_TestNode needs input", res.error());
36 value = res.value() * 2;
37 if (!setOutput(
"out_port", value))
46 return {BT::InputPort<int>(
"in_port"), BT::OutputPort<int>(
"out_port")};
65 BT::InputPort<int>(
"input_int"),
66 BT::InputPort<std::string>(
"input_string"),
69 BT::OutputPort<int>(
"output_int"),
70 BT::OutputPort<std::string>(
"output_string")};
74 TEST(BlackboardTest, GetInputsFromBlackboard)
79 assignDefaultRemapping<BB_TestNode>(config);
82 bb->set(
"in_port", 11);
89 ASSERT_EQ(bb->get<
int>(
"out_port"), 22);
92 TEST(BlackboardTest, BasicRemapping)
101 bb->set(
"my_input_port", 11);
106 ASSERT_EQ(bb->get<
int>(
"my_output_port"), 22);
109 TEST(BlackboardTest, GetInputsFromText)
125 ASSERT_EQ(bb->get<
int>(
"out_port"), 22);
128 TEST(BlackboardTest, SetOutputFromText)
132 <root main_tree_to_execute = "MainTree" >
133 <BehaviorTree ID="MainTree">
135 <BB_TestNode in_port="11" out_port="{my_port}"/>
136 <SetBlackboard output_key="my_port" value="-43" />
151 TEST(BlackboardTest, WithFactory)
159 <root main_tree_to_execute = "MainTree" >
160 <BehaviorTree ID="MainTree">
162 <BB_TestNode name = "first" in_port="11"
163 out_port="{my_input_port}"/>
165 <BB_TestNode name = "second" in_port="{my_input_port}"
166 out_port="{my_input_port}" />
168 <BB_TestNode name = "third" in_port="{my_input_port}"
169 out_port="{my_output_port}" />
180 ASSERT_EQ(bb->get<
int>(
"my_input_port"), 44);
181 ASSERT_EQ(bb->get<
int>(
"my_output_port"), 88);
184 TEST(BlackboardTest, TypoInPortName)
191 <root main_tree_to_execute = "MainTree" >
192 <BehaviorTree ID="MainTree">
193 <BB_TestNode inpuuuut_port="{value}" />
200 TEST(BlackboardTest, CheckPortType)
206 std::string good_one = R
"(
207 <root main_tree_to_execute = "MainTree" >
208 <BehaviorTree ID="MainTree">
210 <TypedNode name = "first" output_int="{matching}" output_string="{whatever}" output="{no_problem}" />
211 <TypedNode name = "second" input_int="{matching}" input="{whatever}" input_string="{no_problem}" />
217 ASSERT_NE(tree.rootNode(),
nullptr);
219 std::string bad_one = R
"(
220 <root main_tree_to_execute = "MainTree" >
221 <BehaviorTree ID="MainTree">
223 <TypedNode name = "first" output_int="{value}" />
224 <TypedNode name = "second" input_string="{value}" />
237 std::cout <<
"Constructor: ref_count " << sptr_.use_count() << std::endl;
242 std::cout <<
"ctor copy: ref_count " << sptr_.use_count() << std::endl;
247 sptr_ = (from.
sptr_);
248 std::cout <<
"equal copied: ref_count " << sptr_.use_count() << std::endl;
254 std::cout << (
"Destructor") << std::endl;
259 return sptr_.use_count();
266 TEST(BlackboardTest, MoveVsCopy)
274 std::cout << (
"----- before set -----") << std::endl;
275 blackboard->set(
"testmove", test);
276 std::cout << (
" ----- after set -----") << std::endl;
285 TEST(BlackboardTest, CheckTypeSafety)
290 bool is = std::is_constructible<BT::StringView, char*>::value;
293 is = std::is_constructible<BT::StringView, std::string>::value;
302 TEST(BlackboardTest, SetBlackboard_Issue725)
307 <root main_tree_to_execute = "MainTree" >
308 <BehaviorTree ID="MainTree">
309 <SetBlackboard value="{first_point}" output_key="other_point" />
318 const Point point = {2,7};
319 blackboard->set(
"first_point", point);
321 const auto status = tree.tickRoot();
323 Point other_point = blackboard->get<
Point>(
"other_point");
326 ASSERT_EQ(other_point.
x, point.
x);
327 ASSERT_EQ(other_point.
y, point.
y);
NodeStatus tickRoot()
tickRoot send the tick signal to the root node. It will propagate through the entire tree.
Tree createTree(const std::string &tree_name, Blackboard::Ptr blackboard=Blackboard::create())
void registerNodeType(const std::string &ID)
std::pair< std::string, PortInfo > InputPort(StringView name, StringView description={})
std::shared_ptr< int > sptr_
std::unordered_map< std::string, PortInfo > PortsList
RefCountClass(const RefCountClass &from)
PortsRemapping input_ports
TEST(BlackboardTest, GetInputsFromBlackboard)
PortsRemapping output_ports
virtual NodeStatus executeTick() override
throws if the derived class return RUNNING.
static PortsList providedPorts()
BB_TestNode(const std::string &name, const NodeConfiguration &config)
Tree createTreeFromText(const std::string &text, Blackboard::Ptr blackboard=Blackboard::create())
RefCountClass(std::shared_ptr< int > value)
NodeStatus tick()
Method to be implemented by the user.
The BehaviorTreeFactory is used to create instances of a TreeNode at run-time.
static Blackboard::Ptr create(Blackboard::Ptr parent={})
Blackboard::Ptr blackboard
BB_TypedTestNode(const std::string &name, const NodeConfiguration &config)
RefCountClass & operator=(const RefCountClass &from)
std::pair< std::string, PortInfo > OutputPort(StringView name, StringView description={})
void registerBehaviorTreeFromText(const std::string &xml_text)
std::vector< Blackboard::Ptr > blackboard_stack
NodeStatus tick()
Method to be implemented by the user.
static const char * xml_text
The SyncActionNode is an ActionNode that explicitly prevents the status RUNNING and doesn't require a...
static PortsList providedPorts()
behaviortree_cpp_v3
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Wed Jun 26 2024 02:51:19