Skip to content

Commit ddcb625

Browse files
committed
Refactor test_buffer_t in middle test
New add_relation() function to make adding relations easier. This allows use to make the buffer internal to the class for better encapsulation.
1 parent c88ca78 commit ddcb625

1 file changed

Lines changed: 24 additions & 16 deletions

File tree

tests/test-middle.cpp

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ static pg::tempdb_t db;
1515
namespace {
1616

1717
/// Simple osmium buffer to store object with some convenience.
18-
struct test_buffer_t
18+
class test_buffer_t
1919
{
20+
public:
2021
size_t add_node(osmid_t id, double lon, double lat)
2122
{
2223
using namespace osmium::builder::attr;
@@ -29,6 +30,15 @@ struct test_buffer_t
2930
return osmium::builder::add_way(buf, _id(wid), _nodes(ids));
3031
}
3132

33+
size_t add_relation(
34+
osmid_t rid,
35+
std::initializer_list<osmium::builder::attr::member_type> members)
36+
{
37+
using namespace osmium::builder::attr;
38+
return osmium::builder::add_relation(
39+
buf, _id(rid), _members(members.begin(), members.end()));
40+
}
41+
3242
template <typename T>
3343
T const &get(size_t pos) const
3444
{
@@ -51,6 +61,7 @@ struct test_buffer_t
5161
return get<osmium::Way>(add_way(wid, ids));
5262
}
5363

64+
private:
5465
osmium::memory::Buffer buf{4096, osmium::memory::Buffer::auto_grow::yes};
5566
};
5667

@@ -221,15 +232,11 @@ TEMPLATE_TEST_CASE("middle import", "", options_slim_default,
221232
}
222233

223234
// set the relation
224-
auto const pos = buffer.buf.committed();
225-
{
226-
using namespace osmium::builder::attr;
227-
using otype = osmium::item_type;
228-
osmium::builder::add_relation(
229-
buffer.buf, _id(123), _member(otype::way, 11),
230-
_member(otype::way, 10, "outer"), _member(otype::node, 1),
231-
_member(otype::way, 12, "inner"));
232-
}
235+
using otype = osmium::item_type;
236+
auto const pos = buffer.add_relation(123, {{otype::way, 11, ""},
237+
{otype::way, 10, "outer"},
238+
{otype::node, 1},
239+
{otype::way, 12, "inner"}});
233240
osmium::CRC<osmium::CRC_zlib> orig_crc;
234241
orig_crc.update(buffer.get<osmium::Relation>(pos));
235242

@@ -238,9 +245,10 @@ TEMPLATE_TEST_CASE("middle import", "", options_slim_default,
238245
mid->flush();
239246

240247
// retrieve the relation
241-
buffer.buf.clear();
242-
auto const &rel = buffer.get<osmium::Relation>(0);
243-
REQUIRE(mid_q->relations_get(123, buffer.buf));
248+
osmium::memory::Buffer outbuf{4096,
249+
osmium::memory::Buffer::auto_grow::yes};
250+
REQUIRE(mid_q->relations_get(123, outbuf));
251+
auto const &rel = outbuf.get<osmium::Relation>(0);
244252

245253
CHECK(rel.id() == 123);
246254
CHECK(rel.members().size() == 4);
@@ -251,10 +259,10 @@ TEMPLATE_TEST_CASE("middle import", "", options_slim_default,
251259

252260
// retrive the supporting ways
253261
rolelist_t roles;
254-
REQUIRE(mid_q->rel_way_members_get(rel, &roles, buffer.buf) == 3);
262+
REQUIRE(mid_q->rel_way_members_get(rel, &roles, outbuf) == 3);
255263
REQUIRE(roles.size() == 3);
256264

257-
for (auto &w : buffer.buf.select<osmium::Way>()) {
265+
for (auto &w : outbuf.select<osmium::Way>()) {
258266
REQUIRE(w.id() >= 10);
259267
REQUIRE(w.id() <= 12);
260268
auto const &expected = nds[w.id() - 10];
@@ -265,7 +273,7 @@ TEMPLATE_TEST_CASE("middle import", "", options_slim_default,
265273
}
266274

267275
// other relations are not retrievable
268-
REQUIRE_FALSE(mid_q->relations_get(999, buffer.buf));
276+
REQUIRE_FALSE(mid_q->relations_get(999, outbuf));
269277
}
270278
}
271279

0 commit comments

Comments
 (0)