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#include <yarp/os/Carriers.h>
12
14
15#include <array>
16#include <thread>
17
18#include <catch2/catch_amalgamated.hpp>
19#include <harness.h>
20
21TEST_CASE("pm::test_numbersTest", "[yarp::pm]")
22{
23 YARP_REQUIRE_PLUGIN("test_numbers1", "portmonitor")
24 YARP_REQUIRE_PLUGIN("test_numbers2", "portmonitor")
25
27
29
30 REQUIRE(yarp::os::Carriers::getCarrierTemplate("portmonitor") != nullptr);
31
33
34 struct TestCase {
35 std::string carrier;
36 int expected_value;
37 int sent_value=1;
38 };
39
40 auto tc = GENERATE(
41 TestCase {"fast_tcp", 1},
42 //send
43 TestCase {"fast_tcp+send.portmonitor+type.dll+file.test_numbers1+type.dll",2}, //1+1
44 TestCase {"fast_tcp+send.portmonitor+type.dll+file.test_numbers1+file1.test_numbers1+type1.dll", 3}, //1+1+1
45 TestCase {"fast_tcp+send.portmonitor+type.dll+file.test_numbers1+file1.test_numbers2+type1.dll", 4}, //(1+1)*2
46 TestCase {"fast_tcp+send.portmonitor+type.dll+file.test_numbers2+file1.test_numbers1+type1.dll", 3}, //(1*2)+1
47 //recv
48 TestCase {"fast_tcp+recv.portmonitor+type.dll+file.test_numbers1+type.dll",2}, //1+1
49 TestCase {"fast_tcp+recv.portmonitor+type.dll+file.test_numbers1+file1.test_numbers1+type1.dll", 3}, //1+1+1
50 TestCase {"fast_tcp+recv.portmonitor+type.dll+file.test_numbers1+file1.test_numbers2+type1.dll", 4}, //(1+1)*2
51 TestCase {"fast_tcp+recv.portmonitor+type.dll+file.test_numbers2+file1.test_numbers1+type1.dll", 3}, //(1*2)+1
52 //mixed
53 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
54 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
55 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
56 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
57 );
58
59 SECTION("Test that normally the portmonitor is not used")
60 {
61 yarp::os::Port sender;
62 yarp::os::Port receiver;
63
64 sender.open("/send");
65 receiver.open("/recv");
66
67 bool b = yarp::os::Network::connect("/send", "/recv", tc.carrier);
68 REQUIRE(b);
69
70 sender.write(yarp::os::Value(tc.sent_value));
71
73
74 yarp::os::Value rval;
75 receiver.read(rval);
76 CHECK(rval.asInt64()==tc.expected_value);
77
78 receiver.close();
79 sender.close();
80 }
81
83}
static Carrier * getCarrierTemplate(const std::string &name)
Get template for carrier.
Definition Carriers.cpp:238
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:784
static bool setLocalMode(bool flag)
Chooses whether communication is process-local.
Definition Network.cpp:1137
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:210
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::test_numbersTest", "[yarp::pm]")