YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
serialPort_nws_yarp_test.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#include <yarp/os/Network.h>
9
10#include <catch2/catch_amalgamated.hpp>
11#include <harness.h>
12
13using namespace yarp::dev;
14using namespace yarp::os;
15
16TEST_CASE("dev::serialPort_nws_yarp", "[yarp::dev]")
17{
18 YARP_REQUIRE_PLUGIN("fakeSerialPort", "device");
19 YARP_REQUIRE_PLUGIN("serialPort_nws_yarp", "device");
20
21 Network::setLocalMode(true);
22
23 SECTION("Checking serialPort_nws_yarp device alone")
24 {
25 PolyDriver dd;
26
28 {
30 p_cfg.put("device", "serialPort_nws_yarp");
31 p_cfg.put("name", "/serialPort_nws");
32 REQUIRE(dd.open(p_cfg));
33 }
34
36
37 //"Close all polydrivers and check"
38 {
39 CHECK(dd.close());
40 }
41 }
42
43 SECTION("Checking serialPort_nws_yarp device attached to fake device")
44 {
47
49 {
51 pnws_cfg.put("device", "serialPort_nws_yarp");
52 pnws_cfg.put("name", "/serialPort_nws");
54
56 pdev_cfg.put("device", "fakeSerialPort");
57 pdev_cfg.put("comport", "fakePort");
58 pdev_cfg.put("baudrate", 9600);
60
63 bool result_att = ww_nws->attach(&ddfake);
65 }
66
67 //tests
68 {
69 Port p;
70 CHECK(p.open("/test:o"));
71 CHECK(Network::connect("/test:o","/serialPort_nws/in"));
73 Bottle b;
74 b.addString("fake_command");
75 CHECK(p.write(b));
77 p.close();
78 }
80
81 //"Close all polydrivers and check"
82 {
83 CHECK(ddnws.close());
85 }
86 }
87
88 Network::setLocalMode(false);
89}
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.
Helper interface for an object that can wrap/or "attach" to a single other device.
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
void addString(const char *str)
Places a string in the bottle, at the end of the list.
Definition Bottle.cpp:170
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 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:436
void close() override
Stop port activity.
Definition Port.cpp:363
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
Definition Port.cpp:79
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.
void delay(double seconds)
Wait for a certain number of seconds.
Definition Time.cpp:111
An interface to the operating system, including Port based communication.
TEST_CASE("dev::serialPort_nws_yarp", "[yarp::dev]")