@@ -507,7 +507,6 @@ TEST(SubTree, Issue653_SetBlackboard)
507
507
tree.tickWhileRunning ();
508
508
}
509
509
510
-
511
510
TEST (SubTree, SubtreeModels)
512
511
{
513
512
// clang-format off
@@ -548,3 +547,71 @@ TEST(SubTree, SubtreeModels)
548
547
}
549
548
550
549
550
+
551
+ class PrintToConsole : public BT ::SyncActionNode
552
+ {
553
+ public:
554
+ PrintToConsole (const std::string& name, const BT::NodeConfiguration& config,
555
+ std::vector<std::string>* console)
556
+ : BT::SyncActionNode(name, config), console_(console) {}
557
+
558
+ static BT::PortsList providedPorts () {
559
+ return {BT::InputPort<std::string>(" message" )};
560
+ }
561
+
562
+ private:
563
+ virtual BT::NodeStatus tick () override {
564
+ if (auto res = getInput<std::string>(" message" ))
565
+ {
566
+ console_->push_back (res.value ());
567
+ return BT::NodeStatus::SUCCESS;
568
+ }
569
+ else
570
+ return BT::NodeStatus::FAILURE;
571
+ }
572
+ std::vector<std::string>* console_;
573
+ };
574
+
575
+ TEST (SubTree, RemappingIssue696)
576
+ {
577
+ // clang-format off
578
+
579
+ static const char * xml_text = R"(
580
+ <root BTCPP_format="4">
581
+ <BehaviorTree ID="Subtree1">\n"
582
+ <Sequence>
583
+ <PrintToConsole message="{msg1}"/>
584
+ <PrintToConsole message="{msg2}"/>
585
+ </Sequence>
586
+ </BehaviorTree>
587
+
588
+ <BehaviorTree ID="Subtree2">
589
+ <Sequence>
590
+ <SubTree ID="Subtree1" msg1="foo1" _autoremap="true"/>
591
+ <SubTree ID="Subtree1" msg1="foo2" _autoremap="true"/>
592
+ </Sequence>
593
+ </BehaviorTree>
594
+
595
+ <BehaviorTree ID="MainTree">
596
+ <SubTree ID="Subtree2" msg2="bar"/>
597
+ </BehaviorTree>
598
+ </root>
599
+ )" ;
600
+
601
+ // clang-format on
602
+
603
+ BehaviorTreeFactory factory;
604
+ std::vector<std::string> console;
605
+ factory.registerNodeType <PrintToConsole>(" PrintToConsole" , &console);
606
+
607
+ factory.registerBehaviorTreeFromText (xml_text);
608
+ auto tree = factory.createTree (" MainTree" );
609
+ tree.tickWhileRunning ();
610
+
611
+ ASSERT_EQ (console.size (), 4 );
612
+ ASSERT_EQ (console[0 ], " foo1" );
613
+ ASSERT_EQ (console[1 ], " bar" );
614
+ ASSERT_EQ (console[2 ], " foo2" );
615
+ ASSERT_EQ (console[3 ], " bar" );
616
+ }
617
+
0 commit comments