Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion tests/gtest_ports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ TEST(PortTest, GetInputDefaultValue_Issue858)
}
}

// Helper class used by Issue #969 test
// Helper class used by Issue #969 and #1065 tests
class CollectDoubleAction : public SyncActionNode
{
public:
Expand Down Expand Up @@ -777,3 +777,41 @@ TEST(PortTest, DefaultEmptyVector_Issue982)
<< " element(s). First element: \""
<< (result.empty() ? "" : result[0]) << "\"";
}

// Issue #1065: passing a string literal like "1;2;3" through a SubTree port
// to a LoopDouble node should work, but fails because the subtree remapping
// stores the value as a plain std::string in the blackboard without converting
// it to SharedQueue<double>.
TEST(PortTest, SubtreeStringLiteralToLoopDouble_Issue1065)
{
// The main tree passes a string literal "1;2;3" to the subtree port "queue".
// Inside the subtree, LoopDouble should parse it and iterate over the values.
std::string xml_txt = R"(
<root BTCPP_format="4">
<BehaviorTree ID="MainTree">
<SubTree ID="LoopSubTree" queue="1;2;3" />
</BehaviorTree>

<BehaviorTree ID="LoopSubTree">
<LoopDouble queue="{queue}" value="{number}">
<CollectDouble value="{number}" />
</LoopDouble>
</BehaviorTree>
</root>
)";

std::vector<double> collected;

BehaviorTreeFactory factory;
factory.registerNodeType<CollectDoubleAction>("CollectDouble", &collected);
factory.registerBehaviorTreeFromText(xml_txt);

auto tree = factory.createTree("MainTree");
auto status = tree.tickWhileRunning();

ASSERT_EQ(status, NodeStatus::SUCCESS);
ASSERT_EQ(collected.size(), 3u);
EXPECT_DOUBLE_EQ(collected[0], 1.0);
EXPECT_DOUBLE_EQ(collected[1], 2.0);
EXPECT_DOUBLE_EQ(collected[2], 3.0);
}
Loading