Fix PR comments
This commit is contained in:
parent
879de346ea
commit
10460fc2fb
@ -11,7 +11,7 @@ namespace osrm
|
|||||||
namespace util
|
namespace util
|
||||||
{
|
{
|
||||||
|
|
||||||
inline void ValidateCoordinate(const rapidjson::Value &coordinate)
|
inline void validateCoordinate(const rapidjson::Value &coordinate)
|
||||||
{
|
{
|
||||||
if (!coordinate.IsArray())
|
if (!coordinate.IsArray())
|
||||||
throw osrm::util::exception("Feature geometry has a non-array coordinate.");
|
throw osrm::util::exception("Feature geometry has a non-array coordinate.");
|
||||||
@ -30,7 +30,7 @@ inline void ValidateCoordinate(const rapidjson::Value &coordinate)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void ValidateFeature(const rapidjson::Value &feature)
|
inline void validateFeature(const rapidjson::Value &feature)
|
||||||
{
|
{
|
||||||
if (!feature.HasMember("type"))
|
if (!feature.HasMember("type"))
|
||||||
{
|
{
|
||||||
|
@ -107,7 +107,7 @@ void Timezoner::LoadLocalTimesRTree(rapidjson::Document &geojson, std::time_t ut
|
|||||||
std::vector<rtree_t::value_type> polygons;
|
std::vector<rtree_t::value_type> polygons;
|
||||||
for (rapidjson::SizeType i = 0; i < features_array.Size(); i++)
|
for (rapidjson::SizeType i = 0; i < features_array.Size(); i++)
|
||||||
{
|
{
|
||||||
util::ValidateFeature(features_array[i]);
|
util::validateFeature(features_array[i]);
|
||||||
// time zone geojson specific checks
|
// time zone geojson specific checks
|
||||||
if (!features_array[i]["properties"].GetObject().HasMember("TZID") &&
|
if (!features_array[i]["properties"].GetObject().HasMember("TZID") &&
|
||||||
!features_array[i]["properties"].GetObject().HasMember("tzid"))
|
!features_array[i]["properties"].GetObject().HasMember("tzid"))
|
||||||
@ -134,7 +134,7 @@ void Timezoner::LoadLocalTimesRTree(rapidjson::Document &geojson, std::time_t ut
|
|||||||
.GetArray();
|
.GetArray();
|
||||||
for (rapidjson::SizeType i = 0; i < coords_outer_array.Size(); ++i)
|
for (rapidjson::SizeType i = 0; i < coords_outer_array.Size(); ++i)
|
||||||
{
|
{
|
||||||
util::ValidateCoordinate(coords_outer_array[i]);
|
util::validateCoordinate(coords_outer_array[i]);
|
||||||
const auto &coords = coords_outer_array[i].GetArray();
|
const auto &coords = coords_outer_array[i].GetArray();
|
||||||
polygon.outer().emplace_back(coords[0].GetDouble(), coords[1].GetDouble());
|
polygon.outer().emplace_back(coords[0].GetDouble(), coords[1].GetDouble());
|
||||||
}
|
}
|
||||||
@ -142,7 +142,7 @@ void Timezoner::LoadLocalTimesRTree(rapidjson::Document &geojson, std::time_t ut
|
|||||||
local_times.size());
|
local_times.size());
|
||||||
|
|
||||||
// Get time zone name and emplace polygon and local time for the UTC input
|
// Get time zone name and emplace polygon and local time for the UTC input
|
||||||
const auto tzname =
|
const auto &tzname =
|
||||||
features_array[i].GetObject()["properties"].GetObject()["tzid"].GetString();
|
features_array[i].GetObject()["properties"].GetObject()["tzid"].GetString();
|
||||||
local_times.push_back(local_time_t{polygon, get_local_time_in_tz(tzname)});
|
local_times.push_back(local_time_t{polygon, get_local_time_in_tz(tzname)});
|
||||||
}
|
}
|
||||||
|
@ -12,19 +12,19 @@ BOOST_AUTO_TEST_CASE(timezone_coordinate_validation_test)
|
|||||||
rapidjson::Document doc;
|
rapidjson::Document doc;
|
||||||
char valid_coord[] = "[8.28369,48.88277]";
|
char valid_coord[] = "[8.28369,48.88277]";
|
||||||
doc.Parse(valid_coord);
|
doc.Parse(valid_coord);
|
||||||
BOOST_CHECK_NO_THROW(util::ValidateCoordinate(doc));
|
BOOST_CHECK_NO_THROW(util::validateCoordinate(doc));
|
||||||
|
|
||||||
char non_array[] = "{\"x\": 48.88277}";
|
char non_array[] = "{\"x\": 48.88277}";
|
||||||
doc.Parse(non_array);
|
doc.Parse(non_array);
|
||||||
BOOST_CHECK_THROW(util::ValidateCoordinate(doc), util::exception);
|
BOOST_CHECK_THROW(util::validateCoordinate(doc), util::exception);
|
||||||
|
|
||||||
char too_many[] = "[8.28369, 48.88277, 8.2806]";
|
char too_many[] = "[8.28369, 48.88277, 8.2806]";
|
||||||
doc.Parse(too_many);
|
doc.Parse(too_many);
|
||||||
BOOST_CHECK_THROW(util::ValidateCoordinate(doc), util::exception);
|
BOOST_CHECK_THROW(util::validateCoordinate(doc), util::exception);
|
||||||
|
|
||||||
char nan[] = "[8.28369, y]";
|
char nan[] = "[8.28369, y]";
|
||||||
doc.Parse(nan);
|
doc.Parse(nan);
|
||||||
BOOST_CHECK_THROW(util::ValidateCoordinate(doc), util::exception);
|
BOOST_CHECK_THROW(util::validateCoordinate(doc), util::exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(timezone_validation_test)
|
BOOST_AUTO_TEST_CASE(timezone_validation_test)
|
||||||
@ -37,7 +37,7 @@ BOOST_AUTO_TEST_CASE(timezone_validation_test)
|
|||||||
"49.07206], [8.28369, 48.88277]]] }}";
|
"49.07206], [8.28369, 48.88277]]] }}";
|
||||||
rapidjson::Document doc;
|
rapidjson::Document doc;
|
||||||
doc.Parse(json);
|
doc.Parse(json);
|
||||||
BOOST_CHECK_NO_THROW(util::ValidateFeature(doc));
|
BOOST_CHECK_NO_THROW(util::validateFeature(doc));
|
||||||
|
|
||||||
char missing_type[] = "{\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometry\" : { "
|
char missing_type[] = "{\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometry\" : { "
|
||||||
"\"type\": \"polygon\", "
|
"\"type\": \"polygon\", "
|
||||||
@ -45,7 +45,7 @@ BOOST_AUTO_TEST_CASE(timezone_validation_test)
|
|||||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||||
"49.07206], [8.28369, 48.88277]]] }}";
|
"49.07206], [8.28369, 48.88277]]] }}";
|
||||||
doc.Parse(missing_type);
|
doc.Parse(missing_type);
|
||||||
BOOST_CHECK_THROW(util::ValidateFeature(doc), util::exception);
|
BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
|
||||||
|
|
||||||
char missing_props[] =
|
char missing_props[] =
|
||||||
"{ \"type\" : \"Feature\","
|
"{ \"type\" : \"Feature\","
|
||||||
@ -54,7 +54,7 @@ BOOST_AUTO_TEST_CASE(timezone_validation_test)
|
|||||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||||
"49.07206], [8.28369, 48.88277]]] }}";
|
"49.07206], [8.28369, 48.88277]]] }}";
|
||||||
doc.Parse(missing_props);
|
doc.Parse(missing_props);
|
||||||
BOOST_CHECK_THROW(util::ValidateFeature(doc), util::exception);
|
BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
|
||||||
|
|
||||||
char nonobj_props[] =
|
char nonobj_props[] =
|
||||||
"{ \"type\" : \"Feature\","
|
"{ \"type\" : \"Feature\","
|
||||||
@ -63,7 +63,7 @@ BOOST_AUTO_TEST_CASE(timezone_validation_test)
|
|||||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||||
"49.07206], [8.28369, 48.88277]]] }}";
|
"49.07206], [8.28369, 48.88277]]] }}";
|
||||||
doc.Parse(nonobj_props);
|
doc.Parse(nonobj_props);
|
||||||
BOOST_CHECK_THROW(util::ValidateFeature(doc), util::exception);
|
BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
|
||||||
|
|
||||||
char missing_tzid[] = "{ \"type\" : \"Feature\","
|
char missing_tzid[] = "{ \"type\" : \"Feature\","
|
||||||
"\"properties\" : { }, \"geometry\" : { \"type\": \"polygon\", "
|
"\"properties\" : { }, \"geometry\" : { \"type\": \"polygon\", "
|
||||||
@ -71,7 +71,7 @@ BOOST_AUTO_TEST_CASE(timezone_validation_test)
|
|||||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||||
"49.07206], [8.28369, 48.88277]]] }}";
|
"49.07206], [8.28369, 48.88277]]] }}";
|
||||||
doc.Parse(missing_tzid);
|
doc.Parse(missing_tzid);
|
||||||
BOOST_CHECK_THROW(util::ValidateFeature(doc), util::exception);
|
BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
|
||||||
|
|
||||||
char tzid_err[] = "{ \"type\" : \"Feature\","
|
char tzid_err[] = "{ \"type\" : \"Feature\","
|
||||||
"\"properties\" : { \"TZID\" : []}, \"geometry\" : { \"type\": \"polygon\", "
|
"\"properties\" : { \"TZID\" : []}, \"geometry\" : { \"type\": \"polygon\", "
|
||||||
@ -79,7 +79,7 @@ BOOST_AUTO_TEST_CASE(timezone_validation_test)
|
|||||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||||
"49.07206], [8.28369, 48.88277]]] }}";
|
"49.07206], [8.28369, 48.88277]]] }}";
|
||||||
doc.Parse(tzid_err);
|
doc.Parse(tzid_err);
|
||||||
BOOST_CHECK_THROW(util::ValidateFeature(doc), util::exception);
|
BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
|
||||||
|
|
||||||
char missing_geom[] = "{ \"type\" : \"Feature\","
|
char missing_geom[] = "{ \"type\" : \"Feature\","
|
||||||
"\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometries\" : { "
|
"\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometries\" : { "
|
||||||
@ -88,7 +88,7 @@ BOOST_AUTO_TEST_CASE(timezone_validation_test)
|
|||||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||||
"49.07206], [8.28369, 48.88277]]] }}";
|
"49.07206], [8.28369, 48.88277]]] }}";
|
||||||
doc.Parse(missing_geom);
|
doc.Parse(missing_geom);
|
||||||
BOOST_CHECK_THROW(util::ValidateFeature(doc), util::exception);
|
BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
|
||||||
|
|
||||||
char nonobj_geom[] =
|
char nonobj_geom[] =
|
||||||
"{ \"type\" : \"Feature\","
|
"{ \"type\" : \"Feature\","
|
||||||
@ -97,7 +97,7 @@ BOOST_AUTO_TEST_CASE(timezone_validation_test)
|
|||||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||||
"49.07206], [8.28369, 48.88277]]] ]}";
|
"49.07206], [8.28369, 48.88277]]] ]}";
|
||||||
doc.Parse(nonobj_geom);
|
doc.Parse(nonobj_geom);
|
||||||
BOOST_CHECK_THROW(util::ValidateFeature(doc), util::exception);
|
BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
|
||||||
|
|
||||||
char missing_geom_type[] = "{ \"type\" : \"Feature\","
|
char missing_geom_type[] = "{ \"type\" : \"Feature\","
|
||||||
"\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometry\" : { "
|
"\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometry\" : { "
|
||||||
@ -106,7 +106,7 @@ BOOST_AUTO_TEST_CASE(timezone_validation_test)
|
|||||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||||
"49.07206], [8.28369, 48.88277]]] }}";
|
"49.07206], [8.28369, 48.88277]]] }}";
|
||||||
doc.Parse(missing_geom_type);
|
doc.Parse(missing_geom_type);
|
||||||
BOOST_CHECK_THROW(util::ValidateFeature(doc), util::exception);
|
BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
|
||||||
|
|
||||||
char nonstring_geom_type[] = "{ \"type\" : \"Feature\","
|
char nonstring_geom_type[] = "{ \"type\" : \"Feature\","
|
||||||
"\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometry\" : "
|
"\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometry\" : "
|
||||||
@ -115,7 +115,7 @@ BOOST_AUTO_TEST_CASE(timezone_validation_test)
|
|||||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||||
"49.07206], [8.28369, 48.88277]]] }}";
|
"49.07206], [8.28369, 48.88277]]] }}";
|
||||||
doc.Parse(nonstring_geom_type);
|
doc.Parse(nonstring_geom_type);
|
||||||
BOOST_CHECK_THROW(util::ValidateFeature(doc), util::exception);
|
BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
|
||||||
|
|
||||||
char missing_coords[] =
|
char missing_coords[] =
|
||||||
"{ \"type\" : \"Feature\","
|
"{ \"type\" : \"Feature\","
|
||||||
@ -124,7 +124,7 @@ BOOST_AUTO_TEST_CASE(timezone_validation_test)
|
|||||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||||
"49.07206], [8.28369, 48.88277]]] }}";
|
"49.07206], [8.28369, 48.88277]]] }}";
|
||||||
doc.Parse(missing_coords);
|
doc.Parse(missing_coords);
|
||||||
BOOST_CHECK_THROW(util::ValidateFeature(doc), util::exception);
|
BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
|
||||||
|
|
||||||
char missing_outerring[] =
|
char missing_outerring[] =
|
||||||
"{ \"type\" : \"Feature\","
|
"{ \"type\" : \"Feature\","
|
||||||
@ -133,6 +133,6 @@ BOOST_AUTO_TEST_CASE(timezone_validation_test)
|
|||||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||||
"49.07206], [8.28369, 48.88277]] }}";
|
"49.07206], [8.28369, 48.88277]] }}";
|
||||||
doc.Parse(missing_outerring);
|
doc.Parse(missing_outerring);
|
||||||
BOOST_CHECK_THROW(util::ValidateFeature(doc), util::exception);
|
BOOST_CHECK_THROW(util::validateFeature(doc), util::exception);
|
||||||
}
|
}
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
Loading…
Reference in New Issue
Block a user