@@ -18,8 +18,16 @@ class NodeWithPorts : public SyncActionNode
1818 {
1919 int val_A = 0 ;
2020 int val_B = 0 ;
21- if (getInput (" in_port_A" , val_A) && getInput (" in_port_B" , val_B) && val_A == 42 &&
22- val_B == 66 )
21+ if (!getInput (" in_port_A" , val_A))
22+ {
23+ throw RuntimeError (" missing input [in_port_A]" );
24+ }
25+ if (!getInput (" in_port_B" , val_B))
26+ {
27+ throw RuntimeError (" missing input [in_port_B]" );
28+ }
29+
30+ if (val_A == 42 && val_B == 66 )
2331 {
2432 return NodeStatus::SUCCESS;
2533 }
@@ -33,6 +41,16 @@ class NodeWithPorts : public SyncActionNode
3341 }
3442};
3543
44+ TEST (PortTest, WrongNodeConfig)
45+ {
46+ NodeConfig config;
47+ config.input_ports [" in_port_A" ] = " 42" ;
48+ // intentionally missing:
49+ // config.input_ports["in_port_B"] = "69";
50+ NodeWithPorts node (" will_fail" , config);
51+ ASSERT_ANY_THROW (node.tick ());
52+ }
53+
3654TEST (PortTest, DefaultPorts)
3755{
3856 std::string xml_txt = R"(
@@ -61,8 +79,7 @@ TEST(PortTest, MissingPort)
6179 BehaviorTreeFactory factory;
6280 factory.registerNodeType <NodeWithPorts>(" NodeWithPorts" );
6381 auto tree = factory.createTreeFromText (xml_txt);
64- NodeStatus status = tree.tickWhileRunning ();
65- ASSERT_EQ (status, NodeStatus::FAILURE);
82+ ASSERT_ANY_THROW (tree.tickWhileRunning ());
6683}
6784
6885TEST (PortTest, WrongPort)
0 commit comments