Skip to content

Commit 790352c

Browse files
committed
improved tests to check unimplemented methods in device drivers
1 parent b20c218 commit 790352c

File tree

9 files changed

+94
-2
lines changed

9 files changed

+94
-2
lines changed

src/devices/fake/fakeDeviceUnwrapped/FakeDeviceUnwrapped.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ yarp::dev::ReturnValue FakeDeviceUnwrapped::doSomething()
2222
return ReturnValue_ok;
2323
}
2424

25+
yarp::dev::ReturnValue FakeDeviceUnwrapped::doSomethingUnimplemented()
26+
{
27+
yCInfo(FAKEDEVICEUNWRAPPED) << "doSomethingUnimplemented executed, returning unimplemented";
28+
return yarp::dev::ReturnValue::return_code::return_value_error_not_implemented_by_device;
29+
}
30+
2531
yarp::dev::ReturnValue FakeDeviceUnwrapped::testSetValue(int value)
2632
{
2733
yCInfo(FAKEDEVICEUNWRAPPED) << "testSetValue" << value;

src/devices/fake/fakeDeviceUnwrapped/FakeDeviceUnwrapped.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class FakeDeviceUnwrapped :
3939

4040
//IFakeDeviceInterfaceTest1
4141
yarp::dev::ReturnValue doSomething() override;
42+
yarp::dev::ReturnValue doSomethingUnimplemented() override;
4243

4344
//IFakeDeviceInterfaceTest2
4445
yarp::dev::ReturnValue testSetValue(int value) override;

src/devices/fake/fakeDeviceWrapper/FakeDeviceWrapper.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <yarp/os/Log.h>
99
#include <yarp/os/LogComponent.h>
1010
#include <yarp/os/LogStream.h>
11+
#include <yarp/dev/ControlBoardInterfaces.h>
1112

1213
using namespace yarp::os;
1314
using namespace yarp::dev;
@@ -34,6 +35,9 @@ yarp::dev::ReturnValue FakeDeviceWrapper::testGetValue(int& value)
3435

3536
bool FakeDeviceWrapper::open(yarp::os::Searchable& config)
3637
{
38+
this->m_RpcPort.open("/FakeDeviceWrapper/rpc");
39+
m_RpcPort.setReader(*this);
40+
3741
yCInfo(FAKEDEVICEWRAPPER) << "FakeDeviceWrapper opened";
3842
return true;
3943
}
@@ -59,3 +63,46 @@ bool FakeDeviceWrapper::attach(yarp::dev::PolyDriver* drv)
5963
}
6064
return false;
6165
}
66+
67+
bool FakeDeviceWrapper::read(yarp::os::ConnectionReader& connection)
68+
{
69+
yarp::os::Bottle command;
70+
yarp::os::Bottle reply;
71+
ReturnValue retval;
72+
73+
bool ok = command.read(connection);
74+
if (!ok) {
75+
return false;
76+
}
77+
reply.clear();
78+
79+
if (command.get(0).asString() == "testSetValue")
80+
{
81+
retval = testSetValue(1);
82+
if (retval) {reply.addVocab32(VOCAB_OK);}
83+
else {reply.addVocab32(VOCAB_ERR);}
84+
}
85+
else
86+
if (command.get(0).asString() == "testGetValue")
87+
{
88+
int val=0;
89+
retval = testGetValue(val);
90+
if (retval) {
91+
reply.addVocab32(VOCAB_OK);
92+
}
93+
else {
94+
reply.addVocab32(VOCAB_ERR);
95+
}
96+
}
97+
else
98+
{
99+
reply.addVocab32(VOCAB_ERR);
100+
}
101+
102+
yarp::os::ConnectionWriter *returnToSender = connection.getWriter();
103+
if (returnToSender != nullptr)
104+
{
105+
reply.write(*returnToSender);
106+
}
107+
return true;
108+
}

src/devices/fake/fakeDeviceWrapper/FakeDeviceWrapper.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <yarp/dev/PolyDriver.h>
1111
#include <yarp/dev/WrapperSingle.h>
1212

