@@ -745,3 +745,64 @@ TEST(BlackboardTest, SetBlackboard_WithPortRemapping)
745745 // Tick till the end with no crashes
746746 ASSERT_NO_THROW (tree.tickWhileRunning (););
747747}
748+
749+ // Issue #942: getLockedPortContent should return a valid locked reference
750+ // even when the port is not explicitly declared in XML, as long as there is
751+ // a default blackboard remapping (e.g., "{=}").
752+ class ActionWithLockedPort : public SyncActionNode
753+ {
754+ public:
755+ ActionWithLockedPort (const std::string& name, const NodeConfig& config)
756+ : SyncActionNode(name, config)
757+ {}
758+
759+ NodeStatus tick () override
760+ {
761+ auto any_locked = getLockedPortContent (" value" );
762+ if (!any_locked)
763+ {
764+ locked_valid = false ;
765+ return NodeStatus::FAILURE ;
766+ }
767+ locked_valid = true ;
768+ // Assign a value through the locked reference
769+ any_locked.assign (42 );
770+ return NodeStatus::SUCCESS ;
771+ }
772+
773+ static PortsList providedPorts ()
774+ {
775+ return { BidirectionalPort<int >(" value" , " {=}" , " A value with default BB remap" ) };
776+ }
777+
778+ bool locked_valid = false ;
779+ };
780+
781+ TEST (BlackboardTest, GetLockedPortContentWithDefault_Issue942)
782+ {
783+ // XML does NOT specify the "value" port — relies on default "{=}"
784+ std::string xml_txt = R"(
785+ <root BTCPP_format="4" >
786+ <BehaviorTree ID="Main">
787+ <ActionWithLockedPort/>
788+ </BehaviorTree>
789+ </root>)" ;
790+
791+ BehaviorTreeFactory factory;
792+ factory.registerNodeType <ActionWithLockedPort>(" ActionWithLockedPort" );
793+ auto tree = factory.createTreeFromText (xml_txt);
794+ auto status = tree.tickWhileRunning ();
795+
796+ ASSERT_EQ (status, NodeStatus::SUCCESS );
797+
798+ for (const auto & node : tree.subtrees .front ()->nodes )
799+ {
800+ if (auto action = dynamic_cast <ActionWithLockedPort*>(node.get ()))
801+ {
802+ ASSERT_TRUE (action->locked_valid );
803+ }
804+ }
805+
806+ // The value should be accessible from the blackboard
807+ ASSERT_EQ (tree.rootBlackboard ()->get <int >(" value" ), 42 );
808+ }
0 commit comments