@@ -371,7 +371,7 @@ TEST(ParserTest, Issue605_whitespaces)
371
371
<Script code=" sub_value:=false " />
372
372
</BehaviorTree>
373
373
374
- <BehaviorTree ID="MyMainTree ">
374
+ <BehaviorTree ID="MainTree ">
375
375
<Sequence>
376
376
<Script code=" my_value:=true " />
377
377
<SubTree ID="MySubtree" sub_value="{my_value} "/>
@@ -380,7 +380,7 @@ TEST(ParserTest, Issue605_whitespaces)
380
380
</root> )" ;
381
381
382
382
factory.registerBehaviorTreeFromText (xml_text);
383
- auto tree = factory.createTree (" MyMainTree " );
383
+ auto tree = factory.createTree (" MainTree " );
384
384
const auto status = tree.tickWhileRunning ();
385
385
386
386
for (auto const & subtree: tree.subtrees )
@@ -391,3 +391,73 @@ TEST(ParserTest, Issue605_whitespaces)
391
391
ASSERT_EQ (status, BT::NodeStatus::SUCCESS);
392
392
ASSERT_EQ (false , tree.rootBlackboard ()->get <bool >(" my_value" ));
393
393
}
394
+
395
+
396
+ class ComparisonNode : public BT ::ConditionNode
397
+ {
398
+ public:
399
+
400
+ ComparisonNode (const std::string& name, const BT::NodeConfiguration& config):
401
+ BT::ConditionNode (name, config) {}
402
+
403
+ static BT::PortsList providedPorts ()
404
+ {
405
+ return {BT::InputPort<int32_t >(" first" ),
406
+ BT::InputPort<int32_t >(" second" ),
407
+ BT::InputPort<std::string>(" operator" )};
408
+ }
409
+
410
+ BT::NodeStatus tick () override
411
+ {
412
+ int32_t firstValue = 0 ;
413
+ int32_t secondValue = 0 ;
414
+ std::string inputOperator;
415
+ if (!getInput (" first" , firstValue) ||
416
+ !getInput (" second" , secondValue) ||
417
+ !getInput (" operator" , inputOperator))
418
+ {
419
+ throw RuntimeError (" can't access input" );
420
+ }
421
+ if ( (inputOperator == " ==" && firstValue == secondValue) ||
422
+ (inputOperator == " !=" && firstValue != secondValue) ||
423
+ (inputOperator == " <=" && firstValue <= secondValue) ||
424
+ (inputOperator == " >=" && firstValue <= secondValue) ||
425
+ (inputOperator == " <" && firstValue < secondValue) ||
426
+ (inputOperator == " >" && firstValue < secondValue) )
427
+ {
428
+ return BT::NodeStatus::SUCCESS;
429
+ }
430
+ // skipping the rest of the implementation
431
+ return BT::NodeStatus::FAILURE;
432
+ }
433
+ };
434
+
435
+ TEST (BlackboardTest, IssueSetBlackboard)
436
+ {
437
+ BT::BehaviorTreeFactory factory;
438
+
439
+ const std::string xml_text = R"(
440
+ <root BTCPP_format="4" >
441
+ <BehaviorTree ID="MySubtree">
442
+ <ComparisonNode first="{value}" second="42" operator="==" />
443
+ </BehaviorTree>
444
+
445
+ <BehaviorTree ID="MainTree">
446
+ <Sequence>
447
+ <SetBlackboard value="42" output_key="value" />
448
+ <SubTree ID="MySubtree" value="{value} "/>
449
+ </Sequence>
450
+ </BehaviorTree>
451
+ </root> )" ;
452
+
453
+ factory.registerNodeType <ComparisonNode>(" ComparisonNode" );
454
+ factory.registerBehaviorTreeFromText (xml_text);
455
+ auto tree = factory.createTree (" MainTree" );
456
+ const auto status = tree.tickWhileRunning ();
457
+
458
+ ASSERT_EQ (status, BT::NodeStatus::SUCCESS);
459
+ ASSERT_EQ (42 , tree.rootBlackboard ()->get <int >(" value" ));
460
+ }
461
+
462
+
463
+
0 commit comments