@@ -247,3 +247,51 @@ TEST(ParserTest, Enums)
247247 ASSERT_EQ (blackboard->get <int >(" color2" ), BLUE);
248248 ASSERT_EQ (blackboard->get <int >(" color3" ), GREEN);
249249}
250+
251+ enum DeviceType { BATT=1 , CONTROLLER=2 };
252+
253+
254+ BT::NodeStatus checkLevel (BT::TreeNode &self)
255+ {
256+ double percent = self.getInput <double >(" percentage" ).value ();
257+ DeviceType devType = self.getInput <DeviceType>(" deviceType" ).value ();
258+
259+ if (devType == DeviceType::BATT)
260+ {
261+ self.setOutput (" isLowBattery" , (percent < 25 ));
262+ }
263+ std::cout << " Device: " << devType << " Level: " << percent << std::endl;
264+ return BT::NodeStatus::SUCCESS;
265+ }
266+
267+ TEST (ParserTest, Enums_Issue_523)
268+ {
269+ BT::BehaviorTreeFactory factory;
270+
271+ const std::string xml_text = R"(
272+ <root BTCPP_format="4" >
273+ <BehaviorTree ID="PowerManagerT">
274+ <Sequence>
275+ <Script code=" deviceA:=BATT; deviceB:=CONTROLLER; LOW_BATT:=20 "/>
276+ <CheckLevel deviceType="{deviceA}" percentage="{LOW_BATT}" isLowBattery="{isLowBattery}"/>
277+ </Sequence>
278+ </BehaviorTree>
279+ </root> )" ;
280+
281+ factory.registerSimpleCondition (" CheckLevel" , std::bind (checkLevel, std::placeholders::_1),
282+ { BT::InputPort (" percentage" ),
283+ BT::InputPort (" deviceType" ),
284+ BT::OutputPort (" isLowBattery" )});
285+
286+ factory.registerScriptingEnums <DeviceType>();
287+
288+ auto tree = factory.createTreeFromText (xml_text);
289+ const auto status = tree.tickWhileRunning ();
290+ ASSERT_EQ (status, BT::NodeStatus::SUCCESS);
291+
292+ const auto & blackboard = tree.subtrees .front ()->blackboard ;
293+ ASSERT_EQ (blackboard->get <int >(" deviceA" ), BATT);
294+ ASSERT_EQ (blackboard->get <int >(" deviceB" ), CONTROLLER);
295+ ASSERT_EQ (blackboard->get <bool >(" isLowBattery" ), true );
296+ }
297+
0 commit comments