diff --git a/qt/search_panel.cpp b/qt/search_panel.cpp index 3787a78dce..46f4bd7adf 100644 --- a/qt/search_panel.cpp +++ b/qt/search_panel.cpp @@ -228,7 +228,7 @@ bool SearchPanel::TryMigrate(QString const & str) } }; - auto progressChanged = [](storage::TCountryId const & id, storage::LocalAndRemoteSizeT const & sz) + auto progressChanged = [](storage::TCountryId const & id, storage::TLocalAndRemoteSize const & sz) { LOG(LINFO, (id, "downloading progress:", sz)); }; diff --git a/qt/update_dialog.cpp b/qt/update_dialog.cpp index 4136c06a39..0685285470 100644 --- a/qt/update_dialog.cpp +++ b/qt/update_dialog.cpp @@ -157,7 +157,7 @@ namespace qt { QColor rowColor; QString statusString; - LocalAndRemoteSizeT size(0, 0); + TLocalAndRemoteSize size(0, 0); MapOptions const options = MapOptions::MapWithCarRouting; diff --git a/storage/storage.cpp b/storage/storage.cpp index aca35ea81c..af3782d5d6 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -291,18 +291,18 @@ bool Storage::IsCoutryIdInCountryTree(TCountryId const & countryId) const return m_countries.Find(Country(countryId)) != nullptr; } -LocalAndRemoteSizeT Storage::CountrySizeInBytes(TCountryId const & countryId, MapOptions opt) const +TLocalAndRemoteSize Storage::CountrySizeInBytes(TCountryId const & countryId, MapOptions opt) const { QueuedCountry const * queuedCountry = FindCountryInQueue(countryId); TLocalFilePtr localFile = GetLatestLocalFile(countryId); CountryFile const & countryFile = GetCountryFile(countryId); if (queuedCountry == nullptr) { - return LocalAndRemoteSizeT(GetLocalSize(localFile, opt), + return TLocalAndRemoteSize(GetLocalSize(localFile, opt), GetRemoteSize(countryFile, opt, GetCurrentDataVersion())); } - LocalAndRemoteSizeT sizes(0, GetRemoteSize(countryFile, opt, GetCurrentDataVersion())); + TLocalAndRemoteSize sizes(0, GetRemoteSize(countryFile, opt, GetCurrentDataVersion())); if (!m_downloader->IsIdle() && IsCountryFirstInQueue(countryId)) { sizes.first = m_downloader->GetDownloadingProgress().first + @@ -1130,9 +1130,9 @@ void Storage::GetNodeAttrs(TCountryId const & countryId, NodeAttrs & nodeAttrs) Country const & nodeValue = node->Value(); nodeAttrs.m_mwmCounter = nodeValue.GetSubtreeMwmCounter(); nodeAttrs.m_mwmSize = nodeValue.GetSubtreeMwmSizeBytes(); - TStatusAndError statusAndErr = ParseStatus(NodeStatus(*node)); - nodeAttrs.m_status = statusAndErr.first; - nodeAttrs.m_error = statusAndErr.second; + StatusAndError statusAndErr = ParseStatus(NodeStatus(*node)); + nodeAttrs.m_status = statusAndErr.status; + nodeAttrs.m_error = statusAndErr.error; // @TODO(bykoianko) NodeAttrs::m_nodeLocalName should be in local language. nodeAttrs.m_nodeLocalName = countryId; } diff --git a/storage/storage.hpp b/storage/storage.hpp index 8c3933a56f..ec3244f178 100644 --- a/storage/storage.hpp +++ b/storage/storage.hpp @@ -23,7 +23,7 @@ struct NodeAttrs { NodeAttrs() : m_mwmCounter(0), m_localMwmCounter(0), m_mwmSize(0), m_localMwmSize(0), m_downloadingMwmSize(0), m_downloadingProgress(0), - m_status(TNodeStatus::Undefined), m_error(TErrNodeStatus::NoError) {} + m_status(TNodeStatus::Undefined), m_error(TNodeErrorCode::NoError) {} /// If the node is expandable (a big country) |m_mwmCounter| is number of mwm files (leaves) /// belongs to the node. If the node isn't expandable |m_mapsDownloaded| == 1. uint32_t m_mwmCounter; @@ -64,7 +64,7 @@ struct NodeAttrs uint8_t m_downloadingProgress; TNodeStatus m_status; - TErrNodeStatus m_error; + TNodeErrorCode m_error; }; /// This class is used for downloading, updating and deleting maps. @@ -74,7 +74,7 @@ public: struct StatusCallback; using TUpdate = function; using TChangeCountryFunction = function; - using TProgressFunction = function; + using TProgressFunction = function; private: /// We support only one simultaneous request at the moment @@ -349,7 +349,7 @@ public: string const & CountryName(TCountryId const & countryId) const; bool IsCoutryIdInCountryTree(TCountryId const & countryId) const; - LocalAndRemoteSizeT CountrySizeInBytes(TCountryId const & countryId, MapOptions opt) const; + TLocalAndRemoteSize CountrySizeInBytes(TCountryId const & countryId, MapOptions opt) const; platform::CountryFile const & GetCountryFile(TCountryId const & countryId) const; TLocalFilePtr GetLatestLocalFile(platform::CountryFile const & countryFile) const; TLocalFilePtr GetLatestLocalFile(TCountryId const & countryId) const; diff --git a/storage/storage_defines.cpp b/storage/storage_defines.cpp index 861304f7c2..6f252f5ad2 100644 --- a/storage/storage_defines.cpp +++ b/storage/storage_defines.cpp @@ -1,5 +1,7 @@ #include "storage/storage_defines.hpp" +#include "std/sstream.hpp" + namespace storage { string DebugPrint(TStatus status) @@ -52,45 +54,53 @@ string DebugPrint(TNodeStatus status) } } -string DebugPrint(TErrNodeStatus status) +string DebugPrint(TNodeErrorCode status) { switch (status) { - case TErrNodeStatus::NoError: + case TNodeErrorCode::NoError: return string("NoError"); - case TErrNodeStatus::UnknownError: + case TNodeErrorCode::UnknownError: return string("UnknownError"); - case TErrNodeStatus::OutOfMemFailed: + case TNodeErrorCode::OutOfMemFailed: return string("OutOfMemFailed"); - case TErrNodeStatus::NoInetConnection: + case TNodeErrorCode::NoInetConnection: return string("NoInetConnection"); } } -TStatusAndError ParseStatus(TStatus innerStatus) +StatusAndError ParseStatus(TStatus innerStatus) { switch (innerStatus) { case TStatus::EUndefined: - return TStatusAndError(TNodeStatus::Undefined, TErrNodeStatus::NoError); + return StatusAndError(TNodeStatus::Undefined, TNodeErrorCode::NoError); case TStatus::EOnDisk: - return TStatusAndError(TNodeStatus::OnDisk, TErrNodeStatus::NoError); + return StatusAndError(TNodeStatus::OnDisk, TNodeErrorCode::NoError); case TStatus::ENotDownloaded: - return TStatusAndError(TNodeStatus::NotDownloaded, TErrNodeStatus::NoError); + return StatusAndError(TNodeStatus::NotDownloaded, TNodeErrorCode::NoError); case TStatus::EDownloadFailed: - return TStatusAndError(TNodeStatus::Error, TErrNodeStatus::NoInetConnection); + return StatusAndError(TNodeStatus::Error, TNodeErrorCode::NoInetConnection); case TStatus::EDownloading: - return TStatusAndError(TNodeStatus::Downloading, TErrNodeStatus::NoError); + return StatusAndError(TNodeStatus::Downloading, TNodeErrorCode::NoError); case TStatus::EInQueue: - return TStatusAndError(TNodeStatus::InQueue, TErrNodeStatus::NoError); + return StatusAndError(TNodeStatus::InQueue, TNodeErrorCode::NoError); case TStatus::EUnknown: - return TStatusAndError(TNodeStatus::Error, TErrNodeStatus::UnknownError); + return StatusAndError(TNodeStatus::Error, TNodeErrorCode::UnknownError); case TStatus::EOnDiskOutOfDate: - return TStatusAndError(TNodeStatus::OnDiskOutOfDate, TErrNodeStatus::NoError); + return StatusAndError(TNodeStatus::OnDiskOutOfDate, TNodeErrorCode::NoError); case TStatus::EOutOfMemFailed: - return TStatusAndError(TNodeStatus::Error, TErrNodeStatus::OutOfMemFailed); + return StatusAndError(TNodeStatus::Error, TNodeErrorCode::OutOfMemFailed); case TStatus::EMixed: - return TStatusAndError(TNodeStatus::Mixed, TErrNodeStatus::NoError); + return StatusAndError(TNodeStatus::Mixed, TNodeErrorCode::NoError); } } + +string DebugPrint(StatusAndError statusAndError) +{ + ostringstream out; + out << "StatusAndError[" << DebugPrint(statusAndError.status) + << ", " << DebugPrint(statusAndError.error) << "]"; + return out.str(); +} } // namespace storage diff --git a/storage/storage_defines.hpp b/storage/storage_defines.hpp index 06d63d3551..3de1e17959 100644 --- a/storage/storage_defines.hpp +++ b/storage/storage_defines.hpp @@ -38,19 +38,33 @@ namespace storage }; string DebugPrint(TNodeStatus status); - enum class TErrNodeStatus + enum class TNodeErrorCode { NoError, UnknownError, /**< Downloading failed because of unknown error. */ OutOfMemFailed, /**< Downloading failed because it's not enough memory */ NoInetConnection, /**< Downloading failed because internet connection was interrupted */ }; - string DebugPrint(TErrNodeStatus status); + string DebugPrint(TNodeErrorCode status); - using TStatusAndError = pair; - using LocalAndRemoteSizeT = pair; + struct StatusAndError + { + StatusAndError(TNodeStatus nodeStatus, TNodeErrorCode nodeError) : + status(nodeStatus), error(nodeError) {} - TStatusAndError ParseStatus(TStatus innerStatus); + bool operator==(StatusAndError const & other) + { + return other.status == status && other.error == error; + } + + TNodeStatus status; + TNodeErrorCode error; + }; + string DebugPrint(StatusAndError statusAndError); + + using TLocalAndRemoteSize = pair; + + StatusAndError ParseStatus(TStatus innerStatus); } // namespace storage using TDownloadFn = function; diff --git a/storage/storage_integration_tests/migrate_tests.cpp b/storage/storage_integration_tests/migrate_tests.cpp index c98499b682..dca8252905 100644 --- a/storage/storage_integration_tests/migrate_tests.cpp +++ b/storage/storage_integration_tests/migrate_tests.cpp @@ -69,7 +69,7 @@ UNIT_TEST(StorageMigrationTests) } }; - auto progressChanged = [](TCountryId const & id, LocalAndRemoteSizeT const & sz) + auto progressChanged = [](TCountryId const & id, TLocalAndRemoteSize const & sz) { LOG_SHORT(LINFO, (id, "downloading progress:", sz)); }; diff --git a/storage/storage_integration_tests/storage_downloading_tests.cpp b/storage/storage_integration_tests/storage_downloading_tests.cpp index 1eb3cb7cb7..bad79c6708 100644 --- a/storage/storage_integration_tests/storage_downloading_tests.cpp +++ b/storage/storage_integration_tests/storage_downloading_tests.cpp @@ -67,7 +67,7 @@ UNIT_TEST(SmallMwms_InterruptDownloadResumeDownload_Test) Storage storage(COUNTRIES_MIGRATE_FILE); TEST(version::IsSingleMwm(storage.GetCurrentDataVersion()), ()); - auto onProgressFn = [](TCountryId const & countryId, LocalAndRemoteSizeT const & mapSize) + auto onProgressFn = [](TCountryId const & countryId, TLocalAndRemoteSize const & mapSize) { TEST_EQUAL(countryId, kCountryId, ()); // Interrupt download @@ -90,7 +90,7 @@ UNIT_TEST(SmallMwms_InterruptDownloadResumeDownload_Test) Storage storage(COUNTRIES_MIGRATE_FILE); - auto onProgressFn = [](TCountryId const & countryId, LocalAndRemoteSizeT const & mapSize) + auto onProgressFn = [](TCountryId const & countryId, TLocalAndRemoteSize const & mapSize) { TEST_EQUAL(countryId, kCountryId, ()); }; diff --git a/storage/storage_integration_tests/storage_group_download_tests.cpp b/storage/storage_integration_tests/storage_group_download_tests.cpp index d3b55056b7..d41b69bff8 100644 --- a/storage/storage_integration_tests/storage_group_download_tests.cpp +++ b/storage/storage_integration_tests/storage_group_download_tests.cpp @@ -79,7 +79,7 @@ void DownloadGroup(Storage & storage, bool oneByOne) }; TCountriesSet downloaded; - auto onProgressFn = [&](TCountryId const & countryId, LocalAndRemoteSizeT const & mapSize) + auto onProgressFn = [&](TCountryId const & countryId, TLocalAndRemoteSize const & mapSize) { TEST(children.find(countryId) != children.end(), ()); if (mapSize.first == mapSize.second) diff --git a/storage/storage_integration_tests/storage_http_tests.cpp b/storage/storage_integration_tests/storage_http_tests.cpp index 3f18f10cef..340314e74b 100644 --- a/storage/storage_integration_tests/storage_http_tests.cpp +++ b/storage/storage_integration_tests/storage_http_tests.cpp @@ -30,7 +30,7 @@ string const kMapTestDir = "map-tests"; string const kTestWebServer = "http://new-search.mapswithme.com/"; -void ProgressFunction(TCountryId const & countryId, LocalAndRemoteSizeT const & mapSize) +void ProgressFunction(TCountryId const & countryId, TLocalAndRemoteSize const & mapSize) { TEST_EQUAL(countryId, kCountryId, ()); } diff --git a/storage/storage_integration_tests/storage_update_tests.cpp b/storage/storage_integration_tests/storage_update_tests.cpp index 920ed98a99..a84be7050e 100644 --- a/storage/storage_integration_tests/storage_update_tests.cpp +++ b/storage/storage_integration_tests/storage_update_tests.cpp @@ -84,7 +84,7 @@ UNIT_TEST(SmallMwms_Update_Test) Platform & platform = GetPlatform(); - auto onProgressFn = [&](TCountryId const & countryId, LocalAndRemoteSizeT const & mapSize) {}; + auto onProgressFn = [&](TCountryId const & countryId, TLocalAndRemoteSize const & mapSize) {}; // Download countries.txt for version 1 TEST(DownloadFile(GetCountriesTxtWebUrl(kMwmVersion1), GetCountriesTxtFilePath(), kCountriesTxtFileSize1), ()); diff --git a/storage/storage_tests/storage_tests.cpp b/storage/storage_tests/storage_tests.cpp index f93ce7a950..3a4ad1e46f 100644 --- a/storage/storage_tests/storage_tests.cpp +++ b/storage/storage_tests/storage_tests.cpp @@ -193,13 +193,13 @@ protected: ++m_currStatus; if (m_transitionList[m_currStatus] == TStatus::EDownloading) { - LocalAndRemoteSizeT localAndRemoteSize = m_storage.CountrySizeInBytes(m_countryId, m_files); + TLocalAndRemoteSize localAndRemoteSize = m_storage.CountrySizeInBytes(m_countryId, m_files); m_totalBytesToDownload = localAndRemoteSize.second; } } virtual void OnCountryDownloadingProgress(TCountryId const & countryId, - LocalAndRemoteSizeT const & progress) + TLocalAndRemoteSize const & progress) { if (countryId != m_countryId) return; @@ -210,7 +210,7 @@ protected: m_bytesDownloaded = progress.first; TEST_LESS_OR_EQUAL(m_bytesDownloaded, m_totalBytesToDownload, (m_countryFile)); - LocalAndRemoteSizeT localAndRemoteSize = m_storage.CountrySizeInBytes(m_countryId, m_files); + TLocalAndRemoteSize localAndRemoteSize = m_storage.CountrySizeInBytes(m_countryId, m_files); TEST_EQUAL(m_totalBytesToDownload, localAndRemoteSize.second, (m_countryFile)); } @@ -241,7 +241,7 @@ public: protected: // CountryDownloaderChecker overrides: void OnCountryDownloadingProgress(TCountryId const & countryId, - LocalAndRemoteSizeT const & progress) override + TLocalAndRemoteSize const & progress) override { CountryDownloaderChecker::OnCountryDownloadingProgress(countryId, progress); @@ -331,7 +331,7 @@ private: } void OnCountryDownloadingProgress(TCountryId const & /* countryId */, - LocalAndRemoteSizeT const & /* progress */) + TLocalAndRemoteSize const & /* progress */) { TEST(false, ("Unexpected country downloading progress.")); } @@ -382,7 +382,7 @@ public: QCoreApplication::exit(); } - void OnProgress(TCountryId const & /* countryId */, LocalAndRemoteSizeT const & /* progress */) {} + void OnProgress(TCountryId const & /* countryId */, TLocalAndRemoteSize const & /* progress */) {} private: Storage & m_storage; @@ -1167,27 +1167,28 @@ UNIT_TEST(StorageTest_GetNodeAttrsSingleMwm) TEST_EQUAL(nodeAttrs.m_mwmCounter, 1, ()); TEST_EQUAL(nodeAttrs.m_mwmSize, 4689718, ()); TEST_EQUAL(nodeAttrs.m_status, TNodeStatus::NotDownloaded, ()); - TEST_EQUAL(nodeAttrs.m_error, TErrNodeStatus::NoError, ()); + TEST_EQUAL(nodeAttrs.m_error, TNodeErrorCode::NoError, ()); storage.GetNodeAttrs("Algeria", nodeAttrs); TEST_EQUAL(nodeAttrs.m_mwmCounter, 2, ()); TEST_EQUAL(nodeAttrs.m_mwmSize, 90878678, ()); TEST_EQUAL(nodeAttrs.m_status, TNodeStatus::NotDownloaded, ()); - TEST_EQUAL(nodeAttrs.m_error, TErrNodeStatus::NoError, ()); + TEST_EQUAL(nodeAttrs.m_error, TNodeErrorCode::NoError, ()); storage.GetNodeAttrs("South Korea_South", nodeAttrs); TEST_EQUAL(nodeAttrs.m_mwmCounter, 1, ()); TEST_EQUAL(nodeAttrs.m_mwmSize, 48394664, ()); TEST_EQUAL(nodeAttrs.m_status, TNodeStatus::NotDownloaded, ()); - TEST_EQUAL(nodeAttrs.m_error, TErrNodeStatus::NoError, ()); + TEST_EQUAL(nodeAttrs.m_error, TNodeErrorCode::NoError, ()); } + UNIT_TEST(StorageTest_ParseStatus) { - TEST_EQUAL(TStatusAndError(TNodeStatus::Undefined, TErrNodeStatus::NoError), + TEST_EQUAL(StatusAndError(TNodeStatus::Undefined, TNodeErrorCode::NoError), ParseStatus(TStatus::EUndefined), ()); - TEST_EQUAL(TStatusAndError(TNodeStatus::Error, TErrNodeStatus::NoInetConnection), + TEST_EQUAL(StatusAndError(TNodeStatus::Error, TNodeErrorCode::NoInetConnection), ParseStatus(TStatus::EDownloadFailed), ()); - TEST_EQUAL(TStatusAndError(TNodeStatus::Downloading, TErrNodeStatus::NoError), + TEST_EQUAL(StatusAndError(TNodeStatus::Downloading, TNodeErrorCode::NoError), ParseStatus(TStatus::EDownloading), ()); } } // namespace storage