YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
test_numbersTest.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>
10#include <yarp/os/Port.h>
11
13
14#include <array>
15#include <thread>
16
17#include <catch2/catch_amalgamated.hpp>
18#include <harness.h>
19
20TEST_CASE("pm::stats_monitorTest", "[yarp::pm]")
21{
22 YARP_REQUIRE_PLUGIN("test_numbers", "portmonitor")
23
25
28
29 struct TestCase {
30 std::string carrier;
31 int expected_value;
32 };
33
34 auto tc = GENERATE(
35 TestCase {"fast_tcp", 1},
36 //send
37 TestCase {"fast_tcp+send.portmonitor+type.dll+file.test_numbers1+type.dll",2}, //1+1
38 TestCase {"fast_tcp+send.portmonitor+type.dll+file.test_numbers1+file1.test_numbers1+type1.dll", 3}, //1+1+1
39 TestCase {"fast_tcp+send.portmonitor+type.dll+file.test_numbers1+file1.test_numbers2+type1.dll", 4}, //(1+1)*2
40 TestCase {"fast_tcp+send.portmonitor+type.dll+file.test_numbers2+file1.test_numbers1+type1.dll", 3}, //(1*2)+1
41 //recv
42 TestCase {"fast_tcp+recv.portmonitor+type.dll+file.test_numbers1+type.dll",2}, //1+1
43 TestCase {"fast_tcp+recv.portmonitor+type.dll+file.test_numbers1+file1.test_numbers1+type1.dll", 3}, //1+1+1
44 TestCase {"fast_tcp+recv.portmonitor+type.dll+file.test_numbers1+file1.test_numbers2+type1.dll", 4}, //(1+1)*2
45 TestCase {"fast_tcp+recv.portmonitor+type.dll+file.test_numbers2+file1.test_numbers1+type1.dll", 3}, //(1*2)+1
46 //mixed
47 TestCase {"fast_tcp+send.portmonitor+type.dll+file.test_numbers1+type.dll+recv.portmonitor+type.dll+file.test_numbers1+type.dll",3}, //1+1+1
48 TestCase {"fast_tcp+send.portmonitor+type.dll+file.test_numbers1+file1.test_numbers1+type1.dll+recv.portmonitor+type.dll+file.test_numbers1+file1.test_numbers1+type1.dll", 5}, //1+1+1+1+1
49 TestCase {"fast_tcp+send.portmonitor+type.dll+file.test_numbers1+file1.test_numbers2+type1.dll+recv.portmonitor+type.dll+file.test_numbers1+file1.test_numbers2+type1.dll", 10}, //((1+1)*2+1)*2
50 TestCase {"fast_tcp+send.portmonitor+type.dll+file.test_numbers2+file1.test_numbers1+type1.dll+recv.portmonitor+type.dll+file.test_numbers2+file1.test_numbers1+type1.dll", 7} //((1*2)+1)*2+1
51 );
52
53 SECTION("Test that normally the portmonitor is not used")
54 {
55 yarp::os::Port sender;
56 yarp::os::Port receiver;
57
58 sender.open("/send");
59 receiver.open("/recv");
60
61 bool b = yarp::os::Network::connect("/send", "/recv", tc.carrier);
62 REQUIRE(b);
63
64 sender.write(yarp::os::Value(tc.expected_value));
65
67
68 yarp::os::Value rval;
69 receiver.read(rval);
70 CHECK(rval.asInt64()==tc.expected_value);
71
72 receiver.close();
73 sender.close();
74 }
75
77}
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
A mini-server for network communication.
Definition Port.h:46
bool write(const PortWriter &writer, const PortWriter *callback=nullptr) const override
Write an object to the port.
Definition Port.cpp:395
bool read(PortReader &reader, bool willReply=false) override
Read an object from the port.
Definition Port.cpp:440
void close() override
Stop port activity.
Definition Port.cpp:330
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
Definition Port.cpp:79
A single value (typically within a Bottle).
Definition Value.h:44
virtual std::int64_t asInt64() const
Get 64-bit integer value.
Definition Value.cpp:216
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
TEST_CASE("pm::stats_monitorTest", "[yarp::pm]")