Skip to content

Commit 9aaf721

Browse files
committed
cleanup of tests
1 parent 11677ff commit 9aaf721

File tree

3 files changed

+27
-530
lines changed

3 files changed

+27
-530
lines changed

deep_conversions/test/test_conversions.cpp

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -79,35 +79,6 @@ TEST_CASE("Image encoding info parsing", "[conversions][image]")
7979
}
8080
}
8181

82-
TEST_CASE_METHOD(deep_ros::test::MockBackendFixture, "Mock Backend SECTION Test", "[conversions][mock]")
83-
{
84-
auto allocator = getAllocator();
85-
REQUIRE(allocator != nullptr);
86-
87-
SECTION("First section")
88-
{
89-
// Just allocate some memory
90-
std::vector<size_t> shape{2, 2};
91-
Tensor tensor(shape, DataType::FLOAT32, allocator);
92-
REQUIRE(tensor.data() != nullptr);
93-
}
94-
95-
SECTION("Second section")
96-
{
97-
// Test conversion function
98-
sensor_msgs::msg::Image ros_image;
99-
ros_image.height = 10;
100-
ros_image.width = 10;
101-
ros_image.encoding = "rgb8";
102-
ros_image.step = 10 * 3;
103-
ros_image.data.resize(10 * 10 * 3, 128);
104-
105-
auto tensor = from_image(ros_image, allocator);
106-
REQUIRE(tensor.data() != nullptr);
107-
REQUIRE(allocator->allocated_bytes() > 0);
108-
}
109-
}
110-
11182
TEST_CASE_METHOD(deep_ros::test::MockBackendFixture, "Image conversion from ROS to Tensor", "[conversions][image]")
11283
{
11384
auto allocator = getAllocator();
@@ -141,16 +112,41 @@ TEST_CASE_METHOD(deep_ros::test::MockBackendFixture, "Image conversion from ROS
141112
SECTION("Grayscale image conversion")
142113
{
143114
sensor_msgs::msg::Image ros_image;
115+
ros_image.header.stamp.sec = 456;
116+
ros_image.header.frame_id = "mono_camera_frame";
144117
ros_image.height = 240;
145118
ros_image.width = 320;
146119
ros_image.encoding = "mono8";
147-
ros_image.step = 320;
120+
ros_image.is_bigendian = false;
121+
ros_image.step = 320; // width * 1 channel
148122
ros_image.data.resize(240 * 320);
149123

124+
// Fill with gradient test pattern
125+
for (size_t y = 0; y < ros_image.height; ++y) {
126+
for (size_t x = 0; x < ros_image.width; ++x) {
127+
size_t idx = y * ros_image.step + x;
128+
ros_image.data[idx] = static_cast<uint8_t>((x + y) % 256);
129+
}
130+
}
131+
150132
auto tensor = from_image(ros_image, allocator);
151133

152-
REQUIRE(tensor.shape().size() >= 3); // At least [1, height, width]
134+
// Validate tensor properties
135+
REQUIRE(tensor.shape().size() == 3); // [1, height, width] for grayscale
136+
REQUIRE(tensor.shape()[0] == 1); // Batch size
137+
REQUIRE(tensor.shape()[1] == 240); // Height
138+
REQUIRE(tensor.shape()[2] == 320); // Width
153139
REQUIRE(tensor.dtype() == DataType::UINT8);
140+
REQUIRE(tensor.data() != nullptr);
141+
REQUIRE(tensor.size() == 240 * 320 * 1);
142+
143+
// Verify data integrity - check a few sample points
144+
auto tensor_data = static_cast<const uint8_t *>(tensor.data());
145+
REQUIRE(tensor_data[0] == static_cast<uint8_t>((0 + 0) % 256)); // Top-left corner
146+
REQUIRE(tensor_data[319] == static_cast<uint8_t>((319 + 0) % 256)); // Top-right corner
147+
148+
// Verify memory allocation tracking
149+
REQUIRE(allocator->allocated_bytes() > 0);
154150
}
155151
}
156152

deep_conversions/test/test_minimal_image.cpp

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)