Merge commit '73efcc6b0ccedf8c1b6d95abdba8340cc9adf100' as 'third_party/libosmium'
This commit is contained in:
+97
@@ -0,0 +1,97 @@
|
||||
#ifndef TEST_BASIC_HELPER_HPP
|
||||
#define TEST_BASIC_HELPER_HPP
|
||||
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <osmium/builder/osm_object_builder.hpp>
|
||||
|
||||
inline void add_tags(osmium::memory::Buffer& buffer, osmium::builder::Builder& builder, const std::vector<std::pair<const char*, const char*>>& tags) {
|
||||
osmium::builder::TagListBuilder tl_builder(buffer, &builder);
|
||||
for (auto& tag : tags) {
|
||||
tl_builder.add_tag(tag.first, tag.second);
|
||||
}
|
||||
}
|
||||
|
||||
inline osmium::Node& buffer_add_node(osmium::memory::Buffer& buffer, const char* user, const std::vector<std::pair<const char*, const char*>>& tags, const osmium::Location& location) {
|
||||
osmium::builder::NodeBuilder builder(buffer);
|
||||
builder.add_user(user);
|
||||
add_tags(buffer, builder, tags);
|
||||
buffer.commit();
|
||||
return builder.object().set_location(location);
|
||||
}
|
||||
|
||||
inline osmium::Way& buffer_add_way(osmium::memory::Buffer& buffer, const char* user, const std::vector<std::pair<const char*, const char*>>& tags, const std::vector<osmium::object_id_type>& nodes) {
|
||||
osmium::builder::WayBuilder builder(buffer);
|
||||
builder.add_user(user);
|
||||
add_tags(buffer, builder, tags);
|
||||
osmium::builder::WayNodeListBuilder wnl_builder(buffer, &builder);
|
||||
for (const osmium::object_id_type ref : nodes) {
|
||||
wnl_builder.add_node_ref(ref);
|
||||
}
|
||||
buffer.commit();
|
||||
return builder.object();
|
||||
}
|
||||
|
||||
inline osmium::Way& buffer_add_way(osmium::memory::Buffer& buffer, const char* user, const std::vector<std::pair<const char*, const char*>>& tags, const std::vector<std::pair<osmium::object_id_type, osmium::Location>>& nodes) {
|
||||
osmium::builder::WayBuilder builder(buffer);
|
||||
builder.add_user(user);
|
||||
add_tags(buffer, builder, tags);
|
||||
osmium::builder::WayNodeListBuilder wnl_builder(buffer, &builder);
|
||||
for (auto& p : nodes) {
|
||||
wnl_builder.add_node_ref(p.first, p.second);
|
||||
}
|
||||
buffer.commit();
|
||||
return builder.object();
|
||||
}
|
||||
|
||||
inline osmium::Relation& buffer_add_relation(
|
||||
osmium::memory::Buffer& buffer,
|
||||
const char* user,
|
||||
const std::vector<std::pair<const char*, const char*>>& tags, const std::vector<std::tuple<char, osmium::object_id_type, const char*>>& members) {
|
||||
osmium::builder::RelationBuilder builder(buffer);
|
||||
builder.add_user(user);
|
||||
add_tags(buffer, builder, tags);
|
||||
osmium::builder::RelationMemberListBuilder rml_builder(buffer, &builder);
|
||||
for (const auto& member : members) {
|
||||
rml_builder.add_member(osmium::char_to_item_type(std::get<0>(member)), std::get<1>(member), std::get<2>(member));
|
||||
}
|
||||
buffer.commit();
|
||||
return builder.object();
|
||||
}
|
||||
|
||||
inline osmium::Area& buffer_add_area(osmium::memory::Buffer& buffer, const char* user,
|
||||
const std::vector<std::pair<const char*, const char*>>& tags,
|
||||
const std::vector<std::pair<bool,
|
||||
std::vector<std::pair<osmium::object_id_type, osmium::Location>>>>& rings) {
|
||||
osmium::builder::AreaBuilder builder(buffer);
|
||||
builder.add_user(user);
|
||||
add_tags(buffer, builder, tags);
|
||||
|
||||
for (auto& ring : rings) {
|
||||
if (ring.first) {
|
||||
osmium::builder::OuterRingBuilder ring_builder(buffer, &builder);
|
||||
for (auto& p : ring.second) {
|
||||
ring_builder.add_node_ref(p.first, p.second);
|
||||
}
|
||||
} else {
|
||||
osmium::builder::InnerRingBuilder ring_builder(buffer, &builder);
|
||||
for (auto& p : ring.second) {
|
||||
ring_builder.add_node_ref(p.first, p.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
buffer.commit();
|
||||
return builder.object();
|
||||
}
|
||||
|
||||
inline osmium::Changeset& buffer_add_changeset(osmium::memory::Buffer& buffer, const char* user, const std::vector<std::pair<const char*, const char*>>& tags) {
|
||||
osmium::builder::ChangesetBuilder builder(buffer);
|
||||
builder.add_user(user);
|
||||
add_tags(buffer, builder, tags);
|
||||
buffer.commit();
|
||||
return builder.object();
|
||||
}
|
||||
|
||||
#endif // TEST_BASIC_HELPER_HPP
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include <osmium/osm/box.hpp>
|
||||
#include <osmium/geom/relations.hpp>
|
||||
|
||||
TEST_CASE("Box") {
|
||||
|
||||
SECTION("instantiation") {
|
||||
osmium::Box b;
|
||||
REQUIRE(!b);
|
||||
REQUIRE(!b.bottom_left());
|
||||
REQUIRE(!b.top_right());
|
||||
REQUIRE_THROWS_AS(b.size(), osmium::invalid_location);
|
||||
}
|
||||
|
||||
SECTION("instantiation_and_extend_with_undefined") {
|
||||
osmium::Box b;
|
||||
REQUIRE(!b);
|
||||
b.extend(osmium::Location());
|
||||
REQUIRE(!b.bottom_left());
|
||||
REQUIRE(!b.top_right());
|
||||
}
|
||||
|
||||
SECTION("instantiation_and_extend") {
|
||||
osmium::Box b;
|
||||
b.extend(osmium::Location(1.2, 3.4));
|
||||
REQUIRE(!!b);
|
||||
REQUIRE(!!b.bottom_left());
|
||||
REQUIRE(!!b.top_right());
|
||||
b.extend(osmium::Location(3.4, 4.5));
|
||||
b.extend(osmium::Location(5.6, 7.8));
|
||||
REQUIRE(b.bottom_left() == osmium::Location(1.2, 3.4));
|
||||
REQUIRE(b.top_right() == osmium::Location(5.6, 7.8));
|
||||
|
||||
// extend with undefined doesn't change anything
|
||||
b.extend(osmium::Location());
|
||||
REQUIRE(b.bottom_left() == osmium::Location(1.2, 3.4));
|
||||
REQUIRE(b.top_right() == osmium::Location(5.6, 7.8));
|
||||
}
|
||||
|
||||
SECTION("output_defined") {
|
||||
osmium::Box b;
|
||||
b.extend(osmium::Location(1.2, 3.4));
|
||||
b.extend(osmium::Location(5.6, 7.8));
|
||||
std::stringstream out;
|
||||
out << b;
|
||||
REQUIRE(out.str() == "(1.2,3.4,5.6,7.8)");
|
||||
REQUIRE((19.36 - b.size()) < 0.000001);
|
||||
}
|
||||
|
||||
SECTION("output_undefined") {
|
||||
osmium::Box b;
|
||||
std::stringstream out;
|
||||
out << b;
|
||||
REQUIRE(out.str() == "(undefined)");
|
||||
}
|
||||
|
||||
SECTION("box_inside_box") {
|
||||
osmium::Box outer;
|
||||
outer.extend(osmium::Location(1, 1));
|
||||
outer.extend(osmium::Location(10, 10));
|
||||
|
||||
osmium::Box inner;
|
||||
inner.extend(osmium::Location(2, 2));
|
||||
inner.extend(osmium::Location(4, 4));
|
||||
|
||||
osmium::Box overlap;
|
||||
overlap.extend(osmium::Location(3, 3));
|
||||
overlap.extend(osmium::Location(5, 5));
|
||||
|
||||
REQUIRE( osmium::geom::contains(inner, outer));
|
||||
REQUIRE(!osmium::geom::contains(outer, inner));
|
||||
|
||||
REQUIRE(!osmium::geom::contains(overlap, inner));
|
||||
REQUIRE(!osmium::geom::contains(inner, overlap));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/osm/changeset.hpp>
|
||||
|
||||
#include "helper.hpp"
|
||||
|
||||
TEST_CASE("Basic_Changeset") {
|
||||
|
||||
SECTION("changeset_builder") {
|
||||
osmium::memory::Buffer buffer(10 * 1000);
|
||||
|
||||
osmium::Changeset& cs1 = buffer_add_changeset(buffer,
|
||||
"user",
|
||||
{{"comment", "foo"}});
|
||||
|
||||
cs1.set_id(42)
|
||||
.set_created_at(100)
|
||||
.set_closed_at(200)
|
||||
.set_num_changes(7)
|
||||
.set_uid(9);
|
||||
|
||||
REQUIRE(42 == cs1.id());
|
||||
REQUIRE(9 == cs1.uid());
|
||||
REQUIRE(7 == cs1.num_changes());
|
||||
REQUIRE(true == cs1.closed());
|
||||
REQUIRE(osmium::Timestamp(100) == cs1.created_at());
|
||||
REQUIRE(osmium::Timestamp(200) == cs1.closed_at());
|
||||
REQUIRE(1 == cs1.tags().size());
|
||||
REQUIRE(std::string("user") == cs1.user());
|
||||
|
||||
osmium::Changeset& cs2 = buffer_add_changeset(buffer,
|
||||
"user",
|
||||
{{"comment", "foo"}, {"foo", "bar"}});
|
||||
|
||||
cs2.set_id(43)
|
||||
.set_created_at(120)
|
||||
.set_num_changes(21)
|
||||
.set_uid(9);
|
||||
|
||||
REQUIRE(43 == cs2.id());
|
||||
REQUIRE(9 == cs2.uid());
|
||||
REQUIRE(21 == cs2.num_changes());
|
||||
REQUIRE(false == cs2.closed());
|
||||
REQUIRE(osmium::Timestamp(120) == cs2.created_at());
|
||||
REQUIRE(osmium::Timestamp() == cs2.closed_at());
|
||||
REQUIRE(2 == cs2.tags().size());
|
||||
REQUIRE(std::string("user") == cs2.user());
|
||||
|
||||
REQUIRE(cs1 != cs2);
|
||||
|
||||
REQUIRE(cs1 < cs2);
|
||||
REQUIRE(cs1 <= cs2);
|
||||
REQUIRE(false == (cs1 > cs2));
|
||||
REQUIRE(false == (cs1 >= cs2));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/osm/entity_bits.hpp>
|
||||
|
||||
TEST_CASE("entity_bits") {
|
||||
|
||||
SECTION("can_be_set_and_checked") {
|
||||
osmium::osm_entity_bits::type entities = osmium::osm_entity_bits::node | osmium::osm_entity_bits::way;
|
||||
REQUIRE(entities == (osmium::osm_entity_bits::node | osmium::osm_entity_bits::way));
|
||||
|
||||
entities |= osmium::osm_entity_bits::relation;
|
||||
REQUIRE((entities & osmium::osm_entity_bits::object));
|
||||
|
||||
entities |= osmium::osm_entity_bits::area;
|
||||
REQUIRE(entities == osmium::osm_entity_bits::object);
|
||||
|
||||
REQUIRE(! (entities & osmium::osm_entity_bits::changeset));
|
||||
|
||||
entities &= osmium::osm_entity_bits::node;
|
||||
REQUIRE((entities & osmium::osm_entity_bits::node));
|
||||
REQUIRE(! (entities & osmium::osm_entity_bits::way));
|
||||
REQUIRE(entities == osmium::osm_entity_bits::node);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <sstream>
|
||||
#include <type_traits>
|
||||
|
||||
#include <osmium/osm/location.hpp>
|
||||
|
||||
TEST_CASE("Location") {
|
||||
|
||||
// fails on MSVC and doesn't really matter
|
||||
// static_assert(std::is_literal_type<osmium::Location>::value, "osmium::Location not literal type");
|
||||
|
||||
SECTION("instantiation_with_default_parameters") {
|
||||
osmium::Location loc;
|
||||
REQUIRE(!loc);
|
||||
REQUIRE_THROWS_AS(loc.lon(), osmium::invalid_location);
|
||||
REQUIRE_THROWS_AS(loc.lat(), osmium::invalid_location);
|
||||
}
|
||||
|
||||
SECTION("instantiation_with_double_parameters") {
|
||||
osmium::Location loc1(1.2, 4.5);
|
||||
REQUIRE(!!loc1);
|
||||
REQUIRE(12000000 == loc1.x());
|
||||
REQUIRE(45000000 == loc1.y());
|
||||
REQUIRE(1.2 == loc1.lon());
|
||||
REQUIRE(4.5 == loc1.lat());
|
||||
|
||||
osmium::Location loc2(loc1);
|
||||
REQUIRE(4.5 == loc2.lat());
|
||||
|
||||
osmium::Location loc3 = loc1;
|
||||
REQUIRE(4.5 == loc3.lat());
|
||||
}
|
||||
|
||||
SECTION("instantiation_with_double_parameters_constructor_with_universal_initializer") {
|
||||
osmium::Location loc { 2.2, 3.3 };
|
||||
REQUIRE(2.2 == loc.lon());
|
||||
REQUIRE(3.3 == loc.lat());
|
||||
}
|
||||
|
||||
SECTION("instantiation_with_double_parameters_constructor_with_initializer_list") {
|
||||
osmium::Location loc({ 4.4, 5.5 });
|
||||
REQUIRE(4.4 == loc.lon());
|
||||
REQUIRE(5.5 == loc.lat());
|
||||
}
|
||||
|
||||
SECTION("instantiation_with_double_parameters_operator_equal") {
|
||||
osmium::Location loc = { 5.5, 6.6 };
|
||||
REQUIRE(5.5 == loc.lon());
|
||||
REQUIRE(6.6 == loc.lat());
|
||||
}
|
||||
|
||||
SECTION("equality") {
|
||||
osmium::Location loc1(1.2, 4.5);
|
||||
osmium::Location loc2(1.2, 4.5);
|
||||
osmium::Location loc3(1.5, 1.5);
|
||||
REQUIRE(loc1 == loc2);
|
||||
REQUIRE(loc1 != loc3);
|
||||
}
|
||||
|
||||
SECTION("order") {
|
||||
REQUIRE(osmium::Location(-1.2, 10.0) < osmium::Location(1.2, 10.0));
|
||||
REQUIRE(osmium::Location(1.2, 10.0) > osmium::Location(-1.2, 10.0));
|
||||
|
||||
REQUIRE(osmium::Location(10.2, 20.0) < osmium::Location(11.2, 20.2));
|
||||
REQUIRE(osmium::Location(10.2, 20.2) < osmium::Location(11.2, 20.0));
|
||||
REQUIRE(osmium::Location(11.2, 20.2) > osmium::Location(10.2, 20.0));
|
||||
}
|
||||
|
||||
SECTION("validity") {
|
||||
REQUIRE(osmium::Location(0.0, 0.0).valid());
|
||||
REQUIRE(osmium::Location(1.2, 4.5).valid());
|
||||
REQUIRE(osmium::Location(-1.2, 4.5).valid());
|
||||
REQUIRE(osmium::Location(-180.0, -90.0).valid());
|
||||
REQUIRE(osmium::Location(180.0, -90.0).valid());
|
||||
REQUIRE(osmium::Location(-180.0, 90.0).valid());
|
||||
REQUIRE(osmium::Location(180.0, 90.0).valid());
|
||||
|
||||
REQUIRE(!osmium::Location(200.0, 4.5).valid());
|
||||
REQUIRE(!osmium::Location(-1.2, -100.0).valid());
|
||||
REQUIRE(!osmium::Location(-180.0, 90.005).valid());
|
||||
}
|
||||
|
||||
|
||||
SECTION("output_to_iterator_comma_separator") {
|
||||
char buffer[100];
|
||||
osmium::Location loc(-3.2, 47.3);
|
||||
*loc.as_string(buffer, ',') = 0;
|
||||
REQUIRE(std::string("-3.2,47.3") == buffer);
|
||||
}
|
||||
|
||||
SECTION("output_to_iterator_space_separator") {
|
||||
char buffer[100];
|
||||
osmium::Location loc(0.0, 7.0);
|
||||
*loc.as_string(buffer, ' ') = 0;
|
||||
REQUIRE(std::string("0 7") == buffer);
|
||||
}
|
||||
|
||||
SECTION("output_to_iterator_check_precision") {
|
||||
char buffer[100];
|
||||
osmium::Location loc(-179.9999999, -90.0);
|
||||
*loc.as_string(buffer, ' ') = 0;
|
||||
REQUIRE(std::string("-179.9999999 -90") == buffer);
|
||||
}
|
||||
|
||||
SECTION("output_to_iterator_undefined_location") {
|
||||
char buffer[100];
|
||||
osmium::Location loc;
|
||||
REQUIRE_THROWS_AS(loc.as_string(buffer, ','), osmium::invalid_location);
|
||||
}
|
||||
|
||||
SECTION("output_to_string_comman_separator") {
|
||||
std::string s;
|
||||
osmium::Location loc(-3.2, 47.3);
|
||||
loc.as_string(std::back_inserter(s), ',');
|
||||
REQUIRE(s == "-3.2,47.3");
|
||||
}
|
||||
|
||||
SECTION("output_to_string_space_separator") {
|
||||
std::string s;
|
||||
osmium::Location loc(0.0, 7.0);
|
||||
loc.as_string(std::back_inserter(s), ' ');
|
||||
REQUIRE(s == "0 7");
|
||||
}
|
||||
|
||||
SECTION("output_to_string_check_precision") {
|
||||
std::string s;
|
||||
osmium::Location loc(-179.9999999, -90.0);
|
||||
loc.as_string(std::back_inserter(s), ' ');
|
||||
REQUIRE(s == "-179.9999999 -90");
|
||||
}
|
||||
|
||||
SECTION("output_to_string_undefined_location") {
|
||||
std::string s;
|
||||
osmium::Location loc;
|
||||
REQUIRE_THROWS_AS(loc.as_string(std::back_inserter(s), ','), osmium::invalid_location);
|
||||
}
|
||||
|
||||
SECTION("output_defined") {
|
||||
osmium::Location p(-3.2, 47.3);
|
||||
std::stringstream out;
|
||||
out << p;
|
||||
REQUIRE(out.str() == "(-3.2,47.3)");
|
||||
}
|
||||
|
||||
SECTION("output_undefined") {
|
||||
osmium::Location p;
|
||||
std::stringstream out;
|
||||
out << p;
|
||||
REQUIRE(out.str() == "(undefined,undefined)");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/osm/node.hpp>
|
||||
|
||||
#include "helper.hpp"
|
||||
|
||||
TEST_CASE("Basic_Node") {
|
||||
|
||||
SECTION("node_builder") {
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
|
||||
osmium::Node& node = buffer_add_node(buffer,
|
||||
"foo",
|
||||
{{"amenity", "pub"}, {"name", "OSM BAR"}},
|
||||
{3.5, 4.7});
|
||||
|
||||
node.set_id(17)
|
||||
.set_version(3)
|
||||
.set_visible(true)
|
||||
.set_changeset(333)
|
||||
.set_uid(21)
|
||||
.set_timestamp(123);
|
||||
|
||||
REQUIRE(17l == node.id());
|
||||
REQUIRE(17ul == node.positive_id());
|
||||
REQUIRE(3 == node.version());
|
||||
REQUIRE(true == node.visible());
|
||||
REQUIRE(false == node.deleted());
|
||||
REQUIRE(333 == node.changeset());
|
||||
REQUIRE(21 == node.uid());
|
||||
REQUIRE(std::string("foo") == node.user());
|
||||
REQUIRE(123 == node.timestamp());
|
||||
REQUIRE(osmium::Location(3.5, 4.7) == node.location());
|
||||
REQUIRE(2 == node.tags().size());
|
||||
|
||||
node.set_visible(false);
|
||||
REQUIRE(false == node.visible());
|
||||
REQUIRE(true == node.deleted());
|
||||
}
|
||||
|
||||
SECTION("node_default_attributes") {
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
|
||||
osmium::Node& node = buffer_add_node(buffer, "", {}, osmium::Location{});
|
||||
|
||||
REQUIRE(0l == node.id());
|
||||
REQUIRE(0ul == node.positive_id());
|
||||
REQUIRE(0 == node.version());
|
||||
REQUIRE(true == node.visible());
|
||||
REQUIRE(0 == node.changeset());
|
||||
REQUIRE(0 == node.uid());
|
||||
REQUIRE(std::string("") == node.user());
|
||||
REQUIRE(0 == node.timestamp());
|
||||
REQUIRE(osmium::Location() == node.location());
|
||||
REQUIRE(0 == node.tags().size());
|
||||
}
|
||||
|
||||
SECTION("set_node_attributes_from_string") {
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
|
||||
osmium::Node& node = buffer_add_node(buffer,
|
||||
"foo",
|
||||
{{"amenity", "pub"}, {"name", "OSM BAR"}},
|
||||
{3.5, 4.7});
|
||||
|
||||
node.set_id("-17")
|
||||
.set_version("3")
|
||||
.set_visible(true)
|
||||
.set_changeset("333")
|
||||
.set_uid("21");
|
||||
|
||||
REQUIRE(-17l == node.id());
|
||||
REQUIRE(17ul == node.positive_id());
|
||||
REQUIRE(3 == node.version());
|
||||
REQUIRE(true == node.visible());
|
||||
REQUIRE(333 == node.changeset());
|
||||
REQUIRE(21 == node.uid());
|
||||
}
|
||||
|
||||
SECTION("large_id") {
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
|
||||
osmium::Node& node = buffer_add_node(buffer, "", {}, osmium::Location{});
|
||||
|
||||
int64_t id = 3000000000l;
|
||||
node.set_id(id);
|
||||
|
||||
REQUIRE(id == node.id());
|
||||
REQUIRE(static_cast<osmium::unsigned_object_id_type>(id) == node.positive_id());
|
||||
|
||||
node.set_id(-id);
|
||||
REQUIRE(-id == node.id());
|
||||
REQUIRE(static_cast<osmium::unsigned_object_id_type>(id) == node.positive_id());
|
||||
}
|
||||
|
||||
SECTION("tags") {
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
|
||||
osmium::Node& node = buffer_add_node(buffer,
|
||||
"foo",
|
||||
{{"amenity", "pub"}, {"name", "OSM BAR"}},
|
||||
{3.5, 4.7});
|
||||
|
||||
REQUIRE(nullptr == node.tags().get_value_by_key("fail"));
|
||||
REQUIRE(std::string("pub") == node.tags().get_value_by_key("amenity"));
|
||||
REQUIRE(std::string("pub") == node.get_value_by_key("amenity"));
|
||||
|
||||
REQUIRE(std::string("default") == node.tags().get_value_by_key("fail", "default"));
|
||||
REQUIRE(std::string("pub") == node.tags().get_value_by_key("amenity", "default"));
|
||||
REQUIRE(std::string("pub") == node.get_value_by_key("amenity", "default"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/osm/node_ref.hpp>
|
||||
|
||||
TEST_CASE("NodeRef") {
|
||||
|
||||
SECTION("instantiation_with_default_parameters") {
|
||||
osmium::NodeRef node_ref;
|
||||
REQUIRE(node_ref.ref() == 0);
|
||||
// REQUIRE(!node_ref.has_location());
|
||||
}
|
||||
|
||||
SECTION("instantiation_with_id") {
|
||||
osmium::NodeRef node_ref(7);
|
||||
REQUIRE(node_ref.ref() == 7);
|
||||
}
|
||||
|
||||
SECTION("equality") {
|
||||
osmium::NodeRef node_ref1(7, { 1.2, 3.4 });
|
||||
osmium::NodeRef node_ref2(7, { 1.4, 3.1 });
|
||||
osmium::NodeRef node_ref3(9, { 1.2, 3.4 });
|
||||
REQUIRE(node_ref1 == node_ref2);
|
||||
REQUIRE(node_ref1 != node_ref3);
|
||||
REQUIRE(!osmium::location_equal()(node_ref1, node_ref2));
|
||||
REQUIRE(!osmium::location_equal()(node_ref2, node_ref3));
|
||||
REQUIRE(osmium::location_equal()(node_ref1, node_ref3));
|
||||
}
|
||||
|
||||
SECTION("set_location") {
|
||||
osmium::NodeRef node_ref(7);
|
||||
REQUIRE(!node_ref.location().valid());
|
||||
REQUIRE(node_ref.location() == osmium::Location());
|
||||
node_ref.set_location(osmium::Location(13.5, -7.2));
|
||||
REQUIRE(node_ref.location().lon() == 13.5);
|
||||
REQUIRE(node_ref.location().valid());
|
||||
}
|
||||
|
||||
SECTION("ordering") {
|
||||
osmium::NodeRef node_ref1(1, { 1.0, 3.0 });
|
||||
osmium::NodeRef node_ref2(2, { 1.4, 2.9 });
|
||||
osmium::NodeRef node_ref3(3, { 1.2, 3.0 });
|
||||
osmium::NodeRef node_ref4(4, { 1.2, 3.3 });
|
||||
|
||||
REQUIRE(node_ref1 < node_ref2);
|
||||
REQUIRE(node_ref2 < node_ref3);
|
||||
REQUIRE(node_ref1 < node_ref3);
|
||||
REQUIRE(node_ref1 >= node_ref1);
|
||||
|
||||
REQUIRE(osmium::location_less()(node_ref1, node_ref2));
|
||||
REQUIRE(!osmium::location_less()(node_ref2, node_ref3));
|
||||
REQUIRE(osmium::location_less()(node_ref1, node_ref3));
|
||||
REQUIRE(osmium::location_less()(node_ref3, node_ref4));
|
||||
REQUIRE(!osmium::location_less()(node_ref1, node_ref1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/builder/osm_object_builder.hpp>
|
||||
#include <osmium/osm.hpp>
|
||||
#include <osmium/osm/object_comparisons.hpp>
|
||||
|
||||
TEST_CASE("Object_Comparisons") {
|
||||
|
||||
SECTION("order") {
|
||||
osmium::memory::Buffer buffer(10 * 1000);
|
||||
|
||||
{
|
||||
// add node 1
|
||||
osmium::builder::NodeBuilder node_builder(buffer);
|
||||
node_builder.add_user("testuser");
|
||||
buffer.commit();
|
||||
}
|
||||
|
||||
{
|
||||
// add node 2
|
||||
osmium::builder::NodeBuilder node_builder(buffer);
|
||||
node_builder.add_user("testuser");
|
||||
buffer.commit();
|
||||
}
|
||||
|
||||
auto it = buffer.begin();
|
||||
osmium::Node& node1 = static_cast<osmium::Node&>(*it);
|
||||
osmium::Node& node2 = static_cast<osmium::Node&>(*(++it));
|
||||
|
||||
node1.set_id(10);
|
||||
node1.set_version(1);
|
||||
node2.set_id(15);
|
||||
node2.set_version(2);
|
||||
REQUIRE(true == node1 < node2);
|
||||
REQUIRE(false == node1 > node2);
|
||||
node1.set_id(20);
|
||||
node1.set_version(1);
|
||||
node2.set_id(20);
|
||||
node2.set_version(2);
|
||||
REQUIRE(true == node1 < node2);
|
||||
REQUIRE(false == node1 > node2);
|
||||
node1.set_id(-10);
|
||||
node1.set_version(2);
|
||||
node2.set_id(-15);
|
||||
node2.set_version(1);
|
||||
REQUIRE(true == node1 < node2);
|
||||
REQUIRE(false == node1 > node2);
|
||||
}
|
||||
|
||||
SECTION("order_types") {
|
||||
osmium::memory::Buffer buffer(10 * 1000);
|
||||
|
||||
{
|
||||
// add node 1
|
||||
osmium::builder::NodeBuilder node_builder(buffer);
|
||||
osmium::Node& node = node_builder.object();
|
||||
REQUIRE(osmium::item_type::node == node.type());
|
||||
|
||||
node.set_id(3);
|
||||
node.set_version(3);
|
||||
node_builder.add_user("testuser");
|
||||
|
||||
buffer.commit();
|
||||
}
|
||||
|
||||
{
|
||||
// add node 2
|
||||
osmium::builder::NodeBuilder node_builder(buffer);
|
||||
osmium::Node& node = node_builder.object();
|
||||
REQUIRE(osmium::item_type::node == node.type());
|
||||
|
||||
node.set_id(3);
|
||||
node.set_version(4);
|
||||
node_builder.add_user("testuser");
|
||||
|
||||
buffer.commit();
|
||||
}
|
||||
|
||||
{
|
||||
// add node 3
|
||||
osmium::builder::NodeBuilder node_builder(buffer);
|
||||
osmium::Node& node = node_builder.object();
|
||||
REQUIRE(osmium::item_type::node == node.type());
|
||||
|
||||
node.set_id(3);
|
||||
node.set_version(4);
|
||||
node_builder.add_user("testuser");
|
||||
|
||||
buffer.commit();
|
||||
}
|
||||
|
||||
{
|
||||
// add way
|
||||
osmium::builder::WayBuilder way_builder(buffer);
|
||||
osmium::Way& way = way_builder.object();
|
||||
REQUIRE(osmium::item_type::way == way.type());
|
||||
|
||||
way.set_id(2);
|
||||
way.set_version(2);
|
||||
way_builder.add_user("testuser");
|
||||
|
||||
buffer.commit();
|
||||
}
|
||||
|
||||
{
|
||||
// add relation
|
||||
osmium::builder::RelationBuilder relation_builder(buffer);
|
||||
osmium::Relation& relation = relation_builder.object();
|
||||
REQUIRE(osmium::item_type::relation == relation.type());
|
||||
|
||||
relation.set_id(1);
|
||||
relation.set_version(1);
|
||||
relation_builder.add_user("testuser");
|
||||
|
||||
buffer.commit();
|
||||
}
|
||||
|
||||
auto it = buffer.begin();
|
||||
const osmium::Node& node1 = static_cast<const osmium::Node&>(*it);
|
||||
const osmium::Node& node2 = static_cast<const osmium::Node&>(*(++it));
|
||||
const osmium::Node& node3 = static_cast<const osmium::Node&>(*(++it));
|
||||
const osmium::Way& way = static_cast<const osmium::Way&>(*(++it));
|
||||
const osmium::Relation& relation = static_cast<const osmium::Relation&>(*(++it));
|
||||
|
||||
REQUIRE(true == node1 < node2);
|
||||
REQUIRE(true == node2 < way);
|
||||
REQUIRE(false == node2 > way);
|
||||
REQUIRE(true == way < relation);
|
||||
REQUIRE(true == node1 < relation);
|
||||
|
||||
REQUIRE(true == osmium::object_order_type_id_version()(node1, node2));
|
||||
REQUIRE(true == osmium::object_order_type_id_reverse_version()(node2, node1));
|
||||
REQUIRE(true == osmium::object_order_type_id_version()(node1, way));
|
||||
REQUIRE(true == osmium::object_order_type_id_reverse_version()(node1, way));
|
||||
|
||||
REQUIRE(false == osmium::object_equal_type_id_version()(node1, node2));
|
||||
REQUIRE(true == osmium::object_equal_type_id_version()(node2, node3));
|
||||
|
||||
REQUIRE(true == osmium::object_equal_type_id()(node1, node2));
|
||||
REQUIRE(true == osmium::object_equal_type_id()(node2, node3));
|
||||
|
||||
REQUIRE(false == osmium::object_equal_type_id_version()(node1, way));
|
||||
REQUIRE(false == osmium::object_equal_type_id_version()(node1, relation));
|
||||
REQUIRE(false == osmium::object_equal_type_id()(node1, relation));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/osm/relation.hpp>
|
||||
|
||||
#include "helper.hpp"
|
||||
|
||||
TEST_CASE("Basic_Relation") {
|
||||
|
||||
SECTION("relation_builder") {
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
|
||||
osmium::Relation& relation = buffer_add_relation(buffer,
|
||||
"foo", {
|
||||
{"type", "multipolygon"},
|
||||
{"name", "Sherwood Forest"}
|
||||
}, {
|
||||
std::make_tuple('w', 1, "inner"),
|
||||
std::make_tuple('w', 2, ""),
|
||||
std::make_tuple('w', 3, "outer")
|
||||
});
|
||||
|
||||
relation.set_id(17)
|
||||
.set_version(3)
|
||||
.set_visible(true)
|
||||
.set_changeset(333)
|
||||
.set_uid(21)
|
||||
.set_timestamp(123);
|
||||
|
||||
REQUIRE(17 == relation.id());
|
||||
REQUIRE(3 == relation.version());
|
||||
REQUIRE(true == relation.visible());
|
||||
REQUIRE(333 == relation.changeset());
|
||||
REQUIRE(21 == relation.uid());
|
||||
REQUIRE(std::string("foo") == relation.user());
|
||||
REQUIRE(123 == relation.timestamp());
|
||||
REQUIRE(2 == relation.tags().size());
|
||||
REQUIRE(3 == relation.members().size());
|
||||
|
||||
int n=1;
|
||||
for (auto& member : relation.members()) {
|
||||
REQUIRE(osmium::item_type::way == member.type());
|
||||
REQUIRE(n == member.ref());
|
||||
switch (n) {
|
||||
case 1:
|
||||
REQUIRE(std::string("inner") == member.role());
|
||||
break;
|
||||
case 2:
|
||||
REQUIRE(std::string("") == member.role());
|
||||
break;
|
||||
case 3:
|
||||
REQUIRE(std::string("outer") == member.role());
|
||||
break;
|
||||
default:
|
||||
REQUIRE(false);
|
||||
}
|
||||
++n;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include <osmium/osm/timestamp.hpp>
|
||||
|
||||
TEST_CASE("Timestamp") {
|
||||
|
||||
SECTION("can be default initialized to invalid value") {
|
||||
osmium::Timestamp t;
|
||||
REQUIRE(0 == t);
|
||||
REQUIRE("" == t.to_iso());
|
||||
}
|
||||
|
||||
SECTION("invalid value is zero") {
|
||||
osmium::Timestamp t(static_cast<time_t>(0));
|
||||
REQUIRE(0 == t);
|
||||
REQUIRE("" == t.to_iso());
|
||||
}
|
||||
|
||||
SECTION("can be initialized from time_t") {
|
||||
osmium::Timestamp t(static_cast<time_t>(1));
|
||||
REQUIRE(1 == t);
|
||||
REQUIRE("1970-01-01T00:00:01Z" == t.to_iso());
|
||||
}
|
||||
|
||||
SECTION("can be initialized from string") {
|
||||
osmium::Timestamp t("2000-01-01T00:00:00Z");
|
||||
REQUIRE("2000-01-01T00:00:00Z" == t.to_iso());
|
||||
}
|
||||
|
||||
SECTION("can be compared") {
|
||||
osmium::Timestamp t1(10);
|
||||
osmium::Timestamp t2(50);
|
||||
REQUIRE(t1 < t2);
|
||||
}
|
||||
|
||||
SECTION("can be written to stream") {
|
||||
std::stringstream ss;
|
||||
osmium::Timestamp t(1);
|
||||
ss << t;
|
||||
REQUIRE("1970-01-01T00:00:01Z" == ss.str());
|
||||
}
|
||||
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/builder/osm_object_builder.hpp>
|
||||
#include <osmium/osm/way.hpp>
|
||||
|
||||
#include "helper.hpp"
|
||||
|
||||
TEST_CASE("Basic_Way") {
|
||||
|
||||
SECTION("way_builder") {
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
|
||||
osmium::Way& way = buffer_add_way(buffer,
|
||||
"foo",
|
||||
{{"highway", "residential"}, {"name", "High Street"}},
|
||||
{1, 3, 2});
|
||||
|
||||
way.set_id(17)
|
||||
.set_version(3)
|
||||
.set_visible(true)
|
||||
.set_changeset(333)
|
||||
.set_uid(21)
|
||||
.set_timestamp(123);
|
||||
|
||||
REQUIRE(17 == way.id());
|
||||
REQUIRE(3 == way.version());
|
||||
REQUIRE(true == way.visible());
|
||||
REQUIRE(333 == way.changeset());
|
||||
REQUIRE(21 == way.uid());
|
||||
REQUIRE(std::string("foo") == way.user());
|
||||
REQUIRE(123 == way.timestamp());
|
||||
REQUIRE(2 == way.tags().size());
|
||||
REQUIRE(3 == way.nodes().size());
|
||||
REQUIRE(1 == way.nodes()[0].ref());
|
||||
REQUIRE(3 == way.nodes()[1].ref());
|
||||
REQUIRE(2 == way.nodes()[2].ref());
|
||||
REQUIRE(! way.is_closed());
|
||||
}
|
||||
|
||||
SECTION("closed_way") {
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
|
||||
osmium::Way& way = buffer_add_way(buffer,
|
||||
"foo",
|
||||
{{"highway", "residential"}, {"name", "High Street"}},
|
||||
{1, 3, 1});
|
||||
|
||||
REQUIRE(way.is_closed());
|
||||
}
|
||||
|
||||
SECTION("way_builder_with_helpers") {
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
{
|
||||
osmium::builder::WayBuilder builder(buffer);
|
||||
builder.add_user("username");
|
||||
builder.add_tags({
|
||||
{"amenity", "restaurant"},
|
||||
{"name", "Zum goldenen Schwanen"}
|
||||
});
|
||||
builder.add_node_refs({
|
||||
{22, {3.5, 4.7}},
|
||||
{67, {4.1, 2.2}}
|
||||
});
|
||||
}
|
||||
buffer.commit();
|
||||
osmium::Way& way = buffer.get<osmium::Way>(0);
|
||||
|
||||
REQUIRE(std::string("username") == way.user());
|
||||
|
||||
REQUIRE(2 == way.tags().size());
|
||||
REQUIRE(std::string("amenity") == way.tags().begin()->key());
|
||||
REQUIRE(std::string("Zum goldenen Schwanen") == way.tags()["name"]);
|
||||
|
||||
REQUIRE(2 == way.nodes().size());
|
||||
REQUIRE(22 == way.nodes()[0].ref());
|
||||
REQUIRE(4.1 == way.nodes()[1].location().lon());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user