YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
depthimage_compression_zlibTest.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2026-2026 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
7#include <yarp/os/Network.h>
8#include <yarp/os/LogStream.h>
9#include <yarp/os/Time.h>
11#include <yarp/sig/Image.h>
12
14
15#include <array>
16#include <thread>
17
18#include <catch2/catch_amalgamated.hpp>
19#include <harness.h>
20
21TEST_CASE("pm::depthimage_compression_zlibTest", "[yarp::pm]")
22{
23 YARP_REQUIRE_PLUGIN("depthimage_compression_zlib", "portmonitor")
24
26
29
30 struct TestCase {
31 std::string carrier;
32 bool should_compress;
33 };
34
35 auto tc = GENERATE(
36 TestCase {"fast_tcp", false},
37 TestCase {"fast_tcp+send.portmonitor+file.depthimage_compression_zlib+type.dll+recv.portmonitor+file.depthimage_compression_zlib+type.dll", true}
38 );
39
40 SECTION("Test depth image compression with portmonitor: " + tc.carrier)
41 {
44
45 sender.open("/send");
46 receiver.open("/recv");
47
48 bool b = yarp::os::Network::connect("/send", "/recv", tc.carrier);
49 REQUIRE(b);
50
51 // Create a test depth image (10x10 pixels)
52 constexpr int width = 10;
53 constexpr int height = 10;
54
56 img.resize(width, height);
57
58 // Fill with test data - create a gradient pattern
59 for (int y = 0; y < height; y++)
60 {
61 for (int x = 0; x < width; x++)
62 {
63 float depth_value = static_cast<float>(x + y * width) / 10.0f;
64 img.pixel(x, y) = depth_value;
65 }
66 }
67
68 sender.write();
69
71
72 yarp::sig::ImageOf<yarp::sig::PixelFloat>* receivedImg = receiver.read();
73 REQUIRE(receivedImg != nullptr);
74
75 // Verify dimensions
76 CHECK(receivedImg->width() == width);
77 CHECK(receivedImg->height() == height);
78
79 // Verify pixel data matches
80 for (int y = 0; y < height; y++)
81 {
82 for (int x = 0; x < width; x++)
83 {
84 float expected_value = static_cast<float>(x + y * width) / 10.0f;
85 float actual_value = receivedImg->pixel(x, y);
86 CHECK(actual_value == expected_value);
87 }
88 }
89
90 receiver.close();
91 sender.close();
92 }
93
95}
A mini-server for performing network communication in the background.
void close() override
Stop port activity.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
T * read(bool shouldWait=true) override
Read an available object from the port.
void write(bool forceStrict=false)
Write the current object being returned by BufferedPort::prepare.
T & prepare()
Access the object which will be transmitted by the next call to yarp::os::BufferedPort::write.
static bool connect(const std::string &src, const std::string &dest, const std::string &carrier="", bool quiet=true)
Request that an output port connect to an input port.
Definition Network.cpp:751
static bool setLocalMode(bool flag)
Chooses whether communication is process-local.
Definition Network.cpp:1118
Utilities for manipulating the YARP network, including initialization and shutdown.
Definition Network.h:718
Typed image class.
Definition Image.h:603
T & pixel(size_t x, size_t y)
Definition Image.h:619
size_t width() const
Gets width of image in pixels.
Definition Image.h:171
void resize(size_t imgWidth, size_t imgHeight)
Reallocate an image to be of a desired size, throwing away its current contents.
Definition Image.cpp:387
size_t height() const
Gets height of image in pixels.
Definition Image.h:177
TEST_CASE("pm::depthimage_compression_zlibTest", "[yarp::pm]")
void delay(double seconds)
Wait for a certain number of seconds.
Definition Time.cpp:111
@ YARP_CLOCK_SYSTEM
Definition Time.h:28
The main, catch-all namespace for YARP.
Definition dirs.h:16