update libosmium to v2.6.0
This commit is contained in:
-103
@@ -1,103 +0,0 @@
|
||||
#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 (const 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 (const 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 (const auto& ring : rings) {
|
||||
if (ring.first) {
|
||||
osmium::builder::OuterRingBuilder ring_builder(buffer, &builder);
|
||||
for (const auto& p : ring.second) {
|
||||
ring_builder.add_node_ref(p.first, p.second);
|
||||
}
|
||||
} else {
|
||||
osmium::builder::InnerRingBuilder ring_builder(buffer, &builder);
|
||||
for (const 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
|
||||
-98
@@ -1,98 +0,0 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include <boost/crc.hpp>
|
||||
|
||||
#include <osmium/osm/box.hpp>
|
||||
#include <osmium/osm/crc.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;
|
||||
osmium::Location loc1 { 1.2, 3.4 };
|
||||
b.extend(loc1);
|
||||
REQUIRE(!!b);
|
||||
REQUIRE(!!b.bottom_left());
|
||||
REQUIRE(!!b.top_right());
|
||||
REQUIRE(b.contains(loc1));
|
||||
|
||||
osmium::Location loc2 { 3.4, 4.5 };
|
||||
osmium::Location loc3 { 5.6, 7.8 };
|
||||
|
||||
b.extend(loc2);
|
||||
b.extend(loc3);
|
||||
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));
|
||||
|
||||
REQUIRE(b.contains(loc1));
|
||||
REQUIRE(b.contains(loc2));
|
||||
REQUIRE(b.contains(loc3));
|
||||
|
||||
osmium::CRC<boost::crc_32_type> crc32;
|
||||
crc32.update(b);
|
||||
REQUIRE(crc32().checksum() == 0xd381a838);
|
||||
}
|
||||
|
||||
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(b.size() == Approx(19.36).epsilon(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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,123 +0,0 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <boost/crc.hpp>
|
||||
|
||||
#include <osmium/osm/changeset.hpp>
|
||||
#include <osmium/osm/crc.hpp>
|
||||
|
||||
#include "helper.hpp"
|
||||
|
||||
TEST_CASE("Basic Changeset") {
|
||||
|
||||
osmium::CRC<boost::crc_32_type> crc32;
|
||||
|
||||
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_num_comments(3)
|
||||
.set_uid(9);
|
||||
|
||||
REQUIRE(42 == cs1.id());
|
||||
REQUIRE(9 == cs1.uid());
|
||||
REQUIRE(7 == cs1.num_changes());
|
||||
REQUIRE(3 == cs1.num_comments());
|
||||
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());
|
||||
|
||||
crc32.update(cs1);
|
||||
REQUIRE(crc32().checksum() == 0x502e8c0e);
|
||||
|
||||
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_num_comments(osmium::num_comments_type(0))
|
||||
.set_uid(9);
|
||||
|
||||
REQUIRE(43 == cs2.id());
|
||||
REQUIRE(9 == cs2.uid());
|
||||
REQUIRE(21 == cs2.num_changes());
|
||||
REQUIRE(0 == cs2.num_comments());
|
||||
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));
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("Create changeset without helper") {
|
||||
osmium::memory::Buffer buffer(10 * 1000);
|
||||
osmium::builder::ChangesetBuilder builder(buffer);
|
||||
|
||||
osmium::Changeset& cs1 = builder.object();
|
||||
cs1.set_id(42)
|
||||
.set_created_at(100)
|
||||
.set_closed_at(200)
|
||||
.set_num_changes(7)
|
||||
.set_num_comments(2)
|
||||
.set_uid(9);
|
||||
|
||||
builder.add_user("user");
|
||||
add_tags(buffer, builder, {
|
||||
{"key1", "val1"},
|
||||
{"key2", "val2"}
|
||||
});
|
||||
|
||||
{
|
||||
osmium::builder::ChangesetDiscussionBuilder disc_builder(buffer, &builder);
|
||||
disc_builder.add_comment(osmium::Timestamp(300), 10, "user2");
|
||||
disc_builder.add_comment_text("foo");
|
||||
disc_builder.add_comment(osmium::Timestamp(400), 9, "user");
|
||||
disc_builder.add_comment_text("bar");
|
||||
}
|
||||
|
||||
buffer.commit();
|
||||
|
||||
REQUIRE(42 == cs1.id());
|
||||
REQUIRE(9 == cs1.uid());
|
||||
REQUIRE(7 == cs1.num_changes());
|
||||
REQUIRE(2 == cs1.num_comments());
|
||||
REQUIRE(true == cs1.closed());
|
||||
REQUIRE(osmium::Timestamp(100) == cs1.created_at());
|
||||
REQUIRE(osmium::Timestamp(200) == cs1.closed_at());
|
||||
REQUIRE(2 == cs1.tags().size());
|
||||
REQUIRE(std::string("user") == cs1.user());
|
||||
|
||||
auto cit = cs1.discussion().begin();
|
||||
|
||||
REQUIRE(cit != cs1.discussion().end());
|
||||
REQUIRE(cit->date() == osmium::Timestamp(300));
|
||||
REQUIRE(cit->uid() == 10);
|
||||
REQUIRE(std::string("user2") == cit->user());
|
||||
REQUIRE(std::string("foo") == cit->text());
|
||||
|
||||
REQUIRE(++cit != cs1.discussion().end());
|
||||
REQUIRE(cit->date() == osmium::Timestamp(400));
|
||||
REQUIRE(cit->uid() == 9);
|
||||
REQUIRE(std::string("user") == cit->user());
|
||||
REQUIRE(std::string("bar") == cit->text());
|
||||
|
||||
REQUIRE(++cit == cs1.discussion().end());
|
||||
}
|
||||
|
||||
-70
@@ -1,70 +0,0 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <boost/crc.hpp>
|
||||
|
||||
#include <osmium/osm/crc.hpp>
|
||||
|
||||
#include "helper.hpp"
|
||||
|
||||
TEST_CASE("CRC of basic datatypes") {
|
||||
|
||||
osmium::CRC<boost::crc_32_type> crc32;
|
||||
|
||||
SECTION("Bool") {
|
||||
crc32.update_bool(true);
|
||||
crc32.update_bool(false);
|
||||
|
||||
REQUIRE(crc32().checksum() == 0x58c223be);
|
||||
}
|
||||
|
||||
SECTION("Char") {
|
||||
crc32.update_int8('x');
|
||||
crc32.update_int8('y');
|
||||
|
||||
REQUIRE(crc32().checksum() == 0x8fe62899);
|
||||
}
|
||||
|
||||
SECTION("Int16") {
|
||||
crc32.update_int16(0x0123U);
|
||||
crc32.update_int16(0x1234U);
|
||||
|
||||
REQUIRE(crc32().checksum() == 0xda923744);
|
||||
}
|
||||
|
||||
SECTION("Int32") {
|
||||
crc32.update_int32(0x01234567UL);
|
||||
crc32.update_int32(0x12345678UL);
|
||||
|
||||
REQUIRE(crc32().checksum() == 0x9b4e2af3);
|
||||
}
|
||||
|
||||
SECTION("Int64") {
|
||||
crc32.update_int64(0x0123456789abcdefULL);
|
||||
crc32.update_int64(0x123456789abcdef0ULL);
|
||||
|
||||
REQUIRE(crc32().checksum() == 0x6d8b7267);
|
||||
}
|
||||
|
||||
SECTION("String") {
|
||||
const char* str = "foobar";
|
||||
crc32.update_string(str);
|
||||
|
||||
REQUIRE(crc32().checksum() == 0x9ef61f95);
|
||||
}
|
||||
|
||||
SECTION("Timestamp") {
|
||||
osmium::Timestamp t("2015-07-12T13:10:46Z");
|
||||
crc32.update(t);
|
||||
|
||||
REQUIRE(crc32().checksum() == 0x58a29d7);
|
||||
}
|
||||
|
||||
SECTION("Location") {
|
||||
osmium::Location loc { 3.46, 2.001 };
|
||||
crc32.update(loc);
|
||||
|
||||
REQUIRE(crc32().checksum() == 0xddee042c);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
#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);
|
||||
|
||||
REQUIRE(osmium::osm_entity_bits::node == osmium::osm_entity_bits::from_item_type(osmium::item_type::node));
|
||||
REQUIRE(osmium::osm_entity_bits::way == osmium::osm_entity_bits::from_item_type(osmium::item_type::way));
|
||||
REQUIRE(osmium::osm_entity_bits::relation == osmium::osm_entity_bits::from_item_type(osmium::item_type::relation));
|
||||
REQUIRE(osmium::osm_entity_bits::changeset == osmium::osm_entity_bits::from_item_type(osmium::item_type::changeset));
|
||||
REQUIRE(osmium::osm_entity_bits::area == osmium::osm_entity_bits::from_item_type(osmium::item_type::area));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,154 +0,0 @@
|
||||
#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)");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
-125
@@ -1,125 +0,0 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <boost/crc.hpp>
|
||||
|
||||
#include <osmium/osm/crc.hpp>
|
||||
#include <osmium/osm/node.hpp>
|
||||
|
||||
#include "helper.hpp"
|
||||
|
||||
TEST_CASE("Basic_Node") {
|
||||
|
||||
osmium::CRC<boost::crc_32_type> crc32;
|
||||
|
||||
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(osmium::item_type::node == node.type());
|
||||
REQUIRE(node.type_is_in(osmium::osm_entity_bits::node));
|
||||
REQUIRE(node.type_is_in(osmium::osm_entity_bits::nwr));
|
||||
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 == uint32_t(node.timestamp()));
|
||||
REQUIRE(osmium::Location(3.5, 4.7) == node.location());
|
||||
REQUIRE(2 == node.tags().size());
|
||||
|
||||
crc32.update(node);
|
||||
REQUIRE(crc32().checksum() == 0x7dc553f9);
|
||||
|
||||
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 == uint32_t(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"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
#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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,147 +0,0 @@
|
||||
#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(node1 < node2);
|
||||
REQUIRE_FALSE(node1 > node2);
|
||||
node1.set_id(20);
|
||||
node1.set_version(1);
|
||||
node2.set_id(20);
|
||||
node2.set_version(2);
|
||||
REQUIRE(node1 < node2);
|
||||
REQUIRE_FALSE(node1 > node2);
|
||||
node1.set_id(-10);
|
||||
node1.set_version(2);
|
||||
node2.set_id(-15);
|
||||
node2.set_version(1);
|
||||
REQUIRE(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(node1 < node2);
|
||||
REQUIRE(node2 < way);
|
||||
REQUIRE_FALSE(node2 > way);
|
||||
REQUIRE(way < relation);
|
||||
REQUIRE(node1 < relation);
|
||||
|
||||
REQUIRE(osmium::object_order_type_id_version()(node1, node2));
|
||||
REQUIRE(osmium::object_order_type_id_reverse_version()(node2, node1));
|
||||
REQUIRE(osmium::object_order_type_id_version()(node1, way));
|
||||
REQUIRE(osmium::object_order_type_id_reverse_version()(node1, way));
|
||||
|
||||
REQUIRE_FALSE(osmium::object_equal_type_id_version()(node1, node2));
|
||||
REQUIRE(osmium::object_equal_type_id_version()(node2, node3));
|
||||
|
||||
REQUIRE(osmium::object_equal_type_id()(node1, node2));
|
||||
REQUIRE(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));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <boost/crc.hpp>
|
||||
|
||||
#include <osmium/osm/crc.hpp>
|
||||
#include <osmium/osm/relation.hpp>
|
||||
|
||||
#include "helper.hpp"
|
||||
|
||||
TEST_CASE("Build relation") {
|
||||
|
||||
osmium::CRC<boost::crc_32_type> crc32;
|
||||
|
||||
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 == uint32_t(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;
|
||||
}
|
||||
|
||||
crc32.update(relation);
|
||||
REQUIRE(crc32().checksum() == 0x2c2352e);
|
||||
}
|
||||
|
||||
TEST_CASE("Member role too long") {
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
|
||||
osmium::builder::RelationMemberListBuilder builder(buffer);
|
||||
|
||||
const char role[2000] = "";
|
||||
builder.add_member(osmium::item_type::node, 1, role, 1024);
|
||||
REQUIRE_THROWS(builder.add_member(osmium::item_type::node, 1, role, 1025));
|
||||
}
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
#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 == uint32_t(t));
|
||||
REQUIRE("" == t.to_iso());
|
||||
REQUIRE_FALSE(t.valid());
|
||||
}
|
||||
|
||||
SECTION("invalid value is zero") {
|
||||
osmium::Timestamp t(static_cast<time_t>(0));
|
||||
REQUIRE(0 == uint32_t(t));
|
||||
REQUIRE("" == t.to_iso());
|
||||
REQUIRE_FALSE(t.valid());
|
||||
}
|
||||
|
||||
SECTION("can be initialized from time_t") {
|
||||
osmium::Timestamp t(static_cast<time_t>(1));
|
||||
REQUIRE(1 == uint32_t(t));
|
||||
REQUIRE("1970-01-01T00:00:01Z" == t.to_iso());
|
||||
REQUIRE(t.valid());
|
||||
}
|
||||
|
||||
SECTION("can be initialized from const char*") {
|
||||
osmium::Timestamp t("2000-01-01T00:00:00Z");
|
||||
REQUIRE("2000-01-01T00:00:00Z" == t.to_iso());
|
||||
REQUIRE(t.valid());
|
||||
}
|
||||
|
||||
SECTION("can be initialized from string") {
|
||||
std::string s = "2000-01-01T00:00:00Z";
|
||||
osmium::Timestamp t(s);
|
||||
REQUIRE("2000-01-01T00:00:00Z" == t.to_iso());
|
||||
REQUIRE(t.valid());
|
||||
}
|
||||
|
||||
SECTION("throws if initialized from bad string") {
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp("x"), std::invalid_argument);
|
||||
}
|
||||
|
||||
SECTION("can be explicitly cast to time_t") {
|
||||
osmium::Timestamp t(4242);
|
||||
time_t x = t.seconds_since_epoch();
|
||||
REQUIRE(x == 4242);
|
||||
}
|
||||
|
||||
SECTION("uint32_t can be initialized from Timestamp") {
|
||||
osmium::Timestamp t(4242);
|
||||
uint32_t x { t };
|
||||
|
||||
REQUIRE(x == 4242);
|
||||
}
|
||||
|
||||
SECTION("can be compared") {
|
||||
osmium::Timestamp t1(10);
|
||||
osmium::Timestamp t2(50);
|
||||
REQUIRE(t1 < t2);
|
||||
REQUIRE(t1 > osmium::start_of_time());
|
||||
REQUIRE(t2 > osmium::start_of_time());
|
||||
REQUIRE(t1 < osmium::end_of_time());
|
||||
REQUIRE(t2 < osmium::end_of_time());
|
||||
}
|
||||
|
||||
SECTION("can be written to stream") {
|
||||
std::stringstream ss;
|
||||
osmium::Timestamp t(1);
|
||||
ss << t;
|
||||
REQUIRE("1970-01-01T00:00:01Z" == ss.str());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/osm/types.hpp>
|
||||
#include <osmium/osm/types_from_string.hpp>
|
||||
|
||||
TEST_CASE("set ID from string") {
|
||||
REQUIRE(osmium::string_to_object_id("0") == 0);
|
||||
REQUIRE(osmium::string_to_object_id("17") == 17);
|
||||
REQUIRE(osmium::string_to_object_id("-17") == -17);
|
||||
REQUIRE(osmium::string_to_object_id("01") == 1);
|
||||
|
||||
REQUIRE_THROWS_AS(osmium::string_to_object_id(""), std::range_error);
|
||||
REQUIRE_THROWS_AS(osmium::string_to_object_id(" "), std::range_error);
|
||||
REQUIRE_THROWS_AS(osmium::string_to_object_id(" 22"), std::range_error);
|
||||
REQUIRE_THROWS_AS(osmium::string_to_object_id("x"), std::range_error);
|
||||
REQUIRE_THROWS_AS(osmium::string_to_object_id("0x1"), std::range_error);
|
||||
REQUIRE_THROWS_AS(osmium::string_to_object_id("12a"), std::range_error);
|
||||
REQUIRE_THROWS_AS(osmium::string_to_object_id("12345678901234567890"), std::range_error);
|
||||
}
|
||||
|
||||
TEST_CASE("set type and ID from string") {
|
||||
auto n17 = osmium::string_to_object_id("n17", osmium::osm_entity_bits::nwr);
|
||||
REQUIRE(n17.first == osmium::item_type::node);
|
||||
REQUIRE(n17.second == 17);
|
||||
|
||||
auto w42 = osmium::string_to_object_id("w42", osmium::osm_entity_bits::nwr);
|
||||
REQUIRE(w42.first == osmium::item_type::way);
|
||||
REQUIRE(w42.second == 42);
|
||||
|
||||
auto r_2 = osmium::string_to_object_id("r-2", osmium::osm_entity_bits::nwr);
|
||||
REQUIRE(r_2.first == osmium::item_type::relation);
|
||||
REQUIRE(r_2.second == -2);
|
||||
|
||||
auto x3 = osmium::string_to_object_id("3", osmium::osm_entity_bits::nwr);
|
||||
REQUIRE(x3.first == osmium::item_type::undefined);
|
||||
REQUIRE(x3.second == 3);
|
||||
|
||||
REQUIRE_THROWS_AS(osmium::string_to_object_id("", osmium::osm_entity_bits::nwr), std::range_error);
|
||||
REQUIRE_THROWS_AS(osmium::string_to_object_id("n", osmium::osm_entity_bits::nwr), std::range_error);
|
||||
REQUIRE_THROWS_AS(osmium::string_to_object_id("x3", osmium::osm_entity_bits::nwr), std::range_error);
|
||||
REQUIRE_THROWS_AS(osmium::string_to_object_id("nx3", osmium::osm_entity_bits::nwr), std::range_error);
|
||||
REQUIRE_THROWS_AS(osmium::string_to_object_id("n3", osmium::osm_entity_bits::way), std::range_error);
|
||||
REQUIRE_THROWS_AS(osmium::string_to_object_id("n3a", osmium::osm_entity_bits::nwr), std::range_error);
|
||||
}
|
||||
|
||||
TEST_CASE("set object version from string") {
|
||||
REQUIRE(osmium::string_to_object_version("0") == 0);
|
||||
REQUIRE(osmium::string_to_object_version("1") == 1);
|
||||
|
||||
REQUIRE_THROWS_AS(osmium::string_to_object_version("-1"), std::range_error);
|
||||
REQUIRE_THROWS_AS(osmium::string_to_object_version(""), std::range_error);
|
||||
REQUIRE_THROWS_AS(osmium::string_to_object_version(" "), std::range_error);
|
||||
REQUIRE_THROWS_AS(osmium::string_to_object_version(" 22"), std::range_error);
|
||||
REQUIRE_THROWS_AS(osmium::string_to_object_version("x"), std::range_error);
|
||||
}
|
||||
|
||||
TEST_CASE("set changeset id from string") {
|
||||
REQUIRE(osmium::string_to_changeset_id("0") == 0);
|
||||
REQUIRE(osmium::string_to_changeset_id("1") == 1);
|
||||
|
||||
REQUIRE_THROWS_AS(osmium::string_to_changeset_id("-1"), std::range_error);
|
||||
REQUIRE_THROWS_AS(osmium::string_to_changeset_id(""), std::range_error);
|
||||
REQUIRE_THROWS_AS(osmium::string_to_changeset_id(" "), std::range_error);
|
||||
REQUIRE_THROWS_AS(osmium::string_to_changeset_id(" 22"), std::range_error);
|
||||
REQUIRE_THROWS_AS(osmium::string_to_changeset_id("x"), std::range_error);
|
||||
}
|
||||
|
||||
TEST_CASE("set user id from string") {
|
||||
REQUIRE(osmium::string_to_user_id("0") == 0);
|
||||
REQUIRE(osmium::string_to_user_id("1") == 1);
|
||||
REQUIRE(osmium::string_to_user_id("-1") == -1);
|
||||
|
||||
REQUIRE_THROWS_AS(osmium::string_to_user_id("-2"), std::range_error);
|
||||
REQUIRE_THROWS_AS(osmium::string_to_user_id(""), std::range_error);
|
||||
REQUIRE_THROWS_AS(osmium::string_to_user_id(" "), std::range_error);
|
||||
REQUIRE_THROWS_AS(osmium::string_to_user_id(" 22"), std::range_error);
|
||||
REQUIRE_THROWS_AS(osmium::string_to_user_id("x"), std::range_error);
|
||||
}
|
||||
|
||||
TEST_CASE("set num changes from string") {
|
||||
REQUIRE(osmium::string_to_num_changes("0") == 0);
|
||||
REQUIRE(osmium::string_to_num_changes("1") == 1);
|
||||
|
||||
REQUIRE_THROWS_AS(osmium::string_to_num_changes("-1"), std::range_error);
|
||||
REQUIRE_THROWS_AS(osmium::string_to_num_changes(""), std::range_error);
|
||||
REQUIRE_THROWS_AS(osmium::string_to_num_changes(" "), std::range_error);
|
||||
REQUIRE_THROWS_AS(osmium::string_to_num_changes(" 22"), std::range_error);
|
||||
REQUIRE_THROWS_AS(osmium::string_to_num_changes("x"), std::range_error);
|
||||
}
|
||||
|
||||
-90
@@ -1,90 +0,0 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <boost/crc.hpp>
|
||||
|
||||
#include <osmium/builder/osm_object_builder.hpp>
|
||||
#include <osmium/osm/crc.hpp>
|
||||
#include <osmium/osm/way.hpp>
|
||||
|
||||
#include "helper.hpp"
|
||||
|
||||
TEST_CASE("Build way") {
|
||||
|
||||
osmium::CRC<boost::crc_32_type> crc32;
|
||||
|
||||
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(osmium::item_type::way == way.type());
|
||||
REQUIRE(way.type_is_in(osmium::osm_entity_bits::way));
|
||||
REQUIRE(way.type_is_in(osmium::osm_entity_bits::node | osmium::osm_entity_bits::way));
|
||||
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 == uint32_t(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());
|
||||
|
||||
crc32.update(way);
|
||||
REQUIRE(crc32().checksum() == 0x7676d0c2);
|
||||
}
|
||||
|
||||
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