upgrade libosmium dependency
This commit is contained in:
+3
@@ -109,6 +109,9 @@ add_unit_test(tags test_filter)
|
||||
add_unit_test(tags test_operators)
|
||||
add_unit_test(tags test_tag_list)
|
||||
|
||||
add_unit_test(thread test_pool ${Threads_FOUND} ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
||||
add_unit_test(util test_cast_with_assert)
|
||||
add_unit_test(util test_double)
|
||||
add_unit_test(util test_options)
|
||||
add_unit_test(util test_string)
|
||||
|
||||
+19
-22
@@ -87,32 +87,29 @@ set_tests_properties(testdata-overview PROPERTIES
|
||||
# multipolygon
|
||||
#
|
||||
#-----------------------------------------------------------------------------
|
||||
add_executable(testdata-multipolygon testdata-multipolygon.cpp)
|
||||
target_link_libraries(testdata-multipolygon
|
||||
${OSMIUM_XML_LIBRARIES}
|
||||
${GDAL_LIBRARIES}
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
set(MULTIPOLYGON_TEST_SCRIPT "run-testdata-multipolygon.bat")
|
||||
find_package(Ruby 1.9)
|
||||
find_package(Gem COMPONENTS json)
|
||||
find_program(SPATIALITE spatialite)
|
||||
|
||||
if(RUBY_FOUND AND GEM_json_FOUND AND SPATIALITE)
|
||||
add_executable(testdata-multipolygon testdata-multipolygon.cpp)
|
||||
target_link_libraries(testdata-multipolygon
|
||||
${OSMIUM_XML_LIBRARIES}
|
||||
${GDAL_LIBRARIES}
|
||||
)
|
||||
|
||||
add_test(NAME testdata-multipolygon
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-D OSM_TESTDATA=${OSM_TESTDATA}
|
||||
-D RUBY=${RUBY_EXECUTABLE}
|
||||
-P ${CMAKE_CURRENT_SOURCE_DIR}/run-testdata-multipolygon.cmake)
|
||||
|
||||
set_tests_properties(testdata-multipolygon PROPERTIES LABELS "data;slow")
|
||||
else()
|
||||
set(MULTIPOLYGON_TEST_SCRIPT "run-testdata-multipolygon.sh")
|
||||
message(WARNING "Disabled testdata-multipolygon test because 'ruby' and/or 'json' ruby gem and/or 'spatialite' was not found")
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
set(EXE_DIR ${CMAKE_BUILD_TYPE})
|
||||
else()
|
||||
set(EXE_DIR .)
|
||||
endif()
|
||||
|
||||
add_test(NAME testdata-multipolygon
|
||||
COMMAND ${CMAKE_SOURCE_DIR}/test/data-tests/${MULTIPOLYGON_TEST_SCRIPT}
|
||||
${OSM_TESTDATA}
|
||||
${EXE_DIR}
|
||||
)
|
||||
set_tests_properties(testdata-multipolygon PROPERTIES
|
||||
LABELS "data;slow")
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
message(STATUS "Configuring data tests - done")
|
||||
|
||||
+2
-15
@@ -5,19 +5,6 @@ repository at https://github.com/osmcode/osm-testdata . To use it, clone
|
||||
the `osm-testdata` repository in the same directory where you cloned the
|
||||
`libosmium` repository.
|
||||
|
||||
## Overview
|
||||
|
||||
The `testdata-overview` program can be used to create a Spatialite file
|
||||
containing all the nodes and ways from the test data files.
|
||||
|
||||
Compile it by running `make testdata-overview`, run it my calling
|
||||
`make overview`.
|
||||
|
||||
## Running the Tests
|
||||
|
||||
Actual tests are in `testcases` subdirectory, one per test from the
|
||||
osm-testdata repository.
|
||||
|
||||
To compile the tests, call `make runtests`, to run them call
|
||||
`make test`.
|
||||
Tests will be built if the CMake option `BUILD_DATA_TESTS` is set and run as
|
||||
part of the `ctest` run.
|
||||
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
set TESTDATA_DIR=%1
|
||||
|
||||
del multipolygon.db multipolygon-tests.json
|
||||
%2\testdata-multipolygon %TESTDATA_DIR%\grid\data\all.osm >multipolygon.log 2>&1
|
||||
if ERRORLEVEL 1 (exit /b 1)
|
||||
ruby %TESTDATA_DIR%\bin\compare-areas.rb %TESTDATA_DIR%\grid\data\tests.json multipolygon-tests.json
|
||||
if ERRORLEVEL 1 (exit /b 1)
|
||||
@@ -0,0 +1,46 @@
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
# Helper script that runs the 'multipolygon' test.
|
||||
#
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
# Remove files that might be left over from previous run
|
||||
file(REMOVE multipolygon.db multipolygon-tests.json)
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
# Create multipolygons from test data.
|
||||
#
|
||||
#-----------------------------------------------------------------------------
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/testdata-multipolygon
|
||||
${OSM_TESTDATA}/grid/data/all.osm
|
||||
RESULT_VARIABLE _result
|
||||
OUTPUT_FILE multipolygon.log
|
||||
ERROR_FILE multipolygon.log
|
||||
)
|
||||
|
||||
if(_result)
|
||||
message(FATAL_ERROR "Error running testdata-multipolygon command")
|
||||
endif()
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
# Compare created multipolygons with reference data.
|
||||
#
|
||||
#-----------------------------------------------------------------------------
|
||||
execute_process(
|
||||
COMMAND ${RUBY} ${OSM_TESTDATA}/bin/compare-areas.rb
|
||||
${OSM_TESTDATA}/grid/data/tests.json
|
||||
multipolygon-tests.json
|
||||
RESULT_VARIABLE _result
|
||||
)
|
||||
|
||||
if(_result)
|
||||
message(FATAL_ERROR "Error running compare-areas command")
|
||||
endif()
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
@@ -1,10 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# helper script needed by cmake to run test
|
||||
|
||||
TESTDATA_DIR=$1
|
||||
|
||||
rm -f multipolygon.db multipolygon-tests.json
|
||||
./testdata-multipolygon ${TESTDATA_DIR}/grid/data/all.osm >multipolygon.log 2>&1 &&
|
||||
${TESTDATA_DIR}/bin/compare-areas.rb ${TESTDATA_DIR}/grid/data/tests.json multipolygon-tests.json
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ std::string read_file(const char* test_id) {
|
||||
assert(fd >= 0);
|
||||
|
||||
std::string input(10000, '\0');
|
||||
ssize_t n = ::read(fd, reinterpret_cast<unsigned char*>(const_cast<char*>(input.data())), 10000);
|
||||
auto n = ::read(fd, reinterpret_cast<unsigned char*>(const_cast<char*>(input.data())), 10000);
|
||||
assert(n >= 0);
|
||||
input.resize(static_cast<std::string::size_type>(n));
|
||||
|
||||
|
||||
@@ -108,6 +108,8 @@ SECTION("DenseFileArray") {
|
||||
test_func_real<index_type>(index2);
|
||||
}
|
||||
|
||||
#ifdef OSMIUM_WITH_SPARSEHASH
|
||||
|
||||
SECTION("SparseMemTable") {
|
||||
typedef osmium::index::map::SparseMemTable<osmium::unsigned_object_id_type, osmium::Location> index_type;
|
||||
|
||||
@@ -118,6 +120,8 @@ SECTION("SparseMemTable") {
|
||||
test_func_real<index_type>(index2);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
SECTION("SparseMemMap") {
|
||||
typedef osmium::index::map::SparseMemMap<osmium::unsigned_object_id_type, osmium::Location> index_type;
|
||||
|
||||
|
||||
+8
-4
@@ -53,10 +53,9 @@ SECTION("Remap") {
|
||||
|
||||
SECTION("FileSize") {
|
||||
const int size = 100;
|
||||
char filename[] = "/tmp/osmium_unit_test_XXXXXX";
|
||||
char filename[] = "test_mmap_file_size_XXXXXX";
|
||||
const int fd = mkstemp(filename);
|
||||
REQUIRE(fd > 0);
|
||||
REQUIRE(0 == unlink(filename));
|
||||
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));
|
||||
@@ -69,14 +68,16 @@ SECTION("FileSize") {
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
SECTION("GrowAndMap") {
|
||||
const int size = 100;
|
||||
char filename[] = "/tmp/osmium_unit_test_XXXXXX";
|
||||
char filename[] = "test_mmap_grow_and_map_XXXXXX";
|
||||
const int fd = mkstemp(filename);
|
||||
REQUIRE(fd > 0);
|
||||
REQUIRE(0 == unlink(filename));
|
||||
|
||||
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));
|
||||
@@ -90,6 +91,9 @@ SECTION("GrowAndMap") {
|
||||
REQUIRE(27ul == data[99]);
|
||||
|
||||
osmium::detail::typed_mmap<uint64_t>::unmap(data, size);
|
||||
|
||||
REQUIRE(0 == close(fd));
|
||||
REQUIRE(0 == unlink(filename));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-3
@@ -65,7 +65,7 @@ TEST_CASE("Reader") {
|
||||
|
||||
const size_t buffer_size = 1000;
|
||||
char buffer[buffer_size];
|
||||
ssize_t length = ::read(fd, buffer, buffer_size);
|
||||
auto length = ::read(fd, buffer, buffer_size);
|
||||
REQUIRE(length > 0);
|
||||
|
||||
osmium::io::File file(buffer, static_cast<size_t>(length), "osm");
|
||||
@@ -83,7 +83,7 @@ TEST_CASE("Reader") {
|
||||
|
||||
const size_t buffer_size = 1000;
|
||||
char buffer[buffer_size];
|
||||
ssize_t length = ::read(fd, buffer, buffer_size);
|
||||
auto length = ::read(fd, buffer, buffer_size);
|
||||
REQUIRE(length > 0);
|
||||
|
||||
osmium::io::File file(buffer, static_cast<size_t>(length), "osm.gz");
|
||||
@@ -101,7 +101,7 @@ TEST_CASE("Reader") {
|
||||
|
||||
const size_t buffer_size = 1000;
|
||||
char buffer[buffer_size];
|
||||
ssize_t length = ::read(fd, buffer, buffer_size);
|
||||
auto length = ::read(fd, buffer, buffer_size);
|
||||
REQUIRE(length > 0);
|
||||
|
||||
osmium::io::File file(buffer, static_cast<size_t>(length), "osm.bz2");
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <chrono>
|
||||
#include <stdexcept>
|
||||
#include <thread>
|
||||
|
||||
#include <osmium/thread/pool.hpp>
|
||||
|
||||
static std::atomic<int> result;
|
||||
|
||||
struct test_job_ok {
|
||||
void operator()() const {
|
||||
result = 1;
|
||||
}
|
||||
};
|
||||
|
||||
struct test_job_with_result {
|
||||
int operator()() const {
|
||||
return 42;
|
||||
}
|
||||
};
|
||||
|
||||
struct test_job_throw {
|
||||
void operator()() const {
|
||||
throw std::runtime_error("exception in pool thread");
|
||||
}
|
||||
};
|
||||
|
||||
TEST_CASE("thread") {
|
||||
|
||||
SECTION("can get access to thread pool") {
|
||||
auto& pool = osmium::thread::Pool::instance();
|
||||
REQUIRE(pool.queue_empty());
|
||||
}
|
||||
|
||||
SECTION("can send job to thread pool") {
|
||||
auto& pool = osmium::thread::Pool::instance();
|
||||
result = 0;
|
||||
auto future = pool.submit(test_job_ok{});
|
||||
|
||||
// wait a bit for the other thread to get a chance to run
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
|
||||
REQUIRE(result == 1);
|
||||
|
||||
future.get();
|
||||
|
||||
REQUIRE(true);
|
||||
}
|
||||
|
||||
SECTION("can send job to thread pool") {
|
||||
auto& pool = osmium::thread::Pool::instance();
|
||||
auto future = pool.submit(test_job_with_result{});
|
||||
|
||||
REQUIRE(future.get() == 42);
|
||||
}
|
||||
|
||||
SECTION("can throw from job in thread pool") {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
// Define assert() to throw this error. This enables the tests to check that
|
||||
// the assert() fails.
|
||||
struct assert_error : public std::runtime_error {
|
||||
assert_error(const char* what_arg) : std::runtime_error(what_arg) {
|
||||
}
|
||||
};
|
||||
#define assert(x) if (!(x)) { throw(assert_error(#x)); }
|
||||
|
||||
#include <osmium/util/cast.hpp>
|
||||
|
||||
TEST_CASE("static_cast_with_assert") {
|
||||
|
||||
SECTION("same types is always okay") {
|
||||
int f = 10;
|
||||
auto t = osmium::static_cast_with_assert<int>(f);
|
||||
REQUIRE(t == f);
|
||||
}
|
||||
|
||||
SECTION("casting to larger type is always okay") {
|
||||
int16_t f = 10;
|
||||
auto t = osmium::static_cast_with_assert<int32_t>(f);
|
||||
REQUIRE(t == f);
|
||||
}
|
||||
|
||||
|
||||
SECTION("cast int32_t -> int_16t should not trigger assert for small int") {
|
||||
int32_t f = 100;
|
||||
auto t = osmium::static_cast_with_assert<int16_t>(f);
|
||||
REQUIRE(t == f);
|
||||
}
|
||||
|
||||
SECTION("cast int32_t -> int_16t should trigger assert for large int") {
|
||||
int32_t f = 100000;
|
||||
REQUIRE_THROWS_AS(osmium::static_cast_with_assert<int16_t>(f), assert_error);
|
||||
}
|
||||
|
||||
|
||||
SECTION("cast int16_t -> uint16_t should not trigger assert for zero") {
|
||||
int16_t f = 0;
|
||||
auto t = osmium::static_cast_with_assert<uint16_t>(f);
|
||||
REQUIRE(t == f);
|
||||
}
|
||||
|
||||
SECTION("cast int16_t -> uint16_t should not trigger assert for positive int") {
|
||||
int16_t f = 1;
|
||||
auto t = osmium::static_cast_with_assert<uint16_t>(f);
|
||||
REQUIRE(t == f);
|
||||
}
|
||||
|
||||
SECTION("cast int16_t -> uint16_t should trigger assert for negative int") {
|
||||
int16_t f = -1;
|
||||
REQUIRE_THROWS_AS(osmium::static_cast_with_assert<uint16_t>(f), assert_error);
|
||||
}
|
||||
|
||||
|
||||
SECTION("cast uint32_t -> uint_16t should not trigger assert for zero") {
|
||||
uint32_t f = 0;
|
||||
auto t = osmium::static_cast_with_assert<uint16_t>(f);
|
||||
REQUIRE(t == f);
|
||||
}
|
||||
|
||||
SECTION("cast uint32_t -> uint_16t should not trigger assert for small int") {
|
||||
uint32_t f = 100;
|
||||
auto t = osmium::static_cast_with_assert<uint16_t>(f);
|
||||
REQUIRE(t == f);
|
||||
}
|
||||
|
||||
SECTION("cast int32_t -> int_16t should trigger assert for large int") {
|
||||
uint32_t f = 100000;
|
||||
REQUIRE_THROWS_AS(osmium::static_cast_with_assert<uint16_t>(f), assert_error);
|
||||
}
|
||||
|
||||
|
||||
SECTION("cast uint16_t -> int16_t should not trigger assert for small int") {
|
||||
uint16_t f = 1;
|
||||
auto t = osmium::static_cast_with_assert<int16_t>(f);
|
||||
REQUIRE(t == f);
|
||||
}
|
||||
|
||||
SECTION("cast uint16_t -> int16_t should trigger assert for large int") {
|
||||
uint16_t f = 65000;
|
||||
REQUIRE_THROWS_AS(osmium::static_cast_with_assert<int16_t>(f), assert_error);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user