Merge commit '879f7eb04200d7d2c28af565229bf6e3d54274fd' into retry/libosmium
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <boost/crc.hpp>
|
||||
|
||||
#include <osmium/builder/attr.hpp>
|
||||
#include <osmium/osm/crc.hpp>
|
||||
#include <osmium/osm/area.hpp>
|
||||
|
||||
using namespace osmium::builder::attr;
|
||||
|
||||
TEST_CASE("Build area") {
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
|
||||
osmium::builder::add_area(buffer,
|
||||
_id(17),
|
||||
_version(3),
|
||||
_visible(),
|
||||
_cid(333),
|
||||
_uid(21),
|
||||
_timestamp(time_t(123)),
|
||||
_user("foo"),
|
||||
_tag("landuse", "forest"),
|
||||
_tag("name", "Sherwood Forest"),
|
||||
_outer_ring({
|
||||
{1, {3.2, 4.2}},
|
||||
{2, {3.5, 4.7}},
|
||||
{3, {3.6, 4.9}},
|
||||
{1, {3.2, 4.2}}
|
||||
}),
|
||||
_inner_ring({
|
||||
{5, {1.0, 1.0}},
|
||||
{6, {8.0, 1.0}},
|
||||
{7, {8.0, 8.0}},
|
||||
{8, {1.0, 8.0}},
|
||||
{5, {1.0, 1.0}}
|
||||
})
|
||||
);
|
||||
|
||||
const osmium::Area& area = buffer.get<osmium::Area>(0);
|
||||
|
||||
REQUIRE(17 == area.id());
|
||||
REQUIRE(3 == area.version());
|
||||
REQUIRE(true == area.visible());
|
||||
REQUIRE(333 == area.changeset());
|
||||
REQUIRE(21 == area.uid());
|
||||
REQUIRE(std::string("foo") == area.user());
|
||||
REQUIRE(123 == uint32_t(area.timestamp()));
|
||||
REQUIRE(2 == area.tags().size());
|
||||
|
||||
int inner = 0;
|
||||
int outer = 0;
|
||||
for (const auto& subitem : area) {
|
||||
switch (subitem.type()) {
|
||||
case osmium::item_type::outer_ring: {
|
||||
const auto& ring = static_cast<const osmium::OuterRing&>(subitem);
|
||||
REQUIRE(ring.size() == 4);
|
||||
++outer;
|
||||
}
|
||||
break;
|
||||
case osmium::item_type::inner_ring: {
|
||||
const auto& ring = static_cast<const osmium::OuterRing&>(subitem);
|
||||
REQUIRE(ring.size() == 5);
|
||||
++inner;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
REQUIRE(outer == 1);
|
||||
REQUIRE(inner == 1);
|
||||
|
||||
osmium::CRC<boost::crc_32_type> crc32;
|
||||
crc32.update(area);
|
||||
REQUIRE(crc32().checksum() == 0x2b2b7fa0);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ TEST_CASE("entity_bits") {
|
||||
REQUIRE(! (entities & osmium::osm_entity_bits::way));
|
||||
REQUIRE(entities == osmium::osm_entity_bits::node);
|
||||
|
||||
REQUIRE(osmium::osm_entity_bits::nothing == osmium::osm_entity_bits::from_item_type(osmium::item_type::undefined));
|
||||
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));
|
||||
|
||||
+219
-1
@@ -137,7 +137,7 @@ TEST_CASE("Location") {
|
||||
}
|
||||
|
||||
SECTION("output_defined") {
|
||||
osmium::Location p(-3.2, 47.3);
|
||||
osmium::Location p(-3.20, 47.30);
|
||||
std::stringstream out;
|
||||
out << p;
|
||||
REQUIRE(out.str() == "(-3.2,47.3)");
|
||||
@@ -152,3 +152,221 @@ TEST_CASE("Location") {
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("Location hash") {
|
||||
if (sizeof(size_t) == 8) {
|
||||
REQUIRE(std::hash<osmium::Location>{}({0, 0}) == 0);
|
||||
REQUIRE(std::hash<osmium::Location>{}({0, 1}) == 1);
|
||||
REQUIRE(std::hash<osmium::Location>{}({1, 0}) == 0x100000000);
|
||||
REQUIRE(std::hash<osmium::Location>{}({1, 1}) == 0x100000001);
|
||||
} else {
|
||||
REQUIRE(std::hash<osmium::Location>{}({0, 0}) == 0);
|
||||
REQUIRE(std::hash<osmium::Location>{}({0, 1}) == 1);
|
||||
REQUIRE(std::hash<osmium::Location>{}({1, 0}) == 1);
|
||||
REQUIRE(std::hash<osmium::Location>{}({1, 1}) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
#define CR(s, v, r) { \
|
||||
const char* strm = "-" s; \
|
||||
const char* strp = strm + 1; \
|
||||
REQUIRE(std::atof(strp) == Approx( v / 10000000.0)); \
|
||||
REQUIRE(std::atof(strm) == Approx(-v / 10000000.0)); \
|
||||
const char** data = &strp; \
|
||||
REQUIRE(osmium::detail::string_to_location_coordinate(data) == v); \
|
||||
REQUIRE(std::string{*data} == r); \
|
||||
data = &strm; \
|
||||
REQUIRE(osmium::detail::string_to_location_coordinate(data) == -v); \
|
||||
REQUIRE(std::string{*data} == r); \
|
||||
}
|
||||
|
||||
#define C(s, v) CR(s, v, "")
|
||||
|
||||
#define F(s) { \
|
||||
const char* strm = "-" s; \
|
||||
const char* strp = strm + 1; \
|
||||
const char** data = &strp; \
|
||||
REQUIRE_THROWS_AS(osmium::detail::string_to_location_coordinate(data), osmium::invalid_location); \
|
||||
data = &strm; \
|
||||
REQUIRE_THROWS_AS(osmium::detail::string_to_location_coordinate(data), osmium::invalid_location); \
|
||||
}
|
||||
|
||||
TEST_CASE("Parsing coordinates from strings") {
|
||||
F("x");
|
||||
F(".");
|
||||
F("--");
|
||||
F("");
|
||||
F(" ");
|
||||
F(" 123");
|
||||
|
||||
CR("123 ", 1230000000, " ");
|
||||
CR("123x", 1230000000, "x");
|
||||
CR("1.2x", 12000000, "x");
|
||||
|
||||
C("0", 0);
|
||||
|
||||
C("1", 10000000);
|
||||
C("2", 20000000);
|
||||
|
||||
C("9", 90000000);
|
||||
C("10", 100000000);
|
||||
C("11", 110000000);
|
||||
|
||||
C("90", 900000000);
|
||||
C("100", 1000000000);
|
||||
C("101", 1010000000);
|
||||
|
||||
C("00", 0);
|
||||
C("01", 10000000);
|
||||
C("001", 10000000);
|
||||
C("0001", 10000000);
|
||||
|
||||
F("1234");
|
||||
F("1234.");
|
||||
F("12345678901234567890");
|
||||
|
||||
C("0.", 0);
|
||||
C("0.0", 0);
|
||||
C("1.", 10000000);
|
||||
C("1.0", 10000000);
|
||||
C("1.2", 12000000);
|
||||
C("0.1", 1000000);
|
||||
C("0.01", 100000);
|
||||
C("0.001", 10000);
|
||||
C("0.0001", 1000);
|
||||
C("0.00001", 100);
|
||||
C("0.000001", 10);
|
||||
C("0.0000001", 1);
|
||||
|
||||
C("1.1234567", 11234567);
|
||||
C("1.12345670", 11234567);
|
||||
C("1.12345674", 11234567);
|
||||
C("1.123456751", 11234568);
|
||||
C("1.12345679", 11234568);
|
||||
C("1.12345680", 11234568);
|
||||
C("1.12345681", 11234568);
|
||||
|
||||
C("180.0000000", 1800000000);
|
||||
C("180.0000001", 1800000001);
|
||||
C("179.9999999", 1799999999);
|
||||
C("179.99999999", 1800000000);
|
||||
C("200.123", 2001230000);
|
||||
|
||||
C("1e2", 1000000000);
|
||||
C("1e1", 100000000);
|
||||
C("1e0", 10000000);
|
||||
C("1e-1", 1000000);
|
||||
C("1e-2", 100000);
|
||||
C("1e-3", 10000);
|
||||
C("1e-4", 1000);
|
||||
C("1e-5", 100);
|
||||
C("1e-6", 10);
|
||||
C("1e-7", 1);
|
||||
|
||||
C("1.0e2", 1000000000);
|
||||
C("1.1e1", 110000000);
|
||||
C("0.1e1", 10000000);
|
||||
C("1.2e0", 12000000);
|
||||
C("1.9e-1", 1900000);
|
||||
C("2.0e-2", 200000);
|
||||
C("2.1e-3", 21000);
|
||||
C("9.0e-4", 9000);
|
||||
C("9.1e-5", 910);
|
||||
C("1.0e-6", 10);
|
||||
C("1.0e-7", 1);
|
||||
C("1.4e-7", 1);
|
||||
C("1.5e-7", 2);
|
||||
C("1.9e-7", 2);
|
||||
C("0.5e-7", 1);
|
||||
C("0.1e-7", 0);
|
||||
C("0.0e-7", 0);
|
||||
C("1.9e-8", 0);
|
||||
C("1.9e-9", 0);
|
||||
C("1.9e-10", 0);
|
||||
|
||||
F("e");
|
||||
F(" e");
|
||||
F(" 1.1e2");
|
||||
F("1.0e3");
|
||||
F("5e4");
|
||||
F("5.0e2");
|
||||
F("3e2");
|
||||
F("1e");
|
||||
F("0.5e");
|
||||
F("1e10");
|
||||
|
||||
CR("1e2 ", 1000000000, " ");
|
||||
CR("1.1e2 ", 1100000000, " ");
|
||||
CR("1.1e2x", 1100000000, "x");
|
||||
CR("1.1e2:", 1100000000, ":");
|
||||
}
|
||||
|
||||
#undef C
|
||||
#undef CR
|
||||
#undef F
|
||||
|
||||
#define CW(v, s) buffer.clear(); \
|
||||
osmium::detail::append_location_coordinate_to_string(std::back_inserter(buffer), v); \
|
||||
CHECK(buffer == s); \
|
||||
buffer.clear(); \
|
||||
osmium::detail::append_location_coordinate_to_string(std::back_inserter(buffer), -v); \
|
||||
CHECK(buffer == "-" s);
|
||||
|
||||
TEST_CASE("Writing coordinates into string") {
|
||||
std::string buffer;
|
||||
|
||||
osmium::detail::append_location_coordinate_to_string(std::back_inserter(buffer), 0);
|
||||
CHECK(buffer == "0");
|
||||
|
||||
CW( 10000000, "1");
|
||||
CW( 90000000, "9");
|
||||
CW( 100000000, "10");
|
||||
CW(1000000000, "100");
|
||||
CW(2000000000, "200");
|
||||
|
||||
CW( 1000000, "0.1");
|
||||
CW( 100000, "0.01");
|
||||
CW( 10000, "0.001");
|
||||
CW( 1000, "0.0001");
|
||||
CW( 100, "0.00001");
|
||||
CW( 10, "0.000001");
|
||||
CW( 1, "0.0000001");
|
||||
|
||||
CW( 1230000, "0.123");
|
||||
CW( 9999999, "0.9999999");
|
||||
CW( 40101010, "4.010101");
|
||||
CW( 494561234, "49.4561234");
|
||||
CW(1799999999, "179.9999999");
|
||||
}
|
||||
|
||||
#undef CW
|
||||
|
||||
TEST_CASE("set lon/lat from string") {
|
||||
osmium::Location loc;
|
||||
loc.set_lon("1.2");
|
||||
loc.set_lat("3.4");
|
||||
REQUIRE(loc.lon() == Approx(1.2));
|
||||
REQUIRE(loc.lat() == Approx(3.4));
|
||||
}
|
||||
|
||||
TEST_CASE("set lon/lat from string with trailing characters") {
|
||||
osmium::Location loc;
|
||||
REQUIRE_THROWS_AS({
|
||||
loc.set_lon("1.2x");
|
||||
}, osmium::invalid_location);
|
||||
REQUIRE_THROWS_AS({
|
||||
loc.set_lat("3.4e1 ");
|
||||
}, osmium::invalid_location);
|
||||
}
|
||||
|
||||
TEST_CASE("set lon/lat from string with trailing characters using partial") {
|
||||
osmium::Location loc;
|
||||
const char* x = "1.2x";
|
||||
const char* y = "3.4 ";
|
||||
loc.set_lon_partial(&x);
|
||||
loc.set_lat_partial(&y);
|
||||
REQUIRE(loc.lon() == Approx(1.2));
|
||||
REQUIRE(loc.lat() == Approx(3.4));
|
||||
REQUIRE(*x == 'x');
|
||||
REQUIRE(*y == ' ');
|
||||
}
|
||||
|
||||
|
||||
+55
-13
@@ -9,7 +9,7 @@
|
||||
using namespace osmium::builder::attr;
|
||||
|
||||
TEST_CASE("Build node") {
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
osmium::memory::Buffer buffer{10000};
|
||||
|
||||
osmium::builder::add_node(buffer,
|
||||
_id(17),
|
||||
@@ -36,7 +36,7 @@ TEST_CASE("Build node") {
|
||||
REQUIRE(false == node.deleted());
|
||||
REQUIRE(333 == node.changeset());
|
||||
REQUIRE(21 == node.uid());
|
||||
REQUIRE(std::string("foo") == node.user());
|
||||
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());
|
||||
@@ -51,7 +51,7 @@ TEST_CASE("Build node") {
|
||||
}
|
||||
|
||||
TEST_CASE("default values for node attributes") {
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
osmium::memory::Buffer buffer{10000};
|
||||
|
||||
osmium::builder::add_node(buffer, _id(0));
|
||||
|
||||
@@ -62,22 +62,23 @@ TEST_CASE("default values for node attributes") {
|
||||
REQUIRE(true == node.visible());
|
||||
REQUIRE(0 == node.changeset());
|
||||
REQUIRE(0 == node.uid());
|
||||
REQUIRE(std::string("") == node.user());
|
||||
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::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_visible("true")
|
||||
.set_changeset("333")
|
||||
.set_timestamp("2014-03-17T16:23:08Z")
|
||||
.set_uid("21");
|
||||
|
||||
REQUIRE(-17l == node.id());
|
||||
@@ -85,11 +86,52 @@ TEST_CASE("set node attributes from strings") {
|
||||
REQUIRE(3 == node.version());
|
||||
REQUIRE(true == node.visible());
|
||||
REQUIRE(333 == node.changeset());
|
||||
REQUIRE(std::string{"2014-03-17T16:23:08Z"} == node.timestamp().to_iso());
|
||||
REQUIRE(21 == node.uid());
|
||||
}
|
||||
|
||||
TEST_CASE("set node attributes from strings using set_attribute()") {
|
||||
osmium::memory::Buffer buffer{10000};
|
||||
|
||||
osmium::builder::add_node(buffer, _id(0));
|
||||
|
||||
osmium::Node& node = buffer.get<osmium::Node>(0);
|
||||
node.set_attribute("id", "-17")
|
||||
.set_attribute("version", "3")
|
||||
.set_attribute("visible", "true")
|
||||
.set_attribute("changeset", "333")
|
||||
.set_attribute("timestamp", "2014-03-17T16:23:08Z")
|
||||
.set_attribute("uid", "21");
|
||||
|
||||
REQUIRE(-17l == node.id());
|
||||
REQUIRE(17ul == node.positive_id());
|
||||
REQUIRE(3 == node.version());
|
||||
REQUIRE(true == node.visible());
|
||||
REQUIRE(333 == node.changeset());
|
||||
REQUIRE(std::string{"2014-03-17T16:23:08Z"} == node.timestamp().to_iso());
|
||||
REQUIRE(21 == node.uid());
|
||||
}
|
||||
|
||||
TEST_CASE("Setting attributes from bad data on strings should fail") {
|
||||
osmium::memory::Buffer buffer{10000};
|
||||
|
||||
osmium::builder::add_node(buffer, _id(0));
|
||||
|
||||
osmium::Node& node = buffer.get<osmium::Node>(0);
|
||||
REQUIRE_THROWS(node.set_id("bar"));
|
||||
REQUIRE_THROWS(node.set_id("123x"));
|
||||
REQUIRE_THROWS(node.set_version("123x"));
|
||||
REQUIRE_THROWS(node.set_visible("foo"));
|
||||
REQUIRE_THROWS(node.set_changeset("123x"));
|
||||
REQUIRE_THROWS(node.set_changeset("NULL"));
|
||||
REQUIRE_THROWS(node.set_timestamp("2014-03-17T16:23:08Zx"));
|
||||
REQUIRE_THROWS(node.set_timestamp("2014-03-17T16:23:99Z"));
|
||||
REQUIRE_THROWS(node.set_uid("123x"));
|
||||
REQUIRE_THROWS(node.set_uid("anonymous"));
|
||||
}
|
||||
|
||||
TEST_CASE("set large id") {
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
osmium::memory::Buffer buffer{10000};
|
||||
|
||||
int64_t id = 3000000000l;
|
||||
osmium::builder::add_node(buffer, _id(id));
|
||||
@@ -104,7 +146,7 @@ TEST_CASE("set large id") {
|
||||
}
|
||||
|
||||
TEST_CASE("set tags on node") {
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
osmium::memory::Buffer buffer{10000};
|
||||
|
||||
osmium::builder::add_node(buffer,
|
||||
_user("foo"),
|
||||
@@ -114,11 +156,11 @@ TEST_CASE("set tags on node") {
|
||||
|
||||
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{"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"));
|
||||
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"));
|
||||
}
|
||||
|
||||
|
||||
+59
-55
@@ -1,76 +1,80 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#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;
|
||||
|
||||
using namespace osmium::builder::attr;
|
||||
TEST_CASE("Node comparisons") {
|
||||
|
||||
SECTION("order") {
|
||||
osmium::memory::Buffer buffer(10 * 1000);
|
||||
osmium::memory::Buffer buffer(10 * 1000);
|
||||
std::vector<std::reference_wrapper<osmium::Node>> nodes;
|
||||
|
||||
osmium::builder::add_node(buffer, _id(10), _version(1));
|
||||
osmium::builder::add_node(buffer, _id(15), _version(2));
|
||||
SECTION("nodes are ordered by id, version, and timestamp") {
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 0), _version(2), _timestamp("2016-01-01T00:00:00Z"))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 1), _version(2), _timestamp("2016-01-01T00:00:00Z"))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 10), _version(2), _timestamp("2016-01-01T00:01:00Z"))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 10), _version(3), _timestamp("2016-01-01T00:00:00Z"))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 12), _version(2), _timestamp("2016-01-01T00:00:00Z"))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 12), _version(2), _timestamp("2016-01-01T00:01:00Z"))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 15), _version(1), _timestamp("2016-01-01T00:00:00Z"))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id(10000000000ll), _version(2), _timestamp("2016-01-01T00:00:00Z"))));
|
||||
|
||||
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);
|
||||
REQUIRE(std::is_sorted(nodes.cbegin(), nodes.cend()));
|
||||
}
|
||||
|
||||
SECTION("order_types") {
|
||||
osmium::memory::Buffer buffer(10 * 1000);
|
||||
SECTION("equal nodes are not different") {
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id(1), _version(2), _timestamp("2016-01-01T00:00:00Z"))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id(1), _version(2), _timestamp("2016-01-01T00:00:00Z"))));
|
||||
|
||||
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));
|
||||
REQUIRE(nodes[0] == nodes[1]);
|
||||
REQUIRE_FALSE(nodes[0] < nodes[1]);
|
||||
REQUIRE_FALSE(nodes[0] > nodes[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));
|
||||
SECTION("IDs are ordered by absolute value") {
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 0))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 1))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( -1))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 10))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id(-10))));
|
||||
|
||||
REQUIRE(node1 < node2);
|
||||
REQUIRE(node2 < way);
|
||||
REQUIRE_FALSE(node2 > way);
|
||||
REQUIRE(way < relation);
|
||||
REQUIRE(node1 < relation);
|
||||
REQUIRE(std::is_sorted(nodes.cbegin(), nodes.cend()));
|
||||
}
|
||||
|
||||
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));
|
||||
SECTION("reverse version ordering") {
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 0), _version(2), _timestamp("2016-01-01T00:00:00Z"))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 1), _version(2), _timestamp("2016-01-01T00:00:00Z"))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 10), _version(3), _timestamp("2016-01-01T00:00:00Z"))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 10), _version(2), _timestamp("2016-01-01T00:01:00Z"))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 12), _version(2), _timestamp("2016-01-01T00:01:00Z"))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 12), _version(2), _timestamp("2016-01-01T00:00:00Z"))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 15), _version(1), _timestamp("2016-01-01T00:00:00Z"))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id(10000000000ll), _version(2), _timestamp("2016-01-01T00:00:00Z"))));
|
||||
|
||||
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));
|
||||
REQUIRE(std::is_sorted(nodes.cbegin(), nodes.cend(), osmium::object_order_type_id_reverse_version{}));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("Object comparisons") {
|
||||
|
||||
osmium::memory::Buffer buffer(10 * 1000);
|
||||
std::vector<std::reference_wrapper<osmium::OSMObject>> objects;
|
||||
|
||||
SECTION("types are ordered nodes, then ways, then relations") {
|
||||
objects.emplace_back(buffer.get<osmium::Node>( osmium::builder::add_node( buffer, _id(3))));
|
||||
objects.emplace_back(buffer.get<osmium::Way>( osmium::builder::add_way( buffer, _id(2))));
|
||||
objects.emplace_back(buffer.get<osmium::Relation>(osmium::builder::add_relation(buffer, _id(1))));
|
||||
|
||||
REQUIRE(std::is_sorted(objects.cbegin(), objects.cend()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -75,3 +75,47 @@ TEST_CASE("Timestamp") {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("Valid timestamps") {
|
||||
|
||||
std::vector<std::string> test_cases = {
|
||||
"1970-01-01T00:00:01Z",
|
||||
"2000-01-01T00:00:00Z",
|
||||
"2006-12-31T23:59:59Z",
|
||||
"2030-12-31T23:59:59Z",
|
||||
"2016-02-28T23:59:59Z",
|
||||
"2016-03-31T23:59:59Z"
|
||||
};
|
||||
|
||||
for (const auto& tc : test_cases) {
|
||||
osmium::Timestamp t{tc};
|
||||
REQUIRE(tc == t.to_iso());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("Invalid timestamps") {
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp{""}, std::invalid_argument);
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp{"x"}, std::invalid_argument);
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp{"xxxxxxxxxxxxxxxxxxxx"}, std::invalid_argument);
|
||||
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp{"2000-01-01x00:00:00Z"}, std::invalid_argument);
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp{"2000-01-01T00:00:00x"}, std::invalid_argument);
|
||||
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp{"2000x01-01T00:00:00Z"}, std::invalid_argument);
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp{"2000-01x01T00:00:00Z"}, std::invalid_argument);
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp{"2000-01-01T00x00:00Z"}, std::invalid_argument);
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp{"2000-01-01T00:00x00Z"}, std::invalid_argument);
|
||||
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp{"0000-00-01T00:00:00Z"}, std::invalid_argument);
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp{"2000-00-01T00:00:00Z"}, std::invalid_argument);
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp{"2000-01-00T00:00:00Z"}, std::invalid_argument);
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp{"2000-01-01T24:00:00Z"}, std::invalid_argument);
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp{"2000-01-01T00:60:00Z"}, std::invalid_argument);
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp{"2000-01-01T00:00:61Z"}, std::invalid_argument);
|
||||
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp{"2000-01-32T00:00:00Z"}, std::invalid_argument);
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp{"2000-02-30T00:00:00Z"}, std::invalid_argument);
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp{"2000-03-32T00:00:00Z"}, std::invalid_argument);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,9 +31,17 @@ TEST_CASE("set type and ID from string") {
|
||||
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);
|
||||
auto d3 = osmium::string_to_object_id("3", osmium::osm_entity_bits::nwr);
|
||||
REQUIRE(d3.first == osmium::item_type::undefined);
|
||||
REQUIRE(d3.second == 3);
|
||||
|
||||
auto u3 = osmium::string_to_object_id("3", osmium::osm_entity_bits::nwr, osmium::item_type::undefined);
|
||||
REQUIRE(u3.first == osmium::item_type::undefined);
|
||||
REQUIRE(u3.second == 3);
|
||||
|
||||
auto n3 = osmium::string_to_object_id("3", osmium::osm_entity_bits::nwr, osmium::item_type::node);
|
||||
REQUIRE(n3.first == osmium::item_type::node);
|
||||
REQUIRE(n3.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);
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ TEST_CASE("Build way") {
|
||||
|
||||
osmium::CRC<boost::crc_32_type> crc32;
|
||||
crc32.update(way);
|
||||
REQUIRE(crc32().checksum() == 0x7676d0c2);
|
||||
REQUIRE(crc32().checksum() == 0x65f6ba91);
|
||||
}
|
||||
|
||||
TEST_CASE("build closed way") {
|
||||
|
||||
Reference in New Issue
Block a user