iCub-main
Loading...
Searching...
No Matches
testServiceParserCanBattery.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
9#include <yarp/os/ResourceFinder.h>
10
11#include <iostream>
12#include <vector>
13
14#include "EoManagement.h"
15#include "gmock/gmock.h"
16#include "gtest/gtest.h"
18#include "testUtils.h"
19
20using ::testing::_;
21using ::testing::An;
22using ::testing::Eq;
23using ::testing::Gt;
24using ::testing::InSequence;
25using ::testing::InvokeArgument;
26using ::testing::Matcher;
27using ::testing::Pointee;
28using ::testing::Return;
29using ::testing::TypedEq;
30using testing::internal::operator==;
31
32TEST(ServiceParserCanBattery, check_settings_positive_001)
33{
34 yarp::os::Bottle bottle;
35 bottle.fromString("(SETTINGS (acquisitionRate 100) (enabledSensors fakeId) )");
36
37 ServiceParserCanBattery_mock serviceParser;
38
39 bool ret = serviceParser.checkSettings(bottle);
40
41 std::map<std::string, BatteryInfo> expected = {{"fakeId", {100, eobrd_unknown, 0, 0, 0, 0, 0, 0, 0}}};
42
43 EXPECT_TRUE(ret);
44
45 EXPECT_EQ(expected.at("fakeId"), serviceParser.batteryInfo_);
46}
47
48TEST(ServiceParserCanBattery, check_settings_negative_001)
49{
50 yarp::os::Bottle bottle;
51 bottle.fromString("(SETTINGS (acquisitionRate 100) (enabledSensors) )");
52
53 ServiceParserMultipleFt_mock serviceParser;
54
55 bool ret = serviceParser.checkSettings(bottle);
56
57 EXPECT_FALSE(ret);
58}
59
60TEST(ServiceParserCanBattery, check_settings_negative_002)
61{
62 yarp::os::Bottle bottle;
63 bottle.fromString("(SETTINGS (acquisitionRate) (enabledSensors fakeId) )");
64
65 ServiceParserMultipleFt_mock serviceParser;
66
67 bool ret = serviceParser.checkSettings(bottle);
68
69 EXPECT_FALSE(ret);
70}
71
72TEST(ServiceParserCanBattery, check_settings_negative_003)
73{
74 yarp::os::Bottle bottle;
75 bottle.fromString("(XXX (acquisitionRate 100) (enabledSensors fakeId) )");
76
77 ServiceParserMultipleFt_mock serviceParser;
78
79 bool ret = serviceParser.checkSettings(bottle);
80
81 EXPECT_FALSE(ret);
82}
83
84TEST(ServiceParserCanBattery, check_settings_negative_004)
85{
86 yarp::os::Bottle bottle;
87 bottle.fromString("(SETTINGS (xxx 100) (enabledSensors fakeId) )");
88
89 ServiceParserMultipleFt_mock serviceParser;
90
91 bool ret = serviceParser.checkSettings(bottle);
92
93 EXPECT_FALSE(ret);
94}
95
96TEST(ServiceParserCanBattery, check_settings_negative_005)
97{
98 yarp::os::Bottle bottle;
99 bottle.fromString("(SETTINGS (acquisitionRate) (XXX fakeId) )");
100
101 ServiceParserMultipleFt_mock serviceParser;
102
103 bool ret = serviceParser.checkSettings(bottle);
104
105 EXPECT_FALSE(ret);
106}
107
108TEST(ServiceParserCanBattery, check_property_sensors_positive_001)
109{
110 ServiceParserCanBattery_mock serviceParser;
111 yarp::os::Bottle bottle;
112 bottle.fromString("(SENSORS (id fakeId) (board bms) (location CAN2:13) )");
113 serviceParser.batteryInfo_ = {100, eobrd_unknown, 0, 0, 0, 0, 0, 0, 0};
114
115 bool ret = serviceParser.checkPropertySensors(bottle);
116
117 BatteryInfo expected = {100, eobrd_bms, 2, 13, 0, 0, 0, 0, 0};
118
119 EXPECT_TRUE(ret);
120
121 EXPECT_EQ(expected, serviceParser.batteryInfo_);
122}
123
124TEST(ServiceParserCanBattery, check_property_sensors_negative_001)
125{
126 ServiceParserCanBattery_mock serviceParser;
127 yarp::os::Bottle bottle;
128 bottle.fromString("(SENSORS (id fakeId) (xxx bms) (location CAN2:13) )");
129 serviceParser.batteryInfo_ = {100, eobrd_unknown, 0, 0, 0, 0, 0, 0, 0};
130
131 bool ret = serviceParser.checkPropertySensors(bottle);
132
133 EXPECT_FALSE(ret);
134}
135
136TEST(ServiceParserCanBattery, check_property_sensors_negative_002)
137{
138 ServiceParserCanBattery_mock serviceParser;
139 yarp::os::Bottle bottle;
140 bottle.fromString("(SENSORS (id fakeId) (board bms) (xxx CAN2:13) )");
141 serviceParser.batteryInfo_ = {100, eobrd_unknown, 0, 0, 0, 0, 0, 0, 0};
142
143 bool ret = serviceParser.checkPropertySensors(bottle);
144
145 EXPECT_FALSE(ret);
146}
147
148TEST(ServiceParserCanBattery, check_property_canboards_positive_001)
149{
150 ServiceParserCanBattery_mock serviceParser;
151 yarp::os::Bottle bottle;
152 bottle.fromString("(CANBOARDS (type bms) (PROTOCOL (major 2) (minor 3) ) (FIRMWARE (major 4) (minor 5) (build 6) ) )");
153 serviceParser.batteryInfo_ = {100, eobrd_bms, 2, 13, 0, 0, 0, 0, 0};
154
155 bool ret = serviceParser.checkPropertyCanBoards(bottle);
156
157 BatteryInfo expected = {100, eobrd_bms, 2, 13, 2, 3, 4, 5, 6};
158
159 EXPECT_TRUE(ret);
160
161 EXPECT_EQ(expected, serviceParser.batteryInfo_);
162}
163
164TEST(ServiceParserCanBattery, check_property_canboards_negative_001)
165{
166 ServiceParserCanBattery_mock serviceParser;
167 yarp::os::Bottle bottle;
168 bottle.fromString("(CANBOARDS (xxx bms) (PROTOCOL (major 2) (minor 3) ) (FIRMWARE (major 4) (minor 5) (build 6) ) )");
169 serviceParser.batteryInfo_ = {100, eobrd_bms, 2, 13, 0, 0, 0, 0, 0};
170
171 bool ret = serviceParser.checkPropertyCanBoards(bottle);
172
173 EXPECT_FALSE(ret);
174}
175
176TEST(ServiceParserCanBattery, check_property_canboards_negative_002)
177{
178 ServiceParserCanBattery_mock serviceParser;
179 yarp::os::Bottle bottle;
180 bottle.fromString("(CANBOARDS (type bms) (XXX (major 2) (minor 3) ) (FIRMWARE (major 4) (minor 5) (build 6) ) )");
181 serviceParser.batteryInfo_ = {100, eobrd_bms, 2, 13, 0, 0, 0, 0, 0};
182
183 bool ret = serviceParser.checkPropertyCanBoards(bottle);
184
185 EXPECT_FALSE(ret);
186}
187
188TEST(ServiceParserCanBattery, check_property_canboards_negative_003)
189{
190 ServiceParserCanBattery_mock serviceParser;
191 yarp::os::Bottle bottle;
192 bottle.fromString("(CANBOARDS (type bms) (PROTOCOL (xx 2) (minor 3) ) (FIRMWARE (major 4) (minor 5) (build 6) ) )");
193 serviceParser.batteryInfo_ = {100, eobrd_bms, 2, 13, 0, 0, 0, 0, 0};
194
195 bool ret = serviceParser.checkPropertyCanBoards(bottle);
196
197 EXPECT_FALSE(ret);
198}
199
200TEST(ServiceParserCanBattery, check_property_canboards_negative_004)
201{
202 ServiceParserCanBattery_mock serviceParser;
203 yarp::os::Bottle bottle;
204 bottle.fromString("(CANBOARDS (type bms) (PROTOCOL (major 2) (xx 3) ) (FIRMWARE (major 4) (minor 5) (build 6) ) )");
205 serviceParser.batteryInfo_ = {100, eobrd_bms, 2, 13, 0, 0, 0, 0, 0};
206
207 bool ret = serviceParser.checkPropertyCanBoards(bottle);
208
209 EXPECT_FALSE(ret);
210}
211
212TEST(ServiceParserCanBattery, check_property_canboards_negative_005)
213{
214 ServiceParserCanBattery_mock serviceParser;
215 yarp::os::Bottle bottle;
216 bottle.fromString("(CANBOARDS (type bms) (PROTOCOL (major 2) (minor 3) ) (xx (major 4) (minor 5) (build 6) ) )");
217 serviceParser.batteryInfo_ = {100, eobrd_bms, 2, 13, 0, 0, 0, 0, 0};
218
219 bool ret = serviceParser.checkPropertyCanBoards(bottle);
220
221 EXPECT_FALSE(ret);
222}
223
224TEST(ServiceParserCanBattery, check_property_canboards_negative_006)
225{
226 ServiceParserCanBattery_mock serviceParser;
227 yarp::os::Bottle bottle;
228 bottle.fromString("(CANBOARDS (type bms) (PROTOCOL (major 2) (minor 3) ) (FIRMWARE (xx 4) (minor 5) (build 6) ) )");
229 serviceParser.batteryInfo_ = {100, eobrd_bms, 2, 13, 0, 0, 0, 0, 0};
230
231 bool ret = serviceParser.checkPropertyCanBoards(bottle);
232
233 EXPECT_FALSE(ret);
234}
235
236TEST(ServiceParserCanBattery, check_property_canboards_negative_007)
237{
238 ServiceParserCanBattery_mock serviceParser;
239 yarp::os::Bottle bottle;
240 bottle.fromString("(CANBOARDS (type bms) (PROTOCOL (major 2) (minor 3) ) (FIRMWARE (major 4) (xx 5) (build 6) ) )");
241 serviceParser.batteryInfo_ = {100, eobrd_bms, 2, 13, 0, 0, 0, 0, 0};
242
243 bool ret = serviceParser.checkPropertyCanBoards(bottle);
244
245 EXPECT_FALSE(ret);
246}
247TEST(ServiceParserCanBattery, check_property_canboards_negative_008)
248{
249 ServiceParserCanBattery_mock serviceParser;
250 yarp::os::Bottle bottle;
251 bottle.fromString("(CANBOARDS (type bms) (PROTOCOL (major 2) (minor 3) ) (FIRMWARE (major 4) (minor 5) (xx 6) ) )");
252 serviceParser.batteryInfo_ = {100, eobrd_bms, 2, 13, 0, 0, 0, 0, 0};
253
254 bool ret = serviceParser.checkPropertyCanBoards(bottle);
255
256 EXPECT_FALSE(ret);
257}
258
259TEST(ServiceParserCanBattery, check_property_canboards_negative_009)
260{
261 ServiceParserCanBattery_mock serviceParser;
262 yarp::os::Bottle bottle;
263 bottle.fromString("(CANBOARDS (type xx) (PROTOCOL (major 2) (minor 3) ) (FIRMWARE (major 4) (minor 5) (build 6) ) )");
264 serviceParser.batteryInfo_ = {100, eobrd_bms, 2, 13, 0, 0, 0, 0, 0};
265
266 bool ret = serviceParser.checkPropertyCanBoards(bottle);
267
268 EXPECT_FALSE(ret);
269}
270
271TEST(ServiceParserCanBattery, checkBoardType_positive_001) {
272 ServiceParserCanBattery_mock serviceParser;
273
274 eObrd_type_t expected = eobrd_bms;
275
276 EXPECT_EQ(expected, serviceParser.checkBoardType("bms"));
277}
278
279TEST(ServiceParserCanBattery, checkBoardType_negative_001) {
280 ServiceParserCanBattery_mock serviceParser;
281
282 eObrd_type_t expected = eobrd_bms;
283
284 EXPECT_NE(expected, serviceParser.checkBoardType("eobrd_strain2"));
285}
286
287TEST(ServiceParserCanBattery, checkBoardType_negative_002) {
288 ServiceParserCanBattery_mock serviceParser;
289
290 eObrd_type_t expected = eobrd_bms;
291
292 EXPECT_NE(expected, serviceParser.checkBoardType(""));
293}
294
295
296TEST(General, toEomn_positive_001) {
297 BatteryInfo info = {100, eobrd_bms, 1, 13, 4, 5, 1, 2, 3};
298
299 eOas_battery_sensordescriptor_t out;
300 bool res = info.toEomn(out);
301
302 eOas_battery_sensordescriptor_t expected = {{eobrd_bms, {1, 2, 3}, {4, 5}}, {eOcanport1, 13, 2}};
303
304 EXPECT_TRUE(res);
305 EXPECT_EQ(expected, out);
306}
307
308TEST(General, toEomn_negative_001) {
309 BatteryInfo info = {100, eobrd_bms, 5, 13, 4, 5, 1, 2, 3};
310
311 eOas_battery_sensordescriptor_t out;
312 bool res = info.toEomn(out);
313
314 EXPECT_FALSE(res);
315}
virtual bool checkSettings(const Bottle &settings)
virtual bool checkPropertySensors(const Bottle &property)
virtual eObrd_type_t checkBoardType(const std::string &boardType)
virtual bool checkPropertyCanBoards(const Bottle &bPropertiesCanBoards)
virtual bool checkSettings(const Bottle &settings)
out
Definition sine.m:8
TEST(ServiceParserCanBattery, check_settings_positive_001)