Skip to content

Commit 2d81a59

Browse files
Add regression test for #1065: subtree string literal to LoopDouble (#1072)
The string value passed through a SubTree port is already type-erased (AnyTypeAllowed) per the port connection rules, and LoopNode's runtime string conversion handles the rest. This test verifies the behavior. Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent fd40532 commit 2d81a59

1 file changed

Lines changed: 39 additions & 1 deletion

File tree

tests/gtest_ports.cpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ TEST(PortTest, GetInputDefaultValue_Issue858)
637637
}
638638
}
639639

640-
// Helper class used by Issue #969 test
640+
// Helper class used by Issue #969 and #1065 tests
641641
class CollectDoubleAction : public SyncActionNode
642642
{
643643
public:
@@ -777,3 +777,41 @@ TEST(PortTest, DefaultEmptyVector_Issue982)
777777
<< " element(s). First element: \""
778778
<< (result.empty() ? "" : result[0]) << "\"";
779779
}
780+
781+
// Issue #1065: passing a string literal like "1;2;3" through a SubTree port
782+
// to a LoopDouble node should work, but fails because the subtree remapping
783+
// stores the value as a plain std::string in the blackboard without converting
784+
// it to SharedQueue<double>.
785+
TEST(PortTest, SubtreeStringLiteralToLoopDouble_Issue1065)
786+
{
787+
// The main tree passes a string literal "1;2;3" to the subtree port "queue".
788+
// Inside the subtree, LoopDouble should parse it and iterate over the values.
789+
std::string xml_txt = R"(
790+
<root BTCPP_format="4">
791+
<BehaviorTree ID="MainTree">
792+
<SubTree ID="LoopSubTree" queue="1;2;3" />
793+
</BehaviorTree>
794+
795+
<BehaviorTree ID="LoopSubTree">
796+
<LoopDouble queue="{queue}" value="{number}">
797+
<CollectDouble value="{number}" />
798+
</LoopDouble>
799+
</BehaviorTree>
800+
</root>
801+
)";
802+
803+
std::vector<double> collected;
804+
805+
BehaviorTreeFactory factory;
806+
factory.registerNodeType<CollectDoubleAction>("CollectDouble", &collected);
807+
factory.registerBehaviorTreeFromText(xml_txt);
808+
809+
auto tree = factory.createTree("MainTree");
810+
auto status = tree.tickWhileRunning();
811+
812+
ASSERT_EQ(status, NodeStatus::SUCCESS);
813+
ASSERT_EQ(collected.size(), 3u);
814+
EXPECT_DOUBLE_EQ(collected[0], 1.0);
815+
EXPECT_DOUBLE_EQ(collected[1], 2.0);
816+
EXPECT_DOUBLE_EQ(collected[2], 3.0);
817+
}

0 commit comments

Comments
 (0)