From 5cc60e88d5785e492240adc0f5c3bd250016eb87 Mon Sep 17 00:00:00 2001 From: "r.kuznetsov" Date: Fri, 25 Aug 2017 13:41:48 +0300 Subject: [PATCH] Fixed tests affected by diffs --- map/framework.cpp | 5 +- map/framework.hpp | 10 +- map/map_tests/bookmarks_test.cpp | 24 +-- map/map_tests/feature_getters_tests.cpp | 2 +- map/map_tests/kmz_unarchive_test.cpp | 2 +- map/map_tests/mwm_url_tests.cpp | 181 +++++++++--------- mapshot/mapshot.cpp | 2 +- .../openlr_assessment_tool/main.cpp | 2 +- platform/http_request.cpp | 2 +- .../assessment_tool/assessment_tool.cpp | 2 +- .../migrate_tests.cpp | 6 +- .../storage_3levels_tests.cpp | 2 +- .../storage_update_tests.cpp | 6 +- 13 files changed, 132 insertions(+), 114 deletions(-) diff --git a/map/framework.cpp b/map/framework.cpp index aa1e7c37ad..0c0dd6d3dc 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -405,6 +405,7 @@ Framework::Framework(FrameworkParams const & params) m_drapeEngine->SetDisplacementMode(mode); }) , m_lastReportedCountry(kInvalidCountryId) + , m_enabledDiffs(params.m_enableDiffs) { m_startBackgroundTime = my::Timer::LocalTime(); @@ -468,7 +469,7 @@ Framework::Framework(FrameworkParams const & params) LOG(LDEBUG, ("Storage initialized")); // Local ads manager should be initialized after storage initialization. - if (!params.m_disableLocalAds) + if (params.m_enableLocalAds) { m_localAdsManager.SetBookmarkManager(&m_bmManager); m_localAdsManager.Startup(); @@ -655,7 +656,7 @@ void Framework::RegisterAllMaps() ("Registering maps while map downloading leads to removing downloading maps from " "ActiveMapsListener::m_items.")); - m_storage.RegisterAllLocalMaps(true /* enableDiffs */); + m_storage.RegisterAllLocalMaps(m_enabledDiffs); // Fast migrate in case there are no downloaded MWM. if (platform::migrate::NeedMigrate()) diff --git a/map/framework.hpp b/map/framework.hpp index 0046c362ad..592876897e 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -110,7 +110,14 @@ class Engine; struct FrameworkParams { - bool m_disableLocalAds = false; + bool m_enableLocalAds = true; + bool m_enableDiffs = true; + + FrameworkParams() = default; + FrameworkParams(bool enableLocalAds, bool enableDiffs) + : m_enableLocalAds(enableLocalAds) + , m_enableDiffs(enableDiffs) + {} }; class Framework : public search::ViewportSearchCallback::Delegate, @@ -174,6 +181,7 @@ protected: StorageDownloadingPolicy m_storageDownloadingPolicy; storage::Storage m_storage; + bool m_enabledDiffs; location::TMyPositionModeChanged m_myPositionListener; diff --git a/map/map_tests/bookmarks_test.cpp b/map/map_tests/bookmarks_test.cpp index 9113a0b069..9716b3345d 100644 --- a/map/map_tests/bookmarks_test.cpp +++ b/map/map_tests/bookmarks_test.cpp @@ -18,6 +18,8 @@ namespace { +static FrameworkParams const kFrameworkParams(false /* m_enableLocalAds */, false /* m_enableDiffs */); + char const * kmlString = "" "" @@ -155,7 +157,7 @@ char const * kmlString = UNIT_TEST(Bookmarks_ImportKML) { - Framework framework; + Framework framework(kFrameworkParams); df::VisualParams::Init(1.0, 1024); BookmarkCategory cat("Default", framework); @@ -172,7 +174,7 @@ UNIT_TEST(Bookmarks_ExportKML) { char const * BOOKMARKS_FILE_NAME = "UnitTestBookmarks.kml"; - Framework framework; + Framework framework(kFrameworkParams); df::VisualParams::Init(1.0, 1024); BookmarkCategory cat("Default", framework); @@ -263,7 +265,7 @@ namespace UNIT_TEST(Bookmarks_Timestamp) { - Framework fm; + Framework fm(kFrameworkParams); df::VisualParams::Init(1.0, 1024); m2::PointD const orgPoint(10, 10); @@ -309,7 +311,7 @@ UNIT_TEST(Bookmarks_Timestamp) UNIT_TEST(Bookmarks_Getting) { - Framework fm; + Framework fm(kFrameworkParams); df::VisualParams::Init(1.0, 1024); fm.OnSize(800, 400); fm.ShowRect(m2::RectD(0, 0, 80, 40)); @@ -401,7 +403,7 @@ namespace UNIT_TEST(Bookmarks_AddressInfo) { // Maps added in constructor (we need minsk-pass.mwm only) - Framework fm; + Framework fm(kFrameworkParams); fm.DeregisterAllMaps(); fm.RegisterMap(platform::LocalCountryFile::MakeForTesting("minsk-pass")); fm.OnSize(800, 600); @@ -464,7 +466,7 @@ UNIT_TEST(Bookmarks_UniqueFileName) UNIT_TEST(Bookmarks_AddingMoving) { - Framework fm; + Framework fm(kFrameworkParams); fm.OnSize(800, 400); fm.ShowRect(m2::RectD(0, 0, 80, 40)); @@ -540,7 +542,7 @@ char const * kmlString2 = UNIT_TEST(Bookmarks_InnerFolder) { - Framework framework; + Framework framework(kFrameworkParams); BookmarkCategory cat("Default", framework); TEST(cat.LoadFromKML(make_unique(kmlString2, strlen(kmlString2))), ()); @@ -549,7 +551,7 @@ UNIT_TEST(Bookmarks_InnerFolder) UNIT_TEST(BookmarkCategory_EmptyName) { - Framework framework; + Framework framework(kFrameworkParams); unique_ptr pCat(new BookmarkCategory("", framework)); static_cast(pCat->CreateUserMark(m2::PointD(0, 0)))->SetData(BookmarkData("", "placemark-red")); TEST(pCat->SaveToKMLFile(), ()); @@ -599,7 +601,7 @@ char const * kmlString3 = UNIT_TEST(Bookmarks_SpecialXMLNames) { - Framework framework; + Framework framework(kFrameworkParams); BookmarkCategory cat1("", framework); TEST(cat1.LoadFromKML(make_unique(kmlString3, strlen(kmlString3))), ()); @@ -623,7 +625,7 @@ UNIT_TEST(Bookmarks_SpecialXMLNames) UNIT_TEST(TrackParsingTest_1) { - Framework framework; + Framework framework(kFrameworkParams); string const kmlFile = GetPlatform().TestsDataPathForFile("kml-with-track-kml.test"); BookmarkCategory * cat = BookmarkCategory::CreateFromKMLFile(kmlFile, framework); TEST(cat, ("Category can't be created")); @@ -649,7 +651,7 @@ UNIT_TEST(TrackParsingTest_1) UNIT_TEST(TrackParsingTest_2) { - Framework framework; + Framework framework(kFrameworkParams); string const kmlFile = GetPlatform().TestsDataPathForFile("kml-with-track-from-google-earth.test"); BookmarkCategory * cat = BookmarkCategory::CreateFromKMLFile(kmlFile, framework); TEST(cat, ("Category can't be created")); diff --git a/map/map_tests/feature_getters_tests.cpp b/map/map_tests/feature_getters_tests.cpp index bf58d74bae..662ed1fc8d 100644 --- a/map/map_tests/feature_getters_tests.cpp +++ b/map/map_tests/feature_getters_tests.cpp @@ -13,7 +13,7 @@ UNIT_TEST(Framework_ForEachFeatureAtPoint_And_Others) { - Framework frm; + Framework frm(FrameworkParams(false /* m_enableLocalAds */, false /* m_enableDiffs */)); frm.DeregisterAllMaps(); frm.RegisterMap(platform::LocalCountryFile::MakeForTesting("minsk-pass")); diff --git a/map/map_tests/kmz_unarchive_test.cpp b/map/map_tests/kmz_unarchive_test.cpp index 5690e5e48e..4aaa3a83ed 100644 --- a/map/map_tests/kmz_unarchive_test.cpp +++ b/map/map_tests/kmz_unarchive_test.cpp @@ -35,7 +35,7 @@ UNIT_TEST(KMZ_UnzipTest) MY_SCOPE_GUARD(fileGuard, bind(&FileWriter::DeleteFileX, kmlFile)); ZipFileReader::UnzipFile(kmzFile, "doc.kml", kmlFile); - Framework framework; + Framework framework(FrameworkParams(false /* m_enableLocalAds */, false /* m_enableDiffs */)); BookmarkCategory cat("Default", framework); TEST(cat.LoadFromKML(make_unique(kmlFile)), ()); diff --git a/map/map_tests/mwm_url_tests.cpp b/map/map_tests/mwm_url_tests.cpp index d453724067..251517c5b1 100644 --- a/map/map_tests/mwm_url_tests.cpp +++ b/map/map_tests/mwm_url_tests.cpp @@ -17,96 +17,99 @@ using namespace url_scheme; namespace { - void ToMercatoToLatLon(double & lat, double & lon) +static FrameworkParams const kFrameworkParams(false /* m_enableLocalAds */, false /* m_enableDiffs */); + +void ToMercatoToLatLon(double & lat, double & lon) +{ + lon = MercatorBounds::XToLon(MercatorBounds::LonToX(lon)); + lat = MercatorBounds::YToLat(MercatorBounds::LatToY(lat)); +} + +UserMarkType const type = UserMarkType::API_MARK; + +class ApiTest +{ +public: + ApiTest(string const & uriString) + : m_fm(kFrameworkParams) { - lon = MercatorBounds::XToLon(MercatorBounds::LonToX(lon)); - lat = MercatorBounds::YToLat(MercatorBounds::LatToY(lat)); + m_m = &m_fm.GetBookmarkManager(); + m_api.SetBookmarkManager(m_m); + + auto const res = m_api.SetUriAndParse(uriString); + if (res != ParsedMapApi::ParsingResult::Incorrect) + { + if (!m_api.GetViewportRect(m_viewportRect)) + m_viewportRect = df::GetWorldRect(); + } } - UserMarkType const type = UserMarkType::API_MARK; + bool IsValid() const { return m_api.IsValid(); } + m2::RectD GetViewport() const { return m_viewportRect; } - class ApiTest + string const & GetAppTitle() const { return m_api.GetAppTitle(); } + bool GoBackOnBalloonClick() const { return m_api.GoBackOnBalloonClick(); } + + size_t GetPointCount() const { - public: - ApiTest(string const & uriString) - { - m_m = &m_fm.GetBookmarkManager(); - m_api.SetBookmarkManager(m_m); - - auto const res = m_api.SetUriAndParse(uriString); - if (res != ParsedMapApi::ParsingResult::Incorrect) - { - if (!m_api.GetViewportRect(m_viewportRect)) - m_viewportRect = df::GetWorldRect(); - } - } - - bool IsValid() const { return m_api.IsValid(); } - m2::RectD GetViewport() const { return m_viewportRect; } - - string const & GetAppTitle() const { return m_api.GetAppTitle(); } - bool GoBackOnBalloonClick() const { return m_api.GoBackOnBalloonClick(); } - - size_t GetPointCount() const - { - return UserMarkNotificationGuard(*m_m, type).m_controller.GetUserMarkCount(); - } - - vector GetRoutePoints() const { return m_api.GetRoutePoints(); } - url_scheme::SearchRequest const & GetSearchRequest() const { return m_api.GetSearchRequest(); } - string const & GetGlobalBackUrl() const { return m_api.GetGlobalBackUrl(); } - int GetApiVersion() const { return m_api.GetApiVersion(); } - - bool TestLatLon(int index, double lat, double lon) const - { - ms::LatLon const ll = GetMark(index)->GetLatLon(); - return my::AlmostEqualULPs(ll.lat, lat) && my::AlmostEqualULPs(ll.lon, lon); - } - - bool TestRoutePoint(int index, double lat, double lon, string const & name) - { - RoutePoint const pt = GetRoutePoints()[index]; - return pt.m_org == MercatorBounds::FromLatLon(lat, lon) && pt.m_name == name; - } - - bool TestName(int index, string const & name) const - { - return GetMark(index)->GetName() == name; - } - - bool TestID(int index, string const & id) const - { - return GetMark(index)->GetApiID() == id; - } - - bool TestRouteType(string const & type) const { return m_api.GetRoutingType() == type; } - private: - ApiMarkPoint const * GetMark(int index) const - { - UserMarkNotificationGuard guard(*m_m, type); - TEST_LESS(index, static_cast(guard.m_controller.GetUserMarkCount()), ()); - return static_cast(guard.m_controller.GetUserMark(index)); - } - - private: - Framework m_fm; - ParsedMapApi m_api; - m2::RectD m_viewportRect; - BookmarkManager * m_m; - }; - - bool IsValid(Framework & fm, string const & uriString) - { - ParsedMapApi api; - api.SetBookmarkManager(&fm.GetBookmarkManager()); - api.SetUriAndParse(uriString); - { - UserMarkNotificationGuard guard(fm.GetBookmarkManager(), UserMarkType::API_MARK); - guard.m_controller.Clear(); - } - - return api.IsValid(); + return UserMarkNotificationGuard(*m_m, type).m_controller.GetUserMarkCount(); } + + vector GetRoutePoints() const { return m_api.GetRoutePoints(); } + url_scheme::SearchRequest const & GetSearchRequest() const { return m_api.GetSearchRequest(); } + string const & GetGlobalBackUrl() const { return m_api.GetGlobalBackUrl(); } + int GetApiVersion() const { return m_api.GetApiVersion(); } + + bool TestLatLon(int index, double lat, double lon) const + { + ms::LatLon const ll = GetMark(index)->GetLatLon(); + return my::AlmostEqualULPs(ll.lat, lat) && my::AlmostEqualULPs(ll.lon, lon); + } + + bool TestRoutePoint(int index, double lat, double lon, string const & name) + { + RoutePoint const pt = GetRoutePoints()[index]; + return pt.m_org == MercatorBounds::FromLatLon(lat, lon) && pt.m_name == name; + } + + bool TestName(int index, string const & name) const + { + return GetMark(index)->GetName() == name; + } + + bool TestID(int index, string const & id) const + { + return GetMark(index)->GetApiID() == id; + } + + bool TestRouteType(string const & type) const { return m_api.GetRoutingType() == type; } +private: + ApiMarkPoint const * GetMark(int index) const + { + UserMarkNotificationGuard guard(*m_m, type); + TEST_LESS(index, static_cast(guard.m_controller.GetUserMarkCount()), ()); + return static_cast(guard.m_controller.GetUserMark(index)); + } + +private: + Framework m_fm; + ParsedMapApi m_api; + m2::RectD m_viewportRect; + BookmarkManager * m_m; +}; + +bool IsValid(Framework & fm, string const & uriString) +{ + ParsedMapApi api; + api.SetBookmarkManager(&fm.GetBookmarkManager()); + api.SetUriAndParse(uriString); + { + UserMarkNotificationGuard guard(fm.GetBookmarkManager(), UserMarkType::API_MARK); + guard.m_controller.Clear(); + } + + return api.IsValid(); +} } UNIT_TEST(MapApiSmoke) @@ -155,7 +158,7 @@ UNIT_TEST(SearchApiSmoke) UNIT_TEST(SearchApiInvalidUrl) { - Framework f; + Framework f(kFrameworkParams); TEST(!IsValid(f, "mapsme://search?"), ("The search query parameter is necessary")); TEST(!IsValid(f, "mapsme://search?query"), ("Search query can't be empty")); TEST(IsValid(f, "mapsme://search?query=aaa&cll=1,1,1"), ("If it's wrong lat lon format then just ignore it")); @@ -187,7 +190,7 @@ UNIT_TEST(LeadApiSmoke) UNIT_TEST(LeadApiInvalid) { - Framework f; + Framework f(kFrameworkParams); TEST(!IsValid(f, "mapsme://lead?"), ("From, type and name parameters are necessary")); TEST(!IsValid(f, "mapsme://lead?utm_source&utm_medium&utm_campaign"), ("Parameters can't be empty")); TEST(IsValid(f, "mapsme://lead?utm_source=a&utm_medium=b&utm_campaign=c"), ("These parameters are enough")); @@ -197,7 +200,7 @@ UNIT_TEST(LeadApiInvalid) UNIT_TEST(MapApiInvalidUrl) { - Framework fm; + Framework fm(kFrameworkParams); TEST(!IsValid(fm, "competitors://map?ll=12.3,34.54"), ()); TEST(!IsValid(fm, "mapswithme://ggg?ll=12.3,34.54"), ()); TEST(!IsValid(fm, "mwm://"), ("No parameters")); @@ -209,7 +212,7 @@ UNIT_TEST(MapApiInvalidUrl) UNIT_TEST(RouteApiInvalidUrl) { - Framework f; + Framework f(kFrameworkParams); TEST(!IsValid(f, "mapswithme://route?sll=1,1&saddr=name0&dll=2,2&daddr=name2"), ("Route type doesn't exist")); TEST(!IsValid(f, "mapswithme://route?sll=1,1&saddr=name0"), ("Destination doesn't exist")); @@ -229,7 +232,7 @@ UNIT_TEST(RouteApiInvalidUrl) UNIT_TEST(MapApiLatLonLimits) { - Framework fm; + Framework fm(kFrameworkParams); TEST(!IsValid(fm, "mapswithme://map?ll=-91,10"), ("Invalid latitude")); TEST(!IsValid(fm, "mwm://map?ll=523.55,10"), ("Invalid latitude")); TEST(!IsValid(fm, "mapswithme://map?ll=23.55,450"), ("Invalid longtitude")); diff --git a/mapshot/mapshot.cpp b/mapshot/mapshot.cpp index 1f9aae1d62..3abc1a7d87 100644 --- a/mapshot/mapshot.cpp +++ b/mapshot/mapshot.cpp @@ -184,7 +184,7 @@ int main(int argc, char * argv[]) try { - Framework f; + Framework f(FrameworkParams(false /* m_enableLocalAds */, false /* m_enableDiffs */)); auto processPlace = [&](string const & place) { diff --git a/openlr/openlr_match_quality/openlr_assessment_tool/main.cpp b/openlr/openlr_match_quality/openlr_assessment_tool/main.cpp index cd5a9d7248..3d24cf1fa9 100644 --- a/openlr/openlr_match_quality/openlr_assessment_tool/main.cpp +++ b/openlr/openlr_match_quality/openlr_assessment_tool/main.cpp @@ -24,7 +24,7 @@ int main(int argc, char * argv[]) QApplication app(argc, argv); FrameworkParams params; - params.m_disableLocalAds = true; + params.m_enableLocalAds = false; Framework framework(params); MainWindow mainWindow(framework); diff --git a/platform/http_request.cpp b/platform/http_request.cpp index e044383e96..846646194c 100644 --- a/platform/http_request.cpp +++ b/platform/http_request.cpp @@ -280,7 +280,7 @@ class FileHttpRequest : public HttpRequest, public IHttpThreadCallback } else if (result == ChunksDownloadStrategy::ENoFreeServers) { - // There is no any server which is able to re-download chunk. + // There is no server which is able to re-download chunk. m_status = EFailed; } diff --git a/search/search_quality/assessment_tool/assessment_tool.cpp b/search/search_quality/assessment_tool/assessment_tool.cpp index a071b571ac..2df013d370 100644 --- a/search/search_quality/assessment_tool/assessment_tool.cpp +++ b/search/search_quality/assessment_tool/assessment_tool.cpp @@ -31,7 +31,7 @@ int main(int argc, char ** argv) QApplication app(argc, argv); FrameworkParams params; - params.m_disableLocalAds = true; + params.m_enableLocalAds = false; Framework framework(params); MainView view(framework); diff --git a/storage/storage_integration_tests/migrate_tests.cpp b/storage/storage_integration_tests/migrate_tests.cpp index 8fa928b53d..785efd72b7 100644 --- a/storage/storage_integration_tests/migrate_tests.cpp +++ b/storage/storage_integration_tests/migrate_tests.cpp @@ -20,11 +20,13 @@ using namespace platform; using namespace storage; +static FrameworkParams const kFrameworkParams(false /* m_enableLocalAds */, false /* m_enableDiffs */); + UNIT_TEST(StorageFastMigrationTests) { WritableDirChanger writableDirChanger(kMapTestDir); - Framework f; + Framework f(kFrameworkParams); auto & s = f.GetStorage(); uint32_t version; @@ -43,7 +45,7 @@ UNIT_TEST(StorageMigrationTests) settings::Set("DisableFastMigrate", true); - Framework f; + Framework f(kFrameworkParams); auto & s = f.GetStorage(); auto statePrefetchChanged = [&](TCountryId const & id) diff --git a/storage/storage_integration_tests/storage_3levels_tests.cpp b/storage/storage_integration_tests/storage_3levels_tests.cpp index 6da1b1b1b0..8f82fcca93 100644 --- a/storage/storage_integration_tests/storage_3levels_tests.cpp +++ b/storage/storage_integration_tests/storage_3levels_tests.cpp @@ -39,7 +39,7 @@ UNIT_TEST(SmallMwms_3levels_Test) Platform & platform = GetPlatform(); - Framework f; + Framework f(FrameworkParams(false /* m_enableLocalAds */, false /* m_enableDiffs */)); auto & storage = f.GetStorage(); string const version = strings::to_string(storage.GetCurrentDataVersion()); TEST(version::IsSingleMwm(storage.GetCurrentDataVersion()), ()); diff --git a/storage/storage_integration_tests/storage_update_tests.cpp b/storage/storage_integration_tests/storage_update_tests.cpp index 6aa2339076..c250d9f219 100644 --- a/storage/storage_integration_tests/storage_update_tests.cpp +++ b/storage/storage_integration_tests/storage_update_tests.cpp @@ -21,6 +21,8 @@ using namespace storage; namespace { +static FrameworkParams const kFrameworkParams(false /* m_enableLocalAds */, false /* m_enableDiffs */); + string const kCountriesTxtFile = COUNTRIES_FILE; string const kMwmVersion1 = "160316"; @@ -87,7 +89,7 @@ UNIT_TEST(SmallMwms_Update_Test) TEST(DownloadFile(GetCountriesTxtWebUrl(kMwmVersion1), GetCountriesTxtFilePath(), kCountriesTxtFileSize1), ()); { - Framework f; + Framework f(kFrameworkParams); auto & storage = f.GetStorage(); string const version = strings::to_string(storage.GetCurrentDataVersion()); TEST(version::IsSingleMwm(storage.GetCurrentDataVersion()), ()); @@ -125,7 +127,7 @@ UNIT_TEST(SmallMwms_Update_Test) TEST(DownloadFile(GetCountriesTxtWebUrl(kMwmVersion2), GetCountriesTxtFilePath(), kCountriesTxtFileSize2), ()); { - Framework f; + Framework f(kFrameworkParams); auto & storage = f.GetStorage(); string const version = strings::to_string(storage.GetCurrentDataVersion()); TEST(version::IsSingleMwm(storage.GetCurrentDataVersion()), ());