Merge commit '6eb4f090f98f6b17a23c57768c16b7716b6c9cbd' as 'third_party/libosmium'
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/handler/check_order.hpp>
|
||||
#include <osmium/memory/buffer.hpp>
|
||||
#include <osmium/opl.hpp>
|
||||
#include <osmium/visitor.hpp>
|
||||
|
||||
TEST_CASE("CheckOrder handler if everything is in order") {
|
||||
osmium::memory::Buffer buffer{1024};
|
||||
|
||||
REQUIRE(osmium::opl_parse("n-126", buffer));
|
||||
REQUIRE(osmium::opl_parse("n123", buffer));
|
||||
REQUIRE(osmium::opl_parse("n124", buffer));
|
||||
REQUIRE(osmium::opl_parse("n128", buffer));
|
||||
REQUIRE(osmium::opl_parse("w-100", buffer));
|
||||
REQUIRE(osmium::opl_parse("w100", buffer));
|
||||
REQUIRE(osmium::opl_parse("w102", buffer));
|
||||
REQUIRE(osmium::opl_parse("r-200", buffer));
|
||||
REQUIRE(osmium::opl_parse("r100", buffer));
|
||||
|
||||
osmium::handler::CheckOrder handler;
|
||||
osmium::apply(buffer, handler);
|
||||
REQUIRE(handler.max_node_id() == 128);
|
||||
REQUIRE(handler.max_way_id() == 102);
|
||||
REQUIRE(handler.max_relation_id() == 100);
|
||||
}
|
||||
|
||||
TEST_CASE("CheckOrder handler: Nodes must be in order") {
|
||||
osmium::memory::Buffer buffer{1024};
|
||||
|
||||
REQUIRE(osmium::opl_parse("n3", buffer));
|
||||
|
||||
SECTION("Positive ID") {
|
||||
REQUIRE(osmium::opl_parse("n2", buffer));
|
||||
}
|
||||
SECTION("Negative ID") {
|
||||
REQUIRE(osmium::opl_parse("n-2", buffer));
|
||||
}
|
||||
|
||||
osmium::handler::CheckOrder handler;
|
||||
REQUIRE_THROWS_AS(osmium::apply(buffer, handler), const osmium::out_of_order_error&);
|
||||
}
|
||||
|
||||
TEST_CASE("CheckOrder handler: Ways must be in order") {
|
||||
osmium::memory::Buffer buffer{1024};
|
||||
|
||||
REQUIRE(osmium::opl_parse("w3", buffer));
|
||||
SECTION("Positive ID") {
|
||||
REQUIRE(osmium::opl_parse("w2", buffer));
|
||||
}
|
||||
SECTION("Negative ID") {
|
||||
REQUIRE(osmium::opl_parse("w-2", buffer));
|
||||
}
|
||||
|
||||
osmium::handler::CheckOrder handler;
|
||||
REQUIRE_THROWS_AS(osmium::apply(buffer, handler), const osmium::out_of_order_error&);
|
||||
}
|
||||
|
||||
TEST_CASE("CheckOrder handler: Relations must be in order") {
|
||||
osmium::memory::Buffer buffer{1024};
|
||||
|
||||
REQUIRE(osmium::opl_parse("r3", buffer));
|
||||
SECTION("Positive ID") {
|
||||
REQUIRE(osmium::opl_parse("r2", buffer));
|
||||
}
|
||||
SECTION("Negative ID") {
|
||||
REQUIRE(osmium::opl_parse("r-2", buffer));
|
||||
}
|
||||
|
||||
osmium::handler::CheckOrder handler;
|
||||
REQUIRE_THROWS_AS(osmium::apply(buffer, handler), const osmium::out_of_order_error&);
|
||||
}
|
||||
|
||||
TEST_CASE("CheckOrder handler: Same id twice is not allowed") {
|
||||
osmium::memory::Buffer buffer{1024};
|
||||
|
||||
REQUIRE(osmium::opl_parse("n3", buffer));
|
||||
REQUIRE(osmium::opl_parse("n3", buffer));
|
||||
|
||||
osmium::handler::CheckOrder handler;
|
||||
REQUIRE_THROWS_AS(osmium::apply(buffer, handler), const osmium::out_of_order_error&);
|
||||
}
|
||||
|
||||
TEST_CASE("CheckOrder handler: Nodes after ways") {
|
||||
osmium::memory::Buffer buffer{1024};
|
||||
|
||||
REQUIRE(osmium::opl_parse("w50", buffer));
|
||||
SECTION("Positive ID") {
|
||||
REQUIRE(osmium::opl_parse("n30", buffer));
|
||||
}
|
||||
SECTION("Negative ID") {
|
||||
REQUIRE(osmium::opl_parse("n-30", buffer));
|
||||
}
|
||||
|
||||
osmium::handler::CheckOrder handler;
|
||||
REQUIRE_THROWS_AS(osmium::apply(buffer, handler), const osmium::out_of_order_error&);
|
||||
}
|
||||
|
||||
TEST_CASE("CheckOrder handler: Nodes after relations") {
|
||||
osmium::memory::Buffer buffer{1024};
|
||||
|
||||
REQUIRE(osmium::opl_parse("r50", buffer));
|
||||
SECTION("Positive ID") {
|
||||
REQUIRE(osmium::opl_parse("n30", buffer));
|
||||
}
|
||||
SECTION("Negative ID") {
|
||||
REQUIRE(osmium::opl_parse("n-30", buffer));
|
||||
}
|
||||
|
||||
osmium::handler::CheckOrder handler;
|
||||
REQUIRE_THROWS_AS(osmium::apply(buffer, handler), const osmium::out_of_order_error&);
|
||||
}
|
||||
|
||||
TEST_CASE("CheckOrder handler: Ways after relations") {
|
||||
osmium::memory::Buffer buffer{1024};
|
||||
|
||||
REQUIRE(osmium::opl_parse("r50", buffer));
|
||||
SECTION("Positive ID") {
|
||||
REQUIRE(osmium::opl_parse("w30", buffer));
|
||||
}
|
||||
SECTION("Negative ID") {
|
||||
REQUIRE(osmium::opl_parse("w-30", buffer));
|
||||
}
|
||||
|
||||
osmium::handler::CheckOrder handler;
|
||||
REQUIRE_THROWS_AS(osmium::apply(buffer, handler), const osmium::out_of_order_error&);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/dynamic_handler.hpp>
|
||||
#include <osmium/builder/attr.hpp>
|
||||
#include <osmium/visitor.hpp>
|
||||
|
||||
struct Handler1 : public osmium::handler::Handler {
|
||||
|
||||
int& count;
|
||||
|
||||
explicit Handler1(int& c) :
|
||||
count(c) {
|
||||
}
|
||||
|
||||
void node(const osmium::Node&) noexcept {
|
||||
++count;
|
||||
}
|
||||
|
||||
void way(const osmium::Way&) noexcept {
|
||||
++count;
|
||||
}
|
||||
|
||||
void relation(const osmium::Relation&) noexcept {
|
||||
++count;
|
||||
}
|
||||
|
||||
void area(const osmium::Area&) noexcept {
|
||||
++count;
|
||||
}
|
||||
|
||||
void changeset(const osmium::Changeset&) noexcept {
|
||||
++count;
|
||||
}
|
||||
|
||||
void flush() noexcept {
|
||||
++count;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
struct Handler2 : public osmium::handler::Handler {
|
||||
|
||||
int& count;
|
||||
|
||||
explicit Handler2(int& c) :
|
||||
count(c) {
|
||||
}
|
||||
|
||||
void node(const osmium::Node&) noexcept {
|
||||
count += 2;
|
||||
}
|
||||
|
||||
void way(const osmium::Way&) noexcept {
|
||||
count += 2;
|
||||
}
|
||||
|
||||
void relation(const osmium::Relation&) noexcept {
|
||||
count += 2;
|
||||
}
|
||||
|
||||
void area(const osmium::Area&) noexcept {
|
||||
count += 2;
|
||||
}
|
||||
|
||||
void changeset(const osmium::Changeset&) noexcept {
|
||||
count += 2;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
osmium::memory::Buffer fill_buffer() {
|
||||
using namespace osmium::builder::attr;
|
||||
osmium::memory::Buffer buffer{1024 * 1024, osmium::memory::Buffer::auto_grow::yes};
|
||||
|
||||
osmium::builder::add_node(buffer, _id(1));
|
||||
osmium::builder::add_way(buffer, _id(2));
|
||||
osmium::builder::add_relation(buffer, _id(3));
|
||||
osmium::builder::add_area(buffer, _id(4));
|
||||
osmium::builder::add_changeset(buffer, _cid(5));
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
TEST_CASE("Base test: static handler") {
|
||||
const auto buffer = fill_buffer();
|
||||
|
||||
int count = 0;
|
||||
Handler1 h1{count};
|
||||
osmium::apply(buffer, h1);
|
||||
REQUIRE(count == 6);
|
||||
|
||||
count = 0;
|
||||
Handler2 h2{count};
|
||||
osmium::apply(buffer, h2);
|
||||
REQUIRE(count == 10);
|
||||
}
|
||||
|
||||
TEST_CASE("Dynamic handler") {
|
||||
const auto buffer = fill_buffer();
|
||||
|
||||
osmium::handler::DynamicHandler handler;
|
||||
int count = 0;
|
||||
|
||||
osmium::apply(buffer, handler);
|
||||
REQUIRE(count == 0);
|
||||
|
||||
handler.set<Handler1>(count);
|
||||
osmium::apply(buffer, handler);
|
||||
REQUIRE(count == 6);
|
||||
|
||||
count = 0;
|
||||
handler.set<Handler2>(count);
|
||||
osmium::apply(buffer, handler);
|
||||
REQUIRE(count == 10);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user