13+
#include <yarp/os/Port.h>
14+
1315
/**
1416
* @ingroup dev_impl_fake
1517
*
@@ -19,10 +21,12 @@
1921
class FakeDeviceWrapper :
2022
public yarp::dev::DeviceDriver,
2123
public yarp::dev::WrapperSingle,
22-
public yarp::dev::test::IFakeDeviceInterfaceTest2
24+
public yarp::dev::test::IFakeDeviceInterfaceTest2,
25+
public yarp::os::PortReader
2326
{
2427
private:
2528
yarp::dev::test::IFakeDeviceInterfaceTest2* iTest=nullptr;
29+
yarp::os::Port m_RpcPort;
2630

2731
public:
2832
FakeDeviceWrapper() = default;
@@ -44,6 +48,9 @@ class FakeDeviceWrapper :
4448
//interfaces
4549
yarp::dev::ReturnValue testSetValue(int value) override;
4650
yarp::dev::ReturnValue testGetValue(int& value) override;
51+
52+
// From PortReader
53+
bool read(yarp::os::ConnectionReader& connection) override;
4754
};
4855

4956
#endif

src/devices/fake/fakeDevice_nwc_yarp/FakeDevice_nwc_yarp.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,9 @@ yarp::dev::ReturnValue FakeDevice_nwc_yarp::doSomething()
5454
yarp::dev::ReturnValue ret = m_thrift_RPC.doSomethingRPC();
5555
return ret;
5656
}
57+
58+
yarp::dev::ReturnValue FakeDevice_nwc_yarp::doSomethingUnimplemented()
59+
{
60+
yarp::dev::ReturnValue ret = m_thrift_RPC.doSomethingUnimplementedRPC();
61+
return ret;
62+
}

src/devices/fake/fakeDevice_nwc_yarp/FakeDevice_nwc_yarp.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ class FakeDevice_nwc_yarp : public yarp::dev::DeviceDriver,
3434
bool close() override;
3535

3636
//From IFakeInterface
37-
yarp::dev::ReturnValue doSomething();
37+
yarp::dev::ReturnValue doSomething() override;
38+
yarp::dev::ReturnValue doSomethingUnimplemented() override;
3839
};

src/devices/fake/fakeDevice_nws_yarp/FakeDeviceServerImpl.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,24 @@ yarp::dev::ReturnValue FakeServerRPCd::doSomethingRPC()
3030
return yarp::dev::ReturnValue_ok;
3131
}
3232

33+
yarp::dev::ReturnValue FakeServerRPCd::doSomethingUnimplementedRPC()
34+
{
35+
if (m_iFake == nullptr)
36+
{
37+
yCError(FAKEDEVICESERVER, "Invalid interface");
38+
return yarp::dev::ReturnValue::return_code::return_value_error_not_ready;
39+
}
40+
41+
yarp::dev::ReturnValue ret = m_iFake->doSomethingUnimplemented();
42+
if (!ret)
43+
{
44+
yCError(FAKEDEVICESERVER, "doSomethingUnimplemented() failed");
45+
return ret;
46+
}
47+
48+
return yarp::dev::ReturnValue_ok;
49+
}
50+
3351
void FakeServerRPCd::setInterface(yarp::dev::test::IFakeDeviceInterfaceTest1* _ifake)
3452
{
3553
m_iFake = _ifake;

src/devices/fake/fakeDevice_nws_yarp/FakeDeviceServerImpl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ class FakeServerRPCd : public FakeTestMsgs
2121

2222
// From FakeTestMsgs
2323
yarp::dev::ReturnValue doSomethingRPC() override;
24+
yarp::dev::ReturnValue doSomethingUnimplementedRPC() override;
2425
};

src/libYARP_dev/src/yarp/dev/testInterfaces/IFakeDeviceInterfaceTest1.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ class YARP_dev_API IFakeDeviceInterfaceTest1
2828
* A method for testing purposes
2929
*/
3030
virtual yarp::dev::ReturnValue doSomething() = 0;
31+
32+
/**
33+
* A method for testing purposes, which implementation is not implemented
34+
*/
35+
virtual yarp::dev::ReturnValue doSomethingUnimplemented() = 0;
3136
};
3237

3338
} // namespace yarp::dev::test

0 commit comments

Comments
 (0)