@@ -726,3 +726,67 @@ TEST(SubTree, SubtreeNameNotRegistered)
726726 ASSERT_ANY_THROW (auto tree = factory.createTreeFromText (xml_text));
727727 ASSERT_ANY_THROW (factory.registerBehaviorTreeFromText (xml_text));
728728}
729+
730+ TEST (SubTree, RecursiveSubtree)
731+ {
732+ // clang-format off
733+
734+ static const char * xml_text = R"(
735+ <root BTCPP_format="4" >
736+
737+ <BehaviorTree ID="MainTree">
738+ <Sequence name="root">
739+ <AlwaysSuccess/>
740+ <SubTree ID="MainTree" />
741+ </Sequence>
742+ </BehaviorTree>
743+
744+ </root>
745+ )" ;
746+
747+ // clang-format on
748+ BehaviorTreeFactory factory;
749+ std::vector<std::string> console;
750+ factory.registerNodeType <PrintToConsole>(" PrintToConsole" , &console);
751+
752+ ASSERT_ANY_THROW (auto tree = factory.createTreeFromText (xml_text));
753+ }
754+
755+ TEST (SubTree, RecursiveCycle)
756+ {
757+ // clang-format off
758+
759+ static const char * xml_text = R"(
760+ <root BTCPP_format="4" main_tree_to_execute="MainTree">
761+
762+ <BehaviorTree ID="MainTree">
763+ <Sequence name="root">
764+ <AlwaysSuccess/>
765+ <SubTree ID="TreeA" />
766+ </Sequence>
767+ </BehaviorTree>
768+
769+ <BehaviorTree ID="TreeA">
770+ <Sequence name="root">
771+ <AlwaysSuccess/>
772+ <SubTree ID="TreeB" />
773+ </Sequence>
774+ </BehaviorTree>
775+
776+ <BehaviorTree ID="TreeB">
777+ <Sequence name="root">
778+ <AlwaysSuccess/>
779+ <SubTree ID="MainTree" />
780+ </Sequence>
781+ </BehaviorTree>
782+ </root>
783+ )" ;
784+
785+ // clang-format on
786+ BehaviorTreeFactory factory;
787+ std::vector<std::string> console;
788+ factory.registerNodeType <PrintToConsole>(" PrintToConsole" , &console);
789+
790+ ASSERT_ANY_THROW (auto tree = factory.createTreeFromText (xml_text));
791+ }
792+
0 commit comments