Skip to content

Commit c09d6d5

Browse files
test(test_node): cover script enum resolution (#1166)
1 parent 6fe6dcd commit c09d6d5

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

‎tests/gtest_substitution.cpp‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ const char* json_text = R"(
3030
}
3131
)";
3232

33+
const char* single_action_xml = R"(
34+
<root BTCPP_format="4">
35+
<BehaviorTree ID="MainTree">
36+
<AlwaysSuccess name="action_A"/>
37+
</BehaviorTree>
38+
</root>
39+
)";
40+
3341
} // namespace
3442

3543
TEST(Substitution, Parser)
@@ -58,6 +66,42 @@ TEST(Substitution, Parser)
5866
ASSERT_EQ(*std::get_if<std::string>(&rules.at("actionC")), "NotAConfig");
5967
}
6068

69+
TEST(Substitution, TestNodePostScriptUsesRegisteredEnums)
70+
{
71+
BehaviorTreeFactory factory;
72+
factory.registerScriptingEnum("EXPECTED_VALUE", 42);
73+
factory.registerBehaviorTreeFromText(single_action_xml);
74+
75+
TestNodeConfig test_config;
76+
test_config.return_status = NodeStatus::SUCCESS;
77+
test_config.post_script = "observed := EXPECTED_VALUE";
78+
factory.addSubstitutionRule("action_A", test_config);
79+
80+
auto blackboard = Blackboard::create();
81+
auto tree = factory.createTree("MainTree", blackboard);
82+
83+
ASSERT_EQ(tree.tickWhileRunning(), NodeStatus::SUCCESS);
84+
ASSERT_EQ(blackboard->get<int>("observed"), 42);
85+
}
86+
87+
TEST(Substitution, TestNodePostScriptReadsStatusNamedBlackboardKey)
88+
{
89+
BehaviorTreeFactory factory;
90+
factory.registerBehaviorTreeFromText(single_action_xml);
91+
92+
TestNodeConfig test_config;
93+
test_config.return_status = NodeStatus::SUCCESS;
94+
test_config.post_script = "observed := SUCCESS";
95+
factory.addSubstitutionRule("action_A", test_config);
96+
97+
auto blackboard = Blackboard::create();
98+
blackboard->set("SUCCESS", 99);
99+
auto tree = factory.createTree("MainTree", blackboard);
100+
101+
ASSERT_EQ(tree.tickWhileRunning(), NodeStatus::SUCCESS);
102+
ASSERT_EQ(blackboard->get<int>("observed"), 99);
103+
}
104+
61105
// Regression test for issue #934: segfault when substituting a SubTree node
62106
TEST(Substitution, SubTreeNodeSubstitution)
63107
{

0 commit comments

Comments
 (0)