|
| 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