YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
IMap2DTest.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#ifndef IMAP2DTEST_H
7#define IMAP2DTEST_H
8
9#include <yarp/dev/api.h>
10#include <yarp/dev/IMap2D.h>
11#include <catch2/catch_amalgamated.hpp>
12
13using namespace yarp::dev;
14using namespace yarp::dev::Nav2D;
15using namespace yarp::sig;
16using namespace yarp::os;
17
18namespace yarp::dev::tests
19{
21 {
22 {
24 std::vector<std::string> ll;
25 std::vector<std::string> la;
26 std::vector<std::string> lp;
27 {
28 Map2DLocation l1 = Map2DLocation("map_1", 10.0, 20.0, 15);
29 Map2DLocation l2 = Map2DLocation("map_1", 10.2, 20.1, 15.5);
30 Map2DArea a1("map_1", std::vector<Map2DLocation> {Map2DLocation("map_1", -10, -10, 0),
31 Map2DLocation("map_1", -10, +10, 0),
32 Map2DLocation("map_1", +10, +10, 0),
33 Map2DLocation("map_1", +10, -10, 0)});
34 Map2DPath p1(std::vector<Map2DLocation> {l1, l2});
35 bool b;
36 b = imap->storeArea("area_test1", a1); CHECK(b);
37 b = imap->storeLocation("loc_test1", l1); CHECK(b);
38 b = imap->storeLocation("loc_test2", l2); CHECK(b);
39 b = imap->storePath("path_test1", p1); CHECK(b);
40 b = imap->getLocationsList(ll); CHECK(b); CHECK(ll.size() == 2);
41 b = imap->getAreasList(la); CHECK(b); CHECK(la.size() == 1);
42 b = imap->getPathsList(lp); CHECK(b); CHECK(lp.size() == 1);
43 }
44
45 {
46 bool b;
47 b = imap->saveLocationsAndExtras("locations_test.ini"); CHECK(b);
48 b = imap->clearAllLocations(); CHECK(b);
49 b = imap->clearAllAreas(); CHECK(b);
50 b = imap->clearAllPaths(); CHECK(b);
51 b = imap->getLocationsList(ll); CHECK(b); CHECK(ll.size() == 0);
52 b = imap->getAreasList(la); CHECK(b); CHECK(la.size() == 0);
53 b = imap->getPathsList(lp); CHECK(b); CHECK(lp.size() == 0);
54
55 b = imap->loadLocationsAndExtras("locations_test.ini"); CHECK(b);
60 b = imap->getLocationsList(ll); CHECK(b); CHECK(ll.size() == 2);
61 b = imap->getAreasList(la); CHECK(b); CHECK(la.size() == 1);
62 b = imap->getPathsList(lp); CHECK(b); CHECK(lp.size() == 1);
63
64 b = imap->getLocation("loc_test1", l1t); CHECK(b);
65 b = imap->getLocation("loc_test2", l2t); CHECK(b);
66 b = imap->getArea("area_test1", a1); CHECK(b);
67 b = imap->getPath("path_test1", p1); CHECK(b);
68 }
69 }
70 }
71
73 {
75 {
76 std::vector <Map2DArea> areas;
77 std::vector <Map2DLocation> locs;
78 std::vector <std::string> loc_names;
79 Map2DLocation loc;
80 Map2DArea area;
81 bool ret;
82 bool b1;
83 ret = imap->clearAllLocations(); CHECK(ret);
84 ret = imap->clearAllAreas(); CHECK(ret);
85 ret = imap->getAreasList(loc_names); CHECK(ret);
86 b1 = (loc_names.size() == 0);
87 CHECK(b1);
88 ret = imap->getLocationsList(loc_names); CHECK(ret);
89 b1 = (loc_names.size() == 0);
90 CHECK(b1);
91
92 ret = imap->storeLocation("loc1", Map2DLocation("map1", 1, 2, 3)); CHECK(ret);
93 ret = imap->storeLocation("loc2", Map2DLocation("map2", 4, 5, 6)); CHECK(ret);
94
95 std::vector<Map2DLocation> vec1, vec2, vec3;
97 v.x = 1.1; v.y = 1.1; vec1.push_back(v);
98 v.x = 1.2; v.y = 1.2; vec1.push_back(v);
99 v.x = 1.3; v.y = 1.3; vec1.push_back(v);
100 ret = imap->storeArea("area1", Map2DArea("map1", vec1)); CHECK(ret);
101 v.x = 2.1; v.y = 2.1; vec2 = vec1; vec2.push_back(v);
102 ret = imap->storeArea("area2", Map2DArea("map2", vec2)); CHECK(ret);
103 v.x = 3.1; v.y = 3.1; vec3 = vec2; vec3.push_back(v);
104 ret = imap->storeArea("area3", Map2DArea("map3", vec3)); CHECK(ret);
105
106 ret = imap->getAreasList(loc_names); CHECK(ret);
107 b1 = (loc_names.size() == 3);
108 CHECK(b1);
109 ret = imap->getLocationsList(loc_names); CHECK(ret);
110 b1 = (loc_names.size() == 2);
111 CHECK(b1);
112
113 ret = imap->getArea("area1", area); CHECK(ret);
114 b1 = (area == Map2DArea("map1", vec1));
115 CHECK(b1);
116 ret = imap->getArea("area_err", area); CHECK(ret == false);
117
118 ret = imap->getLocation("loc1", loc); CHECK(ret);
119 b1 = (loc == Map2DLocation("map1", 1, 2, 3));
120 CHECK(b1);
121 ret = imap->getLocation("loc_err", loc); CHECK(ret == false);
122
123 ret = imap->deleteArea("area1"); CHECK(ret);
124 ret = imap->deleteLocation("loc1"); CHECK(ret);
125 ret = imap->deleteArea("area_err"); CHECK(ret == false);
126 ret = imap->deleteLocation("loc_err"); CHECK(ret == false);
127 ret = imap->getArea("area1", area); CHECK(ret == false);
128 ret = imap->getLocation("loc1", loc); CHECK(ret == false);
129
130 ret = imap->getArea("area2", area); CHECK(ret);
131 b1 = (area == Map2DArea("map2", vec2));
132 CHECK(b1);
133 ret = imap->getLocation("loc2", loc); CHECK(ret);
134 b1 = (loc == Map2DLocation("map2", 4, 5, 6));
135 CHECK(b1);
136
137 ret = imap->clearAllLocations(); CHECK(ret);
138 ret = imap->clearAllAreas(); CHECK(ret);
139 ret = imap->getAreasList(loc_names); CHECK(ret);
140 b1 = (loc_names.size() == 0);
141 CHECK(b1);
142 imap->getLocationsList(loc_names);
143 b1 = (loc_names.size() == 0);
144 CHECK(b1);
145
146 ret = imap->storeArea("area", Map2DArea("map1", vec1)); CHECK(ret);
147 ret = imap->storeLocation("loc", Map2DLocation("map2", 4, 5, 6)); CHECK(ret);
148 ret = imap->renameArea("area_fail", "area_new"); CHECK(ret == false);
149 ret = imap->renameLocation("loc_fail", "loc_new"); CHECK(ret == false);
150 ret = imap->renameArea("area", "area_new"); CHECK(ret);
151 ret = imap->renameLocation("loc", "loc_new"); CHECK(ret);
152 ret = imap->getArea("area", area); CHECK(ret == false);
153 ret = imap->getArea("area_new", area); CHECK(ret);
154 ret = imap->getLocation("loc", loc); CHECK(ret == false);
155 ret = imap->getLocation("loc_new", loc); CHECK(ret);
156
157 //final cleanup, already tested
158 ret = imap->clearAllLocations(); CHECK(ret);
159 ret = imap->clearAllAreas(); CHECK(ret);
160 }
161
163 {
164 std::vector <Map2DPath> paths;
165 std::vector <Map2DLocation> locs;
166 std::vector <std::string> loc_names;
167 std::vector <std::string> path_names;
168 Map2DLocation loc;
169 Map2DPath path;
170 bool ret;
171 bool b1;
172 ret = imap->clearAllLocations(); CHECK(ret);
173 ret = imap->clearAllPaths(); CHECK(ret);
174 ret = imap->getPathsList(path_names); CHECK(ret);
175 b1 = (path_names.size() == 0);
176 CHECK(b1);
177 ret = imap->getLocationsList(loc_names); CHECK(ret);
178 b1 = (loc_names.size() == 0);
179 CHECK(b1);
180
181 ret = imap->storeLocation("loc1", Map2DLocation("map1", 1, 2, 3)); CHECK(ret);
182 ret = imap->storeLocation("loc2", Map2DLocation("map2", 4, 5, 6)); CHECK(ret);
183
184 std::vector<Map2DLocation> vec1, vec2, vec3;
186 v.x = 1.1; v.y = 1.1; vec1.push_back(v);
187 v.x = 1.2; v.y = 1.2; vec1.push_back(v);
188 v.x = 1.3; v.y = 1.3; vec1.push_back(v);
189 ret = imap->storePath("path1", Map2DPath(vec1)); CHECK(ret);
190 v.x = 2.1; v.y = 2.1; vec2 = vec1; vec2.push_back(v);
191 ret = imap->storePath("path2", Map2DPath(vec2)); CHECK(ret);
192 v.x = 3.1; v.y = 3.1; vec3 = vec2; vec3.push_back(v);
193 ret = imap->storePath("path3", Map2DPath(vec3)); CHECK(ret);
194
195 ret = imap->getPathsList(path_names); CHECK(ret);
196 b1 = (path_names.size() == 3);
197 CHECK(b1);
198 ret = imap->getLocationsList(loc_names); CHECK(ret);
199 b1 = (loc_names.size() == 2);
200 CHECK(b1);
201
202 ret = imap->getPath("path1", path); CHECK(ret);
203 b1 = (path == Map2DPath(vec1));
204 CHECK(b1);
205 ret = imap->getPath("path_err", path); CHECK(ret == false);
206
207 ret = imap->getLocation("loc1", loc); CHECK(ret);
208 b1 = (loc == Map2DLocation("map1", 1, 2, 3));
209 CHECK(b1);
210 ret = imap->getLocation("loc_err", loc); CHECK(ret == false);
211
212 ret = imap->deletePath("path1"); CHECK(ret);
213 ret = imap->deleteLocation("loc1"); CHECK(ret);
214 ret = imap->deletePath("path_err"); CHECK(ret == false);
215 ret = imap->deleteLocation("loc_err"); CHECK(ret == false);
216 ret = imap->getPath("path1", path); CHECK(ret == false);
217 ret = imap->getLocation("loc1", loc); CHECK(ret == false);
218
219 ret = imap->getPath("path2", path); CHECK(ret);
220 b1 = (path == Map2DPath(vec2));
221 CHECK(b1);
222 ret = imap->getLocation("loc2", loc); CHECK(ret);
223 b1 = (loc == Map2DLocation("map2", 4, 5, 6));
224 CHECK(b1);
225
226 ret = imap->clearAllLocations(); CHECK(ret);
227 ret = imap->clearAllPaths(); CHECK(ret);
228 ret = imap->getPathsList(path_names); CHECK(ret);
229 b1 = (path_names.size() == 0);
230 CHECK(b1);
231 imap->getLocationsList(loc_names);
232 b1 = (loc_names.size() == 0);
233 CHECK(b1);
234
235 ret = imap->storePath("path", Map2DPath(vec1)); CHECK(ret);
236 ret = imap->storeLocation("loc", Map2DLocation("map2", 4, 5, 6)); CHECK(ret);
237 ret = imap->renamePath("path_fail", "path_new"); CHECK(ret == false);
238 ret = imap->renameLocation("loc_fail", "loc_new"); CHECK(ret == false);
239 ret = imap->renamePath("path", "path_new"); CHECK(ret);
240 ret = imap->renameLocation("loc", "loc_new"); CHECK(ret);
241 ret = imap->getPath("path", path); CHECK(ret == false);
242 ret = imap->getPath("path_new", path); CHECK(ret);
243 ret = imap->getLocation("loc", loc); CHECK(ret == false);
244 ret = imap->getLocation("loc_new", loc); CHECK(ret);
245
246 std::string s = path.toString();
247
248 //final cleanup, already tested
249 ret = imap->clearAllLocations(); CHECK(ret);
250 ret = imap->clearAllPaths(); CHECK(ret);
251 }
252
254 {
258
259 test_store_map1.setMapName("test_map1");
260 test_store_map2.setMapName("test_map2");
261 std::vector<std::string> map_names;
262
263 imap->store_map(test_store_map1);
264 imap->store_map(test_store_map2);
265 imap->get_map("test_map1", test_get_map);
266 CHECK(test_store_map1.isIdenticalTo(test_get_map)); // IMap2D store/get operation successful
267
268 imap->get_map_names(map_names);
269 bool b1 = (map_names.size() == 2);
270 bool b2 = false;
271 if (b1) {
272 b2 = (map_names[0] == "test_map1" && map_names[1] == "test_map2");
273 }
274 CHECK(b1);
275 CHECK(b2);
276 // IMap2D get_map_names operation successful")
277
278 imap->remove_map("test_map1");
279 imap->get_map_names(map_names);
280 b1 = (map_names.size() == 1);
281 CHECK(b1); // IMap2D remove_map operation successful
282
283 imap->clearAllMaps();
284 imap->get_map_names(map_names);
285 b1 = (map_names.size() == 0);
286 CHECK(b1); // IMap2D clear operation successful
287 }
288 }
289}
290
291#endif
bool ret
double y
y position of the location [m], expressed in the map reference frame
double x
x position of the location [m], expressed in the map reference frame
IMap2D Interface.
Definition IMap2D.h:29
std::string toString() const
Returns text representation of the path.
Definition Map2DPath.cpp:42
A mini-server for performing network communication in the background.
void exec_iMap2D_test_1(IMap2D *imap)
Definition IMap2DTest.h:20
void exec_iMap2D_test_2(IMap2D *imap)
Definition IMap2DTest.h:72
For streams capable of holding different kinds of content, check what they actually have.
Definition jointData.cpp:13
An interface to the operating system, including Port based communication.