Merge commit '788bc67faa7738cf7c6b2a192ecf3e3567d1c20e' into develop

This commit is contained in:
Patrick Niklaus
2015-08-28 12:42:03 +02:00
150 changed files with 12325 additions and 4321 deletions
+15 -2
View File
@@ -15,6 +15,11 @@ add_library(testlib STATIC test_main.cpp)
set(ALL_TESTS "")
# Otherwise GCC throws a lot of warnings for REQUIRE(...) from Catch v.1.2.1
if(CMAKE_COMPILER_IS_GNUCXX)
add_definitions(-Wno-parentheses)
endif()
#-----------------------------------------------------------------------------
#
@@ -90,6 +95,7 @@ add_unit_test(area test_node_ref_segment)
add_unit_test(basic test_box)
add_unit_test(basic test_changeset)
add_unit_test(basic test_crc)
add_unit_test(basic test_entity_bits)
add_unit_test(basic test_location)
add_unit_test(basic test_node)
@@ -97,6 +103,7 @@ add_unit_test(basic test_node_ref)
add_unit_test(basic test_object_comparisons)
add_unit_test(basic test_relation)
add_unit_test(basic test_timestamp)
add_unit_test(basic test_types_from_string)
add_unit_test(basic test_way)
add_unit_test(buffer test_buffer_node)
@@ -111,23 +118,24 @@ add_unit_test(geom test_factory_with_projection
ENABLE_IF ${GEOS_AND_PROJ_FOUND}
LIBS ${GEOS_LIBRARY} ${PROJ_LIBRARY})
add_unit_test(geom test_exception)
add_unit_test(geom test_geojson)
add_unit_test(geom test_geos ENABLE_IF ${GEOS_FOUND} LIBS ${GEOS_LIBRARY})
add_unit_test(geom test_geos_wkb ENABLE_IF ${GEOS_FOUND} LIBS ${GEOS_LIBRARY})
add_unit_test(geom test_mercator)
add_unit_test(geom test_ogr ENABLE_IF ${GDAL_FOUND} LIBS ${GDAL_LIBRARY})
add_unit_test(geom test_projection ENABLE_IF ${PROJ_FOUND} LIBS ${PROJ_LIBRARY})
add_unit_test(geom test_tile)
add_unit_test(geom test_wkb)
add_unit_test(geom test_wkt)
add_unit_test(index test_id_to_location ENABLE_IF ${SPARSEHASH_FOUND})
add_unit_test(index test_typed_mmap)
add_unit_test(index test_typed_mmap_grow LABELS "fails_on_windows")
add_unit_test(io test_bzip2 ENABLE_IF ${BZIP2_FOUND} LIBS ${BZIP2_LIBRARIES})
add_unit_test(io test_file_formats)
add_unit_test(io test_reader LIBS "${OSMIUM_XML_LIBRARIES}")
add_unit_test(io test_output_iterator ENABLE_IF ${Threads_FOUND} LIBS ${CMAKE_THREAD_LIBS_INIT})
add_unit_test(io test_string_table)
add_unit_test(tags test_filter)
add_unit_test(tags test_operators)
@@ -136,7 +144,12 @@ add_unit_test(tags test_tag_list)
add_unit_test(thread test_pool ENABLE_IF ${Threads_FOUND} LIBS ${CMAKE_THREAD_LIBS_INIT})
add_unit_test(util test_cast_with_assert)
add_unit_test(util test_data_file)
add_unit_test(util test_delta)
add_unit_test(util test_double)
add_unit_test(util test_file)
add_unit_test(util test_memory_mapping)
add_unit_test(util test_minmax)
add_unit_test(util test_options)
add_unit_test(util test_string)
@@ -6,8 +6,6 @@
#include "testdata-testcases.hpp"
#include <osmpbf/osmpbf.h>
std::string dirname;
int main(int argc, char* argv[]) {
+107 -13
View File
@@ -12,6 +12,10 @@
#include <osmium/io/gzip_compression.hpp>
#include <osmium/visitor.hpp>
std::string S_(const char* s) {
return std::string(s);
}
std::string filename(const char* test_id, const char* suffix = "osm") {
const char* testdir = getenv("TESTDIR");
if (!testdir) {
@@ -286,12 +290,13 @@ TEST_CASE("Reading OSM XML 121") {
}
SECTION("Using Reader") {
REQUIRE_THROWS_AS({
// can throw osmium::gzip_error or osmium::xml_error
REQUIRE_THROWS({
osmium::io::Reader reader(filename("121-truncated_gzip_file", "osm.gz"));
osmium::io::Header header = reader.header();
osmium::memory::Buffer buffer = reader.read();
reader.close();
}, osmium::gzip_error);
});
}
}
@@ -337,25 +342,25 @@ TEST_CASE("Reading OSM XML 140") {
auto len = atoi(t["unicode_utf8_length"]);
REQUIRE(len == strlen(uc));
REQUIRE(!strcmp(uc, t["unicode_xml"]));
REQUIRE(S_(uc) == t["unicode_xml"]);
// workaround for missing support for u8 string literals on Windows
#if !defined(_MSC_VER)
switch (count) {
case 1:
REQUIRE(!strcmp(uc, u8"a"));
REQUIRE(S_(uc) == u8"a");
break;
case 2:
REQUIRE(!strcmp(uc, u8"\u00e4"));
REQUIRE(S_(uc) == u8"\u00e4");
break;
case 3:
REQUIRE(!strcmp(uc, u8"\u30dc"));
REQUIRE(S_(uc) == u8"\u30dc");
break;
case 4:
REQUIRE(!strcmp(uc, u8"\U0001d11e"));
REQUIRE(S_(uc) == u8"\U0001d11e");
break;
case 5:
REQUIRE(!strcmp(uc, u8"\U0001f6eb"));
REQUIRE(S_(uc) == u8"\U0001f6eb");
break;
default:
REQUIRE(false); // should not be here
@@ -382,11 +387,100 @@ TEST_CASE("Reading OSM XML 141") {
const osmium::Node& node = buffer.get<osmium::Node>(0);
const osmium::TagList& tags = node.tags();
REQUIRE(!strcmp(tags["less-than"], "<"));
REQUIRE(!strcmp(tags["greater-than"], ">"));
REQUIRE(!strcmp(tags["apostrophe"], "'"));
REQUIRE(!strcmp(tags["ampersand"], "&"));
REQUIRE(!strcmp(tags["quote"], "\""));
REQUIRE(S_(tags["less-than"]) == "<");
REQUIRE(S_(tags["greater-than"]) == ">");
REQUIRE(S_(tags["apostrophe"]) == "'");
REQUIRE(S_(tags["ampersand"]) == "&");
REQUIRE(S_(tags["quote"]) == "\"");
}
}
// =============================================
TEST_CASE("Reading OSM XML 142") {
SECTION("Using Reader to read nodes") {
osmium::io::Reader reader(filename("142-whitespace"));
osmium::memory::Buffer buffer = reader.read();
reader.close();
int count = 0;
for (auto it = buffer.begin<osmium::Node>(); it != buffer.end<osmium::Node>(); ++it) {
++count;
REQUIRE(it->id() == count);
REQUIRE(it->tags().size() == 1);
const osmium::Tag& tag = *(it->tags().begin());
switch (count) {
case 1:
REQUIRE(S_(it->user()) == "user name");
REQUIRE(S_(tag.key()) == "key with space");
REQUIRE(S_(tag.value()) == "value with space");
break;
case 2:
REQUIRE(S_(it->user()) == "line\nfeed");
REQUIRE(S_(tag.key()) == "key with\nlinefeed");
REQUIRE(S_(tag.value()) == "value with\nlinefeed");
break;
case 3:
REQUIRE(S_(it->user()) == "carriage\rreturn");
REQUIRE(S_(tag.key()) == "key with\rcarriage\rreturn");
REQUIRE(S_(tag.value()) == "value with\rcarriage\rreturn");
break;
case 4:
REQUIRE(S_(it->user()) == "tab\tulator");
REQUIRE(S_(tag.key()) == "key with\ttab");
REQUIRE(S_(tag.value()) == "value with\ttab");
break;
case 5:
REQUIRE(S_(it->user()) == "unencoded linefeed");
REQUIRE(S_(tag.key()) == "key with unencoded linefeed");
REQUIRE(S_(tag.value()) == "value with unencoded linefeed");
break;
default:
REQUIRE(false); // should not be here
}
}
REQUIRE(count == 5);
}
SECTION("Using Reader to read relation") {
osmium::io::Reader reader(filename("142-whitespace"));
osmium::memory::Buffer buffer = reader.read();
reader.close();
auto it = buffer.begin<osmium::Relation>();
REQUIRE(it != buffer.end<osmium::Relation>());
REQUIRE(it->id() == 21);
const auto& members = it->members();
REQUIRE(members.size() == 5);
int count = 0;
for (const auto& member : members) {
++count;
switch (count) {
case 1:
REQUIRE(S_(member.role()) == "role with whitespace");
break;
case 2:
REQUIRE(S_(member.role()) == "role with\nlinefeed");
break;
case 3:
REQUIRE(S_(member.role()) == "role with\rcarriage\rreturn");
break;
case 4:
REQUIRE(S_(member.role()) == "role with\ttab");
break;
case 5:
REQUIRE(S_(member.role()) == "role with unencoded linefeed");
break;
default:
REQUIRE(false); // should not be here
}
}
REQUIRE(count == 5);
}
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+19 -13
View File
@@ -9,7 +9,7 @@
inline void add_tags(osmium::memory::Buffer& buffer, osmium::builder::Builder& builder, const std::vector<std::pair<const char*, const char*>>& tags) {
osmium::builder::TagListBuilder tl_builder(buffer, &builder);
for (auto& tag : tags) {
for (const auto& tag : tags) {
tl_builder.add_tag(tag.first, tag.second);
}
}
@@ -26,9 +26,11 @@ inline osmium::Way& buffer_add_way(osmium::memory::Buffer& buffer, const char* u
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);
{
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();
@@ -38,9 +40,11 @@ inline osmium::Way& buffer_add_way(osmium::memory::Buffer& buffer, const char* u
osmium::builder::WayBuilder builder(buffer);
builder.add_user(user);
add_tags(buffer, builder, tags);
osmium::builder::WayNodeListBuilder wnl_builder(buffer, &builder);
for (auto& p : nodes) {
wnl_builder.add_node_ref(p.first, p.second);
{
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();
@@ -53,9 +57,11 @@ inline osmium::Relation& buffer_add_relation(
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));
{
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();
@@ -69,15 +75,15 @@ inline osmium::Area& buffer_add_area(osmium::memory::Buffer& buffer, const char*
builder.add_user(user);
add_tags(buffer, builder, tags);
for (auto& ring : rings) {
for (const auto& ring : rings) {
if (ring.first) {
osmium::builder::OuterRingBuilder ring_builder(buffer, &builder);
for (auto& p : ring.second) {
for (const auto& p : ring.second) {
ring_builder.add_node_ref(p.first, p.second);
}
} else {
osmium::builder::InnerRingBuilder ring_builder(buffer, &builder);
for (auto& p : ring.second) {
for (const auto& p : ring.second) {
ring_builder.add_node_ref(p.first, p.second);
}
}
+7
View File
@@ -2,7 +2,10 @@
#include <sstream>
#include <boost/crc.hpp>
#include <osmium/osm/box.hpp>
#include <osmium/osm/crc.hpp>
#include <osmium/geom/relations.hpp>
TEST_CASE("Box") {
@@ -48,6 +51,10 @@ TEST_CASE("Box") {
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") {
+9 -3
View File
@@ -1,12 +1,16 @@
#include "catch.hpp"
#include <boost/crc.hpp>
#include <osmium/osm/changeset.hpp>
#include <osmium/osm/crc.hpp>
#include "helper.hpp"
TEST_CASE("Basic_Changeset") {
TEST_CASE("Basic Changeset") {
osmium::CRC<boost::crc_32_type> crc32;
SECTION("changeset_builder") {
osmium::memory::Buffer buffer(10 * 1000);
osmium::Changeset& cs1 = buffer_add_changeset(buffer,
@@ -28,6 +32,9 @@ SECTION("changeset_builder") {
REQUIRE(1 == cs1.tags().size());
REQUIRE(std::string("user") == cs1.user());
crc32.update(cs1);
REQUIRE(crc32().checksum() == 0xf44aff25);
osmium::Changeset& cs2 = buffer_add_changeset(buffer,
"user",
{{"comment", "foo"}, {"foo", "bar"}});
@@ -52,6 +59,5 @@ SECTION("changeset_builder") {
REQUIRE(cs1 <= cs2);
REQUIRE(false == (cs1 > cs2));
REQUIRE(false == (cs1 >= cs2));
}
}
+49
View File
@@ -0,0 +1,49 @@
#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("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);
}
}
+8
View File
@@ -1,11 +1,16 @@
#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);
@@ -36,6 +41,9 @@ SECTION("node_builder") {
REQUIRE(osmium::Location(3.5, 4.7) == node.location());
REQUIRE(2 == node.tags().size());
crc32.update(node);
REQUIRE(crc32().checksum() == 0xc696802f);
node.set_visible(false);
REQUIRE(false == node.visible());
REQUIRE(true == node.deleted());
+8 -3
View File
@@ -1,12 +1,16 @@
#include "catch.hpp"
#include <boost/crc.hpp>
#include <osmium/osm/crc.hpp>
#include <osmium/osm/relation.hpp>
#include "helper.hpp"
TEST_CASE("Basic_Relation") {
TEST_CASE("Build relation") {
osmium::CRC<boost::crc_32_type> crc32;
SECTION("relation_builder") {
osmium::memory::Buffer buffer(10000);
osmium::Relation& relation = buffer_add_relation(buffer,
@@ -55,6 +59,7 @@ SECTION("relation_builder") {
}
++n;
}
}
crc32.update(relation);
REQUIRE(crc32().checksum() == 0xebcd836d);
}
+4
View File
@@ -29,6 +29,10 @@ TEST_CASE("Timestamp") {
REQUIRE("2000-01-01T00:00:00Z" == t.to_iso());
}
SECTION("throws if initialized from bad string") {
REQUIRE_THROWS_AS(osmium::Timestamp("x"), std::invalid_argument);
}
SECTION("can be implicitly cast to time_t") {
osmium::Timestamp t(4242);
time_t x = t;
@@ -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);
}
+9 -1
View File
@@ -1,11 +1,16 @@
#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("Basic_Way") {
TEST_CASE("Build way") {
osmium::CRC<boost::crc_32_type> crc32;
SECTION("way_builder") {
osmium::memory::Buffer buffer(10000);
@@ -38,6 +43,9 @@ SECTION("way_builder") {
REQUIRE(3 == way.nodes()[1].ref());
REQUIRE(2 == way.nodes()[2].ref());
REQUIRE(! way.is_closed());
crc32.update(way);
REQUIRE(crc32().checksum() == 0x20fe7a30);
}
SECTION("closed_way") {
+7 -7
View File
@@ -108,7 +108,7 @@ TEST_CASE("Purge data from buffer") {
node_builder.object().set_removed(true);
}
buffer.commit();
size_t size2 = buffer.committed() - size1;
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 2);
CallbackClass callback;
@@ -127,20 +127,20 @@ TEST_CASE("Purge data from buffer") {
node_builder.add_user("testuser_longer_name");
}
buffer.commit();
size_t size1 = buffer.committed();
{
osmium::builder::NodeBuilder node_builder(buffer);
node_builder.add_user("testuser");
node_builder.object().set_removed(true);
}
buffer.commit();
size_t size2 = buffer.committed() - size1;
{
osmium::builder::NodeBuilder node_builder(buffer);
node_builder.add_user("sn");
}
buffer.commit();
size_t size3 = buffer.committed() - (size1 + size2);
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 3);
CallbackClass callback;
@@ -159,21 +159,21 @@ TEST_CASE("Purge data from buffer") {
node_builder.object().set_removed(true);
}
buffer.commit();
size_t size1 = buffer.committed();
{
osmium::builder::NodeBuilder node_builder(buffer);
node_builder.add_user("testuser");
node_builder.object().set_removed(true);
}
buffer.commit();
size_t size2 = buffer.committed() - size1;
{
osmium::builder::NodeBuilder node_builder(buffer);
node_builder.add_user("sn");
node_builder.object().set_removed(true);
}
buffer.commit();
size_t size3 = buffer.committed() - (size1 + size2);
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 3);
CallbackClass callback;
+16
View File
@@ -0,0 +1,16 @@
#include "catch.hpp"
#include <string>
#include <osmium/geom/factory.hpp>
TEST_CASE("Geometry exception") {
SECTION("geometry_error") {
osmium::geometry_error e("some error message", "node", 17);
REQUIRE(e.id() == 17);
REQUIRE(std::string(e.what()) == "some error message (node_id=17)");
}
}
+21 -14
View File
@@ -5,9 +5,7 @@
#include "../basic/helper.hpp"
TEST_CASE("GEOS_Geometry") {
SECTION("point") {
TEST_CASE("GEOS geometry factory - create point") {
osmium::geom::GEOSFactory<> factory;
std::unique_ptr<geos::geom::Point> point {factory.create_point(osmium::Location(3.2, 4.2))};
@@ -16,7 +14,7 @@ SECTION("point") {
REQUIRE(-1 == point->getSRID());
}
SECTION("non_default_srid") {
TEST_CASE("GEOS geometry factory - create point with non-default srid") {
osmium::geom::GEOSFactory<> factory(4326);
std::unique_ptr<geos::geom::Point> point {factory.create_point(osmium::Location(3.2, 4.2))};
@@ -25,13 +23,23 @@ SECTION("non_default_srid") {
REQUIRE(4326 == point->getSRID());
}
SECTION("empty_point") {
TEST_CASE("GEOS geometry factory - create point with externally created GEOS factory") {
geos::geom::GeometryFactory geos_factory;
osmium::geom::GEOSFactory<> factory(geos_factory);
std::unique_ptr<geos::geom::Point> point {factory.create_point(osmium::Location(3.2, 4.2))};
REQUIRE(3.2 == point->getX());
REQUIRE(4.2 == point->getY());
REQUIRE(0 == point->getSRID());
}
TEST_CASE("GEOS geometry factory - can not create from invalid location") {
osmium::geom::GEOSFactory<> factory;
REQUIRE_THROWS_AS(factory.create_point(osmium::Location()), osmium::invalid_location);
}
SECTION("linestring") {
TEST_CASE("GEOS geometry factory - create linestring") {
osmium::geom::GEOSFactory<> factory;
osmium::memory::Buffer buffer(10000);
@@ -42,7 +50,7 @@ SECTION("linestring") {
{2, {3.6, 4.9}}
});
{
SECTION("from way node list") {
std::unique_ptr<geos::geom::LineString> linestring {factory.create_linestring(wnl)};
REQUIRE(3 == linestring->getNumPoints());
@@ -52,7 +60,7 @@ SECTION("linestring") {
REQUIRE(3.6 == p2->getX());
}
{
SECTION("without duplicates and backwards") {
std::unique_ptr<geos::geom::LineString> linestring {factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward)};
REQUIRE(3 == linestring->getNumPoints());
std::unique_ptr<geos::geom::Point> p0 = std::unique_ptr<geos::geom::Point>(linestring->getPointN(0));
@@ -61,14 +69,14 @@ SECTION("linestring") {
REQUIRE(3.2 == p2->getX());
}
{
SECTION("with duplicates") {
std::unique_ptr<geos::geom::LineString> linestring {factory.create_linestring(wnl, osmium::geom::use_nodes::all)};
REQUIRE(4 == linestring->getNumPoints());
std::unique_ptr<geos::geom::Point> p0 = std::unique_ptr<geos::geom::Point>(linestring->getPointN(0));
REQUIRE(3.2 == p0->getX());
}
{
SECTION("with duplicates and backwards") {
std::unique_ptr<geos::geom::LineString> linestring {factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)};
REQUIRE(4 == linestring->getNumPoints());
std::unique_ptr<geos::geom::Point> p0 = std::unique_ptr<geos::geom::Point>(linestring->getPointN(0));
@@ -76,7 +84,7 @@ SECTION("linestring") {
}
}
SECTION("area_1outer_0inner") {
TEST_CASE("GEOS geometry factory - create area with one outer and no inner rings") {
osmium::geom::GEOSFactory<> factory;
osmium::memory::Buffer buffer(10000);
@@ -105,7 +113,7 @@ SECTION("area_1outer_0inner") {
REQUIRE(3.5 == l0e_p0->getX());
}
SECTION("area_1outer_1inner") {
TEST_CASE("GEOS geometry factory - create area with one outer and one inner ring") {
osmium::geom::GEOSFactory<> factory;
osmium::memory::Buffer buffer(10000);
@@ -142,7 +150,7 @@ SECTION("area_1outer_1inner") {
REQUIRE(5 == l0i0->getNumPoints());
}
SECTION("area_2outer_2inner") {
TEST_CASE("GEOS geometry factory - create area with two outer and two inner rings") {
osmium::geom::GEOSFactory<> factory;
osmium::memory::Buffer buffer(10000);
@@ -195,4 +203,3 @@ SECTION("area_2outer_2inner") {
REQUIRE(5 == l1e->getNumPoints());
}
}
+18
View File
@@ -1,5 +1,7 @@
#include "catch.hpp"
#include <random>
#include <osmium/geom/factory.hpp>
#include <osmium/geom/mercator_projection.hpp>
#include <osmium/geom/projection.hpp>
@@ -128,4 +130,20 @@ SECTION("compare_mercators") {
}
}
SECTION("compare_mercators") {
osmium::geom::MercatorProjection projection_merc;
osmium::geom::Projection projection_3857(3857);
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_real_distribution<> dis_x(-180.0, 180.0);
std::uniform_real_distribution<> dis_y(-90.0, 90.0);
for (int n = 0; n < 100000; ++n) {
const osmium::Location loc(dis_x(gen), dis_y(gen));
REQUIRE(projection_merc(loc).x == Approx(projection_3857(loc).x).epsilon(0.1));
REQUIRE(projection_merc(loc).y == Approx(projection_3857(loc).y).epsilon(0.1));
}
}
}
+93
View File
@@ -0,0 +1,93 @@
#include "catch.hpp"
#include <sstream>
#include <osmium/geom/tile.hpp>
#include "helper.hpp"
#include "test_tile_data.hpp"
TEST_CASE("Tile") {
SECTION("x0.0 y0.0 zoom 0") {
osmium::Location l(0.0, 0.0);
osmium::geom::Tile t(0, l);
REQUIRE(t.x == 0);
REQUIRE(t.y == 0);
REQUIRE(t.z == 0);
}
SECTION("x180.0 y90.0 zoom 0") {
osmium::Location l(180.0, 90.0);
osmium::geom::Tile t(0, l);
REQUIRE(t.x == 0);
REQUIRE(t.y == 0);
REQUIRE(t.z == 0);
}
SECTION("x180.0 y90.0 zoom 4") {
osmium::Location l(180.0, 90.0);
osmium::geom::Tile t(4, l);
REQUIRE(t.x == (1 << 4) - 1);
REQUIRE(t.y == 0);
REQUIRE(t.z == 4);
}
SECTION("x0.0 y0.0 zoom 4") {
osmium::Location l(0.0, 0.0);
osmium::geom::Tile t(4, l);
auto n = 1 << (4-1);
REQUIRE(t.x == n);
REQUIRE(t.y == n);
REQUIRE(t.z == 4);
}
SECTION("equality") {
osmium::geom::Tile a(4, 3, 4);
osmium::geom::Tile b(4, 3, 4);
osmium::geom::Tile c(4, 4, 3);
REQUIRE(a == b);
REQUIRE(a != c);
REQUIRE(b != c);
}
SECTION("order") {
osmium::geom::Tile a(2, 3, 4);
osmium::geom::Tile b(4, 3, 4);
osmium::geom::Tile c(4, 4, 3);
osmium::geom::Tile d(4, 4, 2);
REQUIRE(a < b);
REQUIRE(a < c);
REQUIRE(b < c);
REQUIRE(d < c);
}
SECTION("tilelist") {
std::istringstream input_data(s);
while (input_data) {
double lon, lat;
uint32_t x, y, zoom;
input_data >> lon;
input_data >> lat;
input_data >> x;
input_data >> y;
input_data >> zoom;
osmium::Location l(lon, lat);
osmium::geom::Tile t(zoom, l);
REQUIRE(t.x == x);
REQUIRE(t.y == y);
}
}
}
+475
View File
@@ -0,0 +1,475 @@
std::string s = R"(127.4864358 16.8380041 223904 118630 18
163.1103174 39.4760232 121 48 7
-4.1372725 -22.5105386 31 36 6
98.7193066 -36.2312406 1 1 1
63.5773661 -13.47636 21 17 5
-88.4518148 37.9805485 260 395 10
-14.5903133 -28.2989812 3763 4767 13
-13.4971239 -34.4080035 14 19 5
-169.156223 -64.0900356 3 93 7
27.1473191 -4.1993125 4713 4191 13
-160.9733129 54.3684314 13 81 8
129.0194139 14.2576156 439 235 9
-69.5085993 -56.8253221 10057 22700 15
-77.8387486 18.1961517 1162 1837 12
-76.2695325 -18.2494296 147 282 9
-91.594905 7.6698071 1 3 3
-116.7926741 -20.6060813 179 571 10
109.0552776 -1.9947569 52620 33131 16
-156.1846426 -79.3817554 33 449 9
-95.3403755 -27.8978407 1 4 3
-55.1827573 -73.2293796 44 103 7
-108.5207885 -48.0099293 50 167 8
23.7540108 -15.3395164 9273 8898 14
-155.6662842 -68.3295899 0 0 0
75.8139119 30.9914252 363 209 9
-135.8034544 64.7242469 0 1 2
-48.743352 70.9392876 23 13 6
-38.6968026 7.7867812 0 0 0
-18.5234838 11.8557704 29395 30594 16
-152.5632568 19.4069834 78 455 10
-63.2089431 -80.5909713 0 0 0
-94.1255611 -81.2028822 244 930 10
175.0862205 -33.0865142 3 2 2
-179.6241926 -37.0256609 1 625 10
135.6783824 -38.6011643 459739 323170 19
-139.6407533 -83.2495209 0 7 3
-14.1336447 -56.5465949 58 88 7
-30.7414568 -32.9543731 26 38 6
10.3306861 73.2444693 1082 399 11
-84.8379263 29.2363222 16 26 6
-94.0685822 -39.5503996 7821 20309 15
-86.5944356 -41.7491891 265 642 10
11.9182172 -80.5613703 34937 58784 16
91.8773752 -32.1741317 0 0 0
126.2879157 20.5759564 1742 904 11
-160.7743029 -47.3192128 27999 340565 19
-4.2449045 -50.3288332 31 42 6
-66.6857158 61.4380757 10 9 5
169.7372317 -74.3365704 3 3 2
87.4815328 75.6218888 95 21 7
60.3544927 28.3165267 0 0 0
-48.9614619 -59.3292497 2 5 3
-123.2935018 -59.5454886 80 362 9
-31.5909316 -14.8985476 13 17 5
58.1862173 59.0957666 2710 1209 12
-72.8881665 -2.2648849 1218 2073 12
-33.7267461 8.6006817 106512 124785 18
175.723181 46.4929742 7 2 3
-127.1963326 76.0328786 0 0 0
-161.7444367 -26.7634497 13293 151310 18
-163.976298 -8.1169845 91 1070 11
63.7757109 5.6049418 2 1 2
12.7012434 22.1157713 70160 57276 17
19.5832849 -25.0284049 1135 1171 11
-22.6619642 54.8831276 111 81 8
78.7736907 24.0919863 5888 3530 13
121.9003045 -64.6256685 107 94 7
-64.8766793 61.6655916 81 71 8
113.0498445 -70.0016518 416 397 9
-51.5116259 68.1532424 46781 31217 17
-89.9005747 87.9523248 512 0 11
59.2536822 -75.1520493 10 13 4
17.375372 74.9259262 287448 93371 19
75.6426945 8.4808632 186153 124873 18
144.89589 75.1647661 14786 2875 14
174.4350898 -29.268169 258091 153376 18
-91.8773113 50.6182166 0 0 0
5.3822308 45.1391794 134991 94156 18
43.0978373 -10.0764237 324909 276895 19
55.6682917 -40.9015342 21451 20470 15
-37.584032 52.253723 6 5 4
131.0141997 29.0271798 28309 13621 15
69.8830721 -86.8548645 363918 524287 19
-107.7917548 -76.9626654 26290 110787 17
-57.1736642 49.9345991 2 2 3
165.5170226 -84.9735363 982 1021 10
-139.7208984 -73.8754873 1 12 4
-154.5959463 -10.596718 4 33 6
-106.4164918 36.5042686 3348 6405 14
-92.9688259 -11.2262505 0 2 2
138.2722283 8.1109779 7 3 3
123.1389319 -40.3505677 862 637 10
-171.4780435 24.9112482 0 13 5
89.3668763 -63.1809434 392293 381781 19
-79.6906176 -13.376312 9130 17612 15
133.1329522 -28.9032634 445 298 9
115.0369496 70.6965823 6 1 3
-74.8926697 -78.9770185 2391 7144 13
51.9175766 73.0184277 164 50 8
178.1319784 43.7111421 509 186 9
162.4098389 61.1595443 0 0 0
7.6241126 -75.6182944 2 3 2
172.8902767 28.5068027 125 53 7
156.4030739 -76.7309238 478 431 9
-131.3963189 62.2039684 1 2 3
34.6057088 -36.2933264 2441 2491 12
-3.3896413 -48.2734347 15 20 5
83.528842 -48.219886 2998 2675 12
16.6000512 -31.6322244 17894 19421 15
-18.2425749 21.0749052 14 14 5
35.6035336 46.9916228 78498 46105 17
-109.3453091 -34.2312523 12 38 6
88.4909962 58.6104749 47 19 6
-129.7372783 21.7408241 571 1794 12
25.7269392 -40.1240139 1 1 1
26.3829579 5.248998 37570 31811 16
141.1768247 -41.4653038 14617 10269 14
151.3788752 -38.0160512 241302 161042 18
-92.7471483 -35.391745 15883 39664 16
142.5902623 -14.1023743 28 17 5
179.3461485 -86.7573357 3 3 2
-40.9746194 61.5689546 790 576 11
128.6399735 -54.8895009 56186 44772 16
-141.391583 -63.8272 0 2 2
-3.5004218 19.3089998 4016 3648 13
16.138208 -42.7868627 1 1 1
78.502315 -18.91667 2 2 2
-44.6311826 -15.7483106 98572 142686 18
-120.431941 -39.3431529 0 0 0
-70.4915024 25.4763412 9967 13984 15
118.0711114 -66.5691073 211 192 8
-114.945538 38.1764389 0 0 0
142.991315 -46.3378741 14699 10577 14
34.2770562 -84.7173756 312063 518834 19
109.5563415 -85.9138266 105424 131071 17
-171.8032643 70.1948223 0 3 4
-90.8434294 89.7252122 126 0 9
163.5677082 -53.9885419 3 2 2
128.884016 -63.0732584 112461 95358 17
116.5348575 -56.1616143 843 705 10
-171.5770602 37.9225943 11 197 9
48.1396653 -49.3932234 5191 5392 13
-157.6786731 15.3895763 32507 239456 19
15.7385145 -37.1364397 1113 1251 11
137.5179466 61.2025671 1 0 1
-70.4767722 42.9798424 19938 24086 16
27.8867901 43.4642562 9461 5991 14
68.5677462 -84.9560937 11312 16334 14
-56.790151 -67.124147 179437 395476 19
108.850832 43.3493384 26291 11996 15
-139.0655153 8.2673118 1 7 4
59.3726661 83.3857699 21788 1515 15
-158.4718709 -12.2313178 1 17 5
30.358316 -83.020501 2393 3871 12
-169.9667863 71.1152107 1 13 6
-89.9418297 -7.7258969 131156 273429 19
-16.5050312 47.1843923 116 89 8
-151.9641886 -36.3579042 5103 39881 16
169.7406916 60.0950674 62 18 6
32.6694543 -1.8435981 2 2 2
97.7880811 77.5295169 50569 9674 16
87.7554889 -85.6741368 389947 524287 19
-19.0174909 29.1940122 0 0 1
-86.6180019 82.6445919 1 0 2
-50.1997802 -21.1913243 1476 2294 12
73.8710121 75.2201385 5 1 3
41.7434624 79.1410045 322937 65770 19
-122.4312562 -68.4513916 10 48 6
-54.6116448 -23.1761137 1 2 2
-35.8774263 -51.5317442 102 170 8
179.2976644 -76.2729885 127 107 7
-111.6934402 -85.2696836 1 7 3
-24.2137947 28.4102025 3 3 3
-168.0816395 -64.0317696 16 375 9
43.2514876 6.4266793 2540 1974 12
25.5877932 49.3486828 4 2 3
-133.3671657 -25.0795973 8 36 6
-140.2002274 -37.3713396 452 2507 12
73.6326557 -21.9898207 360 288 9
-83.0901448 -69.1893461 2205 6305 13
-32.83227 -11.1061854 3348 4350 13
-151.8897244 14.6891958 0 0 0
-118.1125151 82.3085937 704 288 12
119.9903922 1.4884267 53 31 6
-116.9455865 -48.1971821 0 2 2
111.4279587 -52.6024326 828 688 10
-78.9207774 28.6183104 147207 218615 19
45.1367631 24.1416251 40 27 6
115.0905685 7.2971256 6714 3929 13
-58.0837371 -55.4033522 43 87 7
-44.6785779 83.0751777 6158 877 14
80.2002966 84.3087089 2960 91 12
-167.3118039 -59.2698371 72 1445 11
139.9974902 -74.5994693 455 419 9
-27.5858357 -36.1890547 6936 9960 14
68.8572424 20.2096749 353 226 9
-168.7172825 69.1607462 2053 15104 16
62.1361934 74.6007777 44079 11896 16
-102.9645124 65.3735325 112191 135144 19
178.8434887 18.6231394 65325 29316 16
-138.0494072 -80.3786289 29 228 8
33.3858934 62.9029909 155382 71699 18
-1.6915643 74.737228 1 0 2
18.2680756 6.6441482 1 0 1
34.0511738 -28.6862516 2 2 2
-24.0705994 -0.6026568 28386 32877 16
-176.8765092 -14.3252022 568 35403 16
154.6553417 -79.7390666 1903 1809 11
151.6055263 59.552346 14 4 4
-101.7681729 45.3498263 113933 187876 19
-52.3703658 -89.8260406 181 511 9
-85.7937259 16.5632413 2143 3713 13
114.7030999 6.6846014 104 61 7
13.6027861 88.6863877 2 0 2
60.5726928 38.256536 43794 25219 16
141.0903381 -35.4468007 7306 4959 13
-38.8182454 -55.2332792 200 350 9
179.7818018 -79.6600052 523970 462627 19
-45.2102175 82.7381225 196301 32058 19
-36.5811826 -35.3991346 0 0 0
-26.7719575 -75.7014102 223154 435372 19
77.3451937 -65.4613594 1 1 1
-37.3286225 38.3250599 51945 50407 17
70.8235495 35.3870419 365288 206979 19
99.8381373 -83.4101655 1 1 1
25.8851923 67.415543 9370 3991 14
-12.3393758 68.5972027 7 3 4
-142.9400273 -36.2904852 1 9 4
110.085689 -50.9514972 422467 348655 19
121.5093657 53.9939447 54888 21044 16
151.1307841 -33.0798435 58 38 6
100.4346499 -57.0129759 6 5 3
114.0564882 63.4987339 428250 141474 19
-17.3978586 19.2981593 57 57 7
-129.101039 -66.3423574 579 3067 12
117.6639917 14.0568892 433504 241463 19
97.7014577 69.1261732 202216 60490 18
-174.7931333 81.4174709 7583 46045 19
47.205341 -48.8608019 20680 21495 15
167.416796 -7.5063098 247 133 8
63.6744589 21.3392888 0 0 0
-106.0719817 33.8353547 53832 104862 18
-48.4051268 27.0438152 191648 221209 19
64.5675545 -27.0683253 5 4 3
110.7800249 -35.8217841 0 0 0
164.8954138 81.9558801 31393 2538 15
-54.4595565 -23.0128432 357 579 10
43.2542709 67.694011 2540 989 12
137.6537233 -78.7052092 28913 28450 15
76.9271563 -60.0777348 0 0 0
-145.0240216 47.3869213 6367 22947 16
136.2328853 -73.4534547 3598 3304 12
48.8047148 74.3001023 81 23 7
-144.6978756 33.6270048 200 820 11
64.6723407 -37.196427 21 19 5
-58.3356482 -19.0812366 22148 36307 16
19.611535 -31.3013119 0 0 0
-63.8923439 -25.9560287 1 2 2
-152.5288047 -30.9747477 0 1 1
-99.8509683 -69.0258965 7295 25181 15
-22.9015207 -21.0915082 13 17 5
161.4402438 61.1430241 15539 4652 14
-102.9499976 -1.2629414 1 4 3
-159.7995801 51.1570142 14 85 8
10.5265485 -86.8526122 67 127 7
47.1581041 -73.1628608 646 823 10
2.7577906 -66.3257104 66540 98133 17
96.9653593 -9.8258675 6 4 3
-55.4199846 25.3325116 2834 3499 13
-47.3590106 59.5085133 2 2 3
179.1441501 22.1324479 7 3 3
16.2649007 47.8480398 4 2 3
-27.8373963 -0.3926597 27700 32839 16
-99.7938802 -48.8013068 912 2685 12
133.4858024 28.457146 3 1 2
-174.7621207 -25.8318084 238 9409 14
106.856378 19.640472 203 113 8
31.4361995 -80.2488406 76981 116886 17
148.6539554 -70.0347611 116 99 7
45.1821773 17.5961595 80 57 7
-30.3630114 71.3238998 54481 27877 17
106.547704 44.9731358 6520 2947 13
-132.8057564 23.3928795 67 221 9
116.6455816 -10.1097592 52 33 6
172.5512559 -53.2307289 3 2 2
-114.2084519 42.834332 2994 6030 14
91.0172087 87.6025 1 0 1
-101.666812 -84.7858729 7130 32495 15
-14.8074931 68.3277393 0 0 0
140.3354277 -7.8709618 14 8 4
-130.4961987 -69.4777523 9011 50594 16
-121.239479 1.0896367 1 3 3
-141.2241052 3.4495348 56471 257117 19
42.6041377 -19.1328846 2532 2269 12
141.3750885 -1.8110503 468036 264781 19
-26.545021 -30.9641274 218 302 9
87.6154866 10.1978751 5 3 3
88.002559 -33.4108714 762 612 10
170.9910642 -7.1925019 3993 2130 12
-66.5680487 -88.1144993 165197 524287 19
-71.5925378 45.720316 0 0 0
-16.457642 57.1688038 930 625 11
20.8379624 -11.1485568 35 33 6
-72.9399538 -16.6504502 1 2 2
52.8746845 -71.5213577 10598 12927 14
93.2392918 12.5073156 48 29 6
-3.7803834 73.7748237 128319 49794 18
93.5713795 -38.8308882 24 19 5
87.3474619 -6.9970464 23 16 5
161.2199467 48.5612779 30 11 5
87.343969 -31.3153618 47 37 6
60.5318627 58.0869948 42 19 6
161.4388458 42.7612385 1 0 1
14.1262999 -26.2101142 4 4 3
-135.776346 -21.4248586 503 2297 12
-100.3980364 82.0236388 1 0 3
-55.8093833 -87.2455194 0 0 0
-15.6397352 64.454076 935 540 11
131.5974423 39.1251372 110 48 7
56.8045509 27.5658629 168 107 8
146.3634996 14.9287416 3 1 2
51.5699041 74.0370231 82 23 7
29.3100901 33.7208834 152414 104963 18
19.0622442 1.6781772 141 126 8
-22.2575472 73.6467471 114864 50126 18
125.0208495 47.8533914 3470 1426 12
-92.4804503 29.8409387 995 1691 12
113.6362202 86.1158625 0 0 0
113.6203756 28.4267778 26 13 5
124.472202 25.8347062 13856 6974 14
79.3654306 -33.7864728 46 38 6
-121.169233 -66.7642843 2 12 4
179.5816311 1.0182064 0 0 0
179.1123794 53.367624 0 0 0
-25.6611689 32.6575586 14048 13236 15
92.3370554 58.8306651 12 4 4
142.2756448 63.6603101 3 1 2
-162.8914282 -84.54406 6229 129034 17
-54.0759935 53.1086102 0 0 0
9.1647045 -39.4876873 34436 40604 16
59.3708822 -43.9789068 10894 10425 14
-16.6397572 46.5985252 929 723 11
-36.1053642 -67.6882841 0 1 1
-82.5851985 -69.5277766 4 12 4
117.0059969 -63.2697116 432546 382068 19
127.9740251 85.5341901 112129 0 17
-13.9255265 59.7720207 120931 76457 18
-167.7778382 41.7974194 69 761 11
-100.1217856 -70.5624949 454 1599 11
-42.4790343 -2.0016191 25034 33132 16
-8.0782317 65.9680074 30 16 6
-37.0481466 -55.2856125 203 350 9
149.074382 16.7121888 58 28 6
-53.1010518 -15.8492068 0 0 0
50.8517919 -30.8366257 42025 38674 16
-175.0355994 77.1929422 0 4 5
-33.3221217 72.5636809 6 3 4
-139.9201802 52.3400823 7296 21546 16
86.0299659 23.4535286 1513 886 11
105.6297238 -50.5521342 25998 21733 15
104.2700533 36.5417507 206999 102450 18
58.5238253 84.0320186 86843 3912 17
-121.9177826 65.4393267 1321 2108 13
-152.689211 57.4112922 39774 159515 19
94.2583831 80.8625455 6240 801 13
118.8199874 -37.6116567 53 39 6
5.787144 7.0599251 4227 3934 13
152.1682213 11.778732 236 119 8
37.4503636 64.311498 2474 1084 12
35.2616139 -59.8196291 38 45 6
-20.2808572 -26.9983008 29075 37875 16
-88.8541607 -20.4896703 66370 146320 18
125.7726709 41.2603793 27 11 5
-55.4322696 22.1767236 11338 14313 15
-38.2393439 -56.4681037 6 11 4
-139.4517643 -81.3621632 3 29 5
-146.7954207 -74.6050826 6044 53642 16
161.6654898 -71.7313805 15549 12957 14
-85.4720514 -73.177675 2 6 3
-25.7457381 -42.9842376 13 20 5
-2.0766311 51.0142455 0 0 1
-82.9179334 1.4865326 8836 16248 15
140.5661302 61.5056993 28 9 5
-30.2614099 35.5786378 54518 51659 17
-49.2072142 -38.6965571 0 1 1
124.6587534 9.5039576 433 242 9
-113.4516741 81.4585593 24229 11410 17
-4.5134723 68.229217 3 1 3
75.4838529 -44.997406 2906 2622 12
6.4715239 28.6900832 8486 6828 14
91.9187555 -24.8192643 6187 4679 13
-28.2510181 -42.6238777 26 40 6
-151.1042237 -21.4553189 2630 18384 15
-149.6272551 0.4235911 1382 8172 14
-51.9171488 74.630423 0 0 0
-36.5660117 37.242858 101 99 8
91.7136677 -30.9077617 772 604 10
61.6846009 -85.9378164 5 7 3
11.3772008 69.40183 34839 14980 16
82.6825938 9.4496443 11954 7759 14
61.8446231 -40.0114106 2751 2545 12
-51.6223196 -11.7880324 5 8 4
113.0309076 -73.4376173 13336 13217 14
-169.3808275 -72.7209175 0 25 5
-98.5653414 -80.0893122 231 910 10
-20.4653707 29.9801495 3 3 3
78.9156686 2.599349 0 0 0
76.0635255 -71.0823347 2913 3216 12
-26.1185551 22.3616029 28013 28589 16
177.8803853 -56.3662368 4071 2828 12
-157.7926463 78.4998022 15 34 8
168.6834344 -34.5535211 7934 4934 13
-77.208013 -44.0964079 0 1 1
-56.6162078 28.1240365 10 13 5
8.6548899 72.178831 137374 53767 18
-27.9342497 8.2525327 1 1 2
91.6356971 -13.5230128 6181 4406 13
-161.9980398 -75.4443511 0 13 4
46.8556576 -27.1078679 5162 4737 13
147.2806954 -48.1491071 465 334 9
-168.2679875 -29.0171568 0 2 2
10.0251187 -3.144812 8 8 4
109.0281873 81.9713348 26307 2528 15
-129.6281276 -36.9614028 73359 320148 19
7.3831244 -18.3270273 2132 2260 12
-34.4625217 53.2837646 52988 42524 17
129.8855275 -26.30807 3525 2358 12
-69.6374195 -45.7769025 10045 21081 15
59.9868336 50.3716565 43688 22120 16
126.4653338 -75.607391 1743 1698 11
-34.6459616 53.2502443 51 41 7
152.2415169 -71.7528837 1 1 1
-83.2126752 32.6685119 35239 52939 17
178.6388805 70.5727365 31 7 5
-153.5646223 -81.9491561 2 29 5
178.2668159 11.8222247 0 0 0
-27.136902 18.4287365 6 7 4
-104.7744923 -64.7769211 54777 193540 18
58.2318889 9.5897974 2710 1938 12
138.9707487 -65.2734433 14516 12149 14
-115.29331 -84.3402223 2944 16033 14
-66.3487123 -81.8340211 20 58 6
76.1802855 40.4007156 364 193 9
-77.5026834 -30.653231 145 301 9
-52.6095007 -79.7155889 11595 28942 15
-2.5594899 -31.6276806 7 9 4
-58.6267217 41.4851391 2 2 3
-0.7245205 -70.7329433 509 801 10
161.2822996 -79.0311957 124257 114418 17
144.8720197 80.1059269 14785 1811 14
159.3764075 -23.5100054 0 0 0
82.3109493 -7.0673699 95504 68115 17
94.3931949 63.0474034 97 34 7
87.4523391 -73.2690527 3043 3297 12
101.4256455 -0.8267694 12 8 4
-112.7666152 -82.3670281 12239 61007 16
-82.0948447 -38.0810449 8 19 5
113.2906728 -19.193243 104 70 7
16.953131 78.402684 35 8 6
-81.7974685 -53.9596787 34 86 7
69.8051889 58.1416894 181902 78760 18
-9.2435464 -53.4296594 3 5 3
30.0415066 11.4884737 4 3 3
125.2704157 -69.6324197 54 49 6
-41.2060435 63.8501787 789 548 11
120.407662 -4.9889504 6835 4209 13
92.0345558 -8.0809262 24761 17121 15
127.1061722 83.1311204 6988 428 13
-178.9414629 64.0086678 770 69897 18
49.0743035 -4.3000419 10425 8387 14
-45.109002 -55.1435498 1534 2803 12
3.2795498 75.95918 32 10 6
)";
+8
View File
@@ -74,6 +74,14 @@ SECTION("linestring_with_two_same_locations") {
});
REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::geometry_error);
try {
factory.create_linestring(wnl);
} catch (osmium::geometry_error& e) {
REQUIRE(e.id() == 0);
REQUIRE(std::string(e.what()) == "need at least two points for linestring");
}
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward), osmium::geometry_error);
{
-76
View File
@@ -1,76 +0,0 @@
#include "catch.hpp"
#include <osmium/index/detail/typed_mmap.hpp>
#if defined(_MSC_VER) || (defined(__GNUC__) && defined(_WIN32))
#include "win_mkstemp.hpp"
#endif
TEST_CASE("TypedMmap") {
SECTION("Mmap") {
uint64_t* data = osmium::detail::typed_mmap<uint64_t>::map(10);
data[0] = 4ul;
data[3] = 9ul;
data[9] = 25ul;
REQUIRE(4ul == data[0]);
REQUIRE(9ul == data[3]);
REQUIRE(25ul == data[9]);
osmium::detail::typed_mmap<uint64_t>::unmap(data, 10);
}
SECTION("MmapSizeZero") {
REQUIRE_THROWS_AS(osmium::detail::typed_mmap<uint64_t>::map(0), std::system_error);
}
SECTION("MmapHugeSize") {
// this is a horrible hack to only run the test on 64bit machines.
if (sizeof(size_t) >= 8) {
REQUIRE_THROWS_AS(osmium::detail::typed_mmap<uint64_t>::map(1ULL << (sizeof(size_t) * 6)), std::system_error);
}
}
#ifdef __linux__
SECTION("Remap") {
uint64_t* data = osmium::detail::typed_mmap<uint64_t>::map(10);
data[0] = 4ul;
data[3] = 9ul;
data[9] = 25ul;
uint64_t* new_data = osmium::detail::typed_mmap<uint64_t>::remap(data, 10, 1000);
REQUIRE(4ul == new_data[0]);
REQUIRE(9ul == new_data[3]);
REQUIRE(25ul == new_data[9]);
}
#else
# pragma message("not running 'Remap' test case on this machine")
#endif
SECTION("FileSize") {
const int size = 100;
char filename[] = "test_mmap_file_size_XXXXXX";
const int fd = mkstemp(filename);
REQUIRE(fd > 0);
REQUIRE(0 == osmium::detail::typed_mmap<uint64_t>::file_size(fd));
REQUIRE(0 == ftruncate(fd, size * sizeof(uint64_t)));
REQUIRE(size == osmium::detail::typed_mmap<uint64_t>::file_size(fd));
osmium::detail::typed_mmap<uint64_t>::grow_file(size / 2, fd);
REQUIRE(size == osmium::detail::typed_mmap<uint64_t>::file_size(fd));
osmium::detail::typed_mmap<uint64_t>::grow_file(size, fd);
REQUIRE(size == osmium::detail::typed_mmap<uint64_t>::file_size(fd));
osmium::detail::typed_mmap<uint64_t>::grow_file(size * 2, fd);
REQUIRE((size * 2) == osmium::detail::typed_mmap<uint64_t>::file_size(fd));
REQUIRE(0 == close(fd));
REQUIRE(0 == unlink(filename));
}
}
@@ -1,34 +0,0 @@
#include "catch.hpp"
#include <osmium/index/detail/typed_mmap.hpp>
#if defined(_MSC_VER) || (defined(__GNUC__) && defined(_WIN32))
#include "win_mkstemp.hpp"
#endif
TEST_CASE("TypedMmapGrow") {
SECTION("GrowAndMap") {
const int size = 100;
char filename[] = "test_mmap_grow_and_map_XXXXXX";
const int fd = mkstemp(filename);
REQUIRE(fd > 0);
uint64_t* data = osmium::detail::typed_mmap<uint64_t>::grow_and_map(size, fd);
REQUIRE(size == osmium::detail::typed_mmap<uint64_t>::file_size(fd));
data[0] = 1ul;
data[1] = 8ul;
data[99] = 27ul;
REQUIRE(1ul == data[0]);
REQUIRE(8ul == data[1]);
REQUIRE(27ul == data[99]);
osmium::detail::typed_mmap<uint64_t>::unmap(data, size);
REQUIRE(0 == close(fd));
REQUIRE(0 == unlink(filename));
}
}
+24
View File
@@ -247,5 +247,29 @@ TEST_CASE("FileFormats") {
REQUIRE_THROWS_AS(f.check(), std::runtime_error);
}
SECTION("url without format") {
osmium::io::File f {"http://www.example.com/api"};
REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
SECTION("url without format and filename") {
osmium::io::File f {"http://planet.osm.org/pbf/planet-latest.osm.pbf"};
REQUIRE(osmium::io::file_format::pbf == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
SECTION("url with format") {
osmium::io::File f {"http://www.example.com/api", "osh"};
REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(true == f.has_multiple_object_versions());
f.check();
}
}
+94
View File
@@ -0,0 +1,94 @@
#include "catch.hpp"
#include <osmium/io/detail/string_table.hpp>
TEST_CASE("String store") {
osmium::io::detail::StringStore ss(100);
SECTION("empty") {
REQUIRE(ss.begin() == ss.end());
}
SECTION("add zero-length string") {
const char* s1 = ss.add("");
REQUIRE(std::string(s1) == "");
auto it = ss.begin();
REQUIRE(s1 == *it);
REQUIRE(std::string(*it) == "");
REQUIRE(++it == ss.end());
}
SECTION("add strings") {
const char* s1 = ss.add("foo");
const char* s2 = ss.add("bar");
REQUIRE(s1 != s2);
REQUIRE(std::string(s1) == "foo");
REQUIRE(std::string(s2) == "bar");
auto it = ss.begin();
REQUIRE(s1 == *it++);
REQUIRE(s2 == *it++);
REQUIRE(it == ss.end());
}
SECTION("add zero-length string and longer strings") {
const char* s1 = ss.add("");
const char* s2 = ss.add("xxx");
const char* s3 = ss.add("yyyyy");
auto it = ss.begin();
REQUIRE(std::string(*it++) == "");
REQUIRE(std::string(*it++) == "xxx");
REQUIRE(std::string(*it++) == "yyyyy");
REQUIRE(it == ss.end());
}
SECTION("add many strings") {
for (const char* teststring : {"a", "abc", "abcd", "abcde"}) {
int i = 0;
for (; i < 100; ++i) {
ss.add(teststring);
}
for (const char* s : ss) {
REQUIRE(std::string(s) == teststring);
--i;
}
REQUIRE(i == 0);
ss.clear();
}
}
}
TEST_CASE("String table") {
osmium::io::detail::StringTable st;
SECTION("empty") {
REQUIRE(st.size() == 1);
REQUIRE(std::next(st.begin()) == st.end());
}
SECTION("add strings") {
REQUIRE(st.add("foo") == 1);
REQUIRE(st.add("bar") == 2);
REQUIRE(st.add("bar") == 2);
REQUIRE(st.add("baz") == 3);
REQUIRE(st.add("foo") == 1);
REQUIRE(st.size() == 4);
auto it = st.begin();
REQUIRE(std::string("") == *it++);
REQUIRE(std::string("foo") == *it++);
REQUIRE(std::string("bar") == *it++);
REQUIRE(std::string("baz") == *it++);
REQUIRE(it == st.end());
st.clear();
REQUIRE(st.size() == 1);
}
}
+79 -53
View File
@@ -4,73 +4,99 @@
#include <osmium/memory/buffer.hpp>
#include <osmium/osm/tag.hpp>
TEST_CASE("tag_list") {
TEST_CASE("create tag list") {
osmium::memory::Buffer buffer(10240);
SECTION("can_be_created_from_initializer_list") {
osmium::memory::Buffer buffer(10240);
const osmium::TagList& tl = osmium::builder::build_tag_list(buffer, {
{ "highway", "primary" },
{ "name", "Main Street" },
{ "source", "GPS" }
});
REQUIRE(osmium::item_type::tag_list == tl.type());
REQUIRE(3 == tl.size());
REQUIRE(std::string("highway") == tl.begin()->key());
REQUIRE(std::string("primary") == tl.begin()->value());
SECTION("with TagListBuilder from char*") {
{
osmium::builder::TagListBuilder builder(buffer);
builder.add_tag("highway", "primary");
builder.add_tag("name", "Main Street");
}
buffer.commit();
}
SECTION("can_be_created_from_map") {
osmium::memory::Buffer buffer(10240);
SECTION("with TagListBuilder from char* with length") {
{
osmium::builder::TagListBuilder builder(buffer);
builder.add_tag("highway", strlen("highway"), "primary", strlen("primary"));
builder.add_tag("nameXX", 4, "Main Street", 11);
}
buffer.commit();
}
const osmium::TagList& tl = osmium::builder::build_tag_list_from_map(buffer, std::map<const char*, const char*>({
SECTION("with TagListBuilder from std::string") {
{
osmium::builder::TagListBuilder builder(buffer);
builder.add_tag(std::string("highway"), std::string("primary"));
const std::string source = "name";
std::string gps = "Main Street";
builder.add_tag(source, gps);
}
buffer.commit();
}
SECTION("with build_tag_list from initializer list") {
osmium::builder::build_tag_list(buffer, {
{ "highway", "primary" },
{ "name", "Main Street" }
});
}
SECTION("with build_tag_list_from_map") {
osmium::builder::build_tag_list_from_map(buffer, std::map<const char*, const char*>({
{ "highway", "primary" },
{ "name", "Main Street" }
}));
REQUIRE(osmium::item_type::tag_list == tl.type());
REQUIRE(2 == tl.size());
if (std::string("highway") == tl.begin()->key()) {
REQUIRE(std::string("primary") == tl.begin()->value());
REQUIRE(std::string("name") == std::next(tl.begin(), 1)->key());
REQUIRE(std::string("Main Street") == std::next(tl.begin(), 1)->value());
} else {
REQUIRE(std::string("highway") == std::next(tl.begin(), 1)->key());
REQUIRE(std::string("primary") == std::next(tl.begin(), 1)->value());
REQUIRE(std::string("name") == tl.begin()->key());
REQUIRE(std::string("Main Street") == tl.begin()->value());
}
}
SECTION("can_be_created_with_callback") {
osmium::memory::Buffer buffer(10240);
const osmium::TagList& tl = osmium::builder::build_tag_list_from_func(buffer, [](osmium::builder::TagListBuilder& tlb) {
SECTION("with build_tag_list_from_func") {
osmium::builder::build_tag_list_from_func(buffer, [](osmium::builder::TagListBuilder& tlb) {
tlb.add_tag("highway", "primary");
tlb.add_tag("bridge", "true");
tlb.add_tag("name", "Main Street");
});
REQUIRE(osmium::item_type::tag_list == tl.type());
REQUIRE(2 == tl.size());
REQUIRE(std::string("bridge") == std::next(tl.begin(), 1)->key());
REQUIRE(std::string("true") == std::next(tl.begin(), 1)->value());
}
SECTION("returns_value_by_key") {
osmium::memory::Buffer buffer(10240);
const osmium::TagList& tl = *buffer.begin<osmium::TagList>();
REQUIRE(osmium::item_type::tag_list == tl.type());
REQUIRE(2 == tl.size());
const osmium::TagList& tl = osmium::builder::build_tag_list_from_func(buffer, [](osmium::builder::TagListBuilder& tlb) {
tlb.add_tag("highway", "primary");
tlb.add_tag("bridge", "true");
});
auto it = tl.begin();
REQUIRE(std::string("highway") == it->key());
REQUIRE(std::string("primary") == it->value());
++it;
REQUIRE(std::string("name") == it->key());
REQUIRE(std::string("Main Street") == it->value());
++it;
REQUIRE(it == tl.end());
REQUIRE(std::string("primary") == tl.get_value_by_key("highway"));
REQUIRE(nullptr == tl.get_value_by_key("name"));
REQUIRE(std::string("foo") == tl.get_value_by_key("name", "foo"));
REQUIRE(std::string("true") == tl["bridge"]);
}
REQUIRE(std::string("primary") == tl.get_value_by_key("highway"));
REQUIRE(nullptr == tl.get_value_by_key("foo"));
REQUIRE(std::string("default") == tl.get_value_by_key("foo", "default"));
REQUIRE(std::string("Main Street") == tl["name"]);
}
TEST_CASE("empty keys and values are okay") {
osmium::memory::Buffer buffer(10240);
const osmium::TagList& tl = osmium::builder::build_tag_list(buffer, {
{ "empty value", "" },
{ "", "empty key" }
});
REQUIRE(osmium::item_type::tag_list == tl.type());
REQUIRE(2 == tl.size());
auto it = tl.begin();
REQUIRE(std::string("empty value") == it->key());
REQUIRE(std::string("") == it->value());
++it;
REQUIRE(std::string("") == it->key());
REQUIRE(std::string("empty key") == it->value());
++it;
REQUIRE(it == tl.end());
REQUIRE(std::string("") == tl.get_value_by_key("empty value"));
REQUIRE(std::string("empty key") == tl.get_value_by_key(""));
}
-1
View File
@@ -59,7 +59,6 @@ TEST_CASE("thread") {
auto& pool = osmium::thread::Pool::instance();
result = 0;
bool got_exception = false;
auto future = pool.submit(test_job_throw {});
REQUIRE_THROWS_AS(future.get(), std::runtime_error);
+81
View File
@@ -0,0 +1,81 @@
#include "catch.hpp"
#include <cstring>
#include <osmium/util/data_file.hpp>
TEST_CASE("temporary file") {
SECTION("create/open") {
osmium::util::DataFile file;
REQUIRE(!!file);
int fd = file.fd();
REQUIRE(fd > 0);
const char buf[] = "foobar";
REQUIRE(::write(fd, buf, sizeof(buf)) == sizeof(buf));
file.close();
REQUIRE(!file);
}
}
TEST_CASE("named file") {
SECTION("create/open") {
{
osmium::util::DataFile file("test.data", true);
REQUIRE(!!file);
int fd = file.fd();
REQUIRE(fd > 0);
REQUIRE(file.size() == 0);
const char buf[] = "foobar";
REQUIRE(::write(fd, buf, sizeof(buf) - 1) == sizeof(buf) - 1);
file.close();
REQUIRE(!file);
}
{
osmium::util::DataFile file("test.data", false);
REQUIRE(!!file);
int fd = file.fd();
REQUIRE(fd > 0);
REQUIRE(file.size() == 6);
char buf[10];
int len = ::read(fd, buf, sizeof(buf));
REQUIRE(len == 6);
REQUIRE(!strncmp(buf, "foobar", 6));
file.close();
REQUIRE(!file);
REQUIRE(unlink("test.data") == 0);
}
}
SECTION("grow file") {
osmium::util::DataFile file("test.data", true);
REQUIRE(!!file);
REQUIRE(file.size() == 0);
file.grow(10);
REQUIRE(file.size() == 10);
}
}
+68
View File
@@ -0,0 +1,68 @@
#include "catch.hpp"
#include <vector>
#include <osmium/util/delta.hpp>
TEST_CASE("delta encode") {
osmium::util::DeltaEncode<int> x;
SECTION("int") {
REQUIRE(x.update(17) == 17);
REQUIRE(x.update(10) == -7);
}
}
TEST_CASE("delta decode") {
osmium::util::DeltaDecode<int> x;
SECTION("int") {
REQUIRE(x.update(17) == 17);
REQUIRE(x.update(10) == 27);
}
}
TEST_CASE("delta encode and decode") {
std::vector<int> a = { 5, -9, 22, 13, 0, 23 };
osmium::util::DeltaEncode<int> de;
std::vector<int> b;
for (int x : a) {
b.push_back(de.update(x));
}
osmium::util::DeltaDecode<int> dd;
std::vector<int> c;
for (int x : b) {
c.push_back(dd.update(x));
}
}
TEST_CASE("delta encode iterator") {
std::vector<int> data = { 4, 5, 13, 22, 12 };
auto l = [](std::vector<int>::const_iterator it) -> int {
return *it;
};
typedef osmium::util::DeltaEncodeIterator<std::vector<int>::const_iterator, decltype(l), int> it_type;
it_type it(data.begin(), data.end(), l);
it_type end(data.end(), data.end(), l);
REQUIRE(*it == 4);
++it;
REQUIRE(*it++ == 1);
REQUIRE(*it == 8);
++it;
REQUIRE(*it++ == 9);
REQUIRE(*it == -10);
++it;
REQUIRE(it == end);
}
+69
View File
@@ -0,0 +1,69 @@
#include "catch.hpp"
#include <osmium/util/file.hpp>
#ifdef _WIN32
// https://msdn.microsoft.com/en-us/library/ksazx244.aspx
// https://msdn.microsoft.com/en-us/library/a9yf33zb.aspx
class DoNothingInvalidParameterHandler {
static void invalid_parameter_handler(
const wchar_t* expression,
const wchar_t* function,
const wchar_t* file,
unsigned int line,
uintptr_t pReserved
) {
// do nothing
}
_invalid_parameter_handler old_handler;
public:
DoNothingInvalidParameterHandler() :
old_handler(_set_invalid_parameter_handler(invalid_parameter_handler)) {
}
~DoNothingInvalidParameterHandler() {
_set_invalid_parameter_handler(old_handler);
}
}; // class InvalidParameterHandler
#endif
TEST_CASE("file_size") {
#ifdef _WIN32
DoNothingInvalidParameterHandler handler;
#endif
SECTION("illegal fd should throw") {
REQUIRE_THROWS_AS(osmium::util::file_size(-1), std::system_error);
}
SECTION("unused fd should throw") {
// its unlikely that fd 1000 is open...
REQUIRE_THROWS_AS(osmium::util::file_size(1000), std::system_error);
}
}
TEST_CASE("resize_file") {
#ifdef _WIN32
DoNothingInvalidParameterHandler handler;
#endif
SECTION("illegal fd should throw") {
REQUIRE_THROWS_AS(osmium::util::resize_file(-1, 10), std::system_error);
}
SECTION("unused fd should throw") {
// its unlikely that fd 1000 is open...
REQUIRE_THROWS_AS(osmium::util::resize_file(1000, 10), std::system_error);
}
}
@@ -0,0 +1,419 @@
#include "catch.hpp"
#include <sys/types.h>
#include <limits>
#include <osmium/util/file.hpp>
#include <osmium/util/memory_mapping.hpp>
#if defined(_MSC_VER) || (defined(__GNUC__) && defined(_WIN32))
#include "win_mkstemp.hpp"
#endif
static const size_t huge = std::numeric_limits<size_t>::max();
TEST_CASE("anonymous mapping") {
SECTION("simple memory mapping should work") {
osmium::util::MemoryMapping mapping(1000, osmium::util::MemoryMapping::mapping_mode::write_private);
REQUIRE(mapping.get_addr() != nullptr);
REQUIRE(mapping.size() >= 1000);
volatile int* addr = mapping.get_addr<int>();
REQUIRE(mapping.writable());
*addr = 42;
REQUIRE(*addr == 42);
REQUIRE(!!mapping);
mapping.unmap();
REQUIRE(!mapping);
mapping.unmap(); // second unmap is okay
}
SECTION("memory mapping of zero length should work") {
osmium::util::MemoryMapping mapping(0, osmium::util::MemoryMapping::mapping_mode::write_private);
REQUIRE(mapping.get_addr() != nullptr);
REQUIRE(mapping.size() == osmium::util::get_pagesize());
REQUIRE(!!mapping);
mapping.unmap();
REQUIRE(!mapping);
}
SECTION("moving a memory mapping should work") {
osmium::util::MemoryMapping mapping1(1000, osmium::util::MemoryMapping::mapping_mode::write_private);
int* addr1 = mapping1.get_addr<int>();
*addr1 = 42;
REQUIRE(!!mapping1);
osmium::util::MemoryMapping mapping2(std::move(mapping1));
REQUIRE(!!mapping2);
REQUIRE(!mapping1);
mapping1.unmap();
int* addr2 = mapping2.get_addr<int>();
REQUIRE(*addr2 == 42);
mapping2.unmap();
REQUIRE(!mapping2);
}
SECTION("move assignment should work") {
osmium::util::MemoryMapping mapping1(1000, osmium::util::MemoryMapping::mapping_mode::write_private);
osmium::util::MemoryMapping mapping2(1000, osmium::util::MemoryMapping::mapping_mode::write_private);
REQUIRE(!!mapping1);
REQUIRE(!!mapping2);
int* addr1 = mapping1.get_addr<int>();
*addr1 = 42;
mapping2 = std::move(mapping1);
REQUIRE(!!mapping2);
REQUIRE(!mapping1);
int* addr2 = mapping2.get_addr<int>();
REQUIRE(*addr2 == 42);
mapping2.unmap();
REQUIRE(!mapping2);
}
#ifdef __linux__
SECTION("remapping to larger size should work") {
osmium::util::MemoryMapping mapping(1000, osmium::util::MemoryMapping::mapping_mode::write_private);
REQUIRE(mapping.size() >= 1000);
size_t size1 = mapping.size();
int* addr1 = mapping.get_addr<int>();
*addr1 = 42;
mapping.resize(8000);
REQUIRE(mapping.size() > size1);
int* addr2 = mapping.get_addr<int>();
REQUIRE(*addr2 == 42);
}
SECTION("remapping to smaller size should work") {
osmium::util::MemoryMapping mapping(8000, osmium::util::MemoryMapping::mapping_mode::write_private);
REQUIRE(mapping.size() >= 1000);
size_t size1 = mapping.size();
int* addr1 = mapping.get_addr<int>();
*addr1 = 42;
mapping.resize(500);
REQUIRE(mapping.size() < size1);
int* addr2 = mapping.get_addr<int>();
REQUIRE(*addr2 == 42);
}
#endif
}
TEST_CASE("file-based mapping") {
SECTION("writing to a mapped file should work") {
char filename[] = "test_mmap_write_XXXXXX";
const int fd = mkstemp(filename);
REQUIRE(fd > 0);
osmium::util::resize_file(fd, 100);
{
osmium::util::MemoryMapping mapping(100, osmium::util::MemoryMapping::mapping_mode::write_shared, fd);
REQUIRE(mapping.writable());
REQUIRE(!!mapping);
REQUIRE(mapping.size() >= 100);
*mapping.get_addr<int>() = 1234;
mapping.unmap();
}
REQUIRE(osmium::util::file_size(fd) == 100);
{
osmium::util::MemoryMapping mapping(100, osmium::util::MemoryMapping::mapping_mode::readonly, fd);
REQUIRE(!mapping.writable());
REQUIRE(!!mapping);
REQUIRE(mapping.size() >= 100);
REQUIRE(*mapping.get_addr<int>() == 1234);
mapping.unmap();
}
REQUIRE(0 == close(fd));
REQUIRE(0 == unlink(filename));
}
SECTION("writing to a privately mapped file should work") {
char filename[] = "test_mmap_write_XXXXXX";
const int fd = mkstemp(filename);
REQUIRE(fd > 0);
osmium::util::resize_file(fd, 100);
{
osmium::util::MemoryMapping mapping(100, osmium::util::MemoryMapping::mapping_mode::write_private, fd);
REQUIRE(mapping.writable());
REQUIRE(!!mapping);
REQUIRE(mapping.size() >= 100);
*mapping.get_addr<int>() = 1234;
mapping.unmap();
}
REQUIRE(osmium::util::file_size(fd) == 100);
{
osmium::util::MemoryMapping mapping(100, osmium::util::MemoryMapping::mapping_mode::readonly, fd);
REQUIRE(!mapping.writable());
REQUIRE(!!mapping);
REQUIRE(mapping.size() >= 100);
REQUIRE(*mapping.get_addr<int>() == 0); // should not see the value set above
mapping.unmap();
}
REQUIRE(0 == close(fd));
REQUIRE(0 == unlink(filename));
}
SECTION("remapping to larger size should work") {
char filename[] = "test_mmap_grow_XXXXXX";
const int fd = mkstemp(filename);
REQUIRE(fd > 0);
osmium::util::MemoryMapping mapping(100, osmium::util::MemoryMapping::mapping_mode::write_shared, fd);
REQUIRE(mapping.size() >= 100);
size_t size1 = mapping.size();
int* addr1 = mapping.get_addr<int>();
*addr1 = 42;
mapping.resize(8000);
REQUIRE(mapping.size() >= 8000);
REQUIRE(mapping.size() > size1);
int* addr2 = mapping.get_addr<int>();
REQUIRE(*addr2 == 42);
mapping.unmap();
REQUIRE(0 == close(fd));
REQUIRE(0 == unlink(filename));
}
SECTION("remapping to smaller size should work") {
char filename[] = "test_mmap_shrink_XXXXXX";
const int fd = mkstemp(filename);
REQUIRE(fd > 0);
{
osmium::util::MemoryMapping mapping(8000, osmium::util::MemoryMapping::mapping_mode::write_shared, fd);
REQUIRE(mapping.size() >= 8000);
size_t size1 = mapping.size();
int* addr1 = mapping.get_addr<int>();
*addr1 = 42;
mapping.resize(50);
REQUIRE(mapping.size() >= 50);
REQUIRE(mapping.size() < size1);
int* addr2 = mapping.get_addr<int>();
REQUIRE(*addr2 == 42);
}
REQUIRE(0 == close(fd));
REQUIRE(0 == unlink(filename));
}
}
TEST_CASE("typed anonymous mapping") {
SECTION("simple memory mapping should work") {
osmium::util::TypedMemoryMapping<uint32_t> mapping(1000);
volatile uint32_t* addr = mapping.begin();
REQUIRE(mapping.writable());
*addr = 42;
REQUIRE(*addr == 42);
REQUIRE(!!mapping);
mapping.unmap();
REQUIRE(!mapping);
mapping.unmap(); // second unmap is okay
}
SECTION("moving a memory mapping should work") {
osmium::util::TypedMemoryMapping<uint32_t> mapping1(1000);
uint32_t* addr1 = mapping1.begin();
*addr1 = 42;
REQUIRE(!!mapping1);
osmium::util::TypedMemoryMapping<uint32_t> mapping2(std::move(mapping1));
REQUIRE(!!mapping2);
REQUIRE(!mapping1);
mapping1.unmap();
auto addr2 = mapping2.begin();
REQUIRE(*addr2 == 42);
mapping2.unmap();
REQUIRE(!mapping2);
}
SECTION("move assignment should work") {
osmium::util::TypedMemoryMapping<uint32_t> mapping1(1000);
osmium::util::TypedMemoryMapping<uint32_t> mapping2(1000);
REQUIRE(!!mapping1);
REQUIRE(!!mapping2);
auto addr1 = mapping1.begin();
*addr1 = 42;
mapping2 = std::move(mapping1);
REQUIRE(!!mapping2);
REQUIRE(!mapping1);
auto addr2 = mapping2.begin();
REQUIRE(*addr2 == 42);
mapping2.unmap();
REQUIRE(!mapping2);
}
#ifdef __linux__
SECTION("remapping to larger size should work") {
osmium::util::TypedMemoryMapping<uint32_t> mapping(1000);
REQUIRE(mapping.size() >= 1000);
auto addr1 = mapping.begin();
*addr1 = 42;
mapping.resize(8000);
auto addr2 = mapping.begin();
REQUIRE(*addr2 == 42);
}
SECTION("remapping to smaller size should work") {
osmium::util::TypedMemoryMapping<uint32_t> mapping(8000);
REQUIRE(mapping.size() >= 8000);
auto addr1 = mapping.begin();
*addr1 = 42;
mapping.resize(500);
auto addr2 = mapping.begin();
REQUIRE(*addr2 == 42);
}
#endif
}
TEST_CASE("typed file-based mapping") {
SECTION("writing to a mapped file should work") {
char filename[] = "test_mmap_file_size_XXXXXX";
const int fd = mkstemp(filename);
REQUIRE(fd > 0);
osmium::util::resize_file(fd, 100);
{
osmium::util::TypedMemoryMapping<uint32_t> mapping(100, osmium::util::MemoryMapping::mapping_mode::write_shared, fd);
REQUIRE(mapping.writable());
REQUIRE(!!mapping);
REQUIRE(mapping.size() >= 100);
*mapping.begin() = 1234;
mapping.unmap();
}
{
osmium::util::TypedMemoryMapping<uint32_t> mapping(100, osmium::util::MemoryMapping::mapping_mode::readonly, fd);
REQUIRE(!mapping.writable());
REQUIRE(!!mapping);
REQUIRE(mapping.size() >= 100);
REQUIRE(*mapping.begin() == 1234);
mapping.unmap();
}
REQUIRE(0 == close(fd));
REQUIRE(0 == unlink(filename));
}
}
TEST_CASE("anonymous memory mapping class") {
SECTION("simple memory mapping should work") {
osmium::util::AnonymousMemoryMapping mapping(1000);
REQUIRE(mapping.get_addr() != nullptr);
volatile int* addr = mapping.get_addr<int>();
REQUIRE(mapping.writable());
*addr = 42;
REQUIRE(*addr == 42);
REQUIRE(!!mapping);
mapping.unmap();
REQUIRE(!mapping);
mapping.unmap(); // second unmap is okay
}
#ifdef __linux__
SECTION("remapping to larger size should work") {
osmium::util::AnonymousMemoryMapping mapping(1000);
REQUIRE(mapping.size() >= 1000);
int* addr1 = mapping.get_addr<int>();
*addr1 = 42;
mapping.resize(2000);
int* addr2 = mapping.get_addr<int>();
REQUIRE(*addr2 == 42);
}
SECTION("remapping to smaller size should work") {
osmium::util::AnonymousMemoryMapping mapping(2000);
REQUIRE(mapping.size() >= 2000);
int* addr1 = mapping.get_addr<int>();
*addr1 = 42;
mapping.resize(500);
int* addr2 = mapping.get_addr<int>();
REQUIRE(*addr2 == 42);
}
#endif
}
+68
View File
@@ -0,0 +1,68 @@
#include "catch.hpp"
#include <osmium/util/minmax.hpp>
#include <osmium/osm/timestamp.hpp>
TEST_CASE("minmax numeric") {
SECTION("min") {
osmium::min_op<int> x;
REQUIRE(x() == std::numeric_limits<int>::max());
x.update(17);
REQUIRE(x() == 17);
x.update(10);
REQUIRE(x() == 10);
x.update(22);
REQUIRE(x() == 10);
}
SECTION("max") {
osmium::max_op<uint32_t> x;
REQUIRE(x() == 0);
x.update(17);
REQUIRE(x() == 17);
x.update(10);
REQUIRE(x() == 17);
x.update(22);
REQUIRE(x() == 22);
}
}
TEST_CASE("minmax timestamp") {
SECTION("min") {
osmium::min_op<osmium::Timestamp> x;
x.update(osmium::Timestamp("2010-01-01T00:00:00Z"));
REQUIRE(x().to_iso() == "2010-01-01T00:00:00Z");
x.update(osmium::Timestamp("2015-01-01T00:00:00Z"));
REQUIRE(x().to_iso() == "2010-01-01T00:00:00Z");
x.update(osmium::Timestamp("2000-01-01T00:00:00Z"));
REQUIRE(x().to_iso() == "2000-01-01T00:00:00Z");
}
SECTION("max") {
osmium::max_op<osmium::Timestamp> x;
x.update(osmium::Timestamp("2010-01-01T00:00:00Z"));
REQUIRE(x().to_iso() == "2010-01-01T00:00:00Z");
x.update(osmium::Timestamp("2015-01-01T00:00:00Z"));
REQUIRE(x().to_iso() == "2015-01-01T00:00:00Z");
x.update(osmium::Timestamp("2000-01-01T00:00:00Z"));
REQUIRE(x().to_iso() == "2015-01-01T00:00:00Z");
}
}
+11
View File
@@ -9,6 +9,7 @@ TEST_CASE("split_string") {
std::vector<std::string> result = {"foo", "baramba", "baz"};
REQUIRE(result == osmium::split_string(str, ','));
REQUIRE(result == osmium::split_string(str, ',', true));
}
SECTION("split_string string without sep") {
@@ -16,34 +17,43 @@ TEST_CASE("split_string") {
std::vector<std::string> result = {"foo"};
REQUIRE(result == osmium::split_string(str, ','));
REQUIRE(result == osmium::split_string(str, ',', true));
}
SECTION("split_string string with empty at end") {
std::string str { "foo,bar," };
std::vector<std::string> result = {"foo", "bar", ""};
std::vector<std::string> resultc = {"foo", "bar"};
REQUIRE(result == osmium::split_string(str, ','));
REQUIRE(resultc == osmium::split_string(str, ',', true));
}
SECTION("split_string string with empty in middle") {
std::string str { "foo,,bar" };
std::vector<std::string> result = {"foo", "", "bar"};
std::vector<std::string> resultc = {"foo", "bar"};
REQUIRE(result == osmium::split_string(str, ','));
REQUIRE(resultc == osmium::split_string(str, ',', true));
}
SECTION("split_string string with empty at start") {
std::string str { ",bar,baz" };
std::vector<std::string> result = {"", "bar", "baz"};
std::vector<std::string> resultc = {"bar", "baz"};
REQUIRE(result == osmium::split_string(str, ','));
REQUIRE(resultc == osmium::split_string(str, ',', true));
}
SECTION("split_string sep") {
std::string str { "," };
std::vector<std::string> result = {"", ""};
std::vector<std::string> resultc;
REQUIRE(result == osmium::split_string(str, ','));
REQUIRE(resultc == osmium::split_string(str, ',', true));
}
SECTION("split_string empty string") {
@@ -51,6 +61,7 @@ TEST_CASE("split_string") {
std::vector<std::string> result;
REQUIRE(result == osmium::split_string(str, ','));
REQUIRE(result == osmium::split_string(str, ',', true));
}
}