forked from organicmaps/organicmaps
[new downloader] Review fixes.
This commit is contained in:
parent
d99e6c7458
commit
eaf0be4936
2 changed files with 36 additions and 44 deletions
|
@ -19,7 +19,7 @@ namespace storage
|
|||
using TMwmSubtreeAttrs = pair<uint32_t, size_t>;
|
||||
|
||||
template <class ToDo>
|
||||
TMwmSubtreeAttrs LoadGroupSingleMwmsImpl(int depth, json_t * group, ToDo & toDo, TCountryId const & parent)
|
||||
TMwmSubtreeAttrs LoadGroupSingleMwmsImpl(int depth, json_t * group, TCountryId const & parent, ToDo & toDo)
|
||||
{
|
||||
uint32_t mwmCounter = 0;
|
||||
size_t mwmSize = 0;
|
||||
|
@ -52,7 +52,7 @@ TMwmSubtreeAttrs LoadGroupSingleMwmsImpl(int depth, json_t * group, ToDo & toDo,
|
|||
json_t * children = json_object_get(j, "g");
|
||||
if (children)
|
||||
{
|
||||
TMwmSubtreeAttrs childAttr = LoadGroupSingleMwmsImpl(depth + 1, children, toDo, id);
|
||||
TMwmSubtreeAttrs childAttr = LoadGroupSingleMwmsImpl(depth + 1, children, id, toDo);
|
||||
mwmChildCounter = childAttr.first;
|
||||
mwmChildSize = childAttr.second;
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ TMwmSubtreeAttrs LoadGroupSingleMwmsImpl(int depth, json_t * group, ToDo & toDo,
|
|||
}
|
||||
|
||||
template <class ToDo>
|
||||
void LoadGroupTwoComponentMwmsImpl(int depth, json_t * group, ToDo & toDo, TCountryId const & parent)
|
||||
void LoadGroupTwoComponentMwmsImpl(int depth, json_t * group, TCountryId const & parent, ToDo & toDo)
|
||||
{
|
||||
// @TODO(bykoianko) After we stop supporting two component mwms (with routing files)
|
||||
// remove code below.
|
||||
|
@ -80,28 +80,28 @@ void LoadGroupTwoComponentMwmsImpl(int depth, json_t * group, ToDo & toDo, TCoun
|
|||
{
|
||||
json_t * j = json_array_get(group, i);
|
||||
|
||||
// name is mandatory
|
||||
char const * name = json_string_value(json_object_get(j, "n"));
|
||||
if (!name)
|
||||
MYTHROW(my::Json::Exception, ("Country name is missing"));
|
||||
|
||||
char const * file = json_string_value(json_object_get(j, "f"));
|
||||
// if file is empty, it's the same as the name
|
||||
if (!file)
|
||||
file = name;
|
||||
{
|
||||
file = json_string_value(json_object_get(j, "n"));
|
||||
if (!file)
|
||||
MYTHROW(my::Json::Exception, ("Country name is missing"));
|
||||
}
|
||||
|
||||
// We expect that mwm and routing files should be less than 2GB.
|
||||
toDo(file, static_cast<uint32_t>(json_integer_value(json_object_get(j, "s"))),
|
||||
static_cast<uint32_t>(json_integer_value(json_object_get(j, "rs"))), depth, parent);
|
||||
uint32_t const mwmSize = static_cast<uint32_t>(json_integer_value(json_object_get(j, "s")));
|
||||
uint32_t const routingSize = static_cast<uint32_t>(json_integer_value(json_object_get(j, "rs")));
|
||||
toDo(file, mwmSize, routingSize, depth, parent);
|
||||
|
||||
json_t * children = json_object_get(j, "g");
|
||||
if (children)
|
||||
LoadGroupTwoComponentMwmsImpl(depth + 1, children, toDo, file);
|
||||
LoadGroupTwoComponentMwmsImpl(depth + 1, children, file, toDo);
|
||||
}
|
||||
}
|
||||
|
||||
template <class ToDo>
|
||||
bool LoadCountriesSingleMwmsImpl(string const & jsonBuffer, ToDo & toDo, TCountryId const & parent)
|
||||
bool LoadCountriesSingleMwmsImpl(string const & jsonBuffer,TCountryId const & parent, ToDo & toDo)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -109,7 +109,7 @@ bool LoadCountriesSingleMwmsImpl(string const & jsonBuffer, ToDo & toDo, TCountr
|
|||
json_t * children = json_object_get(root.get(), "g");
|
||||
if (!children)
|
||||
MYTHROW(my::Json::Exception, ("Root country doesn't have any groups"));
|
||||
TMwmSubtreeAttrs const treeAttrs = LoadGroupSingleMwmsImpl(0, children, toDo, parent);
|
||||
TMwmSubtreeAttrs const treeAttrs = LoadGroupSingleMwmsImpl(0 /* depth */, children, parent, toDo);
|
||||
toDo.SetCountriesContainerAttrs(treeAttrs.first /* mwmNumber */,
|
||||
treeAttrs.second /* mwmSizeBytes */);
|
||||
return true;
|
||||
|
@ -122,7 +122,7 @@ bool LoadCountriesSingleMwmsImpl(string const & jsonBuffer, ToDo & toDo, TCountr
|
|||
}
|
||||
|
||||
template <class ToDo>
|
||||
bool LoadCountriesTwoComponentMwmsImpl(string const & jsonBuffer, ToDo & toDo, TCountryId const & parent)
|
||||
bool LoadCountriesTwoComponentMwmsImpl(string const & jsonBuffer, TCountryId const & parent, ToDo & toDo)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -130,7 +130,7 @@ bool LoadCountriesTwoComponentMwmsImpl(string const & jsonBuffer, ToDo & toDo, T
|
|||
json_t * children = json_object_get(root.get(), "g");
|
||||
if (!children)
|
||||
MYTHROW(my::Json::Exception, ("Root country doesn't have any groups"));
|
||||
LoadGroupTwoComponentMwmsImpl(0, children, toDo, parent);
|
||||
LoadGroupTwoComponentMwmsImpl(0 /* depth */, children, parent, toDo);
|
||||
return true;
|
||||
}
|
||||
catch (my::Json::Exception const & e)
|
||||
|
@ -150,7 +150,7 @@ class DoStoreCountriesSingleMwms
|
|||
public:
|
||||
DoStoreCountriesSingleMwms(TCountriesContainer & cont) : m_cont(cont) {}
|
||||
|
||||
Country * operator()(string const & id, uint32_t mapSize, int depth, TCountryId const & parent)
|
||||
Country * operator()(TCountryId const & id, uint32_t mapSize, int depth, TCountryId const & parent)
|
||||
{
|
||||
Country country(id, parent);
|
||||
if (mapSize)
|
||||
|
@ -205,7 +205,7 @@ public:
|
|||
DoStoreFile2InfoSingleMwms(map<string, CountryInfo> & file2info)
|
||||
: m_file2info(file2info) {}
|
||||
|
||||
Country * operator()(string const & id, uint32_t /* mapSize */, int /* depth */,
|
||||
Country * operator()(TCountryId const & id, uint32_t /* mapSize */, int /* depth */,
|
||||
TCountryId const & /* parent */)
|
||||
{
|
||||
CountryInfo info(id);
|
||||
|
@ -267,7 +267,7 @@ int64_t LoadCountries(string const & jsonBuffer, TCountriesContainer & countries
|
|||
if (isSingleMwm)
|
||||
{
|
||||
DoStoreCountriesSingleMwms doStore(countries);
|
||||
if (!LoadCountriesSingleMwmsImpl(jsonBuffer, doStore, id))
|
||||
if (!LoadCountriesSingleMwmsImpl(jsonBuffer, id, doStore))
|
||||
return -1;
|
||||
if (mapping)
|
||||
*mapping = doStore.GetMapping();
|
||||
|
@ -275,7 +275,7 @@ int64_t LoadCountries(string const & jsonBuffer, TCountriesContainer & countries
|
|||
else
|
||||
{
|
||||
DoStoreCountriesTwoComponentMwms doStore(countries);
|
||||
if (!LoadCountriesTwoComponentMwmsImpl(jsonBuffer, doStore, id))
|
||||
if (!LoadCountriesTwoComponentMwmsImpl(jsonBuffer, id, doStore))
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -300,12 +300,12 @@ void LoadCountryFile2CountryInfo(string const & jsonBuffer, map<string, CountryI
|
|||
if (isSingleMwm)
|
||||
{
|
||||
DoStoreFile2InfoSingleMwms doStore(id2info);
|
||||
LoadCountriesSingleMwmsImpl(jsonBuffer, doStore, kInvalidCountryId);
|
||||
LoadCountriesSingleMwmsImpl(jsonBuffer, kInvalidCountryId, doStore);
|
||||
}
|
||||
else
|
||||
{
|
||||
DoStoreFile2InfoTwoComponentMwms doStore(id2info);
|
||||
LoadCountriesTwoComponentMwmsImpl(jsonBuffer, doStore, kInvalidCountryId);
|
||||
LoadCountriesTwoComponentMwmsImpl(jsonBuffer, kInvalidCountryId, doStore);
|
||||
}
|
||||
}
|
||||
catch (my::Json::Exception const & e)
|
||||
|
|
|
@ -142,6 +142,12 @@ string const kTwoComponentMwmCountriesTxt =
|
|||
}
|
||||
]}]})");
|
||||
|
||||
bool ParentOf(Storage const & storage, string const & parent, string const & country)
|
||||
{
|
||||
Country const c = storage.CountryByCountryId(country);
|
||||
return c.GetParent() == parent;
|
||||
}
|
||||
|
||||
// This class checks steps Storage::DownloadMap() performs to download a map.
|
||||
class CountryDownloaderChecker
|
||||
{
|
||||
|
@ -1162,34 +1168,20 @@ UNIT_TEST(StorageTest_ParentSingleMwm)
|
|||
{
|
||||
Storage storage(kSingleMwmCountriesTxt, make_unique<TestMapFilesDownloader>());
|
||||
|
||||
Country const abkhaziaCountry = storage.CountryByCountryId("Abkhazia");
|
||||
TEST_EQUAL(abkhaziaCountry.GetParent(), "Countries", ());
|
||||
|
||||
Country const algeriaCentralCountry = storage.CountryByCountryId("Algeria_Central");
|
||||
TEST_EQUAL(algeriaCentralCountry.GetParent(), "Algeria", ());
|
||||
|
||||
Country const southKoreaCountry = storage.CountryByCountryId("South Korea_South");
|
||||
TEST_EQUAL(southKoreaCountry.GetParent(), "Countries", ());
|
||||
|
||||
Country const countries = storage.CountryByCountryId("Countries");
|
||||
TEST_EQUAL(countries.GetParent(), kInvalidCountryId, ());
|
||||
TEST(ParentOf(storage, "Countries", "Abkhazia"), ());
|
||||
TEST(ParentOf(storage, "Algeria", "Algeria_Central"), ());
|
||||
TEST(ParentOf(storage, "Countries", "South Korea_South"), ());
|
||||
TEST(ParentOf(storage, kInvalidCountryId, "Countries"), ());
|
||||
}
|
||||
|
||||
UNIT_TEST(StorageTest_ParentTwoComponentsMwm)
|
||||
{
|
||||
Storage storage(kTwoComponentMwmCountriesTxt, make_unique<TestMapFilesDownloader>());
|
||||
|
||||
Country const africaCountry = storage.CountryByCountryId("Africa");
|
||||
TEST_EQUAL(africaCountry.GetParent(), "Countries", ());
|
||||
|
||||
Country const algeriaCountry = storage.CountryByCountryId("Algeria");
|
||||
TEST_EQUAL(algeriaCountry.GetParent(), "Africa", ());
|
||||
|
||||
Country const alsaceCountry = storage.CountryByCountryId("France_Alsace");
|
||||
TEST_EQUAL(alsaceCountry.GetParent(), "France", ());
|
||||
|
||||
Country const countries = storage.CountryByCountryId("Countries");
|
||||
TEST_EQUAL(countries.GetParent(), kInvalidCountryId, ());
|
||||
TEST(ParentOf(storage, "Countries", "Africa"), ());
|
||||
TEST(ParentOf(storage, "Africa", "Algeria"), ());
|
||||
TEST(ParentOf(storage, "France", "France_Alsace"), ());
|
||||
TEST(ParentOf(storage, kInvalidCountryId, "Countries"), ());
|
||||
}
|
||||
|
||||
UNIT_TEST(StorageTest_GetNodeAttrsSingleMwm)
|
||||
|
|
Loading…
Add table
Reference in a new issue