Skip to content

Commit 9100079

Browse files
committed
better test
1 parent b25480c commit 9100079

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

tests/script_parser_test.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include "behaviortree_cpp/scripting/operators.hpp"
44
#include "behaviortree_cpp/bt_factory.h"
5+
#include "../sample_nodes/dummy_nodes.h"
6+
57
#include <lexy/input/string_input.hpp>
68

79
TEST(ParserTest, AnyTypes)
@@ -254,7 +256,11 @@ enum DeviceType { BATT=1, CONTROLLER=2 };
254256
BT::NodeStatus checkLevel(BT::TreeNode &self)
255257
{
256258
double percent = self.getInput<double>("percentage").value();
257-
DeviceType devType = self.getInput<DeviceType>("deviceType").value();
259+
DeviceType devType;
260+
auto res = self.getInput("deviceType", devType);
261+
if(!res) {
262+
throw std::runtime_error(res.error());
263+
}
258264

259265
if(devType == DeviceType::BATT)
260266
{
@@ -271,13 +277,19 @@ TEST(ParserTest, Enums_Issue_523)
271277
const std::string xml_text = R"(
272278
<root BTCPP_format="4" >
273279
<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>
280+
<ReactiveSequence>
281+
<Script code=" deviceA:=BATT; deviceB:=CONTROLLER; battery_level:=30 "/>
282+
<CheckLevel deviceType="{deviceA}" percentage="{battery_level}" isLowBattery="{isLowBattery}"/>
283+
<SaySomething message="FIRST low batteries!" _skipIf="!isLowBattery" />
284+
285+
<Script code=" battery_level:=20 "/>
286+
<CheckLevel deviceType="{deviceA}" percentage="{battery_level}" isLowBattery="{isLowBattery}"/>
287+
<SaySomething message="SECOND low batteries!" _skipIf="!isLowBattery" />
288+
</ReactiveSequence>
278289
</BehaviorTree>
279290
</root> )";
280291

292+
factory.registerNodeType<DummyNodes::SaySomething>("SaySomething");
281293
factory.registerSimpleCondition("CheckLevel", std::bind(checkLevel, std::placeholders::_1),
282294
{ BT::InputPort("percentage"),
283295
BT::InputPort("deviceType"),

0 commit comments

Comments
 (0)