void validate_node_layer(protozero::pbf_reader &layer_message) { using namespace osrm; auto number_of_nodes_found = 0u; const auto check_osmnode_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 // Note - on this layer, there should be no feature attributes, the next thing // we get should be the geometry BOOST_CHECK_EQUAL(feature_message.tag(), util::vector_tile::FEATURE_GEOMETRIES_TAG); auto geometry_iter_pair = feature_message.get_packed_uint32(); BOOST_CHECK_GT(std::distance(geometry_iter_pair.begin(), geometry_iter_pair.end()), 1); }; 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(), "osmnodes"); 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_osmnode_feature(layer_message.get_message()); number_of_nodes_found++; break; case util::vector_tile::KEY_TAG: BOOST_CHECK(false); // There should be no properties on node features break; case util::vector_tile::VARIANT_TAG: BOOST_CHECK(false); // There should be no properties on node features break; default: BOOST_CHECK(false); // invalid tag break; } } BOOST_CHECK_EQUAL(number_of_nodes_found, 1791); }
void validate_feature_layer(protozero::pbf_reader &layer_message) { using namespace osrm; 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(); BOOST_CHECK_EQUAL(std::distance(value_begin, value_end), 14); auto iter = value_begin; BOOST_CHECK_EQUAL(*iter++, 0); // speed key BOOST_CHECK_LT(*iter++, 128); // speed value 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 *iter++; // skip value check, can be valud uint32 BOOST_CHECK_EQUAL(*iter++, 3); // weight key BOOST_CHECK_GT(*iter++, 130); // weight value BOOST_CHECK_EQUAL(*iter++, 4); // duration key BOOST_CHECK_GT(*iter++, 130); // duration value // name BOOST_CHECK_EQUAL(*iter++, 5); BOOST_CHECK_GT(*iter++, 130); // rate BOOST_CHECK_EQUAL(*iter++, 6); BOOST_CHECK_GT(*iter++, 130); 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); }; 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: validate_value(layer_message.get_message()); number_of_speed_values++; break; default: BOOST_CHECK(false); // invalid tag break; } } BOOST_CHECK_EQUAL(number_of_speed_keys, 7); BOOST_CHECK_GT(number_of_speed_values, 128); // speed value resolution }
void validate_turn_layer(protozero::pbf_reader &layer_message) { using namespace osrm; 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(); BOOST_CHECK_EQUAL(std::distance(feature_iter_pair.begin(), feature_iter_pair.end()), 12); auto iter = feature_iter_pair.begin(); BOOST_CHECK_EQUAL(*iter++, 0); // bearing_in key *iter++; BOOST_CHECK_EQUAL(*iter++, 1); // turn_angle key *iter++; 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 *iter++; // skip value check, can be valud uint32 BOOST_CHECK_EQUAL(*iter++, 4); // turn type key *iter++; // skip value check, can be valud uint32 BOOST_CHECK_EQUAL(*iter++, 5); // turn modifier *iter++; // skip value check, can be valud uint32 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); }; 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: validate_value(layer_message.get_message()); break; default: BOOST_CHECK(false); // invalid tag break; } } BOOST_CHECK_EQUAL(number_of_turn_keys, 6); BOOST_CHECK(number_of_turns_found > 700); }