[search] readable name calculation is added into reverse geocoder tests.

This commit is contained in:
Arsentiy Milchakov 2019-02-13 19:12:28 +03:00 committed by mpimenov
parent 5963b2c602
commit 7ce48aa53c
2 changed files with 98 additions and 18 deletions

View file

@ -4,27 +4,47 @@
#include "indexer/classificator_loader.hpp"
#include "indexer/data_source.hpp"
#include "indexer/feature_utils.hpp"
#include "indexer/mwm_set.hpp"
#include "indexer/search_string_utils.hpp"
#include "platform/preferred_languages.hpp"
#include "coding/string_utf8_multilang.hpp"
#include <memory>
#include <string>
using namespace search;
using namespace platform;
namespace
{
void TestAddress(ReverseGeocoder & coder, ms::LatLon const & ll, string const & street,
string const & houseNumber)
void TestAddress(ReverseGeocoder & coder, ms::LatLon const & ll, std::string const & street,
std::string const & houseNumber)
{
ReverseGeocoder::Address addr;
coder.GetNearbyAddress(MercatorBounds::FromLatLon(ll), addr);
string const key =
std::string const etalonKey =
strings::ToUtf8(GetStreetNameAsKey(street, false /* ignoreStreetSynonyms */));
std::string const resultKey =
strings::ToUtf8(GetStreetNameAsKey(addr.m_street.m_name, false /* ignoreStreetSynonyms */));
TEST_EQUAL(key, street, (addr));
TEST_EQUAL(resultKey, etalonKey, (addr));
TEST_EQUAL(houseNumber, addr.GetHouseNumber(), (addr));
}
void TestAddress(ReverseGeocoder & coder, std::shared_ptr<MwmInfo> mwmInfo, ms::LatLon const & ll,
StringUtf8Multilang const & streetNames, std::string const & houseNumber)
{
std::string streetName;
auto const deviceLang = StringUtf8Multilang::GetLangIndex(languages::GetCurrentNorm());
feature::GetReadableName(mwmInfo->GetRegionData(), streetNames, deviceLang,
false /* allowTranslit */, streetName);
TestAddress(coder, ll, streetName, houseNumber);
}
} // namespace
UNIT_TEST(ReverseGeocoder_Smoke)
@ -34,15 +54,55 @@ UNIT_TEST(ReverseGeocoder_Smoke)
LocalCountryFile file = LocalCountryFile::MakeForTesting("minsk-pass");
FrozenDataSource dataSource;
TEST_EQUAL(dataSource.RegisterMap(file).second, MwmSet::RegResult::Success, ());
auto const regResult = dataSource.RegisterMap(file);
TEST_EQUAL(regResult.second, MwmSet::RegResult::Success, ());
auto mwmInfo = regResult.first.GetInfo();
TEST(mwmInfo != nullptr, ());
ReverseGeocoder coder(dataSource);
TEST_EQUAL(languages::GetCurrentNorm(), "en", ());
auto const currentLocale = languages::GetCurrentNorm();
TestAddress(coder, {53.89815, 27.54265}, "vulicamiasnikova", "32");
TestAddress(coder, {53.89953, 27.54189}, "vulicaniamiha", "42");
TestAddress(coder, {53.89666, 27.54904}, "savieckajavulica", "19");
TestAddress(coder, {53.89724, 27.54983}, "praspiektniezalieznasci", "11");
TestAddress(coder, {53.89745, 27.55835}, "vulicakarlamarksa", "18А");
{
StringUtf8Multilang streetNames;
streetNames.AddString("default", "улица Мясникова");
streetNames.AddString("int_name", "vulica Miasnikova");
streetNames.AddString("be", "вуліца Мяснікова");
streetNames.AddString("ru", "улица Мясникова");
TestAddress(coder, mwmInfo, {53.89815, 27.54265}, streetNames, "32");
}
{
StringUtf8Multilang streetNames;
streetNames.AddString("default", "улица Немига");
streetNames.AddString("int_name", "vulica Niamiha");
streetNames.AddString("be", "вуліца Няміга");
streetNames.AddString("ru", "улица Немига");
TestAddress(coder, mwmInfo, {53.89953, 27.54189}, streetNames, "42");
}
{
StringUtf8Multilang streetNames;
streetNames.AddString("default", "Советская улица");
streetNames.AddString("int_name", "Savieckaja vulica");
streetNames.AddString("be", "Савецкая вуліца");
streetNames.AddString("ru", "Советская улица");
TestAddress(coder, mwmInfo, {53.89666, 27.54904}, streetNames, "19");
}
{
StringUtf8Multilang streetNames;
streetNames.AddString("default", "проспект Независимости");
streetNames.AddString("int_name", "praspiekt Niezaliežnasci");
streetNames.AddString("be", "праспект Незалежнасці");
streetNames.AddString("ru", "проспект Независимости");
TestAddress(coder, mwmInfo, {53.89724, 27.54983}, streetNames, "11");
}
{
StringUtf8Multilang streetNames;
streetNames.AddString("int_name", "vulica Karla Marksa");
streetNames.AddString("default", "улица Карла Маркса");
streetNames.AddString("be", "вуліца Карла Маркса");
streetNames.AddString("ru", "улица Карла Маркса");
TestAddress(coder, mwmInfo, {53.89745, 27.55835}, streetNames, "18А");
}
}

