@@ -18,8 +18,16 @@ class NodeWithPorts : public SyncActionNode
18
18
{
19
19
int val_A = 0 ;
20
20
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 )
23
31
{
24
32
return NodeStatus::SUCCESS;
25
33
}
@@ -33,6 +41,16 @@ class NodeWithPorts : public SyncActionNode
33
41
}
34
42
};
35
43
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
+
36
54
TEST (PortTest, DefaultPorts)
37
55
{
38
56
std::string xml_txt = R"(
@@ -61,8 +79,7 @@ TEST(PortTest, MissingPort)
61
79
BehaviorTreeFactory factory;
62
80
factory.registerNodeType <NodeWithPorts>(" NodeWithPorts" );
63
81
auto tree = factory.createTreeFromText (xml_txt);
64
- NodeStatus status = tree.tickWhileRunning ();
65
- ASSERT_EQ (status, NodeStatus::FAILURE);
82
+ ASSERT_ANY_THROW (tree.tickWhileRunning ());
66
83
}
67
84
68
85
TEST (PortTest, WrongPort)
0 commit comments