2016-03-16 06:58:39 -04:00
|
|
|
#include <boost/test/test_case_template.hpp>
|
2016-05-27 15:05:04 -04:00
|
|
|
#include <boost/test/unit_test.hpp>
|
2016-03-16 06:58:39 -04:00
|
|
|
|
2016-03-17 11:28:38 -04:00
|
|
|
#include "fixture.hpp"
|
2016-03-16 07:42:26 -04:00
|
|
|
|
|
|
|
#include "osrm/tile_parameters.hpp"
|
|
|
|
|
|
|
|
#include "osrm/coordinate.hpp"
|
|
|
|
#include "osrm/engine_config.hpp"
|
|
|
|
#include "osrm/json_container.hpp"
|
|
|
|
#include "osrm/osrm.hpp"
|
2016-05-27 15:05:04 -04:00
|
|
|
#include "osrm/status.hpp"
|
2016-03-16 07:42:26 -04:00
|
|
|
|
2016-04-14 10:54:45 -04:00
|
|
|
#include "util/vector_tile.hpp"
|
|
|
|
|
|
|
|
#include <protozero/pbf_reader.hpp>
|
|
|
|
|
2017-03-02 09:45:42 -05:00
|
|
|
#define CHECK_EQUAL_RANGE(R1, R2) \
|
|
|
|
BOOST_CHECK_EQUAL_COLLECTIONS(R1.begin(), R1.end(), R2.begin(), R2.end());
|
|
|
|
|
2016-03-16 06:58:39 -04:00
|
|
|
BOOST_AUTO_TEST_SUITE(tile)
|
|
|
|
|
2017-06-15 07:59:44 -04:00
|
|
|
template <typename algorithm> void test_tile(algorithm &osrm)
|
2016-03-16 07:42:26 -04:00
|
|
|
{
|
|
|
|
using namespace osrm;
|
|
|
|
|
2017-03-21 06:27:15 -04:00
|
|
|
// This tile should contain most of monaco
|
|
|
|
TileParameters params{17059, 11948, 15};
|
2016-03-16 07:42:26 -04:00
|
|
|
|
|
|
|
std::string result;
|
|
|
|
const auto rc = osrm.Tile(params, result);
|
2016-03-17 11:28:38 -04:00
|
|
|
BOOST_CHECK(rc == Status::Ok);
|
2016-04-14 10:54:45 -04:00
|
|
|
|
2017-03-21 06:27:15 -04:00
|
|
|
BOOST_CHECK(result.size() > 114000);
|
2016-04-14 10:54:45 -04:00
|
|
|
|
|
|
|
protozero::pbf_reader tile_message(result);
|
|
|
|
tile_message.next();
|
|
|
|
BOOST_CHECK_EQUAL(tile_message.tag(), util::vector_tile::LAYER_TAG); // must be a layer
|
|
|
|
protozero::pbf_reader layer_message = tile_message.get_message();
|
|
|
|
|
|
|
|
const auto check_feature = [](protozero::pbf_reader feature_message) {
|
|
|
|
feature_message.next(); // advance parser to first entry
|
|
|
|
BOOST_CHECK_EQUAL(feature_message.tag(), util::vector_tile::GEOMETRY_TAG);
|
|
|
|
BOOST_CHECK_EQUAL(feature_message.get_enum(), util::vector_tile::GEOMETRY_TYPE_LINE);
|
|
|
|
|
|
|
|
feature_message.next(); // advance to next entry
|
|
|
|
BOOST_CHECK_EQUAL(feature_message.tag(), util::vector_tile::ID_TAG);
|
|
|
|
feature_message.get_uint64(); // id
|
|
|
|
|
|
|
|
feature_message.next(); // advance to next entry
|
|
|
|
BOOST_CHECK_EQUAL(feature_message.tag(), util::vector_tile::FEATURE_ATTRIBUTES_TAG);
|
|
|
|
// properties
|
2016-09-30 05:44:19 -04:00
|
|
|
auto property_iter_pair = feature_message.get_packed_uint32();
|
2016-10-03 13:07:18 -04:00
|
|
|
auto value_begin = property_iter_pair.begin();
|
|
|
|
auto value_end = property_iter_pair.end();
|
2017-06-15 11:50:57 -04:00
|
|
|
BOOST_CHECK_EQUAL(std::distance(value_begin, value_end), 14);
|
2016-04-14 10:54:45 -04:00
|
|
|
auto iter = value_begin;
|
|
|
|
BOOST_CHECK_EQUAL(*iter++, 0); // speed key
|
2016-05-27 15:05:04 -04:00
|
|
|
BOOST_CHECK_LT(*iter++, 128); // speed value
|
2016-04-14 10:54:45 -04:00
|
|
|
BOOST_CHECK_EQUAL(*iter++, 1); // component key
|
|
|
|
// component value
|
|
|
|
BOOST_CHECK_GE(*iter, 128);
|
|
|
|
BOOST_CHECK_LE(*iter, 129);
|
|
|
|
iter++;
|
|
|
|
BOOST_CHECK_EQUAL(*iter++, 2); // data source key
|
2016-05-27 15:05:04 -04:00
|
|
|
*iter++; // skip value check, can be valud uint32
|
2017-03-09 03:05:09 -05:00
|
|
|
BOOST_CHECK_EQUAL(*iter++, 3); // weight key
|
|
|
|
BOOST_CHECK_GT(*iter++, 130); // weight value
|
|
|
|
BOOST_CHECK_EQUAL(*iter++, 4); // duration key
|
2016-05-27 15:05:04 -04:00
|
|
|
BOOST_CHECK_GT(*iter++, 130); // duration value
|
2016-06-10 14:15:14 -04:00
|
|
|
// name
|
2017-03-09 03:05:09 -05:00
|
|
|
BOOST_CHECK_EQUAL(*iter++, 5);
|
2016-06-10 14:15:14 -04:00
|
|
|
BOOST_CHECK_GT(*iter++, 130);
|
2017-06-15 11:50:57 -04:00
|
|
|
// rate
|
|
|
|
BOOST_CHECK_EQUAL(*iter++, 6);
|
|
|
|
BOOST_CHECK_GT(*iter++, 130);
|
2016-04-14 10:54:45 -04:00
|
|
|
BOOST_CHECK(iter == value_end);
|
|
|
|
// geometry
|
|
|
|
feature_message.next();
|
2016-09-30 05:44:19 -04:00
|
|
|
auto geometry_iter_pair = feature_message.get_packed_uint32();
|
2016-10-03 13:07:18 -04:00
|
|
|
BOOST_CHECK_GT(std::distance(geometry_iter_pair.begin(), geometry_iter_pair.end()), 1);
|
2016-04-14 10:54:45 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
const auto check_value = [](protozero::pbf_reader value) {
|
|
|
|
while (value.next())
|
|
|
|
{
|
2016-05-27 15:05:04 -04:00
|
|
|
switch (value.tag())
|
2016-04-14 10:54:45 -04:00
|
|
|
{
|
2016-05-27 15:05:04 -04:00
|
|
|
case util::vector_tile::VARIANT_TYPE_BOOL:
|
|
|
|
value.get_bool();
|
|
|
|
break;
|
|
|
|
case util::vector_tile::VARIANT_TYPE_DOUBLE:
|
|
|
|
value.get_double();
|
|
|
|
break;
|
2016-09-14 20:17:29 -04:00
|
|
|
case util::vector_tile::VARIANT_TYPE_FLOAT:
|
|
|
|
value.get_float();
|
|
|
|
break;
|
2016-05-27 15:05:04 -04:00
|
|
|
case util::vector_tile::VARIANT_TYPE_STRING:
|
|
|
|
value.get_string();
|
|
|
|
break;
|
2016-05-09 19:20:47 -04:00
|
|
|
case util::vector_tile::VARIANT_TYPE_UINT64:
|
|
|
|
value.get_uint64();
|
|
|
|
break;
|
|
|
|
case util::vector_tile::VARIANT_TYPE_SINT64:
|
|
|
|
value.get_sint64();
|
2016-05-27 15:05:04 -04:00
|
|
|
break;
|
2016-04-14 10:54:45 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-05-09 19:20:47 -04:00
|
|
|
auto number_of_speed_keys = 0u;
|
|
|
|
auto number_of_speed_values = 0u;
|
|
|
|
|
2016-04-14 10:54:45 -04:00
|
|
|
while (layer_message.next())
|
|
|
|
{
|
2016-05-27 15:05:04 -04:00
|
|
|
switch (layer_message.tag())
|
2016-04-14 10:54:45 -04:00
|
|
|
{
|
2016-05-27 15:05:04 -04:00
|
|
|
case util::vector_tile::VERSION_TAG:
|
|
|
|
BOOST_CHECK_EQUAL(layer_message.get_uint32(), 2);
|
|
|
|
break;
|
|
|
|
case util::vector_tile::NAME_TAG:
|
|
|
|
BOOST_CHECK_EQUAL(layer_message.get_string(), "speeds");
|
|
|
|
break;
|
2016-05-09 19:20:47 -04:00
|
|
|
case util::vector_tile::EXTENT_TAG:
|
2016-05-27 15:05:04 -04:00
|
|
|
BOOST_CHECK_EQUAL(layer_message.get_uint32(), util::vector_tile::EXTENT);
|
|
|
|
break;
|
|
|
|
case util::vector_tile::FEATURE_TAG:
|
2016-09-30 08:33:43 -04:00
|
|
|
check_feature(layer_message.get_message());
|
2016-05-27 15:05:04 -04:00
|
|
|
break;
|
|
|
|
case util::vector_tile::KEY_TAG:
|
|
|
|
layer_message.get_string();
|
2016-05-09 19:20:47 -04:00
|
|
|
number_of_speed_keys++;
|
2016-05-27 15:05:04 -04:00
|
|
|
break;
|
|
|
|
case util::vector_tile::VARIANT_TAG:
|
|
|
|
check_value(layer_message.get_message());
|
2016-05-09 19:20:47 -04:00
|
|
|
number_of_speed_values++;
|
2016-05-27 15:05:04 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
BOOST_CHECK(false); // invalid tag
|
|
|
|
break;
|
2016-04-14 10:54:45 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-15 11:50:57 -04:00
|
|
|
BOOST_CHECK_EQUAL(number_of_speed_keys, 7);
|
2016-05-09 19:20:47 -04:00
|
|
|
BOOST_CHECK_GT(number_of_speed_values, 128); // speed value resolution
|
|
|
|
|
|
|
|
tile_message.next();
|
|
|
|
layer_message = tile_message.get_message();
|
|
|
|
|
|
|
|
const auto check_turn_feature = [](protozero::pbf_reader feature_message) {
|
|
|
|
feature_message.next(); // advance parser to first entry
|
|
|
|
BOOST_CHECK_EQUAL(feature_message.tag(), util::vector_tile::GEOMETRY_TAG);
|
|
|
|
BOOST_CHECK_EQUAL(feature_message.get_enum(), util::vector_tile::GEOMETRY_TYPE_POINT);
|
|
|
|
|
|
|
|
feature_message.next(); // advance to next entry
|
|
|
|
BOOST_CHECK_EQUAL(feature_message.tag(), util::vector_tile::ID_TAG);
|
|
|
|
feature_message.get_uint64(); // id
|
|
|
|
|
|
|
|
feature_message.next(); // advance to next entry
|
|
|
|
BOOST_CHECK_EQUAL(feature_message.tag(), util::vector_tile::FEATURE_ATTRIBUTES_TAG);
|
|
|
|
// properties
|
2016-10-03 13:07:18 -04:00
|
|
|
auto feature_iter_pair = feature_message.get_packed_uint32();
|
2017-06-15 11:50:57 -04:00
|
|
|
BOOST_CHECK_EQUAL(std::distance(feature_iter_pair.begin(), feature_iter_pair.end()), 8);
|
2016-10-03 13:07:18 -04:00
|
|
|
auto iter = feature_iter_pair.begin();
|
2016-05-09 19:20:47 -04:00
|
|
|
BOOST_CHECK_EQUAL(*iter++, 0); // bearing_in key
|
|
|
|
*iter++;
|
2016-09-14 20:17:29 -04:00
|
|
|
BOOST_CHECK_EQUAL(*iter++, 1); // turn_angle key
|
2016-05-09 19:20:47 -04:00
|
|
|
*iter++;
|
2017-06-15 11:50:57 -04:00
|
|
|
BOOST_CHECK_EQUAL(*iter++, 2); // turn cost (duration) key
|
|
|
|
*iter++; // skip value check, can be valud uint32
|
|
|
|
BOOST_CHECK_EQUAL(*iter++, 3); // turn weight key
|
2016-10-03 13:07:18 -04:00
|
|
|
*iter++; // skip value check, can be valud uint32
|
|
|
|
BOOST_CHECK(iter == feature_iter_pair.end());
|
2016-05-09 19:20:47 -04:00
|
|
|
// geometry
|
|
|
|
feature_message.next();
|
2016-10-03 13:07:18 -04:00
|
|
|
auto geometry_iter_pair = feature_message.get_packed_uint32();
|
|
|
|
BOOST_CHECK_GT(std::distance(geometry_iter_pair.begin(), geometry_iter_pair.end()), 1);
|
2016-05-09 19:20:47 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
auto number_of_turn_keys = 0u;
|
2016-11-04 19:07:47 -04:00
|
|
|
auto number_of_turns_found = 0u;
|
2016-05-09 19:20:47 -04:00
|
|
|
|
|
|
|
while (layer_message.next())
|
|
|
|
{
|
2016-10-03 13:07:18 -04:00
|
|
|
switch (layer_message.tag())
|
2016-05-09 19:20:47 -04:00
|
|
|
{
|
2016-10-03 13:07:18 -04:00
|
|
|
case util::vector_tile::VERSION_TAG:
|
|
|
|
BOOST_CHECK_EQUAL(layer_message.get_uint32(), 2);
|
|
|
|
break;
|
|
|
|
case util::vector_tile::NAME_TAG:
|
|
|
|
BOOST_CHECK_EQUAL(layer_message.get_string(), "turns");
|
|
|
|
break;
|
|
|
|
case util::vector_tile::EXTENT_TAG:
|
|
|
|
BOOST_CHECK_EQUAL(layer_message.get_uint32(), util::vector_tile::EXTENT);
|
|
|
|
break;
|
|
|
|
case util::vector_tile::FEATURE_TAG:
|
|
|
|
check_turn_feature(layer_message.get_message());
|
2016-11-04 19:07:47 -04:00
|
|
|
number_of_turns_found++;
|
2016-10-03 13:07:18 -04:00
|
|
|
break;
|
|
|
|
case util::vector_tile::KEY_TAG:
|
|
|
|
layer_message.get_string();
|
|
|
|
number_of_turn_keys++;
|
|
|
|
break;
|
|
|
|
case util::vector_tile::VARIANT_TAG:
|
|
|
|
check_value(layer_message.get_message());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
BOOST_CHECK(false); // invalid tag
|
|
|
|
break;
|
2016-05-09 19:20:47 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-15 11:50:57 -04:00
|
|
|
BOOST_CHECK_EQUAL(number_of_turn_keys, 4);
|
2017-03-21 06:27:15 -04:00
|
|
|
BOOST_CHECK(number_of_turns_found > 700);
|
2016-03-16 07:42:26 -04:00
|
|
|
}
|
2016-03-16 06:58:39 -04:00
|
|
|
|
2017-06-15 07:59:44 -04:00
|
|
|
BOOST_AUTO_TEST_CASE(test_tile_ch)
|
|
|
|
{
|
|
|
|
using namespace osrm;
|
|
|
|
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm", osrm::EngineConfig::Algorithm::CH);
|
|
|
|
test_tile(osrm);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(test_tile_corech)
|
|
|
|
{
|
|
|
|
using namespace osrm;
|
|
|
|
auto osrm =
|
|
|
|
getOSRM(OSRM_TEST_DATA_DIR "/corech/monaco.osrm", osrm::EngineConfig::Algorithm::CoreCH);
|
|
|
|
test_tile(osrm);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(test_tile_mld)
|
|
|
|
{
|
|
|
|
using namespace osrm;
|
|
|
|
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/mld/monaco.osrm", osrm::EngineConfig::Algorithm::MLD);
|
|
|
|
test_tile(osrm);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename algorithm> void test_tile_turns(algorithm &osrm)
|
2016-11-08 05:47:19 -05:00
|
|
|
{
|
|
|
|
using namespace osrm;
|
|
|
|
|
2017-03-21 06:27:15 -04:00
|
|
|
// Small tile where we can test all the values
|
|
|
|
TileParameters params{272953, 191177, 19};
|
2016-11-08 05:47:19 -05:00
|
|
|
|
|
|
|
std::string result;
|
|
|
|
const auto rc = osrm.Tile(params, result);
|
|
|
|
BOOST_CHECK(rc == Status::Ok);
|
|
|
|
|
2017-03-21 06:27:15 -04:00
|
|
|
BOOST_CHECK_GT(result.size(), 128);
|
2016-11-08 05:47:19 -05:00
|
|
|
|
|
|
|
protozero::pbf_reader tile_message(result);
|
|
|
|
tile_message.next();
|
|
|
|
BOOST_CHECK_EQUAL(tile_message.tag(), util::vector_tile::LAYER_TAG); // must be a layer
|
|
|
|
// Skip the segments layer
|
|
|
|
tile_message.skip();
|
|
|
|
|
|
|
|
tile_message.next();
|
|
|
|
auto layer_message = tile_message.get_message();
|
|
|
|
|
|
|
|
std::vector<int> found_bearing_in_indexes;
|
|
|
|
std::vector<int> found_turn_angles_indexes;
|
2017-06-15 11:50:57 -04:00
|
|
|
std::vector<int> found_time_penalties_indexes;
|
|
|
|
std::vector<int> found_weight_penalties_indexes;
|
2016-11-08 05:47:19 -05:00
|
|
|
|
|
|
|
const auto check_turn_feature = [&](protozero::pbf_reader feature_message) {
|
|
|
|
feature_message.next(); // advance parser to first entry
|
|
|
|
BOOST_CHECK_EQUAL(feature_message.tag(), util::vector_tile::GEOMETRY_TAG);
|
|
|
|
BOOST_CHECK_EQUAL(feature_message.get_enum(), util::vector_tile::GEOMETRY_TYPE_POINT);
|
|
|
|
|
|
|
|
feature_message.next(); // advance to next entry
|
|
|
|
BOOST_CHECK_EQUAL(feature_message.tag(), util::vector_tile::ID_TAG);
|
|
|
|
feature_message.get_uint64(); // id
|
|
|
|
|
|
|
|
feature_message.next(); // advance to next entry
|
|
|
|
BOOST_CHECK_EQUAL(feature_message.tag(), util::vector_tile::FEATURE_ATTRIBUTES_TAG);
|
|
|
|
// properties
|
|
|
|
auto feature_iter_pair = feature_message.get_packed_uint32();
|
2017-06-15 11:50:57 -04:00
|
|
|
BOOST_CHECK_EQUAL(std::distance(feature_iter_pair.begin(), feature_iter_pair.end()), 8);
|
2016-11-08 05:47:19 -05:00
|
|
|
auto iter = feature_iter_pair.begin();
|
|
|
|
BOOST_CHECK_EQUAL(*iter++, 0); // bearing_in key
|
|
|
|
found_bearing_in_indexes.push_back(*iter++);
|
|
|
|
BOOST_CHECK_EQUAL(*iter++, 1); // turn_angle key
|
|
|
|
found_turn_angles_indexes.push_back(*iter++);
|
2017-06-15 11:50:57 -04:00
|
|
|
BOOST_CHECK_EQUAL(*iter++, 2); // "cost" key (actually duration)
|
|
|
|
found_time_penalties_indexes.push_back(*iter++); // skip value check, can be valud uint32
|
|
|
|
BOOST_CHECK_EQUAL(*iter++, 3); // "weight" key
|
|
|
|
found_weight_penalties_indexes.push_back(*iter++); // skip value check, can be valud uint32
|
2016-11-08 05:47:19 -05:00
|
|
|
BOOST_CHECK(iter == feature_iter_pair.end());
|
|
|
|
// geometry
|
|
|
|
feature_message.next();
|
|
|
|
auto geometry_iter_pair = feature_message.get_packed_uint32();
|
|
|
|
BOOST_CHECK_GT(std::distance(geometry_iter_pair.begin(), geometry_iter_pair.end()), 1);
|
|
|
|
};
|
|
|
|
|
|
|
|
std::unordered_map<int, float> float_vals;
|
|
|
|
std::unordered_map<int, std::int64_t> sint64_vals;
|
|
|
|
|
|
|
|
int kv_index = 0;
|
|
|
|
|
|
|
|
const auto check_value = [&](protozero::pbf_reader value) {
|
|
|
|
while (value.next())
|
|
|
|
{
|
|
|
|
switch (value.tag())
|
|
|
|
{
|
|
|
|
case util::vector_tile::VARIANT_TYPE_FLOAT:
|
|
|
|
float_vals[kv_index] = value.get_float();
|
|
|
|
break;
|
|
|
|
case util::vector_tile::VARIANT_TYPE_SINT64:
|
|
|
|
sint64_vals[kv_index] = value.get_sint64();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
BOOST_CHECK(false);
|
|
|
|
}
|
|
|
|
kv_index++;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
auto number_of_turn_keys = 0u;
|
|
|
|
auto number_of_turns_found = 0u;
|
|
|
|
|
|
|
|
while (layer_message.next())
|
|
|
|
{
|
|
|
|
switch (layer_message.tag())
|
|
|
|
{
|
|
|
|
case util::vector_tile::VERSION_TAG:
|
|
|
|
BOOST_CHECK_EQUAL(layer_message.get_uint32(), 2);
|
|
|
|
break;
|
|
|
|
case util::vector_tile::NAME_TAG:
|
|
|
|
BOOST_CHECK_EQUAL(layer_message.get_string(), "turns");
|
|
|
|
break;
|
|
|
|
case util::vector_tile::EXTENT_TAG:
|
|
|
|
BOOST_CHECK_EQUAL(layer_message.get_uint32(), util::vector_tile::EXTENT);
|
|
|
|
break;
|
|
|
|
case util::vector_tile::FEATURE_TAG:
|
|
|
|
check_turn_feature(layer_message.get_message());
|
|
|
|
number_of_turns_found++;
|
|
|
|
break;
|
|
|
|
case util::vector_tile::KEY_TAG:
|
|
|
|
layer_message.get_string();
|
|
|
|
number_of_turn_keys++;
|
|
|
|
break;
|
|
|
|
case util::vector_tile::VARIANT_TAG:
|
|
|
|
check_value(layer_message.get_message());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
BOOST_CHECK(false); // invalid tag
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify that we got the expected turn penalties
|
2017-06-15 11:50:57 -04:00
|
|
|
std::vector<float> actual_time_turn_penalties;
|
|
|
|
for (const auto &i : found_time_penalties_indexes)
|
2016-11-08 05:47:19 -05:00
|
|
|
{
|
|
|
|
BOOST_CHECK(float_vals.count(i) == 1);
|
2017-06-15 11:50:57 -04:00
|
|
|
actual_time_turn_penalties.push_back(float_vals[i]);
|
2016-11-08 05:47:19 -05:00
|
|
|
}
|
2017-06-15 11:50:57 -04:00
|
|
|
std::sort(actual_time_turn_penalties.begin(), actual_time_turn_penalties.end());
|
|
|
|
const std::vector<float> expected_time_turn_penalties = {
|
2017-03-21 06:27:15 -04:00
|
|
|
0, 0, 0, 0, 0, 0, .1f, .1f, .3f, .4f, 1.2f, 1.9f, 5.3f, 5.5f, 5.8f, 7.1f, 7.2f, 7.2f};
|
2017-06-15 11:50:57 -04:00
|
|
|
CHECK_EQUAL_RANGE(actual_time_turn_penalties, expected_time_turn_penalties);
|
|
|
|
|
|
|
|
// Verify that we got the expected turn penalties
|
|
|
|
std::vector<float> actual_weight_turn_penalties;
|
|
|
|
for (const auto &i : found_weight_penalties_indexes)
|
|
|
|
{
|
|
|
|
BOOST_CHECK(float_vals.count(i) == 1);
|
|
|
|
actual_weight_turn_penalties.push_back(float_vals[i]);
|
|
|
|
}
|
|
|
|
std::sort(actual_weight_turn_penalties.begin(), actual_weight_turn_penalties.end());
|
|
|
|
const std::vector<float> expected_weight_turn_penalties = {
|
|
|
|
0, 0, 0, 0, 0, 0, .1f, .1f, .3f, .4f, 1.2f, 1.9f, 5.3f, 5.5f, 5.8f, 7.1f, 7.2f, 7.2f};
|
|
|
|
CHECK_EQUAL_RANGE(actual_weight_turn_penalties, expected_weight_turn_penalties);
|
2016-11-08 05:47:19 -05:00
|
|
|
|
|
|
|
// Verify the expected turn angles
|
|
|
|
std::vector<std::int64_t> actual_turn_angles;
|
|
|
|
for (const auto &i : found_turn_angles_indexes)
|
|
|
|
{
|
|
|
|
BOOST_CHECK(sint64_vals.count(i) == 1);
|
|
|
|
actual_turn_angles.push_back(sint64_vals[i]);
|
|
|
|
}
|
|
|
|
std::sort(actual_turn_angles.begin(), actual_turn_angles.end());
|
|
|
|
const std::vector<std::int64_t> expected_turn_angles = {
|
2017-03-21 06:27:15 -04:00
|
|
|
-122, -120, -117, -65, -57, -30, -28, -3, -2, 2, 3, 28, 30, 57, 65, 117, 120, 122};
|
2017-03-02 09:45:42 -05:00
|
|
|
CHECK_EQUAL_RANGE(actual_turn_angles, expected_turn_angles);
|
2016-11-08 05:47:19 -05:00
|
|
|
|
|
|
|
// Verify the expected bearings
|
|
|
|
std::vector<std::int64_t> actual_turn_bearings;
|
|
|
|
for (const auto &i : found_bearing_in_indexes)
|
|
|
|
{
|
|
|
|
BOOST_CHECK(sint64_vals.count(i) == 1);
|
|
|
|
actual_turn_bearings.push_back(sint64_vals[i]);
|
|
|
|
}
|
|
|
|
std::sort(actual_turn_bearings.begin(), actual_turn_bearings.end());
|
|
|
|
const std::vector<std::int64_t> expected_turn_bearings = {
|
2017-03-21 06:27:15 -04:00
|
|
|
49, 49, 107, 107, 169, 169, 171, 171, 229, 229, 257, 257, 286, 286, 349, 349, 352, 352};
|
2017-03-02 09:45:42 -05:00
|
|
|
CHECK_EQUAL_RANGE(actual_turn_bearings, expected_turn_bearings);
|
2016-11-08 05:47:19 -05:00
|
|
|
}
|
|
|
|
|
2017-06-15 07:59:44 -04:00
|
|
|
BOOST_AUTO_TEST_CASE(test_tile_turns_ch)
|
|
|
|
{
|
|
|
|
using namespace osrm;
|
|
|
|
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm", osrm::EngineConfig::Algorithm::CH);
|
|
|
|
|
|
|
|
test_tile_turns(osrm);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(test_tile_turns_corech)
|
|
|
|
{
|
|
|
|
using namespace osrm;
|
|
|
|
auto osrm =
|
|
|
|
getOSRM(OSRM_TEST_DATA_DIR "/corech/monaco.osrm", osrm::EngineConfig::Algorithm::CoreCH);
|
|
|
|
|
|
|
|
test_tile_turns(osrm);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(test_tile_turns_mld)
|
2016-11-08 05:47:19 -05:00
|
|
|
{
|
|
|
|
using namespace osrm;
|
2017-06-15 07:59:44 -04:00
|
|
|
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/mld/monaco.osrm", osrm::EngineConfig::Algorithm::MLD);
|
|
|
|
|
|
|
|
test_tile_turns(osrm);
|
|
|
|
}
|
2016-11-08 05:47:19 -05:00
|
|
|
|
2017-06-15 07:59:44 -04:00
|
|
|
template <typename algorithm> void test_tile_speeds(algorithm &osrm)
|
|
|
|
{
|
|
|
|
using namespace osrm;
|
2017-03-05 17:53:41 -05:00
|
|
|
|
2016-11-08 05:47:19 -05:00
|
|
|
// Small tile so we can test all the values
|
|
|
|
// TileParameters params{272953, 191177, 19};
|
|
|
|
TileParameters params{136477, 95580, 18};
|
|
|
|
|
|
|
|
std::string result;
|
|
|
|
const auto rc = osrm.Tile(params, result);
|
|
|
|
BOOST_CHECK(rc == Status::Ok);
|
|
|
|
|
|
|
|
BOOST_CHECK_GT(result.size(), 128);
|
|
|
|
|
|
|
|
protozero::pbf_reader tile_message(result);
|
|
|
|
tile_message.next();
|
|
|
|
BOOST_CHECK_EQUAL(tile_message.tag(), util::vector_tile::LAYER_TAG); // must be a layer
|
|
|
|
protozero::pbf_reader layer_message = tile_message.get_message();
|
|
|
|
|
|
|
|
std::vector<int> found_speed_indexes;
|
|
|
|
std::vector<int> found_component_indexes;
|
|
|
|
std::vector<int> found_datasource_indexes;
|
2017-06-15 11:50:57 -04:00
|
|
|
std::vector<int> found_weight_indexes;
|
2016-11-08 05:47:19 -05:00
|
|
|
std::vector<int> found_duration_indexes;
|
|
|
|
std::vector<int> found_name_indexes;
|
2017-06-15 11:50:57 -04:00
|
|
|
std::vector<int> found_rate_indexes;
|
2016-11-08 05:47:19 -05:00
|
|
|
|
|
|
|
const auto check_feature = [&](protozero::pbf_reader feature_message) {
|
|
|
|
feature_message.next(); // advance parser to first entry
|
|
|
|
BOOST_CHECK_EQUAL(feature_message.tag(), util::vector_tile::GEOMETRY_TAG);
|
|
|
|
BOOST_CHECK_EQUAL(feature_message.get_enum(), util::vector_tile::GEOMETRY_TYPE_LINE);
|
|
|
|
|
|
|
|
feature_message.next(); // advance to next entry
|
|
|
|
BOOST_CHECK_EQUAL(feature_message.tag(), util::vector_tile::ID_TAG);
|
|
|
|
feature_message.get_uint64(); // id
|
|
|
|
|
|
|
|
feature_message.next(); // advance to next entry
|
|
|
|
BOOST_CHECK_EQUAL(feature_message.tag(), util::vector_tile::FEATURE_ATTRIBUTES_TAG);
|
|
|
|
// properties
|
|
|
|
auto property_iter_pair = feature_message.get_packed_uint32();
|
|
|
|
auto value_begin = property_iter_pair.begin();
|
|
|
|
auto value_end = property_iter_pair.end();
|
2017-06-15 11:50:57 -04:00
|
|
|
BOOST_CHECK_EQUAL(std::distance(value_begin, value_end), 14);
|
2016-11-08 05:47:19 -05:00
|
|
|
auto iter = value_begin;
|
|
|
|
BOOST_CHECK_EQUAL(*iter++, 0); // speed key
|
|
|
|
found_speed_indexes.push_back(*iter++);
|
|
|
|
BOOST_CHECK_EQUAL(*iter++, 1); // component key
|
|
|
|
// component value
|
|
|
|
found_component_indexes.push_back(*iter++);
|
|
|
|
BOOST_CHECK_EQUAL(*iter++, 2); // data source key
|
|
|
|
found_datasource_indexes.push_back(*iter++);
|
2017-03-09 03:05:09 -05:00
|
|
|
BOOST_CHECK_EQUAL(*iter++, 3); // weight key
|
2017-06-15 11:50:57 -04:00
|
|
|
found_weight_indexes.push_back(*iter++);
|
2017-03-09 03:05:09 -05:00
|
|
|
BOOST_CHECK_EQUAL(*iter++, 4); // duration key
|
2016-11-08 05:47:19 -05:00
|
|
|
found_duration_indexes.push_back(*iter++);
|
|
|
|
// name
|
2017-03-09 03:05:09 -05:00
|
|
|
BOOST_CHECK_EQUAL(*iter++, 5);
|
2016-11-08 05:47:19 -05:00
|
|
|
found_name_indexes.push_back(*iter++);
|
2017-06-15 11:50:57 -04:00
|
|
|
BOOST_CHECK_EQUAL(*iter++, 6);
|
|
|
|
found_rate_indexes.push_back(*iter++);
|
2016-11-08 05:47:19 -05:00
|
|
|
BOOST_CHECK(iter == value_end);
|
|
|
|
// geometry
|
|
|
|
feature_message.next();
|
|
|
|
auto geometry_iter_pair = feature_message.get_packed_uint32();
|
|
|
|
BOOST_CHECK_GT(std::distance(geometry_iter_pair.begin(), geometry_iter_pair.end()), 1);
|
|
|
|
};
|
|
|
|
|
|
|
|
std::unordered_map<int, std::string> string_vals;
|
|
|
|
std::unordered_map<int, bool> bool_vals;
|
|
|
|
std::unordered_map<int, std::uint64_t> uint64_vals;
|
|
|
|
std::unordered_map<int, double> double_vals;
|
|
|
|
|
|
|
|
int kv_index = 0;
|
|
|
|
|
|
|
|
const auto check_value = [&](protozero::pbf_reader value) {
|
|
|
|
while (value.next())
|
|
|
|
{
|
|
|
|
switch (value.tag())
|
|
|
|
{
|
|
|
|
case util::vector_tile::VARIANT_TYPE_BOOL:
|
|
|
|
bool_vals[kv_index] = value.get_bool();
|
|
|
|
break;
|
|
|
|
case util::vector_tile::VARIANT_TYPE_DOUBLE:
|
|
|
|
double_vals[kv_index] = value.get_double();
|
|
|
|
break;
|
|
|
|
case util::vector_tile::VARIANT_TYPE_FLOAT:
|
|
|
|
value.get_float();
|
|
|
|
break;
|
|
|
|
case util::vector_tile::VARIANT_TYPE_STRING:
|
|
|
|
string_vals[kv_index] = value.get_string();
|
|
|
|
break;
|
|
|
|
case util::vector_tile::VARIANT_TYPE_UINT64:
|
|
|
|
uint64_vals[kv_index] = value.get_uint64();
|
|
|
|
break;
|
|
|
|
case util::vector_tile::VARIANT_TYPE_SINT64:
|
|
|
|
value.get_sint64();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
kv_index++;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
auto number_of_speed_keys = 0u;
|
|
|
|
auto number_of_speed_values = 0u;
|
|
|
|
|
|
|
|
while (layer_message.next())
|
|
|
|
{
|
|
|
|
switch (layer_message.tag())
|
|
|
|
{
|
|
|
|
case util::vector_tile::VERSION_TAG:
|
|
|
|
BOOST_CHECK_EQUAL(layer_message.get_uint32(), 2);
|
|
|
|
break;
|
|
|
|
case util::vector_tile::NAME_TAG:
|
|
|
|
BOOST_CHECK_EQUAL(layer_message.get_string(), "speeds");
|
|
|
|
break;
|
|
|
|
case util::vector_tile::EXTENT_TAG:
|
|
|
|
BOOST_CHECK_EQUAL(layer_message.get_uint32(), util::vector_tile::EXTENT);
|
|
|
|
break;
|
|
|
|
case util::vector_tile::FEATURE_TAG:
|
|
|
|
check_feature(layer_message.get_message());
|
|
|
|
break;
|
|
|
|
case util::vector_tile::KEY_TAG:
|
|
|
|
layer_message.get_string();
|
|
|
|
number_of_speed_keys++;
|
|
|
|
break;
|
|
|
|
case util::vector_tile::VARIANT_TAG:
|
|
|
|
check_value(layer_message.get_message());
|
|
|
|
number_of_speed_values++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
BOOST_CHECK(false); // invalid tag
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> actual_names;
|
|
|
|
for (const auto &i : found_name_indexes)
|
|
|
|
{
|
|
|
|
BOOST_CHECK(string_vals.count(i) == 1);
|
|
|
|
actual_names.push_back(string_vals[i]);
|
|
|
|
}
|
|
|
|
std::sort(actual_names.begin(), actual_names.end());
|
2017-03-21 06:27:15 -04:00
|
|
|
const std::vector<std::string> expected_names = {"Avenue du Carnier",
|
|
|
|
"Avenue du Carnier",
|
|
|
|
"Avenue du Carnier",
|
|
|
|
"Avenue du Carnier",
|
|
|
|
"Avenue du Carnier",
|
|
|
|
"Avenue du Maréchal Foch",
|
|
|
|
"Avenue du Maréchal Foch",
|
|
|
|
"Avenue du Maréchal Foch",
|
|
|
|
"Avenue du Maréchal Foch",
|
|
|
|
"Avenue du Maréchal Foch",
|
|
|
|
"Avenue du Maréchal Foch",
|
|
|
|
"Avenue du Professeur Langevin",
|
|
|
|
"Avenue du Professeur Langevin",
|
|
|
|
"Avenue du Professeur Langevin",
|
|
|
|
"Montée de la Crémaillère",
|
|
|
|
"Montée de la Crémaillère",
|
|
|
|
"Rue Jules Ferry",
|
|
|
|
"Rue Jules Ferry",
|
|
|
|
"Rue Professeur Calmette",
|
|
|
|
"Rue Professeur Calmette"};
|
2016-11-08 05:47:19 -05:00
|
|
|
BOOST_CHECK(actual_names == expected_names);
|
|
|
|
}
|
|
|
|
|
2017-06-15 07:59:44 -04:00
|
|
|
BOOST_AUTO_TEST_CASE(test_tile_speeds_ch)
|
|
|
|
{
|
|
|
|
using namespace osrm;
|
|
|
|
|
|
|
|
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm", osrm::EngineConfig::Algorithm::CH);
|
|
|
|
test_tile_speeds(osrm);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(test_tile_speeds_corech)
|
|
|
|
{
|
|
|
|
using namespace osrm;
|
|
|
|
|
|
|
|
auto osrm =
|
|
|
|
getOSRM(OSRM_TEST_DATA_DIR "/corech/monaco.osrm", osrm::EngineConfig::Algorithm::CoreCH);
|
|
|
|
test_tile_speeds(osrm);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(test_tile_speeds_mld)
|
|
|
|
{
|
|
|
|
using namespace osrm;
|
|
|
|
|
|
|
|
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/mld/monaco.osrm", osrm::EngineConfig::Algorithm::MLD);
|
|
|
|
test_tile_speeds(osrm);
|
|
|
|
}
|
|
|
|
|
2016-03-16 06:58:39 -04:00
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|