Merge pull request #4094 from Project-OSRM/refactor/rapidash
Replace timezone shapefile parsing with geojson parsing
This commit is contained in:
@@ -14,6 +14,10 @@ file(GLOB CustomizerTestsSources
|
||||
customizer_tests.cpp
|
||||
customizer/*.cpp)
|
||||
|
||||
file(GLOB UpdaterTestsSources
|
||||
updater_tests.cpp
|
||||
updater/*.cpp)
|
||||
|
||||
file(GLOB LibraryTestsSources
|
||||
library_tests.cpp
|
||||
library/*.cpp)
|
||||
@@ -55,6 +59,11 @@ add_executable(customizer-tests
|
||||
${CustomizerTestsSources}
|
||||
$<TARGET_OBJECTS:CUSTOMIZER> $<TARGET_OBJECTS:UPDATER> $<TARGET_OBJECTS:UTIL>)
|
||||
|
||||
add_executable(updater-tests
|
||||
EXCLUDE_FROM_ALL
|
||||
${UpdaterTestsSources}
|
||||
$<TARGET_OBJECTS:UPDATER> $<TARGET_OBJECTS:UPDATER> $<TARGET_OBJECTS:UTIL>)
|
||||
|
||||
add_executable(library-tests
|
||||
EXCLUDE_FROM_ALL
|
||||
${LibraryTestsSources})
|
||||
@@ -82,6 +91,7 @@ if(NOT WIN32 AND NOT Boost_USE_STATIC_LIBS)
|
||||
add_definitions(-DBOOST_TEST_DYN_LINK)
|
||||
endif()
|
||||
|
||||
set(UPDATER_TEST_DATA_DIR "${CMAKE_SOURCE_DIR}/unit_tests/updater")
|
||||
set(TEST_DATA_DIR "${CMAKE_SOURCE_DIR}/test/data")
|
||||
add_dependencies(library-tests osrm-extract osrm-contract osrm-partition)
|
||||
# We can't run this Makefile on windows
|
||||
@@ -93,6 +103,7 @@ target_compile_definitions(extractor-tests PRIVATE COMPILE_DEFINITIONS OSRM_FIXT
|
||||
target_compile_definitions(library-tests PRIVATE COMPILE_DEFINITIONS OSRM_TEST_DATA_DIR="${TEST_DATA_DIR}")
|
||||
target_compile_definitions(library-extract-tests PRIVATE COMPILE_DEFINITIONS OSRM_TEST_DATA_DIR="${TEST_DATA_DIR}")
|
||||
target_compile_definitions(library-contract-tests PRIVATE COMPILE_DEFINITIONS OSRM_TEST_DATA_DIR="${TEST_DATA_DIR}")
|
||||
target_compile_definitions(updater-tests PRIVATE COMPILE_DEFINITIONS TEST_DATA_DIR="${UPDATER_TEST_DATA_DIR}")
|
||||
|
||||
target_include_directories(engine-tests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_include_directories(library-tests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
@@ -101,16 +112,18 @@ target_include_directories(library-contract-tests PUBLIC ${CMAKE_CURRENT_SOURCE_
|
||||
target_include_directories(util-tests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_include_directories(partition-tests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_include_directories(customizer-tests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_include_directories(updater-tests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
target_link_libraries(engine-tests ${ENGINE_LIBRARIES} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} ${MAYBE_SHAPEFILE})
|
||||
target_link_libraries(extractor-tests ${EXTRACTOR_LIBRARIES} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} ${MAYBE_SHAPEFILE})
|
||||
target_link_libraries(partition-tests ${PARTITIONER_LIBRARIES} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} ${MAYBE_SHAPEFILE})
|
||||
target_link_libraries(customizer-tests ${CUSTOMIZER_LIBRARIES} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} ${MAYBE_SHAPEFILE})
|
||||
target_link_libraries(engine-tests ${ENGINE_LIBRARIES} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
|
||||
target_link_libraries(extractor-tests ${EXTRACTOR_LIBRARIES} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
|
||||
target_link_libraries(partition-tests ${PARTITIONER_LIBRARIES} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
|
||||
target_link_libraries(customizer-tests ${CUSTOMIZER_LIBRARIES} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
|
||||
target_link_libraries(updater-tests ${UPDATER_LIBRARIES} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
|
||||
target_link_libraries(library-tests osrm ${ENGINE_LIBRARIES} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
|
||||
target_link_libraries(library-extract-tests osrm_extract ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
|
||||
target_link_libraries(library-contract-tests osrm_contract ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
|
||||
target_link_libraries(server-tests osrm ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} ${MAYBE_SHAPEFILE})
|
||||
target_link_libraries(util-tests ${UTIL_LIBRARIES} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} ${MAYBE_SHAPEFILE})
|
||||
target_link_libraries(server-tests osrm ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
|
||||
target_link_libraries(util-tests ${UTIL_LIBRARIES} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
|
||||
|
||||
add_custom_target(tests
|
||||
DEPENDS engine-tests extractor-tests partition-tests customizer-tests library-tests library-extract-tests server-tests util-tests)
|
||||
DEPENDS engine-tests extractor-tests partition-tests updater-tests customizer-tests library-tests library-extract-tests server-tests util-tests)
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"type": "FeatureCollection",
|
||||
"features": [
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"TZID": "Europe\\/Berlin"
|
||||
},
|
||||
"geometry": {
|
||||
"type": "Polygon",
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
8.28369140625,
|
||||
48.88277959345126
|
||||
],
|
||||
[
|
||||
8.57757568359375,
|
||||
48.88277959345126
|
||||
],
|
||||
[
|
||||
8.57757568359375,
|
||||
49.07206662261101
|
||||
],
|
||||
[
|
||||
8.28369140625,
|
||||
49.07206662261101
|
||||
],
|
||||
[
|
||||
8.28369140625,
|
||||
48.88277959345126
|
||||
]
|
||||
], []
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
#include "util/exception.hpp"
|
||||
#include "util/geojson_validation.hpp"
|
||||
#include "util/timezones.hpp"
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(timezoner)
|
||||
|
||||
using namespace osrm;
|
||||
using namespace osrm::updater;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(timezoner_test)
|
||||
{
|
||||
const char json[] =
|
||||
"{ \"type\" : \"FeatureCollection\", \"features\": ["
|
||||
"{ \"type\" : \"Feature\","
|
||||
"\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometry\" : { \"type\": \"polygon\", "
|
||||
"\"coordinates\": [[[8.28369,48.88277], [8.57757, "
|
||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||
"49.07206], [8.28369, 48.88277]]] }} ]}";
|
||||
std::time_t now = time(0);
|
||||
BOOST_CHECK_NO_THROW(Timezoner tz(json, now));
|
||||
|
||||
boost::filesystem::path test_path(TEST_DATA_DIR "/test.geojson");
|
||||
BOOST_CHECK_NO_THROW(Timezoner tz(test_path, now));
|
||||
|
||||
// missing opening bracket
|
||||
const char bad[] =
|
||||
"\"type\" : \"FeatureCollection\", \"features\": ["
|
||||
"{ \"type\" : \"Feature\","
|
||||
"\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometry\" : { \"type\": \"polygon\", "
|
||||
"\"coordinates\": [[[8.28369,48.88277], [8.57757, "
|
||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||
"49.07206], [8.28369, 48.88277]]] }} ]}";
|
||||
BOOST_CHECK_THROW(Timezoner tz(bad, now), util::exception);
|
||||
|
||||
// missing/malformed FeatureCollection type field
|
||||
const char missing_type[] =
|
||||
"{ \"FeatureCollection\", \"features\": ["
|
||||
"{ \"type\" : \"Feature\","
|
||||
"\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometry\" : { \"type\": \"polygon\", "
|
||||
"\"coordinates\": [[[8.28369,48.88277], [8.57757, "
|
||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||
"49.07206], [8.28369, 48.88277]]] }} ]}";
|
||||
BOOST_CHECK_THROW(Timezoner tz(missing_type, now), util::exception);
|
||||
|
||||
const char missing_featc[] =
|
||||
"{ \"type\" : \"Collection\", \"features\": ["
|
||||
"{ \"type\" : \"Feature\","
|
||||
"\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometry\" : { \"type\": \"polygon\", "
|
||||
"\"coordinates\": [[[8.28369,48.88277], [8.57757, "
|
||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||
"49.07206], [8.28369, 48.88277]]] }} ]}";
|
||||
BOOST_CHECK_THROW(Timezoner tz(missing_featc, now), util::exception);
|
||||
}
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
@@ -0,0 +1,138 @@
|
||||
#include "util/exception.hpp"
|
||||
#include "util/geojson_validation.hpp"
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(geojson_validation)
|
||||
|
||||
using namespace osrm;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(timezone_coordinate_validation_test)
|
||||
{
|
||||
rapidjson::Document doc;
|
||||
char valid_coord[] = "[8.28369,48.88277]";
|
||||
doc.Parse(valid_coord);
|
||||
BOOST_CHECK_NO_THROW(util::validateCoordinate(doc));
|
||||
|
||||
char non_array[] = "{\"x\": 48.88277}";
|
||||
doc.Parse(non_array);
|
||||
BOOST_CHECK_THROW(util::validateCoordinate(doc), util::exception);
|
||||
|
||||
char too_many[] = "[8.28369, 48.88277, 8.2806]";
|
||||
doc.Parse(too_many);
|
||||
BOOST_CHECK_THROW(util::validateCoordinate(doc), util::exception);
|
||||
|
||||
char nan[] = "[8.28369, y]";
|
||||
doc.Parse(nan);
|
||||
BOOST_CHECK_THROW(util::validateCoordinate(doc), util::exception);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(timezone_validation_test)
|
||||
{
|
||||
char json[] =
|
||||
"{ \"type\" : \"Feature\","
|
||||
"\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometry\" : { \"type\": \"polygon\", "
|
||||
"\"coordinates\": [[[8.28369,48.88277], [8.57757, "
|
||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||
"49.07206], [8.28369, 48.88277]]] }}";
|
||||
rapidjson::Document doc;
|
||||
doc.Parse(json);
|
||||
BOOST_CHECK_NO_THROW(util::validateFeature(doc));
|
||||
|
||||
char missing_type[] = "{\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometry\" : { "
|
||||
"\"type\": \"polygon\", "
|
||||
"\"coordinates\": [[[8.28369,48.88277], [8.57757, "
|
||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||
"49.07206], [8.28369, 48.88277]]] }}";
|
||||
doc.Parse(missing_type);
|
||||
BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
|
||||
|
||||
char missing_props[] =
|
||||
"{ \"type\" : \"Feature\","
|
||||
"\"props\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometry\" : { \"type\": \"polygon\", "
|
||||
"\"coordinates\": [[[8.28369,48.88277], [8.57757, "
|
||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||
"49.07206], [8.28369, 48.88277]]] }}";
|
||||
doc.Parse(missing_props);
|
||||
BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
|
||||
|
||||
char nonobj_props[] =
|
||||
"{ \"type\" : \"Feature\","
|
||||
"\"properties\" : [ \"TZID\", \"Europe/Berlin\"], \"geometry\" : { \"type\": \"polygon\", "
|
||||
"\"coordinates\": [[[8.28369,48.88277], [8.57757, "
|
||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||
"49.07206], [8.28369, 48.88277]]] }}";
|
||||
doc.Parse(nonobj_props);
|
||||
BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
|
||||
|
||||
char missing_tzid[] = "{ \"type\" : \"Feature\","
|
||||
"\"properties\" : { }, \"geometry\" : { \"type\": \"polygon\", "
|
||||
"\"coordinates\": [[[8.28369,48.88277], [8.57757, "
|
||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||
"49.07206], [8.28369, 48.88277]]] }}";
|
||||
doc.Parse(missing_tzid);
|
||||
BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
|
||||
|
||||
char tzid_err[] = "{ \"type\" : \"Feature\","
|
||||
"\"properties\" : { \"TZID\" : []}, \"geometry\" : { \"type\": \"polygon\", "
|
||||
"\"coordinates\": [[[8.28369,48.88277], [8.57757, "
|
||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||
"49.07206], [8.28369, 48.88277]]] }}";
|
||||
doc.Parse(tzid_err);
|
||||
BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
|
||||
|
||||
char missing_geom[] = "{ \"type\" : \"Feature\","
|
||||
"\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometries\" : { "
|
||||
"\"type\": \"polygon\", "
|
||||
"\"coordinates\": [[[8.28369,48.88277], [8.57757, "
|
||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||
"49.07206], [8.28369, 48.88277]]] }}";
|
||||
doc.Parse(missing_geom);
|
||||
BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
|
||||
|
||||
char nonobj_geom[] =
|
||||
"{ \"type\" : \"Feature\","
|
||||
"\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometry\" : [ \"type\", \"polygon\", "
|
||||
"\"coordinates\", [[[8.28369,48.88277], [8.57757, "
|
||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||
"49.07206], [8.28369, 48.88277]]] ]}";
|
||||
doc.Parse(nonobj_geom);
|
||||
BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
|
||||
|
||||
char missing_geom_type[] = "{ \"type\" : \"Feature\","
|
||||
"\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometry\" : { "
|
||||
"\"no_type\": \"polygon\", "
|
||||
"\"coordinates\": [[[8.28369,48.88277], [8.57757, "
|
||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||
"49.07206], [8.28369, 48.88277]]] }}";
|
||||
doc.Parse(missing_geom_type);
|
||||
BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
|
||||
|
||||
char nonstring_geom_type[] = "{ \"type\" : \"Feature\","
|
||||
"\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometry\" : "
|
||||
"{ \"type\": [\"polygon\"], "
|
||||
"\"coordinates\": [[[8.28369,48.88277], [8.57757, "
|
||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||
"49.07206], [8.28369, 48.88277]]] }}";
|
||||
doc.Parse(nonstring_geom_type);
|
||||
BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
|
||||
|
||||
char missing_coords[] =
|
||||
"{ \"type\" : \"Feature\","
|
||||
"\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometry\" : { \"type\": \"polygon\", "
|
||||
"\"coords\": [[[8.28369,48.88277], [8.57757, "
|
||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||
"49.07206], [8.28369, 48.88277]]] }}";
|
||||
doc.Parse(missing_coords);
|
||||
BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
|
||||
|
||||
char missing_outerring[] =
|
||||
"{ \"type\" : \"Feature\","
|
||||
"\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometry\" : { \"type\": \"polygon\", "
|
||||
"\"coordinates\": [[8.28369,48.88277], [8.57757, "
|
||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||
"49.07206], [8.28369, 48.88277]] }}";
|
||||
doc.Parse(missing_outerring);
|
||||
BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
|
||||
}
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
@@ -0,0 +1,7 @@
|
||||
#define BOOST_TEST_MODULE customizer tests
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
/*
|
||||
* This file will contain an automatically generated main function.
|
||||
*/
|
||||
Reference in New Issue
Block a user