@@ -730,3 +730,134 @@ TEST(PortTest, DefaultWronglyOverriden)
730730 // This is correct
731731 ASSERT_NO_THROW (auto tree = factory.createTreeFromText (xml_txt_correct));
732732}
733+
734+ class OutputVectorStringNode : public SyncActionNode
735+ {
736+ public:
737+ OutputVectorStringNode (const std::string& name, const NodeConfig& config)
738+ : SyncActionNode(name, config)
739+ {}
740+ static PortsList providedPorts ()
741+ {
742+ return { InputPort<std::string>(" string1" , " val1" , " First string" ),
743+ InputPort<std::string>(" string2" , " val2" , " Second string" ),
744+ OutputPort<std::vector<std::string>>(" string_vector" , " {string_vector}" ,
745+ " Vector of strings." ) };
746+ }
747+
748+ NodeStatus tick () override
749+ {
750+ auto string1 = getInput<std::string>(" string1" );
751+ auto string2 = getInput<std::string>(" string2" );
752+
753+ std::vector<std::string> out = { string1.value (), string2.value () };
754+ setOutput (" string_vector" , out);
755+ return NodeStatus::SUCCESS;
756+ }
757+ };
758+
759+ class InputVectorStringNode : public SyncActionNode
760+ {
761+ public:
762+ InputVectorStringNode (const std::string& name, const NodeConfig& config)
763+ : SyncActionNode(name, config)
764+ {}
765+ static PortsList providedPorts ()
766+ {
767+ return { InputPort<std::vector<std::string>>(" string_vector" , " {string_vector}" ,
768+ " Vector of strings." ) };
769+ }
770+
771+ NodeStatus tick () override
772+ {
773+ std::vector<std::string> expected_vec = { " val1" , " val2" };
774+ std::vector<std::string> actual_vec;
775+
776+ if (!getInput<std::vector<std::string>>(" string_vector" , actual_vec))
777+ {
778+ return NodeStatus::FAILURE;
779+ }
780+ if (expected_vec == actual_vec)
781+ {
782+ return NodeStatus::SUCCESS;
783+ }
784+ else
785+ {
786+ return NodeStatus::FAILURE;
787+ }
788+ }
789+ };
790+
791+ class InputVectorDoubleNode : public SyncActionNode
792+ {
793+ public:
794+ InputVectorDoubleNode (const std::string& name, const NodeConfig& config)
795+ : SyncActionNode(name, config)
796+ {}
797+ static PortsList providedPorts ()
798+ {
799+ return { InputPort<std::vector<double >>(" double_vector" , " {double_vector}" ,
800+ " Vector of doubles." ) };
801+ }
802+
803+ NodeStatus tick () override
804+ {
805+ std::vector<double > expected_vec = { 1.0 , 2.0 };
806+ std::vector<double > actual_vec;
807+
808+ if (!getInput<std::vector<double >>(" double_vector" , actual_vec))
809+ {
810+ return NodeStatus::FAILURE;
811+ }
812+ if (expected_vec == actual_vec)
813+ {
814+ return NodeStatus::SUCCESS;
815+ }
816+ else
817+ {
818+ return NodeStatus::FAILURE;
819+ }
820+ }
821+ };
822+
823+ TEST (PortTest, VectorAny)
824+ {
825+ BT::BehaviorTreeFactory factory;
826+ factory.registerNodeType <OutputVectorStringNode>(" OutputVectorStringNode" );
827+ factory.registerNodeType <InputVectorStringNode>(" InputVectorStringNode" );
828+ factory.registerNodeType <InputVectorDoubleNode>(" InputVectorDoubleNode" );
829+
830+ std::string xml_txt_good = R"(
831+ <root BTCPP_format="4" >
832+ <BehaviorTree>
833+ <Sequence name="root_sequence">
834+ <OutputVectorStringNode/>
835+ <InputVectorStringNode/>
836+ </Sequence>
837+ </BehaviorTree>
838+ </root>)" ;
839+
840+ std::string xml_txt_bad = R"(
841+ <root BTCPP_format="4" >
842+ <BehaviorTree>
843+ <Sequence name="root_sequence">
844+ <OutputVectorStringNode/>
845+ <InputVectorDoubleNode double_vector="{string_vector}"/>
846+ </Sequence>
847+ </BehaviorTree>
848+ </root>)" ;
849+
850+ // Test that setting and retrieving a vector<string> works.
851+ BT::Tree tree;
852+ ASSERT_NO_THROW (tree = factory.createTreeFromText (xml_txt_good));
853+
854+ BT::NodeStatus status;
855+ ASSERT_NO_THROW (status = tree.tickOnce ());
856+ ASSERT_EQ (status, NodeStatus::SUCCESS);
857+
858+ // Test that setting a port as a vector<string> and attempting to retrie it as a vector<double> fails.
859+ ASSERT_NO_THROW (tree = factory.createTreeFromText (xml_txt_bad));
860+
861+ ASSERT_NO_THROW (status = tree.tickOnce ());
862+ ASSERT_EQ (status, NodeStatus::FAILURE);
863+ }
0 commit comments