Skip to content

Commit 44a1eba

Browse files
authored
Jazzy compatibility added (#31)
1 parent 32c91e7 commit 44a1eba

File tree

16 files changed

+97
-35
lines changed

16 files changed

+97
-35
lines changed

deep_conversions/test/test_conversions.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
#include <string>
1919
#include <vector>
2020

21-
#include <catch2/catch.hpp>
2221
#include <deep_conversions/image_conversions.hpp>
2322
#include <deep_conversions/imu_conversions.hpp>
2423
#include <deep_conversions/laserscan_conversions.hpp>
2524
#include <deep_conversions/pointcloud_conversions.hpp>
25+
#include <deep_test/compat.hpp>
2626
#include <deep_test/deep_test.hpp>
2727
#include <sensor_msgs/msg/image.hpp>
2828
#include <sensor_msgs/msg/imu.hpp>
@@ -346,16 +346,16 @@ TEST_CASE_METHOD(deep_ros::test::MockBackendFixture, "IMU conversion", "[convers
346346

347347
// Verify data order: [qx, qy, qz, qw, ax, ay, az, gx, gy, gz]
348348
float * data = static_cast<float *>(tensor.data());
349-
REQUIRE(data[0] == Approx(0.1f)); // qx
350-
REQUIRE(data[1] == Approx(0.2f)); // qy
351-
REQUIRE(data[2] == Approx(0.3f)); // qz
352-
REQUIRE(data[3] == Approx(0.9f)); // qw
353-
REQUIRE(data[4] == Approx(1.0f)); // ax
354-
REQUIRE(data[5] == Approx(2.0f)); // ay
355-
REQUIRE(data[6] == Approx(9.8f)); // az
356-
REQUIRE(data[7] == Approx(0.01f)); // gx
357-
REQUIRE(data[8] == Approx(0.02f)); // gy
358-
REQUIRE(data[9] == Approx(0.03f)); // gz
349+
REQUIRE(data[0] == CATCH_APPROX(0.1f)); // qx
350+
REQUIRE(data[1] == CATCH_APPROX(0.2f)); // qy
351+
REQUIRE(data[2] == CATCH_APPROX(0.3f)); // qz
352+
REQUIRE(data[3] == CATCH_APPROX(0.9f)); // qw
353+
REQUIRE(data[4] == CATCH_APPROX(1.0f)); // ax
354+
REQUIRE(data[5] == CATCH_APPROX(2.0f)); // ay
355+
REQUIRE(data[6] == CATCH_APPROX(9.8f)); // az
356+
REQUIRE(data[7] == CATCH_APPROX(0.01f)); // gx
357+
REQUIRE(data[8] == CATCH_APPROX(0.02f)); // gy
358+
REQUIRE(data[9] == CATCH_APPROX(0.03f)); // gz
359359
}
360360
}
361361

@@ -435,9 +435,9 @@ TEST_CASE_METHOD(
435435
// Verify data is in HWC order
436436
const float * tensor_data = tensor_hwc.data_as<float>();
437437
// Check pixel at (0,0): should have channels [0, 1, 2] values
438-
REQUIRE(tensor_data[0] == Approx(0.0f)); // Channel 0
439-
REQUIRE(tensor_data[1] == Approx(1.0f)); // Channel 1
440-
REQUIRE(tensor_data[2] == Approx(2.0f)); // Channel 2
438+
REQUIRE(tensor_data[0] == CATCH_APPROX(0.0f)); // Channel 0
439+
REQUIRE(tensor_data[1] == CATCH_APPROX(1.0f)); // Channel 1
440+
REQUIRE(tensor_data[2] == CATCH_APPROX(2.0f)); // Channel 2
441441
}
442442

