forked from BehaviorTree/BehaviorTree.CPP
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add the ability to load substitution rules from JSON
- Loading branch information
1 parent
d7073b8
commit 2371eac
Showing
6 changed files
with
201 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"TestNodeConfigs": { | ||
"MyTest": { | ||
"async_delay": 2000, | ||
"return_status": "SUCCESS", | ||
"post_script": "msg ='message SUBSTITUED'" | ||
} | ||
}, | ||
|
||
"SubstitutionRules": { | ||
"mysub/action_*": "TestAction", | ||
"talk": "TestSaySomething", | ||
"last_action": "MyTest" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include <gtest/gtest.h> | ||
#include "behaviortree_cpp/bt_factory.h" | ||
|
||
using namespace BT; | ||
|
||
static const char* json_text = R"( | ||
{ | ||
"TestNodeConfigs": { | ||
"TestA": { | ||
"async_delay": 2000, | ||
"return_status": "SUCCESS", | ||
"post_script": "msg ='message SUBSTITUED'" | ||
}, | ||
"TestB": { | ||
"return_status": "FAILURE" | ||
} | ||
}, | ||
"SubstitutionRules": { | ||
"actionA": "TestA", | ||
"actionB": "TestB", | ||
"actionC": "NotAConfig" | ||
} | ||
} | ||
)"; | ||
|
||
TEST(Substitution, Parser) | ||
{ | ||
BehaviorTreeFactory factory; | ||
|
||
factory.loadSubstitutionRuleFromJSON(json_text); | ||
|
||
const auto& rules = factory.substitutionRules(); | ||
|
||
ASSERT_EQ(rules.size(), 3); | ||
ASSERT_EQ(rules.count("actionA"), 1); | ||
ASSERT_EQ(rules.count("actionB"), 1); | ||
ASSERT_EQ(rules.count("actionC"), 1); | ||
|
||
auto configA = std::get_if<TestNodeConfig>(&rules.at("actionA")); | ||
ASSERT_EQ(configA->return_status, NodeStatus::SUCCESS); | ||
ASSERT_EQ(configA->async_delay, std::chrono::milliseconds(2000)); | ||
ASSERT_EQ(configA->post_script, "msg ='message SUBSTITUED'"); | ||
|
||
auto configB = std::get_if<TestNodeConfig>(&rules.at("actionB")); | ||
ASSERT_EQ(configB->return_status, NodeStatus::FAILURE); | ||
ASSERT_EQ(configB->async_delay, std::chrono::milliseconds(0)); | ||
ASSERT_TRUE(configB->post_script.empty()); | ||
|
||
ASSERT_EQ(*std::get_if<std::string>(&rules.at("actionC")), "NotAConfig"); | ||
} |