@@ -533,8 +533,32 @@ TEST(PortTest, DefaultInputStrings)
533533 ASSERT_EQ (status, NodeStatus::SUCCESS);
534534}
535535
536+ struct TestStruct
537+ {
538+ int a;
539+ double b;
540+ std::string c;
541+ };
536542
537- TEST (PortTest, Default_Issues_767_768)
543+ class NodeWithDefaultNullptr : public SyncActionNode
544+ {
545+ public:
546+ NodeWithDefaultNullptr (const std::string& name, const NodeConfig& config) :
547+ SyncActionNode (name, config) {}
548+
549+ NodeStatus tick () override
550+ {
551+ return NodeStatus::SUCCESS;
552+ }
553+
554+ static PortsList providedPorts ()
555+ {
556+ return {BT::InputPort< std::shared_ptr<TestStruct> >(" input" , nullptr , " default value is nullptr" )};
557+ }
558+ };
559+
560+
561+ TEST (PortTest, Default_Issues_767)
538562{
539563 using namespace BT ;
540564
@@ -545,4 +569,29 @@ TEST(PortTest, Default_Issues_767_768)
545569 ASSERT_NO_THROW (auto p = InputPort<std::shared_ptr<std::string>>(" ptr_B" , nullptr , " default nullptr" ));
546570}
547571
572+ TEST (PortTest, DefaultWronglyOverriden)
573+ {
574+ BT::BehaviorTreeFactory factory;
575+ factory.registerNodeType <NodeWithDefaultNullptr>(" NodeWithDefaultNullptr" );
576+
577+ std::string xml_txt_wrong = R"(
578+ <root BTCPP_format="4" >
579+ <BehaviorTree>
580+ <NodeWithDefaultNullptr input=""/>
581+ </BehaviorTree>
582+ </root>)" ;
583+
584+ std::string xml_txt_correct = R"(
585+ <root BTCPP_format="4" >
586+ <BehaviorTree>
587+ <NodeWithDefaultNullptr/>
588+ </BehaviorTree>
589+ </root>)" ;
548590
591+ // this should throw, because we are NOT using the default,
592+ // but overriding it with an empty string instead.
593+ // See issue 768 for reference
594+ ASSERT_ANY_THROW ( auto tree = factory.createTreeFromText (xml_txt_wrong));
595+ // This is correct
596+ ASSERT_NO_THROW ( auto tree = factory.createTreeFromText (xml_txt_correct));
597+ }
0 commit comments