View file

@ -3,6 +3,8 @@
#include "drape_frontend/visual_params.hpp"
#include "indexer/data_header.hpp"
#include "indexer/feature_utils.hpp"
#include "indexer/mwm_set.hpp"
#include "map/bookmark_helpers.hpp"
#include "map/framework.hpp"
@ -13,6 +15,8 @@
#include "platform/platform.hpp"
#include "platform/preferred_languages.hpp"
#include "coding/string_utf8_multilang.hpp"
#include "coding/file_name_utils.hpp"
#include "coding/internal/file_data.hpp"
@ -20,6 +24,7 @@
#include <fstream>
#include <memory>
#include <set>
#include <string>
#include <vector>
using namespace std;
@ -438,12 +443,17 @@ UNIT_TEST(Bookmarks_Getting)
namespace
{
void CheckPlace(Framework const & fm, double lat, double lon, string const & street,
string const & houseNumber)
void CheckPlace(Framework const & fm, std::shared_ptr<MwmInfo> mwmInfo, double lat, double lon,
StringUtf8Multilang const & streetNames, string const & houseNumber)
{
auto const info = fm.GetAddressAtPoint(MercatorBounds::FromLatLon(lat, lon));
TEST_EQUAL(info.GetStreetName(), street, ());
std::string streetName;
auto const deviceLang = StringUtf8Multilang::GetLangIndex(languages::GetCurrentNorm());
feature::GetReadableName(mwmInfo->GetRegionData(), streetNames, deviceLang,
false /* allowTranslit */, streetName);
TEST_EQUAL(info.GetStreetName(), streetName, ());
TEST_EQUAL(info.GetHouseNumber(), houseNumber, ());
}
} // namespace
@ -453,13 +463,23 @@ UNIT_TEST(Bookmarks_AddressInfo)
// Maps added in constructor (we need minsk-pass.mwm only)
Framework fm(kFrameworkParams);
fm.DeregisterAllMaps();
fm.RegisterMap(platform::LocalCountryFile::MakeForTesting("minsk-pass"));
auto const regResult = fm.RegisterMap(platform::LocalCountryFile::MakeForTesting("minsk-pass"));
fm.OnSize(800, 600);
TEST_EQUAL(languages::GetCurrentNorm(), "en", ());
TEST_EQUAL(regResult.second, MwmSet::RegResult::Success, ());
CheckPlace(fm, 53.8964918, 27.555559, "vulica Karla Marksa", "10" /* houseNumber */);
CheckPlace(fm, 53.8964365, 27.5554007, "vulica Karla Marksa", "10" /* houseNumber */);
auto mwmInfo = regResult.first.GetInfo();
TEST(mwmInfo != nullptr, ());
StringUtf8Multilang streetNames;
streetNames.AddString("default", "улица Карла Маркса");
streetNames.AddString("int_name", "vulica Karla Marksa");
streetNames.AddString("be", "вуліца Карла Маркса");
streetNames.AddString("ru", "улица Карла Маркса");
CheckPlace(fm, mwmInfo, 53.8964918, 27.555559, streetNames, "10" /* houseNumber */);
CheckPlace(fm, mwmInfo, 53.8964365, 27.5554007, streetNames, "10" /* houseNumber */);
}
UNIT_TEST(Bookmarks_IllegalFileName)