diff --git a/map/map_tests/bookmarks_test.cpp b/map/map_tests/bookmarks_test.cpp index 9cebe850e5..2aa05f48a2 100644 --- a/map/map_tests/bookmarks_test.cpp +++ b/map/map_tests/bookmarks_test.cpp @@ -21,7 +21,7 @@ #include #include // strlen #include -#include +#include // std::reduce #include #include #include @@ -157,7 +157,7 @@ void CheckBookmarks(BookmarkManager const & bmManager, kml::MarkGroupId groupId) Bookmark const * bm = bmManager.GetBookmark(*it++); TEST_EQUAL(kml::GetDefaultStr(bm->GetName()), "Nebraska", ()); TEST_EQUAL(bm->GetColor(), kml::PredefinedColor::Red, ()); - TEST_EQUAL(bm->GetDescription(), "", ()); + TEST(bm->GetDescription().empty(), ()); TEST_EQUAL(kml::ToSecondsSinceEpoch(bm->GetTimeStamp()), 0, ()); bm = bmManager.GetBookmark(*it++); @@ -169,12 +169,12 @@ void CheckBookmarks(BookmarkManager const & bmManager, kml::MarkGroupId groupId) bm = bmManager.GetBookmark(*it++); m2::PointD org = bm->GetPivot(); - double const kEps = 1e-6; + double constexpr kEps = 1e-6; TEST(base::AlmostEqualAbs(mercator::XToLon(org.x), 27.566765, kEps), ()); TEST(base::AlmostEqualAbs(mercator::YToLat(org.y), 53.900047, kEps), ()); TEST_EQUAL(kml::GetDefaultStr(bm->GetName()), "From: Минск, Минская область, Беларусь", ()); TEST_EQUAL(bm->GetColor(), kml::PredefinedColor::Blue, ()); - TEST_EQUAL(bm->GetDescription(), "", ()); + TEST(bm->GetDescription().empty(), ()); TEST_EQUAL(kml::ToSecondsSinceEpoch(bm->GetTimeStamp()), 888888888, ()); bm = bmManager.GetBookmark(*it++); @@ -302,9 +302,9 @@ namespace Bookmark const * GetBookmark(Framework & fm, m2::PointD const & pt) { auto const * mark = GetMark(fm, pt); - ASSERT(mark != NULL, ()); + ASSERT(mark, ()); ASSERT(mark->GetMarkType() == UserMark::BOOKMARK, ()); - return static_cast(mark); + return dynamic_cast(mark); } Bookmark const * GetBookmarkPxPoint(Framework & fm, m2::PointD const & pt) @@ -327,7 +327,7 @@ UNIT_TEST(Bookmarks_Timestamp) BookmarkManager & bmManager = fm.GetBookmarkManager(); bmManager.EnableTestMode(true); - m2::PointD const orgPoint(10, 10); + m2::PointD constexpr orgPoint(10, 10); vector const arrCat = {"cat", "cat1"}; kml::BookmarkData b1; @@ -444,8 +444,8 @@ UNIT_TEST(Bookmarks_Getting) namespace { -void CheckPlace(Framework const & fm, shared_ptr mwmInfo, double lat, double lon, - StringUtf8Multilang const & streetNames, string const & houseNumber) +void CheckPlace(Framework const & fm, std::shared_ptr const & mwmInfo, double lat, double lon, + StringUtf8Multilang const & streetNames, std::string const & houseNumber) { auto const info = fm.GetAddressAtPoint(mercator::FromLatLon(lat, lon)); @@ -529,7 +529,7 @@ UNIT_TEST(Bookmarks_AddingMoving) fm.OnSize(800, 400); fm.ShowRect(m2::RectD(0, 0, 80, 40)); - m2::PointD const globalPoint = m2::PointD(40, 20); + m2::PointD constexpr globalPoint = m2::PointD(40, 20); m2::PointD const pixelPoint = fm.GtoP(globalPoint); BookmarkManager & bmManager = fm.GetBookmarkManager(); @@ -584,11 +584,11 @@ UNIT_TEST(Bookmarks_Sorting) BookmarkManager & bmManager = fm.GetBookmarkManager(); bmManager.EnableTestMode(true); - auto const kDay = std::chrono::hours(24); - auto const kWeek = 7 * kDay; - auto const kMonth = 31 * kDay; - auto const kYear = 365 * kDay; - auto const kUnknownTime = std::chrono::hours(0); + auto constexpr kDay = std::chrono::hours{24}; + auto constexpr kWeek = 7 * kDay; + auto constexpr kMonth = 31 * kDay; + auto constexpr kYear = 365 * kDay; + auto constexpr kUnknownTime = std::chrono::hours{0}; auto const currentTime = kml::TimestampClock::now(); auto const & c = classif(); @@ -610,12 +610,14 @@ UNIT_TEST(Bookmarks_Sorting) kml::MarkId m_markId; m2::PointD m_position; std::chrono::hours m_hoursSinceCreation; + // Name is autogenerated from types. std::vector m_types; }; struct TestTrackData { kml::TrackId m_trackId; + std::string m_name; std::chrono::hours m_hoursSinceCreation; }; @@ -626,7 +628,8 @@ UNIT_TEST(Bookmarks_Sorting) double constexpr kNearR = 20 * 1000; m2::PointD const myPos = mercator::GetSmPoint(kMoscowCenter, -kNearR, 0.0); - std::vector testMarksData = { + std::vector const testMarksData = + { {0, mercator::GetSmPoint(myPos, kNearR * 0.07, 0.0), kDay + std::chrono::hours(1), {"historic-ruins"}}, {1, mercator::GetSmPoint(myPos, kNearR * 0.06, 0.0), kUnknownTime, {"amenity-restaurant", "cuisine-sushi"}}, {2, mercator::GetSmPoint(myPos, kNearR * 0.05, 0.0), kUnknownTime, {"shop-music", "shop-gift"}}, @@ -642,32 +645,45 @@ UNIT_TEST(Bookmarks_Sorting) {12, mercator::GetSmPoint(myPos, kNearR * 1.04, 0.0), kDay + std::chrono::hours(2), {"shop-music"}}, }; - std::vector testTracksData = { - {0, kDay + std::chrono::hours(1)}, - {1, kUnknownTime}, - {2, kMonth + std::chrono::hours(1)} + std::vector const testTracksData = + { + {0, "Z Last Track", kDay + std::chrono::hours(1)}, + {1, "Middle Track", kUnknownTime}, + {2, "First Track", kMonth + std::chrono::hours(1)} }; - BookmarkManager::SortedBlocksCollection expectedSortedByDistance = { + BookmarkManager::SortedBlocksCollection const expectedSortedByDistance = + { {BookmarkManager::GetTracksSortedBlockName(), {}, {0, 1, 2}}, {BookmarkManager::GetNearMeSortedBlockName(), {8, 6, 4, 2, 1, 0}, {}}, {addrMoscow, {3, 5, 10, 12, 7, 9}, {}}, - {BookmarkManager::GetOthersSortedBlockName(), {11}, {}}}; + {BookmarkManager::GetOthersSortedBlockName(), {11}, {}} + }; - BookmarkManager::SortedBlocksCollection expectedSortedByTime = { + BookmarkManager::SortedBlocksCollection const expectedSortedByTime = + { {BookmarkManager::GetTracksSortedBlockName(), {}, {0, 2, 1}}, {BookmarkManager::GetSortedByTimeBlockName(BookmarkManager::SortedByTimeBlockType::WeekAgo), {8, 0, 12, 9}, {}}, {BookmarkManager::GetSortedByTimeBlockName(BookmarkManager::SortedByTimeBlockType::MonthAgo), {11, 3, 4}, {}}, {BookmarkManager::GetSortedByTimeBlockName(BookmarkManager::SortedByTimeBlockType::MoreThanMonthAgo), {5, 6}, {}}, {BookmarkManager::GetSortedByTimeBlockName(BookmarkManager::SortedByTimeBlockType::MoreThanYearAgo), {10}, {}}, - {BookmarkManager::GetSortedByTimeBlockName(BookmarkManager::SortedByTimeBlockType::Others), {7, 2, 1}, {}}}; + {BookmarkManager::GetSortedByTimeBlockName(BookmarkManager::SortedByTimeBlockType::Others), {7, 2, 1}, {}} + }; - BookmarkManager::SortedBlocksCollection expectedSortedByType = { + BookmarkManager::SortedBlocksCollection const expectedSortedByType = + { {BookmarkManager::GetTracksSortedBlockName(), {}, {0, 1, 2}}, {GetLocalizedBookmarkBaseType(BookmarkBaseType::Sights), {0, 3, 5, 10}, {}}, {GetLocalizedBookmarkBaseType(BookmarkBaseType::Food), {9, 4, 1}, {}}, {GetLocalizedBookmarkBaseType(BookmarkBaseType::Shop), {12, 6, 2}, {}}, - {BookmarkManager::GetOthersSortedBlockName(), {8, 11, 7}, {}}}; + {BookmarkManager::GetOthersSortedBlockName(), {8, 11, 7}, {}} + }; + + BookmarkManager::SortedBlocksCollection const expectedSortedByName = + { + {BookmarkManager::GetTracksSortedBlockName(), {}, {2, 1, 0}}, + {BookmarkManager::GetBookmarksSortedBlockName(), {11, 9, 7, 4, 1, 10, 3, 5, 0, 8, 12, 6, 2}, {}}, + }; auto const kBerlin1 = mercator::FromLatLon(52.5038994, 13.3982282); auto const kBerlin2 = mercator::FromLatLon(52.5007139, 13.4005403); @@ -683,7 +699,8 @@ UNIT_TEST(Bookmarks_Sorting) auto const kVladimir = mercator::FromLatLon(56.2102137, 40.5195297); auto const kBermuda = mercator::FromLatLon(32.2946391, -64.7820014); - std::vector testMarksData2 = { + std::vector const testMarksData2 = + { {100, kBerlin1, kUnknownTime, {"amenity", "building", "wheelchair-yes", "tourism-museum"}}, {101, kGreenland, kUnknownTime, {}}, {102, kVladimir, kUnknownTime, {"tourism-artwork"}}, @@ -709,7 +726,8 @@ UNIT_TEST(Bookmarks_Sorting) auto const addrVladimir = fm.GetBookmarkManager().GetLocalizedRegionAddress(kVladimir); auto const addrBermuda = fm.GetBookmarkManager().GetLocalizedRegionAddress(kBermuda); - BookmarkManager::SortedBlocksCollection expectedSortedByDistance2 = { + BookmarkManager::SortedBlocksCollection const expectedSortedByDistance2 = + { {addrVladimir, {102}, {}}, {addrMoscow, {106, 112}, {}}, {addrMinsk, {107, 104, 108}, {}}, @@ -720,13 +738,16 @@ UNIT_TEST(Bookmarks_Sorting) {addrBermuda, {111}, {}}, }; - BookmarkManager::SortedBlocksCollection expectedSortedByType2 = { + BookmarkManager::SortedBlocksCollection const expectedSortedByType2 = + { {GetLocalizedBookmarkBaseType(BookmarkBaseType::Food), {111, 109, 107, 103}, {}}, {GetLocalizedBookmarkBaseType(BookmarkBaseType::Museum), {110, 106, 100}, {}}, {GetLocalizedBookmarkBaseType(BookmarkBaseType::ReligiousPlace), {108, 105, 104}, {}}, - {BookmarkManager::GetOthersSortedBlockName(), {112, 102, 101}, {}}}; + {BookmarkManager::GetOthersSortedBlockName(), {112, 102, 101}, {}} + }; - std::vector testMarksData3 = { + std::vector const testMarksData3 = + { {200, {0.0, 0.0}, kUnknownTime, {"tourism-museum"}}, {201, {0.0, 0.0}, kUnknownTime, {"leisure-park"}}, {202, {0.0, 0.0}, kUnknownTime, {"tourism-artwork"}}, @@ -735,7 +756,8 @@ UNIT_TEST(Bookmarks_Sorting) {205, {0.0, 0.0}, kUnknownTime, {"amenity-place_of_worship-christian"}}, }; - std::vector testMarksData4 = { + std::vector const testMarksData4 = + { {300, {0.0, 0.0}, kUnknownTime, {"tourism-museum"}}, {301, {0.0, 0.0}, kUnknownTime, {"leisure-park"}}, {302, {0.0, 0.0}, kUnknownTime, {"tourism-artwork"}}, @@ -744,49 +766,56 @@ UNIT_TEST(Bookmarks_Sorting) {305, {0.0, 0.0}, kUnknownTime, {"tourism-hotel"}}, }; - BookmarkManager::SortedBlocksCollection expectedSortedByType4 = { + BookmarkManager::SortedBlocksCollection expectedSortedByType4 = + { {GetLocalizedBookmarkBaseType(BookmarkBaseType::Hotel), {305}, {}}, - {BookmarkManager::GetOthersSortedBlockName(), {304, 303, 302, 301, 300}, {}}}; - - std::vector testTracksData5 = { - {40, kUnknownTime}, - {41, kUnknownTime}, - {42, std::chrono::hours(1)}, - {43, kUnknownTime} + {BookmarkManager::GetOthersSortedBlockName(), {304, 303, 302, 301, 300}, {}} }; - BookmarkManager::SortedBlocksCollection expectedSortedByTime5 = { - {BookmarkManager::GetTracksSortedBlockName(), {}, {42, 40, 41, 43}}}; - - std::vector testTracksData6 = { - {50, kUnknownTime}, - {51, kUnknownTime}, - {52, kUnknownTime} + std::vector const testTracksData5 = + { + {40, "t", kUnknownTime}, + {41, "a", kUnknownTime}, + {42, "u", std::chrono::hours(1)}, + {43, "a", kUnknownTime} }; - auto const fillCategory = [&](kml::MarkGroupId cat, - std::vector const & marksData, - std::vector const & tracksData) + BookmarkManager::SortedBlocksCollection const expectedSortedByTime5 = + { + {BookmarkManager::GetTracksSortedBlockName(), {}, {42, 40, 41, 43}} + }; + + std::vector const testTracksData6 = + { + {50, "-11", kUnknownTime}, + {51, "41", kUnknownTime}, + {52, "", kUnknownTime} + }; + + auto const fillCategory = [&](kml::MarkGroupId cat, std::vector const & marksData, std::vector const & tracksData) { auto es = bmManager.GetEditSession(); - for (auto const & testMarkData : marksData) + for (auto const & [id, position, hours, types] : marksData) { kml::BookmarkData bmData; - bmData.m_id = testMarkData.m_markId; - bmData.m_point = testMarkData.m_position; - if (testMarkData.m_hoursSinceCreation != kUnknownTime) - bmData.m_timestamp = currentTime - testMarkData.m_hoursSinceCreation; - setFeatureTypes(testMarkData.m_types, bmData); + bmData.m_id = id; + bmData.m_name = kml::LocalizableString{{kml::kDefaultLangCode, + std::reduce(types.begin(), types.end(), std::string{}, [](auto const & sum, auto const & type) { return sum + type + " "; })}}; + bmData.m_point = position; + if (hours != kUnknownTime) + bmData.m_timestamp = currentTime - hours; + setFeatureTypes(types, bmData); auto const * bm = es.CreateBookmark(std::move(bmData)); es.AttachBookmark(bm->GetId(), cat); } - for (auto const & testTrackData : tracksData) + for (auto const & [id, name, hours] : tracksData) { kml::TrackData trackData; - trackData.m_id = testTrackData.m_trackId; + trackData.m_id = id; + trackData.m_name = kml::LocalizableString{{kml::kDefaultLangCode, name}}; trackData.m_geometry.Assign({{{0.0, 0.0}, 1}, {{1.0, 0.0}, 2}}); - if (testTrackData.m_hoursSinceCreation != kUnknownTime) - trackData.m_timestamp = currentTime - testTrackData.m_hoursSinceCreation; + if (hours != kUnknownTime) + trackData.m_timestamp = currentTime - hours; auto const * track = es.CreateTrack(std::move(trackData)); es.AttachTrack(track->GetId(), cat); } @@ -797,12 +826,12 @@ UNIT_TEST(Bookmarks_Sorting) // Uncomment for debug output. /* LOG(LINFO, ("\nvvvvvvvvvv ", name, " vvvvvvvvvv")); - for (auto const & block : blocks) + for (auto const & [blockName, markIds, trackIds] : blocks) { - LOG(LINFO, ("========== ", block.m_blockName)); - for (auto const trackId : block.m_trackIds) + LOG(LINFO, ("========== ", blockName)); + for (auto const trackId : trackIds) LOG(LINFO, (" track", trackId)); - for (auto const markId : block.m_markIds) + for (auto const markId : markIds) LOG(LINFO, (" bookmark", markId)); } */ @@ -830,10 +859,13 @@ UNIT_TEST(Bookmarks_Sorting) kml::MarkGroupId catId = bmManager.CreateBookmarkCategory("test", false); fillCategory(catId, testMarksData, testTracksData); - std::vector expectedSortingTypes = { + std::vector const expectedSortingTypes = + { BookmarkManager::SortingType::ByType, BookmarkManager::SortingType::ByDistance, - BookmarkManager::SortingType::ByTime}; + BookmarkManager::SortingType::ByTime, + BookmarkManager::SortingType::ByName + }; auto const sortingTypes = bmManager.GetAvailableSortingTypes(catId, true); TEST(sortingTypes == expectedSortingTypes, ()); @@ -846,25 +878,34 @@ UNIT_TEST(Bookmarks_Sorting) printBlocks("Sorted by type", sortedByType); TEST(sortedByType == expectedSortedByType, ()); - auto const sortedByDistance = getSortedBokmarks(catId, BookmarkManager::SortingType::ByDistance, true, myPos); printBlocks("Sorted by distance", sortedByDistance); TEST(sortedByDistance == expectedSortedByDistance, ()); + + auto const sortedByName = getSortedBokmarks(catId, BookmarkManager::SortingType::ByName, false, myPos); + printBlocks("Sorted by name", sortedByName); + TEST(sortedByName == expectedSortedByName, ()); } { - kml::MarkGroupId catId2 = bmManager.CreateBookmarkCategory("test2", false); + kml::MarkGroupId const catId2 = bmManager.CreateBookmarkCategory("test2", false); fillCategory(catId2, testMarksData2, {} /* tracksData */); - std::vector expectedSortingTypes2 = { + std::vector const expectedSortingTypes2 = + { BookmarkManager::SortingType::ByType, - BookmarkManager::SortingType::ByDistance}; + BookmarkManager::SortingType::ByDistance, + BookmarkManager::SortingType::ByName, + }; auto const sortingTypes2 = bmManager.GetAvailableSortingTypes(catId2, true); TEST(sortingTypes2 == expectedSortingTypes2, ()); - std::vector expectedSortingTypes2_2 = { - BookmarkManager::SortingType::ByType}; + std::vector expectedSortingTypes2_2 = + { + BookmarkManager::SortingType::ByType, + BookmarkManager::SortingType::ByName, + }; auto const sortingTypes2_2 = bmManager.GetAvailableSortingTypes(catId2, false); TEST(sortingTypes2_2 == expectedSortingTypes2_2, ()); @@ -880,19 +921,19 @@ UNIT_TEST(Bookmarks_Sorting) } { - kml::MarkGroupId catId3 = bmManager.CreateBookmarkCategory("test3", false); + kml::MarkGroupId const catId3 = bmManager.CreateBookmarkCategory("test3", false); fillCategory(catId3, testMarksData3, {} /* tracksData */); - std::vector expectedSortingTypes3 = {}; + std::vector const expectedSortingTypes3 = {BookmarkManager::SortingType::ByName}; auto const sortingTypes3 = bmManager.GetAvailableSortingTypes(catId3, false); TEST(sortingTypes3 == expectedSortingTypes3, ()); } { - kml::MarkGroupId catId4 = bmManager.CreateBookmarkCategory("test4", false); + kml::MarkGroupId const catId4 = bmManager.CreateBookmarkCategory("test4", false); fillCategory(catId4, testMarksData4, {} /* tracksData */); - std::vector expectedSortingTypes4 = { BookmarkManager::SortingType::ByType }; + std::vector const expectedSortingTypes4 = { BookmarkManager::SortingType::ByType, BookmarkManager::SortingType::ByName }; auto const sortingTypes4 = bmManager.GetAvailableSortingTypes(catId4, false); TEST(sortingTypes4 == expectedSortingTypes4, ()); @@ -902,9 +943,9 @@ UNIT_TEST(Bookmarks_Sorting) } { - kml::MarkGroupId catId5 = bmManager.CreateBookmarkCategory("test5", false); + kml::MarkGroupId const catId5 = bmManager.CreateBookmarkCategory("test5", false); fillCategory(catId5, {} /* marksData */, testTracksData5); - std::vector expectedSortingTypes5 = { BookmarkManager::SortingType::ByTime }; + std::vector const expectedSortingTypes5 = { BookmarkManager::SortingType::ByTime, BookmarkManager::SortingType::ByName }; auto const sortingTypes5 = bmManager.GetAvailableSortingTypes(catId5, false); TEST(sortingTypes5 == expectedSortingTypes5, ()); @@ -915,9 +956,9 @@ UNIT_TEST(Bookmarks_Sorting) } { - kml::MarkGroupId catId6 = bmManager.CreateBookmarkCategory("test6", false); + kml::MarkGroupId const catId6 = bmManager.CreateBookmarkCategory("test6", false); fillCategory(catId6, {} /* marksData */, testTracksData6); - std::vector expectedSortingTypes6 = {}; + std::vector const expectedSortingTypes6 = {BookmarkManager::SortingType::ByName}; auto const sortingTypes6 = bmManager.GetAvailableSortingTypes(catId6, false); TEST(sortingTypes6 == expectedSortingTypes6, ()); @@ -1071,7 +1112,7 @@ UNIT_CLASS_TEST(Runner, Bookmarks_SpecialXMLNames) TEST_EQUAL(bmManager.GetUserMarkIds(catId2).size(), 1, ()); TEST_EQUAL(bmManager.GetCategoryName(catId2), expectedName, ()); - TEST_EQUAL(bmManager.GetCategoryFileName(catId2), "", ()); + TEST(bmManager.GetCategoryFileName(catId2).empty(), ()); auto const bmId1 = *bmManager.GetUserMarkIds(catId2).begin(); auto const * bm1 = bmManager.GetBookmark(bmId1); @@ -1100,14 +1141,14 @@ UNIT_CLASS_TEST(Runner, TrackParsingTest_1) TEST_EQUAL(bmManager.GetTrackIds(catId).size(), 4, ()); array const names = {{"Option1", "Pakkred1", "Pakkred2", "Pakkred3"}}; - array const col = {{dp::Color(230, 0, 0, 255), + array constexpr col = {{dp::Color(230, 0, 0, 255), dp::Color(171, 230, 0, 255), dp::Color(0, 230, 117, 255), dp::Color(0, 59, 230, 255)}}; - array const length = {{3525.46839061, 27172.44338132, 27046.0456586, 23967.35765800}}; - array const altitudes = {{0, 27, -3, -2}}; + array constexpr length = {{3525.46839061, 27172.44338132, 27046.0456586, 23967.35765800}}; + array constexpr altitudes = {{0, 27, -3, -2}}; size_t i = 0; - for (auto trackId : bmManager.GetTrackIds(catId)) + for (auto const trackId : bmManager.GetTrackIds(catId)) { auto const * track = bmManager.GetTrack(trackId); auto const & geom = track->GetSingleGeometry();