From f4c4ce820c0afabfb670f5e303675afce2d89674 Mon Sep 17 00:00:00 2001 From: Shaur Kumar Date: Tue, 22 Jul 2025 11:28:48 -0400 Subject: [PATCH] tests: added GTest to prove line number is recursively correct --- tests/gtest_factory.cpp | 102 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 101 insertions(+), 1 deletion(-) diff --git a/tests/gtest_factory.cpp b/tests/gtest_factory.cpp index 321d24ef5..b5679d729 100644 --- a/tests/gtest_factory.cpp +++ b/tests/gtest_factory.cpp @@ -2,7 +2,8 @@ #include #include #include -#include +#include "behaviortree_cpp/bt_factory.h" +#include "behaviortree_cpp/exceptions.h" #include "behaviortree_cpp/xml_parsing.h" #include "../sample_nodes/crossdoor_nodes.h" #include "../sample_nodes/dummy_nodes.h" @@ -102,6 +103,78 @@ static const char* xml_text_subtree_part2 = R"( )"; +static const char* xml_text_incorrect1 = R"( + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + )"; + +static const char* xml_text_incorrect2 = R"( + + + + + + + + + + + + + + )"; + // clang-format on TEST(BehaviorTreeFactory, NotRegisteredNode) @@ -173,6 +246,33 @@ TEST(BehaviorTreeFactory, Subtree) ASSERT_EQ(subtree->nodes[4]->name(), "SmashDoor"); } +TEST(BehaviorTreeFactory, SubtreeParsingError) +{ + BehaviorTreeFactory factory; + CrossDoor cross_door; + cross_door.registerNodes(factory); + try + { + auto tree = factory.createTreeFromText(xml_text_incorrect1); + FAIL() << "Expected exception thrown"; + } + catch(const BT::RuntimeError& e) + { + std::string error_msg = e.what(); + EXPECT_TRUE(error_msg.find("line 36") != std::string::npos); + } + try + { + auto tree = factory.createTreeFromText(xml_text_incorrect2); + FAIL() << "Expected exception thrown"; + } + catch(const BT::RuntimeError& e) + { + std::string error_msg = e.what(); + EXPECT_TRUE(error_msg.find("line 7") != std::string::npos); + } +} + TEST(BehaviorTreeFactory, Issue7) { const std::string xml_text_issue = R"(