Skip to content

Commit

Permalink
add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
facontidavide committed Jan 17, 2024
1 parent 574a34f commit c3a04cf
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions tests/gtest_ports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ class NodeWithPorts : public SyncActionNode

static PortsList providedPorts()
{
return {BT::InputPort<int>("in_port_A", 42, "magic_number"), BT::InputPort<int>("in_"
"port"
"_"
"B")};
return {BT::InputPort<int>("in_port_A", 42, "magic_number"),
BT::InputPort<int>("in_port_B")};
}
};

Expand All @@ -38,19 +36,49 @@ TEST(PortTest, DefaultPorts)
std::string xml_txt = R"(
<root BTCPP_format="4" >
<BehaviorTree ID="MainTree">
<NodeWithPorts name = "first" in_port_B="66" />
<NodeWithPorts in_port_B="66" />
</BehaviorTree>
</root>)";

BehaviorTreeFactory factory;
factory.registerNodeType<NodeWithPorts>("NodeWithPorts");

auto tree = factory.createTreeFromText(xml_txt);

NodeStatus status = tree.tickWhileRunning();
ASSERT_EQ(status, NodeStatus::SUCCESS);
}


TEST(PortTest, MissingPort)
{
std::string xml_txt = R"(
<root BTCPP_format="4" >
<BehaviorTree ID="MainTree">
<NodeWithPorts/>
</BehaviorTree>
</root>)";

BehaviorTreeFactory factory;
factory.registerNodeType<NodeWithPorts>("NodeWithPorts");
auto tree = factory.createTreeFromText(xml_txt);
NodeStatus status = tree.tickWhileRunning();
ASSERT_EQ(status, NodeStatus::FAILURE);
}

TEST(PortTest, WrongPort)
{
std::string xml_txt = R"(
<root BTCPP_format="4" >
<BehaviorTree ID="MainTree">
<NodeWithPorts da_port="66" />
</BehaviorTree>
</root>)";

BehaviorTreeFactory factory;
factory.registerNodeType<NodeWithPorts>("NodeWithPorts");

EXPECT_ANY_THROW(auto tree = factory.createTreeFromText(xml_txt));
}

TEST(PortTest, Descriptions)
{
std::string xml_txt = R"(
Expand Down

0 comments on commit c3a04cf

Please sign in to comment.