Skip to content

Commit 497e09e

Browse files
author
Davide Iafrate
committed
test(ros_gz_bridge): cover dynamic bridge discovery
Generated-by: OpenAI Codex (GPT-5) Signed-off-by: Davide Iafrate <dvde.iafrate98@gmail.com>
1 parent 9fee104 commit 497e09e

3 files changed

Lines changed: 392 additions & 0 deletions

File tree

ros_gz_bridge/CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,15 @@ if(BUILD_TESTING)
321321
target_include_directories(test_launch_action_subscriber
322322
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test/subscribers)
323323

324+
add_executable(test_dynamic_bridge test/test_dynamic_bridge.cpp)
325+
target_link_libraries(test_dynamic_bridge
326+
${GTEST_LIBRARIES}
327+
gz-msgs::core
328+
gz-transport::core
329+
rclcpp::rclcpp
330+
${std_msgs_TARGETS}
331+
)
332+
324333
install(TARGETS
325334
test_launch_action_subscriber
326335
test_ros_publisher
@@ -329,6 +338,7 @@ if(BUILD_TESTING)
329338
test_gz_subscriber
330339
test_gz_server
331340
test_ros_client
341+
test_dynamic_bridge
332342
DESTINATION lib/${PROJECT_NAME}
333343
)
334344

@@ -354,6 +364,22 @@ if(BUILD_TESTING)
354364
TIMEOUT 200
355365
)
356366

367+
add_launch_test(test/launch/test_dynamic_bridge.launch.py
368+
TARGET test_dynamic_bridge_gz_to_ros
369+
TIMEOUT 200
370+
ARGS
371+
"direction:=GZ_TO_ROS"
372+
"gtest_filter:=-DynamicBridgeTest.BridgesBidirectionally"
373+
)
374+
375+
add_launch_test(test/launch/test_dynamic_bridge.launch.py
376+
TARGET test_dynamic_bridge_bidirectional
377+
TIMEOUT 200
378+
ARGS
379+
"direction:=BIDIRECTIONAL"
380+
"gtest_filter:=DynamicBridgeTest.BridgesBidirectionally"
381+
)
382+
357383
ament_add_gtest(${PROJECT_NAME}_bridge_config test/bridge_config.cpp
358384
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
359385
target_include_directories(${PROJECT_NAME}_bridge_config PRIVATE src)
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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

Comments
 (0)