443443
SECTION("CHW layout for ONNX models")
@@ -472,15 +472,15 @@ TEST_CASE_METHOD(
472472
const float * tensor_data = tensor_chw.data_as<float>();
473473
// Check that channel 0 comes first (all channel 0 values before channel 1)
474474
// At (h=0, w=0), channel 0 should be at index 0
475-
REQUIRE(tensor_data[0] == Approx(0.0f)); // h=0, w=0, c=0
475+
REQUIRE(tensor_data[0] == CATCH_APPROX(0.0f)); // h=0, w=0, c=0
476476
// At (h=0, w=1), channel 0 should be at index 1
477-
REQUIRE(tensor_data[1] == Approx(10.0f)); // h=0, w=1, c=0
477+
REQUIRE(tensor_data[1] == CATCH_APPROX(10.0f)); // h=0, w=1, c=0
478478
// At (h=1, w=0), channel 0 should be at index 32
479-
REQUIRE(tensor_data[32] == Approx(1000.0f)); // h=1, w=0, c=0
479+
REQUIRE(tensor_data[32] == CATCH_APPROX(1000.0f)); // h=1, w=0, c=0
480480

481481
// Check that channel 1 starts after all channel 0 data
482482
size_t channel1_start = 32 * 32;
483-
REQUIRE(tensor_data[channel1_start] == Approx(1.0f)); // h=0, w=0, c=1
483+
REQUIRE(tensor_data[channel1_start] == CATCH_APPROX(1.0f)); // h=0, w=0, c=1
484484
}
485485

486486
SECTION("Batch conversion with CHW layout")

deep_object_detection/src/deep_object_detection_node.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414

1515
#include "deep_object_detection/deep_object_detection_node.hpp"
1616

17-
#include <cv_bridge/cv_bridge.h>
17+
#if __has_include(<cv_bridge/cv_bridge.hpp>)
18+
#include <cv_bridge/cv_bridge.hpp>
19+
#else
20+
#include <cv_bridge/cv_bridge.h>
21+
#endif
1822

1923
#include <algorithm>
2024
#include <chrono>

deep_object_detection/test/test_deep_object_detection_node.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
#include <string>
4242
#include <vector>
4343

44-
#include <catch2/catch.hpp>
4544
#include <deep_object_detection/deep_object_detection_node.hpp>
45+
#include <deep_test/compat.hpp>
4646
#include <deep_test/deep_test.hpp>
4747
#include <lifecycle_msgs/msg/state.hpp>
4848
#include <rclcpp/rclcpp.hpp>
@@ -161,8 +161,8 @@ TEST_CASE_METHOD(
161161
REQUIRE(node->get_parameter("Preprocessing.color_format").as_string() == "rgb");
162162

163163
// Postprocessing parameters
164-
REQUIRE(node->get_parameter("Postprocessing.score_threshold").as_double() == Approx(0.25));
165-
REQUIRE(node->get_parameter("Postprocessing.nms_iou_threshold").as_double() == Approx(0.45));
164+
REQUIRE(node->get_parameter("Postprocessing.score_threshold").as_double() == CATCH_APPROX(0.25));
165+
REQUIRE(node->get_parameter("Postprocessing.nms_iou_threshold").as_double() == CATCH_APPROX(0.45));
166166
REQUIRE(node->get_parameter("Postprocessing.score_activation").as_string() == "sigmoid");
167167
REQUIRE(node->get_parameter("Postprocessing.enable_nms").as_bool() == true);
168168
REQUIRE(node->get_parameter("Postprocessing.class_score_mode").as_string() == "all_classes");
@@ -230,15 +230,15 @@ TEST_CASE_METHOD(
230230
auto params = std::vector<rclcpp::Parameter>{rclcpp::Parameter("Postprocessing.score_threshold", 0.5)};
231231
auto result = node->set_parameters(params);
232232
REQUIRE(result[0].successful == true);
233-
REQUIRE(node->get_parameter("Postprocessing.score_threshold").as_double() == Approx(0.5));
233+
REQUIRE(node->get_parameter("Postprocessing.score_threshold").as_double() == CATCH_APPROX(0.5));
234234
}
235235

236236
SECTION("NMS IoU threshold can be configured")
237237
{
238238
auto params = std::vector<rclcpp::Parameter>{rclcpp::Parameter("Postprocessing.nms_iou_threshold", 0.6)};
239239
auto result = node->set_parameters(params);
240240
REQUIRE(result[0].successful == true);
241-
REQUIRE(node->get_parameter("Postprocessing.nms_iou_threshold").as_double() == Approx(0.6));
241+
REQUIRE(node->get_parameter("Postprocessing.nms_iou_threshold").as_double() == CATCH_APPROX(0.6));
242242
}
243243
}
244244

deep_ort_backend_plugin/test/test_ort_backend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
#include <thread>
1919
#include <vector>
2020

