@@ -665,4 +665,53 @@ mod tests {
665665 assert_eq ! ( expected_qos. reliability, qos. reliability) ;
666666 assert_eq ! ( qos. reliability, QoSReliabilityPolicy :: BestEffort ) ;
667667 }
668+
669+ #[ test]
670+ fn test_setting_qos_from_parameters ( ) {
671+ use crate :: vendor:: example_interfaces:: msg:: Empty ;
672+ use crate :: * ;
673+
674+ let args = [
675+ "--ros-args" ,
676+ "-p" ,
677+ "qos_reliability:=best_effort" ,
678+ ] . map ( ToString :: to_string) ;
679+
680+ let context = Context :: new ( args, InitOptions :: default ( ) ) . unwrap ( ) ;
681+
682+ let executor = context. create_basic_executor ( ) ;
683+
684+ let node = executor
685+ . create_node ( & format ! ( "test_setting_qos_from_parameters_{}" , line!( ) ) )
686+ . unwrap ( ) ;
687+
688+ let qos_reliability_str = node
689+ . declare_parameter :: < Arc < str > > ( "qos_reliability" )
690+ . default ( "best_effort" . into ( ) )
691+ . mandatory ( )
692+ . unwrap ( )
693+ . get ( ) ;
694+
695+ let mut expected_qos = QOS_PROFILE_DEFAULT ;
696+ expected_qos. reliability = match & * qos_reliability_str {
697+ "reliable" => QoSReliabilityPolicy :: Reliable ,
698+ "best_effort" => QoSReliabilityPolicy :: BestEffort ,
699+ "best_available" => QoSReliabilityPolicy :: BestAvailable ,
700+ x => panic ! ( "unknown reliability string: {x}" ) ,
701+ } ;
702+
703+ assert_eq ! ( expected_qos. reliability, QoSReliabilityPolicy :: BestEffort ) ;
704+ let subscription = node
705+ . create_subscription (
706+ "test_setting_qos_from_parameters_topic" . qos ( expected_qos) ,
707+ |_: Empty | {
708+ // Do nothing
709+ }
710+ )
711+ . unwrap ( ) ;
712+
713+ let qos = subscription. qos ( ) ;
714+ assert_eq ! ( expected_qos. reliability, qos. reliability) ;
715+ assert_eq ! ( qos. reliability, QoSReliabilityPolicy :: BestEffort ) ;
716+ }
668717}
0 commit comments