diff --git a/storage/country.cpp b/storage/country.cpp index 3b29b1f7fe..45181b5884 100644 --- a/storage/country.cpp +++ b/storage/country.cpp @@ -19,7 +19,7 @@ namespace storage using TMwmSubtreeAttrs = pair; template -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 -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(json_integer_value(json_object_get(j, "s"))), - static_cast(json_integer_value(json_object_get(j, "rs"))), depth, parent); + uint32_t const mwmSize = static_cast(json_integer_value(json_object_get(j, "s"))); + uint32_t const routingSize = static_cast(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 -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 -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 & 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()); - 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()); - 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)