| 52 | }; |
| 53 | |
| 54 | TEST(Enums, StrintToEnum) |
| 55 | { |
| 56 | std::string xml_txt = R"( |
| 57 | <root BTCPP_format="4" > |
| 58 | <BehaviorTree ID="Main"> |
| 59 | <Sequence> |
| 60 | <Script code=" my_color := Red "/> |
| 61 | <ActionEnum name="maybe_blue" color="Blue"/> |
| 62 | <ActionEnum name="maybe_green" color="2"/> |
| 63 | <ActionEnum name="maybe_red" color="{my_color}"/> |
| 64 | </Sequence> |
| 65 | </BehaviorTree> |
| 66 | </root>)"; |
| 67 | |
| 68 | BehaviorTreeFactory factory; |
| 69 | factory.registerNodeType<ActionEnum>("ActionEnum"); |
| 70 | factory.registerScriptingEnums<Color>(); |
| 71 | |
| 72 | auto tree = factory.createTreeFromText(xml_txt); |
| 73 | |
| 74 | NodeStatus status = tree.tickWhileRunning(); |
| 75 | |
| 76 | ASSERT_EQ(status, NodeStatus::SUCCESS); |
| 77 | |
| 78 | for(const auto& node : tree.subtrees.front()->nodes) |
| 79 | { |
| 80 | if(auto enum_node = dynamic_cast<ActionEnum*>(node.get())) |
| 81 | { |
| 82 | if(enum_node->name() == "maybe_red") |
| 83 | { |
| 84 | ASSERT_EQ(Color::Red, enum_node->color); |
| 85 | } |
| 86 | else if(enum_node->name() == "maybe_green") |
| 87 | { |
| 88 | ASSERT_EQ(Color::Green, enum_node->color); |
| 89 | } |
| 90 | else if(enum_node->name() == "maybe_blue") |
| 91 | { |
| 92 | ASSERT_EQ(Color::Blue, enum_node->color); |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | TEST(Enums, SwitchNodeWithEnum) |
| 99 | { |
nothing calls this directly
no test coverage detected