iCub-main
Loading...
Searching...
No Matches
testDeviceMultipleFTSensors.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022 Istituto Italiano di Tecnologia (IIT)
3 * All rights reserved.
4 * Author: Luca Tricerri
5 * This software may be modified and distributed under the terms of the
6 * BSD-3-Clause license. See the accompanying LICENSE file for details.
7 */
8#include "gmock/gmock.h"
9#include "gtest/gtest.h"
10
12#include <ethResource.h>
13
14#include "EoProtocolAS.h"
15#include "testUtils.h"
16
17using ::testing::_;
18using ::testing::An;
19using ::testing::Eq;
20using ::testing::Gt;
21using ::testing::InSequence;
22using ::testing::InvokeArgument;
23using ::testing::Matcher;
24using ::testing::Pointee;
25using ::testing::Return;
26using ::testing::TypedEq;
27using testing::internal::operator==;
28
29using namespace yarp;
30using namespace yarp::os;
31using namespace yarp::dev;
32
34{
35 public:
41 using yarp::dev::embObjMultipleFTsensors::embObjMultipleFTsensors::calculateBoardTime;
42 using yarp::dev::embObjMultipleFTsensors::embObjMultipleFTsensors::getSixAxisForceTorqueSensorMeasure;
43 using yarp::dev::embObjMultipleFTsensors::embObjMultipleFTsensors::update;
44
45 embObjMultipleFTsensor_Mock(std::shared_ptr<yarp::dev::embObjDevPrivData> device) : yarp::dev::embObjMultipleFTsensors(device){};
47};
48
50{
51 public:
52 MOCK_METHOD(bool, isOpen, (), (const, override));
53
54 embObjDevPrivData_Mock(std::string name) : yarp::dev::embObjDevPrivData(name){};
55};
56
58{
59 public:
60 MOCK_METHOD(bool, setcheckRemoteValue, (const eOprotID32_t, void *, const unsigned int, const double, const double), (override));
61 MOCK_METHOD(bool, serviceSetRegulars, (eOmn_serv_category_t, vector<eOprotID32_t> &, double), (override));
62};
63
64TEST(MultiplembObjMultipleFTsensor, sendConfig2boards_simple_positive_001)
65{
66 // Setup
69 parser.ftInfo_ = {{"fakeId", {10, 200, eoas_ft_mode_calibrated, eobrd_unknown, 0, 0, 0, 0, 0, 0, 0}}};
70 EthResource_Mock deviceRes;
71 uint32_t id32First = eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_ft, 0, eoprot_tag_as_ft_config);
72
73 EXPECT_CALL(deviceRes, setcheckRemoteValue(id32First, _, 10, 0.010, 0.050)).WillOnce(Return(true));
74
75 // Test
76 bool ret = device.sendConfig2boards(parser, &deviceRes);
77
78 EXPECT_TRUE(ret);
79}
80
81TEST(MultiplembObjMultipleFTsensor, sendConfig2boards_double_sensor_positive_001)
82{
83 // Setup
86 parser.ftInfo_ = {{"fakeId", {10, 100, eoas_ft_mode_calibrated, eobrd_unknown, 0, 0, 0, 0, 0, 0, 0}}, {"fakeId2", {10, 100, eoas_ft_mode_calibrated, eobrd_unknown, 0, 0, 0, 0, 0, 0, 0}}};
87 EthResource_Mock deviceRes;
88 eOas_ft_config_t cfg = {eoas_ft_mode_calibrated, 10, 0, 100};
89 uint32_t id32First = eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_ft, 0, eoprot_tag_as_ft_config);
90 uint32_t id32Second = eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_ft, 1, eoprot_tag_as_ft_config);
91
92 // EXPECT_CALL(deviceRes, setcheckRemoteValue(34013184, Pointee(cfg), 10, 0.010, 0.050)).WillOnce(Return(true));
93 // EXPECT_CALL(deviceRes, setcheckRemoteValue(34013440, Pointee(cfg), 10, 0.010, 0.050)).WillOnce(Return(true));
94 EXPECT_CALL(deviceRes, setcheckRemoteValue(id32First, _, 10, 0.010, 0.050)).WillOnce(Return(true));
95 EXPECT_CALL(deviceRes, setcheckRemoteValue(id32Second, _, 10, 0.010, 0.050)).WillOnce(Return(true));
96
97 bool ret = device.sendConfig2boards(parser, &deviceRes);
98
99 EXPECT_TRUE(ret);
100}
101
102TEST(MultiplembObjMultipleFTsensor, sendConfig2boards_simple_negative_001)
103{
104 // Setup
107 parser.ftInfo_ = {{"fakeId", {10, 100, eoas_ft_mode_calibrated, eobrd_unknown, 0, 0, 0, 0, 0, 0, 0}}};
108 EthResource_Mock deviceRes;
109 uint32_t id32First = eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_ft, 0, eoprot_tag_as_ft_config);
110
111 EXPECT_CALL(deviceRes, setcheckRemoteValue(id32First, _, 10, 0.010, 0.050)).WillOnce(Return(false));
112
113 // Test
114 bool ret = device.sendConfig2boards(parser, &deviceRes);
115 EXPECT_FALSE(ret);
116}
117
118TEST(MultiplembObjMultipleFTsensor, sendStart2boards_simple_positive_001)
119{
120 // Setup
123 parser.ftInfo_ = {{"fakeId", {10, 100, eoas_ft_mode_calibrated, eobrd_unknown, 0, 0, 0, 0, 0, 0, 0}}};
124 EthResource_Mock deviceRes;
125 uint32_t id32First = eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_ft, 0, eoprot_tag_as_ft_cmmnds_enable);
126 bool enable = 1;
127
128 // EXPECT_CALL(deviceRes, setcheckRemoteValue(id32First, Pointee(enable), 10, 0.010, 0.050)).WillOnce(Return(true));
129 EXPECT_CALL(deviceRes, setcheckRemoteValue(id32First, _, 10, 0.010, 0.050)).WillOnce(Return(true));
130
131 // Test
132 bool ret = device.sendStart2boards(parser, &deviceRes);
133 EXPECT_TRUE(ret);
134}
135
136TEST(MultiplembObjMultipleFTsensor, sendStart2boards_double_positive_001)
137{
138 // Setup
141 parser.ftInfo_ = {{"fakeId", {10, 100, eoas_ft_mode_calibrated, eobrd_unknown, 0, 0, 0, 0, 0, 0, 0}}, {"fakeId1", {10, 100, eoas_ft_mode_calibrated, eobrd_unknown, 0, 0, 0, 0, 0, 0, 0}}};
142 EthResource_Mock deviceRes;
143 uint32_t id32First = eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_ft, 0, eoprot_tag_as_ft_cmmnds_enable);
144 uint32_t id32Second = eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_ft, 1, eoprot_tag_as_ft_cmmnds_enable);
145 bool enable = 1;
146
147 // EXPECT_CALL(deviceRes, setcheckRemoteValue(id32First, Pointee(enable), 10, 0.010, 0.050)).WillOnce(Return(true));
148 EXPECT_CALL(deviceRes, setcheckRemoteValue(id32First, _, 10, 0.010, 0.050)).WillOnce(Return(true));
149 EXPECT_CALL(deviceRes, setcheckRemoteValue(id32Second, _, 10, 0.010, 0.050)).WillOnce(Return(true));
150
151 // Test
152 bool ret = device.sendStart2boards(parser, &deviceRes);
153 EXPECT_TRUE(ret);
154}
155
156TEST(MultiplembObjMultipleFTsensor, serviceSetRegulars_simple_positive_001)
157{
158 // Setup
161 parser.ftInfo_ = {{"fakeId", {10, 100, eoas_ft_mode_calibrated, eobrd_unknown, 0, 0, 0, 0, 0, 0, 0}}, {"fakeId1", {10, 100, eoas_ft_mode_calibrated, eobrd_unknown, 0, 0, 0, 0, 0, 0, 0}}};
162 EthResource_Mock deviceRes;
163 uint32_t id32First = eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_ft, 0, eoprot_tag_as_ft_status_timedvalue);
164 uint32_t id32Second = eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_ft, 1, eoprot_tag_as_ft_status_timedvalue);
165 vector<eOprotID32_t> ids = {id32First, id32Second};
166
167 EXPECT_CALL(deviceRes, serviceSetRegulars(eomn_serv_category_ft, ids, _)).WillOnce(Return(true));
168
169 // Test
170 bool ret = device.initRegulars(parser, &deviceRes);
171 EXPECT_TRUE(ret);
172}
173
174TEST(MultiplembObjMultipleFTsensor, update_simple_positive_001)
175{
176 // Setup
177 yarp::os::Network::init();
178 std::shared_ptr<embObjDevPrivData_Mock> privateData = std::make_shared<embObjDevPrivData_Mock>("test");
179 embObjMultipleFTsensor_Mock device(privateData);
180 uint32_t id32First = eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_ft, 0, eoprot_tag_as_ft_status_timedvalue);
181 eOas_ft_timedvalue_t data = {100, 1, 2, 3, {5, 6, 7, 8, 9, 10}};
182 yarp::sig::Vector expected = {5, 6, 7, 8, 9, 10};
183
184 EXPECT_CALL(*privateData, isOpen()).WillRepeatedly(Return(true));
185
186 // Test
187 bool ret = device.update(id32First, 1, (void *)&data);
188 EXPECT_TRUE(ret);
189 EXPECT_EQ(expected, device.ftSensorsData_[0].data_);
190 EXPECT_EQ(3, device.temperaturesensordata_[0].data_);
191}
192
193TEST(MultiplembObjMultipleFTsensor, update_simple_positive_002)
194{
195 // Setup
196 yarp::os::Network::init();
197 std::shared_ptr<embObjDevPrivData_Mock> privateData = std::make_shared<embObjDevPrivData_Mock>("test");
198 embObjMultipleFTsensor_Mock device(privateData);
199 uint32_t id32First = eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_ft, 1, eoprot_tag_as_ft_status_timedvalue);
200 eOas_ft_timedvalue_t data = {100, 1, 2, 3, {5, 6, 7, 8, 9, 10}};
201 yarp::sig::Vector expected = {5, 6, 7, 8, 9, 10};
202 yarp::sig::Vector expectedEmpty = {0, 0, 0, 0, 0, 0};
203
204 EXPECT_CALL(*privateData, isOpen()).WillRepeatedly(Return(true));
205
206 // Test
207 bool ret = device.update(id32First, 1, (void *)&data);
208 EXPECT_TRUE(ret);
209 EXPECT_EQ(expectedEmpty, device.ftSensorsData_[0].data_);
210 EXPECT_EQ(expected, device.ftSensorsData_[1].data_);
211 EXPECT_EQ(0, device.temperaturesensordata_[0].data_);
212 EXPECT_EQ(3, device.temperaturesensordata_[1].data_);
213}
214
215TEST(MultiplembObjMultipleFTsensor, update_negative_001)
216{
217 // Setup
218 std::shared_ptr<embObjDevPrivData_Mock> privateData = std::make_shared<embObjDevPrivData_Mock>("test");
219 embObjMultipleFTsensor_Mock device(privateData);
220 uint32_t id32First = eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_ft, 4, eoprot_tag_as_ft_status_timedvalue);
221 eOas_ft_timedvalue_t data = {100, 1, 2, 3, {5, 6, 7, 8, 9, 10}};
222 yarp::sig::Vector expected = {5, 6, 7, 8, 9, 10};
223 yarp::sig::Vector expectedEmpty = {0, 0, 0, 0, 0, 0};
224
225 EXPECT_CALL(*privateData, isOpen()).WillRepeatedly(Return(true));
226
227 // Test
228 bool ret = device.update(id32First, 1, (void *)&data);
229 EXPECT_FALSE(ret);
230}
231
232TEST(MultiplembObjMultipleFTsensor, update_negative_002)
233{
234 // Setup
235 std::shared_ptr<embObjDevPrivData_Mock> privateData = std::make_shared<embObjDevPrivData_Mock>("test");
236 embObjMultipleFTsensor_Mock device(privateData);
237 uint32_t id32First = eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_pos, 3, eoprot_tag_as_ft_status_timedvalue);
238 eOas_ft_timedvalue_t data = {100, 1, 2, 3, {5, 6, 7, 8, 9, 10}};
239 yarp::sig::Vector expected = {5, 6, 7, 8, 9, 10};
240 yarp::sig::Vector expectedEmpty = {0, 0, 0, 0, 0, 0};
241
242 EXPECT_CALL(*privateData, isOpen()).WillRepeatedly(Return(true));
243
244 // Test
245 bool ret = device.update(id32First, 3, (void *)&data);
246 EXPECT_FALSE(ret);
247}
248
249TEST(MultiplembObjMultipleFTsensor, update_negative_003)
250{
251 // Setup
252 std::shared_ptr<embObjDevPrivData_Mock> privateData = std::make_shared<embObjDevPrivData_Mock>("test");
253 embObjMultipleFTsensor_Mock device(privateData);
254 uint32_t id32First = eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_ft, 3, eoprot_tag_as_ft_status);
255 eOas_ft_timedvalue_t data = {100, 1, 2, 3, {5, 6, 7, 8, 9, 10}};
256 yarp::sig::Vector expected = {5, 6, 7, 8, 9, 10};
257 yarp::sig::Vector expectedEmpty = {0, 0, 0, 0, 0, 0};
258
259 EXPECT_CALL(*privateData, isOpen()).WillRepeatedly(Return(true));
260
261 // Test
262 bool ret = device.update(id32First, 3, (void *)&data);
263 EXPECT_FALSE(ret);
264}
265
266TEST(MultiplembObjMultipleFTsensor, getNrOfSixAxisForceTorqueSensors_positive_001)
267{
268 // Setup
269 std::shared_ptr<embObjDevPrivData_Mock> privateData = std::make_shared<embObjDevPrivData_Mock>("test");
270 embObjMultipleFTsensor_Mock device(privateData);
271
272 device.ftSensorsData_ = {{{0}, {{1, 2, 3, 4, 5, 6}, 99.49}}};
273
274 EXPECT_CALL(*privateData, isOpen()).WillRepeatedly(Return(true));
275
276 // Test
277 yarp::sig::Vector data;
278 double timestamp;
279 bool ret = device.getSixAxisForceTorqueSensorMeasure(0, data, timestamp);
280
281 yarp::sig::Vector expected = {1, 2, 3, 4, 5, 6};
282 EXPECT_EQ(expected, data);
283 EXPECT_EQ(99.49, timestamp);
284}
285
286TEST(MultiplembObjMultipleFTsensor, getNrOfSixAxisForceTorqueSensors_double_positive_001)
287{
288 // Setup
289 std::shared_ptr<embObjDevPrivData_Mock> privateData = std::make_shared<embObjDevPrivData_Mock>("test");
290 embObjMultipleFTsensor_Mock device(privateData);
291
292 device.ftSensorsData_ = {{{0}, {{1, 2, 3, 4, 5, 6}, 99.49}}, {{1}, {{10, 20, 30, 40, 50, 60}, 99.49}}};
293
294 EXPECT_CALL(*privateData, isOpen()).WillRepeatedly(Return(true));
295
296 // Test
297 yarp::sig::Vector data;
298 double timestamp;
299 bool ret = device.getSixAxisForceTorqueSensorMeasure(1, data, timestamp);
300
301 yarp::sig::Vector expected = {10, 20, 30, 40, 50, 60};
302 EXPECT_EQ(expected, data);
303 EXPECT_EQ(99.49, timestamp);
304}
305
306TEST(MultiplembObjMultipleFTsensor, getNrOfSgetTemperatureSensorMeasure_positive_001)
307{
308 // Setup
309 std::shared_ptr<embObjDevPrivData_Mock> privateData = std::make_shared<embObjDevPrivData_Mock>("test");
310 embObjMultipleFTsensor_Mock device(privateData);
311
312 device.temperaturesensordata_ = {{{0}, {34, 99.49}}};
313
314 EXPECT_CALL(*privateData, isOpen()).WillRepeatedly(Return(true));
315
316 // Test
317 double data;
318 double timestamp;
319 bool ret = device.getTemperatureSensorMeasure(0, data, timestamp);
320
321 double expected = 3.4;
322 EXPECT_DOUBLE_EQ(expected, data);
323 EXPECT_EQ(99.49, timestamp);
324}
325
326TEST(MultiplembObjMultipleFTsensor, calculateBoardTime_positive_001)
327{
328 // Setup
329 yarp::os::Network::init();
330 std::shared_ptr<embObjDevPrivData_Mock> privateData = std::make_shared<embObjDevPrivData_Mock>("test");
331 embObjMultipleFTsensor_Mock device(privateData);
332
333 EXPECT_CALL(*privateData, isOpen()).WillRepeatedly(Return(true));
334
335 // Test
336 double data;
337 double timestamp;
338 double first = device.calculateBoardTime(1000000);
339 double second = device.calculateBoardTime(2000000);
340 double diff = second - first;
341
342 EXPECT_DOUBLE_EQ(1.0,diff);
343}
@ data
MOCK_METHOD(bool, setcheckRemoteValue,(const eOprotID32_t, void *, const unsigned int, const double, const double),(override))
MOCK_METHOD(bool, serviceSetRegulars,(eOmn_serv_category_t, vector< eOprotID32_t > &, double),(override))
std::map< std::string, FtInfo > ftInfo_
MOCK_METHOD(bool, isOpen,(),(const, override))
embObjMultipleFTsensor_Mock(std::shared_ptr< yarp::dev::embObjDevPrivData > device)
bool serviceSetRegulars(eOmn_serv_category_t category, vector< eOprotID32_t > &id32vector, double timeout=0.500)
bool setcheckRemoteValue(const eOprotID32_t id32, void *value, const unsigned int retries=10, const double waitbeforecheck=0.001, const double timeout=0.050)
bool initRegulars(ServiceParserMultipleFt &parser, eth::AbstractEthResource *deviceRes)
std::map< eOprotID32_t, FtData > ftSensorsData_
bool sendStart2boards(ServiceParserMultipleFt &parser, eth::AbstractEthResource *deviceRes)
virtual bool getTemperatureSensorMeasure(size_t sensorindex, double &out, double &timestamp) const override
double calculateBoardTime(eOabstime_t current)
virtual bool update(eOprotID32_t id32, double timestamp, void *rxdata)
std::map< eOprotID32_t, TemperatureData > temperaturesensordata_
bool sendConfig2boards(ServiceParserMultipleFt &parser, eth::AbstractEthResource *deviceRes)
virtual bool getSixAxisForceTorqueSensorMeasure(size_t sensorindex, yarp::sig::Vector &out, double &timestamp) const override
Copyright (C) 2008 RobotCub Consortium.
TEST(MultiplembObjMultipleFTsensor, sendConfig2boards_simple_positive_001)