Skip to content

Commit 53edfcb

Browse files
fix:add comm tool test
Signed-off-by: jack.song <jack.song@autocore.ai>
1 parent ebba4f7 commit 53edfcb

File tree

3 files changed

+81
-1
lines changed

3 files changed

+81
-1
lines changed

common/component_interface_tools/CMakeLists.txt

+15
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,19 @@ project(component_interface_tools)
44
find_package(autoware_cmake REQUIRED)
55
autoware_package()
66
ament_auto_add_executable(service_log_checker src/service_log_checker.cpp)
7+
8+
ament_auto_add_library(${PROJECT_NAME} SHARED
9+
src/service_log_checker.cpp
10+
)
11+
12+
if(BUILD_TESTING)
13+
ament_add_ros_isolated_gtest(test_service_log_checker
14+
test/test_service_log_checker.cpp
15+
)
16+
17+
target_link_libraries(test_service_log_checker
18+
component_interface_tools
19+
)
20+
target_include_directories(test_service_log_checker PRIVATE src)
21+
endif()
722
ament_auto_package(INSTALL_TO_SHARE launch)

common/component_interface_tools/package.xml

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
<depend>rclcpp</depend>
1818
<depend>tier4_system_msgs</depend>
1919
<depend>yaml_cpp_vendor</depend>
20-
20+
<depend>service_log_checker</depend>
21+
2122
<test_depend>ament_lint_auto</test_depend>
2223
<test_depend>autoware_lint_common</test_depend>
24+
<test_depend>ament_cmake_ros</test_depend>
2325

2426
<export>
2527
<build_type>ament_cmake</build_type>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright 2023 TIER IV, 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+
#include "gtest/gtest.h"
16+
#include "service_log_checker.hpp"
17+
#include <yaml-cpp/yaml.h>
18+
#include <memory>
19+
#include <string>
20+
21+
TEST(service,checker)
22+
{
23+
{
24+
using ServiceLog = tier4_system_msgs::msg::ServiceLog;
25+
using DiagnosticArray = diagnostic_msgs::msg::DiagnosticArray;
26+
27+
class PubManager : public rclcpp::Node
28+
{
29+
public:
30+
PubManager() : Node("test_pub_node")
31+
{
32+
pub_odom_ = create_publisher<ServiceLog>("service_log", 1);
33+
sub_odom_ = create_subscription<DiagnosticArray>("/diagnostics", 1, std::bind(&PubManager::on_service_log, this, std::placeholders::_1));
34+
}
35+
rclcpp::Publisher<ServiceLog>::SharedPtr pub_odom_;
36+
rclcpp::Subscription<DiagnosticArray>::SharedPtr sub_odom_;
37+
bool flag=false;
38+
void on_service_log(const DiagnosticArray::ConstSharedPtr msg)
39+
{
40+
if(msg->status.size()>0)
41+
{
42+
auto diag_array = msg->status[0].message.c_str();
43+
EXPECT_EQ(diag_array,"ERROR");
44+
flag=true;
45+
}
46+
}
47+
};
48+
49+
auto checker = std::make_shared<ServiceLogChecker>();
50+
51+
auto test_log = std::make_shared<PubManager>();
52+
ServiceLog log;
53+
log.type=6;
54+
log.name="test";
55+
log.node="test_node";
56+
test_log->pub_odom_->publish(log);
57+
58+
while(!test_log->flag)
59+
{
60+
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)