YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
main.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
6#include <yarp/os/all.h>
8
9#include <TestReturnValue.h>
10
11#include <catch2/catch_amalgamated.hpp>
12
13using namespace yarp::os;
15
16namespace {
17
19
20// Server side implementation, used to check that a successful call still
21// returns the values sent by the server.
22class TestReturnValueServer : public TestReturnValue
23{
24public:
25 int32_t stored_value = 0;
26
27 ReturnValue setValueRPC(const std::int32_t value) override
28 {
29 stored_value = value;
30 return ReturnValue_ok;
31 }
32
34 {
37 r.value = stored_value;
38 return r;
39 }
40
42 {
46 r.text = "hello";
47 return r;
48 }
49
50 bool getBoolRPC() override
51 {
52 return true;
53 }
54};
55
56// Calls all the methods of a client whose write is expected to fail, and
57// checks that every yarp::dev::ReturnValue reports a communication error.
59{
60 // Case 1: yarp::dev::ReturnValue returned directly
61 ReturnValue ret = client.setValueRPC(42);
62 CHECK(ret == comm_error);
63 CHECK_FALSE(ret);
64
65 // Case 2: struct with one yarp::dev::ReturnValue field
67 CHECK(rv.ret == comm_error);
68 CHECK_FALSE(rv.ret);
69 CHECK(rv.value == 0);
70
71 // Case 2: struct with more than one yarp::dev::ReturnValue field
73 CHECK(rtv.ret == comm_error);
74 CHECK(rtv.ret2 == comm_error);
75 CHECK(rtv.text.empty());
76
77 // Case 3: no yarp::dev::ReturnValue involved, default value returned
78 CHECK(client.getBoolRPC() == false);
79}
80
81} // namespace
82
83
84TEST_CASE("IdlThriftTest4", "[yarp::idl::thrift4]")
85{
87
88 SECTION("Failed write: client not attached to any port")
89 {
90 TestReturnValue client;
91 check_failed_calls(client);
92 }
93
94 SECTION("Failed write: client port not connected to any server")
95 {
96 Port port;
97 REQUIRE(port.open("/test4/client"));
98 TestReturnValue client;
99 REQUIRE(client.yarp().attachAsClient(port));
100 check_failed_calls(client);
101 port.close();
102 }
103
104 SECTION("Successful call: values returned by the server are preserved")
105 {
106 TestReturnValueServer server;
107 TestReturnValue client;
109
110 ReturnValue ret = client.setValueRPC(42);
112
113 return_getValue rv = client.getValueRPC();
115 CHECK(rv.value == 42);
116
120 CHECK(rtv.text == "hello");
121
122 CHECK(client.getBoolRPC() == true);
123 }
124
126}
127
128int main(int argc, char* argv[])
129{
131 return Catch::Session().run(argc, argv);
132}
#define ReturnValue_ok
Definition ReturnValue.h:82
#define ReturnValue_error_not_ready
Definition ReturnValue.h:88
virtual return_getTwoValues getTwoValuesRPC()
virtual return_getValue getValueRPC()
virtual yarp::dev::ReturnValue setValueRPC(const std::int32_t value)
virtual bool getBoolRPC()
yarp::dev::ReturnValue ret2
yarp::dev::ReturnValue ret
std::int32_t value
yarp::dev::ReturnValue ret
@ return_value_error_nws_nwc_communication_error
Method is not (yet) implemented.
@ return_value_error_not_ready
Method failed due to invalid internal status/invalid request.
A mini-server for performing network communication in the background.
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
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
yarp::os::WireLink & yarp()
Get YARP state associated with this object.
Definition Wire.h:28
int main(int argc, char *argv[])
Definition main.cpp:128
TEST_CASE("IdlThriftTest4", "[yarp::idl::thrift4]")
Definition main.cpp:84
An interface to the operating system, including Port based communication.
The main, catch-all namespace for YARP.
Definition dirs.h:16