|
| 1 | +# Copyright 2026 Open Source Robotics Foundation, Inc. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import unittest |
| 16 | + |
| 17 | +from launch import LaunchDescription |
| 18 | +from launch.actions import DeclareLaunchArgument, SetEnvironmentVariable |
| 19 | +from launch.substitutions import LaunchConfiguration |
| 20 | +from launch_ros.actions import Node |
| 21 | + |
| 22 | +import launch_testing |
| 23 | + |
| 24 | + |
| 25 | +def generate_test_description(): |
| 26 | + bridge = Node( |
| 27 | + package='ros_gz_bridge', |
| 28 | + executable='parameter_bridge', |
| 29 | + parameters=[{ |
| 30 | + 'create_dynamic_bridges': True, |
| 31 | + 'dynamic_bridge_direction': LaunchConfiguration('direction'), |
| 32 | + 'subscription_heartbeat': 50, |
| 33 | + }], |
| 34 | + output='screen', |
| 35 | + ) |
| 36 | + process_under_test = Node( |
| 37 | + package='ros_gz_bridge', |
| 38 | + executable='test_dynamic_bridge', |
| 39 | + arguments=[['--gtest_filter=', LaunchConfiguration('gtest_filter')]], |
| 40 | + output='screen', |
| 41 | + ) |
| 42 | + |
| 43 | + return LaunchDescription([ |
| 44 | + SetEnvironmentVariable('GZ_PARTITION', 'ros_gz_dynamic_bridge_test'), |
| 45 | + SetEnvironmentVariable('ROS_DOMAIN_ID', '42'), |
| 46 | + DeclareLaunchArgument('direction'), |
| 47 | + DeclareLaunchArgument('gtest_filter'), |
| 48 | + bridge, |
| 49 | + process_under_test, |
| 50 | + launch_testing.util.KeepAliveProc(), |
| 51 | + launch_testing.actions.ReadyToTest(), |
| 52 | + ]), locals() |
| 53 | + |
| 54 | + |
| 55 | +class DynamicBridgeTest(unittest.TestCase): |
| 56 | + |
| 57 | + def test_termination(self, process_under_test, proc_info): |
| 58 | + proc_info.assertWaitForShutdown(process=process_under_test, timeout=200) |
| 59 | + |
| 60 | + |
| 61 | +@launch_testing.post_shutdown_test() |
| 62 | +class DynamicBridgeTestAfterShutdown(unittest.TestCase): |
| 63 | + |
| 64 | + def test_exit_code(self, process_under_test, proc_info): |
| 65 | + launch_testing.asserts.assertExitCodes( |
| 66 | + proc_info, |
| 67 | + [launch_testing.asserts.EXIT_OK], |
| 68 | + process_under_test, |
| 69 | + ) |
0 commit comments