Skip to content

Commit 3376160

Browse files
committed
fix(global-parameter-loader): add gtest of global-parameter-loader
Signed-off-by: Cynthia Liu <cynthia.liu@autocore.ai>
1 parent 7122ba0 commit 3376160

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

common/global_parameter_loader/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ project(global_parameter_loader)
44
find_package(autoware_cmake REQUIRED)
55
autoware_package()
66

7+
if(BUILD_TESTING)
8+
file(GLOB_RECURSE test_files test/*.cpp)
9+
ament_add_ros_isolated_gtest(test_global_params_launch ${test_files})
10+
endif()
11+
712
ament_auto_package(
813
INSTALL_TO_SHARE
914
launch

common/global_parameter_loader/package.xml

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
<exec_depend>vehicle_info_util</exec_depend>
1414

15+
<test_depend>ament_cmake_ros</test_depend>
1516
<test_depend>ament_lint_auto</test_depend>
1617
<test_depend>autoware_lint_common</test_depend>
1718

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2023 The Autoware Foundation
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+
#include <gtest/gtest.h>
16+
#include <cstdlib>
17+
#include <iostream>
18+
#include <string>
19+
20+
TEST(TestLaunchFile, test_launch_file)
21+
{
22+
// Define the path of Python launch file
23+
std::string global_params_launch_path = "global_params.launch.py";
24+
25+
// Define the parameters you want to pass to the launch file
26+
std::string use_sim_time_param = "false";
27+
std::string vehicle_model_param = "sample_vehicle";
28+
// Construct the command to run the Python launch script with parameters
29+
std::string command = "ros2 launch global_parameter_loader " + global_params_launch_path +
30+
" use_sim_time:=" + use_sim_time_param +
31+
" vehicle_model:=" + vehicle_model_param;
32+
33+
// Use the system() function to execute the command
34+
int result = std::system(command.c_str());
35+
// Check the result of running the launch file
36+
EXPECT_EQ(result, 0);
37+
}
38+
39+
int main(int argc, char * argv[])
40+
{
41+
testing::InitGoogleTest(&argc, argv);
42+
return RUN_ALL_TESTS();
43+
}

0 commit comments

Comments
 (0)