Upgrade libosmium to v2.15.6
This commit is contained in:
+377
-319
@@ -7,230 +7,293 @@
|
||||
|
||||
#include <cstdint>
|
||||
#include <initializer_list>
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
TEST_CASE("create node using builders") {
|
||||
|
||||
using namespace osmium::builder::attr; // NOLINT(google-build-using-namespace)
|
||||
using namespace osmium::builder::attr; // NOLINT(google-build-using-namespace)
|
||||
|
||||
TEST_CASE("create node using builders: add node with only id") {
|
||||
osmium::memory::Buffer buffer{1024 * 10};
|
||||
|
||||
SECTION("add node with only id") {
|
||||
const auto pos = osmium::builder::add_node(buffer, _id(22));
|
||||
const auto pos = osmium::builder::add_node(buffer, _id(22));
|
||||
|
||||
const auto& node = buffer.get<osmium::Node>(pos);
|
||||
|
||||
REQUIRE(node.id() == 22);
|
||||
REQUIRE(node.version() == 0);
|
||||
REQUIRE(node.timestamp() == osmium::Timestamp{});
|
||||
REQUIRE(node.changeset() == 0);
|
||||
REQUIRE(node.uid() == 0);
|
||||
REQUIRE(std::string{node.user()}.empty());
|
||||
REQUIRE(node.location() == osmium::Location{});
|
||||
REQUIRE(node.tags().empty());
|
||||
}
|
||||
|
||||
SECTION("add node with complete info but no tags") {
|
||||
const osmium::Location loc{3.14, 1.59};
|
||||
const auto pos = osmium::builder::add_node(buffer,
|
||||
_id(1),
|
||||
_version(17),
|
||||
_timestamp(osmium::Timestamp{"2015-01-01T10:20:30Z"}),
|
||||
_cid(21),
|
||||
_uid(222),
|
||||
_location(loc),
|
||||
_user("foo")
|
||||
);
|
||||
|
||||
const auto& node = buffer.get<osmium::Node>(pos);
|
||||
|
||||
REQUIRE(node.id() == 1);
|
||||
REQUIRE(node.version() == 17);
|
||||
REQUIRE(node.timestamp() == osmium::Timestamp{"2015-01-01T10:20:30Z"});
|
||||
REQUIRE(node.changeset() == 21);
|
||||
REQUIRE(node.uid() == 222);
|
||||
REQUIRE(std::string{node.user()} == "foo");
|
||||
REQUIRE(node.location() == loc);
|
||||
REQUIRE(node.tags().empty());
|
||||
REQUIRE(std::distance(node.cbegin(), node.cend()) == 0);
|
||||
}
|
||||
|
||||
SECTION("visible/deleted flag") {
|
||||
osmium::builder::add_node(buffer, _id(1), _deleted());
|
||||
osmium::builder::add_node(buffer, _id(2), _deleted(true));
|
||||
osmium::builder::add_node(buffer, _id(3), _deleted(false));
|
||||
osmium::builder::add_node(buffer, _id(4), _visible());
|
||||
osmium::builder::add_node(buffer, _id(5), _visible(true));
|
||||
osmium::builder::add_node(buffer, _id(6), _visible(false));
|
||||
|
||||
auto it = buffer.select<osmium::Node>().cbegin();
|
||||
REQUIRE_FALSE(it++->visible());
|
||||
REQUIRE_FALSE(it++->visible());
|
||||
REQUIRE(it++->visible());
|
||||
REQUIRE(it++->visible());
|
||||
REQUIRE(it++->visible());
|
||||
REQUIRE_FALSE(it++->visible());
|
||||
REQUIRE(it == buffer.select<osmium::Node>().cend());
|
||||
}
|
||||
|
||||
SECTION("order of attributes doesn't matter") {
|
||||
const osmium::Location loc{3.14, 1.59};
|
||||
const auto pos = osmium::builder::add_node(buffer,
|
||||
_timestamp("2015-01-01T10:20:30Z"),
|
||||
_version(17),
|
||||
_cid(21),
|
||||
_uid(222),
|
||||
_user(std::string{"foo"}),
|
||||
_id(1),
|
||||
_location(3.14, 1.59)
|
||||
);
|
||||
|
||||
const auto& node = buffer.get<osmium::Node>(pos);
|
||||
|
||||
REQUIRE(node.id() == 1);
|
||||
REQUIRE(node.version() == 17);
|
||||
REQUIRE(node.timestamp() == osmium::Timestamp{"2015-01-01T10:20:30Z"});
|
||||
REQUIRE(node.changeset() == 21);
|
||||
REQUIRE(node.uid() == 222);
|
||||
REQUIRE(std::string{node.user()} == "foo");
|
||||
REQUIRE(node.location() == loc);
|
||||
REQUIRE(node.tags().empty());
|
||||
}
|
||||
const auto& node = buffer.get<osmium::Node>(pos);
|
||||
|
||||
REQUIRE(node.id() == 22);
|
||||
REQUIRE(node.version() == 0);
|
||||
REQUIRE(node.timestamp() == osmium::Timestamp{});
|
||||
REQUIRE(node.changeset() == 0);
|
||||
REQUIRE(node.uid() == 0);
|
||||
REQUIRE(node.user()[0] == '\0');
|
||||
REQUIRE(node.location() == osmium::Location{});
|
||||
REQUIRE(node.tags().empty());
|
||||
}
|
||||
|
||||
TEST_CASE("create node with tags using builders") {
|
||||
|
||||
using namespace osmium::builder::attr; // NOLINT(google-build-using-namespace)
|
||||
|
||||
TEST_CASE("create node using builders: add node with complete info but no tags") {
|
||||
osmium::memory::Buffer buffer{1024 * 10};
|
||||
|
||||
SECTION("add tags using _tag") {
|
||||
std::pair<const char*, const char*> t1 = {"name", "Node Inn"};
|
||||
std::pair<std::string, std::string> t2 = {"phone", "+1-123-555-4567"};
|
||||
const osmium::Location loc{3.14, 1.59};
|
||||
const auto pos = osmium::builder::add_node(buffer,
|
||||
_id(1),
|
||||
_version(17),
|
||||
_timestamp(osmium::Timestamp{"2015-01-01T10:20:30Z"}),
|
||||
_cid(21),
|
||||
_uid(222),
|
||||
_location(loc),
|
||||
_user("foo")
|
||||
);
|
||||
|
||||
const auto pos = osmium::builder::add_node(buffer,
|
||||
_id(2),
|
||||
_tag("amenity", "restaurant"),
|
||||
_tag(t1),
|
||||
_tag(t2),
|
||||
_tag(std::string{"cuisine"}, std::string{"italian"})
|
||||
);
|
||||
const auto& node = buffer.get<osmium::Node>(pos);
|
||||
|
||||
const auto& node = buffer.get<osmium::Node>(pos);
|
||||
REQUIRE(node.id() == 1);
|
||||
REQUIRE(node.version() == 17);
|
||||
REQUIRE(node.timestamp() == osmium::Timestamp{"2015-01-01T10:20:30Z"});
|
||||
REQUIRE(node.changeset() == 21);
|
||||
REQUIRE(node.uid() == 222);
|
||||
REQUIRE(std::string{node.user()} == "foo");
|
||||
REQUIRE(node.location() == loc);
|
||||
REQUIRE(node.tags().empty());
|
||||
REQUIRE(std::distance(node.cbegin(), node.cend()) == 0);
|
||||
}
|
||||
|
||||
REQUIRE(node.id() == 2);
|
||||
REQUIRE(node.tags().size() == 4);
|
||||
REQUIRE(std::distance(node.cbegin(), node.cend()) == 1);
|
||||
TEST_CASE("create node using builders: visible/deleted flag") {
|
||||
osmium::memory::Buffer buffer{1024 * 10};
|
||||
|
||||
auto it = node.tags().cbegin();
|
||||
REQUIRE(std::string{it->key()} == "amenity");
|
||||
REQUIRE(std::string{it->value()} == "restaurant");
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "name");
|
||||
REQUIRE(std::string{it->value()} == "Node Inn");
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "phone");
|
||||
REQUIRE(std::string{it->value()} == "+1-123-555-4567");
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "cuisine");
|
||||
REQUIRE(std::string{it->value()} == "italian");
|
||||
++it;
|
||||
REQUIRE(it == node.tags().cend());
|
||||
}
|
||||
osmium::builder::add_node(buffer, _id(1), _deleted());
|
||||
osmium::builder::add_node(buffer, _id(2), _deleted(true));
|
||||
osmium::builder::add_node(buffer, _id(3), _deleted(false));
|
||||
osmium::builder::add_node(buffer, _id(4), _visible());
|
||||
osmium::builder::add_node(buffer, _id(5), _visible(true));
|
||||
osmium::builder::add_node(buffer, _id(6), _visible(false));
|
||||
|
||||
SECTION("add tags using _tags from initializer list") {
|
||||
const auto pos = osmium::builder::add_node(buffer,
|
||||
_id(3),
|
||||
_tags({{"amenity", "post_box"}})
|
||||
);
|
||||
auto it = buffer.select<osmium::Node>().cbegin();
|
||||
REQUIRE_FALSE(it++->visible());
|
||||
REQUIRE_FALSE(it++->visible());
|
||||
REQUIRE(it++->visible());
|
||||
REQUIRE(it++->visible());
|
||||
REQUIRE(it++->visible());
|
||||
REQUIRE_FALSE(it++->visible());
|
||||
REQUIRE(it == buffer.select<osmium::Node>().cend());
|
||||
}
|
||||
|
||||
const auto& node = buffer.get<osmium::Node>(pos);
|
||||
TEST_CASE("create node using builders: order of attributes doesn't matter") {
|
||||
osmium::memory::Buffer buffer{1024 * 10};
|
||||
|
||||
REQUIRE(node.id() == 3);
|
||||
REQUIRE(node.tags().size() == 1);
|
||||
const osmium::Location loc{3.14, 1.59};
|
||||
const auto pos = osmium::builder::add_node(buffer,
|
||||
_timestamp("2015-01-01T10:20:30Z"),
|
||||
_version(17),
|
||||
_cid(21),
|
||||
_uid(222),
|
||||
_user(std::string{"foo"}),
|
||||
_id(1),
|
||||
_location(3.14, 1.59)
|
||||
);
|
||||
|
||||
auto it = node.tags().cbegin();
|
||||
REQUIRE(std::string{it->key()} == "amenity");
|
||||
REQUIRE(std::string{it->value()} == "post_box");
|
||||
++it;
|
||||
REQUIRE(it == node.tags().cend());
|
||||
REQUIRE(std::distance(node.cbegin(), node.cend()) == 1);
|
||||
}
|
||||
const auto& node = buffer.get<osmium::Node>(pos);
|
||||
|
||||
SECTION("add tags using _tags from TagList") {
|
||||
const auto pos1 = osmium::builder::add_node(buffer,
|
||||
_id(3),
|
||||
_tag("a", "d"),
|
||||
_tag("b", "e"),
|
||||
_tag("c", "f")
|
||||
);
|
||||
REQUIRE(node.id() == 1);
|
||||
REQUIRE(node.version() == 17);
|
||||
REQUIRE(node.timestamp() == osmium::Timestamp{"2015-01-01T10:20:30Z"});
|
||||
REQUIRE(node.changeset() == 21);
|
||||
REQUIRE(node.uid() == 222);
|
||||
REQUIRE(std::string{node.user()} == "foo");
|
||||
REQUIRE(node.location() == loc);
|
||||
REQUIRE(node.tags().empty());
|
||||
}
|
||||
|
||||
const auto& node1 = buffer.get<osmium::Node>(pos1);
|
||||
TEST_CASE("create node with tags using builders: add tags using _tag") {
|
||||
osmium::memory::Buffer buffer{1024 * 10};
|
||||
|
||||
const auto pos2 = osmium::builder::add_node(buffer,
|
||||
_id(4),
|
||||
_tags(node1.tags())
|
||||
);
|
||||
std::pair<const char*, const char*> t1 = {"name", "Node Inn"};
|
||||
std::pair<std::string, std::string> t2 = {"phone", "+1-123-555-4567"};
|
||||
|
||||
const auto& node2 = buffer.get<osmium::Node>(pos2);
|
||||
const auto pos = osmium::builder::add_node(buffer,
|
||||
_id(2),
|
||||
_tag("amenity", "restaurant"),
|
||||
_tag(t1),
|
||||
_tag(t2),
|
||||
_tag(std::string{"cuisine"}, std::string{"italian"})
|
||||
);
|
||||
|
||||
REQUIRE(node2.id() == 4);
|
||||
REQUIRE(node2.tags().size() == 3);
|
||||
const auto& node = buffer.get<osmium::Node>(pos);
|
||||
|
||||
auto it = node2.tags().cbegin();
|
||||
REQUIRE(std::string{it++->key()} == "a");
|
||||
REQUIRE(std::string{it++->key()} == "b");
|
||||
REQUIRE(std::string{it++->key()} == "c");
|
||||
REQUIRE(it == node2.tags().cend());
|
||||
REQUIRE(std::distance(node2.cbegin(), node2.cend()) == 1);
|
||||
}
|
||||
REQUIRE(node.id() == 2);
|
||||
REQUIRE(node.tags().size() == 4);
|
||||
REQUIRE(std::distance(node.cbegin(), node.cend()) == 1);
|
||||
|
||||
SECTION("add tags using mixed tag sources") {
|
||||
const std::vector<pair_of_cstrings> tags = {
|
||||
{"t5", "t5"},
|
||||
{"t6", "t6"}
|
||||
};
|
||||
auto it = node.tags().cbegin();
|
||||
REQUIRE(std::string{it->key()} == "amenity");
|
||||
REQUIRE(std::string{it->value()} == "restaurant");
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "name");
|
||||
REQUIRE(std::string{it->value()} == "Node Inn");
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "phone");
|
||||
REQUIRE(std::string{it->value()} == "+1-123-555-4567");
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "cuisine");
|
||||
REQUIRE(std::string{it->value()} == "italian");
|
||||
++it;
|
||||
REQUIRE(it == node.tags().cend());
|
||||
}
|
||||
|
||||
const auto pos = osmium::builder::add_node(buffer,
|
||||
_id(4),
|
||||
_tag("t1", "t1"),
|
||||
_tags({{"t2", "t2"}, {"t3", "t3"}}),
|
||||
_tag("t4", "t4"),
|
||||
_tags(tags)
|
||||
);
|
||||
TEST_CASE("create node with tags using builders: add tags using _tag with equal sign in single cstring") {
|
||||
osmium::memory::Buffer buffer{1024 * 10};
|
||||
|
||||
const auto& node = buffer.get<osmium::Node>(pos);
|
||||
const auto pos = osmium::builder::add_node(buffer,
|
||||
_id(2),
|
||||
_tag("amenity=restaurant"),
|
||||
_tag("name="),
|
||||
_tag("phone"),
|
||||
_tag(std::string{"cuisine=italian"})
|
||||
);
|
||||
|
||||
REQUIRE(node.id() == 4);
|
||||
REQUIRE(node.tags().size() == 6);
|
||||
const auto& node = buffer.get<osmium::Node>(pos);
|
||||
|
||||
auto it = node.tags().cbegin();
|
||||
REQUIRE(std::string{it->key()} == "t1");
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "t2");
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "t3");
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "t4");
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "t5");
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "t6");
|
||||
++it;
|
||||
REQUIRE(it == node.tags().cend());
|
||||
REQUIRE(std::distance(node.cbegin(), node.cend()) == 1);
|
||||
}
|
||||
REQUIRE(node.id() == 2);
|
||||
REQUIRE(node.tags().size() == 4);
|
||||
REQUIRE(std::distance(node.cbegin(), node.cend()) == 1);
|
||||
|
||||
auto it = node.tags().cbegin();
|
||||
REQUIRE(std::string{it->key()} == "amenity");
|
||||
REQUIRE(std::string{it->value()} == "restaurant");
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "name");
|
||||
REQUIRE(it->value()[0] == '\0');
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "phone");
|
||||
REQUIRE(it->value()[0] == '\0');
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "cuisine");
|
||||
REQUIRE(std::string{it->value()} == "italian");
|
||||
++it;
|
||||
REQUIRE(it == node.tags().cend());
|
||||
}
|
||||
|
||||
TEST_CASE("create node with tags using builders: add tags using _tags from initializer list") {
|
||||
osmium::memory::Buffer buffer{1024 * 10};
|
||||
|
||||
const auto pos = osmium::builder::add_node(buffer,
|
||||
_id(3),
|
||||
_tags({{"amenity", "post_box"}})
|
||||
);
|
||||
|
||||
const auto& node = buffer.get<osmium::Node>(pos);
|
||||
|
||||
REQUIRE(node.id() == 3);
|
||||
REQUIRE(node.tags().size() == 1);
|
||||
|
||||
auto it = node.tags().cbegin();
|
||||
REQUIRE(std::string{it->key()} == "amenity");
|
||||
REQUIRE(std::string{it->value()} == "post_box");
|
||||
++it;
|
||||
REQUIRE(it == node.tags().cend());
|
||||
REQUIRE(std::distance(node.cbegin(), node.cend()) == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("create node with tags using builders: add tags using _tags from TagList") {
|
||||
osmium::memory::Buffer buffer{1024 * 10};
|
||||
|
||||
const auto pos1 = osmium::builder::add_node(buffer,
|
||||
_id(3),
|
||||
_tag("a", "d"),
|
||||
_tag("b", "e"),
|
||||
_tag("c", "f")
|
||||
);
|
||||
|
||||
const auto& node1 = buffer.get<osmium::Node>(pos1);
|
||||
|
||||
const auto pos2 = osmium::builder::add_node(buffer,
|
||||
_id(4),
|
||||
_tags(node1.tags())
|
||||
);
|
||||
|
||||
const auto& node2 = buffer.get<osmium::Node>(pos2);
|
||||
|
||||
REQUIRE(node2.id() == 4);
|
||||
REQUIRE(node2.tags().size() == 3);
|
||||
|
||||
auto it = node2.tags().cbegin();
|
||||
REQUIRE(std::string{it++->key()} == "a");
|
||||
REQUIRE(std::string{it++->key()} == "b");
|
||||
REQUIRE(std::string{it++->key()} == "c");
|
||||
REQUIRE(it == node2.tags().cend());
|
||||
REQUIRE(std::distance(node2.cbegin(), node2.cend()) == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("create node with tags using builders: add tags using mixed tag sources") {
|
||||
osmium::memory::Buffer buffer{1024 * 10};
|
||||
|
||||
const std::vector<pair_of_cstrings> tags = {
|
||||
{"t5", "t5"},
|
||||
{"t6", "t6"}
|
||||
};
|
||||
|
||||
const auto pos = osmium::builder::add_node(buffer,
|
||||
_id(4),
|
||||
_tag("t1=t1"),
|
||||
_tags({{"t2", "t2"}, {"t3", "t3"}}),
|
||||
_tag("t4", "t4"),
|
||||
_tags(tags)
|
||||
);
|
||||
|
||||
const auto& node = buffer.get<osmium::Node>(pos);
|
||||
|
||||
REQUIRE(node.id() == 4);
|
||||
REQUIRE(node.tags().size() == 6);
|
||||
|
||||
auto it = node.tags().cbegin();
|
||||
REQUIRE(std::string{it->key()} == "t1");
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "t2");
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "t3");
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "t4");
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "t5");
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "t6");
|
||||
++it;
|
||||
REQUIRE(it == node.tags().cend());
|
||||
REQUIRE(std::distance(node.cbegin(), node.cend()) == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("create node with tags using builders: add tags using _t with string") {
|
||||
osmium::memory::Buffer buffer{1024 * 10};
|
||||
|
||||
const auto pos = osmium::builder::add_node(buffer,
|
||||
_id(5),
|
||||
_t("amenity=post_box,,empty,also_empty=,operator=Deutsche Post")
|
||||
);
|
||||
|
||||
const auto& node = buffer.get<osmium::Node>(pos);
|
||||
|
||||
REQUIRE(node.id() == 5);
|
||||
REQUIRE(node.tags().size() == 4);
|
||||
|
||||
auto it = node.tags().cbegin();
|
||||
REQUIRE(std::string{it->key()} == "amenity");
|
||||
REQUIRE(std::string{it->value()} == "post_box");
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "empty");
|
||||
REQUIRE(it->value()[0] == '\0');
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "also_empty");
|
||||
REQUIRE(it->value()[0] == '\0');
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "operator");
|
||||
REQUIRE(std::string{it->value()} == "Deutsche Post");
|
||||
++it;
|
||||
REQUIRE(it == node.tags().cend());
|
||||
REQUIRE(std::distance(node.cbegin(), node.cend()) == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("create way using builders") {
|
||||
|
||||
using namespace osmium::builder::attr; // NOLINT(google-build-using-namespace)
|
||||
|
||||
osmium::memory::Buffer buffer{1024 * 10};
|
||||
|
||||
SECTION("add way without nodes") {
|
||||
@@ -264,8 +327,6 @@ TEST_CASE("create way with nodes") {
|
||||
{ 8, osmium::Location{8.8, 0.8} }
|
||||
};
|
||||
|
||||
using namespace osmium::builder::attr; // NOLINT(google-build-using-namespace)
|
||||
|
||||
osmium::memory::Buffer wbuffer{1024 * 10};
|
||||
osmium::builder::add_way(wbuffer,
|
||||
_id(1),
|
||||
@@ -383,170 +444,167 @@ TEST_CASE("create way with nodes") {
|
||||
REQUIRE(it == way.nodes().cend());
|
||||
}
|
||||
|
||||
TEST_CASE("create relation using builders") {
|
||||
|
||||
using namespace osmium::builder::attr; // NOLINT(google-build-using-namespace)
|
||||
|
||||
TEST_CASE("create relation using builders: create relation") {
|
||||
osmium::memory::Buffer buffer{1024 * 10};
|
||||
|
||||
SECTION("create relation") {
|
||||
osmium::builder::attr::member_type m{osmium::item_type::way, 113, "inner"};
|
||||
osmium::builder::attr::member_type m{osmium::item_type::way, 113, "inner"};
|
||||
|
||||
osmium::builder::add_relation(buffer,
|
||||
_id(123),
|
||||
_member(osmium::item_type::node, 123, ""),
|
||||
_member(osmium::item_type::node, 132),
|
||||
_member(osmium::item_type::way, 111, "outer"),
|
||||
_member(osmium::builder::attr::member_type{osmium::item_type::way, 112, "inner"}),
|
||||
_member(m)
|
||||
);
|
||||
osmium::builder::add_relation(buffer,
|
||||
_id(123),
|
||||
_member(osmium::item_type::node, 123, ""),
|
||||
_member(osmium::item_type::node, 132),
|
||||
_member(osmium::item_type::way, 111, "outer"),
|
||||
_member(osmium::builder::attr::member_type{osmium::item_type::way, 112, "inner"}),
|
||||
_member(m)
|
||||
);
|
||||
|
||||
const auto& relation = buffer.get<osmium::Relation>(0);
|
||||
const auto& relation = buffer.get<osmium::Relation>(0);
|
||||
|
||||
REQUIRE(relation.id() == 123);
|
||||
REQUIRE(relation.members().size() == 5);
|
||||
REQUIRE(std::distance(relation.cbegin(), relation.cend()) == 1);
|
||||
REQUIRE(relation.id() == 123);
|
||||
REQUIRE(relation.members().size() == 5);
|
||||
REQUIRE(std::distance(relation.cbegin(), relation.cend()) == 1);
|
||||
|
||||
auto it = relation.members().begin();
|
||||
auto it = relation.members().begin();
|
||||
|
||||
REQUIRE(it->type() == osmium::item_type::node);
|
||||
REQUIRE(it->ref() == 123);
|
||||
REQUIRE(std::string{it->role()}.empty());
|
||||
++it;
|
||||
REQUIRE(it->type() == osmium::item_type::node);
|
||||
REQUIRE(it->ref() == 123);
|
||||
REQUIRE(it->role()[0] == '\0');
|
||||
++it;
|
||||
|
||||
REQUIRE(it->type() == osmium::item_type::node);
|
||||
REQUIRE(it->ref() == 132);
|
||||
REQUIRE(std::string{it->role()}.empty());
|
||||
++it;
|
||||
REQUIRE(it->type() == osmium::item_type::node);
|
||||
REQUIRE(it->ref() == 132);
|
||||
REQUIRE(it->role()[0] == '\0');
|
||||
++it;
|
||||
|
||||
REQUIRE(it->type() == osmium::item_type::way);
|
||||
REQUIRE(it->ref() == 111);
|
||||
REQUIRE(std::string{it->role()} == "outer");
|
||||
++it;
|
||||
REQUIRE(it->type() == osmium::item_type::way);
|
||||
REQUIRE(it->ref() == 111);
|
||||
REQUIRE(std::string{it->role()} == "outer");
|
||||
++it;
|
||||
|
||||
REQUIRE(it->type() == osmium::item_type::way);
|
||||
REQUIRE(it->ref() == 112);
|
||||
REQUIRE(std::string{it->role()} == "inner");
|
||||
++it;
|
||||
REQUIRE(it->type() == osmium::item_type::way);
|
||||
REQUIRE(it->ref() == 112);
|
||||
REQUIRE(std::string{it->role()} == "inner");
|
||||
++it;
|
||||
|
||||
REQUIRE(it->type() == osmium::item_type::way);
|
||||
REQUIRE(it->ref() == 113);
|
||||
REQUIRE(std::string{it->role()} == "inner");
|
||||
++it;
|
||||
REQUIRE(it->type() == osmium::item_type::way);
|
||||
REQUIRE(it->ref() == 113);
|
||||
REQUIRE(std::string{it->role()} == "inner");
|
||||
++it;
|
||||
|
||||
REQUIRE(it == relation.members().end());
|
||||
}
|
||||
REQUIRE(it == relation.members().end());
|
||||
}
|
||||
|
||||
SECTION("create relation member from existing relation member") {
|
||||
osmium::builder::add_relation(buffer,
|
||||
_id(123),
|
||||
_member(osmium::item_type::way, 111, "outer"),
|
||||
_member(osmium::item_type::way, 112, "inner")
|
||||
);
|
||||
TEST_CASE("create relation using builders: create relation member from existing relation member") {
|
||||
osmium::memory::Buffer buffer{1024 * 10};
|
||||
|
||||
const auto& relation1 = buffer.get<osmium::Relation>(0);
|
||||
osmium::builder::add_relation(buffer,
|
||||
_id(123),
|
||||
_member(osmium::item_type::way, 111, "outer"),
|
||||
_member(osmium::item_type::way, 112, "inner")
|
||||
);
|
||||
|
||||
const auto pos = osmium::builder::add_relation(buffer,
|
||||
_id(124),
|
||||
_member(*relation1.members().begin()),
|
||||
_members(std::next(relation1.members().begin()), relation1.members().end())
|
||||
);
|
||||
const auto& relation1 = buffer.get<osmium::Relation>(0);
|
||||
|
||||
const auto& relation = buffer.get<osmium::Relation>(pos);
|
||||
const auto pos = osmium::builder::add_relation(buffer,
|
||||
_id(124),
|
||||
_member(*relation1.members().begin()),
|
||||
_members(std::next(relation1.members().begin()), relation1.members().end())
|
||||
);
|
||||
|
||||
REQUIRE(relation.id() == 124);
|
||||
REQUIRE(relation.members().size() == 2);
|
||||
const auto& relation = buffer.get<osmium::Relation>(pos);
|
||||
|
||||
auto it = relation.members().begin();
|
||||
REQUIRE(relation.id() == 124);
|
||||
REQUIRE(relation.members().size() == 2);
|
||||
|
||||
REQUIRE(it->type() == osmium::item_type::way);
|
||||
REQUIRE(it->ref() == 111);
|
||||
REQUIRE(std::string{it->role()} == "outer");
|
||||
++it;
|
||||
auto it = relation.members().begin();
|
||||
|
||||
REQUIRE(it->type() == osmium::item_type::way);
|
||||
REQUIRE(it->ref() == 112);
|
||||
REQUIRE(std::string{it->role()} == "inner");
|
||||
++it;
|
||||
REQUIRE(it->type() == osmium::item_type::way);
|
||||
REQUIRE(it->ref() == 111);
|
||||
REQUIRE(std::string{it->role()} == "outer");
|
||||
++it;
|
||||
|
||||
REQUIRE(it == relation.members().end());
|
||||
}
|
||||
REQUIRE(it->type() == osmium::item_type::way);
|
||||
REQUIRE(it->ref() == 112);
|
||||
REQUIRE(std::string{it->role()} == "inner");
|
||||
++it;
|
||||
|
||||
SECTION("create relation with members from initializer list") {
|
||||
const auto pos = osmium::builder::add_relation(buffer,
|
||||
_id(123),
|
||||
_members({
|
||||
{osmium::item_type::node, 123, ""},
|
||||
{osmium::item_type::way, 111, "outer"}
|
||||
})
|
||||
);
|
||||
REQUIRE(it == relation.members().end());
|
||||
}
|
||||
|
||||
const auto& relation = buffer.get<osmium::Relation>(pos);
|
||||
TEST_CASE("create relation using builders: create relation with members from initializer list") {
|
||||
osmium::memory::Buffer buffer{1024 * 10};
|
||||
|
||||
REQUIRE(relation.id() == 123);
|
||||
REQUIRE(relation.members().size() == 2);
|
||||
REQUIRE(std::distance(relation.cbegin(), relation.cend()) == 1);
|
||||
|
||||
auto it = relation.members().begin();
|
||||
REQUIRE(it->type() == osmium::item_type::node);
|
||||
REQUIRE(it->ref() == 123);
|
||||
REQUIRE(std::string{it->role()}.empty());
|
||||
++it;
|
||||
REQUIRE(it->type() == osmium::item_type::way);
|
||||
REQUIRE(it->ref() == 111);
|
||||
REQUIRE(std::string{it->role()} == "outer");
|
||||
++it;
|
||||
REQUIRE(it == relation.members().end());
|
||||
}
|
||||
|
||||
SECTION("create relation with members from iterators and some tags") {
|
||||
const std::vector<member_type> members = {
|
||||
{osmium::item_type::node, 123},
|
||||
const auto pos = osmium::builder::add_relation(buffer,
|
||||
_id(123),
|
||||
_members({
|
||||
{osmium::item_type::node, 123, ""},
|
||||
{osmium::item_type::way, 111, "outer"}
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
SECTION("using iterators") {
|
||||
osmium::builder::add_relation(buffer,
|
||||
_id(123),
|
||||
_members(members.begin(), members.end()),
|
||||
_tag("a", "x"),
|
||||
_tag("b", "y")
|
||||
);
|
||||
}
|
||||
SECTION("using container") {
|
||||
osmium::builder::add_relation(buffer,
|
||||
_id(123),
|
||||
_members(members),
|
||||
_tag("a", "x"),
|
||||
_tag("b", "y")
|
||||
);
|
||||
}
|
||||
const auto& relation = buffer.get<osmium::Relation>(pos);
|
||||
|
||||
const auto& relation = buffer.get<osmium::Relation>(0);
|
||||
REQUIRE(relation.id() == 123);
|
||||
REQUIRE(relation.members().size() == 2);
|
||||
REQUIRE(std::distance(relation.cbegin(), relation.cend()) == 1);
|
||||
|
||||
REQUIRE(relation.id() == 123);
|
||||
REQUIRE(relation.members().size() == 2);
|
||||
REQUIRE(relation.tags().size() == 2);
|
||||
REQUIRE(std::distance(relation.cbegin(), relation.cend()) == 2);
|
||||
auto it = relation.members().begin();
|
||||
REQUIRE(it->type() == osmium::item_type::node);
|
||||
REQUIRE(it->ref() == 123);
|
||||
REQUIRE(it->role()[0] == '\0');
|
||||
++it;
|
||||
REQUIRE(it->type() == osmium::item_type::way);
|
||||
REQUIRE(it->ref() == 111);
|
||||
REQUIRE(std::string{it->role()} == "outer");
|
||||
++it;
|
||||
REQUIRE(it == relation.members().end());
|
||||
}
|
||||
|
||||
auto it = relation.members().begin();
|
||||
REQUIRE(it->type() == osmium::item_type::node);
|
||||
REQUIRE(it->ref() == 123);
|
||||
REQUIRE(std::string{it->role()}.empty());
|
||||
++it;
|
||||
REQUIRE(it->type() == osmium::item_type::way);
|
||||
REQUIRE(it->ref() == 111);
|
||||
REQUIRE(std::string{it->role()} == "outer");
|
||||
++it;
|
||||
REQUIRE(it == relation.members().end());
|
||||
TEST_CASE("create relation using builders: create relation with members from iterators and some tags") {
|
||||
osmium::memory::Buffer buffer{1024 * 10};
|
||||
|
||||
const std::vector<member_type> members = {
|
||||
{osmium::item_type::node, 123},
|
||||
{osmium::item_type::way, 111, "outer"}
|
||||
};
|
||||
|
||||
SECTION("using iterators") {
|
||||
osmium::builder::add_relation(buffer,
|
||||
_id(123),
|
||||
_members(members.begin(), members.end()),
|
||||
_tag("a", "x"),
|
||||
_tag("b", "y")
|
||||
);
|
||||
}
|
||||
SECTION("using container") {
|
||||
osmium::builder::add_relation(buffer,
|
||||
_id(123),
|
||||
_members(members),
|
||||
_tag("a", "x"),
|
||||
_tag("b", "y")
|
||||
);
|
||||
}
|
||||
|
||||
const auto& relation = buffer.get<osmium::Relation>(0);
|
||||
|
||||
REQUIRE(relation.id() == 123);
|
||||
REQUIRE(relation.members().size() == 2);
|
||||
REQUIRE(relation.tags().size() == 2);
|
||||
REQUIRE(std::distance(relation.cbegin(), relation.cend()) == 2);
|
||||
|
||||
auto it = relation.members().begin();
|
||||
REQUIRE(it->type() == osmium::item_type::node);
|
||||
REQUIRE(it->ref() == 123);
|
||||
REQUIRE(it->role()[0] == '\0');
|
||||
++it;
|
||||
REQUIRE(it->type() == osmium::item_type::way);
|
||||
REQUIRE(it->ref() == 111);
|
||||
REQUIRE(std::string{it->role()} == "outer");
|
||||
++it;
|
||||
REQUIRE(it == relation.members().end());
|
||||
}
|
||||
|
||||
TEST_CASE("create area using builders") {
|
||||
|
||||
using namespace osmium::builder::attr; // NOLINT(google-build-using-namespace)
|
||||
|
||||
osmium::memory::Buffer buffer{1024 * 10};
|
||||
|
||||
SECTION("add area without rings") {
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include <osmium/memory/buffer.hpp>
|
||||
#include <osmium/osm.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
TEST_CASE("create objects using builder") {
|
||||
osmium::memory::Buffer buffer{1024 * 10};
|
||||
std::string user;
|
||||
@@ -441,3 +443,40 @@ TEST_CASE("set_user with length on changeset") {
|
||||
REQUIRE(std::string{"user"} == changeset.user());
|
||||
}
|
||||
|
||||
TEST_CASE("clear_user should clear the user field but nothing else") {
|
||||
osmium::memory::Buffer buffer{1024 * 10};
|
||||
std::string user = "user";
|
||||
|
||||
{
|
||||
osmium::builder::NodeBuilder builder{buffer};
|
||||
builder.set_id(17)
|
||||
.set_visible(true)
|
||||
.set_version(1)
|
||||
.set_changeset(123)
|
||||
.set_uid(555)
|
||||
.set_timestamp("2015-07-01T00:00:01Z")
|
||||
.set_location(osmium::Location{1.2, 3.4})
|
||||
.set_user(user);
|
||||
builder.add_tags({{"highway", "primary"}, {"oneway", "yes"}});
|
||||
}
|
||||
|
||||
auto& node = buffer.get<osmium::Node>(buffer.commit());
|
||||
|
||||
REQUIRE(std::string{"user"} == node.user());
|
||||
|
||||
node.clear_user();
|
||||
|
||||
REQUIRE(std::string{""} == node.user());
|
||||
REQUIRE(node.uid() == 555);
|
||||
REQUIRE(node.tags().size() == 2);
|
||||
|
||||
auto it = node.tags().begin();
|
||||
REQUIRE(it->key() == std::string{"highway"});
|
||||
REQUIRE(it->value() == std::string{"primary"});
|
||||
++it;
|
||||
REQUIRE(it->key() == std::string{"oneway"});
|
||||
REQUIRE(it->value() == std::string{"yes"});
|
||||
++it;
|
||||
REQUIRE(it == node.tags().end());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user