From 5a6defe291016fef7cd559754ab263b08819e34a Mon Sep 17 00:00:00 2001 From: "Takagi, Isamu" Date: Thu, 6 Mar 2025 16:28:32 +0900 Subject: [PATCH] feat(autoware_utils_testing): create test utils Signed-off-by: Takagi, Isamu --- autoware_utils_testing/CMakeLists.txt | 16 ++++++++ autoware_utils_testing/README.md | 11 ++++++ .../autoware_utils_testing/gtest/ros_env.hpp | 29 ++++++++++++++ .../autoware_utils_testing/mock_node.hpp | 35 +++++++++++++++++ .../include/autoware_utils_testing/runner.hpp | 23 +++++++++++ autoware_utils_testing/package.xml | 22 +++++++++++ autoware_utils_testing/src/gtest/ros_env.cpp | 39 +++++++++++++++++++ autoware_utils_testing/test/main.cpp | 21 ++++++++++ 8 files changed, 196 insertions(+) create mode 100644 autoware_utils_testing/CMakeLists.txt create mode 100644 autoware_utils_testing/README.md create mode 100644 autoware_utils_testing/include/autoware_utils_testing/gtest/ros_env.hpp create mode 100644 autoware_utils_testing/include/autoware_utils_testing/mock_node.hpp create mode 100644 autoware_utils_testing/include/autoware_utils_testing/runner.hpp create mode 100644 autoware_utils_testing/package.xml create mode 100644 autoware_utils_testing/src/gtest/ros_env.cpp create mode 100644 autoware_utils_testing/test/main.cpp diff --git a/autoware_utils_testing/CMakeLists.txt b/autoware_utils_testing/CMakeLists.txt new file mode 100644 index 0000000..1cc6667 --- /dev/null +++ b/autoware_utils_testing/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.14) +project(autoware_utils_testing) + +find_package(autoware_cmake REQUIRED) +autoware_package() + +ament_auto_add_library(${PROJECT_NAME} SHARED + "src/gtest/ros_env.cpp" +) + +if(BUILD_TESTING) + file(GLOB_RECURSE test_files test/*.cpp) + ament_auto_add_gtest(test_${PROJECT_NAME} ${test_files}) +endif() + +ament_auto_package() diff --git a/autoware_utils_testing/README.md b/autoware_utils_testing/README.md new file mode 100644 index 0000000..a38880a --- /dev/null +++ b/autoware_utils_testing/README.md @@ -0,0 +1,11 @@ +# autoware_utils_testing + +## Overview + +The **autoware_utils** library is a comprehensive toolkit designed to facilitate the development of autonomous driving applications. +This package provides essential utilities for visualization. +It is extensively used in the Autoware project to handle common tasks such as creating markers for RViz. + +## Design + +- **`marker_helper.hpp`**: Helper functions for creating and manipulating visualization markers. diff --git a/autoware_utils_testing/include/autoware_utils_testing/gtest/ros_env.hpp b/autoware_utils_testing/include/autoware_utils_testing/gtest/ros_env.hpp new file mode 100644 index 0000000..934e5ef --- /dev/null +++ b/autoware_utils_testing/include/autoware_utils_testing/gtest/ros_env.hpp @@ -0,0 +1,29 @@ +// Copyright 2025 The Autoware Contributors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef AUTOWARE_UTILS_TESTING__GTEST__ROS_ENV_HPP_ +#define AUTOWARE_UTILS_TESTING__GTEST__ROS_ENV_HPP_ + +#include + +namespace autoware_utils_testing::gtest +{ + +// Create an environment pointor that executes rclcpp init and shutdown. +// Pass it to the AddGlobalTestEnvironment in your gtest main function. +testing::Environment * ros_env(int argc, char ** argv); + +} // namespace autoware_utils_testing::gtest + +#endif // AUTOWARE_UTILS_TESTING__GTEST__ROS_ENV_HPP_ diff --git a/autoware_utils_testing/include/autoware_utils_testing/mock_node.hpp b/autoware_utils_testing/include/autoware_utils_testing/mock_node.hpp new file mode 100644 index 0000000..d56f734 --- /dev/null +++ b/autoware_utils_testing/include/autoware_utils_testing/mock_node.hpp @@ -0,0 +1,35 @@ +// Copyright 2025 The Autoware Contributors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef AUTOWARE_UTILS_TESTING__MOCK_NODE_HPP_ +#define AUTOWARE_UTILS_TESTING__MOCK_NODE_HPP_ + +#include + +#include + +namespace autoware_utils_testing +{ + +class MockNode : public rclcpp::Node +{ +public: + explicit MockNode(const std::string & name) : Node(name) {} + +private: +}; + +} // namespace autoware_utils_testing + +#endif // AUTOWARE_UTILS_TESTING__MOCK_NODE_HPP_ diff --git a/autoware_utils_testing/include/autoware_utils_testing/runner.hpp b/autoware_utils_testing/include/autoware_utils_testing/runner.hpp new file mode 100644 index 0000000..80bb819 --- /dev/null +++ b/autoware_utils_testing/include/autoware_utils_testing/runner.hpp @@ -0,0 +1,23 @@ +// Copyright 2025 The Autoware Contributors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef AUTOWARE_UTILS_TESTING__RUNNER_HPP_ +#define AUTOWARE_UTILS_TESTING__RUNNER_HPP_ + +namespace autoware_utils_testing +{ + +} // namespace autoware_utils_testing + +#endif // AUTOWARE_UTILS_TESTING__RUNNER_HPP_ diff --git a/autoware_utils_testing/package.xml b/autoware_utils_testing/package.xml new file mode 100644 index 0000000..df1f17e --- /dev/null +++ b/autoware_utils_testing/package.xml @@ -0,0 +1,22 @@ + + + + autoware_utils_testing + 1.1.0 + The autoware_utils_testing package + Takagi, Isamu + Apache License 2.0 + + ament_cmake_auto + autoware_cmake + + gtest_vendor + rclcpp + + ament_lint_auto + autoware_lint_common + + + ament_cmake + + diff --git a/autoware_utils_testing/src/gtest/ros_env.cpp b/autoware_utils_testing/src/gtest/ros_env.cpp new file mode 100644 index 0000000..47311b0 --- /dev/null +++ b/autoware_utils_testing/src/gtest/ros_env.cpp @@ -0,0 +1,39 @@ +// Copyright 2025 The Autoware Contributors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "autoware_utils_testing/gtest/ros_env.hpp" + +#include + +namespace autoware_utils_testing::gtest +{ + +class RclcppEnvironment : public testing::Environment +{ +public: + RclcppEnvironment(int argc, char ** argv) : argc(argc), argv(argv) {} + void SetUp() override { rclcpp::init(argc, argv); } + void TearDown() override { rclcpp::shutdown(); } + +private: + int argc; + char ** argv; +}; + +testing::Environment * ros_env(int argc, char ** argv) +{ + return new RclcppEnvironment(argc, argv); +} + +} // namespace autoware_utils_testing::gtest diff --git a/autoware_utils_testing/test/main.cpp b/autoware_utils_testing/test/main.cpp new file mode 100644 index 0000000..7c283b2 --- /dev/null +++ b/autoware_utils_testing/test/main.cpp @@ -0,0 +1,21 @@ +// Copyright 2025 The Autoware Contributors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +int main(int argc, char ** argv) +{ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +}