@@ -581,3 +581,87 @@ TEST(PortTest, DefaultWronglyOverriden)
581581 // This is correct
582582 ASSERT_NO_THROW (auto tree = factory.createTreeFromText (xml_txt_correct));
583583}
584+
585+ // Helper class used by Issue #969 test
586+ class CollectDoubleAction : public SyncActionNode
587+ {
588+ public:
589+ CollectDoubleAction (const std::string& name, const NodeConfig& config,
590+ std::vector<double >* collected)
591+ : SyncActionNode(name, config), collected_(collected)
592+ {}
593+
594+ NodeStatus tick () override
595+ {
596+ double val = 0 ;
597+ if (getInput (" value" , val))
598+ {
599+ collected_->push_back (val);
600+ return NodeStatus::SUCCESS ;
601+ }
602+ return NodeStatus::FAILURE ;
603+ }
604+
605+ static PortsList providedPorts ()
606+ {
607+ return { BT ::InputPort<double >(" value" ) };
608+ }
609+
610+ private:
611+ std::vector<double >* collected_;
612+ };
613+
614+ // Issue #969: LoopNode<T> uses SharedQueue<T> (shared_ptr<deque<T>>) for its queue
615+ // port, but upstream nodes often produce std::vector<T>. This type mismatch causes
616+ // tree creation to fail.
617+ class ProduceVectorDoubleAction : public SyncActionNode
618+ {
619+ public:
620+ ProduceVectorDoubleAction (const std::string& name, const NodeConfig& config)
621+ : SyncActionNode(name, config)
622+ {}
623+
624+ NodeStatus tick () override
625+ {
626+ std::vector<double > vec = { 10.0 , 20.0 , 30.0 };
627+ setOutput (" numbers" , vec);
628+ return NodeStatus::SUCCESS ;
629+ }
630+
631+ static PortsList providedPorts ()
632+ {
633+ return { BT ::OutputPort<std::vector<double >>(" numbers" ) };
634+ }
635+ };
636+
637+ TEST (PortTest, LoopNodeAcceptsVector_Issue969)
638+ {
639+ // An upstream node outputs std::vector<double>, and LoopDouble should be
640+ // able to iterate over it without requiring manual conversion to SharedQueue.
641+ std::string xml_txt = R"(
642+ <root BTCPP_format="4">
643+ <BehaviorTree ID="MainTree">
644+ <Sequence>
645+ <ProduceVectorDouble numbers="{nums}" />
646+ <LoopDouble queue="{nums}" value="{val}">
647+ <CollectDouble value="{val}" />
648+ </LoopDouble>
649+ </Sequence>
650+ </BehaviorTree>
651+ </root>
652+ )" ;
653+
654+ std::vector<double > collected;
655+
656+ BehaviorTreeFactory factory;
657+ factory.registerNodeType <ProduceVectorDoubleAction>(" ProduceVectorDouble" );
658+ factory.registerNodeType <CollectDoubleAction>(" CollectDouble" , &collected);
659+ auto tree = factory.createTreeFromText (xml_txt);
660+ auto status = tree.tickWhileRunning ();
661+
662+ ASSERT_EQ (status, NodeStatus::SUCCESS );
663+ ASSERT_EQ (collected.size (), 3u );
664+ EXPECT_DOUBLE_EQ (collected[0 ], 10.0 );
665+ EXPECT_DOUBLE_EQ (collected[1 ], 20.0 );
666+ EXPECT_DOUBLE_EQ (collected[2 ], 30.0 );
667+ }
0 commit comments