YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
fakeDeviceWrapped_test.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2024-2024 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#include <yarp/os/Network.h>
10
11#include <catch2/catch_amalgamated.hpp>
12#include <harness.h>
13
14using namespace yarp::dev;
15using namespace yarp::os;
16
17TEST_CASE("dev::fakeDeviceWrapped", "[yarp::dev]")
18{
19 YARP_REQUIRE_PLUGIN("fakeDeviceWrapped", "device");
20
21 Network::setLocalMode(true);
22
23 SECTION("Checking fakeDeviceWrapped device")
24 {
25 PolyDriver dd;
27
29 {
31 p_cfg.put("device", "fakeDeviceWrapped");
32 REQUIRE(dd.open(p_cfg));
33 }
34
35 dd.view(iTest);
36 REQUIRE(iTest);
37
38 iTest->testSetValue(5);
39 int val = 0;
40 iTest->testGetValue(val);
41 CHECK(val == 5);
42
43 //"Close all polydrivers and check"
44 {
45 CHECK(dd.close());
46 }
47 }
48
49 SECTION("Checking fakeDeviceWrapped device with automatically invoked wrapper")
50 {
51 PolyDriver dd;
53
55 {
57 p_cfg.put("device", "fakeDeviceWrapped");
58 //this option, should be used only by yarpdev executable: it is used here for testing purposes only,
59 //wrapping_enabled=1 will open deviceBundler, fakeDeviceWrapper and perform an attach with fakeDeviceWrapped.
60 p_cfg.put("wrapping_enabled", 1);
61 REQUIRE(dd.open(p_cfg));
62 }
63
64 //what interfaces are available now?
65 //This part is not well specified.
66 //Currently no interfaces can be opened since dd will be a deviceBundler and not
67 //a fakeDeviceWrapped (even if dd.id() shows `fakeDeviceWrapped`).
68 //This behavior may change in the future, but it is not very important since `wrapping_enabled` is used
69 //only by yarpdev executable.
70 std::string devicename = dd.id();
71 CHECK (devicename == "fakeDeviceWrapped");
72
73 REQUIRE(iTest == nullptr);
74
75 //"Close all polydrivers and check"
76 {
77 CHECK(dd.close());
78 }
79 }
80
81 Network::setLocalMode(false);
82}
virtual std::string id() const
Return the id assigned to the PolyDriver.
bool view(T *&x)
Get an interface to the device driver.
A container for a device driver.
Definition PolyDriver.h:23
bool close() override
Close the DeviceDriver.
bool open(const std::string &txt)
Construct and configure a device by its common name.
A test interface used internally by continuous integration.
virtual yarp::dev::ReturnValue testGetValue(int &value)=0
This method is used to get a single value from a test device.
virtual yarp::dev::ReturnValue testSetValue(int value)=0
This method is used to set a single value inside the test device.
A mini-server for performing network communication in the background.
A class for storing options and configuration information.
Definition Property.h:33
TEST_CASE("dev::fakeDeviceWrapped", "[yarp::dev]")
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.