Skip to content

Commit 1c2c59d

Browse files
feat: add common interface utils test (autowarefoundation#5173)
* add interface utils test Signed-off-by: jack.song <jack.song@autocore.ai> * style(pre-commit): autofix --------- Signed-off-by: jack.song <jack.song@autocore.ai> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 81ede03 commit 1c2c59d

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

common/component_interface_utils/CMakeLists.txt

+20
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,24 @@ project(component_interface_utils)
33

44
find_package(autoware_cmake REQUIRED)
55
autoware_package()
6+
7+
include_directories(
8+
include
9+
SYSTEM
10+
${rclcpp_INCLUDE_DIRS}
11+
${rosidl_runtime_cpp_INCLUDE_DIRS}
12+
${rcl_INCLUDE_DIRS}
13+
${autoware_adapi_v1_msgs_INCLUDE_DIRS}
14+
)
15+
16+
if(BUILD_TESTING)
17+
ament_add_ros_isolated_gtest(test_component_interface_utils
18+
test/test_component_interface_utils.cpp
19+
)
20+
21+
target_include_directories(test_component_interface_utils
22+
PRIVATE include
23+
)
24+
endif()
25+
626
ament_auto_package()

common/component_interface_utils/package.xml

100644100755
+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<depend>rclcpp</depend>
2020
<depend>rclcpp_components</depend>
2121

22+
<test_depend>ament_cmake_ros</test_depend>
2223
<test_depend>ament_lint_auto</test_depend>
2324
<test_depend>autoware_lint_common</test_depend>
2425

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright 2023 The Autoware Contributors
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 "component_interface_utils/rclcpp/exceptions.hpp"
16+
#include "component_interface_utils/specs.hpp"
17+
#include "component_interface_utils/status.hpp"
18+
#include "gtest/gtest.h"
19+
20+
TEST(interface, utils)
21+
{
22+
{
23+
using component_interface_utils::ServiceException;
24+
using ResponseStatus = autoware_adapi_v1_msgs::msg::ResponseStatus;
25+
using ResponseStatusCode = ResponseStatus::_code_type;
26+
27+
ResponseStatusCode code = 10;
28+
const std::string message = "test_exception";
29+
ServiceException service(code, message);
30+
ResponseStatus code_back;
31+
code_back = service.status();
32+
EXPECT_EQ(code_back.code, code);
33+
EXPECT_EQ(code_back.message, message);
34+
}
35+
36+
{
37+
using component_interface_utils::ServiceException;
38+
using ResponseStatus = autoware_adapi_v1_msgs::msg::ResponseStatus;
39+
using ResponseStatusCode = ResponseStatus::_code_type;
40+
41+
ResponseStatusCode code = 10;
42+
const std::string message = "test_exception";
43+
ServiceException service(code, message);
44+
ResponseStatus code_set;
45+
service.set(code_set);
46+
EXPECT_EQ(code_set.code, code);
47+
EXPECT_EQ(code_set.message, message);
48+
}
49+
50+
{
51+
using component_interface_utils::ServiceException;
52+
using ResponseStatus = autoware_adapi_v1_msgs::msg::ResponseStatus;
53+
using ResponseStatusCode = ResponseStatus::_code_type;
54+
using component_interface_utils::status::copy;
55+
56+
class status_test
57+
{
58+
public:
59+
status_test(ResponseStatusCode code, const std::string & message, bool success = false)
60+
{
61+
status.code = code;
62+
status.message = message;
63+
status.success = success;
64+
}
65+
ResponseStatus status;
66+
};
67+
68+
const status_test status_in(10, "test_exception", true);
69+
auto status_copy = std::make_shared<status_test>(100, "test_exception_copy", false);
70+
copy(&status_in, status_copy);
71+
72+
EXPECT_EQ(status_in.status.code, status_copy->status.code);
73+
EXPECT_EQ(status_in.status.message, status_copy->status.message);
74+
EXPECT_EQ(status_in.status.success, status_copy->status.success);
75+
}
76+
}

0 commit comments

Comments
 (0)