|
| 1 | +// SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES |
| 2 | +// Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 3 | +// |
| 4 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +// you may not use this file except in compliance with the License. |
| 6 | +// You may obtain a copy of the License at |
| 7 | +// |
| 8 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +// |
| 10 | +// Unless required by applicable law or agreed to in writing, software |
| 11 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +// See the License for the specific language governing permissions and |
| 14 | +// limitations under the License. |
| 15 | +// |
| 16 | +// SPDX-License-Identifier: Apache-2.0 |
| 17 | + |
| 18 | +#include <gmock/gmock.h> |
| 19 | +#include "centerpose_decoder_node.hpp" |
| 20 | +#include "rclcpp/rclcpp.hpp" |
| 21 | + |
| 22 | +// Objective: to cover code lines where exceptions are thrown |
| 23 | +// Approach: send Invalid Arguments for node parameters to trigger the exception |
| 24 | + |
| 25 | + |
| 26 | +TEST(centerpose_decoder_node_test, test_invalid_output_field_size) |
| 27 | +{ |
| 28 | + rclcpp::init(0, nullptr); |
| 29 | + rclcpp::NodeOptions options; |
| 30 | + EXPECT_THROW( |
| 31 | + { |
| 32 | + try { |
| 33 | + nvidia::isaac_ros::centerpose::CenterPoseDecoderNode centerpose_decoder_node(options); |
| 34 | + } catch (const std::invalid_argument & e) { |
| 35 | + EXPECT_THAT(e.what(), testing::HasSubstr("Error: received invalid output field size")); |
| 36 | + throw; |
| 37 | + } catch (const rclcpp::exceptions::InvalidParameterValueException & e) { |
| 38 | + EXPECT_THAT(e.what(), testing::HasSubstr("No parameter value set")); |
| 39 | + throw; |
| 40 | + } |
| 41 | + }, std::invalid_argument); |
| 42 | + rclcpp::shutdown(); |
| 43 | +} |
| 44 | + |
| 45 | +TEST(centerpose_decoder_node_test, test_cuboid_scaling_factor) |
| 46 | +{ |
| 47 | + rclcpp::init(0, nullptr); |
| 48 | + rclcpp::NodeOptions options; |
| 49 | + options.append_parameter_override("output_field_size", std::vector<int64_t>{128, 128}); |
| 50 | + options.append_parameter_override("cuboid_scaling_factor", 0.0); |
| 51 | + EXPECT_THROW( |
| 52 | + { |
| 53 | + try { |
| 54 | + nvidia::isaac_ros::centerpose::CenterPoseDecoderNode centerpose_decoder_node(options); |
| 55 | + } catch (const std::invalid_argument & e) { |
| 56 | + EXPECT_THAT( |
| 57 | + e.what(), |
| 58 | + testing::HasSubstr("Error: received a less than or equal to zero cuboid scaling factor")); |
| 59 | + throw; |
| 60 | + } catch (const rclcpp::exceptions::InvalidParameterValueException & e) { |
| 61 | + EXPECT_THAT(e.what(), testing::HasSubstr("No parameter value set")); |
| 62 | + throw; |
| 63 | + } |
| 64 | + }, std::invalid_argument); |
| 65 | + rclcpp::shutdown(); |
| 66 | +} |
| 67 | + |
| 68 | +TEST(centerpose_decoder_node_test, test_score_threshold) |
| 69 | +{ |
| 70 | + rclcpp::init(0, nullptr); |
| 71 | + rclcpp::NodeOptions options; |
| 72 | + options.append_parameter_override("output_field_size", std::vector<int64_t>{128, 128}); |
| 73 | + options.append_parameter_override("cuboid_scaling_factor", 1.0); |
| 74 | + options.append_parameter_override("score_threshold", 1.0); |
| 75 | + EXPECT_THROW( |
| 76 | + { |
| 77 | + try { |
| 78 | + nvidia::isaac_ros::centerpose::CenterPoseDecoderNode centerpose_decoder_node(options); |
| 79 | + } catch (const std::invalid_argument & e) { |
| 80 | + EXPECT_THAT( |
| 81 | + e.what(), |
| 82 | + testing::HasSubstr("Error: received score threshold greater or equal to 1.0")); |
| 83 | + throw; |
| 84 | + } catch (const rclcpp::exceptions::InvalidParameterValueException & e) { |
| 85 | + EXPECT_THAT(e.what(), testing::HasSubstr("No parameter value set")); |
| 86 | + throw; |
| 87 | + } |
| 88 | + }, std::invalid_argument); |
| 89 | + rclcpp::shutdown(); |
| 90 | +} |
| 91 | + |
| 92 | + |
| 93 | +int main(int argc, char ** argv) |
| 94 | +{ |
| 95 | + testing::InitGoogleTest(&argc, argv); |
| 96 | + return RUN_ALL_TESTS(); |
| 97 | +} |
0 commit comments