refactor timezoner a bit for unit tests, add initial unit tests
This commit is contained in:
@@ -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,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()
|
||||
Reference in New Issue
Block a user