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