YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
robotDescription_nwc_yarp_test.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6
8
9#include <yarp/dev/IWrapper.h>
10#include <yarp/dev/PolyDriver.h>
11#include <yarp/os/Time.h>
12#include <yarp/os/Network.h>
13
14#include <algorithm>
15#include <vector>
16
17#include <catch2/catch_amalgamated.hpp>
18#include <harness.h>
19
20using namespace yarp::os;
21using namespace yarp::dev;
22
23TEST_CASE("dev::robotDescriptionClientTest", "[yarp::dev]")
24{
25 YARP_REQUIRE_PLUGIN("robotDescription_nws_yarp", "device");
26 YARP_REQUIRE_PLUGIN("robotDescription_nwc_yarp", "device");
27 YARP_REQUIRE_PLUGIN("robotDescriptionStorage", "device");
28 YARP_REQUIRE_PLUGIN("controlBoard_nws_yarp", "device");
29
30 Network::setLocalMode(true);
31
32 SECTION("Test the robotDescriptionClient device")
33 {
36 pstorage_cfg.put("device", "robotDescriptionStorage");
37 REQUIRE(ddstorage.open(pstorage_cfg)); // robotDescriptionStorage open reported successful
38
41 pserver_cfg.put("device", "robotDescription_nws_yarp");
42 pserver_cfg.put("local", "/robotDescription_nws_yarp/rpc");
43 REQUIRE(ddnws.open(pserver_cfg)); // robotDescription_nws_yarp open reported successful
44
45 yarp::dev::IWrapper* ww_nws = nullptr; ddnws.view(ww_nws);
47 bool result_att = ww_nws->attach(&ddstorage);
49
50 IRobotDescription* idesc = nullptr;
53 pclient_cfg.put("device", "robotDescription_nwc_yarp");
54 pclient_cfg.put("local", "/robotDescription_nwc_yarp/rpc");
55 pclient_cfg.put("remote", "/robotDescription_nws_yarp/rpc");
56 REQUIRE(ddnwc.open(pclient_cfg)); // robotDescription_nwc_yarp open reported successful
57
58 REQUIRE(ddnwc.view(idesc)); // IRobotDescription interface open reported successful
60
61 DeviceDescription dev1; dev1.device_name = "/icubTest/left_arm"; dev1.device_type = "controlBoard_nws_yarp";
62 DeviceDescription dev2; dev2.device_name = "/icubTest/left_leg"; dev2.device_type = "controlBoard_nws_yarp";
63 DeviceDescription dev3; dev3.device_name = "/icubTest/test"; dev3.device_type = "testDevice";
64 auto r1 = idesc->registerDevice(dev1);
65 auto r2 = idesc->registerDevice(dev2);
66 auto r3 = idesc->registerDevice(dev3);
67 CHECK(r1);
68 CHECK(r2);
69 CHECK(r3);
70 std::vector<DeviceDescription> list1;
71 std::vector<DeviceDescription> list2;
72
73 auto r4 = idesc->getAllDevices(list1);
74 CHECK(r4);
75 CHECK(list1.size() == 3);
76 CHECK(std::find(list1.begin(), list1.end(), dev1) != list1.end());
77 CHECK(std::find(list1.begin(), list1.end(), dev2) != list1.end());
78 CHECK(std::find(list1.begin(), list1.end(), dev3) != list1.end());
79 // IRobotDescription::getAllDevices() successfully tested
80
81 auto r5 = idesc->getAllDevicesByType("controlBoard_nws_yarp", list2);
82 CHECK(r5);
83 CHECK(list2.size() == 2);
84 CHECK(std::find(list2.begin(), list2.end(), dev1) != list2.end());
85 CHECK(std::find(list2.begin(), list2.end(), dev2) != list2.end());
86 CHECK_FALSE(std::find(list2.begin(), list2.end(), dev3) != list2.end());
87 // IRobotDescription::getControlBoardWrapperDevices() successfully tested
88
89 // Test unregister device
90 auto r6 = idesc->unregisterDevice("/icubTest/test");
91 auto r7 = idesc->getAllDevicesByType("testDevice", list2);
92 CHECK(r6);
93 CHECK(r7);
94 CHECK(list2.size() == 0); // IRobotDescription::unregisterDevice() successfully tested
95
96 // Test clear all
97 auto r8 = idesc->unregisterAll();
98 CHECK(r8);
99
100 // Close devices
101 CHECK(ddnwc.close()); // robotDescription_nwc_yarp successfully closed
102 CHECK(ddnws.close()); // robotDescription_nws_yarp successfully closed
103 CHECK(ddstorage.close()); // robotDescriptionStorage successfully closed
104 }
105
106 Network::setLocalMode(false);
107}
This interface allows users to retrieve a list which contains the names and the types of the currentl...
Interface for an object that can wrap/or "attach" to another.
Definition IWrapper.h:25
A container for a device driver.
Definition PolyDriver.h:23
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.
A class for storing options and configuration information.
Definition Property.h:33
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.
TEST_CASE("dev::robotDescriptionClientTest", "[yarp::dev]")