Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add common interface tools test #5175

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions common/component_interface_tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,19 @@ project(component_interface_tools)
find_package(autoware_cmake REQUIRED)
autoware_package()
ament_auto_add_executable(service_log_checker src/service_log_checker.cpp)

ament_auto_add_library(${PROJECT_NAME} SHARED
src/service_log_checker.cpp
)

if(BUILD_TESTING)
ament_add_ros_isolated_gtest(test_service_log_checker
test/test_service_log_checker.cpp
)

target_link_libraries(test_service_log_checker
component_interface_tools
)
target_include_directories(test_service_log_checker PRIVATE src)
endif()
ament_auto_package(INSTALL_TO_SHARE launch)
2 changes: 2 additions & 0 deletions common/component_interface_tools/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
<depend>diagnostic_updater</depend>
<depend>fmt</depend>
<depend>rclcpp</depend>
<depend>service_log_checker</depend>
<depend>tier4_system_msgs</depend>
<depend>yaml_cpp_vendor</depend>

<test_depend>ament_cmake_ros</test_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>autoware_lint_common</test_depend>

Expand Down
63 changes: 63 additions & 0 deletions common/component_interface_tools/test/test_service_log_checker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright 2023 TIER IV, Inc.
//
// 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 "gtest/gtest.h"
#include "service_log_checker.hpp"

#include <yaml-cpp/yaml.h>

#include <memory>
#include <string>

TEST(service, checker)
{
{
using ServiceLog = tier4_system_msgs::msg::ServiceLog;
using DiagnosticArray = diagnostic_msgs::msg::DiagnosticArray;

class PubManager : public rclcpp::Node
{
public:
PubManager() : Node("test_pub_node")
{
pub_odom_ = create_publisher<ServiceLog>("service_log", 1);
sub_odom_ = create_subscription<DiagnosticArray>(
"/diagnostics", 1, std::bind(&PubManager::on_service_log, this, std::placeholders::_1));
}
rclcpp::Publisher<ServiceLog>::SharedPtr pub_odom_;
rclcpp::Subscription<DiagnosticArray>::SharedPtr sub_odom_;
bool flag = false;
void on_service_log(const DiagnosticArray::ConstSharedPtr msg)
{
if (msg->status.size() > 0) {
auto diag_array = msg->status[0].message.c_str();
EXPECT_EQ(diag_array, "ERROR");
flag = true;
}
}
};

auto checker = std::make_shared<ServiceLogChecker>();

auto test_log = std::make_shared<PubManager>();
ServiceLog log;
log.type = 6;
log.name = "test";
log.node = "test_node";
test_log->pub_odom_->publish(log);

while (!test_log->flag) {
}
}
}
Loading