YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
chatBot_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>
13
14#include <yarp/sig/Sound.h>
15
16using namespace yarp::dev;
17using namespace yarp::os;
18
19TEST_CASE("dev::chatBot_nws_yarp", "[yarp::dev]")
20{
21 YARP_REQUIRE_PLUGIN("fakeChatBotDevice", "device");
22 YARP_REQUIRE_PLUGIN("chatBot_nws_yarp", "device");
23
24 Network::setLocalMode(true);
25
26 SECTION("Checking chatBot_nws_yarp device alone")
27 {
28 PolyDriver dd;
29
31 {
33 pnws_cfg.put("device", "chatBot_nws_yarp");
34 pnws_cfg.put("name", "/chatBot_nws");
37 }
38
40
41 //"Close all polydrivers and check"
42 {
43 CHECK(dd.close());
44 }
45 }
46
47 SECTION("Checking chatBot_nws_yarp device attached to fake device")
48 {
51
53 {
55 pnws_cfg.put("device", "chatBot_nws_yarp");
56 pnws_cfg.put("name", "/chatBot_nws");
58
60 pdev_cfg.put("device", "fakeChatBotDevice");
62
64 REQUIRE(ddnws.view(ww_nws));
65 REQUIRE(ww_nws!=nullptr);
66 bool result_att = ww_nws->attach(&ddfake);
68 }
69
70 //tests
71 {
72 Port po;
73 Port pi;
74 CHECK(po.open("/test:o"));
75 CHECK(Network::connect("/test:o","/chatBot_nws/text:i"));
76 CHECK(pi.open("/test:i"));
77 CHECK(Network::connect("/chatBot_nws/text:o", "/test:i"));
79
81 b.addString("Hello!");
82 CHECK(po.write(b));
85 CHECK(pi.read(resp));
86 CHECK(resp.get(0).asString() == "Hello there.");
87
88 po.close();
89 pi.close();
90 }
92
93 //"Close all polydrivers and check"
94 {
95 CHECK(ddnws.close());
97 }
98 }
99
100 Network::setLocalMode(false);
101}
TEST_CASE("dev::chatBot_nws_yarp", "[yarp::dev]")
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:176
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.
T * read(bool shouldWait=true) override
Read an available object from the port.
void write(bool forceStrict=false)
Write the current object being returned by BufferedPort::prepare.
A mini-server for network communication.
Definition Port.h:46
A class for storing options and configuration information.
Definition Property.h:32
void exec_params_test(yarp::dev::PolyDriver *pdrv)
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.