Skip to content

Commit 0592491

Browse files
committed
Clean up middle test code
* Change order of add_node() parameters to match Location * Add add_node_and_get() and add_way_and_get() helpers * Add all vector constructors to idlist_t
1 parent 8ff4237 commit 0592491

2 files changed

Lines changed: 28 additions & 16 deletions

File tree

src/osmtypes.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,12 @@ class taglist_t
232232

233233
struct idlist_t : public std::vector<osmid_t>
234234
{
235-
idlist_t() {}
235+
// Get all constructors from std::vector
236+
using vector<osmid_t>::vector;
237+
238+
// Even though we got all constructors from std::vector we need this on
239+
// some compilers/libraries for some reason.
240+
idlist_t() = default;
236241

237242
explicit idlist_t(osmium::NodeRefList const &list)
238243
{

tests/test-middle.cpp

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ namespace {
1616
/// Simple osmium buffer to store object with some convenience.
1717
struct test_buffer_t
1818
{
19-
size_t add_node(osmid_t id, double lat, double lon)
19+
size_t add_node(osmid_t id, double lon, double lat)
2020
{
2121
using namespace osmium::builder::attr;
2222
return osmium::builder::add_node(buf, _id(id), _location(lon, lat));
2323
}
2424

25-
size_t add_way(osmid_t wid, std::vector<osmid_t> const &ids)
25+
size_t add_way(osmid_t wid, idlist_t const &ids)
2626
{
2727
using namespace osmium::builder::attr;
2828
return osmium::builder::add_way(buf, _id(wid), _nodes(ids));
@@ -40,6 +40,16 @@ struct test_buffer_t
4040
return buf.get<T>(pos);
4141
}
4242

43+
osmium::Node const &add_node_and_get(osmid_t id, double lon, double lat)
44+
{
45+
return get<osmium::Node>(add_node(id, lon, lat));
46+
}
47+
48+
osmium::Way &add_way_and_get(osmid_t wid, idlist_t const &ids)
49+
{
50+
return get<osmium::Way>(add_way(wid, ids));
51+
}
52+
4353
osmium::memory::Buffer buf{4096, osmium::memory::Buffer::auto_grow::yes};
4454
};
4555

@@ -125,45 +135,43 @@ TEMPLATE_TEST_CASE("middle import", "", options_slim_default,
125135

126136
SECTION("Set and retrieve a single node")
127137
{
128-
auto const &node = buffer.get<osmium::Node>(
129-
buffer.add_node(1234, 12.3456789, 98.7654321));
138+
auto const &node =
139+
buffer.add_node_and_get(1234, 98.7654321, 12.3456789);
130140

131141
// set the node
132142
mid->nodes_set(node);
133143
mid->flush();
134144

135145
// getting it back works only via a waylist
136-
auto &nodes =
137-
buffer.get<osmium::Way>(buffer.add_way(3, {1234})).nodes();
146+
auto &nodes = buffer.add_way_and_get(3, {1234}).nodes();
138147

139148
// get it back
140149
REQUIRE(mid_q->nodes_get_list(&nodes) == nodes.size());
141150
expect_location(nodes[0].location(), node);
142151

143152
// other nodes are not retrievable
144-
auto &n2 =
145-
buffer.get<osmium::Way>(buffer.add_way(3, {1, 2, 1235})).nodes();
153+
auto &n2 = buffer.add_way_and_get(3, {1, 2, 1235}).nodes();
146154
REQUIRE(mid_q->nodes_get_list(&n2) == 0);
147155
}
148156

149157
SECTION("Set and retrieve a single way")
150158
{
151159
osmid_t const way_id = 1;
152-
double const lat = 12.3456789;
153160
double const lon = 98.7654321;
161+
double const lat = 12.3456789;
154162
idlist_t nds;
155163
std::vector<size_t> nodes;
156164

157165
// set nodes
158166
for (osmid_t i = 1; i <= 10; ++i) {
159167
nds.push_back(i);
160168
nodes.push_back(
161-
buffer.add_node(i, lat + i * 0.001, lon - i * 0.003));
169+
buffer.add_node(i, lon - i * 0.003, lat + i * 0.001));
162170
mid->nodes_set(buffer.get<osmium::Node>(nodes.back()));
163171
}
164172

165173
// set the way
166-
mid->ways_set(buffer.get<osmium::Way>(buffer.add_way(way_id, nds)));
174+
mid->ways_set(buffer.add_way_and_get(way_id, nds));
167175

168176
mid->flush();
169177

@@ -189,16 +197,15 @@ TEMPLATE_TEST_CASE("middle import", "", options_slim_default,
189197

190198
SECTION("Set and retrieve a single relation with supporting ways")
191199
{
192-
std::vector<osmid_t> const nds[] = {
193-
{4, 5, 13, 14, 342}, {45, 90}, {30, 3, 45}};
200+
idlist_t const nds[] = {{4, 5, 13, 14, 342}, {45, 90}, {30, 3, 45}};
194201

195202
// set the node
196-
mid->nodes_set(buffer.get<osmium::Node>(buffer.add_node(1, 12.8, 4.1)));
203+
mid->nodes_set(buffer.add_node_and_get(1, 4.1, 12.8));
197204

198205
// set the ways
199206
osmid_t wid = 10;
200207
for (auto const &n : nds) {
201-
mid->ways_set(buffer.get<osmium::Way>(buffer.add_way(wid, n)));
208+
mid->ways_set(buffer.add_way_and_get(wid, n));
202209
++wid;
203210
}
204211

0 commit comments

Comments
 (0)