[tests] Add ContriesNamesTest.

This commit is contained in:
tatiana-yan 2019-05-21 19:11:34 +03:00 committed by gmoryes
parent 670039d1fc
commit 04394def48
4 changed files with 113 additions and 2 deletions

View file

@ -10,6 +10,7 @@ set(
bookmarks_test.cpp
chart_generator_tests.cpp
cloud_tests.cpp
countries_names_tests.cpp
extrapolator_tests.cpp
feature_getters_tests.cpp
framework_light_tests.cpp

View file

@ -0,0 +1,99 @@
#include "testing/testing.hpp"
#include "map/framework.hpp"
#include "search/categories_cache.hpp"
#include "search/downloader_search_callback.hpp"
#include "search/mwm_context.hpp"
#include "search/utils.hpp"
#include "storage/storage.hpp"
#include "indexer/data_source.hpp"
#include "indexer/ftypes_matcher.hpp"
#include "indexer/mwm_set.hpp"
#include "coding/string_utf8_multilang.hpp"
#include "base/cancellable.hpp"
#include "base/checked_cast.hpp"
#include <algorithm>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace platform;
using namespace storage;
using namespace std;
UNIT_TEST(CountriesNamesTest)
{
Framework f(FrameworkParams(false /* m_enableLocalAds */, false /* m_enableDiffs */));
auto & storage = f.GetStorage();
auto handle = search::FindWorld(f.GetDataSource());
TEST(handle.IsAlive(), ());
FeaturesLoaderGuard g(f.GetDataSource(), handle.GetId());
auto & value = *handle.GetValue<MwmValue>();
TEST(value.HasSearchIndex(), ());
search::MwmContext const mwmContext(move(handle));
base::Cancellable const cancellable;
search::CategoriesCache cache(ftypes::IsLocalityChecker::Instance(), cancellable);
vector<int8_t> const langIndices = {StringUtf8Multilang::kEnglishCode,
StringUtf8Multilang::kDefaultCode,
StringUtf8Multilang::kInternationalCode};
// todo: (@t.yan) fix names for countries which have separate mwms.
set<string> const kIgnoreList = {"American Samoa",
"Sāmoa",
"Pitcairn",
"South Georgia and South Sandwich Islands",
"Lesotho",
"Eswatini",
"Republic of the Congo",
"Democratic Republic of the Congo",
"Aruba",
"Sint Maarten",
"Bahamas",
"Cabo Verde",
"Ivory Coast",
"Palestinian Territories",
"Turkish Republic Of Northern Cyprus",
"Nagorno-Karabakh Republic",
"Vatican City",
"North Macedonia",
"Kosovo",
"Czechia",
"Transnistria",
"Republic of Belarus",
"Hong Kong",
"Guam",
// MAPSME-10611
"Mayorca Residencial",
"Magnolias Residencial"};
auto const features = cache.Get(mwmContext);
features.ForEach([&](uint64_t fid) {
auto ft = g.GetFeatureByIndex(base::asserted_cast<uint32_t>(fid));
TEST(ft, ());
ftypes::Type const type = ftypes::IsLocalityChecker::Instance().GetType(*ft);
if (type != ftypes::COUNTRY)
return;
TEST(any_of(langIndices.begin(), langIndices.end(),
[&](uint8_t langIndex) {
string name;
if (!ft->GetName(langIndex, name))
return false;
return storage.IsNode(name) || kIgnoreList.count(name) != 0;
}),
("Cannot find countries.txt record for country feature:",
ft->DebugString(FeatureType::BEST_GEOMETRY)));
});
}

View file

@ -364,6 +364,13 @@ Country const & Storage::CountryByCountryId(CountryId const & countryId) const
return node->Value();
}
bool Storage::IsNode(CountryId const & countryId) const
{
if (!IsCountryIdValid(countryId))
return false;
return m_countries.FindFirst(countryId) != nullptr;
}
bool Storage::IsLeaf(CountryId const & countryId) const
{
if (!IsCountryIdValid(countryId))

View file

@ -536,9 +536,13 @@ public:
CountryId FindCountryIdByFile(string const & name) const;
// These two functions check whether |countryId| is a leaf
// or an inner node of the country tree.
// Returns true iff |countryId| exists as a node in the tree.
bool IsNode(CountryId const & countryId) const;
// Returns true iff |countryId| is a leaf of the tree.
bool IsLeaf(CountryId const & countryId) const;
// Returns true iff |countryId| is an inner node of the tree.
bool IsInnerNode(CountryId const & countryId) const;
LocalAndRemoteSize CountrySizeInBytes(CountryId const & countryId, MapOptions opt) const;