refactor timezoner a bit for unit tests, add initial unit tests

This commit is contained in:
karenzshea
2017-05-29 23:07:03 +02:00
parent f268163ea0
commit ca353eb7db
6 changed files with 232 additions and 77 deletions
+20 -7
View File
@@ -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)
+38
View File
@@ -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
]
], []
]
}
}
]
}
+62
View File
@@ -0,0 +1,62 @@
#include "util/exception.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);
// missing features list
const char missing_features[] =
"{ \"type\" : \"FeatureCollection\", \"features\": null }";
BOOST_CHECK_THROW(Timezoner tz(missing_features, now), util::exception);
}
BOOST_AUTO_TEST_SUITE_END()
+7
View File
@@ -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.
*/