Merge commit '8511256779228db8d2ffed7ccced2b53c70be248' as 'third_party/libosmium'
This commit is contained in:
+134
@@ -0,0 +1,134 @@
|
||||
#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("Starting with default constructed box") {
|
||||
|
||||
osmium::Box b;
|
||||
|
||||
SECTION("default constructor creates invalid box") {
|
||||
REQUIRE(!b);
|
||||
REQUIRE(!b.bottom_left());
|
||||
REQUIRE(!b.top_right());
|
||||
REQUIRE_THROWS_AS(b.size(), osmium::invalid_location);
|
||||
}
|
||||
|
||||
SECTION("extend with undefined") {
|
||||
REQUIRE(!b);
|
||||
b.extend(osmium::Location{});
|
||||
REQUIRE(!b);
|
||||
REQUIRE(!b.bottom_left());
|
||||
REQUIRE(!b.top_right());
|
||||
}
|
||||
|
||||
SECTION("extend with invalid") {
|
||||
REQUIRE(!b);
|
||||
b.extend(osmium::Location{200.0, 100.0});
|
||||
REQUIRE(!b);
|
||||
REQUIRE(!b.bottom_left());
|
||||
REQUIRE(!b.top_right());
|
||||
}
|
||||
|
||||
SECTION("extend with valid") {
|
||||
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") {
|
||||
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") {
|
||||
std::stringstream out;
|
||||
out << b;
|
||||
REQUIRE(out.str() == "(undefined)");
|
||||
}
|
||||
|
||||
SECTION("output undefined bottom left") {
|
||||
b.top_right() = osmium::Location(1.2, 3.4);
|
||||
std::stringstream out;
|
||||
out << b;
|
||||
REQUIRE(out.str() == "(undefined)");
|
||||
}
|
||||
|
||||
SECTION("output undefined top right") {
|
||||
b.bottom_left() = osmium::Location(1.2, 3.4);
|
||||
std::stringstream out;
|
||||
out << b;
|
||||
REQUIRE(out.str() == "(undefined)");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("Create box from locations") {
|
||||
osmium::Box b{osmium::Location{1.23, 2.34}, osmium::Location{3.45, 4.56}};
|
||||
REQUIRE(!!b);
|
||||
REQUIRE(b.bottom_left() == (osmium::Location{1.23, 2.34}));
|
||||
REQUIRE(b.top_right() == (osmium::Location{3.45, 4.56}));
|
||||
}
|
||||
|
||||
TEST_CASE("Create box from doubles") {
|
||||
osmium::Box b{1.23, 2.34, 3.45, 4.56};
|
||||
REQUIRE(!!b);
|
||||
REQUIRE(b.bottom_left() == (osmium::Location{1.23, 2.34}));
|
||||
REQUIRE(b.top_right() == (osmium::Location{3.45, 4.56}));
|
||||
}
|
||||
|
||||
TEST_CASE("Relationship between boxes") {
|
||||
|
||||
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,145 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <boost/crc.hpp>
|
||||
|
||||
#include <osmium/builder/attr.hpp>
|
||||
#include <osmium/osm/changeset.hpp>
|
||||
#include <osmium/osm/crc.hpp>
|
||||
|
||||
using namespace osmium::builder::attr;
|
||||
|
||||
TEST_CASE("Build changeset") {
|
||||
osmium::memory::Buffer buffer(10 * 1000);
|
||||
|
||||
osmium::builder::add_changeset(buffer,
|
||||
_cid(42),
|
||||
_created_at(time_t(100)),
|
||||
_closed_at(time_t(200)),
|
||||
_num_changes(7),
|
||||
_num_comments(3),
|
||||
_uid(9),
|
||||
_user("user"),
|
||||
_tag("comment", "foo")
|
||||
);
|
||||
|
||||
const osmium::Changeset& cs1 = buffer.get<osmium::Changeset>(0);
|
||||
|
||||
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());
|
||||
|
||||
osmium::CRC<boost::crc_32_type> crc32;
|
||||
crc32.update(cs1);
|
||||
REQUIRE(crc32().checksum() == 0x502e8c0e);
|
||||
|
||||
auto pos = osmium::builder::add_changeset(buffer,
|
||||
_cid(43),
|
||||
_created_at(time_t(120)),
|
||||
_num_changes(21),
|
||||
_num_comments(0),
|
||||
_uid(9),
|
||||
_user("user"),
|
||||
_tag("comment", "foo"),
|
||||
_tag("foo", "bar"),
|
||||
_comment({time_t(300), 10, "user2", "foo"}),
|
||||
_comments({{time_t(400), 9, "user", "bar"}})
|
||||
);
|
||||
|
||||
const osmium::Changeset& cs2 = buffer.get<osmium::Changeset>(pos);
|
||||
|
||||
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));
|
||||
|
||||
auto cit = cs2.discussion().begin();
|
||||
|
||||
REQUIRE(cit != cs2.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 != cs2.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 == cs2.discussion().end());
|
||||
}
|
||||
|
||||
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");
|
||||
{
|
||||
osmium::builder::TagListBuilder tl_builder(buffer, &builder);
|
||||
tl_builder.add_tag("key1", "val1");
|
||||
tl_builder.add_tag("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());
|
||||
}
|
||||
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <boost/crc.hpp>
|
||||
|
||||
#include <osmium/osm/crc.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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
#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));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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)");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <boost/crc.hpp>
|
||||
|
||||
#include <osmium/builder/attr.hpp>
|
||||
#include <osmium/osm/crc.hpp>
|
||||
#include <osmium/osm/node.hpp>
|
||||
|
||||
using namespace osmium::builder::attr;
|
||||
|
||||
TEST_CASE("Build node") {
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
|
||||
osmium::builder::add_node(buffer,
|
||||
_id(17),
|
||||
_version(3),
|
||||
_visible(true),
|
||||
_cid(333),
|
||||
_uid(21),
|
||||
_timestamp(time_t(123)),
|
||||
_user("foo"),
|
||||
_tag("amenity", "pub"),
|
||||
_tag("name", "OSM BAR"),
|
||||
_location(3.5, 4.7)
|
||||
);
|
||||
|
||||
osmium::Node& node = buffer.get<osmium::Node>(0);
|
||||
|
||||
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());
|
||||
|
||||
osmium::CRC<boost::crc_32_type> crc32;
|
||||
crc32.update(node);
|
||||
REQUIRE(crc32().checksum() == 0x7dc553f9);
|
||||
|
||||
node.set_visible(false);
|
||||
REQUIRE(false == node.visible());
|
||||
REQUIRE(true == node.deleted());
|
||||
}
|
||||
|
||||
TEST_CASE("default values for node attributes") {
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
|
||||
osmium::builder::add_node(buffer, _id(0));
|
||||
|
||||
const osmium::Node& node = buffer.get<osmium::Node>(0);
|
||||
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());
|
||||
}
|
||||
|
||||
TEST_CASE("set node attributes from strings") {
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
|
||||
osmium::builder::add_node(buffer, _id(0));
|
||||
|
||||
osmium::Node& node = buffer.get<osmium::Node>(0);
|
||||
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());
|
||||
}
|
||||
|
||||
TEST_CASE("set large id") {
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
|
||||
int64_t id = 3000000000l;
|
||||
osmium::builder::add_node(buffer, _id(id));
|
||||
|
||||
osmium::Node& node = buffer.get<osmium::Node>(0);
|
||||
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());
|
||||
}
|
||||
|
||||
TEST_CASE("set tags on node") {
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
|
||||
osmium::builder::add_node(buffer,
|
||||
_user("foo"),
|
||||
_tag("amenity", "pub"),
|
||||
_tag("name", "OSM BAR")
|
||||
);
|
||||
|
||||
const osmium::Node& node = buffer.get<osmium::Node>(0);
|
||||
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,109 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/builder/attr.hpp>
|
||||
#include <osmium/memory/buffer.hpp>
|
||||
#include <osmium/osm/node_ref.hpp>
|
||||
#include <osmium/osm/node_ref_list.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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("WayNodeList") {
|
||||
osmium::memory::Buffer buffer(1024);
|
||||
|
||||
SECTION("Empty list") {
|
||||
{
|
||||
osmium::builder::WayNodeListBuilder builder(buffer);
|
||||
}
|
||||
REQUIRE(buffer.commit() == 0);
|
||||
REQUIRE(buffer.committed( )> 0);
|
||||
|
||||
const osmium::WayNodeList& nrl = buffer.get<osmium::WayNodeList>(0);
|
||||
REQUIRE(nrl.empty());
|
||||
REQUIRE(nrl.size() == 0);
|
||||
}
|
||||
|
||||
SECTION("Small area") {
|
||||
osmium::builder::add_way_node_list(buffer, osmium::builder::attr::_nodes({
|
||||
{ 1, {0, 0}},
|
||||
{ 2, {0, 1}},
|
||||
{ 3, {1, 1}},
|
||||
{ 4, {1, 0}},
|
||||
{ 1, {0, 0}},
|
||||
}));
|
||||
|
||||
const osmium::WayNodeList& nrl = buffer.get<osmium::WayNodeList>(0);
|
||||
REQUIRE_FALSE(nrl.empty());
|
||||
REQUIRE(nrl.size() == 5);
|
||||
REQUIRE(nrl.is_closed());
|
||||
REQUIRE(nrl.ends_have_same_id());
|
||||
REQUIRE(nrl.ends_have_same_location());
|
||||
}
|
||||
|
||||
SECTION("Not an area") {
|
||||
osmium::builder::add_way_node_list(buffer, osmium::builder::attr::_nodes({
|
||||
{ 1, {0, 0}},
|
||||
{ 2, {1, 0}},
|
||||
{ 1, {0, 0}},
|
||||
}));
|
||||
|
||||
const osmium::WayNodeList& nrl = buffer.get<osmium::WayNodeList>(0);
|
||||
REQUIRE_FALSE(nrl.empty());
|
||||
REQUIRE(nrl.size() == 3);
|
||||
REQUIRE(nrl.is_closed());
|
||||
REQUIRE(nrl.ends_have_same_id());
|
||||
REQUIRE(nrl.ends_have_same_location());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/builder/attr.hpp>
|
||||
#include <osmium/builder/osm_object_builder.hpp>
|
||||
#include <osmium/osm.hpp>
|
||||
#include <osmium/osm/object_comparisons.hpp>
|
||||
|
||||
TEST_CASE("Object_Comparisons") {
|
||||
|
||||
using namespace osmium::builder::attr;
|
||||
|
||||
SECTION("order") {
|
||||
osmium::memory::Buffer buffer(10 * 1000);
|
||||
|
||||
osmium::builder::add_node(buffer, _id(10), _version(1));
|
||||
osmium::builder::add_node(buffer, _id(15), _version(2));
|
||||
|
||||
auto it = buffer.begin();
|
||||
osmium::Node& node1 = static_cast<osmium::Node&>(*it);
|
||||
osmium::Node& node2 = static_cast<osmium::Node&>(*(++it));
|
||||
|
||||
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);
|
||||
|
||||
osmium::builder::add_node(buffer, _id(3), _version(3));
|
||||
osmium::builder::add_node(buffer, _id(3), _version(4));
|
||||
osmium::builder::add_node(buffer, _id(3), _version(4));
|
||||
osmium::builder::add_way(buffer, _id(2), _version(2));
|
||||
osmium::builder::add_relation(buffer, _id(1), _version(1));
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <boost/crc.hpp>
|
||||
|
||||
#include <osmium/builder/attr.hpp>
|
||||
#include <osmium/osm/crc.hpp>
|
||||
#include <osmium/osm/relation.hpp>
|
||||
|
||||
using namespace osmium::builder::attr;
|
||||
|
||||
TEST_CASE("Build relation") {
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
|
||||
osmium::builder::add_relation(buffer,
|
||||
_id(17),
|
||||
_version(3),
|
||||
_visible(),
|
||||
_cid(333),
|
||||
_uid(21),
|
||||
_timestamp(time_t(123)),
|
||||
_user("foo"),
|
||||
_tag("type", "multipolygon"),
|
||||
_tag("name", "Sherwood Forest"),
|
||||
_member(osmium::item_type::way, 1, "inner"),
|
||||
_member(osmium::item_type::way, 2, ""),
|
||||
_member(osmium::item_type::way, 3, "outer")
|
||||
);
|
||||
|
||||
const osmium::Relation& relation = buffer.get<osmium::Relation>(0);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
osmium::CRC<boost::crc_32_type> crc32;
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
#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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
#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);
|
||||
}
|
||||
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <boost/crc.hpp>
|
||||
|
||||
#include <osmium/builder/attr.hpp>
|
||||
#include <osmium/builder/osm_object_builder.hpp>
|
||||
#include <osmium/osm/crc.hpp>
|
||||
#include <osmium/osm/way.hpp>
|
||||
|
||||
using namespace osmium::builder::attr;
|
||||
|
||||
TEST_CASE("Build way") {
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
|
||||
osmium::builder::add_way(buffer,
|
||||
_id(17),
|
||||
_version(3),
|
||||
_visible(true),
|
||||
_cid(333),
|
||||
_uid(21),
|
||||
_timestamp(time_t(123)),
|
||||
_user("foo"),
|
||||
_tag("highway", "residential"),
|
||||
_tag("name", "High Street"),
|
||||
_nodes({1, 3, 2})
|
||||
);
|
||||
|
||||
const osmium::Way& way = buffer.get<osmium::Way>(0);
|
||||
|
||||
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());
|
||||
|
||||
osmium::CRC<boost::crc_32_type> crc32;
|
||||
crc32.update(way);
|
||||
REQUIRE(crc32().checksum() == 0x7676d0c2);
|
||||
}
|
||||
|
||||
TEST_CASE("build closed way") {
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
|
||||
osmium::builder::add_way(buffer,
|
||||
_tag("highway", "residential"),
|
||||
_tag("name", "High Street"),
|
||||
_nodes({1, 3, 1})
|
||||
);
|
||||
|
||||
const osmium::Way& way = buffer.get<osmium::Way>(0);
|
||||
|
||||
REQUIRE(way.is_closed());
|
||||
}
|
||||
|
||||
TEST_CASE("build way 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();
|
||||
|
||||
const 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