21-
#include <catch2/catch.hpp>
2221
#include <deep_ort_backend_plugin/ort_backend_executor.hpp>
2322
#include <deep_ort_backend_plugin/ort_backend_plugin.hpp>
2423
#include <deep_ort_backend_plugin/ort_cpu_memory_allocator.hpp>
24+
#include <deep_test/compat.hpp>
2525

2626
namespace deep_ort_backend
2727
{

deep_ort_gpu_backend_plugin/test/test_ort_gpu_backend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
#include <thread>
2121
#include <vector>
2222

23-
#include <catch2/catch.hpp>
2423
#include <deep_ort_gpu_backend_plugin/ort_gpu_backend_executor.hpp>
2524
#include <deep_ort_gpu_backend_plugin/ort_gpu_backend_plugin.hpp>
2625
#include <deep_ort_gpu_backend_plugin/ort_gpu_memory_allocator.hpp>
26+
#include <deep_test/compat.hpp>
2727
#include <rclcpp/rclcpp.hpp>
2828
#include <rclcpp_lifecycle/lifecycle_node.hpp>
2929

deep_sample/test/test_sample_node.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
#include <thread>
1919
#include <vector>
2020

21-
#include <catch2/catch.hpp>
2221
#include <deep_sample/sample_inference_node.hpp>
22+
#include <deep_test/compat.hpp>
2323
#include <deep_test/deep_test.hpp>
2424
#include <rclcpp/rclcpp.hpp>
2525
#include <sensor_msgs/msg/image.hpp>

deep_test/cmake/add_deep_test.cmake

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ function(add_deep_test TEST_NAME TEST_SOURCE)
3232
)
3333

3434
# Find dependencies
35-
find_package(Catch2 REQUIRED)
35+
# Catch2 version requirement compatibility:
36+
# Humble uses Catch2 2.x, Jazzy+ uses Catch2 3.x
37+
if("$ENV{ROS_DISTRO}" STREQUAL "humble")
38+
find_package(Catch2 2 REQUIRED)
39+
else()
40+
find_package(Catch2 REQUIRED)
41+
endif()
3642
find_package(rclcpp REQUIRED)
3743
find_package(rclcpp_lifecycle REQUIRED)
3844

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) 2025-present WATonomous. All rights reserved.
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+
#pragma once
16+
17+
#ifndef DEEP_TEST__COMPAT_HPP_
18+
#define DEEP_TEST__COMPAT_HPP_
19+
20+
/**
21+
* Compatibility header for handling differences between ROS2 distributions
22+
* (primarily Humble vs Jazzy) and their respective dependencies.
23+
*
24+
* This header includes compatibility macros and includes for test code.
25+
*/
26+
27+
// ============================================================================
28+
// Catch2 Compatibility (2.x in Humble, 3.x in Jazzy+)
29+
// ============================================================================
30+
31+
#if __has_include(<catch2/catch_all.hpp>)
32+
#include <catch2/catch_all.hpp>
33+
#else
34+
#include <catch2/catch.hpp>
35+
#endif
36+
37+
// Compatibility macro for Catch2 2.x vs 3.x Approx API
38+
// Catch2 2.x (Humble): Approx() in global namespace
39+
// Catch2 3.x (Jazzy+): Catch::Approx() in Catch namespace
40+
#if __has_include(<catch2/catch_all.hpp>)
41+
#define CATCH_APPROX(x) Catch::Approx(x)
42+
#else
43+
#define CATCH_APPROX(x) Approx(x)
44+
#endif
45+
46+
#endif // DEEP_TEST__COMPAT_HPP_

deep_test/test/deep_core/test_integration.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
#include <utility>
1818
#include <vector>
1919

20-
#include <catch2/catch.hpp>
2120
#include <deep_core/types/tensor.hpp>
21+
#include <deep_test/compat.hpp>
2222
#include <deep_test/deep_test.hpp>
2323
#include <test_nodes/deep_test_node.hpp>
2424

deep_test/test/deep_core/test_node_lifecycle.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include <string>
1717
#include <vector>
1818

19-
#include <catch2/catch.hpp>
19+
#include <deep_test/compat.hpp>
2020
#include <deep_test/deep_test.hpp>
2121
#include <lifecycle_msgs/msg/state.hpp>
2222
#include <rclcpp/rclcpp.hpp>

0 commit comments

Comments
 (0)