8 #include "gmock/gmock.h"
9 #include "gtest/gtest.h"
13 #include "EoProtocolAS.h"
21 using ::testing::InSequence;
22 using ::testing::InvokeArgument;
23 using ::testing::Matcher;
24 using ::testing::Pointee;
25 using ::testing::Return;
26 using ::testing::TypedEq;
27 using testing::internal::operator==;
30 using namespace yarp::os;
40 using yarp::dev::embObjBattery::embObjBattery::calculateBoardTime;
41 using yarp::dev::embObjBattery::embObjBattery::update;
45 MOCK_METHOD(
double, calculateBoardTime, (eOabstime_t), (
override));
59 MOCK_METHOD(
bool, setcheckRemoteValue, (
const eOprotID32_t,
void *,
const unsigned int,
const double,
const double), (
override));
60 MOCK_METHOD(
bool, serviceSetRegulars, (eOmn_serv_category_t, vector<eOprotID32_t> &,
double), (
override));
63 TEST(CanBatterysensor, sendConfig2boards_simple_positive_001)
68 parser.
batteryInfo_ = {100, eobrd_bms, 0, 0, 0, 0, 0, 0, 0};
71 uint32_t id32First = eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_battery, 0, eoprot_tag_as_battery_config);
73 EXPECT_CALL(deviceRes, setcheckRemoteValue(id32First, _, 10, 0.010, 0.050)).WillOnce(Return(
true));
81 TEST(CanBatterysensor, sendConfig2boards_simple_negative_001)
86 parser.
batteryInfo_ = {100, eobrd_unknown, 0, 0, 0, 0, 0, 0, 0};
88 uint32_t id32First = eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_battery, 0, eoprot_tag_as_battery_config);
90 EXPECT_CALL(deviceRes, setcheckRemoteValue(id32First, _, 10, 0.010, 0.050)).WillOnce(Return(
false));
97 TEST(CanBatterysensor, sendStart2boards_simple_positive_001)
102 parser.
batteryInfo_ = {100, eobrd_bms, 0, 0, 0, 0, 0, 0, 0};
104 uint32_t id32First = eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_battery, 0, eoprot_tag_as_ft_cmmnds_enable);
108 EXPECT_CALL(deviceRes, setcheckRemoteValue(id32First, _, 10, 0.010, 0.050)).WillOnce(Return(
true));
115 TEST(CanBatterysensor, sendStart2boards_simple_negative_001)
120 parser.
batteryInfo_ = {100, eobrd_unknown, 0, 0, 0, 0, 0, 0, 0};
122 uint32_t id32First = eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_battery, 0, eoprot_tag_as_ft_cmmnds_enable);
126 EXPECT_CALL(deviceRes, setcheckRemoteValue(id32First, _, 10, 0.010, 0.050)).WillOnce(Return(
false));
133 TEST(CanBatterysensor, serviceSetRegulars_simple_positive_001)
138 parser.
batteryInfo_ = {100, eobrd_bms, 0, 0, 0, 0, 0, 0, 0};
140 uint32_t id32First = eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_battery, 0, eoprot_tag_as_battery_status_timedvalue);
141 vector<eOprotID32_t> ids = {id32First};
143 EXPECT_CALL(deviceRes, serviceSetRegulars(eomn_serv_category_battery, ids, _)).WillOnce(Return(
true));
150 TEST(CanBatterysensor, serviceSetRegulars_simple_negative_001)
155 parser.
batteryInfo_ = {100, eobrd_bms, 0, 0, 0, 0, 0, 0, 0};
157 uint32_t id32First = eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_battery, 0, eoprot_tag_as_battery_status_timedvalue);
158 vector<eOprotID32_t> ids = {id32First};
160 EXPECT_CALL(deviceRes, serviceSetRegulars(eomn_serv_category_battery, ids, _)).WillOnce(Return(
false));
167 TEST(CanBatterysensor, update_simple_positive_001)
170 yarp::os::Network::init();
171 std::shared_ptr<embObjDevPrivData_Mock> privateData = std::make_shared<embObjDevPrivData_Mock>(
"test");
173 uint32_t id32First = eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_battery, 0, eoprot_tag_as_ft_status_timedvalue);
174 eOas_battery_timedvalue_t
data = {0 , 10 , 0, 2, 3, 4, 5, 0};
177 EXPECT_CALL(*privateData, isOpen()).WillRepeatedly(Return(
true));
178 EXPECT_CALL(device, calculateBoardTime(_)).WillRepeatedly(Return(7));
181 bool ret = device.
update(id32First, 1, (
void *)&
data);
186 TEST(CanBatterysensor, update_simple_positive_trunk_voltage_001)
189 yarp::os::Network::init();
190 std::shared_ptr<embObjDevPrivData_Mock> privateData = std::make_shared<embObjDevPrivData_Mock>(
"test");
192 uint32_t id32First = eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_battery, 0, eoprot_tag_as_ft_status_timedvalue);
193 eOas_battery_timedvalue_t
data = {0 , 10 , 0, 2, 3, 4.123, 5, 0};
196 EXPECT_CALL(*privateData, isOpen()).WillRepeatedly(Return(
true));
197 EXPECT_CALL(device, calculateBoardTime(_)).WillRepeatedly(Return(7));
200 bool ret = device.
update(id32First, 1, (
void *)&
data);
205 TEST(CanBatterysensor, update_simple_negative_001)
208 yarp::os::Network::init();
209 std::shared_ptr<embObjDevPrivData_Mock> privateData = std::make_shared<embObjDevPrivData_Mock>(
"test");
211 uint32_t id32First = eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_battery, 0, eoprot_tag_as_ft_status_timedvalue);
212 eOas_battery_timedvalue_t
data = {0 , 10 , 2, 3, 4, 9};
215 EXPECT_CALL(*privateData, isOpen()).WillRepeatedly(Return(
true));
216 EXPECT_CALL(device, calculateBoardTime(_)).WillRepeatedly(Return(7));
219 bool ret = device.
update(id32First, 1, (
void *)&
data);
224 TEST(CanBatterysensor, getBatteryVoltage_positive_001)
227 std::shared_ptr<embObjDevPrivData_Mock> privateData = std::make_shared<embObjDevPrivData_Mock>(
"test");
232 EXPECT_CALL(*privateData, isOpen()).WillRepeatedly(Return(
true));
239 EXPECT_EQ(expected,
data);
242 TEST(CanBatterysensor, calculateBoardTime_positive_001)
245 yarp::os::Network::init();
246 std::shared_ptr<embObjDevPrivData_Mock> privateData = std::make_shared<embObjDevPrivData_Mock>(
"test");
249 EXPECT_CALL(*privateData, isOpen()).WillRepeatedly(Return(
true));
254 double first = device.embObjBattery::calculateBoardTime(1000000);
255 double second = device.embObjBattery::calculateBoardTime(2000000);
256 double third = device.embObjBattery::calculateBoardTime(3000000);
257 double diff = second - first;
259 EXPECT_TRUE(1.0 == diff);
261 diff = third - first;
263 EXPECT_TRUE(2.0 == diff);
269 std::shared_ptr<embObjDevPrivData_Mock> privateData = std::make_shared<embObjDevPrivData_Mock>(
"test");
272 EXPECT_CALL(*privateData, isOpen()).WillRepeatedly(Return(
true));
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))
MOCK_METHOD(double, calculateBoardTime,(eOabstime_t),(override))
embObjCanBatterysensor_Mock()
embObjCanBatterysensor_Mock(std::shared_ptr< yarp::dev::embObjDevPrivData > device)
embObjDevPrivData_Mock(std::string name)
MOCK_METHOD(bool, isOpen,(),(const, override))
eth::iethresType_t type() override
bool sendConfig2boards(ServiceParserCanBattery &parser, eth::AbstractEthResource *deviceRes)
bool getBatteryVoltage(double &voltage) override
bool sendStart2boards(ServiceParserCanBattery &parser, eth::AbstractEthResource *deviceRes)
bool initRegulars(ServiceParserCanBattery &parser, eth::AbstractEthResource *deviceRes)
bool update(eOprotID32_t id32, double timestamp, void *rxdata) override
CanBatteryData canBatteryData_
Copyright (C) 2008 RobotCub Consortium.
TEST(CanBatterysensor, sendConfig2boards_simple_positive_001)